akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
    int N = sc.nextInt();
    int M = sc.nextInt();       
    UnionFind uf = new UnionFind(N);
    for(int i=0;i<M;i++){
      int A = sc.nextInt()-1;
      int B = sc.nextInt()-1;
      uf.union(A,B);
    }
    System.out.println(uf.maxSize());
}

static class UnionFind {
	
	int[] parent;
	int[] rank;
	
	public UnionFind(int size) {
		this.parent = new int[size];
		this.rank = new int[size];
		for(int i=0;i<size;i++){
          parent[i] = i;
          rank[i] = 1;
        }
	}
	
	public void union(int x, int y) {
		int xRoot = find(x);
		int yRoot = find(y);
		
		//xが属する木の方が大きい場合
		if (rank[xRoot] > rank[yRoot]) { 
			parent[yRoot] = xRoot; //yの親をxに更新
            rank[xRoot]+=rank[yRoot];
		} else if(rank[xRoot] < rank[yRoot]) {
			parent[xRoot] = yRoot;
            rank[yRoot]+=rank[xRoot];
		} else if (xRoot != yRoot){
			parent[yRoot] = xRoot;
			rank[xRoot]+=rank[yRoot]; //同じ高さの木がルートの子として着くから大きさ++;
		}
	}
	
	//引数の属する木のルートを返す
	public int find(int i) {
		if (i != parent[i]) {
			parent[i] = find(parent[i]);
		}
		return parent[i];
	}
	
	//同じ木に属しているか
	public boolean same(int x, int y) {
		return find(x) == find(y);
	}
    
    public int maxSize() {
      int max = 0;
      for(int i=0;i<rank.length;i++){
        //System.out.println(rank[i]);
        max = Math.max(max,rank[i]);
      }
      return max;
	}
  
    public void parList(){
      for(int i=0;i<parent.length;i++){
        System.out.println(i+"の親は"+parent[i]);
      }
      System.out.println();
    }
}
}


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

using namespace std;
const int N=2e5+5;
#define ll long long
int a[N];
ll LCM(ll x,ll y)
{
    return (x*y)/__gcd(x,y);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,x;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]/=2;
    }
    ll lcm=a[0];
    for(int i=1;i<n;i++){
        lcm=LCM(lcm,a[i]);
        if(lcm>x) return cout<<0<<endl,0;
    }
    for(int i=0;i<n;i++)
        if((lcm/a[i])%2==0)
            return cout<<0<<endl,0;
    x=x/lcm;
    cout<<(x+1)/2<<endl;
    return 0;
}


Measured memory_bytes: 640
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range (n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        tmp=0
        for k in range(d):
            tmp+=(x[i][k]-x[j][k])**2
        if math.sqrt(tmp)==int(math.sqrt(tmp)):
            ans+=1
print(ans)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  cin >> s;
  char x = s[0];
  fi(1,3) {
    if(s[i]!=x) ans = 1;
  }
  cout << (ans?"Yes":"No")<<endl;
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
char field[200][200];

int main(){
  ll x,y;
  ll ans = 0;
  cin >> n >> m >> l >> x >> y;
  ll ans2 = 0;
  {
    ans2 += max(x, y) * 2 * l;
    if(max(x , y) % 2)ans2 += 2 * l;
  }
  {
    if(n + m > 2 * l){
      ans += 2 * min(x,y) * l;
      ll p = min(x,y);
      x-= p;
      y-= p;
    }
    if(x > 0)ans += x * n;
    if(y > 0)ans += y * m;
  }
  // print(ans);
  // print(ans2);
  print(min(ans,ans2));
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n;
int gcd(int x,int y){
	return (y==0?x:gcd(y,x%y));
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	int ans=0;
	fo(i,1,n+1) fo(j,1,n+1) fo(k,1,n+1)ans+=gcd(gcd(i,j),k);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3624
def split_and_change(N, Array):
    Arr1 = Array[0::2]
    Arr2 = Array[1::2]
    if N % 2 == 0:
        return Arr2[::-1] + Arr1
    else:
        return Arr1[::-1] + Arr2
    
print(" ".join(split_and_change(int(input()), input().split())))

Measured memory_bytes: 21572
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        int[] a = Read.ints();
        Array.Sort(a);
        if (a[0] == a[1]) { Console.WriteLine(a[2]); }
        else { Console.WriteLine(a[0]); }
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a / gcd(a, b) * b;
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (long i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13396
#include <stdio.h>

int main(){
   int b,a,n,sum;
  
  scanf("%d\n",&n);
  scanf("%d\n",&a);
  scanf("%d\n",&b);


  sum=n*a;

  if(sum<b){
    printf("%d",sum);
  }else{
    printf("%d",b);
  }
}


Measured memory_bytes: 128
//
//  main.cpp
//  Exercise
//
//

#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "string.h"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <set>

using namespace std;

using intll_t = long long;

int main() {
    int A, B, X;
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &X);
    if (A <= X && X <= A + B) {
        printf("YES");
    } else {
        printf("NO");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

using namespace std;

const ll N = 3e5 + 5;

int n;
int dp[N][4];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < 3; j++){
            int x;
            cin>>x;
            dp[i][j] = x + max (dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]);
        }
    cout<<max (max (dp[n][0], dp[n][1]), dp[n][2])<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int h,w;
    cin >> h >> w;
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    vector<vector<int>>data(h,vector<int>(w));
    int color = 1;
    int cnt = 0;
    for(int i = 0;i < h*w;i++){
        if(cnt == a[color-1]){
            color += 1;
            cnt = 0;
        }
        if((i/w)%2 == 0){
            data[i/w][i%w] = color;
            cnt++;
        }else{
            data[i/w][w-1-i%w] = color;
            cnt++;
        }
    }
    rep(i,h){
        rep(j,w){
            cout <<data[i][j];
            if(j!=w-1)cout << " ";
        }
        cout << endl;
    }
    return 0;
}

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

typedef pair< int, long long  int> PLL;

int main() {
	int N;
	while( cin >> N, N ) {
		vector<vector<int>>D( N, vector<int>( N + 1 ) );
		for( size_t i = 0; i < N; i++ ) {
			for( size_t j = 0; j < N + 1; j++ ) {
				cin >> D[i][j];
			}
		}
		map<long long int, int>SCORE;
		priority_queue<PLL, vector<PLL>, greater<PLL>>que;
		que.push( make_pair( 0, 0 ) );
		int ans = INT_MAX / 2;
		while( que.size() ) {
			auto now = que.top(); que.pop();
			if( now.second == (1 << N) - 1 ) {
				ans = min( ans, now.first );
			}
			if( ans < now.first ) {
				break;
			}
			if( SCORE[now.second] != 0 && SCORE[now.second] <= now.first ) {
				continue;
			}
			SCORE[now.second] = now.first;
			for( int i = 0; i < N; i++ ) {
				if( !((1 << i)&now.second) ) {
					PLL next = make_pair( D[i][0], (1 << i) | now.second );
					for( int j = 0; j < N; j++ ) {
						if( (1 << j)& now.second ) {
							next.first = min( next.first, D[i][j + 1] );
						}
					}
					next.first += now.first;
					if( SCORE[next.second] == 0 || SCORE[next.second]>next.first ) {
						que.push( next );
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define ll long long
#define hh puts("")
using namespace std;

inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=ret*10+(ch^48);ch=getchar();}
    return ret*ff;
}
signed main(){
    int x=read(),y=read();
    printf("%d",(x*3+y)/2);
    return 0;
}

Measured memory_bytes: 256
a,b,m = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

ans = 10**10
m.times do |i|
  x,y,c = gets.split.map(&:to_i)
  ans = [ans, as[x-1]+bs[y-1]-c].min
end

puts [ans, as.min+bs.min].min

Measured memory_bytes: 20876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int n;
  cin >> n;
  vector<int> fib(n + 1);
  fib[0] = 1;
  fib[1] = 1;
  for(int i = 2; i <= n; i++)
  {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
  int ans = fib[n];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3116
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	auto M = RD!long;

	long ans = (N - M) * 100 + M * 1900;
	ans *= pow(2, M);

	writeln(ans);
	stdout.flush();
}

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

using namespace std;

const int N = 110, K = 1e5+100, mod = 1e9+7;
int n, k, a[N], dp[N][K], sum[K];


int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	scanf("%d %d", &n, &k);

	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}

	dp[0][0] = 1; // i , k qtd de doces

	for (int i = 1; i <= n; i++){
		memset(sum, 0, sizeof sum);
		sum[0] = dp[i - 1][0];

		for (int j = 1; j <= k; j++){
			sum[j] = (sum[j - 1] + dp[i - 1][j])%mod;
		}

		for (int j = 0; j <= k; j++){
			int sumj = sum[j], 
				rmv = j - a[i] - 1; // [a[i], j]
			if (rmv >= 0){
				//cout << rmv << endl;
			 	sumj = (sumj - sum[rmv] + mod)%mod;
			 }
			dp[i][j] = sumj;
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}

	printf("%d\n", dp[n][k]);

	return 0; 
}

Measured memory_bytes: 43224
n = int(input())
dp = [0, 0, 0]

for i in range(n):
    A = [int(i) for i in input().split()]
    dp = [max(dp[1], dp[2]) + A[0], max(dp[0], dp[2]) + A[1], max(dp[0], dp[1]) + A[2]]
    
print(max(dp))

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int a[100],max=-1000,min=2000;
	for(int i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<3;i++){
		if(a[i]>max){
			max=a[i];
		}
		if(a[i]<min){
			min=a[i];
		}
	}
	printf("%d",max-min);
	
}

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

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(long[]);
    sort!"a > b"(as);
    N -= 2;
    long r = as[0];
    size_t i = 1;
    while (N > 0) {
        r += as[i];
        --N;
        if (N == 0) break;
        r += as[i];
        --N;
        ++i;
    }
    writeln(r);
}

Measured memory_bytes: 11724
# coding: utf-8
card = []
def k_cut(k, a):
    a = a[k:] + a[:k]
    return a

def riffle(n, a):
    c = []
    a_card = a[:n]
    b_card = a[n:]
    for i in range(n):
        c.append(a_card[i])
        c.append(b_card[i])
    return c
    
n = int(input())
m = int(input())
card = [str(i+1) for i in range(2*n)]
for i in range(m):
    k = int(input())
    if k == 0:
        card = riffle(n, card)
    else:
        card = k_cut(k, card)
for i in range(len(card)):
    print(card[i])

Measured memory_bytes: 7704
program AGC37_A
  character(200000)::S
  integer(8)::ans=1,N,i=1,L
  read(*,*)S
  N=len_trim(S)-1
  L=len_trim(S)
  do while(N>0)
     if(S(i:i)==S(i+1:i+1) .and. N>1) then
        N=N-2
        ans=ans+1
        i=i+2
        if(N==0) exit
        if(N/=2 .or. S(L-1:L-1)/=S(L:L)) then
           N=N-1
           ans=ans+1
           i=i+1
        else
           N=N-2
           ans=ans+1
           i=i+2
        end if
     else
        if(N/=2 .or. S(L-1:L-1)/=S(L:L)) then
           N=N-1
           ans=ans+1
           i=i+1
        else
           N=N-2
           ans=ans+1
           i=i+2
        end if
     end if
  end do
  write(*,*)ans
end program AGC37_A

Measured memory_bytes: 1212
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[100][100] = { -1 }, f[10000], g[10000], h[10000], m[100] = { 0 }, counto = 0, x[100] = { 0 }, y = 0, z = 0;
long long ab[100000], abc = 0,abcd=0;
pair<int, int>manji[1500], daburu[100];
char rikka, toka[50][50];
string saya, homu, kyok, mami[100], mado[100];
bool gg = false;
vector<char>uc;
vector<int>gachi;
int main() {
	cin >> a >> b >> c;
	for (int i = 0; i < a; i++) {
		cin >> manji[i].first >> manji[i].second;
	}
	for (int i = 0; i < a; i++) {
		if (manji[i].first >= b && manji[i].second >= c) {
			counto++;
		}
	}
	cout << counto << endl;
	return 0;
}

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

int main(){
  double n,m,j=0,k=0;
  cin>>n>>m;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    j+=a[i];
  }
  for(int i=0;i<n;i++){
    if(4*m*a[i]/j>=1){
      k++;
    }
  }
  if(k>=m){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3732
n, k = map(int, input().split())
sec = [list(map(int, input().split())) for _ in range(k)]
sec.sort()

mod = 998244353

dp = [0] * n
dp[0] = 1
sum_dp = [0, 1]
for i in range(1, n):
    for l, r in sec:
        if i - l < 0:
            break
        elif i - r > 0:
            dp[i] = ((dp[i] + sum_dp[i-l+1]) % mod - sum_dp[i-r]) % mod
        else:
            dp[i] = (dp[i] + sum_dp[i-l+1]) % mod
    
    sum_dp.append((sum_dp[-1] + dp[i]) % mod)

print(dp[n-1])

Measured memory_bytes: 85804
#include<stdio.h>
int main(void){
	int x, y, a;
	while (scanf("%d%d", &x, &y) != EOF){
		if (x == 0 && y == 0){
			break;
		}
		if (x >= y){
			a = x;
			x = y;
			y = a;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A, B, C;
	rep(i, 0, N) {
		int a;
		cin >> a;
		A.push_back(a);
	}
	rep(i, 0, N) {
		int b;
		cin >> b;
		B.push_back(b);
	}
	rep(i, 0, N) {
		int c;
		cin >> c;
		C.push_back(c);
	}

	vsort(A); vsort(B); vsort(C);
	ll array_a[N];
	ll array_b[N];
	memset(array_a, 0, sizeof(array_a));
	memset(array_b, 0, sizeof(array_b));
	rep(i, 0, N) {
		ll a = A[i];
		ll b = B[i];
		array_a[i] = B.end() - upper_bound(B.begin(), B.end(), a);
		array_b[i] = C.end() - upper_bound(C.begin(), C.end(), b);
	}
	for(int i = N - 2; i >= 0; i--) {
		array_b[i] += array_b[i + 1];
	}

	ll res = 0;
	rep(i, 0, N) {
		int a = array_a[i];
		if(a != 0) res += array_b[N - a]; 
	}

	cout << res << endl;

}


Measured memory_bytes: 3192
#include <iostream>
#include <string.h>
#include <algorithm>
typedef long long ll;
using namespace std;

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
    int p=0;
	// ユークリッドの方法
	while( m > n )
	{
        m = m/2;
        p+=1;
	}
	return p;
}//gcd

int main()
{
    char s[10];
  	cin >> s;
  	for(int i=0;i<3;i++)
    {
		if(s[i] == s[i+1])
        {
          cout << "Bad";
          break;
        }else if(i == 2)
        {
          cout << "Good";
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
constexpr long long int MOD = 998244353;
long long int by2or5(const std::vector<int> digits, int p) {
	long long int result = 0;
	for (auto i = 0; i < digits.size(); ++i) {
		if (digits[i] % p == 0) result += i + 1;
	}
	return result;
}

int main() {
	int n, p; std::cin >> n >> p;
	std::string str; std::cin >> str;
	std::vector<int> digits(str.size());
	for (auto i = 0; i < str.size(); ++i) {
		digits[i] = str[i] - '0';
	}
	if (p == 2 || p == 5) {
		std::cout << by2or5(digits, p) << '\n';
	}
	else {
		std::vector<int> rests(str.size() + 1, 0);
		int sum = 0, digit = 1;
		for (int i = str.size() - 1; i >= 0; --i) {
			rests[i] = (digit * digits[i] + rests[i + 1]) % p;
			digit = 10 * digit % p;
		}
		std::vector<int> count(p + 1, 0);
		long long int result = 0;
		for (const auto r : rests) {
			result += count[r];
			++count[r];
		}
		std::cout << result << '\n';
	}
}

Measured memory_bytes: 2172
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

S = input()

N = len(S)

if N % 2 == 1:
    print("No")
else:
    flag = True
    for i in range(int(N/2)):
        a = i*2
        if not(S[a:a+2] == "hi"):
            flag = False
    if flag :
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 43376
n = int(input())
H = [int(i) for i in input().split()]
li = []
for i in range(n-1):
    if H[i] >= H[i+1]:
        li.append(1)
    else:
        li.append(0)

ans,tmp = 0,0
for i in li:
    if i == 1:
        tmp += 1
    else:
        ans = max(ans,tmp)
        tmp = 0
ans = max(ans,tmp)
print(ans)


Measured memory_bytes: 14252
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 10000005
#define LL long long
using namespace std;

char a[2] = {'C','F'},s[105],tot;

int main()
{
	scanf("%s",s);
	for (int i = 0 ; i < strlen(s) ; ++ i)
	{
		if(a[tot] == s[i])
		{
			tot ++;
		}
	}
	if (tot == 2)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int m[202020],ans;
int b[30];
vector<int>z[30];
int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>m[i];
    }
    for(int n=0;n<N;n++){
        int x;
        cin>>x;
        for(int i=0;i<30;i++){
            z[i].push_back(x&((1<<i)-1));
            // cout<<(x&((1<<i)-1))<<' ';
            if(x&(1<<i))b[i]++;
        }
        // cout<<'\n';
    }
    for(int i=0;i<30;i++)
        sort(z[i].begin(),z[i].end());
    for(int i=0;i<30;i++){
        int bit=0;
        for(int j=0;j<N;j++){
            int x=m[j];
            // x's compliment
            int c=(1<<i)-(x&((1<<i)-1));
            // number of x's compliment
            int num=z[i].end()-lower_bound(z[i].begin(),z[i].end(),c);
            // x's i-th bit on
            if(x&(1<<i))bit^=N%2;
            bit^=b[i]%2;
            bit^=num%2;
        }
        // cout<<bit<<' ';
        if(bit)ans+=(1<<i);
    }
    cout<<ans<<'\n';
    return 0;
}


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

int main()
{
  int n, k;

  while (cin >> n >> k, n || k){
    int a[100010], num;

    for (int i = 0; i < n; i++){
      cin >> num;
      if (i == 0) a[i] = num;
      else a[i] = a[i - 1] + num;
    }

    int res = 0;
    for (int i = k; i < n; i++){
      res = max(res, a[i] - a[i - k]);
    }
    cout << res << '\n';
  }
}

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


int main()
{
   string hard="...";
   int k;
   string s;
   cin>>k;
   cin>>s;
   int n=s.length();
   if(n<=k){
    cout<<s;
   }
   else{

    string p=s.substr(0,k);
    p+=hard;
    cout<<p;

   }


    return 0;
}


Measured memory_bytes: 3624
#A = list(map(int, input().split()))
a, b, c = map(int, input().split())
k = int(input())
import math

if a >= b:
  p = int(math.log(a/b,2)) +1
else:
  p = 0
  
if b*(2**p) >= c:
  q = int(math.log(b*(2**p)/c,2)) +1
else:
  q = 0
#print(p)
#print(q)

if (p + q) <= k:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	ll n;
	cin>>n;
	string c;
	cin>>c;
	int red=0;
	rep(i,n){
		if(c[i]=='R')++red;
	}
	int cnt=0;
	rep(i,red){
		if(c[i]!='R')++cnt;
	}
	cout<<cnt;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define MAX 105
using namespace std;

int h[MAX], arr[MAX];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//    #ifndef ONLINE_JUDGE
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
//    #endif
    int n;

    cin>>n;

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

    int k = 0;
    bool flag = false;
    while(true){
        flag = false;
        int f = 0;
        for(int i = 0; i < n; i++){
            if(arr[i] == h[i] && f)
                break;
            else if(arr[i] == h[i] && !f)
                continue;
            else if(arr[i] < h[i]){
                flag = true;
                f = 1;
                arr[i]++;
            }
        }
        k++;
        if(!flag)
            break;
    }

    cout<<(k-1)<<endl;

    return 0;
}


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

const int vmax=10010;
const int inf=1023456789;

int N,M;
typedef tuple<int,int,int> node;
vector<node> graph;

int par[vmax];
void init(){rep(i,vmax) par[i]=i;}
int find(int x){return (par[x]==x)?x:par[x]=find(par[x]);}
void unite(int a,int b){a=find(a),b=find(b);par[a]=b;}
bool same(int a,int b){return find(a)==find(b);}

int kruskal(){
	init();
	sort(begin(graph),end(graph));
	int res=0;
	for(auto &e:graph){
		int a,b,c;
		tie(c,a,b)=e;
		if(!same(a,b)) unite(a,b),res+=c;
	}
	return res;
}

int main(void){
	cin >> N >> M;
	rep(i,M){
		int a,b,c;
		cin >> a >> b >> c;
		graph.push_back(node(c,a,b));
	}
	cout << kruskal() << endl;
	return 0;
}

Measured memory_bytes: 2708
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

import math

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

def combination_fuc(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#dp=[[0 for i in range(N)] for j in range(N)]
#for i in range(N):
#    dp[i][0] = 1
#    dp[i][i] = 1
#for i in range(2,N):
#    for j in range(1,i):
#        dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
#for i in range(1,K+1):
#    tmp=dp[N-K+1][i]*dp[K-1][i-1]
#    if tmp > MOD:
#        print(tmp%MOD)
#    else:
#        print(tmp)

for i in range(1,K+1):
    if N-K+1 >= i:
        print((combination_fuc(N-K+1,i)*combination_fuc(K-1,i-1))%MOD)
    else:
        print(0)


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

signed main() {
    int N;
    cin >> N;

    vector<int> a(N), idx(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        idx[a[i] - 1] = i;
    }

    set<int> se;
    se.insert({-1, N});

    int ans = 0;
    for (int i = 0; i < N; i++) {
        auto it = se.lower_bound(idx[i]);
        int r = *it - idx[i];
        int l = idx[i] - *--it;
        ans += l * r * a[idx[i]];
        se.insert(idx[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n, x, t;
    cin >> n >> x >> t;
    cout << (ll)ceil((ld)n / x) * t;
}   

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    string s; cin>>s;
    int cnt =1;
    char temp = s[0];
    for(int i=0; i<n; i++){
        if(s[i]==temp) continue;
        else{temp = s[i]; cnt++;}
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    ll ans = 0;
    rep(i, N-1){
        if(A.at(i+1) < A.at(i)){
            ans += A.at(i) - A.at(i+1);
            A.at(i+1) = A.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4760
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	int h,w,i,j,x,y,a[30][30],ans=INF,tmp;
	cin >> h >> w;
	for(i=0; i<h; ++i){
		for(j=0; j<w; ++j){
			cin >> a[i][j];
		}
	}
	for(x = 0; x < h; ++x){
		for(y = 0; y < w; ++y){
			tmp = 0;
			for(i=0; i<h; ++i){
				for(j=0; j<w; ++j){
					tmp += (min(abs(i-x),abs(j-y)))*a[i][j];
				}
			}
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);CIN(W);
    V<pair<LL,LL>> vec1,vec2,vec3,vec4;
    CIN(B);CIN(C);
    vec1.pb(make_pair(C,B));
    LL ans = 0;
    REP(a,N-1){
        CIN(D);CIN(E);
        if(D-B==0){
            vec1.pb(make_pair(E,D));
        }else if(D-B==1){
            vec2.pb(make_pair(E,D));
        }else if(D-B==2){
            vec3.pb(make_pair(E,D));
        }else{
            vec4.pb(make_pair(E,D));
        }
    }
    if(vec1.empty())vec1.pb(make_pair(0,0));
    if(vec2.empty())vec2.pb(make_pair(0,0));
    if(vec3.empty())vec3.pb(make_pair(0,0));
    if(vec4.empty())vec4.pb(make_pair(0,0));
    sort(ALL(vec1));
    sort(ALL(vec2));
    sort(ALL(vec3));
    sort(ALL(vec4));
    reverse(ALL(vec1));
    reverse(ALL(vec2));
    reverse(ALL(vec3));
    reverse(ALL(vec4));
    //COUT(vec1.size());
    //COUT(vec2.size());
    //COUT(vec3.size());
    //COUT(vec4.size());
    REP(a,vec1.size()+1){
        REP(b,vec2.size()+1){
            REP(c,vec3.size()+1){
                REP(d,vec4.size()+1){
                    LL ins = 0;
                    //COUT(a*vec1.front().second+b*vec2.front().second+c*vec3.front().second+d*vec4.front().second);
                    if(a*vec1.front().second+b*vec2.front().second+c*vec3.front().second+d*vec4.front().second > W)continue;
                    REP(e,a){
                        ins+=vec1.at(e).first;
                    }
                    REP(f,b){
                        ins+=vec2.at(f).first;
                    }
                    REP(g,c){
                        ins+=vec3.at(g).first;
                    }
                    REP(h,d){
                        ins+=vec4.at(h).first;
                    }
                    ans = max(ins,ans);
                    //cout<<a*vec1.front().second+b*vec2.front().second+c*vec3.front().second+d*vec4.front().second<<" "<<ins<<endl;
                }
            }
        }
    }
    COUT(ans);

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define F first
#define S second
#define pb push_back
#define bit __builtin_popcount
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mkp make_pair
#define ffs fflush(stdout)

using namespace std;
using namespace __gnu_pbds;

//order_of_key(k) : Number of items strictly smaller than k
//find_by_order(k) : K-th element in a set (counting from 0)

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef vector <int> lnum;
typedef pair <int, int> pii;

const int N = (int)1e6 + 5;
const int MOD = (int)1e9 + 7;
const int inf = (int)1e18;
const int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
const ld eps = 1e9 - 7;
const int pp[] = {29, 31, 53, 67, 71};
const double pi = acos(-1.0);

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

vector <int> g[N];
int c[N];
int ans = 1;
map <pair <int, int>, int> mp;

void dfs(int v, int p = 0, int pc = 0) {
  int cur = 1;
  for (auto to : g[v]) {
    if (to == p)
      continue;
    if (cur == pc)
      ++cur;
    c[mp[mkp(to, v)]] = cur;
    ans = max(ans, cur);
    ++cur;
  }
  for (auto to : g[v]) {
    if (to != p)
      dfs(to, v, c[mp[mkp(v, to)]]);
  }
}

signed main() {
  ios_base :: sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    mp[mkp(a, b)] = i + 1;
    mp[mkp(b, a)] = i + 1;
    g[a].pb(b);
    g[b].pb(a);
  }
  dfs(1);
  cout << ans << "\n";
  for (int i = 1; i <= n - 1; ++i)
    cout << c[i] << "\n";
  return 0;
}


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

long long A,B,mid,sum1,sum2;
long long q;
priority_queue<long long,vector<long long> > q1;
priority_queue<long long,vector<long long>,greater<long long> > q2;

int main(){
	cin>>q;
	long long n;
	for(int i=0;i<q;i++){
		cin>>n;
		if(i==0){
		    long long a,b;
			cin>>a>>b;
			B+=b;
			mid=a;
			continue;
		}
		if(n==1){
			long long a,b;
			cin>>a>>b;
			B+=b;
			if(a>mid){
				q2.push(a);
				sum2+=a;
			}else{
				q1.push(a);
				sum1+=a;
			}
			while(q2.size()>q1.size()+1){
				long long m=q2.top();
				q2.pop();
				sum2-=m;
				q1.push(mid);
				sum1+=mid;
				mid=m;
			}
			while(q1.size()>q2.size()){
				long long m=q1.top();
				q1.pop();
				sum1-=m;
				q2.push(mid);
				sum2+=mid;
				mid=m;
			}
		}else if(n==2){
			long long sz1=q1.size(),sz2=q2.size();
			cout<<mid<<" "<<sz1*mid-sum1+sum2-sz2*mid+B<<endl;
		}
    }
	return 0;
}	

Measured memory_bytes: 4936
#include<stdio.h>
#include<stdlib.h>

int min(int a, int b) {
    return a < b ? a : b;
}

int main(void){
    int N, K;
    scanf("%d", &N);
    scanf("%d", &K);

    int d = 0;
    for(int i=0;i<N;i++) {
        int x;
        scanf("%d", &x);
        d += 2*min(x, abs(x-K));
    }

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

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n, a, b, c; cin >> n >> a >> b >> c;
    vector <string> s(n + 1);
    FOR(i, 1, n) 
        cin >> s[i];
    vector <char> ans;
    FOR(i, 1, n) {
        char cx = s[i][0], cy = s[i][1];
        int *x, *y;
        if (s[i][0] == 'A') x = &a;
        else x = &b;
        if (s[i][1] == 'B') y = &b;
        else y = &c;
        // cerr << *x << ' ' << *y << endl;
        if (*x == 0 && *y == 0) break;
        else if (*x > *y) {
            ans.pb(cy);
            (*x)--, (*y)++;
        }
        else if (i == n || *y > *x) {
            ans.pb(cx);
            (*y)--, (*x)++;
        }
        else {
            if (s[i + 1][0] == cy || s[i + 1][1] == cy){
                ans.pb(cy);
                (*x)--, (*y)++;
            }
            else {
                ans.pb(cx);
                (*y)--, (*x)++;
            }
        }
    }
    if (sz(ans) != n) cout << "No\n";
    else {
        cout << "Yes\n";
        for (char e : ans) cout << e << endl;
    }
}

Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()

int main()
{
    ll l, r;
    cin >> l >> r;
    ll sa = r - l;
    if (sa > 2400)
    {
        cout << 0 << endl;
    }
    else
    {
        ll ans = 2500;
        for (ll i = l; i <= r - 1; i++)
        {
            for (ll j = i + 1; j <= r; j++)
            {
                ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
            }
        }
        cout << ans << endl;
    }
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
signed main(){
    string s,a;
    cin >> s;
    int n = s.size();
    int cnt = 0,maxv = 0;
    rep(i,n){
        if((s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')){
            cnt++;
        }
        else{
            maxv = max(cnt,maxv);
            cnt = 0;
        }
    }   
    cout << max(maxv,cnt) << '\n';
    return 0;    
}


Measured memory_bytes: 256
using System;

namespace yomikatawakaran
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            char[] ch = str.ToCharArray();

            for(int i =0; i < str.Length; i++)
            {
                if(ch[i] == '1')
                {
                    ch[i] = '9';
                }
                else
                {
                    ch[i] = '1';
                }
            }
            for (int i = 0; i < str.Length; i++)
            {
                Console.Write(ch[i]);
            }


        }
    }
}


Measured memory_bytes: 11092
def gcd(a, b):
    while b != 0 :
        t = a % b
        a = b
        b = t
    return a
        
sum = 0
N=int(input(""))
for a in range(1, N + 1):
    for b in range(1, N + 1):
        x = gcd(a, b)
        if x == 1:
            sum = sum + N
        else:
            for c in range(1, N + 1):
                sum = sum + gcd(x, c)
print(sum)

Measured memory_bytes: 9168
n,c,k = gets.split.map(&:to_i)
t = n.times.map{gets.to_i}.sort
ans = 0
d = 0
s = t[0]
for i in 0..n-1
    if t[i] <= s+k && d < c
        d += 1
    else
        ans += 1
        d = 1
        s = t[i]
    end
end
puts ans+1

Measured memory_bytes: 4216
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	int x;cin>>x;
	string s;cin>>s;
	if(x<3200){
		cout<<"red"<<endl;
	}else{
		cout<<s<<endl;
	}






























	
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; i+j <= n; j++ {
			k := n - i - j
			if i*10000+j*5000+k*1000 == y && i+j+k == n {
				fmt.Printf("%d %d %d", i, j, k)
				return
			}
		}
	}
	fmt.Println("-1 -1 -1")
}


Measured memory_bytes: 512
Var     x,a,b: Longint;

Procedure       Nhap;
Begin
Readln(x,a,b);
End;

Procedure       XuLy;
Begin
If b<=a Then
        Begin
        Writeln('delicious');
        Exit;
        End;
If (b-a)>x Then
        Begin
        Writeln('dangerous');
        Exit;
        End;
If (b-a)<=x Then
        Begin
        Writeln('safe');
        Exit;
        End;
End;

Begin
Nhap;
XuLy;
End.



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,a[10010][10010],t=0;
bool flag[10010],fl=0;
bool judge()
{
	for(int i=1;i<=n;++i)
		if(a[i][0]!=n)
			return 0;
	return 1;
}

int main()
{	cin>>n;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<n;++j)
			scanf("%d",&a[i][j]);
		a[i][0]=1;
	}
	while(1)
	{
		if(judge())
		{
			printf("%d\n",t);
			return 0;
		}
		fl=0;
		memset(flag,0,sizeof(flag));
		++t;
		for(int i=1;i<=n;++i)
		{
			if(flag[i] || a[i][0]==n) 
				continue;
			int x=a[i][a[i][0]],y=a[x][a[x][0]];
			if(!flag[x] && !flag[i] && i==y)
			{
				fl=1;
				flag[x]=1;flag[i]=1;
				++a[i][0];++a[x][0];
			}
		}
		if(!fl)
		{
			printf("-1\n");
			return 0;
		}
	}
	return 0;
} 

Measured memory_bytes: 39552
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define A 1000

int main(void){
  int n,i,temp,j,k;
  int a[N];

  scanf("%d",&n);
  if(n<0||n>N)exit(1);  
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(k=0;k<n;k++){
    if(k!=n-1) printf("%d ",a[k]);
    else printf("%d\n",a[k]);
  }
  for(j=1;j<n;j++){
    temp=a[j];
    i=j-1;
    while(i>=0 && a[i] > temp){
      a[i+1]=a[i];
      i=i-1;
    }
    a[i+1]=temp;
    for(k=0;k<n;k++){
      if(k!=n-1) printf("%d ",a[k]);
      else printf("%d\n",a[k]);
    }
  }
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
typedef long long ll;

int c[maxn];
ll p[maxn];
int n;

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", c+i);
		p[i] = p[i-1] + c[i];
	}
	
	ll res = (ll)1e18;
	for(int i = 1; i < n; ++i) {
		ll l = p[i];
		ll r = p[n] - p[i];
		ll nw = abs(l - r);
		res = min(res, nw);
	}
	printf("%lld\n", res);
}


Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main() {
    string s[2];
    cin >> s[0] >> s[1];
    cout << (s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[0][2] == s[1][0] ? "YES" : "NO") << endl;
 
    return 0;
}

Measured memory_bytes: 256