akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
int H,W,i,j;
 
while(1){
scanf("%d %d",&H,&W);
if((H==0)&&(W==0))break;
else if((H!=0)&&(W!=0)){
for(i=0;i<H;i++){
for(j=0;j<W;j++){
printf("#");
}
printf("\n");
}
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    string S;  cin >> S;
    int n = S.length() - 1;
    ll sum = 0;

    for(int bits = 0 ; bits < (1 << n) ; bits++){
      ll keep = 0;
      for(int i = 0 ; i <= n ; i++){
        keep *= 10;
        keep += (S[i] - '0');
        if(bits & (1 << i)){
          sum += keep;
          keep = 0;
        }
      }
      sum += keep;
    }

    cout << sum << endl;
	return 0;
}

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

using namespace std;

const int N = 1000 * 1000 + 7;

int nxt[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        nxt[i] = x;
    }
    vector<bool> visited(n + 1, false);
    int current_town = 1;
    while (!visited[current_town]) {
        visited[current_town] = true;
        current_town = nxt[current_town];
    }
    int length_cycle = 0;
    fill(visited.begin(), visited.end(), false);
    int temp_current_town = current_town;
    while (!visited[temp_current_town]) {
        visited[temp_current_town] = true;
        temp_current_town = nxt[temp_current_town];
        ++length_cycle;
    }
    temp_current_town = 1;
    while (temp_current_town != current_town && k) {
        temp_current_town = nxt[temp_current_town];
        --k;
        if (k == 0) {
            cout << temp_current_town << "\n";
            return 0;
        }
    }
    k %= length_cycle;
    while (k) {
        current_town = nxt[current_town];
        --k;
        if (k == 0) {
            break;
        }
    }
    cout << current_town << "\n";
    return 0;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int dp[9];
    int n,a,F =0;
    for(int i=0; i<9; i++) cin>>dp[i];
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a;
        for(int j=0; j<9; j++)
            if(dp[j]==a) dp[j]=0;
    }
    if(dp[0]==0&&dp[4]==0&&dp[8]==0) F=1;
    else if(dp[2]==0&&dp[4]==0&&dp[6]==0)F=1;
    for(int i=0; i<3; i++)
        if(dp[i]==0&&dp[i+3]==0&&dp[i+6]==0) F=1;
    for(int i=0; i<7; i+=3)
        if(dp[i]==0&&dp[i+1]==0&&dp[i+2]==0) F=1;
    F?cout<<"Yes"<<endl:cout<<"No"<<endl;
}


Measured memory_bytes: 3612
q, h, s, d = list(map(int, input().split())) #個数が少ない場合
N = bin(4*int(input()))[2:]
keta0 = int(N[-1])
keta1 = 0
keta2 = 0
keta3 = 0

if len(N) >1:
    keta1 = int(N[-2])
if len(N) >2:
    keta2 = int(N[-3])
if len(N) >3:
    for i in range(len(N) -3):
        keta3 += int(N[-(i+4)])*2**i
keta = [keta0, keta1, keta2, keta3]

a = [[q*8 ,q, 0], [h*4, h, 1], [s*2,s, 2], [d,d, 3]]
a.sort(key=lambda x:x[0])
ans = 0
for i in a:
    for j in range(i[2],4):
        ans += i[1]*keta[j]*2**(j-i[2])
        keta[j] = 0
print(ans)


Measured memory_bytes: 3064
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ss := make([]int, m)
	cs := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&ss[i], &cs[i])
	}

	max := int(math.Pow(10.0, float64(n)))
	for i := 0; i < max; i++ {
		str := strconv.Itoa(i)
		if len(str) != n {
			continue
		}
		ok := true
		for j := 0; j < m; j++ {
			if str[ss[j]-1]-'0' != byte(cs[j]) {
				ok = false
			}
		}
		if ok {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(-1)
}


Measured memory_bytes: 1836
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pob pop_back
#define ft first
#define sc second
#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define ctz __builtin_ctz
typedef pair<int, int> pii;
const int maxn = 1e6;
 
string str[3] ,res;

int main()
{FAST;
    cin >> str[0] >> str[1] >> str[2];
    res = str[0][0];res += str[1][1] ,res+= str[2][2];
    cout << res;
   return 0;
}
 












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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}


int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	cin >> N;
	string s="";
	while(N){
		if(N%2) s = "1"+s;
		else s = "0"+s;
		if(N%2){
			N--;
		}
		N = N/-2;
	}
	if(s.size() == 0) s = "0";
	cout << s << endl;
}


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

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> a(n);
    for (auto& e : a) cin >> e;

    int64_t ans = 0;
    for (int64_t l = 0, r = 0, x = 0; l < n; l++) {
        while (r < n && (x ^ a[r]) == (x + a[r])) x += a[r++];
        ans += r - l;

        if (l == r) r++; else x -= a[l];
    }

    cout << ans << endl;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> mine(H, vector<char>(W));
  
  rep(i,H){
    rep(j,W){
      cin >> mine.at(i).at(j);
    }
  }
  
  
  rep(i,H){
    rep(j,W){
      if(mine.at(i).at(j) == '.'){
        int count = 0;
        rep(k,3){
          rep(l,3){
            if(i+k-1 >= 0 && j+l-1 >= 0 && i+k-1 < H && j+l-1 < W){
              if(mine.at(i+k-1).at(j+l-1) == '#'){
                count++;
              }
            }
          }
        }
        
        cout << count;
      
      }else{
        cout << '#';
      }
      
    }
    cout << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;


int main(){
  long int N;
  long int K;  
  cin >> N;
  cin >> K;
  long int a;
  vector<long int> A(N);
  fill(A.begin(),A.end(),0);
  for(int i=0;i<N;i++){
    cin >> a;
    A[a-1]+=1;
  }
  sort(A.begin(), A.end(),greater<long int>() );
  long int sum=0;
  for(int i=0;i<K;i++){
    sum+=A[i];
  }
  if(sum==N) cout << 0<< endl;
  else cout << N-sum <<endl;
  return 0;
}


Measured memory_bytes: 1792
while line = gets
  n = line.chomp.to_f
  break if n < 0

  i = n.to_i
  f = n - i

  a = []
  8.times do
    a.unshift(i % 2)
    i /= 2
  end

  if i > 0
    puts :NA
    next
  end

  b = []
  4.times do
    f *= 2
    b << f.to_i
    f -= f.to_i
  end

  if f > 0
    puts :NA
    next
  end

  puts "#{a.join}.#{b.join}"
end

Measured memory_bytes: 8856
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main() {

	int h, n;
	cin >> h >> n;
	int ans = 0;
	rep(i, n) {
		int a;
		cin >> a;
		ans += a;
	}

	if (ans >= h)cout << "Yes" << endl;
	else	cout << "No" << endl;

}

Measured memory_bytes: 256
word = list(map(int,input().split()))
ten = [0]*word[0]
for i in range(word[0]):
    ten[i] = list(map(int,input().split()))

answer = 0
for j in range(word[0]):
    if ten[j][0]**2 + ten[j][1]**2 <= word[1]**2:
        answer += 1

print(answer)

Measured memory_bytes: 93144
<?php
fscanf(STDIN, '%s', $string);
$input_text = strtoupper($string);
$length = strlen($input_text);
$output_text = '';
for ($i = 0; $i < $length; ++$i) {
    if ($input_text[$i] == 'B') {
        $output_text = substr($output_text, 0, -1);
    } else {
        $output_text .= $input_text[$i];
    }
}
echo "$output_text\n";

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main()
{
	string s;
	int k;
	cin >> s;
	cin >> k;
	int n = s.size();
	vector<vector<vector<long long int>>> dp(n+1, vector<vector<long long int>>(2, vector<long long int>(5, 0)));
	dp[0][0][0] = 1;
	rep(i, n)
	{
		int D = s[i] - '0';
		rep(j, 2)
		{
			rep(k,5){
				for (int d = 0; d <= (j ? 9 : D);d++){
					if (d == 0){
						// cout << "test" << endl;
						dp[i + 1][j || (d < D)][k] += dp[i][j][k];
					}
					else{
						// cout << "test2" << endl;
						dp[i + 1][j || (d < D)][min(k + 1, 4)] += dp[i][j][k];
					}
						
				}
			}
		}
	}
	cout << dp[n][0][k] + dp[n][1][k] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

void solve() {
  int n;
  cin >> n;
  set<int> s;
  int tot = 0;
  for(int i = 1; tot < n; i++) {
    s.insert(i);
    tot += i;
  }
  s.erase(tot-n);
  for(int out: s) cout << out << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, h, w; cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w);
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b,q;
	cin >> a >> b >> q;
	vector<ll> s(a), t(b);
	REP(i,a) cin >> s[i];
	REP(i,b) cin >> t[i];

	REP(qq,q){
		ll x;
		cin >> x;

		auto s_itr = lower_bound(ALL(s), x);
		ll sl = (s_itr!=s.begin() ? *(s_itr-1) : -3e10);
		ll sr = (s_itr!=s.end() ? *s_itr : 3e10);

		auto t_itr = lower_bound(ALL(t), x);
		ll tl = (t_itr!=t.begin() ? *(t_itr-1) : -3e10);
		ll tr = (t_itr!=t.end() ? *t_itr : 3e10);

		ll ans = 1e18;
		ans = min(ans, abs(sl-tl) + min(x-sl, x-tl)); 
		ans = min(ans, (tr-sl) + min(x-sl, tr-x));
		ans = min(ans, (sr-tl) + min(sr-x, x-tl));
		ans = min(ans, abs(sr-tr) + min(sr-x, tr-x));
		cout << ans << '\n';
	}
	
	return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<int> A(N+1,0);

    int a;
    for(int i=2; i<=N; i++) {
        cin >> a;
        A.at(a)++;
    }

    for(int i=1; i<=N; i++) {
        cout << A.at(i) << endl;
    }
}

Measured memory_bytes: 4048
import sys
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
x.sort()
d=[]
for i in range(m-1):
    d.append(x[i+1]-x[i])
d.sort()
if n==1:
    print(sum(d))
else:
    print(sum(d[:-n+1]))

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

void bfs(vector<vector<int>> &g, int n) {
	int start = 0;
	vector<int> dist(n, -1);	//startからの距離を格納。未訪問は-1
	queue<int> que;
	dist[start] = 0;
	que.push(start);
	while(!que.empty()) {
		int v = que.front();
		que.pop();
		for(int nv: g[v]) {
			if(dist[nv] != -1) continue;
			dist[nv] = dist[v] + 1;
			que.push(nv);
		}
	}
}

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			if(s[i][j] == '#') continue;
			vector<vector<int>> dist(h, vector<int>(w, -1));	//startからの距離を格納。未訪問は-1
			queue<pair<int, int>> que;
			dist[i][j] = 0;
			que.push({i, j});
			while(!que.empty()) {
				pair<int, int> v = que.front();
				int iv = v.first;
				int jv = v.second;
				que.pop();
				rep(k, 4) {
					int niv = iv + dx[k];
					int njv = jv + dy[k];
					if(niv < 0 || niv >= h) continue;
					if(njv < 0 || njv >= w) continue;
					if(s[niv][njv] == '#') continue;
					if(dist[niv][njv] != -1) continue;
					dist[niv][njv] = dist[iv][jv] + 1;
					que.push({niv, njv});
				}
			}
			rep(p, h) rep(q, w) {
				ans = max(ans, dist[p][q]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n,s = map(int, input().split())
a = list(map(int, input().split()))


dp = [[0] * (s + 1) for _ in range(n+1)]


for i in range(1, n+1):
    for j in range(1, s+1):
        if a[i-1] > j:
            dp[i][j] = dp[i-1][j]
        elif a[i-1] == j:
            dp[i][j] = (dp[i-1][j] + i)%998244353
        else:
            dp[i][j] = (dp[i-1][j] + dp[i-1][j-a[i-1]])%998244353

ans = 0

for i in range(1, n+1):
    ans += dp[i][s]
    ans %= 998244353


print(ans)

Measured memory_bytes: 112476
import re

l = list(map(int, input().split()))
a = l[0]
b = l[1]

s = input()

fi = re.findall("-", s)

if len(fi) != 1:
    print("No")
    quit()

index = s.find("-")

for i, c in enumerate(s):
    if i == a:
        if c != "-":
            print("No")
            quit()

    else:
        if c.isdigit() == False:
            print("No")
            quit()

print("Yes")


Measured memory_bytes: 3188
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;


int main()
{
	int k, x; cin >> k >> x;
	for (int i = -1000000; i <= 1000000; i++) {
		if (abs(i - x) < k)cout << i << " ";
	}
	cout << endl;

	return 0;
}


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

int main() {
  int n, x, y, a;
  cin >> n >> x >> y;
  vector<int> num(n, 0);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      num[min(abs(j - i), abs(y - j) + abs(x - i) + 1)]++;

  for (int i = 1; i <= n - 1; i++) cout << num[i] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
 
int main(){
 
string s;
cin >> s;
 
int sim = 1;
if (s[2]==s[3] && s[4]==s[5]) {
	cout << "Yes";
   } else {
   cout << "No";
   }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[100]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k-1] << endl;
}

Measured memory_bytes: 3580
#/usr/bin/python

def solve():
    n = int(input())
    a = sorted(map(int, input().split()), reverse=True)
    a2 = [0] * len(a) * 2
    for i in range(len(a2)):
        a2[i] = a[i//2]
        if i >= n:
            break
    a2[0] = 0
    return sum(a2[:n])

print(solve())


Measured memory_bytes: 31480
#include<stdio.h>
int main(){
    int W,H;
    int i,j;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        for(j=0;j<H;j++){
            for(i=0;i<W;i++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  int i = 0;
  vector<int> v;
  while (i <= a && i <= b) {
    i++;
    if (a % i == 0 && b % i == 0) v.push_back(i);
  }

  cout << *(v.end() - c) << endl;
}


Measured memory_bytes: 256
def main():
    N, W = map(int, input().split())
    w = [0] * N
    v = [0] * N
    for i in range(N):
        w[i], v[i] = map(int, input().split())

    max_v = max(v)
    dp = [[float('inf')] * (max_v * N + 5) for _ in range(N + 5)]

    dp[0][0] = 0

    for i in range(N):
        for j in range(max_v * N):
            if j + v[i] <= max_v * N:
                dp[i+1][j + v[i]] = min(dp[i+1][j + v[i]], dp[i][j] + w[i])
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]) 

    ans = 0
    for j in range(max_v * N + 1):
        if dp[N][j] <= W:
            ans = j

    print(ans)

if __name__ == "__main__":
    main()

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

int  main(){
  int N;
  int A[210];
  cin >> N;
  for (int i= 0; i < N; i++){
      cin >> A[i];
  }
  int res = 0;
  while (true){
    bool exist_odd = false;
  for (int i=0; i<N; i++){
    if (A[i]%2 != 0){
      exist_odd = true;
    }
  }
  if (exist_odd ) break;
  for (int i=0;i <N; i++){
    A[i]/=2;
  }

  res++;
}
cout << res << endl;
}


Measured memory_bytes: 256
import bisect

N=int(input().strip())
L=list(map(int,input().strip().split()))
L.sort()

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        
        if L[minInd]> L[i]+L[j]:
            continue
        if MAX<L[i]+L[j]:
            count+=N-1-minInd+1
        else:
            ind = bisect.bisect_left(L, L[i]+L[j])-minInd # number of < a+b
            count+=ind
        
print(count)

Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

ll INF = 1e17;
vll cost;

vvi edges;
vvi g;

int n, m;

bool bfs(int s) {
  deque<int> stk;
  stk.push_back(s);
  vector<bool> reached(n, false);
  reached[s] = true;
  while (!stk.empty()) {
    int u = stk.front();
    stk.pop_front();
    for (int v : g[u]) {
      if (reached[v]) { continue; }
      reached[v] = true;
      stk.push_back(v);
    }
  }
  return reached[n-1];
}

int main() {
  scanf("%d %d", &n, &m);
  cost.assign(n, INF);
  cost[0] = 0;

  edges.assign(m, vi(3));
  g.resize(n);
  rep (i, m) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a -= 1; b -= 1;
    edges[i][0] = a;
    edges[i][1] = b;
    edges[i][2] = -c;

    g[a].push_back(b);
  }

  rep (j, n) {
    rep (i, m) {
      auto edge = edges[i];
      int u = edge[0];
      int v = edge[1];
      if (cost[u] != INF && cost[v] > cost[u] + edge[2]) {
        cost[v] = cost[u] + edge[2];
      }
    }
  }

  vector<bool> can_reach(n);
  rep (i, n) {
    can_reach[i] = bfs(i);
  }

  rep (i, m) {
    auto edge = edges[i];
    int u = edge[0];
    int v = edge[1];
    if (cost[u] != INF && cost[u] + edge[2] < cost[v] && can_reach[u]) {
      printf("inf\n");
      return 0;
    }
  }

  printf("%lld\n", -cost[n-1]);

  return 0;
}


Measured memory_bytes: 888
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#define endl "\n"
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

#define int long long

const int nmax = 2e5+7;
const int MOD = 1e9+7;

template <class T>
T bm(T b, T p, T m ) /// Faster than recursive one
{
    T res = 1 % m, x = b % m;
    while ( p )
    {
        if ( p & 1 )
            res = ( 1LL *res * x ) % m;
        x = ( 1LL * x * x ) % m;
        p >>= 1;
    }
    return res;
}


void solveTC()
{
    int n;
    cin>>n;

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

    int ans = bm(10LL,n,MOD);
    ans -= bm(9LL,n,MOD);
    ans -= bm(9LL,n,MOD);
    ans += bm(8LL,n,MOD);

    ans = (ans%MOD)+MOD;
    ans %= MOD;

    cout<<ans<<endl;

}

int32_t main()
{
    optimizeIO();

    int tc =1;
    while(tc--)
    {
        solveTC();
    }

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


Measured memory_bytes: 3640
N = int(input())
hlist = list(map(int, input().split()))

move = 0
ans = 0
for i in range(1, N):
    if hlist[i-1] >= hlist[i]:
        move += 1
    else:
        ans = max(ans, move)
        move = 0
else:
    ans = max(ans, move)

print(ans)



Measured memory_bytes: 63856
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define INF 10000000
const int maxn = 2e5+ 5;

int n;
int a[110];
int main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
          ans=max(ans,abs(a[j]-a[i]));

        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
int d[10][10];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		d[za][zb] = d[zb][za] = 1;
	}
	vector<int>v;
	for (int i = 0; i < num; i++)v.push_back(i);
	int r = 0;
	for (;;)
	{
		bool f = true;
		for (int i = 0; i < num - 1; i++)if (d[v[i]][v[i + 1]] == 0)f = false;
		if (f&&v[0] == 0)r++;
		if (!next_permutation(v.begin(), v.end()))break;
	}
	printf("%d\n", r);
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  long long int n,a,b;
  long long int s,t,ans;
  
  cin>>n>>a>>b;
  
  s=n%(a+b);
  t=(n-s)/(a+b);
  
  ans=t*a;
  
  if(s>=a)
  {
    ans=ans+a;
  }
  else
  {
    ans=ans+s;
  }
  
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
signed main(){
	int a,b,z=INF*-1,ans=0;
	cin>>a;
	f(i,a){
		cin>>b;
		if(b<=z)ans++;
		z=b;
	}
	cout<<ans+1<<endl<<a<<endl;
}



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

int main() {
  string S;
  cin >> S;

  ll totalsum = 0;

  rep(i, (1 << S.length()-1) ){
    bitset<9> s(i);
    string sum = {S.at(0)};
    rep(j, S.length()-1 ){
      if (s.test(j)) sum.push_back('+');
      sum.push_back(S.at(j+1));
    }

    string tmp = "";
    rep (i, sum.length()){
      if (sum.at(i) == '+'){
        ll num = stoll(tmp);
        totalsum += num;
        tmp = "";
      }
      else{
        tmp.push_back(sum.at(i));
      }
    }
    ll num = stoll(tmp);
    totalsum += num;
  }
  cout << totalsum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
using namespace std;

int main(int argc,char** argv)
{

	string s;
	cin >> s;
	sort(s.begin(),s.end());
	if(s=="abc"){
		cout << "Yes" <<endl;
	}
	else{
		cout << "No" <<endl;
	}


	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;

ll N;
string s[3];
int main(){
    cin>>s[0]>>s[1]>>s[2];
    cout<<(char)toupper(s[0][0])<<(char)toupper(s[1][0])<<(char)toupper(s[2][0])<<endl;
    return 0;
}

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

int main(){
  int n,l,r;
  long a[200000],sum[200000]={},ans,maxa,mina;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%ld",&a[i]);
  sum[0]=a[0];
  for(int i=1;i<n;i++)
    sum[i]=sum[i-1]+a[i];
  l=0;
  r=2;
  ans=sum[n-1];
  for(int i=1;i<n-2;i++){
    while(l<i-1&&abs(sum[i]-2*sum[l])>abs(sum[i]-2*sum[l+1]))
      l++;
    while(r<n-2&&abs(sum[n-1]-2*sum[r]+sum[i])>abs(sum[n-1]-2*sum[r+1]+sum[i]))
      r++;
    maxa=mina=sum[l];
    maxa=max(maxa,sum[i]-sum[l]);
    maxa=max(maxa,sum[r]-sum[i]);
    maxa=max(maxa,sum[n-1]-sum[r]);
    mina=min(mina,sum[i]-sum[l]);
    mina=min(mina,sum[r]-sum[i]);
    mina=min(mina,sum[n-1]-sum[r]);
    ans=min(ans,maxa-mina);
  }
  printf("%ld\n",ans);
}

Measured memory_bytes: 3328
while True:
    H, W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H-1 or j == 0  or j == W-1:                      
                print("#", end="")
            else:
                 print(".", end="")
        print()
    print()  


Measured memory_bytes: 7004
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  string S;
  cin >> S;
  rep(i, S.size()) {
    if (S[i] == '9') {
      S[i] = '1';
    } else if (S[i] == '1') {
      S[i] = '9';
    }
  }
  cout << S << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define MAX 90
#define rep(i,n) for(int i = 0 ; i < n ; i++)

using namespace std;

int W,H;
int field[MAX][MAX];
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};

int rec(int x,int y){
  int res = 0;

  rep(i,4){
    int nx = x + dx[i];
    int ny = y + dy[i];
   
    if(0 <= nx && nx < H && 0 <= ny && ny < W){
      if(field[nx][ny]){
	field[nx][ny] = 0;
	res = max(res,rec(nx,ny)+1);
	field[nx][ny] = 1;
      }
    }
  }
  return res;
}

int main(){
  while(cin >> W >> H , W | H){
    rep(i,H){
      rep(j,W){
	cin >> field[i][j];
      }
    }

    int ans = -1;
    rep(i,H){
      rep(j,W){
	ans = max(ans,rec(i,j));
      }
    }
      
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

typedef pair<int, int> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M;
	vector<P> div;
	for (int i = 1; i*i <= M; ++i)
	{
		if (M%i == 0)
		{
			div.push_back(P(M/i,i));
			if (i*i != M)
			{
				div.push_back(P(i,M / i));
			}
		}
	}
	so(div); rev(div);
	int ok = 0;
	int ng = SZ(div);
	while (ng - ok > 1) {
		int mid = (ok + ng) / 2;
		if (div[mid].first >= N)ok = mid;
		else ng = mid;
	}
	cout << div[ok].second << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
// AtCoder_Beginner_Contest_126_C

#include <iostream>
#include<string>

using namespace std;

int main (){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    S[K-1] = S[K-1] + 0x20;

    cout << S << endl;
}

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


void solve(long long N, std::vector<std::string> S){
    map<string, ll> mp;
    rep(i, N)
        mp[S[i]]++;
    
    ll max = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr)  {
        if(max < itr->second)
            max = itr->second;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr)  {
        if(max == itr->second)
            cout << itr->first << endl;
    }
    
    
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 26752
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  map<ll,ll>b;
  for(ll i=0;i<n;i++)
  {
    b[a[i]]++;
  }
  ll sum=0;
  for(auto it=b.begin();it!=b.end();it++)sum+=(it->second)*(it->second-1)/2;
  for(ll i=0;i<n;i++)
  {
    cout<<sum-((b[a[i]]-1)*(b[a[i]])/2)+((b[a[i]]-1)*(b[a[i]]-2)/2)<<"\n";
  }
  return 0;  
}

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


int main() {
long N;
cin>>N;
N--;
string  ans="";
while(N>=0){
  long t=N%26;
  ans+=char('a'+t);
  N/=26;
  N--;
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
}


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

int main(){
  int n,wt;
  cin>>n>>wt;
  vector<long long> v(n+1),w(n+1);
  vector<long long> dp(wt+1,0);
  for(int i=1;i<=n;i++){
      cin>>w[i]>>v[i];
  }
  for(int i=0;i<=n;i++){
      for(int j=wt;j>=0;j--){
          if(w[i]<=j) dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
      }
  }
  cout<<dp[wt];

}

Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
#define debug(x) cout<<x;
    

    
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a,b,c;
    cin>>a>>b>>c;

    swap(a,b);
    swap(a,c);
    cout<<a<<' '<<b<<' '<<c<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a,b,c,k,m;
scanf("%d %d %d",&a,&b,&c);
if(c==0&&b!=0&&a!=0){
k=b;
}else if(b==0&&c!=0&&a!=0){
if(a<c){
k=a+1;
}else if(a>=c){
k=c;
}
}else if(a==0&&b!=0&&c!=0){
if(b>=c){
k=b+c;
}else if(b<c){
k=2*b+1;
}
}else if(a==0&&b==0&&c!=0){
k=1;
}else if(a==0&&c==0&&b!=0){
k=b;
}else if(b==0&&c==0&&a!=0){
k=0;
}else if(a!=0&&b!=0&&c!=0){
if((a+b)<=c){
m=c-a;
if(m==b){
	k=2*b+a;
}else if(m<b){
	k=b+c;
}else if(m>b){
	k=2*b+a+1;
}
}else{
k=b+c;
}
}
printf("%d\n",k);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <set>
using namespace std;
typedef long long int ll;

string s[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s; cin >> s;
	for(char c:s){
		int k=c-'A';
		k+=n;
		k%=26;
		cout << (char)('A'+k) ;
	}
	cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
vector<int> vec[N];
int head[N],deg[N];
int n,x,y,tot,flag,A;
struct edge{int to,next;}e[N*2];
void add(int x,int y){
	e[++tot]=(edge){y,head[x]};
	head[x]=tot;
}
int check(vector<int> vec,int ban,int lim,int sz){
	int now=sz; 
	if (ban!=-1){ 
		if (vec[ban]>lim) return 0;
		now--;
	}
	int L=0,R=sz-1;
	if (L==ban) L++;
	if (R==ban) R--;
	if (now&1){
		if (vec[R]>lim) return 0;
		R--;
		if (R==ban) R--;
	}
	while (L<=R){
		if (L==R){
			if (vec[L]>lim) return 0;
		}
		else
			if (vec[L]+vec[R]>lim) return 0;
		L++; R--;
		if (L==ban) L++;
		if (R==ban) R--;
	}
	return 1;
}
int dfs(int x,int fa,int lim){
	if (!flag) return 0;
	vec[x].resize(0);
	for (int i=head[x];i;i=e[i].next)
		if (e[i].to!=fa)
			vec[x].push_back(dfs(e[i].to,x,lim)+1);
	sort(vec[x].begin(),vec[x].end());
	int sz=vec[x].size();
	if (sz%2==0&&check(vec[x],-1,lim,sz))
		return 0;
	if (x==1&&sz%2==0)
		return flag=0,233;
	int l=0,r=sz-1,ans=-1;
	while (l<=r){
		int mid=(l+r)/2;
		if (check(vec[x],mid,lim,sz))
			ans=mid,r=mid-1;
		else l=mid+1;
	}
	/*printf("%d %d\n",x,ans);
	for (int i=0;i<vec[x].size();i++)
		printf("%d ",vec[x][i]);
	puts("");*/
	if (ans==-1)
		flag=0;
	else return vec[x][ans];
} 
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
		deg[x]++; deg[y]++;
	}
	for (int i=1;i<=n;i++)
		A+=(deg[i]-1)/2;
	int l=1,r=n,ans=0;
	while (l<=r){
		int mid=(l+r)/2;
		flag=1;
		dfs(1,1,mid);
		if (flag)
			ans=mid,r=mid-1;
		else l=mid+1;
		//printf("23333 %d %d\n",mid,flag);
	}
	printf("%d %d",A+1,ans);
}

Measured memory_bytes: 21376
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int64 {
	i, _ := strconv.Atoi(next())
	return int64(i)
}

func nextInt3() (int64, int64, int64) {
	return nextInt(), nextInt(), nextInt()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func min(nums ...int64) int64 {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x, k, d := nextInt3()
	x = abs(x)

	var ans int64
	y := min(k, x/d)
	k -= y
	x -= y * d
	if k%2 == 0 {
		ans = x
	} else {
		ans = d - x
	}
	puts(ans)
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,i,j;
	scanf("%d",&n);
	int a[200];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);

	}
	int ans = 0;
	for(i=0;i<n;i++){
		bool valid = true;
		for(j=0;j<i;j++){
			if(a[i] < a[j]){valid = false; break;}
		}
		if(valid){ans++;}
	}
	printf("%d\n",ans);
	return 0;
};

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
int a[100010],b[100010];
int main(){ _;
  int n;cin>>n;
  REP(i,n){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(b,b+n);
  int cnt=0;
  REP(i,n){
    auto pos=lower_bound(b,b+n,a[i])-b;
    if((i^pos)&1)
      cnt++;
  }
  cout<<cnt/2<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
int dp[maxn][13];
char str[maxn];
int main() {
	scanf("%s", str + 1);
	int n = strlen(str + 1);
	if (str[1] == '?') {
		for (int i = 0; i <= 9; i++) {
			dp[1][i] = 1;
		}
	} else {
		dp[1][str[1] - '0'] = 1;
	}
	for (int i = 2; i <= n; i++) {
		if (str[i] == '?') {
			for (int j = 0; j <= 9; j++) {  //当前位置 
				for (int k = 0; k <= 12; k++) { //上衣给位置 
					int t = (k * 10 + j) % 13;
					dp[i][t] = (dp[i][t] + dp[i - 1][k]) % mod;
				}
			}
		} else {
			for (int k = 0; k <= 12; k++) {
				int t = (k * 10 + (str[i] - '0')) % 13;
				dp[i][t] = (dp[i][t] + dp[i - 1][k]) % mod;
			}
		}
	}
	printf("%d\n", dp[n][5]);
	return 0;
}

Measured memory_bytes: 5504
A,B,C = map(int,input().split())
K = int(input())
count = 0

while count < K:
    if C <= B:
        C = C * 2
        count += 1
    elif B <= A:
        B = B * 2
        count += 1
    else:
        count += 1

if C > B and B > A:
    print("Yes")
else:
    print("No")

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

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=0;i<k;i++){
		if(i%2==0){
			if(a%2==1){
				b+=(a-1)/2;
				a=(a-1)/2;
			}else{
				b+=a/2;
				a/=2;
			}
		}else{
			if(b%2==1){
				a+=(b-1)/2;
				b=(b-1)/2;
			}else{
				a+=b/2;
				b/=2;
			}
		}
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

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

using namespace std;

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (b <= a)
        b <<= 1, k--;
    while (c <= b)
        c <<= 1, k--;
    if (k < 0)
        cout << "No";
    else
        cout << "Yes";

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=((int)(n)-1); i>=0; i--)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

	int b = -1, w = -1;
	bool black = false;
	vector<P> p;
	rep(i, N) {
		if (S[i]=='#' && b==-1) b = i;
		if (S[i]=='.' && b!=-1 && w==-1) w = i;
		if (S[i]=='#' && w!=-1) {
			p.push_back(P(w-b, i-w));
			b = i; w = -1;
		}
	}
	if (b!=-1 && w!=-1) {
		p.push_back(P(w-b, N-w));
	}
	int M = p.size();
	vector<int> B(M), W(M);
	rep(i, M) {
		if (i==0) B[i] = p[i].first;
		else B[i] = B[i-1] + p[i].first;
	}
	rrep(i, M) {
		if (i==M-1) W[i] = p[i].second;
		else W[i] = W[i+1] + p[i].second;
	}
	if (M==0) {
		cout << 0 << endl;
	} else if (M==1) {
		cout << min(B[0], W[0]) << endl;
	} else {
		int ans = INT_MAX;
		rep(i, M) {
			if (i==0) ans = min(ans, W[i]);
			else ans = min(ans, B[i-1]+W[i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2040
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n;
	cin >> n;
	long long l[87];
	l[0] = 2, l[1] = 1;
	for (int i = 2; i <= n; ++i) {
		l[i] = l[i - 1] + l[i - 2];
	}
	cout << l[n] << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sum=0,ans=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++) 
	 {if(s[i]!='A'&&s[i]!='C'&&s[i]!='G'&&s[i]!='T')
	   ans=max(ans,sum),sum=0;
	  else 
	   sum++;
	 }
	cout<<max(ans,sum)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long t,n,i,j,m,k;
  cin>>n>>k;
  long long a[n],b[n]={0};
  for(i=0;i<n;i++)
    cin>>a[i];
  b[0]=0;
  b[1]=abs(a[0]-a[1]);
  
  for(i=2;i<n;i++)
  {
      m=b[i-1]+abs(a[i]-a[i-1]);
      for(j=2;j<=k;j++)
      {
          if(i-j>=0)
          if(m>(b[i-j]+abs(a[i]-a[i-j])))
          m=b[i-j]+abs(a[i]-a[i-j]);
      }
      b[i]=m;
  }
             cout<<b[n-1];
  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAXN 100000+10
int n,m;
struct Node
{
	int x,y;
}a[MAXN];

bool cmp(Node a,Node b)
{
	if (a.x==b.x) return a.y<b.y;
	return a.x<b.x;
}

int main()
{
	int ans=1;
	cin>>n>>m;
	for (int i=1;i<=m;i++)
		cin>>a[i].x>>a[i].y;
	sort(a+1,a+1+m,cmp);
	int start=a[1].x,end=a[1].y;
	for (int i=2;i<=m;i++)
	{//	cout<<"start="<<start<<' '<<"end="<<end<<endl;
		if (a[i].x<end&&(a[i].y<end)) start=a[i].x,end=a[i].y;
		else if (a[i].x<end) start=max(start,a[i].x);
			 else { 	
			 		ans++;
			 		start=a[i].x;
			 		end=a[i].y;
			 	  } 
	}	
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String args[]) {
       Scanner sc=new Scanner(System.in);
       String s=sc.next();
       String t=sc.next();
       int dp[][]=new int[s.length()+1][t.length()+1];
       for(int i=1;i<=s.length();i++)
       {
           for(int j=1;j<=t.length();j++)
           {
               if(s.charAt(i-1)==t.charAt(j-1))
               dp[i][j]=1+dp[i-1][j-1];
               else
               dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
           }
       }
       int m=s.length(),n=t.length();
       StringBuilder sb=new StringBuilder();
       while(m>0 && n>0)
       {
           if(s.charAt(m-1)==t.charAt(n-1))
           {
               sb.append(s.charAt(m-1));
               m--;
               n--;
           }
           else
           {
               if(dp[m-1][n]>dp[m][n-1])
               {
                   m=m-1;
                   n=n;
               }
               else
               {
                   m=m;
                   n=n-1;
               }
           }
       }
       System.out.println(sb.reverse().toString());
    }
}

Measured memory_bytes: 83020
n = int(input())
t = []
x = []
y = []
nowx = 0
nowy = 0
time = 0
for i in range(n):
    T,X,Y = (int(x) for x in input().split())
    t.append(T)
    x.append(X)
    y.append(Y)

for i in range(n):
    distance = abs(nowx - x[i]) + abs(nowy - y[i])
    time = t[i] - time
    # matrix.append([t,x,y])
    if (time - distance) % 2 == 0 and time >= distance:
        nowx = x[i]
        nowy = y[i]
        time = t[i]
    else:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 11724