akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
  if b[i] >= a[i] + a[i+1]:
    ans += a[i] + a[i+1]
    a[i] = 0
    a[i+1] = 0
  else:
    ans += b[i]
    if b[i] >= a[i]:
      tmp = b[i] - a[i]
      a[i] = 0
      a[i+1] -= tmp
print(ans)      

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

using ll=long long;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
    int r,c,m;
    cin>>r>>c>>m;
    vector<string> f(r);
    for(int i=0;i<r;i++) cin>>f[i];
    vector<vector<ll>> keep(r,vector<ll>(c,0));
    vector<vector<ll>> turn(r,vector<ll>(c,0));
    for(int i=0;i<r;i++) for(int j=0;j<c;j++) cin>>keep[i][j];
    for(int i=0;i<r;i++) for(int j=0;j<c;j++){
        ll tmp; cin>>tmp;
        turn[i][j]+=tmp;
    }
    for(int i=0;i<r;i++) for(int j=0;j<c;j++){
        ll tmp; cin>>tmp;
        turn[i][j]+=tmp;
    }
    vector<pair<int,int>> task(m);
    for(int i=0;i<m;i++) cin>>task[i].first>>task[i].second;

    auto isBlank=[&](int x,int y){
        return 0<=x && x<r && 0<=y && y<c && f[x][y]=='.';
    };
    function<bool(int,int,int,int,int,int,stack<pair<int,int>>&)> getPath=
    [&](int x,int y,int tx,int ty,int px,int py,stack<pair<int,int>> &st){
        if(!isBlank(x,y)) return false;
        if(x==tx && y==ty) return true;
        for(int i=0;i<4;i++){
            if(x+dx[i]==px && y+dy[i]==py) continue;
            if(getPath(x+dx[i],y+dy[i],tx,ty,x,y,st)){
                st.push({x,y});
                return true;
            }
        }
        return false;
    };
    ll t=0;
    vector<vector<ll>> prev(r,vector<ll>(c,-1));
    auto getCost=[&](int x,int y){
        ll ret=prev[x][y]==-1 ? turn[x][y] : min(turn[x][y],(t-prev[x][y])*keep[x][y]);
        prev[x][y]=t++;
        return ret;
    };
    ll res=0;
    for(int i=0;i+1<m;i++){
        int sx=task[i].first,sy=task[i].second;
        int tx=task[i+1].first,ty=task[i+1].second;
        stack<pair<int,int>> path;
        getPath(sx,sy,tx,ty,-1,-1,path);
        while(!path.empty()){
            auto tmp=path.top(); path.pop();
            res+=getCost(tmp.first,tmp.second);
        }
    }
    res+=getCost(task.back().first,task.back().second);
    cout<<res<<endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define pp pop_back
#define F first
#define S second
#define endl "\n"

typedef long long ll;
typedef long double ld;

void INeedIt() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}   
int l[101];  
int main () {
	INeedIt();
	int n, sum=0;
	cin>>n;
	for (int i=0;i<n;i++) {
		cin>>l[i];
		sum+=l[i];
	}
	sort(l, l+n);
	if (sum-l[n-1]>l[n-1]) {
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}
 

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  set<int> st;
  int query; cin >> query;

  for (int i = 0; i < query; ++i) {
    int op, x; cin >> op >> x;
    if (op == 0) {
      st.insert(x);
      cout << st.size() << '\n';
    } else {
      cout << (st.find(x) != st.end()) << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 12464
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

int main(){
	int N;
	map<string,int> info;
	int M;
	
	cin >> N;
	for(int i = 0 ; i < N ; i++){
		string s; cin >> s;
		info[s] = 0;
	}
	int T = 0;
	cin >> M;
	for(int i = 0 ; i < M ; i++){
		string t;
		cin >> t;
		if( info.count(t) == 0 ){
			cout << "Unknown" << " " << t << endl;
			continue;
		}else if(T == 0 ){
			cout << "Opened by " << t << endl;
		}else{
			cout << "Closed by " << t << endl;
		}
		T ^= 1;
	}
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,c[11][11],p[6];

int len(int x)
{
    int dem=0;
    while (x)
    {
        dem++;
        x/=10;
    }
    return dem;
}

void process()
{
    p[0]=1;
    for (int i=1;i<=6;++i)
        p[i]=p[i-1]*10;
    for (int i=1;i<=n;++i)
    {
        int mod=p[len(i)-1];
        c[i/mod][i%10]++;
    }
    int kq=0;
    for (int i=0;i<=9;++i)
    {
        for (int j=0;j<=9;++j)
        {
            kq+=c[i][j]*c[j][i];
        }
    }
    cout<<kq;
}

int main()
{
    cin>>n;
    process();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    char a[256];
  	char b[256];
  	char result[512];
  	int counterA = 0;
  	int counterB = 1;
  	int N;
  	scanf("%d",&N);
  	scanf("%s %s",a,b);
  	for (int i = 0; i < N*2; i++) {
      if (i % 2 == 0) {
        result[i] = a[i-counterA];
        printf("%c",a[i-counterA]);
        counterA++;
      } else {
        result[i] = b[i-counterB];
        printf("%c",b[i-counterB]);
        counterB++;
      }
    }
    return 0;
}


Measured memory_bytes: 128
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Sum of product of pairs
	var N int
	fmt.Scanf("%d", &N)

	sc.Split(bufio.ScanWords)
	A := make([]int, N)
	var sum int
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		sum += A[i]
		sum = sum % (int(math.Pow10(9)) + 7)
	}

	var ans int
	for i := 0; i < N; i++ {
		sum -= A[i]
		if sum < 0 {
			sum += int(math.Pow10(9)) + 7
		}
		ans += A[i] * sum
		ans = ans % (int(math.Pow10(9)) + 7)
	}

	fmt.Println(ans)
}


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


#define ll                      long long
#define pii                     pair<int, int>
#define pli                     pair<ll, int>
#define pil                     pair<int, ll>
#define pll                     pair<ll, ll>
#define vi                      vector<int>
#define vll                     vector<ll>
#define vb                      vector<bool>
#define vd                      vector<double>
#define vs                      vector<string>
#define ff                      first
#define ss                      second
#define pb                      push_back
#define eb                      emplace_back
#define ppb                     pop_back
#define pf                      push_front
#define ppf                     pop_front
#define vpii                    vector<pii>
#define vpll                    vector<pll>
#define umap                    unordered_map
#define all(x)                  x.begin(),x.end()
#define clr(a,b)                memset(a,b,sizeof a)
#define fr(i, n)                for(ll i=0; i<n;++i)
#define fr1(i, n)               for(ll i=1; i<=n; ++i)
#define rfr(i, n)                for(ll i=n-1; i>=0; --i)
#define precise(x)              cout<<fixed<<setprecision(x)
#define wh                        while
#define mp                        make_pair
#define le                        length()



ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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

ll power(ll x,ll y,ll p) 
{ ll res=1; x=x%p;
    while(y>0) 
    { if (y&1) res=(res*x)%p; 
      y=y>>1; x=(x*x)%p; } 
    return res; } 
    
bool inside(ll x,ll y,ll n,ll m)
{
    return(x>=0&&x<n&&y>=0&&y<=m);
}   


/*void dfs(int s)
{
        if(vis[s])return;
        
        vis[s]=true;
        nodes++;
        for(auto u:g[s])
        {
            if(!vis[u])
            {
                dfs(u);    
            }        
        }
}*/

void solve()
{    
	ll n;
	cin>>n;
	if(n%1000==0)
	{
		cout<<"0"<<endl;
		return;
	}
	cout<<1000-(n%1000 )<<endl;
}

int main()
{
//    int t;
//    cin>>t;
//    wh(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3636
from collections import deque
k = int(input())

q = deque([i for i in range(1,10)])
for i in range(1,k+1):
  x = q.popleft()
  if i == k:
    print(x)
    exit()
  
  if x%10 != 0:
    q.append(10*x+x%10-1)
    
  q.append(10*x+x%10)
  
  if x%10 != 9:
    q.append(10*x+x%10+1)
    

Measured memory_bytes: 11908
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef vector <bool> v_bool;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

string S;
ll N,ans;
int main(){
  cin >> N >> S;
  for (ll d=1;d<N;d++){
    ll x=0,y=0;
    for (ll i=0;i+d<N;i++){
       if (S[i]==S[i+d]){
         x++;
         if (x>y)y=x;
       }
       else {
         x=0;
       }
    }
    if (y>d) y=d;
    if (y>ans) ans=y;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K = map(int, input().split())

ans = 0
for k in range(1, K+1):
    print(cmb(K-1, k-1, mod) * cmb(N-K+1, k, mod) % mod)


Measured memory_bytes: 4596
#include <iostream>

using namespace std;

int main()
{
    string s;
    char a1 , a2;
    cin >> s;
    a1 = s[0];
    if (s[1] == a1){
        if (s[2] == a1){
            cout << "No";
            return 0;
        }else if (s[3] == a1){
            cout << "No";
            return 0;
        }else if (s[2] == s[3]){
            cout << "Yes";
            return 0;
        }else{
            cout << "No";
            return 0;
        }
    }else{
        a2 = s[1];
        if (s[2] == a1){
            if (s[3] == a2){
                cout << "Yes";
                return 0;
            }else{
                cout << "No";
                return 0;
            }
        }else if (s[2] == a2){
            if (s[3] == a1){
                cout << "Yes";
                return 0;
            }else{
                cout << "No";
                return 0;
            }
        }else{
            cout << "No";
            return 0;
        }
    }
    return 0;
}


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

int d;
vector<int> c(26), last(26, -1);
vector<vector<int>> s;

void input() {
    cin >> d;
    s = vector<vector<int>>(d, vector<int>(26));

    for (int& i : c) cin >> i;
    for (auto& v : s)
        for (int& i : v) cin >> i;
}

int f(int contest, int day) {
    int k = 0;
    for (int i = 0; i < 26; ++i) {
        if (i == contest)
            k += s[day][i];
        else
            k -= c[i] * (day - last[i]);
    }
    return k;
}

int main() {
    input();
    int sum = 0;
    for (int day = 0; day < d; ++day) {
        int mf = f(0, day), mi = 0;
        for (int i = 1; i < 26; ++i) {
            int fi = f(i, day);
            if (mf < fi) mf = fi, mi = i;
        }
        cout << mi + 1 << endl;
        last[mi] = day;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main() {
  string S;
  int paint = 0;
  cin >> S;
  for(int i = 1; i < (int)S.length(); i++){
    if(S[i] == S[i-1]){
      if(S[i] == '0'){
	S[i] = '1';
      }
      else if(S[i] == '1'){
	S[i] = '0';
      }
      paint += 1;
    }
  }
  printf("%d\n", paint);
  return 0;
}


Measured memory_bytes: 512
n=int(input())
a=input()
b=input()
for i in range(n):
	cnt=0
	if a[i]==b[0]:
		j=i
		while j<n:
			if a[j]!=b[j-i]:
				break
			else:
				cnt+=1
				j+=1
	if cnt==n-i:
		print(n+i)
		exit()
print(n*2)


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

int main(){
    int n,t; cin >> n >> t;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int,int> mp;
    int sub=0;
    int res=a[0];//差の最大値
    rep(i,n-1){
        if(res<a[i+1]){
            int s = a[i+1]-res;
            mp[s]++;
            if(s>sub){
                sub=s;
            }
        }else{
            res=a[i+1];
        }
    }
    cout << mp[sub] << endl;
    //cout << sub << endl;
    return 0;
}

Measured memory_bytes: 5376
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)


int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    ll s=0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                s+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<s<<endl;
    End
}
/* pray for me
Do before die
*/


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll counter(ll a, ll b, ll q)
{
    ll a_q, b_q;
    if (a % q == 0)
        a_q = a / q;
    else
        a_q = a / q + 1;
    b_q = b / q;

    return (b_q - a_q + 1);

}

int main(int argc, char const *argv[]) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    ll _c = counter(a, b, c);
    ll _d = counter(a, b, d);
    ll cd = counter(a, b, c/__gcd(c,d) * d);

    ll ans = (b - a + 1) - _c - _d + cd;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

main(void)
{
  char moji[11];
  int i;
  int count=0;
  int tuyoi=0;
  
  scanf("%s",moji);
 
  
 
  for(i=0;i<=10;i++)
  {
    if(('A'==moji[i])||('T'==moji[i])||('C'==moji[i])||('G'==moji[i]))
      count++;
    
    else
    {
      if(count>=tuyoi)
        tuyoi = count;
      count = 0;
    }
  }
  printf("%d",tuyoi);
  
  return 0;
}

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

int main() {
    int n, m, sum = 0;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i], sum += a[i];
    sort(a.rbegin(), a.rend());
    rep(i,m) {
        if (a[i] * 4 * m < sum) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String str[] = br.readLine().split(" ");
	int A = Integer.parseInt(str[0]);
	int B = Integer.parseInt(str[1]);
	if (B + B < A)
	    System.out.println(A - (B + B));
	else
	    System.out.println(0);
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
/******* MY EVERY AC WILL BE A TRIBUTE TO SSR ********/
#define vi vector
#define lli long long int
#define vli vi<lli>
#define pb push_back
#define pll pair<lli,lli>
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(),greater<lli>()
#define clear(x) x.clear()
#define rep(i,n) for(lli i=0;i<(lli)n;i++)
#define rep1(i,n) for(lli i=1;i<=(lli)n;i++)
#define rep2(i,n) for(lli i=1;i<(lli)n;i++)
#define refor(i,n) for(lli i=(lli)n;i>=0;i--)
#define range(i,l,r) for(lli i=(lli)l;i<=(lli)r;i++)
#define big(x,y) (x>y)?x:y
#define small(x,y) (x<y)?x:y
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
using namespace std;
lli gcd(lli a,lli b) {return b==0?a:gcd(b,a%b);}
lli lcm(lli a,lli b) {return (a*b)/gcd(a,b);}
bool isprime(lli x) {for(lli i=2;i<=sqrt(x);i++) { if(x%i == 0) return false;} return true;}
lli modpow(lli x,lli y) {x%=mod;lli res=1;while(y>0){if(y&1) res*=x%mod; y=y>>1; x=x*x%mod;} return res%mod;}
lli ncr(lli n,lli k) {lli res=1; if(k>n-k) k=n-k; rep(i,k){res*=(n-i);res/=(i + 1);} return res;}
lli bintodec(lli n) {lli decimal=0,i=0,rem;while (n!=0){rem = n%10;n/=10;decimal += rem*pow(2,i);++i;}return decimal;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    lli i,n,s=0,ans=0;
    vli a;
    string s1;
    cin>>s1;
    rep(i,s1.length())
    { if(s1[i]=='R')
        s++;
      else
	  { a.pb(s);
	   s=0;
		}  
	}
	a.pb(s);
	sort(all(a));
	cout<<a[a.size()-1];

    return 0;
}











Measured memory_bytes: 3636
S = list(input())
dif_min = 10**9
for i in range(len(S)-2):
    if dif_min > abs(int(S[i]+S[i+1]+S[i+2])-753):
        dif_min = abs(int(S[i]+S[i+1]+S[i+2])-753)
print(dif_min)

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

int n;
const int N=3e5 +5;
int E[N], W[N];
char a[N];

int main(){

    scanf("%d", &n);
    scanf(" %s", a);

    for(int i=1; i<=n; ++i){
        E[i]=E[i-1]+(a[i-1]=='E');
        W[i]=W[i-1]+(a[i-1]=='W');
    }

    int mn=n;
    for(int i=0; i<n; ++i){
        int num=W[i]+(E[n]-E[i+1]);
        mn=min(mn, num);
    }

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

    return 0;
}


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

using namespace std;

const int ms = 2e5 + 17;

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

    int a, b, c;
    cin >> a >> b >> c;

    if(a + b >= c)
        cout << "Yes\n";
    else
        cout << "No\n";




}


Measured memory_bytes: 896
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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


	bool flag = false;
	for (int i = A; i <= B; i++) {
		if (i % K == 0) flag = true;
	}

	if (flag) cout << "OK" << "\n";
	else cout << "NG" << "\n";

	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int a[200000];
int n;
signed main(){
    int ans=1;
    bool zero=false;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        if(a[i]==0)zero=true;
    }
    if(zero){
        cout<<0<<endl;
        return 0;
    }
    rep(i,n){
        if(ans>1000000000000000000/a[i]){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
string s,t;
ll ans[55];
ll M=1000000007;
int main(void){
    cin>>n;
    cin>>s>>t;
    if(s[0]==t[0]){
        ans[0]=3;
    }else{
        ans[1]=6;
    }
    for(int i=1;i<n;i++){
        if(ans[i]==0){
            if(s[i-1]==t[i-1]){
                if(s[i]==t[i]){
                    ans[i]=ans[i-1]*2%M;
                }else{
                    ans[i]=ans[i-1]*2%M;
                    ans[i+1]=ans[i];
                }
            }else{
                if(s[i]==t[i]){
                    ans[i]=ans[i-1];
                    //ans[i+1]=ans[i-1];
                }else{
                    ans[i]=ans[i-1]*3%M;
                    ans[i+1]=ans[i];
                }
            }
        }
        //cout<<ans[i]<<endl;
    }
    cout<<ans[n-1]<<endl;
    
}


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

#A
def A():
    def parse_hash(s,i):
        if s[i] == "[":
            i += 1
            op,i = parse_op(s,i)
            h1,i = parse_hash(s,i)
            h2,i = parse_hash(s,i)
            i += 1
            return calc(op,h1,h2),i
        else:
            return parse_letter(s,i)

    def parse_op(s,i):
        return s[i],i+1

    def parse_letter(s,i):
        return s[i],i+1

    def calc(op,h1,h2):
        if op == "+":
            return h1|h2
        elif op == "*":
            return h1&h2
        else:
            return h1^h2

    while 1:
        s = S()
        if s[0] == ".":
            break
        t = S()
        n = len(s)
        s0 = [s[i] for i in range(n)]
        for i in range(n):
            if s0[i] == "a":
                s0[i] = int(t[0])
            elif s0[i] == "b":
                s0[i] = int(t[1])
            elif s0[i] == "c":
                s0[i] = int(t[2])
            elif s0[i] == "d":
                s0[i] = int(t[3])
        p = parse_hash(s0,0)[0]
        ans = 0
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        s0 = [s[i] for i in range(n)]
                        for i in range(n):
                            if s0[i] == "a":
                                s0[i] = a
                            elif s0[i] == "b":
                                s0[i] = b
                            elif s0[i] == "c":
                                s0[i] = c
                            elif s0[i] == "d":
                                s0[i] = d
                        p0 = parse_hash(s0,0)[0]
                        if p == p0:
                            ans += 1
        print(p,ans)

    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    A()



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

using namespace std;

const int N = 3e5 + 50;

map<int, int> mp;
int n;

int main()
{
#ifdef ONLINE_JUDGE
#else
    // freopen("r.txt", "r", stdin);
// freopen("w.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin >> n;
    for (int x, i = 1; i <= n; i++)
    {
        cin >> x;
        mp[x]++;
        if (mp[x] == 2)
        {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}

Measured memory_bytes: 9600
fun main() {
    var s = readLine()!!
    var mod = IntArray(2019, { 0 })
    var ans = 0
    for (i in 0 until s.length) {
        var tmp = IntArray(2019, { 0 })
        for (j in 0 until 2019) {
            if (mod[j] == 0) continue
            var nxt = (j * 10 + (s[i] - '0')) % 2019
            if (nxt == 0) ans += mod[j]
            tmp[nxt] = mod[j]
        }
        tmp[s[i] - '0']++
        mod = tmp
    }
    print(ans)
}

Measured memory_bytes: 56760
import bisect


n = int(input())
a = list(map(int, input().split()))

group = {}
for i in range(n):
    ntz = a[i] & (-a[i])
    if ntz not in group:
        group[ntz] = {}
        group[ntz][a[i] // (ntz*2)] = 1
    elif a[i] // (ntz*2) not in group[ntz]:
        group[ntz][a[i] // (ntz*2)] = 1
    else:
        group[ntz][a[i] // (ntz*2)] += 1
      

ans = 0
for ntz in group:
    li = sorted(group[ntz].keys(), reverse = True)
    for num1 in li:
        if num1 == 0:
            tmp_ans = group[ntz][num1] // 2
            ans += tmp_ans
            group[ntz][num1] -= tmp_ans * 2
            continue
        tmp = len(bin(num1)) - 2
        num2 = num1 ^ (2**tmp - 1)
        if num2 in group[ntz]:
            tmp_ans = min(group[ntz][num1], group[ntz][num2])
            ans += tmp_ans
            group[ntz][num1] -= tmp_ans
            group[ntz][num2] -= tmp_ans
print(ans)


Measured memory_bytes: 104528
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# define MOD 1000000000+7
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c >= a&&c <= b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
 
int main() {
    int N;
    cin >> N;
    vector<ll>A(N,0);
    vector<int>B(N,0);
    for(ll &i:A)cin >> i;
    for(int &i:B)cin >> i;
    
    int it=0;
    for(int i=1;i<N;i++)if(A[it]<A[i])it=i;
    
    rotate(A.begin(), A.begin()+it, A.end());
    rotate(B.begin(), B.begin()+it, B.end());
    A.push_back(A.front());
    B.push_back(B.front());
    vector<ll> C(N+1,0);
    for(int i=1;i<N;i++)C[i+1]=2*(B[i]+C[i])-C[i-1];
   
    
    vector<pair<int,ll>> hull={make_pair(0,A[0]-C[0]),make_pair(1,A[1]-C[1])};
    
    auto flg = [&](pair<int,ll> sub3)->bool{
        if(hull.size()<2)return false;
        pair<int,ll> sub1 = hull[hull.size()-2],sub2=hull.back();
        return (sub3.first-sub1.first)*(sub1.second-sub2.second)>(sub1.second-sub3.second)*(sub2.first-sub1.first);
    };
    
    for(int i=2;i<=N;i++){
        
        pair<int,ll> sub3(i,A[i]-C[i]);
        
        while((bool)flg(sub3))hull.pop_back();
        
        hull.push_back(sub3);
        
    }
    
    ll Fp = 0;
    for(int i=1;i<hull.size();i++){
        int d = hull[i].first - hull[i-1].first;
        
        Fp += hull[i-1].second*(d+1) + hull[i].second*(d-1);
        
    }
    for(int i=0;i<N;i++)Fp+=C[i]*2;
    long double E = (long double)Fp/(2.0*N);
    
    printf("%.12Lf\n",E);
}


Measured memory_bytes: 13384
// Author: πα

#include <bits/stdc++.h>
using namespace std;
#define long int64_t

int main()
{
    int n, i, ans = 0;
    cin >> n;
    vector<int> v(n);
    for(i = 0; i < n; ++i)
        cin >> v[i];
    for(i = 1; i < n-1; ++i)
        ans += (max(v[i-1], v[i+1]) > v[i] and min(v[i-1], v[i+1]) < v[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
#w,h,x,y,r=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#素因数分解した結果を2次元配列にして返す
def prime_factorize(n):
    n_origin=n+0
    primelist=[]
    a=2
    while a*a<=n_origin:
        if n%a!=0:
            a+=1
            continue
        ex=0
        while n%a==0:
            ex+=1
            n=n//a
        primelist.append([a,ex])
        a+=1
    if n!=1:
        primelist.append([n,1])
    return primelist
dic={}
for i in range(1,n+1):
    pfs=prime_factorize(i)
    for pf in pfs:
        dic[pf[0]]=dic.get(pf[0],0)+pf[1]
#print(dic)
ans=1
mod=10**9+7
for v in dic.values():
    ans=(ans*(v+1))%mod
print(ans)



Measured memory_bytes: 42608
#include<bits/stdc++.h>
using namespace std;
char s[15];
int query(int x)
{
    printf("%d\n",x);
    fflush(stdout);
    scanf("%s",s);
    if(s[0]=='V') return 0;
    if(s[0]=='M') return 1;
    return 2;
}
int main()
{
    int n;scanf("%d",&n);
    int l=0,r=n-2;
    int k=query(0);
    if(k==0){return 0;}
    while(l<r)
    {
        int m=l+r>>1;
        int t;
        if(m&1) t=k==1?2:1;
        else t=k;
        int res=query(m);
        if(res==0){return 0;}
        if(res==t) l=m+1;
        else r=m-1;
    }
    for(int i=l;i<=l+1;i++)
        if(query(i)==0) break;
}


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


bool isprime(ll x){
    if(x==2)return true;
    if(x<2||x%2==0)return false;
    ll i=3;
    while(i<=pow(x,0.5)){
        if(x%i==0)return false;
        i=i+2;
    }
    return true;
}

int main() {
    int n,count=0;
    cin>>n;
    rep(i,n){
        ll a;
        cin>>a;
        if(isprime(a))count++;
    }
    cout<<count<<endl;
    
    return 0;
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,e,cont=0,c;
    cin>>n>>m>>e;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;;j++){
            if(((a[i]*j)+1)<=m){cont++;}
            else{break;}
        }
    }
    cout<<cont+e<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
def twopower(n):
    for i in range(32):
        if n < 2**i:
            return 2**i
N = int( input())
A = list( map( int, input().split()))
d = defaultdict( int)
e = defaultdict( int)
for i in range(N):
    d[A[i]] += 1
A.sort(reverse=True)
i = 0
ans = 0
while i < N:
    if e[A[i]] >= d[A[i]]:
        i += 1
        continue
    e[A[i]] += 1
    L = twopower(A[i]) - A[i]
    if e[L] < d[L]:
        ans += 1
        e[L] += 1
    i += 1
print(ans)


Measured memory_bytes: 146672
if __name__ == "__main__":
    n, x = map(int, input().split())
    boxes = list(map(int, input().split()))

    moves = 0
    if boxes[0] > x:
        moves = boxes[0] - x
        boxes[0] = x
    for i in range(n - 1):
        y = boxes[i] + boxes[i + 1] - x
        if y > 0:
            boxes[i + 1] -= y
            moves += y
    print(moves)       

Measured memory_bytes: 14592
#include<bits/stdc++.h>
#define ll long long

using namespace std;

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

int main()
{
	ll n,b;
	cin >> n >> b;
	
	vector< pair<ll,ll> >wtval;


	for(ll i=0;i<n;i++)
	{
		ll a;
		ll c;
		cin >> a;
		cin >> c;
		wtval.push_back((make_pair(a,c)));
	}

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

	// cout << "eee" << endl;
	// for(ll i=0;i<n;i++)
	// {
	// 	cout << wtval[i].first << " ";

	// }

	// cout << endl;

	ll dp[n][b+1];

	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<=b;j++)
		{
			dp[i][j] = 0;
		}
	}

	for(ll i=0;i<n;i++)
	{
		dp[i][0] = 0;
	}

	for(ll i=1;i<=b;i++)
	{
		if(i >= wtval[0].first)
			dp[0][i] = wtval[0].second;
	}

	// for(ll i=0;i<n;i++)
	// {
	// 	for(ll j=0;j<=b;j++)
	// 	{
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	// cout << " b is " << b << endl;

	for(ll i=1;i<n;i++)
	{
		for(ll j=1;j<=b;j++)
		{
			if(wtval[i].first <= j )
				dp[i][j] = max( (wtval[i].second + dp[i-1][j-wtval[i].first
					]), dp[i-1][j] );
			else
				dp[i][j] = dp[i-1][j];
		}
		// cout << i << endl;
		// for(ll i=0;i<n;i++)
		// {
			
		// 	for(ll j=0;j<=b;j++)
		// 	{
		// 		cout << dp[i][j] << " ";
		// 	}
		// 	cout << endl;
		// }

		// cout << endl;
	}

	cout << dp[n-1][b] << endl;

}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x%y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;


int main() {
	string W, temp;

	cin >> W;
	int ans = 0;


	transform(W.begin(), W.end(), W.begin(), ::tolower);

	while (cin >> temp) {

		if (temp == "END_OF_TEXT") break;

		transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
		if (W == temp) ans++;
	}
	cout << ans << endl;



}



Measured memory_bytes: 3204
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N; cin >> N;
  	
  	while(!(N/100 == N%10 and (N%100)/10 == N%10)) {
      ++N;
    }
  
    cout << N << endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc145/tasks/abc145_c



N = gets.to_i
xs = Array.new(N)
ys = Array.new(N)
N.times do |i|
  xs[i], ys[i] = gets.split.map(&:to_i)
end

ans = 0
N.times do |i|
  i.times do |j|
    ans += Math.hypot(xs[i] -xs[j], ys[i] - ys[j])
  end
end

puts ans * 2 / N


Measured memory_bytes: 1788
N = int(input())
W = list(map(int, input().split()))

Sum1 = 0
Sum2 = 0
SUM = []
dif = []

T=0

while T <= N-1:
  i = 0
  l = T+1
  Sum1 = 0
  Sum2 = 0
  while i <= T:
    Sum1 += W[i]
    i += 1
  while l <= N-1:
    Sum2 += W[l]
    l += 1
  
  dif.append(abs(Sum1-Sum2))
  T += 1
  
dif.sort()
print(dif[0])
    

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.nextLine());
        int[] M = new int[A];
        int max = 0;
        int cnt = 0;
        for (int i =0;i< A;i++) {
            M[i] = sc.nextInt();
            if(M[i] >=max) {
                cnt++;
            }
            max = Math.max(max,M[i]);
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
n, q = map(int, input().split())
s = input()
ac = [0] * n
c = 0
for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        c += 1
    ac[i] = c
for i in range(q):
    l, r = map(int, input().split())
    print(ac[r - 1] - ac[l - 1])
            

Measured memory_bytes: 6084
#include <bits/stdc++.h>
#define vi vector<int>
#define rep(i, xtz, n) for(int i=xtz; i<n; i++)

using namespace std;

int main(){
    //freopen("i.in", "r", stdin);
    long long int n, k; cin>>n>>k;
    vector<long long int> val(n), wei(n);
    rep(i, 0, n) cin>>wei[i]>>val[i];
    vector<vector<long long int>> dp(n+1, vector<long long int>(k+1, 0));
    rep(i, 0, n+1){
        rep(j, 0, k+1){
            if(i==0||j==0) dp[i][j]=0;
            else if(wei[i-1]<=j) dp[i][j] = max(dp[i-1][j-wei[i-1]]+val[i-1], dp[i-1][j]);
            else dp[i][j] = dp[i-1][j];
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
        }
    }
    cout<<dp[n][k];
}

Measured memory_bytes: 80256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.nextLine());
		int taro = 0;
		int hana = 0;

		for(int i=0; i<n; i++){
			String taroline = std.next();
			String hanaline = std.next();
			if(taroline.compareTo(hanaline)<0){hana+=3;}
			else if(taroline.compareTo(hanaline)==0){hana++; taro++;}
			else if(taroline.compareTo(hanaline)>0){taro+=3;}
		}
		System.out.println(taro+" "+hana);
	}
}

Measured memory_bytes: 28968
#include <bits/stdc++.h>
using namespace std;
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)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m; cin >> n >> m;
    vector<ll> a(n), cum(n);
    map<ll, ll> mp;

    for(int i=0; i<n; ++i) cin >> a[i];
    cum[0] = a[0];
    for(int i=1; i<n; ++i) cum[i] = cum[i-1] + a[i];

    for(int i=0; i<n; ++i) ++mp[cum[i]%m];

    ll ans = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); ++itr){
        if(itr->first == 0) ans += (itr->second+1)*itr->second/2;
        else ans += itr->second * (itr->second-1) / 2;
    }

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


Measured memory_bytes: 5760
function main(){
 
var seats = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var groupMembers = [2,5,2,2,2];
var eatTimes = [19,39,25,36,22,42];
 
var headGroup = -1;
var pastMinutes = 0;
var waitTime = [];
 
while(waitTime.length < 100){
  // たべおわる
  var slen = seats.length;
  for(; slen--;){
    seats[slen] = mx(seats[slen] - 1, 0);
  }
 
  // 来店
  if(headGroup == -1 && pastMinutes % 5 == 0){
    headGroup = pastMinutes / 5;
  }
 
  // ちゃくせき
  while(headGroup != -1){
    var needsSequencialSeats = groupMembers[headGroup % 5];
    var sequencialSeats = 0;
    var startIndex = -1;
    for(var i = 0, sl = seats.length; i < sl; i++){
      sequencialSeats = seats[i] == 0 ? sequencialSeats + 1 : 0;
 
      if(sequencialSeats == needsSequencialSeats){
        startIndex = i - (needsSequencialSeats - 1);
        break;
      }
    }
 
    if(startIndex != -1){
      // すわれたみたい
      waitTime[headGroup] = pastMinutes - (headGroup * 5);
      for(var i = startIndex, total = (needsSequencialSeats + startIndex); i < total; i++){
        seats[i] = eatTimes[headGroup % 6];
      }
       
      headGroup = (((headGroup + 1) * 5) <= pastMinutes) ? headGroup + 1 : -1;
    }else{
      // すわれなかったみたい
      break;
    }
 
  }
 
  pastMinutes++;
 
}
 
for(var i = 0, ilen = (input.length - 1); i < ilen; i++){
  console.log(waitTime[parseInt(input[i], 10)]);
}
 
}

function mx(a, b){
 var t = (a-b);
 return a - (t & (t >> 31));
}
 
var
input = '';
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 8628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
ll n,a[100005],sum,cnt1,cnt2;
int main(){
   cin>>n;
   for(int i=1;i<=n;i++) cin>>a[i];
   for(int i=1;i<=n;i++){
      sum+=a[i];
      if(i%2 && sum<=0){
         cnt1+=1-sum;
         sum=1;
      }
      if(i%2==0 && sum>=0){
         cnt1+=sum+1;
         sum=-1;
      }
   }
   sum=0;
   for(int i=1;i<=n;i++){
      sum+=a[i];
      if(i%2==0 && sum<=0){
         cnt2+=1-sum;
         sum=1;
      }
      if(i%2 && sum>=0){
         cnt2+=sum+1;
         sum=-1;
      }
   }
   cout<<min(cnt1,cnt2);
   return 0;
}

Measured memory_bytes: 4276
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323


#define TST 0

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;
    string str;
    cin >> str;
    int right = str.length()-1;
    int left = 0;
    int ans = 0;
    while(left < right){
    while(str[left] == 'R' && left < str.length()){
        left ++;
    }
    while(str[right]=='W' && 0 <= right){
        right --;
    }
    if(left >=right){
        cout << ans << endl;
        return 0;
    }
    char tmp = str[left];
    str[left] = str[right];
    str[right] = tmp;
    ans++;
    left++;
    right--;
    }
    cout << ans << endl;
    return 0;

#if TST==1

#endif
}



Measured memory_bytes: 3728
'use strict'

const INF = 900719925474099 // Number.MAX_SAFE_INTEGER / 10;

function Main(input){
	let temp = input.trim().split('\n');
	let temp2 = temp[0].split(' ').map((v)=>parseInt(v));
	let n = temp2.shift();
	let w = temp2.shift();
	let wv = new Array(n);

	for(let i=0;i<n;i++){
		wv[i] = temp[i+1].split(' ').map((v)=>parseInt(v));
	}

	let dp = [...new Array(n+10)].map(()=>(new Array(w + 10).fill(0)));
	
	//渡すDP
	for(let i=0;i<n;i++){
		for(let j=0;j<=w;j++){
			//入れる
			if(j + wv[i][0] <= w){
				dp[i+1][j+wv[i][0]] = Math.max(dp[i+1][j+wv[i][0]], dp[i][j] + wv[i][1]);
			}

			//入れない
			dp[i+1][j] = Math.max(dp[i+1][j],dp[i][j]);

		}
		//console.log(dp);
	}
	console.log(Math.max(...dp[n]));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
    string t;
    cin >> t;
    int l;
    l=t.size();
    rep(i,l){
        if(t[i]=='?'){
            t[i]='D';
        }
    }

    cout << t << endl;
    

    return 0;
}

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

#define F0R(i,n) for(int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define ROF(i,a,b) for(int i = (a); i >= (b); i--)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	FOR(i,1,5) {
		int x; cin >> x;
		if(x == 0) { 
			cout << i << "\n";
			return 0;
		}
	}
}


Measured memory_bytes: 3664
//package atcoderdp;
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
public class Main {
	static Scanner scn = new Scanner(System.in);
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int n = scn.nextInt();
		int k = scn.nextInt();
		int[] h = new int[n+100];
		for(int i =1;i<=n;i++) {
			h[i] = scn.nextInt();
		}
		int[] dp = new int[n+1];
		for(int i =2;i<=n;i++) {
			dp[i]=Integer.MAX_VALUE;
			for(int j = Math.max(1, i-k);j<i;j++) {
				dp[i] = Math.min(dp[i], dp[j]+Math.abs(h[i]-h[j]));
			}
		}
		System.out.println(dp[n]);
	}
}


Measured memory_bytes: 49076
class WeightedUnionFindTree:
    """Disjoint-Set Data Structure with weight

    complexity:
        - init: O(n)
        - find, unite, same: O(alpha(n))
    """

    def __init__(self, n_nodes):
        self.par = [i for i in range(n_nodes)]  # parent
        self.rank = [0] * n_nodes  # depth of tree
        self.weights = [0] * n_nodes

    def find(self, x):
        if self.par[x] == x:
            return x
        root = self.find(self.par[x])
        self.weights[x] += self.weights[self.par[x]]
        self.par[x] = root
        return root

    def unite(self, x, y, weight=0):
        root_x, root_y = self.find(x), self.find(y)
        if root_x == root_y:
            return
        if self.rank[root_x] < self.rank[root_y]:
            self.par[root_x] = root_y
            self.weights[root_x] = weight - self.weights[x] + self.weights[y]
        else:
            self.par[root_y] = root_x
            self.weights[root_y] = -weight - self.weights[y] + self.weights[x]
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[root_x] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weights[x] - self.weights[y]
import sys
n,m=map(int,input().split())
lrd=[]
tree = WeightedUnionFindTree(n)
for _ in range(m):
    lrd.append(list(map(int,input().split())))
for l,r,d in lrd:
    tree.unite(l-1,r-1,d)
    
for l,r,d in lrd:
    if tree.is_same(l-1,r-1):    
        if tree.diff(l-1,r-1) != d:
            print("No")
            sys.exit()
    else:
        tree.unite(l-1,r-1,d)
else:
    print("Yes")

Measured memory_bytes: 109856