akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);

            string ans = "Yay!";
            if (A > 8 || B > 8)
            {
                ans = ":(";
            }

            Console.WriteLine(ans);
            Console.ReadLine();

        }
    }
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int n;
    cin >> n;
    VL av(n);
    REP(i, n) {
        cin >> av[i];
        if (av[i] == 0) {
            cout << 0 << en;
            return;
        }
    }
    ll ans = 1;
    REP(i, n) {
        if (ans > 1000000000000000000 / av[i]) {
            cout << -1 << en;
            return;
        }
        ans *= av[i];
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3992
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

int ordena(void const *a, void const *b) {

    return ( *(int*)a - *(int*)b );

}

int main() {

    int n;

    scanf("%d", &n);

    int vetor[n];

    for (int i=0; i<n; ++i)

        scanf("%d", &vetor[i]);

    qsort(vetor, n, sizeof(vetor[0]), ordena);

    printf("%d\n", vetor[n-1]-vetor[0]);

    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <bitset>
 
using namespace std;
typedef long long ll;

#define pb push_back
#define fe first
#define se second
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef __APPLE__
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    int val=7%n;
    for(int i =1; i<1e7; ++i){
        if(val==0){
            cout << i;
            return 0;
        }
        val=(val*10+7)%n;
    }
    cout << -1;

}

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX_N = 100000;
int n;
vector<int> a, b, c;

int main(){
  cin >> n;
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    a.push_back(x);
  }

  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    b.push_back(x);
  }
  
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    c.push_back(x);
  }

  // sort
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  long long ans = 0;
  for(int i=0; i<n; i++){
    long long an = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    long long cn = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    ans+=an*cn;
  }

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


Measured memory_bytes: 1912
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
ll a,b;
char c;
cin >> a >> c >> b;
if(c=='+') {
  cout << a+b << endl;
} else {
  cout << a-b << endl;
}
return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
  /// Return `true` if the slice was permuted, `false` if it is already
  /// at the last ordered permutation.
  fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
  /// Original author in Rust: Thomas Backman <serenity@exscape.org>
  fn next_permutation(&mut self) -> bool {
    // These cases only have 1 permutation each, so we can't do anything.
    if self.len() < 2 { return false; }

    // Step 1: Identify the longest, rightmost weakly decreasing part of the vector
    let mut i = self.len() - 1;
    while i > 0 && self[i-1] >= self[i] {
      i -= 1;
    }

    // If that is the entire vector, this is the last-ordered permutation.
    if i == 0 {
      return false;
    }

    // Step 2: Find the rightmost element larger than the pivot (i-1)
    let mut j = self.len() - 1;
    while j >= i && self[j] <= self[i-1]  {
      j -= 1;
    }

    // Step 3: Swap that element with the pivot
    self.swap(j, i-1);

    // Step 4: Reverse the (previously) weakly decreasing part
    self[i..].reverse();

    true
  }
}
fn main() {
  let s: String = read();
  if check(&s) {
    if check(&s[..s.len()/2].to_string()) && check(&s[(s.len()/2+1)..].to_string()) {
      println!("Yes");
    } else {
      println!("No");
    }
  } else {
    println!("No");
  }

}

fn check(s: &String) -> bool {
  let s: Vec<char> = s.chars().collect();
  let mut ok = true;
  for i in 0..(s.len()/2) {
    if(s[i] != s[(s.len()-1)-i]) { ok = false; }
  }
  ok
}

Measured memory_bytes: 4352
#![allow(dead_code)]
#![allow(non_snake_case)]

//use std::collections::HashMap;

const PRM: u64 = 1_000_000_007;

fn main(){
    let n: u64 = input();
    let mut counter = [0,0,0,0];
    for _ in 0..n {
        let s: String = input();
        match &*s {
            "AC" => counter[0] += 1,
            "WA" => counter[1] += 1,
            "TLE" => counter[2] += 1,
            "RE" => counter[3] += 1,
            _ => println!("bad input")
        }
    }
    println!("AC x {}", counter[0]);
    println!("WA x {}", counter[1]);
    println!("TLE x {}", counter[2]);
    println!("RE x {}", counter[3]);
}


/*
 *
 * input functions
 *
 */
 fn input<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


fn input_vec<T: std::str::FromStr>() -> Vec<T> {
    input::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap()).collect()
}

fn input_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| input_vec()).collect()
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int  long long int
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define hell 1000000007  
#define hell2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int n,a;
    vector<int> v;
    cin>>n;
    string s="abcdefghijklmnopqrstuvwxyz";
    while(n>0){
        //cout<<((n%26)-1)<<" ";
        v.pb((n%26)-1);
        if(n%26==0) n--;
        n=n/26;
    }
    //cout<<v.size()<<"\n";
    repn(i,v.size()-1,0){
        if(v[i]==-1) cout<<"z";
        else cout<<s[v[i]];
    } 
    return 0;
    
    
}   
     
signed main(){
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output3.txt", "w", stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
//    return 0;
} 

Measured memory_bytes: 3648
import java.util.Scanner;
public class Main{
     
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int a,b;
        a = sc.nextInt();
        b = sc.nextInt();
         
        System.out.println((a*b)+" "+(a*2+b*2));
         
    }
     
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17160
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;

int a, b, c;

int main() {
	cin >> a >> b >> c;
	if (a == b) 
		if (b == c)
			cout << "No";
		else
			cout << "Yes";
	else
		if (a == c || b == c)
			cout << "Yes";
		else 
			cout << "No";
	return 0;
}


Measured memory_bytes: 256
import sys
import collections
import bisect


def main():
    k = [list(map(int, input().split())) for _ in range(3)]

    c = collections.Counter(k[0] + k[1] + k[2])
    print('YES' if sorted(c.values()) == [1, 1, 2, 2] else 'NO')


if __name__ == '__main__':
    main()


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

int main(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) cin >> vec.at(i);
	sort(vec.begin(), vec.end());
	int a, b;
	a = vec.at((n / 2) - 1);
	b = vec.at(n / 2);
	if (a == b) cout << 0 << endl;
	else cout << b - a << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef tuple<int,int,bool> Tb;


int atcoder(){
    //入力
    int n;
    cin >> n;
    
    
    //処理
    
    //出力
    cout << RUP(n,111)*111 << ENT;
    return 0;
}

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


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int A, B, T;
    cin >> A >> B >> T;
    int ans = B * (T/A );
    cout << ans << endl;
    return 0;
}


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

vector<pair<long long, long long> > prime_factorize(long long N) {
  vector<pair<long long, long long> > res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1) res.push_back({N, 1});
  return res;
}


// cout << "hogehoge" << '\n';  // "endl" executes flush in addition to line break.
int main() {
  cin.tie(nullptr);               // Do not flush "cout" when processing "cin".
  // ios::sync_with_stdio(false); // Be careful when using both "cin/cout" and "scanf/printf".

  int n;
  cin >> n;

  const int max = 1e6;

  vector<int> v(max+1);
  for (int i = 1; i <= max; i++) {
    // i=12 の場合
    //   { {2, 2}, {3, 1} }
    // i=1000 の場合
    //   { {2, 3}, {5, 3} }
    const auto &res = prime_factorize(i);
    int x = 1;
    for (auto p : res) {
      x = x * (p.second+1);
    }
    v.at(i) = x;
  }

  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans = ans + v.at(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  for(int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
    
    if(i == N - 1){
      cout << sum << endl;
    }
  }
  
    
}

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

int main(){
    long long k,a,b;cin>>k>>a>>b;

    if (k <= a){
        cout << k + 1 << endl;
        return 0;
    }
    long long delta = b - a;

    long long acc = 0;
    if (delta > 2){
        k -= a - 1;
        acc += a;
        if (k % 2 == 0){
            acc += delta * (k / 2);
        } else {
            acc++;
            k--;
            if (k != 0){
                acc += delta * (k / 2);
            }
        }
    } else {
        acc += k + 1;
    }
    cout << acc << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int bubblesort[100],N,i,j,exist=1,count=0,rep;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&bubblesort[i]);
  
  }

  while(exist==1){
    exist=0;
    for(j=N-1;j>=1;j--){
     
      if(bubblesort[j]<bubblesort[j-1]){
	rep=bubblesort[j-1];
	bubblesort[j-1]=bubblesort[j];
	bubblesort[j]=rep;
	exist=1;
	count++;
      }
    }
  }

  for(i=0;i<N;i++){

    if(i!=N-1)printf("%d ",bubblesort[i]);
    else printf("%d",bubblesort[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2144
import scala.io.StdIn

object Main {
	def main(args: Array[String]): Unit ={
		val num = StdIn.readLine.split(" ").map(_.toInt)
		val N = num(0)
		val T = num(1)

		val roots = (1 to N).foldLeft(Seq.empty[(Int, Int)]){ (seq, tuple) =>
			val num = StdIn.readLine.split(" ").map(_.toInt)
			val c = num(0)
			val t = num(1)
			seq :+ (c,t)
		}

		val rootsWithinT = roots.filter(_._2 <= T)
		val result = if (rootsWithinT.isEmpty) "TLE"
		             else rootsWithinT.map(_._1).min.toString
		
		println(result)
	}
}

Measured memory_bytes: 27200
#D問題
N,M=map(int,input().split())
XYZ=[list(map(int,input().split())) for i in range(N)]
MAX=0
for i in range(8):
    b=bin(i)
    b=b.lstrip("0b")
    while len(b)<3:
        b="0"+b
    blist=list(b)
    A=[0 for i in range(N)]
    if blist[0] == "0":
        for i in range(N):
            A[i]+=XYZ[i][0]
    else:
        for i in range(N):
            A[i]+=(-1*XYZ[i][0])
    if blist[1] == "0":
        for i in range(N):
            A[i]+=XYZ[i][1]
    else:
        for i in range(N):
            A[i]+=(-1*XYZ[i][1])
    if blist[2] == "0":
        for i in range(N):
            A[i]+=XYZ[i][2]
    else:
        for i in range(N):
            A[i]+=(-1*XYZ[i][2])
    A.sort()
    kari=0
    for i in range(M):
        kari+=A[i]
    MAX=max(abs(kari),MAX)
print(MAX)

Measured memory_bytes: 3316
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

#include "bits/stdc++.h"
using namespace std;

#define ll long long
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[N];

void solve()
{    
    ll n, m ;
    cin >> n >> m;
    vector<int> v[n+1], parent(n+1,0) ;
    for(int i=0; i<m; i++){
    	int l, r; 
    	cin >> l >> r ;
    	v[l].push_back(r);
    	parent[r]++;
    }

    queue<pair<int,int>> q; 
    for(int i=1; i<=n; i++){
    	if(!parent[i])q.push({i,0});
    }
    int maxm = 0 ;

    while(!q.empty()){
    	auto it = q.front();q.pop();
    	//cout<<it.first<< " "<<it.second<<"\n";
    	maxm = max(maxm , it.second);
    	for(auto itt: v[it.first]){
    		parent[itt]--;
    		if(parent[itt]==0){
    			q.push({itt,it.second+1}) ;
    		}
    	}
    }
    cout<<maxm;

}

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


// Xorawar

Measured memory_bytes: 9076
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,y;
  cin>>x>>y;
  bool f=false;
  for(int i=0;i<=x;i++)
  {
    int b=x-i;
    if(2*i+4*b==y)
      f=true;
  }
  if(f)
    cout<<"Yes";
  else
    cout<<"No";
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

ll N;
vector<string> ans;

void dfs(string s){
    if(s.size() == N)ans.PB(s);
    else{
        if(int(s[s.size()-1] - '0') != 0)rep(i,int(s[s.size()-1] - '0'),10){
            dfs(s + to_string(i));
        }
        dfs(s + to_string(0));
    }
}

int main(){
    ll M,Q;
    cin>>N>>M>>Q;
    vv a(Q,v(4));
    rep(i,0,Q){
        rep(j,0,4)cin>>a[i][j];
        a[i][0]--;
        a[i][1]--;
    }
    ll sum;
    ll sum_ans =0;
    dfs("1");
    dfs("2");
    dfs("3");
    dfs("4");
    dfs("5");
    dfs("6");
    dfs("7");
    dfs("8");
    dfs("9");
    dfs("0");
    rep(i,0,ans.size()){
        sum = 0;
        ll b,c;
        rep(j,0,Q){
            b = ll(ans[i][a[j][1]]-'0');
            c = ll(ans[i][a[j][0]]-'0');
            if(b == 0)b=10;            
            if(c == 0)c=10;
            if(b > M || c>M)continue;         
            if((b-c) == a[j][2]){
                sum += a[j][3];
            }
        }
        sum_ans = max(sum_ans,sum);
    }
    //rep(i,0,5)cout<<ans[i];
    cout<<sum_ans;
    return 0;
}

Measured memory_bytes: 7532
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

bool check(string s) {
	int x = 0, y = 0;
	bool last = false;
	FOR(i, s.size()) {
		if (last) return false;
		if (s[i] == 'A') x++;
		else y++;
		int mn = min(x, y), mx = max(x, y);
		if (mx == 5) {
			if (mn + mx != 9) last = true;
		}
	}
	return true;
}

int main() {
	int a, b; cin >> a >> b;

	string s;
	FOR(i, a) s.push_back('A');
	FOR(i, b) s.push_back('B');

	do {
		bool b = check(s);
		if (b) {
			cout << s << endl;
		}
	}
	while (next_permutation(s.begin(), s.end()));

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007

#define INF 100000000


int main() {
    
    string s; cin >> s;
    bool flag = 1;
    for(int i = 0; i < s.size(); i+=2) {
        if(s[i] == 'L' ) flag = false;
        if(s[i+1] == 'R') flag = false;
    }
    if(flag) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

# Yesならば aの任意の2要素の差は高々1である
# 小さい方の値を発言している猫はそれぞれ異なる帽子を被る必要がある
# 大きい方の値を発言している猫は同じ帽子を被る猫が少なくとも他に一匹存在する必要がある
L = min(a)
R = max(a)
ans = (
    'Yes' if R - L == 0 and (N >= 2 * L or N == L + 1) or
    R - L == 1 and 2 * (L + 1) - N <= sum(x == L for x in a) <= L else
    'No'
)

print(ans)


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

using namespace std;

long long gcd (long long a, long long b) {
  if (b == 0)
  return a;
  else return gcd(b, a % b);
}

int main()
{
    map <long long, long long> m;
    int n; cin >> n;
    long long res = 1;
    long long t;
    for (int i = 0; i < n; ++i)
    {
      cin >> t;
      res = res / gcd(res, t) * t;
    }

    cout << res << endl;

  return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/16  Problem: ABC 076 A / Link: http://abc076.contest.atcoder.jp/tasks/abc076_a  ----- */


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

	LL R, G; cin >> R >> G;


	LL ans = 2*G-R;
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,m=0,n=0,max=0,k=0;
    cin>>a;
    int b[a]={0},c[a]={0},d[a]={0};
    for(int i=0;i<a;i++) cin>>b[i];
    for(int i=0;i<a;i++){
        if(b[i]%10!=0) {c[k]=b[i]; k++;}
        else n+=b[i];
    }
    sort(c,c+a);
    for(int i=0;i<a;i++) m+=c[i];
    for(int i=0;i<a;i++){
        if(m%10==0&&c[i]!=0){
           m-=c[i];
           break;
        }
    }
    if((m+n)%10==0) cout<<0<<endl;
    else cout<<m+n<<endl;
}



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

using namespace std;

main(){
  int N,K,result = 0;
  vector<int> pr;
  cin >> N >> K;
  pr.resize(N);
  for(int i=0; i<N;i++){
    cin >> pr[i];
  }
  sort(pr.begin(), pr.end());
  for(int i=0; i<K;i++){
    result += pr[i];
  }
  cout<<result<<endl;
  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vl p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(all(p));
  sort(all(q));
  rep(i, x) r.push_back(p[a - i - 1]);
  rep(i, y) r.push_back(q[b - i - 1]);
  sort(all(r), greater<ll>());
  ll ans = 0;
  rep(i, x + y) ans += r[i];
  cout << ans << endl;
}

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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();
            var ss = s;
            for(int i = 1; i < 200; i++) {
                ss = ss.Remove(ss.Length - 1);
                if(ss.Length == 0) {
                    break;
                }
                if(ss.Length % 2 != 0) {
                    continue;
                }

                if(ss.Substring(0, ss.Length / 2) == ss.Substring(ss.Length / 2, ss.Length / 2)) {
                    Console.WriteLine(s.Length - i);
                    break;
                }
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 11092
# 

n=int(input())
a=list(map(int,input().split()))
A=set(a[1:])
res=[-1]*n

dct={}
for e in a:
    dct[e]=dct.get(e,0)+1
tmp=a[0]
res[0]=tmp
dct[tmp]-=1

for i in range(1,n):
    tmp=res[0]^a[i]
    if  dct.get(tmp,0)>0:
        res[1]=a[i]
        res[-1]=res[0]^a[i]
        dct[res[1]]-=1
        dct[res[-1]]-=1
        break
else:
    print('No')
    exit()


for i in range(1,n-2):
    x=res[i]
    y=res[i-1]
    tmp=x^y
    if dct.get(tmp,0)>0:
        res[i+1]=tmp
        dct[tmp]-=1
    else:
        print('No')
        exit()

if res[-2]^res[-3]==res[-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14708
import Text.Printf

main = do
    ss <- getLine
    let ns = map (\x -> read x:: Int) $ words ss
    let (a,b) = (ns!!0, ns!!1)
    let d = a `div` b
    let r = a `mod` b
    let f = ((fromIntegral a) / (fromIntegral b) :: Double)
    printf "%d %d %.5f\n" d r f


Measured memory_bytes: 3924
import sys
input = sys.stdin.buffer.readline
from collections import deque
N, M, L = map(int, input().split())
D = [[1<<40] * N for _ in range(N)]
for i in range(N):
    D[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a][b] = c
    D[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            D[i][j] = min(D[i][j], D[i][k] + D[k][j])
Y = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j: continue
        if D[i][j] <= L:
            Y[i].append(j)
def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D
D2 = []
for i in range(N):
    D2.append(BFS(N, Y, i))

ans = []
for _ in range(int(input())):
    s, t = map(int, input().split())
    a = D2[s-1][t-1]-1
    ans.append(str(a if a >= 0 else -1))
print("\n".join(ans))

Measured memory_bytes: 54364
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int A,c;
    char b;
    cin>>A>>b>>c;
    if(b=='+')cout<<A+c<<endl;
    else cout<<A-c<<endl;
}

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

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

int main(){
  int n,m;
  cin >> n >> m;

  int sum = 0;
  rep(i,m){
    int a;
    cin >> a;
    sum += a;
  }

  if (sum > n){
    cout << -1 << endl;
  }else{
    cout << n-sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
def convert(s): 
  
    # initialization of string to "" 
    new = "" 
  
    # traverse in the string  
    for x in s: 
        new += x  
  
    # return string  
    return new 
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
ans=[]
if a+b+c+d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b+c-d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b-c+d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a+b-c-d==7:
  ans.append(str(a))
  ans.append('+')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b+c+d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b+c-d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('+')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b-c+d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('+')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))
elif a-b-c-d==7:
  ans.append(str(a))
  ans.append('-')
  ans.append(str(b))
  ans.append('-')
  ans.append(str(c))
  ans.append('-')
  ans.append(str(d))
  ans.append('=7')
  print(convert(ans))

Measured memory_bytes: 3292
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1'000'000'007;
constexpr ll mod = 998244353;
const double PI = 3.14159265358;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int N;
  cin >> N;
  N += 2;
  vector<complex<double>> p(N+2);
  p[0] = complex<double>(sx,sy);
  p[N-1] = complex<double>(tx,ty);
  vector<double> r(N);
  r[0] = r[N-1] = 0;
  for(int i=1; i<N-1; i++){
    int x,y,z;
    cin >> x >> y >> z;
    p[i] = complex<double>(x,y);
    r[i] = z;
  } 
  vector<vector<double>> G(N+2, vector<double>(N+2));
  for(int i=0; i<N; i++){
    for(int j=i; j<N; j++){
      G[i][j] = G[j][i] = max(0.0,abs(p[i]-p[j]) - (r[i]+r[j]));
    }
  }
  using pdi = pair<double,int>;
  priority_queue<pdi,vector<pdi>,greater<pdi>> que;
  que.emplace(0,0);
  vector<double> dist(N,INF);
  dist[0] = 0;
  while(que.size()){
    double cost;
    int v;
    tie(cost,v) = que.top();
    que.pop();
    if(cost > dist[v]) continue;
    for(int nv=0; nv<N; nv++){
      double ncost = cost + G[v][nv];
      if(ncost < dist[nv]){
        dist[nv] = ncost;
        que.emplace(ncost,nv);
      }
    }
  }
  cout << fixed << setprecision(10) << dist[N-1] << "\n";
  return 0;
}

Measured memory_bytes: 15284
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

ll mod = 1e9 + 7;
ll dp[10005][2][103];

int main() {
	string s; cin >> s;
	int D; cin >> D;
	int n = s.size();
	dp[0][1][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int c = 0; c < D; c++) {
			for (int d = 0; d < s[i] - '0'; d++) {
				dp[i + 1][0][(c + d) % D] += (dp[i][0][c] + dp[i][1][c]) % mod;
				dp[i + 1][0][(c + d) % D] %= mod;
			}
			dp[i + 1][0][(c + s[i] - '0') % D] += dp[i][0][c];
			dp[i + 1][0][(c + s[i] - '0') % D] %= mod;
			dp[i + 1][1][(c + s[i] - '0') % D] += dp[i][1][c];
			dp[i + 1][1][(c + s[i] - '0') % D] %= mod;
			for (int d = s[i] - '0' + 1; d <= 9; d++) {
				dp[i + 1][0][(c + d) % D] += dp[i][0][c];
				dp[i + 1][0][(c + d) % D] %= mod;
			}
		}
	}
	cout << ((dp[n][0][0] + dp[n][1][0]) % mod  - 1 + mod)%mod << endl;

	return 0;
}

Measured memory_bytes: 16384
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;
 
int a[4], b[4], cnt[10]={0};
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    for (int i = 0; i < 3; i++) {
        cin >> a[i] >> b[i];
        ++cnt[a[i]];
        ++cnt[b[i]];
    }
    for (int i = 1; i <= 4; i++) {
        if (cnt[i] > 2) return cout << "NO", 0;
    }
    cout << "YES";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; a++) {
        for (int b = 0; b + a <= N; b++) {
            int c = N - a - b;
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }

    cout << res10000 <<  " " << res5000 << " " << res1000 << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,count=0,ans=0;
  cin>>n;
  for(int j=1;j<=n;j++){
    for(int i=1;i<=n;i++){
      if(j%i==0){
        count++;
      }
    }
    if(j%2==1 and count==8){
      ans++;
    }
    count=0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int n, a[100];
  int i, j, tmp;
  int cnt = 0;

  scanf("%d", &n);

  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);

  for (i = 0; i < n; i++) {
    for (j = 1; j < n - i; j++) {
      if (a[j - 1] > a[j]) {
        tmp = a[j - 1];
        a[j - 1] = a[j];
        a[j] = tmp;
        cnt++;
      }
    }
  }

  printf("%d", a[0]);
  for (i = 1; i < n; i++)
    printf(" %d", a[i]);
  printf("\n%d\n", cnt);

  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include <iomanip>
#include<algorithm>
using namespace std;
int main()
{
	
	int H[1000],W[1000],c[1000],d=1000,i;
	for( i=0;i<d;i++)
	{
		
	cin>>H[i]>>W[i];
	if(H[i]==0||W[i]==0)
		break;
	c[i]=H[i]*W[i];
	}
	for(int k=0;k<i;k++)
	{
		for(int j=1;j<=c[k];j++)
		{
			cout<<"#";
			if(j%W[k]==0)
				cout<<endl;
			
		}
		cout<<endl;
	
	
	}




	
}

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

using namespace std;

int main(){
	int N;
  	bool flg = true;
  
  	cin >> N;
  	vector<int> num(N);
  
  	for(int i; i < num.size(); i++){
      	cin >> num.at(i);
      
      	if(num.at(i) % 2 == 0){
      		if(!(num.at(i) % 3 == 0 || num.at(i) % 5 == 0)){
          		cout << "DENIED" << endl;
          		flg = false;
        		break;
        	}
        }
    }
    
    if(flg){
    	cout << "APPROVED" << endl;
    }
  
	return 0;
}

Measured memory_bytes: 3564
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// 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, ( $($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);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
    }
    if n.is_power_of_two() {
        puts!("No\n");
        return;
    }
    puts!("Yes\n");
    assert!(n >= 3);
    let mut p = 2;
    let mut edges = vec![];
    while p < n {
        edges.extend_from_slice(&[(1, p), (p, p + 1), (1, p + n + 1), (p + n, p + n + 1)]);
        p += 2;
    }
    if p == n {
        // realise n as ? ^ 1 ^ ?
        let mut q = 1;
        while q < n {
            q *= 2;
        }
        q /= 2;
        let other = n ^ q ^ 1;
        // q ^ 1 ^ other
        edges.extend_from_slice(&[(n, q), (other + n, 2 * n)]);
    }
    edges.push((3, 1 + n));
    assert_eq!(edges.len(), 2 * n - 1);
    for &(a, b) in &edges {
        puts!("{} {}\n", a, b);
    }
}

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: 15736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
queue <P> que;
const int maxn = 1010;
int h,w,ch,cw,dh,dw;
char c[maxn][maxn];
int vis[maxn][maxn];
int x[4] = {-1,0,1,0};
int y[4] = {0,1,0,-1};
vector<P> ans[maxn * maxn];

int main(){
    cin >> h >> w;
    cin >> ch >> cw >> dh >> dw;
    for(int i = 1;i<=h;i++){
        for(int j = 1;j<=w;j++){
            cin >> c[i][j];
        }
    }
    que.push(P(ch,cw));
    for(int i = 0;i<=h;i++){
        for(int j = 0;j<=w;j++){
            vis[i][j] = -1;
        }
    }
    int cnt = 0;
    vis[ch][cw] = 0;
    ans[cnt].push_back(P(ch,cw));
    while(true){
        bool isupdate = false;
        while(!que.empty()){
            P tmp = que.front();
            que.pop();
            int dx = tmp.first;
            int dy = tmp.second;
            if(dx == dh && dy == dw){
                cout << vis[dh][dw] << endl;
                return 0;
            }
            for(int i = 0;i<4;i++){
                int xx = dx + x[i];
                int yy = dy + y[i];
                if(xx >= 1 && xx <= h && yy >= 1 && yy <= w && vis[xx][yy] == -1 && c[xx][yy]!='#'){
                    que.push(P(xx,yy));
                    ans[cnt].push_back(P(xx,yy));
                    vis[xx][yy] = vis[dx][dy];
                }
            }
        }
        for(int i = 0;i<ans[cnt].size();i++){
            int dx = ans[cnt][i].first;
            int dy = ans[cnt][i].second;
            for(int j = -2;j<=2;j++){
                for(int k = -2;k<=2;k++){
                    int xx = dx + j;
                    int yy = dy + k;
                    if(xx >= 1 && xx <= h && yy >= 1 && yy <= w && vis[xx][yy]==-1 && c[xx][yy]!='#'){
                        que.push(P(xx,yy));
                        vis[xx][yy] = vis[dx][dy] + 1;
                        ans[vis[xx][yy]].push_back(P(xx,yy));
                        isupdate = true;
                    }
                }
            }
        }
        cnt++;
        if(vis[dh][dw]!=-1) break;
        if(!isupdate) break;
    }
    cout << vis[dh][dw] << endl;

    // for(int i = 1;i<=h;i++){
    //     for(int j = 1;j<=w;j++){
    //         cout << vis[i][j] <<" ";
    //     }
    //     cout << endl;
    // }


    return 0;
}

Measured memory_bytes: 37688
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
typedef    complex<ld>   P;
#define    X   real()
#define    Y   imag()
ld restant(P p){return abs(p);}
//polar(x,y) mag=l,arg=y
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pair<ll,ll> >   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pair<int,int> >   vpi;
typedef    vector<pair<double,double> >   vpd;
typedef    pair<double,double>   pd;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf   1000000000000000001
#define    ninf   -1000000000000000001
#define    ima   1000000001
#define    imi   -1000000001
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define all(x) x.be(),x.en()
#define    eps   1e-9
const    ld   PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return((a-b+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}

int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{	
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
	cin>>a[i];

}
sort(a,a+n);

int an=ima;
for(int i=a[0];i<=a[n-1];i++)
{
	int al=0;
	for(int j=0;j<n;j++)
	al+=(pow(abs(a[j]-i),2));
	
	an=min(al,an);
}

cout<<an;

}return 0;}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    S=input()
    n=len(S)
    pre=S[:n//2]
    suf=S[n-n//2::]
    suf=suf[::-1]
    ans=0
    for p,s in zip(pre,suf):
        ans+=(p!=s)
    print(ans)
resolve()

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


void solve(long long a, long long b, long long c, long long d, long long e, long long k){
    cout << ((e-a<=k) ? "Yay!" : ":(") <<endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    long long d;
    scanf("%lld",&d);
    long long e;
    scanf("%lld",&e);
    long long k;
    scanf("%lld",&k);
    solve(a, b, c, d, e, k);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

string S, T, U;
int A, B;

int main() {
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;
	if (S == U) {
		cout << A - 1 << " " << B << endl;
	}
	else {
		cout << A << " " << B - 1 << endl;
	}
}

Measured memory_bytes: 256
from collections import deque

N,Q = list(map(int,input().split()))

G=[]
for i in range(N):
    G.append([])
for i in range(N-1):
    a,b = list(map(int,input().split()))
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

p=[0]*Q
x=[0]*Q
c=[0]*N
for i in range(Q):
    p,x = list(map(int,input().split()))
    p-=1
    c[p] += x

stack=deque([0])
parent = [-1]*N

while(stack):
    v = stack.pop()
    for u in G[v]:
        if u!=parent[v]:
            c[u]+=c[v]
            parent[u]=v
            stack.appendleft(u)


ans = ' '.join([str(x) for x in c])

print(ans)

Measured memory_bytes: 124436
n, h = map(int, input().split())
A, B = [0]*n, [0]*n
for i in range(n):
  A[i], B[i] = map(int, input().split())
maxa = max(A)
c, d = 0, 0
for i in sorted(B)[::-1]:
  if i > maxa:
    c += i
    d += 1
    if c >= h:
      print(d)
      exit()

ans = d - (c-h)//maxa
print(ans)

Measured memory_bytes: 12532