akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 100005
#define NIL -1
struct Node {
    int p;
    int left;
    int right;
};

struct Node Tree[MAX];
int N,D[MAX];

void findDepth(int,int);

int main(){
    int i,j;
    int d,v,c;
    int left,right,value;
    scanf("%d", &N);
    for (i = 0; i < N; i ++) Tree[i].p = Tree[i].right = Tree[i].left = NIL;

    for (i = 0 ; i < N ; i ++) {
        scanf("%d %d",&v, &d);
        for ( j = 0; j < d; j++ ) {
            scanf("%d", &c);
            if (j == 0 ) Tree[v].left = c;
            else Tree[left].right = c;
            left = c;
            Tree[c].p = v;
        }
    }
    for (i = 0 ; i < N ; i ++ ){
        if (Tree[i].p == NIL ) right = i;
    }
    findDepth(right, 0);
    
    for (value = 0; value < N; value ++) {
        printf("node %d: parent = %d, depth = %d, ", value,Tree[value].p,D[value]);

        if ( Tree[value].p == NIL ) printf("root, ");
        else if (Tree[value].left == NIL ) printf("leaf, ");
        else printf("internal node, ");

        printf("[") ;

        for ( i = 0 , c = Tree[value].left; c != NIL ; c = Tree[c].right, i ++ ) {
            if (i) printf(", ");
            printf("%d",c);
        }
        printf("]\n");
    } 
    return 0;
}

void findDepth(int value,int p) {
    if(value == NIL)return;
    D[value] = p;
    findDepth(Tree[value].right, p);
    findDepth(Tree[value].left, p+1);
}


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

const int INF = 0x3f3f3f3f;
const int MAXN = 112;
const int MAXK = 112345;

int n, k;
int stones[MAXN];
int pd[MAXK][5];

int other_p(int p){
	if(p==1) return 2;
	else return 1;
}

int rec(int rest, int p)
{
	if(rest<=0)
		return other_p(p);

	if(pd[rest][p])
		return pd[rest][p];

	bool can_win = false;
	for(int i=0;i<n;i++)
	{
		if( (rest-stones[i] >= 0) && (rec(rest-stones[i], other_p(p)) == p) )
			can_win = true;
	}

	if(can_win) return pd[rest][p] = p;
	else return pd[rest][p] = other_p(p);
}

int main()
{
	cin >> n >> k;
	for(int i=0;i<n;i++)
		cin >> stones[i];

	int resp = rec(k, 1);
	if(resp == 1)
		cout << "First" << endl;
	else
		cout << "Second" << endl;

	return 0;
}

Measured memory_bytes: 9984
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();

        int x = 0;
        int max = 0;

        for (int i = 0; i<n; i++) {
            switch (s.charAt(i)) {
                case 'I':
                    x++;
                    break;
                case 'D':
                    x--;
                    break;
            }
            max = Math.max(max, x);
        }
        System.out.println(max);
    }

}


Measured memory_bytes: 35488
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define emp emplace

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 3010;
int n;
int a[N];

ll pd[N][N][2];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", a+i);
	for (int s = 1; s <= n; s++)
	{
		for (int i = 1; i + s - 1 <= n; i++)
		{
			int j = i + s - 1;
			pd[i][j][0] = max(pd[i][j-1][1] + a[j], pd[i+1][j][1] + a[i]);
			pd[i][j][1] = min(pd[i][j-1][0] - a[j], pd[i+1][j][0] - a[i]);
		}
	}
	printf("%lld\n", pd[1][n][0]);
	return 0;
}



Measured memory_bytes: 141568
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    vector<int> ants;
    REP(i, 5) {
        int a;
        cin >> a;
        ants.push_back(a);
    }
    int k;
    cin >> k;
    sort(all(ants));
    
    if (ants[4] - ants[0] > k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

// 累積和
struct cumulative_sum {
    using lint = long long int;
    int sz;
    // data[i]:元の数列
    vector<lint> data;
    // cum[i]:[0,i)の和
    vector<lint> sum;
    // 要素数を指定して初期化
    cumulative_sum(const int _sz) : sz(_sz) {
        data.assign(sz, 0);
        sum.assign(sz + 1, 0);
    }
    lint& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        for (int i = 0; i < sz; i++) sum[i + 1] = sum[i] + data[i];
    }
    // [a,b)の和を求める
    lint query(const int a, const int b) {
        return sum[b] - sum[a];
    }
};

int main() {
    int n, t;
    cin >> n >> t;
    t++;
    cumulative_sum cum(t);
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        cum[l]++, cum[r]--;
    }
    cum.build();
    int ans = 0;
    for (int i = 0; i < t + 1; i++) {
        ans = max((lint)ans, cum.query(0, i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t,tut[N];

lli p[N];

// bool cmp<

int main()
{
	fast;
	cin>>n;
	fo(i,1,n)
	cin>>p[i].fi,p[i].se=i;
	p[0].fi=-1;
	sort(p+1,p+n+1);
	int cnt=0;

	fo(i,1,n)
	{
		if(p[i].fi!=p[i-1].fi)
			cnt++;
		ar[p[i].se]=cnt;
	}

	fo(i,2,n)
	{
		if(ar[i]%2)
			sum++;
		i++;
	}
	cout<<sum<<endl;

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 3840
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#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-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

void optimizeIO(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

vector< vector<int> > dp(3003, vector<int>(3003, -1));

int cal(string &a, string &b, int ai, int bi ){
    if( ai == 0 || bi == 0 )
        return dp[ai][bi] = 0;
    int &res = dp[ai][bi];
    if(res != -1 )
        return res;
    if( a[ai-1] == b[bi-1] )
        res = cal(a, b, ai-1, bi-1)+1;
    return res = max( res, max( cal(a, b, ai-1, bi), cal(a, b, ai, bi-1)));
}

int main(){
	optimizeIO();
    string a,b;
    int ai, bi;
    cin >> a;
    cin >> b;
    ai = a.size(), bi = b.size();
    int len = cal(a, b, ai, bi)-1;
    string res(len+1, 'x');
    while( ai > 0 && bi > 0 ){
        if( a[ai-1] == b[bi-1] ){
            res[len--] = a[ai-1];
            ai--, bi--;
        }else if( dp[ai-1][bi] > dp[ai][bi-1] )
            ai--;
        else
            bi--;
    }
    cout << res << endl;


	return 0;
}

Measured memory_bytes: 36224
#include<bits/stdc++.h>
using namespace std;
long long mark[100004],dp[100004];
int main() {
    mark[0]=1;
    for(long long i=1;i<=100002;i++){
        mark[i]=mark[i-1]*3;
        mark[i]=mark[i]%1000000007;
    }
    string p;
    cin>>p;
    vector<long long>s;
    for(long long i=p.size()-1;i>-1;i--){
        s.push_back(p[i]-'0');
    }
    dp[0]=1;
    for(long long i=1;i<=s.size();i++){
        if(s[i-1]==1){
            dp[i]=2*dp[i-1]+mark[i-1];
        }
        else{
            dp[i]=dp[i-1];
        }
        dp[i]=dp[i]%1000000007;
        //cout<<dp[i]<<' '<<i<<' '<<s[i-1]<<endl;
    }
    cout<<dp[s.size()];
}


Measured memory_bytes: 2932
#include<iostream>
#include<vector>
using namespace std;
int N;
int K;
vector<int> a;

void solve(){
        cout << (N+K-3)/(K-1) << endl;
}

int main(){
    int t;
    cin >> N >> K;
    for (int i = 0; i < N; i++){
        cin >> t;
        a.push_back(t);
    }
    solve();
}

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

int main() {
	int n;cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=-1;
	int anst;
	for(int m=-100;m<=100;m++){
		anst=0;
		for(auto x:a){
			anst+=(x-m)*(x-m);
		}
		if(ans>anst)ans=anst;
		if(ans==-1)ans=anst;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct lazysegtree{
	using F=function<T(T,T)>;
	using G=function<T(T,T,int,int)>;
	const F calcfn,lazycalcfn;
	const G updatefn;
	int n;
	T defvalue,lazydefvalue;
	vector<T>dat,lazy;
	lazysegtree(int n_=0,T defvalue_=0,
		const F calcfn_=[](T a,T b){return a+b;},
		const F lazycalcfn_=[](T a,T b){return a+b;},
		const G updatefn_=[](T a,T b,int l,int r){return a+b*(r-l);},
		T lazydefvalue_=0
	):defvalue(defvalue_),lazydefvalue(lazydefvalue_),
		calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
		lazy.assign(2*n-1,lazydefvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
	}
	void eval(int i,int l,int r)
	{
		dat[i]=updatefn(dat[i],lazy[i],l,r);
		if(r-l>1)
		{
			lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]);
			lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]);
		}
		lazy[i]=lazydefvalue;
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			lazy[k]=lazycalcfn(lazy[k],x);
			eval(k,l,r);
		}
		else
		{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			dat[k]=calcfn(dat[2*k+1],dat[2*k+2]);
		}
	}
	T query(int a,int b,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return defvalue;
		else if(a<=l&&r<=b)return dat[k];
		else return calcfn(
			query(a,b,2*k+1,l,(l+r)/2),
			query(a,b,2*k+2,(l+r)/2,r)
		);
	}
};
main()
{
	int N,Q;
	cin>>N>>Q;
	lazysegtree<pair<long,pair<int,int> > >P(
		N,
		make_pair(0,make_pair(0,0)),
		[](pair<long,pair<int,int> >A,pair<long,pair<int,int> >B)
		{
			return make_pair(A.first+B.first+(long)A.second.second*B.second.first,
				make_pair(
					A.second.first+B.second.first,
					A.second.second+B.second.second
				)
			);
		},
		[](pair<long,pair<int,int> >A,pair<long,pair<int,int> >B)
		{
			A.first^=B.first;
			return A;
		},
		[](pair<long,pair<int,int> >A,pair<long,pair<int,int> >B,int l,int r)
		{
			if(B.first==0)return A;
			else
			{
				return make_pair((long)(r-l)*(r-l-1)/2-A.first-(long)A.second.first*(A.second.first-1)/2-(long)A.second.second*(A.second.second-1)/2,
					make_pair(A.second.second,A.second.first)
				);
			}
		},
		make_pair(0,make_pair(0,0))
	);
	vector<pair<long,pair<int,int> > >init(N);
	for(int i=0;i<N;i++)
	{
		int t;cin>>t;
		if(t==0)init[i].second.first++;
		else init[i].second.second++;
	}
	P.copy(init);
	for(int i=0;i<Q;i++)
	{
		int t,l,r;cin>>t>>l>>r;
		l--;
		if(t==1)P.update(l,r,make_pair(1,make_pair(0,0)));
		else cout<<P.query(l,r).first<<endl;
	}
}


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, X;
    cin >> A >> B >> X;
    if(X >= A && X <= A+B){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


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

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int r = 0;
    vector<int> sequences;
    sequences.push_back(1);
    cin >> r;
    for (int i = 2; i <= n; i++) {
      int c;
      cin >> c;
      if (r == c)
        ++sequences[sequences.size()-1];
      else {
        r = c;
        if (i % 2)
          sequences.push_back(1);
        else {
          if (sequences.size() == 1)
            ++sequences[sequences.size()-1];
          else {
            sequences[sequences.size()-2] += sequences[sequences.size()-1] + 1;
            sequences.pop_back();
          }
        }
      }
      /*
      if (i % 2)
        if (r == c)
          ++sequences[sequences.size()-1];
        else {
          sequences.push_back(1);
          r = c;
        }
      else
        if (r == c)
          ++sequences[sequences.size()-1];
        else {
          sequences[sequences.size()-2] += sequences[sequences.size()-1] + 1;
          sequences.pop_back();
          r = c;
        }
      */
    }
    /*
    for (int i = 0; i < n; i++) {
      int c;
      cin >> c;
      if (r == c)
        ++sequences[sequences.size()-1];
      else {
        r = c;
        if (i % 2)
          ++sequences[sequences.size()-1];
        else
          sequences.push_back(1);
      }
    }
    */
    int count = 0;
    for (int i = 0; i < sequences.size(); i++)
      if (r && i % 2 || !r && !(i % 2))
        count += sequences[sequences.size()-i-1];
    cout << count << endl;
  }
}

Measured memory_bytes: 0
# bit全探索ver
s=list(input())
n=len(s)-1

for i in range(2**n):
    equ=s[0]
    for j in range(n):
        if (i>>j)&1:
            equ+='+'+s[j+1]
        else:
            equ+='-'+s[j+1]
    if eval(equ)==7:
        print(equ+'=7')
        exit()

Measured memory_bytes: 3060
# -*- coding:utf-8 -*-
import sys
import numpy as np

def solve():
    H, W = list(map(int, sys.stdin.readline().split()))
    grid = []
    for _ in range(H):
        grid.append(list(input()))
    grid = (np.array(grid) == ".")*1  # ランプが置ける:1, 障害物:0

    #print(grid)

    L = np.zeros((H,W), dtype=int)  # 左方向に照らせるマスの数
    R = np.zeros((H,W), dtype=int)  # 右方向に照らせるマスの数
    U = np.zeros((H,W), dtype=int)  # 上方向に照らせるマスの数
    D = np.zeros((H,W), dtype=int)  # 下方向に照らせるマスの数

    # 左方向に照らせるマスの数のDPを埋める
    for i in range(W):
        if i == 0:
            L[:, i] = grid[:, i]
        else:
            L[:, i] = (L[:, i-1] + 1) * grid[:, i]

    # 右方向に照らせるマスの数のDPを埋める
    for i in range(W-1, -1, -1):
        if i == W-1:
            R[:, i] = grid[:, i]
        else:
            R[:, i] = (R[:, i+1] + 1) * grid[:, i]

    # 上方向に照らせるマスの数のDPを埋める
    for i in range(H):
        if i == 0:
            U[i] = grid[i]
        else:
            U[i] = (U[i-1] + 1) * grid[i]

    # 下の方向に照らせるマスの数のDPを埋める
    for i in range(H-1, -1, -1):
        if i == H-1:
            D[i] = grid[i]
        else:
            D[i] = (D[i+1] + 1) * grid[i]

    # 全方向すべてのDPを埋めた。
    # よって、i行j列目に明かりを設置したとき、全方向に照らせるマスの数を格納した ans_grid は、
    ans_grid = L + R + U + D - 3
    ans = np.max(ans_grid)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 268536
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++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(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a,ll n,ll m=MOD){
    ll p=1;
    for(;n;n>>=1,a=a*a%m)
        if(n&1)
            p=p*a%m;
    return p;
}

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll answer = modpow(2,n);
    ll nca=1,ncb=1;
    ll tmp =n;
    REP(i,a){
        nca=nca*tmp%MOD;
        tmp--;
        nca=nca*modinv(i+1,MOD)%MOD;
    }
    tmp = n;
    REP(i,b){
        ncb=ncb*tmp%MOD;
        tmp--;
        ncb=ncb*modinv(i+1,MOD)%MOD;
    }
    answer -= nca;
    answer -= ncb;
    answer -= 1;
    while(answer < 0)answer+=MOD;
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()
N=int(S)
cnt=0
def rec(l,x,N):
    global cnt
    if  len(l)==x:
        tmp=int("".join(map(str,l)))
        if tmp<=N and len(set(l))==3:
            cnt+=1
    else:
        for n in range(3):
            l.append(3+2*n)
            rec(l,x,N)
            l.pop()

for n in range(3,len(S)+1):
    rec([],n,N)
print(cnt)

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    int a;
    ll ans = 0;
    int memo = 10;
    for(int i=0;i<5;i++){
        cin >> a;
        if(a%10==0) ans+= a;
        else{
            ans += a/10 * 10 + 10;
            if(memo > a%10) memo = a%10;
        }

    }
    cout << ans - (10-memo) << endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
using namespace std;
#define dbg(x) cerr << #x " = " << x <<endl;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int ans = c - (a - b);
	cout << max(0, ans) << endl;
}

Measured memory_bytes: 256
D = list(map(int, input().split()))
s = input()

for x in range(len(s)):
    if s[x:x+1] == "S":
        temp = D[0]
        D[0] = D[4]
        D[4] = D[5]
        D[5] = D[1]
        D[1] = temp
    elif s[x:x+1] == "W":
        temp = D[0]
        D[0] = D[2]
        D[2] = D[5]
        D[5] = D[3]
        D[3] = temp
    elif s[x:x+1] == "E":
        temp = D[0]
        D[0] = D[3]
        D[3] = D[5]
        D[5] = D[2]
        D[2] = temp
    elif s[x:x+1] == "N":
        temp = D[0]
        D[0] = D[1]
        D[1] = D[5]
        D[5] = D[4]
        D[4] = temp
    
print(D[0])


Measured memory_bytes: 5608
n = int(input())
wl = []
for _ in range(n):
    wl.append(input())



word0 = wl[0][-1]

for i in range(1,n):
    if wl[i][0] == word0 and wl[i] not in wl[:i]:
        word0 = wl[i][-1]
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 9188
# 2020/07/23
# AtCoder Beginner Contest 154 - A

# Input
s, t = input().split()
a, b = map(int,input().split())
u = input()

aa = a
ab = b

# Calc
if s == u:
    aa = aa - 1
elif t == u:
    ab = ab - 1

# Output
print(aa, ab)


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

int main(){
    int N; cin>>N;
    ll count=0;
    vector<int> L(N);
    for(ll i=0;i<N;i++) cin>>L[i];
    sort(L.begin(),L.end());
    for(ll i=0;i<N;i++){
        for(ll j=i+1;j<N;j++){
            for(ll k=j+1;k<N;k++){
                if(L[i]!=L[j]&&L[j]!=L[k]){
                    if(L[i]+L[j]>L[k]) count++;
                }
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3632
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <vector>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define VSORT(list) (std::sort((list).begin(), (list).end()))

std::vector<int> list0;
std::vector<int> list1;

int main(int argc, char* argv[]) {
  int N, M;
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    std::cin >> a;
    list0.push_back(a);
  }
  std::cin >> M;
  for (int i = 0; i < M; i++) {
    int a;
    std::cin >> a;
    list1.push_back(a);
  }
  VSORT(list0);
  VSORT(list1);
  int p = 0;
  for (int i = 0; i < M; i++) {
    for (;;) {
      if (p >= N || list0[p] > list1[i]) {
        std::cout << "NO" << std::endl;
        return 0;
      }
      if (list0[p] == list1[i]) {
        p++;
        break;
      }
      p++;
    }
  }
  std::cout << "YES" << std::endl;
  return 0;
}



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

using namespace std;
using ll = long long;

int main() {
  ll N, K;
  cin >> N >> K;
  double ret = 0;
  for (int i = 1; i <= N; ++i) {
    ll a=i;
    double c=1./N;
    while(a<K){
      a*=2;
      c/=2;
    }
    ret += c;
  }
  cout << setprecision(10) << ret << endl;
}


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


/* 最大公約数 Greatest Common Divisor */
long long GCD (long long a, long long b) {
    if ( b == 0 ){
        return a;
    } else {
        return GCD(b,a%b);
    }
}

/* 最小公倍数 Least Common Multiple */
long long LCM (long long a, long long b) {
    long long gcd = GCD(a,b);
    return a/gcd * b;
}

int main() {
    int N;
    cin >> N;
    long long T[100];
    for ( int i = 0; i < N; ++i ) {
        cin >> T[i];
    }
    
    long long ans = T[0];
    for ( int i = 1; i < N; ++i ) {
        ans = LCM (ans,T[i]);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
/* 拡張ダイクストラ */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    REP(i, n) cin >> v[i];

    ll gokei = min(n, k);
    ll ans = 0;

    /* 左からa個、右からb個 */
    REP(a, gokei+1) REP(b, gokei+1-a) {
        ll tmp = 0;
        vector<ll> motsu;
        REP(i, a) {
            motsu.push_back(v[i]);
            tmp += v[i];
        }
        REP(i, b) {
            motsu.push_back(v[n-1-i]);
            tmp += v[n-1-i];
        }

        ll suteru = k - (a + b);
        sort(ALL(motsu));
        REP(i, suteru) {
            if(i == motsu.size()) break;
            if(motsu[i] >= 0) break;
            tmp -= motsu[i];
        }
        ans = max(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    vector<int> x(5,0);
    rep(i,5) cin>>x[i];
    int ans=0;
    rep(i,5)if(x[i]==0) ans=i+1;
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e6+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=1000001;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
//Lordvishnu@almighty
int main()
{
	
	ll int i,j,k,n,m;
	cin>>n;
     ll a[n];
     for(i=0;i<n;i++)
     	cin>>a[i];
    ll  l=a[0];
     m=0;
     for(i=1;i<n;i++)
     {
     	m+=max(0ll,l-a[i]);
     	l=max(l,a[i]);
     }
     cout<<m;
	
	

}
//Lordvishnu@almighty

Measured memory_bytes: 5084
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
string s1, s2;
int main() {
	cin >> s1 >> s2;
	reverse(s2.begin(), s2.end());
	cout << (s1 == s2 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	string a;
	int n = 0;
	cin >> a;
	rep(i, a.size()) {
		if (a[i] == '1')n++;
	}
	cout << n << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ALucky7 solver = new ALucky7();
        solver.solve(1, in, out);
        out.close();
    }

    static class ALucky7 {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int n = s.nextInt();
            String str = n + "";
            if (str.charAt(0) == '7' || str.charAt(1) == '7' || str.charAt(2) == '7') {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 36288
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	long long N, C;
	cin >> N >> C;

	vector<long long> x(N);
	vector<long long> v(N);
	auto prev = 0ll;
	for (auto i = 0; i < N; ++i)
	{
		cin >> x[i] >> v[i];
	}

	vector<long long> left;
	vector<long long> right;
	auto maxL = LLONG_MIN;
	auto sumL = 0ll;
	auto maxR = LLONG_MIN;
	auto sumR = 0ll;
	left.push_back(0);
	right.push_back(0);
	for (auto i = 0; i < N; ++i)
	{
		sumL += v[i];
		maxL = max(maxL, sumL - x[i]);
		left.push_back(maxL);

		sumR += v[N - i - 1];
		maxR = max(maxR, sumR - (C - x[N - i - 1]));
		right.push_back(maxR);
	}

	auto result = 0ll;
	sumL = 0;
	sumR = 0;

	for (auto i = 0; i <= N; ++i)
	{
		auto tempL = 0ll;
		auto tempR = 0ll;
		if (i > 0)
		{
			sumL += v[i - 1];
			tempL = sumL - x[i - 1] * 2;
			sumR += v[N - i];
			tempR = sumR - (C - x[N - i]) * 2;
		}

		result = max(result, tempL + right[N - i]);
		result = max(result, tempR + left[N - i]);
	}

	cout << result << endl;

	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int64_t sum,x;
  sum = 0;
  x = 0;
  
  for(int i = 1; i < N+1; i ++){
    if(i%15 == 0)
      x += i;
    else if(i%3 == 0)
      x += i;
    else if(i%5 == 0)
      x += i;
    else
      sum += i;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int S,a;
  string K;
  cin >> S;
  cin >> K;
  
  a = K.size();
  
  if(a > S){
    K.erase(S);
    cout << K << "..." << endl;
  }else{
    cout << K << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3628
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

# A:product
'''
data = input("")
data = data.split(" ")
a = int(data[0])
b = int(data[1])

if (a*b)%2 == 1: print("Odd")
else: print("Even")
'''

# B:1 21
'''
data = input()
data = int(data.replace(" ",""))
if data%(data**(1/2)) == 0: print("Yes")
else: print("No")
'''

# C:Traveling
'''
n = int(input(""))
data = [0]*n
t = [0]*n
x = [0]*n
y = [0]*n
flag = 0

for i in range(n):
    data[i] = input("")
    t[i] = int(data[i].split(" ")[0])
    x[i] = int(data[i].split(" ")[1])
    y[i] = int(data[i].split(" ")[2])

for i in range(n):
    if i == 0:
        if x[i]+y[i] > t[i] or (x[i]+y[i]-t[i])%2 != 0:
            print("No")
            flag = 1
            break
    else:
        if abs(x[i]-x[i-1])+abs(y[i]-y[i-1]) > t[i] or (x[i]+y[i]-t[i])%2 != 0:
            print("No")
            flag = 1
            break
if flag == 0:print("Yes")
'''

# D:Checker
def check(y,x,k):
    l = max(0,min(m,x))
    r = max(0,min(m,x+k))
    d = max(0,min(m,y))
    u = max(0,min(m,y+k))
    f[d][l] += 1
    f[d][r] -= 1
    f[u][l] -= 1
    f[u][r] += 1
n,k = LI()
m = k*2
f = [[0]*(m+1) for i in range(m+1)]
for i in range(n):
    x,y,c = input().split()
    x = int(x)%m
    y = int(y)%m
    if c == "W":
        y += k
        y %= m
    check(y-m+1,x-m+1,k)
    check(y+1,x-m+1,k)
    check(y-k+1,x-k+1,k)
    check(y+k+1,x-k+1,k)
    check(y-m+1,x+1,k)
    check(y+1,x+1,k)
    check(y-k+1,x+k+1,k)
    check(y+k+1,x+k+1,k)

for y in range(m+1):
    for x in range(m):
        f[y][x+1] += f[y][x]

for y in range(m):
    for x in range(m+1):
        f[y+1][x] += f[y][x]

ans = 0
for i in f:
    ans = max(ans,max(i))
print(ans)


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

int main(){
  string s,t;
  cin >> s >> t;
  int basho=-1;
  bool flag;
  if(s.length()<t.length()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i=0;i<=s.length()-t.length();i++){
    flag=true;
    for(int j=0;j<t.length();j++){
      if(s[i+j]!='?'&&s[i+j]!=t[j]) flag=false;
    }
    if(flag) basho=i;
  }

  if(basho==-1){
    cout << "UNRESTORABLE" << endl;
  }else{
    string ans="";
    for(int i=0;i<basho;i++){
      ans+=((s[i]=='?')?'a':s[i]);
    }
    ans+=t;
    for(int i=basho+t.length();i<s.length();i++){
      ans+=((s[i]=='?')?'a':s[i]);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $h, $n);
$array = explode(' ', trim(fgets(STDIN)));
rsort($array);
for($i = 0; $i < $n; $i++){
    $h -= $array[$i];
}
if($h > 0){
    echo 'No';
}else{
    echo 'Yes';
}

?>

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln << "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// ⊂ニニニニニニニニニニニニニ( ^ω^)ニニニニニニニニニニニニニ⊃

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	string s;
	cin >> s;
	int fx = 0;
	rep(i,s.length()) fx += s[i] - '0';
	int x = stoi(s);
	
	if (x%fx==0) cout << "Yes" ln;
	else cout << "No" ln;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define clr(v, d) memset(v, d, sizeof(v))
#define fi first
#define se second
#define pp push_back
#define pb pop_back
#define pi 3.141592654
#define MOD 1000000007 
#define cons1 1e12
#define cons2 1e6
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, ll> pa;
typedef unsigned long long int ull;
typedef double long dl;
const int N = 1e5+9,oo=-1e9;
ll dp[100][N], n, v[100][100];
ll sol(int i, int k)
{
	if (i == n)  return 0;
	if (dp[i][k] != -1)    return dp[i][k];

	if (k < v[i][0])    return dp[i][k] = sol(i + 1, k);
	else            return dp[i][k] = max(sol(i + 1, k), v[i][1] + sol(i + 1, k - v[i][0]));
}
void solve() {
	int w;
	clr(dp, -1);
	cin >> n >> w;
	rep(i, 0, n)
		cin >> v[i][0] >> v[i][1];
	cout << sol(0, w) << endl;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	//cin >> t;
	while (t--)
		solve();

#ifndef ONLINE_JUDGE
	- system("pause");
#endif

}

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

using namespace std;

int main(){
  int x, n;
  set<int> s;
  cin >> x >> n;
  for(int i=0;i<n;i++){
    int p;
    cin >> p;
    s.insert(p);
  }
  for(int i=0;;i++){
    if(s.find(x-i)==s.end()){
      cout << x-i << endl;
      return 0;
    }
    if(s.find(x+i)==s.end()){
      cout << x+i << endl;
      return 0;
     }
  }
}



Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
A, B, C = map(int, input().split())
K = int(input())

counter = 0
for i in range(K):
    if A >= B:
        B *= 2
        counter += 1

for i in range(K):
    if B >= C:
        C *= 2
        counter += 1

if A < B and B < C and counter <= K:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
CB=[]
for _ in range(m):
    b, c = map(int, input().split())
    CB.append((c, b))
CB.sort(reverse=True)
 
for c, b in CB:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] >= c:
            break
        heapq.heappushpop(a, c)
 
print(sum(a))

Measured memory_bytes: 20984
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    //出力
    System.out.println((a + b) * h / 2);
  }
}

Measured memory_bytes: 22612
x = int(input())
flag = 0

def judge(x):
    count = 0
    for i in range(1,x+1):
        if x%i == 0:
            count +=1

    return count

while (1):
    if judge(x) == 2:
        print(x)
        break
    else:
        x = x+1


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
ll n;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n;
	ll ans=1e18;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ans=min(ans,n/i+i-2);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final long t = scanner.nextInt();

        final List<Long> list = IntStream.range(0, n)
                .mapToObj(i -> scanner.nextLong())
                .collect(Collectors.toList());

        long counter = 0;
        long previous = list.get(0);
        for (int i = 1; i < list.size(); i++) {
            final Long current = list.get(i);
            counter += Math.min(current - previous, t);
            previous = current;
        }
        System.out.println(counter + t);
    }
}


Measured memory_bytes: 69880
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int mod = 1e9+7;

// mod_power.cc
ll po(ll k, ll x) {
  if (x == 0) {
    return 1;
  }
  if (x == 1) {
    return k % mod;
  }
  ll y = po(k, x/2);
  y = y * y % mod;
  if (x % 2 == 1) {
    y = y * k % mod;
  }
  return y;
}

ll combination(ll n, ll k) {
  k = min(k, n-k);
  if (k == 0) {
    return 1;
  }
  ll ret = 1;
  FOR (i, n-k+1, n+1) {
    ret = ret * i % mod;
  }
  ll denomi = 1; // denominator
  FOR (i, 1, k+1) {
    denomi = denomi * i % mod;
  }
  ret = ret * po(denomi, mod-2) % mod; // inverse
  return ret;
}

int main() {
  string s;
  cin >> s;
  int l = s.length();
  vi accum_a(l+1, 0);
  vi accum_b(l+1, 0);
  vi accum_c(l+1, 0);
  vi accum_q(l+1, 0);
  rep (i, l) {
    accum_a[i+1] = accum_a[i];
    accum_b[i+1] = accum_b[i];
    accum_c[i+1] = accum_c[i];
    accum_q[i+1] = accum_q[i];
    if (s[i] == 'A') {
      accum_a[i+1] += 1;
    } else if (s[i] == 'B') {
      accum_b[i+1] += 1;
    } else if (s[i] == 'C') {
      accum_c[i+1] += 1;
    } else {
      accum_q[i+1] += 1;
    }
  }

  ll ans = 0;
  FOR (i, 1, l-1) {
    if (s[i] == 'A' || s[i] == 'C') {
      continue;
    }
    int cnt_a = accum_a[i];
    int cnt_c = accum_c[l] - accum_c[i+1];
    int cnt_q0 = accum_q[i];
    int cnt_q1 = accum_q[l] - accum_q[i+1];

    ll pattern_left_d3 = po(3, cnt_q0-1);
    ll pattern_left = po(3, cnt_q0);
    ll pattern_right_d3 = po(3, cnt_q1-1);
    ll pattern_right = po(3, cnt_q1);
    ll all_a = pattern_left * cnt_a % mod;
    all_a = (all_a + pattern_left_d3 * cnt_q0 % mod) % mod;
    ll all_c = pattern_right * cnt_c % mod;
    all_c = (all_c + pattern_right_d3 * cnt_q1 % mod) % mod;
    ans = (ans + all_a * all_c % mod) % mod;
    debug(ans);
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int a,b,c,d;
	int ans=0;
	cin >>a>>b>>c>>d;
	int ans1=(c+b-1)/b;
	int ans2=((a+d-1)/d);
	cout<<solve(ans1 <=ans2)<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			long N = sc.nextLong();
			if (N == 0) break;
			int ans = 0;
			for (long i = 0; i < N / 4; ++i) {
				ans += sc.nextInt();
			}
			System.out.println(ans);
		}
	}
}

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

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double kaku1 = (60 * h + m) / 60 * 2 * M_PI;
    double kaku2 = (60 * h + m) / 720 * 2 * M_PI;
    cout << fixed << setprecision(10)
         << sqrt(a * a + b * b - 2 * a * b * cos(kaku1 - kaku2)) << endl;
    ;
    return 0;
}

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

int main()
{
    double a, b, c;
    int e, f;
    cin>>e>>f;
    a=e/.08;
    b=f/.1;
    if(a>b)
    {
        if(a*(.1)>=f && a*(.1)<f+1)
        {
            c=round(a);
            if (c<a) c=c+1;
            cout<<c<<endl;
        }
        else cout<<"-1"<<endl;
    }
    else if(a<b)
    {
        if(b*(.08)>=e && b*(.08)<e+1)
        {
            c=round(b);
            if (c<b) c=c+1;
            cout<<c<<endl;
        }
        else cout<<"-1"<<endl;
    }
    else
    {
        c=round(b);
        if (c<b) c=c+1;
        cout<<c<<endl;
    }

    return 0;
}



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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619

vector<int>to[200005];
mint ans; 
int N;
int dfs(int v, int p = -1) {
	int res = 1;
	vector<int>ts;
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		int t = dfs(e, v);
		res += t;
		ts.push_back(t);
	}
	if (-1 != p) {
		ts.push_back(N - res);
	}
	mint now = mint(2).pow(N - 1) - 1;
	for (int t:ts) {
		now -= mint(2).pow(t) - 1;
	}
	ans += now;
	return res;
}

int main() {
	cin >> N;
	for (int n = 0; n < N - 1; ++n) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	dfs(0);
	ans /= mint(2).pow(N);
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 32404