akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

vector<int> g[1<<20];int n,m,a,b;
int visited[1<<20];

int dfs(int s) {
  visited[s] = true;
  int ans = 0;
  for(int x:g[s]) {
    if(visited[x]) continue;
    ans += dfs(x);
  }
  return ans+1;
}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
cin>>n>>m;
rep(i,m) {
  cin>>a>>b;
  g[a].pb(b);
  g[b].pb(a);
}

int ans = 0;
for(int i = 1;i <= n;i++) {
  if(!visited[i]) {
    int tans = dfs(i);
    ans = max(ans,tans);
  }
}
cout<<ans;
 return 0;
}


Measured memory_bytes: 44640
# abc151 C
n, m = gets.split.map(&:to_i)

ps = m.times.map {
  pp, xx = *gets.split
  [pp.to_i, xx == "AC"]
}

ps2 = ps.group_by{|(pp,ss)|pp}
ac = ps2.select{|k,v|v.any?{|vv|vv[1]}}.size
wa = ps2.map{|(k,v)| v.find_index{|vv|vv[1]} || 0 }.inject(:+) || 0
puts [ac,wa].join(' ')

# ans = s.match?(//)

# puts (ans) ? 'Yes' : 'No'

# puts (ans) ? 'YES' : 'NO'

# puts c.map{|x| x.map{|xx| format("%2d",xx) }.join }.join("\n")



Measured memory_bytes: 28668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS=1e-10;
const ll INF=1000000000;
int main(){
    int n;
    while(cin>>n,n){
        int x[210]={};int y[210]={};
        for(int i=1;i<n;i++){
            int idx,d;
            cin>>idx>>d;
            switch(d){
                case 0:x[i]=x[idx]-1;y[i]=y[idx];break;
                case 1:y[i]=y[idx]-1;x[i]=x[idx];break;
                case 2:x[i]=x[idx]+1;y[i]=y[idx];break;
                case 3:y[i]=y[idx]+1;x[i]=x[idx];break;
            }
        }   
        int xpm=-INF;int xmm=INF;int ymm=INF;int ypm=-INF;
        for(int i=0;i<n;i++){
            xpm=max(xpm,x[i]);
            xmm=min(xmm,x[i]);
            ypm=max(ypm,y[i]);
            ymm=min(ymm,y[i]);
        }
        //cout<<xpm<<" "<<xmm<<" "<<ypm<<" "<<ymm<<endl;
        cout<<xpm-xmm+1<<" "<<ypm-ymm+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3008
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
const ll mod=10e9+7;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll S;
    cin>>S;
    ll ya=S/1000000000;
    ll amari=1000000000*ya-S;
    ll xb=1,yb;
    if(amari==0){
        xb=0;
        yb=0;
    }
    else {
      ya++;
      yb=1000000000+amari;
    }
    cout<<0<<" "<<0<<" "<<1000000000<<" "<<yb<<" "<<xb<<" "<<ya<<endl;
    return 0;
}


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

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  
  int ans = 0;
  for(int i = 1; i <= n; ++i)
  {
    string s = to_string(i);
    int tmp = 0;
    for(int k = 0; k < s.size(); ++k) tmp += s[k] - '0';
    if(a <= tmp && tmp <= b) ans += i;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int spaces = b - a - 1;
        if (spaces % 2 == 0) System.out.println("Borys");
        else System.out.println("Alice");
    }
}


Measured memory_bytes: 21844
n = int(input())
a = list(map(int,input().split()))
ans = int(1)
a.sort(reverse=True)
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ans = ("-1")
        break
if 0 in a:
    ans = 0
print(ans)


Measured memory_bytes: 21660
S = input()

alphabets = [chr(i) for i in range(97, 97+26)]
str_len = len(S)

if str_len < 26:
    for alphabet in alphabets:
        if alphabet not in S:
            print(S + alphabet)
            exit()
else:
    for i in range(-1, -str_len, -1):
        tmp_string = sorted(list(S[i:]))
        for tmp_str in tmp_string:
            if tmp_str > S[i - 1]:
                print(S[:i - 1] + tmp_str)
                exit()
print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    int N, T; cin >> N >> T;
    vector<int> t(N);
    for (int i = 0; i < N; i++) cin >> t[i];

    ll ans = 0;
    for (int i = 0; i < N - 1; i++) {
        if (t[i + 1] - t[i] < T) ans += t[i + 1] - t[i];
        else ans += T; 
    }
    ans += T;
    cout << ans << endl;
}

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

int main(){
    int N;
    int H = 0;
    int B = 0;
    cin >> N;
    int A[2][N];
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            cin >> A[i][j];
        }
    }

    for(int i=0;i<N;i++){
        int C = 0;
        for(int j=0;j<=i;j++){
            C += A[0][j];
            B = j;
        }
        for(int r=B;r<N;r++){
            C += A[1][r];
        }
        if(C > H){
            H = C;
        }
    }

    cout << H << endl;
    return 0;

}

Measured memory_bytes: 256
import numpy as np

N = int(input())
data = np.array(list(map(int, input().split())))

ans = 0
for i in range(N):
	if data[i] % 2 == 0:
		if data[i] % 5 == 0:
			ans = 0
		elif data[i] % 3 == 0:
			ans = 0
		else:
			ans = 1
			break

if ans == 0:
	print("APPROVED")
else:
	print("DENIED")

Measured memory_bytes: 12488
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {
	string s;
  	cin >> s;
  
  	FOR(3){
      	if(s[i] == s[i + 1]){
          COUT("Bad");
          return 0;
        }
    }
  
  COUT("Good");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
    double a, b;
    int sum;
    double mean;

    int roundup_mean;
    double rounddown_mean;
    double roundup_dif;
  
    cin >> a >> b;
    sum = a + b;
    mean = (a + b)/2;
    rounddown_mean = (a + b)/2;
    
    roundup_dif = 1 - (mean - rounddown_mean);
  
    roundup_mean = rounddown_mean + roundup_dif * ((sum)%2);    

    cout << roundup_mean << endl;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dx[2] = {1,0};
int dy[2] = {0,1};
char a[1000][1000];
long long dp[1000][1000] = {};

int main() {
    int H,W;
    cin >> H >> W;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) cin >> a[i][j];
    }

    dp[0][0] = 1;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if(a[i][j] == '#') continue;
            for(int d=0; d<2; ++d){
                int nx = i + dx[d];
                int ny = j + dy[d];
                if(nx >=0 && nx < H && ny >= 0 && ny < W && a[nx][ny] == '.'){
                    dp[nx][ny] += dp[i][j];
                    dp[nx][ny] %= mod;
                }
            }
        }
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

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

using namespace std;

#define MAX 101

int arr[MAX], W;

void ins(int id, int w){
  for(int i = 0 ; i < W-w+1 ; i++){
    if(arr[i] == -1){
      bool flg = true;
      for(int j = i ; j < i+w ; j++){
        if(arr[j] != -1){
          flg = false;
          break;
        }
      }

      if(flg){
        cout << i << endl;
        for(int j = i ; j < i+w ; j++){
          arr[j] = id;
        }
        return;
      }
    }
  }

  cout << "impossible" << endl;
}

void del(int id){
  for(int i = 0 ; i < W ; i++){
    if(arr[i] == id){
      while(arr[i] == id){
        arr[i++] = -1;
      }
      return;
    }
  }
}

int main(){
  int Q, id, w;
  char ch;

  while(cin >> W >> Q ,(W | Q)){
    memset(arr,-1,sizeof(arr));
    for(int i = 0 ; i < Q ; i++){
      cin >> ch;

      if(ch == 's'){
        cin >> id >> w;
        ins(id, w);
      }else{
        cin >> id;
        del(id);
      }
    }
    cout << "END" << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#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>;

const double PI = acos(-1);

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double theta_m = m / 60 * 2 * PI;
  double theta_h = (h / 12 + +m / 720) * 2 * PI;
  double ans = sqrt(a * a + b * b - 2 * a * b * cos(abs(theta_h - theta_m)));
  // cout << fixed << setprecision(20) << ans << endl;
  printf("%.10f\n", ans);
  return 0;
}


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

using namespace std;

namespace mod {

template <class T, int M>
class MInt;

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp);

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n);

template <class T, int M>
class MInt {
  T n_;

 public:
  MInt() : n_(0) {}
  MInt(T n) : n_((n % M + M) % M) {}

  MInt &operator+=(const MInt &rhs) {
    n_ += rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator-=(const MInt &rhs) {
    n_ += M - rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator*=(const MInt &rhs) {
    n_ = n_ * rhs.n_ % M;
    return *this;
  }

  MInt &operator/=(const MInt &rhs) { return (*this) *= Inv(rhs); }

  T Get() { return n_; }
};

template <class T, int M>
MInt<T, M> operator-(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res -= rhs;
}

template <class T, int M>
MInt<T, M> operator+(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res += rhs;
}

template <class T, int M>
MInt<T, M> operator*(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res *= rhs;
}

template <class T, int M>
MInt<T, M> operator/(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res /= rhs;
}

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp) {
  if (exp == 0) {
    return 1;
  }

  auto a = Pow(base, exp / 2);
  a *= a;
  if (exp % 2 == 1) {
    a *= base;
  }

  return a;
}

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n) {
  return Pow(n, static_cast<T>(M - 2));
}
}  // namespace mod

const int md = 1e9 + 7;
using MInt = mod::MInt<long long, md>;
class BinCoef {
  vector<MInt> f;

 public:
  BinCoef(int n) : f(n + 1) {
    f[0] = f[1] = 1;
    for (int i = 2; i <= n; i++) {
      f[i] = MInt(i) * f[i - 1];
    }
  }

  MInt NCM(int n, int m) {
    if (n < m) {
      return 0;
    }
    return f[n] * mod::Inv(f[m] * f[n - m]);
  }

  MInt HCM(int n, int m) { return NCM(n + m - 1, m); }
};

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<int> va(n + 1), indeces(n + 1, -1);
  int idx1, idx2;
  for (int i = 0; i < n + 1; ++i) {
    cin >> va[i];
    if (indeces[va[i]] < 0) {
      indeces[va[i]] = i;
    } else {
      idx1 = indeces[va[i]];
      idx2 = i;
    }
  }

  int cnt = idx1 + (n - idx2);
  BinCoef bc(n + 1);

  vector<MInt> ans;
  for (int i = 1; i <= n + 1; ++i) {
    ans.push_back(bc.NCM(n + 1, i) - bc.NCM(cnt, i - 1));
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].Get() << '\n';
  }
  return 0;
}

Measured memory_bytes: 5812
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n,k;
    cin >> n >> k;

    if(k==1){
        cout << 0 << endl;
        return 0;
    }

    const int ans = min(n % k, k - n % k);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(), x.end()
using namespace std;
ll power(ll x, ll y,ll  m) 
{ 
    if (y == 0) 
        return 1; 
    ll  p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
ll modInverse(ll a, ll m) 
{ 
    ll g = __gcd(a, m); 
    if (g != 1) 
        cout << "Inverse doesn't exist"; 
    
    
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
        
              return power(a, m-2, m); 
    
} 

ll fact[1000];
void fac(ll m)
{
	ll i;
	fact[0]=1;
	for(i=1;i<1000;i++)
	{
		fact[i]=(i*fact[i-1])%m;
	}
}

ll comb(ll n,ll k,ll m)
{
	return(fact[n]*modInverse(fact[k],m)%m *modInverse(fact[n-k],m)%m)%m;
}
bool cmp(pair<ll,ll> a,pair<ll,ll>b)
{
	if(a.second==b.second)
	return a.first<b.first;
	return a.second>b.second;
}
void SieveOfEratosthenes(ll n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
     bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
/*ll f(ll a)
{
ll i;ll res=1;ll c;
for(i=2;i*i<=a;i++)
{
	if(a%i==0)
	{
		c=0;
		while(a%i==0)
		{
			c++;
			a=a/i;
		}
		
	}
	if(c>0)
	{
		res*=(c+1);
	}
}
	if(a>1)
	{
		res*=2;
	}
		
	return res;
}*/
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll n;
  cin>>n;
  ll res=0;ll i;
  for(i=1;i<=n-1;i++)
  {
  	res+=(n-1)/(i);
  }
  cout<<res<<endl;
return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
char a[105];
char b[105];
int cmp(int x,int y)
{
	return x>y;
}
int main()
{
	gets(a);
	gets(b);
	sort(a,a+strlen(a));
	sort(b,b+strlen(b),cmp);
	for(int i=0;i<max(strlen(a),strlen(b));i++)
	{
		if(a[i]<b[i])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		if(a[i]>b[i])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a>b&&b!=1){
		printf("Alice\n");
	} if(a!=1&&a<b){
		printf("Bob\n");
	} if(a==b){
		printf("Draw\n");
	} if(a==1&&b>1){
		printf("Alice\n");
	} if(a>1&&b==1){
		printf("Bob\n");
	}
	system("pause");
	return 0;
}



Measured memory_bytes: 504
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

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

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    int N, R;
    cin >> N >> R;
    int res = 0;
    if (N >= 10) {
        res = R;
    } else {
        res = R + (100*(10-N));
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };


struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

  int root(int x) {
    if (par[x] < 0)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { return -par[root(x)]; }
};

signed main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<int> p(n);
  UnionFind tree(n+1);
  REP(i, n) {
    int x;
    cin >> x;
    p[i] = x-1;
  }
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    tree.unite(x-1, y-1);
  }
  ll ans = 0;
  REP(i, n) {
    if(tree.same(p[i], i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
let rec take n = function
  | [] -> []
  | x :: xs ->
      if n = 0 then []
      else x :: take (n - 1) xs

let () = Scanf.scanf "%d %d" @@ fun n m ->
  let ans = ref [] in
  let i = ref 1 in
  let j = ref (n / 2) in
  while (!i < !j) do
    ans := (!i, !j) :: !ans;
    incr i;
    decr j
  done;
  let i = ref (1 + n / 2) in
  let j = ref (n - 1 + n mod 2) in
  while (!i < !j) do
    ans := (!i, !j) :: !ans;
    incr i;
    decr j
  done;
  List.iter (fun (i, j) -> Printf.printf "%d %d\n" i j) @@
  take m !ans


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



// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
  long long H,W;
  vector<string> image;
  string im;
  cin >> H >> W;

  REP(i, W+2){
    cout << '#';
  }
  cout << endl;

  REP(i, H){
    cout << '#';
    cin >> im;
    cout << im;

    cout << '#' << endl;
  }
  REP(i, W+2){
    cout << '#';
  }
  cout << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
int const MOD = 1000000007;
#define END {cout<<END<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n';
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int n,m,q,_,x,y;
string s,t;
bool ok;
char ch;
V(int)a;
void ins(int g){
  rer(i,g,n){
    int m=a[i];
    int q=i-g;
    while(q>=0&&a[q]>m){
      a[q+g]=a[q];
      q-=g;
      x++;
    }
    a[q+g]=m;
  }
  return;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
    
  cin>>n; a.assign(n,0); V(int)b;
  rep(i,n)cin>>a[i];
  y=1;
  while(y<=n){
    b.eb(y);
    y*=2;
  }
  reverse(ALL(b));
  for(auto e:b)ins(e);
  pri1(b.size());
  rep(i,b.size())cout<<b[i]<<(i==b.size()-1?'\n':' ');
  pri1(x);
  rep(i,n)pri1(a[i]);
}


Measured memory_bytes: 6716
#include <stdio.h>

int main(void){
	int max, min, i, j, s, sum, n;
	while(1){
		scanf("%d",&n);
		if(!n) break;
		sum = 0;
		max = 0, min = 500;
		for(i = 0;i < n;i++){
			sum = 0;
			for(j = 0;j < 5;j++){
				scanf("%d",&s);
				sum += s;
			}
			if(max < sum) max = sum;
			if(min > sum) min = sum;
		}
		printf("%d %d\n",max,min);
	}
	return 0;
}

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

#define min(a, b) ((a) < (b) ? (a): (b))
#define max(a, b) ((a) > (b) ? (a): (b))

int n;
int down[1024][1024];
int right[1024][1024];

int side(int y, int x)
{
    int d;
    int r;
    int s = min(down[y][x], right[y][x]);
    int i;

    for (i = 1; i < s; i++){
        int t = min(down[y][x + i], right[y + i][x]);
        s = min(s, t);
    }

    return s;
}

int main(void)
{
    while (scanf("%d", &n), n){
        char map[1024][1024];
        int maxi = 0;
        int i, j, k;

        for (i = 0; i < n; i++){
            scanf("%s", map[i]);
        }

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

            for (j = n - 1; j >= 0; j--){
                d = map[j][i] == '.' ? d + 1 : 0;
                down[j][i] = d;
                r = map[i][j] == '.' ? r + 1 : 0;
                right[i][j] = r;
            }
        }

        for (i = 0; i < n - maxi; i++){
            for (j = 0; j < n - maxi; j++){
                int s = side(i, j);
                maxi = max(maxi, s);
            }
        }

        printf("%d\n", maxi);
    }

    return 0;
}

Measured memory_bytes: 9796
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int r,c;
	int A[101][101]={};

	cin>>r>>c;
	for (int i=0;i<r;i++){
		for (int j=0;j<c;j++){
			cin>>A[i][j];
		}
	}

	for (int i=0;i<=r;i++){
		for (int j=0;j<=c;j++){
			A[i][c]=0;
			A[r][j]=0;
		}
	}

	for (int i=0;i<r;i++){
		for (int j=0;j<c;j++){
			A[i][c]+=A[i][j];
			A[r][j]+=A[i][j];
			A[r][c]+=A[i][j];
		}
	}


	for (int i=0;i<=r;i++){
		for (int j=0;j<=c;j++){
			if(j)cout<<" ";
			cout<<A[i][j];
		}
		cout<<endl;
	}



	return 0;
}

Measured memory_bytes: 3116
n=gets.to_i
s=gets.chomp.to_s


#p s
count=0
for i in 0..9
    i=i.to_s
    v=s.index(i)
    if v==nil
        next
    end
    for j in 0..9
       j=j.to_s
        vv=s.index(j,v+1)
      if vv==nil
              next
      
    end
            for k in 0..9
               k=k.to_s
                vvv=s.index(k,vv+1)
                if vvv==nil
                        next
                
                end
                #p [i,j,k]
                count+=1
               
            end
        
    end


        
end

p count

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

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> xSection{0, w};
    vector<int> ySection{0, h};
    for(int i = 0; i < n; i++)
    {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            xSection[0] = min(max(xSection[0], x), xSection[1]);
        }
        else if (a == 2) {
            xSection[1] = max(xSection[0], min(xSection[1], x));
        }
        else if (a == 3) {
            ySection[0] = min(max(ySection[0], y), ySection[1]);
        }
        else if (a == 4) {
            ySection[1] = max(ySection[0], min(ySection[1], y));
        }
    }
    cout << (xSection[1] - xSection[0]) * (ySection[1] - ySection[0]) << "\n";
}

Measured memory_bytes: 256
n, l = map(int, input().split())
s = list()
for i in range(n):
    s.append(l + i)
sum = sum(s)
if s[0] >= 0:
    print(sum - s[0])
elif s[n - 1] <= 0:
    print(sum - s[n - 1])
else:
    print(sum)
    

Measured memory_bytes: 3060
import math
N = int(input())
X_f = math.floor(N/1.08)
X_c = math.ceil(N/1.08)
if math.floor(X_f*1.08) == N:
    print(X_f)
elif math.floor(X_c*1.08) == N:
    print(X_c)
else:
    print(":(")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;

vector<vector<ll>> kn(pow(2,9),vector<ll>(100001,0));
vector<pair<ll,ll>> vec(1000000);
vector<ll> ans(100000,0);
ll n;

void dfs(ll k){
  if(k >= min((ll)pow(2,9),n)){
    return;
  }
  if(k == 0){
    REP(i,vec[k].first,100001){
      kn[k][i] = vec[k].second;
    }
  }else{
    rep(i,100001){
      kn[k][i] = kn[(k-1)/2][i];
      if(i >= vec[k].first){
        chmax(kn[k][i],kn[(k-1)/2][i-vec[k].first] + vec[k].second);
      }
    }
  }
  dfs(k*2+1);
  dfs(k*2+2);
}

void calc(ll v,ll l,ll score,ll num){
  if(l < 0){
    return;
  }
  if(v < (ll)pow(2,9)){
    chmax(ans[num],kn[v][l] + score);
  }else{
    calc((v-1)/2,l,score,num);
    calc((v-1)/2,l-vec[v].first,score+vec[v].second,num);
  }
}

int main(){
  cin >> n;
  rep(i,n){
    cin >> t1 >> t2;
    vec[i].first = t2;//weight
    vec[i].second = t1;
  }
  dfs(0);
  ll q;
  cin >> q;
  rep(i,q){
    cin >> t1 >> t2;
    t1--;
    calc(t1,t2,0,i);
  }
  rep(i,q){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 420948
#include <bits/stdc++.h>
using namespace std;
// #define cerr if(false)cerr
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;

inline void solve()
{
    int n, k;
    cin >> n >> k;
    vll arr(n);
    for (auto &it : arr)
        cin >> it;
    sort(all(arr));
    cout << accumulate(arr.begin(), arr.begin() + k, 0ll) << endl;
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3628
A, B, C = map(int, input().split())

ans = 0
if A % 2 != B % 2 == C % 2:
    B += 1
    C += 1
    ans += 1
elif B % 2 != C % 2 == A % 2:
    C += 1
    A += 1
    ans += 1
elif C % 2 != A % 2 == B % 2:
    A += 1
    B += 1
    ans += 1

ABC = sorted([A, B, C])

ans += ((ABC[2] - ABC[1]) // 2 + (ABC[2] - ABC[0]) // 2)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main()
{
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> A;
    for(int i=0; i<N; i++)
    {
    	int a;
    	cin >> a;
    	A.push_back(a);
    }

    vector<int> C;
    for(int i=0; i<N; i++)
    {
    	C.push_back((D-1)/A[i]+1);
    }

    int sum = accumulate(C.begin(), C.end(), X);

    cout << sum << endl;

	return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	cout << t << s;
	return 0;
}

Measured memory_bytes: 256
// C - Different Strokes
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
using LLL = tuple<ll,ll,ll>;

int main(){
	int N; cin>>N;
	vector<LLL> V;
	rpz(i, N){
		ll a,b; cin>>a>>b;
		V.emplace_back(a+b, a, b);
	}
	sort(allr(V));
	ll ans = 0;
	rpz(i, N){
		if(i%2) ans -= get<2>(V[i]);
		else ans += get<1>(V[i]);
	}
	cout<< ans <<endl;
}

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

void soalkeren() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  int i = 1;
  int stprev = 0;
  while(i < n) {
    bool ok = 1;
    int k = 0;
    int sz = s[0].size();
    for (int j = stprev; j < stprev + min(l, sz - stprev)&&ok; j++) {
      if(s[0][j] != s[i][k]) {
        ok = 0;
        break;
      }
      k++;
    }
    //cout << sz - stprev << endl;
    //cout << ok << endl;
    //cout << stprev << " " <<  stprev + min(l, sz - stprev) << endl;
    if(ok) {
      //cout << k << endl;
      //cout << l  - k << endl;
      //k--;
      for(int m = k; m < l; m++) {
        s[0] += s[i][m];
      }
      stprev = 0;
      i++;
    }
    else {
      stprev++;
    }

  }
  cout << s[0];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (auto x : s) {
    cout << x;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main() {
	string s, t; cin >> s >> t;
	int n = s.size();
	map<char, char>m;
	map<char, char>m1;
	for (char c = 'a'; c <= 'z'; c++) {
		m[c] = '0';
		m1[c] = '0';
	}
	bool flag = 1;
	for (int i = 0; i < n; i++) {
		if (flag) {
			char c = s[i];
			if (m[c] == '0'&&m1[t[i]] == '0') {
				m[c] = t[i];
				m1[t[i]] = c;
			}
			else if (m[c] != t[i])flag = 0;
			else if (m1[t[i]] != c)flag = 0;
		}
	}
	cout << (flag ? "Yes\n" : "No\n");
}

Measured memory_bytes: 776
import java.util.*;
import java.awt.geom.*;

import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1167();
	}
	
	class AOJ1167{
		int[] a1,a2,dp1,dp2;
		AOJ1167(){
			initialize();
			while(sc.hasNext()){
				int n=sc.nextInt();
				if(n==0)	break;
				System.out.println(dp1[n]+" "+dp2[n]);
			}
		}
		void initialize(){
			final int MAX=1000000;
			a1=new int[200];
			a2=new int[50];
			for(int i=1,i2=1; true; ++i){
				int tmp=i*(i+1)*(i+2)/6;
				a1[i]=tmp;
				if(tmp%2==1)	a2[i2++]=tmp;
				if(tmp>MAX){
					a1[i+1]=MAX;
					a2[i2+1]=MAX;
					break;
				}
			}
			dp1=new int[MAX];
			dp2=new int[MAX];
			for(int i=1; i<MAX; ++i){
				dp1[i]=MAX;
				dp2[i]=MAX;
			}
			for(int i=1; a1[i]<MAX; ++i)for(int j=0; j<MAX; ++j)	dp1[j]=min(dp1[j], j<a1[i]? dp1[j]: dp1[j-a1[i]]+1);
			for(int i=1; a2[i]<MAX; ++i)for(int j=0; j<MAX; ++j)	dp2[j]=min(dp2[j], j<a2[i]? dp2[j]: dp2[j-a2[i]]+1);
		}
	}
}

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

int main() {
	while (1) {
		int m, f, r;
		cin >> m >> f >> r;

		if (m == -1 && f == -1 && r == -1)
			break;

		if (m == -1 || f == -1)
			cout << "F" << endl;
		else if (m + f >= 80)
			cout << "A" << endl;
		else if (m + f >= 65)
			cout << "B" << endl;
		else if (m + f >= 50)
			cout << "C" << endl;
		else if (m + f >= 30)
			if (r >= 50)
				cout << "C" << endl;
			else
				cout << "D" << endl;
		else
			cout << "F" << endl;
	}
}

Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cstdlib>


using namespace std;

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

int main(){
    long long N,K;
    cin>>N>>K;
    bool zero = false;
    long long a = N%K;
    long long b = a - K;
    b = -b;
    if(b>a)
        cout<<a<<endl;
    else
        cout<<b<<endl;
}  

Measured memory_bytes: 256
n = int(input())
a = [int(_) for _ in input().split()]

mode = 0
ans = 1
for i in range(0, n-1):
    if mode == 0:
        if a[i] < a[i+1]:
            mode = 1
        elif a[i] > a[i+1]:
            mode = 2
    elif mode == 1:
        if a[i] > a[i+1]:
            ans += 1
            mode = 0
    else:
        if a[i] < a[i+1]:
            ans += 1
            mode = 0

print(ans)

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

int gcd(int x, int y)
{
	if (y == 0) return x;
	return gcd(y, x % y);
}

signed main(void)
{
	P x, y;
	int a, b, ans;
	cin >> x.first >> x.second >> y.first >> y.second;
	ans = 0;
	a = abs(y.first - x.first);
	b = abs(y.second - x.second);
	if (x != y)
		ans = a + b - gcd(a, b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#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;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

char a[2111][2111];
int up[2111][2111];
int ri[2111][2111];

int UP(int x1,int y1,int x2,int y2)
{
	return (up[x2][y2]-up[x2][y1-1]-up[x1-1][y2]+up[x1-1][y1-1]);
}

int RI(int x1,int y1,int x2,int y2)
{
	return (ri[x2][y2]-ri[x2][y1-1]-ri[x1-1][y2]+ri[x1-1][y1-1]);
}

int dp[2011][2011];

int DP(int x1,int y1,int x2,int y2)
{
	return (dp[x2][y2]-dp[x2][y1-1]-dp[x1-1][y2]+dp[x1-1][y1-1]);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m,q;
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=='1') dp[i][j]=1;
		}
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='1'&&a[i+1][j]=='1')
			{
				up[i][j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(a[i][j]=='1'&&a[i][j+1]=='1')
			{
				ri[i][j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			up[i][j]+=up[i-1][j]+up[i][j-1]-up[i-1][j-1];
			dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
			ri[i][j]+=ri[i-1][j]+ri[i][j-1]-ri[i-1][j-1];
		}
	}
	for(int i=0;i<q;i++)
	{
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		int V = DP(x1,y1,x2,y2);
		int E = RI(x1,y1,x2,y2-1)+UP(x1,y1,x2-1,y2);
		cout<<V-E<<'\n';
	}
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H), debug_out(T...);
}

int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
#define debug(...) 3
    fastIO;
#endif
    ll n,a,b;
    cin>>n>>a>>b;
    if(a==0)cout<<0<<endl;
    else {
        ll x=n/(a+b);
        if(a+b>n) cout<<min(a,n)<<endl;
        else cout<<a*x+(n%(a+b)!=0?min(a,n-(a+b)*x):0)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
    
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
    
int main(void) {
    int n, i, x;
    char com[16];
    scanf("%d",&n);
    
    for(i=0;i<n;i++) {
        scanf("%s",com);
        if(!strcmp(com,"insert")) {
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool connect(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool isSame(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
    UnionFind uf = UnionFind(500000);
    int n, m;
    cin >> n >> m;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        uf.connect(t, i+200000);
    }
    for(int i=0; i<m; i++){
        int t1, t2;
        cin >> t1 >> t2;
        uf.connect(200000+t1-1, 200000+t2-1);
    }

    int res=0;
    for(int i=0; i<n; i++){
        if(uf.isSame(i+1, 200000+i)) res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,K;
    cin >> N >> K;
    lint A[N];
    rep(i,N) cin >> A[i];
    lint left=0,right=1e12;
    while(right-left>1){
        lint mid=(right+left)/2;
        lint cut=0;
        rep(i,N) cut+=((A[i]+mid-1)/mid)-1;
        if(cut>K) left=mid;
        else right=mid;
    }
    cout << right << endl;
}

Measured memory_bytes: 5160
#include <bits/stdc++.h>
#define maxn 1005
#define mod 1000000009
#define ll long long
using namespace std;

typedef pair<int, int> P;

int n;
vector<int> v[maxn * maxn];
int stp = 0;
bool used[maxn * maxn];
int dp[maxn * maxn];
int ans = 0;

void dfs(int now)
{
    //printf("now=%d\n", now);
    if (used[now])
    {
        printf("-1\n");
        exit(0);
    }
    if (dp[now])
        return;
    used[now] = 1;
    dp[now] = 1;
    for (int x : v[now])
    {
        dfs(x);
        dp[now] = max(dp[now], dp[x] + 1);
    }
    used[now] = 0;
    ans = max(ans, dp[now]);
    return;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        vector<P> b;
        for (int j = 0; j < n - 1; j++)
        {
            int now;
            scanf("%d", &now);
            now--;
            if (now > i)
                b.push_back(P(i, now));
            else
                b.push_back(P(now, i));
            //printf("tot=%d\n", b[j].first * n + b[j].second);
            if (j > 0)
                v[b[j - 1].first * n + b[j - 1].second].push_back(b[j].first * n + b[j].second);
        }
    }
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            v[0].push_back(i * n + j);
    dfs(0);
    printf("%d\n", ans - 1);
    return 0;
}

Measured memory_bytes: 46708
#include <stdio.h>
int main(){
	//jadi soalnya tu
	//selama hasilnya blm > dari k
	//jalanin program A
	//kalo udah baru tambahin
	int jalan, k;
	scanf("%d", &jalan);
	scanf("%d", &k);
	
	int dariSoal=1;
	
	for(int i=0; i<jalan; i++){
		if(dariSoal<k){
			dariSoal *= 2;
		} else {
			dariSoal += k;
		}
	}
	printf("%d\n", dariSoal);
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  long long sum = 0;
  int num_cases = pow(2, S.size()-1);
  string e = "";

  for(int i=0; i<num_cases; i++){
    e = S.at(0);
    for(int j=0; j<S.size()-1; j++){
      if (!(i>>j&1)){
        e += S.at(j+1);
      }else{
        sum += (long long) stoll(e);
        e = S.at(j+1);
      }
    }
    sum += (long long) stoll(e);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] dd = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)
				dd[i][j] = INF;
			dd[i][i] = 0;
		}
		int[] ii = new int[m];
		int[] jj = new int[m];
		int[] ww = new int[m];
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			int w = sc.nextInt();
			ii[h] = i;
			jj[h] = j;
			ww[h] = w;
			dd[i][j] = dd[j][i] = w;
		}
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					dd[i][j] = Math.min(dd[i][j], dd[i][k] + dd[k][j]);
		int ans = 0;
		for (int h = 0; h < m; h++)
			if (dd[ii[h]][jj[h]] < ww[h])
				ans++;
		println(ans);
	}
}


Measured memory_bytes: 40772
#include <bits/stdc++.h>
typedef int64_t int64;
using namespace std;

int main(){
    double sum=0.0;
    
    int N; cin >> N;
    for(int i=0; i<N; ++i){
        double x; string s; cin >> x >> s;
        if(s=="BTC"){ x *= 380000.0; }
        sum += x;
    }
    cout << sum << endl;
    
    return 0;
}

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

int main(){
	while(1){
		int n,q;
		cin>>n>>q;
		int a[200];
		for(int i=0;i<200;i++){
			a[i]=0;
		}
		int max=0;
		if(n==0&&q==0) break;
		for(int i=0;i<n;i++){
			int m;
			cin>>m;
			for(int j=0;j<m;j++){
				int x;
				cin>>x;
				a[x]++;
				if(max<x) max=x;
			}
		}
		int ans=0,mem=0;
		for(int i=1;i<=max;i++){
			if(a[i]>=q){
				if(mem<a[i]){
					 ans=i;
					 mem=a[i];
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}



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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}



int main()
{


char x;cin>>x;

if(x=='A')cout<<"T"<<"\n";
else if(x=='T')cout<<"A"<<"\n";
else if(x=='G')cout<<"C"<<"\n";
else cout<<"G"<<"\n";

return 0;

}


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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n; cin >> n; 
    int a[n];
    for(int &i : a) cin >> i;
    sort(a, a + n, greater<int>());

    int j = n - 1;
    for(int i = 1; i < n; i++) if(a[i] < 0) {j = i; break;}

    int ans = 0;
    for(int i = 0; i < j; i++) ans += a[i];
    for(int i = j; i < n; i++) ans -= a[i];

    cout << ans << '\n';
    for(int i = 1; i < j; i++) cout << a[j] << " " << a[i] << '\n', a[j] -= a[i];
    for(int i = j; i < n; i++) cout << a[0] << " " << a[i] << '\n', a[0] -= a[i];     
}

Measured memory_bytes: 4052
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n, k;
vector<int> d;
vector<vector<int>> p;
vector<pair<int, int>> pv;

void dfs(int now, int dep, int from) {
  d[now] = dep;
  for (auto &i : p[now]) {
    if (from != i)
      dfs(i, dep + 1, now);
  }
}

int main() {
  cin >> n >> k;
  d.resize(n);
  p.resize(n);
  pv.resize(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
    pv[i] = make_pair(a, b);
  }
  int ans = n;
  if (k % 2 == 0) {
    for (int i = 0; i < n; i++) {
      int ret = 0;
      dfs(i, 0, -1);
      for (auto &j : d) {
        if (j > k / 2)
          ret++;
      }
      ans = min(ans, ret);
    }
  } else {
    for (auto &pr : pv) {
      int ret = 0;
      dfs(pr.first, 0, pr.second);
      dfs(pr.second, 0, pr.first);
      for (auto &j : d) {
        if (j > k / 2)
          ret++;
      }
      ans = min(ans, ret);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512