akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

typedef pair<int, int> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
	return firstElof.second > secondElof.second;
}

signed main(void)
{
	string s, t;
	cin >> s >> t;
	int n = s.size();
	vector<int>start(26,-1), goal(26,-1);
	rep(i, n) {
		int si = s[i] - 'a';
		int ti = t[i] - 'a';

		if (start[si] != -1 || goal[ti] != -1) {
			if (start[si] != ti || goal[ti] != si) {
				print("No");
				return 0;
			}
		}
		else {
			start[si] = ti;
			goal[ti] = si;
		}
	}
	print("Yes");

	
}

Measured memory_bytes: 776
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
int main(){
  string k;ll d;cin>>k>>d;
  //ll dp[10010][2][110];
  vector<vvl> dp(10010,vvl(2,vl(110)));
  dp[0][0][0]=1;
  ll n=k.size();
  rep(i,n){
    rep(j,d){
      rep(dig,10){
        dp[i+1][1][(j+dig)%d]+=dp[i][1][j];
        dp[i+1][1][(j+dig)%d]%=MOD;
      }
      rep(dig,k[i]-'0'){
        dp[i+1][1][(j+dig)%d]+=dp[i][0][j];
        dp[i+1][1][(j+dig)%d]%=MOD;
      }
      dp[i+1][0][(j+(k[i]-'0'))%d]+=dp[i][0][j];
      dp[i][0][j]%=MOD;

    }

  }
  //rep(i,n+1){
    //rep(j,d){
      //cout<<dp[i][1][j]<<" "<<dp[i][0][j]<<" ";
    //}
    //cout<<endl;
  //}
  cout<<(dp[n][0][0]+dp[n][1][0]-1+MOD)%MOD<<endl;

  
}

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

int main() {
	ios :: sync_with_stdio(false);
	map <string, int> mp;
	for(string s; cin >> s; )
		mp[s] ++;
	string f = "", l = "";
	for(auto p : mp) {
		string s = p.first;
		if(mp[s] > mp[f])
			f = s;
		if(s.size() > l.size())
			l = s;
	}
	cout << f << ' ' << l << '\n';
	return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n,s[105],sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        sum+=s[i];
    }
    sort(s,s+n);
    for(int i=0;i<n;i++){
        if(sum%10!=0){
            cout<<sum<<endl;
            return(0);
        }
        if(s[i]%10!=0)
            sum-=s[i];
    }
    if(sum%10!=0){
            cout<<sum<<endl;
            return(0);
        }
    cout<<"0"<<endl;
    return(0);
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;

int main() {

    int n;
    cin >> n;
    vi acum1(n), acum2(n);
    cin >> acum1[0];
    fo(i, n - 1) {
        int a;
        cin >> a;
        acum1[i + 1] = acum1[i] + a;
    }

    cin >> acum2[0];
    fo(i, n - 1) {
        int a;
        cin >> a;
        acum2[i + 1] = acum2[i] + a;
    }

    int maior = 0;
    for ( int i = 0; i < n; i++ ) {
        int aux = 0;
        aux += acum1[i] + acum2[n - 1];
        if ( i > 0 ) {
            aux -= acum2[i - 1];
        }
        maior = max(aux, maior);
    }

    cout << maior << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 200000
ll a[ma],mark[ma];
int main()
{
   ll i,j,x,y,n;
   while(cin>>x>>n)
   {
       for(i=1;i<=n;i++)
       {
           cin>>y;
           mark[y]=1;
       }
       ll min1=inf,p;
       for(i=0;i<=2000;i++)
       {
           if(mark[i]==0)
           {
               ll r=abs(x-i);
               if(r<min1)
               {
                   min1=r;
                   p=i;
               }
           }
       }
       cout<<p<<endl;
   }
   return 0;

}




Measured memory_bytes: 3572
# -*- coding: utf-8 -*-
import math

# def f2(x, y, z, n):
#     return x*x+y*y+z*z+x*y+y*z+z*x

def f(x, y, z, n):
    if x*x+y*y+z*z+x*y+y*z+z*x == n:
        return True
    else:
        return False
def main():
    N = int(input())
    for n in range(1, N + 1):
        cnt = 0
        for x in range(1, 100):
            if x * x > n:
                break
            for y in range(x, 100):
                if x*x + y*y > n:
                    break
                for z in range(y, 100):
                    if x*x + y*y + z*z > n:
                        break
                    if f(x, y, z, n):
                        # print(x, end=' ')
                        # print(y, end=' ')
                        # print(z)
                        if x == y == z:
                            cnt += 1
                        elif x != y and y != z and z != x:
                            cnt += 6
                        else:
                            cnt += 3
        # print(n, end=': ')
        print(cnt)
    return
if __name__ == '__main__':
    main()

Measured memory_bytes: 70600
import sys
readline = sys.stdin.readline

S = readline().rstrip()
DIV = 10 ** 9 + 7

dp = [[0] * 4 for i in range(len(S) + 1)]
# dp[i + 1][0] : i文字目まで見たとき、ABCの部分文字列がまだ始まっていない場合の数
# dp[i + 1][1] : i文字目まで見たとき、ABCのAまで一致した場合の数
# dp[i + 1][2] : i文字目まで見たとき、ABCのBまで一致した場合の数
# dp[i + 1][3] : i文字目まで見たとき、ABCのCまで一致した場合の数

dp[0][0] = 1

for i in range(len(S)):
  # 状態を遷移しない場合
  for j in range(4):
    dp[i + 1][j] += dp[i][j] * (3 if S[i] == "?" else 1) # ?の場合は全ての遷移があり得る
  
  if S[i] == "A" or S[i] == "?":
    dp[i + 1][1] += dp[i][0] # 開始状態に遷移することが出来る
    
  if S[i] == "B" or S[i] == "?":
    dp[i + 1][2] += dp[i][1] # Bを使用した状態に遷移
  
  if S[i] == "C" or S[i] == "?":
    dp[i + 1][3] += dp[i][2] # Cを使用した状態に遷移
    
  for j in range(4):
    dp[i + 1][j] %= DIV
    
# 最後の文字まで見たとき、Cまで一致した場合の数が答え
print(dp[len(S)][3])


Measured memory_bytes: 32040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;

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

int main(){
    ll N;
    cin >> N;
    multiset<ll> s;
    rep(i,N){
        ll a;
        cin >> a;
        auto itr=s.lower_bound(a);
        if (itr==s.begin()){
            s.insert(a);
        }
        else {
            itr--;
            s.erase(itr);
            s.insert(a);
        }
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 4992
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

const double pi = acos(-1);

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

// 角度 -> ラジアン
double torad(double deg){
    return 1. * deg * pi / 180;
}

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

    double a, b, h, m; cin>>a>>b>>h>>m;

    double H = 30 * h + 0.5 * m;
    double M = 6 * m;

    double theta = abs(H - M);
    theta = min(theta, 360 - theta);

    double ans = sqrt(a * a + b * b - 2 * a * b * cos(torad(theta)));

    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 4240
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int main()
{
  finp;
  string s;
  cin>>s;
  bool no=false;
  bool so=false;
  bool ea=false;
  bool we=false;

  for(auto i:s)
  {
    if(i=='N')no=true;
    else if(i=='S')so=true;
    else if(i=='W')we=true;
    else ea=true;
  }

  if((!no && !so) || (no && so))
  {
    if((!we && !ea) || (we && ea))
    {
      cout<<"Yes";
    }
    else cout<<"No";
  }
  else cout<<"No";
  
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int r;
    cin >> r;
    cout << 3 * pow(r, 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int main(void){
	int sum,i,s[1001];
	double m,a2n,a2,a,n;
	
	while(1){
		scanf("%lf",&n);
		if(n==0) break;
		sum=0;
		a2n=0;
		rep(i,0,n){
			scanf("%d",&s[i]);
			sum+=s[i];
		}
		m=sum/n;
		rep(i,0,n){
			a2n+=pow(s[i]-m,2);
		}
		a2=a2n/n;
		a=pow(a2,0.5);
		printf("%10.10lf\n",a);
	}
	return 0;
}

Measured memory_bytes: 716
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const long long INF = 1LL << 60;

int r;

int main()
{
  cin >> r;
  cout << setprecision(10) << 2*3.14159265358979*r << endl;
}

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

int main() {
  ll h,n;
  cin >> h >> n;
  ll total = 0;
  rep(i,n) {
    int x;
    cin >> x;
    total += x;
  }
  if (h <= total) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3604
using System.Text;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var q = int.Parse(line[2]);
        var a = new int[n];
        for (int i = 0; i < q; i++)
        {
            var t = int.Parse(Console.ReadLine().Trim());
            a[t - 1]++;
        }
        getAns(a, n, k - q);
    }
    static void getAns(int[] a, int n, int t)
    {
        var sb = new StringBuilder();
        for (int i = 0; i < n; i++)
            sb.Append(a[i] + t > 0 ? "Yes\n" : "No\n");
        Console.WriteLine(sb);
    }
}


Measured memory_bytes: 15456
#!/bin/bash

read N Y
Y=$((Y / 1000))

for A in $(seq 0 $N); do
    B=$(( ( (Y-10*A) - (N-A) ) / 4 ))
    C=$(( N - A - B ))

    if (( $(( B >= 0 && C >= 0 && 10*A + 5*B + C == Y )) )); then
        echo $A $B $C
        exit
    fi

done
echo -1 -1 -1


Measured memory_bytes: 580
n, m = map(int, input().split())
mat = [[0 for i in range(m)] for j in range(n)]
vec = [0 for i in range(m)]

for i in range(n):
    row = list(map(int, input().split()))
    for j in range(m):
        mat[i][j] = row[j]

for i in range(m):
    vec[i] = int(input())

for i in range(n):
    a = 0
    for j in range(m):
        a += mat[i][j]*vec[j]
    print(a)


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

int main(){
    int N; 
    cin >> N;
    vector<ll> A(N);
    vector<ll> num(N+1, 0);
    rep(i, N){
        cin>>A[i];
        num[A[i]]++;
    }

    ll sum=0;
    rep(i, N){
        int aaaa=i+1;
        sum+=num[aaaa]*(num[aaaa]-1)/2;
    }

    rep(i, N){
        ll sum_sub=sum;
        sum_sub-=(num[A[i]]-1)*num[A[i]]/2;
        sum_sub+=(num[A[i]]-2)*(num[A[i]]-1)/2;
        cout<<sum_sub<<endl;
    }
    return 0;
}

Measured memory_bytes: 6368
n,m=map(int,input().split())
List=list(map(int,input().split()))
count=0
total=0
for i in List:
    total=total+i

for i in List:
    if i>=total/m/4:
        count=count+1
    else:
        count=count+0

if count>=m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100
int a[MN+5],u[MN+5];
int main()
{
	int n=read(),i;
	for(i=1;i<=n;++i)++u[a[i]=read()];
	sort(a+1,a+n+1);
	if(a[1]==a[2])
	{
		if(a[1]==a[3]||a[n]!=2*a[1]-1)return 0*puts("Impossible");
		for(i=a[1];i<=a[n];++i)if(u[i]<2)return 0*puts("Impossible");
	}
	else
	{
		if(a[n]!=2*a[1])return 0*puts("Impossible");
		for(i=a[1];++i<=a[n];)if(u[i]<2)return 0*puts("Impossible");
	}
	puts("Possible");
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(void){
  int i;
  char a[50],b[20];
  scanf("%s %s", a, b);
  for( i=0; i<strlen(a); i++){
    if(a[i]!=b[i]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 1648
import java.util.*

private class B {
    fun solve() {
        val n = nextInt();
        val p = Array(n * n) { nextInt() - 1 }
        val hall = Array(n) { IntArray(n) { 1 } } 
        val hatred = Array(n) { x -> IntArray(n) {y -> x.coerceAtMost(y).coerceAtMost(n - x - 1).coerceAtMost(n - y - 1)} }
        var ans = 0
        for (current in p) {
            val q = LinkedList<Point>()
            val x = current % n
            val y = current / n
            q.add(Point(x, y))
            hall[x][y] = 0
            ans += hatred[x][y]
            while (!q.isEmpty()) {
                val current = q.pollFirst()
                val nextHatred = hatred[current.x][current.y] + hall[current.x][current.y]
                for (i in 0..3) {
                    val next = current.shift(i)
                    if (next.isGood(n) && nextHatred < hatred[next.x][next.y]) {
                        hatred[next.x][next.y] = nextHatred
                        q.addLast(next)
                    }
                }
            }
        }
        println(ans)
    }

    class Point(val x: Int, val y: Int) {
        val dx = intArrayOf(-1, 1, 0, 0)
        val dy = intArrayOf(0, 0, -1, 1)

        fun shift(dir: Int): Point {
            return Point(x + dx[dir], y + dy[dir])
        }

        fun isGood(n: Int): Boolean {
            return x >= 0 && x < n && y >= 0 && y < n
        }
    }


    var tokenBuffer = listOf<String>()
    var bufferPosition = 0

    private fun checkBuffer() {
        if (bufferPosition == tokenBuffer.size) {
            tokenBuffer = nextLine().split(" ")
            bufferPosition = 0
        }
    }

    fun nextLine() = readLine()!!
    fun nextInt(): Int {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toInt()
    }

    fun nextLong(): Long {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toLong()
    }

    fun nextDouble(): Double {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toDouble()
    }

    fun nextToken(): String {
        checkBuffer()
        return tokenBuffer[bufferPosition++]
    }
}

fun main() {
    val reader = B().solve()

}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

inline bool inside(ll y, ll x, ll H, ll W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

ll h,w;
char G[55][55];
ll dist[55][55];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>h>>w;
  rep(i,h) rep(j,w) cin>>G[i][j];
  memset(dist,-1,sizeof(dist));
  queue<pll> q;
  q.emplace(0,0);
  dist[0][0]=1;
  while(!q.empty()){
    ll y=q.front().first, x=q.front().second;
    q.pop();
    rep(i,4){
      ll ny=dy[i]+y, nx=dx[i]+x;
      if(inside(ny,nx,h,w)&&G[ny][nx]=='.'&&dist[ny][nx]==-1){
        dist[ny][nx]=dist[y][x]+1;
        q.emplace(ny,nx);
      }
    }
  }
  if(dist[h-1][w-1]==-1){
    cout<<-1<<endl;
    return 0;
  }
  
  ll z=0;
  rep(i,h) rep(j,w) if(G[i][j]=='#') z++;
  cout<<h*w-z-dist[h-1][w-1]<<endl;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

void mul(ll &a,ll &b){
    a=a*b%MOD,--b;
    return;
}

int main(){
    ll N;
    string S;
    cin >> N >> S;
    ll ans=1;
    vector<ll> candidate(7,0);
    candidate[6]=N;
    rep(i,3*N){
        if (S[i]=='R'){
            if (candidate[0]) mul(ans,candidate[0]);
            else if (candidate[4]) ++candidate[2],mul(ans,candidate[4]);
            else if (candidate[5]) ++candidate[1],mul(ans,candidate[5]);
            else ++candidate[3],mul(ans,candidate[6]);
        }
        if (S[i]=='G'){
            if (candidate[1]) mul(ans,candidate[1]);
            else if (candidate[5]) ++candidate[0],mul(ans,candidate[5]);
            else if (candidate[3]) ++candidate[2],mul(ans,candidate[3]);
            else ++candidate[4],mul(ans,candidate[6]);
        }
        if (S[i]=='B'){
            if (candidate[2]) mul(ans,candidate[2]);
            else if (candidate[3]) ++candidate[1],mul(ans,candidate[3]);
            else if (candidate[4]) ++candidate[0],mul(ans,candidate[4]);
            else ++candidate[5],mul(ans,candidate[6]);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int> d(K);
  vector<vector<int>> c;
  
 
   d.resize(K);
 c.resize(K, vector<int>());
 for(int i=0; i<K; i++){
    cin >> d[i];
    c[i].resize(d[i]);
    for(int j=0; j<d[i]; j++)
   cin >> c[i][j];
 }



  
 
 // vector<bool> a(N,false);
//  vector<int> b(N);
 // for(int i=0; i<N; i++)
 //   b[i]=i+1;
  


  
  int count=0;

  for(int i = 1; i <= N; i++) {
      bool yes=false;
         for(auto x : c){ 
           for(auto y : x){
            
               if (y==i)  yes=true;
                         
   }
               
         }
     if(!yes) count++;
    }
  
  
     cout << count <<endl;



}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
ll dp[5000][5000];
int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;

  for(int i = 1;i <= N - 1;i++){
    for(int j = i + 1;j <= N;j++){
      if(s[i-1] == s[j-1])dp[i][j] = min(dp[i-1][j-1] + 1,(ll)j-i);
    }
  }

  ll ans = 0;
  for(int i = 1;i <= N - 1;i++){
    for(int j = i+1;j <= N;j++){
      ans = max(ans,dp[i][j]);
    }
  }

  cout << ans << endl;
}


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

using namespace std;

#define all(v)          v.begin(), v.end()
#define pb              push_back
#define sz(x)          (int) (x.size())
#define endl            "\n"
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))
#define EPS 1e-7

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;


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

    int n; cin >> n;
    string s; cin >> s;
    int r = count(all(s), 'R');
    if(r == n || !r) return cout << 0, 0;
    int w = n - r, c = 0;
    string x = string(r, 'R') + string(w, 'W');
    for(int i = 0; i < n; i++){
        if(s[i] != x[i]) c++;
    }
    cout << c/2;
    return 0;
}


Measured memory_bytes: 3948
# -*- coding: utf-8 -*-
from collections import Counter
from heapq import heappush, heappop

def inpl(): return map(int, input().split())
H, W = inpl()
C = []
A = Counter()

for _ in range(10):
    C.append(tuple(inpl()))

for _ in range(H):
    A.update(tuple(inpl()))

min_cost = [float("inf") for _ in range(10)]
# ダイクストラ
g = 1
for s in range(10):
    searched = [False] * 10
    searched[s] = True
    N = 10
    INF = float("inf")
    d = [INF for _ in range(N)]
    d[s] = 0
    heap = [[0, s]] # cost, destination
    
    while len(heap):
        pcost, p = heappop(heap)
        searched[p] = True
        
        if d[p] < pcost:
            continue
        
        for i in range(10):
            if not searched[i]:
                new_cost = pcost + C[p][i]
                if new_cost < d[i]:
                    d[i] = new_cost
                    heappush(heap, [new_cost, i])
        
    min_cost[s] = d[1]

res = 0
for i in range(10):
    res += A[i] * min_cost[i]

print(res)

Measured memory_bytes: 3436
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N,AC = 0,WA = 0,TLE = 0,RE = 0;
    string S;
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> S;
        if(S == "AC"){
            AC++;
        }else if(S == "WA"){
            WA++;
        }else if(S == "TLE"){
            TLE++;
        }else if(S == "RE"){
            RE++;
        }
    }
    
    cout << "AC x " << AC << endl; 
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl; 
    cout << "RE x " << RE << endl; 
}

Measured memory_bytes: 3620
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
inline int m_min(int x,int y)
{ return x<y ? x : y; }
const int Mn(100050);
int ans[Mn];
int main()
{
	int n,m;
	string s;
	cin >>n>>m>> s;
	int cnt(0),p(n);
	while(p)
	{
		bool flag(true);
		for(int i(m_min(p,m));i>=1;--i)
			if(s[p-i]=='0')
			{
				p = p-i;
				ans[++cnt] = i;
				flag = false;
				break;
			}
		if(flag)	break;
	}
	if(p!=0)	printf("-1");
	else
		for(int i(cnt);i;--i)
			printf("%d ",ans[i]);
	return 0;
}


Measured memory_bytes: 1024
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    H1, M1, H2, M2, K = iim()

    hm1 = H1 * 60 + M1
    hm2 = H2 * 60 + M2

    if hm1 > hm2:
        hm2 += 24 * 60
    diff = hm2 - hm1


    print(diff -K)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9172
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N, M;
vector<int> l;
vector<int> r;

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

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    l.push_back(a);
    r.push_back(b);
  }

  sort(All(l), greater<int>());
  sort(All(r));

  if (r[0] - l[0] >= 0) {
    cout << r[0] - l[0] + 1 << "\n";
  } else {
    cout << 0 << "\n";
  }

}

Measured memory_bytes: 1276
import math
from functools import reduce

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

s = input()

left = int(s[0:2])
right = int(s[2:4])

if left <= 12 and left != 0:
    if right <= 12 and right != 0:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if right <= 12 and right != 0:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3820
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	lli sum = 0ll;
	for (auto &i : s)
		sum += (i - '0');
	cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}

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

int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s;
  cin >> t;
  rep(i, n) { cout << s[i] << t[i]; }
  cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
int n;
  double count=0.0;
  scanf("%d",&n);
  while(n>100||n<1){
    scanf("%d",&n);
  }
  for(int i=1;i<=n;i++){
    if(i%2==1){
      count++;   
    }
  }
    double b=count/n;
  printf("%f",b);
}

Measured memory_bytes: 128
#include<iostream>I don't know
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
double ta[300][3];
bool used[300],tused[300];

	int n,m;
double ans=0;
double solve(int now){
double ret=0.0;
while(true){
	tused[now]=0;

	int next=0,f=0;
	for(int i=0;i<n;i++){
		if(tused[i]&&!f)next=i,f=1;
	}
	for(int i=0;i<n;i++){
	if(tused[i]){
		for(int j=0;j<3;j++)ret+=(ta[i][j]-ta[now][j])*(ta[i][j]-ta[now][j]);

		}
	}
	now=next;
	bool endf=1;
	for(int i=0;i<n;i++)if(tused[i])endf=0;
	if(endf)break;
}
return ret;
}
void  dfs(int h,int use){
	if(h==n){
	//for(int i=0;i<n;i++)cout<<used[i]<<" ";cout<<endl;
	if(use==m){
	int next=0;
	for(int i=n-1;i>=0;i--)if(used[i])next=i,tused[i]=used[i];
	ans=max(ans,solve(next));
	}
	return ;
	}
	used[h]=1;
	dfs(h+1,use+1);
	used[h]=0;
	dfs(h+1,use);
}
int main(){

	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)cin>>ta[i][0]>>ta[i][1]>>ta[i][2];
	dfs(0,0);
	printf("%.10f\n",ans);
	return 0;
}

Measured memory_bytes: 1284
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int N;
long H ;
int MAX = 0;
long mem=0;
int sum=0;
int main(void) {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H;
		if (H <= mem) {
			mem=H;
			sum++;
		}
		else {
			mem = H;
			if (sum > MAX) {
				MAX = sum;
			}
			sum = 0;
		}
		if (sum > MAX) {
			MAX = sum;
		}
	}
	cout << MAX << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

vvint g;
map<int,int> memo;

int dfs(int v) {
    if (g[v].size() == 0) return 0;
    if (memo.count(v)) return memo[v];
    int res = 0;
    for (int n_v : g[v]) chmax(res,dfs(n_v)+1);
    return memo[v] = res;
}

int main() {
    int n, m; cin >> n >> m;
    g.resize(n);
    rep(i,m) {
        int x, y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
    }
    rep(i,n) dfs(i);
    int ans = 0;
    rep(i,n) ans = max(ans,memo[i]);
    cout << ans << endl;
}

Measured memory_bytes: 13824
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main()
{
    int N, K;
    int cnt = 1;
    cin >> N >> K;
    
    while (N >= K) {
        N /= K;
        cnt++;
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcd (int a, int b) {
  return (b == 0) ? a : gcd(b, a%b);
}


int main() {
  int a, b;
  cin >> a >> b;
  
  if (a==b) {
    cout << a;
  } else {
    (a > b) ? cout << gcd(a,b) : cout << gcd(b,a);
  }
  cout << endl;
}

  

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

int main(){
    int n,x; cin >> n >> x;
    vector<int> L(n); rep(i,n) cin >> L[i];
    vector<int> D(n+1);
    D[0] = 0; rep(i,n) D[i+1] = D[i] + L[i];
    int ans = 0;
    for(int i = 0; (D[i] <= x) && (i < n + 1); i++) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
import scala.math.{cos, sin, sqrt, pow, Pi}

object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val a, b, C = sc.nextDouble
  val t = C * Pi / 180
  val S = a * b * sin(t) / 2
  val c = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(t))
  val L = a + b + c
  val h = b * sin(t)
  println(S)
  println(L)
  println(h)
}

Measured memory_bytes: 45832
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
int main()
{
	long long a = 0, b = 0, c = 0, hairetu[1000] = { }, mi = 0, ma = 0, ansa = 0, ansb = 0, x = 0, y = 0;
	
	int snow=0;
		int one = 0, ten = 0, hun = 0, thou = 0,man=0;
		std::cin >> a >> b;
		if (a == 0) { c = 1; }
		if (a == 1) { c = 100; }
		if (a == 2) { c = 10000; }
	bool okada = true;
	for (int i = 1; i <= 100; i++) {
		hairetu[i] = i*c;
		if (i == 100) {
			hairetu[i] = (i+1)* c;
		}
		
	}

	std::cout <<hairetu[b]<< std::endl;

}







Measured memory_bytes: 256
n = int(input())
cnt = 0
lista = [0] * (n + 1)
for i in range(1, n + 1, 2):
    c = 1
    for j in range(1, i, 2):
        if i % j == 0:
            c += 1
    if c == 8:
        cnt += 1
print(cnt)
"""
# 奇数のみ
for i in range(1, n + 1, 2):
    # 3 * 1, 3 * 3, 3 * 5...
    for j in range(i, n + 1, 2 * i):
        lista[j] += 1
for i in range(n + 1):
    if lista[i] == 8:
        cnt += 1
print(cnt)
"""

Measured memory_bytes: 38640
#include <iostream>

using namespace std;

int main() {

	int j, l, m, n, t;

	while(cin >> l) {
		if(l==0)
			break;
		t=0;
		j=0;
		for(int i=1; i<=12; i++) {
			cin >> m >> n;
			t+=m-n;
			if(t>=l&&j==0) 
				j=i;
		}
		if(t>=l)
			cout << j << endl;
		else
			cout << "NA" << endl;
	}

	return 0;

}

Measured memory_bytes: 0
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
  a_ = a[i]
  b_ = b[i]
  c_ = c[i]
  if a_ == b_ and b_ != c_:
    ans += 1
  elif a_ == c_ and b_ != c_:
    ans += 1
  elif b_ == c_ and a_ != c_:
    ans += 1
  elif a_==b_ and a_==c_:
    ans += 0
  else:
    ans += 2
print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long INF = 1LL<<60;
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; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int benef[105][11];
int shop[105][10];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    int ans = -1e9-1;
    rep(i,n) rep(j,10) cin >> shop[i][j];
    rep(i,n) rep(j,11) cin >> benef[i][j];
    for(int bit = 1; bit<(1<<10); bit++) {
        int cnt = 0;
        rep(i,n) {
            int cnt2 = 0;
            for(int j = 0; j < 10; j++) {
                if((bit>>j&1) && shop[i][j]) cnt2++;
            }
            cnt += benef[i][cnt2];
        }
        chmax(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int c1,c2,c3;
  cin>>c1>>c2>>c3;
  int d1=c2-c1, d2=c3-c2;
  bool OK=true;
  for(int i=0;i<2;i++){
    int a,b,c;cin>>a>>b>>c;
    if(!(d1==b-a && d2==c-b))
      OK=false;
  }
  
  if(OK)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if (b%100==0)
	    b=b+b/100;
	printf("%d",b);
	for (int i=1;i<=a;i++)
	    printf("00");
//	system("pause");
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    deque<int> d;
    rep(i,n) {
        int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (p == 0) d.push_front(a[i]);
        else d[p-1] = a[i];
    }
    int ans = d.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    const int INF = 1LL << 30;
    int N, M;
    while (cin >> N >> M, N) {
        vector<int> s(N);
        REP (i, N) cin >> s[i];
        auto count = [&](int X) -> int {
            int L = 1, res = 1;
            if (s.front() >= L + X) return INF;
            while (L + X <= s.back()) {
                int p = (upper_bound(s.begin(), s.end(), L) - s.begin()) - 1;
                int add = max(1LL, X - abs(L - s[p]));
                if (p + 1 < N && s[p + 1] < L + X) {
                    add = max(add, X - abs(L - s[p + 1]));
                }
                L += add;
                res++;
            }
            return res;
        };
        if (count(1) < M) {
            cout << -1 << endl;
            continue;
        }
        int ok = 1, ng = s.back();
        while (ng - ok > 1) {
            int m = (ok + ng) / 2;
            if (count(m) >= M) ok = m;
            else ng = m;
        }
        if (count(ok) != INF) cout << ok << endl;
        else cout << -1 << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


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

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    std::sort(l.begin(), l.end(), std::greater<int>());
    int sum = 0;
    for(int i = 0; i < k; i++) sum += l[i];
    cout << sum << endl;
    return 0;
}

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

int Max(int x, int y) {
    int a = x;
    if (a < y) {
        a = y;
    }
    return a;
}

int Min(int x, int y) {
    int a = x;
    if (a > y) {
    a = y;
    }
    return a;
}
int main() {
    int n;
    cin >> n;
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data.at(i);
    }
    int max = data.at(1) - data.at(0);
    int min = data.at(0);
    for (int i = 1; i < n; i++) {
        max = Max(max, data.at(i) - min);
        min = Min(min, data.at(i));
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a1,a2,a3;
  cin>>a1>>a2>>a3;
  int sum=a1+a2+a3;
  if(sum>=22)
  {
    cout<<"bust"<<endl;
  }
  else
  {
    cout<<"win"<<endl;
  }
}

Measured memory_bytes: 3628
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbig=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
int n,dp[100111];
vector<int> con[100111];
void dfs(int x,int pre=-1)
{
	for(int i=0;i<con[x].size();i++)
	{
		int u=con[x][i];
		if(u==pre)continue;
		dfs(u,x);
		dp[x]^=dp[u]+1;
	}
}
int main()
{
	geti(n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		getii(x,y);
		con[x].PB(y);
		con[y].PB(x);
	}
	dfs(1);
	if(dp[1]==0)puts("Bob");else puts("Alice");
	return 0;
}

Measured memory_bytes: 13952
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

public class Main {
    public static void main(String[] args) throws IOException {
        for (int b=1; b<=4; b++){
            for (int f=1; f<=3; f++){
                for (int r=1; r<=10; r++){
                    Dom.allRes.add(new Dom(b, f, r, 0));
                }
            }
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int n = Integer.parseInt(br.readLine());
        String hashs =  HashMarks(20).toString();
        for (int i=0; i<n; i++){
            String[] line = br.readLine().split(" ");
            int b = Integer.parseInt(line[0]);
            int f = Integer.parseInt(line[1]);
            int r = Integer.parseInt(line[2]);
            int v = Integer.parseInt(line[3]);
            
            for (Dom dom: Dom.allRes){
                if (dom.b == b && dom.f == f && dom.r == r){
                    dom.v += v;
                }
            }
        }
        int cnt = 0;
        for (Iterator<Dom> d = Dom.allRes.iterator(); d.hasNext();){
            Dom dom = d.next();
            cnt += 1;
            System.out.print(" " + dom.v);
            if (cnt%10==0){
                System.out.println();
            }
            if (!d.hasNext()){
                break;
            }
            if (cnt%30==0){
                System.out.println(hashs);
            }
        }
    }
    private static String HashMarks(int n){
        StringBuilder sb = new StringBuilder();
        for (int i=0; i<n; i++){
            sb.append("#");
        }
        return sb.toString();
    }
}
class Dom {
    final int b; //?£?
    final int f; //???
    final int r; //??????
    int v; //???
    static List<Dom> allRes = new ArrayList<Dom>();
    
    Dom (int b, int f, int r, int v){
        this.b = b;
        this.f = f;
        this.r = r;
        this.v = v;
    }
}

Measured memory_bytes: 19148
//

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

int main() {
	int X, Y;
	cin >> X >> Y;

	string ans = "No";
	for (int i=0; i<=X; i++) {
		int a = i;
		int b = X - i;
		if (a * 2 + b * 4 == Y) ans = "Yes";
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
        int n,k,q,point;
        cin>>n>>k>>q;
        int* players;
        players = new int[n];
        for(int i = 0; i< n;i++)players[i] = k;
        for(int i = 0; i< q; i++){
                cin>>point;
                players[point-1]++;
        }
        for(int i=0;i<n;i++){
                if(players[i]-q <1)cout<<"No\n";
                else cout<<"Yes\n";
        }
        return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


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

    vector<ll> fib(n+1);
    fib[0] = 1;
    fib[1] = 1;
    for(int i = 2; i <= n; i++){
        fib[i] = fib[i-1]+fib[i-2];
    }

    cout << fib[n] << endl;

    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n>>m;
    char a[n+1][m+1];
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)cin>>a[i][j];
    }
    ll dp[n+1][m+1];
    mms(dp,0);
    dp[0][1]=1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(a[i-1][j-1]=='.')
            {
                dp[i][j]=((dp[i][j]+dp[i-1][j])%mod+dp[i][j-1])%mod;
                //cout<<dp[i-1][j]<<"\n";
            }
        }
        //cout<<"\n";
    }
    cout<<dp[n][m];
}


Measured memory_bytes: 9088
#include <iostream>
#include <string>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int m, h;
    while (cin >> s && s != "-") {
        cin >> m;
        for (int i = 0; i < m; i++) {
            cin >> h;
            s = s.substr(h) + s.substr(0, h);
        }
        cout << s << "\n";
    }
}

Measured memory_bytes: 3152