akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(h)]

ww = 2*w
m = 0
l = []

def pos(i):
    y = i // ww
    y *= 2
    ri = i % ww
    if ri < w:
        x = ri
    else:
        x = ww - ri - 1
        y += 1
    return y, x

for i in range(h*w-1):
    y, x = pos(i)
    if a[y][x] % 2 != m:
        yy, xx = pos(i+1)
        l.append((y+1, x+1, yy+1, xx+1))
        m = 1
    else:
        m = 0

print(len(l))
for y, x, yy, xx in l:
    print(y, x, yy, xx)


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

using namespace std;

int digit(int n){
    int p = n, i = 1;
    while(true){
        if(p / 10) {++i; p /= 10;}
        else break; 
    }
    return i;
}

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

    cnt = 0;
    for(int i=1; i<=N; ++i)
        if(digit(i) % 2 == 1) ++cnt;
    
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/arc073/tasks/arc073_a
# 愚直でよくね？
N, T = read_ints()
t = read_ints()

ans = 0
# t(i+1)<ti+Tだったら差を足してそうじゃなければTを足すのが良さそう
for i in range(N - 1):
    if t[i + 1] < t[i] + T:
        ans += t[i + 1] - t[i]
    else:
        ans += T
ans += T  # 最後の人
print(ans)


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

int main()
{
  int a , b;
  cin >> a >> b;
  vector<int> v;
  if(a > b)
  {
    for(int i = 0 ; i < a ; ++i)
    {
      v.push_back(b);
    }
  }
  else
  {
    for(int i = 0 ; i < b ; ++i)
    {
      v.push_back(a);
    }
  }
  for(int i = 0 ; i < v.size() ; ++i)
  {
    cout << v[i];
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    int A,B,C;  cin >> A >> B >> C;

    if (A == B){
        cout << C << endl;
    }

    if (A == C){
        cout << B << endl;
    }

    if (B == C){
        cout << A << endl;
    }

    return 0;
}


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

int main(void)
{
  int n;
  string s;
  cin >> n >> s;

  string ans = "Yes";

  if (n % 2 == 0) {
    for (int i = 0; i < n / 2; i++) {
      if (s[i] != s[i + n / 2]) {
        ans = "No";
        break;
      }
    }
  } else {
    ans = "No";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve(){
	while (true) {
		string s;
		cin >> s;
		if (s == "#") return;
		s.push_back('/');
		int grid[10][10] = {};
		int x = 0;
		int w = 0;
		string b;
		REP(i, s.length()) {
			if (s[i] == '/') {
				int y = 0;
				REP(q, b.length()) {
					if (b[q] == 'b') {
						grid[x][y] = 1;
						y++;
					}
					else {
						y += b[q] - '0';
					}
				}
				w = y;
				b.clear();
				x++;
			}
			else {
				b.push_back(s[i]);
			}
		}
		{
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			a--; b--; c--; d--;
			assert(grid[a][b] == 1);
			grid[a][b] = 0;
			assert(grid[c][d] == 0);
			grid[c][d] = 1;
		}
		REP(i, x) {
			if (i != 0) cout << "/";
			int cnter = 0;
			REP(q, w) {
				if (grid[i][q] == 1) {
					if (cnter != 0) {
						cout << cnter;
					}
					cnter = 0;
					cout << "b";
				}
				else {
					cnter++;
				}
			}
			if (cnter != 0) cout << cnter;
		}
		cout << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<string> split_naive(const string &s, char delim) {
	vector<string> elems;
	string item;
	for(char ch:s){
		if(ch==delim){
			if(!item.empty()) elems.push_back(item);
			item.clear();
		}
		else{
			item += ch;
		}
	}
	if(!item.empty()) elems.push_back(item);
	return elems;
}

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

	string S=in<string>();
	int N=S.size();
	int M=1<<N-1;
	ll A=0;
	REP(i,M){
		int V=i;
		vector<int> F(N-1,0);
		int index=0;
		while(V){
			if(V&1) F[index]=1;
			V/=2;
			index++;
		}
		index=0;
		string T(S);
		REP(j,N-1){
			if(F[j]){
				T.insert(index+j+1,"+");
				index++;
			}
		}
		auto U=split_naive(T,'+');
		for(auto& x:U){
			ll K;
			sscanf(x.c_str(),"%lld",&K);
			A += K;
		}
	}
	out(A);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int n, m;
bool G[10][10];

signed main(){
    cin >> n >> m;
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a][b] = true;
        G[b][a] = true;
    }
    vector<int> d(n);
    rep(i, 0, n) d[i] = i;
    int ans = 0;
    do{
        if(d[0] != 0) continue;
        bool f = true;
        rep(i, 1, n){
            if(G[d[i - 1]][d[i]] == false) f = false;
        }
        if(f) ans++;
    }while(next_permutation(all(d)));
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) {
        int n = scanner.nextInt();
        long ans = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt() - 1;
        }
        for (int i = 0; i < n; i++) {
            ans += scanner.nextInt();
        }
        int[] c = new int[n];
        for (int i = 1; i < n; i++) {
            c[i - 1] = scanner.nextInt();
        }
        for (int i = 1; i < n; i++) {
            if (a[i - 1] + 1 == a[i]) {
                ans += c[a[i - 1]];
            }
        }
        System.out.println(ans);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21332
//In the name of God:)
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long int
#define fast  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int MAXN = 1e5 + 10;


int main(){
    ll n , m , in , sum = 0;
    scanf("%lld%lld" , &n , &m);
    for(int i = 0 ; i < m ; i++){
        scanf("%lld" , &in);
        sum += in;
    }
    if(sum > n){
        printf("-1\n");
    }
    else{
        printf("%lld\n" , n - sum);
    }
}


Measured memory_bytes: 3828
#include <stdio.h>
int main(void){
    double x1,x2,y1,y2,P1,P2;
    double sqrt(double x);
    scanf("%lf %lf %lf %lf", &x1,&y1,&x2,&y2);
        
        P1=(x2-x1)*(x2-x1);
        P2=(y2-y1)*(y2-y1);
        
    printf("%.8f\n", sqrt(P1+P2));
    
    return(0);
    
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 181
#define MAX_N 1100000
#define INF 1e9
int arr[MAX];
int dp1[MAX_N], dp2[MAX_N];
 
void make(){
    vector<int> odd;
    for(int i = 1 ; i < MAX ; i++){
	arr[i] = i*(i+1)*(i+2)/6;
	if(arr[i] % 2) odd.push_back(arr[i]);
    }
 
    for(int i = 0 ; i < MAX_N ; i++){
	dp1[i] = dp2[i] = INF;
    }
    dp1[0] = dp2[0] = 0;
    for(int i = 0 ; i < MAX ; i++){
	for(int j = 0 ; j < MAX_N ; j++){
	    if(j + arr[i] >= MAX_N) continue;
	    dp1[j+arr[i]] = min(dp1[j+arr[i]], dp1[j]+1);
	}
    }
 
    for(int i = 0 ; i < odd.size() ; i++){
	for(int j = 0 ; j < MAX_N ; j++){
	    if(j + odd[i] >= MAX_N) continue;
	    dp2[j+odd[i]] = min(dp2[j+odd[i]], dp2[j]+1);
	}
    }
}
 
int main(){
    int n;
    make();
    while(cin >> n ,n){
	cout << dp1[n] << " " << dp2[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 11688
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;

namespace hello_world
{class Program
	{
		static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(" ");
			int a = int.Parse(input[0]);
			int b=  int.Parse(input[1]);
			int c = int.Parse(input[2]);
			int d = int.Parse(input[3]);
			while (a > 0 && c > 0)
			{
				c -= b;
				if (c <= 0)
				{
					

					Console.WriteLine("Yes");
					return;

				}
				a -= d;
				if (a <= 0)
				{
					Console.WriteLine("No");
					

					return;
				}
			}

		}


	}

}

	

Measured memory_bytes: 27532
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int n;
    cin >> n;
    vector<string> str;
    vector<string> sn;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        str.push_back(s);
        sn.push_back(s);
    }
    sort(str.begin(),str.end());
    for(int i=0; i<str.size(); i++){
        if(str[i]==str[i-1]){
            cout << "No" <<endl;
            return 0;
        }
    }
    bool ans = false;
    for(int i=1; i<sn.size(); i++){
        int ind = sn[i-1].size()-1;
        char first = sn[i][0];
        char last = sn[i-1][ind];
        if(first!=last){
            cout << "No" <<endl;
            return 0;
        }else{
            ans = true;
        }
        
    }
    if(ans == true){
        cout << "Yes" <<endl;
    }
}

Measured memory_bytes: 3612
from itertools import combinations

N = int(input())
S = [input() for _ in range(N)]
MARCH = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for s in S:
    for m in MARCH:
        if s[0] == m:
            MARCH[m] += 1
ans = 0
for i, j, k in combinations(MARCH, 3):
    ans += MARCH[i] * MARCH[j] * MARCH[k]
print(ans)


Measured memory_bytes: 9772
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let xs: Vec<u128> = sc.vec(n);
    let mut ac = 0;
    for &x in xs.iter() {
        ac ^= x;
    }
    for &x in xs.iter() {
        put!(ac ^ x);
    }
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


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

int main(void) {
    int N;
    cin >> N;
    vector< int > a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] == count + 1) {
            ++count;
        }
    }
    if (count == 0) {
        cout << -1 << "\n";
    } else {
        cout << (N - count) << "\n";
    }

    return 0;
}


Measured memory_bytes: 1024
import sys
m=10**6;a=[1]*m;a[0:2]=0,0
for i in range(2,1000):
 if a[i]>0:
  for j in range(i*2,m,i):a[j]=0
for i in range(m):a[i]+=a[i-1]
for e in sys.stdin:print(a[int(e)])


Measured memory_bytes: 44856
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    M = max(A)
    m = min(A)

    T = M if abs(M) >= abs(m) else m
    i = A.index(T) + 1
    ans = []
    if T >= 0:
        for j, a in enumerate(A):
            if a < 0:
                ans.append((i, j + 1))
        for i in range(N - 1):
            ans.append((i + 1, i + 2))
    else:
        for j, a in enumerate(A):
            if a > 0:
                ans.append((i, j + 1))
        for i in range(N - 1, 0, -1):
            ans.append((i + 1, i))


    print(len(ans))
    for a, b in ans:
        A[b - 1] += A[a - 1]
        print(a, b)


if __name__ == "__main__":
    main()



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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            if (N % 2 == 1)
            {
                Console.WriteLine("No");
                return;
            }
            else
            {
                var s1 = S.Substring(0, N / 2);
                var s2 = S.Substring(N / 2);
                Console.WriteLine(s1 == s2 ? "Yes" : "No");
            }
        }
    }
}


Measured memory_bytes: 13140
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n+1))
        self.rank = [0]*(n+1)

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def are_same(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
P = list(map(int, input().split()))
uf = UnionFind(N)
for i in range(M):
    x, y = map(int, input().split())
    uf.unite(x, y)

ans = 0
for n in range(N):
    if uf.are_same(P[n], n+1):
        ans += 1

print(ans)

Measured memory_bytes: 14452
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int d[100005],m[100005];
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>d[i];
	long long sum=0;
	for(int i=1;i<=n;i++)
		sum-=d[i];
	for(int i=1;i<=n;i+=2)
		sum+=2*d[i];
	m[1]=sum;
	for(int i=2;i<=n;i++)
		m[i]=2*d[i-1]-m[i-1];
	for(int i=1;i<=n;i++)
		cout<<m[i]<<' ';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 2816
n, m = gets.split.map(&:to_i)
a = m.times.map{gets.to_i}

mod = 10**9 + 7

dp = Array.new(n, 0)
m.times do |i|
  dp[a[i] - 1] = -1
  if i > 0 && a[i] - 1 == a[i - 1]
    puts 0
    exit
  end
end

if dp[0] == -1
  dp[1] = 1
elsif dp[1] == -1
  dp[0] = 1
else
  dp[0] = 1
  dp[1] = 2
end

2.upto(n) do |i|
  next if dp[i] == -1

  if dp[i - 1] == -1
    dp[i] = dp[i - 2] % mod
  elsif dp[i - 2] == -1
    dp[i] = dp[i - 1] % mod
  else
    dp[i] = (dp[i - 1] + dp[i - 2]) % mod
  end
end

puts dp[n - 1]


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int D;
    cin>>D;
    vector<int> c(26);
    rep(i,26){
        int tmp=0;
        cin>>tmp;
        c[i]=tmp;
    }
    vector<vector<int>> s(D,vector<int>(26));
    vector<int> last(26,0);//最後にiのテストをやってからの経過日数とする
    rep(i,D){
        rep(j,26){
            int stmp=0;
            cin>>stmp;
            s[i][j]=stmp;
        }
    }
    vector<int> ans;
    //減少量が一番少なくなるように割り当てる
    //作戦.「(テストiをやった時の増加量-残りのテストに対する減少量)が一番多いテストをやる」

    rep(i,D){
        //i日目にやるやつを決める
        int testnum=0;
        long long  minusmax=0;
        long long minusmaxtmp=-100000000000;
        rep(j,26){
            //テストjをやった時の満足度の増減量を調べる
            minusmax=s[i][j];
            rep(k,26){
                if(k!=j){
                    minusmax+=-1*c[k]*(last[k]+1);//もしやらなかったらなので1足す
                }
            }
            if(minusmax>minusmaxtmp){
                testnum=j;
                minusmaxtmp=minusmax;
            }
        }
        //i日目にtestnum番のテストをやることに決めたので
        //testnum番以外のlastを1増やす,testnum番は0に戻る
        rep(j,26){
            if(j!=testnum){
                last[j]++;
            }else{
                last[j]=0;
            }
        }
        ans.push_back(testnum+1);

    }
    rep(i,D){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		if (A[A.length-1] == B[0] && B[B.length-1] == C[0])
			System.out.println("YES");
		else System.out.println("NO");
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

string ans;
vector<ll> vec;
vector<vector<pair<int,ll>>> graph;

void dfs(int now, ll d){
    if(vec[now]!=-INF && vec[now]!=d){
        ans="No";
        return;
    }
    if(vec[now]==d) return;
    
    vec[now]=d;
    
    for(auto p:graph[now]){
        dfs(p.first,d+p.second);
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    graph.resize(n);
    vec.resize(n);
    rep(i,0,n) vec[i]=-INF;
    ans="Yes";
    
    rep(i,0,m){
        int l,r;
        ll d;
        cin>>l>>r>>d;
        l--;r--;
        graph[l].emplace_back(r,d);
        graph[r].emplace_back(l,-d);
    }
    
    rep(i,0,n){
        if(vec[i]==-INF) dfs(i,0);
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 15488
#include<stdio.h>
int main(){
  int n,m,p[1010],g,i,j;
  char h[1010][10],s[10];
  while(scanf("%d %d",&n,&m),n){
    for(i=g=0;i<n;i++)scanf("%s %d",h[i],&p[i]);
    while(m--){
      scanf("%s",s);
      for(j=0;j<n;j++){
	for(i=0;i<8;i++){
	  if(h[j][i]=='*')continue;
	  if(h[j][i]-s[i])break;
	}
	if(i==8)g+=p[j];
      }
    }
    printf("%d\n",g);
  }
  return 0;
}

Measured memory_bytes: 612
#include <iostream>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int ans = 0;
  if (s[0] == '1')
    ans++;
  if (s[1] == '1')
    ans++;
  if (s[2] == '1')
    ans++;
  cout << ans << endl;
  return 0;
}

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

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

    vector<int> a(H), b(W);
    set<pair<int, int>> bomb;
    rep(i, m){
        int h, w;
        cin >> h >> w;
        h--; w--;
        bomb.insert({h, w});
        a[h]++;
        b[w]++;
    }

    int res1 = 0, res2 = 0;
    int ans = 0;
    rep(i, H)
        res1 = max(res1, a[i]);
    rep(i, W)
        res2 = max(res2, b[i]);
    vector<int> p, q;
    rep(i, H)
        if (a[i] == res1) p.pb(i);
    rep(i, W)
        if (b[i] == res2) q.pb(i);
    if (p.size() * q.size() > m){
        cout << res1 + res2 << endl;
        return 0;
    }
    rep(i, p.size()){
        rep(j, q.size()){
            if (bomb.count({p[i], q[j]}))
                ans = max(ans, res1 + res2 - 1);
            else ans = max(ans, res1 + res2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23760
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int N;
	vector<char> sig;
	
	for (int i=0; i<26; i++) sig.push_back((char)('a'+i));
	for (int i=0; i<26; i++) sig.push_back((char)('A'+i));
	

	while (cin>>N, N) {
		vector<int> list(N);
		string S;
		
		for (int i=0; i<N; i++) {
			cin>>list[i];
		}
		
		cin>>S;
		
		for (int i=0; i<S.size(); i++) {
			int t = find(sig.begin(), sig.end(), S[i])-sig.begin();
			int key = list[i%list.size()];
			
			cout << sig[(t-key+52)%52];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1220
a ,b ,m= map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
s = []
for i in range(m):
    s.append(list(map(int,input().split())))


ans = [min(alist)+min(blist)]

for i in range(m):
    x = s[i][0]
    y = s[i][1]
    c = s[i][2]
    p = alist[x-1] + blist[y-1] - c
    ans.append(p)

print(min(ans))

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

using Lint=long long;

int main()
{
   int N; cin>>N;
   string s; cin>>s;
   int ans=0;
   for(int i=0;i+3<=N;i++){
      if(s.substr(i,3)=="ABC") ans++;
   }
   cout<<ans<<endl;
   return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 500'005;

ll addM(ll a, ll b){
	return (a + b) % MOD;
}

ll mulM(ll a, ll b){
	ll temp = ((a % MOD) * (b % MOD)) % MOD;
  	return temp;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a % MOD;
  	else if(b%2==0) return mulM(powM(a, b/2), powM(a, b/2));
  	else return mulM(a, mulM(powM(a, (b-1)/2), powM(a, (b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a, powM(b, MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/


void Main(){
    ll n, m; cin >> n >> m;
    ll k =  m - n;
    // a(m, n) = (m-1) * (a(m-2, n-2) + a(m-1, n-1))
    // a(i, 0) = 0
    // a(i, 1) = i - 1
    
    vll dp(n + 5);
    dp[0] = 1;
    dp[1] = k;
    rep(i, n) {
        ll tmp1 = mulM(i + k + 1, dp[i + 1]);
        ll tmp2 = mulM(i + 1,  dp[i]);
        dp[i + 2] = addM(tmp1, tmp2);
    }
    // rep3(i, 0, n) cout << dp[i] << " ";
    // cout << endl;
    
    ll ans = dp[n];
    rep3(i, k+1, m){
        ans = mulM(i, ans);    
    }
    cout << ans << endl;
	return;
}

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

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    string s, tmp;
    cin >> s;

    tmp = s;
    reverse(all(tmp));

    // 処理
    int top, tail;
    top  = s.find('A');
    tail = tmp.find('Z');

    // 出力
    cout << s.size() - tail - top << endl;

    return 0;
}


Measured memory_bytes: 900
#include<stdio.h>
int main(void)
{
    char op;
    int a,b;
    do{
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+'){
        printf("%d\n",a+b);
    }
    else if(op=='-'){
        printf("%d\n",a-b);
    }   
    else if(op=='*'){
        printf("%d\n",a*b);
    }   
    else if(op=='/'){
        printf("%d\n",a/b);
    }
    }while(op!='?');
return 0;
}

Measured memory_bytes: 600
N = int(input())
K = int(input())
n = N 
ans = n
c = 0
co = 0

while n > 10: #桁数を数える
    c = c + 1 
    n = n // 10
#print(c)
while c > -1: #上の桁から見ていく
    m = N // (10 ** c)
    d = m % 10
    #print(m)
    #print(d)
    if d == 1: # 1がどこまで連続しているかを調べる
        co = co + 1
    else:      #初めて1以外の数がでてきたらそれを一旦答えとする
        ans = d 
        break
    c = c - 1
if K <= co: #1が連続しているところを答える場合は答えは1
        ans = 1

print(ans)

Measured memory_bytes: 3064
n, t=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)

tot=0
n.times do |i|
  if i+1<n
    if a[i+1]-a[i]<t
      tot+=(a[i+1]-a[i])
    else
      tot+=t
    end
  else
    tot+=t
  end
end

puts tot

Measured memory_bytes: 16004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll h;
    ll d = 1;
    ll ans = 0;
    cin >> h;
    while(h!=0){
        ans += d;
        h /= 2;
        d *= 2;
    }
    cout << ans << endl;
}

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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    string S;
    cin >> S;
    cout << S;
    int N = S.size();
    if (S[N - 1] == 's')
        cout << "es";
    else
        cout << "s";
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

const LL inf = 11234567890123456;
LL N, M;
std::vector<LL>a;
long double memo[512][512];

long double dp(LL p, LL c)
{
	if (p == N + 1)
	{
		if (c > M) return -inf;
		return 0;
	}
	if (memo[p][c] != -1.) return memo[p][c];
	long double res = -inf;
	for (LL w = 1; w <= N; ++w)
	{
		if (p + w - 1 >= N + 1) break;
		res = std::max(res, dp(p + w, c + 1) + (a[p + w - 1] - a[p - 1]) / (long double)w);
	}
	return memo[p][c] = res;
}

int main()
{
	in >> N >> M;
	a.resize(N + 1);
	rep(i, N) in >> a[i + 1];
	rep(i, N) a[i + 1] += a[i];
	rep(i, 512) rep(j, 512) memo[i][j] = -1.;
	out << std::fixed << std::setprecision(6);
	out << dp(1, 0) << std::endl;
	return 0;
}


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

//solution:
signed main() {
	int n, count, moves = 0; cin >> n, count = n;
  	string s; cin >> s;
  	for(int i = n - 1; ~i; --i) count -= (s[i] == 'W');
  	for(int i = 0; i < count; ++i) moves += (s[i] == 'W');
  	cout << moves << "\n";
  	return 0;
} //farewell, until we meet again..

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  int a[3][3];
  int n;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  cin >> n;
  int b[n];
  for (int k = 0; k < n; k++) {
    cin >> b[k];
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (a[i][j] == b[k]) {
          a[i][j] = 0;
        }
      }
    }
  }
  int flag = 0;
  //横みる
  for (int i = 0; i < 3; i++) {
    if (a[i][0] == 0) {
      if (a[i][1] == 0) {
        if (a[i][2] == 0) {
          flag++;
        }
      }
    }
  }
  //縦見る
  for (int i = 0; i < 3; i++) {
    if (a[0][i] == 0) {
      if (a[1][i] == 0) {
        if (a[2][i] == 0) {
          flag++;
        }
      }
    }
  }
  //斜め見る
  if (a[0][0] == 0) {
    if (a[1][1] == 0) {
      if (a[2][2] == 0) {
        flag++;
      }
    }
  }
  if (a[0][2] == 0) {
    if (a[1][1] == 0) {
      if (a[2][0] == 0) {
        flag++;
      }
    }
  }
  if (flag != 0) {
    cout << "Yes";
  }
  if (flag == 0) {
    cout << "No";
  }
  return 0;
}

// g++ lo.cpp
// ./a.exe
// g++ -o つくりたいふぁいるめい　もとのふぁいる.cpp

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
//#include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using G = greater<T>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, G<T> >;

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

const int INF = 2e9;
const LL MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, W;
  cin >> N >> W;
  VLL v(N), w(N);
  REP(int, i, N) cin >> w[i] >> v[i];
  VVLL dp(N+1, VLL(100001, INF));
  dp[0][0] = 0;
  REP(int, i, N) REP(int, j, 100001)
  {
    dp[i+1][j] = dp[i][j];
    if (j-v[i] >= 0) chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
  }
  
  REPR(int, j, 100001)
  {
    if (dp[N][j] <= W)
    {
      cout << j << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin >> k >> a >> b;
  int re;
  if(a%k==0) cout << "OK" << endl;
  else{
    re=a/k;
    if(re<b/k) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
}


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

const int N = 3e5 + 9;

int a[N], vis[N], id[N];
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; long long k; cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	vis[1] = 1;
	id[1] = 0; int nw = 1; vector<int> v; v.push_back(1);
	while (1) {
		int p = a[nw];
		if (vis[p]) {
			int s = id[p];
			if (k <= s) cout << v[k] << '\n';
			else {
				k -= s;
				k %= ((int)v.size() - s);
				cout << v[s + k] << '\n';
			}
			return 0;
		}
		vis[p] = 1;
		id[p] = id[nw] + 1;
		nw = p;
		v.push_back(p);
	}
    return 0;
}

Measured memory_bytes: 6552
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll n;cin>>n;
    vll a(n); REP(i,n) cin>>a[i];
    map<ll,ll> mp;
    REP(i,n){
        mp[a[i]-1]++;
        mp[a[i]]++;
        mp[a[i]+1]++;
    }
    ll ans = 0;
    for(auto p:mp){
        ans = max(ans,p.second);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9984
#include <iostream>
using namespace std;
int main(){
  	int n;
  cin>>n;
  for(int i=1;i<10;i++){
   	for(int j=i;j<10;j++){
     	if(n==i*j){
         	cout<<"Yes"<<endl;
          return 0;
        }
    }
  }
  cout<<"No"<<endl;
  	
 	 
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
int dis[303][303];
bool notneed[303][303];
int main(){
  	int n;
	cin>>n;
  	for(int i=1;i<=n;++i){
    	for(int j=1;j<=n;++j){
    		cin>>dis[i][j];
    	}
  	}
  	bool flag=true;
  	for(int i=1;i<=n;++i){
    	for(int j=1;j<=n;++j){
      		for(int k=1;k<=n;++k){
    			if(i!=j&&j!=k&&k!=i){
      				if(dis[i][j]+dis[j][k]<dis[i][k])flag=false;
      				if(dis[i][j]+dis[j][k]==dis[i][k])notneed[i][k]=true;
    			}
      		}
    	}
  	}
  	if(!flag){
    	printf("-1\n");
  	}else{
    	long long ans=0;
    	for(int i=1;i<=n;++i){
      		for(int j=i+1;j<=n;++j){
    			if(!notneed[i][j])ans+=dis[i][j];
      		}
    	}
    	printf("%lld\n",ans);
  	}
  	return 0;
}

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

ll val[10][10];
ll n;
int len;
ll ans;

int get_dig(ll k) {
  int cnt = 1;
  while ((k /= 10) != 0) ++cnt;
  return cnt;
}

void set_val() {
  ll p = 1;
  for (int i = len-1; i >= 0; --i) {
    p *= 10;
    val[i][len-1] = n % p;
  }
  for (int i = len-1; i >= 0; --i) {
    for (int j = len-2; j >= i; --j) {
      val[i][j] = val[i][j+1] / 10;
    }
  }
}

void dfs(ll sum, int l, int d) {
  if (d == len) {
    if (l == len) ans += sum;
    return;
  }
  dfs(sum + val[l][d], d+1, d+1);
  dfs(sum, l, d+1);
}

int main() {
  cin >> n;
  len = get_dig(n);
  set_val();
  dfs(0, 0, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int a, b;
    cin >> a >> b;
    int ret = 0;
    FOR(i, 0, 2) {
        if (a > b) {
            ret += a;
            a--;
        } else {
            ret += b;
            b--;
        }
    }
    cout << ret << endl;

    return 0;
};


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char S[100];
  scanf("%s", &S);
  int length = 0;
  while(S[length] != NULL){
    length++;
  }
  int ans = 0;
  // 1
  for(int i = 0; i < length / 2; i++){
    if(S[i] != S[(length - 1) - i]) {
      ans = -1;
      break;
    }
  }
  // 2
  for(int i = 0; i < (length - 1) / 2; i++){
    if(S[i] != S[(length - 1) / 2 - 1 - i]) {
      ans = -1;
      break;
    }
  }
  // 3
  for(int i = 0; i < length / 2; i++){
    if(S[(length + 3) / 2 - 1 + i] != S[length - 1 - i]) {
      ans = -1;
      break;
    }
  }
  if(ans == -1) printf("No");
  else printf("Yes");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

int ans =0;
void cnt(int n, string s, char add){
  int a,b,c;
  a = b = c = 0;
  s+=add;

  for(int i = 0; i < s.length();i++){
    if(s[i] == '3')
      a++;
    else if(s[i] == '5')
      b++;
    else if(s[i] == '7')
      c++;
  }
  if(a && b && c )
    ans++;
  double ab  = stoi(s);

  if(ab*10+3 <=n)
    cnt(n,s,'3');
  if(ab*10+5 <=n)
    cnt(n,s,'5');
  if(ab*10+7 <=n)
    cnt(n,s,'7');

}

int main()
{
  int n;
  string s;
  cin >> n;

  cnt(n,s,'3');
  cnt(n,s,'5');
  cnt(n,s,'7');

  cout << ans << endl;


    return 0;
}


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

namespace cswork {
    class Program {
        static void Main (string[] args) {
                        long n = Read();
            HashSet<string> set = new HashSet<string>();

            for(int i=0; i<n; i++){
                set.Add(ReadStr());
            }

            Write(set.Count);
            
            Exit ();
        }

        public static void Write (string str) {
            Console.WriteLine (str);
        }

        public static void Write (int i) {
            Console.WriteLine (i);
        }

        public static void Write (double d) {
            Console.WriteLine (d);
        }

        public static string ReadStr () {
            return Console.ReadLine ();
        }

        public static int ReadInt () {
            return int.Parse (Console.ReadLine ());
        }

        public static long Read () {
            return long.Parse (Console.ReadLine ());
        }

        public static double ReadDouble () {
            return double.Parse (Console.ReadLine ());
        }

        public static void Exit () { }

        public static List<string> ReadListStr () {
            return new List<string> (ReadStr ().Split (" "));
        }

        public static List<long> ReadList () {
            return ReadListStr ().ConvertAll (x => long.Parse (x));
        }
    }
}

Measured memory_bytes: 47184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string[] values = Console.ReadLine().Split(' ');
			int[] nums = new int[n];
			for (int i = 0; i < n; i++)
			{
				nums[i] = int.Parse(values[i]);
			}

			Array.Sort(nums);
			int diff =  nums[n / 2 ]- nums[(n / 2)-1];

			Console.WriteLine(diff.ToString());
	}
}

Measured memory_bytes: 18912
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  1000005
#define endl "\n"
using namespace std;
ll n;
vector<double>v;
vector<vector<double> >dp(3000,vector<double>(3000,-1));
double rec(int i, int w){
    if(i==n&&w>n/2)
        return 1;
    if(i==n)
        return 0;
    if(dp[i][w]!=-1)
        return dp[i][w];
    double ans=v[i]*rec(i+1,w+1)+(1-v[i])*rec(i+1,w);
    return dp[i][w]=ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    double p;
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>p;
        v.pb(p);
    }
    double ans=rec(0,0);
    cout<<fixed<<setprecision(10)<<ans<<endl;

    return 0;
}



Measured memory_bytes: 72960
#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.at(i);
}
int ans=0;
bool odd=true;
while(odd==true) {
    for(int i=0; i<n; i++){
    if(A[i]%2==1){
        odd=false;
     break;
    }
    }
    for(int i=0; i<n; i++){
   A[i]/=2;
    }
    ans++;
}
ans--;
cout<<ans<<endl;
}

Measured memory_bytes: 3636
# include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

long long *value, *weight, dp[100005][102]={};

int main()
{
	fast;
    long long n,w;
    cin>>n>>w;
    value = new long long[n+1];
    weight = new long long[n+1];
    long long sum=0;
    for(int i=0; i<n; i++){
        cin>>weight[i+1]>>value[i+1];
        sum+=(long long)value[i+1];
    }

    for(int i=0; i<=sum;i++)dp[i][0]=2e10;
    dp[0][0]=0;
    int ans=0;
    for(int i=1; i<=n; i++){
    	for(int j=1; j<=sum; j++){
    		if(j-value[i]>=0)
    		dp[j][i]=min(dp[j][i-1], dp[j-value[i]][i-1]+weight[i]);
    		else dp[j][i] = dp[j][i-1];

    		if(w>=dp[j][i] && j>ans){

                ans=j;
    		}

		}
    }
    cout<<ans;
////	}

//    for(int i=1; i<=100; i++){
//    	for(int j=1; j<=n; j++){
//    		cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
//    cout<<dp[w][n];
    return 0;
}



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

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

using namespace std;

typedef long long ll;
unordered_map<ll,int> mp;
int maxi,N,c[10][10], dig[] = {0,1,2,3,4,5,6,7,8,9};

ll toInt(string s) {
  ll ret = 0;
  rep(i,(int)s.size()) { ret *= 10LL; ret += (s[i]-'0'); }
  return ret;
}

struct Data {
  string s;
  int cost;
  bool operator < ( const Data& data ) const {
    return cost > data.cost;
  }
};

typedef pair<int,int> ii;

void compute(){
  mp.clear();
  string init = "";
  REP(i,1,N+1) init += string(1,(char)('0'+i));
  mp[toInt(init)] = 0;
  priority_queue<Data> Q;
  Q.push((Data){init,0});
  while( !Q.empty() ){
    Data data = Q.top(); Q.pop();
    ll temp_index = toInt(data.s);
    if( mp.count(temp_index) && mp[temp_index] < data.cost ) continue;
    rep(i,N) REP(j,i+1,N) {
      swap(data.s[i],data.s[j]);
      temp_index = toInt(data.s);
      if( ( mp.count(temp_index) && mp[temp_index] > data.cost + c[i][j] ) || !mp.count(temp_index) ) {
        mp[temp_index] = data.cost + c[i][j];
        Q.push((Data){data.s,mp[temp_index]});
      }
      swap(data.s[i],data.s[j]);
    }
  }
  for(unordered_map<ll,int>::iterator it = mp.begin(); it != mp.end(); it++){
    maxi = max(maxi,it->second);
  }
  printf("%d\n",maxi);
}

int main(){

  cin >> N;
  rep(i,N) rep(j,N) cin >> c[i][j];
  compute();

  return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, A, X[55];
ll DP[55][55][2525];

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

  DP[0][0][0] = 1;
  for (int i = 1; i <= N; i++){
    for (int j = 0; j <= N; j++){
      for (int k = 0; k <= 2500; k++){
        DP[i][j][k] += DP[i-1][j][k];
        if (k + X[i] <= 2500) DP[i][j+1][k+X[i]] += DP[i-1][j][k]; 
      }
    }
  }

  ll ans = 0;
  for (int j = 1; j <= 50; j++){
    ans += DP[N][j][j*A];
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 55112