akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

signed main() {
  string s,t;
  cin >> s >> t;
  map<char,set<int>> mp;
  for(int i=0; i<s.size(); i++) {
    char c = s[i];
    if(mp.count(c)) mp[c].insert(i);
    else mp[c] = set<int>({i});
  }

  long long ans = 0;
  int pos = 0;
  for(auto c : t) {
    set<int>& p = mp[c];
    auto it = p.lower_bound(pos);
    if(it == p.end()) {
      ans += s.size();
      pos = 0;
      it = p.lower_bound(pos);
      if(it == p.end()) {puts("-1"); return 0;}
    }

    pos = (*it) + 1;
    //cout << c << " " << pos << " " << ans << endl;
  }
  ans += pos;
  cout << ans << endl;
}


Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){

  int n;
  while( cin >> n , n ){

    int ans,M = 0;
    int a,b,c;
    for( int i = 0 ; i < n ; i++ ){
      cin >> a >> b >> c;
      if( b + c > M ){
	ans = a;
	M = b + c;
      }
    }

    cout << ans << " " << M << endl;

  }
  return 0;
}

Measured memory_bytes: 1160
import sys
import numpy as np
MOD = 1000000007
def main():
    n, m = [int(x) for x in input().split()]
    pattern = [1]
    broken = -1
    brokencnt = 0
    if brokencnt < m:
        broken = int(input())
        brokencnt += 1
    for i in range(1, n + 1):
        if i == broken:
            pattern.append(0)
            if brokencnt < m:
                broken = int(input())
                brokencnt += 1
            continue
        if i == 1:
            pattern.append(pattern[i - 1])
        if i > 1:
            pattern.append((pattern[i - 1] + pattern[i - 2]) % MOD)
    print(pattern[n])
main()

Measured memory_bytes: 16288
#include <iostream>
using namespace std;
int main() {
    char a[50],b[50];
    for(int i=0;i<50;i++)
    {
        a[i]='\0';
        b[i]='\0';
    }
    cin>>a>>b;
    char c[100];
    int at=0,bt=0;
    for(int i=0;i<100;i++)
    {
        if(i%2==0)
        {
            c[i]=a[at];
            at++;
        }
        else
        {
            c[i]=b[bt];
            bt++;
        }
    }
    for(int i=0;i<100;i++)
    {
        if(c[i]!='\0')cout<<c[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
conseq = 0
ans = False
for i in range(n):
  d1,d2 = map(int,input().split())
  if d1 == d2:
    conseq += 1
    if conseq >= 3:
      ans = True
  else:
    conseq = 0

if ans:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9176
h,w,d = map(int, input().split())
al = []
num_to_xy = [(-1,-1)]*(h*w+1)
for hi in range(h):
    row = list(map(int, input().split()))
    for wi,v in enumerate(row):
        num_to_xy[v] = (hi+1, wi+1)

dist_l = [ [] ]*(d+1)
for start in range(1,d+1):
    dists = [0]
    c_dist = 0
    for i in range(start, h*w-d+1, d):
        x1,y1 = num_to_xy[i]
        x2,y2 = num_to_xy[i+d]
        dist = abs(x2-x1) + abs(y2-y1)
        c_dist += dist
        dists.append(c_dist)
    dist_l[start] = dists


ansl = []
q = int(input())
for _ in range(q):
    l,r = map(int, input().split())
    start = l%d
    if start == 0: start = d
    posl, posr = (l-start)//d, (r-start)//d
    ans = dist_l[start][posr] - dist_l[start][posl]
    ansl.append(ans)

for a in ansl: print(a)

Measured memory_bytes: 91116
#include<iostream>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxx = 1e6;
ll a[maxx];
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i ++) cin >> a[i]; 
	if(n == 1) puts("0");
	else{
		ll cnt = 0, ans = 0;
		for(int i = 1; i < n; i ++)
		{
			if(a[i - 1] >= a[i])
			{
				cnt ++;
			}
			else cnt = 0;
			ans = max(ans, cnt);
		}
		cout << ans << '\n';
	}
	

	return 0;
}



Measured memory_bytes: 1024
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll n,m,x;
  cin >> n >> m >> x;

  vll c(n);
  vector<vector<ll>>  a(n,vector<ll>(m));

  rep(i,n)
  {
    cin >> c[i];
    rep(j,m)
    {
      cin >> a[i][j];
    }
  }

  ll ans = LLONG_MAX;
  bool OK = false;

  for(ll bit = 0;  bit < (1 << n); bit++)
  {
    ll val = 0;
    vll b(m,0);
    for(ll i = 0; i < n; i++)
    {
      if((bit >> i) & 1)
      {
        val += c[i];
        rep(j,m)
        {
          b[j] += a[i][j];
        }
      }
    }

    bool flg = true;
    rep(i,m)
    {
      if(b[i] < x)
      {
        flg = false;
      }
    }

    if(flg)
    {
      ans = min(ans,val);
      OK = true;
    }

  }

  if(OK) cout << ans << endl;
  else cout << -1 << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 3628
N = int(input())
K = int(input())


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


def contain_one(n):
    a = 100
    max_num = 10**a

    while 1:
        if n // max_num == 0:
            a -= 1
            max_num = 10**a
        else:
            break

    return 9*a+(n//max_num)


def contain_two(n):
    if n <=10:
        return 0

    a = 100
    max_num = 10**a

    while 1:
        if n // max_num == 0:
            a -= 1
            max_num = 10**a
        else:
            break

    cnt = 0
    #10^a位まで
    for i in range(1, a):
        cnt += 9*9*i

    #10^a位
    tmp = n // max_num
    cnt += 9*a*(tmp-1)

    #nの10^a桁より小さい数
    tmp = n % max_num
    #怪しい
    if tmp != 0:
        cnt += contain_one(tmp)

    return cnt


def contain_three(n):
    if n <=100:
        return 0

    a = 100
    max_num = 10**a

    while 1:
        if n // max_num == 0:
            a -= 1
            max_num = 10**a
        else:
            break

    cnt = 0
    #10000以上の時ここがダメ
    for i in range(2, a):
        if i == 2:
            cnt += 9**2 * 9
        else:
            #3H(a-2) = aCa-2
            cnt += 9**2 * 9 * cmb(i, i-2)
            #aH2
            #cnt += 9**2 * 9 * (i*(i+1)//2)
            # tmp = tmp * 3
            # cnt += tmp


    tmp = n // max_num
    if a == 2:
        cnt += 9**2 * (tmp-1)
    else:
        cnt += 9**2 * (tmp-1) * cmb(a, a-2)


    tmp = n % max_num
    if tmp != 0:
        cnt += contain_two(tmp)

    return cnt


if K == 1:
    print(contain_one(N))
elif K == 2:
    print(contain_two(N))
else:
    print(contain_three(N))


Measured memory_bytes: 3192
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    fastIO;
    int H, W, K;
    cin >> H >> W >> K;
    int r[H] = {0}, C[W] = {0};
    vvi a(H, vi(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c;
            cin >> c;
            if (c == '#')   a[i][j] = 1;
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << H); i++) {
        for (int j = 0; j < (1 << W); j++) {
            int black = 0;
            for (int row = 0; row < H; row++) {
                for (int col = 0; col < W; col++) {
                    if ((i & (1 << row)) || (j & (1 << col))) {
                        continue;
                    } else  black += a[row][col];
                }
            }
            if (black == K) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void bfs(int ind, queue<int>& bfs_q, vector<int>& path, int n, int x, int y){
    if(y==ind){
        swap(x,y);
    }
    if(ind>0 && path[ind-1]==-1){
        path[ind-1]=path[ind]+1;
        bfs_q.push(ind-1);
    }

    if(ind<n-1 && path[ind+1]==-1){
        path[ind+1]=path[ind]+1;
        bfs_q.push(ind+1);
    }

    if(ind==x && path[y]==-1){
        path[y]=path[ind]+1;
        bfs_q.push(y);
    }
}

void solve(){
    int n,k,x,y;
    cin>>n>>x>>y;
    x--;
    y--;
    vector<vector<int>> path(n,vector<int>(n,-1));
    vector<int> ans(n,0);
    for(int i=0;i<n;i++){
        queue<int> bfs_q;
        bfs_q.push(i);
        path[i][i]=0;
        while(!bfs_q.empty()){
            bfs(bfs_q.front(),bfs_q,path[i],n,x,y);
            bfs_q.pop();
        } 
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans[path[i][j]]++;
        }
    }

    for(int i=1;i<n;i++){
        cout<<ans[i]<<"\n";
    }
}

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

    solve();
    return 0;
}

Measured memory_bytes: 16000
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int n,MOD,a,b,c,t;

template<class T>
class matrix{
public:
	vector<vector<T>> elm;
	int height,width;
	
	
	matrix():height(0),width(0){};
	matrix(int h,int w):height(h),width(w){
		elm.resize(h,vector<T>(w,0));	//0-padding
	}
	
	matrix<T> operator + (const matrix &m)const{
		matrix<T> ret = this;
		rep(i,height) rep(j,width) ret[i][j] += m.elm[i][j];
		return ret;
	}
	matrix<T> operator - (const matrix m)const{
		matrix<T> ret = this;
		rep(i,height) rep(j,width) ret[i][j] -= m.elm[i][j];
		return ret;
	}
	matrix<T> operator * (const matrix m)const{
		assert(width==m.height);
		matrix<T> ret(height,m.width);
		rep(i,height){
			rep(j,m.width){
				rep(k,width){
					(ret.elm[i][j] += elm[i][k]*m.elm[k][j])%=MOD;
				}
			}
		}
		return ret;
	}
	
	void output(){
		rep(i,height){
			rep(j,width){
				if(j)cout<<" ";
				cout<<elm[i][j];
			}
			cout<<endl;
		}
	}
	
	matrix<T> tern(){
		matrix<T> ret(width,height);
		rep(i,height) rep(j,width) ret.elm[j][i] = elm[i][j];
		return ret;
	}
};


vector<matrix<int>> T;

matrix<int> f(int t,matrix<int> v){
	matrix<int> ret = v;
	int c=0;
	while(t){
		if(t%2==1)ret = T[c]*ret;
		t/=2;
		c++;
	}
	return ret;
}


int main(){
	while(cin>>n>>MOD>>a>>b>>c>>t&&(n||MOD||a||b||c||t)){
		matrix<int> v(n,1);
		rep(i,n)cin>>v.elm[i][0];
		
		T.clear();
		T.resize(30,matrix<int>(n,n));
		rep(i,n)T[0].elm[i][i]=b;
		rep(i,n-1)T[0].elm[i][i+1]=c;
		rep(i,n-1)T[0].elm[i+1][i]=a;
		
		for(int i=1;i<30;i++) T[i] = T[i-1] * T[i-1];
		
		f(t,v).tern().output();
	}
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    vector<int> s = a;
    sort(s.rbegin(), s.rend());
    rep(i,n){
        int ans = s.at(0);
        if(s.at(0) == a.at(i)) ans = s.at(1);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3200
'use strict'

//定数
const INF  =  900719925474099 // Math.floor(Number.MAX_SAFE_INTEGER / 10);


function Main(input){
	let temp = input.trim().split('\n');
	let n = parseInt(temp[0]);
	let a = ('0 ' + temp[1]).split(' ').map((v)=>parseInt(v));


	let dp = [...new Array(n+5)].map(()=>new Array(2));
	dp[0][0] = 0;
	dp[0][1] = -INF;

	//動的計画法で殴る
	for(let i=1;i<=n;i++){
		//反転しない場合
		dp[i][0] = Math.max( dp[i-1][0]+a[i], dp[i-1][1]-a[i] );

		//反転する場合
		dp[i][1] = Math.max( dp[i-1][0]-a[i], dp[i-1][1]+a[i] );
	}

	//回答出力
	//console.log([...dp].map((v)=>v.join(',')));
	console.log(dp[n][0]);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 57608
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
inline int power(int a, int b) {
    long long res = a, ans = 1;
    for (; b; b >>= 1, res = res * res % mod) if (b & 1) ans = ans * res % mod;
    return ans;
}
void fwt(int *a, int n, int type) {
    for (int p = 0; p < n; p++) {
        for (int i = 0; i < 1 << n; i++) {
            if ((i >> p) & 1) {
                int x = a[i ^ (1 << p)], y = a[i];
                a[i ^ (1 << p)] = (x + y) % mod;
                a[i] = (x - y + mod) % mod;
            }
        }
    }
    if (type == -1) {
        int inv = power(1 << n, mod - 2);
        for (int i = 0; i < 1 << n; i++) a[i] = 1ll * a[i] * inv % mod;
    }
}
int n, p[1 << 18], sum, a[1 << 18], b[1 << 18];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < 1 << n; i++) {
        scanf("%d", p + i);
        sum += p[i];
    }
    sum = power(sum, mod - 2);
    for (int i = 0; i < 1 << n; i++) {
        p[i] = 1ll * p[i] * sum % mod;
    }
    p[0]--;
    for (int i = 1; i < 1 << n; i++) a[i] = mod - 1;
    a[0] = (1 << n) - 1;
    fwt(a, n, 1);
    fwt(p, n, 1);
    for (int i = 1; i < 1 << n; i++) b[i] = 1ll * a[i] * power(p[i], mod - 2) % mod;
    fwt(b, n, -1);
    for (int i = 1 << n; i --> 0; ) b[i] = (b[i] + mod - b[0]) % mod;
    for (int i = 0; i < 1 << n; i++) printf("%d\n", b[i]);
    return 0;
}

Measured memory_bytes: 5888
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N, M = map(int, input().split())
    f = set(range(1,M+1))
    for _ in range(N):
        a = set(list(map(int, input().split()))[1:])
        f.intersection_update(a)
    print(len(f))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#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

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;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a(n),b(n);
	ll sum1=0,sum2=0,diff=0;
	int ans=0;
	priority_queue<ll> que;
	rep(i,n){
		cin>>a[i];
		sum1+=a[i];
	}
	rep(i,n){
		cin>>b[i];
		sum2+=b[i];
		if(a[i]-b[i]>0){
			que.push(a[i]-b[i]);
		}else if(a[i]-b[i]<0){
			ans++;
			diff+=b[i]-a[i];
		}
	}
	if(sum1<sum2){
		cout<<-1<<endl;
		return 0;
	}
	while(!que.empty() && diff>0){
		ll now=que.top();
		que.pop();
		ans++;
		diff-=now;
	}
	cout<<ans<<endl;
}

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

int main() {
  int H, M, h, m, K;
  cin >> H >> M >> h >> m >> K;
  cout <<  h*60+m-K-(H*60+M) << endl;
}

Measured memory_bytes: 3564
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		byte[] cc = (" " + sc.next()).getBytes();
		int n = cc.length - 1;
		if (cc[n] != '0' || cc[1] != '1' || cc[n - 1] != '1') {
			println(-1);
			return;
		}
		for (int i = 2, j = n - 2; i < j; i++, j--)
			if (cc[i] != cc[j]) {
				println(-1);
				return;
			}
		int i = 1;
		for (int j = 2; j <= n / 2; j++)
			if (cc[j] == '1' || j == n / 2)
				while (i < j) {
					println(i + " " + j);
					i++;
				}
		if (cc[i] == '1') {
			i++;
			println(i - 1 + " " + i);
		}
		for (int j = i + 1; j <= n; j++)
			println(i + " " + j);
	}
}


Measured memory_bytes: 48892
n = int(input())

def func(n):
    if n%2 == 0:
        return int(n/2)
    else:
        return int(3*n+1)

l = []
ans = 0

while n not in l:
    l.append(n)
    ans+=1
    n = func(n)

print(ans+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main()
{
	int k, x;
	cin >> k >> x;
	int max;
	int min;
	min = x - k + 1;
	max = x + k - 1;
	for (int i = min; i <= max;i++){
		cout << i << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
def decrease_height_by_one(hs):
    highest_indexes = [i for i, h in enumerate(hs) if h == max(hs)]
    is_indexes_discontinuous = (i1+1 < i2 for i1, i2 in
                                zip(highest_indexes, highest_indexes[1:]))
    for index in highest_indexes:
        hs[index] -= 1
    return 1 + sum(is_indexes_discontinuous)

input()
hs = list(map(int, input().split()))

n = 0
while max(hs):
  n += decrease_height_by_one(hs)
print(n)


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

using namespace std;
int main() {
	int a, b;
	string s;
	cin >> a >> b;
	cin >> s;
	if(s.length() != a + b + 1){
		cout << "No" << endl;
	}else{
		int c = 1;
		for(int i=0; i<s.length(); i++){
			if(s[i] == '-' && i == a){
				c--;
			}
			else if(s[i] < '0' || s[i] > '9'){
				cout << "No" << endl;
				return 0;
			}
		}
		if(c == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define P 1000000007
#define M 1000005
using namespace std; 
int main() { 
	int w,h,x,y;
	cin>>w>>h>>x>>y;
	printf("%lf ",1.0*w*h/2);
	if(x*2==w&&2*y==h)puts("1");
	else puts("0");
	return 0;
}

Measured memory_bytes: 384
from fractions import gcd
from functools import reduce
import sys

N, M = map(int,input().split())
an = list(map(lambda x: int(x)//2,input().split()))

time = 0

def myfunc(x):
  cnt = 0
  while True:
    if x%2!=0:break
    x = x//2
    cnt += 1
  return cnt

f0 = myfunc(an[0])

for a in an[1:]:
  if myfunc(a) != f0:
    print(0)
    sys.exit()

lcm = reduce(lambda x, y: (x*y)//gcd(x,y),an)
if lcm > M:
  print(0)
  sys.exit()
print((M//lcm +1)//2)

Measured memory_bytes: 16308
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    ll N ; cin >> N ;// contry
    ll M ; cin >> M ;// road
    ll R; cin >> R;// visit
    vector<ll>r;
    rep(i,R){
        ll inp; cin >> inp;
        inp--;
        r.pb(inp);
    }
    sort(all(r));
    
    ll road[201][201];
    rep(i,201)rep(j,201) road[i][j] = 1e9+7;
    rep(i,201) road[i][i] = 0;
    rep(i,M){
        ll a,b,c;cin >> a >> b >> c;
        a--; b--;
        road[a][b] = c;
        road[b][a] = c;
    }
    rep(k,N)rep(i,N)rep(j,N)
        road[i][j] = min(road[i][j] , road[i][k] + road[k][j]);

    
    ll ans = 10e9 + 7;
    do{
        ll ret = 0;
        rep(i,r.size()-1)
            ret += road[r[i]][r[i+1]];
        ans = min(ret, ans);
    }while(next_permutation(all(r)));
    
    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  //s[0]=0の場合
  int ans0 = 0;
  for(int i = 0; i < s.length(); i+=2){
    if(s[i]!='0') ans0++;
  }
  for(int i = 1; i < s.length(); i+=2){
    if(s[i]!='1') ans0++;
  }
  //s[0]=1の場合
  int ans1 = 0;
  for(int i = 0; i < s.length(); i+=2){
    if(s[i]!='1') ans1++;
  }
  for(int i = 1; i < s.length(); i+=2){
    if(s[i]!='0') ans1++;
  }
  if(ans0<=ans1) cout << ans0;
  else cout << ans1;  
}

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

int main() {
  string S,T;
  cin>>S>>T;
  int a,b;
  cin>>a>>b;
  string U;
  cin>>U;
  if(U==S)cout<<a-1<<' '<<b<<endl;
  else cout<<a<<' '<<b-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
 
typedef long long ll;
typedef pair<int, int> P;
 
 
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    int N;
    cin >> N;
    vector<string> s(N);
    rep(i, N) cin >> s[i];
 
    int cnt = 0;
    rep(i, N) {
        if (s[i][0] == 'A') cnt++;
        else cnt--;
 
        if (cnt < 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
 
    if (cnt == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
 
}

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

int main(){
	int N;
	scanf("%d", &N);
	int a_p, b_p, c_p;
	scanf("%d %d %d", &a_p, &b_p, &c_p);
	for (int i = 1; i < N; ++i){
		int a, b, c, tmpa = a_p, tmpb = b_p, tmpc = c_p;
		scanf("%d %d %d", &a, &b, &c);
		a_p = a + max(tmpb, tmpc);
		b_p = b + max(tmpc, tmpa);
		c_p = c + max(tmpa, tmpb);
	}
	printf("%d\n", max({a_p, b_p, c_p}));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int K,S;
    cin >> K >> S;
    int cnt = 0;
    for(int X = 0;X<=K;X++){
        for(int Y=0;Y<=K;Y++){
            int Z = S - X - Y;
            if(Z>=0&&Z<=K){
                cnt++;
            }
        }
    }
    cout << cnt  << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;
int n , k;
int a[103];

int main()
{
    cin >> n >> k;
    for(int i = 1; i<= n; i++) cin >> a[i];

    vector<bool> f(k+1, false);
    for(int i = 1; i <= k; i++)
    for(int j = 1; j <= n; j++)
        if ( i >= a[j] && !f[i- a[j]] ) f[i] = true;

string str[2] = {"Second", "First"};
    cout <<str[(int)f[k]];

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, k, a, b, c;
  string s;
  in3(n, k, s);
  a = b = 0;
  if(n == 1 && k == 1 && s == "1"){
    out(1);
    memi;
    return 0;
  }
  while(k > 0){
    if(s[b] == '0')
      k--;
    while(s[b] == s[b + 1]){
      b++;
      if(b == n - 1){
        out(n);
        memi;
        return 0;
      }
    }
    if(b == n - 1){
      out(b);
      memi;
      return 0;
    }
    b++;
  }
  while(s[b] == s[b + 1]){
    b++;
    if(b == n - 1){
      out(n);
      memi;
      return 0;
    }
  }
  c = b - a + 1;
  while(b < n - 1){
    while(s[a] == s[a + 1])
      a++;
    if(s[a] == '0'){
      a++;
      b++;
      while(s[b] == s[b + 1]){
        b++;
        if(b == n - 1)
          break;
      }
      if(b != n - 1 && s[b] == '0'){
        b++;
        while(s[b] == s[b + 1]){
          b++;
          if(b == n - 1)
            break;
        }
      }
      c = max(c, b - a + 1);
    }
    a++;
  }
  out(c);
  memi;
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL N = 1000000007;

LL ec = 0,hed[200005] = {0},nxt[400005],to[400005];
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL n,flg,a[200005];
LL deg[200005] = {0},siz[200005],mx[200005];

void dfs(LL u,LL f){
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
		mx[u] = max(mx[u],mx[v]);
		siz[u] += siz[v];
	}
	if(deg[u] == 1){
		siz[u] = a[u];
		mx[u] = a[u];
	}
	else{
		LL del = siz[u] - a[u],mxd;
		mxd = (mx[u] * 2 > siz[u] ? siz[u] - mx[u] : (siz[u] >> 1));
		if(del < 0 || del > mxd) flg = 0;
		siz[u] -= (del << 1); mx[u] = siz[u];
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v;
	cin >> n;
	for(LL i = 1;i <= n;i ++) cin >> a[i];
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		add_edge(u,v); add_edge(v,u);
		deg[u] ++; deg[v] ++;
	}
	
	if(n == 2){
		if(a[1] == a[2]) cout << "YES" << endl;
		else cout << "NO" << endl;
		return 0;
	}
	
	LL rt = 1; for(LL i = 1;i <= n;i ++) if(deg[i] != 1) rt = i;
	add_edge(n + 1,rt); a[n + 1] = 0;
	flg = 1; dfs(n + 1,0);
	cout << (flg ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 16768
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

C = sorted(C, reverse=True)
AB = sorted([a + b for a in A for b in B], reverse=True)

ABC_k = sorted([ab + c for ab in AB[:K] for c in C], reverse=True)

for ans in ABC_k[:K]:
    print(ans)

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

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

constexpr int INF = 2000000000;
constexpr ll LLINF = 9000000000000000000;

void dfs(int u, vvi &E, vi &p, vi &sz) {
	sz[u] = 1;
	for (int v : E[u])
		if (p[u] != v) {
			p[v] = u;
			dfs(v, E, p, sz);
			sz[u] += sz[v];
		}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int N;
	cin >> N;
	vvi E(N, vi());
	for (int i = 0; i + 1 < N; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	vi p(N, -1), sz(N, 0);
	dfs(0, E, p, sz);

	vi path;
	int c = N - 1, psz = 0;
	while (c >= 0) {
		path.push_back(sz[c] - psz);
		psz = sz[c];
		c = p[c];
	}
	reverse(path.begin(), path.end());
	
	ll ls = 0LL, rs = 0LL;
	int i = 0, j = (int)path.size() - 1;
	while (i <= j) {
		ls += path[i++];
		if (i <= j) rs += path[j--];
	}
	
	cout << (ls > rs ? "Fennec" : "Snuke") << endl;
	
	return 0;
}


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

#define stx tuple<int, int, int>
#define xt pair<int, int>

int main() {
  int N, Q;
  cin >> N >> Q;
  priority_queue<stx, vector<stx>, greater<stx>> STX;
  int S, T, X, D[Q];
  for (int i = 0; i < N; i++) {
    cin >> S >> T >> X;
    STX.push(stx(S - X, T - X, X));
  }
  for (int i = 0; i < Q; i++) {
    cin >> D[i];
  }

  priority_queue<xt, vector<xt>, greater<xt>> XT;
  for (int i = 0; i < Q; i++) {
    while (!STX.empty() && get<0>(STX.top()) <= D[i]) {
      XT.push({get<2>(STX.top()), get<1>(STX.top())});
      STX.pop();
    }

    while (!XT.empty() && XT.top().second <= D[i]) XT.pop();

    if (XT.empty())
      cout << -1 << endl;
    else
      cout << XT.top().first << endl;
  }

  return 0;
}


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

int main(void)
{
    ll a;
    cin >> a;
    ll ans = a + pow(a, 2) + pow(a, 3);
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 4096
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
 struct edge{ int to; int cost; };
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n,q,k,d[100000];
vector<edge> graph[100000];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	for(int i = 0;i < n;i++) d[i] = INF;
	d[s] = 0;
	que.push(make_pair(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0;i < graph[v].size();i++){
			edge e = graph[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(make_pair(d[e.to],e.to));
			}
		}
	}
}

signed main(){
	cin >> n;
	for(int i = 0;i < n - 1;i++){
		int a,b,c;
		cin >> a >> b >> c; a--;b--;
		graph[a].push_back({b,c});
		graph[b].push_back({a,c});
	}
	cin >> q >> k;
	k--;
	dijkstra(k);
	for(int i = 0;i < q;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		cout << d[a] + d[b] << endl;
	}
	return 0;
}

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

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

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;
    vector<int> sizes;

    Unionfind(int n) : par(n), sizes(n, 1) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[ry] = rx;
        sizes[rx] += sizes[ry];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return sizes[root(x)];
    }

};

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

    int x;
    cin >> x;

    if(x) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3608
import sys
from collections import deque

readline = sys.stdin.readline

N, M = map(int, readline().split())
G = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, readline().split())
    G[x-1].append((y-1, 2*i))
    G[y-1].append((x-1, 2*i+1))

G0 = [None]*N
V = [(0, -1)]
used = [0]*N
used[0] = 1
que = deque([0])
while que:
    v = que.popleft()
    g = []
    for e in G[v]:
        w, d = e
        if used[w]:
            continue
        g.append(e)
        V.append(e)
        used[w] = 1
        que.append(w)
    G0[v] = g

memo = [0]*(2*N+1)
for v, e in reversed(V):
    r = 1
    for w, d in G0[v]:
        r = r * (1 + memo[d]) % M
    memo[e] = r

lv = [0]*(2*N); rv = [0]*(2*N)
for v, e in V:
    s = 1 + memo[e ^ 1]
    for w, d in G0[v]:
        lv[d] = s
        s = s * (1 + memo[d]) % M
    s = 1
    for w, d in reversed(G0[v]):
        rv[d] = s
        s = s * (1 + memo[d]) % M
    for w, d in G0[v]:
        memo[d ^ 1] = lv[d] * rv[d] % M

ans = []
for v in range(N):
    r = 1
    for w, d in G[v]:
        r = r * (1 + memo[d]) % M
    ans.append("%d\n" % r)
sys.stdout.writelines(ans)

Measured memory_bytes: 94316
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int x;

  for (int i = 1; i <= 5; i ++) {
    std::cin >> x;

    if (x != i) {
      std::cout << i << std::endl;

      return 0;
    }
  }

  assert(false);

  return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main(){
  int n1, n2, n3;
  
  scanf("%d %d %d", &n1, &n2, &n3);
  if((n1!=5 && n1!=7) || (n2!=5 && n2!=7) || (n3!=5 && n3!=7)) printf("NO\n");
  else if((n1==7 && n2==7) || (n1==7 && n3==7) || (n2==7 && n3==7)) printf("NO\n");
  else printf("YES\n");
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
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; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
template<class T> struct RollingHash{
    using ull=unsigned long long int;
    const ull M=(1ull<<61)-1;
    const ull mask30 = (1ull << 30) - 1;
    const ull mask31 = (1ull << 31) - 1;
    const ull mask61 =M;
    vector<ull> hash,pows;
    ull base;

        // mod 2^61-1
    ull cal_mod(ull x){
        ull xu=(x>>61);
        ull xd=(x&mask61);
        ull res=xu+xd;
        if(res>=M)res-=M;
        return res;
    }

    //a*b mod 2^61-1
    ull mul(ull a,ull b){
        ull au=(a>>31),bu=(b>>31);
        ull ad=(a&mask31),bd=(b&mask31);
        ull mid=ad*bu+au*bd;
        ull midu=(mid>>30);
        ull midd=(mid&mask30);
        return cal_mod(au*bu*2+midu+(midd<<31)+ad*bd);
    }


    RollingHash(const T &a,ull base):hash(a.size()+1,0),pows(a.size()+1,1){
		for(int i = 0; i <int (a.size()); i++) {
            pows[i + 1] =mul(pows[i], base);
            hash[i + 1] =cal_mod(mul(hash[i], base) + ull(a[i]));
            if(hash[i+1]>=M)hash[i+1]-=M;
		}
    }
    //[b1,b1+len]と[b2,b2+len]が一致するかどうか
    bool match(int b1, int b2,int len){
        ull h1 = cal_mod(hash[b1+len]+M-mul(hash[b1], pows[len]));
        ull h2 = cal_mod(hash[b2 + len]+M-mul(hash[b2],pows[len]));
        return (h1 == h2);
    }
    //[l,l+len]のハッシュ値
    ull get(int l, int len){
        return cal_mod(hash[l+len] + M - mul(hash[l], pows[len]));
    }
};
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    RollingHash<string> rh(s,1007);
    int l=0,r=n/2+1,mid;
    while(r-l>1){
        int mid=(l+r)/2;
        map<unsigned long long,int> mp;
        bool ok=false;
        for(int i=0;i<n-mid+1;i++){
            unsigned long long val=rh.get(i,mid);
            if(mp.count(val)){
                if(i-mp[val]>=mid)ok=true;
            }else{
              mp[rh.get(i,mid)]=i;
            }
        }
        if(ok)l=mid;
        else r=mid;
    }
    cout<<l<<"\n";
}

Measured memory_bytes: 3984
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#define R register
#define next kkksc03
#define maxn 1000000
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
inline ll read();
inline void write(ll x);
inline void writesp(ll x);
inline void writeln(ll x);
string s;
ll len;
ll ans;
int main(){
	cin>>s;
	len=s.length();
	for(R ll i=0;i<len/2;i++) if(s[i]!=s[len-1-i]) ans++;
	 writeln(ans);
}
inline ll read(){
	ll x=0,t=1;char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*t;
}
inline void write(ll x){
	if(x<0){putchar('-');x=-x;}
	if(x<=9){putchar(x+'0');return;}
	write(x/10);putchar(x%10+'0');
}
inline void writesp(ll x){
	write(x);putchar(' ');
}
inline void writeln(ll x){
	write(x);putchar('\n');
}

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

int par[20000000]; //union-find
int ranks[20000000]; //union-find

void init(int n){ //union-find 初期化
    for(int i=0;i<n;i++){
        par[i]=i;
        ranks[i]=0;
    }
}

int find(int x){ //union-find 根を探す
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=find(par[x]);
    }
}

void unite(int x, int y){ //union-find グループの統合
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(ranks[x]<ranks[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(ranks[x]==ranks[y]) ranks[x]++;
    }
}

bool same(int x, int y){ //union-find 同じかグループかどうか判定
    return find(x) == find(y);
}

int main(){
    int n,k,l;
    cin >> n >> k >> l;
    int p[k],q[k];
    int r[l],s[l];
    rep(i,k){
        int pp,qq;
        cin >> pp >> qq;
        p[i]=pp-1;
        q[i]=qq-1;
    }
    rep(i,l){
        int rr,ss;
        cin >> rr >> ss;
        r[i]=rr-1;
        s[i]=ss-1;
    }
    init(2*n);

    rep(i,k) unite(p[i],q[i]);
    rep(i,l) unite(r[i]+n,s[i]+n);

    int ar[n],br[n];
    map<P,int> mp;
    rep(i,n){
        ar[i] = find(i);
        br[i] = find(i+n);
        auto ite= mp.find(P(ar[i],br[i]));
        if(ite!=mp.end()) mp.at(P(ar[i],br[i]))++;
        else mp.insert(make_pair((P(ar[i],br[i])),1));
    }

    rep(i,n){
        int ans = mp.at(P(ar[i],br[i]));
        printf("%d ",ans);
    }



}

Measured memory_bytes: 18688
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


	#define mod_num 2
	//SZは文字列長より十分に長くとろうね！！！！
	#define SZ 100005
	
	ll M[10] = {1000000007,1000000009};
	ll c[10] = {37, 41};
	ll val[mod_num][SZ], hs[mod_num][SZ];
	
	void init(string s){
		rep(i,mod_num) val[i][0] = 1;
		rep(j,SZ-1){
			rep(i,mod_num) val[i][j+1] = val[i][j] * c[i] % M[i];
		}
		rep(i,s.size()){
			rep(j,mod_num){
				hs[j][i+1] = hs[j][i] + val[j][i+1] * (s[i]-'0');
				hs[j][i+1] %= M[j];
			}
		}
	}
	ll get_val(int l,int r){
		ll num = 0;
		ll coef = 1;
		rep(i,mod_num){
			ll add = (hs[i][r+1] - hs[i][l] + M[i]) * val[i][SZ-1-l] % M[i];
			num += coef * add;
			coef *= M[i];
		}
		return num;
	}

	



int k,n;
string str;


ll curr[mod_num][SZ];

int get(int L,int R){
	int lb = L-1,ub = R+1;
	//[lb,ub)
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		rep(k,mod_num){
		    ll x = hs[k][mid] - hs[k][L-1];
		    if(x < 0) x += M[k];
		    if(x >= M[k]) x -= M[k];
		    
		    if(x != curr[k][mid-L+1]*val[k][L-1]%M[k]) goto fail;
		}
		lb = mid; continue;
		fail:; ub = mid;
	}
	return lb;
}
int main(){
	cin >> k >> str;
	init(str);
	n = str.size();
	
	int len = (n+k)/(k+1);
	
	string cur = "";
	
	for(int i=1;i<=len;i++){
		for(int j=1;j<=9;j++){
			rep(k,mod_num) curr[k][i] = (curr[k][i-1]+val[k][i] * 1LL * j)%M[k];
			cur.pb('0'+j);
			int need = 0;
			int beg = 1;
			while(beg <= n && need <= k+1){
				//[beg..beg+i-1]
				int las = get(beg,beg+i-1);//if(i==1&&j==1)cout<<beg<<" "<<las<<endl;
				if(las == beg+i-1 || str[las]-'0' < cur[las+1-beg]-'0') beg += len;
				else beg += len-1;
				need++;
			}
			if(need <= k+1){
				break;
			}
			else cur.pop_back();
		}
	}
	
	assert(cur.size() == len);
	
	cout << cur << endl;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

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; }


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

    int n, k, x, y;
    cin >> n >> k >> x >> y;

    int ans = 0;
    if (n <= k) {
        ans = n * x;
    } else {
        ans = k * x + (n - k) * y;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# ABC085D - Katana Thrower
def main():
    # find the max in A (x)
    # use Bi > x in B and then repeat x if H still remains
    N, H, *AB = map(int, open(0).read().split())
    A = AB[::2]
    x = max(A)
    B = [i for i in AB[1::2] if i > x]
    B.sort(reverse=1)
    ans = 0
    for i in B:
        ans += 1
        H -= i
        if H <= 0:
            break
    else:
        ans += (H + x - 1) // x
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 25124
#include <iostream>

using namespace std;

int main()
{
	long long w, h, x, y;
	cin >> w >> h >> x >> y;
	
	double ans = w * h / 2.0;
	if (x + x == w && y + y == h) {
		printf("%.12f 1\n", ans);
	}
	else {
		printf("%.12f 0\n", ans);
	}

	return 0;
}

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int ans= 0;
        int n = sc.nextInt();
        char[] c  = sc.next().toCharArray();

        for(int i=1;i<n;i++){
            int temp = 0;
            HashSet<Character> alphabet = new HashSet<>();
            for(int j=0;j<i;j++)alphabet.add(c[j]);
            for(int j=i;j<n;j++){
                if(alphabet.contains(c[j])){
                    temp++;
                    alphabet.remove(c[j]);
                }
            }
            ans = Math.max(ans,temp);
        }

        System.out.println(ans);

    }
}




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

using namespace std;


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

    vector<int> A(N);
    int count = 0;
    const int INF = 2000000000;

    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }

    // 最長減少(等しい場合も含む)部分列の数列の長さがi+1のときの最終要素の最大値dp[i]?
    vector<int> dp;

    // 初期条件
    dp.push_back(A[0]);

    // dp開始
    for(int i = 1; i < N; i++) {
        // dp[i]の右から走査
        auto iter = lower_bound(dp.rbegin(), dp.rend(), A[i]);

        // A[i]が右端の値以下の場合
        if(iter == dp.rbegin()) {
            dp.push_back(A[i]);

        // A[i]より小さい値がdp[i]に存在する場合
        } else {
            *(iter-1) = A[i];            
        }
    }

    // dp[i]の大きさが答え    
    cout << dp.size() << endl;
	return 0;
}


Measured memory_bytes: 4296
import math
A, B = (int(x) for x in input().split(' '))

for i in range(1001):
  p8 = math.floor(i*0.08)
  p1 = math.floor(i*0.10)
  
  if p8 == A and p1 == B:
    print(i)
    break
  
  if i >= 1000:
    print(-1)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;


int main(){
	while(1){
		int n,a[10],i,j,k;
		cin>>n;
		if(n==0)break;
		for(i=0;i<10;i++){
			a[i]=0;
		}
		for(i=0;i<n;i++){
			cin>>j;
			a[j]++;
		}
		for(i=0;i<10;i++){
			if(a[i]==0){
				cout<<'-'<<endl;
			}else{
				for(j=0;j<a[i];j++){
				cout<<'*';
				}
				cout<<endl;
			}
		}	
	}
    return 0;
}

Measured memory_bytes: 1152