akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

typedef struct geoBlock {
	int rHeight, lHeight;
	bool isFlooded = false;
	int incl; // '/'=1, '\'=-1, '_'=0
	int puddleHeight;
};

int main() {
	string geoShape;
	cin >> geoShape;
	geoBlock* mBlock = new geoBlock[geoShape.length()];
	int minHeight, maxHeight;
	for (int i = 0; i < geoShape.length(); i++) {

		if (geoShape[i] == '/') {
			mBlock[i].incl = 1;
		}
		else if (geoShape[i] == '\\') {
			mBlock[i].incl = -1;
		}
		else if (geoShape[i] == '_') {
			mBlock[i].incl = 0;
		}
		if (i == 0) {
			mBlock[i].lHeight = 0;
			mBlock[i].rHeight = mBlock[i].lHeight + mBlock[i].incl;
		}
		else {
			mBlock[i].lHeight = mBlock[i - 1].rHeight;
			mBlock[i].rHeight = mBlock[i].lHeight + mBlock[i].incl;
		}
		int min = (mBlock[i].lHeight > mBlock[i].rHeight ? mBlock[i].rHeight : mBlock[i].lHeight);
		int max = (mBlock[i].lHeight > mBlock[i].rHeight ? mBlock[i].lHeight : mBlock[i].rHeight);
		if (i == 0) {
			minHeight = min;
			maxHeight = max;
			continue;
		}

		if (minHeight > min) {
			minHeight = min;
		}
		else if (maxHeight < max) {
			maxHeight = max;
		}
	}
	int puddleCount = 0;
	for (int i = maxHeight; i > minHeight - 1; i--) {
		bool isInPuddle = false;
		int puddleStart;
		for (int j = 0; j < geoShape.length(); j++) {
			if (mBlock[j].isFlooded)continue;
			if ((isInPuddle == false) && (mBlock[j].lHeight == i) && (mBlock[j].incl == -1)) {
				isInPuddle = true;
				puddleStart = j;
			}
			else if ((isInPuddle == true) && (mBlock[j].rHeight == i) && (mBlock[j].incl == 1)) {
				isInPuddle = false;
				puddleCount++;
				for (int k = puddleStart; k < j + 1; k++) {
					mBlock[k].isFlooded = true;
					mBlock[k].puddleHeight = i;
				}
			}
		}
	}
	int* area = new int[puddleCount];
	int marker = 0;
	int sumArea = 0;
	for (int i = 0; i < puddleCount; i++) {
		area[i] = 0.0f;
		while (marker < (geoShape.length() + 1)) {
			if (mBlock[marker].isFlooded) {
				while (mBlock[marker].isFlooded) {
					area[i] += (mBlock[marker].puddleHeight) - (mBlock[marker].lHeight > mBlock[marker].rHeight ? mBlock[marker].lHeight : mBlock[marker].rHeight) + (mBlock[marker].incl == -1 ? 1 : 0);
					if (mBlock[marker].rHeight == mBlock[marker].puddleHeight) {
						marker++;
						break;
					}
					marker++;
				}
				break;
			}
			else {
				marker++;
			}
		}
		sumArea += area[i];
	}
	cout << sumArea << endl << puddleCount;
	for (int i = 0; i < puddleCount; i++) {
		cout << " " << area[i];
	}
	cout << endl;
	delete[] area;
	delete[] mBlock;
	return 0;
}


Measured memory_bytes: 3452
# coding: utf-8

# https://atcoder.jp/contests/abc079/tasks/abc079_d
# 16:03-17:18


def dijkstra(d, s, t):
    INF = 10**10
    dist = [INF] * 10
    dist[s] = 0
    checked = []

    while True:
        # 未チェックの中から，sからのコストが現状最も小さいものを見つける
        nodes = [node for node in range(10) if node not in checked]
        shortest_node, cost = nodes[0], dist[nodes[0]]

        for node in nodes:
            if dist[node] < cost:
                shortest_node, cost = node, dist[node]
        
        if shortest_node == t:
            return dist[t]

        checked.append(shortest_node)
        
        nodes = [node for node in range(10) if node not in checked]
        for node in nodes:
            dist[node] = min(
                dist[shortest_node] + d[shortest_node][node], dist[node])


def main():
    H, W = map(int, input().split())

    c = [None] * 10
    for i in range(10):
        c[i] = list(map(int, input().split()))

    A = [None] * H
    for i in range(H):
        A[i] = list(map(int, input().split()))

    shortests = [None] * 10
    for s in range(10):
        if s == 1:
            shortests[s] = 0
        else:
            shortests[s] = dijkstra(c, s, 1)
    
    counts = [0] * 10
    for h in range(H):
        for w in range(W):
            if A[h][w] == -1:
                continue

            counts[A[h][w]] += 1
    
    ans = 0
    for i in range(10):
        ans += counts[i] * shortests[i]
    
    return ans


print(main())


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

namespace AC
{
    class Program
    {

        static void Main(string[] args)
        {
            var X = ReadInt();
            var pl = PrimeList(100003);
            foreach (var i in pl)
            {
                if (i >= X)
                {
                    Console.WriteLine(i);
                    Console.ReadKey();
                    return;
                }
            }

            Console.WriteLine();
            Console.ReadKey();
        }

        static List<int> PrimeList(int num)
        {
            var pri = new List<int>();
            pri.Add(2);

            for (var i = 3; i <= num; i += 2)
            {
                var prime = true;
                for (var j = 3; j <= Math.Sqrt(i); j += 2)
                {
                    if (i % j == 0)
                    {
                        prime = false;
                        break;
                    }
                }
                if (prime) pri.Add(i);
            }

            return pri;
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13252
//AtCoder ABC071 C - Make a Rectangle
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N;
    cin>>N;
    unordered_map<ll,ll> lm;
    for(int i=0;i<N;++i){
        ll a;
        cin>>a;
        lm[a]++;
    }
    vector<pair<ll,ll>> tbl(lm.size());
    ll no=0;
    for(const auto& i:lm){
        tbl[no++]=i;
    }
    sort(tbl.begin(),tbl.end(),[](auto& a, auto& b){
        return (a.first>b.first);
    });
    ll a=0,b=0;
    for (auto&& t:tbl) {
        if(t.second>=2 && a<=0) {
            a=t.first;
            t.second -= 2;
        }
        if(t.second>=2 && b<=0) {
            b=t.first;
            t.second -= 2;
            break;
        }
    }
    cout<<a*b<<endl;
    return 0;
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define LEN(s)      (string(s)).length()
#define NPOS        string::npos
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<class T>string join(const vector<T>& v,string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(LEN(d));}

template<class T>ostream& operator<<(ostream& s,const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

template<class T>bool contain(const string& s,const T& v)
{return s.find(v)!=NPOS;}

template<class T,class U>string& replace(string& s,const T& f,const U& t)
{for(auto p=s.find(f);p!=NPOS;p=s.find(f,p+LEN(t)>0?p+LEN(t)-1:p+LEN(t)))s.replace(p,LEN(f),t);}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    string X; cin >> X;
    replace(X, "ST", "");
    //SHOW(X);
    cout << LEN(X) << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#define MAX 10000

int main(){
    int H[MAX], W[MAX];
    int i, j, k;

    for(i = 0; i < MAX; i++){
        scanf("%d %d", &H[i], &W[i]);
        if(H[i] == 0 && W[i] == 0) break;
    }

    for(i = 0; i < MAX; i++){
        if(H[i] == 0 && W[i] == 0) break;
        for(j = 0; j < H[i]; j++){
            for(k = 0; k < W[i]; k++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2084
h, w  = map(int, input().split())
s = [input() for _ in range(h)]
m = [[-1]*w for _ in range(h)]
def dp(x, y):
    if m[x][y] == -1:
        if x == 0 and y == 0:
            m[x][y] = 1 if s[x][y] == "#" else 0
        elif x == 0:
            a = dp(x, y-1)
            m[x][y] = a+1 if s[x][y] == "#" and s[x][y-1] == "." else a
        elif y == 0:
            b = dp(x-1, y)
            m[x][y] = b+1 if s[x][y] == "#" and s[x-1][y] == "." else b
        else:
            a = dp(x, y-1)
            b = dp(x-1, y)
            c = a+1 if s[x][y] == "#" and s[x][y-1] == "." else a
            d = b+1 if s[x][y] == "#" and s[x-1][y] == "." else b
            m[x][y] = min(c, d)
    return m[x][y]
print(dp(h-1, w-1))

Measured memory_bytes: 9344
using System;
using System.Collections.Generic;

public class HowManyDivisors
{
    //???????????????????????? a~b?????????c????´???°??????????????????????????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int i;
        string[] unit_num;
        int[] num = new int[3]; //a, b, c = num[0], num[1], num[2]
        int count = 0; //?´???°?????±?¨?
        /*---??£?¨???¨---*/

        
        /*3?????????[a,b,c](a???b????????????c????´???°??????????????????)????????????????????§??????*/
        unit_num = Console.ReadLine().Split(' ');
        num[0] = int.Parse(unit_num[0]);
        num[1] = int.Parse(unit_num[1]);
        num[2] = int.Parse(unit_num[2]);

        /*a~b????????§c????´???°?????°????????????*/
        for(i = num[0]; i <= num[1]; i++){
            if(num[2] % i == 0){
                count++;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<int>;
using A = array<int, 2>;
constexpr int MOD{1000000000 + 7};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr array<int, 4> dx{1, 0, -1, 0};
constexpr array<int, 4> dy{0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int div_roundup(int a, int b)
{
    return (a + b - 1) / b;
}
// vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
// ***************************************************************************
bool is_ok(int a, int b, int c)
{
    const bool l = b <= a;
    const bool r = b <= c;
    if (l && !r || !l && r)
        return true;
    else
        return false;
}
void solve()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int &x : p)
        cin >> x;

    int count = 0;

    rep(i,n-2){
        if(is_ok(p[i],p[i+1],p[i+2]))
            count++;
    }

    cout << count << endl;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(0);

    solve();
}


Measured memory_bytes: 256
N = int(input())
h = [int(i) for i in input().split()]
dp = [float("inf")]*N

dp[0] = 0

for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1: dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])

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

int main() {
	string s,t;
	cin >> s >> 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
#include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<vector<int>>abc(3,vector<int>(n)); for(auto&&i:abc)for(auto&&j:i)cin>>j;
	sort(abc.at(0).begin(),abc.at(0).end()); sort(abc.at(2).begin(),abc.at(2).end());
	int64_t ans=0;
	for(auto&&b:abc.at(1)){
		auto ait=lower_bound(abc.at(0).begin(),abc.at(0).end(),b);
		auto cit=upper_bound(abc.at(2).begin(),abc.at(2).end(),b);
		int a=ait-abc.at(0).begin(),c=abc.at(2).end()-cit;
		ans+=1L*a*c;
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 4764
h,w,k=[int(i) for i in input().split()]

def get_conbination(i,length):
    return format(i, '#0'+str(length+2)+'b')[2:]
sheet=[]
for i in range(h):
    sheet.append(input())

ans=0
for i in range(2**h):
    for j in range(2**w):
        total=0
        gyou_select=get_conbination(i,h)
        retu_select = get_conbination(j, w)
        for gyou in range(h):
            for retu in range(w):
                if gyou_select[gyou]=="0" and retu_select[retu]=="0":
                    if sheet[gyou][retu]=="#":
                        total+=1
        if total==k:
            ans+=1

print(ans)



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


int main()
{
	string S;
	cin >> S;
	int n = S.size() - 1;
	long long ans = 0;
	for (int i = 0; i < (1 << n); i++)
	{
		long long temp = 0;
		for (int j = 0; j < n; j++)
		{
			temp = temp * 10 + (S[j] - '0');
			if (i & (1 << j))
			{
				ans += temp;
				temp = 0;
			}
		}
		temp = temp * 10 + (S[n] - '0');
		ans += temp;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
int x[200000];
signed main() {
	int b, a, ans;
	cin >> b >> a;
	f(i, a) {
		cin >> x[i];
	}
	f(i, a) {
		if (i)ans = min(ans, b + x[i - 1] - x[i]);
		else ans = x[a - 1] - x[0];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
flag=0
while flag==0:
    a,b,c = input('').split()
    a = int(a)
    b = int(b)
    c  = int(c)

    if 1<=a<=13 and 1<=b<=13 and 1<=c<=13:
        flag=1

score = a+b+c
if score>=22:
    print("bust")
else:
    print("win")

Measured memory_bytes: 3060
s = input()
k = int(input())
alp = 'bcdefghijklmnopqrstuvwxyza'
t = alp.find(s[0])
if len(s) == 1:
    s = alp[(k+t)%26]
else: 
    if k >= 25-t:
        s = 'a' + s[1:]
        k -= 25-t
    for i in range(1, len(s)-1):
        t = alp.find(s[i])
        if k >= 25-t:
            s = s[:i] + 'a' + s[i+1:]
            k -= 25-t
    s = s[:len(s)-1] + alp[(k+alp.find(s[-1]))%26]
print(s)

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

struct Edge{
    int to;
    int weight;
    Edge(int t, int w):to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
vector<int> color;

bool dfs(Graph &G, int v, int cur = 0){
    color[v] = cur;
    for(auto next_v:G[v]){
        if(color[next_v.to] != -1){
            if(next_v.weight % 2 == 0 && color[next_v.to] != color[v]){
                return false;
            }
            continue;
        }
        if(next_v.weight % 2 == 0){
            if(!dfs(G, next_v.to, cur))return false;
        }else{
            if(!dfs(G, next_v.to, 1 - cur)) return false;
        }
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    Graph G(n);
    rep(i, n-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    color.assign(n, -1);
    rep(i, n){
        if(color[i] != -1) continue;
        dfs(G, i);
    }
    rep(i, n){
        cout << color[i] << endl;
    }
    return 0;
}

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

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


int main(){
    int X;
    cin >> X;

    if(400<=X&&X<600){
        cout << 8 << endl;
    }else if(600<=X&&X<800){
        cout << "7" << endl;
    }else if(800<=X&&X<1000){
        cout << "6" << endl;
    }else if(1000<=X&&X<1200){
        cout << "5" << endl;
    }else if(1200<=X&&X<1400){
        cout << "4" << endl;
    }else if(1400<=X&&X<1600){
        cout << "3" << endl;
    }else if(1600<=X&&X<1800){
        cout << "2" << endl;
    }else if(1800<=X&&X<2000){
        cout << "1" << endl;
    }
    
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  std::ios::sync_with_stdio(0);
  std::cin.tie(NULL);
  std::cout.tie(0);
  
  string s;
  cin >> s; //Sunny, Cloudy, or Rainy.
  if(s == "Cloudy") cout << "Rainy";
  else if(s == "Rainy") cout << "Sunny";
  else cout << "Cloudy";
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,m,n,s;
 s=0;
 cin >> n >> m;
 int a[m];
 for(i=0;i<m;i++){
 cin >> a[i];
 s+=a[i];}
 if(n>=s)
 cout << n-s;
 else
 cout << "-1";
 return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int32_t main() {

    simplify
    int n;
    cin>>n;
    vector<int>arr(n);

    int xori=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        xori^=arr[i];
    }
    for(int i=0;i<n;i++){
        cout<<(xori^arr[i])<<" ";
    }



    return 0;
}


Measured memory_bytes: 4764
# -*- coding: utf-8 -*-
N, X, M = map(int, input().split())

mod_check_list = [False for _ in range(M)]
mod_list = [(X ** 2) % M]
counter = 1
mod_sum = (X ** 2) % M
last_mod = 0
for i in range(M):
    now_mod = (mod_list[-1] ** 2) % M
    if mod_check_list[now_mod]:
        last_mod = now_mod
        break
    mod_check_list[now_mod] = True
    mod_list.append(now_mod)
    counter += 1
    mod_sum += now_mod

loop_start_idx = 0
for i in range(counter):
    if last_mod == mod_list[i]:
        loop_start_idx = i
        break

loop_list = mod_list[loop_start_idx:]
loop_num = counter - loop_start_idx
ans = 0
if (N - 1) <= counter:
    ans = X + sum(mod_list[:N - 1])
else:
    ans += X + mod_sum
    N -= (counter + 1)
    ans += sum(loop_list) * (N // loop_num) + sum(loop_list[:N % loop_num])

print(ans)

Measured memory_bytes: 12480
#include <iostream>
using namespace std;
int main(){
  long long a;cin>>a;
  long long ans = a+1;
  for(long long i = 1; a >= i*i; i++){
    if(!(a%i)){
      ans = min(ans,i+a/i-2);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N, M, X, Y =map(int,input().split())
A =list(map(int,input().split()))
B =list(map(int,input().split()))
result =0
flag = 0
for i in range (X+1, Y+1):
    flag = 0
    for j in range (N):
        if A[j] >=i:
            flag=1
    for k in range (M):
        if B[k] <i:
            flag=1
    if flag ==0:
        result =1
        
if result !=1:
    print('War')
else:
    print('No War')


Measured memory_bytes: 3064
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var S = new string[N];
            var P = new int[N];
            for (int i = 0; i < N; i++)
            {
                S[i] = cin.Read;
                P[i] = cin.ReadInt;
            }
            var ans = Enumerable.Range(1, N).OrderBy(i => S[i - 1]).ThenByDescending(i => P[i - 1]);
            Console.WriteLine(string.Join("\n", ans));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13664
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

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


	ll N, M;
	cin >> N >> M;

	vll A(N);
	vp CB(M);

	rep(i, N) {
		cin >> A[i];
	}
	rep(i, M) {
		cin >> CB[i].second >> CB[i].first;
	}

	sort(A.begin(), A.end());
	sort(CB.begin(), CB.end(), greater<pair<ll,ll> >());

	ll index = 0;

	rep(i, M) {
		rep(k, CB[i].second) {
			if (A[index] < CB[i].first) {
				A[index] = CB[i].first;
				index++;
			}
			else {
				i = M;
				break;
			}
		}
	}

	ll sum = 0;

	rep(i, N) {
		sum += A[i];
	}


	cout << sum << endl;




	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A[200000];
    cin >> N;
    REP(i, N) cin >> A[i];
    sort(A, A + N);
    reverse(A, A + N);

    ll ans = 0;
    vector<int> ring = {A[0]};
    priority_queue<pii> que; que.push({A[0], 0});
    FOR(i, 1, N) {
        pii p = que.top(); que.pop();
        ans += p.first;
        int index = p.second, next = A[i], size = ring.size();
        que.push({min(next, ring[index]), index});
        que.push({min(next, ring[(index + 1) % size]), index + 1});
        ring.insert(ring.begin() + index + 1, next);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7512
using System;
using System.Linq;

namespace test
{
  class Program
  {
   	static void Main(string[] args)
   	{
            string[] a = Console.ReadLine().Split(' ');
            string s = Console.ReadLine();
            char[] str = s.ToCharArray();
            int n = int.Parse(a[0]);
            int k = int.Parse(a[1]);

            if (str[k - 1] == 'A')
            {
                str[k - 1] = 'a';
            }
            else if (str[k - 1] == 'B')
            {
                str[k - 1] = 'b';
            }
            else
            {
                str[k - 1] = 'c';
            }

           Console.WriteLine(new String(str));
   	}
  }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}

void solve(){
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	string s;
	cin>>s;
	int f=0,f1=0;
	if(c>d){
		for(int i=max(0,b-2);i<min(n-2,d-1);i++)if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
			f=1;break;
		}
		if(!f){cout<<"No";return;}
		f=0;
		for(int i=a-1;i<c-1;i++)if(s[i]=='#'&&s[i+1]=='#'){f=1;break;}
		for(int i=b-1;i<d-1;i++)if(s[i]=='#'&&s[i+1]=='#'){f1=1;break;}
		if(f||f1)cout<<"No";
		else cout<<"Yes";
	}
	else{
		for(int i=a-1;i<c-1;i++)if(s[i]=='#'&&s[i+1]=='#'){f=1;break;}
		for(int i=b-1;i<d-1;i++)if(s[i]=='#'&&s[i+1]=='#'){f1=1;break;}
		if(f||f1)cout<<"No";
		else cout<<"Yes";
	}
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 592
#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 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 << 29;
const ll INF64 = 1ll << 45;
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()
{
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  if(h == 0 && m == 0) {
    cout << abs(a-b) << endl;
    return 0;
  }
  double x = (h+m/60) * M_PI / 6;
  double y = M_PI*m / 30;
  if(y == 0) y = 2*M_PI;
  double t = abs(x-y);
  double ans = sqrt(a*a+b*b-2*a*b*cos(t));
  printf("%0.12f\n", ans);
}

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

const int MAXN = 1000010;
char str[MAXN];
int Q[MAXN], suf[MAXN], pre[MAXN], f[MAXN];
int n, q, last;

ll solve(int k) {
	if(!last) return 0;
	int h = 1, t = 0;
	ll s = 0, ans = 0;
	for(int i = 1; i <= n; ++i) {
		if(str[i] == 'D') {
			Q[++t] = i;
			s += f[i];
		}
		if(str[i] == 'C') {
			while(h <= t && i - Q[h] >= k) s -= f[Q[h++]];
			ans += 1LL * f[i] * (t - h + 1) - s;
		}
	}
	return ans;
}
int main() {
	scanf("%d", &n);
	scanf("%s", str + 1);
	/*
	for(int i = 1; i <= n; ++i) {
		pre[i] = pre[i - 1];
		if(str[i] == 'M') pre[i] = i;
	}
	suf[n + 1] = n + 1;
	for(int i = n; i > 0; --i) {
		suf[i] = suf[i + 1];
		if(str[i] == 'M') suf[i] = i;
	}*/
	
	for(int i = 1; i <= n; ++i) {
		f[i] = f[i - 1] + (str[i] == 'M');
		if(str[i] == 'M') last = i;
	}
	int k;
	scanf("%d", &q);
	while(q--) {
		scanf("%d", &k);
		printf("%lld\n", solve(k));
	}
	
	return 0;
}

Measured memory_bytes: 10752
n, m = map(int, input().split())
arr = [int(input()) for _ in range(m)]
mod = 10 ** 9 + 7

dp = [1] + [0] * n + [0]

j = 0
for i in range(1, n + 1):
    if j < m and i == arr[j]:
        dp[i] = 0
        j += 1
        continue

    dp[i] = dp[i - 1] + dp[i - 2]
    dp[i] %= mod

print(dp[n])


Measured memory_bytes: 8592
import java.util.*;
public class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    long[] b = new long[a];
    long MAX = (long)Math.pow(10,18);
    long result = 1;
    
    
    for(int i = 0; i < a; i++)
    {
      b[i] = sc.nextLong();
      if(b[i]  == 0)
      {
        System.out.println(0);
      	return;
      }
    }
    
    
    for(int i = 0; i < a; i++)
    {
      if(MAX/result < b[i])
      {
        System.out.println(-1);
        return;
      }
      else
      {
        result *= b[i];
      }
    }
    System.out.println(result);
  }
}


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

using namespace std;

typedef long long ll;

char played_hand[(int)1e5+10];
bool not_win[(int)1e5+10];

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

    int n, k;
    ll r, s, p;
    string t;

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    map<char,char> m;
    m['r'] = 'p';
    m['s'] = 'r';
    m['p'] = 's';

    for(int i=0; i<n; i++)
        played_hand[i] = m[t[i]];

    for(int i=k; i<n; i++){
        if(played_hand[i-k] == played_hand[i] and !not_win[i-k]){
            played_hand[i] = t[i];
            not_win[i] = true;
        }
    }
    
    ll total = 0;
    for(int i=0; i<n; i++){
        if(!not_win[i]){
            if(played_hand[i] == 'r') total+=r;
            if(played_hand[i] == 's') total+=s;
            if(played_hand[i] == 'p') total+=p;
        }
    }
    cout << total << "\n";

    return 0;
}

Measured memory_bytes: 720
n=int(input())
ans=[0]*4
for i in range(n):
    s=input()
    if s=='AC':
        ans[0]+=1
    elif s=='WA':
        ans[1]+=1
    elif s=='TLE':
        ans[2]+=1
    else:
        ans[3]+=1
print('AC'+' x '+str(ans[0]))
print('WA'+' x '+str(ans[1]))
print('TLE' + ' x '+str(ans[2]))
print('RE'+' x '+str(ans[3]))

Measured memory_bytes: 9088
number_of_500_coins = gets.to_i
number_of_100_coins = gets.to_i
number_of_50_coins = gets.to_i
total_value = gets.to_i

counter = 0
(number_of_500_coins + 1).times do |i|
  (number_of_100_coins + 1).times do |j|
    (number_of_50_coins + 1).times do |k|
      counter += 1 if 500 * i + 100 * j + 50 * k === total_value
    end
  end
end

puts counter


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

int main(){
    int n;
    cin>>n;
    vector<int> res(n);
    vector<int> c(n),s(n),f(n);
    for(int i=0;i<n-1;i++){
        cin>>c[i]>>s[i]>>f[i];
    }
    
    for(int i=0;i<n;i++){
        int time=0;
        for(int j=i;j<n-1;j++){
            if(time<s[j]) time=s[j];
            else time+=((-time)%f[j]+f[j])%f[j];
            time+=c[j];
        }
        res[i]=time;
    }
    for(int i=0;i<n;i++) cout<<res[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = ll(1e9 + 7);

int c[100010];

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

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

	int t = (N + 1) % 2;
	int n = (N + 1) / 2;
	for(int i = 0; i < n; i++) {
		int k = t + 2 * i;
		//cout << k << endl;
		bool ok = true;
		if(N % 2) {
			if(i == 0 && c[k] != 1) ok = false;
			if(i != 0 && c[k] != 2) ok = false;
		}
		else {
			if(c[k] != 2) ok = false;
		}
		if(!ok) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll ans = 1;
	for(int i = 0; i < N / 2; i++) {
		ans = ans * 2 % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(Math.abs(x-a)<Math.abs(x-b)) {
			System.out.println("A");
		}else {
			System.out.println("B");
		}
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21844
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int k, t;
int a[110];

int main() {
    while (cin >> k >> t) {
        for (int i = 0; i < t; i++) {
            cin >> a[i];
        }
        sort(a, a + t);
        int x = accumulate(a, a + t - 1, 0);
        int y = a[t - 1] - 1;
        cout << max(0, y - x) << endl;
    }
}


Measured memory_bytes: 256
from itertools import accumulate
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N, M, K = inpl()

X = sum([n*(n+1)//2 for n in range(1, N)])*M*(M)%MOD
Y = sum([m*(m+1)//2 for m in range(1, M)])*N*(N)%MOD


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N*M + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

print((X+Y)*cmb(N*M-2, K-2, MOD)%MOD)


Measured memory_bytes: 83280
#include<cstdio>
     
    int main(){
    char w[2] = { 'H', 'D' };
    char in1, in2;
    int a = 0;
     
    scanf("%c %c", &in1, &in2);
     
    if(in1 == 'D') a++;
    if(in2 == 'D') a = (a+1)%2;
     
    if(a == 0) printf("H");
    if(a == 1) printf("D");
     
    return 0;
    }

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

int solve(const std::string& s)
{
  int result = 0;
  int count = 0;
  for (auto& c : s) {
    if (c == 'R') {
      ++count;
      result = std::max(result, count);
    } else {
      count = 0;
    }
  }
  return result;
}

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

  std::cout << std::setprecision(20);
  std::cout << solve(s) << std::endl;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int result = -1;
  for (int i = 1; i < 1100; i++) {
    if (floor(i * 0.08) == a && floor(i * 0.10) == b) {
      result = i;
      break;
    }
  }
  cout << result << endl;
  return 0;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  char c;
  int cnt = 0;
  rep(i,4){
    cin >> c;
    if(c=='2')cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
ma = [[0]*n for _ in range(n)]
list_ABC = [ list(map(int,input().split(" "))) for i in range(m)]
for a, b, c in list_ABC:
    ma[a-1][b-1] = c
    ma[b-1][a-1] = c

x = csr_matrix(ma)
y = dijkstra(x, directed=False).astype(int)

ans = 0

for a, b, c in list_ABC:
  if y[a-1][b-1] != c:
      ans += 1

print(ans)

Measured memory_bytes: 17536
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int N = ReadLineParseInt();
        int[] asc = new int[N];
        int[] dsc = new int[N];
        int[] W = ReadLineParseIntArray();

        asc[0] = W[0];
        for(int i = 1; i < N; i++)
        {
            asc[i] = asc[i - 1] + W[i];
        }
        dsc[N - 1] = W[N - 1];
        for(int i = 1; i < N; i++)
        {
            dsc[N - i - 1] = dsc[N - i] + W[N - i - 1];
        }
        int min = int.MaxValue;
        for(int i = 0; i < N - 1; i++)
        {
            int v = Abs(asc[i] - dsc[i + 1]);
            min = Min(min, v);
        }
        WriteLine(min);
    }
      static int ReadLineParseInt() => int.Parse(ReadLine());
      static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

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

struct C {
	double r, g, b;
	C(double r = 0, double g = 0, double b = 0): r(r), g(g), b(b){}
};

double sq(double a)
{
	return a * a;
}

double dist(C a, C b)
{
	return sq(a.r - b.r) + sq(a.g - b.g) + sq(a.b - b.b);
}

C c[20];

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++){
		double r, g, b;
		scanf("%lf %lf %lf", &r, &g, &b);
		c[i] = C(r, g, b);
	}
	
	vector<bool> pat(n, false);
	for (int i = 0; i < m; i++){
		pat[n - i - 1] = true;
	}
	
	double res = 0;
	
	do {
		vector<int> v;
		for (int i = 0; i < n; i++){
			if (pat[i]) v.push_back(i);
		}
		
		double sum = 0;
		for (int i = 0; i < m; i++){
			for (int j = i + 1; j < m; j++){
				sum += dist(c[v[i]], c[v[j]]);
			}
		}
		
		res = max(res, sum);
	} while (next_permutation(pat.begin(), pat.end()));
	
	printf("%.20f\n", res);
}

Measured memory_bytes: 1272
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(ll x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ll a=ri(),b=ri(),c=ri(),x=ri(),y=ri(),i,n=max(2*x,2*y),ta,tb,ans=1e18;
	for(i=0;i<=n;i+=2)
	{
		ta=max(0ll,x-i/2);tb=max(0ll,y-i/2);
		ans=min(ans,i*c+ta*a+tb*b);
	}
	wi(ans);putchar('\n');
	return 0;
}
/*
1500 2000 1600 3 2

7900


*/

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	h, w int
	s    []string
	ch   = make(chan [][]int, 4)
)

func calcLeft() {
	ls := make([][]int, h)
	for i := range ls {
		ls[i] = make([]int, w)
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				ls[i][j] = 0
				continue
			}
			if j == 0 {
				ls[i][j] = 1
				continue
			}
			ls[i][j] = ls[i][j-1] + 1
		}
	}
	ch <- ls
}

func calcRight() {
	rs := make([][]int, h)
	for i := range rs {
		rs[i] = make([]int, w)
		for j := w - 1; j >= 0; j-- {
			if s[i][j] == '#' {
				rs[i][j] = 0
				continue
			}
			if j == w-1 {
				rs[i][j] = 1
				continue
			}
			rs[i][j] = rs[i][j+1] + 1
		}
	}
	ch <- rs
}

func calcTop() {
	ts := make([][]int, h)
	for i := range ts {
		ts[i] = make([]int, w)
	}
	for j := 0; j < w; j++ {
		for i := 0; i < h; i++ {
			if s[i][j] == '#' {
				ts[i][j] = 0
				continue
			}
			if i == 0 {
				ts[i][j] = 1
				continue
			}
			ts[i][j] = ts[i-1][j] + 1
		}
	}
	ch <- ts
}

func calcDown() {
	ds := make([][]int, h)
	for i := range ds {
		ds[i] = make([]int, w)
	}
	for j := 0; j < w; j++ {
		for i := h - 1; i >= 0; i-- {
			if s[i][j] == '#' {
				ds[i][j] = 0
				continue
			}
			if i == h-1 {
				ds[i][j] = 1
				continue
			}
			ds[i][j] = ds[i+1][j] + 1
		}
	}
	ch <- ds
}

func main() {
	fmt.Scan(&h, &w)

	sc := bufio.NewScanner(os.Stdin)
	s = make([]string, h)
	for i := range s {
		sc.Scan()
		s[i] = sc.Text()
	}

	go calcLeft()
	go calcRight()
	go calcTop()
	go calcDown()

	s1, s2, s3, s4 := <-ch, <-ch, <-ch, <-ch
	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if v := s1[i][j] + s2[i][j] + s3[i][j] + s4[i][j] - 3; v > ans {
				ans = v
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 138304
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 100000; 

int main(){
    ll n;
    cin >> n;

    for(int i = 0; ; i++){
        ll num = i * i;
        if(num > n){
            cout << (i-1) * (i-1) << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
//C-submarine
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int i,j,n,k,a[262144],c=1,r=0;
    scanf("%d",&n);
    a[n]=inf;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),sortfncsj);
    for(i=1;i<=n;i++){
        if(a[i-1]!=a[i]){
            if(a[i-1]<=c){r+=c-a[i-1];}
            else{r+=c;}
            c=1;
        }
        else{
            c++;
        }
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 892
d = {}
N, d['A'], d['B'], d['C'] = map(int, input().split())
S = [input() for _ in range(N)]

if sum(d.values()) == 0:
    print('No')
elif sum(d.values()) == 1:
    ans = []
    for s in S:
        if d[s[0]] == d[s[1]] == 0:
            print('No')
            exit()
        elif d[s[0]] > d[s[1]]:
            d[s[0]] -= 1
            d[s[1]] += 1
            ans.append(s[1])
        else:
            d[s[0]] += 1
            d[s[1]] -= 1
            ans.append(s[0])
    print('Yes')
    print(*ans, sep='\n')
else:
    ans = []
    for i, s in enumerate(S):
        if d[s[0]] == d[s[1]] == 0:
            print('No')
            exit()
        elif d[s[0]] > d[s[1]]:
            d[s[0]] -= 1
            d[s[1]] += 1
            ans.append(s[1])
        elif d[s[0]] < d[s[1]]:
            d[s[0]] += 1
            d[s[1]] -= 1
            ans.append(s[0])
        elif d[s[0]] == d[s[1]] == 1 and i != N-1 and S[i] != S[i+1]:
            # elif sum(d.values()) == 2 and d[s[0]] == d[s[1]] == 1 and i != N-1 and S[i] != S[i+1]:
            if s[0] in S[i+1]:
                d[s[0]] += 1
                d[s[1]] -= 1
                ans.append(s[0])
            else:
                d[s[0]] -= 1
                d[s[1]] += 1
                ans.append(s[1])
        else:
            d[s[0]] -= 1
            d[s[1]] += 1
            ans.append(s[1])
    print('Yes')
    print(*ans, sep='\n')


Measured memory_bytes: 95892