akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations
from heapq import heappush, heappop

class Dijkstra:
    def __init__(self, N):
        self.N = N # #vertices
        self.E = [[] for _ in range(N)]

    def add_edge(self, init, end, weight, undirected=False):
        self.E[init].append((end, weight))
        if undirected: self.E[end].append((init, weight))
    
    def distance(self, s):
        INF = float('inf')
        E, N = self.E, self.N
        self.dist = dist = [INF] * N # the distance of each vertex from s
        self.prev = prev = [-1] * N # the previous vertex of each vertex on a shortest path from s
        dist[s] = 0
        n_visited = 0 # #(visited vertices)
        heap = []
        heappush(heap, (0, s))
        while heap:
            d, v = heappop(heap)
            if dist[v] < d: continue # (s,v)-shortest path is already calculated
            for u, c in E[v]:
                temp = d + c
                if dist[u] > temp:
                    dist[u] = temp; prev[u] = v
                    heappush(heap, (temp, u))
            n_visited += 1
            if n_visited == N: break
        return dist
    
    def shortest_path(self, t):
        P = []
        prev = self.prev
        while True:
            P.append(t)
            t = prev[t]
            if t == -1: break
        return P[::-1]

def dist(p1, p2): return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) ** 0.5
    
xs, ys, xt, yt = map(int, input().split())
N = int(input())
P = [[(xs, ys), 0, 0], [(xt, yt), 0, 1]]
for i in range(2, N+2):
    x, y, r = map(int, input().split())
    P.append([(x, y), r, i])
dk = Dijkstra(N+2)
for [p1, r1, i], [p2, r2, j] in combinations(P, 2):
    d = max(0, dist(p1, p2) - (r1 + r2))
    dk.add_edge(i, j, d, undirected=True)
print(dk.distance(0)[1])

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

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

    sort(A.begin(), A.end());
    int m = 0;

    while(true){
        if(m==N-1) break;
        sort(A.begin()+m, A.end());
        m = lower_bound(A.begin()+m, A.end(), 1) - A.begin();
        for(int i=m+1; i<N; i++) A[i] = A[i]%A[m];
    }
    cout << A[m] << endl;
}


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

int main() {
    int n;
    cin >> n;
    string s;
    while(1){
        s = to_string(n);
        if(s.at(0) == s.at(1) && s.at(1) == s.at(2)){
            cout << s << endl;
            return 0;
        }
        n++;
    }
}

Measured memory_bytes: 256
/// awoooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

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

const int N = (int)3e6 + 5;
const int inf = (int)1e9 + 7;

int n, m;
int d[101][101];
char a[101][101];

int main() {
  ios_base :: sync_with_stdio(false);

  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      d[i][j] = inf;
    }
  }
  d[1][1] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      d[i + 1][j] = min(d[i + 1][j], d[i][j] + (a[i][j] != a[i + 1][j]));
      d[i][j + 1] = min(d[i][j + 1], d[i][j] + (a[i][j] != a[i][j + 1]));
    }
  }
  int ans = 0;
  for (int cnt = 1, f = a[1][1] == '#'; cnt <= d[n][m] + 1; cnt++, f ^= 1) {
    ans += f;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)

typedef long long ll;
const int N = 200010;
int A[N],B[N],C[N];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j;
    int ind1,ind2;
    cin>>n;
    fr(i,n)cin>>A[i];
    fr(i,n)cin>>B[i];
    ll tot =0;
    for(int bit=0;bit<=28;bit++)
    {
        int t = (1<<bit);
        int k = 2*t -1;
        fr(i,n)C[i]=(B[i]&k);
        sort(C,C+n);
        int ans =0;
        fr(i,n)
        {
            int num = A[i]&k;
          
            ind2 = lower_bound(C,C+n,2*t-num)-C-1;
            ind1 = lower_bound(C,C+n,t-num)-C;
            ans += max(ind2-ind1+1,0);
            ind2 = lower_bound(C,C+n,4*t-num)-C-1;
            ind1 = lower_bound(C,C+n,3*t-num)-C;
            ans += max(ind2-ind1+1,0);
            ans = ans%2;
        }
        if (ans%2)tot+= t;
    }
    cout<<tot<<"\n";

            
    
    return 0;
}

Measured memory_bytes: 2560
from collections import deque

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

links = [[] for _ in range(N + 1)]

for _ in range(M):
    A, B = map(int, input().split())
    links[A].append(B)
    links[B].append(A)

dist = [-1] * (N + 1)
michi = [-1] * (N + 1)
dist[1] = 0
q = deque([1])

while q:
    now = q.popleft()
    for i in links[now]:
        if dist[i] == -1:
            dist[i] = dist[now] + 1
            michi[i] = now
            q.append(i)

print('Yes')
for i in range(2, N + 1):
    print(michi[i])


Measured memory_bytes: 94852
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S; cin>>S;
  stack<char>A;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='0')A.push('0');
    else if(S.at(i)=='1')A.push('1');
    else if(!A.empty())A.pop();
  }
  stack<char>B;
  for(int i=0;!A.empty();i++){
    B.push(A.top());
    A.pop();
  }
  for(int i=0;!B.empty();i++){
    cout<<B.top();
    B.pop();
  }
  cout<<endl;
}

Measured memory_bytes: 3616
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        N: usize,
        A: [i64; N],
    }
    use std::collections::HashSet;
    let mut set = HashSet::new();

    for a in A {
        if set.contains(&a) {
            set.remove(&a);
        } else {
            set.insert(a);
        }
    }
    println!("{}", set.len());
}


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

int main() {
  long long N;
  cin >> N;
  
  vector<long long> V(N);
  for (long long i = 0; i < N; i++)
    cin >> V.at(i);
  
  sort(V.begin(),V.end());
  
  long long count = 0;
  for (long long j = 0; j < N - 1; j++) {
    if (V.at(j) == V.at(j + 1))
      count++;
  }
  
  if (count == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 1792
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn divisors(x: i64) -> Vec<i64> {
    let mut v = vec![];

    let mut d = 1;
    while d * d <= x {
        if x % d == 0 {
            v.push(d);
            v.push(x / d);
        }
        d += 1;
    }

    v.sort();
    v.dedup();

    v
}

fn distance(x: i64, y: i64) -> i64 {
    (x - 1) + (y - 1)
}

fn main() {
    let N = read!(i64);

    let mut m = std::i64::MAX;
    let ds = divisors(N);
    for d in ds {
        m = min(m, distance(d, N / d));
    }

    println!("{}", m)
}


Measured memory_bytes: 4352
#include<cstdio>
#include <iostream>
using namespace std;
long long n,m,a[1015];
long long sum=0;
int num;
int main() {
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		sum+=a[i];
	}
	double ans=sum*1.0/((double)m*4.0);
	for(int i=1;i<=n;++i){
		if(a[i]>=ans)num++;
	}
	if(num>=m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,i;
  cin >> n >>k;
  
  long long int ans;
  ans=0;
  
  if(n>k){
  vector<long long int> h(n);
  for(i=0;i<n;++i)
  {
  cin >> h.at(i);
  }
  
  sort(h.begin(),h.end());
  
  for(i=0;i<n-k;++i)
  {
  ans=ans+h.at(i);
  }
  }
  cout << ans << endl;
  
return 0;
}

Measured memory_bytes: 4788
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    long long N;
    cin >> N;
    long double dN = sqrtl((long double)N);
    long num1;
    for(int i = (int)dN; i >= 1; i--){
        if(N % i == 0){
            num1 = N / i;
            break;
        }
    }
    int ans;
    for(ans = 0; num1 >= 1; ans++){
        num1 /= 10;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
open System
open System.Collections
open System.Collections.Generic
open System.IO
open System.Linq

let r() = Console.ReadLine()
let Int() = r() |> int

[<EntryPoint>]
let main _ = 
    let a = Int()
    let b = Int()
    let h = Int()
    let ans = (a+b)*h/2
    printfn "%i" ans
    0
    



Measured memory_bytes: 11992
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

bool o[1000];

int main(void)
{
    int n, k, d;
    int i;

    ios::sync_with_stdio(false);
    cin >> n >> k;
    for(i = 1; i <= k; i ++)
    {
        cin >> d;
        while(d --)
        {
            int x;
            cin >> x;
            o[x] = true;
        }
    }

    int oo = 0;
    for(i = 1; i <= n; i ++)
        oo += !o[i];
    cout << oo << endl;

    return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

string s1, s2;

vector<string> split_string(string s, char c){
	vector<string> s_vec;
	ll pre = 0;
	REP(i,0,s.size()){
		if(s[i] == c){
			s_vec.push_back(s.substr(pre, i-pre));
			pre = i+1;
		}
	}
	s_vec.push_back(s.substr(pre, s.size()-pre));
	return s_vec;
}
int main() {
	while (cin >> s1 && s1 != ".") {
		cin >> s2;
		ll no_match = 0;
		vector<string> s1_vec = split_string(s1, '"');
		vector<string> s2_vec = split_string(s2, '"');
		if(s1_vec.size() != s2_vec.size()){
			no_match = 2;
		}else{
			REP(i,0, s1_vec.size()){
				if(s1_vec[i] != s2_vec[i]){
					if(i%2) no_match++;
					else no_match = 2;
				}
			}
		}

		if(no_match == 0){
			p("IDENTICAL");
		}else if(no_match == 1){
			p("CLOSE");
		}else{
			p("DIFFERENT");
		}
	}

	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long N, std::vector<long long> a){
    vector<long long> b(N * 3), c(N * 3);
    priority_queue<int> R;
    priority_queue<int, vector<int>, greater<int>> Q;
    int s = 0;
    for(int i = 0; i < 3 * N; ++i) {
        s += a[i];
        Q.push(a[i]);
        if (i >= N) {
            s -= Q.top();
            Q.pop();
        }
        b[i] = s;
    }
    s = 0;
    for(int i = 3 * N - 1; i >= 0; --i) {
        s += a[i];
        R.push(a[i]);
        if (i < 2 * N) {
            s -= R.top();
            R.pop();
        }
        c[i] = s;
    }
    int res = (int)-1e15;
    for(int i = N - 1; i < 2 * N; ++i) {
        res = max(res, b[i] - c[i + 1]);
    }
    cout << res << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(3*N);
    for(int i = 0 ; i < 3*N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}

Measured memory_bytes: 9588
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}
#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}
fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }

    input! {
        w: String,
    }

    let mut map = HashMap::<char, usize>::new();
    for c in w.chars() {
        *map.entry(c).or_insert(0) += 1;
    }
    for (_, n) in map {
        if n % 2 == 1 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}
fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <iostream>
#include<string>
#include <algorithm>
#include <queue>
#define NIL -1
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MAX 10003
int n, m, money[20], retu[50001] = { NIL };
int maisuu = 0;
bool hantei = false;
int main() {
	retu[0] = 1;
	cin >> n >> m;
	REP(i, m) {
		cin >> money[i];
	}
	queue <int>q; q.push(0);
	while (maisuu+=1,maisuu) {
		int siz = q.size();
		REP(i, siz) {
			int front = q.front();
			if (q.empty()) { hantei = true; break; }
			q.pop();
			REP(i, m) {
				if (front + money[i] < n) {
					if (retu[front + money[i]] == false) {
						retu[front + money[i]] = 1;
						q.push(front + money[i]);
					}
				}
				if (front + money[i] == n) {
					 hantei = true; break;
				}
			}
			if (hantei) { break; }
		}
		if (hantei) { break; }
	}
	cout << maisuu  << endl;;
	return 0;
}

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

public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] strArray = str.split(" ",0);
		int num[] = new int[strArray.length];

		for(int i=0; i<strArray.length; i++){
			num[i] = Integer.parseInt(strArray[i]);
		}

		int ans1 = num[0] * num[1];
		int ans2 = 2*(num[0] + num[1]);

		System.out.println(ans1 + " " + ans2);

	}

}

Measured memory_bytes: 16892
#include <stdio.h>
long long gcd(long long gcd_a, long long gcd_b) {
	if (gcd_a < gcd_b) {
		long long gcd_c;
		gcd_c = gcd_a;
		gcd_a = gcd_b;
		gcd_b = gcd_c;
	}
	if (!gcd_b)return gcd_a;
	return gcd(gcd_b, gcd_a % gcd_b);
}
long long ans, n, x;
int main() {
	scanf("%lld", &n);
	for (long long i = 1; i <= n; i++) {
		for (long long j = 1; j <= n; j++) {
			x = gcd(i, j);
			for (long long k = 1; k <= n; k++) {
				ans += gcd(x, k);
			}
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1732
# coding: utf-8
# Here your code !
#coding: utf-8

while True:
    n = int(raw_input())
    if n == 0:
        break
    coolist = [(0, 0)]
    xmax = 0
    xmin = 0
    ymax = 0
    ymin = 0
    for i in range(n-1):
        l = map(int, raw_input().split())
        if l[1] == 0:
            coo = (coolist[l[0]][0] - 1,coolist[l[0]][1])
            if xmin > coolist[l[0]][0] - 1:
                xmin = coolist[l[0]][0] - 1
            coolist.append(coo)
        if l[1] == 1:
            coo = (coolist[l[0]][0],coolist[l[0]][1] - 1)
            if ymin > coolist[l[0]][1] - 1:
                ymin = coolist[l[0]][1] - 1
            coolist.append(coo)
        if l[1] == 2:
            coo = (coolist[l[0]][0] + 1,coolist[l[0]][1])
            if xmax < coolist[l[0]][0] + 1:
                xmax = coolist[l[0]][0] + 1
            coolist.append(coo)
        if l[1] == 3:
            coo = (coolist[l[0]][0],coolist[l[0]][1] + 1)
            if ymax < coolist[l[0]][1] + 1:
                ymax = coolist[l[0]][1] + 1
            coolist.append(coo)
    print xmax-xmin+1,ymax-ymin+1

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

ll n, a, b, c;
vector<string> s;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  cin >> n >> a >> b >> c;

  vector<char> ans(n);
  s = vector<string>(n);
  rep(i, n) {
    cin >> s[i];
  }

  rep(i, n) {
    ll *x, *y;
    if (s[i] == "AB") {
      x = &a;
      y = &b;
    } else if (s[i] == "AC") {
      x = &a;
      y = &c;
    } else {
      x = &b;
      y = &c;
    }

    if (*x == 0 && *y == 0) {
      cout << "No" << endl;
      return 0;
    }

    if (*x == 0) {
      (*x)++;
      (*y)--;
      ans[i] = s[i][0];
    } else if (*y == 0) {
      (*x)--;
      (*y)++;
      ans[i] = s[i][1];
    } else {
      if (i == n - 1) {
        (*x)++;
        (*y)--;
        ans[i] = s[i][0];
      } else if (s[i + 1][0] == s[i][0] || s[i + 1][1] == s[i][0]) {
        (*x)++;
        (*y)--;
        ans[i] = s[i][0];
      } else if (s[i + 1][0] == s[i][1] || s[i + 1][1] == s[i][1]) {
        (*x)--;
        (*y)++;
        ans[i] = s[i][1];
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, n) {
    cout << ans[i] << endl;
  }

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    long long a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int l = 1, r = n - 2;
    long long cl = a[0], cr = a[n-1];
    long long sum = cr - cl;
    while(l <= r){
        if(cl > cr) swap(cl, cr);
        if(abs(cl - a[r]) < abs(cr - a[l])){
            sum += abs(cr - a[l]);
            cr = a[l];
            l++;
        }else{
            sum += abs(cl - a[r]);
            cl = a[r];
            r--;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/math/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  boost::for_each(vc, [&os, &vc](T value) {
    os << value;
    if (value != vc.back())
      os << ' ';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream&
operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  //string S{}; std::cin >> S;
  ui N{}, M{}; std::cin >> N >> M;

  vector<ui> input_k(M), input_p(M);
  vector<vector<ui>> input_s(M);

  /*
   *  index: switch unique-number.    := [1, N]
   *  value: connected lamp list. V_i := [1, M]
   */
  vector<vector<ui>> S(N);
  rep(0, M)
  {
    cin >> input_k[i];
    input_s[i] = vector<ui>(input_k[i]);
    rep_uj(0, input_s[i].size())
    {
      cin >> input_s[i][j];
      --input_s[i][j];

      S[input_s[i][j]].push_back(i);
    }
  }
  rep(0, M) cin >> input_p[i];

  ull ans{};
  for (ull it = 1ULL << N; it > 0; --it)
  {
    vector<ui> bits{ input_p };
    rep(0, N)
    {
      if (it & (1ULL << i)
        && !S[i].empty())
      {
        boost::for_each(S[i], [&bits](auto value) {
          bits[value] = !bits[value];
          });
      }
    }
    auto res = boost::accumulate(bits, 0U, [](auto res, auto b) {
      return res | b;
      });
    if (!res)
      ++ans;
  }

  using std::cout;
  cout << ans << '\n';
  
  return;
}

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

  solve();

  return 0;
}


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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    string s;
    scan(s);

    auto n = s.length.to!int;

    if (s == "keyence") {
        writeln("YES");
        return;
    }

    foreach (i ; 0 .. n) {
        foreach (j ; i + 1 .. n + 1) {
            string res;

            foreach (k ; 0 .. n) {
                if (i <= k && k < j) {
                    continue;
                }
                res ~= s[k];
            }

            if (res == "keyence") {
                writeln("YES");
                return;
            }
        }
    }

    writeln("NO");
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg ; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg ; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

long powmod(long x, long y, long mod = 1_000_000_007L) {
    long res = 1L;

    while (y > 0) {
        if (y & 1) {
            (res *= x) %= mod;
        }
        (x *= x) %= mod;
        y >>= 1;
    }

    return res;
}

Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

const int MAXN = 507;

int n, m;
int c[MAXN][MAXN];
int a[MAXN][MAXN], b[MAXN][MAXN];
char s[MAXN];

int main(){

    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++){
        scanf("%s", s);
        for(int j=1; j<=m; j++){
            c[i][j] = (s[j-1] == '#' ? 1 : 0);
        }
    }

    for(int i=2; i<=n-1; i++){
        if((i % 2) == 1){
            for(int j=1; j<=m-1; j++){
                a[i][j] = 1;
            }
        }else{
            for(int j=2; j<=m; j++){
                b[i][j] = 1;
            }
        }
    }

    for(int i=1; i<=n; i++){
        a[i][1] = 1;
        b[i][m] = 1;
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            a[i][j] |= c[i][j];
            b[i][j] |= c[i][j];
        }
    }


    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            a[i][j] ? printf("#") : printf(".");
        }
        printf("\n");
    }

    printf("\n");

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            b[i][j] ? printf("#") : printf(".");
        }
        printf("\n");
    }


    return 0;
}

Measured memory_bytes: 3712
import heapq
from collections import defaultdict, deque
from math import ceil, factorial
from fractions import gcd
import sys
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10**9+7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))


K = ii()

runrun = deque()
runrunAll = []
new = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
runrun.append(new)
runrunAll.extend(new)
for i in range(1, 10):
    before = runrun[i-1]
    new = deque()
    for b in before:
        head = b[0]
        ihead = int(head)
        if head == '0':
            new.append(str(ihead) + b)
            new.append(str(ihead+1) + b)
        elif head == '9':
            new.append(str(ihead-1) + b)
            new.append(str(ihead) + b)
        else:
            new.append(str(ihead-1) + b)
            new.append(str(ihead) + b)
            new.append(str(ihead+1) + b)
    runrun.append(new)
    runrunAll.extend(new)

runrunAll = [int(r) for r in runrunAll]
runrunAll = sorted(set(runrunAll))
print(runrunAll[K])


Measured memory_bytes: 117336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int A,B;
  cin >> A >> B;
  cout  << A*B << endl;

}


Measured memory_bytes: 3596
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

######################################################

INF = 1e10
H, W = list(map(int, input().split()))

dp = [[INF] * 10 for _ in range(10)]

for i in range(10):
    for j, v in enumerate([int(_) for _ in input().split()]):
        dp[i][j] = v

for k in range(10):
    for i in range(10):
        for j in range(10):
            # k経由でiからjへ
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
ans = 0
for h in range(H):
    for w in [int(_) for _ in input().split()]:
        if w == -1: continue
        ans += dp[w][1]
print(ans)


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

//#define long long ll
#define INF 1000000007
#define N 300005

long long f[N];


long long pow(long long a, long long b, long long MOD)
{
 long long x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y%mod * y%mod);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
long long InverseEuler(long long n, long long MOD)
{
 return pow(n,MOD-2,MOD);
}

long long C(long long n, long long r, long long MOD)
{

 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

lli SUM(lli n){
    n = n*(n+1);
    n /= 2;
    n %= mod;
    return n;
}

lli add(lli a , lli b){
    return (a+b)%mod;
}

lli mul(lli a, lli b){

    return (a%mod * b%mod)%mod;
}

int main(){
	f[0] = 1;

	for(int i = 1 ; i < N ; i++) f[i] = mul(f[i-1],i);

 	int n,m,k;
 	scn3(n,m,k);

 	lli suma = 0, sumb = 0;

 	for(int i=n-1; i ; i--) suma = add(suma, SUM(i));
 	for(int i=m-1; i ; i--) sumb = add(sumb, SUM(i));

 	lli c = C((n*m-2+mod)%mod , k-2 , mod);

 	lli ans = mul(mul(c,m*m),suma) + mul(mul(c,n*n),sumb);
 	cout<<ans%mod;

 	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    char a;
    cin >> a;

    if ((int)(a-'A') > 25) puts("a");
    else puts("A");
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
class UnionFind{
  private:
    vector<int>par;
  public:
    UnionFind(int n):par(n,-1){}
    int root(int x){
      if(par[x] < 0)return x;
      return par[x] = root(par[x]);
    }
    bool unite(int x,int y){
      x = root(x); y = root(y);
      if (x == y) return false;
      if (par[x] > par[y]) swap(x, y);
      par[x] += par[y];
      par[y] = x;
      return true;
    }
    bool same(int x,int y){
      return root(x) == root(y);
    }
    int size(int x) {
      return -par[root(x)];
    }
};
int main(){
  string s,t;
  cin >> s >> t;
  int ans = 12212;
  rep(i,(int)s.size() - (int)t.size() + 1){
    int tmp = 0;
    rep(j,(int)t.size())if(s[i + j] != t[j])tmp++;
    ans = min(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
map<string,int> ss;
int n;
string s;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s;
        sort(s.begin(),s.end());
        ss[s]++;
    }
    long long ans=0;
    for(auto j:ss){
        ans+=(1LL*(j.second)*(j.second-1));
    }
    printf("%lld\n",ans/2);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 11264
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};

//全二点間の距離
//ヨ i,d[i][i]<0なら負の閉路
in MAX_dist=1e9+7;
in V=0;
vector<vector<in>> d(0,vector<in>(0,MAX_dist));//d[x][y]:=x->yのcost,枝が無ければMAX_dist,d[i][i]=0

void init(in n){
    d=vector<vector<in>>(n,vector<in>(n,MAX_dist));
    rep(i,n) d[i][i]=0;
    V=n;
}

void warshall(){
    rep(k,V){
        rep(i,V){
            if(d[i][k]==MAX_dist) continue;
            rep(j,V){
                if(d[k][j]==MAX_dist) continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n;
    cin>>n;
    init(n);
    vector<vector<in>> a(n,vector<in>(n));
    rep(i,n)rep(j,n) cin>>a[i][j];
    rep(i,n)rep(j,n) d[i][j]=a[i][j];
    warshall();
    rep(i,n)rep(j,n){
        if(d[i][j]!=a[i][j]){
            cout<<-1<<endl;
            return 0;
        }
    }
    rep(i,n)REP(j,i+1,n){
        rep(k,n){
            if(i==k) continue;
            if(j==k) continue;
            if(d[i][j]==d[i][k]+d[k][j]){
                a[i][j]=0;
                a[j][i]=0;
                break;
            }
        }
    }
    in ans=0;
    rep(i,n)rep(j,n) ans +=a[i][j];
    cout<<ans/2ll<<endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
using namespace std;
 
int main()
{
long long w,a,b,c; cin>>w>>a>>b;
if(b<a) swap(a,b);
if(b-(a+w)>0) cout<<b-(a+w);
else cout<<0;
return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N, P;
    string S;
    cin >> N >> P >> S;

    ll res = 0;
    if (P == 2) {
        for (int i=0; i<N; ++i) if ((int)(S[i]-'0') % 2 == 0) res += i+1;
    } else if (P == 5) {
        for (int i=0; i<N; ++i) if (S[i] == '0' || S[i] == '5') res += i+1;
    } else {
        vector<ll> dp(N+1);
        ll ten = 1;
        for (int i=N-1; i>=0; --i) {
            dp[i] = (dp[i+1] + ten * (ll)(S[i]-'0')) % P;
            (ten *= 10) %= P;
        }
        map<ll, ll> mp;
        for (int i=0; i<N+1; ++i) ++mp[dp[i]];
        for (auto p : mp) res += p.second * (p.second-1) / 2;
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);
const ll MOD=1000000007;

int main(){
	ll n,m;
	cin>>n>>m;
	ll a[n+1];
	ll b[m+1];
	FOR(i,1,n) cin>>a[i];
	FOR(i,1,m) cin>>b[i];
	ll dp[n+1][m+1];
	FOR(i,0,m) dp[0][i]=0;
	FOR(i,0,n) dp[i][0]=0;
	FOR(i,1,n){
		FOR(j,1,m){
			dp[i][j]=(dp[i-1][j]+dp[i][j-1]+MOD)%MOD;
			dp[i][j]=(dp[i][j]-dp[i-1][j-1]+MOD)%MOD;
			if(a[i]==b[j]) dp[i][j]=(dp[i][j]+1+dp[i-1][j-1]+MOD)%MOD;
			
		}
	}
	cout<<(dp[n][m]+1)%MOD<<endl;
}

Measured memory_bytes: 31616
def main():
    k, a, b = map(int, input().split())
    inc = b - a
    if (inc < 3):
        print(k + 1)
        return

    if (k < a - 1):
        print(k + 1)
        return

    k -= a - 1
    ans = a
    ans += k % 2
    ex = k // 2
    ans += ex * inc
    print(ans)

main()

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

int cmp(const void *p, const void *q) {
	return *(int*)p - *(int*)q;
}

int main(void) 
{
	int N, L[200];
	long int sum = 0;

	if (scanf("%d", &N) != 1)return 0;

	for (int i = 0; i < 2 * N; i++) {
		if (scanf("%d", &L[i]) != 1)return 0;
	}

	qsort(L, 2*N, sizeof(int), cmp);

	for (int i = 0; i < N; i++) {
		sum += L[2 * i];
	}

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


	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

int main() {
  char buf[262144];
  scanf("%s", buf);
  std::string s = buf;
  scanf("%s", buf);
  std::string t = buf;

  std::vector<std::vector<size_t>> ss(26), tt(26);
  for (size_t i = 0; i < s.length(); ++i) {
    ss[s[i]-'a'].push_back(i);
    tt[t[i]-'a'].push_back(i);
  }

  std::sort(ss.begin(), ss.end());
  std::sort(tt.begin(), tt.end());
  puts((ss == tt)? "Yes": "No");
}


Measured memory_bytes: 4864
#include <iostream>
using namespace std;
#include <algorithm>
#include <functional>
int main() {
    int  N,M,X,Y;
    
    cin >> N >> M >> X >> Y;
    int x[N],y[M];
    bool isWar = false;
    if(X >= Y){
      isWar = true;
    } 
    int maxx;
    int miny;
    cin >> maxx;
    for(int i = 2; i <= N; i++){
      int tmp = 0;
      cin >> tmp;
      maxx = std::max(maxx,tmp);
    }
    cin >> miny;
    for(int i = 2; i <= M; i++){
      int tmp = 0;
      cin >> tmp;
      miny = std::min(miny,tmp);
    }
    maxx = std::max(maxx,X);
    miny = std::min(miny,Y);
    if(maxx < miny){
      
    }else{
      isWar = true;
    }
    if(isWar){
      cout << "War" << endl;
    }else{
      cout << "No War" << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
ans = [0]*(10**5)
a = 0
for x in range(1,10**2):
  for y in range(1,10**2):
    for z in range(1,10**2):
      ans[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1
for i in range(1,N+1):
  print(ans[i])


Measured memory_bytes: 9932
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
//#define ll long long
//#define ll1 1ll
//#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);


	int N, Q; cin >> N >> Q;
	string s; cin >> s;
	s = "?" + s + "?";
	vector<char>t(Q);
	vector<char>d(Q);
	rep(i, 0, Q) { cin >> t[i] >> d[i]; }

	int l = 0, r = N + 1;
	while (r - l > 1) {
		int m = (l + r) / 2;
		int x = m;
		rep(i, 0, Q) {
			if (t[i] == s[x]) {
				if (d[i] == 'L')x--;
				else x++;
			}
		}
		dump(m, x);
		if (x == 0)l = m;
		else r = m;
	}
	dump(l, r);

	int ll = 0, rr = N + 1;
	while (rr - ll > 1) {
		int m = (ll + rr) / 2;
		int x = m;
		rep(i, 0, Q) {
			if (t[i] == s[x]) {
				if (d[i] == 'L')x--;
				else x++;
			}
		}
		if (x == N+1)rr = m;
		else ll = m;
	}
	dump(ll, rr);
	cout << N-(l + (N + 1 - rr)) << endl;

	return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

int main()
{
    ll n, k, q;
    cin >> n >> k >> q;

    vector<ll> v(n, k);

    rep(i, q) {
        ll tmp;
        cin >> tmp;
        ++v[tmp-1];
    }

    rep(i, n) {
        if (v[i] - q > 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

int main(){
  queue<int> q;
  int n,k,u;
  int c[101];
  vector<int>  d[101];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    d[u].resize(k);
    for(int j=0;j<k;j++) cin>>d[u][j];
  }
  for(int i=0;i<=n;i++) c[i]=-1;
  q.push(1);
  c[1]=0;
  int a;
  while(!q.empty()){
    a=q.front(),q.pop();
    for(int i=0;i<d[a].size();i++)
      if( d[a][i]>1 && c[d[a][i]]==-1){
	q.push(d[a][i]);
	c[d[a][i]]=c[a]+1;
      }
  }
  for(int i=1;i<=n;i++) cout<<i<<" "<<c[i]<<endl;
  return 0;
}

Measured memory_bytes: 1200
N=int(input())
a=list(map(int,input().split()))
b=a[0]
for i in range(N-1):
  b=b^a[i+1]
x=[0 for i in range(N)]
for i in range(N):
  x[i]=b^a[i]
x=map(str,x)
ans=' '.join(x)
print(ans)

Measured memory_bytes: 39444
X=input()

N=len(X)
n=N-1
A=0
num=0
total=0

for i in range(2**n):
    A=X[0]
    for j in range(n):
        if (i>>j)&1:
            A+=".+"+X[j+1]
        else:
            A+=".-"+X[j+1]

    num=list(map(int,A.split(".")))
    total=sum(num)

    if total==7:
        break

print(A.replace(".","")+"=7")


Measured memory_bytes: 9072