akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

const ll MAX = 1e10;



ll nijo(ll x) {
    ll ng = 0;
    ll ok = 100000;
    while (ok-ng > 1) {
        ll mid = (ok+ng)/2;
        if (mid*mid >= x) ok = mid;
        else ng = mid;
    }
    if (ok*ok==x) return ok;
    return -1;
}

ll mul(ll x, ll y) {
    if (x==0 or y==0) return 0;
    if ((MAX+1)/y < x) return MAX+1;
    return x*y;
}


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin>> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    map<ll,ll>cnt,P,check;

    vector<ll> prime;
    for (ll i = 2; i*i*i <= MAX; i++) {
        bool ok = true;
        for (auto j : prime) if (i%j==0) ok = false;
        if (ok) prime.emplace_back(i);
    }
    rep(i,N) {
        ll p = 1, q = 1;
        for (auto j : prime) {
            ll m = j*j*j;
            while (A[i]%m==0) A[i] /= m;
            if (A[i]%(j*j)==0) {
                p *= j*j;
                q = mul(q,j);
                A[i] /= j*j;
            }
            else if (A[i]%j==0) {
                p *= j;
                q = mul(q,j*j);
                A[i] /= j;
            }
            if (A[i]==1) break;
        }
        if (A[i] != 1) {
            p *= A[i];
            ll val = nijo(A[i]);
            if (val==-1) q = mul(q,A[i]*A[i]);
            else q = mul(q,val);
        }
       cnt[p]++;
       P[p] = q;

    }
    int ans = 0;
    for (auto i :cnt) {
        if (check[i.first]) continue;
        check[i.first] = 1;
        if (i.first==1) {
            ans++;
            continue;
        }
        ll q = P[i.first];
        if (q==MAX+1 or !cnt.count(q)) ans += i.second;
        else {
            check[q] = 1;
            ans += max(i.second,cnt[q]);
        }
    }

    cout << ans << ln;
}


Measured memory_bytes: 22736
n = int(input())
s = [input() for _ in range(n)]
from collections import defaultdict
d = defaultdict(int)
for ele in "abcdefghijklmnopqrstuvwxyz":
  d[ele] = 0

for i, ele in enumerate(s):
  t = defaultdict(int)
  for l in ele:
    t[l] += 1
  if i==0:
    for k in d.keys():
      d[k] = t[k]
  for k in d.keys():
    d[k] = min(d[k], t[k])
  
ans = ""
for k, v in sorted(d.items(), key=lambda x:x[0]):
  if v>0:
    ans+=k*v
print(ans)

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main()
{
   int a, b, t, i;
   for(i=1; i<=3000; i++)
   {
       cin >> a >> b;
       
       if(a > b)
       {  
           t = a;
           a = b;
           b = t;
       }
        if(a == 0, b == 0)
          break;
          
       cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3068
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>

using namespace std;
static const int INF = 1e8;
typedef pair<int, int> P;


void solve()
{
	int x;
	cin >> x;
	if (x < 1200)
	{
		cout << "ABC" << endl;
	}
	else
	{
		cout << "ARC" << endl;
	}
}

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

Measured memory_bytes: 256
package main

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

type Restraunt struct {
	n int
	s string
	p int
}

type Restraunts []Restraunt

func (rs Restraunts) Len() int {
	return len(rs)
}

func (rs Restraunts) Less(i, j int) bool {
	if rs[i].s != rs[j].s {
		return rs[i].s < rs[j].s
	}
	return rs[i].p > rs[j].p
}

func (rs Restraunts) Swap(i, j int) {
	rs[i], rs[j] = rs[j], rs[i]
}

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

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var rs Restraunts = make([]Restraunt, N)
	for i := range rs {
		sc.Scan()
		rs[i].n, rs[i].s = i+1, sc.Text()
		sc.Scan()
		rs[i].p, _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(rs)
	for i := range rs {
		fmt.Println(rs[i].n)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int main()
{
    int64_t n,xn,sum=0;
    cin>>n;
    xn=n;
    REP(i,n)
    {
        int64_t x;cin>>x;
        if(x%2==0&&x%4!=0)xn--;
        if(x%4==0)sum++;
    }
    if((n-xn)%2==1)xn++;
    if(2*sum+1>=xn)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
#define MAX 100000
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
using ll = long long;

ll dp[109][100009];

int main(){
  ll n,k;
  cin>>n>>k;
  vector<int>w(n);
  vector<int>v(n);
  rep(i,n)cin>>w[i]>>v[i];
  rep(i,n+1)rep(j,MAX+1)dp[i][j]=LLINF;
  dp[0][0]=0;
  rep(i,n){
    rep(j,MAX+1){
      chmin(dp[i+1][j],dp[i][j]);
      if(j+v[i]<=MAX){
        chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);
      }
    }
  }
  int ans=0;
  rep(i,MAX+1){
    if(dp[n][i]<=k)chmax(ans,i);
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 80128
n = int(input())
S = ''

for i in range(n):
    S += input()[0]
    
m = S.count('M')
a = S.count('A')
r = S.count('R')
c = S.count('C')
h = S.count('H')

print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)

Measured memory_bytes: 3060
use proconio::{input, fastout};
use proconio::marker::Chars;

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        aa: [Chars; h],
    }

    let mut h_index = vec![];
    for i in 0..h {
        if aa[i].iter().any(|&c| c == '#') {
            h_index.push(i);
        }
    }
    let mut aa1 = vec![];
    for i in h_index.into_iter() {
        aa1.push(aa[i].clone());
    }
    let mut w_index = vec![];

    for i in 0..w {
        for j in 0..aa1.len() {
            if aa1[j][i] == '#' {
                w_index.push(i);
                break;
            }
        }
    }
    let mut ans = vec![];

    for i in 0..aa1.len() {
        ans.push(vec![]);
        for &j in &w_index {
            ans[i].push(aa1[i][j]);
        }
    }
    for line in ans {
        let line = line.iter().collect::<String>();
        println!("{}", line);
    }
}


Measured memory_bytes: 2240
w, h, x, y = map(int, input().split())
menseki = w * h
res1 = 0
tmp = 0
res2 = 0
if menseki % 2 == 0:
    if x * h <= y * w:
        tmp = x
    else:
        tmp = y
# y = h/w*x
if x == w/2 and y == h/2:
    res2 = 1
else:
    res2 = 0
print(menseki/2, res2)


Measured memory_bytes: 3060
fn read_vec<T>() -> Vec<T>
where T: std::str::FromStr,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(
        |e| e.parse().ok().unwrap()
        ).collect()
}

fn main()
{
    let inputs: Vec<u32> = read_vec();
    if (inputs[0] <= inputs[2]) && (inputs[2] <= inputs[1]) {
        println!("Yes");
    } else if (inputs[1] <= inputs[2]) && (inputs[2] <= inputs[0]) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.util.*;
public class Main{
    public static void main(String[] args){
        int buffernum = myGetInt();
        if(buffernum <= 100){
            System.out.println(buffernum*buffernum*buffernum);
        }    
    }
    static int myGetInt(){
        Scanner sc = new Scanner(System.in);
        return sc.nextInt();
    }
}

Measured memory_bytes: 26048
N, K = map(int, input().split())
A = list(map(int, input().split()))

# you have n balls.  i-th ball is written Ai
# we want for a kind of numbers to be lessor or equal to K by re-writing ball number Ai
# calculate minimum count

# 方針
# 何種類あるかを調べる : num_cnt
# その中でもっとも個数の少ないものから順に書き換える : num_cnt - K 
# ただし num_cnt > k の場合にのみこの操作をする

num = [0]*max(A)
cnt = [0]*max(A)

# count sequence
for a in A:
    if num[a-1] == 0:
        num[a-1] = 1

    cnt[a-1] += 1

kind = sum(num)

if kind > K:
    new_cnt = sorted([e for e in cnt if e != 0])
    res = sum(new_cnt[:(kind-K)])
else:
    res = 0

print(res)

Measured memory_bytes: 24996
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#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 (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, a;
	cin >> n >> a;
	n %= 500;
	if (n <= a)
		Yes();
	else
		No();

	return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: n, i
  real(8) :: res(50)
  read (*, *) n
  read (*, *) res(1:n)
  do i = 1, n - 1
    call insertion_sort(res(1:n))
    res(i + 1) = (res(i) + res(i + 1)) * 0.5
  end do
  write (*, "(f0.7)") res(n)

  contains

  subroutine insertion_sort(s)
    real(8), intent(inout) :: s(:)
    real(8) :: tmp
    integer :: i, j
    do i = 2, size(s)  ! ループ終了時に [1, i] が昇順
      do j = i, 2, -1  ! i の位置にあった新要素が適切な位置に来るまで隣同士 swap
        if (s(j) >= s(j - 1)) exit
        tmp = s(j)
        s(j) = s(j - 1)
        s(j - 1) = tmp
      end do
    end do
  end subroutine insertion_sort
end program main


Measured memory_bytes: 512
require 'prime'

# nの階乗
nn = 1
(1..gets.to_i).each do |i|
	nn = nn * i
end

# 素因数分解　→　約数の個数
nn_a = Prime.prime_division(nn)
divisor = 1

nn_a.each {|a|
	divisor *= (a[1] + 1)
}

# 10^9+7 の余り
print divisor % (10**9 + 7)


Measured memory_bytes: 4476
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <unordered_map>
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ll long long
const ll MOD = 1000000007;
using namespace std;
int main()
{
    int t;
    cin>>t;
    if(t==1)
    cout<<0;
    else
    cout<<1;
}

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

int t1, t2;
ll a1, a2, b1, b2;

int main() {
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  if (a1 < b1) {
    swap(a1, b1);
    swap(a2, b2);
  }
  ll d = (b1 * t1 + b2 * t2) - (a1 * t1 + a2 * t2);
  if (d < 0) {
    cout << 0 << endl;
    return 0;
  }
  if (d == 0) {
    cout << "infinity" << endl;
    return 0;
  }
  ll d0 = a1 * t1 - b1 * t1;
  ll k = d0 / d;
  ll ans = 2 * k + 1;
  if (d * k == d0) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>
int main(void){
 int n,i;
 scanf("%d",&n);
 long long int c[n+1];
 c[0]=2;
 c[1]=1;
 for(i=2;i<n+1;i++){
  c[i]=c[i-1]+c[i-2];
 }
 printf("%lld",c[n]);
 return 0;
}

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

using namespace std;

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
xyz = [[int(x) for x in input().split()] for _ in range(n)]

ans = 0

for i in range(8):
    i_bin = bin(i)[2:].zfill(3)
    new_xyz_sum = []
    for j in range(n):
        tmp = 0
        x, y, z = xyz[j]
        if i_bin[0] == "0":
            x *= -1
        if i_bin[1] == "0":
            y *= -1
        if i_bin[2] == "0":
            z *= -1
        tmp = x + y + z
        new_xyz_sum.append(tmp)
    new_xyz_sum = sorted(new_xyz_sum, reverse=True)
    ans = max(ans, sum(new_xyz_sum[:m]))

print(ans)

        


Measured memory_bytes: 41712
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n; cin >> n;
  long long int ans = 1;
  for(int i = 1; i <= n; i++){
    ans *= i;
    ans %= 1000000007;
  }
  cout << ans << endl;
  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll n,x[200],ans=1e10;
    cin>>n;
    for(int i=0;i<n;i++) cin>>x[i];
    for(int p=1;p<=100;p++){
        ll y=0;
        for(int i=0;i<n;i++){
            y+=(x[i]-p)*(x[i]-p);
        }
        ans=min(ans,y);
    }
    cout<<ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

// 提出時にMainに変更する
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int k = sc.nextInt();
        String s = sc.next();

        if (s.length() <= k) {
            System.out.println(s);
        } else {
            System.out.println(s.substring(0, k) + "...");
        }
        sc.close();
    }
}

Measured memory_bytes: 38396
/*                        _
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                   ____/`---'\____
                  /  \\|     |//  \
                 / \\||| /:\ |||// \
                / _||||| -:- |||||- \
               |   | \\\ \-/ /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
            ____'. .'  /--.--\  `. .'_____
          /"" '<  `.___\_<|>_/___.' >' "" \
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` / _/
          `-.____`.___ \_____/___.-`___.-'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.    IIT PATNA    I_LOVE_ADITI_GOEL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define LIM 100005


#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define deb(a) cerr << #a << ": " << a << endl
#define ftt cin>>t;for(int tt=1;tt<=t;++tt)
#define forr(i,n) for((i)=1;(i)<=(n);(i)++)
#define Rev(v) reverse(v.begin(),v.end())
#define Sort(v) sort(v.begin(),v.end())
#define mem(a,b) memset(a,b,sizeof(a))
#define umii unordered_map<int,int>
#define all(a) a.begin() , a.end()
#define vvi vector<vector<int>>
#define pq priority_queue<int>
#define sqr(a) (((a) * (a)))
#define double long double
#define dbg cout<<"\nhi\n"
#define pii pair<int,int>
#define mii map<int,int>
#define vb vector<bool>
#define eb emplace_back
#define vi vector<int>
#define nl cout<<"\n"
#define pb push_back
#define int long long
#define sp <<" "<<
#define se second
#define fi first
 
int fpow(int x,int y,int m) {
     int temp;
     if( y == 0 || x == 1)
          return 1;
     temp = fpow(x, y/2,m);
     if (y % 2 == 0)
          return ((temp)*(temp)) % m;
     else
          return (((x) % m)*((temp*temp) % m)) % m;
}
int gcd(int a,int b)
{
    if(b == 0)return a;
    return gcd(b,a % b);
}
void sieve(int n)
{
     bool prime[5*LIM];
     memset(prime, true, sizeof(prime));
      int rootn = (int)sqrt(n);
     for (int p = 2; p <= rootn; p++)
          if (prime[p] == true)
               for (int i = p*p; i <= n; i += p)
                    prime[i] = false;
     prime[1] = 0;

}

int cnt, sum, mid, mx = -1e17, mn = 1e17, a[2*LIM];
int n, m, d, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
string s;

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


int32_t main()
{     fio;
      cin>>n>>k;
      
      vi a(n);
      forr(i,n)cin>>a[i-1];
      Sort(a);
      sum=0;
      for(i=0;i<k;i++)sum+=a[i];
      cout<<sum;
     
}


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

int main()
{
  int N;
  long double ans;
  
  cin >> N;
  
  if (N % 2 == 0) {
    ans = (long double)(N / 2.0) / N;
  }
  else {
    ans = (long double)(N / 2 + 1) / N;
  }
  cout <<  fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: i64,
        m: i64,
        a: [i64; m],
    }
    let s:i64 = a.into_iter().sum();
    println!("{}", if n-s >= 0 {
        n - s
    }
    else {
        -1
    });
}

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

using namespace std;

int main(){

    char s[3];
    cin >> s;

    if(s[0]=='S' && s[1]=='S' && s[2]=='S'){
        cout << "0" ;
    }

    else if(s[0]=='R' && s[1]=='R' && s[2]=='R'){
        cout << "3";
    }

    else if(s[0]=='R' && s[1]=='R' && s[2]=='S' || s[0]=='S' && s[1]=='R' && s[2]=='R'){
        cout << "2" ;
    }

    else  cout << "1" ;

     return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>
 
using namespace std;
  
/********** TEMPLATE STARTS HERE ***********/
    
#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define gcd __gcd 
#define debug(a) cout << #a << ": " << a << '\n';
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << '\n';
#define SET(a, b) memset(a, b, sizeof(a));
#define refresh fflush(stdout);
#define digits(n) (int)(log10(n) + 1)
  
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pii> vii;
typedef vector <pll> vll;
    
const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;
    
template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
   
/*********** TEMPLATE ENDS HERE *************/

#define int long long

main()
{
	IOS
	
	string a, b;
	int n, m;
	
	cin >> n >> m;
	cin >> a >> b;
	
	int p = gcd(n, m);
	
	p = n * m / p;
	
	if(a[0] != b[0])
	{
		cout << -1;
		return 0;
	}
	
	int x1 = p / m;
	int x2 = p / n;
	
	while(x1 < n && x2 < m)
	{
		if(a[x1] != b[x2])
		{
			cout << -1;
			return 0;
		}
		
		x1 += p / m;
		x2 += p / n;
	}
	
	cout << p;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		HashSet<Integer>[] graph = new HashSet[n + 1];
		for (int i = 1; i <= n; i++) {
		    graph[i] = new HashSet<Integer>();
		}
		for (int i = 0; i < m; i++) {
		    graph[sc.nextInt()].add(sc.nextInt());
		}
		double[] dp = new double[n + 1];
		for (int i = n - 1; i >= 1; i--) {
		    for (int x : graph[i]) {
		        dp[i] += (dp[x] + 1) / graph[i].size();
		    }
		}
		double min = dp[1];
		for (int i = 1; i < n; i++) {
		    if (graph[i].size() <= 1) {
		        continue;
		    }
		    double max = 0;
		    dp[i] = 0;
		    for (int x : graph[i]) {
		        max = Math.max(dp[x] + 1, max);
		        dp[i] += dp[x] + 1;
		    }
		    dp[i] -= max;
		    dp[i] /= (graph[i].size() - 1);
		    for (int j = i - 1; j >= 1; j--) {
		        dp[j] = 0;
		        for (int x : graph[j]) {
		            dp[j] += (dp[x] + 1) / graph[j].size();
		        }
		    }
		    min = Math.min(min, dp[1]);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 107088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int t[n];
  long long int a[n];
  for(int i=0; i<n; i++){
    cin >> t[i] >> a[i];
  }
  long long int tmpt,tmpa;
  for(int i=1; i<n; i++){
    tmpt = t[i];
    tmpa = a[i];
    t[i] = t[i]*max((t[i-1]+tmpt-1)/tmpt,(a[i-1]+tmpa-1)/tmpa);
    a[i] = a[i]*max((t[i-1]+tmpt-1)/tmpt,(a[i-1]+tmpa-1)/tmpa);
    //cout << t[i] << " " << a[i] << endl;
  }
  cout << t[n-1]+a[n-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  
  while(A < B){
    if(A / 1000 == (((A - (A / 100) * 100)) % 10) * 10 
      + ((A - (A / 100) * 100) / 10)){
      break;
    }
    A++;
  }
  
  while(B > A){
    if(B / 1000 == (((B - (B / 100) * 100)) % 10) * 10
      + ((B - (B / 100) * 100) / 10)){
      break;
    }
    B--;
  }
  
  if(A == B && A / 1000 != (((A - (A / 100) * 100)) % 10) * 10 
      + ((A - (A / 100) * 100) / 10)){
    cout << 0 << endl;
  }
  else{
    cout << B / 100 - A / 100 + 1 << endl;
  }
}

Measured memory_bytes: 256
//
//Let's play Amidakuji.
//
//In the following example, there are five vertical lines and four horizontal lines.The horizontal lines can intersect(jump across) the vertical lines.
//
#include <iostream>
using namespace std;

typedef struct _INTPAIR {
    int a;
    int b;
} INTPAIR;

bool read(int& w, int& n, INTPAIR** ppArray);
bool initializeRod(const int w, int** ppArray);
bool swapRods(const int n, const INTPAIR* pConditions, int* pRods);
bool Write(const int w, const int* pRods);

int main()
{
    int w = 0, n = 0;
    INTPAIR* pConditions = NULL;
    int* pRods = NULL;

    // Start read conditions.
    if (!read(w, n, &pConditions))
        return 1;

    // Create rods.
    if (!initializeRod(w, &pRods))
        return 1;

    // Start swap rods.
    if (!swapRods(n, pConditions, pRods))
        return 1;

    // Output rods.
    if (!Write(w, pRods))
        return 1;
    
    delete[] pConditions;
    delete[] pRods;
}

bool read(int& w, int& n, INTPAIR** ppArray)
{
    char dummy;

    if (NULL == ppArray || NULL != *ppArray)
        return false;

    cin >> w;
    cin >> n;

    *ppArray = new INTPAIR[n];
    
    for (int i = 0; i < n; i++) {
        cin >> ((*ppArray) + i)->a;
        cin >> dummy;
        cin >> ((*ppArray) + i)->b;
    }

    return true;
}

bool initializeRod(const int w, int** ppArray)
{
    if (NULL == ppArray || NULL != *ppArray)
        return false;

    *ppArray = new int[w];

    for (int i = 0; i < w; i++) {
        *(*ppArray + i) = i + 1;
    }

    return true;
}

bool swapRods(const int n, const INTPAIR* pConditions, int* pRods)
{
    if (NULL == pConditions || NULL == pRods)
        return false;

    for (int i = 0; i < n; i++) {
        int idxL = (pConditions + i)->a - 1;
        int idxR = (pConditions + i)->b - 1;
        int tmp = 0;
        tmp = *(pRods + idxL);
        *(pRods + idxL) = *(pRods + idxR);
        *(pRods + idxR) = tmp;
    }

    return true;
}

bool Write(const int w, const int* pRods)
{
    if (NULL == pRods)
        return false;

    for (int i = 0; i < w; i++)
        cout << *(pRods + i) << endl;

    return true;
}

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

bool is_prime(int n){
    int k = (int)pow(n, 0.5) + 2;
    for (int i = 2; i < k; i++){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}


int main(){
    int N;
    cin >> N;
    vector<int> primes = vector<int>();
    for (int i = 11; i <= 55555; i+=10){
        if(is_prime(i)){
            cout << i;
            N -= 1;
            if (N > 0){
                cout << " ";
            }else{
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace  std;

llint n;
llint a[100005];

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

  cin >> n;
  for(int i = 1; i <= n; i++) cin >> a[i];

  llint lb = 2, ub = 2;
  for(int i = n; i >= 1; i--){
    lb = (lb+a[i]-1)/a[i]*a[i];
    ub = ub/a[i]*a[i];
    if(lb > ub){
      cout << -1 << endl;
      return 0;
    }
    ub += a[i]-1;
  }
  cout << lb << " " << ub << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	while(x!=y){
		if(x>y){
			x=x-y;
		}
		else if(y>x){
			y=y-x;
		}
	}
	cout<<x<<endl;
	return 0;
}

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

int main()
{
    std::string S;
    std::cin >> S;
    int len = S.length();
    int r = 0, b = 0;
    for (int i = 0; i < len; i++)
    {
        if (S[i] == '0')r++;
        else b++;
    }

    std::cout << (len - std::abs(r - b)) << std::endl;
    return 0;
}

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

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    if(a > b) {
        cout << (a - 1) << endl;
    } else {
        cout << a << endl;
    }
}


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

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

    if(n % (2 * d + 1) == 0){
        cout << n / (2 * d + 1) << endl;
    }else{
        cout << n / (2 * d + 1) + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def ch(x):
    if x in ["+", "-", "*"]:
        return x
    else:
        return int(x)

def calc(x):
    if x[2] == "+":
        return x[0] + x[1]
    elif x[2] == "-":
        return x[0] - x[1]
    elif x[2] == "*":
        return x[0] * x[1]

N = list(map(ch, input().split()))

st = []

while True:
    if len(N) == 0:
        break
    elif (type(N[0]) is int):
        st.append(N[0])
        N.pop(0)
    elif (type(N[0]) is str):
        st[-2] = calc([st[-2],st[-1],N[0]])
        st.pop(-1)
        N.pop(0)
print(*st)
        



Measured memory_bytes: 5604
s = str(input())
l = len(s)
s = s[::-1]
i = 0
while i < l:
    if (s[i:min(l,i+7)] == "remaerd"):
        i += 7
    elif (s[i:min(l,i+6)] == "resare"):
        i += 6
    elif (s[i:min(l,i+5)] == "maerd" ):
        i += 5
    elif (s[i:min(l,i+5)] == "esare"):
        i += 5
    else:
        print('NO')
        break

else:
    print('YES')

Measured memory_bytes: 3188
#include <stdio.h>

int main() {
    int n, b, f, r, v;
    int p[4][3][10] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        p[b - 1][f - 1][r - 1] += v;
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                printf(" %d", p[i][j][k]);
            }
             printf("\n");
        }
        if (i != 3) printf("####################\n");
    }
}



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

int main(int argc, char const *argv[]) {

        std::string s;
        std::cin >> s;

        int a_pos = s.find("A");
        s = s.substr(a_pos,s.length());
        int z_pos = s.rfind("Z");

        std::cout << s.substr(0, z_pos+1).length() << '\n';

        return 0;
}


Measured memory_bytes: 832
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T>
ostream& operator<<(ostream& stream, const vector<T> v){
    stream << "[";
    for (int i=0; i<(int)v.size(); i++) cout << v[i] << " ";
    stream << "]";
    return stream;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	string s="YAKI";

    string a;
    cin >> a;

    bool ok=1;
    int i;
    for (i=0; i<4 && i<s.length(); i++)
        if (a[i]!=s[i]) ok=0;

    if (s.length()<4 || !ok) cout << "No";
    else cout << "Yes\n";
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int64_t X;
  cin >> X;

  int64_t y = 100;
  for (int i = 1; 1; i++) {
    y *= 1.01;
    if (y >= X) {
      cout << i << '\n';
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3648
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
a = [l() for j in range(n)]
a.sort()
x = a[-1][1]+a[-1][0]
print(x)


Measured memory_bytes: 28600
object Main extends App {
  val mod = 1000000007
  val sc = new java.util.Scanner(System.in) 
  val n = sc.nextInt()
  val a = Array.fill(n)(sc.nextLong())
  var ans = 0L
  var x = 0L
  for (i <- 0 until n) {
    ans =  (ans + a(i) * x) % mod
    x = (x + a(i)) % mod
  }
  println(ans)
}

Measured memory_bytes: 61080
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b; cin >> a >>  b;

  if ((a*b) % 2 == 0)
  {
      cout << "Even" << endl;
  }

  else cout << "Odd" << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int k, x;
    cin>>k>>x;

    rep(i, k) {
        cout<<x - k + 1 + i<<endl;
    }
    rep(i, k - 1) {
        cout<<x + 1 + i<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl
#define SZ(X) ((int)X.size())

using namespace std;

typedef tuple<int, int, int> iii;

const int MN = 20;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int L; cin >> L;
	vector<iii> ans;
	int k = 0;
	for (int i = 0; i < MN; i++) if ((L >> i) & 1)
        k = i;
    int n = k + 1;
    for (int i = 1; i <= k; i++) {
        ans.push_back(iii(i, i + 1, 0));
        ans.push_back(iii(i, i + 1, 1 << (i - 1)));
    }
    for (int i = 0; i < k; i++) if ((L >> i) & 1) {
        L ^= (1 << i);
        ans.push_back(iii(i + 1, n, L));
    }
	cout << n << " " << SZ(ans) << endl;
	for (iii e : ans) {
        int u, v, w;
        tie(u, v, w) = e;
        cout << u << " " << v << " " << w << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int p[55]={2,7,17,37,47,67,97,107,127,137,157,167,197,227,257,277,307,317,337,347,367,397,457,467,487,547,557,577,587,607,617,647,677,727,757,787,797,827,857,877,887,907,937,947,967,977,997,1087,1097,1117,1187,1217,1237,1277,1297};

int main(){
	int N,i;
	scanf("%d",&N);
	for(i=0;i<N-1;i++)printf("%d ",p[i]);
	printf("%d\n",p[N-1]);
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using P = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

struct Edge { ll from, to, cost; };

ll N, M;
vector<Edge> edges;
vector<ll> d;
ll score = INFL;

using namespace chrono;
bool shortest_path(ll s) {
	auto start = system_clock::now();
	fill(d.begin(), d.end(), INFL);
	d[s] = 0;
	while (true) {
		bool update = false;
		for (const auto& e : edges) {
			if (d[e.from] != INFL && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update)return true;

		auto end = system_clock::now();
		auto mill = duration_cast<milliseconds>(end - start).count();
		if (mill > 1500 && score == INFL)score = d.back();
		if (mill > 1800) {
			return score == d.back();
		}
	}
}

int main()
{
	cin >> N >> M;
	edges.resize(N);
	d.resize(N);

	REP(i, M) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--; c = -c;
		edges.push_back({ a,b,c });
	}
	if (!shortest_path(0)) {
		cout << "inf" << endl;
	}
	else {
		cout << -d.back() << endl;
	}

	return 0;
}


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

using ll = long long int;
using P = std::pair<int, int>;

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

int n;
std::string s;

int dp[5010][5010];

int dfs(int i, int j)
{
    if (i >= n || j >= n || s[i] != s[j])
        return 0;
    if (dp[i][j] > 0)
        return dp[i][j];

    return dp[i][j] = std::min(dfs(i + 1, j + 1) + 1, j - i);
}

int main()
{
    std::cin >> n >> s;

    int ans = 0;

    rep(i, n)
    {
        rep(j, n)
        {
            if (j > i)
                ans = std::max(ans, dfs(i, j));
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 70548
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--) 
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s;
    cin >> s;
   
    if (s =="ABC") {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }



}























































































































































































































































































































































































































































































































































































































































































    
   
   













































































































































































































































































































































   



    






    


   









    


















































































































































































































































































































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

using namespace std;
typedef long long ll;

int a[3000];
vector<vector<ll>> dp(3000, vector<ll>(3000, -1));


ll fun(int l, int r){
	if(dp[l][r] != -1) return dp[l][r];
	if(l == r){
		return dp[l][l] = a[l];
	}
	return dp[l][r] = max(a[l] - fun(l+1, r),a[r] - fun(l, r-1));
}


int main(){
	int n; cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	cout << fun(0, n-1);
}

Measured memory_bytes: 74016
#include <cstdio>
#include <vector>
#include <algorithm>

typedef struct node{
	int x;
	int y;
	int depth;
	int id;
	node *right;
	node *left;
} node;


bool compX(node &n1, node &n2){
	return n1.x < n2.x;
}

bool compY(node &n1, node &n2){
	return n1.y < n2.y;
}

node *nil;
std::vector<int> ans;
std::vector<node> nodes;

node* make_tree(int l, int r, int depth){
	if (l>=r){
		return nil;
	}

	if (depth % 2 == 0){
		std::sort(&nodes[l], &nodes[r], compX);
	}
	else{
		std::sort(&nodes[l], &nodes[r], compY);
	}

	int mid = (l+r)/2;
	nodes[mid].depth = depth;
	nodes[mid].left = make_tree(l, mid, depth+1);
	nodes[mid].right = make_tree(mid+1, r, depth+1);
	
	return &nodes[mid];
}

void search(node *n, int x_l, int x_h, int y_l, int y_h){
	int x = n->x;
	int y = n->y;
	
	if (x_l <= x && x <= x_h && y_l <= y && y <= y_h) ans.push_back(n->id);
	
	if (n->depth % 2 == 0){
		if (n->left != nil && x_l <= x) search(n->left, x_l, x_h, y_l, y_h);
		if (n->right != nil && x <= x_h) search(n->right, x_l, x_h, y_l, y_h);
	}
	
	else{
		if (n->left != nil && y_l <= y) search(n->left, x_l, x_h, y_l, y_h);
		if (n->right != nil && y <= y_h) search(n->right, x_l, x_h, y_l, y_h);
	}
	
}

void search_from_root(node *root, int x_l, int x_h, int y_l, int y_h){
	search(root, x_l, x_h, y_l, y_h);
	sort(ans.begin(), ans.end());
	for (int i=0; i<ans.size(); i++) printf("%d\n", ans[i]);
	printf("\n");
	ans.clear();
}

int main(void){
	int n, q, x, y;
	node *root;
	scanf("%d", &n);
	nodes.resize(n);

	for(int i=0; i<n;i++){
		scanf("%d %d", &x, &y);
		nodes[i].x = x;
		nodes[i].y = y;
		nodes[i].id = i;
	}
	
	root = make_tree(0, n, 0);
	scanf("%d", &q);
	for (int i=0;i<q;i++){
		int x_low, x_high, y_low, y_high;
		scanf("%d %d %d %d", &x_low, &x_high, &y_low, &y_high);
		search_from_root(root, x_low, x_high, y_low, y_high);
	}
}

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

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

  int idx = S.size() / 2;
  int ans = 0;
  for (int i = 0; i < S.size() / 2; i++) {
    char begin = S.at(i);
    char end = S.at(S.size() - 1 - i);
    if (begin != end) ans++;
  }

  printf("%d", ans);
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(unused_must_use)]
use std::io::{stdin, stdout, stderr, Write, BufWriter, BufReader, BufRead};

macro_rules! read_from_line {
    ($inbuf:ident => $($name:ident : $ty:ty),* ) => {
        let mut buf = String::new();
        $inbuf.read_line(&mut buf).unwrap();
        buf.pop();
        let mut words = buf.split_whitespace();
        $(
            let $name:$ty = words.next().unwrap().parse().unwrap();
        )*
    };
}

macro_rules! read_many {
    ($inbuf:ident => $name:ident : $ty:ty) => {
        let $name: Vec<$ty> = strio::read_many_from_line(&mut $inbuf);
    };
}

fn main() {
    let cout = stdout();
    let mut cout = BufWriter::new(cout.lock());
    let cin = stdin();
    let mut cin = BufReader::new(cin.lock());

    //read_from_line!(cin => a:i32, b:String);
    //let xs: Vec<i32> = strio::read_many_from_line(&mut cin);
    
    read_from_line!(cin => _n:i32);
    read_many!(cin => xs:i64);
    let mut xs_sorted = xs.iter().enumerate().map(|(ix, x)| x - (ix as i64)).collect::<Vec<i64>>();
    xs_sorted.sort();
    let mut mids = vec![];
    if xs_sorted.len() % 2 == 0 {
        mids.push(xs_sorted.len() / 2);
        mids.push(xs_sorted.len() / 2 - 1);
    } else {
        mids.push(xs_sorted.len() / 2);
    }

    let ans: i64 = mids.iter().map(|mid| {
        let midv = xs_sorted[*mid];
        xs_sorted.iter().map(|x| (x - midv).abs()).sum()
    }).min().unwrap();

    writeln!(cout, "{}", ans);
}

mod strio {
    use std::str::FromStr;
    use std;

    pub fn read_from_line<T, R> (r: &mut R) -> T where
        T: FromStr,
        <T as std::str::FromStr>::Err : std::fmt::Debug,
        R: std::io::BufRead,
    {
        let mut buf = String::new();
        r.read_line(&mut buf).unwrap();
        buf.pop();
        buf.parse().unwrap()
    }

    pub fn read_many_from_line<T, R> (r: &mut R) -> Vec<T> where
        T: FromStr,
        <T as std::str::FromStr>::Err : std::fmt::Debug,
        R: std::io::BufRead,
    {
        let mut buf = String::new();
        r.read_line(&mut buf).unwrap();
        buf.pop();
        buf.split_whitespace().map(|x| x.parse().unwrap()).collect()
    }
}


Measured memory_bytes: 10492
class UnionFind():

    def __init__(self, s):
        self.nodes = [-1 for _ in range(s)]

    def find(self, x):
        if self.nodes[x] < 0:
            return x
        else:
            return self.find(self.nodes[x])

    def union(self, x, y):
        s_1 = self.find(x)
        s_2 = self.find(y)
        if s_1 == s_2:
            return False
        if self.nodes[s_1] > self.nodes[s_2]:
            s_1, s_2 = s_2, s_1
        self.nodes[s_1] += self.nodes[s_2]
        self.nodes[s_2] = s_1
        return True

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


if __name__ == "__main__":
    n, q = map(int, input().split())
    sets = UnionFind(n)
    for i in range(q):
        com, x, y = map(int, input().split())
        if com == 0:
            sets.union(x, y)
        else:
            result = sets.is_same(x, y)
            if result is True:
                print("1")
            else:
                print("0")



Measured memory_bytes: 5816
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
	vector<vector<int>> a(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (a[j][k] == b)
					a[j][k] = 0;
			}
		}
	}

	bool bingo = false;
	if (a[0][0] + a[1][1] + a[2][2] == 0 || a[2][0] + a[1][1] + a[0][2] == 0)
		bingo = true;
	for (int i = 0; i < 3; i++) {
		if (a[i][0] + a[i][1] + a[i][2] == 0 || a[0][i] + a[1][i] + a[2][i] == 0)
			bingo++;
	}
	cout << (bingo ? "Yes" : "No") << endl;
	return 0;
}

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

using namespace std;

int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	set<int> s;
	set<int>::iterator ps;

	for (int i = 0; i < k; i++) {
		if ((a + i) <= b) {
			s.insert(a + i);
		}
	}
	for (int i = 1; i <= k; i++) {
		if ((b - k + i) >= a) {
			s.insert(b - k + i);
		}
	}

	for (ps = s.begin(); ps != s.end(); ++ps) {
		cout << *ps << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string name;
  int a,x,y; 
  char b;
  
  cin >> name;
  a = name.size();
  x = a-1;
  y = a-2;
  b = name.at(x);
    
  if (b == 's'){
      name = name + 'e' + 's';
      cout << name <<endl;
  }
  else{
    name = name + 's';
    cout << name <<endl;
  }
  return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
const int N=2e3+10;
int n;
LL dp[N][N],ans,minn=3e18,x,a[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline I abss(I&x){return x>0 ? x : -x;}
template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;}
int main()
{
	//freopen("Colorful Slimes.in","r",stdin);
	read(n,x);
	for(RG int i=0;i<n;i++) read(a[i]);
	memset(dp,0x3f,sizeof dp);
	for(RG int i=0;i<n;i++)
	{
		dp[i][0]=a[i];
		for(RG int j=1;j<n;j++) dp[i][j]=mi(dp[i][j-1],a[(i-j+n)%n]);
	}
	for(RG int i=0;i<n;i++)
	{
		ans=0;
		for(RG int j=0;j<n;j++) ans+=dp[j][i];
		minn=mi(minn,ans+x*i);
	}
	printf("%lld\n",minn);
	return 0;
}

Measured memory_bytes: 31872
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll n, k;
    cin >> n >> k;
    ll h[n];
    rp(i, 0, n) cin >> h[i];
    sort(h, h + n);
    ll ans = inf;
    rp(i, 0, n)
    {
        if (k - 1 + i < n)
            ans = min(ans, h[k - 1 + i] - h[i]);
    }
    ce(ans);
}

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

int main()
{
  long long a, b, c;
  cin >> a >> b >> c;
  if(a%2==1 && b%2==1 && c%2==1)
  {
    if(a >= b && a >= c)
    {
      cout << b*c << endl;
    }
    else if(b >= a && b >= c)
    {
      cout << a*c << endl;
    }
    else
    {
      cout << a*b << endl;
    }
  }
  else
  {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

string bigger(string &s, string &t){
    if(s.size() > t.size()) return s;
    if(s.size() < t.size()) return t;
    return max(s, t);
}


int main() {
    int w, h;
    while(cin >> w >> h, w){
        vector<string> v(h);
        for (int i = 0; i < h; ++i) {
            cin >> v[i];
        }
        vector<vector<string>> dp(h+1, vector<string>(w+1, "0"));
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if(!isdigit(v[i][j])) continue;
                string s = bigger(dp[i+1][j], dp[i][j+1]);
                if(s != "0") dp[i+1][j+1] = s + v[i][j];
                else dp[i+1][j+1] = v[i][j];
            }
        }
        string ans = "0";
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                ans = bigger(ans, dp[i+1][j+1]);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


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

using namespace std;

int main(void){
  int n,cnt=0;
  cin >> n;
  vector<int>v(n);
  for(int i=0;i<n;i++)cin >> v[i];

  for(int i=0;i<n;i++){
    int id=i;
    for(int j=i;j<n;j++){
      if(v[id]>v[j])id=j;
    }
    if(i!=id)cnt++,swap(v[i],v[id]);
  }
  for(int i=0;i<n;i++)cout << v[i] << (i<n-1?" ":"\n");
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1196