akhauriyash/Code-Regression huggingface dataset:
H,W=map(int,input().split())
List = [list(input()) for i in range(H)]
res = "Yes"
flag = True

def checkAround(ListX,i,j):
  if i == 0 and j ==0:
    if List[i+1][j] == "#" or List[i][j+1] == "#":
      return True
    else: 
      return False
  elif i == 0 and j !=0 and j != W-1:
    if List[i+1][j] == "#" or List[i][j-1] == "#" or List[i][j+1] == "#":
      return True
    else: 
      return False
  elif i == 0 and j == W-1:
    if List[i+1][j] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  elif i != 0 and i != H-1 and j == 0:
    if List[i+1][j] == "#" or List[i-1][j] == "#" or List[i][j+1] == "#":
      return True
    else: 
      return False
  elif i == H-1 and j == W-1:
    if List[i-1][j] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  elif i == H-1 and j !=0 and j != W-1:
    if List[i-1][j] == "#" or List[i][j+1] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  elif i == H-1 and j == 0:
    if List[i-1][j] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  elif i != 0 and i != H-1 and j == W-1:
    if List[i+1][j] == "#" or List[i-1][j] == "#" or List[i][j-1] == "#":
      return True
    else: 
      return False
  else:
    if List[i+1][j] == "#" or List[i-1][j] == "#" or List[i][j-1] == "#" or List[i][j+1] == "#":
      return True
    else: 
      return False

for k in range(H):
  for l in range(W):
    if List[k][l] == ".":
      pass
    else:
      flag = checkAround(List,k,l)
      if not flag:
        res = "No"
        break
  if not flag:
    break
print(res)

Measured memory_bytes: 9352
#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()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    while (a >= b)
    {
        b *= 2;
        cnt++;
    }
    while (b >= c)
    {
        c *= 2;
        cnt++;
    }
    if (cnt <= k)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)
#define mod 1000000007
long long int power(long long int x,long long int y,long long m){if(y==0)return 1;long long int p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
long long int nCr(long long int n,long long int r,long long int m){if(r>n)return 0;long long int a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

	long long int a,b,c;
	cin>>a>>b>>c;
	long long int ct=(power(2,a,mod));
	if(ct==0)	ct+=mod;
	ct--;
	ct-=(nCr(a,c,mod));
	if(ct<0)	ct+=mod;
	ct-=(nCr(a,b,mod));
	if(ct<0)	ct+=mod;
	cout<<ct;
	return 0;	
}

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

int main() {
    string s;
    cin >> s;

    int p = 0, g = 0, ans = 0;
    for (auto& e : s) {
        if (e == 'p') {
            if (p < g) {
                p++;
            } else {
                g++;
                ans--;
            }
        } else {
            if (p < g) {
                p++;
                ans++;
            } else {
                g++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 1000003
#define INF 1e9
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m,i,j,k;
   	cin>>n>>m;
   	char c;
    vector <char> v[1005];
   	for(i=1 ; i<=n ; i++){
   		v[i].pb(',');
   	   for(j=1;j<=m;j++){
   	    	cin>>c;
   	    	v[i].pb(c);
	  }
	}
   	ll dp[n+5][m+5];
   	memset(dp,0,sizeof(dp));
   	dp[1][1]=1;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if( i == 1 and j==1) continue;
			if(v[i][j] == '#'){
				dp[i][j]=0;
				continue;
			}
			dp[i][j] = (dp[i-1][j] + dp[i][j-1])%N;
		}
	}
	cout<<dp[n][m];
 }

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
/* Coding Space*/
const int INF = 2000000000;
int f[100][10] = {};
int p[100][11] = {};

int ans = -INF;
int n;
int now[100] = {};
int dfs(int index,bool check){
  if(index == 10 && check){
    int t_ans = 0;
    rep(i,n){
      t_ans += (p[i][now[i]]);
    }
    ans = max(ans,t_ans);
    return 0;
  }else if(index == 10 && check == 0)
    return 0;
  dfs(index+1,check);
  rep(i,n){
    if(f[i][index] == 1)
      now[i]++;
  }
  dfs(index+1,1);
  rep(i,n){
    if(f[i][index] == 1)
      now[i]--;
  }
  return 0;
}

int main(){
  cin >> n;
  rep(i,n)
    rep(j,10) cin >> f[i][j];
  rep(i,n)
    rep(j,11) cin >> p[i][j];
  dfs(0,0);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

const ll mod = 1e9 + 7;

ll gcd(ll x, ll  y){
    if(x<y){
        ll z = x;
        x = y;
        y = z;
    }
    if(x % y == 0)return y;
    else return gcd( y, x % y);
}

int main()
{
    FASTIO
     /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    // cin >> T;
    T = 1;
    for(int cs = 1; cs <= T; cs++)
    {
        ll a, b, c, k, result;
        ll ar[5];
      cin >> a>> b>> c>>k;
        ar[0] = a;
        ar[1] = b;
        ar[2] =  c;
        sort(ar, ar+3);
        result = ar[2] * (1 << k);
        cout<<result+ar[0]+ar[1]<<endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		printf("Case %d:\n", i+1);
		int s;
		scanf("%d", &s);
		rep(j, 10){
			char str[16];
			sprintf(str, "%08d", s*s);
			str[6] = '\0';
			s = atoi(str + 2);
			printf("%d\n", s);
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) sort(ALL(x), greater<T>())
#define REVERSE(x) reverce(ALL(x))
#define ACM(x, y) accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

// デバッグ用
#define PUT_LIST(x, y) std::copy(ALL(x), ostream_iterator<decltype(x)::value_type>(cout, y))

const int kMod = 1e9 + 7;

itn main() {
	ios::sync_with_stdio(false);

	int a, b;

	cin >> a >> b;

	int max = 2000, min = 0;
	int hf;

	int hf8, hf10;

	REP(i, 2000) {
		hf8 = i * 8 / 100;
		hf10 = i / 10;

		if (a == hf8 && b == hf10) {
			cout << i;
			break;
		}
		else if (a < hf8 && b < hf10) {
			cout << -1;
			break;
		}
	}

	return 0;
}


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

using namespace std;
typedef long long ll;

#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()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

ll solve(const string &S) {
  int N = SIZE(S);
  vector<ll> val(2019, 0);
  ll fac = 1;
  ll cur = 0;
  val[cur]++;
  REP(i, N) {
    ll add = S[N-1-i] - '0';
    cur = (cur + fac * add) % 2019;
    fac = (fac * 10) % 2019;
    val[cur]++;
  }
  ll res = 0;
  REP(i, SIZE(val)) {
    res += val[i] * (val[i] - 1) / 2;
  }
  return res;
}

int main()
{
  string S; cin >> S;
  cout << solve(S) << endl;;
  return 0;
}


Measured memory_bytes: 3728
import sys
sys.setrecursionlimit(10000)

def main():
    while 1:
        W, H = map(int, input().split())
        if W == 0 and H == 0:
            break
        C = [list(map(int, input().split())) for _ in range(H)]

        def dfs(h, w):
            C[h][w] = 0

            for dh in range(-1, 2):
                for dw in range(-1, 2):
                    nh = h + dh
                    nw = w + dw
                    if nh < 0 or nh >= H or nw < 0 or nw >= W:
                        continue
                    if C[nh][nw] == 0:
                        continue
                    dfs(nh, nw)

        count = 0
        for h in range(H):
            for w in range(W):
                if C[h][w] == 0:
                    continue
                dfs(h, w)
                count += 1
        print(count)


if __name__ == "__main__":
    main()



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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

bool infected[20001];

void init(){
    rep(i, 20001) infected[i] = false;
    infected[1] = true;
}

int main(void){
    int N, M;
    vector<int> ans;
    while(true){
        init();
        cin >> N >> M;
        if(N == 0) break;
        vector<pair<int, pair<int, int>>> pack(M);
        rep(i, M){
            int t, s, d; cin >> t >> s >> d;
            pack[i] = make_pair(t, make_pair(s, d));
        }
        sort(pack.begin(), pack.end());
        rep(i, M){
            if(infected[pack[i].second.first]) infected[pack[i].second.second] = true;
        }
        int cnt = 0;
        rep(i, N+1) if(infected[i]) cnt++;
        ans.push_back(cnt);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3364
cards = [[False for i in range(13)] for j in range(4)]
pattern = ["S", "H", "C", "D"]

N = int(input())
for g in range(N):
    ch, rank = input().split()
    rank = int(rank)
    cards[pattern.index(ch)][rank-1] = True
for i in range(4):
    for j in range(13):
        if cards[i][j] == False:
            print(pattern[i], j+1)


Measured memory_bytes: 5604
#include<stdio.h>
//start o
int i,j,n,max[6];
char table[10][10],mark[2]={'o','x'};
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int l(int dx,int dy,int x,int y,char m,int count){
  if(table[x][y]=='.'||table[x][y]=='0')return 0;
  if(table[x][y]==m)return count;
  return l(dx,dy,x+dx,y+dy,m,count+1);
}
int search(int x,int y,char m){
  //mの長さを取る
  int k,count;
  count = 0;
  if(table[x][y]!='.')return 0;
  for(k=0;k<8;k++){
    count += l(dx[k],dy[k],x+dx[k],y+dy[k],m,0);
  }
  return count;
}
int okikae2(int dx,int dy,int x,int y,char m){
  if(table[x][y]=='0'||table[x][y]=='.')return 0;
  else if(table[x][y]==m)return 1;
  else if(okikae2(dx,dy,x+dx,y+dy,m)){
    table[x][y]=m;
    return 1;
  }
  else return 0;
}
int okikae(int x,int y,char m){
  //mに置き換えていく
  int k;
  table[x][y]=m;
  for(k=0;k<8;k++){
    okikae2(dx[k],dy[k],x+dx[k],y+dy[k],m);
  }
  return 0;
}

int main(){
  for(i=0;i<10;i++)table[0][i]=table[9][i]='0';
  for(i=1;i<9;i++){
    scanf("%s",&table[i][1]);
    table[i][0]='0';
    table[i][9]='0';
  }
  max[1]=-1;
  for(n=0;;n=(n+1)%2){
    max[n]=-1;
    for(i=n?8:1;n?i>-1:i<9;n?i--:i++){
      for(j=n?8:1;n?j>-1:j<9;n?j--:j++){
        if(max[n]<search(i,j,mark[n])){
          max[2+n]=i;
          max[4+n]=j;
          max[n]=search(i,j,mark[n]);
        }
      }
    }
    if(max[n]!=0)okikae(max[2+n],max[4+n],mark[n]);
    /*
    printf("%d:%d:%d[%d]\n",n,max[0],max[1],search(6,7,mark[1]));
    for(i=1;i<9;i++){
      for(j=1;j<9;j++){
        printf("%c",table[i][j]);
      }
      puts("");
      }/*/
    if(max[0]==0&&max[1]==0)break;
  }
  for(i=1;i<9;i++){
    for(j=1;j<9;j++){
      printf("%c",table[i][j]);
    }
    puts("");
  }
  return 0;
}

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

int main(){
  int n,d;
  cin>>n;
  int arr[n];
  int ma1= INT_MIN,ma2=ma1,cnt=0;
  for(int i=0;i<n;i++){
      cin>>arr[i];
      if(arr[i]>ma1)ma1 = arr[i];
  }
  for(int i=0;i<n;i++){
      if(arr[i]==ma1)cnt++;
      else
        if(arr[i]>ma2)ma2=arr[i];
  }
  //cout<<cnt<<"\n\n";
  if(cnt>1){
      for(int i=0;i<n;i++)cout<<ma1<<"\n";
  }
  else{
      for(int i=0;i<n;i++){
          if(arr[i]==ma1)cout<<ma2<<"\n";
          else
          cout<<ma1<<"\n";
      }
  }
}


Measured memory_bytes: 2432
_ = input()
l = [int(x) for x in input().split()]
l.sort(reverse=True)

alices_score = sum([x if i % 2 == 0 else 0 for i, x in enumerate(l)])
bobs_score = sum([x if i % 2 != 0 else 0 for i, x in enumerate(l)])

print(alices_score - bobs_score)

Measured memory_bytes: 3060
N,M,X = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(N)]
ans = float('inf')
for bit in range(2**N):
    temp = [0]*M
    money = 0
    for i in range(N):
        if bit & (1<<i):
            money += ca[i][0]
            for idx,rikai in enumerate(ca[i][1:]):
                temp[idx] += rikai
            #temp[i] += ca[i][1+idx]
    ok = True
    for x in temp:
        if x < X:
            ok = False
    #print(bin(bit),temp)
    if ok:
        ans = min(ans,money)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68548
#pragma GCC optimize("O3")
#pragma GCC target("sse4.1")
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = ((int)(n) - 1); i >= 0; --i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#endif

void solve (int n)
{
    vector<string> s(n);
    forn (i, n)
        cin >> s[i];

    vector<string> t(n, string(n, '-'));
    ll ans = 0;
    forn (b, n)
    {
        forn (i, n) forn (j, n)
            t[i][(j + b) % n] = s[i][j];

        bool ok = true;
        forn (i, n) forn (j, n)
            ok &= (t[i][j] == t[j][i]);

        ans += ok * n;
    }

    cout << ans << endl;
}

int32_t main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

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

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, K;

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

    vi p(N);
    vi s(N + 1);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        s[i + 1] = s[i] + p[i];
        if (i + 1 >= K) {
            ans = max(ans, s[i + 1] - s[i + 1 - K]);
        }
    }

    cout << fixed << setprecision(10);
    cout << double(ans + K) / 2 << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MOD = (int)1e9 + 7;

template<class T> using Rig = pair<T, long long>;
template<class T> Rig<T> add(const Rig<T> &a, const Rig<T> &b) {
    if (a.first != b.first) return min(a, b);
    return Rig<T>(a.first, (a.second + b.second) % MOD);
}
template<class T> Rig<T> mul(const Rig<T> &a, const Rig<T> &b) {
    return Rig<T>(a.first + b.first, a.second * b.second % MOD);
}

template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& p) { return os << p.first << " " << p.second; }
const int INF = (int)1e9 + 7;
using pii = pair<int, int>;
int main() {
    int h, w; cin >> h >> w;
    int si, sj, ti, tj; cin >> si >> sj >> ti >> tj;
    vector<vector<Rig<int>>> dp(h, vector<Rig<int>>(w, Rig<int>(INF, 0)));
    vector<vector<bool>> done(h, vector<bool>(w));
    queue<pair<Rig<int>, pii>> que;
    dp[si][sj] = Rig<int>(0, 1);
    que.emplace(dp[si][sj], pii(si, sj));
    while (!que.empty()) {
        pii p = que.front().second; que.pop();
        int i = p.first, j = p.second;
        if (done[i][j]) continue;
        done[i][j] = true;
        int dij[] = {0, 1, 0, -1, 0};
        for (int k = 0; k < 4; k++) {
            int ni = i + dij[k], nj = j + dij[k + 1];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            dp[ni][nj] = add(dp[ni][nj], mul(dp[i][j], Rig<int>(1, 1)));
            que.emplace(dp[ni][nj], pii(ni, nj));
        }
        int nis[] = {i, i, 0, h - 1}, njs[] = {0, w - 1, j, j};
        for (int k = 0; k < 4; k++) {
            int ni = nis[k], nj = njs[k];
            dp[ni][nj] = add(dp[ni][nj], mul(dp[i][j], Rig<int>(1, 1)));
            que.emplace(dp[ni][nj], pii(ni, nj));
        }
    }
    cout << dp[ti][tj] << endl;
    return 0;
}



Measured memory_bytes: 6152
abc = input().split(" ", 3)
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])
if 0 <= a and a <= 100 and 0 <= b and b <= 100 and 0 <= c and c <= 100:
    if a < b and b < c:
        print("Yes")
    else:
        print("No")


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

int main() {
  int n;
  cin >> n;
  char str[n];
  vector<set<int>> colors(3);
  for (int i = 0; i < n; ++i) {
    cin >> str[i];
    if (str[i] == 'R') colors[0].insert(i);
    else if (str[i] == 'G') colors[1].insert(i);
    else colors[2].insert(i);
  }
  long long ans(0);
  int i(0), j(1), k(2);
      for (int ii: colors[i]) {
        for (int ij: colors[j]) {
          int diff = abs(ii - ij);
          int mn = min(ii, ij);
          int mx = max(ii, ij);
          int c(0);
          if (diff % 2 == 0 && colors[k].count(mn + diff / 2)) {
            c--;
          }
          if (colors[k].count(mx + diff)) c--;
          if (colors[k].count(mn - diff)) c--;
          ans += (long long) colors[k].size() + c;
        }
      }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

void solve()
{
   ll n,sumr=0,suml=0,ans=INF;cin>>n;
   ll a[n];REP(i,n){cin>>a[i];sumr+=a[i];}
    REP(i,n){
        ans=min(ans,abs(sumr-suml));
        sumr-=a[i];
        suml+=a[i];
    }ans=min(ans,abs(sumr-suml));
    cout<<ans<<endl;

}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(true){
        c-=b;
        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll mod=998244353;

int main() {
    ll n,i;cin>>n;ll a[n],b[n],c[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dp[3][n];
    dp[0][0]=a[0];dp[1][0]=b[0];dp[2][0]=c[0];
    for(i=1;i<n;i++)
    {
        dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
        dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
        dp[2][i]=max(dp[1][i-1],dp[0][i-1])+c[i];
    }
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
    return 0;
}

Measured memory_bytes: 4992
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if a*500 + b*100 + c*50 == X:
        res += 1
       
print(res)

Measured memory_bytes: 3064
/* kadai 3_3
   nabe9393 */
 
#include<stdio.h>
 
int main(void){
  int data, base;
  int digit = 1;
  scanf("%d %d", &data, &base);
  while (data / base > 0){
    digit += 1 ;
    data /= base;
  }
  printf("%d\n", digit);
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;import java.util.Collections;

 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
	    String str=reader.readLine();
	    String s[]=str.split(" ");
	    int e=Integer.parseInt(s[0]);
	    int y=Integer.parseInt(s[1]);

	    StringBuffer sb=new StringBuffer();

	    switch(e){
	    case 0:
		int year=0;
	        if(y<=1911){
		    year=y-1867;
		    sb.append("M");
		}else if(y<=1925){
		    year=y-1911;
		    sb.append("T");
		}else if(y<=1988){
		    year=y-1925;
		    sb.append("S");
		}else if(y<=2016){
		    year=y-1988;
		    sb.append("H");
		}
		sb.append(year);
		break;
	    case 1:
		y+=1867;
		sb.append(y);
		break;
	    case 2:
		y+=1911;
		sb.append(y);
		break;
	    case 3:
		y+=1925;
		sb.append(y);
		break;
	    case 4:
		y+=1988;
		sb.append(y);
		break;
	    }
	    System.out.println(sb);
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



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

int main() {
	int n;
	cin >> n;
	vector<double> x(n);
	double b = 0.0;

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

	double a = (double)n * 1.0;
	double p = round(b / a);
	int location = (int)p;

	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += pow((x[i] - location), 2);
	}
	cout << total;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<numeric>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    int sum = accumulate(all(A), 0);
    int cnt = 0;
    rep(i, 0, N) {
        if (A[i] * M * 4 >= sum) {
            ++cnt;
        }
    }
    if (cnt >= M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

int P[100100],v[100100];

void init(int N)
{
	for(int i=0; i<=N; ++i) 
	    P[i] = i;
} 

int root(int a)
{
    if(P[a]==a)   
	   return a;
    int x=P[a];
    P[a]=root(P[a]);
    v[a]+=v[x];
    return P[a];    
}
 
bool is_same_set(int a,int b)
{
	return(root(a)==root(b));
}

void unite(int a,int b,int w)
{
	int u=root(a);
	int m=root(b);
	P[m]=u;
	v[m]=v[a]-v[b]+w;
}

int main()
{
    int M,N;
    while(cin >> N >> M)
    {
        if(!N && !M)
          break;
        init(N);
        for(int i=1;i<=N;i++)
           v[i]=0;
        for(int i=0;i<M;i++)
        {
            char c;
            int a,b,w;
            cin >> c;
            if(c=='?')
            {
                cin >> a >> b;
                if(!is_same_set(a,b))
                   cout << "UNKNOWN" << endl;
                else
                   cout << v[b]-v[a] << endl;
            }
            else if(c=='!')
            {
                cin >> a >> b >> w;
                unite(a,b,w);
            }
        }
     }
}


Measured memory_bytes: 5944
#!/usr/bin/env python3
import sys

MOD = 1000000007

def solve(N: int, A: "List[int]"):
    from collections import defaultdict
    M = N // 2
    def get_range(idx):
        r = (N - idx) // 2 + 1        
        return range(max(0, M-r), idx//2+1+1)
    
    dp_a = defaultdict(lambda:-float('inf'))
    dp_s = defaultdict(lambda:-float('inf'))
    dp_s[(0, -1)] = 0 
    for i in range(N):
        for j in get_range(i):
            dp_s[(j, i)] = max(dp_s[(j, i)], dp_a[(j, i-1)], dp_s[(j, i-1)])
            dp_a[(j, i)] = max(dp_a[(j, i)], dp_s[(j, i)], dp_s[(j-1, i-1)]+A[i])
    print(max(max(v for (j, i), v in dp_a.items() if j == M),
              max(v for (j, i), v in dp_s.items() if j == M)))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    vector<vector<int>> tree(n + 1);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }
    queue<pair<int, int>> qa;
    qa.emplace(make_pair(v, 0));
    vector<int> dis_a(n + 1, -1);
    dis_a[v] = 0;
    while (!qa.empty()) {
        auto front = qa.front();
        qa.pop();
        for (auto e: tree[front.first]) {
            if (dis_a[e] < 0) {
                dis_a[e] = front.second + 1;
                qa.emplace(make_pair(e, front.second + 1));
            }
        }
    }

    queue<pair<int, int>> qb;
    qb.emplace(make_pair(u, 0));
    vector<int> dis_t(n + 1, -1);
    dis_t[u] = 0;
    while (!qb.empty()) {
        auto front = qb.front();
        qb.pop();
        for (auto e: tree[front.first]) {
            if (dis_t[e] < 0) {
                dis_t[e] = front.second + 1;
                qb.emplace(make_pair(e, front.second + 1));
            }
        }
    }

    int ans = -1;
    for (int i = 1; i <= n; i++) {
        if (dis_a[i] > dis_t[i] && dis_t[i] >= 0) {
            ans = max(ans, dis_a[i]);
        }
    }

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


Measured memory_bytes: 6784
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

//0以上N以下の整数で，いずれかの桁に3を含むものの個数を求めよ
// 0 <= N <= 10^100
const int MAX_N = 110;
const int MAX_K = 5;

ll dp[MAX_N][2][MAX_K];
//dp[i][smaller = 0][countnot0 = k] : N以下が確定していない，その桁までに0がk個登場する
//dp[i][smaller = 1][countnot0 = k] : N以下が確定している，その桁までに0がk個登場する
//if(i桁目がnot0) dp[i + 1][smaller][countnot0 + 1] = dp[i + 1][smaller][countnot0];

int main() {
    string N; cin >> N;
    vector<int>n;
    int K; cin >> K;
    int Nlen = N.size();
    rep(i, Nlen) n.pb(N[i] - '0');
    dp[0][0][0] = 1;
    rep(i, Nlen) {
        rep(smaller, 2) {
            rep(count0, K + 1) {
                rep(x, 10) {
                    if(!smaller && x > n[i])continue;
                    dp[i + 1][smaller || (x < n[i])][count0 + (x != 0)] += dp[i][smaller][count0];
                }
            }
        }
    }
    cout << dp[Nlen][0][K] + dp[Nlen][1][K] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

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

	if(a<=b && b<=c){
		printf("%d %d %d\n",a,b,c);
	} else if(b<=a && a<=c){
		printf("%d %d %d\n",b,a,c);
	} else if(c<=a && a<=b){
		printf("%d %d %d\n",c,a,b);
	} else if(a<=c && c<=b){
		printf("%d %d %d\n",a,c,b);
	} else if(b<=c && c<=a){
		printf("%d %d %d\n",b,c,a);
	} else  if(c<=b && b<=a){
		printf("%d %d %d\n",c,b,a);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	string S; cin >> S;
	int N = S.size();
	vector<string> A = {"maerd","remaerd","esare","resare"};
	int now = 0;
	reverse(S.begin(),S.end());
	bool ok = true;
	while(now < N){
		if(now+4 >= N){
			ok = false;
			break;
		}
		string t = S.substr(now,5);
		bool flag = false;
		rep(i,4){
			if(t == A[i]) flag = true;
		}
		if(flag){
			now += 5;
		}
		else{
			string t2 = S.substr(now,6);
			bool flag2 = false;
			rep(i,4){
				if(t2 == A[i]) flag2 = true;
			}
			if(flag2) now += 6;
			else{
				if(S.substr(now,7) == "remaerd") now += 7;
				else{
					ok = false;
					break;
				}
			}
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
	
}
   


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;

using VI = vector <int> ;
using VVI = vector <VI> ;
const int INF = 100000000;

int solve(string& A, string& B, string& C) {
    vector<int> ABMatch(A.size());
    vector<int> BCMatch(B.size());
    vector<int> ACMatch(A.size());

    // A precalculation
    for (int i = A.size()-1; i >= 0; --i) {
        bool pass = true;
        int l = A.size()-i;
        for (int j = 0; j < l && j < B.size(); ++j) {
            if (A[i+j] != B[j] && B[j] != '?' && A[i+j] != '?') {
                pass = false;
                break;
            }
        }
        ABMatch[i] = pass;

        pass = true;
        for (int j = 0; j < l && j < C.size(); ++j) {
            if (A[i+j] != C[j] && A[i+j] != '?' && C[j] != '?') {
                pass = false;
                break;
            }
        }
        ACMatch[i] = pass;
    }

    //B precalculation
    for (int i = B.size()-1; i >= 0; --i) {
        bool pass = true;
        int l = B.size()-i;

        for (int j = 0; j < l && j < C.size(); ++j) {
            if (B[i+j] != C[j] && B[i+j] != '?' && C[j] != '?') {
                pass = false;
                break;
            }
        }

        BCMatch[i] = pass;
    }

    int ans = A.size() + B.size() + C.size();
    // B start
    for (int a = 0; a < A.size(); ++a) {
        // B C no intersection
        if (ABMatch[a]) {
            int len = A.size();
            len = max(len, a+(int)B.size());
            ans = min(ans, len + (int)C.size());
        } else {
            continue;
        }

        // C start
        for (int b = 0; b < B.size(); ++b) {
            bool AC = true;

            // if intersect then check AC Match
            if (a+b < A.size()) {
                AC = ACMatch[a+b];
            }

            if (AC && ABMatch[a] && BCMatch[b]) {
                int len = A.size();
                len = max(len, a+(int)B.size());
                len = max(len, a+b+(int)C.size());
                ans = min(ans, len);
            }
        }

        // C in A, not in B
        for (int b = a+B.size(); b < A.size(); ++b) {
            if (ABMatch[a] && ACMatch[b]) {
                int len = A.size();
                len = max(len, b+(int)C.size());
                ans = min(ans, len);
            }
        }
    }

    //A B no intersection
    for (int b = 0; b < B.size(); ++b) {
        if (BCMatch[b]) {
            int len = B.size();
            len = max(len, b+(int)C.size());
            ans = min(ans, len + (int)A.size());
        }
    }

    return ans;
}

int main() {
    string A;
    string B;
    string C;

    int ans = INF;

    cin >> A >> B >> C;

    ans = min(ans, solve(A, B, C));
    ans = min(ans, solve(A, C, B));
    ans = min(ans, solve(B, A, C));
    ans = min(ans, solve(B, C, A));
    ans = min(ans, solve(C, A, B));
    ans = min(ans, solve(C, B, A));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque

n, m = map(int, input().split())
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

dist = [1000000] * n
ans = [None]*n
not_visited = set(range(n))
not_visited.remove(0)
vs = deque([0])
dist[0] = 0
while vs:
    v = vs.popleft()
    for other_side in e[v]:
        if other_side in not_visited:
            vs.append(other_side)
            not_visited.remove(other_side)
            if dist[other_side] > dist[v] + 1:
                dist[other_side] = dist[v] + 1
                ans[other_side] = v

print("Yes")
for i in ans[1:]:
    print(i+1)


Measured memory_bytes: 43168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define ff first
#define ss second
vector<int> adj[100005];
int dptable[100005], V, E;

int DFS(int source) {
	if (dptable[source] != -1) {
		return dptable[source];
	}
	else if (adj[source].size() == 0) {
		return 0;
	}
	else {
		for (const int& vertex: adj[source]) {
			dptable[source] = max(dptable[source], DFS(vertex) + 1);
		}
		return dptable[source];
	}
}

int main() {
	ios::sync_with_stdio(0);
	int V, E, a, b;
	cin >> V >> E;

	memset(dptable, -1, sizeof(dptable));
	for (int i = 0; i < E; i++) {
		cin >> a >> b;
		adj[a - 1].push_back(b - 1);
	}
	int maximum = 0;
	int temp;
	for (int i = 0; i < V; i++) {
		temp = DFS(i);
		if (temp > maximum) {
			maximum = temp;
		}
	}

	cout << maximum << endl;
	return 0;
}

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

int main()
{
	int n;
	while (cin >> n, n)
	{
		long int ary[5001] = {};

		for (int i = 1; i <= n; i++)
		{
			cin >> ary[i];
		}
		for (int i = 1; i <= n; i++)
		{
			ary[i] += ary[i - 1];
		}

		long int ans = -9999999999;
		for (int i = 0; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				ans = max(ans, ary[j] - ary[i]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
/// Macros ---------------------
#define ll long long
#define sz(a) (int)a.size()
#define int long long
#define pb push_back
#define vi vector<int>
#define f first
#define s second
#define ii pair<int,int>
#define lb lower_bound
#define up upper_bound
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define ld long double
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Constracts -----------------------------------------------
const int maxn=1e5;
const int INF=(1ll)<<(30ll);
const int inf=1000000000000000000;
const int eps=1e-9;
/// Quick Pow ------------------------------------------------
int qpow(int b,int e)
{
    if( !e ) return 1;
    if( e & 1 ) return qpow(b, e - 1) * b;
    int pwur = qpow(b, e >> 1);
    return pwur * pwur;
}

/// My Code ---------------------------------------------------

int a[maxn],mk[maxn];

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

    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int cnt=0;
    for(int i=1;i!=2;i=a[i]){
        cnt++;
        if(mk[i]){cout<<"-1\n";return 0;}
        mk[i]=true;
    }
    cout<<cnt<<'\n';

    return 0;
}


Measured memory_bytes: 5188
#include "bits/stdc++.h"
using namespace std;
const int maxn=1e5+100;
int n;
vector<int>g[maxn];
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int k=-1;
    for(int i=1;i<=2*n;i++){
        if(i*(i-1)==2*n){
            k=i; break;
        }else if(i*(i-1)>2*n){break;}
    }
    if(k==-1){
        printf("No\n");
    }else{
        printf("Yes\n");
        printf("%d\n",k);
        int t=0;
        for(int i=1;i<=k;i++){
            for(int j=i+1;j<=k;j++){
                ++t;
                g[i].push_back(t);
                g[j].push_back(t);
            }
        }
        for(int i=1;i<=k;i++){
            printf("%d ",g[i].size());
            for(auto v:g[i]){
                printf("%d ",v);
            }
            printf("\n");
        }
    }
    return 0;
}


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


public class Main {
    private static int MOD = 1000000007;


    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String str = br.readLine();
        if (str.contains("7")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 25332
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int s = 0;
        
        if(a > b){
            s = a;
            a = b;
            b = s;
        }
        if(b > c){
            s = b;
            b = c;
            c = s; 
        }
        if(a > b){
            s = a;
            a = b;
            b = s; 
        }
        System.out.println(a + " " + b + " " + c);
    }
}


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

using namespace std;

#define REP(var, n)  for (int var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<int>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pii;

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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

int MOD = (int) 1e9 + 7;


auto solve() {
    string s;
    cin >> s;
    int n = s.size();

    int c = 0;
    REP(st, n) {
        FOR(e, st + 1, n+1) {
            bool ok = true;
            FOR(i, st, e) {
                if (
                        s[i] == 'A' ||
                        s[i] == 'C' ||
                        s[i] == 'G' ||
                        s[i] == 'T'
                        ) {
                } else {
                    ok = false;
                }
            }

            if (ok)
                chmax(c, e - st);
        }
    }

    return c;
}


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

//    cout << (solve() ? "Heisei" : "TBD") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

var walls [][]bool
var count [][]int

type Item struct {
	Y int
	X int
	C int

	Index int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].C < pq[j].C
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.Index = -1
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.Index = n
	*pq = append(*pq, item)
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].Index = i
	pq[j].Index = j
}

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

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func dist(y1, x1, y2, x2 int) int {
	return abs(y1-y2) + abs(x1-x2)
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	H, W := nextInt(), nextInt()
	Ch, Cw := nextInt(), nextInt()
	Dh, Dw := nextInt(), nextInt()
	Ch -= 1
	Cw -= 1
	Dh -= 1
	Dw -= 1

	walls = make([][]bool, H)
	for y := 0; y < H; y++ {
		walls[y] = make([]bool, W)
		s := next()
		for x := 0; x < W; x++ {
			if s[x] == '#' {
				walls[y][x] = true
			}
		}
	}

	count = make([][]int, H)
	for y := 0; y < H; y++ {
		count[y] = make([]int, W)
		for x := 0; x < W; x++ {
			count[y][x] = -1
		}
	}

	pq := make(PriorityQueue, 0)
	heap.Init(&pq)
	heap.Push(&pq, &Item{Dh, Dw, 0, -1})

	for {
		if len(pq) == 0 {
			break
		}
		item := heap.Pop(&pq).(*Item)
		if count[item.Y][item.X] >= 0 {
			continue
		}
		count[item.Y][item.X] = item.C
		if item.Y == Ch && item.X == Cw {
			break
		}

		for y := max(0, item.Y-2); y <= min(H-1, item.Y+2); y++ {
			for x := max(0, item.X-2); x <= min(W-1, item.X+2); x++ {
				if walls[y][x] {
					continue
				}
				d := dist(y, x, item.Y, item.X)
				if d == 0 {
					continue
				} else if d == 1 {
					heap.Push(&pq, &Item{y, x, item.C, -1})
				} else {
					heap.Push(&pq, &Item{y, x, item.C + 1, -1})
				}
			}
		}
	}

	fmt.Println(count[Ch][Cw])
}


Measured memory_bytes: 35552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  int N, K, X, Y; cin >> N >> K >> X >> Y;
  if(N<=K)    cout << N*X << endl;
  else  cout << K*X + (N-K)*Y << endl;
  
  return 0;
}

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

using namespace std;

int main()
{

  string S;
  cin >> S;
  if (S.at(5) == '0')
  {
    if (S.at(6) == '1' || S.at(6) == '2' || S.at(6) == '3' || S.at(6) == '4')
    {
      cout << "Heisei" << endl;
    }
    else
    {
      cout << "TBD" << endl;
    }
  }
  else
  {
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 1000000007;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

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

    int k = S.size();

    int p, q;

    for (int i = 0; i < k; ++i) {
        if (S[i] == 'A') {
            q = i;
            break;
        }
    }

    for (int i = k-1; i >0; --i) {
        if (S[i] == 'Z') {
            p = i;
            break;
        }
    }

    cout << p - q + 1 << endl;

}

Measured memory_bytes: 640