akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

string s;

int main()
{
    cin >> s;
    s.insert(s.begin() + 4, ' ');
    cout << s << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
vector<ll>sum;
//[l,r)
ll f(int l,int r){
    return sum[r]-sum[l];
}
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n){
        cin >> a[i];
    }
    sum.resize(n+1,0);
    rep(i,n){
        sum[i+1] = sum[i] + a[i];
    }
    ll ans = 1e18;
    int pos1,pos2;
    pos1 = 0;
    pos2 = 3;
    for(int i = 1; i < n-1; i++){
        ll s1 = f(0,i);
        ll s2 = f(i,n);
        while(pos1+1 < i and abs(s1-2*f(0,pos1)) > abs(s1-2*f(0,pos1+1)))pos1++;
        while(pos2+1 < n and abs(s2-f(i,pos2)*2) > abs(s2-f(i,pos2+1)*2))pos2++;
        ll p = f(0,pos1);
        ll q = s1-f(0,pos1);
        ll r = f(i,pos2);
        ll s = s2-f(i,pos2);
        ans = min(ans, max({p,q,r,s})-min({p,q,r,s}));
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

typedef long long ll;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループのノード数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};

int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> p(N);
    for(int i=0; i<N; i++){
        cin >> p[i];
        p[i]--;
    }
    UnionFind Uni(N);
    for(int i=0; i<M; i++){
        int x,y;
        cin >> x >> y;
        x--; y--;
        Uni.connect(x, y);
    }
    vector<bool> ans(N, 0);
    for(int i=0; i<N; i++){
        if(Uni.root(p[i])==Uni.root(i)){
            ans[p[i]]=1;
        }
    }
    int out=0;
    for(int i=0; i<N; i++){
        if(ans[i]) out++;
    }
    cout << out << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
	int X; cin >> X;
	int sum = 0;
	int res = 0;
	for (int i = 0; sum < X; i++) {
		sum += i;
		res = i;
	}
	cout << res << endl;
	//system("pause");
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,m;
//l ans;
ll op;
ll dset[100005];
ll le;
map <ll,ll> mp;
ll find(ll a){
	if(dset[a]<0)return a;
	return dset[a] = find(dset[a]);
}
ll dunion(ll a,ll b){
	ll x = find(a);
	ll y = find(b);
	
	if(x==y)return 0;
	if(dset[x]<dset[y]){
		op-=(-dset[y])*(n+dset[y]);
		op-=(-dset[x])*(n+dset[x]);
		dset[x]+=dset[y];
		dset[y] = x;
		le-=1;
		op+=(-dset[x])*(n+dset[x]);
		mp.erase(y);
		
		le-=1;
	}else{
		op-=(-dset[y])*(n+dset[y]);
		op-=(-dset[x])*(n+dset[x]);
		dset[y]+=dset[x];
		dset[x] = y;
		op+=(-dset[y])*(n+dset[y]);
		mp.erase(x);
		le-=1;
	}
}

vector < pair <ll,ll> > bri;
int main(){
	cin>>n>>m;
	//ans = n*n;
	le = n;
	op = n*(n-1);
	memset(dset,-1,sizeof(dset));
	for(ll i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		
		//vec[x].push_back(y);vec[y].push_back(x);
		bri.push_back({x,y});
	}
	vector <ll> ans;
	map <ll,ll> ::iterator itr;
	for(ll i=1;i<=n;i++)
	mp[i]=1;
	for(ll i=m-1;i>=0;i--){
		ll a,b;
		a = bri[i].first;b = bri[i].second;
		//ans.push_back((le*(le-1))/2);
		ll gh = 0;
		gh =op;
		
		/*
		for(itr=mp.begin();itr!=mp.end();itr++){
			ll x = itr->first;
			gh+=(-dset[x])*(n+dset[x]);
		}*/
		/*
		for(ll k=1;k<=n;k++){
			//cout<<dset[k]<<" ";
			if(dset[k]<0)
			gh+=(-dset[k])*(n+dset[k]);
		}//cout<<endl;*/
		//cout<<(gh/2)<<endl;
		
		ans.push_back(gh/2);
		dunion(a,b);
		
	}
	for(ll i=ans.size()-1;i>=0;i--){
		cout<<ans[i]<<endl;
	}
	
}

Measured memory_bytes: 12016
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64
int h,w;
int ans[103][103];
int t[103][103];

int main(){
char a;
cin>>h>>w;
rep(i,h)rep(j,w)ans[i][j]=-1;

rep(i,h){
	rep(j,w){
		cin>>a;
		if(a=='c'){
			t[i][j]=1;
			//ans[i][j]=0;
		}
	}
}

rep(i,h){
	rep(j,w){
		if(t[i][j]==1){
			int cnt=0;
			for(int k=j;k<w;k++){
				if(ans[i][k]==-1||cnt<ans[i][k]){
					ans[i][k]=cnt;
					cnt++;
				}
			}
		}
	}
}

rep(i,h){
	rep(j,w){
		cout<<ans[i][j];
		if(j<w-1)cout<<" ";
	}
	cout<<endl;
}
	return 0;
}



Measured memory_bytes: 3152
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define INF ( 1 << 30 )

int main(){
  int n, use[201], now, ban;
  while(cin >> n , n){

    priority_queue<int,vector<int>,greater<int> > TaHa[2];
    queue<int> tmp;
    fill_n(use,201,false),now = 0,ban = 0;

    for(int i = 0 ; i < n ; i++ ){
      int card;
      cin >> card;
      use[card] = true;
      TaHa[0].push(card);
    }
    for(int i = 1 ; i <= 2*n ; i++) if(!use[i]) TaHa[1].push(i);

    while(!TaHa[0].empty() && !TaHa[1].empty()){
      while(!TaHa[ban].empty() && now >= TaHa[ban].top()){
        tmp.push(TaHa[ban].top());
        TaHa[ban].pop();
      }
      if(!TaHa[ban].empty()) now = TaHa[ban].top() , TaHa[ban].pop();
      else now = 0;
      while(!tmp.empty()) TaHa[ban].push(tmp.front()) , tmp.pop();
      ban ^= 1;
    }
    cout << TaHa[1].size() << endl << TaHa[0].size() << endl;
  }
}

Measured memory_bytes: 1216
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String S = in.next();
            for (int i = 0; i < S.length(); i++) {
                out.print('x');
            }
            out.println();
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 23508
# ABC127C - Prison
n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
ans = 0
l, r = lst[0][0], lst[0][1]
for i in lst[1:]:
    l = max(l, i[0])
    r = min(r, i[1])
for i in range(1, n + 1):
    if l <= i <= r:
        ans += 1
print(ans)

Measured memory_bytes: 28104
def keisan(a) :
    p=1000-a
    otsurifh=p//500
    otsurih=(p-otsurifh*500)//100
    otsurifj=(p-otsurifh*500-otsurih*100)//50
    otsurij=(p-otsurifh*500-otsurih*100-otsurifj*50)//10
    otsurig=(p-otsurifh*500-otsurih*100-otsurifj*50-otsurij*10)//5
    otsurii=(p-otsurifh*500-otsurih*100-otsurifj*50-otsurij*10-otsurig*5)
    return(otsurifh+otsurih+otsurifj+otsurij+otsurig+otsurii)

for i in range(5):
    c=int(input())
    if c==0 : break
    b=keisan(c)
    print(b)
    


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

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

  vector<int> w(n);
  rep (i, n) cin >> w[i];

  int ans = INF;
  rep (i, n + 1) {
    int a = 0;
    int b = 0;
    for (int j = 0; j < i; j++) a += w[j];
    for (int j = i; j < n; j++) b += w[j];
    ans = min(ans, abs(a - b));
  }

  cout << ans << endl;
}


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++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, h, k, s, t;
  in2(n, h);
  vector<ll> a(n), b(n);
  rep(i, n)
    in2(a[i], b[i]);
  sort(all(a));
  sort(all(b));
  k = 0;
  while(a[n - 1] < b[n - 1 - k] && k < n)
    k++;
  s = 0;
  rep(i, k){
    h -= b[n - 1 - i];
    s++;
    if(h <= 0){
      out(s);
      memi;
      return 0;
    }
  }
  s += (h + a[n - 1] - 1) / a[n - 1];
  out(s);
  memi;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
	int num[100][2],max=0,low[100];
	int a,i,l,n=0,m;
	for(;;){
		if(scanf("%d",&a) == EOF){break;}
		for(i=0;i<n;i++){
			if(num[i][0] == a){
				num[i][1]++;
				break;
			}
		}
		if(i == n){
			num[n][0] = a;
			num[n][1] = 1;
			n++;
		}
	}
	for(i=0;i<n;i++){
		if(max<num[i][1]){
			m=0;
			max = num[i][1];
			low[m] = num[i][0];
			m++;
		}
		else if(max == num[i][1]){
			low[m] = num[i][0];
			m++;
		}
	}
	for(i=0;i<m;i++){
		for(l=0;l<m-1;l++){
			if(low[l]>low[l+1]){
				a = low[l];
				low[l] = low[l+1];
				low[l+1] = a;
			}
		}
	}
	for(i=0;i<m;i++){
		printf("%d\n",low[i]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
 
using namespace std;
 
typedef long long int int64;
 
const int N = (1 << 13) + 10;
const int M = 1005;
const int64 INF64 = (1LL << 61) + 10;

int main() {
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int64 ai, bi, unlocks;
	
	int full = (1 << n)-1;
	vector<int64> dp(N, INF64);
	dp[0] = 0;
	
	for(int k = 1; k <= m; k++) {
		vector<int64> new_dp(N);
		new_dp = dp;
		cin >> ai >> bi;
		unlocks = 0;
		for(int i = 1; i <= bi; i++) {
			int temp;
			cin >> temp;
			unlocks |= (1 << (temp-1));
		}
		for(int i = 0; i <= full; i++) {
			if(dp[i] == INF64) continue;
			new_dp[(i | unlocks)] = min(new_dp[(i | unlocks)], dp[i] + ai);
		}
		dp = new_dp;
	}
	
	if(dp[full] == INF64)
		cout << "-1" << endl;
	else
		cout << dp[full] << endl;
	return 0;
}

Measured memory_bytes: 384
import sys 

input = sys.stdin.readline
# sys.setrecursionlimit(25000)

import collections as c

n = int(input())
al = list(map(int, input().split(' ')))

c = c.Counter(al)

s = 0
for k, v in c.most_common():
    s += (v) * (v - 1) // 2

for i in range(n):
    temp = c[al[i]]
    a = temp * (temp - 1) // 2
    b = (temp - 2) * (temp - 1) // 2
    
    print(s - a + b)


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

using namespace std;
using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}   

signed main() {
    int n, w;
    scanf("%d%d", &n, &w);
    vector<ll> dp(w + 1);
    // dp[i] - the maximum total value of items with total weight exactly i
    for (int item = 0; item < n; ++item) {
        int weight, value;
        scanf("%d%d", &weight, &value);
        // dp[0] -> dp[3] -> dp[6]
        for (int weight_already = w - weight; weight_already >= 0; weight_already--) {
            max_self(dp[weight_already + weight], dp[weight_already] + value);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= w; i++) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", answer);    
    return false;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cassert>
#include<climits>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 110

using namespace std;

vector<int> G[MAX];
int remain[MAX];
int depth[MAX];

int main(){
  int T;
  cin >> T;
  while(T--){

    for(int i=0;i<MAX;i++){
      G[i].clear();
      remain[i] = 0;
      depth[i] = -1;
    }
    vector<int> record;
    vector<int> input;

    int r,cur,upper;

    while(cin >> r,r){
      input.push_back(r);
    }

    remain[0] = input[0];
    cur = 0, upper = 1, depth[0] = 0;

    for(int i=1;i<input.size();i++){
      //cout << "the input => " << input[i] << endl;
      //cout << "i = " << i << " cur = " << cur << endl;
      if( input[i] > 0 ){

	G[cur].push_back(upper);
	G[upper].push_back(cur);
	depth[upper] = depth[cur] + 1;
	remain[upper] = input[i] - 1;
	assert(remain[upper] >= 0);
	remain[cur]--;
	assert(remain[cur] >= 0);
	cur = upper++;

      } else {
	assert(depth[cur] != -1);
	int next = depth[cur] + input[i];
	for(int j=record.size()-1;j>=0;j--){
	  if(next == depth[record[j]]){
	    next = record[j];
	    break;
	  }
	}
	assert(next >= 0);
	G[next].push_back(cur);
	G[cur].push_back(next);
	remain[next]--;
	assert(remain[next] >= 0);
	remain[cur]--;
	assert(remain[cur] >= 0);

      }

      record.push_back(cur);

      for(int j=record.size()-1;j>=0;j--){
	if(remain[cur] != 0){
	  break;
	}
	cur = record[j];
      }
    }

    for(int i=0;i<upper;i++){
      cout << i+1;
      sort(G[i].begin(),G[i].end());
      for(int j=0;j<G[i].size();j++){
	cout << " " <<  G[i][j]+1;
      }
      cout << endl;
    }


  }
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;

int main(){
    int n;
    std::cin >> n;
    std::vector<tuple<string,int,int>> a;
    rep(i,n){
        string s;
        int d;
        std::cin >> s>>d;
        a.pb(make_tuple(s,-d,i+1));
    }
    sort(all(a));
    rep(i,n)std::cout << get<2>(a[i]) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<pair<string, string>, ll> mp;
    rep(i, 1 << n)
    {
        string red = "", blue = "";
        rep(j, n)
        {
            if ((i >> j) & 1)
            {
                red += s[j];
            }
            else
            {
                blue += s[j];
            }
        }
        mp[{red, blue}]++;
    }
    ll ans = 0;
    rep(i, 1 << n)
    {
        string red = "", blue = "";
        rep(j, n)
        {
            if ((i >> j) & 1)
            {
                red += s[n + j];
            }
            else
            {
                blue += s[n + j];
            }
        }
        reverse(ALL(red));
        reverse(ALL(blue));
        ans += mp[{blue, red}];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 60868
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
left = []



for i in range(n):
    left.append((l[i][0]+l[i][1],l[i][0]-l[i][1]))
left.sort()   
count = 1
right = 10**10
right = left[0][0]
c = 0

while True:
    
    for i in range(c,n+1):
        if i == n:
            print(count)
            exit()
        if left[i][1] >= right:
            count += 1
            right = left[i][0]
            c = i
            
            
            
    if c == n-1:
        print(count)
        exit()
        


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

VL Dijkstra(vector<vector<PLL>>& G, int s) {
	VL dist(SZ(G), LINF);
	dist[s] = 0;
	priority_queue<PLL, vector<PLL>, greater<PLL>> que;
	que.push(PLL(0LL, s));

	while (!que.empty()) {
		PLL p = que.top(); que.pop();
		int v; /* 頂点*/ long long d; /* 頂点vまでの距離 */
		tie(d, v) = p;

		if (d > dist[v]) continue;

		FOR(i, 0, (int)G[v].size()) {
			int nv = G[v][i].first;
			if (dist[nv] > dist[v] + G[v][i].second) {
				dist[nv] = dist[v] + G[v][i].second;
				que.push(PLL(dist[nv], nv));
			}
		}
	}
	return dist;
}


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

	LL N, M; cin >> N >> M;
	vector<vector<PLL>>G(N);
	FOR(i, 0, M) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a].push_back(PLL(b, 1));
		G[b].push_back(PLL(a, 1));
	}
	auto res = Dijkstra(G, 0);
	
	LL ans = res[N-1]<=2;
	cout<<(ans?"POSSIBLE":"IMPOSSIBLE")<<endl;

	return 0;
}


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

const int N = 1E5 + 50;

int n, m, ans, vis[N], a[N], b[N], c[N], d[N], f[N];

int find(int x) {
    return x == f[x] ? x : f[x] = find(f[x]);
}
void merge(int u, int v) {
    f[u] = v; 
}
int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) 
        scanf("%d", a + i), m ^= a[i], c[i] = a[i], f[i] = i;
    c[++n] = a[n] = m, m = 0;
    for(int i = 1; i < n; i++) 
        scanf("%d", b + i), m ^= b[i], d[i] = b[i];
    d[n] = b[n] = m;
    // for(int i = 1; i <= n; i++) cout << c[i] << ' '; puts("");
    // cout << m << '\n';
    sort(c + 1, c + 1 + n), sort(d + 1, d + 1 + n);
    for(int i = 1; i <= n; i++) {
        if(c[i] != d[i]) return 0 * printf("-1\n");
    }
    int len = unique(c + 1, c + 1 + n) - c - 1;
    for(int i = 1; i <= n; i++) {
        a[i] = lower_bound(c + 1, c + 1 + len, a[i]) - c;
        b[i] = lower_bound(c + 1, c + 1 + len, b[i]) - c;
        if(a[i] != b[i]) {
            // cout << a[i] << ' ' << b[i] << '\n';
            vis[a[i]] = vis[b[i]] = 1;
            merge(find(a[i]), find(b[i]));
            ans ++;
        }
    } 
    for(int i = 1; i <= len; i++) {
        find(i);
        if(!vis[i]) ans --;
    }
    sort(f + 1, f + 1 + len);
    ans += unique(f + 1, f + 1 + len) - f - 1;
    cout << ans - 1 - (a[n] != b[n]) + (!vis[a[n]])<< '\n';
    return 0;
}   

Measured memory_bytes: 4096
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

#[fastout]
fn main() {
    input! {
        n: usize,
        v: [usize; n]
    }
    let mut m1 = std::collections::BTreeMap::<usize, usize>::new();
    let mut m2 = std::collections::BTreeMap::<usize, usize>::new();
    for i in 0..n {
        if i % 2 == 0 {
            *m1.entry(v[i]).or_insert(0) += 1;
        } else {
            *m2.entry(v[i]).or_insert(0) += 1;
        }
    }
    let mut m1 = m1.iter().map(|(&k, &v)| (v, k)).collect::<Vec<_>>();
    let mut m2 = m2.iter().map(|(&k, &v)| (v, k)).collect::<Vec<_>>();
    m1.sort_by_key(|&(v, _)| Reverse(v));
    m2.sort_by_key(|&(v, _)| Reverse(v));
    if m1[0].1 != m2[0].1 {
        println!("{}", n - m1[0].0 - m2[0].0);
        return;
    }
    if m1.len() == 1 && m2.len() == 1 {
        println!("{}", n / 2);
        return;
    }
    let mut ans = n;
    if m2.len() != 1 {
        ans = min(ans, n - m1[0].0 - m2[1].0);
    }
    if m1.len() != 1 {
        ans = min(ans, n - m1[1].0 - m2[0].0);
    }
    println!("{}", ans);
}


Measured memory_bytes: 7976
#include <iostream>
#include <vector>
using namespace std;
int main(){
    long long N, M;
    cin >> N >> M;
    if(N == 1 && M == 1){
        cout << 1 << endl;
        return 0;
    }
    if(N == 1){
        cout << M - 2 << endl;
        return 0;
    }
    if(M == 1){
        cout << N - 2 << endl;
        return 0;
    }
    cout << (N - 2) * (M - 2) << endl;
}

Measured memory_bytes: 3612
program walk_and_teleport
  implicit none
  integer :: n
  integer(8) :: a, b, x(100000) = 0_8, y(100000) = 0_8, z(100000) = 0_8
  read(*,*) n, a, b
  read(*,*) x(1:n)
  y(1:n-1) = a*(x(2:n)-x(1:n-1))
  z(1:n-1) = b
  write(*,'(i0)') sum(merge(y,z,y<z))
  stop
end program walk_and_teleport

Measured memory_bytes: 3200
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int n, a, b;
	cin >> n >> a >> b;

	if (n * a < b) {
		cout << n * a << endl;
	}
	else {
		cout << b << endl;

	}
}

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

using namespace std;
 
int main() {
    int a[5];
    for(int i= 0;i<5;i++) cin >>a[i];
    int sai = 10;
    int soko = 0;
    for(int i= 0;i<5;i++){
      if(a[i]%10 == 0)continue;
      if(a[i]%10 <= sai){
        sai = a[i]%10;
        soko = i;
      }
    }
    for(int i = 0;i<5;i++){
      if(i == soko) continue;
      if(a[i]%10 == 0) continue;
      a[i] += 10-a[i]%10;
    }
    int g = 0;
    for(int i= 0;i<5;i++) g+= a[i];
    cout<<g;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    string S;
    cin >> S;
    int n = S.size();
    rep(i, n)
    {
        cout << "x";
    }
    return 0;
}

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

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int pcnt(int x)
{
    return __builtin_popcount(x);
}
int f(int x)
{
    if (x == 0)
        return 0;
    return f(x % pcnt(x)) + 1;
}
int main(void)
{
    int n, pc;
    string s;
    cin >> n >> s;
    vector<int> v(n);
    rep(i, 0, n) v[i] = s[i] - '0';
    rep(i, 0, n) pc += v[i];
    vector<int> ans(n, 0);
    rep(b, 0, 2)
    {
        int npc = pc;
        if (b == 0)
            npc++;
        else
            npc--;
        if (npc <= 0)
            continue;
        int r0 = 0;
        rep(i, 0, n)
        {
            r0 = (2 * r0) % npc;
            r0 += v[i];
        }
        int k = 1;
        for (int i = n - 1; i >= 0; --i)
        {
            if (v[i] == b)
            {
                int r = r0;
                if (b == 0)
                    r = (r + k) % npc;
                else
                    r = (r - k + npc) % npc;
                ans[i] = f(r) + 1;
            }
            k = (2 * k) % npc;
        }
    }
    rep(i, 0, n) cout << ans[i] << endl;
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, q;
  cin >> n >> q;
  vector<int> hoge(n);
  vector<char> fuga(n);
  bool f = false;
  char tmp;
  int count = 0;
  int i = 1;

  for (int i = 0; i < n; i++){
    cin >> tmp;
    if (i == 0){
      fuga[i] = tmp;
      hoge[i] = count;
      continue;
    }
    if(tmp == 'C'){
      if (fuga[i - 1] == 'A'){
        count += 1;
      }
    }
    fuga[i] = tmp;
    hoge[i] = count;
  }
  int l, r;
  rep_i(i, q){
    cin >> l >> r;
    // cout << hoge[r - 1] << " " << hoge[l - 1] << endl;
    cout << hoge[r - 1] - hoge[l - 1] << endl;
  }
  
  
  
  // rep_i(i, n){
  //   cin >> tmp;
  //   if(tmp == 'A'){
  //     if (f){
  //       f = false;
  //     }else{
  //       f = true;
  //     }
  //   }else if(tmp == 'C'){
  //     if (f){
  //       count += 1;
  //     }
  //     f = false;
  //   }else{
  //     f = false;
  //   }
  //   hoge[i] = count;
  // }

}


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

#define repl(i,a,b) for(i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define max(x,y) x>y?x:y

#define bool int
#define false 0
#define true 1

int n;
int x[111],y[111],r[111],c[111];
bool used[111];
char mem[1<<24];

bool judge(int i,int j){
	bool ok=true;
	int k;
	rep(k,i){
		if(used[k])continue;
		if(pow(x[i]-x[k],2)+pow(y[i]-y[k],2)<pow(r[i]+r[k],2))ok=false;
	}
	rep(k,j){
		if(used[k])continue;
		if(pow(x[k]-x[j],2)+pow(y[k]-y[j],2)<pow(r[k]+r[j],2))ok=false;
	}
	return ok;
}

int dfs(int v){
	if(mem[v]!=-1)return mem[v];
	int res=0;
	int i,j;
	rep(i,n)repl(j,i+1,n){
		if(!used[i]&&!used[j]&&c[i]==c[j]&&judge(i,j)){
			used[i]=used[j]=true;
			res=max(res,dfs(v|(1<<i)|(1<<j))+2);
			used[i]=used[j]=false;
		}
	}
	return mem[v]=res;
}

int main(){
	//cin.sync_with_stdio(false);
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int i;
		rep(i,n)scanf("%d%d%d%d",x+i,y+i,r+i,c+i);
		memset(used,0,sizeof(used));
		memset(mem,-1,sizeof(mem));
		printf("%d\n", dfs(0));
	}
	return 0;
}

Measured memory_bytes: 16992
integer A,B
read*,A,B
if (A==1)then
	A=A+13
endif
if (B==1)then
	B=B+13
endif
if(A>B)then
	print"(A)","Alice"
else if(A<B)then
	print"(A)","Bob"
else
	print"(A)","Draw"
endif
end

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,x;
int cost[20];
int books[20][20];
int dfs(int pos,int algo[]);
int main(){
  cin>>n>>m>>x;
  for(int i=0;i<n;i++){
    cin>>cost[i];
    for(int j=0;j<m;j++){
      cin>>books[i][j];
    }
  }
  
  int array[20]={0};
  cout<<dfs(0,array)<<endl;
  return(0);
}

int dfs(int pos,int algo[]){
  if(pos==n){
    for(int i=0;i<m;i++){
      if(algo[i]<x){
	return(-1);
      }
    }
    return(0);
  }

  int v1,v2;
  for(int i=0;i<m;i++){
    algo[i]+=books[pos][i];
  }
  v1=dfs(pos+1,algo);
  for(int i=0;i<m;i++){
    algo[i]-=books[pos][i];
  }
  v2=dfs(pos+1,algo);
  
  if(v1==-1){
    if(v2==-1){
      return(-1);
    }
    return(v2);
  }
  if(v2==-1){
    return(v1+cost[pos]);
  }
  return(min(v1+cost[pos],v2));
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define repd(i,a,b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int A, B, C, K;
	int sum = 0;
	cin >> A >> B >> C >> K;
	if(A>=K) cout << K << endl;
	else if(A+B>=K) cout << A << endl;
	else cout << A-(K-(A+B)) << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 100010;

int n;
ll x[MAXN], y[MAXN], t[MAXN];

bool check(ll diffT, ll diffX, ll diffY) {
  ll diff = abs(diffX) + abs(diffY);
  return diff <= diffT && diff % 2 == diffT % 2;
}

void solve() {
  ll curt = 0, curx = 0, cury = 0;
  for (int i=0;i<n;i++) {
    ll diffT = t[i] - curt;
    ll diffX = x[i] - curx;
    ll diffY = y[i] - cury;
    if (check(diffT, diffX, diffY)) {
      curt = t[i];
      curx = x[i];
      cury = y[i];
    } else {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  solve();
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

struct Node
{
    int key;
    Node *prev, *next;
};

Node *nil;

Node* listSearch(int key)
{
    Node *cur = nil->next;
    while ( cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void init()
{
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList()
{
    Node *cur = nil->next;
    int isf = 0;
    while (1) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t)
{
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst()
{
    deleteNode(nil->next);
}

void deleteLast()
{
    deleteNode(nil->prev);
}

void deleteKey(int key)
{
    deleteNode(listSearch(key));
}

void insert(int key)
{
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i=0; i< n; ++i) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') { insert(key); np++; size++; }
        else if (com[0] == 'd') {
            if (strlen(com) > 6) {
                if (com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }

    printList();

    return 0;
}



Measured memory_bytes: 33920
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 2e5 + 9;
int val[N], ans[N], temp[N];
vector<int> adj[N];
vector<int> v;

void dfs(int node, int par) {
	auto it = lower_bound(v.begin(), v.end(), val[node]);
	int pos = it - v.begin();
	bool lsa = 0;
	if(it == v.end())
		v.push_back(val[node]);
	else {
		lsa = 1;
		temp[node] = v[pos];
		v[pos] = val[node];
	}
	ans[node] = v.size();
	for(auto it: adj[node]) {
		if(it == par) continue;
		dfs(it, node);
	}
	if(lsa)
		v[pos] = temp[node];
	else
		v.pop_back();
}

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	int n, u, v;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> val[i];
	for (int i = 1; i < n; ++i) {
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; ++i)
		cout << ans[i] << '\n';
	return 0;
}


Measured memory_bytes: 31192
def all_pos(lst):
    for e in lst:
        if e < 0:
            return False
    return True

def all_neg(lst):
    for e in lst:
        if e > 0:
            return False
    return True

N = int(input())
A = list(map(int, input().split()))

ans = []
M = 0
if all_pos(A):
    A.sort()
    res = A[0]
    for i in range(1, N - 1):
        ans.append((res, A[i]))
        res -= A[i]
    ans.append((A[-1], res))
    M = A[-1] - res
elif all_neg(A):
    A.sort()
    A.reverse()
    res = A[0]
    for i in range(1, N):
        ans.append((res, A[i]))
        res -= A[i]
    M = res
else:
    A.sort()
    A.reverse()
    tmp_neg = A[-1]
    tmp_pos = A[0]
    for i in range(1, len(A) - 1):
        if A[i] >= 0:
            ans.append((tmp_neg, A[i]))
            tmp_neg -= A[i]
        else:
            ans.append((tmp_pos, A[i]))
            tmp_pos -= A[i]
    ans.append((tmp_pos, tmp_neg))
    M = tmp_pos - tmp_neg
    
print(M)
for e in ans:
    print(e[0], e[1])

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()

#define EPS 1e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;
#define MAXN 20
char grid[MAXN][MAXN + 1];
int n, m, d[MAXN][MAXN], max_dist = 0;
void bfs(int x, int y) {
	queue<ii> Q;
	for(int k = 0; k < n; ++k) {
		for(int j = 0; j < m; ++j) {
			if(grid[k][j] == '.')
				d[k][j] = -1;
			else
				d[k][j] = 0;
		}
	}
	d[x][y] = 0;
	Q.push({x, y});
	while(!Q.empty()) {
		int i = Q.front().f;
		int j = Q.front().s;
		max_dist = max(max_dist, d[i][j]);
		Q.pop();
		if(i && d[i - 1][j] == -1) {
			d[i - 1][j] = 1 + d[i][j];
			Q.push({i - 1, j});
		}
		if(i < n - 1 && d[i + 1][j] == -1) {
			d[i + 1][j] = 1 + d[i][j];
			Q.push({i + 1, j});
		}
		if(j && d[i][j - 1] == -1) {
			d[i][j - 1] = 1 + d[i][j];
			Q.push({i, j - 1});
		}
		if(j < m - 1 && d[i][j + 1] == -1) {
			d[i][j + 1] = 1 + d[i][j];
			Q.push({i, j + 1});
		}
	}
}
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; ++i) 
		cin >> grid[i];
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(grid[i][j] == '.')
				 bfs(i, j);
	cout << max_dist << '\n';
    return 0;
}



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

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

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

int main() {
    int n;
    while(cin >> n, n){
        int ans = 0, l = 0, r = 0, p = 0;
        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            if(s == "lu") l = 1;
            else if(s == "ru") r = 1;
            else if(s == "ld") l = 0;
            else r = 0;
            if(l == 1 && r == 1 && p == 0) ans++, p = 1;
            if(l == 0 && r == 0 && p == 1) ans++, p = 0;
        }
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 3132
#include <iostream>

using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    int ret = 1;
    int a = 0;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        a += tmp;
        if (a <= x)ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,w;
  int mp[500][500];
  vector<pair<int,int> > ans;
  cin>>h>>w;
  rep(i,h){
    rep(j,w){
      cin>>mp[i][j];
      mp[i][j]%=2;
    }
  }
  rep(i,h-1){
    rep(j,w){
      if(mp[i][j]%2==1){
	mp[i+1][j]++;
	pair<int,int> p=make_pair(i+1,j+1);
	ans.push_back(p);
	p=make_pair(i+2,j+1);
	ans.push_back(p);
      }
    }
  }
  rep(i,w-1){
    if(mp[h-1][i]%2==1){
      mp[h-1][i+1]++;
      pair<int,int> p=make_pair(h,i+1);
      ans.push_back(p);
      p=make_pair(h,i+2);
      ans.push_back(p);
    }
  }
  cout<< ans.size()/2 <<endl;
  rep(i,ans.size()/2 ){
    cout<<ans[i*2].fst<<" "<<ans[i*2].scd<<" "<<ans[(i*2)+1].fst<<" "<<ans[(i*2)+1].scd<<endl;
  }

  return 0;
}

Measured memory_bytes: 8432
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

int main(void)
{
	int a;
	long long int ans=0;
	cin >> a;
	int flag = 9;
	
	if (a == 1)
	{
		ans = 4;
	}
	else if (a == 2)
	{
		ans = 4;
	}
	else if (a == 4)
	{
		ans = 4;
	}
	else
	{
		while (1)
		{
			ans++;
			
			if (a % 2 == 0)
			{
				a = a / 2;
			}
			else if (a % 2 == 1)
			{
				a = 3 * a + 1;
			}
			if (a == 4)
			{
				ans = ans + 4;
				break;
			}
		
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int min_point = 1001;
  int max_point = 0;
  int N;
  cin>>N;
  while(N--){
    int d;
    cin>>d;
    min_point = min(d,min_point);
    max_point = max(d,max_point);
  }

  cout << max_point - min_point <<endl;
  return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int a[1000],n,f,d;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    while(1){
        if(f>0)break;

        for(int i=0;i<n;i++){
            if(a[i]%2==1){f+=100;break;}
            a[i]=a[i]/2;
        }
        if(f==0)d++;

    }

    cout<<d<<endl;
}


Measured memory_bytes: 256
# coding: utf-8
n = str(input())
ketasu = len(n)
if n[ketasu-1] == "3":
    print("bon")
elif n[ketasu-1] == "0" or n[ketasu-1] == "1" or n[ketasu-1] == "6" or n[ketasu-1] == "8":
    print("pon")
else:
    print("hon")

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

int main() {
	int n,m;
	cin >> n >> m;
	int a,sma=0;
	for(int i=0;i<m;i++)
	{
		cin >> a;
		sma += a;
	}
	int k = n - sma;
	if(k < 0)
	{
		k = -1;
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(void) {}
  Edge(int src, int dst) : src(src), dst(dst) {}
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void edges_to_graph(Graph &graph, const Edges &edges, const int vertices, const bool directed = true) {
  graph.resize(vertices);
  for (const auto &e : edges) graph[e.src].emplace_back(e);
  if (!directed) for (const auto &e : edges) graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}

vector<double> calc_dp(const Graph &graph, const int dltv) {
  const int n = graph.size();
  vector<double> dp(n);
  rrep (i, n - 1) {
    double sum = 0, en = graph[i].size();
    if (i == dltv && en != 1) {
      double maxi = -1;
      allrep (e, graph[i]) {
        sum += dp[e.dst];
        maxi = max(maxi, dp[e.dst]);
      }
      sum -= maxi;
      --en;
    } else {
      allrep (v, graph[i]) sum += dp[v.dst];
    }
    dp[i] = sum / en + 1;
  }
  return dp;
}

int main(void) {
  int n, m;
  cin >> n >> m;
  Graph graph;
  Edges edges(m);
  rep (i, m) {
    int s, t;
    cin >> s >> t;
    edges[i] = {--s, --t};
  }
  edges_to_graph(graph, edges, n);
  double ans = DBL_MAX;
  rep (i, n - 1) {
    auto dp = calc_dp(graph, i);
    ans = min(ans, dp[0]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5888