akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

signed main(){
	int flg = 0;
	int K,A,B;
	cin >> K >> A >> B;
	FOR(i,A,B + 1){
		if(i % K == 0)flg = 1;
	}
	if(flg)out("OK");
	else out("NG");
}

Measured memory_bytes: 3652
n,m=map(int,input().split())
pys=[]
def make_number(p,x):
    return str(p*10**6+x).zfill(12)
for i in range(m):
    a,b=map(int,input().split())
    pys.append([a,b,i])
pys.sort()
ans=[i for i in range(m)]
c=-1
j=0
for [p,y,s] in pys:
    if c!=p:
        j=1
        c=p
    ans[s]=make_number(p,j)
    j+=1
for i in range(m):
    print(ans[i])

Measured memory_bytes: 34364
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define Rint register int
#define Temp template<typename T>
#define mem(a,b) memset(a,(b),sizeof(a))
typedef long long LL;
using namespace std;
Temp inline void read(T &x){
    x=0;T w=1,ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
    x=x*w;
}

const int maxn=1000+10;
int n;
int a[maxn],b[maxn],c[maxn],d[maxn];
int ans;
bool G[maxn<<1][maxn<<1];
bool vis[maxn];
int mat[maxn];
inline bool dfs(int x){
	for(Rint i=n+1;i<=(n<<1);i++){
		if(vis[i]==0&&G[x][i]){
			vis[i]=1;
			if(mat[i]==0||dfs(mat[i])){
				mat[i]=x;
				return true;
			}
		}
	}
	return false;
}

int main(){
	read(n);
	for(Rint i=1;i<=n;i++)read(a[i]),read(b[i]);
	for(Rint i=1;i<=n;i++)read(c[i]),read(d[i]);
	for(Rint i=1;i<=n;i++){
		for(Rint j=1;j<=n;j++){
			if(a[i]<c[j]&&b[i]<d[j])G[i][n+j]=1,G[n+j][i]=1;
		}
	}
	for(Rint i=1;i<=n;i++){
		mem(vis,0);
		if(dfs(i))ans++;
	}
	printf("%d\n",ans);
//	for(Rint i=n+1;i<=(n<<1);i++)cout<<i<<' '<<mat[i]<<endl;
    return 0;
}

Measured memory_bytes: 640
def main():
    A, B = map(int, input().split())
    if A == B:
        print('Draw')
    elif A == 1 and B <= 13:
        print('Alice')
    elif B == 1 and A <= 13:
        print('Bob')
    elif A > B:
        print('Alice')
    elif B > A:
        print('Bob')
main()

Measured memory_bytes: 9172
#include <stdio.h>

int main() {
	int fold, dist1, dist2;
	scanf("%d", &fold);
	scanf("%d %d", &dist1, &dist2);
	while (dist1 <= dist2) {
		if(dist1 % fold == 0) {
			printf("OK");
			return 0;
		}
		dist1++;
	}
	printf("NG");
	return 0;
}

Measured memory_bytes: 1688
package main

import "fmt"

func main() {
	xs := make([]int, 5)
	var sum, max int
	for i := range xs {
		fmt.Scan(&xs[i])
		if xs[i]%10 == 0 {
			sum += xs[i]
		} else {
			sum += (xs[i]/10 + 1) * 10
			if v := 10 - xs[i]%10; v > max {
				max = v
			}
		}
	}
	fmt.Println(sum - max)
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
root=[i for i in range(n+1)]
def r(x):
    if root[x]==x:
        return x
    else:
        root[x]=r(root[x])
        return root[x]
def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    if x>y:
        x,y=y,x
    root[y]=x

for i in range(m):
    x,y=map(int,input().split())

    unite(x,y)
ans=0
size=[0]*(n+1)
for i in range(n):
    size[r(i+1)]+=1

for i in range(n):
    ans=max(ans,size[i+1])

print(ans)


Measured memory_bytes: 87112
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {

	int x;
	scanf("%d", &x);
	int i = 0;
	for ( ; i<= x ; i++ ){
		if (i * (i-1) >= 2*x) {
			break;
		}
	}
	cout << i-1 << endl;;
}


Measured memory_bytes: 3620
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif




#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()   //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend()//...,3,2,1

using namespace std;
//using ll = long long;


const int MOD = 1000000007;
const int INF = 1e18;

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

const double pi = acos(-1);



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


using Graph = vector<vector<int>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//*max_element(ALL(vector))
//count(ALL(vector),num) -> n




void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

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

    int k; cin >> k;
    int a,b; cin >> a >> b;
    
    bool isOK = false;
    for (int i = 0; i < 100010; i++) {
        if(a<=k*i && k*i<=b) {
            isOK = true;
            break;
        }
    }
    
    cout << ((isOK)?"OK":"NG") << endl;
    
    
    
    
}



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



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n,k,s;
    cin>>n>>k>>s;

    if(n==k){
        rep(i,n) cout<<s<<" ";
        cout<<endl;
    }
    else if(s==1){
        rep(i,k) cout<<s<<" ";
        rep(i,n-k) cout<<s+1<<" ";
        cout<<endl;
    }
    else{
        rep(i,k) cout<<s<<" ";
        rep(i,n-k) cout<<s-1<<" ";
        cout<<endl;
    }

}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int x[3][3],y[3][3],z[3][2],a[3];
int main(){
for(int i=0;i<3;i++){cin>>x[i][0]>>x[i][1]>>x[i][2]>>y[i][0]>>y[i][1]>>y[i][2];
z[i][0]=x[i][0]*3600+x[i][1]*60+x[i][2];z[i][1]=y[i][0]*3600+y[i][1]*60+y[i][2];}
for(int i=0;i<3;i++){a[i]=z[i][1]-z[i][0];}
for(int i=0;i<3;i++){cout<<a[i]/3600<<' '<<(a[i]/60)%60<<' '<<a[i]%60<<endl;}
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, X;
    cin >> N >> M >> X;
    int lcost = 0;
    int rcost = 0;
    for (int i=0; i<M; ++i) {
        int Ai;
        cin >> Ai;
        if (Ai < X)
            ++lcost;
        else
            ++rcost;
    }
    cout << (lcost < rcost ? lcost : rcost) << '\n';
    return 0;
}


Measured memory_bytes: 888
module DoublyLinkedList = struct
  type t = {
    mutable data : int;
    mutable next : t;
    mutable prev : t;
  }

  let make () =
    let rec head = { data = 0; next = head; prev = head } in
    head

  let insert data head =
    let x = { data = data; next = head.next; prev = head } in
    head.next.prev <- x;
    head.next <- x

  let delete x =
    x.next.prev <- x.prev;
    x.prev.next <- x.next

  let delete_first head = delete head.next

  let delete_last head = delete head.prev

  let delete_node data head =
    let rec doit ite =
      if ite == head then None
      else if ite.data = data then Some ite
      else doit ite.next in
    match doit head.next with
    | None -> ()
    | Some ite -> delete ite

  let iteri f head =
    let rec doit i ite =
      if ite == head then ()
      else begin
        f i ite.data;
        doit (i + 1) ite.next
      end in
    doit 0 head.next
end

module L = DoublyLinkedList

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let head = L.make () in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["insert"; n] -> L.insert (int_of_string n) head
    | ["delete"; n] -> L.delete_node (int_of_string n) head
    | ["deleteFirst"] -> L.delete_first head
    | _ -> L.delete_last head
  done;
  L.iteri (fun i n -> if i <> 0 then print_string " "; print_int n) head;
  print_newline ()

Measured memory_bytes: 41020
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,a[maxn];

int main() {
//  freopen("in.cpp","r",stdin);
  int n;
  ll sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  sort(a,a+n);
  int ret=1;
  for(int i=n-2;i>=0;i--){
    sum-=a[i+1];
    if(sum + sum >= a[i+1])ret++;
    else break;
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 640
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//


int32_t main()
{
    io;
    string s;
    cin>>s;
    int n = s.size();
    if(s[n-1] == '3')
        cout<<"bon";
    else if(s[n-1] == '0' || s[n-1] == '1' || s[n-1] == '6' || s[n-1] == '8')
        cout<<"pon";
    else
        cout<<"hon";
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    string ans;
    if(a.size() > b.size()) ans = "GREATER";
    else  if(a.size() < b.size()) ans = "LESS";
    else {
        if(a < b) ans = "LESS";
        else if(a > b) ans = "GREATER";
        else ans = "EQUAL";
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

plist = make_divisors(N)

ans = 0
for p in plist:
    if p == N : continue
    m = N//p - 1
    if m > p:
        ans += m
        
print(ans)


Measured memory_bytes: 3268
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <cmath>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;



lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    cin >> a >> b >> c;



    cout <<  ((a+b>=c)?"Yes":"No")    << endl;


//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 256
(function (input) {
  'use strict';
  const lines = input.split('\n')
  const firstLine = lines[0].split(' ')
  const N = Number(firstLine[0])
  const T = Number(firstLine[1])

  let Max = 2000

  for (var i=1; i <= N ; i++) {
    const tmpline = lines[i].split(' ')
    const cost = Number(tmpline[0])
    const time = Number(tmpline[1])
    if ( time <= T && cost < Max) Max = cost
  }
  Max === 2000 ? console.log('TLE') : console.log(Max)
  
})(require("fs").readFileSync("/dev/stdin", 'utf8'));


Measured memory_bytes: 21064
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;
using ui = unsigned int;


int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	vector<int> dist(M-1);
	for (int i = 0; i < M; i++)
		cin >> X[i];
	sort(X.begin(), X.end());

	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}

	for (int i = 0; i < M-1; i++) {
		dist[i] = X[i+1] - X[i];
	}
	sort(dist.begin(), dist.end());
	for (int i = 0; i < N-1; i++) {
		dist[M-2-i] = 0;
	}
	cout << accumulate(dist.begin(), dist.end(), 0) << endl;

}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main() { 
    string S;
    cin >> S;
    int pre = 0;
    int ctp = 0;
    REP(i,S.size()){
        char s = S.at(i);
        if(s == 'C' or s == 'G' or s=='A' or s == 'T'){
            ctp += 1;
        }
        else{
            ctp = 0;
        }
        if(ctp>pre){
            pre = ctp;
        }
        
    }
    cout << pre << endl;
}


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

int main(){
  int a, b;
  while(1){
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    else{
      printf("%d %d\n", min(a, b), max(a, b));
    }
  }

  return 0;
}



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

signed main(){
	int A, V, B, W, T;
	scanf("%lld%lld%lld%lld%lld", &A, &V, &B, &W, &T);
	int D = abs(A - B);
	if(V * T >= D + W * T){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 3764
S=input()
T=input()
ans=1001

for i in range(len(S)):
  if i+len(T)>len(S):
    break
  
  subs=S[i:i+len(T)]
  tmp=0
  for j in range(len(T)):
    tmp=1+tmp if subs[j]!=T[j] else 0+tmp
  ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 9008
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
#define dd double
using namespace std;

int main(){
	string s[10005];
	string st="";
	ll a[10005][3]={0};
	memset(a,0,sizeof(a));
	ll n;cin>>n;
	for(ll i=0;i<n;i++){
		cin>>s[i];
		if(s[i][0]=='B'){
			a[i][0]++;
		}
		if(s[i][s[i].size()-1]=='A'){
			a[i][1]++;
		}
	}
	ll flag=0;
	for(ll i=0;i<n;i++){
		if(a[i][0]==0&&a[i][1]!=0){
			flag=1;
			st+=s[i];
			a[i][2]=-1;
			break;
		}
	}
	ll q=0;
	if(flag==1){
		for(ll i=0;i<n;i++){
			if(a[i][2]==-1){
				continue;
			}
			else{
				if(a[i][0]!=0&&a[i][1]!=0){
					st+=s[i];
					a[i][2]=-1;
				}
			}
		}
		for(ll i=0;i<n;i++){
			if(a[i][2]==-1){
				continue;
			}
			else{
				if(a[i][0]!=0){
					st+=s[i];
					a[i][2]=-1;
					break;
				}
			}
		}
		for(ll i=0;i<n;i++){
			if(a[i][2]==-1){
				continue;
			}
			else{
				if(q%2==0){
					if(a[i][1]!=0){
						st+=s[i];
						a[i][2]=-1;
						i=-1;
						q++;
					}
				}
				else{
					if(a[i][0]!=0){
						st+=s[i];
						a[i][2]=-1;
						i=-1;
						q++;
					}
				}
			}
		}
		for(ll i=0;i<n;i++){
			if(a[i][2]!=-1){
				st+=s[i];
				a[i][2]=-1;
			}
		}
	}
	if(flag==0){
		for(ll i=0;i<n;i++){
			if(a[i][1]!=0&&a[i][2]!=-1){
				st+=s[i];
				a[i][2]=-1;
				break;
			}
		}
		for(ll i=0;i<n;i++){
			if(a[i][2]==-1){
				continue;
			}
			else{
				if(a[i][0]!=0&&a[i][1]!=0){
					st+=s[i];
					a[i][2]=-1;
				}
			}
		}
		for(ll i=0;i<n;i++){
			if(a[i][2]==-1){
				continue;
			}
			else{
				if(a[i][0]!=0){
					st+=s[i];
					a[i][2]=-1;
				}
			}
		}
		for(ll i=0;i<n;i++){
			if(a[i][2]!=-1){
				st+=s[i];
				a[i][2]=-1;
			}
		}
	}
	ll count = 0;
	for(ll i=0;i<st.size()-1;i++){
		if(st[i]=='A'&&st[i+1]=='B'){
			count++;
		}
	}
	cout<<count<<endl;
} 

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int a[maxn], cnt[maxn];
map<int, int> mi;
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    a[0] = a[0] % m;
    for (int i = 1; i < n; ++i) a[i] = (a[i - 1] + a[i]) % m;
    for (int i = 0; i < n; ++i) ++mi[a[i]];
    long long ans = 0;
    for (auto o : mi){
        if (o.first == 0) ans += o.second;
        if (o.second > 1) ans += (long long)o.second * (o.second - 1) / 2;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    string S;
    cin >> S;
    long long ans=0;
    int count=0;
    rep(i,S.size()){
        if(S[i]=='W'){
            ans+=i;
            ans-=count;
            count++;
        }
    }
    cout << ans << endl;


}


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

int gcd(int m, int n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}

int main() {
  int n, k, g = 0, m = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    g = gcd(a, g);
    m = max(m, a);
  }
  if (k > m || k % g) {
    puts("IMPOSSIBLE");
  } else {
    puts("POSSIBLE");
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 500

static const int INFTY = (1<<21);

int main(){
  int n,i,j,a,b,e,sum,minv;
  int A[N][N],d[N],p[N],v[N];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d", &e);
      A[i][j] = (e==-1)?INFTY:e;
    }
  }

  for(i=0; i<n; i++){
    d[i] = INFTY;
    p[i] = -1;
    v[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    a = -1;
    for(i=0; i<n; i++){
      if(minv>d[i] && !v[i]){
        a = i;
        minv = d[i];
      }
    }
    if(a == -1)
      break;

    v[a] = 1;
    for(b=0; b<n; b++){
      if(!v[b] && A[a][b] != INFTY ){
        if(d[b] > A[a][b]){
          d[b] =  A[a][b];
          p[b] = a;
        }
      }
    }
  }

  sum = 0;

  for(i=0; i<n; i++){
    if(p[i] != -1){
      sum += A[i][p[i]];
    }
  }

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

  return 0;
}


Measured memory_bytes: 2088
/**
 *    author:  FromDihPout
 *    created: 2020-08-04
**/

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

#define all(x) (x).begin(), (x).end()

const int INF = 1e9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> a(r);
    for (int i = 0; i < r; i++) {
        cin >> a[i];
        a[i]--;
    }
    
    vector<vector<int>> dist(n, vector<int> (n, INF));
    for (int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        dist[u][v] = w;
        dist[v][u] = w;
    }
    for (int i = 0; i < n; i++) {
        dist[i][i] = 0;
    }
    
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    sort(all(a));
    int ans = INF;
    do {
        int curr_dist = 0;
        for (int i = 1; i < r; i++) {
            curr_dist += dist[a[i]][a[i-1]];
        }
        ans = min(ans, curr_dist);
    } while (next_permutation(all(a)));
    
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3764
/**
 * Title: C - Synthetic Kadomatsu
 * Url: https://atcoder.jp/contests/abc119/tasks/abc119_c
 */
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

#define ll long long
#define INF 1000000000

int n, A, B, C;

int dfs(int cur, int a, int b, int c, vector<int> l) {
    if(cur==n) {
        if(min(a, min(b, c))>0) {
            return abs(a-A)+abs(b-B)+abs(c-C) - 30;
        } else {
            return INF;
        }
    }
    int ret0 = dfs(cur+1, a, b, c, l);
    int ret1 = dfs(cur+1, a+l[cur], b, c, l) + 10;
    int ret2 = dfs(cur+1, a, b+l[cur], c, l) + 10;
    int ret3 = dfs(cur+1, a, b, c+l[cur], l) + 10;
    return min(ret0, min(ret1, min(ret2, ret3)));
}

int main() {
    cin >> n >> A >> B >> C;
    vector<int> l(n);
    for(int i=0; i<n; i++) cin >> l[i];
    cout << dfs(0, 0, 0, 0, l) << endl;

    return 0;
}

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/20
// Problem:A- Getting Difference a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

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

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1;

int N, K;

bool solve(vector< int > s)
{
  if (K > s[s.size() - 1]) return false;
  ll m_gcd = s[0];
  FOR(i, 1, N) {
    if (s[i] % m_gcd == 0) continue;
    m_gcd = s[i] % m_gcd;
  }
  if (K % m_gcd == 0) return true;
  return false;
}

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

  cin >> N >> K;
  vector< int > a(N);
  REP(i, N) {
    cin >> a[i];
  }
  sort(ALL(a));

  bool ok = solve(a);

  OK(ok);

  return 0;
}



Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int n; cin>>n;
    string s,t; cin>>s>>t;
    int ans=n*2;
    int cnt=0;
    rep(i,n){
        if(s.substr(i,n-i)==t.substr(0,n-i)){
            cnt=n-i;
            break;
        }
    }
    cout<<ans-cnt<<endl;
}








Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			int N = sc.nextInt();
			String s = sc.next();
			int R = 0, B = 0;
			for(int i = 0; i < N; i++) {
				if(s.charAt(i) == 'R') R++;
				else B++;
			}
			System.out.println(R > B ? "Yes" : "No");
		}
	}
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n+1);
    for (int i = n; i >= 0; i--) {
        cin >> a[i];
    }
    const int N = 45000; 
    vector<int> prime; prime.reserve(N);
    auto sieve = [&](){
        vector<bool> is(N+1, true);
        for (int p = 2; p*p <= N; p++) {
            if (is[p]) {
                for (int i = p*p; i <= N; i+=p) {
                    is[i] = false;
                }
            }
        }
        for (int p = 2; p <= N; p++) {
            if (is[p]) prime.emplace_back(p);
        }
    };
    sieve();
    auto check = [&](int p){
        if (a[0] % p) return false;
        for (int k = 1; k < p; k++) {
            int s = 0;
            for (int i = k; i <= n; i+=p-1) {
                s = (s+a[i]) % p;
            }
            s = (s+p) % p;
            if (s) return false;
        }
        return true;
    };
    vector<int> res; res.reserve(N);
    for (int p: prime) {
        if (p <= n && check(p))
            res.emplace_back(p);
    }
    int g = 0;
    for (int x: a) {
        g = __gcd(g, abs(x));
    }
    for (int p: prime) {
        if (g % p == 0) {
            res.emplace_back(p);
            while (g % p == 0) {
                g /= p;
            }
        }
    }
    if (g > 1) res.emplace_back(g);
    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end());
    for (int p: res) {
        cout << p << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
using namespace std;
const int N=100000+10;
int n,m,p[N];
int x[N],y[N];
int par[N];
int find(int x){
    return par[x]==x?x:par[x]=find(par[x]);
}
int ins(set<int> st1, set<int> st2) {
    int ans=0;
    for(auto x:st1) ans+=st2.count(x);
    return ans;
}
vector<int> v[N];
int main() {
    for(int i=0;i<N;i++)par[i]=i;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&p[i]);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&x[i],&y[i]);
        par[find(x[i])]=find(y[i]);
    }
    for(int i=1;i<=n;i++) v[find(i)].push_back(i);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i==find(i)){
            set<int> s1,s2;
            for(auto x: v[i]) s1.insert(x), s2.insert(p[x]);
            ans+=ins(s1,s2);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 23288
#include <bits/stdc++.h>
using namespace std;
#define w(x) int x;cin>>x;while(x--)
#define ll long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define vi vector<int>
#define fr(a,b) for(int i=a;i<=b;i++)
#define inf 1e18
#define mod 1000000007
int main()
{   
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
#endif*/
	fast;
    ll n;
    cin>>n;
    ll k=1;
    ll k1=1;
    ll k2=1;
    for(int i=1;i<=n;i++){
    	k=k*10;
    	k=k%mod;
    	k1=k1*9;
    	k1=k1%mod;
    	k2=k2*8;
    	k2=k2%mod;
    }
    ll k3=(2*k1)%mod;
    //cout<<k<<" "<<
    cout<<(k-k3+k2+mod)%mod<<"\n";
	return 0;
}

Measured memory_bytes: 3564
/*
AOJ - ITP1_10_d
Date: 20181014
Author: Mikoron * ♡mikoiwate_351♡
*/

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

#define NMAX 100

int main(void) {

        short n, i, x[NMAX], y[NMAX];
        double diff, max, p_1, p_2, p_3, p_inf;

                scanf("%hd", &n);

                for(i = 0; i < n; i++) {
                        scanf("%hd", &x[i]);
                }

                for(i = 0; i < n; i++) {
                        scanf("%hd", &y[i]);
                }

                max = p_1 = p_2 = p_3 = p_inf = 0.0;

                for(i = 0; i < n; i++) {
                        diff = (double)abs(x[i]-y[i]);
                        if(diff > max) max = diff;
                        p_1 += diff;
                        p_2 += pow(diff,2.0);
                        p_3 += pow(diff,3.0);
                }
                p_2 = pow(p_2,1.0/2.0);
                p_3 = pow(p_3,1.0/3.0);

                printf("%.7lf\n", p_1);
                printf("%.7lf\n", p_2);
                printf("%.7lf\n", p_3);
                printf("%.7lf\n", max);

        return 0;
}



Measured memory_bytes: 2124
from itertools import permutations as perm
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def is_prime(v):
    """素数"""
    if v <= 1:
        return False
    if v == 2:
        return True
    if v % 2 == 0:
        return False
    for x in range(3, ceil(v ** 0.5), 2):
        if v % x == 0:
            return False
    return True


def main():
    """エントリーポイント"""
    N = input(int)
    for x in range(N, 100003 + 1):
        if is_prime(x):
            print(x)
            break


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3316
def solve():
    s = input()
    t = input()

    for _ in range(len(s)):
        if s == t:
            print('Yes')
            break
        s = rotate(s)
    else:
        print('No')


def rotate(string):
    return string[1:] + string[0]


if __name__ == '__main__':
    solve()


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

static bool greater_sort(const pair <int, int>&a, const pair <int, int>&b) {
	if (a.first < b.first) return false;
	if (a.first > b.first) return true;
	if (a.second < b.second) return true;
	return false;
}

int main(void) {
	int N;
	cin >> N;
	vector <string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S.begin(), S.end());

	vector <pair <int, int>> cont;
	int same_cnt = 0;
	string before = "";
	for (int i = 0; i < N; i++) {
		if (before != S[i]) {
			cont.push_back(make_pair(same_cnt, i-1));
			same_cnt = 0;
			before = S[i];
		}
		same_cnt++;
	}
	cont.push_back(make_pair(same_cnt, N-1));

	sort(cont.begin(), cont.end(), greater_sort);
	int cnt_max = cont[0].first;

	for (int i = 0; i < cont.size(); i++) {
		if (cnt_max==cont[i].first) {
			cout << S[cont[i].second] << endl;
		} else {
			break;
		}
	}
  return 0;
}


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

int main()
{
	int N;
	cin >> N;
	int* C = new int[N];
	int* S = new int[N];
	int* F = new int[N];
	int* O = new int[N + 1];
	//N-1からもとめていく
	for (int i = 1; i < N; i++)
	{
		cin >> C[i] >> S[i] >> F[i];
	}
	O[N] = 0;

	for (int i = N-1; i >= 1; i--)
	{
			O[i] = S[i] + C[i];
		
		

		for (int j = i; j < N-1; j++)
		{
			
			O[i] = ((int)ceil((double)O[i] / F[j +1]) )*F[j +1];
			if (O[i] < S[j+1])
			{
				O[i] = S[j+1];
			}
			O[i] += C[j+1];
		}
	}
	for (int i = 1; i < N - 1; i++)
	{

	}
	for (int i = 1; i <= N; i++)
	{
		cout << O[i] << endl;
	}
	return 0;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	int f[90];
	f[0] = 2;
	f[1] = 1;
	FOR(i, 2, 87) {
		f[i] = f[i - 1] + f[i - 2];
	}
	print(f[n]);
}

Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int A,B;
    cin >> A >> B;
    
    int ans = A-B*2;
    if(ans>=0){
        cout << abs(ans) << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//
// Created by 李青坪 on 2018/11/20.
//

#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#define NIL -1
#define MAXN 10000

using namespace std;

typedef long long llong;

llong INFINITY = 1LL << 32;
llong graph[MAXN][MAXN];
int n, e;

void init(){
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            graph[i][j] = (i == j ? 0: INFINITY);
        }
    }
}

void floyd(){
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            if (graph[i][k] == INFINITY) continue;
            for (int j = 0; j < n; ++j) {
                if (graph[k][j] == INFINITY) continue;
                graph[i][j] = min(graph[i][j], graph[i][k]+graph[k][j]);
            }
        }
    }
}

int main() {
    scanf("%lld %d", &n, &e);
    init();
    llong u, v, w;
    for (int i = 0; i < e; ++i) {
        scanf("%lld %lld %lld", &u, &v, &w);
        graph[u][v] = w;
    }
    floyd();
    for (int j = 0; j < n; ++j) {
        if (graph[j][j] < 0) {
            printf("NEGATIVE CYCLE\n");
            return 0;
        }

    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            if (i) printf(" ");
            if (graph[k][i] == INFINITY) printf("INF");
            else printf("%lld", graph[k][i]);
        }
        printf("\n");
    }
}
/*
6 5
0 1 50
1 2 50
2 3 50
3 4 50
4 5 50
 */


Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        var sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        final long MOD = 1000000007;
        
        long a = 1;
        long b = 1;
        long c = 1;
        for(int i = 0; i < n; i++){
            a *= 10;
            a %= MOD;
            b *= 9;
            b %= MOD;
            c *= 8;
            c %= MOD;
        }
        long ans = a - b*2 + c;
        ans %= MOD;
        if(ans < 0) ans += MOD;
        System.out.println(ans);
    }
}

Measured memory_bytes: 35600
N, M = map(int, input().split())
AC_or_not = [False] * N
n_penalty = [0] * N
cnt_ac = 0
cnt_pen = 0

for _ in range(M):
    prob, wa_ac = input().split()
    prob = int(prob) - 1
    if wa_ac == 'AC':
        if not AC_or_not[prob]:
            cnt_pen += n_penalty[prob]
            cnt_ac += 1
            AC_or_not[prob] = True
    else:
            n_penalty[prob] += 1

print(cnt_ac ,cnt_pen)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
  int a, b, c; cin >> a >> b >> c;
  set<int> S;
  S.insert(a);
  S.insert(b);
  S.insert(c);
  cout << S.size() << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int count=1;
        while(true){
            int num = sc.nextInt();
            if(num == 0)
            break;
            else
            System.out.println("Case "+count++ +": "+num);
        }
    }
}


Measured memory_bytes: 41940
#include <stdio.h>

char
to_grade(int m, int f, int r)
{
	if (m == -1 || f == -1)   return 'F';
	if (m+f >= 80)            return 'A';
	if (m+f >= 65)            return 'B';
	if (m+f >= 50)            return 'C';
	if (m+f >= 30 && r >= 50) return 'C';
	if (m+f >= 30)            return 'D';
	return 'F';
}

int
main()
{
	for (;;)
	{
		int m, f, r;
		scanf("%d %d %d", &m, &f, &r);

		if (m == -1 && f == -1 & r == -1)
			break;

		char glade = to_grade(m, f, r);
		printf("%c\n", glade);
	}
	
	return 0;
}

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

class Mondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var array = new int[9];
        var rate = new int[] { 400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 4801 };
        for (int i = 0; i < 9; ++i) array[i] = 0;
        for (int i = 0; i < N; ++i)
        {
            for (int j = 0; j < rate.Length; ++j)
            {
                if (j == 8) {
                    array[j]++;
                }
                else if (a[i] < rate[j])
                {
                    if (array[j] == 0) { array[j]++; }
                    break;
                }
            }
        }
        var type = array.Take(8).Sum();
        var min = type == 0 ? 1 : type;
        var max = type + array[8];
        Console.WriteLine($"{min} {max}");
    }
}

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

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

  bool printed = false;
  rep(i, K) {
    if (printed) cout << " ";
    cout << S;
    printed = true;
  }

  rep(i, N - K) {
    if (printed) cout << " ";
    cout << (S == 1000000000 ? 1 : S + 1);
    printed = true;
  }
  return 0;
}


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

#define PI 3.14159265359

int main(){
   string S;
   cin >> S;
   if (S == "RRR") cout << 3 << endl;
   else if (S == "RRS" || S == "SRR") cout << 2 << endl;
   else if (S == "SSS") cout << 0 << endl;
   else cout << 1 << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	int N,ans=0,b=0,ba=0,a=0;
	string s;
	cin >> N;
	FOR(i,0,N){
		cin >> s;
		FOR(j,0,s.size()-1){
			if(s[j]=='A'&&s[j+1]=='B')ans++;
		}
		if(s[0]=='B'&&s[s.size()-1]=='A'){
			ba++;
		}else if(s[0]=='B'){
			b++;
		}else if(s[s.size()-1]=='A'){
			a++;
		}
	}
	if(ba){
		ans += ba-1;
		if(a){a--;ans++;}
		if(b){b--;ans++;}
	}
	cout << ans+min(a,b) << endl;
}


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

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

    bool flag1 = false;
    bool flag2 = false;

    if (S.at(2) == S.at(3)) {
        flag1 = true;
    }

    if (S.at(4) == S.at(5)) {
        flag2 = true;
    }

    if (flag1 & flag2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x>=0 && y>=0 && x+r<=W && y+r<=H)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}


Measured memory_bytes: 2148
using System;
using System.Linq;
namespace AtCoderTemplate
{public class App{public static void Main(string[] args)=>Console.WriteLine(Console.ReadLine().ToCharArray().Select((chars,index)=>new{chars,index}).Where(v=>v.chars=='W').Select((v,toPos)=>new{v.index,toPos}).Sum(v=>(long)(v.index-v.toPos)));}}

Measured memory_bytes: 18528
#include<stdio.h>

int main()
{
    long long int i,j;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            printf("%lldx%lld=%lld\n",i,j,i*j);
        }
    }
    return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) {
	int c[N + 1][N + 1];
	int m = X.size();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X; // X[0] に空白を挿入
	Y = ' ' + Y; // Y[0] に空白を挿入
	for ( int i = 0; i <= m; i++ ) c[i][0] = 0;
	for ( int j = 1; j <= n; j++ ) c[0][j] = 0;
	
	for ( int i = 1; i <= m; i++ ) {
		for ( int j = 1; j <= n; j++ ) {
			if ( X[i] == Y[j] ) {
				c[i][j] = c[i - 1][j - 1] + 1;
			} else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}
	
	return maxl;
}

int main() {
	string s1, s2;
	int n; cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}


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

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

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	os << "{";
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
	}
	os << "}";
	return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
	os << "{";
	repi(itr, map_var) {
		os << *itr;
		itr++;
		if (itr != map_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
	os << "{";
	repi(itr, set_var) {
		os << *itr;
		itr++;
		if (itr != set_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}

#define DUMPOUT cerr

void dump_func() {
	DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
	DUMPOUT << head;
	if (sizeof...(Tail) > 0) {
		DUMPOUT << ", ";
	}
	dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

	int N;
	cin >> N;
	vector<int> d(N);
	rep(i, N) cin >> d[i];

	int ans = 0;
	rep(i, N) for (int j = i + 1; j < N; j++) {
		ans += d[i] * d[j];
	}
	cout << ans << endl;

	
	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)

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

sk = sum(P[:K])
n = sum(P[:K])
for i in range(N):
    if i < K:
        continue

    n -= P[i - K]
    n += P[i]

    sk = max(sk, n)
    prev = n

ans = sk / 2. + K / 2.
print(ans)


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> grid(h);
	for (int i = 0; i < h; i++) {
		cin >> grid[i];
	}
	vector<vector<int>> section(h, vector<int>(w));
	vector<bool> empty(h, true);
	int cur = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (grid[i][j] == '#') {
				cur++;
				section[i][j] = cur;
				empty[i] = false;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (!section[i][j]) {
				section[i][j] = section[i][j - 1];
			}
		}
		for (int j = w - 2; j >= 0; j--) {
			if (!section[i][j]) {
				section[i][j] = section[i][j + 1];
			}
		}
	}
	for (int i = 1; i < h; i++) {
		if (empty[i]) {
			if (!empty[i - 1])
				empty[i] = false;
			for (int j = 0; j < w; j++)
				section[i][j] = section[i - 1][j];
		}
	}
	for (int i = h - 2; i >= 0; i--) {
		if (empty[i]) {
			for (int j = 0; j < w; j++)
				section[i][j] = section[i + 1][j];
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (j) cout << ' ';
			cout << section[i][j];
		}
		cout << '\n';
	}
}



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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int h, w, n;
  Solver2(LL h, LL w) : h(h), w(w){};

  void solve() {
    cin >> n;
    int ans = h;
    vector<int> p(h + 1, w + 1);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      p[x] = min(p[x], y);
    }
    int ub = 1;

    for (int i = 2; i <= h; ++i) {
      if (p[i] <= ub) {
        cout << i - 1 << endl;
        return;
      } else if (p[i] > ub + 1) {
        ub++;
      }
    }

    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, w;
  std::cin >> n >> w;

  Problem::Solver2 sol(n, w);
  sol.solve();
  return 0;
}


Measured memory_bytes: 1024
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 1005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int cnt[2005];

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

    int n, x, y;

    cin>>n>>x>>y;

    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            int dist = j - i;
            dist = min(dist, abs(i - x) + 1 + abs(y - j));
            cnt[dist]++;
        }
    }

    for(int i = 1; i <= n - 1; i++){
        cout<<cnt[i]<<endl;
    }
}


Measured memory_bytes: 256