akhauriyash/Code-Regression huggingface dataset:
/*
[abc139] F - Engines
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

typedef complex<double> P;

const int MAX_N = 100;

int N;
pair<double, P> ps[MAX_N];

namespace std {
bool operator<(const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}  // namespace std

double solve() {
    for (int i = 0; i < N; i++) {
        ps[i].first = arg(ps[i].second);
    }
    sort(ps, ps + N);

    double ans = 0;
    for (int i = 0; i < N; i++) {
        P s;
        for (int j = 0; j < N; j++) {
            s += ps[(i + j) % N].second;
            ans = max(ans, abs(s));
        }
    }

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        double x, y;
        cin >> x >> y;
        ps[i].second = {x, y};
    }

    cout << setprecision(16) << solve() << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

int euq(int a, int b) {
    return b ? euq(b, a%b) : a;
}

int lcm(int a, int b) {
    int g = euq(a, b);
    return (a*b)/g;
}

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

    int nt=1, na=1;
    rep(i, N) {
        int T, A;
        cin >> T >> A;
        
        int mul = max((nt/T+bool(nt%T)), (na/A+bool(na%A)));
        //nt *= mul; na *= mul;
        nt = T*mul; na = A*mul;
        //cout << nt << " " << na << endl;
    }

    cout << nt+na << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import math
def factorization(n):
    i = 2
    factors = []
    while i <= math.floor(math.sqrt(n)):
        if n%i == 0:
            factors.append(i)
            n //= i
        else:
            i += 1
    if n > 1:
        factors.append(n)
    return factors
N = int(input())
if N==1:
    print(1)
    exit()
c = Counter()
for i in range(1, N+1):
    f = factorization(i)
    c.update(f)
ans = 1
for x in c.values():
    ans *= (x+1)
print(ans % int(1e9+7))

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
int main(void)
{
	int N,A,B,C,D,a,b;
	scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);
	if(N%A!=0)
	{
		a=(N/A+1)*B;
	}
	else
	{
		a=(N/A)*B;
	}
	if(N%C!=0)
	{
		b=(N/C+1)*D;
	}
	else
	{
		b=(N/C)*D;
	}
	if(a>b){a=b;}
	printf("%d\n",a);
	return 0;
}


Measured memory_bytes: 3220
#include<iostream>
using namespace std;
int main()
{
    int x[5],i;

    for(i=0;i<5;i++)
    {
        cin >> x[i];
    }

    for(i=0;i<5;i++)
    {
        if(x[i]==0)
        {
            cout << i+1 << endl;
        }
        else continue;
    }

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll n, k, ans = INF;
  cin >> n >> k;

  ll nn = n % k;

  cout << min(nn, abs(nn - k)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	int n; cin >> n;
	int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i];

	ll pre_sum[n + 1] = {};
	pre_sum[1] = a[1];
	for (int i = 3; i <= n; i += 2)
		pre_sum[i] = pre_sum[i - 2] + a[i];

	ll dp[n + 1] = {};
	for (int i = 2; i <= n; i++) {
		if (i & 1) {
			dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
		} else {
			dp[i] = max(pre_sum[i - 1], dp[i - 2] + a[i]);
		}
	}

	cout << dp[n];
}

Measured memory_bytes: 7488
import java.util.Scanner;

//A Piece of Cake
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int k = sc.nextInt();
			if(k==0)break;
			int s = 0;
			for(int i=0;i<k*(k-1)/2;i++)s+=sc.nextInt();
			System.out.println(s/(k-1));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<string> S;
    string s;
    for (int i = 1; i <= N; i++) s.push_back('0' + i);
    do {
        S.push_back(s);
    } while (next_permutation(begin(s), end(s)));
    string P;
    rep(i,N) {
        int p;
        cin >> p;
        P.push_back('0'+p);
    }
    string Q;
    rep(i,N) {
        int q;
        cin >> q;
        Q.push_back('0'+q);
    }
    int a = distance(begin(S), lower_bound(begin(S), end(S), P));
    int b = distance(begin(S), lower_bound(begin(S), end(S), Q));
    cout << abs(a-b) << endl;
}


Measured memory_bytes: 2424
import com.sun.org.apache.regexp.internal.RE;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Restaurant> restaurants = new ArrayList<>();
        for (int i = 1; i <= N; i++) {
            restaurants.add(new Restaurant(i, sc.next(), sc.nextInt()));
        }
        Comparator<Restaurant> restaurantComparator =
                Comparator.comparing(Restaurant::getCity)
                        .thenComparing(Restaurant::getPoint, Comparator.reverseOrder());

        restaurants.sort(restaurantComparator);

        for (Restaurant restaurant : restaurants) {
            System.out.println(restaurant.index);
        }
    }

    class Restaurant {
        int index;
        String city;
        int point;

        String getCity() {
            return city;
        }

        int getPoint() {
            return point;
        }

        Restaurant(int index, String city, int point) {
            this.index = index;
            this.city = city;
            this.point = point;
        }
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

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

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

const int MAX = 7400006;

int memo[500005];
bool used[MAX];

signed main() {
	
	std::vector<int> a, b;
	while (true) {
		int m, n;
		std::cin >> m >> n;
		if (m == 0 && n == 0) break;
		a.emplace_back(m);
		b.emplace_back(n);
	}

	struct D { int m, n, i; };
	std::vector<D> d;
	REP(i, a.size()) {
		d.emplace_back(D{ a[i], b[i], i });
	}

	std::sort(d.begin(), d.end(), [&](D& l, D& r) {
		return l.m < r.m;
	});

	std::vector<int> ans(d.size());
	int pre = -1;
	REP(_, d.size()) {
		int m = d[_].m;
		int n = d[_].n;
		int p = d[_].i;


		if (pre != m) {
			REP(i, 500005) memo[i] = 0;
			REP(i, MAX) used[i] = false;
			pre = m;

			int q = 1;
			FOR(i, m, MAX) {
				if (!used[i]) {
					memo[q++] = i;
					if (q > 500001) break;
					for (int j = 1; j * i < MAX; ++j) used[j * i] = true;
				}
			}
		}

		ans[p] = memo[n + 1];
	}

	REP(i, d.size()) {
		std::cout << ans[i] << std::endl;
	}

	return 0;
}


Measured memory_bytes: 12312
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	ll x;
	cin >> x;
	
	vector<bool> ok(x + 1, false);
	ok[1] = true;
	
	for(int i = 2; i <= x; ++i) {
		int a = i * i;
		while( a <= x ) {
			ok[a] = true;
			a *= i;
		}
	}
	
	for(int i = x; i >= 1; i--) {
		if( ok[i] ) {
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}


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

bool ban[8][8];
int H, W;
bool search(int x, int y)
{
    //   cout << "x=" << x << endl;
    //   cout << "y=" << y << endl;
    //   cout << "H-1=" << H - 1 << endl;
    //   cout << "W-1=" << W - 1 << endl;
    if (ban[x][y] == false)
        return false;
    ban[x][y] = false;

    if (x == H - 1 && y == W - 1)
    {
        //       cout << "goal" << endl;
        return true;
    }
    else
    {
        bool ans = false;
        if (x - 1 >= 0 && x - 1 < H && ban[x - 1][y] == true)
        {
            //         cout << "false1" << endl;
            ans = false;
        }
        else if (y - 1 >= 0 && y - 1 < W && ban[x][y - 1] == true)
        {
            //         cout << "false2" << endl;
            ans = false;
        }
        else
        {
            bool down = (x + 1 < H && ban[x + 1][y] == true);
            bool right = (y + 1 < W && ban[x][y + 1] == true);
            if (down && right)
                ans = false;
            else if (down)
            {
                ans = search(x + 1, y);
            }
            else if (right)
            {
                ans = search(x, y + 1);
            }
        }
        return ans;
    }
}

int main()
{
    cin >> H >> W;
    //   char a[H][W];
    int counter = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            char c;
            cin >> c;
            if (c == '#')
            {
                ban[i][j] = true;
                counter++;
            }
            else
                ban[i][j] = false;
        }
    }
    if (counter == H + W - 1)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
    return 0;

    int x = 0, y = 0;
    bool ans = search(x, y);
    if (ans == true)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var xys = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var x1 = xys[0];
        var y1 = xys[1];
        var x2 = xys[2];
        var y2 = xys[3];

        var dx = x2 - x1;
        var dy = y2 - y1;
        var x3 = x2 - dy;
        var y3 = y2 + dx;
        var x4 = x1 - dy;
        var y4 = y1 + dx;
        Console.WriteLine($"{x3} {y3} {x4} {y4}");
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n, x; cin >> n >> x;
  ll now = 0, cnt = 1;
  for(ll i=0; i<n; ++i){
    ll l; cin >> l;
    now += l;
    if(now <= x) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
const int SIZE=5+1*1e5;
const LL INF=1<<30;
string is[]={"dream","erase","eraser","dreamer"};
int main(){
	string s;
	cin >> s;
	reverse(ALL(s));
	REP(i,4) reverse(ALL(is[i]));
	int i=0;
	while(i<s.size()){
		REP(k,5){
			if(k==4){
				cout << "NO" << endl;
				return 0;
			}
			bool able=true;
			REP(j,is[k].size()){
				if(s[i+j]!=is[k][j]) able=false;
			}			
			if(able){
				i+=is[k].size();
				break;	
			} 
		}
	}
	cout << "YES" << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)

/////////////////////////////////////////////////////////

ll myceil(ll a, ll b){
  if(a % b == 0) return a / b;
  else return a / b + 1;
}

void Main(){
  int N; cin >> N;
  vector<pair<ll, ll>> vp(N);
  rep(i, 0, N) cin >> vp[i].first >> vp[i].second;

  ll T, A;
  T = A = 1;
  rep(i, 0, N){
    T = vp[i].first * max(myceil(T, vp[i].first), myceil(A, vp[i].second));
    A = vp[i].second * max(myceil(T, vp[i].first), myceil(A, vp[i].second));
  }
  cout << T + A << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


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

using namespace std;
typedef long long ll;

int main(void)
{
   string s;
   int q;
   cin >> s >> q;

   while(q--){
      string x;
      cin >> x;
      int a, b;
      cin >> a >> b;
      if(x == "print"){
         for (int i = a; i <= b;i++)
            cout << s.at(i);
         cout << endl;
      }
      else if(x=="reverse"){
         reverse(s.begin() + a, s.begin() + b+1);
      }
      else if(x == "replace"){
         string p;
         cin >> p;
         s.replace(a,p.length(), p);
      }
   }

   return 0;
}



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


int main(){
  int N; vector<int> H(100);
  cin >> N;
  for(int i=0; i<N; i++) cin >> H[i];

  int ans = 0;
  while(true){
    int start = -1;
    for(int i=0; i<N; i++){
      if(H[i] > 0) {start = i; break;}
    }

    if(start == -1) break;

    while(H[start] > 0) {H[start]--; start++;}
    ans++;
  }

  cout << ans << endl;
}

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

using namespace std;

int main () {
    string s[3];
    int idx[3] = {};
    cin >> s[0] >> s[1] >> s[2];
    int card = 0;

    while (true) {
        if (idx[card] == s[card].length()) {
            cout << (char) (card + 'A') << endl;
            break;
        }
        idx[card] += 1;
        card = s[card][idx[card] - 1] - 'a';
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	for (ll i = 0; i < n; i++) a.push_back(a[i]);
	vector<ll> pl(200010, -1);
	vector<ll> ne(n);
	for (ll i = 0; i < 2 * n; i++) {
		if (pl[a[i]] != -1 && pl[a[i]] < n) {
			ne[pl[a[i]]] = i;
		}
		pl[a[i]] = i;
	}
	ll now = 0;
	bool flag = true;
	while (now%n != 0 || flag) {
		flag = false;
		now += ne[now%n] - now % n;
		now++;
	}
	ll period = now / n;
	k %= period;
	ll remain = k * n;
	now = 0;
	while (now < remain) {
		while (now + ne[now%n] - now % n < remain) {
			now += ne[now%n] - now % n;
			now++;
		}
		if (now < remain) cout << a[now%n] << ' ';
		now++;
	}
}

Measured memory_bytes: 7780
#include "bits/stdc++.h"
using namespace std;
int main(){
    int H, W, h, w;
    scanf("%d %d %d %d", &H, &W, &h, &w);
    if(H%h == 0 && W%w == 0) return printf("No\n"), 0;
    printf("Yes\n");
    for(int e = 1; e <= H; e++){
        for(int f = 1; f <= W; f++)
            if(e%h == 0 && f%w == 0) printf("%d ", -1000*(h*w - 1) - 1);
            else printf("1000 ");
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main()
{
   long double x,y,n,m;
   cin>>n>>m>>x>>y;
   long double a,k,l;
   k = n/2;
   l = m/2;
   cout<<l*k*2<<" ";
   if(k==x && l==y) cout<<1;
   else cout<<0;
   
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M=map(int, sys.stdin.readline().split())
al=[ [] for i in range(N+1) ]	#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#リバース隣接リスト
I=[ 0 for i in range(N+1) ] #入次数
O=[ 0 for i in range(N+1) ] #出次数
edge=[] #辺の集合
I[0]=None

for _ in range(M):
    s,t=map(int, sys.stdin.readline().split())
    al[s].append(t)
    rev_al[t].append(s)
    I[t]+=1
    O[s]+=1
    edge.append((s,t))

#トポロジカルソート
L=[]
q=deque()
for x in range(N):
    if I[x]==0:
        q.append(x) 

while q:
    fro=q.popleft()
    L.append(fro)
    for to in al[fro]:
        I[to]-=1
        if I[to]==0:
            q.append(to)

if len(L)!=N:
    prin

#頂点毎の到達する確立
P=[ 0 for i in range(N+1) ]   #確率
P[1]=1

for x in L:
    if O[x]!=0:
        p=float(1)/O[x]
        for to in al[x]:
            P[to]+=P[x]*p
        
#頂点毎の期待値
E=[ 0 for i in range(N+1) ]   #期待値

for x in L[::-1]:
    for to in rev_al[x]:
        p=float(1)/O[to]
        E[to]+=(E[x]+1)*p
#消す辺
ans=E[1]
for del_s,del_t in edge:
    if O[del_s]-1==0:
        continue
    new_E=float(E[del_s]*O[del_s]-(E[del_t]+1))/(O[del_s]-1)
    #print "del_s,del_t,new_E, :: ",del_s,del_t,new_E,E,E[1]+(new_E-E[del_s])*P[del_s]
    if new_E<E[del_s]:
        ans=min(ans,E[1]-(E[del_s]-new_E)*P[del_s])

print ans

Measured memory_bytes: 67228
def main():
    n = int(input())
    a = list(map(int, input().split()))
    mm = {0:0}

    ans = 'YES'
    for i in range(n):
        if mm.get(a[i]) != None:
            ans = 'NO'
            break
        else:
            mm[a[i]] = 1
    
    print(ans)

main()

Measured memory_bytes: 108884
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<string> hoge(n);
  vector<string> huga(n);
  for(int i=0; i<n; i++){
    cin>>hoge.at(i);
  }
  huga=hoge;

  for(int i=0; i<n; i++){
    for(int j=n-1; j>=i+1; j--){
      if(hoge.at(j)[1]<hoge.at(j-1)[1]){
        string change=hoge.at(j);
        hoge.at(j)=hoge.at(j-1);
        hoge.at(j-1)=change;
      }
    }
  }

  for(int i=0; i<n; i++){
    int minj=i;
    for(int j=i; j<n; j++){
      if(huga.at(j)[1]<huga.at(minj)[1]){
        minj=j;
      }
    }
    string change=huga.at(i);
    huga.at(i)=huga.at(minj);
    huga.at(minj)=change;
  }

  for(int i=0; i<n; i++){
    cout<<hoge.at(i);
    if(i!=n-1){
      cout<<" ";
    }else{
      cout<<endl;
    }
  }
  cout<<"Stable"<<endl;

  for(int i=0; i<n; i++){
    cout<<huga.at(i);
    if(i!=n-1){
      cout<<" ";
    }else{
      cout<<endl;
    }
  }
  if(hoge==huga){
    cout<<"Stable"<<endl;
  }else{
    cout<<"Not stable"<<endl;
  }
}


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

int main(){
    string s;
    cin >> s;
    int a = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2, 2));

    if (1 <= a && a <= 12){
        if(1 <= b && b <= 12){
            cout << "AMBIGUOUS" << endl;
        }
        else{
            cout << "MMYY" << endl;
        }
    }
    else{
        if(1 <= b && b <= 12){
            cout << "YYMM" << endl;
        }
        else{
            cout << "NA" << endl;
        }
    }   
    return 0;
}



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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const PII DATA_NIL = PII(-1, (1LL<<31) - 1);

class SegmentTree {
private:
    const int n;
    vector<PII> dat;
    void prop_to(int i) { dat[i] = max(dat[i<<1], dat[i<<1|1]); }

public:
    SegmentTree(int _n) : n(_n), dat(2*n, DATA_NIL) {}

    void fill(int l, int r, PII x)
    {
        l += n, r += n;
        for (; l<r; l >>= 1, r >>= 1) {
            if (l & 1) { dat[l] = max(dat[l], x); l++; }
            if (r & 1) dat[r-1] = max(x, dat[r-1]);
        }
    }

    int get(int i)
    {
        PII res = dat[i += n];
        while (i >>= 1) { res = max(res, dat[i]); }
        return res.second;
    }

    void dump()
    {
        cerr << "-----------" << endl;
        int h = __lg(2*n);
        for (int i=1; i<=h; i++) {
            for (int j=0; j<1<<(i-1); j++) cerr << dat[(1<<(i-1)) + j].second << " ";
            cerr << endl;
        }
        cerr << "-----------" << endl;
    }
};

int main()
{
    ios::sync_with_stdio(false);

    int N, Q;
    cin >> N >> Q;

    int n = 1;
    while (n < N) { n <<= 1; }
    SegmentTree seg_tree(n);

    rep(q, Q) {
        int T; cin >> T;
        if (T == 0) {
            int A, B, X; 
            cin >> A >> B >> X;
            seg_tree.fill(A, B+1, PII(q, X));
        } else {
            int I; cin >> I;
            cout << seg_tree.get(I) << endl;
        }
        // seg_tree.dump();
    }
}

Measured memory_bytes: 4884
#include <stdio.h>
#include <iostream>
#include <complex>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;
#define INF (1e100)
#define EPS (1e-10)
const double pi = atan2(0.0, -1.0);

P unit(double t) { return P(cos(t), sin(t)); }
double dot(const P& a, const P& b) { return real(conj(a)*b); }
double cross(const P& a, const P& b) { return imag(conj(a)*b); }
int ccw(const P& a, P b, P c) {
    b -= a, c -= a;
    if (cross(b, c) > 0) return 1;
    if (cross(b, c) < 0) return -1;
    if (dot(b, c) < 0) return 2;
    if (norm(b) < norm(c)) return -2;
    return 0;
}
bool intersectSS(const P& s0, const P& s1, const P& t0, const P& t1) {
    return ccw(s0, s1, t0) * ccw(s0, s1, t1) <= 0
        && ccw(t0, t1, s0) * ccw(t0, t1, s1) <= 0;
}
bool intersectSP(const P& s0, const P& s1, const P& p) {
    return abs(s0-p) + abs(s1-p) - abs(s1-s0) < EPS;
}
P projection(const P& l0, const P& l1, const P& p) {
    const double t = dot(p-l0, l0-l1) / norm(l0-l1);
    return l0 + t*(l0-l1);
}
double distanceSP(const P& s0, const P& s1, const P& p) {
    const P r = projection(s0, s1, p);
    if (intersectSP(s0, s1, r)) return abs(r-p);
    return min(abs(s0-p), abs(s1-p));
}
double distanceSS(const P& s0, const P& s1, const P& t0, const P& t1) {
    if (intersectSS(s0, s1, t0, t1)) return 0;
    return min(min(distanceSP(s0, s1, t0), distanceSP(s0, s1, t1)),
               min(distanceSP(t0, t1, s0), distanceSP(t0, t1, s1)));
}

int N, M, L;
P ps[128][8];
double xs[128], ys[128], as[128], rs[128];
double g[128][128], dp[128];
int vis[128];

double solve() {
    rep (i, N) dp[i] = INF;
    rep (i, N) vis[i] = 0;
    dp[M] = 0;
    rep (i, N) {
        int at = -1;
        rep (i, N) if (vis[i] == 0) at = i;
        rep (i, N) if (vis[i] == 0 && dp[i] < dp[at]) at = i;
        vis[at] = 1;
        rep (i, N) if (vis[i] == 0) dp[i] = min(dp[i], dp[at] + g[at][i]);
    }
    return dp[L];
}

int main() {
    for (;;) {
        scanf("%d%d%d", &N, &M, &L);
        if (N == 0) return 0;
        M--, L--;
        rep (i, N) scanf("%lf%lf%lf%lf", xs+i, ys+i, as+i, rs+i);
        rep (i, N) rep (k, 5) {
            const double t = (as[i]+90+k*144) * pi / 180.0;
            ps[i][k] = P(xs[i], ys[i]) + rs[i] * unit(t);
        }
        rep (i, N) rep (j, i) {
            g[i][j] = g[j][i] = INF;
            rep (a, 5) rep (b, 5) {
                const double d = distanceSS(ps[i][a], ps[i][(a+1)%5],
                                            ps[j][b], ps[j][(b+1)%5]);
                g[i][j] = g[j][i] = min(g[i][j], d);
            }
        }
        printf("%.9f\n", solve());
    }
}

Measured memory_bytes: 1396
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
map<int,int> m;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		m[A]++;
	}
	int res=0;
	for(auto i=m.begin();i!=m.end();i++){
		res+=(i->second)%2;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 4992
from collections import Counter

n = int(input())
ss = [input() for _ in range(n)]

inf = float('inf')
l = [inf] * 26

for s in ss:
    num_of_c = Counter(s)
    for i in range(26):
        l[i] = min(l[i], num_of_c[chr(i+97)])
for i in range(26):
    if l[0] == inf:
        l[0] = 0
    print(chr(i+97) * l[i], end = '')


Measured memory_bytes: 3316
#if defined(LOCAL)
#define PROBLEM_NAME "b"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)

void solve(istream& cin, ostream& cout) {
  l a, b, c, k; cin >> a >> b >> c >> k;
  l sum = a + b + c;
  l m = max({a, b, c});
  sum -= m;
  F(i, 0, k) m = m * 2;
  sum += m;
  cout << sum << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int a[5];
	int ptr = 0;
	for(int i=0; i<5; i++){
		cin >> a[i];
		if(a[i]==0)ptr=i+1;
	}
	cout << ptr << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r;
  cin>>r;
  cout<<r*r<<endl;
}

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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }


  int main(){
    int N, K;
    cin >> N >> K;
    map<int, int> A;
    REP(i, N) {
      int x;
      cin >> x;
      A[x]++;
    }

    vector<int> v;
    for(auto x: A) v.push_back(x.second);
    sort(all(v));

    int n = v.size();
    int ans = 0;

    if(n <= K){
      print(0);
      return 0;
    }
    else {
      REP(i, n - K) ans += v[i];
    }

    print(ans);

  
  }

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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    cin>>n;
    cout<<n*n*n;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>

class Dice {
    const std::array<char,4> dirs{ {'N', 'E', 'S', 'W'} };
    const std::map<char,int> index{ {dirs[0],1}, {dirs[1],2}, {dirs[2],3}, {dirs[3],4} };
    /* order: bottom, north, east, south, west, top */
    std::array<int,6> faces{{6, 5, 3, 2, 4, 1}};
    std::array<int,6> nums{{1, 2, 3, 4, 5, 6}};
    int& bottom{faces[0]}; int& north{faces[1]}; int& east{faces[2]};
    int& south {faces[3]}; int& west {faces[4]}; int& top {faces[5]};
public:
    Dice(){};
    Dice(std::array<int,6> d) { Dice(); nums = d; }
    void rotate(char c);
    void roll_tb_axis_clockward(void);
    int get_top(void);
    void set_top(int n);
    int get_east(void);
    int get_south(void);
    ~Dice(){}
};
void Dice::rotate(char c) {
    if(std::find(dirs.begin(), dirs.end(), c) == dirs.end()) return;
    const int i{index.at(c)}, j{(i+5)%4+1};
    const int prev{bottom};
    bottom = faces[i]; faces[i] = top;
    top = faces[j];    faces[j] = prev;
}
void Dice::roll_tb_axis_clockward(void) {
    const int prev{north};
    north = west; west = south;
    south = east; east = prev;
}
int Dice::get_top(void) {
    return nums[top-1];
}
void Dice::set_top(int n) {
    int face_index{};
    for(face_index=0; face_index<6; face_index++) {
        if(nums[faces[face_index]-1] == n) break;
    }
    if(face_index>=6) return;
    const std::array<std::string,6> rotates{ {"NN", "S", "W", "N", "E", ""} };
    for(auto c : rotates[face_index]) {
        rotate(c);
    }
}
int Dice::get_east(void) {
    return nums[east-1];
}
int Dice::get_south(void) {
    return nums[south-1];
}

int main() {
    std::array<int,6> faces;
    for(auto& x : faces) { std::cin >> x; }
    Dice dice1{faces};
    int top_num{faces[0]}, south_num{faces[1]};
    for(auto& x : faces) { std::cin >> x; }
    Dice dice2{faces};
    dice1.set_top(top_num);
    dice2.set_top(top_num);
    for(auto j=0; j<4; j++) {
        if(dice1.get_south() == south_num) break;
        dice1.roll_tb_axis_clockward();
    }
    for(auto j=0; j<4; j++) {
        if(dice2.get_south() == south_num) break;
        dice2.roll_tb_axis_clockward();
    }
    std::cout << (dice1.get_east() == dice2.get_east() ? "Yes" : "No") << std::endl;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define ll           long long
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define scn(a)       scanf("%lld",&a)
#define nl           printf("\n")
#define scns(a,b)    scanf("%lld %lld",&a,&b)
#define print(a)     printf("%lld",a)
#define tc           ll t; scn(t); while(t--)
#define vec          vector<ll>
#define pb           push_back
#define pairs        pair<ll,ll>
#define fi           first
#define se           second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.rbegin(),v.rend())
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         5000005
#define inf          LLONG_MAX
#define zer          LLONG_MIN
#define dbug(a)      cout<<"dbug : "<<a<<endl
#define debug(a,b)   cout<<a<<" "<<b<<endl
#define read(v)      vec v(n,0); rep(i,0,n) {cin>>v[i];}
#define write(a,n)   rep(i,0,n) {cout<<a[i]<<" ";}
#define All          rep(i,0,n) 
ll zero = 0;




int main()
{
	ll n;
	cin>>n;
	read(a);
	
	ll mm = a[0];
	ll ans=0;
	
	rep(i,1,n)
	{
		if(a[i] < mm) ans+=(mm - a[i]);
		else mm = a[i];
	}
	
	cout<<ans;
return 0;
}

Measured memory_bytes: 4812
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll dist[123456];
deque<int> dq;

int main(void){
	int n,i,k;
	ll l,a[123456];
	bool flag = false;
	cin >> n >> l;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(i=1; i<n; ++i){
		if(a[i-1] + a[i] >= l){
			k = i;
			flag = true;
			break;
		}
	}
	if(!flag){
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
	for(i=1; i<k; ++i){
		cout << i << endl;
	}
	for(i=(n-1); i>=k; --i){
		cout << i << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
#!/usr/bin/env python
import sys

def _s(): return sys.stdin.readline().strip()

m = {
    "MON":6,
    "TUE":5,
    "WED":4,
    "THU":3,
    "FRI":2,
    "SAT":1,
    "SUN":7
}
s = _s()
print(m[s])


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

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

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    long long x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define v vector
#define mp make_pair
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
int main() {
	// your code goes here
	IOS;
	ll n,x;
	
	ll i,j,m,k,sum=0;
      char ch;
      cin>>ch;
      int a=ch;
      if(a>=97){
            cout<<"a";
      }
      else{
            cout<<"A";
      }
	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,m,sum=0,sum1=0,i=0;
	while(~scanf("%d,%d",&n,&m)){
		sum+=n*m;
		sum1+=m;
		i++;
	}
	cout<<sum<<endl<<(sum1+i/2)/i<<endl;
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<set>
using namespace std;
#define pb push_back
#define fi first
#define sc second

int main(){
	int n;
	long long x,a[4000],b[2000],ans=0;
	cin>>n>>x;
	for(int i=0;i<n;++i){
		cin>>a[i];
		ans+=a[i];
		a[n+i]=a[i];
		b[i]=a[i];
	}
	for(int r=1;r<n;++r){
		long long s=0;
		for(int i=n;i<2*n;++i){
			if(a[i-r]<b[i-n]){
				b[i-n]=a[i-r];
			}
		}
		for(int i=0;i<n;++i){
			s+=b[i];
		}
		if(s+r*x<ans){
			ans=s+r*x;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
long long MIN(long long a,long long b){return  a<b?a:b;}
int main(){
  long long n,m,r,i,j,k,t[10],d[210][210]={};
  long long c[10][310]={};
  scanf("%lld %lld %lld",&n,&m,&r);
  for(i=0;i<r;i++)scanf("%lld",&t[i]);
  for(i=0;i<r;i++)t[i]--;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)d[i][j]=1e18;
    d[i][i]=0;
  }
  while(m--){
    scanf("%lld %lld %lld",&i,&j,&k);
    d[i-1][j-1]=d[j-1][i-1]=k;
  }
  for(i=0;i<r;i++){
    for(j=0;j<300;j++)c[i][j]=1e18;
    c[i][1<<i]=0;
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      for(k=0;k<n;k++)d[j][k]=MIN(d[j][k],d[j][i]+d[i][k]);
    }
  }
  for(i=0;i<(1<<r);i++){
    for(j=0;j<r;j++){
      if((i&(1<<j))==0)continue;
      for(k=0;k<r;k++)c[k][i|(1<<k)]=MIN(c[k][i|(1<<k)],c[j][i]+d[t[j]][t[k]]);
    }
  }
  /*for(i=0;i<(1<<r);i++){
    for(j=0;j<r;j++)printf("%10d ",c[j][i]);printf("\n");
    }//*/
  j=(1<<r)-1;
  for(i=0;i<r;i++)c[0][j]=MIN(c[0][j],c[i][j]);
  printf("%lld\n",c[0][j]);
  return 0;
}
  


Measured memory_bytes: 512
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		if (x + r > W || x - r < 0 || y + r > H || y - r < 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}

}

Measured memory_bytes: 26264
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int len = s.length();
    string ans = "";
    for(int i = 0; i < len; i++){
        if(s[i] == '1') ans += '1';
        if(s[i] == '0') ans += '0';
        if(s[i] == 'B'){
            if(ans != "") ans = ans.substr(0,ans.length()-1);
        }
    }
    cout << ans << endl;
}

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

using namespace std;
const int MAXN = 3e5 + 5;
const int MAXV = 1e5 + 5;
const int MAXM = 1 << 9;
typedef long long ll;

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

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

template<typename T>
void read(T &x) {
    x = 0;
    int f = 1;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    x *= f;
}

int a[MAXM][MAXV];
int n, m, r, q, v[MAXN], w[MAXN];

int query(int x, int y) {
    if (x <= m) return a[x][y];
    else {
        int ans = query(x / 2, y);
        if (y >= w[x]) chkmax(ans, v[x] + query(x / 2, y - w[x]));
        return ans;
    }
}

int main() {
    read(n), m = (1 << 9) - 1, r = 1e5;
    for (int i = 1; i <= n; i++)
        read(v[i]), read(w[i]);
    for (int i = 1; i <= m; i++) {
        int f = i / 2;
        for (int j = 1; j <= r; j++) {
            a[i][j] = a[f][j];
            if (j >= w[i]) chkmax(a[i][j], v[i] + a[f][j - w[i]]);
        }
    }
    read(q);
    for (int i = 1; i <= q; i++) {
        int x, y;
        read(x), read(y);
        printf("%d\n", query(x, y));
    }
    return 0;
}


Measured memory_bytes: 205384
n = gets.to_i
h = gets.split.map(&:to_i)

h << 10 ** 10
ans = 0
s = 0
h.each_index do |i|
	next if i == 0
	if h[i] > h[i - 1]
		ans = [ans, i - s - 1].max
		s = i
	end
end

puts ans


Measured memory_bytes: 11012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define irep(i,a,b) for(typeof(i) i = (a); i < (b); ++i)
#define itrep(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)


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

	int N;
	cin >> N;
	vector<ll> A(N,-1);
	vector<ll> B(N,-1);
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	if (N % 2 == 1) { 
		int h = (N - 1) / 2; // 真ん中のindex
		cout << B[h] - A[h] + 1 << endl;
	}
	else {
		int hm = N / 2 - 1; // 半分の手前
		int hp = hm + 1; // 半分の後
		cout << (B[hm] + B[hp]) - (A[hp] + A[hm]) + 1 << endl;
	}
	return(0);
}


Measured memory_bytes: 6352
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

ans = abs(A[-1] - W)
if N > 1:
    ans = max(ans, abs(A[-1] - A[-2]))
print(ans)


Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>

int main(){
    int m, f, r;
    char result[50];
    int i=0;
    while(1){
        scanf("%d %d %d", &m, &f, &r);
        if((m==-1)&&(f==-1)&&(r==-1)){
            break;
        }
        else{
            if((m==-1) || (f==-1)){
                result[i] = 'F';
            }
            else if(m+f >= 80){
                result[i] = 'A';
            }
            else if(m+f >= 65){
                result[i] = 'B';
            }
            else if(m+f >= 50){
                result[i] = 'C';
            }
            else if(m+f >= 30){
                if(r >= 50){
                    result[i] = 'C';
                }
                else{
                    result[i] = 'D';
                }
            }
            else{
                result[i] = 'F';
            }
        }
        i = i + 1;
    }

    for(int j=0; j<i; j++){
        printf("%c\n", result[j]);
    }

    return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include<algorithm>
#include <vector>
#include <string>
#include <stdio.h>
#include <cstdio>
#include <ctype.h>
#include <cstdlib>
using namespace std;

int main() {
	int a,b,c,n;
	int d=0;
	cin>>a>>b>>c;
	if(a==b&&b==c&&a%2==0){
				cout<<-1<<endl;

			}else{
	while(a%2==0&&b%2==0&&c%2==0){
		d=(a/2)+(b/2)+(c/2);
		a=a/2;
		b=b/2;
		c=c/2;
		a=a+b+c;
		b=a-b;
		c=a-c;
		a=b+c-a;
		a=(b-a)+(c-a);
		n++;

	}
	cout<<n<<endl;
			}
	return 0;
}


Measured memory_bytes: 256
#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>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int d, n;
    cin >> d >> n;
    int cnt = 0;
    for (int i = 1; i < INF; i++) {
        int now = 0;
        int j = i;
        while (j % 100 == 0) {
            now++;
            j /= 100;
        }
        if (now == d) cnt++;
        if (cnt == n) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256