akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    int w, h, n;
    cin >> w >> h >> n;
    int x1 = 0, y1 = 0, x2 = w, y2 = h;
    forn (i, n) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1)
            x1 = max(x1, x);
        else if (a == 2)
            x2 = min(x2, x);
        else if (a == 3)
            y1 = max(y1, y);
        else
            y2 = min(y2, y);
    }
    cout << max(0, x2 - x1) * max(0, y2 - y1) << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

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

using namespace std;

int main(){
	string a,b;
	cin>>a>>b;
	int x,y;
	cin>>x>>y;
	string u;
	cin>>u;
	if(u==a)
		x--;
	else
		y--;
	cout<<x<<" "<<y<<"\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int[] taste = new int[n];
        int eat=200;
        int pai=0;

        for (int i = 0; i < n; i++) {
            taste[i] = l+i;
            pai+=l+i;
            if (Math.abs(taste[i]) < Math.abs(eat)) {
                eat = taste[i];
            }
        }

        System.out.println(pai - eat);
    }
}

Measured memory_bytes: 23252
class SegTree:  # 0-index !!!
    def __init__(self, seq, fx, ex):
        self.n = len(seq)
        self.fx = fx
        self.ex = ex
        self.size = 1<<(self.n - 1).bit_length()
        self.tree = [ex] * (self.size * 2)
        # build
        for i, x in enumerate(seq, start=self.size):
            self.tree[i] = x
        for i in reversed(range(1, self.size)):
            self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, i, x):
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])

    def query(self, l, r):
        tmp_l = self.ex
        tmp_r = self.ex
        l += self.size
        r += self.size
        while l < r:
            if l & 1:
                tmp_l = self.fx(tmp_l, self.tree[l])
                l += 1
            if r & 1:
                tmp_r = self.fx(self.tree[r - 1], tmp_r)  # 交換法則を仮定しない(順序大事に)
            l >>= 1
            r >>= 1
        return self.fx(tmp_l, tmp_r)

# ---------------------- #

n, k = (int(x) for x in input().split())
P = list(int(x) for x in input().split())

min_seg = SegTree(P, fx=min, ex=10**18)
max_seg = SegTree(P, fx=max, ex=0)

asc_count = [1] * n
for i in range(1, n):
    if P[i] > P[i - 1]:
        asc_count[i] = asc_count[i - 1] + 1

ans = 1
no_count = 0
if asc_count[k - 1] >= k:
    no_count += 1
for i in range(1, n - k + 1):
    if P[i - 1] != min_seg.query(i - 1, i + k - 1) or P[i + k - 1] != max_seg.query(i, i + k):
        ans += 1
        if asc_count[i + k - 1] >= k:
            no_count += 1

print(ans - max(no_count - 1, 0))


Measured memory_bytes: 103684
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    N = read_int()
    A = inp()
    for _ in range(N):
        print('-' if solve(inp(), A) < 0 else '+')


def solve(A, B):
    i = 0
    j = 0
    N = len(A)
    M = len(B)
    while i < N and j < M:
        c = A[i]
        d = B[i]
        if '0' <= c <= '9':
            if '0' <= d <= '9':
                ii = i + 1
                while ii < N and '0' <= A[ii] <= '9':
                    ii += 1
                jj = j + 1
                while jj < M and '0' <= B[jj] <= '9':
                    jj += 1
                a = int(A[i : ii])
                b = int(B[j : jj])
                if a != b:
                    return a - b
                i = ii
                j = jj
            else:
                return -1
        else:
            if '0' <= d <= '9':
                return 1
            if c != d:
                return ord(c) - ord(d)
            i += 1
            j += 1

    if i < N:
        return 1
    if j < M:
        return -1
    return 0


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



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

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

  map<int, int> cnt;
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= 100; j++) {
      for (int k = 1; k <= 100; k++) {
        int X = pow(i, 2) + pow(j, 2) + pow(k, 2) + (i * j) + (j * k) + (i * k);
        if (cnt.count(X)) {
          cnt.at(X)++;
        } else {
          cnt[X] = 1;
        }
      }
    }
  }

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

Measured memory_bytes: 5476
#include <bits/stdc++.h>
#define optimize ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 2000000020LL
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define POS(n, x) (lower_bound(ALL(n), x) - (n).begin())
#define ll long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define PB push_back
#define EB emplace_back
#define MOD 1000000007
#define PRIME 101 
#define MAXN 200020
#define MAXL 23
#define endl '\n'

using namespace std;

// (1 + sqrt(5)) / 2
const ld GOLDEN_RATIO = 1.6180339887498949025257388711906969547271728515625;
const ld PI = 2.0 * acos(0.0);
const int BLOCK = 333;

int dp[MAXN], peso[MAXN], N;

int solve(int i)
{
	if(dp[i] != -1) return dp[i];
	if(i == N) return dp[i] = 0;

	dp[i] = abs(peso[i] - peso[i + 1]) + solve(i + 1);

	if(i + 1 < N) dp[i] = min(dp[i], abs(peso[i] - peso[i + 2]) + solve(i + 2));

	return dp[i];
}

int main(int argc, char const *argv[])
{
	optimize;
	
	memset(dp, -1, sizeof dp);

	cin >> N;

	for(int i = 1; i <= N; i++)
		cin >> peso[i];

	cout << solve(1) << endl;

	return 0;
}

Measured memory_bytes: 10988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n, m, k; cin >> n >> m >> k;
    bool ok = false;
    eFOR(i, 0, n)eFOR(j, 0, m) {
        int sum = 0;
        sum += i * m;
        sum += j * n;
        sum -= i * j * 2;
        ok |= sum == k;
    }
    cout << (ok ? "Yes\n" : "No\n");
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = nextInt()
    val S = Array(N) { next() }
    val Ch = Array(N) { IntArray(26) }
    val Co = IntArray(26)
    S.forEachIndexed { index, s ->
        s.forEach { c ->
            Ch[index][c - 'a'] += 1
        }
    }
    for (n in Co.indices) {
        var min = Int.MAX_VALUE
        for (m in Ch.indices)
            min = Math.min(min, Ch[m][n])
        Co[n] = min
    }
    val ans = mutableListOf<String>()
    Co.forEachIndexed { index, n ->
       if (n > 0) ans.add(("" + ('a' + index)).repeat(n))
    }
    println(ans.joinToString(""))
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 37820
#include<stdio.h>
#include<string.h>
#define N 101

int main(void)
{
  int i,n,j,k=0,l;
  char p[N];
  

  while(scanf("%s",p)!=EOF)
    {

  while(k<strlen(p))
    {
      
      if(p[k]=='@')
	{
	  for(l=1;l<=p[k+1]-48;l++)
	    {
	      printf("%c",p[k+2]);
	    }
	  k=k+3;
	}
      else
	{
	  printf("%c",p[k]);
	  k++;
	}
    }
  k=0;
    
  printf("\n");
    }	  
	  
	     

  
  
    return 0;
}

Measured memory_bytes: 524
def main():
  n = int(input())
  a = list(map(int, input().split()))
  if 0 in a:
    print(0)
    return
  
  ans = 1
  for i in a:
    ans *= i
    if ans > (10 ** 18):
      print(-1)
      return
  print(ans)
  
main()


Measured memory_bytes: 21584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int X;
    cin >> X;
    
    rep(i, 720){
        if (X * (i + 1) % 360 == 0){
            cout << (i + 1);
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3632
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

fn main() {
    input! {
        n: usize,
        s: String,
    }
    let sc = s.chars().collect::<Vec<char>>();
    let mut ss = vec!['S'; n];
    let mut sw = vec!['S'; n];
    sw[1] = 'W';
    let mut ws = vec!['S'; n];
    ws[0] = 'W';
    let mut ww = vec!['S'; n];
    ww[0] = 'W';
    ww[1] = 'W';

    for i in 1..n - 1 {
        ss[i + 1] = forward(i, i - 1, &sc, &ss);
        sw[i + 1] = forward(i, i - 1, &sc, &sw);
        ws[i + 1] = forward(i, i - 1, &sc, &ws);
        ww[i + 1] = forward(i, i - 1, &sc, &ww);
    }
    let mut n = n - 1;

    if forward(n, n - 1, &sc, &ss) == ss[0] && forward(0, 1, &sc, &ss) == ss[n] {
        println!("{}", ss.iter().collect::<String>());
        return;
    }
    if forward(n, n - 1, &sc, &sw) == sw[0] && forward(0, 1, &sc, &sw) == sw[n] {
        println!("{}", sw.iter().collect::<String>());
        return;
    }
    if forward(n, n - 1, &sc, &ws) == ws[0] && forward(0, 1, &sc, &ws) == ws[n] {
        println!("{}", ws.iter().collect::<String>());
        return;
    }
    if forward(n, n - 1, &sc, &ww) == ww[0] && forward(0, 1, &sc, &ww) == ww[n] {
        println!("{}", ww.iter().collect::<String>());
        return;
    }
    println!("-1")
}

fn forward(cn: usize, pn: usize, s: &Vec<char>, v: &Vec<char>) -> char {
    match s[cn] {
        'o' => match v[cn] {
            'S' => match v[pn] {
                'S' => 'S',
                'W' => 'W',
                _ => ' ',
            },
            'W' => match v[pn] {
                'S' => 'W',
                'W' => 'S',
                _ => ' ',
            },
            _ => ' ',
        },
        'x' => match v[cn] {
            'S' => match v[pn] {
                'S' => 'W',
                'W' => 'S',
                _ => ' ',
            },
            'W' => match v[pn] {
                'S' => 'S',
                'W' => 'W',
                _ => ' ',
            },
            _ => ' ',
        },
        _ => ' ',
    }
}


Measured memory_bytes: 4176
/*
    Code written by Talant I.D.
*/
   
#include <bits/stdc++.h>
   
using namespace std;
   
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
   
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353

inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}

bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2) 
		if(n % i == 0) return false;
	return true;
}

int main(){ 
    do_not_disturb
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //freopen("milkvisits.in", "r", stdin);
    //freopen("milkvisits.out", "w", stdout);
	int n, i;
	cin >> n;
	vector <int> v(n), dp(n);
	for(i = 0; i < n; i++){
		cin >> v[i];
	}
	if(n == 1){
		cout << 0;
		return 0;
	}
	dp[0] = 0;
	dp[1] = abs(v[0]-v[1]);
	for(i = 2; i < n; i++){
		dp[i] = min(abs(v[i]-v[i-1])+dp[i-1], abs(v[i]-v[i-2])+dp[i-2]);
	}
	cout << dp[n-1];
    
    return 0;
} // What is to be written here?


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		List<List<Integer>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int x = Integer.parseInt(sa[0]);
			int y = Integer.parseInt(sa[1]);
			list.get(x).add(y);
			list.get(y).add(x);
		}
		br.close();

		int use = 2 * (n - 1 - m);
		if (use == 0) {
			System.out.println(0);
		} else if (use > n) {
			System.out.println("Impossible");
		} else {
			long ans = 0;
			boolean[] used = new boolean[n];
			boolean[] visit = new boolean[n];
			for (int i = 0; i < n; i++) {
				if (!visit[i]) {
					int min = Integer.MAX_VALUE;
					int idx = -1;
					Queue<Integer> que = new ArrayDeque<>();
					que.add(i);
					visit[i] = true;
					while (!que.isEmpty()) {
						int cur = que.poll();
						if (a[cur] < min) {
							min = a[cur];
							idx = cur;
						}
						for (int next : list.get(cur)) {
							if (!visit[next]) {
								que.add(next);
								visit[next] = true;
							}
						}
					}
					used[idx] = true;
					ans += min;
				}
			}
			PriorityQueue<Integer> que = new PriorityQueue<>();
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				if (used[i]) {
					cnt++;
				} else {
					que.add(a[i]);
				}
			}
			for (int i = 0; i < use - cnt; i++) {
				ans += que.poll();
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 77932
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vector<int> x(N),y(N);
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i];
    }

    map<pint,int> cnt;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j) continue;
            int dx=x[i]-x[j];
            int dy=y[i]-y[j];
            cnt[pint(dx,dy)]++;
        }
    }
    int ans=0;
    for(auto x:cnt){
        ans=max(ans,x.second);
    }
    cout<<N-ans<<endl;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

const long long MOD=1e9+7;

int n,a,b;

long long moe(long long a,long long b)
{
    if (b==0) return 1;
    if (b%2==0) return moe((a*a)%MOD,b/2);
    return (a*moe((a*a)%MOD,b/2))%MOD;
}

long long nCk(long long n,long long k)
{
    long long t=1;
    if (k>n-k) k=n-k;
    for (int i=0;i<k;++i)
    {
        t=(t*(n-i))%MOD;
        t=(t*moe(i+1,MOD-2))%MOD;
    }
    return t;
}

int main()
{
    scanf("%d %d %d",&n,&a,&b);
    long long k=moe(2,n);
    long long x=nCk(n,a),y=nCk(n,b);
    long long kq=(k-x-y-1+MOD*MOD)%MOD;
    cout<<kq;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,q;
	cin>>n>>q;
	vector< vector<int> >A(n);
	while(q--){
		int i,t;
		cin>>i>>t;
		if(i==0){
			int x;
			cin>>x;
			A[t].push_back(x);
		}
		else if(i==1){
			if(!A[t].empty()){
				for(int j=0; j<A[t].size()-1; j++){
					cout<<A[t][j]<<" ";
				}
				cout<<*(A[t].end()-1)<<endl;
			}
			else	cout<<endl;
		}
		else if(i==2){
			A[t].clear();
		}
	}
	return 0;
}


Measured memory_bytes: 5792
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
int main() {
    long long n,k;
    cin>>n>>k;
    ll a[n],p1=1,p2;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=k;i<n;i++){
        if(a[i-k]<a[i]) cout<<"Yes";
        else cout<<"No";
        cout<<"\n";
    }
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    map<int,int> mp;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        if(a/400<8) mp[a/400]++;
        else mp[8]++;
    }

    if(mp[8] == N){
        cout << 1 << " " << mp[8] << endl;
    } else {
        cout << mp.size()-1 << " " << mp.size()-1+mp[8] << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  int v[4][13] = {0};
  rep(i, n) {
    string s;
    int num;
    cin >> s >> num;
    if (s == "S")
      v[0][num - 1] = 1;
    else if (s == "H")
      v[1][num - 1] = 1;
    else if (s == "C")
      v[2][num - 1] = 1;
    else if (s == "D")
      v[3][num - 1] = 1;
  }
  rep(j, 13) if (v[0][j] == 0) cout << "S " << j + 1 << endl;
  rep(j, 13) if (v[1][j] == 0) cout << "H " << j + 1 << endl;
  rep(j, 13) if (v[2][j] == 0) cout << "C " << j + 1 << endl;
  rep(j, 13) if (v[3][j] == 0) cout << "D " << j + 1 << endl;
  return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int n, c;
    cin >> n >> c;
    vector<vector<bool>> ct(c, vector<bool>(200010, false));
    // bool ct[30][100010];
    for (int i = 0; i < n; i++) {
        int s, t, chnl;
        cin >> s >> t >> chnl;
        s *= 2; s -= 1;
        t *= 2; chnl--;
        fill(ct[chnl].begin() + s, ct[chnl].begin() + t, true);
        // memset(ct[chnl] + s, true, sizeof(bool) * (t - s));
    }

    int mx = 0;
    for (int i = 0; i <= 200000; i++) {
        int cnt = 0;
        for (int j = 0; j < c; j++) {
            if (ct[j][i]) cnt++;
        }
        mx = max(cnt, mx);
    }
    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[2]-a[0]<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
using namespace std;
typedef vector<int>V;
int main(void){
	int n;
	int i;
	int box[100001];
	int cnt;
	V v;
	int MAX=-1;
	cin>>n;
	for(i=0;i<n;i++)	cin>>box[i];
	box[n]=box[n-1];
	cnt=1;
	for(i=0;i<n;i++){
		if(box[i]!=box[i+1])	cnt++;
		else{
			 v.PB(cnt);
			 cnt=1;
		}
	}
	//for(i=0;i<v.size();i++)	cout<<v[i]<<endl;
	if(v.size()<=1){
		MAX=max(MAX,v[0]);
	}
	else{
		MAX=max(MAX,v[0]+v[1]);
		MAX=max(MAX,v[v.size()-1]+v[v.size()-2]);
		for(i=1;i<v.size()-1;i++){
			MAX=max(MAX,v[i-1]+v[i]+v[i+1]);
		}
	}
	cout<<MAX<<endl;		
	return 0;
}


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

signed main(){
  int K;
  cin>>K;
  string S;
  cin>>S;
  int SS=S.size();
  if(K>=SS){
    cout<<S<<endl;
    return 0;
  }
  S=S.substr(0,K);
  cout<<S<<"..."<<endl;
}

Measured memory_bytes: 3632
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int N;
    cin >> N;

    int h[N];
    int x[N];
    int y[N];

    int index_base;

    for( int ni = 0 ; ni < N ; ni++ ){
        cin >> x[ni];
        cin >> y[ni];
        cin >> h[ni];
        if(h[ni]>0) index_base = ni;
    }

    int Cx;
    int Cy;
    int H;
    int flag;
    for( Cx = 0 ; Cx <= 100 ; Cx++ ){
        for( Cy = 0 ; Cy <= 100 ; Cy++ ){
            flag = 1;
            H = h[index_base] + abs(x[index_base]-Cx) + abs(y[index_base]-Cy);
            //cout << "Cx Cy" << Cx << " " << Cy << endl;
            //cout << "H " << H << endl;
            for( int ni = 0 ; ni < N ; ni++ ){
                if(h[ni]==0){
                    if(H - abs(x[ni]-Cx) - abs(y[ni]-Cy) > 0){
                        flag = 0;
                        break;
                    } 
                }else{
                    if(H != h[ni] + abs(x[ni]-Cx) + abs(y[ni]-Cy)){
                        flag = 0;
                        break;
                    } 
                }
            }
            if(flag==1) break;
        }
        if(flag==1) break;
    }
    cout << Cx;
    cout << " ";
    cout << Cy;
    cout << " ";
    cout << H;


}

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

/**
|||||||||||||       |||||     |||||    ||||||||||
||||||||||||||      |||||     |||||  |||||
|||||     |||||     |||||     |||||  |||||
||||||||||||||||    |||||||||||||||    ||||||||||
|||||||||||||||||   |||||||||||||||           |||||
|||||        |||||  |||||     |||||           |||||
|||||         ||||| |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int>m;
    vector<int>h;
    for(int i=0;i<n+1;i++){
        int t;
        cin>>t;
        m.push_back(t);
    }
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        h.push_back(t);
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        if(h[i]>=m[i]){
            ans+=m[i];
            int nm=m[i+1];
            m[i+1]=max(0,m[i+1]-(h[i]-m[i]));
            ans+=(m[i+1]==0)?nm:(h[i]-m[i]);
            m[i]=0;
        }
        else{
            ans+=h[i];
            m[i]-=h[i];
        }
    }
    cout <<ans << endl;
    return 0;
}


Measured memory_bytes: 1400
/*
 * Good Luck
 */
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;
    cout << !n;
}

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

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h, n;
    cin >> h >> n;
    
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        h -= a;
    }
    if(h <= 0){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int[] a = new int[n];
			int ret = Integer.MAX_VALUE;
			
			for(int i=0;i<n;i++) {
				a[i] = sc.nextInt();
			}
			
			for(int i=-100;i<=100;i++) {
				int cost = 0;
				for(int j=0;j<n;j++) {
					cost += (a[j]-i)*(a[j]-i);
				}
				
				ret = Math.min(ret, cost);
			}
			
			System.out.println(ret);
	    }
		
	}
	


Measured memory_bytes: 35988
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define N	    100001
#define rep(i,a,b)  for(int i=a;i<b;i++)
typedef long long ll;
void solve(){
	int a, b, c, x, y;
	cin>>a>>b>>c>>x>>y;
	int ans = 0;
	int n = min(x, y);
	ans = min(n * 2 * c, (a + b) * n);
	if(x == n) {
		y = y - n;
		ans += min(2 * c * y, y * b);
	}
	else {
		x = x - n;
		ans += min(2 * c * x, x * a);
	}
	cout<<ans<<endl;
}
int main() {
	int t;
//	cin>>t;
	t = 1;
	while(t--){
		solve();
	}
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<int> v(n);
  rep(i, 0, n) cin >> v.at(i);
  vector<int> c(n);
  rep(i, 0, n) cin >> c.at(i);
  
  int sum = 0;
  rep(i, 0, n)
    sum += max(v.at(i)-c.at(i), 0);
  
  cout << sum << "\n";

}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int N = sc.nextInt();
		int M = sc.nextInt();

		if(N == M) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}

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

typedef pair<int64_t, int64_t> P;
const int64_t INF = 1e18;

vector<int64_t> dijkstra(int N, int s, vector<P> edges[]){
    vector<int64_t> dist(N, INF);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, s});
    while(que.size()){
        auto p = que.top(); que.pop();
        int i = p.second;
        int64_t d = p.first;
        if(d > dist[i]) continue;
        for(auto& e : edges[i]){
            int j = e.first;
            int64_t d2 = d + e.second;
            if(d2 < dist[j]){
                dist[j] = d2;
                que.push({d2, j});
            }
        }
    }
    return dist;
}

int main(){
    int N, M, S;
    cin >> N >> M >> S;
    vector<vector<int>> edges[50];
    for(int i=0; i<M; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--;
        edges[a].push_back({b, c, d});
        edges[b].push_back({a, c, d});
    }
    vector<int> C(N), D(N);
    for(int i=0; i<N; i++) cin >> C[i] >> D[i];

    int T = 2500;
    auto encode = [&](int i, int j){ return i*T+j; };

    vector<P> es[T*50];
    for(int i=0; i<N; i++){
        for(int c=0; c<T; c++){
            int now = encode(i, c);
            es[now].emplace_back(encode(i, min(T-1, c+C[i])), D[i]);
            for(auto& e : edges[i]){
                int j = e[0], pay = e[1], tm = e[2];
                if(c >= pay) es[now].emplace_back(encode(j, c-pay), tm);
            }
        }
    }

    auto dist = dijkstra(T*N, encode(0, min(S, T-1)), es);
    for(int i=1; i<N; i++){
        int64_t ans = 1e18;
        for(int c=0; c<T; c++) ans = min(ans, dist[encode(i, c)]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 23684
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a%2==0||b%2==0||c%2==0){
		printf("0\n");
	}else{
		printf("%lld\n",min((long long)a*b,min((long long)a*c,(long long)b*c)));
	}
}

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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair
#define X first
#define Y second

const int MAXN = 300;
int a[MAXN];
int main()
{
    ios_base::sync_with_stdio(false);

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int n;
    cin >> n;
    n = 2 * n;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for (int i=0;i<n;i+=2)
    {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define rep(i,n) for(int i=0;i<(n);++i)

#define out(v) cout<<v<<"\n"
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int H, W; cin >> H >> W;

  vector<int> row[H], column[W];
  rep(i, H) row[i].push_back(-1);
  rep(i, W) column[i].push_back(-1);

  char board[H][W];
  rep(i, H) rep(j, W) {
    char c; cin >> c;
    board[i][j] = c;
    if (c == '#') {
      row[i].push_back(j);
      column[j].push_back(i);
    }
  }
  rep(i, H) row[i].push_back(W);
  rep(i, W) column[i].push_back(H);

  int ans = 0;
  rep(i, H) rep(j, W) {
    if (board[i][j] == '#')
      continue;
    auto it = lower_bound(all(row[i]), j);
    auto it2 = lower_bound(all(column[j]), i);
    int n = *it - *(it-1) - 1,
        m = *it2 - *(it2-1) - 1;
    chmax(ans, n + m - 1);
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 38400
#include <stdio.h>

int main()
{
  int a, b, c;
  scanf("%d\n", &a);
  scanf("%d\n", &b);
  scanf("%d\n", &c);
  if (a < b && b <c) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}


Measured memory_bytes: 2076
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int d,t,s;
    cin >> d >> t >> s;
    if(d <= s*t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3632
def get_subsets(fullset):
  listrep = list(fullset)
  subsets = []
  for i in range(2**len(listrep)):
    subset = []
    for k in range(len(listrep)):            
      if i & 1<<k:
        subset.append(listrep[k])
    subsets.append(subset)        
  return subsets

n, m = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(m)]
ps = list(map(int, input().split()))

ans = 0
subsets = get_subsets(set(range(1, n+1)))
for ss in subsets:
    ss = set(ss)
    b = False
    for idx in range(m):
        pat = set(mat[idx][1:])
        if len(pat&ss)%2 != ps[idx]:
            b = True
            break
    if not b:
       ans += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = [int(input()) for _ in range(n)]
m = max(a)

if a.count(m) > 1:
    for _ in range(n):
        print(m)
else:
    for i in range(n):
        if a[i] == m:
            a[i] = 0
            ma = max(a)
            print(ma)
        else:
            print(m)


Measured memory_bytes: 12532
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,ll> P;

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

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

const ll mod = 1000000007;

ll mpow(ll x, ll n) {
	ll ans = 1; x %= mod;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}

ll inv_mod(ll a) { return mpow(a, mod - 2); }

class Factorial {
private:
	vector<ll> fac;
	vector<ll> ifac;
public:

	Factorial(ll N) {
		fac.push_back(1);
		for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);
		ifac.resize(N + 1);
		ifac[N] = inv_mod(fac[N]);
		for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;
	}

	ll fact(ll a) { return fac[a]; }
	ll ifact(ll a) { return ifac[a]; }

	ll cmb(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		ll tmp = ifact(a - b) * ifact(b) % mod;
		return tmp * fac[a] % mod;
	}
	ll per(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		return fac[a] * ifac[a - b] % mod;
	}
};

class modint {
	static constexpr std::int_fast64_t Modulus = 1e9 + 7;
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr operator u64() const { return a; }
};


int main() {
	ll n;
	cin >> n;
	vector<ll> as(n), bs(n);
	rep(i, n) cin >> as[i];
	rep(i, n) cin >> bs[i];
	int j = 0;
	for (int i = 0; i < n; i++) {
		int error = 0;
		bool ok = false;
		for (; j < n; j++) {
			if (as[j] != bs[i] && as[i] != bs[j]) {
				swap(bs[i], bs[j]);
				ok = true;
				break;
			}
			error++;
			if (error == n) {
				cout << "No" << endl;
				return 0;
			}
		}
		if (ok) continue;
		j = 0;
		for (; j < n; j++) {
			if (as[j] != bs[i] && as[i] != bs[j]) {
				swap(bs[i], bs[j]);
				break;
			}
			error++;
			if (error == n) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	rep(i, n) {
		cout << bs[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 6420
#include<stdio.h>
#include<stdlib.h>
int main ()
{
   int a,b,c,t,p;
   scanf("%d %d %d",&a,&b,&c);
   t=a;
   a=b;
   b=t;
   p=a;
   a=c;
   c=p;
   printf("%d %d %d",a,b,c);
   return 0;
 } 

Measured memory_bytes: 1696
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for i in range(q)]

rui=[0]*(n+1)
tmp=0
for i in range(n):
  if s[i-1] == 'A' and s[i] == 'C':
    tmp += 1
  rui[i] = tmp

for l,r in lr:
  print(rui[r-1] - rui[l-1])


Measured memory_bytes: 29620
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  map<int,int> mp;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    mp[tmp]++;
  }

  int cnt = 0;
  for(auto itr = mp.begin() ; itr!=mp.end() ; itr++){
    //cout << itr->first << " " << itr->second << endl;
    if(itr->first > itr->second){
      cnt += itr->second;
    }
    else{
      cnt += itr->second - itr->first;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>
int main(void) {
    int H, W, i, j;
    while(1) {
        scanf("%d%d", &H, &W);
        if(W == 0 && H == 0) break;
        for(i = 0; i < H; i++) {
            for(j = 0; j < W; j++) {
                putchar('#');
            }
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}


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

int main()
{
    int h, w;
    cin >> h >> w;

    int a[h][w];
    for(int i = 0; i < h ; i++) {
        int count = 0;
        char s[w];
        cin >> s;
        for (int j = 0 ; j < w ; j++) {
            if (s[j] == '.'){
                count = 0;
                if (a[i-1][j-1] == -1 && i > 0 && j > 0) {
                    count++;
                }
                if (a[i-1][j] == -1 && i > 0) {
                    count++;
                }
                if (a[i-1][j+1] == -1 && i > 0 && j <  w - 1) {
                    count++;
                }
                if (a[i][j-1] == -1 && j > 0) {
                    count++;
                }
                a[i][j] = count;
            } else if (s[j] == '#') {
                if (a[i-1][j-1] != -1 && i > 0 && j > 0) {
                    a[i-1][j-1]++;
                }
                if (a[i-1][j] != -1 && i > 0) {
                    a[i-1][j]++;
                }
                if (a[i-1][j+1] != -1 && i > 0 && j <  w - 1) {
                    a[i-1][j+1]++;
                }
                if (a[i][j-1] != -1 && j > 0) {
                    a[i][j-1]++;
                }
                a[i][j] = -1;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == -1) {
                cout << '#';
            } else {
                cout << a[i][j];
            }
        }
        cout << endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 2e3 + 100, maxk = 1e4 + 10, base = 1380;
const ll inf = 2e18, mod = 1e9 + 7;

int n, k, sz[maxn], hashVal[maxn];
char s[maxn][maxk], ans[maxk];
set<int> st;
pair<int, int> pool[2][maxn * maxk];
bitset<maxk> dp[maxn];

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

	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i], sz[i] = strlen(s[i]);
		ll HASH = 0;
		for (int j = 0; j < sz[i]; j++)
			HASH = (HASH * base + s[i][j]) % mod;
		hashVal[i] = HASH;
	}
	
	dp[n][0] = true;
	for (int i = n - 1; i >= 0; i--)
		dp[i] = (dp[i + 1] | (dp[i + 1] << sz[i]));

	int now = 0, tail = 0;
	for (int i = 0; i < n; i++)
	{
		if (dp[i + 1][k - sz[i]] && st.find(hashVal[i]) == st.end())
			pool[now][tail++] = mp(i, 0);
		st.insert(hashVal[i]);
	}

	for (int len = 0; len < k; len++)
	{
		char c = 'z';
		for (int i = 0; i < tail; i++)
			c = min(c, s[pool[now][i].ff][pool[now][i].ss]);

		/*cerr << "HERE " << len << ' ' << c << ':' << tail << endl;
		for (int i = 0; i < tail; i++)
			cerr << pool[now][i].ff << ' ' << pool[now][i].ss << endl;*/

		int TAIL = 0, mnpos = mod, x, y;
		for (int i = 0; i < tail; i++)
		{
			x = pool[now][i].ff;
			y = pool[now][i].ss;
			if (s[x][y] == c)
			{
				if (y + 1 == sz[x])
				{
					mnpos = min(mnpos, x);
					//cerr << "###" << endl;
				}
				else
				{
					pool[now ^ 1][TAIL++] = mp(x, y + 1);
					//cerr << "$$$" << endl;
				}
			}
		}
		st.clear();
		if (mnpos != mod)
			for (int i = mnpos + 1; i < n; i++)
			{
				//cerr << "DEBUG " << mnpos << ' ' << i << endl;
				if ((k - len - 1 - sz[i] >= 0 && dp[i + 1][k - len - 1 - sz[i]]) && st.find(hashVal[i]) == st.end())
					pool[now ^ 1][TAIL++] = mp(i, 0);
				st.insert(hashVal[i]);
			}

		tail = TAIL;
		now ^= 1;
		ans[len] = c;
	}

	cout << ans << endl;
}



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

public class Main {

	public static void main(String[] args) {

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
			int n = Integer.parseInt(br.readLine());
			String[] s = br.readLine().split(" ");
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = Integer.parseInt(s[i]);
			}
			int cnt = 0;
			for (int i = 1; i < n; i++) {
				if (a[i - 1] == a[i]) {
					if (i == n - 1) {// 最後の一回
						a[i] = a[i - 1] + 1;
					} else { // それ以外は前後の数の和
						a[i] = (a[i - 1] + a[i + 1]) % 10000 + 1;
					}
					cnt++;
				}
			}
			System.out.println(cnt);

		} catch (IOException e) {
		}

	}

}


Measured memory_bytes: 21332
n=int(input())
ans=[0 for i in range(10**5+21)]
Q=[0,1,2,3]
def li(x):
  if x==0 : return [0,1]
  if x==9 : return [8,9]
  return [x-1,x,x+1]

now=0
for q in Q:
  W=[i for i in range(10)] if q==0 else li(q)
  for w in W:
    E=[i for i in range(10)] if [q,w]==[0,0] else li(w)
    for e in E:
      R=[i for i in range(10)] if [q,w,e]==[0,0,0] else li(e)
      for r in R:
        T=[i for i in range(10)] if [q,w,r,e]==[0,0,0,0] else li(r)
        for t in T:
          Y=[i for i in range(10)] if [q,w,e,r,t]==[0,0,0,0,0] else li(t)
          for y in Y:
            U=[i for i in range(10)] if [q,w,e,r,t,y]==[0,0,0,0,0,0] else li(y)
            for u in U:
              I=[i for i in range(10)] if [q,w,e,r,t,y,u]==[0,0,0,0,0,0,0] else li(u)
              for i in I:
                O=[i for i in range(10)] if [q,w,e,r,t,y,u,i]==[0,0,0,0,0,0,0,0] else li(i)
                for o in O:
                  P=[i for i in range(10)] if [q,w,e,r,t,y,u,i,o]==[0,0,0,0,0,0,0,0,0] else li(o)
                  for p in P:
                    
                    ans[now]= 10**9*q + 10**8*w + 10**7*e + 10**6*r + 10**5*t + 10**4*y + 1000*u + 100*i + 10*o + p
                    
                    if now>=10**5+2 : break
                    now+=1


print(ans[n])

Measured memory_bytes: 7388
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;

int main() {
	cin >> n;
	cout << (n <= 999 ? "ABC" : "ABD") << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
  	int N, ctr=0;
	std::string A, B, C;
  	
  	std::cin >> N >> A >> B >> C;
  
  	for(int i=0; i<N; i++){
      	if(A[i] != B[i] || B[i] != C[i]){
        	ctr += (A[i] != B[i] && B[i] != C[i] && C[i] != A[i]) ? 2:1;
        }
    }

  	std::cout << ctr << "\n";
  	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair


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

    //  freopen("a.txt", "r", stdin);
   
      vector<ll> pre;

      ll n;
      cin >> n;

      auto kek = [&](ll k) -> int {
            if (k == 1) return 0;
            ll f = n;
            while (f % k == 0) f /= k;
            f %= k;
            return f == 1;
      };

      ll s = 0;

      for (ll i = 1; i * i <= n; ++i) {
            if (n % i == 0) {
                  s += kek(i);
                  if (n / i != i) s += kek(n / i);
            }
      }

      for (ll i = 1; i * i <= (n - 1); ++i) {
            if ((n - 1) % i == 0) {
                  s += kek(i);
                  if ((n - 1) / i != i)
                        s += kek((n - 1) / i);
            }
      }

      cout << s;
    
      return 0;
}

Measured memory_bytes: 256