akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};

fn main() {
    input! {
        n:usize, m:usize,
        lrd: [(usize1,usize1,i64); m]
    };
    
    let mut grp: HashMap<usize, Vec<(usize, i64)>> = HashMap::new();
    for &(l,r,d) in &lrd {
        match grp.entry(l) {
            Vacant(e) => { e.insert(vec![(r,d)]); },
            Occupied(mut e) => e.get_mut().push((r,d))
        };
        match grp.entry(r) {
            Vacant(e) => { e.insert(vec![(l,d * -1)]); },
            Occupied(mut e) => e.get_mut().push((l,d * -1))
        };
    };

    let mut chk: Vec<bool> = vec![false;n];
    let mut dst: Vec<i64> = vec![0;n];

    let ans = (0..n).fold(true, |ac, i| {
        if !chk[i] {
            ac && dfs(&grp ,&mut chk, &mut dst, i, 0)
        } else {
            ac
        }
    });

    if ans { println!("Yes") } else { println!("No") }
}

fn dfs(grp:&HashMap<usize, Vec<(usize, i64)>>, chk:&mut Vec<bool> , dst: &mut Vec<i64>, i:usize, d:i64) -> bool {
    let di = dst[i];
    if chk[i] {
        di == d
     } else {
        chk[i] = true;
        dst[i] = d;
        match grp.get(&i) {
            None => true,
            Some(e) => e.iter().fold(true, |ac, &(n,vv)| {
                    ac && dfs(grp, chk, dst, n, vv+d)
                })
        }
    }
}


Measured memory_bytes: 29432
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	map<string,int>ma;
	rep(i,n){
		string s;
		cin>>s;
		ma[s]++;
	}
	int m=0;
	for(auto it=ma.begin();it!=ma.end();it++)
		cmax(m,it->second);
	for(auto it=ma.begin();it!=ma.end();it++)
		if(m==it->second)cout<<it->first<<endl;
}









Measured memory_bytes: 23808
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int K,T;
vector<int> A;
void input(){
    fast_io();
    cin >> K >> T;
    A = fetch_vec<int>(T);
}

int solve(){
    sort(A.begin(),A.end(),greater<int>());
    int ans = 2*A[0]-accumulate(A.begin(),A.end(),0);
    ans--;
    if(ans<0) ans = 0;
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

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

static const int INF=1e9;
typedef long long ll;

int main(){
    ll r,D,x;
    cin >> r >> D >> x;
    ll X[11];
    X[0]=x;
    for(int i=1;i<=10;i++){
        X[i]=r*X[i-1]-D;
        cout << X[i] << endl;
    }
}

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

int main() {
	int n; cin >> n;
	vector<string>s(n); for (auto&& x : s)cin >> x;
	string ans, abc = "abcdefghijklmnopqrstuvwxyz";
	for (int i = 0; i <abc.size(); i++) {
		int cnt = 1e9;
		for (int j = 0; j < s.size(); j++) {
			int tmp = count(s[j].begin(), s[j].end(), abc[i]);
			cnt = min(cnt, tmp);
		}
		for (int j = 0; j < cnt; j++)ans += abc[i];
	}
	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++)
typedef long long int ll;
int main(){
  int n;string s;cin >>n;
  vector<int> a;
  if(n>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
 }


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

vector<ll> dijkstra(int n, int start, vector<vector<pair<int, ll>>> &adj) {
	vector<ll> dist(n, INF);
	dist[start] = 0;
	priority_queue<pair<ll, int>> q;
	q.push({-dist[start], start});
	while(!q.empty()) {
		int node = q.top().ss; q.pop();
		for(ii i : adj[node]) {
			if(dist[node] + i.ss < dist[i.ff]) {
				dist[i.ff] = dist[node] + i.ss;
				q.push({-dist[i.ff], i.ff});
			}
		}
	}
	
	return dist;
}

void solve() {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--; t--;
	
	vector<vector<pair<int, ll>>> a(n), b(n);
	for(int i = 0; i < m; i++) {
		int u, v;
		ll wa, wb;
		cin >> u >> v >> wa >> wb;
		u--; v--;
		
		a[u].pub({v, wa});
		b[u].pub({v, wb});
		a[v].pub({u, wa});
		b[v].pub({u, wb});
	}
	
	ll mn = INF;
	vector<ll> ans(n), dists = dijkstra(n, s, a), distt = dijkstra(n, t, b);
	for(int i = n - 1; i >= 0; i--) {
		mn = min(mn, dists[i] + distt[i]);
//		cout << dists[i] << " " << distt[i] << endl;
		ans[i] = mn;
	}
	
	for(int i = 0; i < n; i++) {
		cout << (ll)1e15 - ans[i] << endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

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

int main() {
  long n;
  cin >> n;
  vector<long> a(n);
  vector<long> ans(n);
  for(long i=0;i<n;i++) cin >> a[i];

  for(long i=1;i<=1000000000;i*=2) {
    long x=0;
    for(long j=0;j<n;j++) if(a[j]/i%2==1) x++;
    if(x%2==0) {
      for(long j=0;j<n;j++) if(a[j]/i%2==1) ans[j]+=i;
    } else {
      for(long j=0;j<n;j++) if(a[j]/i%2==0) ans[j]+=i;
    }
  }
  for(long i=0;i<n;i++) cout << ans[i] << " ";
  cout << endl;
}

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

void makePrimeTable(vector<bool> &isPrime, int n) {
    isPrime.resize(n + 1, true);
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i * i <= n; i++) {
        if(isPrime[i]) {
            for(int j = 2; i * j <= n; j++) {
                isPrime[i * j] = false;
            }
        }
    }
}

vector<bool> isPrime;

void solve(ll n, ll p) {
    vector<ll> kouho;
    ll now = n + 1;
    while(kouho.size() < p) {
        if(isPrime[now]) {
            kouho.emplace_back(now);
        }
        now++;
    }
    sort(ALL(kouho));
    vector<ll> res;
    for(ll i = 0; i < kouho.size(); i++) {
        for(ll j = i; j < kouho.size(); j++) {
            res.emplace_back(kouho[i] + kouho[j]);
        }
    }
    sort(ALL(res));
    cout << res[p - 1] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    makePrimeTable(isPrime, 1000100);
    while(1) {
        ll n, p;
        cin >> n >> p;
        if(n == -1 && p == -1) {
            break;
        }
        solve(n, p);
    }
}


Measured memory_bytes: 3256
#include <iostream>
#include <vector>

using namespace std;

int gcd(int a, int b){
  while (a >= 1 && b >= 1){
   if (a == b){
     return a;
    }
   else if (a > b){
    a -= b;
   }
   else if (a < b){
    b -=a;
   }
   else if (a == 1 || b == 1){
    return 1;
  }
 }
}
int main(){
  int a, b;
  cin >> a >> b;

  cout << (long long)a*b/gcd(a, b) << "\n";

}

Measured memory_bytes: 760
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	vector<int> v(n);
	rep(i, n) v[i] = i + 1;
	int a, b;
	int cnt = 0;
	do {
		if (v == p) a = cnt;
		if (v == q) b = cnt;
		cnt++;
	} while (next_permutation(v.begin(), v.end()));
	cout << abs(a - b) << endl;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    int X,A;
    cin >> X >> A;

    if(X < A) {
        pl(0)
    } else {
        pl(10)
    }


    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
  ll N, X;
  cin >> N >> X;
  ll a[N];
  for(int i = 0; i < N; i++) cin >> a[i];
  ll ans = 0;
  for(ll i = 0; i < N - 1; i++){
    if(a[i] + a[i + 1] <= X) continue;
    ll sub = a[i] + a[i + 1] - X;
    ans += sub;
    a[i + 1] = max<ll>(0, a[i + 1] - sub);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;

ll case1(ll H, ll W){
    ll ret = 100000000000;
    for(ll h = 1; h < H; h++){
        ll areaA = W * h;
        ll areaB = (H - h) * (W / 2);
        ll areaC = (H - h) * (W - W / 2);
        ll Smax = max(areaA, max(areaB, areaC));
        ll Smin = min(areaA, min(areaB, areaC));
        ll Sdiff = Smax - Smin;
        if(Sdiff < ret) ret = Sdiff;
    }
    return ret;
}

ll case2(ll H, ll W){
    ll ret = 10000000000;
    for(ll h = 1; h < H; h++){
        ll areaA = W * h;
        ll areaB = W * ((H - h) / 2);
        ll areaC = W * (H - h - ((H - h) / 2));
        ll Smax = max(areaA, max(areaB, areaC));
        ll Smin = min(areaA, min(areaB, areaC));
        ll Sdiff = Smax - Smin;
        if(Sdiff < ret) ret = Sdiff;
    }
    return ret;
}

int main(){
    ll H, W;
    cin >> H >> W;
    ll ca1 = case1(H, W);
    ll ca2 = case2(H, W);
    ll ca3 = case1(W, H);
    ll ca4 = case2(W, H);
    ll ans = min(ca1, min(ca2, min(ca3, ca4)));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from math import factorial as f
n,m=map(int,input().split())
if abs(n-m) >= 2:
  print(0)
  quit()
if n == m:
  print(f(n)*f(m)*2%(10**9+7))
else:
  print(f(max(m,n))*f(min(m,n))%(10**9+7))

Measured memory_bytes: 83660
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var A int64
	fmt.Scan(&A)
	var B float64
	fmt.Scan(&B)
	var tmp int64
	tmp = int64(100*B + 0.01)
	//sc.Split(bufio.ScanWords)
	fmt.Print(tmp * A / 100)
}
func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int64(i)
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func SortedBinaryAppend(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinaryDelete(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinarySearch(sortedArr []int, targetValue int) int {
	post := len(sortedArr) - 1
	pre := 0
	for {
		div := (post + pre) / 2
		tim := sortedArr[div]
		if tim == targetValue {
			return pre + div
		} else if tim > targetValue {
			post = tim
		} else {
			pre = tim
		}
		if pre == post {
			return -1
		}
	}
}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func arrSum(arr []int) int {
	sum := 0
	for _, a := range arr {
		sum += a
	}
	return sum
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}


Measured memory_bytes: 1776
#include<iostream>

using namespace std;

int main()
{
  char c;
  while(cin.get(c)){
    if(c>='a'&& c<='z'){
      cout << (char)(c-32);
    }else if(c>='A' && c<='Z'){
      cout << (char)(c+32);
    }else cout << c;
  }
  return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<(n);++i)
#define repeq(i,a,n) for(int i=a,i<=(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
/*
int main(){
    int n,q;
    cin >> n;
    vector<int> a(n);
    rep(i,0,n){
        cin >> a.at(i);
    }
    
    cin >> q;
    vector<int> b(q);
    vector<int> c(q);
    vector<ll> s(q);
    int ans=0;

    rep(i,0,q){
        cin >> b.at(i) >> c.at(i);
    }

    int count=0;
    rep(i,0,q){
        ans=0;
        count=0;
        rep(j,0,n){
            if(a.at(j)==b.at(i)){

                a.at(j)=c.at(i);
            }
            ans+=a.at(j);
        }
        cout << ans << endl;
    }
    return 0;
}
*/
const int MX =100005;

int main(){
    int n;
    //Nの読み込み
    cin >> n;
    //それぞれの値が何個ずつ入っているかの配列
    vector<ll> cnt(MX);
    //aの入力を受けたらaの個数を+1していく
    rep(i,0,n){
        int a;
        cin >> a;
        cnt[a]++;
    }

    ll total=0;
    rep(i,0,MX){
        total+=i*cnt[i];
    }

    int q;
    cin >> q;
    rep(i,0,q){
        int b,c;
        cin >> b >> c;
        total-=b*cnt[b];
        total+=c*cnt[b];
        //total-=c*cnt[c];
        cnt[c]+=cnt[b];
        cnt[b]=0;
        //total+=b*cnt[b];
        //total+=c*cnt[c];
        cout << total << endl;
    }

    return 0;
}


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

vector<int> me;

vector<int> rotate(char c, vector<int> a) {
    if (c == 'R') {
        return {a[4], a[5], a[2], a[3], a[1], a[0]};
    }
    if (c == 'F') {
        return {a[0], a[1], a[5], a[4], a[2], a[3]};
    }
    if (c == 'L') {
        return rotate('R', rotate('R', rotate('R', a)));
    }
    if (c == 'B') {
        return rotate('F', rotate('F', rotate('F', a)));
    }
    exit(1);
}

int get_d() {
    return me[4];
}

int n;
vector<int> dp;
vector<map<pair<int, int>, int>> mp;
vector<set<pair<int, int>>> ss;

int dfs(int a) {
    if (dp[a] != -1) return dp[a];
    int ret = 0;
    for (int i = 0; i < n; i++) {
        if (a >> i & 1) {
            int acc = dfs(a ^ (1 << i));
            for (auto &p : mp[i]) {
                if (ss[a ^ (1 << i)].count(p.first) == 0) {
                    acc += p.second;
                }
            }
            ret = max(ret, acc);
        }
    }
    return dp[a] = ret;
}

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

    while (1) {
        cin >> n;
        if (n == 0) break;
        mp = vector<map<pair<int, int>, int>>(n);
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            me.assign(6, 0);
            for (int j = 0; j < 6; j++) cin >> me[j];
            string s;
            cin >> s;

            mp[i][{x, y}] = get_d();
            for (char c : s) {
                me = rotate(c, me);
                if (c == 'R') x++;
                if (c == 'L') x--;
                if (c == 'F') y--;
                if (c == 'B') y++;
                mp[i][{x, y}] = get_d();
            }
        }
//        for (int i = 0; i < n; i++) {
//            cerr << i << "th" << endl;
//            for (auto &p : mp[i]) {
//                cerr << "(" << p.first.first << "," << p.first.second << "), " << p.second << endl;
//            }
//        }
        ss = vector<set<pair<int, int>>>(1 << n);
        for (int i = 0; i < 1 << n; i++) {
            for (int j = 0; j < n; j++) {
                if (i >> j & 1) continue;
                for (auto &p : mp[j]) {
                    ss[i | (1 << j)].insert(p.first);
                }
            }
        }
        dp.assign(1 << n, -1);
        dp[0] = 0;
        int ans = 0;
        for (int i = 0; i < 1 << n; i++) {
            ans = max(ans, dfs(i));
        }
        cout << ans << '\n';
    }
}


Measured memory_bytes: 236624
#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;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());

int main() {
ll n;
cin >> n;
string ans="Yes";
ll h[n];
REP(i,n) cin >>h[i];
for(int i=n-1;i>0;i--) {
  if(h[i-1]-h[i]>0) h[i-1]--;
  if(h[i-1]-h[i]>0) ans="No"; 
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

void sort(int* list, int size) {
	int i, j, tmp;
	for(i=0;i<size-1;i++) {
		for(j=i+1;j<size;j++) {
			if(list[i] > list[j]) {
				tmp = list[i];
				list[i] = list[j];
				list[j] = tmp;
			}
		}
	}
}

int main(void) {
	int a[3];
	scanf("%d %d %d", a, a+1, a+2);
	sort(a, 3);
	printf("%d %d %d\n", a[0], a[1], a[2]);
	
	return 0;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

void func(int N, string cur, char largest, int depth){
    if( depth == N){
        cout << cur << endl;
        return;
    }

    for(char c = 'a'; c <= largest+1; c++ ){

        func(N, cur+c, max(largest,c), depth+1);
    }

}

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    cin >> N;

    func(N, "a", 'a', 1);
}


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

int main(){
  int n; cin >> n;
  deque<int> d;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    if(i % 2 == 0) d.push_back(a);
    else d.push_front(a);
  }
  for(int i = 0; i < n; i++){
    if(n % 2 == 0){
      cout << d.front() << " ";
      d.pop_front();
    }
    else{
      cout << d.back() << " ";
      d.pop_back();
    }
  }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e3+10;
const int M = 1e6+10;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}
inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}
inline ll C(ll y, ll x) { ll ans = 1; if(y < 0 || x < 0 || y < x) return 0; y %= mod; if(!y || !x) return 1; for0(i, x) ans = ans * (y-i) % mod; for1(i, x) ans = ans * Pow(i, mod-2) % mod; return ans; }
//==================================================================================================================================================================//

int n, m, dp[N][N];
char mp[N][N];

int main() {
   dp[1][1] = 1;
   scanf("%d %d", &n, &m);
   for1(i, n) for1(j, m) {
      scanf(" %c", &mp[i][j]);
   }
   for1(i, n) for1(j, m) {
      if(mp[i][j] == '#' || (i==1 && j==1)) continue;
      dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
   }
   printf("%d\n", dp[n][m]);
   return 0;
}

Measured memory_bytes: 8700
#include <stdio.h>
#include <string.h>

int main() {
    int arr[100]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    scanf("%d", &n);
    printf("%d\n", arr[n-1]);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,x,y;
    cin>>n>>m>>x>>y;
    int ara[n],bra[m];
    for(i=0;i<n;i++)
        cin>>ara[i];
    for(i=0;i<m;i++)
        cin>>bra[i];
    sort(ara,ara+n);
    sort(bra,bra+m);
    for(i=ara[n-1]+1;i<=bra[0];i++)
    {
        if(i>x && i<=y)
        {
            cout<<"No War"<<endl;
            return 0;
        }
    }
    cout<<"War"<<endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

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

        // 入力(A B C)
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[] ary = {a, b, c};
        Arrays.sort(ary);

        System.out.println((ary[0]==5 && ary[1]==5 && ary[2]==7) ? "YES": "NO");
        sc.close();
    }
}


Measured memory_bytes: 21588
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;i++)
using namespace std;
using ll = long long;
using R = double;
const int inf = 100000;

const int nmax = 40, abmax = 10;
int a[nmax], b[nmax], c[nmax];
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];


int main(){
	int n, ma, mb;
	cin >> n >> ma >> mb;

	rep(i, 0, n)
		cin >> a[i] >> b[i] >> c[i];

	rep(i, 0, nmax + 1) {
		rep(j, 0, nmax*abmax + 1) {
			rep(k, 0, nmax*abmax + 1) {
				dp[i][j][k] = inf;
			}
		}
	}

	dp[0][0][0] = 0;


	rep(i,0,n) {
		rep(j,0, nmax*abmax + 1){
			rep(k,0, nmax*abmax + 1) {
				if (j-a[i] >= 0 && k-b[i] >= 0) {
					dp[i + 1][j][k] = min(dp[i][j-a[i]][k-b[i]]+c[i], dp[i][j][k]);
				}
				else {
					dp[i + 1][j][k] = dp[i][j][k];
				}
			}
		}
	}
	
	int cnt, ans;
	cnt = 1;
	ans = inf;
	while (1) {
		if (cnt*ma <= nmax * abmax && cnt*mb <= nmax * abmax) {
			ans = min(ans,dp[n][cnt*ma][cnt*mb]);
		}
		else {
			break;
		}
		cnt++;
	}

	if (ans == inf) {
		cout << "-1" << endl;
	}
	else {
		cout << ans << endl;
	}




	return 0;
}

Measured memory_bytes: 25984
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 2000 + 10;

ll a[MAXN], dp[MAXN][MAXN];

int main() {
	int n, x;
	scanf("%d%d", &n, &x);
	for(int i=0; i<n; i++)	scanf("%lld", a+i);

	for(int i=0; i<n; i++)	dp[0][i] = a[i];
	for(int i=1; i<n; i++) {
		for(int j=0; j<n; j++) {
			dp[i][j] = min(dp[i-1][j], dp[i-1][(j+n-1)%n]);
		}
	}
	ll ans = (1ll<<63)-1;
	for(int i=0; i<n; i++) {
		ll sum = 0;
		for(int j=0; j<n; j++)	sum += dp[i][j];
		ans = min(ans, sum+1ll*x*i);
	}
	printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 31616
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  string gomi;
  getline(cin, gomi);
  rep(i, n) {
    string s;
    getline(cin, s);
    cout << regex_replace(s, regex("Hoshino"), "Hoshina") << endl;
  }
}

Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.println(
            IntStream.range(0, sc.nextInt()) //生成処理
                 .map(i -> sc.nextInt() -1) //中間処理
                 .sum() //末端処理
        );

        // a1で割ったあまりの最大値はa1 - 1
        // この時、m = (a1 - 1)(a2 - 1)...(an - 1) で求められる
        

        sc.close();
    }
}


Measured memory_bytes: 29900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N; cin>>N;
  vector<int64_t> A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  if(N%2==1){
    cout<<B[(N+1)/2-1]-A[(N+1)/2-1]+1;
  }
  else{
    cout<<(B[N/2-1]+B[N/2])-(A[N/2-1]+A[N/2])+1;
  } 
}

Measured memory_bytes: 6408
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x[5];
    for(int i=0;i<5;i++)
    {
        cin>>x[i];
    }
    for(int i=0;i<5;i++)
    {
        if(x[i]==0)
        {
            cout<<i+1<<'\n';
        }
    }
}

Measured memory_bytes: 3616
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	h := make([]int, n)

	for i := range h {
		h[i] = nextInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(h)))

	ans := 0
	for i := range h {
		if k > 0 {
			k--
		} else {
			ans += h[i]
		}
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 4736
n = int(input())
sl = []

for _ in range(n):
    s = list(input())
    sl.append(s)

ans = 0
for i in range(n):
    flag = True
    for j in range(n):
        for k in range(n):
            if j != k:
                if sl[j][(k+i)%n] != sl[k][(j+i)%n]:
                    flag = False
    if flag:
        ans += n

print(ans)






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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int64_t> a(n),b(n),c(m),d(m);
  for (int i=0;i<n;i++) cin>>a.at(i)>>b.at(i);
  for (int i=0;i<m;i++) cin>>c.at(i)>>d.at(i);
  for (int i=1;i<=n;i++) {
    int64_t buf=abs(a.at(i-1)-c.at(0))+abs(b.at(i-1)-d.at(0));
    int ans=1;
    for (int j=1;j<=m;j++){
      if(buf>abs(a.at(i-1)-c.at(j-1))+abs(b.at(i-1)-d.at(j-1))) {
        buf=abs(a.at(i-1)-c.at(j-1))+abs(b.at(i-1)-d.at(j-1));
        ans=j;
      }
    }
  	cout << ans << endl;
  }
}


Measured memory_bytes: 256
from math import factorial
def comb(n,k):
    if n>=k:
        return int(factorial(n)/(factorial(k)*factorial(n-k)))
    else:
        return 0


def calc(a,k):
        t = len(a)
        t1 = len(a) - 1
        if k<1 or t == 0:
            return 0
        else:
            if a[t1]>0:
                ans = (9**k)*comb(t1,k) + (9**(k-1))*(a[t1]-1)*comb(t1,k-1)
                ans+=calc(a[:(t-1)],k-1)
            else:
                ans = 0
                ans+=calc(a[:(t-1)],k)
            if a[-k]>=1 and k == 1:
               ans+=1
            return ans


n = int(input())
k = int(input())
number = []
while n:
    number.append(n%10)
    n//=10

t = len(number)
t1 = len(number) - 1

if t>=k:
    ans = 0
    ans += calc(number,k)
else:
    ans = 0
print(ans)

Measured memory_bytes: 3064
import copy
N,M=map(int,input().split())
A=[]

for i in range(M):
    a,b=map(int,input().split())
    A.append([a,b])
    
ANS=0
for i in range(M):
    L=[[]for _ in range(N+1)]
    for j in range(M):
        if i==j:
            continue
        else:
            L[A[j][0]].append((A[j][1],A[j][0]))
            L[A[j][1]].append((A[j][0],A[j][1]))
    X=1
    C=[100 for i in range(N+1)]
    C[1]=1
    C[0]=1
    Q=L[1]
    #print(L)
    for j in range(1000):
        if len(Q)==j:
            break
        if C[Q[j][0]]==100:
            C[Q[j][0]]=C[Q[j][1]]+1
            for k in L[Q[j][0]]:
                if C[k[0]]==100:
                    Q.append((k[0],k[1]))
    #print(Q)
    #print(C)
    if 100 in C:
        ANS+=1
print(ANS)

Measured memory_bytes: 41456
#include <stdio.h>
int main(void)
{
    int A,B,C,K;
    scanf("%d %d %d %d",&A,&B,&C,&K);
    if(A >= K){
        printf("%d",K);
    }else if(A+B >= K){
        printf("%d",A);
    }else{
        printf("%d",2*A+B-K);
    }
} 

Measured memory_bytes: 1700
#include<bits/stdc++.h>
#define in inline
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9') {
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
char s[14];
signed main(){
	scanf("%s",s+1);
	if(s[2]=='B')puts("ARC");
	else puts("ABC");
}

Measured memory_bytes: 3656
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def dfs(v):
    flag = True
    for i in range(n):
        if not visit[i]:
            flag = False
    if flag:
        return 1

    ret = 0

    for i in range(n):
        if not g[v][i]:
            continue
        if visit[i]:
            continue

        visit[i] = True
        ret += dfs(i)
        visit[i] = False

    return ret


    for next in g[v]:
        if visit[next]:
            continue
        else:
            visit[next] = True
            dfs(next)


n, m = na()
g = [[0] * n for _ in range(n)]
for i in range(m):
    a, b = na()
    a -= 1
    b -= 1
    g[a][b] = g[b][a] = True

visit = [False] * n
visit[0] = True
print(dfs(0))







Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int H,W,Count=0;
	cin >> H >> W;
	string S[H];
	for (int i=0; i<H; i++){
		cin >> S[i];
	}
	for (int i=0; i<H; i++){
		for (int j=0; j<W; j++){
			if (S[i].at(j) == '#' ) {
				cout << '#';
			}
			else {
				Count = 0;
				if (i != 0){
					if (j != 0){
						if (S[i-1].at(j-1) == '#' ) {
							Count ++;
						}
					}
					if (S[i-1].at(j) == '#' ) {
						Count ++;
					}
					if (j != W-1){
						if (S[i-1].at(j+1) == '#' ) {
							Count ++;
						}
					}
				}
				if (i != H-1){
					if (j != 0){
						if (S[i+1].at(j-1) == '#' ) {
						Count ++;
						}
					}
					if (S[i+1].at(j) == '#' ) {
						Count ++;
					}
					if (j != W-1){
						if (S[i+1].at(j+1) == '#' ) {
							Count ++;
						}
					}
				}
				if (j != W-1){
					if (S[i].at(j+1) == '#' ) {
					Count ++;
					}
				}
				if (j != 0){
					if (S[i].at(j-1) == '#' ) {
						Count ++;
					}
				}
					cout << Count;
			}
		}
		cout << endl;
	}	
}

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

int main() {
	int i,j,k,c=0,n,a,b,w,x,y,z,t;
	cin>>a>>b>>c>>x;
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				w=i*500+j*100+k*50;
				if(w==x)
					t++;
				if(w>x)
					break;
			}
		}
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 256
#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");}

ll X, K, D;
int main(){
  cin >> X >> K >> D;
  X = abs(X);
  ll cnt = (X - 1) / D + 1;

  if (cnt > K){
    cout << abs(X - K * D) << endl;
    return 0;
  }

  if ((K - cnt) % 2 == 0){
    cout << abs(X - cnt * D) << endl;
  }else{
    cout << abs(X - (cnt - 1) * D) << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<set>

using namespace std;
set <string> S;

int main()
{
    int i,j;
    string::size_type lens,lent;
    string s,t;
    cin>>s;
    cin>>t;
    lens=s.size();
    lent=t.size();
    for(i=0;i<lens;++i)
    {
        if(s[i]=='?'||s[i]==t[0])
        {
           string temp=s;
            for(j=0;j<i;++j)
            {
                if(temp[j]=='?')
                    temp[j]='a';
            }
             bool flag=false;
        for(j=0;j<lent;++j)
        {
            if((temp[i+j]!='?'&&temp[i+j]!=t[j]))break;
            temp[i+j]=t[j];
            if(j==lent-1)
            {
                flag=true;
            }
        }
        if(flag)
        {
            for(j=i+lent;j<lens;++j)
            {
                if(temp[j]=='?')temp[j]='a';
            }
            S.insert(temp);
        }
        }
    }
    if(S.size()==0)cout<<"UNRESTORABLE"<<endl;
    else cout<<*S.begin()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ()
{
    ll n,q,a,b,c,sum=0;
    cin>>n;
    ll arr[n+5];
    ll vis[1000050]={0};
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
        vis[arr[i]]++;
    }
    for (int i=0;i<n;i++)
    {
        sum+=arr[i];
    }
    cin>>q;
    while(q--)
    {
        cin>>b>>c;
        sum=sum-vis[b]*b+vis[b]*c;
        vis[c]+=vis[b];
        vis[b]=0;
        cout<<sum<<'\n';
    }
    return 0;
}

Measured memory_bytes: 12184
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

struct edge{int u,d;};
using namespace std;

int main(){
  int i,j,n,m,l,r,d,t;
  priority_queue<int> pq;
  queue<int> que;
  cin >> n >> m;
  struct edge e;
  vector<edge> v[n+1];
  long long p[n+1]={0},x;
  int num[n+1]={};
  bool ch[n+1]={};
  //for(i=0;i<=n;i++)num[i]=-1;
  for(i=0;i<m;i++){
    cin >> l >> e.u >> e.d;
    if(!ch[l])ch[l]=1;
    num[e.u]++;
    v[l].push_back(e);
  }
  if(m==0){
    cout << "Yes" << endl;
    return 0;
  }
  for(i=1;i<=n;i++){
    if(num[i]==0 && ch[i])que.push(i);
  }
  if(que.empty()){
    cout << "No" << endl;
    return 0;
  }
  while(!que.empty()){
    t = que.front();
    //cout << t << "t"<<endl;
    que.pop();
    for(i=0;i<v[t].size();i++){
      x = p[t] + v[t][i].d;
      if(p[v[t][i].u]==0 || p[v[t][i].u]==x){
        p[v[t][i].u]=x;
        num[v[t][i].u]--;
        if(num[v[t][i].u]==0)que.push(v[t][i].u);
      }
      else{
        cout << "No" << endl;
        return 0;
      }
    }
  }
  //for(i=1;i<=n;i++)cout << p[i] << " ";
  //cout << endl;
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
  int n,m; cin>>n>>m;
  vector<int> h(n);
  for (int i=0; i<n; i++) cin>>h[i];

  Graph tree(n);
  for (int i=0; i<m; i++){
    int a,b; cin>>a>>b;
    a-=1;
    b-=1;
    tree[a].push_back(h[b]);
    tree[b].push_back(h[a]);
  }
  int ans=0;
  for (int i=0; i<n; i++){
    int i_h=h[i];
    bool ok=true;
    for (int d : tree[i]){
      if (i_h<=d) ok=false;
    }
    if (ok) ans+=1;
  }
  cout<<ans<<endl;
}

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

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

  vector<vector<pair<int,int>>> a(n);
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;

    for (int j = 0; j < num; j++) {
      int x,y;
      cin >> x >> y;
      x--;

      a[i].emplace_back(x,y);
    }
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool ok = true;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if(1 & (bit >> (n - 1 - i))) { // honest
        cnt++;
        for (auto it: a[i]) {
          int itr = it.first;
          int b = it.second;
          if((1 & (bit >> (n - 1 - itr))) != b) {
            ok = false;
            break;
          }
        }
      }
      if(!ok) break;
    }
    if(ok) {
      ans = max(ans, cnt);
      //cout << bit << '\n';
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    Scanner sin=new Scanner(System.in);
	    int a=sin.nextInt();
	    int b=sin.nextInt();
	    int c=sin.nextInt();
	    if (a==b&&b==c){
			System.out.println("No");
		}else if(a==b||b==c||c==a){
			System.out.println("Yes");
		}else System.out.println("No");
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; ++i){
        ans += i*(n/i)*(n/i + 1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
N = int(input())


Sn = 1
n = 1
while Sn < N:
    n += 1
    Sn += n
    if Sn == N:
        break

res = []
for i in range(n, 0, -1):
    if N - i >= 0:
        res.append(i)
        N -= i

for ans in res[::-1]:
    print(ans)


Measured memory_bytes: 41584
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;
#define ipair pair<int,int>
#define mod 1000000007

int main()
{
    string s;
    cin>>s;
    int f=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='9')
        {
            f++;
            break;
        }
    }
    if(f>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



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

int main(){
    string a,b;
    cin >> a >> b;
    string A,B;
    int size_a = atoi(a.c_str());
    int size_b = atoi(b.c_str());

    for(int i = 0; i < size_b; i++) 
        A += a;
    for(int i = 0; i < size_a; i++) 
        B += b;
    size_a = atoi(A.c_str());
    size_b = atoi(B.c_str());
    if(size_a >= size_b)
        cout << size_a << endl;
    else 
        cout << size_b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,k;
  cin>>n>>k;
  vector<ll> h(n);
  vector<ll> c(n,1e9);
  rep(i,n)cin>>h[i];
  c[0]=0;
  rep(i,n) {
    repeat(j,i+1,min(i+k+1,n)) {
      c[j]=min(c[j],c[i]+abs(h[i]-h[j]));
    }
  }
  cout << c[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1792
z=list(map(int,input().split()))
z.sort()
a=0

while True:
    if z[1]==z[0]:
        break
    a=z[1]-z[0]
    if z[0]%a==0:
        z[1] = z[0]
        z[0] = a
        z.sort()
        break
    z[1]=z[0]
    z[0]=a
    z.sort()

print(z[0])

Measured memory_bytes: 7676
import bisect

N,A=map(int,input().split())
x=[i-A for i in map(int,input().split())]

B=max(max(x),abs(min(x)))

dp=[[0]*(2*N*B+1) for _ in [0]*(N+1)]
dp[0][N*B]=1
# dp[n][k]:n番目までの整数でkが作れる場合の数
    
for n in range(1,N+1):
    for k in range(-N*B,N*B+1):
        dp[n][k]+=dp[n-1][k-x[n-1]]+dp[n-1][k]

print(dp[N][N*B]-1)

Measured memory_bytes: 75580
# coding=utf-8


def hit_and_blow(answer: list, expect: list) -> tuple:
    hit, blow = 0, 0
    for (i, j) in zip(answer, expect):
        if i == j:
            hit += 1
    answer_set = set(answer)
    expect_set = set(expect)
    blow_set = answer_set & expect_set
    blow = len(blow_set) - hit
    return hit, blow


if __name__ == '__main__':
    while True:
        try:
            answer_number = list(map(int, input().split()))
            expected_number = list(map(int, input().split()))
        except EOFError:
            break
        h, b = hit_and_blow(answer_number, expected_number)
        print(h, b)

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

int main() {
  int s,count=1,a=0;
  cin >> s;
  vector<int> vec(1,s);
  for(int i = 0;i<1000000;i++){
    if(s%2 == 1){
      s = s*3+1;
    }
    else{
      s /=2;
    }
    count++;
    vec.push_back(s);
    for(int j=0;j<vec.size()-1;j++){
      if(vec.at(j) == s){
        cout << count << endl;
        a = 1;
        break;
       }
    }
    if(a == 1){
        break;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    int a,b;
    int ans=0;
    cin>>n>>m;
    vector<vector<int>> matrix(n,vector<int>(n,0));
    vector<int> v(n);
    iota(v.begin(),v.end(),0);
    for(int i=0;i<m;i++){
        cin>>a>>b;
        matrix[a-1][b-1]=1;
        matrix[b-1][a-1]=1;
    }
    int i;
    do{
        if(v[0]!=0) continue;
        for(i=0;i<n-1;i++){
            if(matrix[v[i]][v[i+1]]!=1){
                break;
            }
        }
        if(i==n-1){
            ans++;
        }
    }while(next_permutation(v.begin(),v.end()));
    cout<<ans<<endl;
}


Measured memory_bytes: 256