akhauriyash/Code-Regression huggingface dataset:
/* Aditya0412 */
    #include <bits/stdc++.h>
    using namespace std; 
    #define int long long 
    #define pb push_back 
    #define vii vector < int > 
    #define pii pair < int , int >
    #define fi first
    #define all(a)      (a).begin(),(a).end()
    #define si(x)       (int)((x).size())
    #define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
    #define se second 
    #define endl        '\n'
    #define f(i,a,b)    for(int i=a;i<b;i++)
    #define mem(a,x)          memset(a,x,sizeof(a))
    #define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    const int  mod=998244353;
    // const int  mod = 1000000000+7;
    const int  N=200000+6;
    #define M_PI           3.14159265358979323846

    // int x2[]={+1,-1,+0,+0};
    // int y2[]={+0,+0,+1,-1};
    // int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
    // int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
    // int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
    // int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};

    // === Debug macro starts here ===

    int recur_depth = 0;
    #ifdef DEBUG
    #define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
    #else
    #define dbg(x)
    #endif
    template<typename Ostream, typename Cont>
    typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
        os<<"[";
        for(auto& x:v){os<<x<<", ";}
        return os<<"]";
    }
    template<typename Ostream, typename ...Ts>
    Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
        return os<<"{"<<p.first<<", "<<p.second<<"}";
    }

    // === Debug macro ends here ===

    main() 
    {
        fastIO;
        int n,x,m;
        cin>>n>>x>>m;
        bool vis[m+5];mem(vis,false);
        vector< int > v;int val;
        while(1)
        {
            if(vis[x])
            {
                val=x;break;
            }
            else
            {
                vis[x]=true;
                v.pb(x);
                x=x*x;
                x%=m;

            }
            
        }

        int nn=si(v);
        int ans=0;
        f(i,0,nn)
        {
            if(n>0)
            {
                ans+=v[i];
                n--;
            }
        }
        dbg(ans);
        int ind;
        if(n>0)
        {
            dbg(val);
            f(i,0,nn)
            {
                if(v[i]==val)
                {
                    ind=i;break;
                }
            }
            int sum=0;
            f(i,ind,nn)
            sum+=v[i];
            nn=(nn-1-ind+1);
            ans+=(sum*(n/nn));
            int left=n%nn;
            for(int i=ind;left>0;left--,i++)
            {
                ans+=v[i];
            }
            dbg(ans);
        }
        cout<<ans;


        
    } 

Measured memory_bytes: 3920
#include <stdio.h>

#define N 50

int main() {
	static char s[N][N + 1], t[N][N + 1];
	int n, m, i, j, k, l, yes;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (i = 0; i < m; i++)
		scanf("%s", t[i]);
	for (i = 0; i + m <= n; i++)
		for (j = 0; j + m <= n; j++) {
			yes = 1;
			for (k = 0; k < m; k++)
				for (l = 0; l < m; l++)
					if (s[i + k][j + l] != t[k][l]) {
						yes = 0;
						goto out;
					}
out:
			if (yes) {
				printf("Yes\n");
				return 0;
			}
		}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
using System;


namespace ConsoleApplication9
{
    class Program
    {
        static void Main()
        {
            int count = 0;
            string W = Console.ReadLine();
            string w = W.ToLower();
            while(true)
            {
                string T = Console.ReadLine();
                if (T == "END_OF_TEXT")
                    break;
                else
                {
                    string T2 = T.ToLower();
                    string[] t = T2.Split(' ');
                    for (int i = 0; i < t.Length; i++)
                    {
                        if (t[i] == w)
                            count += 1;
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
  double n,m,d;
  cin >> n >> m >> d;
  double x = (n-d)*2.0/pow(n,2);
  if(d == 0){
    x /= 2;
  }
  cout << setprecision(15) << x*(m-1) << endl;
}

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

using namespace std;
using ll = long long;

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  map<ll, ll> ma;
  for(int i=0; i<n; i++){
    ll a; cin >> a;
    ma[a]++;
  }
  
  ll sum = 0;
  for(auto it:ma){
   ll num = it.first;
   if(num<=it.second){
     sum += it.second-num;
   }else{
     sum += it.second;
   }
  
  }
  
  cout << sum << endl;
  

  return 0;
}

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

#define pb push_back
#define ff first
#define ss second

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

int a, b;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> a >> b;
	if (b % a == 0)
		cout << a + b;
	else
		cout << b - a;
	return 0;
}


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

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

    ll ans = 0;
    for (ll k = 0; k < 30; k++) {
        ll cnt = 0;
        ll t = 1ll << k;

        vector<ll> tmpa(n), tmpb(n);
        rep(i, n) {
            tmpa[i] = a[i] % (2 * t);
            tmpb[i] = b[i] % (2 * t);
        }
        sort(tmpb.begin(), tmpb.end());
        rep(i, n) {
            ll lb = t - tmpa[i], rb = 2 * t - tmpa[i];
            cnt += lower_bound(tmpb.begin(), tmpb.end(), rb) - lower_bound(tmpb.begin(), tmpb.end(), lb);
            lb = 3 * t - tmpa[i], rb = 4 * t - tmpa[i];
            cnt += lower_bound(tmpb.begin(), tmpb.end(), rb) - lower_bound(tmpb.begin(), tmpb.end(), lb);
        }
        if (cnt & 1) ans += t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9548
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=1e5+5;
int n,buk[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	n=nxi();
	int ans=0;
	for(int i=1; i<=n; ++i){
		int v=nxi();
		if(v>n) ++ans;
		else ++buk[v];
	}
	for(int i=1; i<=n; ++i){
		ans+=buk[i]>=i?buk[i]-i:buk[i];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main() {
	char N[10];
    int i=0,sum=0,n;
    scanf("%s",&N);
    while(N[i]!=NULL){
        sum+=N[i]%48;
        i++;
    }
    n=atoi(N);
    if(n%sum==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
	return 0;
}

Measured memory_bytes: 128
N,M = map(int,input().split( ))
loads = []
teams = [[i] for i in range(N)]
syozoku = {i:i for i in range(N)}
for _ in range(M):
    A,B = map(int,input().split( ))
    if syozoku[A-1] != syozoku[B-1]:
        hairu,nukeru = min(syozoku[A-1],syozoku[B-1]),max(syozoku[A-1],syozoku[B-1])
        team = teams[nukeru]
        teams[nukeru] = []
        teams[hairu] += team
        for i in team:
            syozoku[i] = hairu

ans = -1
for team in teams:
    if len(team) != 0:
        ans += 1
print(ans)

Measured memory_bytes: 31336
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl;

int main ()
{
 string s;
 cin >> s;
 map < char, int > mp;
 int i, cnt = 0;
 for(i = 0; i < 4; i++)
 {
   mp[s[i]]++;
   if(mp[s[i]] == 2) cnt++;
   if(cnt == 2)
   {
     cout << "Yes" << endl;
     exit(0);
   }
 }
 cout << "No" << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define mod 1000000007
typedef long long ll;
using namespace std;

const int MAX = 100005;
int main(){
  int n; cin >> n;
  pair<int,int> X[MAX];
  for(int i=0;i<n;i++){
    int x,l; cin >> x >> l;
    X[i].second = x-l;
    X[i].first = x+l;
  }
  int mx;
  int ans = n;
  sort(X,X+n);
  mx = X[0].first;

  for(int i=1;i<n;i++){
    if(X[i].second < mx){
      ans--;
    }
    else{
      mx = X[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
 long long int N,A[5];
  cin>>N>>A[0]>>A[1]>>A[2]>>A[3]>>A[4];
  long long int step=0;
  long long int Ncity[6]={0};
  long long int mincap=10000000000000000;
  int mincapindex=0;
  for(int i=0; i<5; i++){
    if(A[i]<mincap) mincap=A[i];
  }
  
  int distance=0;
  step+=4;
  step+=N/mincap;
  if(N%mincap!=0) step+=1;
    
  cout<<step;
  return 0;
}

Measured memory_bytes: 256
/*
[abc133] F - Colorful Tree
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_Q = 1e5;

const int MAX_V = MAX_N;
const int MAX_LOG_V = 18;

struct edge {
    int d;
    int c;
    int to;
};

int N, Q;
vector<edge> g[MAX_N];
vector<int> req[MAX_N];
int X[MAX_Q], Y[MAX_Q], U[MAX_Q], V[MAX_Q];
int W[MAX_Q];
int dist[MAX_N];
int cur_num[MAX_N], cur_sum[MAX_N];
map<int, int> num[MAX_N], sum[MAX_N];

int par[MAX_LOG_V][MAX_V];
int dep[MAX_V];

void dfs(int v, int p = -1, int d = 0) {
    par[0][v] = p;
    dep[v] = d;
    for (auto& e : g[v]) {
        if (e.to == p) {
            continue;
        }
        dfs(e.to, v, d + 1);
    }
}

int lca(int u, int v) {
    if (dep[u] > dep[v]) {
        swap(u, v);
    }
    for (int k = 0; k < MAX_LOG_V; k++) {
        if (((dep[v] - dep[u]) >> k) & 1) {
            v = par[k][v];
        }
    }
    if (u == v) {
        return u;
    }
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
        if (par[k][u] != par[k][v]) {
            u = par[k][u];
            v = par[k][v];
        }
    }
    return par[0][u];
}

void init() {
    dfs(0);
    for (int k = 1; k < MAX_LOG_V; k++) {
        for (int v = 0; v < N; v++) {
            par[k][v] = (par[k - 1][v] < 0) ? -1 : par[k - 1][par[k - 1][v]];
        }
    }
}

void dfs2(int v, int par = -1) {
    for (int c : req[v]) {
        num[v][c] = cur_num[c];
        sum[v][c] = cur_sum[c];
    }

    for (auto& e : g[v]) {
        if (e.to == par) {
            continue;
        }
        dist[e.to] = dist[v] + e.d;
        cur_num[e.c]++;
        cur_sum[e.c] += e.d;
        dfs2(e.to, v);
        cur_num[e.c]--;
        cur_sum[e.c] -= e.d;
    }
}

int calc(int v, int x, int y) { return dist[v] - sum[v][x] + y * num[v][x]; }

void solve() {
    init();
    for (int i = 0; i < Q; i++) {
        W[i] = lca(U[i], V[i]);
        req[U[i]].push_back(X[i]);
        req[V[i]].push_back(X[i]);
        req[W[i]].push_back(X[i]);
    }

    dfs2(0);

    for (int i = 0; i < Q; i++) {
        int ans = calc(U[i], X[i], Y[i]) + calc(V[i], X[i], Y[i]) -
                  2 * calc(W[i], X[i], Y[i]);
        cout << ans << endl;
    }
}

int main() {
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--;
        g[a].push_back((edge){d, c, b});
        g[b].push_back((edge){d, c, a});
    }
    for (int i = 0; i < Q; i++) {
        cin >> X[i] >> Y[i] >> U[i] >> V[i];
        X[i]--, U[i]--, V[i]--;
    }

    solve();

    return 0;
}


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

int main(){
  int n,m,p;
  int x[100];

  while(cin >> n >> m >>p, n||m||p){
    int sum = 0;
    for(int i=0;i<n;i++){
      cin >> x[i];
      x[i];
      sum += x[i];
    }

    sum *= 100*(100-p);
    sum /= 100;

    if(!x[m-1])cout << 0 << endl;
    else cout << sum/x[m-1] << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 100;
const int MOD = 1000000007;

void doc() {
    freopen("OB.inp","r",stdin);
    freopen("OB.out","w",stdout);
}

int n, cha[maxN];
vector<int> a[maxN];
int root = 0, k = 0;

void Preorder(int u){
    cout << " " << u;
    for(int v : a[u]){
        if (v == -1) continue;
            Preorder(v);
    }
}

void Inorder(int u){
    if (a[u][0] != -1)
        Inorder(a[u][0]);
    cout << " " << u;
    if (a[u][1] != -1)
        Inorder(a[u][1]);
}

void Postorder(int u){
    if (a[u][0] != -1)
        Postorder(a[u][0]);
    if (a[u][1] != -1)
        Postorder(a[u][1]);
    cout << " " << u;
}

void solve() {
    cin >> n;
    memset(cha, -1, sizeof(cha));
    for(int i = 0; i < n; i++){
        int x, left, right;
        cin >> x >> left >> right;
        a[x].push_back(left);
        a[x].push_back(right);
        if (left != -1){

            cha[left] = x;
        }
        if (right != -1){

            cha[right] = x;
        }
    }

    while (cha[root] != -1) root++;

    cout << "Preorder" << '\n';
    Preorder(root);
    cout << '\n';
    cout << "Inorder" << '\n';
    Inorder(root);
    cout << '\n';
    cout << "Postorder" << '\n';
    Postorder(root);
    cout << '\n';

}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
   
    solve();
}



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

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

	cout << ceil(1.0*(N - 1) / (K - 1)) << endl;
}


Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        xy: [(f64, f64); n],
    }
    let mut tot = 0.0;
    for i in 0..n {
        for j in 0..i {
            let dx = xy[i].0 - xy[j].0;
            let dy = xy[i].1 - xy[j].1;
            let d = (dx * dx + dy * dy).sqrt();
            tot += d;
        }
    }
    puts!("{}\n", tot * 2.0 / n as f64);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i,k) ans += p[i];
  cout << ans << endl;
  return 0;
}

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

int func( int num ){ //順列を計算する関数
  if( num == 0 ) return 1;
  return num * func(num-1);
}

int main() {
  int n;
  cin >> n;
  vector<int> p(n),q(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  for(int i=0;i<n;i++){
    cin >> q.at(i);
  }

  int pnum=1,qnum=1;
  for(int i=1;i<=n;i++){
    int cnt=0;
    for(int j=1;j<i;j++){
      if( i == 1 ) break;
      if( p.at(j-1) < p.at(i-1) ){
        cnt++;
      }
    }
    pnum += ( ( p.at(i-1)-cnt ) * func(n-i) );
    
  }
  
  for(int i=1;i<=n;i++){
    int cnt=0;
    for(int j=1;j<i;j++){
      if( i == 1 ) break;
      if( q.at(j-1) < q.at(i-1) ){
        cnt++;
      }
    }
    qnum += ( ( q.at(i-1)-cnt ) * func(n-i) );
    
  }
  cout << abs( pnum - qnum ) << endl;

  return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<long> A(N), a, b;
	for (long& i : A) cin >> i;
	sort(A.begin(), A.end());
	vector<long> c(A.begin(), next(A.begin(), (A.size() + 1) / 2));
	if (1 < c.size()) swap(c.front(), c[c.size() - 2]);
	vector<long> d(next(A.begin(), (A.size() + 1) / 2), A.end());
	for (int i = 0; i < N; i++) {
		if (i % 2) {
			a.push_back(d.back());
			d.pop_back();

		}
		else {
			a.push_back(c.back());
			c.pop_back();
		}
	}
	long e = 0, f = 0;
	for (int i = 1; i < N; i++) e += abs(a[i - 1] - a[i]);
	vector<long> g(A.begin(), next(A.begin(), A.size() / 2));
	vector<long> h(next(A.begin(), A.size() / 2), A.end());
	if (1 < h.size()) swap(h[1], h.back());
	for (int i = 0; i < N; i++) {
		if (i % 2) {
			b.push_back(g.back());
			g.pop_back();
		}
		else {
			b.push_back(h.back());
			h.pop_back();
		}
	}
	for (int i = 1; i < N; i++) f += abs(b[i - 1] - b[i]);
	cout << max(e, f);
}

Measured memory_bytes: 4852
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
	int n;
	int set[52] = {};
	cin >> n;
	for (int i = 0; i < n; i++){
		char suit;
		int rank;
		cin >> suit >> rank;
		int suit2Num;
		switch (suit) {
			case 'S':
				suit2Num = 0;
				break;
			case 'H':
				suit2Num = 1;
				break;
			case 'C':
				suit2Num = 2;
				break;
			case 'D':
				suit2Num = 3;
				break;
			default:
				break;
		}
		set[13 * suit2Num + (rank - 1)] = 1;
	}
	char num2Suit[4] = {'S', 'H', 'C', 'D'};
	for (int i = 0; i < 52; i++){
		if (!set[i]){
			char suitAns = num2Suit[i / 13];
			int rankAns = i % 13 + 1;
			cout << suitAns << " " << rankAns << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3096
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int e = sc.nextInt();

    if(a == 0){
        System.out.println(1);
    }else if(b == 0){
        System.out.println(2);
    }else if(c == 0){
        System.out.println(3);
    }else if(d == 0){
        System.out.println(4);
    }else{
        System.out.println(5);
    }

    


    
    


    


    
    


    
	}
}

Measured memory_bytes: 35672
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int n, k;
    cin >> n >> k;
    int r = n % k;
    int ans = 0;
    while (n > 0){
        n -= n % k;
        n /= k;
        ++ans;
    }
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3616
fn solve() {
    loop {
        let n: usize = read();
        if n == 0 {
            break;
        }
        let a: Vec<i64> = (0..n).map(|_| read::<i64>()).collect();
        let mut s = a[0];
        let mut ans = s;
        for i in 1..n {
            s = max(s + a[i], a[i]);
            ans = max(ans, s);
        }
        println!("{}", ans);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::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")
}

// =========



Measured memory_bytes: 9072
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<ll, ll> P;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa; cin>>nyaa;
ll gcd(ll x, ll y) {
	return y ? gcd(y, x%y) : x;
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	if ((double)x / g * y > 2e18)return -1;
	return x / g * y;
}

pair<ll, ll> marge(pair<ll, ll> x, pair<ll, ll> y) {
	ll l = lcm(x.first, y.first);
	if (l == -1)return { -1,-1 };
	rep(i, x.first) {
		if ((y.first*i + y.second) % x.first == x.second%x.first) {
			return { l,y.first*i + y.second };
		}
	}
	return { -1,-1 };

}

void solve() {
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	rep(i, n)cin >> p[i];
	rep(i, n)--p[i];
	rep(i, n)cin >> q[i];
	rep(i, n)--q[i];
	vector<vector<int>> ans(n);
	rep(c, 3 * n) {
		vector<int> np(n);
		rep(i, n)np[i] = q[p[i]];
		rep(i, n)if (np[i] == i)ans[i].push_back(c+1);
		np.swap(p);
	}
	pair<ll, ll> res = { 1,0 };
	rep(i, n) {
		if (ans[i].size() < 2) {
			cout << -1 << endl;
			return ;
		}
		res = marge({ ans[i][1] - ans[i][0],ans[i][0] }, res);
		if (res.first == -1) {

			cout << -1 << endl;
			return ;
		}
	}
	if (res.second > 1e18) {
		cout << -1 << endl;
	}
	else cout << res.second%res.first << endl;

}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//find_prime();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 3508
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  vector<vector<pair<int, int>>> A(N);
  REP(i, N){
    int a;
    cin >> a;
    A[i].resize(a);
    REP(j, a){
      cin >> A[i][j].first >> A[i][j].second;
      A[i][j].first--;
    }
  }

  int ans = 0;
  REP(bit, (1<<N)){
    int ret = 0;
    bool flag = true;
    REP(i, N){
      if((bit >> i)&1){
        REP(j, A[i].size()){
          if(((bit >> A[i][j].first)&1) != A[i][j].second) flag = false;
        }
        ret++;
      }
    }

    if(flag) chmax(ans, ret);
  }

  cout << ans << "\n";

  return 0;
}

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

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;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    map<int, int> mp;
    for (int i = 0; i < k; i++)
    {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            int temp;
            cin >> temp;
            temp--;
            mp[temp]++;
        }
    }
    int ctr = 0;
    for (int i = 0; i < n; i++)
    {   
        if (mp[i] == 0)
            ctr++;
    }
    cout << ctr << endl;
    return 0;
}

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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 1005;

int n, m, k;
char board[15][N];

int main() {
    scanf("%d %d %d", &n, &m, &k);
    
    for (int i = 0; i < n; i++) {
        scanf("%s", &board[i][1]);
        for (int j = 1; j <= m; j++) {
            board[i][j] -= '0';
        }
    }
    
    int ans = 1e9;
    for (int mask = 0; mask < (1 << (n - 1)); mask++) {
        vector<int> cuts;
        for (int j = 0; j < n - 1; j++) {
            if ((1 << j) & mask) {
                cuts.push_back(j);
            }
        }
        cuts.push_back(n - 1);
        vector<int> sums(cuts.size(), 0);
        bool good = true;
        int cutNo = 0;
        for (int i = 1; i <= m; i++) {
            
            bool needCut = false;
            int last = 0;
            for (int j = 0; j < cuts.size(); j++) {
                int s = 0;
                for (int k = last; k <= cuts[j]; k++) {
                    s += board[k][i];
                } 
                if (s > k) {
                    good = false;
                }
                if (s + sums[j] > k) {
                    needCut = true;
                }
                last = cuts[j] + 1;
            }
            
            if (needCut) {
                cutNo++;
                for (int j = 0; j < cuts.size(); j++) {
                    sums[j] = 0;
                }
            }
            last = 0;
            for (int j = 0; j < cuts.size(); j++) {
                int s = 0;
                for (int k = last; k <= cuts[j]; k++) {
                    s += board[k][i];
                } 
                sums[j] += s;
                last = cuts[j] + 1;
            }
        }
        if (good == false) {
            continue;
        } else {
            ans = min(ans, (int)cuts.size() - 1 + cutNo);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
for k in range(n - 1):
    if a[k] >= a[k + 1]:
        break
else:
    print('YES')
    exit(0)
for i in range(n):
    for j in range(i + 1, n):
        tmp = a.copy()
        tmp[i], tmp[j] = tmp[j], tmp[i]
        for k in range(n - 1):
            if tmp[k] >= tmp[k + 1]:
                break
        else:
            print('YES')
            exit(0)
print('NO')

Measured memory_bytes: 3064
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(i=a;i<b;i++)
    #define rfo(i,b,a) for(i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 1e5 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    int dp[110][MAX];
    int wt;
    int v[MAX],w[MAX];
    void solve()
    {
        cin>>n>>wt;
        fo(i,1,n+1)
        {
            cin>>w[i]>>v[i];
        }
        
        fo(i,1,n+1)
        {
            fo(j,1,wt+1)
            {
                if(j>=w[i])
                dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
                else
                dp[i][j]=dp[i-1][j];
            }
        }
        cout<<dp[n][wt]<<endl;
    	
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //

    int32_t main() 
      {
      	
      	// int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
      	ios_base::sync_with_stdio(0);
      	cin.tie(NULL);
      	
      	// cin>>t;while(t--)
      	solve();
      	
    	return 0;
      }

Measured memory_bytes: 80128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;



int main(){
	int n;
	string s;
	cin >> n >> s;
	int ans = 0, sum = 0;
	FORI(0, n) {
		if (s[i] == 'I') {
			sum++;
		}
		else {
			sum--;
		}
		ans = max(sum, ans);
	}
	cout << ans << endl;

	return 0;
}


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

int main()
{
    int size, num, limit, start = 1, num_breack_bricks = 0;
    bool find_one = false;
    cin>> size;
    limit = size - 1;
    for (int i=1; i <= size; i++)
    {
        cin >> num;
        if(num!= start){
            num_breack_bricks++;
        }
        else if(num==start){
            find_one = true;
            start++;
        }
    }
    if(limit < num_breack_bricks || find_one==false)
        cout<< -1 << endl;
    else
        cout << num_breack_bricks << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            int n = Integer.parseInt(br.readLine());
            int[] T = new int[n];
            String st = br.readLine();
            String[] s = st.split(" ",0);
            int sum = 0;
            for(int i = 0; i<n;i++){
                T[i]=Integer.parseInt(s[i]);
                sum +=T[i];
            }
            int m = Integer.parseInt(br.readLine());
            for(int i = 0;i<m;i++){
                int sumi = sum;
                st = br.readLine();
                s = st.split(" ",0);
                int j  = Integer.parseInt(s[0]);
                int jm = Integer.parseInt(s[1]);
                sumi = sumi - T[j-1] + jm;
                System.out.println(sumi);
            }
            
        }catch(Exception ex){
            System.exit(0);
        }
    }
}

Measured memory_bytes: 8652
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <cmath>
#include <math.h>

typedef long long ll;
using namespace std;

int main(void){
    int N, M;
    cin >> N >> M;
    int A[M];
    int sum =0;
    for(int i = 0; i < M; i++) {
        cin >> A[i];
        sum += A[i];
    }
    if(sum<N) cout << N-sum << endl;
    else if(sum==N) cout << 0 << endl;
    else cout << -1 << endl;
}



Measured memory_bytes: 3632
#include "bits/stdc++.h"
 
using namespace std;
 
// template<typename... T>
// void read(T&... args) {
//     ((cin >> args), ...);
// }
 
// template<typename... T>
// void write(T&&... args) {  
//     ((cout << args << " "), ...);
// }
 
// #define deb(x) cerr << #x << " " << x <<endl;
 
// #define debs(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << '\n'
// void err(istringstream *iss) {}
// template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) {
//     string _name;
//     *iss >> _name;
//     if (_name.back()==',') _name.pop_back();
//     cerr << _name << " = " << _val << "; ", err(iss, args ...);
// }


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

	int n,k;
	while(cin>>n>>k){
		vector<int>lst(n);	
		for(int i=0; i<n; cin>>lst[i++]);
		vector<long long>dp(n+2,LONG_MAX);
		dp[0]=0;

		for(int i=1; i<n; ++i)
			for(int j=1; j<=k; ++j)
				if(i-j>=0)
					dp[i]=min(dp[i-j]+abs(lst[i]-lst[i-j]), dp[i]);

		// for(auto x: dp)
		//     cout<<x<<" ";
		// // cout<<endl;		
		
		cout<<dp[n-1]<<endl; 
	}
	
    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=30000010;
int n,a[2][3];
ll f[N];

ll solve(int x,int y,int n){
	rep(i,0,n) f[i]=i;
	rep(i,0,2) rep(j,a[x][i],n) f[j]=max(f[j],f[j-a[x][i]]+a[y][i]);
	return f[n];
}

int main(){
	scanf("%d",&n);
	rep(i,0,1) rep(j,0,2) scanf("%d",&a[i][j]);
	printf("%lld\n",solve(1,0,solve(0,1,n)));
	return 0;
}

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

int main(){
	int n,ans=200000,i,j,tmp=0;
	char s[101],ss[101];
	scanf("%s",s);
	for(j=0;j<26;j++){
		strcpy(ss,s);
		while(1){
			int f=0;char t='a'+j;
			for(i=0;ss[i]!=0;i++){
				if(t!=ss[i])f=1;
			}
			if(f==0)break;
			for(i=1;ss[i]!=0;i++){
				if(ss[i]=='a'+j)ss[i-1]=ss[i];
			}ss[i-1]=0;
			tmp++;
		}
		if(tmp<ans)ans=tmp;
		tmp=0;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    k = ni()
    print((k // 2) ** 2 if k % 2 == 0 else (k // 2) * (k // 2 + 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val numbers = sc.nextLine.split(" ").map(_.toInt)
    val majority = numbers.sorted.toList(1)
    println(numbers.filterNot(n => n == majority)(0))
  }
}


Measured memory_bytes: 25544
N, L = map(int, input().split())
a = [int(i) for i in input().split()]

for i in range(N - 1) :
    if a[i] + a[i+1] >= L :
        print('Possible')
        for j in range(i) :
            print(j + 1)
        for j in range(N - 2, i, -1) :
            print(j + 1)
        print(i + 1)
        break
else :
    print('Impossible')

Measured memory_bytes: 63984
#include<stdio.h>
main(){
	int a,b,c,d,i,count;
	while(scanf("%d %d",&a,&b)!=EOF){
		count=1;
		d=a+b;
		if(d>=10){
			while(1){
				d/=10;
				count++;
				if(d<10)
					break;
			}
		}
	printf("%d\n",count);
	}
	return 0;			
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int n = 5e5 + 5;
const ll INF = 1.5e18;

int H, W, A, B;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> H >> W >> A >> B;

	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			if((i < B) == (j < A))
				cout << "1";
			else
				cout << "0";
		}
		cout << "\n";
	}

	return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
int main(){
    int i, j, n, a[1000], v;
    scanf("%d", &n);
    for(i=0; i<n; i++)scanf("%d", &a[i]);
    for(i=1; i<n; i++){
        for(j=0; j<n-1; j++)printf("%d ", a[j]);
        printf("%d\n", a[n-1]);
        v=a[i];
        j=i-1;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
    }
    for(i=0; i<n-1; i++)printf("%d ", a[i]);
    printf("%d\n", a[n-1]);
    return 0;
}

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

int main() {
  int N, l, r, a;
  a = 0;
  cin >> N;
  for (int i = 0; i < N ; i++) {
    cin >> l >> r;
    a = a + r - l + 1;
  }
  cout << a << endl;
}

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

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

  if ((N / 1000) - ((N % 1000) / 100) - (((N % 1000) % 100) / 10) == -(N / 1000) ||
   ((N % 1000) / 100) - (((N % 1000) % 100) / 10) - (((N % 1000) % 100) % 10) == -((N % 1000) / 100))
  {
  	cout << "Yes" << endl;
  }
  else
  {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import bisect
from collections import deque
N = int(input())
nums = deque()

for i in range(N):
    temp =  int(input())
    ind = bisect.bisect_left(nums, temp)
    if ind == 0:
        nums.appendleft(temp)
    else:
        nums[ind - 1] = temp
print(len(nums))

Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, W;
    cin >> H >> W;
    VS w(H), h(W);
    rep(i, 0, H){
        cin >> w[i];
        rep(j, 0, W) h[j].push_back(w[i][j]);
    }
    string sh, sw;
    rep(i, 0, H) sh.push_back('.');
    rep(i, 0, W) sw.push_back('.');
    vector<bool> vh(H, true), vw(W, true);
    rep(i, 0, H){
        if(w[i] == sw) vh[i] = false;
    }
    rep(i, 0, W){
        if(h[i] == sh) vw[i] = false;
    }
    rep(i, 0, H){
        rep(j, 0, W){
            if(vh[i] && vw[j]) cout << w[i][j];
        }
        if(vh[i]) cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#ABC168

n = int(input())

if n % 10 == 0:
    print('pon')
elif n % 10 == 1:
    print('pon')
elif n % 10 == 2:
    print('hon')
elif n % 10 == 3:
    print('bon')
elif n % 10 == 4:
    print('hon')
elif n % 10 == 5:
    print('hon')
elif n % 10 == 6:
    print('pon')
elif n % 10 == 7:
    print('hon')
elif n % 10 == 8:
    print('pon')
elif n % 10 == 9:
    print('hon')


Measured memory_bytes: 9136
/*input
3
1 2 1
2 3 1
*/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <iomanip>
#include <utility>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;
vector < pair < int, ll > > v[N];
int color[N];

void dfs(int s, int col, int p)
{
  color[s] = col;
  for(auto x: v[s]) {
    if(x.first == p) continue;
    int d1 = x.second;
    if(d1 % 2 == 0) {
      dfs(x.first, col, s);
    }
    else {
      dfs(x.first, (col + 1) % 2, s);
    }
  }
}

int main()
{
  ifalse;
  int n;
  cin >> n;
  memset(color, -1, sizeof(color));
  for(int i = 1; i < n; i ++) {
    int x, y;
    ll w;
    cin >> x >> y >> w;
    v[x].push_back({y, w});
    v[y].push_back({x, w});
    // if(w % 2 == 0) {
    //   if(color[x] == -1 and color[y] == -1) {
    //     color[x] = color[y] = 0;
    //   } 
    //   else if(color[x] == -1) {
    //     color[x] = color[y];
    //   }
    //   else {
    //     color[y] = color[x];
    //   }
    // }
    // else {
    //   if(color[x] == -1 and color[y] == -1) {
    //     color[x] = 0;
    //     color[y] = 1;
    //   } 
    //   else if(color[x] == -1) {
    //     color[x] = !color[y];
    //   }
    //   else {
    //     color[y] = !color[x];
    //   } 
    // }
  }
  dfs(1, 0, 0);
  for(int i = 1; i <= n; i ++) {
    cout << color[i], nl;
  }
  return 0;
}

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

using namespace std;

struct numAndCnt {
  int num;
  int cnt;
};

int main()
{
  /* Input */
  int n;
  cin >> n;

  vector<int> evenSeries;  //偶数部
  vector<int> oddSeries; //奇数部

  for (int id = 0; id < n; id++) {
    int val;
    cin >> val;

    if (id % 2 == 0) {
      evenSeries.push_back(val);
    }
    else {
      oddSeries.push_back(val);
    }
  }

  sort(evenSeries.begin(), evenSeries.end());
  sort(oddSeries.begin(), oddSeries.end());

  /* Create List of num and count. */
  vector<numAndCnt> evenMax;
  numAndCnt tempEvenIns;
  int evenIdCnt = 1;
  tempEvenIns.cnt = evenIdCnt;
  for (int id = 0; id < evenSeries.size() - 1; id++) {
    tempEvenIns.num = evenSeries[id];
    if (evenSeries[id] < evenSeries[id + 1]) {
      tempEvenIns.cnt = evenIdCnt;
      evenMax.push_back(tempEvenIns);
      evenIdCnt = 1;
    }
    else
      evenIdCnt++;
  }
  tempEvenIns.cnt = evenIdCnt;
  tempEvenIns.num = evenSeries[evenSeries.size() - 1];
  evenMax.push_back(tempEvenIns);

  vector<numAndCnt> oddMax;
  numAndCnt tempOddIns;
  int oddIdCnt = 1;
  tempOddIns.cnt = oddIdCnt;
  for (int id = 0; id < oddSeries.size() - 1; id++) {
    tempOddIns.num = oddSeries[id];
    if (oddSeries[id] < oddSeries[id + 1]) {
      tempOddIns.cnt = oddIdCnt;
      oddMax.push_back(tempOddIns);
      oddIdCnt = 1;
    }
    else
      oddIdCnt++;
  }
  tempOddIns.cnt = oddIdCnt;
  tempOddIns.num = oddSeries[oddSeries.size() - 1];
  oddMax.push_back(tempOddIns);

  /* Sort numAndCnt's instance using value of count. */
  sort(evenMax.begin(), evenMax.end(), [](const numAndCnt &c, const numAndCnt &d) {return c.cnt > d.cnt; });
  sort(oddMax.begin(), oddMax.end(), [](const numAndCnt &c, const numAndCnt &d) {return c.cnt > d.cnt; });

  if (evenMax[0].num == oddMax[0].num) {
    if (evenMax.size() == 1 && oddMax.size() == 1) {
      cout << n / 2 << endl;
    }
    else if (evenMax.size() == 1 && oddMax.size() > 1) {
      cout << n / 2 - oddMax[1].cnt << endl;
    }
    else if (evenMax.size() > 1 && oddMax.size() == 1) {
      cout << n / 2 - evenMax[1].cnt << endl;
    }
    else {
      if (evenMax[1].cnt > oddMax[1].cnt) {
        cout << n - (evenMax[1].cnt + oddMax[0].cnt) << endl;
      }
      else {
        cout << n - (evenMax[0].cnt + oddMax[1].cnt) << endl;
      }
    }
  }
  else {
    cout << n - (evenMax[0].cnt + oddMax[0].cnt) << endl;
  }

  return 0;
}


Measured memory_bytes: 1784