akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

long long GCD(long long a, long long b) 
{ 
    if(b==0) 
        return a; 
    return GCD(b, a % b);  
      
}

long long LCM(long long a, long long b)
{
    long long gcd=GCD(a,b);
     return (a*b)/gcd;
}

int main()
{
    long long i, j, k, n, m, t, x, y, s=0, c=0, l;
    cin >> x >> y;
    while (x>0)
    {
        s+=x-1;
        x--;
    }
    while (y>0)
    {
        s+=y-1;
        y--;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
#define ld long double
const int mod = 1e9 + 7;
 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
 
 
 
 
 int bin(multiset<int>&s)
 {

	 
	 int l=0,r=s.size()-1,mid,ans=1;
	 while(l<=r)
	 {
		 mid=(l+r)/2;
		 auto k =s.begin();
	   	advance(k,mid);
		 if(*k>=s.size()-mid)
		 { 
			 ans=s.size()-mid; r=mid-1;
		 }
		 else l=mid+1;
	 }
	 return ans;
 }
 
 
 
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

 

int n;
cin>>n;
string s;
cin>>s;

if(n&1)
{
	cout<<"No\n"; return 0;
}

for(int i=0;i<n/2;i++)
{
	if(s[i]!=s[i+n/2])
	{
		cout<<"No\n"; return 0;
	}
}

cout<<"Yes\n";
 
 
}

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

const int MAX = 1e6+6;

ll n , a[MAX] , b[MAX];


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin>>n;
    for(int i = 1 ; i <= n+1 ; i++ ) cin>>a[i];
    for(int i = 1 ; i <= n ; i++ ) cin>>b[i];
    
    ll ans = 0;
    
    for(int i =1 ; i <=n ; i++ ) {
        
        
        ll tot = a[i] + a[i+1];
        
        ll mn = min(tot , b[i]);
        
        tot -= mn;
        
        ans += mn;
        
        a[i+1] = min(a[i+1] , tot);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5120
n = int(input())
v = [int(i) for i in input().split()]


def gcd(x, y):
    if y > x:
        x, y = y, x
    if y == 0:
        return x
    if x % y == 0:
        return y
    return gcd(y, x % y)


l = [0 for i in range(n)]
r = l[:]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
    r[-i-1] = gcd(r[-i], v[-i])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))


Measured memory_bytes: 14436
#include<cstdio>
#include<cstring>
const int p[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
int cnt[25],f[25][80];
int dfs(int h,int k){
	if(h==25)return k==1;
	if(f[h][k]!=-1)return f[h][k];
	int ans=0;
	for(int i=0;i<=cnt[h];i++)if(!(k%(i+1)))ans+=dfs(h+1,k/(i+1));
	return f[h][k]=ans;
}
int main(){
	int n,t,i,j;
	scanf("%d",&n);
	for(i=2;i<=n;i++){
		t=i;
		for(j=0;j<25&&t>1;j++)if(!(t%p[j]))
			for(;!(t%p[j]);cnt[j]++)t/=p[j];
	}
	memset(f,-1,sizeof(f));
	printf("%d\n",dfs(0,75));
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int p,l,r;};
struct Node T[MAX];
int n;

void preParse(int u){
  if( u== NIL)return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if( u== NIL)return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if( u== NIL)return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p = NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d", &v, &l,&r);
    T[v].l = l;
    T[v].r = r;
    if( l != NIL)T[l].p =v;
    if(r != NIL) T[r].p =v;
  }

  for(i=0;i<n;i++)if(T[i].p == NIL)root =i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2724
#include <iostream>

using namespace std;

int main()
{
string S,T;cin>>S>>T;
int A,B;cin>>A>>B;
string U;cin>>U;

if(U==T)
{
    --B;
    cout<<A<<" "<<B;
}else{
    --A;
    cout<<A<<" "<<B;

}
    return 0;
}


Measured memory_bytes: 256
import collections
N,K,Q = map(int,input().split())

A=[]
for i in range(Q):
    A.append(int(input()))
    
jud = Q - K

ans_list = [0] * N

c = collections.Counter(A)
key = list(c.keys())
val = list(c.values())
for i in range(len(c)):
  ans_list[key[i]-1] = val[i]

for i in range(len(c)):
    if val[i] > jud:
        ans_list[key[i]-1] +=1
for i in range(N):
    if ans_list[i] > jud:
        print("Yes")
    else:
        print("No")

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

int main(){
int n;
  cin >> n;
  
  int a[n];
  bool ok=1;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if((!(a[i]%2)) && a[i]%3 && a[i]%5)ok=0;
  }
  if(ok)cout << "APPROVED";
  else cout << "DENIED";
}


Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

struct N {
  int w, s, v;
};
bool operator<(const N &l, const N &r) {
  if (l.w + l.s == r.w + r.s)
    return l.s < r.s;
  return l.w + l.s < r.w + r.s;
}

long long dp[1010][20101] = {0};
int main() {
  int n;
  cin >> n;
  vector<N> ns(n);
  for (int i = 0; i < n; i++)
    cin >> ns[i].w >> ns[i].s >> ns[i].v;
  sort(ns.begin(), ns.end());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 20201; j++) {
      dp[i + 1][j] = dp[i][j];
      if (j >= ns[i].w && j - ns[i].w <= ns[i].s)
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - ns[i].w] + ns[i].v);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= 20201; i++)
    ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}


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

int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios::sync_with_stdio(false),cin.tie(0);
	
		int n; cin >> n;

if(400<= n && n<600) cout << 8<< endl;
else if(600<= n && n<=799) cout << 7<< endl;
else if(800<= n && n<=999) cout << 6<< endl;
else if(1000<= n && n<=1199) cout << 5<< endl;
else if(1200<= n && n<=1399) cout << 4<< endl;
else if(1400<= n && n<=1599) cout << 3<< endl;
else if(1600<= n && n<=1799) cout << 2<< endl;
else if(1800<= n && n<=1999) cout << 1<< endl;


	return 0;
}

Measured memory_bytes: 3604
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem119a(s))
}

fun problem119a(s: String): String {
    return if (s.take(4).toInt() >= 2019 && s.drop(5).take(2).toInt() >= 5) "TBD" else "Heisei"
}

Measured memory_bytes: 30992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S;
  cin>>S;
  int A=S/1000;
  int B=(S%1000)/100;
  int C=(S%100)/10;
  int D=S%10;
  if(A+B+C+D==7){
    cout<<A<<'+'<<B<<'+'<<C<<'+'<<D<<'='<<7<<endl;
  }
  else if(A+B+C-D==7){
    cout<<A<<'+'<<B<<'+'<<C<<'-'<<D<<'='<<7<<endl;
  }
  else if(A+B-C+D==7){
    cout<<A<<'+'<<B<<'-'<<C<<'+'<<D<<'='<<7<<endl;
  }
  else if(A+B-C-D==7){
    cout<<A<<'+'<<B<<'-'<<C<<'-'<<D<<'='<<7<<endl;
  }
  else if(A-B+C+D==7){
    cout<<A<<'-'<<B<<'+'<<C<<'+'<<D<<'='<<7<<endl;
  }
  else if(A-B+C-D==7){
    cout<<A<<'-'<<B<<'+'<<C<<'-'<<D<<'='<<7<<endl;
  }
  else if(A-B-C+D==7){
    cout<<A<<'-'<<B<<'-'<<C<<'+'<<D<<'='<<7<<endl;
  }
  else if(A-B-C-D==7){
    cout<<A<<'-'<<B<<'-'<<C<<'-'<<D<<'='<<7<<endl;
  }
}

Measured memory_bytes: 3604
n,q = map(int,input().split())
s = input()
lst = [0]*n
for i in range(n-1):
  lst[i+1] = lst[i] + 1*(s[i:i+2] == "AC")
for i in range(q):
  l,r = map(int,input().split())
  print(lst[r-1]-lst[l-1])

Measured memory_bytes: 9540
#include<cstdio>
#include<algorithm>
int n,a,b,u,x[101],h[101],y[101],cx,cy,H;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d%d",&x[i],&y[i],&h[i]); 
        if(h[i]!=0)u=i;
    }
    for(int xi=0;xi<=100;++xi)
      for(int yi=0;yi<=100;++yi)
        {
            cx=xi,cy=yi;
            H=h[u]+abs(x[u]-cx)+abs(y[u]-cy);
            for(int i=1;i<=n;++i)
            {
                if(h[i]!=std::max(H-std::abs(x[i]-cx)-std::abs(y[i]-cy),0))break;
                if(i==n)
                {
                    printf("%d %d %d",cx,cy,H);
                    return 0;
                }
            }
        }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

int A, B, C, K;

int solve() {
    int ret = 0;
    int k = K;
    ret += min(k, A);
    k = max(0, k-A-B);
    ret -= min(k, C);
    return ret;
}

int main() {
    cin >> A >> B >> C >> K;
    cout << solve() << endl;
}

Measured memory_bytes: 3632
n, k = [int(i) for i in input().split()]
towns = [int(i) for i in input().split()]
ind_ = 1
ts = []
visited = [0]*n
loop_s = None
while(True):
    ind_ = towns[ind_-1]
    if visited[ind_-1]:
        loop_s = ts.index(ind_)
        break
    else:
        visited[ind_-1] = 1
        ts.append(ind_)
if k <= len(ts):
    print(ts[k-1])
else:
    init = len(ts[:loop_s])
    loop_l = len(ts) - init
    loop = ts[loop_s:]
    print(loop[((k-init)%loop_l)-1])


Measured memory_bytes: 32200
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <sstream>

using namespace std;

int main() {
    int a,b[100],min = 10000,max = -1,i;

    cin >> a;

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

    for(i = 0;i < a;i++){
        if(min > b[i]){
            min = b[i];
        }
    }

     for(i = 0;i < a;i++){
        if(max < b[i]){
            max = b[i];
        }
    }
    
     cout << max - min << endl;
     
    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N, M = map(int, input().split())
A = [int(x) for x in input().split()]
accum = [0 for i in range(N + 1)] #累積和
for i in range(N):
    accum[i + 1] = (accum[i] + A[i]) % M
accum.sort()
c = Counter(accum)
ans = 0
for val in c.values():
    if val > 1:
        ans += val * (val - 1) // 2
print(ans)

Measured memory_bytes: 16568
n = int(input())
ntens = []
suma = 0
for _ in range(n):
    s = int(input())
    suma += s
    if s % 10 != 0:
        ntens.append(s)

ntens.sort()
if suma % 10 != 0:
    print(suma)
else:
    if len(ntens) == 0:
        print(0)
    else:
        print(suma - ntens[0])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N= 1e5 + 10;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
 
 
int main()
{
    int n, m, x, ans=inf;
    cin >> n >> m >> x;
    int skill_point[m + 1], sp_up[n+1][m + 1], cost[n+1];
    for (int i = 1; i <= n;i++)
    {
        cin >> cost[i];
        for (int j = 1; j <= m;j++)   cin >> sp_up[i][j];
    }
 
 
    for (int i = 0; i <=(1<<n)-1;i++)
    {
        int current_cost = 0;
        memset(skill_point, 0, sizeof(skill_point));
        for (int j = 0; j <= (n-1);j++)
        {
            if((i>>j)&1)
            {
                current_cost += cost[j+1];
                for (int k = 1; k <= m;k++) skill_point[k] += sp_up[j+1][k];
            }
        }
        bool flag = true;
        for (int k = 1; k <= m;k++) 
        {
            if(skill_point[k] < x)
            {
                flag = false;
                break;
            }
        }
        ans = flag?min(ans, current_cost):ans;
    }
    if(ans==inf) ans = -1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3588
def check(a):
    m = [-1, -1, -1]
    if [a[0][0], a[1][1],a[2][2]] == m:
        print("Yes")
        return
    if [a[0][2], a[1][1], a[2][0]] == m:
        print("Yes")
        return
    for i in range(3):
        if a[i] == m:
            print("Yes")
            return
        elif [r[i] for r in a] == m:
            print("Yes")
            return
    print("No")
    return

a=[list(map(int,input().split()))for _ in range(3)]
n=int(input())
b=[int(input()) for _ in range(n)]
for i in range(n):
    for y,row in enumerate(a):
        try:
            x=row.index(b[i])
            a[y][x]=-1
        except ValueError:
            pass
check(a)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}

int main(){
  int n,m;
  cin>>n>>m;
  int count=0,max=0,mc=0,a[10000];
  lp(i,m){
    int x,y;
    cin>>x>>y;
    if(x>=n) a[i]=0;
    else{
      a[i]=n-x;
      if(y>max){
	max=y;
	mc=i;
      }
    }
  }
  int ans=0;
  lp(i,m){
    if(mc==i) 1;
    else{ans+=a[i];}
  }
  cout<<ans<<endl;
	  

  return 0;
}



Measured memory_bytes: 3104
import time
import itertools

def main():
    N,M,R = tuple([int(x) for x in input().split()])

    r = [int(x)-1 for x in input().split()]
    
    w_e = [tuple([int(x)for x in input().split()]) for _ in [0]*M]
    w_e = [(a-1,b-1,w) for (a,b,w) in w_e]


    g = Graph(list(range(N)),w_e)

    minimums = {}
    for r_i in r:
        minimums[r_i] = g.dijkstra(r_i)[0]

    bf = itertools.permutations(r)

    candidates = []
    for bf_i in bf:
        distance = 0
        for i in range(R-1):
            distance += minimums[bf_i[i]][bf_i[i+1]]
        candidates.append(distance)

    print(min(candidates))

def speedtest(func,*args):
    b = time.perf_counter()
    res = func(*args)
    e = time.perf_counter()
    elapsed = e-b
    print("{} (sec)".format(elapsed))

    return res

class Graph:
    def __init__(self,w_v,w_e):
        super().__init__()
        self.size = len(w_v)
        self.w_v = [v_i for v_i in w_v]#value of vartex
        self.w_e = [{} for _ in [0]*self.size]

        self.neighbor = [[] for _ in [0]*self.size]
        for a_i,b_i,w_i in w_e:
            self.w_e[a_i][b_i] = w_i#weight of edge
            self.w_e[b_i][a_i] = w_i#weight of edge

            self.neighbor[a_i].append(b_i)
            self.neighbor[b_i].append(a_i)

    def dijkstra(self,v_n):
        d = [-1]*self.size
        temp_d = [(10**9,i)for i in range(self.size)]
        temp_d[v_n] = (0,v_n)
        prev = [-1]*self.size

        q = set(range(self.size))
        
        while len(q)>0:
            u = min([temp_d[q_i] for q_i in q])[1]
            d[u] = temp_d[u][0]
            q.discard(u)
            for v in self.neighbor[u]:
                temp = temp_d[u][0]+self.w_e[u][v]
                if temp_d[v][0]>temp:
                    temp_d[v] = temp,v
                    prev[v] = u

        return d,prev

if __name__ == "__main__":
    main()

Measured memory_bytes: 11896
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<pair<double,string>> v;
    REP(i,n){
      double p,a,b,c,d,e,f,s;
      int m;
      string l;
      cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      double ini = a+b+c;
      double cyc = d+e;
      double t = ini + cyc * m;
      double inc = s * f * m - p;
      v.emplace_back(-inc/t, l);
    }
    sort(begin(v),end(v));
    REP(i,n)
      cout<<v[i].second<<endl;
    cout << "#"<< endl;
  }
  return 0;
}

Measured memory_bytes: 1256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    string s = "";
    cin >> s;
    for (int i=0; i<s.size(); i++) {
        if (i%2 == 0) {
            if (s.at(i) == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            if (s.at(i) == 'R') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import math 

a,b,x = map(int,input().split())
if (2*x) / (a**2) >= b:
  theta = math.atan((2/a)*(b - (x/(a**2))))
  print(theta*180/math.pi)
else:
  theta = math.atan( (a * (b**2)) / (2*x))
  print(theta*180/math.pi)
  

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

void solve(){
  vector<int> a(3);
  for(int i = 0; i < 3; i++) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  int ans = 0;
  for(int i = 1; i < 3; i++){
    ans += a[i - 1] - a[i];
  }
  cout << ans << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u32,
        m: u32,
    }
    println!("{}",
        (1900 * m + 100 * (n-m)) * 2u32.pow(m));
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;
string q = "ox";
int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy[8] = {1, -1, 1, 0, -1, 1, 0, -1};

vector<string> rev(vector<string> s, int turn, int y, int x){
  char c = q[(turn+1)%2];
  s[y][x] = q[turn%2];
  for(int dir=0; dir<8; dir++){
    int ny = y + dy[dir];
    int nx = x + dx[dir];
    if( nx < 0 || ny < 0 || nx >= 8 || ny >= 8 ) continue;
    if( s[ny][nx] == '.' ) continue;
    bool f = false;
    while( s[ny][nx] == c ){
      ny += dy[dir];
      nx += dx[dir];

      if( nx < 0 || ny < 0 || nx >= 8 || ny >= 8 ) break;
      if( s[ny][nx] == q[turn%2] ){
        f = true;
        break;
      }
      if( s[ny][nx] == '.' ) break;
    }
    while( f ){
      if( ny == y && nx == x ) break;
      s[ny][nx] = q[turn%2];
      ny -= dy[dir];
      nx -= dx[dir];
    }
  }
  return s;
}


int calc(vector<string> s, int turn, int y, int x){
  char e = q[(turn+1)%2];
  char my = q[turn%2];
  int cnt = 0;
  for(int dir=0; dir<8; dir++){
    int ny = y + dy[dir];
    int nx = x + dx[dir];
    if( nx < 0 || ny < 0 || nx >= 8 || ny >= 8 ) continue;
    int tmp = 0;
    bool f = false;
    while( s[ny][nx] == e ){
      tmp++;
      ny += dy[dir];
      nx += dx[dir];

      if( nx < 0 || ny < 0 || nx >= 8 || ny >= 8 ) break;
      if( s[ny][nx] == my ){
        f = true;
        break;
      }
    }
    cnt += tmp * f;
  }
  return cnt;
}

vector<string> func(vector<string> s, int turn){
  int a = -1;
  int rx = -1, ry = -1;
  for(int i=0; i<8; i++){
    for(int j=0; j<8; j++){
      int x = j, y = i;
      if( turn % 2 == 1 ) x = 7 - j;
      if( turn % 2 == 1 ) y = 7 - i;
      if( s[y][x] != '.' ) continue;

      int r = calc(s, turn, y, x);
      if( a < r ){
        a = r;
        rx = x;
        ry = y;
      }
    }
  }
  // cerr << a << " " << rx << " " << ry << endl;
  if( a <= 0 ) return s;
  return rev(s, turn, ry, rx);
}

int main(void) {

  vector<string> s(8);
  for(int i=0; i<8; i++) cin >> s[i];
  int q = 0;
  int turn = 0;
  while( turn < 200 ){
    vector<string> t = func(s, turn);
    turn++;
    if( s == t ) q++;
    s = t;
    // if( q > 3 ) break;
    // for(int i=0; i<8; i++) cerr << s[i] << endl;
    // cerr << endl;
  }

  for(int i=0; i<8; i++){
    cout << s[i] << endl;
  }

  return 0;
}


// EOF

Measured memory_bytes: 3232
N=int(input())
S=input()
ans=[]
black=0
white=0
for n in range(N):
    if S[n]=='.':
        white+=1
    else:
        black+=1
stones={'b':0,'w':white}
for n in range(N):
    if S[n]=='#':
        stones['b']+=1
    else:
        stones['w']-=1
    ans.append(stones['b']+stones['w'])
if 'b' in stones:
    if stones['b']==N:
        print(0)
    else:
        print(min(min(ans),white,black))
else:
    print(min(min(ans),white,black))


Measured memory_bytes: 86980
import java.util.Scanner;

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



Measured memory_bytes: 26116
class UnionFind:
    def __init__(self, N, l):
        self.roots = list(range(N+1))
        self.counter = [1]*(N+1)
        for a, b in l:
            self.union(a, b)

    def get_root(self, n):
        if self.roots[n] != n:
            self.roots[n] = self.get_root(self.roots[n])
        return self.roots[n]

    def union(self, a, b):
        a, b = sorted([self.get_root(a), self.get_root(b)])
        if a != b:
            self.roots[b] = a
            self.counter[a] += self.counter[b]
            self.counter[b] = 0

    def find(self, a, b):
        return self.get_root(a) == self.get_root(b)

    def count(self, x):
        return(self.counter[self.get_root(x)])


N, M, K = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for _ in range(M)]
cd = [[int(i) for i in input().split()] for _ in range(K)]
friend = [[] for _ in range(N+1)]
uf = UnionFind(N, ab)

for a, b in ab:
    friend[a].append(b)
    friend[b].append(a)

ans = [uf.count(i)-1-len(friend[i]) for i in range(N+1)]

for c, d in cd:
    if uf.find(c, d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans[1:])


Measured memory_bytes: 125784
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll p1,p2;
ll mx1,mx2;

vector<vector<ll> > vv;

void dfs(ll a, ll p, ll h){
  if(h+1>mx1){
    mx1 = h+1;
    p1 = a;
  }
  if(vv[a].sz==1&&p!=-1){
    return;
  }
  rep(i,0,vv[a].sz){
    if(vv[a][i]==p)continue;
    dfs(vv[a][i],a,h+1);
  }
  return;
}

int main(){
  ll n;
  cin>>n;
  if(n==1){
    cout << "First" << endl;
    return 0;
  }
  if(n==2){
    cout << "Second" << endl;
    return 0;
  }
  vector<vector<ll> > vv_(n,vector<ll>());
  vv = vv_;
  rep(i,0,n-1){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    vv[a].pb(b);
    vv[b].pb(a);
  }
  mx1 = 0;
  dfs(0,-1,0);
  mx1 = 0;
  dfs(p1,-1,0);
  if((mx1-2)%3==0){
      cout << "Second" << endl;
    }
    else{
      cout << "First" << endl;
    }
  
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> A,B;
  for(int i=0;i<n;i++){
    int x,y;
    cin >> x >> y;
    A.push_back(x+y);
    B.push_back(x-y);
  }
  int amx = *max_element(A.begin(),A.end());
  int amn = *min_element(A.begin(),A.end());
  int bmx = *max_element(B.begin(),B.end());
  int bmn = *min_element(B.begin(),B.end());
  
  int x = 0;
  int y = 0;
  for(int i=0;i<n;i++){
    x = max(x,min(max(amx-A[i],bmx-B[i]),max(A[i]-amn,B[i]-bmn)));
    y = max(y,min(max(amx-A[i],B[i]-bmn),max(A[i]-amn,bmx-B[i])));
  }
  cout << min(x,y) << endl;
}

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

const int N=2e5+100;
const int C=1e5+10;

int a[N],b[N];

int main(){
	int n;
	scanf("%d",&n);
	a[C]++; 
	b[C]++;
	for(int i=0;i<n;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		l+=C;
		r+=C;
		a[l]++;
		b[r]++;
	}
	for(int i=N-2;i>=0;i--) a[i]+=a[i+1];
	for(int i=1;i<N;i++) b[i]+=b[i-1];
	long long ans=0;
	for(int i=0;i<N;i++) ans+=min(a[i+1],b[i]);
	printf("%lld",ans*2);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<queue>
#define ll long long
#define inf INT_MAX
main()
{
	ll int n;
	cin>>n;
	ll int h[n],d[n];
	memset(h,0,sizeof(d));
for(int i=0;i<n;i++)
{
	cin>>h[i];
}
d[0]=0;
d[1]=abs(h[1]-h[0]);
for(int i=2;i<n;i++)
{
	d[i]=min(d[i-1]+abs(h[i-1]-h[i]),d[i-2]+abs(h[i-2]-h[i]));
}
cout<<d[n-1]<<endl;

}


Measured memory_bytes: 1792
# coding=utf-8


def fib(number):
    if number == 0 or number == 1:
        return 1
    memo1 = 1
    memo2 = 1

    for i in range(number-1):
        memo1, memo2 = memo1+memo2, memo1
    return memo1


if __name__ == '__main__':
    N = int(input())
    print(fib(N))



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

int dx[2] = {1, 0};
int dy[2] = {0, 1};
const ll INF = 1LL<<60;

struct V {
  P p; 
  ll cost;
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) {
    cin >> s[i];
  }
  vector<vector<ll> > costs(h, vector<ll>(w,INF));
  queue<V> que;
  V v;
  v.p = P(0,0);
  if (s[0][0] == '#') v.cost = 1;
  else v.cost = 0;
  que.push(v);
  while (!que.empty()) {
    V v = que.front(); que.pop();
    rep(i,2) {
      int y = v.p.first + dy[i];
      int x = v.p.second + dx[i];
      if (x < 0 || y < 0 || x >= w || y >= h) continue;
      V nextv;
      //白から黒にいくときだけcostに+1
      if (s[v.p.first][v.p.second] == '.' && s[y][x] == '#') nextv.cost = v.cost+1;
      else nextv.cost = v.cost;
      if (nextv.cost >= costs[y][x]) continue;
      costs[y][x] = nextv.cost; //update
      nextv.p = P(y,x);
      que.push(nextv);
    }
  }
  cout << costs[h-1][w-1] << endl;
  return 0;
}

Measured memory_bytes: 384
temp = input().split(" ")
n = int(temp[0])
inp = input().split(" ")
nums = [0 for a in range(100003)]
for a in range(n):
    nums[int(inp[a])+1]+=1
    nums[int(inp[a])+2]+=1
    nums[int(inp[a])]+=1
print(max(nums))
 

Measured memory_bytes: 10764
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

S = input()
T = input()

ans = 0
for i in range(len(S)):
	if S[i] != T[i]:
		ans += 1

print(ans)

Measured memory_bytes: 10716
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int d, t, s; cin >> d >> t >> s;
  cout << (d <= t * s ? "Yes" : "No") << endl;

  return 0;
}

// EOF

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

using namespace std;

#define int long long

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, m, x;
  cin >> n >> m >> x;
  int ans = 1e9;
  int A[n][m+1];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m + 1; ++j) {
      cin >> A[i][j];
    }
  }

  for (int mask= 0; mask < 1 << n; ++mask) {
    int h[m+1] = {};
    int cost = 0;
    for (int i = 0; i < n; ++i) {      
      if (mask >> i & 1) {
        cost += A[i][0];
        for (int j = 1; j <= m; ++j) {
          h[j] += A[i][j];
        }
      }
    }
    // cout << cost << '\n';
    bool pos = true;
    for (int i = 1; i <= m; ++i){
      pos &= h[i] >= x;
      // cout << h[i] << ' ';
    }
    // cout << '\n';
    if (pos) ans = min(ans, cost);
  }
  if (ans == 1e9) ans = -1;
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 3644
@cnt = 0
def bubble_sort(array)
	length = array.length
  for i in 1..length do
    for j in 1..(length-i) do
      if array[j - 1] > array[j]
        t = array[j]
        array[j] = array[j - 1]
        array[j - 1] = t
				@cnt += 1
      end
    end
  end
	return array
end

size = gets.chomp.to_i
input_values = gets.chomp.split.map(&:to_i)

bubble_sort(input_values)
puts input_values.join(' ')
puts @cnt

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const string YES = "YES";
const string NO = "NO";

void solve(long long N, long long K) {
  if( (N + 1) / 2 >= K ){
    cout << YES << endl;
  }else{
    cout << NO << endl;
  }

}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int main(){
    string A;cin>>A;
    map<char,vector<int>> m;
    map<int,int> len;
    set<char> s;
    int l{1};
    for(int i{(int)A.size()-1};i>=0;--i){
        s.insert(A[i]);
        m[A[i]].push_back(i);
        if(s.size()>=26)++l,s.clear();
        len[i]=l;
    }
    for(auto& x:m)sort(x.second.begin(),x.second.end());
    int a{};
    for(;;){
        if(l<=1){
            for(int i{};i<26;++i){
                char c='a'+i;
                if(lower_bound(m[c].begin(),m[c].end(),a)==m[c].end()){cout<<c;break;}
            }
            break;
        }
        for(int i{};i<26;++i){
            char c='a'+i;
            int b{*lower_bound(m[c].begin(),m[c].end(),a)};
            if(lower_bound(m[c].begin(),m[c].end(),b)!=m[c].end()&&len[a]==len[b+1]+1){
                cout<<c;
                a=b+1;
                --l;
                break;
            }
        }
    }
    cout<<endl;
}


Measured memory_bytes: 10756
import java.util.Scanner;
 
class Main {
	int k;
	int s;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		k = sc.nextInt();
		s = sc.nextInt();
	}
	void solve(){
		int ans = 0;
		for(int x=0;x<=k;x++){
			for(int y=0;y<=k;y++){
				if((s-(x+y)<=k)&&(s-(x+y)>=0)) ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

ll gcd(ll A, ll B)
{
    if (A < B)
    {
        swap(A, B);
    }

    while (1)
    {
        ll r = A % B;
        if (r == 0)
        {
            return B;
        }
        A = B;
        B = r;
    }
}

ll cal2(ll x, ll C, ll D)
{
    ll gcdCD = (C * D) / gcd(C, D);
    ll ans = x - (x / C) - (x / D) + (x / gcdCD);
    return ans;
}

void solve()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll ans = cal2(B, C, D) - cal2(A - 1, C, D);
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import permutations
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M,R=map(int,input().split())
    r=list(map(lambda x:int(x)-1,input().split()))
    d=[[INF]*N for _ in range(N)]
    for i in range(M):
        A,B,C=map(int,input().split())
        A-=1; B-=1
        d[A][B]=C
        d[B][A]=C
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    ans=INF
    for p in permutations(r):
        tmp=0
        for i in range(R-1):
            tmp+=d[p[i]][p[i+1]]
        ans=min(ans,tmp)
    print(ans)
            

if __name__ == '__main__':
    main()


Measured memory_bytes: 42204
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
int n,k,w[100000];
int check(int P)
{
	int j,i2=0;
	long long int sum;
	for(j=1;j<=k;j++)
	{
		sum=0;
		while(sum+w[i2+1]<=P)
		{
			i2++;
			sum+=w[i2];
			if(i2==n)
				return n;
		}
	}
	return i2;
}
int binarysearch(int left,int right,int minP)
{
	if(left>right)
		return minP;
	int mid;
	mid=(left+right)/2;
	int v=check(mid);
	if(v>=n)
	{
		if(minP>mid)
			minP=mid;

		binarysearch(left,mid-1,minP);
	}
	else
		binarysearch(mid+1,right,minP);
}
int main()
{
	int i,p;
	int MAX=100000*10000;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%d",&w[i]);
	p=binarysearch(0,MAX,MAX);
	printf("%d\n",p);
	return 0;
}


Measured memory_bytes: 2188
X, K, D = map(int, input().split())

N = X // D
if K < abs(N):
    ans = abs(abs(X) - K * D)
else:
    if (K - abs(N)) % 2 == 0:
        ans = abs(X - N * D)
    else:
        ans = abs(X - (N+1) * D)

print(ans)


Measured memory_bytes: 9044
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
 
 public class Main {
   public static void main(String[] args) throws IOException {
     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
     int n = Integer.parseInt(in.readLine());
     StringTokenizer stk = new StringTokenizer(in.readLine());
     in.close();
     char[] s = stk.nextToken().toCharArray();
     int abc_cnt = 0;
     for (int i=0; i<n-2; i++){
       if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
         abc_cnt++;
     }
     System.out.println(abc_cnt);
   }
 }

Measured memory_bytes: 22996
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define INF (long)1e+9

typedef long long ll;
typedef pair<ll, ll> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

void solve(void){
    int n;
    cin >> n;
    int isopen[n][10];
    ll benefit[n][11];
    rep(n, i) rep(10, k) scanf("%d", &isopen[i][k]);
    rep(n, i) rep(11, k) scanf("%lld", &benefit[i][k]);
    int digit = 0; bool flag[11];
    fill(flag, flag+11, false);
    ll score = -INF;
    rep(pow(2, 10)-1, i){
        while (flag[digit]) {
            flag[digit] = false;
            digit++;
        }
        flag[digit] = true; digit = 0;
        ll temp_score = 0;
        rep(n, j) {
            int count = 0;
            rep(10, k) if(isopen[j][k] and flag[k]) count++;
            temp_score += benefit[j][count];
        }
        score = max(score, temp_score);
    }
    cout << score << endl;
}

int main(void){
  solve();
  return 0;
}


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

int main(){
	int n;
	cin >> n;
	char tmp;

	while(n != 0){

		map <char,int> c;
		map <char,int>::iterator ic;
		int flag = 0;
		int flag2 = 0;
		char max;
		char second_max;

		cin >> max;
		second_max = max;
		c[max]++;

		if(n == 1){
			cout << max << " " << 1 << endl;
			flag = 1;
		}else{
			for(int i = 2 ; i <= n ; i++){
				cin >> tmp;
				c[tmp]++;
				if(tmp != max){
					if(flag2 == 0){
						second_max = tmp;
						flag2 = 1;
					}else if(c[max] <= c[tmp]){
						second_max = max;
	 					max = tmp;
					}else if(c[second_max] < c[tmp]){
						second_max = tmp;
					}
				}

				if((flag == 0 && c[max] - c[second_max] > n-i) || (flag2 == 0 && n - c[max] < c[max] )){
				  cout << max << " " << i << endl;
					flag = 1;
					flag2 = 1;
				}
			}
		}

		if(flag == 0){
			cout << "TIE" << endl;
		}

		for(ic = c.begin() ; ic != c.end() ; ic++){
		}
		cin >> n;
	}
	return 0;
}



Measured memory_bytes: 3084
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		StringBuilder sb = new StringBuilder();
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		switch (s) {
		case "Sunny":
			sb.append("Cloudy");
			break;
		case "Cloudy":
			sb.append("Rainy");
			break;
		case "Rainy":
			sb.append("Sunny");
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="SUN")cout<<7;
    if(s=="MON")cout<<6;
    if(s=="TUE")cout<<5;
    if(s=="WED")cout<<4;
    if(s=="THU")cout<<3;
    if(s=="FRI")cout<<2;
    if(s=="SAT")cout<<1;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

/*
//D
int main(void) {

}
*/


//C
int main(void) {
	ll n;
	//上記には含まない
	ll aECount = 0;
	ll bSCount = 0;
	ll spCount = 0; //Specila count
	cin >> n;
	ll ans = 0;
	rep(0, n) {
		string str;
		cin >> str;
		if (str[0] == 'B' && str[str.size() - 1] == 'A') spCount++;
		else if (str[0] == 'B') bSCount++;
		else if (str[str.size() - 1] == 'A')aECount++;
		string::size_type pos = str.find("AB");
		while (pos != string::npos) {
			ans++;
			pos = str.find("AB", pos + 2); //"AB".length
		}
	}

	
	//aE + bSaE + bS
	if (spCount == 0) {
		ans += min(aECount, bSCount);
	}
	else {
		ll m = min(aECount, bSCount);
		m = min(m, spCount);
		if (m == spCount) {
			ans += spCount * 2;
			ans += min(aECount, bSCount) - spCount;
		}
		else if (m == aECount) {
			ans += aECount * 2;
			if (bSCount == 0) {
				ans += max((ll)0, spCount - 1);
			}
			else {
				ans += spCount - aECount;
			}
			
		}
		else if (m == bSCount) {
			ans += bSCount * 2;
			if (aECount == 0) {
				ans += max((ll)0, spCount - 1);
			}
			else {
				ans += spCount - bSCount;
			}

		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int dp[3030][3030];

int A, B, C, D;
long long int MOD = 998244353;

int main(void) {

	cin >> A >> B >> C >> D;

	dp[A][B] = 1;

	for (int i = A; i <= C; i++) {
		dp[i + 1][B] = (dp[i][B] * B)%MOD;
	//	cout << dp[i + 1][B] << endl;
	}

	for (int j = B; j <= D; j++) {
		dp[A][j + 1] = (dp[A][j] * A) % MOD;
	}

	for (int i = A+1 ; i <= C; i++) {
	//	long long int tmp = (dp[i - 1][B]*B)%MOD;
		for (int j = B+1; j <= D; j++) {
		//	tmp *= i; tmp %= MOD; tmp += dp[i - 1][j]; tmp %= MOD;
			dp[i][j] = (dp[i - 1][j] * j + dp[i][j - 1] * i - ((((dp[i - 1][j - 1] * (i - 1)) % MOD)*(j - 1)) % MOD) + MOD) % MOD;
		}
	}

	cout << dp[C][D] << endl;

	return 0;
}

Measured memory_bytes: 74564
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>

using namespace std;

using ll = long long;
using ld = long double;
using lli = long long int;
using ull = unsigned long long;

#define PI 3.14159265358979323846264338327950L

int main(){
  ull N, Q, A_i, B_i, C_i, temp, sum=0;
  vector<ull> A_num(100001, 0);

  cin >> N;
  for(ull i=0; i<N; i++){
    cin >> temp;
    A_num.at(temp) += 1;
    sum += temp;
  }

  cin >> Q;
  for(ull i=0; i<Q; i++){
    cin >> B_i >> C_i;
    if(A_num[B_i] != 0){
      sum += A_num[B_i] * (C_i - B_i) ;
      A_num[C_i] += A_num[B_i];
      A_num[B_i] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 3780
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

alias P = Tuple!(int, "to", long, "c");

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto G = new P[][N];
    foreach (i; 1..N) {
        G[i] ~= P(i-1, 0);
    }
    foreach (_; 0..M) {
        auto lrc = readln.split.to!(int[]);
        auto L = lrc[0]-1;
        auto R = lrc[1]-1;
        long C = lrc[2];
        G[L] ~= P(R, C);
    }

    auto Q = heapify!"a.c > b.c"([P(0, 0)]);
    auto DP = new long[](N);
    DP[] = long.max/3;
    DP[0] = 0;
    while (!Q.empty) {
        auto i = Q.front.to;
        auto c = Q.front.c;
        Q.popFront();
        if (DP[i] < c) continue;
        foreach (n; G[i]) if (DP[n.to] > c + n.c) {
            DP[n.to] = c + n.c;
            Q.insert(P(n.to, c + n.c));
        }
    }
    writeln(DP[N-1] == long.max/3 ? -1 : DP[N-1]);
}

Measured memory_bytes: 24784
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int H = int.Parse(str[0]);
        int W = int.Parse(str[1]);
        long K = long.Parse(str[2]);
        bool[,] b = new bool[H,W];
        long c = 0;
        long e = 0;
        for(int i=0;i<H;i++){
            string s = Console.ReadLine();
            for(int j=0;j<W;j++){
                b[i,j] = s[j] == '#';
                if(b[i,j]){
                    c++;
                }
            }
        }
        bool b1 = false;
        for(int i=0;i<W;i++){
            if(b[0,i] && b[H-1,i]){
                b1 = true;
                e++;
            }
        }
        bool b2 = false;
        for(int i=0;i<H;i++){
            if(b[i,0] && b[i,W-1]){
                b2 = true;
                e++;
            }
        }
        if(b1 && b2){
            sb.Append("1\n");
        }
        else{
            long d = 0;
            if(b1){
                for(int i=0;i<H-1;i++){
                    for(int j=0;j<W;j++){
                        if(b[i,j] && b[i+1,j]){
                            d++;
                        }
                    }
                }
            }
            if(b2){
                for(int i=0;i<H;i++){
                    for(int j=0;j<W-1;j++){
                        if(b[i,j] && b[i,j+1]){
                            d++;
                        }
                    }
                }
            }
            long[,] M = new long[2,2];
            M[0,0] = c;
            M[0,1] = Define.mod-d;
            M[1,1] = e;
            long[,] ans = Pow(M,K-1);
            sb.Append((ans[0,0]+ans[0,1])%Define.mod+"\n");
        }
    }
    long[,] Mul(long[,] a,long[,] b){
        long[,] c = new long[a.GetLength(0),b.GetLength(1)];
        for(int i=0;i<a.GetLength(0);i++){
            for(int j=0;j<b.GetLength(1);j++){
                long d = 0;
                for(int k=0;k<a.GetLength(1);k++){
                    d = (d+a[i,k]*b[k,j])%Define.mod;
                }
                c[i,j] = d;
            }
        }
        return c;
    }
    long[,] Pow(long[,] a,long e){
        if(e == 0){
            long[,] c = new long[a.GetLength(0),a.GetLength(0)];
            for(int i=0;i<a.GetLength(0);i++){
                for(int j=0;j<a.GetLength(0);j++){
                    c[i,j] = i == j ? 1 : 0;
                }
            }
            return c;
        }
        else if(e%2 == 0){
            long[,] b = Mul(a,a);
            return Pow(b,e/2);
        }
        else{
            return Mul(Pow(a,e-1),a);
        }
    }
}
public static class Define{
    public const long mod = 1000000007;
}

Measured memory_bytes: 17272
#include<stdio.h>
#include<string.h>
#include<queue>
#include<map>
#include<map>
#include<vector>
#include<utility>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    int t;
    ll n,m;
    cin>>n;
    if(n%500==0)
        printf("%lld",n/500*1000);
    else {
        ll t=n/500*1000;
        n%=500;
        printf("%lld",t+n/5*5);
        
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program2
    {
        static void Main(string[] args)
        {
            int a, c, d;
            c = 0;
            List<int> intlist = new List<int>();

            int alice = 0;
            int bob = 0;
            /*
            string[] a = Console.ReadLine().Split(' ');
            long b = long.Parse(a[0]);
            long c = long.Parse(a[1]);
            long d;
            */

            a = int.Parse(Console.ReadLine());
            //b = int.Parse(Console.ReadLine());
            string[] b = Console.ReadLine().Split(' ');

            for(int i = 0;i<b.Length;i++)
            {
                intlist.Add(int.Parse(b[i]));
            }
            intlist.Sort();
            intlist.Reverse();

            for(int i = 0;i < intlist.Count;i += 1)
            {
                if (i % 2 == 0)
                {
                    alice += intlist[i];
                }
                else
                    bob += intlist[i];
            }
            c = alice - bob;
            Console.Write(c);
        }
    }
}


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

namespace ABC093_A_abc_of_ABC
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string s = Console.ReadLine();
			List<string> sArr = new List<string>();
			for (int i = 0; i < 3; i++)
			{
				sArr.Add(s.Substring(i, 1));
			}

			if (sArr.Any(x => x == "a") && sArr.Any(x => x == "b") && sArr.Any(x => x == "c"))
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
		}
	}
}

Measured memory_bytes: 13268
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x = I()
if x >= 30:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 65416