akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

long long rhash(string s)
{
    long long ret = s[0] - 'a';
    for (int i = 1; i < s.length(); i++)
    {
        ret += ret * 26 + s[i] - 'a';
    }
    return ret;
}

int main()
{
    int n;
    unsigned long long ans = 0LL;
    cin >> n;
    vector<string> s(n);
    map<long long, int> mp;
    for (auto i : s)
    {
        cin >> i;
        sort(i.begin(), i.end());
        long long hash = rhash(i);
        mp[hash]++;
    }
    for (auto x : mp)
    {
        long long cnt = x.second;
        ans += cnt * (cnt - 1) / 2LL;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 7296
a = int(input())

num_list = [a]
init_flag = True
result = 1
while True:
	result += 1
	num = num_list[-1]
	if num%2 == 0:
		new_num = int(num/2)
	else:
		new_num = int(3*num+1)

	if not init_flag and new_num in num_list:
		#print(num_list.index(num))
		print(result)
		break
	num_list.append(new_num)
	init_flag = False
	

Measured memory_bytes: 3060
from itertools import combinations

N, *L = map(int, open(0).read().split())

result = 0
for a, b, c in combinations(L, 3):
    if a == b or b == c or c == a:
        continue
    if a + b > c and b + c > a and c + a > b:
        result += 1
print(result)


Measured memory_bytes: 9212
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

static const int MAX = 100001;

/******* c++14 don't include *******/

template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }

/*******                      *******/

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n, m;
    cin >> n >> m;
    int max_l = -1;
    int min_r = MAX;
    rep(i, m){
        int l, r;
        cin >> l >> r;
        if(max_l>r || l>min_r){
            cout << 0 << endl;
            return 0;
        }
        max_l = max(max_l, l);
        min_r = min(min_r, r);
    }
    
    cout << min_r-max_l+1 << endl;
    
    return 0;
}


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

using namespace std;

int main(void){
	int tmp;
	stack<int> st;
	vector<int> vehicles;

	while (cin >> tmp){
		if (tmp != 0){
			st.push(tmp);
		}
		else{
			if (st.empty() == false){
				vehicles.push_back(st.top());
				//cout << st.top() << endl;
				st.pop();
			}
		}
	}

	vector<int>::iterator it = vehicles.begin();
	while (it != vehicles.end()){
		cout << *it << endl;
		++it;
	}
	return 0;
}

Measured memory_bytes: 1220
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"math"
)
 
func run() {

	var A int64;
    A = nextInt();
    var B int64;
    B = nextInt();
	solve(A, B);

}

func solve(A int64, B int64){
	Println(math.Max(math.Max(float64(A+B),float64(A-B)),float64(A*B)))
}


// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int64 {
	a, err := strconv.ParseInt(next(),10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}


Measured memory_bytes: 2816
n = int(input())
h = [int(x) for x in input().split()]
dp = [float("inf")]*n
dp[0] = 0
dp[1] = abs(h[0]-h[1]) 
for i in range(2,n):
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[-1])

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi vector<int>
#define pii pair<int,int> 
#define piii pair<pair<int,int>,int> 

#define chalne_de continue
int mod=1000000007;
const int N = 1000005;

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	int x , y ;
	cin >> x >> y;
	int a[] = {4,6,9,11};
	map<int,int> m,s;
	int b[] = {1,3,5,7,8,10,12};
	for ( int i = 0; i< 7; i++)
		s[b[i]] = true;
	for ( int i =0; i < 4;i++)
		m[a[i]] = true;
	if ( x == 2 || y == 2)
	{
		cout << "No\n";
	}
	else
	{
		if ( m[x] == true && m[y] == true)
			cout << "Yes\n";
		else if ( s[x] == true && s[y] == true)
		{
			cout << "Yes\n";
		}
		else
			cout << "No";
	}
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define MAX_N 100000
#define P 1000000007
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n; lnt ans;
lnt inv[MAX_N+5] = {1, 1};
lnt a[MAX_N+5], b[MAX_N+5];
int main() {
	read(n); for (int i = 1; i <= n; i++) read(a[i]);
	for (int i = 2; i <= n; i++) inv[i] = P-P/i*inv[P%i]%P;
	for (int i = 1; i <= n; i++) b[i] = (b[i-1]+inv[i])%P;
	for (int i = 1; i <= n; i++)
		(ans += (b[i]+b[n-i+1]-1+P)%P*a[i]%P) %= P;
	for (int i = 1; i <= n; i++) (ans *= i) %= P;
	return printf("%lld\n", ans), 0;
}

Measured memory_bytes: 2560
class Segtree(object):
    def __init__(self,A,f,u):
        n=2**(len(A).bit_length())
        N=2*n-1
        self.__num=n
        self.__len=N
        self.__seg=[u]*N
        self.__f=f
        self.__u=u
        # init
        for i in range(len(A)): # set
            self.__seg[n+i-1]=A[i]
        for i in range(n-2,-1,-1): # built, iの子のnodeは2i+1,2i+2
            self.__seg[i]=f(self.__seg[2*i+1],self.__seg[2*i+2])

    def __repr__(self):
        return str(self.__seg)

    def get_tree(self):
        return self.__seg

    def update(k,v):
        "A[k]=v"
        k+=self.__num-1
        self.__seg[k]=v
        while k+1: # k=0の処理が終わったら-1になってる
            k=(k-1)//2 # kの親のnodeは(k-1)//2
            self.__seg[k]=self.__f(self.__seg[k*2+1],self.__seg[k*2+2])

    def query(self,p,q): # reduce(f,A[p:q])
        if q<=p: return self.__u
        p+=self.__num-1
        q+=self.__num-2
        res=self.__u
        while q-p>1:
            if p&1==0:
                res=self.__f(res,self.__seg[p])
            if q&1==1:
                res=self.__f(res,self.__seg[q])
                q-=1
            p=p//2
            q=(q-1)//2
        if p==q: res=self.__f(res,self.__seg[p])
        else: res=self.__f(self.__f(res,self.__seg[p]),self.__seg[q])
        return res


def resolve():
    from fractions import gcd
    n=int(input())
    A=list(map(int,input().split()))
    if n==2:
        print(max(A))
        return
    seg=Segtree(A,gcd,0)
    ans=0
    for i in range(n):
        ans=max(ans,gcd(seg.query(0,i),seg.query(i+1,n)))
    print(ans)

resolve()

Measured memory_bytes: 90720
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int eu[N],ev[N],cnt;
void add(int u,int v){
	cnt++;
	eu[cnt]=u,ev[cnt]=v;
}
int main()
{
    int n;
    scanf("%d",&n);
    int f=n-(n&1);
    for(int i=1;i<=f;i++){
        for(int j=i+1;j<=f;j++)
			if(j!=f+1-i)
				add(i,j);
    }
    if(f!=n)
		for(int i=1;i<=f;i++)
			add(i,n);
	printf("%d\n",cnt);
	for(int i=1;i<=cnt;i++)
		printf("%d %d\n",eu[i],ev[i]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
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...));
}

const int MOD = 1000000007;




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

    vector<string> a(H);
    rep(i,H) cin >> a[i];

    vector<string> ans;
    rep(i,H){
        string tmp = "";
        rep(j,W){
            bool isVerticalOK = false;
            rep(k,H){
                if (a[k][j] == '#'){
                    isVerticalOK = true;
                }
            }
            bool isHorizontalOK = false;
            rep(k,W){
                if (a[i][k] == '#'){
                    isHorizontalOK = true;
                }
            }
            if (isVerticalOK && isHorizontalOK) tmp += a[i][j];
        }
        if (tmp != ""){
            ans.push_back(tmp);
        }
    }

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



Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int x = in.nextInt();
            int y = in.nextInt();

            UnionFind uf = new UnionFind();
            uf.init(13);
            uf.unite(1, 3);
            uf.unite(1, 5);
            uf.unite(1, 7);
            uf.unite(1, 8);
            uf.unite(1, 10);
            uf.unite(1, 12);
            uf.unite(4, 6);
            uf.unite(4, 9);
            uf.unite(4, 11);

            System.out.println(uf.isSame(x, y) ? "Yes" : "No");
        }
    }
}

class UnionFind {
    private int[] par;
    private int[] rank;

    public void init(int n) {
        par = new int[n];
        rank = new int[n];
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    public int getRoot(int x) {
        if (par[x] == x) {
            return x;
        } else {
            par[x] = getRoot(par[x]);
            return par[x];
        }
    }

    public void unite(int x, int y) {
        x = getRoot(x);
        y = getRoot(y);
        if (x == y) {
            return;
        }
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
    }

    public boolean isSame(int x, int y) {
        return getRoot(x) == getRoot(y);
    }
}

Measured memory_bytes: 27016
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

dt = 0.006
diff = 100000000

for i in range(N):
    temp = T - H[i]*dt
    if diff > abs(temp-A):
        diff = min(diff, abs(temp-A))
        ans = i+1
    
print(ans)

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

LL N, W, w[112], v[112];
std::vector<std::pair<LL, LL>>wv;
std::vector<std::pair<LL, LL>>A, B;
LL ans;

int main()
{
	in >> N >> W;
	wv.resize(N);
	rep(i, N)
	{
		in >> v[i] >> w[i];
		wv[i].first = v[i], wv[i].second = w[i];
	}
	auto x = N / 2, y = N - N / 2;
	A.resize(1 << x); B.resize(1 << y);
	rep(i, (1 << x))
	{
		rep(j, x)
		{
			if (i&(1 << j))
			{
				A[i].first += wv[j].second;
				A[i].second += wv[j].first;
			}
		}
	}
	std::sort(A.begin(), A.end());
	for (LL i = 1; i < (1 << x); ++i) { A[i].second = std::max(A[i].second, A[i - 1].second); }
	rep(i, (1 << y))
	{
		rep(j, y)
		{
			if (i&(1 << j))
			{
				B[i].first += wv[x + j].second;
				B[i].second += wv[x + j].first;
			}
		}
	}
	for (auto b : B)
	{
		auto iter = std::upper_bound(A.begin(), A.end(), std::pair<LL, LL>(W - b.first, 1000000000000000ll));
		if (iter != A.begin()) { ans = std::max(ans, b.second + (iter - 1)->second); }
	}

	out << ans << std::endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl;
#define CNO cout<<"No"<<endl;

typedef long long LL;
typedef long double LD;

int n;
vector<int> a;
vector<int> ans;

void swp(){
  ans.push_back(n-1);
  swap(a[0],a[n-1]);
}

void sft(){
  ans.push_back(1);
  int tmp=a[0];
  rep(i,n-1) a[i]=a[i+1];
  a[n-1]=tmp;
}

int main(){
  cin >> n;
  a=vector<int>(n);
  rep(i,n) cin >> a[i];
  repp(i,1,n){
    while(a[0]!=i) sft();
    while(1){
      sft();
      swp();
      if(a[n-1]==i-1) break;
    }
  }
  sft();
  // rep(i,n) cout << a[i] << " ";
  // cout << endl;
  cout << ans.size() << endl;
  rep(i,ans.size()) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 892
def floor(a,b,n):
    if b == 1:
        print(0)
    elif n < b:
        print(int(a*n/b)-a*int(n/b))
    else:
        print(int(a*(b-1)/b))

a, b, n = [int(i) for i in input().split()]
floor(a,b,n)

Measured memory_bytes: 9136
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main() {
	while (true) {
		int n[4], cnt;
		char wat[4];
		scanf("%s", &wat);
		if (wat[0] == '0'&&wat[1] == '0'&&wat[2] == '0'&&wat[3] == '0') { goto endnow; }
		for (int i = 0;i < 4;++i) {
			n[i] = (int) wat[i] - 48;
		}
		for (int i = 1;i < 10;++i) {
			if (n[0] == i&&n[1] == i&&n[2] == i&&n[3] == i) {
				printf("NA\n");
				goto Ihatemath;
			}
		}
		cnt = 0;
		while (true) {
			int l[4];
			if (n[0] == 6 && n[1] == 1 && n[2] == 7 && n[3] == 4) {
				printf("%d\n", cnt);
				goto Ihatemath;
			}
			memcpy(l, n, sizeof(n));
			sort(l, l + 4,greater<int>());
			int lon = l[0] * 1000 + l[1] * 100 + l[2] * 10 + l[3];
			int shor = l[0] + l[1] * 10 + l[2] * 100 + l[3] * 1000;
			int wanna = lon - shor;
			n[0] = wanna / 1000;
			wanna = wanna % 1000;
			n[1] = wanna / 100;
			wanna = wanna % 100;
			n[2] = wanna / 10;
			wanna = wanna % 10;
			n[3] = wanna;
			cnt++;
		}
	Ihatemath:;
	}
endnow:;
	return 0;
}


Measured memory_bytes: 996
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int extra = (a * b) % 2;
        if (extra == 1) {
            System.out.println("Odd");
        } else if (extra == 0) {
            System.out.println("Even");
        }
    }
}

Measured memory_bytes: 20564
n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

ans = 0
for v in a:
  if x < v:
    print(ans)
    break
  x -= v
  ans += 1
else:
  if x != 0:
    ans -= 1
  print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    //今から文字入力
    int a;
    int b;
    int c;
    cin>>a>>b>>c;
    if(a>b)
    {
        swap(a,b);
    }
    if(b>c)
    {
        swap(b,c);
    }
    if(a>b)
    {
        swap(a,b);
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <cstdlib>
#include <iomanip>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <iterator>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <cstring>
#include <sstream>
#include <stack>
#include <random>

using namespace std;

#define vi vector<int> 
#define vvi vector<vi>
#define pi pair<int,int>
#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define io ios::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(a) int((a).size()) 
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define loop(i,b) for (int i = 0; i < b; ++i)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define INF numeric_limits<int>::max()
#define LLINF numeric_limits<ll>::max()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define F first
#define S second
#define MOD 1000000007
#define cflout(x) cout << fixed << setprecision(8) << x << endl
#define setzero(x) memset(x, 0, sizeof(x))

#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif

random_device _random_device;
default_random_engine _generator(_random_device());
uniform_int_distribution<long long unsigned> _distribution(0, 0xFFFFFFFFFFFFFFFF);

inline long long unsigned get_random_number() {
    return _distribution(_generator);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

inline ll nxt() {
	ll x;
	cin >> x;
	return x;
}

namespace aux {	
vector<string> split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) {
		v.emplace_back(x);
    }
    return v;
}
}

int n;

int main() {
	io;
	n = nxt();
	ll ans = 0;
	loop(i, n) {
		int l = nxt(), r = nxt();
		ans += (r-l+1);
	}
	cout << ans << endl;




	return 0;
}




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

int dataSet[10];
bool bz_flag[10];
stack<int> temp_A,temp_B;

bool test_cl (int data_pos)
{
	if (data_pos<10)
	{
		if (temp_A.empty())
		{
			temp_A.push(dataSet[data_pos]);
			bz_flag[data_pos] = true;
			return test_cl(data_pos + 1);
		}
		else
		{
			if (temp_A.top()<dataSet[data_pos])
			{
				temp_A.push(dataSet[data_pos]);
				bz_flag[data_pos] = true;
				return test_cl(data_pos + 1);
			}
			else
			{
				if (temp_B.empty())
				{
					temp_B.push(dataSet[data_pos]);
					bz_flag[data_pos] = true;
					return test_cl(data_pos + 1);
				}
				else
				{
					if (temp_B.top() < dataSet[data_pos])
					{
						temp_B.push(dataSet[data_pos]);
						bz_flag[data_pos] = true;
						return test_cl(data_pos + 1);
					}
					else
					{
						return false;
					}
				}
			}
		}
	}
	else
	{
		return true;
	}
}

int main ()
{
	int N;
	cin>>N;
	while (N--)
	{
		memset(bz_flag,false,sizeof(bz_flag[0]));
		for (int i=0;i<10;i++)
		{
			cin>>dataSet[i];
		}
		if (test_cl(0) == true)
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
		while (!temp_A.empty())
		{
			temp_A.pop();
		}
		while (!temp_B.empty())
		{
			temp_B.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>

using namespace std;

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



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

int main()
{
    int a,b,box1,box2;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        box1=a;
        box2=b;
        while(b)
        {
            int q=a%b;
            a=b;
            b=q;
        }
        printf("%d %d\n",a,box1/a*box2);
    }
    return 0;
}

Measured memory_bytes: 1188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static double Solve(int N, int[][] points)
        {
            double sum = 0;
            for (int i = 0; i < N; ++i)
            {
                for (int j = 0; j < N; ++j)
                {
                    double x = points[i][0] - points[j][0];
                    double y = points[i][1] - points[j][1];
                    sum += Math.Sqrt(x * x + y * y);
                }
            }
            return sum / N;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            var points = new int[N][];
            for (int i = 0; i < N; ++i) { points[i] = ReadInts(); }
            Console.WriteLine(Solve(N, points));
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int k,soma=0;
  cin>>k;
  for(int a=1;a<=k;a++){
    for(int b=1;b<=k;b++){
      for(int c=1;c<=k;c++){
        soma+=__gcd(__gcd(a,b),c);
      }
    }
  }
  cout<<soma<<endl;
  return 0;
}

Measured memory_bytes: 3640
import math
def trial_division(tar):
	dest  = int(math.sqrt(tar))+1
	for i in range(2,dest):
		if tar%i == 0:
			#print(int(i))
			return int(0) #not prime number
	return int(1) #prime number

x = int(input())
while trial_division(x)==0:
	x+=1
print(x)

Measured memory_bytes: 2940
from collections import defaultdict
import heapq


class Dijkstra:
    """
    dijkstraの最短経路問題を解く
    input:
        S: start node
        adj: adj[a]=[(b,dist)]//なんとなく
    """

    def __init__(self, start, num_node, adj):
        """
        adj: adj[a]=[(b,dist)]
        num_node: num of nodes
        dist: dist from start_node
        prev: 最短経路において、一つ前のノードを記憶。経路復元に使う?
        """
        self.start_node = start
        self.adj= adj
        self.num_node = num_node
        self.dist = [float('inf')]*num_node
        self.prev = defaultdict(lambda: None)

        # dist form S to S = 0
        self.dist[start] = 0

    def calc_dist(self):
        """
        最短経路 distを計算する
        Q: content (dist_from_start,node)
        Qはheapqとして使う。dist_from_startの小さい順になる
        Qには、dist*N+nodeを入れることで高速化
        """
        Q = []
        heapq.heappush(Q, self.start_node)
        while Q:
            dist_to_node, node = divmod(heapq.heappop(Q),self.num_node)
            # 現在の値よりも大きくて、更新にならない場合
            if self.dist[node] < dist_to_node:
                continue

            # 次のホップを計算する
            for nex,weight in self.adj[node]:
                cand = dist_to_node + weight

                if self.dist[nex] > cand:  # update
                    self.dist[nex] = cand
                    self.prev[nex] = node
                    heapq.heappush(Q, cand*self.num_node+nex)

    def get_dist(self, d):
        """
            startからdまでの距離を返す
            これの前にcalc()を実行しておく
            たどり着けない場合は、float('inf')がかえる
        """
        return self.dist[d]
    def get_path(self,dst):
        """
        startからdstまでのpathをlistでreturn
        valifyしてないので怪しい
        """
        cur=dst
        ret=[cur]
        while cur!=self.start_node:
            cur=self.prev[cur]
            ret.append(cur)
        return list(reversed(ret))
N,M,S = map(int,input().split())
edges=[list(map(int,input().split())) for _ in range(M)]
C=[list(map(int,input().split())) for _ in range(N)]

max_c=2501


def toId(node,cur):
    return node*max_c+cur

def revId(id):
    return id//max_c,id%max_c


states=N*max_c
adj=[[] for _ in range(states)]


for a,b,c,d in edges:
    a-=1
    b-=1
    for cc in range(max_c-c):
        adj[toId(a,cc+c)].append((toId(b,cc),d))
        adj[toId(b,cc+c)].append((toId(a,cc),d))

for i,(c,d) in enumerate(C):
    for cc in range(max_c-c):
        adj[toId(i,cc)].append(((toId(i,cc+c),d)))


#for i,a in enumerate(adj):
#    print("from {}".format(revId(i)))
#    for v,d in a:
#        print("\t: {} cost:{}".format(revId(v),d))
    
S=min(S,max_c-1)
start=toId(0,S)

D=Dijkstra(start,states,adj)
D.calc_dist()
for i in range(1,N):
    ans=float("inf")
    path=None
    for cc in range(max_c):
        if ans>D.get_dist(toId(i,cc)):
            ans=D.get_dist(toId(i,cc))
            path=D.get_path(toId(i,cc))
    print(ans)



Measured memory_bytes: 135644
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fastAF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mapll map<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define deb(x) cout<<x
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
void swap(auto*,auto*);
int main()
{
   
    fastAF
    string s; cin>>s;
    ll sum=0;
    for(ll i=0;i<s.length();i++)
    {
    	sum+=s[i]-'0';
    }
    if(sum%9==0) cout<<"Yes\n"; else cout<<"No\n";
}
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;
}

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

using namespace std;
typedef long long int ll;

const ll p = 31;
const ll N = 1e9 +1;


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

  ll n;
  cin>>n;
  ll a[n];
  ll ctm = 0;
  ll ctt = 0;
  for(int i = 0;i<n;i++){
  	cin>>a[i];
  	if(i==0){
  		
  	}
  	else{
  		if(a[i]<=a[i-1]){
  			ctt++;
  		}
  		else{
  			ctm = max(ctt,ctm);
  			ctt = 0;
  		}
  	}
  	
  }
  ctm = max(ctt,ctm);
  cout<<ctm;


}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

#define pow2(x) ((x) * (x))

using namespace std;

int main( void )
{
	int A, B, C;

	while (cin >> A >> B >> C, A | B | C)
	{
		int val = pow2(min(A, B)) + pow2(min(max(A, B), C));

		int n;
		cin >> n;

		for (int i=0; i < n; ++i)
		{
			int r;
			cin >> r;

			if (pow2(2 * r) > val)
				cout << "OK";
			else
				cout << "NA";
			cout << endl;
		}		
	}
	return 0;
}

Measured memory_bytes: 1156
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), W = getint();

	ll dp[100001] = {};
	rep(i, N) {
		int w = getint();
		int v = getint();
		for (int j = W - w; j >= 0; j--) {
			chmax(dp[j + w], dp[j] + v);
		}
	}

	printf("%lld", dp[W]);

	Would you please return 0;
}

Measured memory_bytes: 896
N, W = gets.split.map(&:to_i) 
OBJS = N.times.map{ gets.split.map(&:to_i) }
objs = Array.new(4){ [] }
w1 = OBJS[0][0]
OBJS.each do |w, v|
  objs[w-w1] << v
end
objs.each{|vs| vs.sort_by!{|v| -v}}
nn1, nn2, nn3, nn4 = objs[0].size, objs[1].size, objs[2].size, objs[3].size

ans = 0
for n1 in 0..nn1
  for n2 in 0..nn2
    for n3 in 0..nn3
      for n4 in 0..nn4
        #p n: [n1,n2,n3,n4]
        next if n1 > nn1 || n2 > nn2 || n3 > nn3 || n4 > nn4
        w = w1 * (n1 + n2 + n3 + n4) + (n2 + n3 + n4) + (n3 + n4) + (n4)
        next if w > W
        sum = (objs[0].first(n1) +
               objs[1].first(n2) +
               objs[2].first(n3) +
               objs[3].first(n4))
              .inject(0, :+)
        ans = sum if sum > ans
      end
    end
  end
end
p ans


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

using namespace std;

int main(int argc, const char *argv[]) {
  int N = 0;
  int index = 0;

  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  B = A;
  sort(B.begin(), B.end(), greater<int>());
  for (int i = 0; i < N; i++) {
    if (A[i] == B[index]) {
      cout << B[index + 1] << endl;
    }else{
      cout << B[index] << endl;
	}
  }
  return 0;
}


Measured memory_bytes: 3200
import scala.io.StdIn._

object Main extends App {

  val A = Array.fill(3)(readLine().split(" ").map(_.toInt))
  val n = readInt()
  val B = Array.fill(n)(readInt())



  def solve(): String = {
    val r = Array.fill(3, 3)(false)
    for {
      i <- 0 until 3
      j <- 0 until 3
    } for {
      k <- 0 until n
    } {
      if(A(i)(j) == B(k)) r(i)(j) = true
    }

    var ans = "No"
    for(i <- 0 until 3)
      if(r(0)(i) && r(1)(i) && r(2)(i)) ans = "Yes"
    for(i <- 0 until 3)
      if(r(i)(0) && r(i)(1) && r(i)(2)) ans = "Yes"
    if(r(0)(0) && r(1)(1) && r(2)(2)) ans = "Yes"
    if(r(0)(2) && r(1)(1) && r(2)(0)) ans = "Yes"
    ans
  }

  println(solve())

}



Measured memory_bytes: 55040
package main

import "fmt"

func main() {
	var N, Y int
	fmt.Scan(&N, &Y)

	check(N, Y)
}
func check(N, Y int) {
	for x := 0; x <= N; x++ {
		for y := 0; y <= (N - x); y++ {
			z := N - x - y
			if sum(x, y, z, Y) {
				fmt.Println(x, y, z)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}
func sum(x, y, z, Y int) bool {
	if 10000*x+5000*y+1000*z == Y {
		return true
	}
	return false
}


Measured memory_bytes: 512
import numpy as np

H,W=map(int,input().split())

s=np.zeros((H+2,W+2),dtype=int)

for i in range(H):
    s0=input()
    for j in range(W):
        if s0[j]==".":
            num=0
        elif s0[j]=="#":
            num=1
        
        s[i+1][j+1]=num
        

ans_s=s[1:H+1,1:W+1]

ans=0
for k in range(1,H+1):
    for l in range(1,W+1):
        if s[k][l]==1:
            if s[k-1][l]==0 and s[k+1][l]==0 and s[k][l-1]==0 and s[k][l+1]==0:
                ans=1
                break

if ans==1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 27084
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int n,k,ans=0;
   cin >> n >> k;
   int data[50];
   for(int i=0;i<n;i++){
       cin >> data[i];
   }
   sort(data,data+n);
   reverse(data,data+n);
   for(int i=0;i<k;i++){
       ans+=data[i];
   }
   cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    S = input()
    L_S = len(S)

    if L_S % 2 != 0:
        print('No')
        exit()

    for i in range(L_S // 2):
        if S[i * 2] != 'h' or S[i * 2 + 1] != 'i':
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF -999999
ll dp[101][100001]={-1};
ll fn(ll n,ll W,vector<ll>&w,vector<ll>&v,ll  index){
    //base case
    if(n<=0 || W<=0)
        return 0;
    if(dp[n][W]!=-1){
        return dp[n][W];
    }
    ll op1=0;
    ll op2=0;
    op1=fn(n-1,W,w,v,index+1);
    if(W-w[index]>=0)
    op2=v[index]+fn(n-1,W-w[index],w,v,index+1);
    else
    op2=fn(n-1,W,w,v,index+1);
    dp[n][W]=max(op1,op2);
    return dp[n][W];

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,W;
    cin>>n>>W;
    vector<ll>w(n+1);
    vector<ll>v(n+1);
    for(ll i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    for(ll i=1;i<=n;i++){
   	for(ll j=0;j<=W;j++){
   		dp[i][j]=-1;
   	}
   }
   cout<< fn(n,W,w,v,0)<<endl;
    return 0;
}


Measured memory_bytes: 78464
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
temp_sum = 0
for i in range(n):
    while b[j] < c[i]:
        temp_sum += num_b[j]
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += temp_sum

print(ans)


Measured memory_bytes: 24052
/*
 *  Created on: 26-May-2019
 *      Author: ankur314
 */
#include<bits/stdc++.h>
#define lli long long int 
#define li long int
#define db double 
#define ldb long double
#define vr vector 
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007

#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    int n,m;cin>>n>>m;
    vector <int> v[m];
    int p[m];
    fi(i,0,m)
    {
        int dump;cin>>dump;
        fi(j,0,dump)
        {
            int temp;cin>>temp;
            temp--;
            v[i].pb(temp);
        }
    }
    //fi(i,0,m)
    //{
    //	for(int iter:v[i])
    //	{
    //		cout<<iter<<" ";
    //	}
    //	cout<<"\n";
    //}
    fi(i,0,m) cin>>p[i];
    int ans=0;
    fi(i,0,pow(2,n))
    {
        bool vis[10];
        memset(vis,false,sizeof(vis));
        fi(j,0,10)
        {
            if((i & (1<<j)))
            {
                //cout<<j<<" ";
                vis[j] = true;
            }
        }
        int key=0;
        fi(i,0,m)
        {
            int val=0;
            for(int iter : v[i])
            {
                //cout<<iter<<"\n";
                if(vis[iter]) val++;
            }
            if(val % 2 != p[i]) key=1;
        }
        if(key==0) ans++;
    }
    cout<<ans;
    return 0;
}


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

int main(void){
  string board1,board2,board3;
  while(cin>>board1>>board2>>board3){
    if(board1[0]!='+' and board1[0]==board1[1] and board1[1]==board1[2]){
      cout<<board1[0]<<endl;
      continue;
    }
    if(board2[0]!='+' and board2[0]==board2[1] and board2[1]==board2[2]){
      cout<<board2[0]<<endl;
      continue;
    }
    if(board3[0]!='+' and board3[0]==board3[1] and board3[1]==board3[2]){
      cout<<board3[0]<<endl;
      continue;
    }
    if(board1[0]!='+' and board1[0]==board2[0] and board2[0]==board3[0]){
      cout<<board1[0]<<endl;
      continue;
    }
    if(board1[1]!='+' and board1[1]==board2[1] and board2[1]==board3[1]){
      cout<<board1[1]<<endl;
      continue;
    }
    if(board1[2]!='+' and board1[2]==board2[2] and board2[2]==board3[2]){
      cout<<board1[2]<<endl;
      continue;
    }
    if(board1[0]!='+' and board1[0]==board2[1] and board2[1]==board3[2]){
      cout<<board1[0]<<endl;
      continue;
    }
    if(board1[2]!='+' and board1[2]==board2[1] and board2[1]==board3[0]){
      cout<<board1[2]<<endl;
      continue;
    }
    cout<<"NA"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
object Main extends App {
  private[this] val n = scala.io.StdIn.readLine.toInt
  private[this] var color = scala.Array.fill[Int](n)(-1)
  private[this] var maps = Array.fill(n)(List.empty[(Int, Int)])
  (0 until n - 1).foreach { _ =>
    val Array(u, v, w) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val uu = u - 1
    val vv = v - 1
    maps(uu) = (vv, w) :: maps(uu)
    maps(vv) = (uu, w) :: maps(vv)
  }

  private[this] val queue = new scala.collection.mutable.Queue[(Int, Boolean)]

  queue += ((0, true))

  while (queue.nonEmpty) {
    val (n, now_color) = queue.dequeue()
    if (color(n) == -1) {
      if (now_color) {
        color(n) = 0
      } else {
        color(n) = 1
      }

      maps(n).foreach { next =>
        val nextPoint = next._1
        val nextLen = next._2
        nextLen % 2 == 0 match {
          case true =>
            queue += ((nextPoint, now_color))
          case false if now_color =>
            queue += ((nextPoint, false))
          case _ =>
            queue += ((nextPoint, true))
        }
      }
    }
  }

  color.foreach(println)
}


Measured memory_bytes: 85532
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int n; cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];

  int ans = 0, now = 0;

  for(int i = 0; i < n; i++){
    if(now < h[i]) ans += h[i] - now;
    now = h[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int arr[100005][4];
int n;
long long dp[100001][4][4];
long long func(int i,int j,int taken)
{
    if(i>n || j>3)return 0;
    if(dp[i][j][taken]!=-1)return dp[i][j][taken];
    long long ans1=0,ans2=0;
    if(j!=taken)ans1=arr[i][j]+func(i+1,1,j);
    else ans1=func(i,j+1,taken);

        ans2=func(i,j+1,taken);

    return  dp[i][j][taken]=max(ans1,ans2);
}
int main()
{
    std :: ios :: sync_with_stdio(false);

    cin>>n;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=3;j++) {
            cin>>arr[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    long long ans=func(1,1,0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 23680
N,M,K = gets.split.map(&:to_i)
MOD = 998244353

#前処理 O(n)
$fact,$fact_inv,$inv = Array.new(N+1),Array.new(N+1),Array.new(N+1)
$fact[0] = $fact[1] = 1
$fact_inv[0] = $fact_inv[1] = 1
$inv[1] = 1
for i in 2..N
  $fact[i] = $fact[i-1] * i % MOD
  $inv[i] = MOD - $inv[MOD % i]*(MOD/i) % MOD
  $fact_inv[i] = $fact_inv[i-1] * $inv[i] % MOD
end
#クエリ O(1)
def nCkMOD(n,k)
  $fact[n]*($fact_inv[k]*$fact_inv[n-k] % MOD) % MOD
end

def func(x)
  y = N - x
  ((M*(M-1).pow(y-1,MOD))%MOD) * nCkMOD(N-1,x) % MOD
end
ans = 0
for i in 0..K
  ans += func(i)
  ans % MOD
end

puts ans % MOD

Measured memory_bytes: 18988
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *right,*left,*parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x){
  while(x->left != NIL) x=x->left;
  return x;
}

Node * find(Node *u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u = u->left;
    else u=u->right;
  }
  return u;
}

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

void treeDelete(Node *z){
  Node *y;
  Node *x;

  if(z->left == NIL || z->right ==NIL) y = z;
  else y = treeSuccessor(z);

  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!=z){
    z->key = y->key;
  }
  free(y);
}



void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(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(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n);

  for(i = 0;i < n; i++){
    cin >> com;

    if(com[0] == 'f'){
      scanf("%d",&x);
      Node *t = find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(com == "insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com == "delete"){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }

  return 0;
}



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

#define ll long long

using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  ll R, S, P;
  cin >> R >> S >> P;
  string t;
  cin >> t;
  vector<bool> check(N, false);
  ll ans = 0;

  for (int i = 0; i < N; i++) {
    if (t[i] == 'p') {
      if (i - K >= 0 && t[i - K] == 'p') {
        if (!check[i - K]) {
          check[i] = true;
          ans += S;
        }
      } else {
        check[i] = true;
        ans += S;
      }
    }
    if (t[i] == 's') {
      if (i - K >= 0 && t[i - K] == 's') {
        if (!check[i - K]) {
          check[i] = true;
          ans += R;
        }
      } else {
        check[i] = true;
        ans += R;
      }
    }
    if (t[i] == 'r') {
      if (i - K >= 0 && t[i - K] == 'r') {
        if (!check[i - K]) {
          check[i] = true;
          ans += P;
        }
      } else {
        check[i] = true;
        ans += P;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        flg = True
        for k in range(M):
            for l in range(M):
                flg = flg & (B[k][l] == A[i+k][j+l])
        
        if flg:
            ans = 'Yes'
            print(ans)
            exit()

ans = 'No'
print(ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n;i++){
        cin >> a.at(i);
    }
    bool ans = true;
    int cnt = 0;
    while(ans){
        for (int i = 0;i < n;i++){
            if (a.at(i) % 2 == 0){
                a.at(i) /= 2;
            }
            else {
                ans = false;
                break;
            }
        }
        if (ans){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct Point{
	int x,y;
};
typedef vector<Point>V_Point;
char box[1001][1002];
int box1[1001][1001];
int flg[1000][1000]={0};
int main(void){
	int q,n,m;
	int w,h;
	int x,y;
	int a1,b1,a2,b2,a3,b3;
	int flag,flag2;
	int cnt;
	int mis;
	int i,j;
	Point pp;
	V_Point v;
	cin>>q>>m;
	// printf("q=%d m=%d\n",q,m);
	w=m;	h=m;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>box[i][j];
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			box1[i+1][j+1]=box[i][j]-'0';
		}
	}
	// for(i=1;i<=h;i++){
		// for(j=1;j<=w;j++){
			// cout<<box[i][j];
		// }
		// cout<<endl;
	// }
	mis=0;
	for(i=1;i<=h/2;i++){
		for(j=1;j<=w/2;j++){
			flag=0;	
			a1=i;		b1=w+1-j;
			a2=h+1-i;	b2=w+1-j;
			a3=h+1-i;	b3=j;
			if(box1[i][j]!=box1[a1][b1])		flag=1;
			if(box1[i][j]!=box1[a2][b2])		flag=1;
			if(box1[i][j]!=box1[a3][b3])		flag=1;
			if(flag==1){
				flg[i][j]=1;
				flg[a1][b1]=1;
				flg[a2][b2]=1;
				flg[a3][b3]=1;
				// printf("i=%d j=%d\n",i,j);
				mis++;
			}
			// if(i==1&&j==3||i==4&&j==3){
				// printf("left_up    y=%d x=%d\n",i,j);
				// printf("right_up   y=%d x=%d\n",a1,b1);
				// printf("right_down y=%d x=%d\n",a2,b2);
				// printf("left_down  y=%d x=%d\n",a3,b3);
			// }
		}
	}
	// printf("mistake=%d\n",mis);
	cnt=0;
	if(mis==0)	cnt++;
	// printf("cnt_now=%d\n",cnt);
	for(i=0;i<q-1;i++){
		// printf("cloth_now=%d\n",i+2);
		// printf("mistake_now=%d\n",mis);
		cin>>n;
		// printf("n=%d\n",n);
		v.clear();
		for(j=0;j<n;j++){
			cin>>y>>x;
			// printf("y=%d x=%d\n",y,x);
			if(box1[y][x]==0)	box1[y][x]=1;
			else				box1[y][x]=0;
			pp.y=y;	pp.x=x;
			v.push_back(pp);
		}
		// printf("check2\n");
		for(j=0;j<(int)v.size();j++){
			flag=0;
			pp=v[j];
			a1=pp.y;		b1=w+1-pp.x;
			a2=h+1-pp.y;	b2=w+1-pp.x;
			a3=h+1-pp.y;	b3=pp.x;
			// printf("y=%d x=%d map=%c flg=%d\n",pp.y,pp.x,box[pp,y][pp.x],flg[pp.y][pp.x]);
			// printf("y=%d x=%d map=%c\n",a1,b1,box[a1][b1]);
			// printf("y=%d x=%d map=%c\n",a2,b2,box[a2][b2]);
			// printf("y=%d x=%d map=%c\n",a3,b3,box[a3][b3]);
			// printf("\n");
			if(flg[pp.y][pp.x]==1){
				if(box1[pp.y][pp.x]==box1[a1][b1]&&box1[a1][b1]==box1[a2][b2]&&box1[a2][b2]==box1[a3][b3]){
					mis--;
					flg[pp.y][pp.x]=0;
					flg[a1][b1]=0;
					flg[a2][b2]=0;
					flg[a3][b3]=0;
				}
			}
			else{
				if(!(box1[pp.y][pp.x]==box1[a1][b1]&&box1[a1][b1]==box1[a2][b2]&&box1[a2][b2]==box1[a3][b3])){
					mis++;
					flg[pp.y][pp.x]=1;
					flg[a1][b1]=1;
					flg[a2][b2]=1;
					flg[a3][b3]=1;
				}
			}
		}
		// printf("mistake_next=%d\n",mis);
		if(mis==0){
			cnt++;
			// printf("i=%d cnt_now=%d\n",i+2,cnt);
		}
	}
	cout<<cnt<<endl;
	return 0;
}
		
	
	
	
	
	
	
	


Measured memory_bytes: 11956
def unitmat(n):
    return [[int(i==j) for i in range(n)] for j in range(n)]
def matadd(A,B):
    h=len(A); w=len(A[0])
    C=[[A[i][j]+B[i][j] for j in range(w)] for i in range(h)]
    return C
def matmul(A,B):
    h=len(A)
    w=len(B[0])
    l=len(B)
    C=[[0]*w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            for k in range(l):
                C[i][j]+=A[i][k]*B[k][j]
    for i in range(h):
        for j in range(w):
            C[i][j]%=mod
    return C
def matpow(A,k):
    n=len(A)
    B=unitmat(n)
    while k:
        if k&1:
            B=matmul(B,A)
        A=matmul(A,A)
        k>>=1
    return B

l,a,b,mod=map(int,input().split())
X=[[0],[a],[1]]
maxdigit=18
Idx=[0]*(maxdigit+1)
for i in range(maxdigit+1):
    if 10**i-1<a:
        continue
    Idx[i]=min((10**i-1-a)//b+1,l)
for i in range(1,maxdigit+1):
    f=[[10**i,1,0],[0,1,b],[0,0,1]]
    X=matmul(matpow(f,Idx[i]-Idx[i-1]),X)
print(X[0][0])

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

int main(){
  int x,y,r=0;
  
  cin >> x >> y;
  
  swap(x, y);
  while(y>0)
  {
    r = x % y;
  	x = y;
    y = r;
  }
  
  cout << x << endl;
  
  return 0;
}


Measured memory_bytes: 3096