akhauriyash/Code-Regression huggingface dataset:
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
use std::cmp;
fn main() {
    // 一行読み込み、空白で分解してusize２つパースする
    //let N = get!(usize);
    let mut Time: Vec<i32> = (0..5).map(|_| read()).collect();
    let mut nextTime = vec![];
    let mut j: usize = 0;
    for i in 0..Time.len() {
        if &Time[i] % 10 == 0 {
            nextTime.push(Time[i]);
        } else {
            nextTime.push(Time[i] - Time[i] % 10 + 10);
        }
    }
    let mut BestTime = 999999999;

    for i in 0..Time.len() {
        let mut SumTime = 0;
        for j in 0..Time.len() {
            if i == j {
                SumTime += Time[j];
            } else {
                SumTime += nextTime[j];
            }
        }
        BestTime = cmp::min(BestTime, SumTime);
    }
    println!("{}", BestTime);
}


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

int main() {
    int n;
    scanf("%d", &n);
    list<int> li;
    rep(i, n) {
        char s[20];
        scanf("%s", s);
        int x;
        // if (s == "insert") {
        if (strlen(s) == 6) {
            scanf("%d", &x);
            if (s[0] == 'i') {
                // scanf("%d", &x);
                li.push_front(x);
            } else if (s[0] == 'd') {
                // scanf("%d", &x);
                for (auto itr = li.begin(); itr != li.end(); itr++) {
                    if (*itr == x) {
                        li.erase(itr);
                        break;
                    }
                }
            }
        // } else if (s == "delete") {
        // } else if (strlen(s) == 6 && s[0] == 'd') {
            
            // auto itr = find(li.begin(), li.end(), x);
            // if (itr != li.end()) li.erase(itr);
        // } else if (s == "deleteFirst") {
        //     li.pop_front();
        // } else if (s == "deleteLast") {
        //     li.pop_back();
        // }
        // } else if (strlen(s) > 6) {
        } else {
            if (s[6] == 'F') li.pop_front();
            else if (s[6] == 'L') li.pop_back();
        }
    }
    for (auto x = li.begin(); x != li.end(); x++) {
        if (x != prev(li.end())) printf("%d ", *x);
        else printf("%d\n", *x);
    }
}


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

int main()
{
  int N; cin >> N;
  map<char, ll> cnt;
  for (int i = 0; i < N; ++i) {
    string s; cin >> s;
    cnt[s[0]]++;
  }

  string P = "MMMMMMAAAR";
  string Q = "AAARRCRRCC";
  string R = "RCHCHHCHHH";

  ll ans = 0;
  for (int i = 0; i < 10; ++i) {
    ans += cnt[P[i]] * cnt[Q[i]] * cnt[R[i]];
  }

  cout << ans << endl;
}

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

const int N = 105, mod = 1000000007;
typedef long long LL;

int pow(int x, int y, int ans = 1) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}

int n, p, h[N];

std::pair<int, int> solve(int l, int r, int base) {
	int x = h[l], w = 0;
	for (int i = l; i <= r; ++i)
		x = std::min(x, h[i]);
	for (int i = l; i <= r; ++i)
		if (h[i] == x) ++w;
	int prod0 = 1, prod1 = 1, lst = l - 1;
	for (int i = l; i <= r + 1; ++i)
		if (i > r || h[i] == x) {
			if (i - 1 > lst)  {
				auto t = solve(lst + 1, i - 1, x);
				prod0 = (LL) prod0 * (t.first + t.second) % mod;
				prod1 = (LL) prod1 * t.second % mod;
			}
			lst = i;
		}
	int t = pow(2, x - base);
	prod0 = (pow(2, w, prod0) + (LL) (t + mod - 2) * prod1) % mod;
	prod1 = (LL) t * prod1 % mod;
	return {prod0, prod1};
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> h[i];
	std::cout << solve(1, n, 0).first << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 45

int F[N];

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

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

int main(){
  int N;cin>>N;
  vector<int>A(N);
  
  int count=0;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    if(A.at(i)<0)
      count++;
    A.at(i)=abs(A.at(i));
  }
  
  sort(A.begin(),A.end());
  
  long long res=0;
  
  if(count%2==0){
    for(int i=0;i<N;i++)
      res+=A.at(i);
  }
  else{
    for(int i=1;i<N;i++)
      res+=A.at(i);
    res-=A.at(0);
  }
  
  cout<<res;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a,b,k;

int main(){
	scanf("%d%d%d",&a,&b,&k);
	for(int i =	100;i>=1;i--){
		if(a%i==0 && b%i==0){
			k--;
			if(k==0){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

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

dp = [float('inf')] * N

dp[0] = 0

for i in range(1,N):
    if i == 1:
        dp[i] = min(dp[i], dp[i-1] + abs (h[i] - h[i-1]))
    else:
        dp[i] = min(dp[i], dp[i-1] + abs (h[i] - h[i-1]))
        dp[i] = min(dp[i], dp[i-2] + abs (h[i] - h[i-2]))

print(dp[N-1])

Measured memory_bytes: 13776
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int multiplier = scan.nextInt();
        int numder = scan.nextInt();
        
        int minnumder = 0;
        
        if (multiplier != 0){
            minnumder = 100;
            for(int i = 1; i < multiplier ; i++){
                minnumder = minnumder * 100;
            }
        }else{
            minnumder = 1;
        }
        if(numder == 100){
            numder++;
        }
        
        int ans = minnumder * numder;
 
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <sstream>
#include <stack>

using namespace std;

int main()
{
   int n;
   scanf("%d",&n);
   int *a=new int[n];
   for(int i=0;i<n;++i)
   {
       scanf("%d",&a[i]);
   }
   int sum=0;
   for(int i=0;i<n;++i)
   {
       sum+=a[i]-1;
   }
   printf("%d\n",sum);
}


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

int main() {

  vector<int> coordinate(5);
  int k;
  bool ans = false;
  

  for (int i = 0; i < 5; i++) {
    cin >> coordinate.at(i);
  }
  cin >> k;
  
  sort(coordinate.begin(), coordinate.end());
  reverse(coordinate.begin(), coordinate.end());
  
  if (coordinate.at(0) - coordinate.at(4) > k) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 2*100000+5
char s1[MAXN],s2[MAXN];
int a[30],b[30];
int main() {
	scanf("%s",s1),scanf("%s",s2);
	for(int i=0;s1[i];i++)
		a[s1[i]-'a']++;
	for(int i=0;s2[i];i++)
		b[s2[i]-'a']++;
	sort(a,a+30), sort(b,b+30);
	for(int i=0;i<30;i++)
		if(a[i]!=b[i]) {
			puts("No");
			return 0;
		}
	puts("Yes");
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

int main() {
    int N, ai;
    cin >> N;

    int max0=0, max1=0, max0_idx=0, max1_idx=0;
    for (int i=0; i<N; i++) {
        cin >> ai;
        if (ai > max0) {
            max1_idx = max0_idx;
            max1 = max0;

            max0_idx = i;
            max0 = ai;
        } else if (ai > max1) {
            max1_idx = i;
            max1 = ai;
        }
    }

    for (int i=0; i<N; i++) {
        if (i != max0_idx) cout << max0 << endl;
        else cout << max1 << endl;
    }

    return 0;
}



Measured memory_bytes: 1664
n=int(input())
a=[]
t=n
for i in range(2, int(-(-n**0.5//1))+1):
    if t%i==0:
        c=0
        while t%i==0:
            c+=1
            t //= i
        a.append([i,c])

if t!=1:
    a.append([t,1])

if a==[] and t!=1:
    a.append([n, 1])
ans=0
for i in a:
    j = 1
    while i[1]>=0:
        i[1]-=j
        if i[1]>=0:
            ans+=1
            j+=1
print(ans)


Measured memory_bytes: 63648
#include    <iostream>
#include    <vector>
#include    <string>
#include    <utility>

using namespace std;

typedef struct{
    int idx;    // 入力順のインデックス
    char dec;   // トランプの柄
    int num;    // トランプの数字
}playingCard;

void printVector(const vector<playingCard> &A) {
    for(int i = 0; i < A.size(); i++) {
        cout << A[i].dec << A[i].num;
        if(i+1 < A.size()) cout << ' ';
    }
    cout << endl;
}

void swap(playingCard &a, playingCard &b) {
        playingCard tmp = a;
        a = b;
        b = tmp;
}

vector<playingCard> bubble(vector<playingCard> A) {
    const int n = A.size();
    for(int i = 0; i < n-1; i++)
        for(int j = n-2; j >= i; j--) 
            if(A[j].num > A[j+1].num) 
                swap(A[j], A[j+1]);
    return A;
}

vector<playingCard> insertion(vector<playingCard> A) {
    const int n = A.size();
    for(int i = 0; i < n; i++) {
        int minj = i;
        for(int j = i; j < n; j++)
            if(A[j].num < A[minj].num)  minj = j;
        if(A[i].num != A[minj].num)
            swap(A[i], A[minj]);
    }
    return A;
}

bool isStable(const vector<playingCard> &A) {
    for(int i = 0; i < A.size() - 1; i++) {
        if(A[i].num == A[i+1].num && A[i].idx > A[i+1].idx) return false;    
    }
    return true;
}

int main() {
    int n;

    cin >> n;

    // 入力
    vector<playingCard> card(n);
    for(int i = 0; i < n; i++) {
        string ipt;
        cin >> ipt;
        
        card[i].idx = i;
        card[i].dec = ipt[0];
        card[i].num = ipt[1] - '0';
    }

    // 処理
    vector<playingCard> sortBubble = bubble(card);
    vector<playingCard> sortInsert = insertion(card);

    printVector(sortBubble);
    cout << (isStable(sortBubble) ? "Stable" : "Not stable") << endl;
    
    printVector(sortInsert);
    cout << (isStable(sortInsert) ? "Stable" : "Not stable") << endl;

    return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
long long DP[2020][2020];
pair<long long,int> C[2020];
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>C[i].first;
		C[i].second=i;
	}
	sort(C,C+N);
	reverse(C,C+N);
	for(int i=0;i<N;i++)
		for(int j=0;j<=i;j++)
		{
			int k=i-j;
			DP[j+1][k]=max(DP[j+1][k],DP[j][k]+C[i].first*(C[i].second-j));
			DP[j][k+1]=max(DP[j][k+1],DP[j][k]+C[i].first*(N-C[i].second-1-k));
		}
	long long Ans=0;
	for(int i=0;i<=N;i++)
		Ans=max(Ans,DP[i][N-i]);
	cout<<Ans<<endl;
	return 0;
}


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

const int N = 200005;

int ans = 0, n, f[N][2];
char s[N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> (s + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= n; i++)
    {
        if (i > 1)
            f[i][1] = f[i - 2][0] + 1;
        if (s[i] != s[i - 1])
            f[i][0] = f[i - 1][0] + 1;
        f[i][0] = max(f[i][0], f[i - 1][1] + 1);
        ans = max(ans, max(f[i][0], f[i][1]));
    }
    cout << ans;
}


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

bool judge(int i, int D[], int K){
  for (int j=0; j<K; j++) {
    if (to_string(i).find(to_string(D[j]))!= string::npos) {
        return false;
        break;
    }
  }
  return true;
}

int main(){
  int N, K;
  cin>>N>>K;
  int l, r=0, D[K];
  while(cin>>l){
    D[r]=l;
    r++;
  }

  for (int i=N; i<100000; i++) {
    if (judge(i, D, K)==true) {
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int NOT_FOUND=-1;
int binarySearch(int A[],int left,int right,int key){
    while(left<right){
        int mid=(left+right)/2;
        if(A[mid]==key){
            return mid;
        }else if(key<A[mid]){
            right=mid;
        }else{
            left=mid+1;
        }
    }
    return NOT_FOUND;
}
int main(){
    int n;
    cin>>n;
    int S[100000];
    for(int i=0;i<n;i++){
        cin>>S[i];
    }
    int q;
    cin>>q;
    int T[50000];
    for(int i=0;i<q;i++){
        cin>>T[i];
    }
    int C=0;
    for(int i=0;i<q;i++){
        if(binarySearch(S,0,n,T[i])!=NOT_FOUND)
            C++;
    }
    cout<<C<<endl;
}


Measured memory_bytes: 3684
#include <stdio.h>
#include <stdlib.h>

int main() {
	long *a, db[50000], sum;
	int n, i, j, c=0;
	while(1) {
		scanf("%d",&n);
		if (n==0) break;
		a = (long *)malloc( sizeof(long) * n );
		for(i=0;i<n;i++) {
			scanf("%d",&a[i]);
		}
		db[c] = -2147483647;
		// Set Start Point
		for(i=0;i<n;i++) {
			sum = 0;
			for(j=i;j<n;j++) {
				sum+=a[j];
				if (db[c]<sum) db[c] = sum;
			}
		}
		c++;
		free(a);
	}
	for(i=0;i<c;i++) {
		printf("%d\n",db[i]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> A(N),B(N);
    rep(i,0,N)cin >> A[i];
    rep(i,0,N)cin >> B[i];
    vector<int> upA(N),upB(N);
    upA[0] = upB[N-1] = 1;
    rep(i,1,N)if(A[i] > A[i-1])upA[i] = 1;
    for(int i = N-2;i >= 0;i--)if(B[i] > B[i+1])upB[i] = 1;
    ll ans = 1;
    //rep(i,0,N)cout << upA[i] << " ";cout<< endl;
    //rep(i,0,N)cout << upB[i] << " ";cout  << endl;
    rep(i,0,N){
        //if(upA[i] && upB[i] && A[i] != B[i])ans = 0;
        if(upA[i] && A[i] > B[i])ans = 0;
        if(upB[i] && B[i] > A[i])ans = 0;
        if(!(upA[i] || upB[i]) )ans *= min(A[i], B[i]);
        ans %= MOD;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int D = sc.nextInt();
		int N = sc.nextInt();
		int ans = 0;
		
		if(D == 0){
			if(N != 100) ans = N;
			else ans = 101;
		}else{
			if(N != 100) ans = (int)(N * Math.pow(100, D));
			else ans = (int)((N + 1) * Math.pow(100, D));
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int a, b; cin >> a >> b;
  int c, d; cin >> c >> d;
  auto ans = std::max(a*b, c*d);
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,q=map(int,input().split())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1))

node=[[] for _ in range(n)]
d=deque()
d.append(0)
for pair in v:
    node[pair[0]].append(pair[1])
    node[pair[1]].append(pair[0])
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
seen=[0]*n
seen[0]=1
while True:
    if not d:
        break
    i=d.pop()
    for j in node[i]:
        if seen[j]==0:
            d.appendleft(j)
            seen[j]=1
            ans[j]+=ans[i]
print(*ans)

Measured memory_bytes: 124780
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		int[]a = new int[N];
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		scan.close();
		int min = Integer.MAX_VALUE;
		int right = 0;
		for(int left = 0; left < N; left++) {
			while(right < N && map.size() < K) {
				if(a[right] <= K) {
					map.merge(a[right], 1, (val1, val2) -> val1 + val2);
				}
				right++;
			}
			if(map.size() == K) {
				int l = right - left;
				min = Math.min(min, l);
			}
			if(right == left) {
				right ++;
			}else {
				if(a[left] <= K) {
					if(map.get(a[left]) == 1) {
						map.remove(a[left]);
					}else {
						map.merge(a[left], -1, (val1, val2) -> val1 + val2);
					}
				}
			}
		}
		if(min == Integer.MAX_VALUE) {
			System.out.println(0);
		}else {
			System.out.println(min);
		}
	}
}


Measured memory_bytes: 72440
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

vector<pair<int, int> > edges;
vector<int> ck;

int main () {
    int N, M;
    scanf("%d%d", &N, &M);
    for(int i=1;i<=M;i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        edges.push_back({a,b});
    }
    ck = vector<int> (N+1, 0);
    for(int i=0;i<M;i++) {
        if(edges[i].second==N) {
            ck[edges[i].first]=1;
        }
    }
    for(int i=0;i<M;i++) {
        if(edges[i].first == 1) {
            if(ck[edges[i].second]) {
                cout << "POSSIBLE";
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 2544
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    ll act[3][n];
    rep(j,n){
        rep(i,3){cin>>act[i][j];}
    }
    ll dp[3][n];
    rep(i,3){
        dp[i][0]=act[i][0];
    }
    repr(i,1,n){
        rep(j,3){
            dp[j][i]=max(dp[(j+1)%3][i-1],dp[(j+2)%3][i-1])+act[j][i];
            DEBUG{printf("j %d, i %d, dp %lld\n", j,i,dp[j][i]);}
        }
    }
    ll res = 0;
    rep(i,3){
        res = max(res, dp[i][n-1]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int n;
int a[100005];

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = n - 2; i >= 0; i--){
        if (a[i] > a[i + 1]) a[i]--;
        if (a[i] > a[i + 1]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    constexpr ll K_ = 38;
    constexpr ll K = K_ - 1;
    constexpr ll N = K_ * K_ - K_ + 1;
    //    assert(N >= 1000 and N <= 2000);
    cout << N << " " << K_ << endl;
    vector<vector<vector<ll>>> table(K, vector<vector<ll>>(K, vector<ll>(K, 0)));
    for (ll i = 0; i < K; i++) {
        for (int j = 0; j < K; j++) {
            table[0][i][j] = i;
        }
    }
    for (ll i = 1; i < K; i++) {
        for (ll j = 0; j < K; j++) {
            for (ll k = 0; k < K; k++) {
                table[i][j][k] = (table[i - 1][j][k] + k) % K;
            }
        }
    }
    auto f = [=](ll i, ll j) {
        return K * i + j + 2 + K;
    };
    for (ll i = 0; i <= K; i++) {
        cout << 1;
        const ll start = K * i + 2;
        for (ll j = 0; j < K; j++) {
            cout << " " << start + j;
        }
        cout << endl;
    }
    for (ll i = 0; i < K; i++) {
        for (ll j = 0; j < K; j++) {
            cout << i + 2;
            for (ll k = 0; k < K; k++) {
                cout << " " << f(k, table[i][j][k]);
            }
            cout << endl;
        }
    }

    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    using Block = struct {
      lli w, s, v;
    };
    vector<Block> v(n);
    for (int i = 0; i < n; ++i) {
      cin >> v[i].w >> v[i].s >> v[i].v;
    }
    sort(v.begin(), v.end(), [] (auto a, auto b) { return a.w + a.s < b.w + b.s; });


    const int N = 1000 + 5;
    const int M = 20000 + 5;
    static lli dp[N][M];
    fill(&dp[0][0], &dp[N - 1][M - 1], 0);

    for (int i = 0; i < v.size(); ++i) {
      for (int j = 0; j < M; ++j) {
        setmax(dp[i + 1][j], dp[i][j]);
      }
      for (int j = 0; j <= v[i].s; ++j) {
        setmax(dp[i + 1][j + v[i].w], dp[i][j] + v[i].v);
      }
    }
    cout << *max_element(&dp[0][0], &dp[N - 1][M - 1] + 1) << endl;
  }
  
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int l = -1;
    int r = n;
    int idx;
    int male = 0;
    int female = 0;
    rep(i, 20) {
        if ( i == 0 ) {
            idx = 0;
        }
        else {
            idx = ( r + l ) / 2;
        }
        cout << idx << endl;
        cout.flush();
        string s;
        cin >> s;
        if ( s == "Vacant" ) {
            return 0;
        }
        else if ( s == "Male" ) {
            if ( i == 0 ) {
                male = idx % 2;
                female = ( idx % 2 ) ? 0 : 1;
                idx = ( r + l ) / 2;
            }
            else if ( male != idx % 2 ) {
                r = idx;
            }
            else {
                l = idx;
            }
        }
        else {
            if ( i == 0 ) {
                female = idx % 2;
                male = ( idx % 2 ) ? 0 : 1;
                idx = ( r + l ) / 2;
            }
            else if ( female != idx % 2 ) {
                r = idx;
            }
            else {
                l = idx;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 852
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

struct edge { int to, cap, rev; };

const int MAX_SIZE = 202;

vector<edge>G[MAX_SIZE];

void add_edge(int from, int to, int cap) {
	G[from].push_back(edge{ to, cap, (int)G[to].size() });
	G[to].push_back(edge{ from, 0, (int)G[from].size() - 1 });
}

bool used[MAX_SIZE];
int dfs(int p, int t, int f) {
	if (p == t)return f;
	used[p] = true;

	for (int i = 0; i < G[p].size(); i++) {
		edge &e = G[p][i];
		if (used[e.to] || e.cap == 0)continue;
		int _f = dfs(e.to, t, min(f, e.cap));
		if (_f) {
			e.cap -= _f;
			G[e.to][e.rev].cap += _f;
			return _f;
		}
	}

	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	while (true) {
		fill_n(used, MAX_SIZE, false);
		int f = dfs(s, t, INF);
		if (f)flow += f;
		else return flow;
	}
}

int n;
vector<pair<int, int>> r, b;
int main() {
	cin >> n;
	int s = 2 * n, t = s + 1;
	REP(i, n) {
		int c, d;
		cin >> c >> d;
		r.emplace_back(mp(c, d));
		add_edge(s, i, 1);
	}
	REP(i, n) {
		int c, d;
		cin >> c >> d;
		b.emplace_back(mp(c, d));
		add_edge(n + i, t, 1);
	}
	REP(i, n)REP(j, n) {
		if (r[i].first < b[j].first&&r[i].second < b[j].second)add_edge(i, j + n, 1);
	}
	cout << max_flow(s, t) << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i=2; i*i<=n; ++i) {
        while (n%i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n]++;
    return res;
}

ll mod = 1e9+7;

struct ModComb {
    vector<long long> fact, rfact;
    long long max, mod;
    ModComb(long long ma, long long mod) :fact(ma, 0), rfact(ma, 0), max(ma), mod(mod) {
        fact[0] = 1;
        for (long long i=1; i<max; ++i) {
            fact[i] = fact[i-1]*i;
            fact[i] %= mod;
        }
        rfact[max-1] = mod_inverse(fact[max-1], mod);
        for (long long i=max-2; i>=0; --i) {
            rfact[i] = rfact[i+1]*(i+1);
            rfact[i] %= mod;
        }
    }
    long long mod_pow(long long x, long long n, long long mod) {
        long long a = 1LL;
        while (n) {
            if (n%2) a = ((a%mod)*(x%mod))%mod;
            x = ((x%mod)*(x%mod))%mod;
            n /= 2LL;
        }
        return a;
    }

    long long mod_inverse(long long a, long long m) {
        return mod_pow(a, m-2, m);
    }

    long long operator()(long long n, long long r) {
        if (n < r) return 0;
        return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    ModComb mb(210000LL, mod);

    auto v = prime_factor(m);
    ll res = 1;
    for (auto& t : v) {
        ll num = t.second;
        ll tmp = mb(num+n-1, n-1);
        res = (res * tmp) % mod;
    }
    cout << res << endl;
}


Measured memory_bytes: 3584
#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[i];
    }
    vector<long long int> s(N+1, 0);
    for(int i = 0; i < N; i++) {
        s[i+1] = s[i] + a[i];
    }
    map<long long int, long long int> nums;
    for(int i = 0; i < N+1; i++) {
        nums[s[i]]++;
    }
    long long res = 0;
    for(auto it : nums) {
        long long int num = it.second;
        res += num*(num-1)/2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 15104
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;
#define MAX_A 200
#define MAX_E 10100

struct edge{int s, v, cost;};

int e, v;
edge es[MAX_E];
int _rank[MAX_A], par[MAX_A];

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

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

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

int unite(int x, int y){
	x = find(x);
	y = find(y);
	if(_rank[x] < _rank[y]){
		par[x] = y;
	} else {
		par[y] = x;
		if(_rank[y] == _rank[x]) _rank[x]++;
	}
}

bool same(int x,int y){
	return find(x) == find(y);
}

int kraskal(){
	sort(es, es+e,comp);
	
	init(v);
	
	int sum = 0;
	
	for(int i = 0; i < e; i++){
		if(same(es[i].s, es[i].v) == false){
			// cout<<es[i].s<<" "<<es[i].v<<" "<<es[i].cost<<endl;
			sum += (es[i].cost-100)/100;
			unite(es[i].s, es[i].v);
		}
	}
	return sum;
}

int main(){
	
	while(1){
		string s, z;
		char t;
		int a[3], count = 0,  size;
		cin>>v;
		if(!v)break;
		cin>>e;
		for(int i = 0; i < e; i++){
			cin>>z;
			size = z.size();
			count = 0;
			for(int j = 0; j < size; j++){
				t = z[j];
				if(t != ',') s += t;
				if(t == ',' || j == size-1){
					a[count++] = stoi(s);
					s.clear();
				}
			}
			es[i].s = a[0];
			es[i].v = a[1];
			es[i].cost = a[2];
		}
		
		cout<<kraskal()<<endl;
		
	}
	
	
	return 0;
}


Measured memory_bytes: 3220
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var k = int.Parse(Console.ReadLine().Trim());
        getAns(k);
    }
    static void getAns (int k)
    {
        var q = new Queue<string>();
        for (int i = 1; i <= 9; i++) q.Enqueue(i.ToString());
        var count = 0;
        while (true)
        {
            var w = q.Dequeue();
            count++;
            if (count == k) { Console.WriteLine(w); return; }
            var a = w[w.Length - 1] - '0';
            if (a == 0) { q.Enqueue(w + "0"); q.Enqueue(w + "1"); }
            else if (a == 9) { q.Enqueue(w + "8"); q.Enqueue(w + "9"); }
            else
            {
                q.Enqueue(w + (a - 1).ToString());
                q.Enqueue(w + a.ToString());
                q.Enqueue(w + (a + 1).ToString());
            }
        }
    }
}


Measured memory_bytes: 33872
S=input()
while len(S) >=5:
	if S[-7:]=='dreamer':
		S=S[:-7]
	elif S[-6:] == 'eraser':
		S=S[:-6]
	elif S[-5:] == 'dream':
		S=S[:-5]
	elif S[-5:] == 'erase':
		S=S[:-5]
	else:
		print('NO')
		break
if len(S)==0:
	print('YES')
if 1<=len(S)<=4:
	print('NO')


Measured memory_bytes: 3188
#include<stdio.h>

int main(){
	int a,b,c,i;
	int ans = 0;
	scanf("%d %d %d",&a, &b, &c);

	for(i = a; i <= b; i++){
	  if(c % i == 0)
		  ans++;		
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int d=n/100;
	int m=111*d;
	if(n<=m) cout << m << endl;
	else{
		d++; m=111*d;
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();

        long ans = n - 1;

        int sqrt = (int) Math.sqrt(n);

        for (int i = sqrt; 1 < i; i--) {
            if (n % i == 0) {
                ans = i + (n / i) - 2;
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
const int N = 4002;
char A[N], B[N]; int n,L[N],R[N];
int dis(int x,int y){
	while(x<1) x+=n; while(x>n) x-=n;
	while(y<1) y+=n; while(y>n) y-=n;
	return min(abs(x-y),n-abs(x-y));
}
int main() {
	scanf("%s%s",A+1,B+1);
	n = strlen(A+1);

	bool allzero = 1;
	for(int i=1;i<=n;i++)if(B[i]=='1') allzero=0;
	if(allzero) {
		for(int i=1;i<=n;i++)if(A[i]=='1')return !printf("-1\n");
		return !printf("0\n");
	}

	for(int i=1;i<=n;i++) B[i+n]=B[i];
	for(int i=1;i<=n;i++){
		for(int j=i;j<=2*n;j++) if(B[j]=='1') {
			R[i]=j-i; break;
		}
		bool suc=0;
		for(int j=i;j>=1;j--) if(B[j]=='1') {
			suc=1; L[i]=i-j; break;
		}
		if(suc==0) {
			for(int j=n;j>i;j--) if(B[j]=='1'){
				L[i]=i+(n-j); break;
			}
		}
		//printf("[%d, %d]\n", L[i],R[i]);
	}
	int answer=1e9;
	for(int i=0;i<n;i++) {
		//printf("i=%d\n", i);
		bool flag[N] = {0}; 
		int modify=0,tmpans=0;
		for(int j=1;j<=n;j++){
			if(A[j]!=B[i+j]) flag[j]=1, modify ++;
		}
		tmpans+=modify;

		int mndt=1e9;
		// dx: go right i steps
		// dy: go left n-i steps
		multiset< pair<int,int> > st,stl; 
		st.clear(); stl.clear();
		for(int j=1;j<=n;j++) if(flag[j]) if(L[j]&&R[j]) st.insert(make_pair(R[j],L[j])), stl.insert(make_pair(L[j],R[j]));
		
		for(int go_right=0;go_right<=n;go_right++) {
			//printf("go_right = %d\n", go_right);
			while(st.size()){
				pair<int,int> p=*st.begin();
				if(p.first<=go_right){
					st.erase(st.begin()); stl.erase(stl.find(make_pair(p.second,p.first)));
				}else{
					break;
				}
			}
			while(stl.size()){
				pair<int,int> p=*stl.rbegin();
				if(p.first>=n-go_right){
					stl.erase(stl.find(p)); st.erase(st.find(make_pair(p.second,p.first)));
				}else{
					break;
				}
			}
			int tmp=go_right;
			int go_left=-1;
			if(stl.size()){
				go_left=(*stl.rbegin()).first; tmp+=go_right+go_left;
				tmp+=dis(-go_left,i);
			} else {
				tmp+=dis(go_right,i);
			}
			mndt=min(mndt,tmp);
		}

		st.clear(); stl.clear();
		for(int j=1;j<=n;j++) if(flag[j]) if(L[j]&&R[j]) st.insert(make_pair(R[j],L[j])), stl.insert(make_pair(L[j],R[j]));
		for(int go_left=0;go_left<=n;go_left++) {
			
			while(st.size()){
				pair<int,int> p=*st.rbegin();
				if(p.first>=n-go_left){
					//if(i==1&&go_left==0) printf("!\n");
					st.erase(st.find(p)); stl.erase(stl.find(make_pair(p.second,p.first)));
				}else{
					break;
				}
			}
			while(stl.size()){
				pair<int,int> p=*stl.begin();
				if(p.first<=go_left){
					//if(i==1&&go_left==0) printf("!\n");
					stl.erase(stl.begin()); st.erase(st.find(make_pair(p.second,p.first)));
				}else{
					break;
				}
			}
			int tmp=go_left;
			int go_right=-1;
			if(st.size()){
				go_right=(*st.rbegin()).first; tmp+=go_right+go_left;
				tmp+=dis(go_right,i);
			} else {
				tmp+=dis(-go_left,i);
			}
			mndt=min(mndt,tmp);
		}
		//if(i==1)printf("# %d\n", mndt);
		tmpans+=mndt;
		answer=min(answer,tmpans);

	}
	cout << answer << endl;
}




Measured memory_bytes: 512
n = gets.to_i

min = 0

(1..(n/2)).each do |a|
  b = n - a
  sum = a.to_s.chars.inject(0){|sum,c| sum + c.to_i }
  sum += b.to_s.chars.inject(0){|sum,c| sum + c.to_i }

  if min ==  0
    min = sum
  elsif min > sum
    min = sum
  end
end

puts min

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n,a[N],f,t,b;

int main(){
    readi(n);
    lp(i,1,n){
        readi(a[i]);
        if(a[i]%4 == 0) ++f;
        else if(a[i]%2 == 0) ++t;
        else ++b;
    }

    if(f >= (t%2) + b - 1) cout <<"Yes";
    else cout <<"No";
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);
*/


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->left != NIL) x=x->left;

  return x;

}

Node treeMaximum(Node x){

  while(x->right != NIL) x=x->right;

  return x;

}

Node treeSearch(Node u, int k){

  if(u == NIL || k == u->key) return u;

  if(k < u->key) return treeSearch(u->left,k);

  else return treeSearch(u->right,k);

}

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 to be deleted
  Node x; // child of y



}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){

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

}
void preorder(Node u){

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


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

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

  return 0;
}



Measured memory_bytes: 20476
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

public class Main {
    static int MOD = 1000000007;

    public static class Mas {
        int x;
        int y;
        int step;

        Mas(int x, int y, int step) {
            this.x = x;
            this.y = y;
            this.step = step;
        }
    }

    private static final int[] vX = { 1, 0, 0, -1 };
    private static final int[] vY = { 0, 1, -1, 0 };

    public static void main(String[] args) {

        FastScanner fs = new FastScanner();
        int[] dp = new int[45];
        int n = fs.nextInt();
        dp[0] = 1;
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        System.out.println(dp[n]);
    }

}



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

int main(){
    while(1){
        int n,w;
        cin >> n >> w;
        if(n == 0) break;

        vector<int> h(100, 0);
        int d = 0;
        for(int i=0; i<n; i++){
            int v;
            cin >> v;
            h[v/w]++;
            d = max(d, v/w);
        }
        double ans = 0;
        for(int i=0; i<=d; i++){
            ans += (1-(double)i/d)*h[i];
        }
        ans /= *max_element(h.begin(), h.end());
        ans += 0.01;
        cout << fixed << setprecision(10);
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
	int x1, y1, x2, y2;
	cin>>x1>>y1>>x2>>y2;
	
	int dx=x2-x1;
	int dy=y2-y1;
	
	int x3=x2-dy;
	int y3=y2+dx;
	
	int x4=x1-dy;
	int y4=y1+dx;
	
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

}

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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int n;
    pair<int, int> v[100005];
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> v[i].f;
        v[i].s=i;
    }
    sort(v+1, v+n+1);
    for(int i=1; i<=n; i++){
        cout << v[i].s << es;
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
const int N = 3e5 + 233;
int n, m, p[N], pre[N], ans = 0;
set<int> a[N];
inline int find(int x) {
  return pre[x] == x ? x : pre[x] = find(pre[x]);
}

main(void) {
  read(n); read(m);
  for(int i = 1; i <= n; i ++)
    read(p[i]), pre[i] = i;
  for(int i = 1; i <= m; i ++) {
    int x, y; read(x); read(y);
    pre[find(y)] = find(x);
  }
  for(int i = 1; i <= n; i ++)
    a[find(i)].insert(p[i]);
  for(int i = 1; i <= n; i ++)
    if(a[find(i)].count(i))
      ++ ans;
  cout << ans << "\n";
}


Measured memory_bytes: 21248