akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int x[4] = {-1,0,1,0};
int y[4] = {0,-1,0,1};
void dfs(vector<vector<char> > &v, int i, int j, char c) {
	if(v[i][j] == c) {
		v[i][j]= 0;
		rep(k,4) {
			dfs(v, i+x[k], j+y[k], c);
		}
	} else return;
}
int main() {
	int h, w;
	while(cin >> h >> w && (h || w)) {
		vector<vector<char> > v(h+2);
		rep(i,h+2) {
			vector<char> va(w+2);
			v[i] = va;
		}
		rep(i,h) {
			string s;
			cin >> s;
			rep(j,w) {
				v[i+1][j+1] = s[j];
			}
		}
		int cnt = 0;
		rep2(i,1,h+1) {
			rep2(j,1,w+1) {
				if(v[i][j]) {
					cnt++;
					char ch = v[i][j];
					dfs(v, i, j, ch);
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=310;
const int inf=0x3f3f3f3f;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n,m,mp[Maxn][Maxn],st,ed;
int num[Maxn][Maxn],tot=0;
char s[Maxn];
struct Edge{int y,d,next;}e[Maxn*Maxn*6];
int last[Maxn*Maxn<<1],cur[Maxn*Maxn<<1],len=1;

void ins(int x,int y,int d)
{
	int t=++len;
	e[t].y=y;e[t].d=d;
	e[t].next=last[x];last[x]=t;
}
void addedge_1(int x,int y,int d){ins(x,y,d),ins(y,x,0);}
void addedge_2(int x,int y,int d){/*printf("%d %d %d\n",x,y,d);*/ins(x,y,d),ins(y,x,d);}
//void addedge_2(int x,int y,int d){/*printf("%d %d %d\n",x,y,d);*/addedge_1(x,y,d),addedge_1(y,x,d);}
int h[Maxn*Maxn<<1];
bool bfs()
{
	memset(h,0,sizeof(h));h[st]=1;
	static queue<int>q;q.push(st);
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int i=last[x];i;i=e[i].next)
		{
			int y=e[i].y;
			if(e[i].d>0&&!h[y])h[y]=h[x]+1,q.push(y);
		}
	}
//	puts("=========");
	return h[ed];
}
int dfs(int x,int f)
{
	if(x==ed)return f;
	int s=0,t;
	for(int i=cur[x];i;i=e[i].next)
	{
		int y=e[i].y;
		if(e[i].d>0&&h[y]==h[x]+1&&s<f)
		{
			cur[x]=i;
			t=dfs(y,min(e[i].d,f-s));
			s+=t;e[i^1].d+=t;e[i].d-=t;
		}
	}
	if(!s)h[x]=0;
	return s;
}
int main()
{
//	freopen("trade.in","r",stdin);
//	freopen("trade.out","w",stdout);
	n=read(),m=read();
	int stx,sty,edx,edy;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)
		{
			if(s[j]=='S')stx=i,sty=j,mp[i][j]=1;
			else if(s[j]=='T')edx=i,edy=j,mp[i][j]=2;
			else if(s[j]=='.')mp[i][j]=3;
			else mp[i][j]=4,num[i][j]=++tot;
		}
	}
	if(stx==edx||sty==edy)return puts("-1"),0;
	st=(tot<<1)+1,ed=(tot<<1)+2;
	for(int i=1;i<=n;i++)
	{
		int t=-1;
		for(int j=1;j<=m;j++)
		if(mp[i][j]!=3)
		{
			if(t!=-1)
			{
				int t1=num[i][t],t2=num[i][j];
				if(mp[i][t]==1)t1=st;
				if(mp[i][t]==2)t1=ed;
				if(mp[i][j]==1)t2=st;
				if(mp[i][j]==2)t2=ed;
				addedge_2(t1,t2,inf);
			}
			t=j;
		}
	}
	for(int j=1;j<=m;j++)
	{
		int t=-1;
		for(int i=1;i<=n;i++)
		if(mp[i][j]!=3)
		{
			if(t!=-1)
			{
				int t1=num[t][j]+tot,t2=num[i][j]+tot;
				if(mp[t][j]==1)t1=st;
				if(mp[t][j]==2)t1=ed;
				if(mp[i][j]==1)t2=st;
				if(mp[i][j]==2)t2=ed;
				addedge_2(t1,t2,inf);
			}
			t=i;
		}
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	if(mp[i][j]==4)addedge_2(num[i][j],num[i][j]+tot,1);
//	printf("%d %d\n",len,ed);
	int ans=0;
	while(bfs())
	{
		memcpy(cur,last,sizeof(cur));
		ans+=dfs(st,inf);
	}
	printf("%d",ans);
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n;
  cin >> n;
  int sum_val = 0, ans = 0, bef = 0;
  cin >> bef;
  rep(i, 0, n - 1) {
    int h;
    cin >> h;
    if (bef >= h) {
      sum_val++;
      ans = max(ans, sum_val);
    } else
      sum_val = 0;
    bef = h;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp

max = 0
for i in 0..(N - 2) do
  l = S[0..i].split("").uniq.join
  r = S[(i+1)..(N-1)]

  count = 0
  for j in 0..(l.size - 1) do
    count += 1 if r.index(l[j])
  end
  max = [max, count].max
end

puts max


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

int main()
{
	int H;
	int W;

	cin >> H >> W;
	
	string board[H];


	for (int i = 0; i < H; i++)	cin >> board[i];


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



	// 縦
	for (int i = 0; i < H; i++) {
	
		// 横
		for (int j = 0; j < W; j++) {
		
			if (board[i][j] == '#') continue;

			int cnt = 0;

			for (int k = 0; k < 8; k++) {
					
				int ni = i + dy[k];
				int nj = j + dx[k];


				if (ni < 0 || H <= ni) continue;
				if (nj < 0 || W <= nj) continue;
				if (board[ni][nj] == '#') cnt++;

			}

			board[i][j] = (char) ( '0' + cnt );

		}

	}


	for (int i = 0; i < H; i++)  cout << board[i] << endl;
	
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
using namespace std;

int main() {
    char s[11], t[11], u[11];
    int a, b;
    scanf("%s %s", s, t);
    scan2Int(a,b);
    scanf("%s", u);
    if (!strcmp(s, u))
        a -= 1;
    else
        b -= 1;

    printf("%d %d\n", a, b);
    return 0;
}


Measured memory_bytes: 3784
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //USE LONGS TO AVOID OVERFLOW THEN CAST
 
	public static void main(String[] args) { 
		FastScanner input = new FastScanner();
		PrintWriter w = new PrintWriter(System.out);
		String S = input.next();
		int N = S.length();
		long ans = 0;
		long B = 0;
		for (int L = 0; L<N; L++) {
			if (S.charAt(L)=='B') {
				long W = 0;
				B++;
				L++;
				for (int next = L; next < N; next++) {
					if (S.charAt(next)=='W') break;
					L++;
					B++;
				}
				for (int next = L; next < N; next++) {
					if (S.charAt(next)=='B') break;
					L++;
					W++;
				}
				ans+=B*W;
				L--;
			}
		}
		w.println(ans);
		w.flush();
	}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

using namespace std;
using ll = long long;

int main() {
    ll a;
    cin>>a;
    ll ini=100;
    int cnt=0;
    while(ini<a) {
        ini+=(ini/100);
        ++cnt;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3632
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def solve():
    n = getN()
    dp = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    # Free(C/T), A, G, AG, AC, AT, GA, AGA, AGG, AGT, ATG, (OUT)
    #     0      1  2   3   4   5   6   7    8    9    10

    for i in range(n):
        tmp = [0] * 12

        tmp[3] = dp[1] + dp[6] + dp[7]
        tmp[4] = dp[1]
        tmp[5] = dp[1] + dp[6] + dp[7]
        tmp[6] = dp[2] + dp[8] + dp[10]
        tmp[7] = dp[3]
        tmp[8] = dp[3]
        tmp[9] = dp[3]
        tmp[10] = dp[5]
        tmp[11] = dp[3] + dp[4] + dp[6] + dp[7] + dp[8] + dp[9] + dp[10] + dp[11] * 4
        tmp[1] = dp[0] + dp[1] + dp[4] + dp[5] + dp[6] + dp[7] + dp[9]
        tmp[2] = dp[0] + dp[2] + dp[8] + dp[9] + dp[10]
        tmp[0] = dp[0] * 2 + dp[2] * 2 + dp[4] * 2 + dp[5] * 2 + dp[8] + dp[9] + dp[10]

        dp = [x % MOD for x in tmp]
    #     print(dp)
    # print(sum(dp)%MOD)
    # print(pow(4, n, MOD))
    print(sum(dp[:-1]) % MOD)

def gu(n=5):
    ban = ["AGC", "ACG", "GAC", "AGAC", "AGGC", "AGTC", "ATGC"]
    select = ["A", "G", "C", "T"]
    ans = 0
    space = [0] * 11
    sp = ["ATG", "AGT", "AGG", "AGA", "GA", "AT", "AC", "AG", "G", "A"]
    for i in range(4 ** n):
        lis = []
        for j in range(n):
            lis.append(select[i%4])
            i //= 4
        ji = "".join(lis)
        fl = True
        # print(ji)
        for b in ban:
            if b in ji:
                fl = False
        if fl:
            ans += 1
            en = False
            for dd, spp in enumerate(sp):
                if ji.endswith(spp):
                    space[dd] += 1
                    en = True
                    break
            if not en:
                space[-1] += 1

    space.reverse()

    print(space)
    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()
    # for i in range(1, 7):
    #     gu(i)






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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};

int main() {
	int a,b,c;
	cin >> a;
	if (a == 25) {
		cout << "Christmas" << endl;
	} else if (a == 24) {
		cout << "Christmas Eve" << endl;
	} else if (a == 23) {
		cout << "Christmas Eve Eve" << endl;
	} else {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

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

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

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = 1100000;

LL Inverse(LL n, LL m) {
    n %= m;
    if (n <= 1) return n; // Handles properly (n = 0, m = 1).
    return m - ((m * Inverse(m, n) - 1) / n);
}

LL fact[MAXN];
LL invfact[MAXN];
const LL mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    fact[0] = 1;
    for (int i = 1; i < MAXN; i++) fact[i] = (i*fact[i-1]) % mod;
    for (int i = 0; i < MAXN; i++) invfact[i] = Inverse(fact[i], mod);

    int N;
    cin >> N;
    LL res = fact[N];
    for (int l = 1; l <= N-1; l++) {
        if (2*l-N < 0) continue;
        res -= ((fact[l]*fact[l-1])%mod*invfact[2*l-N]) % mod;
    }
    res %= mod;
    res += mod;
    res %= mod;
    cout << res << "\n";
}



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

int charToInt(char);
string sumStr(string, string);

int charToInt(char c) {
  return (int)c - (int)'0';
}

string sumStr(string a, string b) {
  int pa = a.length()-1, pb = b.length()-1;
  string str(83, '0');
  int pstr = str.length()-1;
  int next = 0;
  while(pa >= 0 && pb >= 0) {
    int temp = charToInt(a[pa]) + charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp%10+(int)'0');

    pa--;
    pb--;
    pstr--;
  }
  while(pa >= 0) {
    int temp = charToInt(a[pa]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp%10+(int)'0');

    pa--;
    pstr--;
  }
  while(pb >= 0) {
    int temp = charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp%10+(int)'0');

    pb--;
    pstr--;
  }
  str[pstr] = (char)(next + (int)'0');

  for(int i = 0; i < str.length(); i++) {
    if(str[i] != '0') {
      return str.substr(i, str.length()-i);
    }
  }
  return "0";
}

int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; i++) {
    bool overflow = false;
    int data[N][8];
    string sum;
    for(int j = 0; j < 2; j++) {
      string str;
      cin >> str;
      if(str.length() > 80) overflow = true;
      if(!overflow) {
	if(j == 0) sum = str;
	else       sum = sumStr(sum, str);
        if(sum.length() > 80) overflow = true;
      }
    }

    if(overflow) cout << "overflow" << endl;
    else         cout << sum << endl;
  }
  return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	
	map<int, int>color;
	for (auto&&x:a) {
		if (1 <= x && x <= 399)color[0]++;
		else if (400 <= x && x <= 799)color[1]++;
		else if (800 <= x && x <= 1199)color[2]++;
		else if (1200 <= x && x <= 1599)color[3]++;
		else if (1600 <= x && x <= 1999)color[4]++;
		else if (2000 <= x && x <= 2399)color[5]++;
		else if (2400 <= x && x <= 2799)color[6]++;
		else if (2800 <= x && x <= 3199)color[7]++;
		else color[8]++;
	}
	int sum = 0;
	for (int i = 0; i < 8; i++)if (color[i])sum++;
	if (sum == 0 && color[8])cout << 1 << ' ' << color[8] << endl;
 	else cout << sum << ' ' << sum + color[8] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  char ch;
  
  while(1){
    scanf("%c", &ch);
    if (ch >= 'a' && ch <= 'z') {
      printf("%c", ch - 32);
    } else if (ch >= 'A' && ch <= 'Z') {
      printf("%c", ch + 32);
    } else {
      printf("%c", ch);
    }
    if ( ch == '\n' ) break;
  }
}


Measured memory_bytes: 2624
def scc_puzzle():
	n,m = map(int, raw_input().split(" "))
	max_ans = m/2
	if n>=max_ans:
		print max_ans
		return
	else:
		min_ans = n
		# binary search
		while min_ans+1<max_ans:
			current_ans = (max_ans+min_ans)/2
			if _check(current_ans, n ,m):
				max_ans = current_ans
			else:
				min_ans = current_ans
		# there is no opportunity for max_ans to be an ans
		# however, the min_ans could be, based on our _check() fun
		print min_ans
		return


def _check(ans, n, m):
	total_c = ans*2+(ans-n)*2
	if total_c>m:
		# current ans is too large
		return True
	else:
		return False


if __name__ == "__main__":
	scc_puzzle()

Measured memory_bytes: 2568
N = input()
name = []
name2time = {}
for i in range(int(N)):
    I = input()
    s, t = I.split()
    name.append(s)
    name2time[s] = int(t)
X = input()
index = name.index(X)
name = name[index+1:]
time = 0
for music in name:
    time += name2time[music]
print(time)

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

int main(){
  int N;
  cin >> N;
  int A[N], f=0, s=0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    if (f<=A[i]){
        s=f; f=A[i];
    } else if (s<A[i]) s=A[i];
  }
  for(int i=0; i<N; i++){
      if (f!=A[i]) cout << f << endl;
      else cout << s << endl;
  }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fi first
#define se second
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e3 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n, a[N];
ll dp[N][N];
pii b[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i=1; i<=n; i++) 
	{
		cin >> a[i];
		b[i] = {a[i], i};
	}
	sort(b+1, b+n+1); reverse(b+1, b+n+1);
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	for(int i=1; i<=n; i++)
		for(int j=0; j<i; j++)
		{
			if(dp[i-1][j]==-1) continue;
			dp[i][j] = max(dp[i][j], dp[i-1][j]+1ll*b[i].fi*abs(b[i].se-(n-(i-1-j))));
			dp[i][j+1] = max(dp[i][j+1], dp[i-1][j]+1ll*b[i].fi*abs(b[i].se-(j+1)));
		}
	ll ans = *max_element(dp[n], dp[n]+n+1);
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=1'000'000'007;
const double EPS=1e-14;
const bool DEBUG=true;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(){
    int N;
    cin>>N;
    int d1, d2;
    int c=0;
    for(int i=0; i<N; ++i){
        cin>>d1>>d2;
        if(d1==d2){
            c++;
            if(c==3){
                cout<<Yes<<endl;
                return;
            }
        }else{
            c=0;
        }
    }
    cout<<No<<endl;

    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    answer();

    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int n;
    int v[3] = {};
    cin >> n >> v[0] >> v[1] >> v[2];
    vector<int> ans;
    bool pos = true;
    vector<string> q(n);
    for (int i = 0; i < n; i++) cin >> q[i];
    for (int i = 0; i < n; i++) {
        int i1 = q[i][0] - 'A', i2 = q[i][1] - 'A';
        if (!v[i1] && !v[i2]) {
            pos = false;
            break;
        }
        if (v[i1] == 1 && v[i2] == 1 && i + 1 < n) {
            int j1 = q[i + 1][0] - 'A', j2 = q[i + 1][1] - 'A';
            if (i1 == j1 || i1 == j2) {
                v[i1]++, v[i2]--;
                ans.push_back(i1);
            } else {
                v[i1]--, v[i2]++;
                ans.push_back(i2);
            }
        } else if (v[i1] > v[i2]) {
            v[i1]--, v[i2]++;
            ans.push_back(i2);
        } else {
            v[i1]++, v[i2]--;
            ans.push_back(i1);
        }
    }
    if (pos) {
        cout << "Yes\n";
        for (auto e : ans) cout << char('A' + e) << "\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 7056
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;



int main(int argc, char const *argv[])
{
	unsigned long x, y;
	
	cin >> x >> y;

	unsigned long i  = x;
	int cnt = 1;
	i *= 2;
	while(i <= y){
		i *= 2;
		cnt ++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll a, b1, b2;
    char dot;
    cin >> a >> b1 >> dot >> b2;
    cout << a * (b1 * 100 + b2) / 100 << '\n';
}


Measured memory_bytes: 3196
#include<iostream>
using namespace std;
#define mod 1000000007
long long H, W, A, B, K, ret, res, fact[300000], inv[300000], factinv[300000];
long long ncr(int n, int r) { return (n - r >= 0 && r >= 0) ? 1LL * fact[n] * factinv[r] % mod * factinv[n - r] % mod : 0; }
int main() {
	fact[0] = 1; for (int i = 1; i < 300000; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
	inv[1] = 1; for (int i = 2; i < 300000; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	factinv[0] = 1; for (int i = 1; i < 300000; i++) factinv[i] = 1LL * factinv[i - 1] * inv[i] % mod;
	cin >> H >> W >> A >> B; long long sum = 0;
	for (int i = 0; i < H - A; i++) {
		sum += ncr(B + i - 1, B - 1)*ncr((W - B - 1) + (H - i - 1), W - B - 1); sum %= mod;
	}
	cout << sum << endl;
	return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  vector<int> d(n);
  
  rep(i,k){
    int m;
    cin >> m;
    rep(j,m) {
      int a;
        cin >> a;
      d[a-1] = 1;
    }
  }
  
  int ans = 0;
  rep(i,n) if (d[i] == 0) ans++;
  cout << ans << endl;
  return 0;
     
    }

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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vbool = vector<bool>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(n), z(n);
    REP(i, n) {
        cin >> x[i] >> y[i] >> z[i];
    }
    vector<ll> ans(8);
    REP(f, 1 << 3) {
        vector<ll> s(n);
        REP(i, n) {
            s[i] += ((f & 1 << 0) ? 1 : -1) * x[i];
            s[i] += ((f & 1 << 1) ? 1 : -1) * y[i];
            s[i] += ((f & 1 << 2) ? 1 : -1) * z[i];
        }
        sort(ALL(s));
        REP(i, m) {
            ans[f] += s[n - i - 1];
        }
    }
    cout << *max_element(ALL(ans));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


int main(){
  int i=0,n=0,l=0,k=0;
    
  
  scanf("%d",&n);
      
  if(n%1000==0){
    printf("0\n");
    return 0;
  }
  else
    printf("%d\n",abs(n%1000-1000));
  
  return 0;
}


Measured memory_bytes: 1732
/*********বিসমিল্লাহির রাহমানির রাহিম**********/

#include <bits/stdc++.h>
#define ll long long
#define PI 2 * acos(0)
#define MAX 100000
#define M 10000007
using namespace std;

/*................OMI.................*/
int main()
{
   int n;
   cin >> n;
   int vag = n / 500;

   int res = vag * 1000;

   n = n % 500;

   vag = n / 5;

   res = res + (vag * 5);

   cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	int N;
	cin >> N;
	string W[101];
	bool ans = true;
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}
	for (int i = 0; i < N-1; i++) {
		if (W[i][W[i].size() - 1] != W[i + 1][0])
			ans = false;
		for (int j = i + 1; j < N; ++j) {
			if (W[i] == W[j])
				ans = false;
		}
	}
	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func Gcd(a, b int) int {
	var t int
	for b != 0 {
		t = b
		b = a % b
		a = t
	}
	return a
}

func Lcm(a, b int) int {
	return a * b / Gcd(a, b)
}

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	fmt.Printf("%d\n", Lcm(a, b))
}


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

int main(){
    ll n;cin>>n;
    string S;cin>>S;
    map<char,ll> lst;
    rep(i,n){
        lst[S[i]]++;
    }
    ll ans = lst['R'] * lst['G'] * lst['B'];
    for(ll l = 1;l<=(n-1)/2;l++){
        for(ll i = 0; i+2*l < n; i++){
            if(S[i] != S[i+l] && S[i+l] != S[i+2*l] && S[i] != S[i+2*l])ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


void solve(long long N){
    for(long long i = 100000; i >= 1; --i){
        if(i * i <= N){
            cout << i * i << endl;
            exit(0);
        }
    }
}

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


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

using namespace std;

int N;
int arr[104][104];

int main(){
    scanf("%d", &N);
    int cnt = 0;
    if(N%2==0){
        for(int i=1;i<=N;++i) for(int j=1;j<=N;++j) if(i!=j&&i+j!=N+1){
            ++cnt; arr[i][j] = 1;
        }
    }
    else{
        for(int i=1;i<=N;++i) for(int j=1;j<=N;++j) if(i!=j&&i+j!=N){
            ++cnt; arr[i][j] = 1;
        }
    }
    printf("%d\n", cnt/2);
    for(int i=1;i<=N;++i) for(int j=i+1;j<=N;++j) if(arr[i][j]){
        printf("%d %d\n", i, j);
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace B___Digits
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var k = int.Parse (input[1]);
            var count = 0;
            while (n >= k)
            {
                n = n / k;
                count++;
            }
            Console.WriteLine (count + 1);
        }
    }
}

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

int cntDigits(int n) {
    if (n == 0) return 0;
    return cntDigits(n/10) + 1;
}

int main() {
    int n, cnt = 0;
    cin >> n;

    while (n) {
        if (cntDigits(n) % 2 == 1) cnt++;
        n--;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
N = int(input())
s_list = [input() for i in range(N)]

ans = 0
word= {}

for j in s_list:
#     a = ''.join(sorted(list(j)))
    a = ''.join(sorted(j))
    if a in word:
        ans += word[a]
        word[a] += 1
    else:
        word[a] = 1
    
print(ans)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORB(i, m, n) for (int i = m; i >= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << #i << "= " << i << endl
using namespace std;

int main()
{
    int n, firstw = -1, firstr = -1;
    int ans = 1000000;
    string c;
    cin >> n >> c;
    int count[2] = {};
    bool white = false, red = false;
    REP(i, n)
    {
        if (c[i] == 'R')
        {
            if (!red)
            {
                red = true;
                firstr = i;
            }
            count[0]++;
        }
        else
        {
            count[1]++;
            if (!white)
            {
                white = true;
                firstw = i;
            }
        }
    }
    if (firstw == -1)
    {
        cout << 0 << endl;
        return 0;
    }
    int w = 0;
    int r = count[0];
    int k = max(w, r);
    REP(i, n + 1)
    {
        k = max(w, r);
        ans = min(k, ans);
        //debug(w);
        //debug(r);
        //debug(ans);
        if (i != n)
        {
            if (c[i] == 'W')
            {
                w++;
            }
            else
            {
                r--;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3716
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0, x = 0, y = 0, z = 0,n=0,m=0, maxy = -1, mini = 9999, counter = 0, s = 0, endp = 0, checker = 0;
std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[1001][1001];
long long int iremono2[1001];
std::vector<unsigned long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input, one, two;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
int main()
{
	cin >> n >> m ;
	if (n % 500 > m) {
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define int long long
#define maxn 51
#define re register
#define FOR(i, l, r) for(re int i = l; i <= r; ++i)
using namespace std;

int n, m, c, r, t, x, y, z, k;
int a[maxn], f[maxn][maxn][maxn*maxn];

signed main() {
	scanf("%lld%lld", &n, &k);
	FOR(i, 1, n)
	  scanf("%lld", &a[i]);
	f[0][0][0] = 1;
	FOR(i, 1, n) 
	  FOR(j, 0, i)
	    FOR(k, 0, 2500) {
	    	f[i][j][k] += f[i-1][j][k];
	    	if(j > 0 && k >= a[i])
	    	  f[i][j][k] += f[i-1][j-1][k-a[i]];
		}
	int res = 0;
	FOR(i, 1, n)
	  res += f[n][i][k*i];
	cout << res << endl;
}

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

inline void swap(int& a, int& b) {
	int t = 0;
	t = a, a = b, b = t;
}

class Dice {
private:
	int label[6];
public:
	Dice(int* a) {
		for (int i = 0; i < 6; i++) {
			label[i] = a[i];
		}
	}

	void N() {
		int cpy[] = { label[0],label[1],label[4],label[5] };
		label[0] = cpy[1];
		label[1] = cpy[3];
		label[4] = cpy[0];
		label[5] = cpy[2];

	}
	void S() {
		int cpy[] = { label[0],label[1],label[4],label[5] };
		label[0] = cpy[2];
		label[1] = cpy[0];
		label[4] = cpy[3];
		label[5] = cpy[1];

	}
	void W() {
		int cpy[] = { label[0],label[2],label[3],label[5] };
		label[0] = cpy[1];
		label[2] = cpy[3];
		label[3] = cpy[0];
		label[5] = cpy[2];

	}
	void E() {
		int cpy[] = { label[0],label[2],label[3],label[5] };
		label[0] = cpy[2];
		label[2] = cpy[0];
		label[3] = cpy[3];
		label[5] = cpy[1];

	}

	int getup() {
		return label[0];
	}
};

int main() {
	int a[6];
	for (int i = 0; i < 6; i++) {
		cin >> a[i];
	}
	class Dice dice(a);
	char order[101];
	cin >> order;
	int j = 0;
	while (order[j] != NULL) {
		switch(order[j]) {
		case 'N':dice.N(); break;
		case 'S':dice.S(); break;
		case 'W':dice.W(); break;
		case 'E':dice.E(); break;
		default: break;
		}
		//cout<<dice.getup();
		j++;
	}

	cout << dice.getup() << endl;
}


Measured memory_bytes: 3088
/************************************
	Name: 荆国浩 
	E-mail: 1839714778@qq.com 
************************************/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stdio.h>
#include <fstream>
#include <stack>
#define rep(N) for(int i=0;i<N;i++)
#define ll long long 
#define pii pair<int,int>
#define For(I,N) for(int I=0;I<N;I++)
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
	string n;
	cin>>n;
	cout<<(n[0]==n[2]?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;
using ll = long long;

#define EPS (1e-7) 

int main() {
	double T, X;
	cin >> T >> X;

	cout << T / X << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define       M                        1000000007
#define       ll                       long long
#define	      FIO		                   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define        ifor(st,lim)             for(int i=st;i<lim;i++)
#define       jfor(stt,llim)           for(int j=stt;j<llim;j++)
#define       eifor(st,lim)            for(int i=st;i<=lim;i++)
#define       ejfor(stt,llim)          for(int j=stt;j<=llim;j++)
#define       blank		                 cout<<'\n';

void solve()
{
    string s,t; cin>>s>>t;
    int n = s.size();
    int m = t.size();
    int ans = INT_MAX;
    eifor(0,n-m) {
      int diff = 0;
      jfor(0,m) {
        if(t[j] != s[i+j]) diff++;
      }
      ans = min(ans,diff);
    }  
    cout<<ans<<endl;
}

int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
int t=1; 
  while(t--){
    solve();
   } 
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int i;
  int a,b,k;

  scanf("%d %d %d",&a,&b,&k);
  for(i=0;i<k;i++){
    if(i%2==0){
      if(a%2==1){
	a--;
      }
      b+=a/2;
      a=a/2;
    }else{
      if(b%2==1){
	b--;
      }
      a+=b/2;
      b=b/2;
    }
  }
  printf("%d %d\n",a,b);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

const int dir[] = { 0,1,1,1,0,-1,-1,-1};

int main() {
	int H, W;
	cin >> H >> W;

	vector<string> m(H);

	for (int i = 0; i < H; i++)	cin >> m[i];

	vector<vector<int>> ans(H,vector<int>(W));

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			int cnt = 0;
			for (int k = 0; k < 8; k++)
			{
				if (i + dir[k] >= 0 && 
					i + dir[k] < H &&
					j + dir[(k + 6) % 8] >= 0 && 
					j + dir[(k + 6) % 8] < W &&
					m[i + dir[k]][j + dir[(k + 6)%8]] == '#') {
					cnt++;
				}
			}
			if (m[i][j] == '.') m[i][j] = '0' + cnt;
		}
	}

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


	return 0;
}

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

int main()
{
    //input
    int n, d;
    cin >> n >> d;
    vector<pair<int, int>> co(n);
    for (int i = 0; i < n; i++)
        cin >> co.at(i).first >> co.at(i).second;

    //judge
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        double k = sqrt(pow(co.at(i).first, 2) + pow(co.at(i).second, 2));
        if (k <= d)
            count++;
    }

    //output
    cout << count << endl;
    return 0;
}

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

int main() {
    int64_t H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    Ch--; Cw--; Dh--; Dw--;

    vector<string> S(H);
    for (string& s : S) {
        cin >> s;
    }

    //繋がっているところは一つにまとめる
    constexpr int64_t DIR_NUM = 4;
    constexpr int64_t dx[DIR_NUM] = { 0, 1, 0, -1 };
    constexpr int64_t dy[DIR_NUM] = { 1, 0, -1, 0 };

    constexpr int64_t SKIP_WIDTH = 2;

    vector<int64_t> cost(H * W, LLONG_MAX);
    struct Element {
        int64_t node, cost;
        bool operator>(const Element& rhs) const {
            return cost > rhs.cost;
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;

    cost[Ch * W + Cw] = 0;
    pq.push({ Ch * W + Cw, 0 });
    while (!pq.empty()) {
        Element t = pq.top();
        pq.pop();
        if (t.cost > cost[t.node]) {
            continue;
        }

        for (int64_t k = 0; k < DIR_NUM; k++) {
            int64_t ni = t.node / W + dy[k];
            int64_t nj = t.node % W + dx[k];
            if (ni < 0 || H <= ni || nj < 0 || W <= nj || S[ni][nj] == '#') {
                continue;
            }

            int64_t next_index = ni * W + nj;
            int64_t new_cost = t.cost;
            if (new_cost < cost[next_index]) {
                pq.push({ next_index, cost[next_index] = new_cost });
            }
        }

        for (int64_t i = -SKIP_WIDTH; i <= SKIP_WIDTH; i++) {
            for (int64_t j = -SKIP_WIDTH; j <= SKIP_WIDTH; j++) {
                int64_t ni = t.node / W + i;
                int64_t nj = t.node % W + j;
                if (ni < 0 || H <= ni || nj < 0 || W <= nj || S[ni][nj] == '#') {
                    continue;
                }

                int64_t next_index = ni * W + nj;
                int64_t new_cost = t.cost + 1;
                if (new_cost < cost[next_index]) {
                    pq.push({ next_index, cost[next_index] = new_cost });
                }
            }
        }
    }

    int64_t goal_index = Dh * W + Dw;
    cout << (cost[goal_index] == LLONG_MAX ? -1 : cost[goal_index]) << endl;
}

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

int dp[5001][5001];     /// dp[i][j] = lcs length of first i letters of S and first j letters of T
char S[5001], T[5001];

int main(){
    cin>>S;
    cin>>T;
    int n = strlen(S), m = strlen(T);

    for(int i = 0; i<=n; i++){
        for(int j = 0; j<=m; j++){
            if(i == 0 || j == 0){
                dp[i][j] == 0;
                continue;
            }

            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);

            if(S[i-1] == T[j-1]){
                dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
            }
        }
    }

    int cur1 = n, cur2 = m;
    string ans;
    while(cur1 > 0 && cur2 > 0){
        if(dp[cur1][cur2] == dp[cur1-1][cur2]){
            cur1--;
            continue;
        }
        if(dp[cur1][cur2] == dp[cur1][cur2-1]){
            cur2--;
            continue;
        }

        ans.push_back(S[cur1-1]);
        cur1--;
        cur2--;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;

}





Measured memory_bytes: 50720
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x;
	cin>>x;
	int g = gcd(x,360);
	int l = x*360/g;
	int ans = l/x;
	cout<<ans;	
	return 0;
}

Measured memory_bytes: 3648
words = lambda t : list(map(t, input().split()))
n = int(input())

total = 0
for i in range(1,n):
    #print("check", (n-i)//i, i)
    if (n-i) // i <= i:
        #print("end", n//i, i)
        break
    if (n-i) % i == 0:
        #print(n-i,i)
        total += (n-i) // i

print(total)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b;
    cin>>a>>b;
    int N;cin>>N;
    rep(i,N){
        int l,r;
        cin>>l>>r;
        if(r<=a||b<=l)continue;
        cout<<1<<endl;
        return 0;
    }
    cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 3076
/* created   : 2019-08-11 23:15:12
 * accepted  : 2019-08-11 23:23:15
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int pr = -999;
  for (int i = 0; i < n; i++) {
    if (pr <= a[i] - 1) {
      a[i]--;
      pr = a[i];
    }
    else if (pr <= a[i]) {
      pr = a[i];
    }
    else {
      cout << "No" << "\n";
      return;
    }
  }
  cout << "Yes" << "\n";
}

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


Measured memory_bytes: 640
x, y, na, nb, nc = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

A2 = A[-x:]
B2 = B[-y:]
ai = na - x
bi = nb - y
ans = 0
while C:
  if ai < na and bi < nb:
    if A[ai] < B[bi]:
      if C[-1] > A[ai]:
        A[ai] = C.pop(-1)
        ai += 1
      else:
        break
    else:
      if C[-1] > B[bi]:
        B[bi] = C.pop(-1)
        bi += 1
      else:
        break
  elif ai < na:
    if C[-1] > A[ai]:
      A[ai] = C.pop(-1)
      ai += 1
    else:
      break
  elif bi < nb:
    if C[-1] > B[bi]:
      B[bi] = C.pop(-1)
      bi += 1
    else:
      break
  else:
    break
print(sum(A[-x:]) + sum(B[-y:]))

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

int main(){
  int N,x;
  cin>>N>>x;

  vector<int> a(N);
  vector<int> cal(N);

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

  if(a[0]>x) cal[0]=x; 
  for(int i=0;i<N-1;i++){
    if(cal[i]+cal[i+1]>x){
      int next_num=cal[i]+cal[i+1];
      if(next_num-x<=cal[i+1]) cal[i+1]-=next_num-x;
      else{
	cal[i]-=next_num-(x+cal[i+1]);
	cal[i+1]=0;
      }
    }
  }

  unsigned long long int times=0;
  for(int i=0;i<N;i++){
    times+=a[i]-cal[i];
  }
  cout<<times<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<vector>
int a[100000];
typedef std::pair<int,int> pii;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    std::sort(a,a+n);
    std::vector<pii> v;
    for(int i=0;i<m;i++){
        int b,c;
        scanf("%d%d",&b,&c);
        v.push_back({b,c});
    }
    std::sort(v.begin(),v.end(),[](pii x,pii y){return (x.second>y.second);});
    int ai=0;
    for(auto itr=v.begin();itr!=v.end();itr++){
        int b=(*itr).first,c=(*itr).second;
        for(int i=0;i<b;i++){
            if(a[ai]<c){
                a[ai]=c;
                ai++;
            }else{
                ai=n;
                break;
            }
        }
        if(ai>=n)break;
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=a[i];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1912
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';


int main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	vector<char> s(200002);
	rep(i, n) cin >> s[i];
	a -= 1;
	b -= 1;
	c -= 1;
	d -= 1;
	s[a] = 'A';
	s[b] = 'B';
	if (c < d) {
		while (true) {
			int tmpa = a;
			int tmpb = b;
			if (s[b + 2] == '.'&&b + 2 <= d) {
				b += 2;
				s[b] = 'B';
				s[b - 2] = '.';
			}
			if (s[b + 1] == '.'&&b + 1 <= d) {
				b += 1;
				s[b] = 'B';
				s[b - 1] = '.';
			}
			if (s[a + 2] == '.'&&a + 2 <= c) {
				a += 2;
				s[a] = 'A';
				s[a - 2] = '.';
			}
			if (s[a + 1] == '.'&&a + 1 <= c) {
				a += 1;
				s[a] = 'A';
				s[a - 1] = '.';
			}
			if (a == c && b == d) { cout << "Yes"; return 0; }
			if (a == tmpa && b == tmpb) { cout << "No"; return 0; }
		}
	}
	else{
		while (true) {
			int tmpa = a;
			int tmpb = b;
			if (s[a + 2] == '.'&&a + 2 <= c) {
				a += 2;
				s[a] = 'A';
				s[a - 2] = '.';
			}
			else if (s[a + 1] == '.'&&a + 1 <= c) {
				a += 1;
				s[a] = 'A';
				s[a - 1] = '.';
			}
			else if (s[b + 1] == '.'&&b + 1 <= d) {
				b += 1;
				s[b] = 'B';
				s[b - 1] = '.';
			}
			else if (s[b + 2] == '.'&&b + 2 <= d) {
				b += 2;
				s[b] = 'B';
				s[b - 2] = '.';
			}
			if (a == c && b == d) { cout << "Yes"; return 0; }
			if (a == tmpa && b == tmpb) { cout << "No"; return 0; }
		}
	}
	}

	

Measured memory_bytes: 384
def flip_flip_and_flip(N: int, M: int) -> int:
    if N == 1 and M == 1:
        return 1
    if N == 1:
        return M - 2
    if M == 1:
        return N - 2
    return (N-2)*(M-2)


if __name__ == "__main__":
    N, M = map(int, input().split())
    ans = flip_flip_and_flip(N, M)
    print(ans)


Measured memory_bytes: 2940