akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        public static readonly string Yes = "Yes";
        public static readonly string YES = "YES";
        public static readonly string No = "No";
        public static readonly string NO = "NO";
        public static readonly string OK = "OK";
        public static readonly string NG = "NG";

        void Omame()
        {
            cin = new Scanner();
            long X = cin.nextLong();
            long A = cin.nextLong();
            long B = cin.nextLong();

            X -= A;

            Console.WriteLine(X - (X / B) * B);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, L, A[100010] = {}; cin >> N >> L;
  int t[100010] = {};
  pque<INTP> que;
  REP(i, N){
    cin >> A[i+1];
    que.push({A[i+1], i+1});
  }
  int ans = 0;
  while(!que.empty()){
    INTP p = que.top(); que.pop();
    int plus = 0;
    if(p.first < A[p.second-1]) plus = max(plus, t[p.second-1]);
    if(p.first < A[p.second+1]) plus = max(plus, t[p.second+1]);
    t[p.second] = plus + L-p.first;
  }
  REP(i, N){
    // cerr << i+1 << " : " << t[i+1] << endl;
    ans = max(ans, t[i+1]);
  }
  cout << ans << endl;
}



Measured memory_bytes: 6456
c,d,t,u,sz;
long s;
char x[18],buf[5<<17];
main()
{
	read(0,buf,5<<17);
	c=*buf;
	while(c!=10)
	{
		t+=1;
		d=buf[sz+=1];
		if(c!=d)
		{
			s+=(long)t*(t+1)>>1;
			if(c=='>')s-=t<u?t:u;
			u=t;
			t=0;
			c=d;
		}
	}
	t=17;
	do{
		x[--t]=s%10+'0';
		s/=10;
	}while(s);
	write(1,x+t,17-t);
}


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

using namespace std;

using ll = long long;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    ll x = 0;
    for (int i = n; i >= 1; i--) {
        if (i % 2) x += a[i - 1];
        else x -= a[i - 1];
    }

    for (int i = 1; i <= n; i++) {
        cout << x << " ";
        x = 2 * a[i - 1] - x;
    }
    
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#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)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll k;
  cin >> k;
  vector<bool> visited(k,false);
  auto c = [](pll a,pll b){return a.first>b.first;};
  priority_queue<pll,vector<pll>,decltype(c)> cost(c);
  // cost,node
  cost.push(make_pair(1ll,1ll));
  ll ans;
  while(!cost.empty()){
    pll nx = cost.top();
    cost.pop();
    //cout << nx.first << "," << nx.second << endl;
    if(nx.second==0){
      ans = nx.first;
      break;
    }
    if(visited[nx.second]) continue;
    else visited[nx.second] = true;
    if(!visited[(nx.second * 10ll)%k]) cost.push(make_pair(nx.first, (nx.second * 10ll)%k));
    if(!visited[(nx.second + 1ll)%k]) cost.push(make_pair(nx.first+1, (nx.second + 1ll)%k));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(double)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int main(){    
    int N;cin>>N;
    string S;
    cin>>S;
    stack<char>st;
    int cnt_l=0,cnt_r=0;
    REP(i,N){
        if(S[i]=='('){
            st.push(S[i]);
            cnt_l++;
        }else{
            cnt_r++;
            if(!st.empty()&&st.top()=='('){
                cnt_l--;cnt_r--;
                st.pop();
            }else{
                st.push(S[i]);
            }
        }

    }
    string res="";
    REP(i,cnt_r)res+="(";
    res+=S;
    REP(i,cnt_l)res+=")";
    
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define fi first
#define se second

int n;
vector<int> v;
signed main(){
	cin >> n;
	for(int i = 1 ; i <= n + n ; i ++){
		int x; cin >> x; v.push_back(x);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i = 1 ; i <= n + n ; i += 2)
		ans += v[i - 1];
	cout << ans;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)
import Data.Sequence ((<|), (|>), ViewL(..), ViewR(..), Seq)
import qualified Data.Sequence as Sq

main :: IO ()
main = do
  q <- readLn
  replicateM q f >>= solve
  where
    f = readil B.readInt <$> B.getLine

solve :: [[Int]] -> IO ()
solve = foldM_ f Sq.empty
  where
    f sq [0, d, x] = push sq d x
    f sq [1, p] = do
      randomAccess sq p >>= print
      return sq
    f sq [2, d] = pop sq d

push :: Seq Int -> Int -> Int -> IO (Seq Int)
push sq d x
  | d == 0 = return $ x <| sq
  | otherwise = return $ sq |> x

randomAccess :: Seq Int -> Int -> IO Int
randomAccess sq p = return $ Sq.index sq p

pop :: Seq Int -> Int -> IO (Seq Int)
pop sq d
  | d == 0 = let (_ :< sq') = Sq.viewl sq
             in return sq'
  | otherwise = let (sq' :> _) = Sq.viewr sq
                in return sq'

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')



Measured memory_bytes: 139452
from collections import deque


dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

H, W = map(int, input().split())
maze = [input() for _ in range(H)]


def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j] == ".":
                dist = [[-1] * W for _ in range(H)]
                dist[i][j] = 0
                que = deque()
                que.append([i, j])

                while que:
                    y, x = que.popleft()
                    for k in range(4):
                        nx = x + dx[k]
                        ny = y + dy[k]
                        if nx >= W or nx < 0 or ny >= H or ny < 0:
                            continue
                        if dist[ny][nx] != -1:
                            continue
                        if maze[ny][nx] == "#":
                            continue
                        dist[ny][nx] = dist[y][x] + 1
                        que.append([ny, nx])
            else:
                continue
            ans = max(ans, max(max(steps) for steps in dist))
    print(ans)


if __name__ == "__main__":
    solve()


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

int main() {
  string O, E; cin >> O >> E;
  for (int i = 0; i < O.length(); i++) {
    cout << O[i];
    if (i+1 > E.length()) break;
    cout << E[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
#abc168d
n,m=map(int,input().split())
g=[[] for i in range(n)]
for i in range(m):
 a,b=map(int,input().split())
 g[a-1].append(b-1)
 g[b-1].append(a-1)
p=[-1]*n
q=[0]
while q:
 i=q.pop(0)
 for j in g[i]:
  if p[j]==-1:
   p[j]=i
   q.append(j)
print('Yes')
for i in range(1,n):
 print(p[i]+1)


Measured memory_bytes: 33636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> town(N+1);
  
  for (int i = 0; i < M; i++) {
    int a1, a2;
    cin >> a1 >> a2;
    town.at(a1)++;
    town.at(a2)++;   
  }  
  for (int i = 1; i <= N; i++) {
    cout << town.at(i) << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    # error_print(A)
    m = -1
    for i in range(1, N):
        if A[i-1] == A[i]:
            A[i] = m
            m -= 1
            ans += 1
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7748
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  int key;
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);

  for(i = 2; i <= n; i++){
    key = A[i];
    j = i -1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    trace(A, n);
  }


  return 0;
}

Measured memory_bytes: 608
n,m,p = map(int, input().split())
es = []
g1 = [[]for _ in range(n)]
g2 = [[] for _ in range(n)]
li = []
for i in range(m):
  a,b,c = map(int, input().split())
  li.append((a - 1,b - 1,c))
  g1[a - 1].append((b - 1,(c-p)*-1))
  g2[b - 1].append((a - 1,(c-p)*-1))
done1 = [0] * n
done1[0] = 1
s = [0]
while s:
  d = s.pop()
  for node,_ in g1[d]:
    if not done1[node]:
      done1[node] = 1
      s.append(node)
done2 = [0] * n
done2[n - 1] = 1
s = [n - 1]
while s:
  d = s.pop()
  for node, _ in g2[d]:
    if not done2[node]:
      done2[node] = 1
      s.append(node)
done = [0] * n
for i in range(n):
  done[i] = done1[i] & done2[i]
for a,b,c in li:
  if done[a] & done[b]:
    es.append((a,b,(c-p)*-1))
m = len(es)
d = [0]*n
for i in range(n):
  for j in range(m):
    f, t, c = es[j]
    if d[t] > d[f] + c:
      d[t] = d[f] + c
      if i == n - 1:
        print(-1)
        exit(0)
d = [float('inf')] * n
d[0] = 0
while(True):
  update = False
  for i in range(m):
    f, t, c = es[i]
    if d[f] != float('inf') and d[t] > d[f] + c:
      d[t] = d[f] + c
      update = True
  if not update:
    break
print(max(0, -d[n - 1]))


Measured memory_bytes: 54760
#include <stdio.h>
#define NOT -1

int u[100][100];//u[id][k v]
int time = 0;
int d[100];
int f[100];

void search(int a){
  int i,k,q;
  time++;
  d[a] = time; 
  k = u[a][0];
  if(k > 0){
    for(i=1;i<=k;i++){
      q = u[a][i];
      if(d[q]==NOT){
	search(q);   
      }
    }
  }
  time++;
  f[a]=time;
}



int main(){
  
  int n,i,ii,t,kk,c;
  int a;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&t);
    scanf("%d",&u[t][0]);
    for(ii=1;ii<=u[t][0];ii++)
      scanf("%d",&u[t][ii]);
    d[i]=NOT;
  }



  search(1);
  
  for(i=1;i<=n;i++)
    if(d[i]==NOT)
      search(i);


  

  for(i=1;i<=n;i++)
    printf("%d %d %d\n",i,d[i],f[i]);
  
  
  return 0;
}



Measured memory_bytes: 2048
//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define all(a) begin(a),end(a)

using namespace std;
using namespace __gnu_pbds;

using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
	cout<<w.size()<<en;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<en;
	if (fl) cout<<flush;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a,int base=10)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=base;
		k+=a[i]-'0';
	}
	return k;
}

template<class T>
void eras(vector<T>& a,T b)
{
	a.erase(find(a.begin(),a.end(),b));
}

string its(ll k,int base=10)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%base)+'0');
		k/=base;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=300010;
ll a,b,c;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
	cin>>a>>b>>c;
	if (c*(2*a+2*b-c)<(a-b)*(a-b) && c>a+b) cout<<"Yes\n";
	else cout<<"No\n";
}





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

using namespace std;

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

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


// 約数列挙
vector<int> divisor(int n) {
	vector<int> ret;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	return ret;
}

signed main() {

	int N;
	cin >> N;
	
	vector<int> dv = divisor(N);

	int ans = 0;
	for(int d:dv) {
		int m = d - 1;
		if (m == 0) continue;

		if (N / m == N % m) ans += m;
	}

	cout << ans << endl;

	return 0;
}


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

int main(void) {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int ca = min(a, k);
  int cc = max(0, k - a - b);
  int result = ca - cc;
  cout << result << endl;
  return 0;
}

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

int main()
{
    string s;
    cin >> s;
    char c;
    bool ismixed = false;
    for (auto i = 0; i < s.length(); i++)
    {
        if (i != 0 && c != s.at(i))
        {
            ismixed = true;
            break;
        }
        c = s.at(i);
    }
    if (ismixed)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
import numpy as np

N, K, Q = [int(x) for x in input().split()]

A = list()
while True:
    try:
        A.append(int(input()))
    except EOFError:
        break

scores = np.full((N), K - Q)

for a in A:
    scores[a - 1] += 1

for score in scores:
    print("Yes" if score > 0 else "No")


Measured memory_bytes: 17636
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int md = 1e9 + 7;

int mul(int a, int b) {
  return ((ll)a * b) % md;
}

void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

int power(int a, ll b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
} 

int inv(int x) {
  return power(x, md - 2);
}

const int N = 3e5 + 7;

int sum[N];
int pr[N];
int ip[N];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int h;
  cin >> h;
  int n = (1 << h) - 1;
  int L = (1 << (h - 1));
  vector <int> p(L);
  for (int i = 0; i < L; ++i) {
    cin >> p[i];
    p[i] += L - 1;
  }
  pr[1] = 1;
  for (int i = 2; i < N; ++i) {
    pr[i] = mul(pr[i / 2], i);
  }
  for (int i = 1; i < N; ++i) {
    ip[i] = inv(pr[i]);
  }
  auto add_ver = [&] (int v, int x) {
    while (v > 0) {
      add(sum[v], x);
      v /= 2;
    }
  };  
  auto del_ver = [&] (int v, int x) {
    while (v > 0) {
      sub(sum[v], x);
      v /= 2;
    }
  };  

  auto get_dv = [&] (int u) {
    int dv = mul(mul(ip[u], ip[u]), u);
    return dv;
  };

  vector <vector <int>> who(n + 1);
  for (int x = (1 << (h - 1)); x <= n; ++x) {
    int v = x;
    while (v > 0) {
      who[v].push_back(x);
      v /= 2;
    } 
  } 

  int ans = 0;
  for (int u = 1; u < L; ++u) {
    int l = 2 * u;
    int r = 2 * u + 1;
    int cur_sum = 0;
    int dv = get_dv(u);
    for (auto v : who[l]) {
      add_ver(p[v - L], mul(pr[v], pr[p[v - L]]));
    }
    for (auto v : who[r]) {
      int w = p[v - L];
      int go = mul(pr[v], pr[w]);
      while (w != 1) {
        int par = w / 2;
        int other_w = w ^ 1;
        
        add(cur_sum, mul(mul(go, sum[other_w]), get_dv(par))); 
        w = par;
      }
    }

    for (auto v : who[l]) {
      del_ver(p[v - L], mul(pr[v], pr[p[v - L]]));
    }
    add(ans, mul(cur_sum, dv));
  }
  cout << ans << '\n';
}



Measured memory_bytes: 28584
n,a,b=map(int,input().split())
ans=0
for i in range(n):
  num=str(i+1)
  long=len(str(i+1))
  zenbu=0
  for j in range(long):
    zenbu+=int(num[j])
  #print(i+1,zenbu)
  if (a<=zenbu<=b):
    #print(i+1)
    ans+=i+1
print(ans)

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

// hpがhのモンスターを倒すのに必要な攻撃回数を返す
int costHp(int h)
{
    // cost_hp[i]: hp がiのモンスターを倒すのに必要な攻撃回数
    static map<int, int> cost_hp = {{1, 1}};

    if (cost_hp.count(h) > 0)
        ;
    else
    {
        const int splitted = costHp(h / 2);
        cost_hp[h] = splitted * 2 + 1;
    }
    return cost_hp[h];
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int h;
    cin >> h;

    cout << costHp(h) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll a,b;cin>>a>>b;
  if(b==1){cout<<0<<endl;return 0;}
  rep(i,100){
  ll d=1+((a-1)*i);
  if(d>=b){cout<<i<<endl;return 0;}
  }
  //caricurate
  //output
}

Measured memory_bytes: 256
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    int n;
    cin >> n;
    vector<bool> vec(n, false);
    rep(i, n) {
        int d1, d2;
        cin >> d1 >> d2;
        vec[i] = (d1 == d2);
    }
    
    rep(i, n - 2) {
        if (vec[i] && vec[i + 1] && vec[i + 2]) {
            cout << "Yes\n";
            return 0;
        }
    }
    
    cout << "No\n";
}


Measured memory_bytes: 3612
n = gets.to_i
points = readlines.map{|s| s.split.map(&:to_i)}

def d(p1, p2)
  Math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
end

g = Array.new(n) {Array.new(n){0}}

(0...n).each do |i|
  (0...n).each do |j|
    next if i == j
    g[i][j] = d(points[i], points[j])
  end
end

puts g.flatten.reduce(:+) / n

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int a=0,b=0,c=0;
    for(int i=0;i<3;i++){
        if(s[i]=='a')a++;
        if(s[i]=='b')b++;
        if(s[i]=='c')c++;

    }
    if(a==1&&b==1&&c==1)
        cout<<"Yes"<<"\n";
    else 
        cout<<"No"<<"\n";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))
ans = 0
for x in t:
	low,up = 0,n
	while up - low > 1:
		mid = (up + low) // 2
		if s[mid] <= x:
			low = mid
		else:
			up = mid
	ans += (x == s[low])
print(ans)


Measured memory_bytes: 16712
# -*- coding: utf-8 -*-
import sys

def main():
	y, x = map(int, input().split(" "))
	
	lines = []
	for ii in range(y):
		line = input()
		lines.append(list(line))
	
	for i, val in enumerate(lines):
		for j, vol in enumerate(val):
			if vol == ".":
				counts = 0
				if i != 0:
					if lines[i - 1][j] == "#":
						counts = counts + 1
				if (y - 1) > i:
					if lines[i + 1][j] == "#":
						counts = counts + 1
				if j != 0:
					if lines[i][j - 1] == "#":
						counts = counts + 1
				if (x - 1) > j:
					if lines[i][j + 1] == "#":
						counts = counts + 1
				if i != 0 and j != 0:
					if lines[i - 1][j - 1] == "#":
						counts = counts + 1
				if (y - 1) > i and (x - 1) > j:
					if lines[i + 1][j + 1] == "#":
						counts = counts + 1
				if i != 0 and (x - 1) > j:
					if lines[i - 1][j + 1] == "#":
						counts = counts + 1
				if j != 0 and (y - 1) > i:
					if lines[i + 1][j - 1] == "#":
						counts = counts + 1
				print("{}".format(counts), end = "")
			else:
				print("#", end = "")
		print("")
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3572
n = int(input())
h_ls = list(map(int, input().split()))
h_ls.insert(0,0)
h_ls.append(0)

change_count = 0

while True:
    for i in range(n+1):
        status = [0] * 2
        if h_ls[i] == 0:
            status[0] = 'zero'
        else:
            status[0] = 'not_zero'
        if h_ls[i+1] == 0:
            status[1] = 'zero'
        else:
            status[1] = 'not_zero'
        if status[0] != status[1]:
            change_count+= 1
    for i in range(n+2):
        if h_ls[i] != 0:
            h_ls[i] -= 1
    if h_ls == [0] * (n+2):
        break

count = change_count // 2
print(count)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    long long int n,p[100]={0};
    cin>>n;
    p[0]=2,p[1]=1;
    for(int i=2;i<n+1;i++){
        p[i]+=p[i-1]+p[i-2];
    }
   cout<<p[n]<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int n = Integer.parseInt(str);
			int[] count = new int[128];
			Arrays.fill(count, 0);
			for(int i = 0; i< n;i++) {
				int[] co = new int[128];
				Arrays.fill(co, 0);
				str = br.readLine();
				for(int j = 0;j < str.length();j++) {
					co[(int)str.charAt(j)]++;
				}
				if(i==0) {
					count = co;
				}else {
					for(int j = 0; j < 128;j++) {
						if(count[j] > co[j]) {
							count[j] = co[j];
						}
					}
				}
			}
			for(int i = 0; i< 128;i++) {
				for(int j = 0; j< count[i];j++) {
					System.out.print((char)i);
				}
			}
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;

int main(void) 
{
    int d,t,s;
    cin >> d >> t >> s;
    if (d<=t*s){
        cout << "Yes" << endl;
    } 
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
#define MAX 200009
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
bool sortbyme(const pair<int,int> &a, 
              const pair<int,int> &b){
	return (a.first+a.second > b.first+b.second);

}
struct test 
{ 
   int x, y, z; 
}; 
// ll n;
// ll m;
// ll k;

// vector<pair<ll,ll>> v;
// ll vis[500000];
// ll dist[500000];

// void dfs(ll node){
//     vis[node]=1;
//     for(auto i:v[node]){
//         if(vis[i]==0){
//             dfs(i);
            
//         }
//     }
// }
// void bfs(ll node){
//     queue<ll> q;
//     vis[node]=1;
//     dist[node]=0;
    
//     q.push(node);
//     while(!q.empty()){
//         ll curr=q.front();
//         q.pop();
        
//         for(auto i:v[curr]){
//             if(vis[i]==0){
//                 vis[i]=1;
//                 dist[i]=dist[curr]+1;
//                 q.push(i);
                
                
//             }
//         }
        
//     }
// }




void solve(){

ll n;
cin>>n;
vector<pair<ll,ll>> v;
for(ll i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    v.pb({a,b});
}
ll cc=0;

   for(ll i=0;i<n;i++){
       if(v[i].first==v[i].second)cc++;
       else
       cc=0;
       
       if(cc==3){
           cout<<"Yes"<<endl;
           return;
           
       }
   }
   cout<<"No"<<endl;
   
return;
}



int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    

    ll t;
    t=1;
   // cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}


int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long n, k;
    cin >> n >> k;

    long long zero = 0;
    long long half = 0;

    for(int i = 1; i <= n; ++i){
        if((k & 1) == 0 && i % k == (k >> 1))
            ++half;
        if(i % k == 0)
            ++zero;
    }

    long long tot = 0;

    tot += half * half * half;

    tot += zero * zero * zero;

    cout << tot;

    return 0;
}


Measured memory_bytes: 256
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
)

func main() {
        var n int
        fmt.Scan(&n)
        sc := bufio.NewScanner(os.Stdin)
        sc.Split(bufio.ScanWords)
        s := make([]int, n)
        for i := 0; i < n; i++ {
                sc.Scan()
                a, _ := strconv.Atoi(sc.Text())
                s[i] = a
        }
        step := 0
        pos := 1
        visited := map[int]struct{}{}
        for true {
                pos = s[pos-1]
                step++
                if pos == 2 {
                        break
                }
                if _, v := visited[pos]; v {
                        step = -1
                        break
                }
                visited[pos] = struct{}{}
        }
        fmt.Printf("%d\n", step)
        return
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


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

    int n; cin >> n;
    ll W; cin >> W;
    vector<ll> w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];

    const ll inf = 1LL<<60;
    // dp[i][j] := i 番目まで見て、価値の合計 j を達成するために必要な最小な重さ（存在しなければinf）
    vector<vector<ll>> dp(n+5, vector<ll>(100005, inf));
    dp[0][0]=0;
    rep(i, n){
        rep(j, 100001){
            chmin(dp[i+1][j], dp[i][j]);
            if(j-v[i]>=0) chmin(dp[i+1][j], dp[i][j-v[i]]+w[i]);
        }
    }

    ll ans=0;
    rep(j, 100001) if(dp[n][j]<=W) ans=j;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 83328
def main():
    n, k, q = map(int, input().split())

    answer_dict = {}

    for _ in range(q):
        a = int(input())
        if a in answer_dict:
            answer_dict[a] += 1
        else:
            answer_dict[a] = 1

    for i in range(n):
        if i+1 in answer_dict:
            if k - q + answer_dict[i+1] > 0:
                print("Yes")
                continue
        else:
            if k - q > 0:
                print("Yes")
                continue

        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    char S[110];
   
    cin>>N;
    for(int i=0;i<N;i++)cin>>S[i];
    int maxv =0;
    int count=0;
    for (int i=0;i<N;i++){
        if(S[i]=='I'){
            count++;
        }
        else {
            count--;
        }
        maxv=max(maxv,count);
        
    }
    cout<<maxv<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdio>

using namespace std;
#define MP make_pair
typedef pair<int,int> PII;

int main(){
  int N;

  while(cin >> N, N){
	vector<PII> tm(N);
	int range[24*60*60+1];
	fill(range, range+24*60*60+1, 0);
	for(int i=0;i<N;++i){
	  int h1, m1, s1, h2, m2, s2;
	  scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
	  tm[i].first = s1+m1*60+h1*60*60;
	  tm[i].second = s2+m2*60+h2*60*60;
	  range[tm[i].first]++;
	  range[tm[i].second]--;
	}

	int ans = 0, sum = 0;
	for(int i=0;i<24*60*60+1;++i){
	  sum += range[i];
	  ans = max(ans, sum);
	}

	cout << ans << endl;
  }
}

Measured memory_bytes: 1652
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author lstd
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}



void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using namespace std;

class BRollerCoaster {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, k;
		in >> n >> k;

		int h[100005], ans = 0;
		REP(i,n)
			in >> h[i], ans += (h[i] >= k);

		out << ans;

	}
};

int main() {
	BRollerCoaster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
int x,y;
scanf("%d%d",&x,&y);
if((x>=1 && x<=12)&&(y>x && y<=12))
{
    if(x==2||y==2){
        printf("No\n");
    }
    else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
    {
        printf("Yes\n");
    }
    else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))
    {
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

}
return 0;
}


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

int main(){
  //全部でN枚
  int N;
  cin >> N;
  int alice=0;
  int bob=0;
  int result;
  vector<int> all_num(N);
  
  for(int i=0;i<N;i++){
    cin >> all_num.at(i);
  }
  
  sort(all_num.begin(),all_num.end());
  reverse(all_num.begin(),all_num.end());
  
  for(int j=0; j<N; j++){
    if(j % 2 == 0){
      alice += all_num.at(j);
    }
    else{
      bob += all_num.at(j);
    }
  }
  
  result = alice - bob;
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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 (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int a,b; cin >> a >>b;
  cout << max(0, a-2*b) << endl;
  return 0;
}


Measured memory_bytes: 256
/*
diverta 2019 Programming Contest A
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

int main()
{
    int n, ans = 0;
    std::cin >> n;
    std::vector<std::string> s(n);
    for (int i = 0; i < n; i++)
        std::cin >> s[i];

    int cnt_ab = 0;
    int cnt_top_b = 0;
    int cnt_last_a = 0;
    int cnt_ba = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i][0] == 'B' && *(s[i].end() - 1) == 'A')
        {
            cnt_ba++;
        }
        else if (s[i][0] == 'B')
        {
            cnt_top_b++;
        }
        else if (*(s[i].end() - 1) == 'A')
        {
            cnt_last_a++;
        }
        for (auto itr = s[i].begin(); itr < s[i].end() - 1; itr++)
        {
            if (*itr == 'A' && *(itr + 1) == 'B')
                cnt_ab++;
        }
    }

    if (cnt_ba > 0)
    {
        cnt_ab = cnt_ab + cnt_ba - 1;
        if (cnt_top_b > 0)
        {
            cnt_ab++;
            cnt_top_b--;
        }
        if (cnt_last_a > 0)
        {
            cnt_ab++;
            cnt_last_a--;
        }
    }

    std::cout << cnt_ab + std::min(cnt_top_b, cnt_last_a) << std::endl;

    return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;


int main() {
    ll N, p = 1, MOD = 1000000007;
    cin >> N;
    REP(i, N) {
        p = p * (i+1) % MOD;
    }
    cout << p << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>

using namespace std;

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

    set <string> substrings;

    for(int length = 1; length <= 5; length++)
    {
        for(int i = 0; i + length - 1 < S.size(); i++)
        {
            substrings.insert(S.substr(i, length));
        }
    }

    int i = 1;
    for(set <string> :: iterator it = substrings.begin(); it != substrings.end() && i <= k; it++, i++)
    {
        if(i == k)
        {
            cout << *it;
        }
    }

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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 (a > b) {
    a = b;
    return true;
  }
  return false;
}
vector<vector<int>> vec;
int n;
vector<int> color;
vector<set<int>> color_inv;
void bsf(int s, int c) {
  queue<int> q;
  q.push(s);
  color[s] = c;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    rep(v, 0, vec[u].size()) {
      if (color[vec[u][v]] != -1)
        continue;
      color[vec[u][v]] = c;
      q.push(vec[u][v]);
    }
  }
}
int assignColor() {
  // O(|V|+|E|)
  int cnt = 0;
  rep(i, 0, n) {
    if (color[i] == -1) {
      bsf(i, cnt);
      cnt++;
    }
  }
  return cnt;
}

int and_set(set<int> a, set<int> b) {
  int ret = 0;
  for (auto x : a) {
    if (b.count(x))
      ret++;
  }
  return ret;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;
  vec.resize(N);
  color.resize(N, -1);
  n = N;

  vector<int> p(N);
  rep(i, 0, N) {
    cin >> p[i];
    p[i]--;
  }
  vector<int> x(M), y(M);
  rep(i, 0, M) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;

    vec[x[i]].push_back(y[i]);
    vec[y[i]].push_back(x[i]);
  }

  int cnt = assignColor();
  dump(cnt);

  color_inv.resize(cnt,set<int>());
  vector<set<int>> st(cnt,set<int>());
  dump(color);

  rep(i, 0, N) {
    dump(i,color[i]);

    color_inv[color[i]].insert(i);
    st[color[i]].insert(p[i]);
  }
  dump(color,color_inv,st);
  int ans = 0;

  rep(i, 0, cnt) { ans += and_set(color_inv[i], st[i]); }

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


Measured memory_bytes: 26112
#include <stdio.h>
#include <string.h>

int remain(int n)
{

  int i,f[n],count;
  char fs[0];
  
  count=0;
  for(i=0;i<n;i++){
    scanf("%s", fs);
    if(strcmp(fs,"lu")==0)
      f[i]=0;
    if(strcmp(fs,"ld")==0)
      f[i]=1;
    if(strcmp(fs,"ru")==0)
      f[i]=2;
    if(strcmp(fs,"rd")==0)
      f[i]=3;
  }
  for(i=0;i<n-1;i++){
    if(f[i]==0&&f[i+1]==2||
       f[i]==2&&f[i+1]==0||
       f[i]==1&&f[i+1]==3||
       f[i]==3&&f[i+1]==1)
      count=count+1;
  }
  return (count);
}

int main(void)
{

  int n,c;
  
  while(1){
    scanf("%d", &n);
    if(n==0)break;
    c=remain(n);
    printf("%d\n", c);
  }
  
  return 0;
}

Measured memory_bytes: 604