akhauriyash/Code-Regression huggingface dataset:
S = input()
Q = int(input())

S_front, S_back = [], []
reverse = False

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse = not reverse
    else:
        T = False if (query[1] == "1") else True
        if reverse ^ T is False:
            S_front += query[2]
        else:
            S_back += query[2]

if reverse is True:
    S = S[::-1]
    ans = "".join(S_back)[::-1] + S + "".join(S_front)
else:
    ans = "".join(S_front)[::-1] + S + "".join(S_back)
print(ans)


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

using namespace std;

typedef long long int lli;

int main() {
    int n, cont = 0;
    lli a[100000], small = 1e10, sum = 0;

    cin >> n;
    for (int i=0; i<n; i++) {
        scanf("%lld", &a[i]);
        small = min(small, abs(a[i]));
        sum += abs(a[i]);
        if (a[i] < 0) cont++;
    }

    if (cont%2) sum -= small*2;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = input()

E = [0] * (n + 10)
W = [0] * (n + 10)

e = 0
w = 0
for i in range(n):
    if s[i] == "E":
        e += 1
    else:
        w += 1
    W[i+1] = w
    E[i+1] = e

ans = float("inf")
for i in range(1, n+1):
    x = 0
    x += W[i-1]
    x += E[n]-E[i]
    ans = min(ans, x)

print(ans)

Measured memory_bytes: 19572
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll n,k,x,y;
    cin>>n;
    cin>>k;
    cin>>x;
    cin>>y;
    if (n<=k)
        cout<<n*x<<endl;
    else
        cout<<k*x+(n-k)*y<<endl;
}

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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int a = in(), b = in();
	if (abs(a - b) > 1) {
		cout << 0 << endl;
		return 0;
	}

	lint ans = (a - b) ? 1 : 2;
	for (int i = 1; i <= a; ++i) {
		ans *= i;
		ans %= mod;
	}
	for (int i = 1; i <= b; ++i) {
		ans *= i;
		ans %= mod;
	}

	print(ans);
}


Measured memory_bytes: 256
n = [a for a in str(input())]
if int(n[0] + n[1] + n[2]) <= int(n[0] + n[0] + n[0]):
    print(n[0] + n[0] + n[0])
else:
    print(str(int(n[0]) + 1) + str(int(n[0]) + 1) + str(int(n[0]) + 1))

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    char a[10];
    while(~scanf("%s",a))
    {
        if((a[0]-'0')+(a[1]-'0')+(a[2]-'0')+(a[3]-'0')==7)
        {
            printf("%c+%c+%c+%c=7\n",a[0],a[1],a[2],a[3]);
        }
        else if((a[0]-'0')+(a[1]-'0')+(a[2]-'0')-(a[3]-'0')==7)
        {
            printf("%c+%c+%c-%c=7\n",a[0],a[1],a[2],a[3]);
        }
        else if((a[0]-'0')+(a[1]-'0')-(a[2]-'0')-(a[3]-'0')==7)
        {
            printf("%c+%c-%c-%c=7\n",a[0],a[1],a[2],a[3]);
        }
        else if((a[0]-'0')-(a[1]-'0')-(a[2]-'0')-(a[3]-'0')==7)
        {
            printf("%c-%c-%c-%c=7\n",a[0],a[1],a[2],a[3]);
        }
        else if((a[0]-'0')+(a[1]-'0')-(a[2]-'0')+(a[3]-'0')==7)
        {
            printf("%c+%c-%c+%c=7\n",a[0],a[1],a[2],a[3]);
        }
        else if((a[0]-'0')-(a[1]-'0')-(a[2]-'0')+(a[3]-'0')==7)
        {
            printf("%c-%c-%c+%c=7\n",a[0],a[1],a[2],a[3]);
        }
        else if((a[0]-'0')-(a[1]-'0')+(a[2]-'0')-(a[3]-'0')==7)
        {
            printf("%c-%c+%c-%c=7\n",a[0],a[1],a[2],a[3]);
        }
        else if((a[0]-'0')-(a[1]-'0')+(a[2]-'0')+(a[3]-'0')==7)
        {
            printf("%c-%c+%c+%c=7\n",a[0],a[1],a[2],a[3]);
        }
        else{break;}
    }
    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b, c;cin >> a >> b >> c;
    cout << min({abs(a-b)+abs(b-c), 
                 abs(a-c)+abs(c-b),
                 abs(b-a)+abs(a-c),
                 abs(b-c)+abs(c-a),
                 abs(c-a)+abs(a-b),
                 abs(c-b)+abs(b-a),
                 }) << endl;
    return 0;
}


Measured memory_bytes: 256
x, y = map(int,input().split())
ans = []
if y-x >= 0:
    ans.append(y-x)
if y+x >= 0:
    ans.append(y+x+1)
if -y+x >= 0:
    ans.append(-y+x+2)
if -y-x >= 0:
    ans.append(-y-x+1)

print(min(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1000010;
int n,m,hd,tl,q[2][MAXN],dp[MAXN],g[MAXN];
char s[MAXN];
int main () {
	//freopen("1436.in","r",stdin);
	scanf("%d%d%s",&n,&m,s);
	hd=tl=1;
	q[0][tl]=n,q[1][tl]=0;
	for (int i=n-1;i>=0;i--) {
		if (s[i]=='0') {
			if (hd>tl) {g[i]=-1;dp[i]=1e9;}
			else {g[i]=q[0][hd],dp[i]=q[1][hd]+1;}
		}
		else {g[i]=-1;dp[i]=1e9;}
		if (hd<=tl&&q[0][hd]-i>=m) {hd++;}
		while (hd<=tl&&q[1][tl]>=dp[i]) {tl--;}
		tl++;
		q[0][tl]=i,q[1][tl]=dp[i];
	}
	int cur=0;
	if (dp[0]>=1e9) {
		printf("-1\n");
		return 0;
	}
	for (int i=1;i<=n;i++) {
		if (cur>=n) {break;}
		printf("%d ",g[cur]-cur);
		cur=g[cur];
	}
	return 0;
}

Measured memory_bytes: 7040
#include<stdio.h>

int main()
{
	int n;
	scanf("%d", &n);
	int i, rank;
	char sym;
	int card[4][14] = {0};
	for (i = 1; i <= n; i++)
	{
		scanf(" %c %d\n", &sym, &rank);
		switch (sym)
		{
		case 'S':
			card[0][rank-1] = -1;
			break;
		case 'H':
			card[1][rank-1] = -1;
			break;
		case 'C':
			card[2][rank-1] = -1;
			break;
		case 'D':
			card[3][rank-1] = -1;
		}
	}
	int j, k;
	for (j = 0; j <= 3; j++)
	{
		switch (j)
		{
		case 0:
			for (k = 0; k <= 12; k++)
			{
				if (card[0][k] != -1) printf("S %d\n", k + 1);
			}
			break;
		case 1:
			for (k = 0; k <= 12; k++)
			{
				if (card[1][k] != -1) printf("H %d\n", k + 1);
			}
			break;
		case 2:
			for (k = 0; k <= 12; k++)
			{
				if (card[2][k] != -1) printf("C %d\n", k + 1);
			}
			break;
		case 3:
			for (k = 0; k <= 12; k++)
			{
				if (card[3][k] != -1) printf("D %d\n", k + 1);
			}
		}
	}
	return 0;

}

Measured memory_bytes: 1028
N,M = list(map(int,input().split()))
AB = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x: x[0])
cost = 0
for ab in AB:
    if M >= ab[1]:
        cost += ab[0]*ab[1]
        M -= ab[1]
    else:
        cost += ab[0]*M
        break
print(cost)


Measured memory_bytes: 29796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	long double a,b,c;
	cin >> a >> b >> c;
	long double x;
	x = a+b+2*sqrt(a*b)-c;
	if(x<0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}


  return 0;
}


Measured memory_bytes: 256
import sys
from itertools import permutations

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XY = [list(map(int, input().split())) for _ in range(n)]

    def calc(x1, y1, x2, y2):
        return pow(pow(x1 - x2, 2) + pow(y1 - y2, 2), 0.5)

    dist = 0
    cnt = 0
    for pattern in permutations(list(range(n))):
        cnt += 1
        for i in range(1, n):
            x1, y1 = XY[pattern[i - 1]]
            x2, y2 = XY[pattern[i]]
            dist += calc(x1, y1, x2, y2)

    print(dist / cnt)


if __name__ == '__main__':
    resolve()


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n,m;
bool mat[101][101],rmat[101][101];
int cnt[101];
bool vis[101];

void dfs(int v){
  vis[v]=true;
  rep(i,n){
    if(!mat[v][i]||vis[i])continue;
    dfs(i);
  }
}
void rdfs(int v){
  vis[v]=true;
  rep(i,n){
    if(!rmat[v][i]||vis[i])continue;
    rdfs(i);
  }
}

int dfs2(int v,int dst){
  if(cnt[v]==dst)return v;
  vis[v]=true;
  rep(i,n){
    if(!rmat[v][i]||vis[i])continue;
    int tmp=dfs2(i,dst);
    if(tmp!=-1){
      mat[v][i]=true;
      mat[i][v]=false;
      rmat[i][v]=true;
      rmat[v][i]=false;
      return tmp;
    }
  }
  return -1;
}
int rdfs2(int v,int dst){
  if(cnt[v]==dst)return v;
  vis[v]=true;
  rep(i,n){
    if(!mat[v][i]||vis[i])continue;
    int tmp=rdfs2(i,dst);
    if(tmp!=-1){
      mat[v][i]=false;
      mat[i][v]=true;
      rmat[i][v]=false;
      rmat[v][i]=true;
      return tmp;
    }
  }
  return -1;
}

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    rep(i,n)rep(j,n)mat[i][j]=rmat[i][j]=false;
    rep(i,n)cnt[i]=0;
    rep(i,m){
      int a,b;
      cin>>a>>b;
      a--;b--;
      mat[b][a]=rmat[a][b]=true;
      cnt[b]++;
    }
    bool update=true;
    while(update){
      update=false;
      int mx=-1,mn=100000000;
      rep(i,n){
        maxch(mx,cnt[i]);
        minch(mn,cnt[i]);
      }

      {
        rep(i,n)vis[i]=false;
        rep(i,n)if(cnt[i]==mx)dfs(i);
        rep(i,n){
          if(!vis[i]||cnt[i]>=mx-1)continue;
          rep(j,n)vis[j]=false;
          int dst=dfs2(i,mx);
          cnt[dst]--; cnt[i]++;
          update=true;
          break;
        }
      }
      if(!update){
        rep(i,n)vis[i]=false;
        rep(i,n)if(cnt[i]==mn)rdfs(i);
        rep(i,n){
          if(!vis[i]||cnt[i]<=mn+1)continue;
          rep(j,n)vis[j]=false;
          int dst=rdfs2(i,mn);
          cnt[dst]++; cnt[i]--;
          update=true;
          break;
        }
      }
    }
    int mx=-1,mn=10000000;
    rep(i,n){
      maxch(mx,cnt[i]);
      minch(mn,cnt[i]);
    }
    cout<<mn<<" "<<mx<<endl;
  }
  return 0;
}



Measured memory_bytes: 3108
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - B +/- A
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b;
  scanf("%d%d", &a, &b);

  if (b % a == 0) printf("%d\n", a + b);
  else printf("%d\n", b - a);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
    int i,j,count = 0;
    int alen,blen;
    char a[101];
    char b[101];
    char tmp;
    scanf("%s",&a);
    scanf("%s",&b);
    alen = strlen(a);
    blen = strlen(b);
    for(i=0;i<alen;i++){
        if(strstr(a,b) != 0){
                count=1;
                break;
        }
        tmp = a[alen-1];
        for(j=(alen-1);j>0;j--){
            a[j] = a[j-1];
        }
        a[0] = tmp;
    }
    if(count == 1) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 524
#include<stdio.h>
#define MAX 100
int G[MAX+1][MAX+1];





int main(){
  int n,i,j,l,len,num,k;

  for(i=0; i<MAX+1; i++){
    for(j=0; j<MAX+1; j++){
      G[i][j]=0;
    }
  }
  
  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d %d",&len,&num);
    for(l=0; l<num; l++){
      scanf("%d",&k);
      for(j=1; j<=n; j++){
	if(k==j)G[len][j]=1;
      }
    }
  }
  for(i=1; i<=n; i++){
    for(j=1; j<=n; j++){
      if(j>1)printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod1=1000000007,mod2=999999893,MAX=1000005,INF=1<<30;

ll ru1[MAX],ru2[MAX];

struct Rollinghash{
    string S;
    int n;
    int base1;
    int base2;
    vector<ll> h1,h2;
    vector<int> bit;
    
    void make(string &T,int ba1,int ba2){
        S=T;
        n=S.size();
        h1.assign(n+1,0);
        h2.assign(n+1,0);
        bit.assign(n+1,0);
        base1=ba1;
        base2=ba2;
        
        for(int i=1;i<=n;i++){
            h1[i]=h1[i-1]*base1+ll(S[i-1]-'a');
            h1[i]%=mod1;
            
            h2[i]=h2[i-1]*base2+ll(S[i-1]-'a');
            h2[i]%=mod2;
        }
        
        for(int i=n-1;i>=0;i--){
            bit[i]=bit[i+1]|(1<<(S[i]-'a'));
        }
    }
    
    pair<ll,ll> ha(int l,int r){
        pair<ll,ll> res;
        res.fi=(h1[r]-h1[l]*ru1[r-l]%mod1+mod1)%mod1;
        res.se=(h2[r]-h2[l]*ru2[r-l]%mod2+mod2)%mod2;
        
        return res;
    }//開区間
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    mt19937_64 rng(58);
    ll ha1=rng()%mod1,ha2=rng()%mod2;
    
    ru1[0]=1;
    ru2[0]=1;
    
    for(int i=1;i<MAX;i++){
        ru1[i]=ru1[i-1]*ha1%mod1;
        ru2[i]=ru2[i-1]*ha2%mod2;
    }
    int N;cin>>N;
    ll ans=0;
    vector<string> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        reverse(all(A[i]));
    }
    sort(all(A),[](auto a,auto b){
        if(si(a)==si(b)) return a<b;
        return si(a)<si(b);
    });
    
    vector<Rollinghash> S(N);
    for(int i=0;i<N;i++){
        S[i].make(A[i],ha1,ha2);
    }
    
    int i=0;
    while(i<N){
        int j=i;
        while(j<N&&si(A[i])==si(A[j])) j++;
        
        map<pair<ll,ll>,int> MA;
        
        for(int k=i;k<j;k++){
            MA[S[k].ha(0,si(A[k])-1)]|=(1<<(A[k].back()-'a'));
        }
        
        for(int k=j;k<N;k++){
            if(MA.count(S[k].ha(0,si(A[i])-1))){
                ans+=__builtin_popcount(MA[S[k].ha(0,si(A[i])-1)]&S[k].bit[si(A[i])-1]);
            }
        }
        
        i=j;
    }
    
    cout<<ans<<endl;
}


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

int popcount(int x) {
	return __builtin_popcount(x);
}

int f(int x) {
	if (x == 0) return 0;
	return f(x%popcount(x))+1;
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> x(n);
	vector<int> ans(n);
	rep(i,n) x[i] = s[i]-'0';

	int count = 0;
	rep(i,n) count += x[i];

	rep(bit,2) {
		int ncount = count;

		if (bit == 0) ncount++;
		else ncount--;

		if(ncount <= 0) continue;

		int r = 0;
		rep(i,n) {
			r = (r*2)%ncount;
			r += x[i];
		}// r<=200000

		int k = 1;
		for(int i = n-1; i >= 0; --i) {
			int r0 = r;
			if(x[i] == bit) {
				if(bit == 0) r0 = (r0 + k) % ncount;
				else r0 = (r0 - k + ncount) % ncount;
				ans[i] = f(r0) + 1;
			}
			k = (k*2)%ncount;
		}
	}
	rep(i,n) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 5164
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll D = 0, S = 0;
  ll M;
  cin >> M;
  vl d(M), c(M);
  REP(i, M) {
    cin >> d[i] >> c[i];
    D += c[i];
    S += d[i] * c[i];
  }
  cout << D - 1 + ((S - 1) / 9) << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<math.h>
#include<algorithm>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> TP;

ll N;
int L[210];

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

int main()
{
    // get a integer
    ll N;
    scanf( "%lld", &N );
    for (int i = 0; i < 2 * N; ++i) {
        scanf( "%d", &(L[i]) );
    }
    sort( &L[0], &L[2*N] );
    ll answer = 0; 
    for (int i = 0; i < 2 * N; i += 2 ) {
        int add = min( L[i], L[i+1] );
        answer += add;
    }
    printf( "%lld\n", answer );
}



Measured memory_bytes: 760
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static int max_profit(ArrayList<Integer> arr) {
		int min_val = arr.get(0);
		int max_val = -Integer.MIN_VALUE;
		
		int i = 1;
		while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		}
		
		
		return max_val;
	}
	public static void main(String [] args) {
		Scanner br = new Scanner(System.in);
		int len;
		
		len = br.nextInt();
		ArrayList<Integer> arr= new ArrayList<Integer>();
		int val = 0;
		while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		}
		
		
		//invoke the computation part
		System.out.println(max_profit(arr));
		br.close();
		
	}
	
}

Measured memory_bytes: 104848
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=2e5+50,P = 998244353;


int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }
void upd(int &a,int b){ a=add(a,b); }
int powMod(int x, int k) {
	int res = 1;
	for (;k;k >>= 1, x = mul(x, x)) if (k & 1) res = mul(res, x); 
	return res;
}
int inv(int x) { return powMod(x, P - 2); } 
int frac(int a,int b){ return mul(a, inv(b)); }

int ans,n;
char s[N]; 

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	scanf("%s",s+1);
	ans=1;
	n=strlen(s+1);
	for(int z=1,i=2;i<=n;){
		++ans;
		if(z==1){
			if(s[i]==s[i-1]){
				if(i+1>n)--ans;
				z=2;i+=2;
			}else{
				z=1,++i;
			}
		}else{
			z=1,++i;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =5e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
int n,q;
int c[MAXN],ans[MAXN],rt,pos[MAXN],sum,a[MAXN];
struct node{
	int l,r,index;
	bool operator <(const node& o)const
    {
        if(pos[l]==pos[o.l]) return r<o.r;
        return pos[l]<pos[o.l];
    }
}need[MAXN];
void add(int x)
{
	a[c[x]]++;
	if(a[c[x]]==1) sum++;
}
void del(int x)
{
	a[c[x]]--;
	if(a[c[x]]==0) sum--;
}
int main()
{
	scanf("%d %d",&n,&q);
	rt=sqrt(1.0*n);
	for(int i=1;i<=n;i++)
	{
	    scanf("%d",&c[i]);
	    pos[i]=i/rt; 
	} 
	for(int i=1;i<=q;i++)
	{
		scanf("%d %d",&need[i].l,&need[i].r);
		need[i].index=i;
	}
	sort(need+1,need+1+q);
	int l=1,r=0;
	for(int i=1;i<=q;i++)
	{
		while(l<need[i].l)
		{
			del(l);
			l++;
		}
		while(l>need[i].l)
		{
			l--;
			add(l);
		}
		while(r<need[i].r)
		{
			r++;
			add(r);
		}
		while(r>need[i].r)
		{
			del(r);
			r--;
		}
		ans[need[i].index]=sum;
	}
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 17460
s=input()
if len(s)==2 or s[0]==s[1]:
    print("1 2" if s[0]==s[1] else "-1 -1")
else:
    for i in range(2,len(s)):
        if s[i-2]==s[i]:
            print(i-1,i+1)
            break
        elif s[i-1]==s[i]:
            print(i,i+1)
            break
    else:
        print(-1,-1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int arr[212345];
int main(){
    int n,x;
    cin>>n>>x;
    if(x == 2 * n - 1 || x == 1){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
        int pos = n; 
        for(int i = 1;i<n;i++){
            arr[i] = i + n;
            if(i + n == x) pos = i;
        }
        arr[n] = n;
        for(int i = n + 1;i < 2 * n;i++){
            arr[i] = i - n;
            if(i - n == x) 
                pos = i;
        } 
        swap(arr[pos],arr[n]);
        for(int i = 1;i<2 * n;i++){
            printf("%d\n",arr[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 2304
/*created by tanishk gupta*/
#include <bits/stdc++.h>
using namespace std;
#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 repl(i,a,n) for(long long int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef vector<int> VI;
typedef long long int ll;
typedef unsigned long long ull;
//typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll MOD=1e9+7;
const ll mod=1e9+7;
//const llint MOD;
const ll N=(ll)(1e6+1);
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll add(ll a,ll b){return ((a%MOD)+(b%MOD))%MOD;}
ll mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll sub(ll a,ll b){return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll binpow(ll x, ll y){ll z = 1;while(y){if(y & 1) z = mul(z, x);x = mul(x, x);y >>= 1;}return z;}
ll inv(int x){return binpow(x, MOD - 2);}
ll divide(ll x, ll y){return mul(x, inv(y));}
ll fact[N];
void precalc(){fact[0] = 1;for(ll i = 1; i < N; i++)fact[i] = mul(fact[i - 1], i);}
ll C(ll n, ll k){return divide(fact[n], mul(fact[k], fact[n - k]));}
//bool prime[N];
//void sieve() {for(int i=2;i<N;i++) {prime[i]=true;}for (int p=2; p*p<=N; p++){if (prime[p] == true){for (int i=p*p; i<=N; i += p)prime[i] = false;}}}
ll legendpow(ll n, ll p){ll total = 0;while (n){n /= p;total += n;}return total;}

//head==================================================================================


int main() {
//#ifdef _DEBUG
	//freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
int n;
cin>>n;
int a[n];
ll sum=0;
rep(i,0,n)cin>>a[i];
rep(i,1,n)
{
    if(a[i]<a[i-1])
    {
        sum+=(a[i-1]-a[i]);
        a[i]=a[i-1];
    }

}
cout<<sum;
}


Measured memory_bytes: 4412
# dp[i] 足場iまでいくコストの最小値

n,k = map(int,input().split())
h = [0] + list(map(int,input().split()))

# dp[2]までは初期条件で確定
dp = [0 for i in range(n+1)]
dp[2] = abs(h[2]-h[1])

for i in range(3,n+1):
    arr = [dp[i-j] + abs(h[i] - h[i-j]) for j in range(1,min(i-1,k)+1)]
    dp[i] = min(arr)


ans = dp[n]
print(ans)


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

using namespace std;

const int MX = 2000, INF = 1e9;

char s[MX + 1];
vector<int> G[MX];

tuple<int, int, int> dfs(int v, int p = -1) {
	int mn = 0, mx = 0, cnt = 0;
	if (s[v] == '1') cnt++;
	
	for (int u : G[v]) {
		if (u == p) continue;
		int mnU, mxU, cntU;
		tie(mnU, mxU, cntU) = dfs(u, v);
		
		mnU += cntU;
		mxU += cntU;
		
		mn = max(mnU + mxU, mn);
		mx += mxU;
		cnt += cntU;
	}
	
	mn = max(mn - mx, 0);
	
	return make_tuple(mn, mx, cnt);
}

int main() {
	int n;
	ignore = scanf("%d %s", &n, s);
	for (int i = 1, u, v; i < n; i++) {
		ignore = scanf("%d %d", &u, &v);
		u--; v--;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	
	int ans = INF;
	for (int v = 0; v < n; v++) {
		int mn, mx;
		tie(mn, mx, ignore) = dfs(v);
		if (mn == 0 && mx % 2 == 0) ans = min(ans, mx / 2);
	}
	
	if (ans == INF) ans = -1;
	printf("%d\n", ans);
	
	return 0;
}


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

using str = string;
using ll = long long;

int a[500010];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    str s;
    cin>>s;
    
    int n=s.size()+1;
    
    int nn=0;
    int sn=0;
    int mn=0;
    
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='<')nn++;
        else nn--;
        sn=min(sn,nn);
        mn=min(mn,nn);
        a[i+1]=nn;
    }
    
    vector<pair<int,int>> p;
    bool down=true;
    sn=0;
    
    for(int i=1;i<n;i++)
    {
        if(i==n-1)
        {
            sn=min(sn,a[i]);
            p.push_back(make_pair(n-1,sn));
        }
        else
        {
            if(down&&a[i-1]<a[i])
            {
                down=false;
            }
            else if(!down&&a[i-1]>a[i])
            {
                p.push_back(make_pair(i-1,sn));
                sn=a[i];
                down=true;
            }
            else 
            {
                sn=min(sn,a[i]);
            }
        }
    }
    
    int cur=0;
    
    for(int i=0;i<n-1;i++)
    {
        if(p[cur].first<i)cur++;
        if(p[cur].first==i)
        {
            a[i]-=min(p[cur].second,p[cur+1].second);
        }
        else a[i]-=p[cur].second;
    }
    
    a[n-1]-=p[cur].second;
    
    ll ans=0;
    for(int i=0;i<n;i++)ans+=a[i];
    
    cout<<ans<<"\n";
    
    return 0;
}



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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

class slide_minimum{
    public:
    std::vector<ll> list;
    std::vector<ll> ans;
    ll n;   // listの長さ
    ll wl;  // 枠の大きさ
    std::deque<ll> deq;

    slide_minimum(ll n, ll l, std::vector<ll> list) : n(n), wl(l){
        for(ll i=0; i<n; i++) this->list.push_back(list[i]);
    }
    std::vector<ll> get(){
        for(ll i=0; i<n; i++){
            while(!deq.empty() && list[deq.back()] >= list[i]) deq.pop_back();
            deq.push_back(i);

            if(i+1 >= wl){
                ans.push_back(list[deq.front()]);
                if(deq.front()==i+1-wl)deq.pop_front();
            }
        }
        return this->ans;
    }
 };

int main(){
    ll n,l,a;
    vector<ll> list;
    //vector<ll> ans;
    cin >> n >> l;
    REP(i,n){
        cin >> a;
        list.push_back(a);
    }

    slide_minimum sm(n, l, list);
    vector<ll> ans = sm.get();

    /*
    std::deque<ll> deq;

    for(ll i=0; i<n; i++){
        while(!deq.empty() && list[deq.back()] >= list[i]) deq.pop_back();
        deq.push_back(i);

        if(i+1 >= l){
            ans.push_back(list[deq.front()]);
            if(deq.front()==i+1-l)deq.pop_front();
        }
    }
    */
    
    cout << ans[0];
    for(ll i=1; i<ans.size(); i++)cout << " " << ans[i];
    cout << endl;
}


Measured memory_bytes: 34596
num = input().split(" ")

W = int(num[0])
H = int(num[1])
x = int(num[2])
y = int(num[3])
r = int(num[4])


if (x-r) < 0:    # 左
    print("No")
elif x+r > W:     # 右
    print("No")
elif y+r > H:   # 上
    print("No")
elif y-r < 0:   #下
    print("No")
else:
    print("Yes")



Measured memory_bytes: 5596
#include <stdio.h>
int main(void){
    int n,m,l,i,j,k;
    int a[100][100],b[100][100];
    long c[100][100]={0};
    scanf("%d %d %d",&n,&m,&l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);}}
    
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d",&b[i][j]);}}

    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];}}}
    
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            if(j) printf(" ");
            printf("%ld",c[i][j]);}
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
map<ll,ll> ma;
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  int n;  string s;
  cin >> n >> s;
  s.erase(unique(all(s)), s.end());
  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 512
def powmod(b,e,m):
    r=1
    while e>0:
        if e%2==1:
            r=(r*b)%m
        e>>=1
        b=(b*b)%m
    return r

def check(N,d):
    if N%2==0:
        for i in range(1,N,2):
            if i in d:
                if d[i]!=2:
                    return False
            else:
                 return False
    else:
        if 0 in d:
            if d[0]!=1:
                return False
        else:
            return False
        for i in range(2,N,2):
            if i in d:
                if d[i]!=2:
                    return False
            else:
                return False
    return True

N=int(input())
A=list(map(int,input().split()))
d={}

for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1

if check(N,d):
    ans=powmod(2,N//2,10**9+7)
else:
    ans=0
print(ans)


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

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

	for (int i = 0; i < 3;i++) {
		if (s[i]==t[i]) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
L = [input().split() for _ in range(N)]
L = [[int(x[0]),int(x[1])] for x in L]
L = sorted(L)
c = 0
s = 0
for i in range(N):
  A = L[i][0]
  B = L[i][1]
  s += B
  if s <= M:
    c += A*B
  else:
    c += (B-(s-M))*A
    break
print(c)

Measured memory_bytes: 49524
#include<iostream>
using namespace std;
int a,b,c;
bool ans=false;
int main(){
    cin>>a>>b>>c;
    for (int i=0; i<=1000; i++) {
        int now=b*i+c;
        if (now % a==0 && now!=0) ans=true;
    }
    if (ans) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	String[] w = new String[n];
	w[0] = scan.next();
	int flag = 1;
	for(int i = 1; i < n; i++){
	    w[i] = scan.next();
	    if(w[i].charAt(0) !=
	       w[i-1].charAt(w[i-1].length()-1)){
		flag = -1;
	    }
	}

	if(flag == 1){
	    for(int i = 0; i < n; i++){
		for(int j = i-1; j >= 0; j--){
		    if(w[i].equals(w[j])){
			flag = -1;
		    }
		}
	    }
	}

	if(flag == 1){
	    System.out.println("Yes");
	}else{
	    System.out.println("No");
	}
    }
}


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

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

    vector<int> a(n), b(n, 0);
    for (auto& x : a) cin >> x;

    sort(a.begin(), a.end());

    int cnt = 0, i = 0;
    while (x > 0) {
        i %= n;
        if (a[i] <= x && b[i] == 0) {
            cnt++;
        } else if (b[i]) {
            cnt--;
        }
        b[i] += a[i];
        x -= a[i];

        i++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int d=0,n,x,l,ans=1;
	scanf("%d%d", &n,&x);
	for (int i = 0; i < n; i++) {
		scanf("%d", &l);
		if(d+l<=x){
			ans++;
			d+=l;
		}else{
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
/*
  3, 4文字目が等しく、5, 6文字目が等しければ"Yes"
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S; cin >> S;
  string ans;

  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
    ans = "Yes";
  } else {
    ans = "No";
  }

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

Measured memory_bytes: 256
#define _USE_MATH_DEFINES    
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define quickIO()   {cin.tie(0);    cout.sync_with_stdio(false);}
#define rep(i,n)    for(ll i=0; i<(ll)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define fcout cout << fixed << setprecision(10) 
const ll inf = 1e18;
const ll mod = 1e9 +7;
     
ld sqrtld(ld x){
    ld left = 0, right = x;
    rep(i, 100){
        ld mid = (left + right)/2;
        if (mid*mid <= x)   left =mid;
        else    right = mid;
    }
    return left;
}


int main (){
    int n;
    cin >> n;
    int a=0;
    int b;
    int count=1;
    int ans=0;
    rep(i,n){
        cin >> b;
        if( a==b){
            count++;
        }else{
            ans += count/2;
            count = 1;
        }  
        if(i == n-1){
            ans += count/2;
            count = 1;
        }
        a = b;
    }
    cout << ans << endl;
    return 0;
}



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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]={x,y}; v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll n, W, ans=0;
    cin >> n >> W;
    vll v(n), w(n);
    REP(i,n) cin >> w[i] >> v[i];
    const ll V = sum(v);
    vvll dp(n+1, vll(V+1, INF));
    dp[0][0]=0;

    REP(i,n){
        FOR(j,0,V){
            ll m = max(0LL, j-v[i]);
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j], dp[i][m]+w[i]);
        }
    }
    FOR(j,0,V){
        if(dp[n][j]>W){
            cout << j-1 << endl;
            return 0;
        }
    }
    cout << V << endl;
    return 0;
}


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

int main() {
    //入力
    char al;
    cin >> al;
    //std:isupper()で大文字かどうかを判定（大文字ならtrue）
    if (isupper(al)) cout << "A" << endl;
    else cout << "a" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
vector<string> split(const string &s, char delim) {
	vector<string> elems;
	string item;
	for (char ch : s) {
		if (ch == delim) {
			if (!item.empty())
				elems.push_back(item);
			item.clear();
		} else {
			item += ch;
		}
	}
	if (!item.empty())
		elems.push_back(item);
	return elems;
}

// 本体

int main() {
	IOS();
	ll x, y;
	cin >> x >> y;
	if ((y - 2 * x) % 2 == 0 && (y - 2 * x) / 2 >= 0 && (4 * x - y) % 2 == 0 && (4 * x - y) / 2 >= 0) {
		dump("Yes");
	} else {
		dump("No");
	}
}

Measured memory_bytes: 3648
using System;
class ProgramD
    {
        static void Main(string[] args)
        {
            
            //入力
            string input = Console.ReadLine();
            int n = int.Parse(input);

            string s = Console.ReadLine();

            int count = 0;

            for(int num = 0; num < 1000;num++)
            {
                int v1 = -1;
                int v2 = -1;
                int v3 = -1;
                int temp1 = num /100;
                int temp2 = (num - temp1 * 100) /10;
                int temp3 = num - temp1 *100-temp2*10;
                for(int i = 0;i < n - 2;i++)
                {
                    if(temp1 == s[i] - '0')
                    {
                        v1 = i;
                        break;
                    }
                }

                if(v1 == -1)
                    continue;

                for(int i = v1 + 1 ;i< n;i++)
                {
                    if(temp2 == s[i] - '0')
                    {
                        v2 = i;
                        break;
                    }
                }

                if(v2 == -1)
                    continue;

                for(int i = v2 + 1 ;i< n;i++)
                {
                    if(temp3 == s[i] - '0')
                    {
                        v3 = i;
                        break;
                    }
                }

                if(v3 != -1)
                    count++;
                             
            }

            Console.WriteLine(count);
          
        }
    }

Measured memory_bytes: 13140
n,a,b=map(int,input().split())
d=[[0]*401 for i in range(401)]
h=[]
for i in range(n):
    s=[]
    c=d[:]
    p,q,r=map(int,input().split())
    if d[p][q]!=0:
        d[p][q]=min(r,c[p][q])
    else:
        s.append([p,q])
        d[p][q]=r
    h=sorted(h,key=lambda x:x[1]+x[0])
    for j in range(len(h)-1,-1,-1):
        if h[j][0]+p<401 and h[j][1]+q<401:
            if c[h[j][0]+p][h[j][1]+q]!=0:
                d[h[j][0]+p][h[j][1]+q]=min(r+c[h[j][0]][h[j][1]],d[h[j][0]+p][h[j][1]+q])
            else:
                s.append([h[j][0]+p,h[j][1]+q])
                d[h[j][0]+p][h[j][1]+q]=r+c[h[j][0]][h[j][1]]
    else:
        h+=s
else:
    c=float("inf")
    k=1
    while a*k<401 and b*k<401:
        if d[a*k][b*k]!=0:
            c=min(c,d[a*k][b*k])
        k+=1
    else:
        if c==float("inf"):
            print(-1)
        else:
            print(c)


Measured memory_bytes: 7584
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>

#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


double distance(P p1,P p2){
    double d = (double)((p1.first - p2.first)*(p1.first - p2.first) + (p1.second - p2.second)*(p1.second - p2.second));
    d = sqrt(d);
    rn d;
}

int N;
double ans = 0;
vector<P> xy;
ll fact(int n){
    ll a = 1LL;
    FOR(i,1,n+1){
        a*= i;
    }
    rn a;
}

int main(){
    cin >> N;
    
    rep(i,N){
        int x,y;
        cin >> x >> y;
        xy.pb(P(x,y));
    }

    int indexes[N];
    double ans = 0LL;
    
    for (int i = 0; i < N; i++) indexes[i] = i;
    do {
        rep(i,N-1){
            ans += distance(xy[indexes[i]],xy[indexes[i+1]]);
        }
    } while (std::next_permutation(indexes, indexes + N));
    
    printf ("%.10f",(double)ans/fact(N));
    rn 0;
}



Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 2/25
// Problem:ABC 050 LiningUp c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

#define MOD 1000000007

int main()
{
  int N;
  int cnt = 1;
  cin >> N;
  vector<int> A(N);
  vector<int> Ans(N);
  REP(i,N) {
    cin >> A[i];
    // N人の時の報告は左にi人,右にN-i-1人いる
    Ans[i] = abs(N-i-1-i);
  }
  sort(ALL(A));
  sort(ALL(Ans));

  if (A == Ans) {
    REP(i,N/2) {
      cnt <<= 1;
      cnt %= MOD;
    }
  } else {
    cnt = 0;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1024
f = {
  :a => {
    '0' => :x,
    '1' => :y
  },
  :x => {
    '0' => nil,
    '1' => :z
  },
  :y => {
    '0' => :x,
    '1' => nil
  },
  :z => {
    '0' => :w,
    '1' => :b
  },
  :w => {
    '0' => :b,
    '1' => :y
  },
  :b => {
    '0' => :y,
    '1' => :x
  },
}

loop do
  s = gets.chomp
  if s == '#'
    break
  end
  p = :a
  s.chars do |c|
    p = f[p][c]
    break unless p
  end
  puts p==:b ? 'Yes' : 'No'
end

Measured memory_bytes: 6092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    double ans=0;
    for(int i=1;i<=n;i++){
        int count=0;
        for(int j=i;j<k;j*=2){
            count++;
        }
        ans+=1.0/(n*pow(2,count));
    }
    printf("%.10lf\n",ans);
    return 0;
}


Measured memory_bytes: 256