akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int a;
  int b;
  int c;
  int d;

  cin >> N;
  
  a = N / 1000;
  b = (N - 1000 * a) / 100;
  c = (N - 1000 * a - 100 * b) / 10;
  d = N - 1000 * a - 100 * b - 10 * c;

  if (a == b && b == c) {
    cout << "Yes" << endl;
  }
  else if (b == c && c == d) {
    cout << "Yes" << endl; 
}
  else {
    cout << "No" << endl;
  }
}

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

int main() {
    int A, B, S, T, U;
    cin >> A >> B;
    S = A+B;
    T = A-B;
    U = A*B;
    if(S>=T && S>=U){
        cout << S <<endl;
    }
    else if(T>=S && T>=U){
        cout << T << endl;
    }
    else if(U>=S && U>=T){
        cout << U << endl;
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0;i<n-1;i++){
        if(s.at(i) != s.at(i+1)) ans++;
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<fstream>
#include<stdio.h>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

#define PI  3.141592
//----------------------------------------


long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}




int main(void)
{

	int n, k;
	cin >> n >> k;
	vector<int> p(n);

	rep(i, n) cin >> p[i];

	//累積和

	vector<double> left(n + 3);
	
	left[0] = 0;
	
	for (int i = 1; i <= n; i++)
	{
		double kitai = (1 + p[i-1]) / 2.0;
		left[i] = left[i - 1] + kitai;
	}



	double kmax = 0;

	rep(i, n-k+1)
	{

		double now = left[i + k] - left[i];
		kmax = max(now, kmax);


	}

	cout << setprecision(19) << kmax << endl;
}

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

long long mod = 1'000'000'007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<long long> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    vector<long long> y(m);
    for (int i = 0; i < m; i++) cin >> y[i];
    long long ans_x = 0;
    long long ans_y = 0;
    for (int i = 0; i < n; i++){
        ans_x += (2*i - n + 1) * x[i];
        ans_x %= mod;
    }
    for (int i = 0; i < m; i++){
        ans_y += (2*i - m + 1) * y[i];
        ans_y %= mod;
    }

    cout << ans_x * ans_y % mod << endl;
}

Measured memory_bytes: 1792
def xgcd(a, b)
  y = 0; q=v=w=x = 1
  while b > 0
    v -= q*x; w -= q*y
    q,b = a.divmod a=b
    x,y,v,w = v,w,x,y
  end
  [a,x,y]
end
N,A,B = gets.split.map &:to_i
n,s,P = 1,2,10**9+7
30.times {|i| n*=s and n%=P if N[i]>0; s*=s; s%=P}
a,b = [A,B].map{|r| N < r+r ? N-r : r}.sort
s=t=u = 1
F =->(x,y){ x.upto(y){|i| t*=N+1-i; u*=i; t%=P; u%=P}; s += t*xgcd(u,P)[1]%P }
F[1,a]; F[a+1,b]
p (n<s ? P+n-s : n-s) % P

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back


int main()
{
    ll N;
    string S;
    ll Q;
    cin >> N >> S >> Q;
    S = " " + S;

    vector<set<ll>> A(26);
    REP(i,1,N+1) A[S[i]-'a'].insert(i);

    vec ans;

    REP(q,0,Q) {
        
        ll t;
        cin >> t;
        
        if(t == 1) {
            
            ll i;
            char c;
            cin >> i >> c;

            A[S[i]-'a'].erase(i);
            A[c-'a'].insert(i);
            S[i] = c;

        }
        else {

            ll l, r;
            cin >> l >> r;

            ll cnt = 0;
            REP(a,0,26) {
                if(r > l) {
                    if(A[a].upper_bound(r) != A[a].lower_bound(l)) ++cnt;
                }
                else {
                    cnt = 1;
                }
            }
            ans.pb(cnt);

        }
    
    }

    FORR(cnt,ans) PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 27512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  string s, t;
  cin >> s >> t;
  int qs = s.size();
  int qt = t.size();
  int ans = 0;
  rep(i, qs-qt+1){
    int match = 0;
    rep(j, qt){
      if(s[i+j] == t[j]) match++;
    }
    ans = max(ans, match);
  }
  cout << qt - ans << endl;
  return 0;
}

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

int main(int argc, const char * argv[]) {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    string a,b,c;
    cin >> a >> b >> c;
    cout << "A" << b.at(0) << "C";
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  for (int m = 0;; m++)
  {
    rep(i, n)
    {
      if (a[i] % 2 != 0)
      {
        cout << m << endl;
        return 0;
      }
      a[i] /= 2;
    }
  }
  return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	
	int N; cin >> N;
	set<int> st;
	REP(i,N){
		int A; cin >> A;
		st.insert(A);
	}

	if(st.size() == N) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;

}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
// bingo
int main(){
    vector<vector<int>> a(3 , vector<int>(3));
    vector<vector<bool>> jg(3 , vector<bool>(3, false));

    int n;
    rep(i,3){
        rep(j,3) cin >> a.at(i).at(j);
    }
    cin >> n;
    vector<int> b(n);
    rep(k, n){
        cin >> b.at(k);
        rep(i,3){
           rep(j,3){
               if(b.at(k)==a.at(i).at(j)) jg.at(i).at(j)=true;
           }
        }
    }
    string ans="No";
    rep(i,3){
        if(jg[i][0] and jg[i][1] and jg[i][2]) ans ="Yes";
        if(jg[0][i] and jg[1][i] and jg[2][i]) ans ="Yes";
    }
    if(jg[0][0] and jg[1][1] and jg[2][2]) ans ="Yes";
    if(jg[2][0] and jg[1][1] and jg[0][2]) ans ="Yes";
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int x, a, b; cin >> x >> a >> b;
    if (abs(x-a) > abs(x-b)){
        cout << "B" << endl;
    } else {
        cout << "A" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

const int MAX_N = 100, MAX_M = 100;
int n,m;
char field[MAX_N][MAX_M + 1];

const char SOIL = '0', POND = '1';

void init()
{
    //std::cin >> n >> m;
    n = 12; m = 12;
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++)
    {
        if( i == 0 && j == 0 ){ continue; }
        std::cin >> field[i][j];
    }
}

void dfs(int i, int j)
{
    if( i < 0 || j < 0 || i >= n || j >= m ){ return; }
    if( field[i][j] == SOIL ){ return; }

    field[i][j] = SOIL;

    // 4近傍に探索
    dfs( i - 1, j );
    dfs( i + 1, j );
    dfs( i, j - 1 );
    dfs( i, j + 1 );
}

void view()
{
    std::cout << std::endl;
    for( int i = 0; i < n; i++ ) 
    {
        for( int j = 0; j < m; j++ )
        { std::cout << field[i][j]; }
        std::cout << std::endl;
    }
}

void solve()
{
    int pond_count = 0;

    // 池の部分を探す
    for( int i = 0; i < n; i++ ) for( int j = 0; j < m; j++ )
    {
        if( field[i][j] == POND )
        { 
            dfs( i, j );
            //view();
            pond_count++;
        }
    }
    std::cout << pond_count << std::endl;
}

int main()
{
    while( std::cin >> field[0][0] )
    {
        init();
        solve();
    }
}



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

using namespace std;
#define ll long long int
const int MAXN = 2 * 1e5 + 5;

void solve(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for( auto & x: a)
        cin >> x;
    for( auto & x: b)
        cin >> x;
    ll mncost = __LONG_LONG_MAX__;
    for(int i = 0, x, y, z; i < k; ++i){
        cin >> x >> y >> z;
        x--, y--;
        mncost = min(mncost, (ll)a[x] + b[y] - z);
    }

    //else take smallest of both
    sort(a.begin(), a.end());
    sort(b.begin(),b.end());
    mncost = min(mncost,(ll) a[0] + b[0]);
    cout << mncost << '\n';



}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
	//int t; cin >> t;
	//while(t--)
		solve();
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	public static String next_permutation(String S) {

		ArrayList<Character> list = new ArrayList<>();
		for (int i = 0; i < S.length(); i++) {
			list.add(S.charAt(i));
		}

		char pivot = 0;
		int pivotPos = -1;

		for (int i = list.size() - 2; i >= 0; i--) {
			if (list.get(i + 1) > list.get(i)) {
				pivot = list.get(i);
				pivotPos = i;
				break;
			}
		}

		if (pivot == 0 && pivotPos == -1) {
			return "Final";
		}

		int L = pivotPos + 1;
		int R = list.size() - 1;

		int minPos = -1;
		char min = Character.MAX_VALUE;

		for (int i = R; i >= L; i--) {
			if (pivot < list.get(i)) {
				if (list.get(i) < min) {
					min = list.get(i);
					minPos = i;
				}
			}
		}

		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R + 1));

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			sb.append(list.get(i));
		}

		return sb.toString();
	}

	static int factorial(int n) {
		if (n == 0) {
			return 1;
		}
		return n * factorial(n - 1);
	}

	static List<Integer> StringToList(String str) {
		List<Integer> list = new ArrayList<Integer>();
		StringTokenizer tokenizer = new StringTokenizer(str, "");
		while (tokenizer.hasMoreTokens()) {
			list.add(Integer.valueOf(tokenizer.nextToken()));
		}
		return list;
	}

	static double Distance(int x1, int x2, int y1, int y2) {
		return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
	}

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

		int N = scan.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];
		double total = 0;
		List<Integer> list = new ArrayList<Integer>();

		String S = "";

		for (int i = 0; i < N; i++) {
			x[i] = scan.nextInt();
			y[i] = scan.nextInt();
			S = S.concat(String.valueOf(i + 1));
			list.add(i, Character.getNumericValue(S.charAt(i)));
		}

		for (int k = 0; k < factorial(N); k++) {

			for (int i = 0; i < list.size() - 1; i++) {

				total += Distance(x[list.get(i) - 1], x[list.get(i + 1) - 1], y[list.get(i) - 1],
						y[list.get(i + 1) - 1]);
			}

			S = next_permutation(S);

			if (k != factorial(N) - 1) {

				for (int j = 0; j < N; j++) {

					list.set(j, Character.getNumericValue(S.charAt(j)));
				}
			}
			//System.out.println(S);

			/*
			if (S.equals("Final")) {
				break;
			}
			*/
		}
		System.out.println(total / (double) factorial(N));

		scan.close();

	}
}


Measured memory_bytes: 60800
# AGC039A

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


s = input()
k = int(input())

def sub(s):
    if not s:
        return 0
    # 連続する文字のカウント
    prev = s[0]
    counts = []
    count = 1
    for c in s[1:]:
        if c==prev:
            count += 1
        else:
            counts.append(count)
            count = 1
        prev = c
    if count>=2:
        counts.append(count)
    return sum([item//2 for item in counts])

if s[0]!=s[-1]:
    ans = k * sub(s)
elif all(s[0]==s[i] for i in range(1, len(s))):
    ans = (k * len(s)) // 2
else:
    i = 0
    while s[i]==s[-1]:
        i += 1
    ss = s[i:] + s[:i]
    ans = sub(s[:i]) + (k-1)*sub(ss) + sub(s[i:])
print(ans)
#     s1 = s[:-1] + "A"
#     c1 = sub(s1)
#     s2 = "B" + s[1:]
#     c2 = sub(s2)

    

Measured memory_bytes: 38384
n = int(input())
a = list(map(int, input().split()))
M = 10**9+7
res = [-1] * (n+1)
for i in range(n+1):
    if res[a[i]] == -1:
        res[a[i]] = i
    else:
        d = a[i]
        l, r = res[d], n-i


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7  # 出力の制限
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

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


for i in range(1, n+2):
    print((cmb(n+1, i, mod)-cmb(l+r, i-1, mod)) % mod)


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

int main(void)
{
	int n, m, s, t;
	bool a[200001] = { false };
	bool b[200001] = { false };
	cin >> n >> m;
	for(int i = 0; i < m; ++i) {
		cin >> s >> t;
		if(s == 1)
			a[t] = true;
		else if(t == n)
			b[s] = true;
	}
	for(int i = 0; i < n; ++i) {
		if(a[i] == true && b[i] == true) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 640
#表　数字
#裏　白紙
#「1～10」のカードで同じカードは引けない
def judge(c1,c2,c3):
    num=[i for i in range(1,11) if i!=c1 or i!=c2 or i!=c3]
    if c1+c2<=14:
        return True
    elif c1+c2>=17:
        return False
    tmp=0
    for x in range(20-c1-c2,0,-1):
        if x in num:
            tmp+=1
        if tmp>=4:
            return True
    return False
        
while True:
    try:
        c1,c2,c3=map(int,input().split())
    except EOFError:
        break
    if judge(c1,c2,c3)==True:
        print("YES")
    else:
        print("NO")
    



Measured memory_bytes: 5600
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    if (s == "RRR") cout << 3 << endl;
    else if (s == "RRS" || s == "SRR") cout << 2 << endl;
    else if (s == "SSS") cout << 0 << endl;
    else cout << 1 << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3624
N, K = map(int, input().split())
td = [list(map(int, input().split()))
      for _ in range(N)]
td.sort(key=lambda x: -x[1])
q = []
v = set()
cnt = 0
for t, d in td[:K]:
    cnt += d
    if t in v:
        q.append(d)
    else:
        v.add(t)
cnt += len(v) ** 2
ans = cnt
for t, d in td[K:]:
    if t not in v and len(q) != 0:
        x = q.pop()
        cnt += d + 2 * len(v) + 1 - x
        v.add(t)
        ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 32256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    string s;
    cin >> s;
    int a, z;
    a = s.find('A');
    reverse(s.begin(), s.end());
    z = s.size() - s.find('Z') - 1;
    cout << z - a + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define S second
const int INF = 987654321;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 1};
int dx[4] = {0, 1, 0, 1};

int main(void) {
	//freopen("in.txt", "r", stdin);
	int a,b;
	cin >> a >> b;
	if(a < 1 || a > 9) {
		cout << -1 << '\n';
		return 0;
	}
	if(b < 1 || b > 9) {
		cout << -1 << '\n';
		return 0;
	}
	cout << a*b << '\n';
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""

import math

def dist(x1, y1, x2, y2):
    return math.sqrt( (x2 - x1)**2 + (y2 - y1)**2 )

def main():
    A, B, H, M = map(int, input().split())
    theta1 = (60*H + M) * math.pi / 360
    theta2 = M * math.pi / 30
    x1 = A * math.sin(theta1)
    y1 = A * math.cos(theta1)
    x2 = B * math.sin(theta2)
    y2 = B * math.cos(theta2)
    print(dist(x1, y1, x2, y2))

if __name__ == "__main__":
    main()




Measured memory_bytes: 9524
//  aoj-VolumeICPCOOC2015-B  / 2015-11-30
#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()

template<typename T>ostream& operator << (ostream &os , const vector<T> &v){
    rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : ""); return os;
}
template<typename T>istream& operator >> (istream &is , vector<T> &v){
    rep(i,v.size()) is >> v[i]; return is;
}

#ifdef DEBUG
void debug(){ cerr << " : Debug" << endl; }
#endif
template<class F,class...R> void debug(const F &car,const R&... cdr){
#ifdef DEBUG
    cerr << car << " "; debug(cdr...);
#endif
}

const double EPS=1e-8;

struct Point{
    double x,y;
    Point():x(0),y(0){}
    Point(double x,double y):x(x),y(y){};
    bool operator == (const Point &a) const { return x == a.x && y == a.y; }
    Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
};
istream &operator >> (istream& is, Point& p){ return is >> p.x >> p.y;}
ostream &operator << (ostream& os, const Point& p){ return os << "(" << p.x << "," << p.y << ")";}

double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
double norm(const Point& a) { return sqrt(dot(a, a)); }
double distance(const Point& a, const Point& b) { return norm(a - b); }

bool check(vector<Point> &P, vector<int> &R,Point &np,int nr){
    rep(i,P.size()){
        if(distance(P[i],np) - (R[i] + nr) < 0.0) return false;
    }
    return true;
}

bool solve(){
    int n; cin >> n;
    vector<int> R(n); cin >> R;
    vector<Point> P;
    for(int r : R){
        double l= P.size() > 0 ? max(P.back().x,(double)r) : r;
        double h=1e10;
        while(h-l>1e-8){
            double m = (l+h)/2;
            Point p = Point(m,r);
            if(check(P, R, p, r)) h = m;
            else l = m;
        }
        P.push_back(Point(h,r));
    }
    debug(P);
    double ans = 0;
    rep(i,P.size()) ans = max(ans,P[i].x+R[i]);
    printf("%.10f\n",ans);
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}

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

int main(){

	int x, y, t;

	while(1){
		cin >> x >> y;

		if(x == 0 && y == 0) break;

		if(x > y){
			t = x;
			x = y;
			y = t;
		}

		cout << x << " " << y << endl;
	}

	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    ll H, W;
    cin >> H >> W;

    string row = "";
    rep(i, W + 2) row += '#';
    print(row);
    rep(i, H){
        string s;
        cin >> s;
        print("#" + s + "#");
    }
    print(row);

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int n, adj[101][101];

int main()
{
  scanf("%d", &n);
  int u, k, v;
  for(int i=0; i<=n; i++)
  {
    for(int j=0; j<=n; j++)
    {
      adj[i][j] = 0;
    }
  }
  for(int i=0; i<n; i++)
  {
    scanf("%d%d", &u, &k);
    for(int j=0; j<k; j++)
    {
      scanf("%d", &v);
      adj[u][v] = 1;
    }
  }
  for(int i=1; i<=n; i++)
  {
    for(int j=1; j<=n; j++)
    {
      if(j!=1) printf(" ");
      printf("%d", adj[i][j]);
    }
    printf("\n");
  }



  return 0;
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S,T;
    cin >> S >> T;
    vector<int> start(26, -1);
    vector<int> goal(26, -1);
    rep(i,S.size()){
        int a=S[i]-'a';
        int b=T[i]-'a';
        if(start[a]!=-1 || goal[b]!=-1){
            if(start[a]!=b || start[a]!=b){
                cout << "No" << endl;
                return 0;
            }
        }
        start[a]=b;
        goal[b]=a;
    }
    cout << "Yes" << endl;
}


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

int INFp=1000000007;
const string minusinf ="-";
const int mininf = -1;
int cost[10]={0,
    2
    ,
    5
    ,
    5
    ,
    4
    ,
    5
    ,
    6
    ,
    3
    ,
    7
    ,
    6
};
void chmax(string &a,string b){
    if(a == minusinf) a=b;
    else if(a.size()<b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}


int main(){
    int n,m;
    int a[15];
    cin>>n>>m;
    for(int i=0;i<m;i++) cin>>a[i];
    
    //sort(a,a+m,greater<int>());
    
    //int dp[11000]={-1};//i本使うときの最大桁数
    
    vector<int> dp(11000, -1);
    dp[0]=0;
    
    for(int i=0; i<=n; i++){
        if(dp[i] == -1)
            continue;
        
        int index;
        for(int j=0; j<m; j++){
            index = i + cost[a[j]];
            if(index > n)
                continue;
            
            dp[index] = max(dp[index], dp[i]+1);
        }
    }
    
    
    int costcount=n;
    
    vector<int> ans;
    int cnt = n;
    for(int i=0; i<dp[n]; i++){
        int select = -1;
        for(int j=0; j<m; j++){
            int dst = cnt - cost[a[j]];
            if(dst < 0 || dp[dst] == -1)
                continue;
            
            if(dp[cnt]-dp[dst] == 1)
                select = max(select, a[j]);
        }
        
        ans.push_back(select);
        cnt -= cost[select];
    }
    
    
    for(int i=0;i<ans.size();i++){
        cout<<ans[i];
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int M, N;
  while(cin>>M>>N){
    vector<int> d(N + 2); //0 - start, N + 1 - goal
    REP(i, N) cin>>d[i + 1];
    vector<bool> is_ok(N + 2);
    queue<int> que;
    is_ok[N + 1] = true;
    que.push(N + 1);
    while(!que.empty()){
      int u = que.front(); que.pop();
      REP(v, N + 2)if(v + d[v] == u || (u == N + 1 && v + d[v] >= u)){
        for(int c = 1; c <= M && v - c >= 0; c++) if(!is_ok[v - c]){
          que.push(v - c);
          is_ok[v - c] = true;
        }
      }
    }
    bool ans = true;
    vector<bool> used(N + 2);
    que.push(0);
    used[0] = true;
    while(!que.empty()){
      int u = que.front(); que.pop();
      if(!is_ok[u]) ans = false;
      for(int c = 1; c <= M && u + c < N + 2; c++){
        int v = u + c;
        int to = v + d[v];
        if(to < 0) to = 0;
        if(to > N + 1) to = N + 1;
        if(used[to]) continue;
        que.push(to);
        used[to] = true;
      }
    }
    if(ans) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
  }
  return 0;
}

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

string s;
int cnt[2020];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    reverse(s.begin(), s.end());
    int n = s.length();
    long long res = 0;
    int base = 1;
    int rem = 0;
    memset(cnt, 0, sizeof(cnt));
    cnt[0] = 1;
    for (int i = 0; i < n; i++){
        rem = (rem + (s[i] - '0') * base) % 2019;
        // cout << rem <<"\n";
        cnt[rem]++;
        base = (base * 10) % 2019; // ** 0 also counts
    }
    for (int i = 0; i < 2019; i++)
        res += cnt[i] * (cnt[i] - 1) / 2;

    cout << res <<"\n";

    return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

int a, b, c;

int main() {
	cin>>a>>b>>c;
	int t = (a + c - 1)/c;
	if(t <= b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    string S;
    cin >> S;
    int length = S.size();

    int begin, end;
    // find A
    for (int i = 0; i < length; i++)
    {
        if (S[i] == 'A')
        {
            begin = i;
            break;
        }
    }

    //find Z
    for (int i = length; i > begin; i--)
    {
        if (S[i] == 'Z')
        {
            end = i;
            break;
        }
    }
    cout << end - begin + 1 << endl;
    return (0);
}

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

int main() {
    int64_t X;
    cin >> X;
    int64_t Y = 100;
    int cnt = 0;

    bool even = true;
    while (even) {
        if (Y < X) {
            Y += Y * 0.01;
            cnt++;
        }
        else {
            even = false;
            break;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */
const int N = 410;
int n,h[N];

inline void mrg(int *f,int *g,int len){
	for(int i=len;~i;i--){
		f[i] = mul(f[i], g[0]);
		for(int j=i-1;~j;j--){
			f[i] = add(f[i], mul(f[j],g[i-j]));
		}
	}
}
int bin[N][N];
int f[N][N][2][N],g[2][N];
int pw[N],ipw[N];
int _f[N];
inline void dfs(int l,int r,int x){
	// int empty=0;
	f[x][l][0][0]=f[x][l][1][0]=1;
	for(int u=l,v;u<=r;u=v+1){
		v=u;
		if(h[u]>x){
			while(v+1<=r&&h[v+1]>x)++v;
			dfs(u,v,x+1);
			mrg(f[x][l][0],f[x+1][u][0],r-l+1);
			mrg(f[x][l][1],f[x+1][u][1],r-l+1);
		}else{
			_f[0]=_f[1]=1;
			mrg(f[x][l][0],_f,r-l+1);
			_f[0]=0;
			mrg(f[x][l][1],_f,r-l+1);
		}
	}
	memset(g,0,sizeof(g));
	// cout << l << "to" << r << " " << x << endl;
	for(int i=0;i<=r-l+1;i++){
		// cout << f[x][l][1][i] << " " << f[x][l][0][i] << endl;
		//this line empty
		g[1][i] = add(g[1][i], f[x][l][1][i]);
		g[0][i] = add(g[0][i], f[x][l][1][i]);
	}
	for(int i=0;i<=r-l+1;i++){
		for(int j=0;j<=i;j++){
			
			g[0][j] = add(g[0][j], mul(f[x][l][0][i], mul(bin[i][j], pw[j]-(j==i))));
			// if(j==0)cout << i << " " << j << "::" << bin[i][j] <<" " << pw[j]-(j==i) << "|" << g[x][l][0][j] << endl;
			g[1][j] = add(g[1][j], mul(f[x][l][1][i], mul(bin[i][j], pw[j]-(j==i))));
		}
	}
	// cout << g[x][l][0][0] << endl;
	for(int i=0;i<=r-l+1;i++)f[x][l][1][i]=g[1][i],f[x][l][0][i]=g[0][i];
}

int main()
{
	pw[0]=1;for(int i=1;i<=400;i++)pw[i]=add(pw[i-1],pw[i-1]);
	ipw[0]=1;for(int i=1;i<=400;i++)ipw[i]=mul(ipw[i-1],(mod+1)>>1);
	bin[0][0]=1;for(int i=1;i<=400;i++){
		bin[i][0]=bin[i][i]=1;for(int j=1;j<=i;j++)bin[i][j]=add(bin[i-1][j],bin[i-1][j-1]);
	}
	cin >> n;
	for(int i=1;i<=n;i++)scanf("%d",&h[i]);
	dfs(1,n,1);
	int ans=0;
	ans=add(ans,f[1][1][0][0]);
	cout << ans << endl;
	return 0;
}

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

res = 0
for i in range(1,n-1):
    l = [p[i-1],p[i],p[i+1]]
    if p[i] != min(l) and p[i] != max(l):
        res += 1

print(res)

Measured memory_bytes: 3064
#include<stdio.h>


int main( void )
{
	int N ,LIST ;
	while( 1 )
	{
		scanf( "%d %d" ,&N ,&LIST ) ;

		if( N | LIST )
		{
			int ans[ 500 + 1 ] = { 0 } ;

			int fri[ 500 + 1 ][ 500 + 1 ] = { 0 } ;

			int cnt = 0 ;
			int a ,b ;

			int i ,j ,k ;
			for( i = 0 ; i < LIST ; ++i )
			{
				scanf( "%d %d" ,&a ,&b ) ;

				fri[ a ][ b ] = fri[ b ][ a ] = 1 ;
			}

			for( i = 2 ; i <= N ; ++i )
			{
				if( fri[ 1 ][ i ] == 1 )
				{
					++ans[ i ] ;

					cnt += ( ans[ i ] == 1 ) ;

					for( j = 2 ; j <= N ; ++j )
					{
						if( fri[ i ][ j ] == 1 )
						{
							++ans[ j ] ;

							cnt += ( ans[ j ] == 1 ) ;
						}
					}
				}
			}

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

		else
		{
			return 0 ;
		}
	}
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  vector<pair<ll,ll>> dr;

  REP(i, n){
      int ta, tb;
      cin >> ta >> tb;
      dr.pb(make_pair(ta, tb));
    }
    sort(dr.begin(),dr.end());

    for(int c = 0;m > 0; c++){
        if(dr[c].second <= m) ans+= (dr[c].first * dr[c].second);
        else ans += (dr[c].first * m);
        m -= dr[c].second;
      }
      cout << ans << endl;
      return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;
const int N = 200005;

// rozwiązuje równanie ax=1(%MOD), gdy MOD pierwsze
int inverse(int a) {
    int n = MOD - 2;
    int r = 1;
    while (n) {
        if (n % 2) r = (r * 1LL * a) % MOD;
        a = (a * 1LL * a) % MOD;
        n >>= 1;
    }
    return r;
}

int n, a, b, r, i, j, pot[N], invPot[N];
VI graf[N], res[N], il[N];

void print() {
	for (int i=1;i<=n;i++) {
		printf("%d:  ", i);
		for (int j=0;j<graf[i].size();j++) printf("%d %d %d  ", graf[i][j], il[i][j], res[i][j]);
		printf("\n");
	}
}

ii go(int w, int o) {
	int sum = 1;
	for (int i=0;i<graf[w].size();i++) if (graf[w][i] != o) {
		ii x = go(graf[w][i], w);
		il[w][i] = x.first;
		res[w][i] = x.second;
		sum += il[w][i];
	}
	int r = pot[sum - 1];
	for (int i=0;i<graf[w].size();i++) if (graf[w][i] == o) il[w][i] = n - sum; else {
		r = (r * 1LL * res[w][i]) % MOD;
		r = (r * 1LL * invPot[il[w][i]]) % MOD;
	}
	return ii(sum, r);
}

void go2(int w, int o, int val) {
	int r = pot[n - 1];
	for (int i=0;i<graf[w].size();i++) {
		if (graf[w][i] == o) res[w][i] = val;
		r = (r * 1LL * res[w][i]) % MOD;
		r = (r * 1LL * invPot[il[w][i]]) % MOD;
	}
	for (int i=0;i<graf[w].size();i++) if (graf[w][i] != o) {
		int r2 = r;
		r2 = (r2 * 1LL * invPot[n - 1]) % MOD;
		r2 = (r2 * 1LL * pot[n - 1 - il[w][i]]) % MOD;
		r2 = (r2 * 1LL * pot[il[w][i]]) % MOD;
		r2 = (r2 * 1LL * inverse(res[w][i])) % MOD;
		go2(graf[w][i], w, r2);
	}
}

int main() {
scanf("%d", &n);
pot[0] = invPot[i] = 1;
for (i=1;i<=n;i++) {
	pot[i] = (pot[i - 1] * 1LL * i) % MOD;
	invPot[i] = inverse(pot[i]);
}

for (i=1;i<n;i++) {
	scanf("%d %d", &a, &b);
	graf[a].pb(b);
	graf[b].pb(a);
	res[a].pb(0);
	res[b].pb(0);
	il[a].pb(0);
	il[b].pb(0);
}
go(1, -1);
go2(1, -1, 0);
//print();
for (i=1;i<=n;i++) {
	r = pot[n - 1];
	for (j=0;j<graf[i].size();j++) {
		r = (r * 1LL * res[i][j]) % MOD;
		r = (r * 1LL * invPot[il[i][j]]) % MOD;
	}
	printf("%d\n", r);
}
return 0;
}

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<pair<ll,ll>> v(n);
    ll l=0,r=INF,maxl_r=0,minr_l=0;
    for(i=0;i<n;i++){
        cin >> v[i].second >> v[i].first;
        l = max(l,v[i].second);
        r = min(v[i].first,r);
    }
    if(n==2){
        cout << v[0].first-v[0].second+1 +v[1].first-v[1].second+1 << endl;
        return 0;
    }
    ll ret = 0;
    for(i=0;i<n;i++){
        // Lの最大を持つ区間とRの最小を持つ区間が同じ集合なら
        // 少なくともこの点数はとれる
        // 最大のL(最小のR)を持つものが両方に表れる時もあるが,
        // その時は最大のLを持つ区間と最小のRを持つ区間を別の集合にしたときの
        // 最善の選択よりも必ず悪くなる.
        // (例:単純に最大のL(最小のR)だけの集合とそれ以外に分ければ両方に含まれる時よりも悪くならない)
        ret = max(ret,max(0LL,r-l+1)+v[i].first-v[i].second+1);
    }
    
    // Lの最大を持つ区間とRの最小を持つ区間が違う集合にある場合
    sort(v.begin(),v.end());
    vector<ll> l1(n+1,-INF),l2(n+2,-INF),r1(n+1,INF),r2(n+2,INF);
    for(i=0;i<n;i++){
        l1[i+1] = max(l1[i],v[i].second);
        r1[i+1] = min(r1[i],v[i].first); 
    }
    for(i=n;i>0;i--){
        l2[i] = max(l2[i+1],v[i-1].second);
        r2[i] = min(r2[i+1],v[i-1].first);
    }
    for(i=1;i<n;i++){
        ret = max(max(r1[i]-l1[i]+1,0LL)+max(0LL,r2[i+1]-l2[i+1]+1),ret);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int);
void print(void);
Node treeMaximum(Node);
Node treeMinimum(Node);
Node treeSearch(Node, int);
Node treeSuccessor(Node);
void delete(Node);
void inorder(Node);
void preorder(Node);
Node find(Node, int);

int main()
{
  int m,i,x;
  char com[10];
  Node t;

  scanf("%d",&m);
  
  for(i = 0; i < m; i++){
    scanf("%s",com);
    if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0] == 'd'){
      scanf("%d",&x);
      delete(treeSearch(root, x));
    }
    else if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0] == 'f'){
      scanf("%d",&x);
      t = treeSearch(root, x);
      if(t != NIL)printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}

void insert(int k)
{
  Node y;
  Node x;
  Node z;
  
  y = NIL; //xの親
  x = root;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

Node treeMaximum(Node x)
{
  while(x->left != NIL){
    x = x->right;
  }
  return x;
}

Node treeMinimum(Node x)
{
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeSearch(Node x, int k)
{
  while(x != NIL && k != x->key){
    if(k < x->key)x = x->left;
    else x = x->right;
  }
  
    return x;
}

Node treeSuccessor(Node x)
{
  Node y;
  
  if(x->right != NIL)return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;
}

void delete(Node z)
{
  Node y; //消去候補
  Node x; //yの子

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;

  if(x != NIL)x->parent = y->parent;
  
  if(y->parent == NIL)root = x;
  else if(y == y->parent->left)y->parent->left = x;
  else y->parent->right = x;

  if(y != z)z->key = y->key;
}

void inorder(Node x)
{
  if(x != NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}

void preorder(Node x)
{
  if(x == NIL)return;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}

Node find(Node x, int k)
{
  while(x != NIL && k != x->key){
    if(k < x->key)x = x->left;
    else x = x->right;
  }

    return x;
}



Measured memory_bytes: 20468
/* Simplicity and Goodness */
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;

bool is_comp[N];
vi range(N);

void sieve()
{
    is_comp[0] = is_comp[1] = 1;

    for(int i = 2; i*i < N; i ++) {
        if(!is_comp[i]) {
            for(int j = i*i; j < N; j += i) {
                is_comp[j] = 1;
            }
        }
    } 

    range[0] = 0;

    for(int i = 1; i < N; i ++) {
        if(!is_comp[i] and !is_comp[(i+1)/2])
            range[i] = 1 + range[i-1];
        else
            range[i] = range[i-1];
    }
}

void solve()
{   
    int l, r;
    scn(l); scn(r);

    int here = range[r] - range[l-1];
    prin(here);
}

int main()
{
    sieve();

    int t = 1;
    scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<string> prize(n);
    set<string> type;
    for (int i=0; i<n; ++i)
        cin >> prize.at(i);

    for (auto& itr : prize)
        type.insert(itr);

    cout << (int)type.size();
}


Measured memory_bytes: 25072
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	int alen;
	cin >> alen;
	VE aarray(alen);
	VE barray(alen - 1);
	REP(i, alen - 1) {
		cin >> barray[i];
	}
	int ans = barray[0];
	REP(i, alen - 2) {
		ans += min(barray[i],barray[i+1]);
	}
	ans += barray[barray.size() -1];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=4e5 +10,mod=998244353;
const ll inf=1e18;

bool arr[maxn], is[maxn];
int tw[maxn];
vector<pii> v;

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

    tw[0]=1;
    for(int i=1;i<maxn;i++)
	tw[i]= 2ll*tw[i-1] %mod;
    int n; cin>>n;
    string s; cin>>s;

    int CNT=1, ans=0;
    for(int i=0;i<n;i++){
	CNT=(CNT + (s[i]=='1' ? tw[n-1-i] : 0 )) %mod;
    }
 
    for(int lp=1;lp<=n;lp++){
	if((2*n)%lp!=0) continue;
	if(n%lp == 0) continue;
	int k=lp/2;
	string ss;
	for(int i=0;i<n;i++){
	    ss+= '0' + ((s[i%k]=='1') ^ ((i/k)&1));
	}
	int cnt=1;
	for(int i=0;i<k;i++){
	    cnt= ( cnt + (s[i]=='1' ? tw[k-1-i] : 0)) %mod;
	}
	if(ss>s) cnt--;
	for(auto p:v){
	    if(lp%p.F==0)
		cnt=(cnt - p.S) %mod;
	}
	ans=(1ll*ans + 1ll*cnt*lp) %mod;
	v.PB({lp,cnt});
	CNT=(CNT - cnt) %mod;
    }
    ans=(1ll*ans + 1ll*CNT*2*n) %mod;
    if(ans<0) ans+=mod;
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


Measured memory_bytes: 2532
#define _GLIBCXX_DEBUG // 未完
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a/GCD(a,b)*b; }

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

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

  // 期待値計算 1~Nまでの和 * N
  vector<double> q(N);
  double maxV = 0;
  double sum = 0;
  for(int i = 0; i < N; i++) {
    int a; cin >> a;
    q.at(i) = a*(a+1.0)/(2.0*a);
    sum += q.at(i);
    if(i < K-1) continue;
    maxV = max(maxV, sum);
    sum -= q.at(i-(K-1));
  }

  cout << fixed << setprecision(10);
  cout << maxV << endl;
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}
	long long int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

long long int lcm(long long int a, long long int b) {
	long long int L;
	L = a / gcd(a, b);
	L *= b;
	return L;
}

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	for (int i = 2; i * i <= n; i++) {
		;
		if (is_prime.at(i)) {
			for (int j = i * i; j <= n; j += i) {
				is_prime.at(j) = false;
			}
		}
		Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int keta(long long int N) {
	int k = 0;
	while (N > 0) {
		N /= 10;
		k++;
	}
	return k;
}



int Combination(int n, int m) {
	long long int s = 1, t = 1;
	int tmp = n;
	while (n - m != tmp) {
		s *= tmp;
		tmp--;
	}
	tmp = m;
	while (tmp != 1) {
		t *= tmp;
		tmp--;
	}
	return s / t;
}


int main() {
	long long int n, a, b;
	string s, t;
	cin >> a >> b >> n;
	if (n >= a) {
		cout << 0 << ' ';
		if (b + a >= n) {
			cout << b + a - n << endl;
		}
		else
			cout << 0 << endl;
	}
	else {
		cout << a - n << ' ' << b << endl;
	}
}


Measured memory_bytes: 256