akhauriyash/Code-Regression huggingface dataset:
H,W=map(int,input().split())
MAP=[input() for i in range(H)]

CANGO=[[0]*W for i in range(H)]
CANGO[0][0]=1

Q=[(0,0)]

while Q:
    x,y=Q.pop()

    for tox,toy in [[x+1,y],[x-1,y],[x,y+1],[x,y-1]]:
        if 0<=tox<H and 0<=toy<W and CANGO[tox][toy]==0:
            if tox%4==0:
                if toy%4==0 and MAP[tox][toy]=="6":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
                if toy%4==1 and MAP[tox][toy]=="3":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
                if toy%4==2 and MAP[tox][toy]=="1":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
                if toy%4==3 and MAP[tox][toy]=="4":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
            if tox%4==2:
                if toy%4==0 and MAP[tox][toy]=="1":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
                if toy%4==1 and MAP[tox][toy]=="3":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
                if toy%4==2 and MAP[tox][toy]=="6":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
                if toy%4==3 and MAP[tox][toy]=="4":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
            if tox%4==1:
                if toy%4==0 and MAP[tox][toy]=="2":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))

                if toy%4==2 and MAP[tox][toy]=="2":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))
            if tox%4==3:
                if toy%4==0 and MAP[tox][toy]=="5":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))

                if toy%4==2 and MAP[tox][toy]=="5":
                    CANGO[tox][toy]=1
                    Q.append((tox,toy))

if CANGO[H-1][W-1]==1:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 5868
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long ans = k;
        for (int i = 1; i < n; i++) {
            ans *= k - 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
import sys

input = sys.stdin.buffer.readline

n, m, p = map(int, input().split())
graph = [[] for _ in range(n + 1)]
revgraph = [[] for _ in range(n + 1)]
loop = [False] * (n + 1)
edges = []
for _ in range(m):
    a, b, c = map(int, input().split())
    edges.append((a, b, c - p))
    graph[a].append((b, c - p))
    revgraph[b].append((a, c - p))
is_route = [False] * (n + 1)
# DFS
start = 1

stack = [start]
while stack:
    v = stack.pop()
    is_route[v] = True
    for u, c in graph[v]:
        if is_route[u]:
            continue
        stack.append(u)
is_revroute = [False] * (n + 1)

goal = n
stack = [goal]
while stack:
    v = stack.pop()
    is_revroute[v] = True
    for u, c in revgraph[v]:
        if is_revroute[u]:
            continue
        stack.append(u)


def check(v):
    return is_route[v] and is_revroute[v]


# Bellman-Ford

dist = [-(10 ** 10)] * (n + 1)
start = 1
dist[start] = 0
cnt = 0
update = True
used = set([start])
while update:
    cnt += 1
    update = False
    for fr, to, co in edges:
        if check(fr) and check(to):
            if dist[fr] != -(10 ** 10) and dist[to] < dist[fr] + co:
                dist[to] = dist[fr] + co
                update = True
    if not update:
        break
    if cnt > n:
        print(-1)
        exit()
print(max(0, dist[n]) if dist[n] != -(10 ** 10) else -1)


Measured memory_bytes: 46192
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
namespace Flandle_Scarlet
{
    #define N 100100

    #define F(i,l,r) for(int i=l;i<=r;++i)
    #define D(i,r,l) for(int i=r;i>=l;--i)
    #define MEM(x,a) memset(x,a,sizeof(x))
    #define FK(x) MEM(x,0)
    int n,a[N];
    void R1(int &x)
    {
        x=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
        while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        x=(f==1)?x:-x;
    }
    void Input()
    {
        R1(n);
        F(i,1,n) R1(a[i]);
    }

    void Soviet()
    {
        if (n==1)
        {
            puts("1");
            return;
        }

        int ans;
        bool flag=0,res=0;
        ans=a[1];
        int k=1;
        F(i,2,n)
        {
            if (!res)
            {
                if (a[i]>ans) flag=res=1,ans=a[i];
                else if (a[i]<ans) flag=0,res=1,ans=a[i];
            }
            else
            {
                if (flag)
                {
                    if (a[i]>=ans) ans=a[i];
                    else ++k,ans=a[i],res=false;
                }
                else
                {
                    if (a[i]<=ans) ans=a[i];
                    else ++k,ans=a[i],res=false;
                }
            }
        }
        printf("%d\n",k);
    }
    void IsMyWife()
    {
        if (0)
        {
            freopen("","r",stdin);
            freopen("","w",stdout);
        }
        Input();
        Soviet();
    }
};
int main()
{
    Flandle_Scarlet::IsMyWife();
    return 0;
}


Measured memory_bytes: 640
program probC
  implicit none
  integer,allocatable :: a(:)
  integer i,ans1,n,now,del1,del2

  read(*,*) n
  allocate(a(0:n+1))
  a=0
  read(*,*) a(1:n)

  ans1=0
  do i =1,n+1
     ans1 = ans1 + abs(a(i-1)-a(i))
  end do

  do i = 1,n
     del1 = abs(a(i-1)-a(i))+abs(a(i)-a(i+1))
     del2 = abs(a(i-1)-a(i+1))

     write(*,*) ans1+del2-del1
  end do
  
end program probC


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		if (A <= 8 && B <= 8)
			System.out.println("Yay!");
		else
			System.out.println(":(");
	}
}



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

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

    const int MAXN = 200000;
    static int kinds[MAXN];

    // 0が羊, 1が狼
    for (int kind0 = 0; kind0 <= 1; kind0++) {
        for (int kind1 = 0; kind1 <= 1; kind1++) {
            kinds[0] = kind0;
            kinds[1] = kind1;

            // 次のやつを決定
            for (int i = 1; i < N; i++) {
                if ((kinds[i] == 0 and s[i] == 'o') or
                    (kinds[i] == 1 and s[i] == 'x')) {
                    kinds[(i + 1) % N] = kinds[i - 1];
                } else {
                    kinds[(i + 1) % N] = (kinds[i - 1] + 1) % 2;
                }
            }

            if (kinds[0] != kind0) continue;
            if (kinds[1] == kinds[N - 1] and
                !(kinds[0] == 0 and s[0] == 'o') and
                !(kinds[0] == 1 and s[0] == 'x')) continue;
            if (kinds[1] != kinds[N - 1] and
                !(kinds[0] == 0 and s[0] == 'x') and
                !(kinds[0] == 1 and s[0] == 'o')) continue;

            for (int i = 0; i < N; i++) {
                cout << (kinds[i] == 0 ? 'S' : 'W');
            }
            cout << endl;

            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <list>
#include <set>
#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)
using namespace std;
using ll = long long;
const int INF = 1e9 + 1;
ll MOD = 1e9+7;
ll dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
ll dy[9] = {-1,  0,  1,-1, 0, 1,-1, 0, 1};

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

    int X1, Y1, X2, Y2, X3, Y3, X4, Y4;
    cin >> X1 >> Y1 >> X2 >> Y2;
    X3 = X2-(Y2-Y1);
    Y3 = Y2+(X2-X1);
    X4 = X3-(Y3-Y2);
    Y4 = Y3+(X3-X2);
    printf("%d %d %d %d\n", X3, Y3, X4, Y4);
    return 0;
}


Measured memory_bytes: 256
// Aizu Vol-10 1091: KND is So Sexy
// 2017.8.18 bal4u@uu

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

int main()
{
	double a, l, x, s, ans;

	while (scanf("%lf%lf%lf", &a, &l, &x) == 3) {
		s = l + a / 2.0;
		ans = a/2.0 * sqrt(s*(s - a));
		s = l + x / 2.0;
		ans += l * sqrt(s*x/2.0);
		printf("%.8lf\n", ans);
	}
	return 0;
}

Measured memory_bytes: 656
from collections import deque
S = list(input()) 
d = deque()
for s in S:
    d.append(s)
q = int(input())
o = 0

for _ in range(q):
    qu = list(input().split())
    if len(qu) == 1:
        o = -1 if o == 0 else 0
    if len(qu) == 3:
        if qu[1] == '1':
            d.appendleft(qu[2]) if o == 0 else d.append(qu[2])
        if qu[1] == '2':
            d.append(qu[2]) if o == 0 else d.appendleft(qu[2])

r = ''
if o == 0:
    for _ in range(len(d)):
        r += d.popleft()
else:
    for _ in range(len(d)):
        r += d.pop()

print(r)


Measured memory_bytes: 7044
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        //int  = sc.nextInt();
        int res;

        res = (N-2)*180;
        
        
        System.out.println(res);
        
        }
    }

Measured memory_bytes: 35636
N = int(input())
x = 1
alphabet = {i-96:chr(i) for i in range(97, 97+26)}
if int(N) > 26:
    ans = ''
    while x != 0:
        x = N // 26
        mod = N%26
        #print(x, mod)
        if mod == 0:
            ans += 'z'
            #x -= x%26
            x -= 1
        else:
        #print(x, mod, alphabet[mod])
            ans += alphabet[mod]
        N = x
else:
    ans = alphabet[int(N)]
print(ans[::-1])

Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	int res = 0;
	string S;

	int mx1 = -100000;
	int mn1 = 100000;
	int mx2 = -100000;
	int mn2 = 100000;
	for (int i = 0; i < H; i++) {
		cin >> S;
		for (int j = 0; j < W; j++) {
			if (S[j] == 'B') {
				mx1 = max(mx1, i + j);
				mn1 = min(mn1, i + j);
				mx2 = max(mx2, i - j);
				mn2 = min(mn2, i - j);
			}
		}
	}

	res = max(res, mx1 - mn1);
	res = max(res, mx2 - mn2);

	cout << res << endl;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll inf = 1e9+7;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  if(2*n >= m) ans = m/2;
  else ans += (n + (m-2*n)/4);
  cout << ans << "\n";
  return 0;
}   

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			String W = sc.next();
			int cnt = 0;
			for(;;) {
				String T = sc.next();
				if(T.contentEquals("END_OF_TEXT")) break;
				T = T.toLowerCase();

				if(T.contentEquals(W)) cnt++;
			}
			System.out.println(cnt);
		}
	}
}


Measured memory_bytes: 26104
#include<stdio.h>
int main(void)
{
 int N;
 
 scanf("%d", &N);

 int i,j,hozon,minj,A[N+1];
 int count = 0;

   
 for(i = 0; i < N; i++)
{
 scanf("%d",&A[i]);
}
 for(i = 0; i < N; i++)
{
  minj = i;
 for(j = i; j < N; j++)
{
 if(A[minj] > A[j])
{
 minj = j;
}
}
 if(minj != i)
{
  hozon = A[i];
  A[i] = A[minj];
  A[minj] = hozon;
  count++;
}
}
 for(i = 0; i < N; i++)
{
 if(i > 0)
 printf(" ");
 printf("%d",A[i]);
}
 printf("\n");
 printf("%d\n",count);
 return 0;

}

Measured memory_bytes: 1844
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(){
ll n,m,s=0,i;
cin>>n>>m;
ll a[m];
for(i=0; i<m; i++){
cin>>a[i];
s=s+a[i];
}
if(s>n){
    cout<<-1<<endl;
}
else{
   cout<<n-s<<endl;
}



return 0;









}


Measured memory_bytes: 3640
import sys
# from collections import deque
# from collections import Counter
# from math import sqrt
# from math import log
# from math import ceil

# def gcd(a, b):
# 	if(a==0):
# 		return b 
# 	return gcd(b%a,a)

# def sieve(n): 
# 	prime=[True for i in range(n+1)]
# 	p=2
# 	while(p*p<=n): 
# 		if (prime[p]==True): 
# 			for i in range(p*p,n+1,p): 
# 				prime[i]=False
# 		p+=1
# 	prime[0]=False
# 	prime[1]=False
# 	s=set()
# 	for i in range(len(prime)):
# 		if(prime[i]):
# 		s.add(i)
# 	return s 

# alpha=['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']
# mod=10**9+7

fast_reader=sys.stdin.readline
fast_writer=sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i)) for i in argv))
	fast_writer('\n')

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

def sep_input():
	return map(int, input().split())

#_______________________________________________________________________________________________________________________________________

x,y=sep_input()
l=[]
for i in range(x+1):
	l.append(2*i + 4*(x-i))
	l.append(4*i + 2*(x-i))
s=set(l)
if(y in s):
	print('Yes')
else:
	print('No')

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

int n;
int cnt=0;

void dfs(ll i, int a, int b, int c){
    if(i>n) return;
    if(a>0 && b >0 && c>0) cnt++;
    /*
    string s;
    s = to_string(i);
    set<char> k;
    for(int i=0; i<s.size(); i++){
        k.insert(s.at(i));
    }
    if(k.count('3') && k.count('5') && k.count('7')) cnt++;
    */
    dfs(10*i+3, a+1, b, c);
    dfs(10*i+5, a, b+1, c);
    dfs(10*i+7, a, b, c+1);
}

int main(){
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << cnt << endl;
}

Measured memory_bytes: 3536
N = int(input())
dp = [[0, 0, 0] for _ in range(N + 1)]

for i in range(1, N + 1):
    a = tuple(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[j])
print(max(dp[N]))

Measured memory_bytes: 83460
#include <iostream>

using namespace std;

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

    int n;
    string s;
    cin>>s;

    n = (int)s.size();

    long long meg = 0;
    int db = 0, j = 0;
    while(j < n-2)
    {
        if(s[j] == 'A')
            db++;
        else
            db = 0;

        if(s[j] == 'A' && s[j+1] == 'B' && s[j+2] == 'C')
        {
            meg += (long long)db;
            s[j+2] = 'A';
            db--;
            j += 2;
        }
        else
            j++;
    }

    cout<<meg<<"\n";

    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,ans=1,k=7;
int main()
{
    scanf("%d",&n);
    if(n%2==0||n%5==0)
    {
        printf("-1");
        return 0;
    }
    while(1)
    {
        if(k%n==0)
        {
            printf("%d",ans);
            return 0;
        }
        ans++;
        k=k*10+7;
        k%=n;
    }
}


Measured memory_bytes: 3824
N,K=map(int,input().split())
l=[x for x in range(1,N+1)]
for i in range(K):
	d=int(input())
	A=list(map(int,input().strip().split()))
	for j in range(len(A)):
		if A[j] in l:
			l.remove(A[j])
print(len(l))


Measured memory_bytes: 9080
x, y = list(map(int, input().split()))
xs = [x, -x]
ys = [y, -y]
ans = float("inf")
for i, x in enumerate(xs):
    for j, y in enumerate(ys):
        if x + abs(x-y) == y:
            kouho = abs(x-y) + i + j
            ans = min(ans, kouho)
print(ans)

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

void solve(long long N, std::vector<long long> A){
    sort(A.begin(), A.end());
    long long b = (N % 2 == 0) ? A[N / 2 - 1] : A[((N + 1) / 2 - 1)];
    long long ans = 0;
    for(long long i = 0; i < N; ++i) ans += abs(A[i] - b);
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        cin >> A[i];
        A[i] = A[i] - i - 1;
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

bool cmp(pair<int,string> d1, pair<int,string> d2){
	if(d1.fi==d2.fi) return d1 < d2;
	return d1.fi > d2.fi;
}

signed main() {
	int n;
	while (cin >> n && n) {
		char c;
		map<string, int> mp;
		cin.ignore();
		rep(i, 0, n) {
			string s, t;
			getline(cin, s);
			stringstream ss;
			ss << s;
			while (ss >> t) {
				mp[t]++;
			}
		}
		cin >> c;
		vector<pair<int, string> > d;
		for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
			string tmp = it->fi;
			int time = it->se;
			if (tmp[0] == c) {
				d.push_back(make_pair(time, tmp));
			}
		}
		sort(all(d),cmp);
		int cnt = 0;
		rep(i, 0, d.size()) {
			if (cnt == 5) break;
			if (cnt != 0) cout << " ";
			cout << d[i].se;
			cnt++;
		}
		if(cnt==0) cout<<"NA";
		cout << endl;
	}
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}

int prime[1000000];bool visprime[10000000];
void sieve(){int k=0;for(int i=2;i*i<=1000000;i++){for(int j=i*i;j<=1000000;j+=i){visprime[j]=true;}}for(int i=2;i<=1000000;i++){if(visprime[i]==false) prime[k++]=i;}}


int main()
{


  ll  a,b;
  cin>>a>>b;
  if(a==b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


















}


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

public class Main{


	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// input
		String tempStr= br.readLine();//clear

		// Constraints

		for(int i= 0; i < tempStr.length(); i++){
			if(Character.isLowerCase(tempStr.charAt(i)))
				// output
				System.out.print(Character.toUpperCase(tempStr.charAt(i)));
		else
			System.out.print(Character.toLowerCase(tempStr.charAt(i)));
		}
		System.out.println();
	}
}

Measured memory_bytes: 25076
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

k = list(map(int, input().split()))[0]

am = 7 % k
i = 1

for i in range(k):
    if am==0:
        print(i+1)
        exit()
    else:
        i+=1
        am=(am*10+7)%k
 
print('-1')


Measured memory_bytes: 9180
#include <iostream>
    #include <string>
    #include <cmath>
    #include <vector>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <utility>
    #include <functional>
     
    using namespace std;
     
    int main() {
    	int n;
    	cin >> n;
    	cout << "ABC" << n << endl;
     
    	return 0;
    }

Measured memory_bytes: 256
package main

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

const YES = "Yes"
const NO = "No"

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var A int64
	scanner.Scan()
	A, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var B int64
	scanner.Scan()
	B, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var C int64
	scanner.Scan()
	C, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	s := make([]string, N)
	for i := int64(0); i < N; i++ {
		scanner.Scan()
		s[i] = scanner.Text()
	}
	solve(N, A, B, C, s)
}
func solve(N int64, A int64, B int64, C int64, s []string) {
	m := map[rune]int64{'A': A, 'B': B, 'C': C}
	var res []rune
	for i := int64(0); i < N; i++ {
		ss := []rune(s[i])
		s1 := ss[0]
		s2 := ss[1]
		if m[s1] == 0 && m[s2] == 0 {
			fmt.Println(NO)
			return
		}
		if m[s1] == 0 {
			m[s1]++
			m[s2]--
			res = append(res, s1)
			continue
		}
		if m[s2] == 0 {
			m[s1]--
			m[s2]++
			res = append(res, s2)
			continue
		}
		if i == N-1 {
			m[s1]++
			m[s2]--
			res = append(res, s1)
			continue
		}
		if strings.ContainsRune(s[i+1], s1) {
			m[s1]++
			m[s2]--
			res = append(res, s1)
			continue
		}
		if strings.ContainsRune(s[i+1], s2) {
			m[s1]--
			m[s2]++
			res = append(res, s2)
			continue
		}
	}
	fmt.Println(YES)
	for _, r := range res {
		fmt.Println(string(r))
	}
}


Measured memory_bytes: 6124
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int MOD = 1e9 + 7;

string K;
int D;

int memo[10001][2][101];
int go(int n = 0, bool lt = false, int rem = 0) {
   if (n >= SZ(K))
      return rem == 0 ? 1 : 0;
   int& res = memo[n][lt][rem];
   if (res < 0) {
      res = 0;
      FOR(d, 0, lt ? 9 : K[n]-'0') {
         res += go(n+1, lt || (d < K[n]-'0'), (rem + d) % D);
         if (res >= MOD)
            res -= MOD;
      }
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> K;
   cin >> D;

   memset(memo, -1, sizeof(memo));
   int res = go() - 1;  // substract one due to 0
   if (res < 0)
      res += MOD;
   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 9088
#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a<c) a=c;
	if(b>d) b=d;
	if(b-a<0) printf("0\n");
	else printf("%d\n",b-a);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
        long ans = 0;
        long N = long.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Array.Sort(a);
        for (long i = N; i < 3*N-1; i+=2)
        {
            ans += a[i];
        }
        Console.WriteLine(ans.ToString());
    }
}


Measured memory_bytes: 46228
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
n = ni()
cnt=0
f=False
for i in range(n):
    d1,d2 = ma()
    if d1==d2:
        cnt+=1
    else:
        cnt=0
    if cnt==3:
        f=True
        break
yn(f)


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<vector<int>> f(n, vector<int>(10));

  rep(i, n) rep(j, 10) cin >> f[i][j];

  vector<vector<ll>> p(n, vector<ll>(11));
  rep(i, n) rep(j, 11) cin >> p[i][j];

  ll ans = -INF64;

  for(int bit = 1; bit < 1<<10; ++bit) {
    vector<int> c(n, 0);

    ll tmp = 0;

    rep(i, n) rep(j, 10) if(f[i][j]==1 && (bit & 1<<j)) ++c[i];
    rep(i, n) tmp += p[i][c[i]];

    chmax(ans, tmp);
  }

  cout << ans << endl;
}

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

using namespace std;

int main()
{
    int  s;
    while(cin>>s)
    {
        if(s<1200)
            printf("ABC\n");
        else if(s<2800)
            printf("ARC\n");
        else
            printf("AGC\n");
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] x = new int[n];
            int[] y = new int[n];
            int[] h = new int[n];
            int idx = -1;
            for (int i = 0; i < n; i++) {
                x[i] = in.nextInt();
                y[i] = in.nextInt();
                h[i] = in.nextInt();

                if (h[i] > 0) idx = i;
            }

            for (int i = 0; i <= 100; i++) {
                out:
                for (int j = 0; j <= 100; j++) {
                    int tmp = h[idx] + Math.abs(x[idx] - i) + Math.abs(y[idx] - j);

                    for (int k = 0; k < n; k++) {
                        if (h[k] != Math.max(tmp - Math.abs(x[k] - i) - Math.abs(y[k] - j), 0)) continue out;
                    }

                    out.println(i + " " + j + " " + tmp);
                    return;
                }
            }

            throw new RuntimeException();
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21460
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int round_value,point_hanako=0,point_taro=0;

            //??????????????°????????????
            var read_text = Console.ReadLine();
            round_value = int.Parse(read_text);

            for(int i=0;i<round_value;i++)
            {
                read_text = Console.ReadLine();
                var card = read_text.Split(' ');

                if(string.Compare(card[0],card[1])>0)
                {
                    point_taro += 3;
                }
                else if(string.Compare(card[0],card[1])<0)
                {
                    point_hanako += 3;
                }
                else
                {
                    point_hanako++;
                    point_taro++;
                }
            }
            Console.WriteLine(point_taro + " " + point_hanako);
        }
    }
}

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

int main()
{
int a, b;
cin >> a >> b;
if(a + b == 15 and a * b == 15)
{
cout << "x" << endl;
}
else if(a + b == 15)
{
cout << "+"<< endl;
}
else if(a * b ==15)
{
cout << "*"<< endl;
}
else
{
cout << "x" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>

using namespace std;


int main() {
	int i, j, k;
	int n;
	vector<int> v(205);

	cin >> n;

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


	bool flag = false;
	int cnt = 0;

	while (!flag) {
		for (i = 0; i < n; i++) {
			if (v[i] % 2 != 0) {
				flag = true;
				break;
			}
			else {
				v[i] = v[i] / 2;
			}
		}
		cnt++;
	}

	cout << cnt-1 << endl;


	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
typedef long long LL;
int sz=0;
LL IN(void)
{
  LL x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main(void)
{
  LL N=IN();int str[12]={0};
  while(N){N--;str[sz++]=97+N%26;N/=26;}
  for(int i=0;i<sz;i++)printf("%c",str[sz-i-1]);
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

int main(){

  long long int n,m;
  
  cin >> n >> m;
  
  for(int i=m/n;i>0;i--){
    
    if( m % i == 0){
      cout << i << endl;
      
      return 0;
    }
    
  }
}
   


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

struct card_t {
    long long number;
    int count;
    card_t(long long n, int c=1): number(n), count(c){
    }
    friend bool operator<(const card_t& a,const card_t& b) {
        return a.number > b.number;
    }
};


int main() {
    int n, m;
    cin >> n >> m;
    vector<long long> a(n);
    priority_queue<card_t> q;
    for (int i=0;i<n;i++) {
        cin >> a[i];
        q.push(card_t(a[i]));
    }
    long long c;
    int b;
    for (int j=0;j<m;j++) {
        cin >> b >> c;
        int d=0;
        while (b) {
            card_t p = q.top();
            if (p.number >= c) {
                break;
            }
            q.pop();
            if (p.count > b) {
                p.count -= b;
                d += b;
                b = 0;
                q.push(p);
            } else {
                b -= p.count;
                d += p.count;
            }
        }
//        cerr << "d: " << d << endl; 
        if (d > 0) {
            q.push(card_t(c,d));
        }
    }
    long long answer = 0;
    while (!q.empty()) {
        card_t p = q.top(); q.pop();
        answer += p.number * p.count; 
    }
    cout << answer << endl;
    return 0;
}


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

int main()
{
int a,b,c,k;
cin >> a >> b >> c >> k;
  
if(a>=k){cout << k << endl;}
else if(a+b>=k){cout << a << endl;}
else {cout << a-(k-a-b) << endl;}
  
return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

/*#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif */
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    ll a,b;
    cin>>a>>b;
    if(a < 6)
        cout<<0<<endl;
    else if(a >= 6&& a <= 12)
        cout<<b/2<<endl;
    else
        cout<<b<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
    int a[100];
    int i, n;
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    for(i=n-1; i>0; i--) {
        printf("%d ", a[i]);
    }
    printf("%d\n", a[0]);
    return 0;
}

Measured memory_bytes: 596
/*
❤️❤️❤️I_love_QMsh❤️❤️❤️
*/



#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST_ALLOCATOR_MEMORY 200000000
#ifdef FAST_ALLOCATOR_MEMORY
  int allocator_pos = 0;
  char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
  inline void * operator new ( size_t n ) {
    char *res = allocator_memory + allocator_pos;
    allocator_pos += n;
    assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
    return (void *)res;
  }
  inline void operator delete ( void * ) noexcept { }
  //inline void * operator new [] ( size_t ) { assert(0); }
  //inline void operator delete [] ( void * ) { assert(0); }
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // <int> .find_by_order(int) .order_of_key(int)

template<typename T> bool smin(T &a, const T &b) { bool ret = b < a; return a = (ret ? b : a), ret; }
template<typename T> bool smax(T &a, const T &b) { bool ret = a < b; return a = (ret ? b : a), ret; }

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd;

const int N = 43;
const int M = (int)1e9 + 7;

gp_hash_table<ll, int> dp;
gp_hash_table<ll, int> prv;

int get(ll x) {
  return (x ? get(x / 10) + 1 : 0);
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, x, y, z;
  cin >> n >> x >> y >> z;

  vector<int> st10(n + 1);
  st10[0] = 1;
  for (int i = 1; i <= n; i++) {
    st10[i] = 1ll * st10[i - 1] * 10 % M;
  }
  vector<ll> st10l(18);
  st10l[0] = 1;
  for (int i = 1; i < 18; i++) {
    st10l[i] = st10l[i - 1] * 10;
  }

  dp[0] = 1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    prv = dp;
    dp.clear();
    for (auto &arr : prv) {
      int csz = get(arr.first);

      for (int d = 1; d <= 10; d++) {
        ll nxtv = arr.first;
        bool empty = 0;
        nxtv = (nxtv * 10 + (d == 10 ? d - 1 : d));
        int sz = csz + 1;

        while (true) {
          int pos = 0, rem = x;
          bool ok = 1;
          for (int i = sz; i >= 1; i--) {
            int val = (nxtv / st10l[i - 1]) % 10;
            if (rem >= val) {
              rem -= val;
            } else {
              ok = 0;
            }
            if (rem == 0) {
              rem = (pos == 0 ? y : (pos == 1 ? z : -1));
              pos++;
            }
          }
          if (ok) {
            if (rem == -1) {
              ans = (ans + 1ll * arr.second * st10[n - i - 1]) % M;
            } else {
              dp[nxtv] = (dp[nxtv] + arr.second) % M;
            }
            break;
          } else {
            nxtv %= st10l[sz - 1];
            sz--;
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 178432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++)
#define FORD(i, a, b) for (int i = (a), i##_len = (b); i > i##_len; i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main() {
    int n, q;
    cin >> n;
    vector<tuple<int, int>> vw(n);
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        vw[i] = make_tuple(a, b);
    }
    cin >> q;
    vector<tuple<int, int>> vl(q);
    REP(i, q) {
        int a, b;
        cin >> a >> b;
        vl[i] = make_tuple(a, b);
    }

    int former = min(1024, n);
    vector<vector<int>> former_dp(former, vector<int>(100001, -1));
    vector<set<int>> former_set(former);

    former_dp[0][0] = 0;
    former_dp[0][get<1>(vw[0])] = get<0>(vw[0]);
    former_set[0].insert(0);
    former_set[0].insert(get<1>(vw[0]));

    FOR(i, 1, former) {
        int v, w;
        tie(v, w) = vw[i];
        auto& anc_dp = former_dp[(i - 1) / 2];
        auto& now_dp = former_dp[i];
        auto& anc_set = former_set[(i - 1) / 2];
        auto& now_set = former_set[i];
        for (auto j : anc_set) {
            now_dp[j] = anc_dp[j];
            now_set.insert(j);
        }
        for (auto j : anc_set) {
            if (w + j <= 100000) {
                now_dp[w + j] = max(now_dp[w + j], anc_dp[j] + v);
                now_set.insert(w + j);
            }
        }
    }

    REP(i, former) {
        int m = 0;
        auto& now_dp = former_dp[i];
        FOR(j, 1, 100001) {
            m = max(m, now_dp[j]);
            now_dp[j] = m;
        }
    }

    for (auto temp : vl) {
        int v, l;
        tie(v, l) = temp;
        if (v <= former) {
            cout << former_dp[v - 1][l] << endl;
            continue;
        }
        vector<tuple<int, int>> later;
        int vv = v;
        while (vv > former) {
            later.push_back(vw[vv - 1]);
            vv >>= 1;
        }
        auto& anc_dp = former_dp[vv - 1];
        int m = later.size();
        int ans = 0;
        REP(i, pow(2, m)) {
            int v_sum = 0;
            int w_sum = 0;
            int ii = i;
            for (auto temp : later) {
                int j, k;
                tie(j, k) = temp;
                if (ii & 1) {
                    v_sum += j;
                    w_sum += k;
                }
                if (w_sum > l) { break; }
                ii >>= 1;
            }
            if (w_sum > l) { continue; }
            ans = max(ans, v_sum + anc_dp[l - w_sum]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 440176
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>

using namespace std;

#define INF 1<<30

struct node{
  int cost, num;
  node(int c, int n): cost(c), num(n){}
  bool operator >(const node &e) const{
	return cost > e.cost;
  }

};

int main(void){
  int n;
  int m;
  int n1,n2,c;

  while(1){
	cin >> n;
	if(n == 0) break;

	bool visited[n];
	memset(visited, false, sizeof(visited));
	int cost[n][n];
	fill((int *)cost, (int *)cost+n*n, INF);
	bool used[n];
	fill(used, used+n, false);
	priority_queue<node, vector<node>, greater<node> > q;
	int ret=0;

	cin >> m;

	for(int i=0;i<m;i++){
	  cin >> n1; cin.ignore();
	  cin >> n2; cin.ignore();
	  cin >> c;

	  cost[n1][n2] = c / 100 - 1;
	  cost[n2][n1] = c / 100 - 1;	
	}
	q.push(node(0,0));
	while(!q.empty()){
	  node tmp = q.top(); q.pop();
	  //cout << "poped: from " << tmp.num << " cost " << tmp.cost << endl;

	  if(used[tmp.num] == true) continue;
	  used[tmp.num] = true;
	  ret += tmp.cost;

	  for(int i=0;i<n;i++){
		if(cost[tmp.num][i] != INF){
		  q.push(node(cost[tmp.num][i], i));
		}
	  }
	}
	cout << ret << endl;
  }	
}

Measured memory_bytes: 0
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<=en; i++)
#define gnr(i,l,r) for(int i=int(r)-1; i>=int(l); i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt &operator%=(ModInt that) { x %= that.x; return *this; }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
  ModInt operator%(ModInt that) const { return ModInt(*this) %= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while(b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if(u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}

	bool operator==(ModInt that) const { return x == that.x; }
	bool operator!=(ModInt that) const { return x != that.x; }
	ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1;
	while(k) {
		if(k & 1) r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}
typedef ModInt<mod> mint;

int n,m,_,x,y,q,key;
string s,sb;
bool ok;

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

  cin>>n; int a[n+1],al[200001]={}; mint dp[n+1]; dp[0]=1;
	rer(i,1,n){
		cin>>a[i];
		dp[i]=dp[i-1];
		if(al[a[i]]&&i-al[a[i]]>1)dp[i]+=dp[al[a[i]]];
		al[a[i]]=i;
	}
	cout<<dp[n].get();
}

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

int main(void){
    int n;
    cin >> n;
    
    int* arr = new int[n];
    
    int origin = 0;
    int i = 0;
    
    for (i = 0; i < n; i++){
        cin >> arr[i];
        origin = origin ^ arr[i];
    }
    
    for (i = 0; i < n - 1; i++){
        cout << (origin ^ arr[i]) << " ";
    }
    
    cout << (origin ^ arr[i]) << endl;
    
    delete[] arr;

    return 0;
}


Measured memory_bytes: 3596
//
// Created on 2020/04/08.
//

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

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int ans = 0;
    int n;
    cin>>n;
    int num = 1;
    for (int i = 0; i < n; ++i) {
        int a;
        cin>>a;
        if(a != num){
            ans ++;
        }else{
            num ++;
        }
    }
    if(ans == n){
        ans = -1;
    }
    cout<<ans<<endl;
}


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

int main() {
  string s,t;
  cin >> s;
  cin >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256