akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var s = ReadLine().ToCharArray();
            var t = ReadLine().ToCharArray();
            Array.Sort(s);
            Array.Sort(t);Array.Reverse(t);
            if (-1 == string.Join("", s).CompareTo(string.Join("", t)))
                WriteLine("Yes");
            else
                WriteLine("No");

        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 26248
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    ll n=lin();
    ll p=2;
    int ans=0;
    bool flag=false;
    while(p*p<=n){
        if(n%p==0){
            int cnt=0;
            while(n%p==0){
                n/=p;
                cnt++;
            }
            int plus=0;
            while((plus+2)*(plus+1)/2<=cnt)plus++;
            ans+=plus;
        }
        p++;
    }
    if(n!=1)ans++;
    cout<<ans<<endl;
}

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

#define MAX 100

int main() {
	char W[11], T[MAX], lower[MAX];
	int i,count;

	scanf("%s", W);

	while (1) {
		scanf("%s", T);
		if (strcmp(T, "END_OF_TEXT") == 0) break;

		for (i = 0; i < strlen(T); i++) {
			if (T[i] >= 'A' && T[i] <= 'Z') {
				T[i] = T[i] + 32;
			}
		}

		if (strcmp(T, W) == 0) count++;

	}

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

	return 0;

}


Measured memory_bytes: 2044
from sys import stdin
def main():
	readline=stdin.readline
	N=int(readline())
	a=list(map(int,readline().split()))
	b=[0]*N
	for i in range(N):
		n=N-i
		count=0
		for k in range(n,N+1,n):
			if k==n:
				pass
			else:
				count+=b[k-1]
		if count%2!=a[n-1]:
			b[n-1]=1
		else:
			b[n-1]=0
	
	res=[]
	M=0
	for i in range(N):
		if b[i]==1:
			res.append(i+1)
			M+=1
	
	print(M)
	print(*res)
if __name__=="__main__":
	main()

Measured memory_bytes: 14104
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int search(string s,char a){
    int cnt = 0;
    rep(i,s.size()){
        if(s[i]==a) cnt++;
    }
    return cnt;
}
void write(map<char,int> mp,char a){
    rep(i,mp[a]) cout << a;
}
int main(){
    int n;
    cin >> n;
    map<char,int> mp;
    rep(i,alpha.size()) mp[alpha[i]]=100;
    string s;
    rep(i,n){
        cin >> s;
        rep(j,alpha.size()){
            mp[alpha[j]]=min(mp[alpha[j]],search(s,alpha[j]));
        }
    }
    rep(i,alpha.size()){
        if(mp[alpha[i]]!=100) write(mp,alpha[i]);
    }
    cout << endl;
}

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

using namespace std;

int64_t N, Z, W;
int64_t a[2001];
pair<int64_t, int64_t> p[2001];

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

    cin >> N >> Z >> W;

    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    
    for(int i = 0; i < N - 1; ++i){
        p[i].first = a[i] - a[N - 1];
        p[i].second = i;
        if(p[i].first < 0){
            p[i].first *= -1;
        }
    }

    p[N - 1].first = a[N - 1] - W;
    p[N - 1].second = N - 1;
    if(p[N - 1].first < 0){
        p[N - 1].first *= -1;
    }

    sort(p, p + N);

    int64_t ans = 0;
    int64_t ma = N - 1;
    int64_t ushi = 0;
    int64_t num = -1;
    while(ma >= ushi){
        while(ma >= 0){
            if(ans < p[ma].first && num < p[ma].second){
                ans = p[ma].first;
                num = p[ma].second;
                break;
            }
            --ma;
        }
        while(ushi < N){
            if(ans > p[ushi].first && num < p[ushi].second && p[ushi].second != N - 1){
                ans = p[ushi].first;
                num = p[ushi].second;
                break;
            }
            ++ushi;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main()
{
    long long A,B,V,W,T;
    cin>>A>>V>>B>>W>>T;
    if(abs(B-A)>(V-W)*T)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {
    // 入力
    ll N;
    cin >> N;
    ll A[N];
    rep(i,N) cin >> A[i];
    ll B[N];
    rep(i,N) cin >> B[i];
    ll out = 0;
    ll plus = 0;
    ll minus = 0;
    ll C[N];
    rep(i,N){
        C[i] = A[i]-B[i];
        if(C[i]<0){
            out++;
            minus -= C[i];
        }else plus += C[i];
    }
    if(minus>plus) out = -1;
    else if(out>0){
        sort(C,C+N);
        rep(i,N){
            minus -= C[N-1-i];
            out++;
            if(minus<=0) break;
        }
    }
    cout << out << endl;
    return 0;
}


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

    class Program
    {
        static void Main(string[] args)
        {
            string[] dataline = Console.ReadLine().Split(' ');
            bool flag = true;
            for (int i = 0; i < dataline.Length-1; i++)
            {
                if (dataline[i].Last() != dataline[i+1].First())
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }


Measured memory_bytes: 13268
import std.stdio, std.conv, std.string, std.algorithm, std.array;

void main()
{
    foreach(line; stdin.byLine())
    {
        auto f = line.split(",").map!(to!int).array;
        int[] dis = f[0..10];
        int len = dis.reduce!"a + b",
            v1 = f[10], v2 = f[11];
        real m = 1.0 * len / (v1 + v2) * v1;
        foreach(i, d; dis)
        {
            m -= d;
            if(m <= 0)
            {
                (i + 1).writeln;
                break;
            } 
        }
    }
}

Measured memory_bytes: 1084
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
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
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, k := scanInt(), scanInt()
	a := scanInts(n)

	for i := k; i < n; i++ {
		if a[i] <= a[i-k] {
			fmt.Fprintln(wr, "No")
		} else {
			fmt.Fprintln(wr, "Yes")
		}
	}

}


Measured memory_bytes: 5824
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int A,B,C,X,Y;cin >> A >> B >> C >> X >> Y;
  ll ans = 0;
  if(A+B>2*C){
    int m = min(X,Y);
    X -= m;
    Y -= m;
    ans = 2ll*m*C;
  }
  if(A>2*C) ans += (ll) 2*X*C;
  else ans += (ll) X*A;
  if(B>2*C) ans += (ll) 2*Y*C;
  else ans += (ll) Y*B;
  cout << ans << endl;
  return 0;
}


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

struct UF{
    vector<int> par, rank, size;
    UF(){}
    UF(int n){ init(n); }
    void init(int n){
        par.assign(n, 0);
        rank.assign(n, 0);
        size.assign(n, 1);
        for(int i=0;i<n;i++) par[i] = i;
    }
    int find(int x){
        if(par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x != y){
            if(rank[x] > rank[y]) swap(x, y);
            par[x] = y;
            size[y] += size[x];
        }
    }
    bool same(int x, int y){ return find(x) == find(y); }
    int get_size(int x){ return size[find(x)]; }
};

int main(void){
    int n, m;
    cin >> n >> m;
    UF uf(n+1);
    for(int i=0;i<m;i++){
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
    }

    set<int> s;
    for(int i=1;i<=n;i++){
        s.insert(uf.find(i));
    }
    int ans = s.size();
    cout << ans-1 << endl;

}


Measured memory_bytes: 7740
// C - All Green
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int D,G; cin>>D>>G;
	vector<int> P(D), C(D);
	rep(i, D) cin>>P[i]>>C[i];

	int ans = INT_MAX;
	for(int bin=1; bin<(1<<D); ++bin){ // max<2^10=1024

		int cnt = 0, tot = 0;
		rep(j, D) // max=10
			if(bin & 1<<j){
				cnt += P[j]; // count
				tot += P[j]*(j+1)*100 + C[j]; // total
			}
		if(tot >= G) ans = min(ans, cnt);

		rep(j, D)
			if(bin & 1<<j){
				int now_cnt = cnt;
				int now_tot = tot - C[j];
				rep(k, P[j]-1){ // max=100, delete p-1 times
					now_cnt--;
					now_tot -= (j+1)*100;
					if(now_tot >= G) ans = min(ans, now_cnt);
				}
			}

	}
	cout<< ans <<endl;
}


Measured memory_bytes: 256
import collections
n = int(input())
l = map(int, input().split())
c = collections.Counter(l)
c = sorted(c.items(), key=lambda c:c[0], reverse=True)
 
ans = 1
cnt = 0
 
for key,val in c:
  if cnt==0 and val>=4:
    ans=key**2
    break
  if val>=2:
    ans*=key
    cnt+=1
  if cnt == 2:
    break
else:
  ans = 0
print(ans)

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main() {
  int n;
  cin >> n;
  vi d(n);
  rep (i, n) {
    cin >> d[i];
  }
  sort(all(d));
  int mi = d[n / 2 - 1];
  int ma = d[n / 2];
  cout << ma - mi << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int i;
  int a;
  int out = 0;
  int mountainHeight[25];
  int mountainAmount;
  cin>>mountainAmount;
  for (i=0;i<mountainAmount;i++){
    cin>>mountainHeight[i];
  }
  a = mountainHeight[0];
  for (i=0;i<mountainAmount;i++){
    if(mountainHeight[i] < a){
    } else {
      out++;
      a = mountainHeight[i];
    }
  }
  cout<<out;
}

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

int main() {
	string o, e;
	cin >> o >> e;
	string a(o.size() + e.size(), 0);
	for (int i = 0; i < o.size(); i++) {
		a[2 * i] = o[i];
	}
	for (int j = 0; j < e.size(); j++) {
		a[2 * j + 1] = e[j];
	}
	cout << a;
	return 0;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  int con = 0;
  for (int i = min(A, B); i > 0; i--) {
    if (A % i == 0 && B % i == 0) con++;
    if (con == K) {
      cout << i << endl;
      return 0;
    }
  }
}

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

//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [i32; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: usize, b: usize, c: usize,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    input! {
        s: chars
    }
    let mut ans = s;
    if ans.len() == 2 {
        let ans: String = ans.into_iter().collect();
        println!("{}", ans);
    } else if ans.len() == 3 {
        ans.reverse();
        let ans: String = ans.into_iter().collect();
        println!("{}",ans);
    }
}

Measured memory_bytes: 4352
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int n,m,k; cin >> n >> m >> k;
    vector<ll> a(n);
    rip(i,n,0) cin >> a[i];
    vector<ll> b(m);
    rip(i,m,0) cin >> b[i];
    vector<ll> aa(n+1),bb(m+1);
    rip(i,n,0) aa[i+1] = a[i] + aa[i];
    rip(i,m,0) bb[i+1] = b[i] + bb[i];
    int ans = 0;
    rip(i,n+1,0) {
        ll now = k - aa[i];
        if(now < 0) continue;
        chmax(ans, i + int(upper_bound(bb.begin(), bb.end(), now) - bb.begin())-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9592
#include <iostream>
#include <bits/stdc++.h>
#include <cstdlib>
#include <string>
using namespace std;

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

    string odd[3] = {"R", "U", "D"};
    string even[3] = {"L", "U", "D"};

    int length = (int)s.size();
    string res = "Yes";

    for (int i = 0; i < length; i++) {
        string se = s.substr(i, 1);

        if(se != "L" && se != "R") {
            continue;
        }

        if ((i + 1) % 2 == 0) {
            if (se != "L") {
                res = "No";
                break;
            }
        } else {
            if (se != "R") {
                res = "No";
                break;
            }
        }
    }

    cout << res;

    return 0;
}

Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
q=int(input())
from collections import Counter
d=Counter(a)
sum=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    tmp=d[b]*(b-c)
    sum-=tmp
    print(sum)
    d[c]+=d[b]
    d[b]=0

Measured memory_bytes: 23820
// In the name of Allah the Lord of the Worlds.

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

typedef long long ll;

int n , m;
vector<ll>v;
ll dp[55][55][105];

ll f(int i , int j , int k)
{
    if(i>j)return 0;
    if(k==0)return 0;
    if(dp[i][j][k]!=-1)return dp[i][j][k];
    ll value = 0;
    if(k>=1){
        value = max(value , f(i+1 , j , k-1)+v[i]);
        value = max(value , f(i , j-1 , k-1)+v[j]);
    }
    if(k>=2){
        value = max(value , f(i+1 , j , k-2));
        value = max(value , f(i , j-1 , k-2));
    }
    return dp[i][j][k] = value;
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    cin >> n >> m;
    for(int i=0;i<n;i++){
        ll in;
        cin >> in;
        v.push_back(in);
    }
    memset(dp , -1 , sizeof(dp));
    cout << f(0 , n-1 , m) << endl;
    return 0;
}


Measured memory_bytes: 2688
def resolve():
    n, m = map(int, input().split()) # 標準入力1行目の処理、n頂点、m辺
    adj = [[] for i in range(n+1)] # 隣接リスト初期化、要素数は頂点数
    for i in range(m):
        A, B = map(int, input().split())
        adj[A].append(B) # このappendのやり方だと、adj[0]が空になることに注意
        adj[B].append(A) # （問題文の頂点インデックスが1始まりであるため）
    #print(adj)
    # 隣接リストさえ作成できたら、あとはBFSで全探索するだけ

    from collections import deque
    q = deque([1])
    ans = [-1 for i in range(n+1)]
    while q:
        v = q.popleft() # vertex(頂点)の意
        for u in adj[v]:
            if ans[u] == -1: # 未踏なら
                ans[u] = v
                q.append(u)
    print("Yes")
    for i in range(2, n+1):
        print(ans[i])

resolve()

Measured memory_bytes: 34008
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    
    int sub = N;
    int S = 0;
    for (int i = 0; sub > 0; i++){
        S += sub % 10;
        sub /= 10;
    }

    if (N % S == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

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

int main(){
    long a,b,c,d;
    cin >> a >> b >> c;
    d = c-a-b;
    if(c-a-b>0 && 4*a*b<d*d) cout << "Yes" << endl; 
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: usize = iterator.next().unwrap().parse().unwrap();

    let ans = (x / 500) * 1000 + (x % 500 / 5) * 5;

    return ans.to_string();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define fr(s,n) for (int i=(int)(s);i<(int)(n);i++)
#define lc cout<<"\n"
int main(){
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;

    ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
    int n;
    cin>>n;
    string s="ACL";
    fr(0,n){
        cout<<s;
    }
}




Measured memory_bytes: 3648
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = 0;
		while(true) {
		    int x = sc.nextInt();
		    i++;
		    if (x == 0) break;
		    System.out.println("Case " + i + ": " + x);
		    
		}
		    
		
    }
}


Measured memory_bytes: 42796
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int *heightTable;
int *widthTable;

void func(int N,int M){
	int h_value[N],w_value[M];

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&h_value[loop]);
		heightTable[h_value[loop]]++;
	}

	for(int loop = 0; loop < M; loop++){
		scanf("%d",&w_value[loop]);
		widthTable[w_value[loop]]++;
	}

	int S;

	for(int range = 2; range <= N; range++){

		S = 0;

		for(int right = 0; right < range;right++){
			S += h_value[right];
		}

		heightTable[S]++;

		for(int left = 1; left <= N-range; left++){
			S -= h_value[left-1];
			S += h_value[left+range-1];
			heightTable[S]++;
		}
	}

	for(int range = 2; range <= M; range++){

		S = 0;

		for(int right = 0; right < range;right++){
			S += w_value[right];
		}

		widthTable[S]++;

		for(int left = 1; left <= M-range; left++){
			S -= w_value[left-1];
			S += w_value[left+range-1];
			widthTable[S]++;
		}
	}

	int ans = 0;

	for(int i = 1; i <= 1500000; i++){
		ans += heightTable[i]*widthTable[i];
	}

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

}

int main(){

	int N,M;

	heightTable = new int[1500001];
	widthTable = new int[1500001];

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		for(int i = 0; i <= 1500000; i++){
			heightTable[i] = widthTable[i] = 0;
		}

		func(N,M);
	}

    return 0;
}

Measured memory_bytes: 14436
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

A, B, C = map(int, readline().split())

for i in range(1, B+1):
    if A * i % B == C:
        print('YES')
        quit()
print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge;

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

    int bingo[9];
    rep(i, 9) cin >> bingo[i];

    // for (int i = 0; i < 3; i++)
    // {
    //     for (int j = 0; j < 3; j++)
    //     {
    //         cin >> a[3 * i + j];
    //     }
    // }

    cin >> n;
    vi vec(n);
    rep(i, n) cin >> vec[i];

    bool bin[9] = {false};
    for (const auto &v : vec)
    {
        rep(i, 9)
        {
            if (v == bingo[i])
                bin[i] = true;

            //cout << bingo[i] << endl;
        }
        //cout << v << endl;
    }

    if (bin[0] && bin[1] && bin[2])
        cout << "Yes" << endl;
    else if (bin[3] && bin[4] && bin[5])
        cout << "Yes" << endl;
    else if (bin[6] && bin[7] && bin[8])
        cout << "Yes" << endl;
    else if (bin[0] && bin[3] && bin[6])
        cout << "Yes" << endl;
    else if (bin[1] && bin[4] && bin[7])
        cout << "Yes" << endl;
    else if (bin[2] && bin[5] && bin[8])
        cout << "Yes" << endl;
    else if (bin[0] && bin[4] && bin[8])
        cout << "Yes" << endl;
    else if (bin[2] && bin[4] && bin[6])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

set<int> numbers;
int n, k, cards[10], used[10];

void addcard(int x, int y){
  if(x == 0){
    numbers.insert(y);
  }
  for(int i = 0;i < n;i++){
    if(used[i] == 0){
      int shift = 10;
      if(cards[i] >= 10)shift *= 10;
      used[i] = 1;
      addcard(x - 1, y * shift + cards[i]);
      used[i] = 0;
    }
  }
}

int main(){
  while(1){
    numbers.clear();
    scanf("%d%d", &n, &k);
    if(n == 0 && k == 0)return 0;
    for(int i = 0;i < n;i++){
      used[i] = 0;
      scanf("%d", cards + i);
    }
    addcard(k, 0);
    printf("%d\n", numbers.size());
  }
}

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

int main() {
    int n, a, b;
    ll k;
    cin >> n >> k;
    map<int, ll> mp;
    for (int i = 0; i < n; i++) {
        scanf(" %d %d", &a, &b);
        mp[a] += b;
    }
    for (auto it: mp) {
        if (k <= it.second) {
            cout << it.first << endl;
            break;
        }
        k -= it.second;
    }

    return 0;
}

Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Small_Large_or_Equal
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);

            if (a > b)
                Console.WriteLine("a > b");
            else if (a < b)
                Console.WriteLine("a < b");
            else
                Console.WriteLine("a == b");
        }
    }
}

Measured memory_bytes: 8876
import collections
n,p=map(int,input().split())
factor=[]
if n==1:
    print(p)
    exit()
for i in range(2,int(p**0.5)+1):
    while p%i==0:
        p=p//i
        factor.append(i)
#print(factor)
if not factor:
    print(1)
    exit()
ans=1
a=collections.Counter(factor)

for s,v in a.items():
    ans*=s**(v//n)
print(ans)

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

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    long long  st=1,sa=1,t,a;
    for(int i=0;i<n;i++)
    {
        scanf("%lld%lld",&t,&a);

        if(t >=st&&a<sa)
        {
            if(sa%a==0)
            {
                t*=sa/a;
                a*=sa/a;
            }
            else
            {
                t*=sa/a+1;
                a*=sa/a+1;
            }
        }
        else if(t <st&&a >=sa)
        {
            if(st%t==0)
            {
                a*=st/t;
                t*=st/t;
            }
            else
            {
                a*=st/t+1;
                t*=st/t+1;
            }
        }
        else if(t <st&&a<sa)
        {
            long long  x,y;
            x = st/t;
            y = sa/a;
            if(st%t!=0) x++;
            if(sa%a!=0) y++;
            t*=max(x,y);
            a*=max(x,y);
        }
        sa = a;
        st =t;
    }
    printf("%lld\n",sa+st);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main()
{
  int n, k;
  string s;
  cin >> n >> k >> s;
  s[k - 1] = s[k - 1] + 32;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

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

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n, k;
	while(cin >> n >> k) {
		vector<LL> v(n);
		REP(i, n) cin >> v[i];
		int ans = 0;
		REP(pc, k+1) {
			REP(bo, pc + 1) {
				vector<LL> pd;
				if(pc >= SZ(v)) {
					pd = v;
				} else {
					REP(i, bo) {
						pd.push_back(v[i]);
					}
					RREP(i, pc - bo) {
						if(SZ(v) - 1 - i >= bo) {
							pd.push_back(v[SZ(v) - 1 - i]);
						}
					}
				}
				// REP(i, SZ(pd)) {
				// 	if(pd[i] < 0) {
				// 		mv.push_back(pd[i]);
				// 	} else {
				// 		pv.push_back(pd[i]);
				// 	}
				// }
				sort(ALL(pd));
				// sort(ALL(pv));
				// sort(ALL(mv));
				// reverse(ALL(mv));
				// pd.clear();
				// REP(i, SZ(mv)) {
				// 	pd.push_back(mv[i]);
				// }
				// REP(i, SZ(pv)) {
				// 	pd.push_back(pv[i]);
				// }
				// dpite(ALL(pd));
				int sum = 0;
				REP(i, min(k - pc, SZ(pd))) {
					if(pd[i] < 0) {
						continue;
					}
					sum += pd[i];
				}
				FOR(i, min(k - pc, SZ(pd)), SZ(pd)) {
					sum += pd[i];
				}
				DEBUG(sum);
				chmax(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>

#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long


using namespace std;


long long calc(long long n){

        switch(n%4){

            case 0:
                return n;
            case 1:
                return 1ll;
            case 2:
                return n+1;
            case 3:
                return 0ll;
        }
}



int main() {
    FASTIO
    ll a,b;cin >> a >> b;
    ll a1 = calc(a-1);
    ll b1 = calc(b);
    ll ans = b1^a1;
    if(a > 0)
        cout << ans;
    else
        cout << b1;
}

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

using namespace std;

int N;

vector<long long int > a;

vector<pair<long long int, long long int> > V;

long long int CAND(long long int h) {
	long long int A = a[h] / 2;
	if (a[N - 1] >= A) { return a[N - 1]; }
	if (A >= a[h + 1]) { return a[h + 1]; }

	long long int min, med, max;
	min = h + 1; max = N - 1;
	while (1) {
		med = (min + max + 1) / 2;
		if (a[med] == A) { return A; }
		if (a[med] - A >= 0 && a[med + 1] - A <= 0) { break; }
		else if (a[med + 1] - A > 0) { min = med + 1; }
		else /*(a[med] - A < 0)*/ { max = med - 1; }
	}

	if (abs(a[med]*2-a[h]) < abs(a[med + 1]*2-a[h])) { return a[med]; }
	else {return a[med + 1]; }

	return -9999;
}

int main(void) {

	cin >> N;

	long long int tmp;
	for (int i = 0; i < N; i++) {
		cin >> tmp; a.push_back(tmp);
	}

	sort(a.rbegin(), a.rend());

	

	for (int i = 0; i < N-1; i++) {
		long long int k = CAND(i);
		V.push_back(pair<long long int, long long int>(a[i], k));
	}

	long long int I, J, I_max, J_max, num, max_num = 0;

	for (int i = 0; i < V.size(); i++) {
		I = V[i].first; J = V[i].second;
		num = I + min(J,I-J);
		if (num > max_num) { max_num = num; I_max = I; J_max = J; }
	}

	/*for (int i = 0; i < V.size(); i++) {
		cout << V[i].first << " " << V[i].second << endl;

	}*/

	cout << I_max << " " << J_max << endl;

	//system("pause");
	return 0;
};

Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<cstring>
#define eps 1e-8
#define pi acos(-1)
#define mp make_pair
#define PH push
#define pb push_back
#define PII pair<ll,ll>
#define VI vector<int>
#define fi first
#define se second
#define N(a,b) a=N(a,b)
#define Min(a,b) a=min(a,b)
#define sqr(x) ((x)*(x))
#define CL(a) memset(a,0,sizeof a)
#define fr(i,n) for(int i=1;i<=n;i++)
#define FR(i,S,n) for(int i=S;i<=n;i++)
#define dr(i,n) for(int i=n;i;i--)
#define DR(i,n,S) for(int i=n;i>=S;i--)
#define SZ(x) ((int)(x).size())
#define all(n) n.begin(),n.end()
#define rd(x) scanf("%d",&x)
#define pr(x) printf("%d",x)
#define prn(x) printf("%d\n",x)
typedef long long ll;
typedef unsigned long long ull;
ll expow(ll a,ll b,ll p) {ll v=1; for (; b; b>>=1,a=a*a%p)if (b&1)v=v*a%p; return v;}
ll inv(ll a,ll p) {return expow(a,p-2,p);}
using namespace std;
const int N=1000+10;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    //cout<<a[0]<<" "<<a[1];
    puts(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i< (int)(n); i++)
#define rep2(i,x,n) for(int i = (int)x; i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int ab, bc, ca;
	cin >> ab >> bc >> ca;
	printf("%d\n", ab * bc / 2);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	cout << max(0LL, b * (n - 1) + a - a * (n - 1) - b + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }

    var harr = BooleanArray(h){ false }
    var warr = BooleanArray(w){ false }

    var aarr = Array<String>(h){""}
    repeat(h) { hh ->
        val a = readLine()!!

        var all = true
        repeat(w) { ww ->
            if (a[ww] == '#') {
                warr[ww] = true
                all = false
            }
        }
        harr[hh] = !all
        aarr[hh] = a
    }

    repeat(h) { hh ->
        if (harr[hh]) {
            repeat(w) { ww ->
                if (warr[ww]) print(aarr[hh][ww])
            }
            println()
        }
    }
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

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

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int x,a,b;cin>>x>>a>>b&&x|a|b;){
		if(-a+b<=0)
			cout<<"delicious"<<endl;
		else if(-a+b<=x)
			cout<<"safe"<<endl;
		else
			cout<<"dangerous"<<endl;
	}
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
#define TRUE 1
 
Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
 
  z->parent = y;
  if(y==NIL) root  = z;
  else if(y->key > z->key) y->left=z;
  else y->right = z;
 
}
 
void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}
 
void preorder(Node u){
  if(u!=NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}
 
Node find(int k,Node u){
  if(u==NIL || u->key==k) return u;
  if(k > u->key) return find(k,u->right);
  else return find(k,u->left);
 
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void derete(Node u){
  Node x;
  Node y;

  if(u->left==NIL || u->right ==NIL) y=u;
  else y=treeSuccessor(u);
 
  if(y->left!=NIL) x=y->left;
  else x=y->right;
 
  if(x!=NIL) x->parent=y->parent;
 
  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;
 
  if(y!=u) u->key=y->key;
}


 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     
    if(com[0]=='f'){
      scanf("%d", &x);
      Node t = find(x,root);
      if ( t != NIL ) printf("yes");
      else printf("no");
      printf("\n");
    }
 
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }

    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      derete(find(x,root));
    }
 
  }
  return 0;
}

Measured memory_bytes: 19348
fun main(args: Array<String>) {
    val n = Integer.parseInt(readInputLine())
    val inputs = readInputLine().split(" ").map { Integer.parseInt(it) }
    val aList: MutableList<Int> = mutableListOf()
    
    for (i in 0 until n) {
        aList.add(inputs[i])
    }
    
    aList.sortDescending()

    var ans = 0
    
    var isAlice = true
    
    for (elem in aList) {
        if (isAlice) {
            ans += elem
        } else {
            ans -= elem
        }
        isAlice = !isAlice
    }
    
    println("$ans")
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37928
#include <cstdio>
#include <cstring>


#define M 1046527
#define NIL (-1)
#define L 14
char H[M][L];
 
int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }
    else if (ch == 'C'){
        return 2;
    }
    else if (ch == 'G'){
        return 3;
    }
    else if (ch == 'T'){
        return 4;
    }
    else return 0;
}

long long getKey(char str[]){
    long long sum = 0,p=1,i;
    for (i = 0;i<strlen(str);i++){
        sum+=p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1+(key %(M-1));}
int find(char str[]){
    long long key,i,h;
    key = getKey(str);
    for (i = 0;;i++){
        h = (h1(key)+i*h2(key)) % M;
        if (strcmp(H[h],str)==0)return 1;
        else if (strlen(H[h])==0)return 0;
    }
    return 0;
}
int insert(char str[]){
    long long key,i,h;
    key = getKey(str);
    for(i = 0;;i++){
        h = (h1(key)+i*h2(key))%M;
        if (strcmp(H[h],str) == 0) return 1;
        else if (strlen(H[h]) == 0){
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i,n,h;
    char str[L],com[9];
    for (i=0;i<M;i++){
        H[i][0]='\0';
    }
    scanf("%d",&n);
    for (i=0;i<n;i++){
        scanf("%s %s",com,str);
        if (com[0] == 'i'){
            insert(str);
        }
        else {
            if(find(str)){
                printf("yes\n");
            }
            else{
                printf("no\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 17052
#include <iostream>
#include <numeric>
#include <cmath>
#include <queue>
#include <limits>
#include <stdio.h>
#include <iomanip>
#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
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}


int main() {
	ll N;
	string an = "Yes";
	cin >> N;
	vector<ll> t(N + 1);
	vector<ll> x(N + 1);
	vector<ll> y(N + 1);
	t[0] = 0; x[0] = 0, y[0] = 0;
	rep(i, N) {
		cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
		if (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]) > (t[i + 1] - t[i]))an = "No";
		else if (((t[i + 1] - t[i]) - (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]))) % 2 != 0) {
			an = "No";
		}
	}
	cout << an << endl;
}

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

int main(){
	string s; cin>>s;
	int k=s.size();
	int cnta=0, cntb=0;
	rep(i,k){
		char a,b;
		
		if(i%2==0) a='0';
		else a='1';
		if(s[i]!=a) cnta++;
		
		if(i%2==0) b='1';
		else b='0';
		if(s[i]!=b) cntb++;	
	}
	cout<<min(cnta,cntb)<<endl;
}

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

A = [0 for i in range(10**4+1)]

for x in range(1, 100):
  for y in range(1, 100):
    for z in range(1, 100):
      a = x*x + y*y + z*z + x*y + y*z + z*x
      if a <= 10**4:
        A[a] += 1

for i in range(1, N+1):
  print(A[i])

Measured memory_bytes: 9140
R, G, B, N = map(int, input().split())

ans = 0

for r in range(N+1):
  if r*R > N:
    break
  for g in range(N+1):
    rg = r*R + g*G
    if rg > N:
      break
    if (N - rg)%B == 0 :
      ans += 1
      
print(ans)
    

Measured memory_bytes: 2940