akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    VI p(n);
    REP(i,n) p[i] = in() - 1;
    VL c(n, b);

    VVL dp(n + 1, VL(n + 1, 1e18));
    dp[0][0] = 0;
    REP(i,n+1){
        REP(j,n) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + c[j]);
        if (i < n){
            REP(j,n+1) dp[i+1][j] = dp[i][j];
            dp[i+1][p[i]+1] = dp[i][p[i]];
            c[p[i]] = a;
        }
    }
    cout << dp[n][n] << endl;

    return 0;
}


Measured memory_bytes: 195840
n = int(input())
if n == 1:
    print(1)
elif n >= 2 and n < 4:
    print(2)
elif n >= 4 and n < 8:
    print(4)
elif n >= 8 and n < 16:
    print(8)
elif n >= 16 and n < 32:
    print(16)
elif n >= 32 and n < 64:
    print(32)
elif n >= 64:
    print(64)
  

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;

    int xmax = -101;
    for (int i = 0; i < n; i++)
    {
        int xi;
        cin >> xi;
        xmax = max(xi, xmax);
    }

    int ymin = 101;
    for (int i = 0; i < m; i++)
    {
        int yi;
        cin >> yi;
        ymin = min(yi, ymin);
    }

    string ans;
    if (xmax < ymin && x < ymin && xmax < y)
    {
        ans = "No War";
    }
    else
    {
        ans = "War";
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int N=5005;
const int MOD=1000000007;
int n,a,b;
long long f[N][2];
long long g[N];
long long dp[N][2];
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if(a>b) swap(a,b);
	if(b==1)
	{
		printf("%lld",ksm(2,n));
		return 0;
	}
	f[0][0]=f[0][1]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<i;j++)
			f[i][1]=(f[i][1]+f[j][0])%MOD;
		for(int j=0;j+a<=i;j++)
			f[i][0]=(f[i][0]+f[j][1])%MOD;
	}
	g[0]=1;
	for(int i=1;i<=n;i++)
		g[i]=(f[i][0]+f[i][1])%MOD;
	long long ans=0;
	for(int i=1;i<n;i++)
	{
		if(i<a) dp[i][0]=(dp[i][0]+1)%MOD;
		for(int j=i-a+1;j<i;j++)
			if(j>0) dp[i][0]=(dp[i][0]+dp[j][1])%MOD;
		if(i<b) dp[i][1]=(dp[i][1]+g[i-1])%MOD;
		for(int j=i-b+1;j<i;j++)
			if(j>0) dp[i][1]=(dp[i][1]+dp[j][0]*(i-j==1?1:g[i-j-2])%MOD)%MOD;
		if(i+b-1>=n) ans=(ans+dp[i][0]*g[n-i-1]%MOD)%MOD;
		if(i+a-1>=n) ans=(ans+dp[i][1])%MOD;
	}
	printf("%lld",(ksm(2,n)-ans+MOD)%MOD);
	return 0;
}

Measured memory_bytes: 3980
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define N 200001
using namespace std;
int n;
struct node{
	int i,x;
} d[N];
inline bool cmp(node a,node b){
	return a.x<b.x;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i=-~i){
		scanf("%d",&d[i].x);
		d[i].i=i;
	}
	sort(d+1,d+n+1,cmp);
	for(int i=1;i<=n;i=-~i)
		if(i==d[n].i)
			printf("%d\n",d[n-1].x);
		else
			printf("%d\n",d[n].x);
	return 0;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


// aとbの最大公約数
ll gcd(ll a, ll b) {
	if (a < b) gcd(b, a);
	ll r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}

// nの素因子
set<int> prime(int n){
	set<int> ret;
	for (int p = 2; p*p <= n; p++){
		if (n%p == 0){
			ret.insert(p);
			while (n % p == 0) n /= p;
		}
	}
	if (n>1) ret.insert(n);
	return ret;
}

// 素数判定
bool isprime(int  n){
	if (n < 2) return false;
	else if (n == 2) return true;
	else if (n % 2 == 0) return false;
	else
		for (int i = 3; i*i <= n; i++)
			if (n%i == 0) return false;

	return true;
}



signed main(){

	int N;
	cin >> N;
	vector<int> a(N + 1);
	rep(i, N + 1) cin >> a[N - i];

	set<int> ans;

	// a[i]のgcdは自明
	int g = abs(a[N]);
	for (int i = 0; i < N; i++){
		if (a[i] != 0)
			g = gcd(g, abs(a[i]));
	}

	ans = prime(g);

	// あらかじめgcdで割っておく
	rep(i, N + 1) a[i] /= g;
	// 候補についてチェック
	for (int p = 2; p <= 10001; p++){
		if (!isprime(p)) continue;

		vector<int> c;
		c = a;
		for (int i = p; i <= N; i++){
			if (i % (p - 1)==0)
				c[(p - 1)] += c[i];
			else
				c[i % (p - 1)] += c[i];
		}

		// すべてがpで割り切れるか
		bool found = true;
		rep(i, p){
			if (i > N) break;
			if (abs(c[i]) % p == 0) continue;
			else {
				found = false;
				break;
			}
		}
		if (found)
			ans.insert(p);
	}

	for (int p : ans){
		cout << p << endl;
	}

	return 0;
}


Measured memory_bytes: 384
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ n, k ] = readMany(2).map(it => parseInt(it))
    const p = readMany(n).map(it => parseInt(it)).sort((a, b) => a - b)

    let answer = 0
    for (let i = 0; i < k; i += 1) {
        answer += p[i]
    }

    console.log(answer)
})()


Measured memory_bytes: 29864
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

template<typename T>
struct BIT{
	vector<T> bit;
	BIT(int sz){
		bit.resize(sz);
	}
	void add(int k, T x){ //k番目にxを加える
		for(int i = k; i < bit.size(); i |= i+1) bit[i] += x;	
	}
	T sum(int k){ //[0,k)の区間の総和を求める
		T res = 0;
		for(int i = k-1; i >= 0; i = (i & (i+1))-1){
			res += bit[i];
		}
		return res;
	}
};

int main(){
    int N; cin >> N;
    string s; cin >> s;
    int Q; cin >> Q;
    vector<BIT<int>> bit(26,BIT<int>(N));
    rep(i,N){
        bit[s[i]-'a'].add(i,1);
    }
    rep(i,Q){
        int c,a; cin >> c >> a;
        a--;
        if(c == 1){
            char b; cin >> b;
            bit[s[a]-'a'].add(a,-1);
            bit[b-'a'].add(a,1);
            s[a] = b;
        }
        else{
            int b; cin >> b;
            int ans = 0;
            rep(j,26){
                if(bit[j].sum(b)-bit[j].sum(a) >= 1) ans++;
            }
            cout << ans << endl;
        }
    }

}


Measured memory_bytes: 53636
import sys

ERROR_INPUT = 'input is invalid'


def main():
    n = get_length()
    arr = get_array(length=n)

    sourtLi, count = bubbleSort(li=arr, length=n)
    print(*sourtLi)
    print(count)
    return 0


def get_length():
    n = int(input())
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n


def get_array(length):
    nums = input().split(' ')
    return [str2int(string=n) for n in nums]


def str2int(string):
    n = int(string)
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n


def bubbleSort(li, length):
    count = 0
    for n in range(length):
        for n in range(1, length - n):
            if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

    return li, count


main()

Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main() {
	int N, M;
    cin >> N >> M;
    vvi g(N + 1);
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vi dist(N + 1, -1);
    dist[1] = 0;
    vi near(N+1);
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : g[v]) {
            if (dist[u] != -1)continue;
            dist[u] = dist[v] + 1;
            near[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << endl;
    for (int i = 2; i <= N; i++)cout << near[i] << endl;
}

Measured memory_bytes: 10744
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void){
	char w[11]={0};
	char t[1001]={0};
	int i;
	int count=0;
	scanf("%s",w);
	for(i=0;i<11;i++) w[i]= tolower(w[i]);
	while(1){
		scanf(" %s",t);
		if(!strcmp(t,"END_OF_TEXT")){
			break;
		}
		for(i=0;i<1001;i++){
			t[i]= tolower(t[i]);
		}

		if(!strcmp(t,w)){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 552
#include<iostream>
using namespace std;
int main() {
    int n, m, l;
    int x[100][100];
    int y[100][100];
    long long z[100][100];
    cin >> n >> m >> l;
    for (int prime1 = 0; prime1 < n; prime1++) {
        for (int prime2 = 0; prime2 < m; prime2++) {
            cin >> x[prime1][prime2];
        }
    }
    for (int prime2 = 0; prime2 < m; prime2++) {
        for (int prime3 = 0; prime3 < l; prime3++) {
            cin >> y[prime2][prime3];
        }
    }
    for (int prime1 = 0; prime1 < n; prime1++) {
        for (int prime3 = 0; prime3 < l; prime3++) {
            z[prime1][prime3] = 0;
            for (int prime2 = 0; prime2 < m; prime2++) {
                z[prime1][prime3] += x[prime1][prime2] * y[prime2][prime3];
            }
        }
    }
    for (int prime1 = 0; prime1 < n; prime1++) {
        for (int prime3 = 0; prime3 < l; prime3++) {
            if(prime3<l-1){
                cout << z[prime1][prime3] << " ";
            }else{
                cout << z[prime1][prime3];
            }
        }
        cout << endl;
    }
    return 0;
}

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

#define int long long

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

    int t[100001], x[100001], y[100001];
    t[0] = x[0] = y[0] = 0;
    for(int i=0; i<n; ++i) {
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    bool ans = true;
    for(int i=0; i<n; ++i) {
        int dt = t[i+1] - t[i];
        int dl = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if(dl > dt) ans = false;
        if(dl%2!=dt%2) ans = false;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

	int A, B;
	cin >> A >> B;

	cout << A * B << endl;

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

long long fibo[100001];

long long fib(int n){
    if(fibo[n] != 0)
        return fibo[n];
    else{
        fibo[n] = (fib(n-1) + fib(n-2)) % MOD;
        return fibo[n];
    }
}

int main(){
    long long a, n, m, b = -1;
    long long ans = 1;

    memset(fibo, 0, 100001);

    fibo[1] = 1;
    fibo[2] = 1;

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a;
        int d = a - b;
        if(d == 1){
            ans = 0;
            break;
        }
        else{
            ans = ans * fib(d - 1) % MOD;
        }
        b = a;
    }
    ans = ans * fib(n - b) % MOD;
    cout << ans % MOD << endl;
}

Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

LL a[2010], f[2010][2010];
int id[2010];
int n;

inline void work() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        id[i] = i;
    }
    // sort(id + 1, id + n + 1, [&](int i, int j) {return a[i] < a[j] || (a[i] == a[j] && i < j);});
    sort(id + 1, id + n + 1, [&](int i, int j) {return a[i] < a[j];});
    for (int i = n; i >= 1; --i) {
        f[i][i] = a[id[1]] * abs(id[1] - i);
        for (int j = i + 1; j <= n; ++j) {
            f[i][j] = max(f[i][j - 1] + a[id[j - i + 1]] * abs(id[j - i + 1] - j), f[i + 1][j] + a[id[j - i + 1]] * abs(id[j - i + 1] - i));
        }
    }
    cout << f[1][n] << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 26340
#include <iostream>
#include <cstdlib>

using namespace std;
#define N 5000
#define C 15
#define CHANGE_RATE 0.1

int main()
{
    int d = 0;
    int c[26];
    int s[365][26];
    int t_c[C][365];
    int last[26] = {0};
    int score_c[C] = {0};
    int score = 0;
    int max_c = 0;

    cin >> d;

    for(int i = 0; i < 26; i++)
    {
        cin >> c[i];
    }

    for(int i = 0; i < d; i++)
    {
        for(int j = 0; j < 26; j++)
        {
            cin >> s[i][j];
        }
    }

    for(int i = 0; i < C; i++)
    {
        for(int j = 0; j < 365; j++)
        {
            t_c[i][j] = rand() % 26;
        }
    }

    for(int n = 0; n < N; n++)
    {
        score = 0;
        max_c = 0;
        for(int ca = 0; ca < C; ca++)
        {
            score_c[ca] = 0;
            for(int i = 0; i < 26; i++)
                last[i] = 0;

            for(int i = 0; i < d; i++)
            {
                for(int j = 0; j < 26; j++)
                {
                    if(t_c[ca][i] == j)
                    {
                        last[j] = 0;
                        score_c[ca] += s[i][j];
                    }
                    else
                    {
                        last[j]++;
                        score_c[ca] -= c[j] * last[j];
                    }
                }
            }
        }

        for(int ca = 0; ca < C; ca++)
        {
            if(score < score_c[ca])
            {
                score = score_c[ca];
                max_c = ca;
            }
        }
        //cout << score << endl;

        for(int ca = 0; ca < C; ca++)
        {
            if(ca == max_c) continue;
            for(int i = 0; i < d; i++)
            {
                if((rand() / (double)RAND_MAX) < CHANGE_RATE)
                {
                    t_c[ca][i] = rand() % 26;
                }
                else
                {
                    t_c[ca][i] = t_c[max_c][i];
                }
            }
        }
    }

    for(int i = 0; i < d; i++)
    {
        cout << ((t_c[max_c][i] % 26) + 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 3700
n,k=map(int,input().split())
lr=[tuple(map(int,input().split())) for i in range(k)]
mod=998244353
dp=[0]*n
dp[0]=1
s=0
for i in range(n):
  s+=dp[i]
  for l,r in lr:
    if i+l<n:
      dp[i+l]=(dp[i+l]+s)%mod
      if i+r+1<n:
        dp[i+r+1]=(dp[i+r+1]-s)%mod
print(dp[n-1])

Measured memory_bytes: 16904
#include <iostream>
#include <cstdio>
#include <cstring>
#define int long long
using namespace std;
const int INF=1e3+125;
const int dfx[]={0,0,1,-1},dfy[]={1,-1,0,0};
const int bfx[]={-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1,2,2,2,2,2};
const int bfy[]={-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2};
int h,w,cx,cy,dx,dy,qx[INF*INF*30+25],qy[INF*INF*30+25],l,r,dis_[INF][INF];
bool vis[INF][INF];
char Map[INF][INF];
void DFS(int x,int y) {
        for (int i=0; i<4; i++) {
                int gx=x+dfx[i],gy=y+dfy[i];
                if (gx<1 || gy<1 || gx>h || gy>w|| Map[gx][gy]!='.' || dis_[gx][gy]<=dis_[x][y]) continue;
                vis[gx][gy]=true;
                dis_[gx][gy]=dis_[x][y];
                qx[++r]=gx;
                qy[r]=gy;
                DFS(gx,gy);
        }
        return;
}
void BFS() {
        memset(dis_,63,sizeof dis_);
        vis[cx][cy]=true;
        dis_[cx][cy]=0;
        // bool flag=false;
        while (l<=r) {
                int x=qx[l],y=qy[l]; l++;
                DFS(x,y);
                // if (vis[dx][dy]) flag=true;
                // if (flag) break;
                for (int i=0; i<20; i++) {
                        int gx=x+bfx[i],gy=y+bfy[i];
                        if (gx<1 || gy<1 || gx>h || gy>w|| Map[gx][gy]!='.' || dis_[gx][gy]<=dis_[x][y]+1) continue;
                        dis_[gx][gy]=dis_[x][y]+1;
                        vis[gx][gy]=true;
                        // if (vis[dx][dy]) flag=true;
                        // if (flag) break;
                        qx[++r]=gx;
                        qy[r]=gy;
                }
                // if (flag) break;
                // for (int i=1; i<=h; i++) {
                //         for (int j=1; j<=w; j++)
                //                 cout<<dis_[i][j]<<" ";
                //         cout<<endl;
                // }
        }
        return;
}
signed main()
{
        scanf("%lld %lld",&h,&w); scanf("%lld %lld %lld %lld ",&cx,&cy,&dx,&dy);
        for (int i=1; i<=h; i++) {
                for (int j=1; j<=w; j++)
                        cin>>Map[i][j];
        }
        // cout<<"ok\n";
        l=1;
        qx[++r]=cx;
        qy[r]=cy;
        BFS();
        if (vis[dx][dy]) cout<<dis_[dx][dy]<<"\n";
        else cout<<"-1\n";
        return 0;
}


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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<32>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int n, a, b, c, d;
string s;

int main()
{
    ci >> n >> a >> b >> c >> d;
    ci >> s;
    a--; b--; c--; d--;
    s += "###";
    
    bool flg = true;
    if(c < d) {
	rep(i, b + 1, d) if(s[i] == '#' && s[i + 1] == '#') flg = false;
	rep(i, a + 1, c) if(s[i] == '#' && s[i + 1] == '#') flg = false;
    } else {
	rep(i, a + 1, c) if(s[i] == '#' && s[i + 1] == '#') flg = false;
	
	bool ch = false;
	rep(i, b - 1, d) {
	    if(s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') ch = true;
	}

	flg = (flg & ch);
    }

    co << (flg ? "Yes" : "No") << en;
    
    return 0;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int main(void)
{
	int n,p,a,flag=0,i;
	scanf("%d%d",&n,&p);
	FOR(i,0,n){
		scanf("%d",&a);
		if(a%2) flag=1;
	}
	if(flag) printf("%lld\n",1LL<<(n-1));
	else printf("%lld\n",p?0:1LL<<n);
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll ks(ll w[],ll v[],ll n,ll W){
    ll k[n+1][W+1];
    for(ll i=0;i<=n;i++){
        for(ll t=0;t<=W;t++){
            if(i==0 || t==0){
                k[i][t]=0;
            }
            else if(w[i-1]<=t){
                k[i][t]=max(v[i-1]+k[i-1][t-w[i-1]],k[i-1][t]);
            }
            else{
                k[i][t]=k[i-1][t];
            }
        }
    }
    return k[n][W];
}
int main(){
    ll n,W;
    cin>>n>>W;
    ll w[n],v[n];
    for(ll i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    ll ans=ks(w,v,n,W);
    cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 79104
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        var A = new int[26];
        for (int i = 0; i < 26; i++)
        {
            A[i] = int.MaxValue / 3;
        }
        int N = cin.nextint;
        var W = new int[N];
        for (int i = 0; i < N; i++)
        {
            W[i] = ReadLine()[0] - 'a';
        }
        var dp = new int[N + 1];
        for (int i = 0; i < N; i++)
        {
            chmin(ref A[W[i]], dp[i]);
            dp[i + 1] = Math.Min(dp[i] + 1, A[W[i]] + 1);
        }
        WriteLine(dp[N]);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}


Measured memory_bytes: 20320
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    string s;
    cin >> s;
    int n[500500];
    for (int i = 0; i < s.size() + 1; i++) {
        n[i] = -1;
    }

    if (s[0] == '<') n[0] = 0;
    if (s[s.size() - 1] == '>') n[s.size()] = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '>' && s[i + 1] == '<') {
            n[i + 1] = 0;
        }
    }

    //右
    for (int i = 0; i < s.size(); i++) {
        if (n[i] == 0) {
            int cnt = 0;
            while (1) {
                if (s[i] == '<') {
                    cnt++;
                    n[i + 1] = max(n[i + 1], cnt);
                    i++;
                }
                else break;
            }
            //i--;
        }
    }

    //左
    for (int i = s.size() - 1; i >= 0; i--) {
        if (n[i + 1] == 0) {
            int cnt = 0;
            while (1) {
                if (s[i] == '>') {
                    cnt++;
                    n[i] = max(n[i], cnt);
                    i--;
                }
                else break;
            }
            /*
            while (s[i] == '>' && n[i] == -1) {
                cnt++;
                n[i] = cnt;
                i--;
            }
            */
            //i++;
        }
    }

    /*
    for (int i = 0; i < s.size() + 1; i++) {
        cout << n[i] << " ";
    }
    cout << endl;
    */

    long long ans = 0;
    for (int i = 0; i < s.size() + 1; i++) {
        ans += n[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2820
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/

int main()
{
	int n;
	
	scanf("%d", &n);
	puts(n >= 1200 ? "ARC" : "ABC");
}

Measured memory_bytes: 256
require 'set'

def f(s)
	0 while s.gsub!(/\(\((-?\d+)\)\)/, '(\1)')
	0 while s.gsub!(/\((\d+)\)/, '\1')
	return if $checked[s]
	$checked[s] = 0

	op_hash = {}
	num_hash = {}
	if s.scan(/\d+/).size == 1
		$set << eval(s)
		return
	end

	s.gsub!(/\((-?\d+)\)/) do
		c = ((?A.ord) + num_hash.size).chr
		num_hash[c] = $1.to_i
		c
	end

	s.gsub!(/\d+/) do |x|
		c = ((?A.ord) + num_hash.size).chr
		num_hash[c] = x.to_i
		c
	end

	
	s.gsub!(/(?<=[A-Z]|\([A-Z]\))[-+*\/](?=[A-Z]|\([A-Z]\))/) do |x|
		c = ((?a.ord) + op_hash.size).chr
		op_hash[c] = x
		c
	end
	
	op_hash.each do |c, op|
		d = s.dup
		begin
			if d.sub!(/([A-Z]|\([A-Z]\))#{c}([A-Z]|\([A-Z]\))/){|x|
				x = num_hash[$1[0] == ?( ? $1[1..-2] : $1]
				y = num_hash[$2[0] == ?( ? $2[1..-2] : $2]
				raise if op == ?/ && y == 0

				z = if x * y < 0 && op == ?/
						-(x.abs.send(op, y.abs))
					else
						x.send(op, y)
					end

				if z < 0
					"(#{z})"
				else
					z.to_s
				end
			}
				next_s = d.gsub(/[a-z]/){|l| op_hash[l]}.gsub(/[A-Z]/){|l| ?( + num_hash[l].to_s + ?)}
				f(next_s)
			end
		rescue
		end
	end
end

loop do
	s = gets.chomp
	break if s == ?#
	$set = Set.new
	$checked = {}
	f(s)
	p $set.size
end

Measured memory_bytes: 10560
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll x, y = 100;
    cin >> x;
    ll ans = 0;
    while(y < x) {
        y = y + y / 100;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;

bool AOJ0136()
{
	int n;
	cin >> n;
	double h;
	int dist[6] = { 0 };
	REP(i, n) {
		cin >> h;
		if (h < 165) dist[0]++;
		else if (h < 170) dist[1]++;
		else if (h < 175) dist[2]++;
		else if (h < 180) dist[3]++;
		else if (h < 185) dist[4]++;
		else dist[5]++;
	}
	REP(i, 6) {
		cout << i + 1 << ":";
		REP(j, dist[i]) {
			cout << "*";
		}
		cout << endl;
	}

	return true;
}

int main()
{
	AOJ0136();

	return 0;
}

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

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int num[n];
      double data[n];
      double min=1000000;
      int min_num;
      for(int i=0;i<n;i++)
	{
	  int a,b;
	  cin>>num[i]>>a>>b;
	  data[i]=(double)b/((a/100.0)*(a/100.0));
	  ///  cout<<data[i]<<endl;
	  data[i]-=22;
	  data[i]=max(data[i],-data[i]);
	  if(data[i]<min||data[i]==min&&num[i]<num[min_num])
	    {
	      min=data[i];
	      min_num=i;
	    }
	}
      cout<<num[min_num]<<endl;
    }
}

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

int main() {
  int n,m;
  cin>>n>>m;
  int a[2*m];
  for(int i=0;i<2*m;i++){
    cin>>a[i];    
  }
  int b[n]={0};
  for (int i=0;i<2*m;i++){
    b[a[i]-1]++;
  }
  for(int i=0;i<n;i++){
    cout<<b[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        //入力
        int N = int.Parse(Console.ReadLine());
        //Nの桁数
        int digit = (int)Math.Floor(Math.Log10(N)) + 1;

        //回答となる数値
        int ans = 0;

        for (int i = 1; i < digit; i++) {
            if (i % 2 == 1) {
                ans += 9 * (int)Math.Pow(10, i - 1);
            }
        }
        //最後に、奇数桁ならば端数分を足す
        if (digit % 2 == 1) {
            ans += N + 1 - (int)Math.Pow(10, digit - 1);
        }

        //出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
vector <int> edges[100000];
int d[100000];
int main(){
  int N;
  int M;
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int a;
    int b;
    cin >> a >> b;
    edges[a - 1].push_back(b - 1);
    edges[b - 1].push_back(a - 1);
  }

  for(int i = 0; i < N; i++){
    d[i] = INT_MAX;
  }

  queue <int> q;
  q.push(0);
  d[0] = 0;
  while(!q.empty()){
    int cur = q.front();
    q.pop();
    for(int i = 0; i < edges[cur].size(); i++){
      int next = edges[cur][i];
      if(d[next] == INT_MAX){
        d[next] = d[cur] + 1;
        q.push(next);
      }
    }
  }

  cout << "Yes" << endl;
  for(int i = 1; i < N; i++){
    for(int j = 0; j < edges[i].size(); j++){
      int tmp = edges[i][j];
      if(d[i] - 1 == d[tmp]){
        cout << tmp + 1 << endl;
        break;
      }
    }
  }
  return 0;
}


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

int main(){
    int n; cin>>n;
    double p[n];
    for(int i=1;i<=n;i++) cin>>p[i];
    double dp[n+1][n+1];
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
        }
    }
    double ans=0.0;
    for(int j=n/2+1;j<=n;j++){
        ans += dp[n][j];
    }

    cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 49860
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	int x, n;
	cin >> x >> n;

	int p[105];
	int q[105];

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

	for (int i = 0; i <=101; i++) {
		q[i] = 0;
	}

	for (int i = 0; i < n; i++) {
		q[p[i]] = 1;
	}

	int a = 1000;
	int b =-1;

	for (int i = 0; i <= 101; i++) {
		if (q[i]==0) {
			if (abs(x-i)<a) {
				a = abs(x - i);
				b = i;
			}
		}
	}

	cout << b;
	return 0;
}

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

using namespace std;

void lower(string &s)
{
	size_t size = s.size();
	for (int i = 0; i < size; i++)
		if (s[i] >= 0x41 && s[i] <= 0x5a)
			s[i] += 0x20;
}

void cup(string w, char *q, int *cnt)
{
	if (w.size() == strlen(q) && strncmp(w.c_str(), q, w.size()) == 0)
		(*cnt)++;
}

int main()
{
	string w, t;
	getline(cin, w);
	char *T = " \t\n";
	
	while (1) 
	{
		string buf;
		getline(cin, buf);
		t += (buf + "\n");
		if (buf == "END_OF_TEXT")
			break;
	}
	
	lower(w);
	lower(t);
	
	int c = 0;
	char *q = strtok((char *)t.c_str(), T);
	if (q == NULL)
		return -1;
	cup(w, q, &c);
	
	while ((q = strtok(NULL, T)) != NULL)
	{
		cup(w, q, &c);
	}
	
	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 1204
import itertools
N, M, Q = map(int, input().split(" "))
abcd = []
for i in range(Q):
    abcd.append(list(map(int, input().split(" "))))
A = list(itertools.combinations_with_replacement(range(1, M + 1), N))
ans = 0            
for a in A:
    score = 0
    for i in abcd:
        if a[i[1] - 1] == a[i[0] - 1] + i[2]:
            score += i[3]
    ans = max(ans, score)
print(ans)


Measured memory_bytes: 21612
/* ITP1_7_D: Matrix Multiplication */

#include <iostream>

void read_matrix(long long int **matrix, int n_row, int n_col) {
    for (int row = 0; row < n_row; row++) {
        matrix[row] = new long long int[n_col];
        for (int col = 0; col < n_col; col++) {
            std::cin >> matrix[row][col];
        }
    }
}

void write_matrix(long long int **matrix, int n_row, int n_col) {
    for (int row = 0; row < n_row; row++) {
        std::cout << matrix[row][0];
        for (int col = 1; col < n_col; col++) {
            std::cout << " " << matrix[row][col];
        }
        std::cout << "\n";
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n_a_row, n_a_col, n_b_col;
    std::cin >> n_a_row >> n_a_col >> n_b_col;

    long long int **A = new long long int*[n_a_row];
    long long int **B = new long long int*[n_a_col];
    long long int **C = new long long int*[n_a_row];

    read_matrix(A, n_a_row, n_a_col);
    read_matrix(B, n_a_col, n_b_col);
    for (int row = 0; row < n_a_row; row++)
        C[row] = new long long int[n_b_col];

    // Multiply two matrixes.
    for (int b_col = 0; b_col < n_b_col; b_col++) {
        for (int a_row = 0; a_row < n_a_row; a_row++) {
            long long int v = 0;
            for (int a_col = 0; a_col < n_a_col; a_col++) {
                v += A[a_row][a_col] * B[a_col][b_col];
            }
            C[a_row][b_col] = v;
        }
    }

    write_matrix(C, n_a_row, n_b_col);

    return 0;
}

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

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

#define ll long long
const int mod = 1e9 + 7;
const int nax = 1e5 + 5;
int n, m, k, q;

int main()
{
	fast();
	int a, b;
	cin >> k >> a >> b;
	int l = a/k, r = b/k;
	if(l == r){
		if(a % k == 0 || b % k == 0){
			cout <<"OK";
		}
		else
			cout << "NG";
	}
	else cout <<"OK";
}



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

int main(int argc, char const *argv[])
{
    string S;
    int N;
    cin >> S;
    cin >> N;
    int Q, F;
    char C;
    bool rev = false;
    bool t;
    deque<char> d;
    for (int i = 0; i < S.size(); i++)
    {
        d.push_back(S[i]);
    }
    for (int i = 0; i < N; i++)
    {
        cin >> Q;
        if (Q == 2)
        {
            cin >> F >> C;
            t = (F == 1) && rev || !(F == 1) && !rev;
            if (t)
            {
                d.push_back(C);
            }
            else
            {
                d.push_front(C);
            }
        }
        else
        {
            rev = !rev;
        }
    }
    if (rev)
    {
        reverse(d.begin(), d.end());
    }
    for (int i = 0; i < d.size(); i++)
    {
        cout << d[i];
    }
    cout << endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int idx = s.length() - 1;
    bool flg = false;
    while(1) {
        if ( idx < 4 ) break;
        if ( idx - 6 >= 0 && s.substr(idx - 6, 7) == "dreamer" ) {
            flg = true;
            idx -= 7;
        }
        else if ( idx - 5 >= 0 && s.substr(idx - 5, 6) == "eraser" ) {
            flg = true;
            idx -= 6;
        }
        else if ( idx - 4 >= 0 && s.substr(idx - 4, 5) == "dream" ) {
            flg = true;
            idx -= 5;
        }
        else if ( idx - 4 >= 0 && s.substr(idx - 4, 5) == "erase" ) {
            flg = true;
            idx -= 5;
        }
        else {
            cout << "NO" << endl;
            return 0;
        }
    }
    if ( flg && idx == -1) cout << "YES" << endl;
    else                   cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int digitNum = 0;
    while(n>0){
        int tmp = n%k;
        n-=tmp;
        n/=k;
        digitNum++;
    }
    cout << digitNum << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
inf = 10 ** 8 + 1
dp = [inf] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[n - 1])

Measured memory_bytes: 13900
#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use grapth::*;
use input_scanner::*;
use math::*;
use string_algorithm::*;
use util::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i64> = scan.next_vec(n);
    let mut h: HashMap<i64, i64> = HashMap::new();

    let mut sum = 0;
    for x in a {
        let e = h.entry(x).or_insert(0);
        *e += 1;
        sum += x;
    }
    let q: usize = scan.next();
    for _ in 0..q {
        let b: i64 = scan.next();
        let c: i64 = scan.next();
        let mut cnt = 0;
        if let Some(v) = h.get_mut(&b) {
            cnt = *v;
            *v = 0;
        }
        sum -= b * cnt;
        *h.entry(c).or_insert(0) += cnt;
        sum += c * cnt;

        println!("{}", sum);
    }
}

mod datastructure {}
mod grapth {}
mod math {}
mod string_algorithm {}
mod util {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }

    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str =
                unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }
}


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

int main() {
  int cities, roads;
  cin >> cities >> roads;
  vector<int> answers(cities);
  for(int i =0; i < roads; i++) {
   int a,b;
    cin >> a >> b;
    answers.at(a-1)++;
    answers.at(b-1)++;
  }
  for(int i = 0; i < cities; i++) {
    cout << answers.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;

ll N,ans;
multiset<ll> st;

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

	cin >> N;
	
	//st.insert(ll(1e9+1));

	FOR(i, 0, N) {

		ll A;
		cin >> A;

		auto ite = st.lower_bound(A);

		if (st.begin()!=ite) {//すべてAより大きかったら

			ite--;
			st.erase(ite);

		}

		st.insert(A);
			

		
	}
	cout << st.size() << endl;
	//cout << ans << endl;



}

Measured memory_bytes: 8312
import heapq, copy
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = -10 ** 10
for a in range(min(n, k) + 1):
    have = []
    for i in range(a):
        have.append(v[i])

    o_have = copy.deepcopy(have)

    for b in range(min(n, k) - a + 1):
        for i in range(b):
            have.append(v[n-i-1])

        heapq.heapify(have)
        # print(1, have)
        for c in range(k - a - b):
            if len(have) <= 0:
                break
            item = heapq.heappop(have)
            # print(c, item, have)
            if item >= 0:
                have.append(item)
                break
        ans = max(ans, sum(have))
        # print(2, have, ans, a, b)
        have = copy.deepcopy(o_have)

print(ans)


Measured memory_bytes: 76632
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
    int w;
    cin >> w;
    for (int i = 0; i < pow(3, 15); i++) {
        ll x = i;
        ll now = 0;
        ll t = 1;
        for (int j = 0; j < 15; j++) {
            if (x % 3 == 0)now += t;
            else if (x % 3 == 1) now -= t;
            x /= 3;
            t *= 3;
        }

        if (now == w) {
            string ret;
            x = i;
            t = 1;
            for (int j = 0; j < 15; j++) {
                if (x % 3 == 0)ret = '+' + ret;
                else if (x % 3 == 1)ret = '-' + ret;
                else ret = '0' + ret;
                x /= 3;
                t *= 3;
            }

            bool notzero = false;
            for (int j = 0; j < 15; j++) {
                if (ret[j] != '0')notzero = true;
                if (notzero)cout << ret[j];
            }
            cout << endl;
            break;
        }
    }
    return 0;
}


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

#define mod 1000000000
int n,a[200005],b[200005],t[20][20];
double x;
long long ans=0;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lf",&x);
		long long tmp=x*mod+0.5;
		while(tmp%2==0)tmp/=2,a[i]++;
		while(tmp%5==0)tmp/=5,b[i]++;
		if(a[i]>18)a[i]=18;
		if(b[i]>18)b[i]=18;
		for(int j=18-a[i];j<=18;j++){
			for(int k=18-b[i];k<=18;k++){
				ans+=t[j][k];
			}
		}
		t[a[i]][b[i]]++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 5344
#include <iostream>

int64_t solve(int64_t N, int64_t M)
{
	if (abs(N - M) >= 2) return 0;

	int64_t R = 1;

	for (int64_t i = 0; i < N; ++i)
	{
		R *= (i + 1);
		R %= 1000000007;
	}

	for (int64_t i = 0; i < M; ++i)
	{
		R *= (i + 1);
		R %= 1000000007;
	}
	
	if (N == M)
	{
		R *= 2;
		R %= 1000000007;
	}

	return R;
}

int main()
{
	int64_t N, M;
	std::cin >> N >> M;
	std::cout << solve(N, M) << std::endl;

	return 0;
}


Measured memory_bytes: 256
import bisect

s = input()
t = input()

if set(list(t)).issubset(set(list(s))):
    index_list = [ [] for i in range(26) ]
    for i, v in enumerate(s,1):
        index_list[ord(v)-97].append(i)
    ls = len(s)
    for i in range(26):
        index_list[i].append(ls+1)

    old_index = 0
    index = 0
    turn = 0 
    for i, v in enumerate(t):

        new_index = bisect.bisect_left(index_list[ord(v)-97],index+1)
        index = index_list[ord(v)-97][new_index]

        

        if index == ls+1:
            new_index = bisect.bisect_left(index_list[ord(v)-97],0)
            index = index_list[ord(v)-97][new_index]
            turn += 1


    print(index+turn*ls)

else:
    print(-1)

Measured memory_bytes: 56240
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

class Node {
public:
  std::vector<int> neighbor;
};

std::vector<int> bfs(std::vector<Node>& graph, const int& n, int s) {
  std::vector<int> dist(n+1, -1);
  dist[s] = 0;
  std::queue<int> visit;
  visit.push(s);
  while (!visit.empty()) {
    int u = visit.front(); visit.pop();
    for (int node : graph[u].neighbor) {
      if (dist[node] == -1) {
        dist[node] = dist[u] + 1;
        visit.push(node);
      }
    }
  }
  return dist;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<Node> graph(n + 1);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    std::cin >> a >> b;
    graph[a].neighbor.push_back(b);
    graph[b].neighbor.push_back(a);
  }
  std::vector<int> d_f = bfs(graph, n, 1);
  std::vector<int> d_s = bfs(graph, n, n);
  int f = 0, s = 0;
  for (int i = 1; i <= n; ++i) {
    if (d_f[i] <= d_s[i])
      f++;
    else
      s++;
  }
  if (f > s)
    printf("Fennec\n");
  else if (s >= 1)
    printf("Snuke\n");
}


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

using namespace std;


int main()
{
    long long int a,b,n,t=0,tb;
    cin>>n>>a>>b;
    t=n/(a+b);
    tb=t*a;
    long long int rem=n%(a+b);
    if(rem>=a)tb+=a;
    else tb+=rem;
    cout<<tb<<endl;


    return 0;
}


Measured memory_bytes: 256