akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	int n=s.length();
	LL cnt[201020]={};
	LL ans=0;
	FOR(i,0,n){
		if(s[i]=='B'){
			cnt[i]++;
			if(i!=0){
				cnt[i]+=cnt[i-1];
			}
		}else{
			if(i!=0)cnt[i]+=cnt[i-1];
			ans+=cnt[i];
		}
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2180
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

int main() {
    ll N, Q;
    cin >> N >> Q;
    vector<vector<ll>> tree(N);
    for (ll i = 0; i < N-1; i++) {
        ll ai, bi;
        cin >> ai >> bi;
        ai--;
        bi--;
        tree[ai].push_back(bi);
        tree[bi].push_back(ai);
    }
    vector<ll> counter(N, 0);
    for (ll i = 0; i < Q; i++) {
        ll pi, xi;
        cin >> pi >> xi;
        pi--;
        counter[pi] += xi;
    }
    vector<ll> ans(N, -1);
    struct DFSInfo {
        ll idx;
        ll sum;
    };
    vector<DFSInfo> stack;
    stack.push_back(DFSInfo{0, counter[0]});
    while (!stack.empty()) {
        DFSInfo info = stack.back();
        stack.pop_back();
        ans[info.idx] = info.sum;
        for (ll next : tree[info.idx]) {
            if (ans[next] >= 0) {
                continue;
            }
            stack.push_back(DFSInfo{next, info.sum + counter[next]});
        }
    }
    for (ll i = 0; i < N; i++) {
        cout << ans[i];
        if (i < N - 1) {
            cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 22000
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


// 最小全域有向木 O(EV)
// 0-index
// 例外判定のために Edge[0] => {-1,-1,-1} が必須なため　辺のindexは 1-index
const int MAXV = 10010;
const int MAXE = 10010;
const int MAXW = 2147483647;
struct Edge {
    int u, v, c;
    Edge(int x = -1, int y = 0, int z = 0) : u(x), v(y), c(z) {}
};
int V, E, root;
Edge edges[MAXE];
inline void addEdge(int u, int v, int c){ edges[++E] = Edge(u, v, c);}
bool con[MAXV];
int mnInW[MAXV], prv[MAXV], cyc[MAXV], vis[MAXV];
inline int DMST() {
    fill(con, con + V, 0);
    int r1 = 0, r2 = 0;
    while (true) {
        fill(mnInW, mnInW + V, MAXW);
        fill(prv, prv + V, -1);
        for (int i = 1; i <= E; i++) {
            int u = edges[i].u, v = edges[i].v, c = edges[i].c;
            if (u != v && v != root && c < mnInW[v]){mnInW[v] = c; prv[v] = u;}
        }
        fill(vis, vis + V, -1);
        fill(cyc, cyc + V, -1);
        r1 = 0;
        bool jf = false;
        for (int i = 0; i < V; i++) {
            if (con[i]) continue;
            if (prv[i] == -1 && i != root) {
                return -1;
            }
            if (prv[i] >= 0) r1 += mnInW[i];
            int s;
            for (s = i; s != -1 && vis[s] == -1; s = prv[s]) vis[s] = i;
            if (s >= 0 && vis[s] == i) {
                // get a cycle
                jf = true; int v = s;
                do { cyc[v] = s; con[v] = true; r2 += mnInW[v]; v = prv[v];
                } while (v != s);
                con[s] = false;
            }
        }
        if (!jf) break;
        for (int i = 1; i <= E; i++) {
            int &u = edges[i].u;
            int &v = edges[i].v;
            if (cyc[v] >= 0) edges[i].c -= mnInW[edges[i].v];
            if (cyc[u] >= 0) edges[i].u = cyc[edges[i].u];
            if (cyc[v] >= 0) edges[i].v = cyc[edges[i].v];
            if (u == v){ edges[i--] = edges[E--]; }
        }
    }
    return r1 + r2;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int e;
    cin >> V >> e >> root;
    for(int i = 0; i < e;i++) {
        int a, b, c;
        cin >> a >> b >> c;
        addEdge(a, b, c);
    }
    cout << DMST() << endl;
    
    return 0;
}



Measured memory_bytes: 3348
#include<iostream>

int main(){
int r,c;
 std::cin >> r >> c;
 char a[r][c];
 for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
        std::cin >> a[i][j];
    }
 }
 char count;
 for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
        count='0';
        if(a[i][j]=='#') continue;

        if(a[i+1][j]=='#' && i+1>=0 && i+1<=r-1) count++;
        if(a[i-1][j]=='#' && i-1>=0 && i-1<=r-1) count++;

        if(a[i][j+1]=='#' && j+1>=0 && j+1<=c-1) count++;
        if(a[i][j-1]=='#' && j-1>=0 && j-1<=c-1) count++;

        if(a[i-1][j+1]=='#' && (j+1>=0 && j+1<=c-1) && (i-1>=0 && i-1<=r-1)) count++;
        if(a[i+1][j-1]=='#' && (j-1>=0 && j-1<=c-1) && (i+1>=0 && i+1<=r-1)) count++;

        if(a[i-1][j-1]=='#' && (j-1>=0 && j-1<=c-1) && (i-1>=0 && i-1<=r-1)) count++;
        if(a[i+1][j+1]=='#' && (j+1>=0 && j+1<=c-1) && (i+1>=0 && i+1<=r-1)) count++;

        a[i][j]=count;
    }
 }

 for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
        std::cout <<a[i][j];
    }
    std::cout << "\n";
 }
 return 0;
}


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

vector<int> nei[200005];
int n;
int lt3[200005];// <3 (less than 3)
int sz[200005],mx[200005];
long long ans=0;

void precalc(int now,int lst){
	if(lt3[now]){
		sz[now]++;
	}
	for(int i=0;i<nei[now].size();i++){
		if(nei[now][i]!=lst){
			precalc(nei[now][i],now);
			sz[now]+=sz[nei[now][i]];
			mx[now]=max(mx[now],mx[nei[now][i]]+1);
		}
	}
}

void dfs(int now,int lst,int mxx){
	int mx1=mxx,mx2=0;
	if(lt3[now]){
		for(int i=0;i<nei[now].size();i++){
			if(nei[now][i]!=lst){
				mx2=max(mx2,mx[nei[now][i]]+1);
				if(mx1<mx2){
					swap(mx1,mx2);
				}
			}
		}
		ans+=min(mx1-1,mx2+1)+1;
	}else{
		int l=1e9;
		if(sz[1]!=sz[now]){
			l=mxx;
		}
		for(int i=0;i<nei[now].size();i++){
			if(nei[now][i]!=lst){
				mx2=max(mx2,mx[nei[now][i]]+1);
				if(mx1<mx2){
					swap(mx1,mx2);
				}
				if(sz[nei[now][i]]){
					l=min(l,mx[nei[now][i]]+1);
				}
			}
		}
		ans+=max(0,min(mx1-1,mx2+1)-l+1);
	}
	for(int i=0;i<nei[now].size();i++){
		if(nei[now][i]!=lst){
			dfs(nei[now][i],now,mx[nei[now][i]]==mx1-1?mx2+1:mx1+1);
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	for(int i=1;i<=n;i++){
		scanf("%1d",lt3+i);
	}
	precalc(1,0);
	dfs(1,0,0);
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 25472
#include <bits/stdc++.h>
using namespace std;
long int N,sum=0;

int main(){
    cin >> N;
    for(long int i=1;i<N+1;i++) {
        if((i%3 != 0) & (i%5 != 0)){
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main()
{
	int n = 0, m = 0, a[100][100] = { 0 }, b[100] = { 0 };

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}
	
	for (int i = 0; i < m; i++)
		cin >> b[i];

	for (int i = 0; i < n; i++) {
		int k = 0;
		for (int j = 0; j < m; j++)
			k += a[i][j] * b[j];
		cout << k << endl;
	}

    return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

vector<vector<int>> A;
vector<int> color;
int num = 1;

void dfs(int u) {
    stack<int> S;
    S.push(u);
    color[u] = num;
    while (!S.empty()) {
        int now = S.top(); S.pop();
        rep(i, A[now].size()) {
            int next = A[now][i];
            if (color[next] == -1) {
                color[next] = num;
                S.push(next);
            }
        }
    }
    num += 1;
}

int main() {
    int n, m;
    cin >> n >> m;
    A = vector<vector<int>>(n);
    color = vector<int>(n, -1);
    rep(i, m) {
        int s, t;
        cin >> s >> t;
        A[s].push_back(t);
        A[t].push_back(s);
    }
    rep(i, n) {
        if (color[i] == -1) dfs(i);
    }
    int q;
    cin >> q;
    rep(i, q) {
        int s, t;
        cin >> s >> t;
        if (color[s] == color[t]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}


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

int main() {
	int n,p;
	long long stat[52][2];
	memset(stat,0,sizeof(stat));
	stat[0][0]=1;
	cin>>n>>p;
	for (int i=1;i<=n;i++) {
		int tt; cin>>tt;
		if (tt%2 == 1) {
			stat[i][0] = stat[i-1][0] + stat[i-1][1];
			stat[i][1] = stat[i-1][1] + stat[i-1][0];
		}else {
			stat[i][1] = stat[i-1][1]*2;
			stat[i][0] = stat[i-1][0]*2;
		}
	}
	cout<<stat[n][p]<<endl;
	return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,D;
    cin >> n >> D;
    int k = 2 * D + 1;
    int res = n / k;
    if (n % k > 0) ++ res;
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=500050;
int pre[maxn];
int n,m;
int find(int x){
	return x==pre[x]?x:pre[x]=find(pre[x]);
}
void join(int x,int y){
	x=find(x);y=find(y);
	if(x==y)	return;
	pre[x]=y;
}
void solve(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)	pre[i]=i;
	for(int i=1;i<=m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		join(a,b);
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(pre[i]==i)	sum++;
	}
	printf("%d\n",sum-1);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 2112
#include<stdio.h>
int main()
{	int N,a,s=0;
	scanf("%d",&a);
	N=a;
	while(N)
	{	s=s*10+N%10;
		N=N/10;
	}
	if(a==s)
		printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007LL





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

    ll n,temp = 0;
    cin>>n;

    for (ll i = 1; i <= n-1; i++)
    {
        if (n%i==0)
        {
            temp = temp +n/i -1;
        }
        else
        {
            temp = temp + n / i;
        }
        
    }
    cout<<temp<<endl;
}

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

int kurai (int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int main() {
    int N;
    cin >> N;
    bool harshad = false;
    int hoge = N % kurai(N);

    if (hoge == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using ll = long long;
using matrix = vector<vector<ll>>;

constexpr ll M = 1e9 + 7;

matrix mul(matrix a, matrix b) {
    matrix res(a.size(), vector<ll>(b[0].size()));
    for(int i = 0; i < (int)a.size(); ++i) {
        for(int k = 0; k < (int)b.size(); ++k) {
            for(int j = 0; j < (int)b[0].size(); ++j) {
                (res[i][j] += a[i][k] * b[k][j]) %= M;
            }
        }
    }
    return res;
}

matrix modpow(matrix x, ll n) {
    matrix res(x.size(), vector<ll>(x.size()));
    for(int i = 0; i < (int)x.size(); ++i) {
        res[i][i] = 1;
    }
    
    while(n > 0) {
        if(n & 1) {
            res = mul(res, x);
        }
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll fib(int n) {
    matrix A(2, vector<ll>(2));
    A[0][0] = A[0][1] = 1;
    A[1][0] = 1;
    matrix b(2, vector<ll>(1));
    b[0][0] = b[1][0] = 1;
    return mul(modpow(A, n - 1), b)[0][0];
}

int main() {
    ll K;
    cin >> K;

    ll lb = 0, ub = 1e10;
    while(ub - lb > 1) {
        ll m = (lb + ub) / 2;
        if(m * (m + 1) < K) {
            lb = m;
        } else {
            ub = m;
        }
    }
    K -= lb * (lb + 1);
    int x = lb * 2 + (K - 1) / ub + 1;
    if(K > 0) {
        if(K > ub) {
            K -= ub;
        }
    }
    int y = 0;
    if(K <= (ub + 1) / 2) {
        y = 2 * K - 1;
    } else {
        y = ub - (ub & 1) - (K - (ub + 1) / 2 - 1) * 2;
    }

    cout << (fib(y) * fib(x - y + 1) % M) << endl;
}


Measured memory_bytes: 3140
# YouTube解説の方法（deque使わない）
import sys
input = sys.stdin.readline

def bisect_right_reverse(L, target):
    ok = len(L)
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if L[mid] < target:
            ok = mid
        else:
            ng = mid
    return ok

N = int(input())
A = [int(input()) for _ in range(N)]

L = []
for i in range(N):
    k = bisect_right_reverse(L, A[i])
    if k == len(L):
        L.append(A[i])
    else:
        L[k] = A[i]

print(len(L))

Measured memory_bytes: 13564
#include <cstdio>

int P, A[3000], I[3000] = { 0,1 }, R[3000], X[3000], T[3000];

int main()
{
	scanf ("%d", &P);
	for (int i = 0; i < P; i++) scanf ("%d", &A[i]);
	for (int i = 2; i < P; i++) I[i] = (P - P / i) * I[P % i] % P;

	X[0] = 1;
	int K = 0;
	for (int i = 0; i < P; i++){
		for (int j = 0; j <= K; j++){
			T[j + 1] = (T[j + 1] + X[j]) % P;
			T[j] = (T[j] + P - X[j] * i % P) % P;
		}
		K++;
		for (int j = 0; j <= K; j++){
			X[j] = T[j];
			T[j] = 0;
		}
	}

	for (int i = 0; i < P; i++) if (A[i]){
		for (int j = 0; j <= K; j++) T[j] = 0;
		for (int j = K; j >= 1; j--) T[j - 1] = (X[j] + T[j] * i) % P;

		int C = 0;
		for (int j = K - 1; j >= 0; j--){
			C = C * i % P;
			C = (C + T[j]) % P;
		}
		for (int j = K - 1; j >= 0; j--){
			R[j] = (R[j] + I[C] * T[j]) % P;
		}
	}

	for (int j = 0; j < P; j++) printf ("%d ", R[j]); puts("");

	return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 1e+8;

using namespace std;

int main() {
  int m=1e+6;
  vector<int> dp1(2*m, INF), dp2(2*m, INF);
  dp1[0]=dp2[0]=0;
  REP(i,200) {
    int t=i*(i+1)*(i+2)/6;
    if (t>m) break;
    REP(j,m){
      dp1[j+t] = min(dp1[j+t], dp1[j]+1);
      if(t%2) dp2[j+t] = min(dp2[j+t], dp2[j]+1);
    }
  }
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    cout<<dp1[n]<<' '<<dp2[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 16764
N , M = map(int,input().split())
L = []
R = []
cnt = 0
flag = True
for i in range(M):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)
L_max = max(L)
R_min = min(R)
for i in range(N+1):
	flag = True
	if i >= L_max and i <= R_min:
		cnt+=1
print(cnt)

Measured memory_bytes: 10984
def main():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort(reverse = True)

    if all(v[i] == v[0] for i in range(A)):
        ct = 0
        for i in range(N):
            if v[i] == v[0]:
                ct += 1
        cases = [1]
        for i in range(1, ct+1):
            cases.append(cases[-1]*(ct-i+1)//i)
        return v[0], sum(cases[A:(min(ct, B)+1)])
    else:
        i = 0
        tot = 0
        while i < A:
            tot += v[i]
            i += 1
        max_i = i
        ref = v[i-1]
        ct_used = 0
        for j in range(A):
            if v[j] == ref:
                ct_used += 1

        ct = 0
        for j in range(N):
            if v[j] == ref:
                ct += 1
        cases = 1
        for j in range(1, ct_used+1):
            cases = cases * (ct-j+1)//j
        return tot/max_i, cases

if __name__ == '__main__':
    output = main()
    for v in output:
        print(v)

Measured memory_bytes: 3064
package main

import (
  "fmt"
)

func min(x, y int) int {
  if x > y {
    return y
  }
  return x
}

func main(){
  var n,k,x,y int
  fmt.Scan(&n, &k, &x, &y)

  if min(n,k) == n {
    fmt.Println(n * x)
  } else {
    fmt.Println(k * x + (n-k) * y)
  }
}

Measured memory_bytes: 512
a,b,k = (int(x) for x in input().split())

if k >= a :
  if k >= b :
    if a + b >= k :
      a1 = 0
      b1 = b - k + a
    else :
      a1 = 0
      b1 = 0
  else :
    a1 = 0
    b1 = b - k + a
else :
  a1 = a - k
  b1 = b

print(a1,b1)

Measured memory_bytes: 3064
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e15;
#define PI 3.14159265
 
const ll N = 55;
const ll P = 2750;

vector<pair<ll,pll>> adj[N];
ll C[N], D[N];

ll dist[N][P];

void solve(){
    ll n,m,s;
    cin>>n>>m>>s;
    rep(i,0,m){
        ll u,v,a,b;
        cin>>u>>v>>a>>b;
        adj[u].pb({v,{a,b}});
        adj[v].pb({u,{a,b}});
    }
    rep(i,1,n+1)    cin>>C[i]>>D[i];
    s = min(s, P-1);
    using T = pair<ll,pll>;
    priority_queue<T, vector<T>, greater<T> > pq;
    pq.push({0,{1,s}});
    rep(i,1,n+1)    rep(j,0,P)   dist[i][j]=INF;
    dist[1][s] = 0;
    while(!pq.empty()){
        T v = pq.top();
        ll len = v.ft;
        ll u = v.sd.ft;
        ll p = v.sd.sd;
        pq.pop();
        if(len != dist[u][p]){
            continue;
        }
        if(p != (P-1)){
            if(dist[u][p]+D[u]<dist[u][min(P-1, p+C[u])]){
                dist[u][min(P-1, p+C[u])]=dist[u][p]+D[u];
                pq.push({dist[u][min(P-1, p+C[u])], {u, min(P-1, p+C[u])}});
            }
        }
        for(auto i:adj[u]){
            if(i.sd.ft <= p){
                if(dist[u][p]+i.sd.sd < dist[i.ft][p-i.sd.ft]){
                    dist[i.ft][p-i.sd.ft]=dist[u][p]+i.sd.sd;
                    pq.push({dist[i.ft][p-i.sd.ft], {i.ft, p-i.sd.ft}});
                }
            }
        }
    }
    rep(i,2,n+1){
        ll ans=INF;
        rep(j,0,P)  ans=min(ans, dist[i][j]);
        cout<<ans<<endl;
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll no;
    // cin>>no;
    no = 1;
    while(no--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 7424
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math","-fno-stack-protector")
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
#include <assert.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
const int MOD=1e9+7;
#define SZ 666666
int d,c[26],s[999][26],g[999],g_[999];
int f()
{
	int lp[26];
	memset(lp,0,sizeof lp);
	int ans=0;
	for(int i=1;i<=d;++i)
	{
		assert(g[i]>=0&&g[i]<26);
		int u=i-lp[g[i]];
		ans+=s[i][g[i]]-c[g[i]]*u*(u-1)/2;
		lp[g[i]]=i;
	}
	for(int j=0;j<26;++j)
	{
		int u=d-lp[j];
		ans-=c[j]*u*(u+1)/2;
	}
	return ans;
}
int main()
{
	srand(19260818);
	cin>>d;
	for(int i=0;i<26;++i) cin>>c[i];
	for(int i=1;i<=d;++i)
		for(int j=0;j<26;++j) cin>>s[i][j];
	for(int i=1;i<=d;++i) g[i]=rand()%26;
	ll of=f();
	int gc=0;
	while((++gc)%100!=0||clock()<CLOCKS_PER_SEC*1.8)
	{
		for(int i=1;i<=d;++i) g_[i]=g[i];
		int x=1;
		while(rand()%2) ++x;
		const int up=2;
		int c=-1;
		if(rand()&1) c=rand()%up;
		while(x--)
		{
			int p=rand()%d+1;
			int u=(~c)?c:(rand()%up);
			if(u==0)
				g[p]=rand()%26;
			else if(u==1)
			{
				pii mx(-1,0);
				for(int x=0;x<26;++x)
					mx=max(mx,pii(s[p][x],x));
				g[p]=mx.se;
			}
		}
		ll cf=f();
		if(cf<of)
		{
			for(int i=1;i<=d;++i) g[i]=g_[i];
		}
		else
		{
//			if(of!=cf)
//			cerr<<cf<<"\n";
			of=cf;
		}
	}
	for(int i=1;i<=d;++i)
		cout<<g[i]+1<<"\n";
	cerr<<of<<"\n";
}


Measured memory_bytes: 3684
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        String s = scan.next();
        if(a >= 3200){
            System.out.println(s);
        }else{
            System.out.println("red");
        }
    }
}

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

using namespace std;

const int INF = 1e9;
int n , m ;
int a[81][81] ;
int f[81][81][80*80*2+1];
int dp(int i , int j , int sum)
{
    if ( i ==n && j == m )
        return  min(sum + a[i][j] ,abs(sum-a[i][j]));
    int &res = f[i][j][sum];
    if ( res != -1)
            return res;
    res = INF ;
    if ( i < n)
        res = min(res,min(dp(i+1,j,sum+a[i][j]),dp(i+1,j,abs(sum-a[i][j]))));
    if ( j < m)
        res=min(res,min(dp(i,j+1,sum+a[i][j]),dp(i,j+1,abs(sum-a[i][j]))));
    return res;
}
int main()
{
    cin >> n >> m ;
    for(int i =1 ; i<= n; i++)
        for(int j = 1; j<= m ; j++)
        cin >> a[i][j];
    for(int i = 1; i<= n; i++)
        for(int j = 1; j<= m ; j++)
         {
             int x;
             cin >> x;
             a[i][j] = abs(a[i][j] - x ) ;
         }
    memset(f,-1,sizeof f);
    cout<<dp(1,1,0);
    return 0;
}


Measured memory_bytes: 331712
#include<stdio.h>

int main(){

int i,i2,Ans=0;

for (i=1;i<10;i++)
{
	for(i2=1;i2<10;i2++)
	{
		Ans=i*i2;
		printf("%dx%d=%d\n",i,i2,Ans);
	}
}
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int ze(int a, int b) {
  return max(a - b, b - a);
}
int main () {
  int N;
  cin >> N;
  vector<int>he(N);
  for (int i = 0; i < N; i ++) cin >> he[i];
  vector<int>dp(N);
  dp[0] = 0;
  dp[1] = ze(he[0], he[1]);
  for (int i = 2; i < N; i ++) {
    int ku = dp[i - 1] + ze(he[i], he[i - 1]);
    int ma = dp[i - 2] + ze(he[i], he[i - 2]);
    dp[i] = min(ku, ma);
  }
  cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
N = gets.to_i
tasks = []
N.times{
	tasks << gets.strip.split(/ /).collect(&:to_i)
}
def check(tasks)
	tasks = tasks.sort_by{|a, b| b}
	t = 0
	tasks.each{|a, b|
		t += a
		if t > b
			return false
		end
	}
	return true
end

if check(tasks)
	puts "Yes"
else
	puts "No"
end


Measured memory_bytes: 28536
#include<bits/stdc++.h>
#define ll long long
#define p 1000000007
using namespace std;
ll quick_mod(ll a, ll b)
{
    ll ans = 1;
    a %= p;
    while(b)
    {
        if(b & 1)
        {
            ans = ans * a % p;
            b--;
        }
        b >>= 1;
        a = a * a % p;
    }
    return ans;
}
 
ll C(ll n, ll m)
{
    if(m > n) return 0;
    ll ans = 1;
    for(int i=1; i<=m; i++)
    {
        ll a = (n + i - m) % p;
        ll b = i % p;
        ans = ans * (a * quick_mod(b, p-2) % p) % p;
    }
    return ans;
}
 
ll Lucas(ll n, ll m)
{
    if(m == 0) return 1;
    return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
int main()
{
    ll x,y,m,n;
    scanf("%lld%lld",&x,&y);
    if(2*x-y<0||2*y-x<0||(2*x-y)%3!=0||(2*y-x)%3!=0)
    {
        printf("0");
        return 0;
    }
    printf("%lld",Lucas((2*x-y)/3+(2*y-x)/3,(2*x-y)/3));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s,t;
	cin>>s>>t;
	ll ans=inf;
	for(ll i=0;i<s.size()-t.size()+1;i++){
		ll cnt=0;
		for(ll j=0;j<t.size();j++){
			if(s[i+j]!=t[j]){
				cnt++;
			}
		}
		ans=min(cnt,ans);
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i=0;i<n;i++){
    cin >> l[i];
  }
  int maxlen = *max_element(l.begin(),l.end());
  int total = accumulate(l.begin(),l.end(),0);
  if (maxlen < total-maxlen)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  map<int,int> ans;
  for(int i=0;i<n;i++)
    {
      int num;
      cin >> num;
      for(int j=1;j<=num/2;j++)
	{
	  if(num%j == 0)
	    ans[j]++;
	}
      ans[num]++;
    }

  for(map<int,int>::iterator it = ans.begin();it != ans.end();it++)
    if((*it).second >= n)
      cout << (*it).first << endl;
    
  return 0;
}

Measured memory_bytes: 1200
n, k = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
prev = 0
count = 0
used = {prev: count}
for _ in range(min(k, n)):
  prev = A[prev]
  count += 1
  if prev in used:
    break
  used[prev] = count
if count > used[prev]:
  for _ in range((k - used[prev]) % (count - used[prev])):
    prev = A[prev]
print(prev + 1)

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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 1; i<n; i++){
    string s1 = s.substr(0, i);
    string s2 = s.substr(i, n-i);
    set<char> memo{};
    rep(j,s1.size()) memo.insert(s1[j]);
    int res = 0;
    rep(j,s2.size()){
      if(memo.count(s2[j])) {
        res++;
        memo.erase(s2[j]);
      }
    }
    ans = max(ans, res);
  }
  cout << ans << endl;  
}

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

class Mondai
{
    static void Main()
    {
        var S = Console.ReadLine();
        var letter = S[0];
        var count = 1;
        for (int i=1;i<S.Length;++i){
            if (letter != S[i])
            {
                count++;
                letter = S[i];
            }
        }
        Console.WriteLine(count-1);
    }
}


Measured memory_bytes: 13116
n = int(input())
cake = 4
donuts = 7
check = 0
for i in range(26):
    for j in range(15):
        ans = cake*i+donuts*j
        if (ans == n) and (check == 0):
            print('Yes')
            check = 1
if check == 0:
    print('No')

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

#define MAX 1000000
#define n_MAX 101

int main() {

  while( true ) {

    long long int n, m;
    cin >> m >> n;
    if ( n == 0 ) break;

    long long int c[n_MAX][n_MAX], t[n_MAX][n_MAX];

    for ( int i = 1; i < n_MAX; i++ ) {
      for ( int j = 1; j < n_MAX; j++ ) {
	c[i][j] = MAX;
	t[i][j] = MAX;
      }
      c[i][i] = 0;
      t[i][i] = 0;
    }

    for ( long long int i = 0; i < m; i++ ) {

      long long int a, b;
      cin >> a >> b;
      cin >> c[a][b] >> t[a][b];
      c[b][a] = c[a][b];
      t[b][a] = t[a][b];

    }

    for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= n; j++ ) {
	for ( int k = 1; k <= n; k++ ) {
	  c[j][k] = min( c[j][k], c[j][i] + c[i][k] );
	  t[j][k] = min( t[j][k], t[j][i] + t[i][k] );
	}
      }
    }

    long long int in;
    cin >> in;

    for ( long long int i = 0; i < in; i++ ) {

      long long int p, q, r;
      cin >> p >> q >> r;
      if ( r == 0 ) {
	cout << c[p][q] << endl;
      }else {
	cout << t[p][q] << endl;
      }

    }

  }

  return 0;

}

Measured memory_bytes: 1312
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

template <class Monoid>
class SegmentTree
{
public:
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid M1;
  int sz;
  vector<Monoid> seg;

  SegmentTree(int n,const Func fu, const Monoid &m1): F(fu) , M1(m1) {init(n);}
  void init(int n)
  {
      sz= 1;
      while (sz < n) sz *= 2;
      seg.assign(sz * 2, M1);
  }
  void update(int k,const Monoid &x)
  {
    k+=sz;
    seg[k]=x;
    while(k>>=1)
    {
      seg[k]=F(seg[k*2],seg[k*2+1]);
    }
  }
  Monoid query(int l,int r)
  {
    Monoid L=M1,R=M1;
    l+=sz;r+=sz;
    for(;l<r;l>>=1,r>>=1)
    {
      if(l&1)L=F(L,seg[l++]);
      if(r&1)R=F(seg[--r],R);
    }
    return F(L,R);
  }
  Monoid &operator[](int n){
    return seg[n+sz];
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  ll m;cin>>m;

  SegmentTree<ll>st(n+1,[](ll a,ll b){return a+b;},0);
  vector<vector<ll>>g(n+1);
  rep(i,n)g[0].push_back(n-i);
  n++;
  rep(i,m){
    ll a,b;cin>>a>>b;
    g[a].push_back(b);
  }
  vector<ll>visited(n),ls(n);
  ll id=0,cn=0;
  ll mi=1e9,tcnt=0;
  function<void(ll,ll&,ll&)>dfs=[&](ll v,ll& idx,ll&cnt){
    ls[v]=idx++;
    st.update(ls[v],1);
    visited[v]=1;
    for(auto nv:g[v]){
      cnt++;
      if(ls[nv]!=0&&st[ls[nv]]){
        //cout<<"test"<<nv<<" "<<v<<" "<<ls[nv]<<" "<<ls[v]<<endl;
        if(chmin(mi,st.query(ls[nv],ls[v]+1))){
          tcnt=cnt;
        }
      }
      if(visited[nv])continue;
      dfs(nv,idx,cnt);
      cnt++;
    }
    st.update(ls[v],0);
  };
  vector<ll>et;
  function<void(ll,ll&)>dfs2=[&](ll v,ll&cnt){
  //  cout<<"cnt"<<cnt<<endl;
    st.update(ls[v],v);
    visited[v]=1;
    et.push_back(v);
    for(auto nv:g[v]){
      cnt++;

      if(ls[nv]!=0&&st[ls[nv]]){
        if(cnt==tcnt){
          cout<<mi<<"\n";
          //cout<<ls[nv]<<" "<<ls[v]<<endl;
          repi(i,ls[nv],ls[v]+1){
            if(st[i]>0)cout<<st[i]<<"\n";
          }
          cout<<flush;
        }
      }
      if(visited[nv])continue;
      dfs2(nv,cnt);
      cnt++;
    //  et.push_back(v);
    }
    st.update(ls[v],0);
  };
  dfs(0,id,cn);
  cn=0;
  visited.assign(n,0);
  dfs2(0,cn);
  cout<<endl;
  if(mi==1e9){
    cout<<-1<<endl;
  }
  return 0;

}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (LL i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (LL i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

LL const MOD = 1e9 + 7;
LL const MaxSize = 1e5 + 5;
//LL const MOD = 998244353;

LL N, M, S, T;

SAL g;
queue<int> q;
int d[3 * MaxSize];

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/georgeli/A_1.in", "r", stdin);
	cin >> N >> M;

	g = SAL(3 * N);

	LP(i, 0, M)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g.at(u).push_back(v + N);
		g.at(u + N).push_back(v + 2 * N);
		g.at(u + 2 * N).push_back(v);
	}
	cin >> S >> T;
	S--;
	T--;

	memset(d, -1, sizeof(d));

	q.push(S);
	d[S] = 0;

	while (!q.empty()) {
		int v = q.front();
		q.pop();

		LP(i, 0, g.at(v).size())
		{
			int u = g.at(v)[i];

			if (d[u] >= 0)
				continue;
			//cout << u << " " << v;

			d[u] = d[v] + 1;
			if (u == T) {
				cout << d[T] / 3;
				return 0;
			}
			q.push(u);
		}
	}

	cout << -1 << endl;

	return 0;

}


Measured memory_bytes: 17792
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
	cin >> A >> B >> C >> D;
	if(abs(A-C) <= D || (abs(A-B) <= D && abs(B-C) <= D)) cout << "Yes";
	else cout << "No";
}



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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e9
#define F first
#define S second


const int MAX = 402;

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;


int main(){
    int n,m,q;
    cin >> n >> m >> q;
    vector<vector<int>> train(n+1,vector<int>(n+1,0));
    Rep(i,m){
        int l,r;
        cin >> l >> r;
        train[l][r]++;
    }
    /*For(i,1,n+1){
        For(j,1,n+1){
            cout << train[i][j] << sp;
        }
        cout << endl;
    }*/
    vector<vector<int>> car(n+1,vector<int>(n+1,0));
    For(i,1,n+1){
        For(j,1,n+1){
            car[i][j] = car[i-1][j] + car[i][j-1] - car[i-1][j-1] + train[i][j];
            //cout << car[i][j] << sp;
        }
        //cout << endl;
    }
    Rep(i,q){
        int l,r;
        cin >> l >> r;
        cout << car[r][r] - car[l-1][r] << endl; 
    }
}

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

using namespace std;

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

	auto sum = 0;
	auto longest = 0;
	while (N--) {
		int x;
		cin >> x;
		sum += x;
		longest = max(longest, x);
	}

	cout << (2*longest < sum ? "Yes" : "No");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

using T = tuple<int, int, int>;

signed main() {
	int N;
	cin >> N;
	vector<T>vec(N);
	REP(i, N) {
		int w, s, v;
		cin >> w >> s >> v;
		vec[i] = T(w, s, v);
	}
	sort(ALL(vec), [](T lhs, T rhs) {
		auto[lw, ls, lv] = lhs;
		auto[rw, rs, rv] = rhs;
		int lstate = min(ls, rs - lw);
		int rstate = min(rs, ls - rw);
		return lstate > rstate;
	});
	vector<vector<int>>dp(N + 1, vector<int>(20020, -INF));
	dp[0][0] = 0;
	REP(i, N) {
		auto[w, s, v] = vec[i];
		REP(j, 20020) {
			CHMAX(dp[i + 1][j], dp[i][j]);
			if(j <= s) {
				CHMAX(dp[i + 1][j + w], dp[i][j] + v);
			}
		}
	}
	cout << *max_element(ALL(dp[N])) << endl;
}

Measured memory_bytes: 163748
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



char buf[105];

int main(){

	scanf("%s",buf);

	int len;
	for(len = 0; buf[len] != '\0'; len++);

	for(int i = 0; i < len/2; i++){
		if(buf[i] != buf[len-1-i]){

			printf("No\n");
			return 0;
		}
	}

	int head = 0,tail = ((len-1)/2)-1;

	while(head < tail){
		if(buf[head] != buf[tail]){

			printf("No\n");
			return 0;
		}
		head++;
		tail--;
	}

	head = ((len+3)/2)-1,tail = len-1;

	while(head < tail){
		if(buf[head] != buf[tail]){

			printf("No\n");
			return 0;
		}
		head++;
		tail--;
	}

	printf("Yes\n");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int x,y; cin >> x >> y;
  COUT(x+y/2);
  return 0;
}

Measured memory_bytes: 256
gets;P=*0..1e5;Q=[0]*2e5;F=->x{x==(p=P[x])?x:(s=F[p];Q[x]+=Q[p];P[x]=s)};puts$<.any?{|s|l,r,d=s.split.map &:to_i;(x=F[l])==(y=F[r])?Q[l]+d!=Q[r]:!(P[y]=x;Q[y]=Q[l]+d-Q[r])}?:No: :Yes

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 100 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);


int n , m;
char   a[N][N];
bool vis[N][N];
int  dis[N][N];

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

bool inside(int x , int y){ return x >= 0 && x < n && y >= 0 && y < m; }

int ans = 0;
queue < ii > q;

void bfs(int x , int y){
    memset(vis , 0 , sizeof vis);
    memset(dis , 0 , sizeof dis);

    q.push({x , y});
    vis[x][y] = 1;

    while(!q.empty()){
            x = q.front().first;
            y = q.front().second;;
            q.pop();

            ans = max(ans , dis[x][y]);

            for(int i = 0 ; i < 4 ; i ++){
                    int nx = x + dx[i];
                    int ny = y + dy[i];

                    if(!inside(nx , ny))continue;
                    if(a[nx][ny] == '#')continue;
                    if(vis[nx][ny])continue;

                    vis[nx][ny] = 1;
                    dis[nx][ny] = 1 + dis[x][y];
                    q.push({nx , ny});
            }
    }
}

void solve(int testCase){

    scanf("%d %d" , &n , &m);

    for(int i = 0 ; i < n ; i ++){
            scanf("%s" , a[i]);
    }

    for(int i = 0 ; i < n ; i ++){
            for(int j = 0 ; j < m ; j ++){
                    if(a[i][j] == '.')bfs(i , j);
            }
    }

    printf("%d\n" , ans);

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


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

int n,m,x;
int c[12];
int a[12][12];

int main(){
    /*入力*/ 
    cin >> n >> m >> x;
    for(int i = 0;i < n;i++){
        cin >> c[i];
        for(int j = 0;j < m;j++){
            cin >> a[i][j];
        }
    }
    /**/

    int ans = INT_MAX;

    for (int bit = 0; bit < (1<<n); ++bit)
    {
        // bit の表す集合を求める
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                S.push_back(i);
            }
        }

        int rikai[12] = {0};
        int sans = 0;

        //各アルゴリズムにc[S.front()]をたす
        while(!S.empty()) {
            //cout << S.front() << " ";
            
            sans += c[S.front()];
            for(int i = 0;i < m;i++){
                rikai[i] += a[S.front()][i];
            }
            S.erase(S.begin());
        }
        
        //全てのアルゴリズムがx以上の理解度をえられたら,
        int count = 0;
        for(int i = 0;i < m;i++){
            //cout << rikai[i] << " " << x << endl;
            if(rikai[i] >= x){
                count++;
            }
        }
        
        //最小コストを求める
        if(count == m){
            ans = min(ans , sans);
        }
    }

    
    if(ans == INT_MAX){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
    


    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 109 A / Link: http://abc109.contest.atcoder.jp/tasks/abc109_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	LL A, B; cin >> A >> B;
	string ans;
	if ((A*B)%2 == 1) {
		ans = "Yes";
	}
	else {
		ans = "No";
	}
	
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int a[maxn];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,s;
    cin>>n>>s;
    rep(i,1,n)cin>>a[i];
    int l=1,r=1;
    int ans=n+1,cur=0;
    while(l<=n&&r<=n){
        while(r<=n&&cur<s)cur+=a[r++];
        if(cur>=s)ans=min(ans,r-l);
        while(l<r&&cur>=s)ans=min(ans,r-l),cur-=a[l++];
    }
    cout<<(ans==n+1?0:ans)<<endl;
}
/* 
3 3
1 3 1
6 4
1 2 1 2 3 2
 */


Measured memory_bytes: 3608
s = input()
flag = 0

if s[0] == s[1] and s[2] == s[3] and s[0] != s[2] :
    flag = 1

elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1] :
    flag = 1


elif s[0] == s[3] and s[1] == s[2] and s[0] != s[1] :
    flag = 1


if(flag == 1):
    print('Yes')
else:
    print('No')

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

int main() {
    int k;
    cin >> k;
    int x = 7%k;
    set<int> s;
    int i = 1;
    if (k%2 == 0 || k%5 == 0 ) {
        cout << -1 << endl;
        return 0;
    }
    while (s.count(x) == 0) {
        if(x == 0) {
            cout << i << endl;
            return 0;
        }
        s.insert(x);
        x = (x*10+7)%k;
        i++;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 50452
#include <bits/stdc++.h>
static const int MAX = 100;
static const int INFTY = 10000000;
int V;
std::vector<std::pair<int, int> > G[MAX];

void dijkstra() {
    std::priority_queue<std::pair<int, int> > pq;
    bool visited[MAX];
    int d[MAX];
    for (int i = 0; i < V; i++) {
        visited[i] = false;
        d[i] = INFTY;
    }
    d[0] = 0;
    pq.push({0, 0}); //dist from target * -1, current node
    visited[0] = true;

    while ( !pq.empty() ) {
        std::pair<int, int> f = pq.top(); pq.pop();
        int current = f.second;
        visited[current] = true;

        if (d[current] < f.first * (-1)) continue;

        for (unsigned long i = 0; i < G[current].size(); i++) {
            int target = G[current][i].first;
            if (visited[target]) continue;
            if (d[target] > d[current] + G[current][i].second) {
                d[target] = d[current] + G[current][i].second;
                pq.push({d[target] * (-1), target});
            }
        }
    }

    for (int i = 0; i < V; i++) {
        std::cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << std::endl;
    }
}



int main()
{
    int source, target, cost, edges;
    std::scanf("%d", &V);
    for (int i = 0; i < V; i++) {
        std::scanf("%d %d", &source, &edges);
        for (int j = 0; j < edges; j++) {
            std::scanf("%d %d", &target, &cost);
            G[source].push_back({target, cost});
        }
    }
    dijkstra();
    return 0;
}



Measured memory_bytes: 3228
#include <stdio.h>
#include <math.h>

double aven(int n,int *data){
   int i;
   double sum=0;
   for(i=0;i<n;++i){
     sum+=data[i];
   }
   return (sum/n);
}

double hyouzyunhensa(int n,int *data,double ave){
   
   int i;
   double sum=0;
   
   for(i=0;i<n;++i){
     sum+=(data[i]-ave)*(data[i]-ave);
   }
    return(sqrt(sum/n));
}



int main(){

    int i,j=0,n;
    int data[1001];
    double ans[1001];
    
    while (1){
    scanf("%d",&n);
    if (n==0) break; 
    for(i=0;i<n;++i){
     scanf("%d",&data[i]);
     }
     ans[j]=hyouzyunhensa(n,data,aven(n,data));
     ++j;
    }
    
    for(i=0;i<j;++i){
		printf("%.8lf\n",ans[i]);
	}
    
    return 0;
}

Measured memory_bytes: 1796
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
abc113 D
"""

h, w, k = map(int, input().split())
cut = 10**9+7

if w == 1:
    if k == 1:
        print(1)
        exit()
    if k != 1:
        print(0)
        exit()

anslili = [[0]*(w+1) for i in range(h+1)]
anslili[0][1] = 1

amidahornot = [0, 1]
amidahorput = [0, 0]
for i in range(1, w+2):
    n, p = amidahornot[i], amidahorput[i]
    amidahornot.append(n+p)
    amidahorput.append(n)
amidahor = [amidahornot[i]+amidahorput[i] for i in range(w+2)]
amidahor[0] = 1

for y in range(1, h+1):
    anslili[y][1] = (anslili[y-1][1]*amidahor[w-1] + anslili[y-1][2] * amidahor[w-2]) % cut
    for x in range(2, w):
        anslili[y][x] = (anslili[y-1][x-1]*amidahor[x-2]*amidahor[w-x] + anslili[y-1][x+1]*amidahor[x-1]*amidahor[w-x-1] + anslili[y-1][x]*amidahor[x-1]*amidahor[w-x]) % cut
    anslili[y][w] = (anslili[y-1][w]*amidahor[w-1] + anslili[y-1][w-1] * amidahor[w-2]) % cut

print(anslili[h][k])


Measured memory_bytes: 3064