akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
	int i,j,k,box,n,m,a[1000],b[1000],w[1000],ans,cnt,max;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	max=0;
	ans=0;
	cnt=0;
	for(i=0;i<m;i++){
		w[i]=b[i]-n;
		if(w[i]>0){
			cnt++;
			if(max<=w[i]){
				max=w[i];
			}
		ans+=w[i];
		}
	}
	if(cnt>1){
		printf("%d\n",ans-max);
	}
	else{
		printf("0\n");
	}
	return 0;
}
		


Measured memory_bytes: 2704
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var aa, bb, cc, xx string
	var a, b, c, x int
	if sc.Scan() {
		aa = sc.Text()
		a, _ = strconv.Atoi(aa)
	}
	if sc.Scan() {
		bb = sc.Text()
		b, _ = strconv.Atoi(bb)
	}
	if sc.Scan() {
		cc = sc.Text()
		c, _ = strconv.Atoi(cc)
	}
	if sc.Scan() {
		xx = sc.Text()
		x, _ = strconv.Atoi(xx)
	}

	//fmt.Println(a, b, c, x)

	counter := 0
	for ia := 0; ia <= a; ia++ {
		for ib := 0; ib <= b; ib++ {
			for ic := 0; ic <= c; ic++ {
				if ia*500+ib*100+ic*50 == x {
					counter++
				}
			}
		}
	}
	fmt.Println(counter)
}

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


int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	vector<int> v,vv;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		v.push_back(x);
		vv.push_back(y);
	}
	
	sort(v.begin(),v.end());
	sort(vv.begin(),vv.end());
	
	if(n&1){
		cout<< vv[n/2] - v[n/2]+1;
	}
	else{
		int mn = v[n/2-1] + v[n/2];
		int mx = vv[n/2-1] + vv[n/2];
		cout<<mx - mn + 1;
	}
	return 0;
}


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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int cnt[55];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    pair<int, int> a[n];
    for(int i = 0; i < n; i++)cin >> a[i].fi >> a[i].se;
    pair<int, int> c[m];
    for(int i = 0; i < m; i++)cin >> c[i].fi >> c[i].se;
    for(int i = 0; i < n; i++){
        int min = INT_MAX, in = -1;
        for(int j = 0; j < m; j++){
            int now = abs(a[i].fi - c[j].fi) + abs(a[i].se - c[j].se);
            if(now < min){
                min = now;
                in = j;
            }
        }
        cout << in + 1 << '\n';
    }
    return 0;
}
// Write Here


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

using namespace std;

int n;
vector <pair<int, int>> tree[100010];
vector <int> visited;
set <int> coloured[100010];
vector <int> ans;
int k;

void dfs(int u, int p, int pc)
{
    int c = 1;

    for (auto v: tree[u])
    {
        if (v.first == p)
            continue;

        coloured[u].insert(c);
        coloured[v.first].insert(c);
        
        if (c == pc)
            c++;

        k = max(k, c);
        ans[v.second] = c;
        dfs(v.first, u, c);
        c++;
    }
}

int main()
{
    cin >> n;

    vector <pair<int, int>> edges;

    for (int i = 1; i < n; i++)
    {
        int u, v;

        cin >> u >> v;

        edges.push_back({u, v});

        tree[u].push_back({v, i-1});
        tree[v].push_back({u, i-1});
    }

    ans.assign(n-1, 0);
    dfs(1, 0, 0);

    cout << k << "\n";
    for (int c: ans)
    {
        cout << c << "\n";
    }

    return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int a;
    cin >> a;
    int b = a / 100, c = a % 100;
    if(b >= 1 && b <= 12 && c >= 1 && c <= 12) cout << "AMBIGUOUS\n";
    else if(b >= 1 && b <= 12) cout << "MMYY\n";
    else if(c >= 1 && c <= 12) cout << "YYMM\n";
    else cout << "NA\n";
    return 0;
}

Measured memory_bytes: 256
import sys
imput=sys.stdin.readline

n,m=map(int,input().split())
x=[[] for _ in range(n)]
y=[[] for _ in range(n)]
z=[]
for _ in range(m):
  s,t=map(int,input().split())
  x[s-1].append(t-1)
  y[t-1].append(s-1)
  z.append((s-1,t-1))
e=[-1]*n
e[-1]=0
for i in range(n-1)[::-1]:
  a=0
  for c in x[i]:
    a+=e[c]+1
  e[i]=a/len(x[i])

p=[0]*n
p[0]=1

for i in range(1,n):
  for _p in y[i]:
    p[i]+=p[_p]/len(x[_p])
    
ma=0
for s,t in z:
  k=len(x[s])
  if k==1: continue
  a,b=e[s],e[t]
  c=k/(k-1)*(a-1-b/k)
  ma=max(ma, (a-c-1)*p[s])
print(e[0]-ma)


Measured memory_bytes: 84696
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

bool check(string l, string r) {
	for (int i = 0; i < l.size(); ++i) {
		if (l[i] == r[i] || r[i] == '_') {

		}
		else {
			return false;
		}
	}
	return true;
}
struct warp {
	int x;
	int d;
	int t;
};
bool operator < (const warp&l, const warp&r) {
	return l.x<r.x;
}
int main() {
	int L,N;cin>>L>>N;
	vector<warp>warps;
	warps.push_back(warp{ 0,0,0 });
	for (int i = 0; i < N; ++i) {
		int a,b,c;cin>>a>>b>>c;
		warps.push_back(warp{ a,b,c });
	}
	warps.push_back(warp{ L,0,0 });
	sort(warps.begin(),warps.end());
	vector<int>costs(N+2,1e9);
	costs[0]=0;
	for (int k = 0; k < N + 1; ++k) {
		const int nx=warps[k].x;
		const int nd=warps[k].d;
		const int nt=warps[k].t;
		auto it = lower_bound(warps.begin(), warps.end(), warp{ nx + nd,0,0 });
		
		const int nextx=it->x;
		costs[it-warps.begin()]=min(costs[it - warps.begin()],costs[k]+nt+nextx-(nx+nd));

		costs[k+1]=min(costs[k+1],costs[k]+(warps[k+1].x-nx));
	}
	cout<<costs[N+1]<<endl;


	
	return 0;
}


Measured memory_bytes: 3184
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int num=sc.nextInt();
        String str=String.valueOf(num);
        int NUM=0;

        for(int i=0;i<str.length();i++){
            NUM+=Character.getNumericValue(str.charAt(i));
        }
        
        if(num%NUM==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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


int main(){
    string s;
    cin >> s;
    ll k;
    cin >> k;
    char ini = '1';
    int len = 0;
    rep(i,(int)s.size()){
        if(s[i]=='1'){
            len++;
        }
        else{
            ini = s[i];
            break;
        }
    }
    if(k <= len){
        cout << 1 << endl;
    }
    else{
        cout << ini << endl;
    }




    return 0;
}

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

#define ll long long
#define uint unsigned int
#define vi vector<int>
#define pii pair<int,int>

#define for0(i,n) for(int i=0; i<(n); i++)
#define for1(i,n) for(int i=1; i<=(n); i++)
#define from(i,a,b) for(int i=(a); i<=(b); i++)
#define forr(i,a,b) for(int i=(a); i>=(b); i--)

#define PB push_back
#define MP make_pair
#define FI first
#define SE second

#define all(x) (x).begin(),(x).end()
#define len(x) (int)(x).size()

#define safe_map unordered_map<long long, int, custom_hash>

#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main

void amax(int& x, int y){if(x<y)x=y;}
void amin(int& x, int y){if(x>y)x=y;}
int gcd(int a, int b){if(b){return gcd(b,a%b);}return a;}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {  // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};








void solve1(){
int n; cin>>n;
    if(n<600)
        n=8;
    else if(n<800)
        n=7;
    else if(n<1000)
        n=6;
    else if(n<1200)
        n=5;
    else if(n<1400)
        n=4;
    else if(n<1600)
        n=3;
    else if(n<1800)
        n=2;
    else
        n=1;
    cout << n << '\n';
}


void solve(){
    int a,b,c,k; cin >> a >> b >> c >> k;
    
    while(c<=b||b<=a){
        if(k==0){
            cout<<"No\n";
            return;
        }
        if(b<=a){
            b<<=1;
        }else{
            c<<=1;
        }
        k--;
    }
    cout << "Yes\n";
}

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



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll k,saidai=0;
    int n,q,x;
    cin>>n>>k>>q;
    vector<ll> a(n);
    rep(i,n) a[i]=k-q;
    rep(i,q){
        cin>>x;
        a[x-1]++;
    }
    rep(i,n){
        if(a[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 4008
d,n=map(int,input().split())
l=list(map(int,input().split()))
al=[]
for i in range(1,len(l)):
    al.append(l[i]-l[i-1])
x=l[0]+d-l[n-1]
al.append(x)
#print(al)
mx=max(al)
ss=sum(al)
print(ss-mx)

Measured memory_bytes: 86276
#include <bits/stdc++.h>
#define turbo cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define inf 99999999

using namespace std;

const ll P = 1e9 + 7;

ll tab[105][100005];
ll limit[105];

ll moduluj(ll a){
  if(a%P >= 0)
    return a%P;
  else
    return a%P+P;
}

int main(){
    turbo
    ll x,n,k;
    cin >> n >> k;
    for(ll i=1;i<=n;i++){
      cin >> x;
      limit[i]=x;
    }
    for(ll i=0;i<=k;i++)
      tab[0][i] = 1;
    for(ll i=1;i<=n;i++){
      for(ll j=0;j<=k;j++){
        ll w = tab[i-1][j];
        if(j-min(limit[i],j)-1 != -1)
          w-=tab[i-1][j-min(limit[i],j)-1];
        w = moduluj(w);
        tab[i][j] = moduluj(w + tab[i][j-1]);
      }
    }
    cout << moduluj(tab[n][k]-tab[n][k-1]) << "\n";
    return 0;
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	int N;
	string s;

	cin >> N >> s;

	int ans = 0;

	for (int i = 0; i < N; ++i) {
		int j;
		for (j = i + 1; j < N && s[j] == s[i]; ++j);
		++ans;
		i = j - 1;
	}

	cout << ans << '\n';



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif
  cout << setprecision(20);

  string S;
  cin >> S;
  if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) {
    cout << "Bad" << endl;
  }else {
    cout << "Good" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

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

  string S;
  cin >> S;

  cout << S.substr(0, S.size() - 8) << endl;
  return 0;
}


Measured memory_bytes: 256
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def countLoop(n):
  if n == 1 :
    return 1
  cnt = 0
  for i in range(1,n+1):
    if n >= i :
      n -= i
      cnt += 1
    else :
      return cnt

n = int(input())

c =  collections.Counter(prime_factorize(n))

cnt = 0
for x in c:
  cnt += countLoop(c[x])

print(cnt)

Measured memory_bytes: 9468
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
 
using namespace std;
int main(){
    double a,b,c,d,e,f;
    while((cin>>a>>b>>c>>d>>e>>f)){
        double x = (c*e-b*f)/(a*e-b*d);
        double y = (c*d-a*f)/(b*d-a*e);
        x = round(1000*x) / 1000;
        y = round(1000*y) / 1000;
        if(x==0)x=0;
        if(y==0)y=0;
        cout << fixed << setprecision(3) << x << " " << y << endl;
    }
    return 0;
}

Measured memory_bytes: 3268
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
 
#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
 
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
#define MOD 1000000007
 
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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
 
 
using namespace std;
 
int main()
{
    int r[5];
    vector<int> s;
    ll t = 0;
 
    int m = 20;
    int p;
    rep(i, 5){
        int b;
        cin >> b;
        r[i] = b;
        if(i == 0) p = b;
        if((b % 10)<m && (b % 10 != 0)){
            p = b;
            m = b % 10;
        }
    }
    int flag = 0;
    rep(i, 5){
        if((r[i] == p) && flag == 0){
            flag = 1;
            continue;
        }
        else{
            s.push_back(r[i]);
        }
    }
 
    rep(i, 4){
        if(t % 10 == 0) t += s[i];
        else{
            t += (10 - (t % 10));
            t += s[i];
        }
    }
    if (t % 10 != 0) t += (10 - (t%10));
    t += p;
    cout << t;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using llong = long long;
using ullong = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()
#define loop(i, times) for (llong i = 0; i < times; i++)
#define rloop(i, times) for (llong i = times -1; 0 <= i; i--)

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


int main(void)
{
	string s; cin >> s;
	llong ans1 = 0;
	llong ans2 = 0;

	string s_reverse1;
	string s_reverse2;
	loop(i, (llong)s.size())
	{
		if (i % 2 == 0)
		{
			s_reverse1 += "0";
			s_reverse2 += "1";
		}
		else
		{
			s_reverse1 += "1";
			s_reverse2 += "0";
		}

	}

	loop(i, (llong)s.size())
	{
		if (s[i] != s_reverse1[i])
			ans1++;
		if (s[i] != s_reverse2[i])
			ans2++;
	}

	cout << min(ans1, ans2);
	return 0;
}

Measured memory_bytes: 768
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine(); // 改行
        String[] strz = new String[N];
        for (int n = 0; n < N; n++){
            strz[n] = sc.nextLine();
        }

        for (int n = 0; n < N; n++){
            char[] charn = strz[n].toCharArray();
            Arrays.sort(charn);
            strz[n] = new String(charn);
        }

        Map<String, Integer> map = new HashMap<>();
        for (String s : strz) {
            Integer i = map.get(s);
            map.put(s, i == null ? 1 : i + 1);
        }
        long cnt = 0;
        for (String key : map.keySet()){
            long num = map.get(key);
            if (num > 1) {
                // cnt+=conbi(num,2);
                cnt+= (num*(num-1)/2);
            }
        }
        System.out.println(cnt);
    }

    public static long f (long n){
        if (n<=1){return 1;}
        return f(n-1)*n;
    }
    public static long conbi(long n,long r){
        if ((r - n) < 0) {r = n - r;}
        if (r == 0) {return 1;}
        if (r == 1) {return n;}
        return (f(n)/(f(r)*f(n-r)));
    }
}


Measured memory_bytes: 106032
import math
A, B = map(int, input().split())
x1 = math.ceil(A * 100.0 / 8)
x2 = B * 10
y1 = math.ceil((A+1) * 100.0 / 8)
y2 = (B+1) * 10

r = -1
for p in range(max(x1,x2), min(y1,y2)):
    r = p
    break
print(r)

Measured memory_bytes: 3064
import math
A,B,H,M = map(int, input().split())

# 12時からの角度を求める
# [１分あたりに進む角度]＝３６０÷（１２×６０）
tansin = (H*60+M)*0.5
tyosin = M*6
kakudo = tansin - tyosin
ans = (A**2)+(B**2)-(2*A*B*math.cos(math.radians(kakudo)))
print(math.sqrt(ans))

Measured memory_bytes: 9508
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;


vector<int> cake_cut(int n, int w, int h) {
    vector<pair<int, int>> pieces({{w, h}});
    for(int i = 0; i < n; i++) {
        int p, s;
        cin >> p >> s;
        pair<int, int> piece = pieces[p-1];
        pieces.erase(pieces.begin()+p-1);
        s %= 2*(piece.first + piece.second);
        if(s <= piece.first) {
            int fst = min(s, piece.first - s);
            int snd = max(s, piece.first - s);
            pieces.emplace_back(fst, piece.second);
            pieces.emplace_back(snd, piece.second);
        } else if(s <= piece.first + piece.second) {
            s -= piece.first;
            int fst = min(s, piece.second - s);
            int snd = max(s, piece.second - s);
            pieces.emplace_back(piece.first, fst);
            pieces.emplace_back(piece.first, snd);
        } else if(s <= 2*piece.first + piece.second) {
            s-= piece.first + piece.second;
            int fst = min(s, piece.first - s);
            int snd = max(s, piece.first - s);
            pieces.emplace_back(fst, piece.second);
            pieces.emplace_back(snd, piece.second);
        } else {
            s -= 2*piece.first + piece.second;
            int fst = min(s, piece.second - s);
            int snd = max(s, piece.second - s);
            pieces.emplace_back(piece.first, fst);
            pieces.emplace_back(piece.first, snd);
        }
    }
    vector<int> ret;
    transform(
        pieces.begin(),pieces.end(), back_inserter(ret),
        [](const pair<int, int>& p) { return p.first*p.second; }
    );
    sort(ret.begin(), ret.end());
    return ret;
}

int main() {
   while(true) {
       int n, w, h;
       cin >> n >> w >> h;
       if(n == 0 && w == 0 && h == 0) break;
       vector<int> ret = cake_cut(n, w, h);
       for(int i = 0; i < n; i++) {
           cout << ret[i] << ' ';
       }
       cout << ret[n] << endl;
   }
   return 0;
}

// 
// [Probrem] Cut the Cake
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1149&lang=jp
// 


Measured memory_bytes: 3088
#include<stdio.h>
#include<string.h>
#define LEN 1000005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head = 1, tail = 1, n;

void enqueue(P x){
  Q[tail] = x;
  if(tail + 1 == LEN){tail = 0;}
  else {tail++;}
}

P dequeue(){
  P x;
  x = Q[head];
  if(head + 1 == LEN){head = 0;}
  else {head++;}
  return x;
}


int main(){
  int elaps = 0, c=0,count = 0;
  int i , q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    if(strlen(Q[i].name) > 10){
      printf("%s",Q[i].name);
      count++;
      break;}
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }
  i = 0;
  while(1){
    i++;
    if(count == n)break;
     if((Q[i].t - q) > 0){
       Q[i].t -= q;
       c += q;
       enqueue(Q[i]);
     }
     else {
       c += Q[i].t;
       printf("%s %d\n",Q[i].name,c);
       count++;
       Q[i] = dequeue();
     }
  }
  return 0;
}

Measured memory_bytes: 21080
#include<iostream>
using namespace std;
int main(){
  string s; cin >> s;
  bool ans = true;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='L') ans = false;
    }else{
      if(s[i]=='R') ans = false;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 764
let n = read_int ()
let s = read_line ()
let m = 1_000_000_007
let cs = Array.make 128 0
let _ =
  String.iter (fun c -> cs.(Char.code c) <- cs.(Char.code c) + 1) s;
  Array.fold_left (fun ans c -> ans * (c + 1) mod m) 1 cs - 1 |> Printf.printf "%d\n"

Measured memory_bytes: 640
(defun main ()
  (let ((n (concatenate 'list (read-line)))
        (tmp ""))
    (labels ((change (lst)
                    (let ((v (car lst)))
                      (if (equal v #\1)
                          (setq tmp (concatenate 'string tmp "9"))
                          (if (not (null v))
                              (setq tmp (concatenate 'string tmp "1"))
                              (return-from change nil)))
                      (change (cdr lst)))))
      (change n)
      (princ tmp))))

(main)

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inv2 = 5e8 + 4;

vector< int > g[100000];
vector< vector< int64 > > dp[100000];

void rec(int idx) {
  vector< vector< int64 > > sub(3, vector< int64 >(1));
  sub[0][0] = 1;
  for(auto &to : g[idx]) {
    rec(to);
    auto &ch = dp[to];
    vector< int64 > sub1(ch[0].size() + 1);
    for(int i = 0; i < ch[0].size(); i++) {
      (sub1[i + 1] += ch[0][i] * 2) %= mod;
      (sub1[i + 1] += ch[1][i]) %= mod;
    }
    vector< vector< int64 > > beet(3, vector< int64 >(sub[0].size() + ch[0].size()));
    for(int k = 0; k < 3; k++) {
      for(int i = 0; i < sub[k].size(); i++) {
        for(int j = 0; j <= ch[0].size(); j++) {
          if(j < ch[0].size()) {
            for(int l = 0; l < 3; l++) {
              (beet[k][i + j] += sub[k][i] * ch[l][j] % mod) %= mod;
            }
          }
          if(k == 0) (beet[1][i + j] += sub[k][i] * sub1[j]) %= mod;
          if(k == 1) (beet[2][i + j] += sub[k][i] * sub1[j] % mod * inv2) %= mod;
        }
      }
    }
    for(int k = 0; k < 3; k++) ch[k].clear();
    sub.swap(beet);
  }
  dp[idx].swap(sub);
}

int main() {
  int N;
  cin >> N;
  for(int i = 1; i < N; i++) {
    int p;
    cin >> p;
    g[--p].emplace_back(i);
  }

  int64 fact[2002];
  fact[0] = 1;
  for(int i = 1; i < 2002; i++) {
    (fact[i] = fact[i - 1] * i) %= mod;
  }

  rec(0);

  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    int64 add = 0;
    for(int j = 0; j < 3; j++) (add += dp[0][j][i]) %= mod;
    (add *= fact[N - i]) %= mod;
    if(i & 1) (ret += mod - add) %= mod;
    else (ret += add) %= mod;
  }

  cout << ret << endl;
}


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

using namespace std;

const int mod = 1e9 + 7, N = 2e7 + 5;
int n, m, K, ans, fact[N], invFact[N];

int add (int _a, int _b) {
    _a += _b;
    if (_a >= mod) _a -= mod;
    return _a;
}

int mult (int _a, int _b) { return (int)(1LL * _a * _b % mod); }

int binPow (int _a, int _m) {
    int ret = 1;
    for (; _m; _m >>= 1, _a = mult(_a, _a) ) if (_m & 1) ret = mult(ret, _a);
    return ret;
}

int C (int _k, int _n) {
    if (_k < 0 || _n < 0 || _k > _n) return 0;
    return mult(mult(fact[_n], invFact[_k]), invFact[_n - _k]);
}

int main () {

    fact[0] = 1; for (int i = 1; i < N; ++i) fact[i] = mult(fact[i - 1], i);
    invFact[N - 1] = binPow(fact[N - 1], mod - 2); for (int i = N - 1; i > 0; --i) invFact[i - 1] = mult(invFact[i], i);

    scanf("%d %d %d", &n, &m, &K);

    for (int i = K; i > 0; --i) {
        ans = add(ans, mult(mult(mult(n, m), i), mult(mult(2, fact[K - 2]), mult(K - i, C(K - 2, m + n - 2) ) ) ) );
        ans = add(ans, mult(mult(i, add(n, m) ), mult(C(K - 1, m + n - 1), fact[K - 1]) ) );
    }

    int ret = K;
    for (int i = 0; i < K; ++i) ret = mult(ret, n + m - i);

    printf("%d", add(ans, ret) );

    return 0;
}


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

const long MAX = 100001;
const long NIL = -1;

struct Node{
	long parent, leftChild, rightSibling;
};

struct Node T[MAX];
long n, Depth[MAX];

void print(long id){
	cout << "node " << id << ": ";
	cout << "parent = " << T[id].parent << ", ";
	cout << "depth = " << Depth[id] << ", ";

	if (T[id].parent == NIL) cout << "root, ";
	else if (T[id].leftChild == NIL) cout << "leaf, ";
	else cout << "internal node, ";

	cout << "[";

	for (long i = 0, c = T[id].leftChild; c != NIL; i++, c = T[c].rightSibling){
		if (i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

long setDepth(long id, long parent){
	Depth[id] = parent;
	if (T[id].rightSibling != NIL) setDepth(T[id].rightSibling, parent);
	if (T[id].leftChild != NIL) setDepth(T[id].leftChild, parent + 1);
}

int main(){
	long degree, id, child, leftChild, rightSibling;
	cin >> n;
	for (long i = 0; i < n; i++){
		T[i].parent = T[i].leftChild = T[i].rightSibling = NIL;
	}
	for (long i = 0; i < n; i++){
		cin >> id >> degree;
		for (long j = 0; j < degree; j++){
			cin >> child;
			if (j == 0) T[id].leftChild = child;
			else T[leftChild].rightSibling = child;
			leftChild = child;
			T[child].parent = id; 
		}
	}
	for (long i = 0; i < n; i++){
		if (T[i].parent == NIL) rightSibling = i;
	}

	setDepth(rightSibling, 0);

	for (long i = 0; i < n; i++) print(i);

	return 0;
}

Measured memory_bytes: 7408
#include <bits/stdc++.h>
#include <string>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define endl '\n'
const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
////////////////////////////////
 
int dp[105][MAX];
 
int32_t main(){
    fastio
    int n, W;
    cin >> n  >> W;
    int w[n+1], v[n+1], sum = 0;
    rep(i,1,n,1){
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    memset(dp,MOD,sizeof(dp));
    dp[0][0] = 0;
    int ans =0;
    rep(i,1,n,1){
        rep(val,0,sum,1){
            if(val < v[i]) dp[i][val] = dp[i-1][val];
            else dp[i][val] = min(w[i] + dp[i-1][val-v[i]], dp[i-1][val]);
            if(dp[i][val] <= W) ans = max(ans, val);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 82304
import sys
input = sys.stdin.buffer.readline

def main():
    M,K = map(int,input().split())
    if M == 0:
        if K == 0:
            print(0,0)
        else:
            print(-1)
    elif M == 1:
        if K == 0:
            print(0,0,1,1)
        else:
            print(-1)
    else:
        if 2**M <= K:
            print(-1)
        else:
            use = [i for i in range(2**M)]
            use.pop(K)
            _use = list(reversed(use))
            ans = use+[K]+_use+[K]
            print(*ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 17296
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    H = list(map(int, input().split()))

    ans = 1
    for i in range(1, N):
        ok = True
        for j in range(i):
            if H[j] > H[i]:
                ok = False

        ans += ok
            
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

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

const int N=2005;
int fa[N],a[N],sn[N],sz[N],d[N],s[N],mark[N],dp[N],n,mx;
vi e[N],ans;

void dfs1(int u){
	sz[u]=1;
	for(auto v:e[u]){
		dfs1(v),sz[u]+=sz[v];
		if(sz[v]>sz[sn[u]]) sn[u]=v;
	}
}
void dfs2(int u,int dep){
	s[d[u]=dep]++,mx=max(mx,dep);
	if(sn[u]) dfs2(sn[u],dep);
	for(auto v:e[u])
		if(v!=sn[u]) dfs2(v,dep+1);
}
void rot(int p){
	if(p>1) ans.pb(p);
	for(int t=a[1];p;p=fa[p]) swap(t,a[p]);
}

void solve(int k){
	fill(mark+1,mark+n+1,0);\
	for(int cnt=0;cnt<s[k];){
		int x=a[1];
		if(d[x]==k){
			int y=x; cnt++;
			while(sn[y]&&(a[sn[y]]<=x||!mark[sn[y]])) y=sn[y];
			rot(y);
			while(mark[y]) y=fa[y];
			mark[y]=1;
		}
		else{
			int cur=0;
			rep(i,1,n){
				if(d[i]>k||mark[i]) continue;
				dp[i]=dp[fa[i]]+(d[a[i]]==k);
				if(dp[i]>dp[cur]) cur=i;
			}
			rot(cur);
		}
	}
}

int main(){
	read(n);
	rep(i,2,n){
		read(fa[i]),fa[i]++;
		e[fa[i]].pb(i);
	}
	rep(i,1,n) read(a[i]),a[i]++;
	
	/*
	rep(i,1,n) a[i]=i;
	random_shuffle(a+1,a+n+1);
	freopen("a.in","w",stdout);
	printf("%d\n",n);
	rep(i,2,n) printf("%d ",fa[i]-1);
	puts("");
	rep(i,1,n) printf("%d ",a[i]-1);
	puts("");
	fclose(stdout);
	*/
	
	dfs1(1),dfs2(1,1);
	per(i,mx,1) solve(i);
	rep(i,1,n) assert(a[i]==i);
	printf("%d\n",(int)ans.size());
	for(auto x:ans) printf("%d\n",x-1);
	return 0;
}

Measured memory_bytes: 640
import sys

K, T = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

if len(A) == 1:
    print(A[0] - 1)
else:    
    A.sort(reverse=True)
    other_sum = sum(A[1:])
    print(max(0, A[0] - other_sum - 1))

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

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

	string text = "";
	for (int i = 0; i < n; i++) {
		if (S[i] == '0') text += "0";
		if (S[i] == '1') text += "1";
		if (S[i] == 'B' && (int)text.size() != 0) text.pop_back();
	}
	cout << text << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int inh,inw,ch,cw,dh,dw;
//vector <vector<char>> s;
//vector <vector<int >> mark;
char s[1000][1000];
int mark[1000][1000];
bool isValid(pair<int,int>p,int value){
    //cout << "isvalid " << x << " " << y << endl;
    int x=p.first ,y=p.second;
    if(x<0)return false;
    if(y<0)return false;
    if(x>=inw)return false;
    if(y>=inh)return false;
    if(s[y][x]=='#')return false;
    if(mark[y][x]==-1)return true;
    if(mark[y][x]<=value)return false;
    //cout << "true" << endl;
    return true;
}
bool markIt(pair<int,int>p,int value){
    if(isValid(p,value)){
        mark[p.second][p.first]=value;
        return true;
    }
    return false;
}
void myFill(int x, int y, int value){
    //cout << x << " " << y << " " << value << endl;
    //dequeを使ってBFS
    deque <pair<int,int>>myDeque;
    myDeque.push_back({x,y});
    mark[y][x]=value;
    while(!myDeque.empty()){
        pair <int,int> walk = myDeque.front();
        int cost = mark[walk.second][walk.first];
        myDeque.pop_front();
        pair <int,int> up=walk,down=walk,right=walk,left=walk;
        up.second++;
        down.second--;
        right.first++;
        left.first--;
        if(markIt(up,cost))myDeque.push_front(up);
        if(markIt(down,cost))myDeque.push_front(down);
        if(markIt(right,cost))myDeque.push_front(right);
        if(markIt(left,cost))myDeque.push_front(left);
        for(int i = -2; i <= 2; i++){
            for(int j = -2; j <= 2; j++){
                pair <int,int> magic = walk;
                magic.first+=i;
                magic.second+=j;
                if(markIt(magic,cost+1))myDeque.push_back(magic);
            }
        }
    };
}
int main(){
    cin >> inh >> inw >> ch >> cw >> dh >> dw;
    //s = vector<vector<char>>(inh,vector<char>(inw));
    //mark = vector<vector<int>>(inh,vector<int>(inw,-1));

    for(int i = 0; i < inh; i++){
        for(int j = 0; j < inw; j++){
            cin >> s[i][j];
            mark[i][j]=-1;
        }
    }
    ch--;
    cw--;
    dh--;
    dw--;
    myFill(cw,ch,0);
    cout << mark[dh][dw] << endl;

    #if 0
    for(int i = 0; i < inh; i++){
        for(int j = 0; j < inw; j++){
            cout << mark[i][j]; 
        }
        cout << endl;
    }
    #endif
    return 0;
}

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

int main(){
	int n,x;
	cin>>n>>x;
	
	int l[n],ans[n+1];
	
	for(int i=0;i<n;i++)
		cin>>l[i];
	
	ans[0]=0;
	for(int i=1;i<n+1;i++)
		ans[i]=ans[i-1]+l[i-1];
		
	cout<<(upper_bound(ans,ans+n+1,x)-ans)<<'\n';
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

int a[1001][1001];
queue<pair<int, int>> que;

int main()
{
	memset(a, 0, sizeof(a));
	int h,w;
	cin >> h >> w;
	REP(i, h)REP(j,w)
	{
		char c;
		cin >> c;
		if( c == '#' )
		{
			a[i][j] = 1;
			que.push( pair<int,int>(i,j) );
		}
	}
	
	while( !que.empty() )
	{
		auto p = que.front(); que.pop();
		const int dx[4] = {1,-1,0,0};
		const int dy[4] = {0,0,1,-1};
		REP(i,4)
		{
			auto q = p;
			q.first += dx[i];
			q.second += dy[i];
			if( 0 <= q.first && q.first < h &&
			0 <= q.second && q.second < w &&
			a[q.first][q.second] == 0 )
			{
				a[q.first][q.second] = a[p.first][p.second] + 1;
				que.push( q );
			}
		}
	}

	int maxx = 1;
	REP(i,h)REP(j,w)
	{
		maxx = max( maxx, a[i][j] );
	}

	cout << maxx - 1 << endl;

	return 0;
}

Measured memory_bytes: 12304
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

int main()
{
	long long n, k;
	scanf("%lld%lld", &n, &k);
	long long a[200000];
	for (long long i = 0; i < n; ++i)
	{
		scanf("%lld", a + i);
	}
	std::sort(a, a + n);
	long long l = -1000000000000000001;
	long long r = 1000000000000000001;
	while (r - l > 1)
	{
		long long mid = l + (r - l) / 2;
		long long cnt = 0;
		for (long long i = 0; i < n - 1; ++i)
		{
			long long search;
			if (a[i] < 0)
			{
				search = mid <= 0 ? (-mid + (-a[i] - 1)) / (-a[i]) : mid / a[i];
				cnt += (a + n) - std::lower_bound(a + i + 1, a + n, search);
			}
			else if (a[i] == 0)
			{
				if (mid >= 0) cnt += n - (i + 1);
			}
			else
			{
				search = mid <= 0 ? (mid - (a[i] - 1)) / a[i] : mid / a[i];
				cnt += std::upper_bound(a + i + 1, a + n, search) - (a + i + 1);
			}
		}
		if (cnt >= k)
		{
			r = mid;
		}
		else
		{
			l = mid;
		}
	}
	printf("%lld\n", r);
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s;
	cin >> s;
	int n = s.size();
	int res = n;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] != s[i + 1]) {
			res = min(res, max(i + 1, n - (i + 1)));
		}
	}

	cout << res << endl;
	return 0;
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x)
    {
        c("Yes");
    }
    else
        c("No");
    ed;
    return 0;
}

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

int main() {
    vector<int> n(4);
    rep(i, 4) cin >> n[i];

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

    vector<int> v = {1, 4 ,7, 9};
    cout << (n == v ? "YES" : "NO") << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  char c1[4], c2[4];
  unused = scanf("%s", c1);
  unused = scanf("%s", c2);
  
  if(c1[0]==c2[2] && c1[1]==c2[1] && c1[2]==c2[0]) printf("YES");
  else printf("NO");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main(){
  int ans = 0;

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

  cout << ans << endl;
}



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

int gcd (int a, int b) {//a=20 b=15
    int r = a % b;//r=5
    while (r > 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return (b);
}

int main() {
    int K;
    cin >> K;
    int sum = 0;
    for (int a = 1; a <= K; a++) {
      for (int b = 1; b <= K; b++) {
        for (int c = 1; c <= K; c++) {
          sum += gcd (a, gcd(b,c));
        }
      }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3624
s= input()

def f(s):
    rs=s[::-1]
    for i in range(len(s)):
        if s[i] != rs[i]:
            return False
    return True

if f(s) and f(s[0:(len(s)-1)//2]) and f(s[(len(s)+3)//2-1:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;

  string sharp = "";
  for (int i = 0; i < W+2; ++i){
    sharp += '#';
  }
  vector<string> vec(H+2, sharp);
  for (int i = 1; i < H+1; ++i){
    for (int j = 1; j < W+1; ++j){
      cin >> vec.at(i).at(j);
    }
  }
  for (int i = 0; i < vec.size(); ++i){
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <malloc.h>
#include <string.h>

int main(void) {
  int n;
  scanf("%d", &n);
  int i, a;

  for(i=0; i < n; i++){
    scanf("%d", &a);
    if((a % 2 == 0) && (a % 3 != 0) && (a % 5 != 0)){
      printf("DENIED");
      return 0;
    }
  }
  printf("APPROVED");
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>

using namespace std;

long long a[201];
char s[202];
int main(){
	int t;
	scanf("%d",&t);
	for(int tt=1;tt<=t;tt++){
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			scanf("%lld",&a[i]);
		scanf("%s",s+1);
		for(int i=n;i;i--){
			if(a[i]==0)continue;
			int u=60;
			while(!(a[i]>>u&1))u--;
			for(int j=i-1;j;j--)
				if(a[j]>>u&1)a[j]^=a[i];
		}
		int ans=0;
		for(int i=1;i<=n;i++)
			if(s[i]=='1'&&a[i])
				ans=1;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
double mem[51][5001];
int x,y,z,v[100],used[51][5001];
struct po{int e,a;};
po E[101];

double dfs(int pos,int mo){
  if(pos==y) return mo;
  if(used[pos][mo]) return mem[pos][mo];
  used[pos][mo]=1;
  
  for(int i=0;i<x;i++) {
    int npos=min(y,pos+v[i]),nmo=mo;
    int e=E[npos].e, a=E[npos].a;
    if(e){
      if(e==1)npos=min(y,npos+a);
      if(e==2)nmo+=a;
      if(e==3)nmo=max(0,nmo-a);
    }
    mem[pos][mo] += dfs(npos,nmo)/x;
  }
  return mem[pos][mo];
}

int main(){
  while(1){
  cin>>x>>y>>z;
  if(!x&&!y&&!z)break;
  for(int i=0;i<x;i++)cin>>v[i];
  memset(E,0,sizeof(E));
  for(int i=0,a;i<z;i++)cin>>a,cin>>E[a].e>>E[a].a;

  memset(used,0,sizeof(used));  
  for(int i=0;i<51;i++)for(int j=0;j<5001;j++) mem[i][j]=0;
  cout <<(int)dfs(0,0)<<endl;
  }
  return 0;
}

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

#define testc int t;cin>>t;while(t--)
#define endl "\n"
#define rep(i,a,b) for(int i=a;i<b;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define repi(i,n) for(int i=0;i<n;++i)
#define REPI(i,n) for(int i=0;i<=n;++i)

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vld vector < ld >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()

# define pii pair < int , int >
# define vpii vector < pii >
# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define mod 1000000007

void solve(){
    int h,w;
    cin>>h>>w;
    vvi grid(h+1,vi(w+1,0));
    grid[0][1] = 1;
    REP(i,1,h){
        REP(j,1,w){
            char x;
            cin>>x;
            if(x!='#'){
                grid[i][j] = (grid[i-1][j] + grid[i][j-1])%mod;
                //cout<<i<<" "<<j<<" "<<grid[i][j]<<endl;
            }
        }
    }
    cout<<grid[h][w];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 4224
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<int64_t> a(x);
  vector<int64_t> b(y);
  vector<int64_t> c(z);
  for (int i = 0; i < x; i++) cin >> a[i];
  for (int i = 0; i < y; i++) cin >> b[i];
  for (int i = 0; i < z; i++) cin >> c[i];

  sort(a.begin(), a.end(), greater<int64_t>());
  sort(b.begin(), b.end(), greater<int64_t>());
  sort(c.begin(), c.end(), greater<int64_t>());

  vector<int64_t> abc;  // a + b + c
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      if ((i + 1) * (j + 1) > k) break;
      for (int m = 0; m < z; m++) {
        if ((i + 1) * (j + 1) * (m + 1) > k) break;

        abc.push_back(a[i] + b[j] + c[m]);
      }
    }
  }
  sort(abc.begin(), abc.end(), greater<int64_t>());
  for (int i = 0; i < k; i++) {
    cout << abc[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 1404
N, W = map(int, input().split())
v = []
w = []
for _ in range(N):
    vi, wi = map(int, input().split())
    v.append(vi)
    w.append(wi)

dp = [[0] * (W+1) for _ in range(N+1)]
# print(v)
# print(w)
for i in range(N):
    for j in range(W+1):
        dp[i+1][j] = max(dp[i][j - w[i]] + v[i], dp[i]
                         [j]) if j >= w[i] else dp[i][j]

# print(*dp, sep='\n')
print(dp[N][W])



Measured memory_bytes: 41884