akhauriyash/Code-Regression huggingface dataset:
// Best practice
 
#include<bits/stdc++.h>
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
 
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}
 
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 
 
// Code from Here -------------------------------------------------------------------------------

const int nax = 1e5;
vi adj[nax];
int dp[nax][2];

int count(int k, int par, int c){
	int &ans = dp[k][c];
	if(ans!=-1)return ans;
	ans=1;
	for(auto it: adj[k]){
		if(it==par)continue;
		if(c==0)ans = (ans * (count(it, k, c^1) + count(it, k, c))%MOD)%MOD;
		else ans = (ans* count(it, k, c^1))%MOD;
	}
	return ans;
}

signed main() {
	tezz
 
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

	int n,p,q;
	cin >> n;
	for(int i=0; i<n-1; i++){
		cin >> p >> q;
		--p, --q;
		adj[p].pb(q);
		adj[q].pb(p);
	}
	ini(dp, -1);
	cout << (count(0, -1, 0) + count(0, -1, 1))%MOD << endl;
 
	return 0;
}  

Measured memory_bytes: 20396
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    int N = in.nextInt();
    Set<Integer> set = new HashSet<Integer>();
    set.add(1);

    int six = 6;
    while (six <= N) {
      set.add(six);
      six *= 6;
    }

    int nine = 9;
    while (nine <= N) {
      set.add(nine);
      nine *= 9;
    }

    int[] nums = new int[N + 1];

    for (int i = 1; i <= N; i++) {
      for (Integer n : set) {
        if (n <= i) {
          if (nums[i] == 0) {
            nums[i] = nums[i - n] + 1;
          } else {
            nums[i] = Math.min(nums[i], nums[i - n] + 1);
          }
        }
      }
    }

    System.out.println(nums[N]);
  }
}

Measured memory_bytes: 26284
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define scan(a,n) for(long int index=0;index<n;index++) cin>>a[index];
#define print(a,n) for(long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int,long long int>>
#define vsi vector<string>
#define vci vector<char>
#define all(n) (n.begin(),n.end())
 
 
 
int main() {
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fast;
    ll t;
    t=1;
    while(t--){
      
      string a,b;
      cin>>a>>b;
      ll n=a.length(),m=b.length();
      ll mx=0,x,i,j;
      for(i=0;i<n-m+1;i++){
        x=0;
        for(j=0;j<m;j++){
          if(a[j+i]==b[j]) x++;
        }
        mx=max(mx,x);
 
        
 
    }
    cout<<m-mx;
      }
return 0;    
 }  

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  ll mi=A[0];
  int ans=1;
  for(int i=1;i<N;i++){
    if(A[i]<=mi) ans++;
    mi=min(mi,A[i]);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a < b and b < c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}



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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string s;
    cin >>s;

    map<string,int> m;
    m["SAT"]=1;
    m["FRI"]=2;
    m["THU"]=3;
    m["WED"]=4;
    m["TUE"]=5;
    m["MON"]=6;
    m["SUN"]=7;


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << m[s] << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;

int main(int argc, char const *argv[]) {
  int a[3], b[3], p[4]={};
  int f = 0;

  for(int i=0; i<3; i++){
    scanf("%d %d", &a[i], &b[i]);
    p[a[i]-1]++;
    p[b[i]-1]++;
  }

  // printf("%d %d %d %d\n", p[0], p[1], p[2], p[3]);

  for(int i=0; i<4; i++){
    if(p[i]>2){
      printf("NO");
      f = 1;
    }
  }

  if(f==0) printf("YES");

  return 0;
}


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

long gcd(long num1, long num2){
	long v0 = num1, v1 = num2, v2 = num1 % num2;
	while(v2 != 0){
		v0 = v1;
		v1 = v2;
		v2 = v0 % v1;
	}
	return v1;
}

long lcm(long num1,long num2){
	return num1*num2/gcd(num1,num2);
}

int main(){
	long A,B,C,D,E;
	cin>>A>>B>>C>>D;
	E = lcm(C,D);
	long ac,bc,ad,bd,ae,be;
	if(A%C==0)ac = A;
	else ac = A + (C-(A%C));
	bc = B - (B%C);
	if(A%D==0)ad=A;
	else ad = A + (D-(A%D));
	bd = B - (B%D);
	if(A%E==0)ae = A;
	else ae = A + (E-(A%E));
	be = B - (B%E);
	//cout<<ac<<" "<<bc<<" "<<ad<<" "<<bd<<" "<<ae<<" "<<be<<endl;
	long cnum = (bc - ac)/C + 1;
	long dnum = (bd - ad)/D + 1;
	long eenum = (be - ae)/E + 1;
	//cout<<cnum<<" "<<dnum<<" "<<eenum<<endl;
	cout<<B-A+1-cnum-dnum+eenum<<endl;
}


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

using namespace std;

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

  int a, b, k;
  cin >> a >> b >> k;

  for (int i = a; i < min(a+k, b+1); ++i) cout << i << endl;
  for (int i = max(a+k, b-k+1); i <= b; ++i) cout << i << endl;

  return 0;
}



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

using namespace std;

int main()
{
	string str;
	int n;
	cin >> str>>n;
	while (n--){
		string require;
		cin >> require;
		if (require == "replace"){
			int a, b;
			string p;
			cin >> a >> b >> p;
			str.replace(a, b - a + 1, p);
		}
		else if (require == "reverse"){
			int a, b;
			string rev;
			cin >> a >> b;
			rev = str.substr(a, b - a + 1);
			reverse(rev.begin(), rev.end());
			str.replace(a, b - a + 1, rev);
		}
		else{
			int a, b;
			cin >> a >> b;
			cout << str.substr(a, b - a + 1) << endl;
		}
	}
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;
int main(){
  long long n, m, q;
  cin >> n >> m >> q;
  long long left, right, x, y;
  long long line[n + 1][n + 1], accumul[n + 1][n + 1];

  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++){
      line[i][j] = 0;
      accumul[i][j] = 0;
    }

  for (int i = 1; i <= m; i++){
    cin >> left >> right;
    line[left][right] += 1;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++){
      accumul[i][j] = accumul[i][j - 1] + line[i][j];
    }

  for (int i = 0; i < q; i++){
    cin >> x >> y;
    long long count=0;
    for (int j = x; j <= y; j++)
      count += accumul[j][y] - accumul[j][x - 1];
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 30;

int main(void){
    ll N,M; cin >> N >> M;
    
    priority_queue<ll> que;
    
    for(int i = 0; i < N; i++){
        ll A; cin >> A;
        que.push(A);
    }
    
    for(int i = 0; i < M; i++){
        ll temp;
        temp = que.top(); que.pop();
        temp /= 2;
        que.push(temp);
    }
    
    ll ans = 0;
    while(!que.empty()){
        ans += que.top(); que.pop();
    }
    
    cout << ans << "\n";
}


Measured memory_bytes: 1400
n = gets.to_i
ms = [1]
dp = Array.new(n+10, 100000)
dp[0] = 0
(1..n).each do |i|
  dp[i] = i
  x = 6
  while x <= 100000
    if i-x >= 0
      dp[i] = [dp[i], dp[i-x] + 1].min
    else
      dp[i] = [dp[i], dp[i-1] + 1].min
    end
    x *= 6
  end
  x = 9
  while x <= 100000
    if i-x >= 0
      dp[i] = [dp[i], dp[i-x] + 1].min
    else
      dp[i] = [dp[i], dp[i-1] + 1].min
    end
    x *= 9
  end
end
puts dp[n]

Measured memory_bytes: 2556
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int n, a, b, c, i, x;
    scanf("%d", &n);
    a = b = c = 0;
    for(i = 1; i <= n; ++i)
    {
        scanf("%d", &x);
        if(x % 4 == 0)
        {
            a++;
        }else
        if(x % 2 == 0)
        {
            b++;
        }else
        c++;
    }
    c += b % 2;
    if(a + 1 >= c)
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う

int main(){
  int A,B,C;
  cin >> A >> B >> C;  
  if(A+B >= C){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }

  return 0;
}



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

int main()
{
    int ca, cb, cc, k;
    cin>>ca>>cb>>cc>>k;

    vector<long long> a(ca), b(cb), c(cc);
    for (int i=0; i<ca; i++) cin>>a[i];
    for (int i=0; i<cb; i++) cin>>b[i];
    for (int i=0; i<cc; i++) cin>>c[i];

    vector<long long> ab;
    for (int i = 0; i < ca; i++) {
        for (int j = 0; j < cb; j++) {
            ab.push_back(a[i] + b[j]);
        }
    }
    sort(ab.begin(), ab.end());
    reverse(ab.begin(), ab.end());

    vector<long long> abc;
    for (int i = 0; i < min(k, (int)ab.size()); i++) {
        for (int j = 0; j < cc; j++) {
            abc.push_back(ab[i] + c[j]);
        }
    }
    sort(abc.begin(), abc.end());
    reverse(abc.begin(), abc.end());

    for (int i = 0; i < k; i++) {
        cout << abc[i] << endl;
    }
    return 0;
}


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

int main(){
    int cards[4][13] = {};

    int n, y;
    char x;

    cin >> n;

    for (int i = 0; i < n; i++){
        cin >> x >> y;
        if (x == 'S') cards[0][y - 1] = 1;
        if (x == 'H') cards[1][y - 1] = 1;
        if (x == 'C') cards[2][y - 1] = 1;
        if (x == 'D') cards[3][y - 1] = 1;
    }

    for (int j = 0; j < 4; j++){
        for (int l = 0; l < 13; l++){
            if (cards[j][l] == 0){
                if (j == 0) cout << "S " << l + 1 << endl;
                if (j == 1) cout << "H " << l + 1 << endl;
                if (j == 2) cout << "C " << l + 1 << endl;
                if (j == 3) cout << "D " << l + 1 << endl;  
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n, m, a, b;
vector<pair<int, int>> stars, c;
int main() {
	while (cin >> m, m) {
		stars.clear();
		c.clear();
		cin >> a >> b;
		for (int i = 0; i < m - 1; i++) {
			int x, y; cin >> x >> y;
			c.push_back(make_pair(x - a, y - b));
		}
		cin >> n;
		for (int i = 0; i < n; i++) {
			int x, y; cin >> x >> y;
			stars.push_back(make_pair(x, y));
		}
		sort(stars.begin(), stars.end());
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m - 1; j++) {
				pair<int, int> p = make_pair(stars[i].first + c[j].first, stars[i].second + c[j].second);
				if (*lower_bound(stars.begin(), stars.end(), p) != p)goto joi2007;
			}
			cout << stars[i].first - a << ' ' << stars[i].second - b << endl;
		joi2007:;
		}
	end:;
	}
}

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

bool p[1000010];
void init(){
    int MAX = 1000010;
    for(int i=0;i<MAX;i++) p[i]=1;
    p[0]=0, p[1] = 1;
    for(int i=2;i<=MAX/2;i++){
        if(p[i]){
            for(int j=i+i;j<MAX;j+=i) p[j]=0;
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    int a[n];
    init();
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(p[a[0]]==false){
        cout << 0 << endl;
        return 0;
    }
    ll mod = 1e9+7;
    ll dp[n+1][2]={};
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        if(i) dp[i+1][1] += dp[i][0];
        dp[i+1][1] %= mod;
        if(i-2>=0 && a[i]>a[i-2] && p[a[i]]){
            dp[i+1][0] += dp[i][1];
        }
        if(i && a[i]>a[i-1] && p[a[i]]){
            dp[i+1][0] += dp[i][0];
        }
        if(i==0){
            dp[i+1][0] += dp[i][0];
        }
        dp[i+1][0] %= mod;
    }
    ll ans = dp[n][0] + dp[n][1];
    ans %= mod;
    cout << ans << endl;
}



Measured memory_bytes: 6140
#include <stdio.h>

void swap(int *a, int *b){
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int main(){
    int X, Y, Z;
    scanf("%d%d%d", &X, &Y, &Z);
    swap(&X, &Y);
    swap(&X, &Z);
    printf("%d %d %d\n", X, Y, Z);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    if(k == 0) {
        cout << (ll)n * n << endl;
        return 0;
    }

    ll ans = 0;
    for(int i = k + 1; i <= n; i++){
        ans += (n / i) * (i - k);
        ans += max(0, n % i - k + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
priority_queue<ll,vector<ll>,greater<ll>> pque;
priority_queue<ll> pque1;
ll n,s[300000],ans1[100001],ans2[100001],su2,su1,ans=-1e15,p;
int main(void){
    cin>>n;
    for(int i=0;i<n*3;i++)cin>>s[i];
    for(int i=0;i<n;i++){
        pque.push(s[i]);
        su1+=s[i];
        pque1.push(s[3*n-i-1]);
        su2+=s[3*n-i-1];
    }
    ans1[0]=su1;
    ans2[0]=su2;
    for(int i=0;i<n;i++){
        su1+=s[n+i];
        pque.push(s[n+i]);
        p=pque.top();
        //cout<<p<<endl;
        su1-=p;
        pque.pop();
        ans1[i+1]=su1;
        
        su2+=s[2*n-1-i];
        pque1.push(s[2*n-1-i]);
        p=pque1.top();
        //cout<<p<<endl;
        su2-=p;
        pque1.pop();
        ans2[i+1]=su2;
    }
    for(int i=0;i<n+1;i++){
        //cout<<ans1[i]<<" "<<ans2[n-i]<<endl;
        ans=max(ans,ans1[i]-ans2[n-i]);
    }
    cout<<ans<<endl;
}


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

int main() {
    int ans = 0;
    vector<int> x(5);
    for(int i = 0; i < 5; i++) {
        cin >> x.at(i);
        if(x.at(i) == 0)
            ans = i + 1;
    }

    cout << ans << endl;
}

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

const int N=2e5+5;
int n;
ll k,bit[N],pf[N];

void upd(int x){
	for(;x<N;x=x|(x+1))
		bit[x]++;
}

ll get(int x){
	ll res=0;
	for(;x>=0;x=(x&(x+1))-1)
		res+=bit[x];
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>k;
	vector<ll> b;
	for(int i=1;i<=n;++i){
		cin>>pf[i];
		pf[i]+=pf[i-1];
		b.push_back(pf[i]-1LL*k*i);
	}
	b.push_back(0);
	sort(b.begin(),b.end());
	ll res=0;
	upd(lower_bound(b.begin(),b.end(),0)-b.begin());
	for(int i=1;i<=n;++i){
		int x=lower_bound(b.begin(),b.end(),pf[i]-1LL*k*i)-b.begin();
		res+=get(x);
		upd(x);
	}
	cout<<res<<'\n';
}




Measured memory_bytes: 7992
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[][] map = Enumerable.Range(0, hw[0]).Select(_ => Console.ReadLine().Select(x => x == '.' ? int.MaxValue - 2 : int.MaxValue - 1).ToArray()).ToArray();
        int count = hw[0] * hw[1];
        for (int i = 0; i < hw[0]; i++)
        {
            for (int j = 0; j < hw[1]; j++)
            {
                if (map[i][j] == int.MaxValue - 1)
                {
                    count--;
                }
            }
        }
        map[0][0] = 1;
        bool flag = true;
        while (flag)
        {
            flag = false;
            for (int i = 0; i < hw[0]; i++)
            {
                for (int j = 0; j < hw[1]; j++)
                {
                    if (map[i][j] != int.MaxValue - 1)
                    {
                        int min = int.MaxValue;
                        if (i != 0)
                        {
                            min = Math.Min(min, map[i - 1][j] + 1);
                        }
                        if (i != hw[0] - 1)
                        {
                            min = Math.Min(min, map[i + 1][j] + 1);
                        }
                        if (j != 0)
                        {
                            min = Math.Min(min, map[i][j - 1] + 1);
                        }
                        if (j != hw[1] - 1)
                        {
                            min = Math.Min(min, map[i][j + 1] + 1);
                        }

                        if(min < map[i][j])
                        {
                            if(i == hw[0] - 1 && j == hw[1] - 1)
                            {
                                Console.WriteLine(count - min);
                                return;
                            }
                            flag = true;
                            map[i][j] = min;
                        }
                    }
                }
            }
        }
        Console.WriteLine(-1);
    }    
}

Measured memory_bytes: 13524
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

int main(){

    int H, W;
    cin >> H >> W;

    
    char A[H][W];
    queue < pair <int, int> > Q;

    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            cin >> A[i][j];
            if (A[i][j] == '#'){
                Q.push(make_pair(i, j));
            }
        }
    }

    int ans = 0;
    int x[4] = {0, 0, -1, 1};
    int y[4] = {-1, 1, 0 ,0};

    vector < pair<int, int> > N;

    while(Q.empty() == false){
        
        int qx = Q.front().first;
        int qy = Q.front().second;
        Q.pop();

        for (int i = 0; i < 4; i++){
            int dx = x[i], dy = y[i];
            int X = qx + dx, Y = qy + dy;
            
            if (0 <= X && X < H && 0 <= Y && Y < W && A[X][Y] == '.'){
                A[X][Y] = '#';
                N.push_back( make_pair(X, Y) );
            }
        }

        if (Q.empty() == true){
            if (N.empty() == true){
                break;
            }else{
                ans ++;
                for (int i = 0; i < N.size(); i++){
                    Q.push( make_pair(N[i].first, N[i].second) );
                }
                N.clear();
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
	
	ll ans = 100000;
	ll n;
	cin >> n;
	FOR(i,0,n){
		ans *= 105;
		ans /= 100;
		if(ans%1000){
			ans /= 1000;
			ans *= 1000;
			ans += 1000;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void set_square(int x, int y, int k, vector<vector<int>> &imos){
    if(x<0 || y<0) return;
    imos[ max(0, x-k+1) ][ max(0, y-k+1) ] += 1;
    imos[ max(0, x-k+1) ][y+1] -= 1;
    imos[x+1][ max(0, y-k+1) ] -= 1;
    imos[x+1][y+1] += 1;
}

void set_imos(int x, int y, int k, vector<vector<int>> &imos){
    set_square(x, y, k, imos);
    set_square(x+k, y-k, k, imos);
    set_square(x-k, y-k, k, imos);
    set_square(x+k, y+k, k, imos);
    set_square(x-k, y+k, k, imos);
    set_square(x, y+2*k, k, imos);
}

int main(){
    int n, k; cin >> n >> k;
    // 入力を受け取り、扱いやすいように希望を同値変形して座標を圧縮する
    // 具体的には全ての希望を、「(x,y)∈[0,2k)*[0,2k)を黒に塗りたいな」という希望に同値変形する
    vector<int> x(n), y(n);
    rep(i, 0, n){
        cin >> x[i] >> y[i];
        char c; cin >> c;
        if(c=='W') x[i] += k;
        x[i]%=2*k; y[i]%=2*k;
    }

    // 市松模様は[0,2k)*[0,2k)のどこを黒い部分の左下にするかという情報で一意に定まる（全単射）ので、そのように表す
    // imos[i][j] := (i,j)が黒い部分の左下になるような市松模様を塗った時に叶えられる希望の数
    vector<vector<int>> imos(5*k+5, vector<int>(5*k+5, 0));
    rep(i, 0, n){
        // (x[i],y[i])を黒に塗れるような市松模様(X, Y)について、最後に累積した時に imos[X][Y]+=1 になるように重みを加算する
        set_imos(x[i], y[i], k, imos);
    }

    // 左→右へ累積
    rep(i, 0, 2*k) rep(j, 1, 2*k) imos[i][j] += imos[i][j-1];
    // （問題文の画像で）下→上へ累積
    rep(j, 0, 2*k) rep(i, 1, 2*k) imos[i][j] += imos[i-1][j];

    // 最大値の検索
    int ans=0;
    rep(i, 0, 2*k) rep(j, 0, 2*k) chmax(ans, imos[i][j]);

    cout << ans << '\n';
    return 0;
}


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

using namespace std;

int d;
int c[26];
int s[365][26];

int score(vector<int> ans){
    vector<int> last(26,-1);
    int r = 0;
    for(int i = 0;i < ans.size();i++){
        r += s[i][ans[i]];
        last[ans[i]] = i;
        for(int j = 0;j < 26;j++){
            r -= c[j]*(i-last[j]);
        }
    }
    return r;
}

void sb(){
    vector<int> ans;
    int a;
    for(int i = 0;i < d;i++){
        cin >> a;
        ans.push_back(a-1);
        cout << score(ans) << endl;
    }
}

int main(){
    int i,j;
    cin >> d;
    for(i = 0;i < 26;i++) cin >> c[i];
    for(i = 0;i < d;i++){
        for(j = 0;j < 26;j++){
            cin >> s[i][j];
        }
    }
    sb();
    //sc();
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    int h,w,d;cin>>h>>w>>d;
    int col[2000][2000];
    if(d%2==1){
        rep(i,0,2000){
            rep(j,0,2000){
                if(i%2!=j%2)continue;
                if(i%2==0)col[i][j]=1;
                else col[i][j]=2;
            }
        }
    }
    else{
        for(int i=0;i<2000;i+=2){
            for(int j=0;j<2000;j+=2){
                int f=i/d,g=j/d;
              f%=2;g%=2;
                if(f==0){
                    if(g==0)col[i][j]=1;
                    else col[i][j]=2;
                }
                else{
                    if(g==0)col[i][j]=4;
                    else col[i][j]=3;
                }
            }
        }
        for(int i=1;i<2000;i+=2){
            for(int j=1;j<2000;j+=2){
                col[i][j]=col[i-1][j-1];
            }
        }
    }
    char out[4]={'R','G','Y','B'};
    rep(i,0,h){
        rep(j,0,w){
            int s=i+j;
            int t=i-j+1000;
            cout<<out[col[s][t]-1];
        }
        cout<<endl;
    }
    
}



Measured memory_bytes: 16128
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ayR = new int[n];
        int[] axB = new int[n];
        
        Map<Integer, Integer> xyR = new HashMap<Integer, Integer>();
        Map<Integer, Integer> xyB = new HashMap<Integer, Integer>();
        
        
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            ayR[i] = sc.nextInt();
            xyR.put(ayR[i], x);
        }
        for (int i = 0; i < n; i++) {
            axB[i] = sc.nextInt();
            xyB.put(axB[i], sc.nextInt());
        }
        Arrays.sort(axB);
        Arrays.sort(ayR);
        int count = 0;
        boolean[] r = new boolean[n];
        
        for (int i = 0; i < n; i++) {
            int xB = axB[i];
            int yB = xyB.get(xB);
            
            for (int j = n-1; j >= 0; j--) {
                int yR = ayR[j];
                int xR = xyR.get(yR);
                if (!r[j] && xR < xB && yR < yB) {
                    r[j] = true;
                    count++;
                    break;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 22228
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

#define loop(i,first,end) for(int i=(first);i<(end);i++)
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define vint vector<int>
#define vuint vector<unsigned int>
#define vull vector<ull>
#define vll vector<ll>

const ull mod = 1000000007ULL;
const ull INF = (ull)(-1LL);

int main(void){
	uint n;
	cin >> n;
	vuint p(n);
	uint count = 0;
	loop(i, 0, n){
		cin >> p[i];
		if (p[i] != i + 1)count++;
	}
	cout << (count <= 2 ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#define sz(x) ((ll)(x).size());
#define pb push_back;
#define all(x) (x).begin(),(x).end()
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N, M; cin >> N >> M;
    vvll e(N+1, vll(0));
    for(int i=0; i<M; i++){
        ll a, b; cin >> a >> b;
        e[a].emplace_back(b);
        e[b].emplace_back(a);
    }
    vll pr(N+1, 0);
    vb ald(N+1, false);
    ald[1] = true;
    queue<ll> q;
    q.push(1);
    while(!q.empty()){
        ll p = q.front();
        q.pop();
        
        for(auto x: e[p]){
            if(ald[x] == false){
                q.push(x);
                ald[x] = true;
                pr[x] = p;
            }
        }
    }
    cout << "Yes" << endl;
    for(int i=2; i<N+1; i++){
        cout << pr[i] << endl;
    }
}

Measured memory_bytes: 12868
import java.util.*;

public class Main {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        DoubleList[] lists = new DoubleList[n];
        for (int i = 0; i < n; i++) {
            lists[i] = new DoubleList(i);
        }
        if (n == 1) {
            System.out.println(lists[0].idx + 1);
            return;
        }
        int prev = sc.nextInt() - 1;
        int start = prev;
        for (int i = 1; i < n; i++) {
            int x = sc.nextInt() - 1;
            lists[prev].right = x;
            lists[x].left = prev;
            prev = x;
        }
        int end = prev;
        for (int i = 0; i < q; i++) {
            int idx = start;
            int x = sc.nextInt() - 1;
            if (x == end) {
                end = lists[x].left;
                lists[end].right = -1;
                lists[x].left = -1;
                lists[x].right = start;
                lists[start].left = x;
                start = x;
            } else if (x == start) {
                start = lists[x].right;
                lists[start].left = -1;
                lists[x].right = -1;
                lists[x].left = end;
                lists[end].right = x;
                end = x;
            } else {
                lists[end].right = x;
                lists[start].left = x;
                int nextEnd = lists[x].left;
                int nextStart = lists[x].right;
                lists[x].right = start;
                lists[x].left = end;
                end = nextEnd;
                start = nextStart;
                lists[start].left = -1;
                lists[end].right = -1;
            }
        }
        int idx = start;
        StringBuilder sb = new StringBuilder();
        while (idx != -1) {
            if (idx != start) {
                sb.append(" ");
            }
            sb.append(lists[idx].idx + 1);
            idx = lists[idx].right;
        }
        System.out.println(sb);
    }
    
    static class DoubleList {
        int idx;
        int left;
        int right;
        
        public DoubleList(int idx) {
            this.idx = idx;
            this.left = -1;
            this.right = -1;
        }
    }
}


Measured memory_bytes: 105352
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	char s[81],c;
	int l,p;
	while(gets(s)!=NULL){
		l=strlen(s);
		while(strstr(s,"the")==NULL && strstr(s,"that")==NULL && strstr(s,"this")==NULL){
			rep(i,l){
				if(in(s[i],'a','z')){
					s[i]++;
					if(s[i]>'z')s[i]-=26;
				}
			}
		}
		puts(s);
	}
	return 0;
}

Measured memory_bytes: 1096
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int ans;
    static int count;

    public static void main(String[] args) {
        int times = sc.nextInt();

        for (int i = 0; i < times; i++) {

            count = 0;



            int num = sc.nextInt();



            KAKESAN(num, false);



            System.out.println(count);
        }
    }

    static void KAKESAN(int num, boolean endFlg) {
        ans = 0;
        int disit = String.valueOf(num).length();

        if (disit == 1) {
            endFlg = true;
        }

        if (!endFlg) {
            for (int j = 0; j < disit - 1; j++) {

                String numStringA = String.valueOf(num).substring(0, j + 1);
                String numStringB = String.valueOf(num).substring(j + 1, disit);

                int tmp = Integer.parseInt(numStringA)
                        * Integer.parseInt(numStringB);

                if (tmp > ans) {
                    ans = tmp;
                }
            }
            count++;
            KAKESAN(ans, false);
        }
    }
}

Measured memory_bytes: 31388
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int>m(5);
    for(int i=0;i<5;i++){
        cin>>m[i];
    }

    vector<int>n(5);
    for(int i=0;i<5;i++){
        if(m[i]%10==0){
            n[i]=0;
        }
        else {
            n[i]=10-m[i]%10;
        }
    }

    sort(n.begin(),n.end());

    cout<<n[0]+n[1]+n[2]+n[3]+m[0]+m[1]+m[2]+m[3]+m[4]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int maxn = 200006;
#define _for(i,a,b) for(int i=a;i<=b;i++)
int n;
long long a[maxn],ans;
int main(int argc, char const *argv[])
{
    cin>>n;
    _for(i,1,n)cin>>a[i];
    long long k = 0;
    long long now = 0;
    int l = 1;
    int r = 1;
    long long next = 0;
    while(l<=n+1&&r<=n+1)
    {

        if(now==k)
        {          
            ans+=next;
            next++;
            k+=a[r];
            now=now^a[r];
            r++;
        }
        else
        {
            next--;
            k-=a[l];
            now=now^a[l];
            l++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int nax = 3e5 + 10;
char s[nax];
int n;
int sum[nax];


/**
    1000111100011100100111

    10000000111|1000001111
    1111111111100000000111
*/

int main () {
    scanf("%d", &n);
    scanf("%s", s + 1);


    for (int i = 1 ; i <= n ; ++ i) {
        sum[i] = sum[i - 1] + (s[i] == 'R' ? 1 : 0);
    }

    if (sum[n] == n || sum[n] == 0) {
        return !printf("0");
    }

    int ans = INT_MAX;
    ///let's say last 1 is at i

    for (int i = 1 ; i <= n ; ++ i) {
        int one_here = sum[i];
        int zero_here = i - sum[i];

        int one_from = sum[n] - sum[i];
        int ct = 0;
        ct += min(zero_here, one_from);
        zero_here -= ct, one_from -= ct;
        ct += max(zero_here, one_from);
        ans = min(ans, ct);
    }
    printf("%d\n", ans);

}


Measured memory_bytes: 4820
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


n = ip()                              #入力整数1つ
#a,b= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)


#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s = a[0]
for i in range(1,n):
    s = fractions.gcd(s,a[i])
print(s)

Measured memory_bytes: 25352
#include <iostream>
#include <cctype>
#include <string>
using namespace std;

int main(){
	string s;
	int a, b;
	
	cin >> a >> b;
	cin >> s;
	
	for (int i=0; i<s.size(); i++){
		if (i==a){
		   if (s[i]!='-'){
		      cout<< "No";
		      return 0;
		   }
		}
		else if (!isdigit(s[i])) {
		   cout << "No";
		   return 0;
	    }
	} 
	
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a,c=[],[]
for _ in range(m):
  a.append(list(map(int,input().split()))[0])
  c.append(sum((1<<(int(i)-1)) for i in input().split()))
inf=float('inf')
# dp[i]: 状態がbin(i)の時のの費用の最小値
# bin(i)のj桁が1: j番目の宝箱を開けることが可能
dp=[inf]*(1<<n)
dp[0]=0
for i in range(2**n):
  for j in range(m):
    dp[i|c[j]]=min(dp[i|c[j]],dp[i]+a[j])
print(dp[-1] if inf!=dp[-1] else-1)

Measured memory_bytes: 45272
a,b,m=map(int,input().split())
fri=list(map(int,input().split()))
mic=list(map(int,input().split()))
wari=[list(map(int,input().split())) for i in range(m)]
mi=min(fri)+min(mic)
for i in range(m):
    if fri[wari[i][0]-1]+mic[wari[i][1]-1]-wari[i][2]<mi:
        mi=fri[wari[i][0]-1]+mic[wari[i][1]-1]-wari[i][2]
print(mi)


Measured memory_bytes: 38568
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;

signed main() {
  ll K;
  cin >> K;
  ll sum = 0;
  rep(i, K) {
    rep(j, K) {
      rep(k, K) {
        ll g = gcd(gcd(i + 1, j + 1), k + 1);
        sum += g;
      }
    }
  }
  COUT(sum);
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll= long long;
using ld= long double;
using vi= vector<int>;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vvi= vector<vector<int>>;
using vvl= vector<vector<ll>>;
using vvd= vector<vector<ld>>;
using vvs= vector<vector<string>>;
using vvb= vector<vector<bool>>;
using pll= pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

template <class T>
inline void chmin(T &a, T b) {
    if(a > b) { a= b; }
}

template <class T>
inline void chmax(T &a, T b) {
    if(a < b) { a= b; }
}

    int op(int a, int b) { return max(a, b); };
    int e() { return (int)(0); };
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    segtree<int, op, e> seg(300001);
    REP(i, N) {
        seg.set(A[i], seg.prod(max(0, A[i] - K), min(300001, A[i] + K + 1)) + 1);
    }
    cout << seg.all_prod() << "\n";
}

Measured memory_bytes: 9832
#include <vector>
#include <algorithm>
#include <iostream>
#include <chrono>
#include<bitset>
#include<deque>
#include <map>
#define vint vector<int>
#define vint2 vector<vint>
#define vchar vector<char>
#define vchar2 vector<vchar> 
#define vchar3 vector<vchar2> 
#define pr pair<int,int>
#define vpr vector<pr>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
typedef  long long int ll;
using namespace std;
//CHAR_BIT	ビット フィールドではない最小変数のビット数。	8
//SCHAR_MIN	signed char 型変数の最小値。	–128
//SCHAR_MAX	signed char 型変数の最大値。	127
//UCHAR_MAX	unsigned char 型変数の最大値。	255 (0xff)
//CHAR_MIN	char 型変数の最小値。 - 128、 / J オプション使用時は 0
//CHAR_MAX	char 型変数の最大値。	127、 / J オプション使用時は 255
//MB_LEN_MAX	多文字定数の最大バイト数。	5
//SHRT_MIN	short 型変数の最小値。	–32768
//SHRT_MAX	short 型変数の最大値。	32767
//USHRT_MAX	unsigned short 型変数の最大値。	65535 (0xffff)
//INT_MIN	int 型変数の最小値。	–2147483647 – 1
//INT_MAX	int 型変数の最大値。	2147483647
//UINT_MAX	unsigned int 型変数の最大値。	4294967295 (0xffffffff)
//LONG_MIN	long 型変数の最小値。	–2147483647 – 1
//LONG_MAX	long 型変数の最大値。	2147483647
//ULONG_MAX	unsigned long 型変数の最大値。	4294967295 (0xffffffff)




int  main(){
	ll N, A, B;
	cin >> N >> A >> B;
	if (A > B){ cout << 0 << endl; return 0; }
	if (A == B){ cout << 1 << endl; return 0; }
	if (N == 1){ cout << 0 << endl; return 0; }
	cout << (1 + (N - 2)*(B - A))<<endl;
	


	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;


using R=double;
using edge=struct{int to;};
using G=vector<vector<edge>>;
const R inf=1e60;

using P=tuple<R,int>;
vector<P> points;
inline R distance(P a,P b){
	R ax,bx;
	int ay,by;
	tie(ax,ay)=a,tie(bx,by)=b;
	return sqrt(max<R>(0.0,(bx-ax)*(bx-ax)+1.0*(by-ay)*(by-ay)));
}

int main(void){
	int n;
	while(cin >> n,n){
		set<int> altitude;
		int x[110],y[110];
		rep(i,n) cin >> x[i] >> y[i],altitude.insert(y[i]);

		points.clear();
		rep(i,n) points.push_back(P(x[i],y[i]));
		rep(i,n-1){
			int ly=y[i],hy=y[i+1];
			if(ly>hy) swap(ly,hy);
			for(auto &ny:altitude){
				if(ly < ny && ny < hy){
					R nx=1.0*x[i]+1.0*(ny-y[i])/(y[i+1]-y[i])*(x[i+1]-x[i]);
					points.push_back(P(nx,ny));
				}
			}
		}

		uniq(points);
		
		const int m=points.size(),n=m*m,s=m-1;
	   	map<int,R> dist;
	    using state=tuple<R,int>;
	    priority_queue<state,vector<state>,greater<state>> q;
	    dist[s]=0,q.push(state(0,s));
	     
	    while(!q.empty()){
	        R c; int v;
	        tie(c,v)=q.top();q.pop();
	        int i=v/m,j=v%m;
	        rep(a,3)rep(b,3){
				if(a==1&&b==1) continue;
				const int ni=i+(a-1),nj=j+(b-1);
				if(ni<0||m<=ni) continue;
				if(nj<0||m<=nj) continue;
				if(get<1>(points[ni])!=get<1>(points[nj])) continue;
				const int nv=m*ni+nj;
				R nc=c+distance(points[i],points[ni])+distance(points[j],points[nj]);
				if(dist.find(nv)==end(dist)) dist[nv]=inf;
				if(chmin(dist[nv],nc)) q.push(state(nc,nv));
			}
	    }

		R ans=inf;
		rep(i,m) if(dist.find(m*i+i)!=end(dist)) chmin(ans,dist[m*i+i]);
		cout.precision(20);
		cout << fixed << ans << endl;
	}	
	return 0;
}

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

int main(){
	int n; cin>>n;
	vector<int> a(n);
	vector<int> b(n-1);
	rep(i,n-1) cin>>b[i];
	a[0]=b[0];
	for(int i=1; i<n; i++){
		a[i]=min(b[i-1],b[i]);
	}
	a[n-1]=b[n-2];
	cout<<accum(a)<<endl;
}

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

int main(){
    string s;
    cin >> s; 
    vector<string> t = {
        "hi",
        "hihi",
        "hihihi",
        "hihihihi",
        "hihihihihi"
    };
    bool flag = false;
    for(auto x:t){
        if(s == x) flag = true;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define srep(i) for(int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
const int MOD = 1000000009;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

int bit_cnt(int n, int v) {
    int cnt = 0;
    while(n / v != 0) {
        n /= v;
        cnt++;
    }
    cnt++;
    return cnt;
}

int main() {
    int N, K;
    cin >> N >> K;
    cout << bit_cnt(N, K) << endl;
}

Measured memory_bytes: 256
mod = 998244353 #出力の制限
# コンビネーション
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 10**6 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, A, B, K = map(int, input().split())

ans = 0
for n in range(N+1):
    m = (K-n*A)//B
    if (K-n*A)%B == 0 and 0 <= m <= N:
        ans += cmb(N, m)*cmb(N, n) % mod
        ans %= mod
print(ans)

Measured memory_bytes: 122052
#include <iostream>

using namespace std;

int a = 0, b = 0, c = 0, tmp = 0;

int main()
{
	cin >> a >> b >> c;

	if ( a > b ){
	
		tmp = a;
		a = b;
		b = tmp;
	};

    if ( b > c ){

		tmp = b;
		b = c;
		c = tmp;
	};

	if ( a > b ){

		tmp = a;
		a = b;
		b = tmp;
	};
	
	cout <<a<<" "<<b<<" "<<c<<endl;

	return 0;
}

Measured memory_bytes: 1168
INF=int(1e9)

while 1:
  n,m,p=map(int,input().split())
  if (n,m,p)==(0,0,0): break
  es=[]
  for i in range(m):
    u,v,w=map(int,input().split())
    es.extend([(u,v,w),(v,u,w)])
  
  d=[[INF]*n for _ in range(n)]
  for i in range(n): d[i][i]=0
  for e in es: d[e[0]][e[1]]=e[2]
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  
  dp=[[0]*n for _ in range(n)]
  for e in es:
    if d[0][e[0]]+e[2]+d[e[1]][-1]==d[0][-1]:
      dp[e[0]][e[1]]=1
  for k in range(n):
    for i in range(n):
      for j in range(n):
        dp[i][j]+=dp[i][k]*dp[k][j];
  
  for _ in range(p):
    c=int(input())
    print("{:.9f}".format(dp[0][c]*dp[c][-1]/dp[0][-1]))

Measured memory_bytes: 7836
<>;
for(<>){
	/ /;
	$C=int(sqrt($`*$'));
	$C-=$C*$C==$`*$';
	if($C*($C+1)>=$`*$'){
		print$C*2-2,$/
	}else{
		print$C*2-($`!=$'),$/
	}
}


Measured memory_bytes: 512