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

using namespace std;
#define int long long int
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define loop(i,k,n) for(int i=k;i<n;i++)
#define MOD 1000000007
#define r0 return 0
/*
//gcd in O(log(a))
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
*/
/*
int gcd, x, y;

void extendedEuclid (int a, int b)
{
    if (b==0)
    {
        x=1;
        y=0;
        gcd=a;
        return;
    }
    extendedEuclid(b, a%b);
    int x1=y;
    int y1=x-(a/b)*y;
    x=x1;
    y=y1;
}

int nCr (int n, int r)
{
    int p=1, k=1, modInv;
    if (n-r<r)
        r=n-r;
    if (r!=0)
    {
        while (r)
        {
            p=(p*n)%MOD;
            k*=r;
            n--;
            r--;
        }
        extendedEuclid(k, MOD);
        modInv=(x+MOD)%MOD;
        p=(p*modInv)%MOD;
    }
    else
        p=1;
    return p;
}
*/


int32_t main(void)
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        string grid[n];
        for(int i=0;i<n;i++)
        {
            cin>>grid[i];
        }
        int dp[n][m]={0};
        dp[0][0]=1;
        for(int i=1;i<m;i++)
        {
            if(grid[0][i]=='#')
                dp[0][i]=0;
            else
                dp[0][i]=dp[0][i-1];

        }
        for(int i=1;i<n;i++)
        {
            if(grid[i][0]=='#')
                dp[i][0]=0;
            else
                dp[i][0]=dp[i-1][0];

        }
        for(int i=1;i<n;i++)
        {
            for(int j=1;j<m;j++)
            {
                if(grid[i][j]=='.')
                {
                    dp[i][j]=(dp[i][j-1]+dp[i-1][j])%MOD;
                }
                else
                    dp[i][j]=0;
            }
        }

cout<<dp[n-1][m-1];


    }
}



Measured memory_bytes: 9088
import java.util.*;

public class Main {
	static public void main(String args[]){
		Scanner sc=new Scanner(System.in);
		 
		 int n=sc.nextInt();
		 int m=sc.nextInt();
		 if(m<2)m=0;
		 
		 n*=n-1; n/=2;
		 m*=m-1; m/=2;
		 System.out.print(n+m);
	}
}

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

typedef long long int ll;

int main()
{
    ll n;
    cin >> n;
    vector<ll> l(n);
    for(ll i = 0;i < n;i++){
        cin >> l[i];
    }

    ll ans = 0;

    for(ll i = 0;i < n;i++){
        for(ll j = i + 1;j < n;j++){
            for(ll k = j + 1;k < n;k++){
                if(l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j] && l[i] != l[j] && l[j] != l[k] && l[k] != l[i]){
                    ans++;
                }
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3624
// ABC 81 B

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

typedef long long ll;

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; }
const long long INF = 1LL<<60;

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;

  for (int i = 1; i <= n; i++) {
    int num = 0;
    int tmp = i;

    num += tmp / 10000;
    tmp = tmp % 10000;
    num += tmp / 1000;
    tmp = tmp % 1000;
    num += tmp / 100;
    tmp = tmp % 100;
    num += tmp / 10;
    tmp = tmp % 10;
    num += tmp;

    if (a <= num && num <= b) {
      ans += i;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int N = 1e5 + 50;
int sum(int x)
{
    int ret = 0;
    while(x)
    {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}
int main()
{
	IO;
    int n, mn = 1e9;
    cin >> n;
    for(int i = 1; i < n; i++)
        mn = min(mn, sum(i) + sum(n - i));
    cout << mn;
}


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;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long double EPS = 1e-14;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long double a, b, c;
  cin >> a >> b >> c;
  if (abs(sqrt(a)+sqrt(b)-sqrt(c)) < EPS || sqrt(a)+sqrt(b) > sqrt(c))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const ll mod=1e9+7;
int n,a[10010];
int cnt[1000010];
vector<pii> fac[10010];
int main() {
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++) {
		scanf("%d",a+i);
		int t=a[i];
		for(j=2;j*j<=t;j++) {
			if(t%j==0) {
				int c=0;
				while(t%j==0) {
					t/=j;
					c++;
				}
				fac[i].push_back({j,c});
				cnt[j]=max(cnt[j],c);
			}
		}
		if(t>1) {
			fac[i].push_back({t,1});
			cnt[t]=max(cnt[t],1);
		}
	}
	ll res=0;
	vector<pii> v;
	for(i=1;i<=1000000;i++) {
		if(cnt[i]) {
			v.push_back({i,cnt[i]});
		}
	}
	for(i=1;i<=n;i++) {
		ll x=1;
		j=0;
		for(auto& it:v) {
			while(j<sz(fac[i])&&fac[i][j].fi<it.fi)j++;
			int c=0;
			if(j==sz(fac[i])||fac[i][j].fi!=it.fi) {
				c=it.se;
			} else c=it.se-fac[i][j].se;
			for(int k=0;k<c;k++) x=(x*it.fi)%mod;
		}
		res=(res+x)%mod;
	}
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 4608
fun main(arr:Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!! }
    val ans = if(canPaint(map)) "Yes" else "No"
    println(ans)
}

fun canPaint(map:List<String>):Boolean {
    for(r in map.indices) {
        for(c in map[r].indices) {
            if(map[r][c] != '#') {
                continue
            }
            var canPaint = false
            for(rs in Math.max(0, r-1)..Math.min(map.lastIndex, r+1)) {
                for(cs in Math.max(0, c-1)..Math.min(map[r].lastIndex, c+1)) {
                    if(r==rs && c == cs) {
                        continue
                    }
                    if(r!=rs&&c!=cs) {
                        continue
                    }
                    if(map[rs][cs] == '#') {
                        canPaint = true
                        break
                    }
                }
                if(canPaint){
                    break
                }
            }
            if(!canPaint) {
                return false
            }
        }
    }
    return true
}

Measured memory_bytes: 36056
import java.util.*;

public class Main {


//    public static int gcd(int x, int y){
//        if (y==0) return x;
//        return gcd(y, x%y);
//    }

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int h[] = new int[n];

        for (int i=0; i<n; i++){
            h[i] = sc.nextInt();
        }

        int origin_count = 1;

        for (int j=1; j<n; j++) {
            int count = 0;

            for (int k = 0; k <= j; k++) {
                if (h[k] > h[j]) {
                    count++;
                }
            }
            if (count==0) {
                origin_count++;
            }
        }
            System.out.println(origin_count);

    }
}




Measured memory_bytes: 21844
#include<bits/stdc++.h>
     
using namespace std;
     
     
int main (){
   	string s;
   	cin >> s;
   	if(s == "SUN") cout << 7 << endl;	
   	if(s == "MON") cout << 6 << endl;
   	if(s == "TUE") cout << 5 << endl;
   	if(s == "WED") cout << 4 << endl;
   	if(s == "THU") cout << 3 << endl;
   	if(s == "FRI") cout << 2 << endl;
   	if(s == "SAT") cout << 1 << endl;
   	return 0;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    stocks = 0
    money = 1000
    i = 0
    while i < N:
        buy = i
        while buy < N-1 and A[buy] > A[buy+1]:
            buy += 1
        sell = buy
        while sell < N-1 and A[sell] <= A[sell+1]:
            sell += 1
        if buy == sell:
            print(money)
            return
        
        stocks = money//A[buy]
        money = money - stocks*A[buy]
        money += stocks*A[sell]
        stocks = 0
        i = sell+1
    print(money)
    

if '__main__' == __name__:
    resolve()


Measured memory_bytes: 9140
D = int(input())
cl = list(map(int, input().split()))
sl = [list(map(int, input().split())) for _ in range(D)]

def score(d, ti, last):
    s = sl[d-1][ti]
    for i in range(len(cl)):
        c = cl[i]
        s -= c*(d-last[i])
    return s

res = []
last = [0]*26
for d in range(D):
    ti = 0
    s = 0
    for t in range(26):
        l = last[t]
        last[t] = d+1
        ss = score(d+1,t,last)
        if ss>s:
            s = ss
            ti = t
        last[t] = l
    last[ti] = d+1
    res.append(ti+1)

for t in res:
    print(t)



Measured memory_bytes: 68440
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int comp(string a,string b){
  int cnt=0;
  for(int i=0;i<a.length();i++){
    if(a[i]!=b[i])cnt++;
  }
  return cnt;
}
int main(){
  fastIO();
  string s,t;
  int ans=1e9;
  cin>>s>>t;
  for(int i=0;i<=(s.length()-t.length());i++){
    ans=min(ans,comp(t,s.substr(i,t.length())));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3608
from fractions import gcd


def main():
    N = int(input())
    A = list(map(int, input().split()))
    left = [0] * N
    right = [0] * N
    for i in range(1, N):
        left[i] = gcd(left[i-1], A[i-1])
        right[-1-i] = gcd(right[-i], A[-i])
    gcds = []
    for i in range(N):
        gcds.append(gcd(left[i], right[i]))
    print(max(gcds))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16112
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    static string str[1000];
    REP(i,n)cin >> str[i];
    REP(i,n){
        //cout << str[i-1][str[i-1].size()-1] << ":" << str[i][0] << endl;
        if(i>0)if(str[i-1][str[i-1].size()-1] != str[i][0]){
            cout << "No" << endl;
            return 0;
        }
        REP(j,i){
            //cout << str[j] << ":" << str[i] << endl;
            if(str[i]==str[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int n,m;
map<int,int>mp;
int a[N],b[N];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),mp[a[i]]++;
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&b[i]);
		if(mp[b[i]]<=0)
		{
			puts("NO");
			return 0;
		}
		mp[b[i]]-=1;
	}
	puts("YES");
	return 0;
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	if(n<m)
	{
		puts("NO");
	}
	else
	{
		for(int i=n;i>=n-m+1;i--)
		{
			if(b[m-n+i]>a[i])
			{
				puts("NO");
				return 0;
			}
		}
		puts("YES");
	}
	return 0;
}

Measured memory_bytes: 12800
def main():
    n = int(input())
    aa = [0] + list(map(int, input().split())) + [0]
    c_all = sum(abs(aa[i] - aa[i - 1]) for i in range(1, len(aa)))
    for i in range(1, n + 1):
        c = c_all - abs(aa[i + 1] - aa[i]) - abs(aa[i] -
                                                 aa[i - 1]) + abs(aa[i + 1] - aa[i - 1])
        print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14176
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>

int n, d;

int main() {
	scanf("%d %d", &n, &d); int ans = 0;
	for (int i = 1, x, y; i <= n; ++i) {
		scanf("%d %d", &x, &y);
		double dis = sqrt(1ll * x * x + 1ll * y * y);
		if (dis <= d) ++ans;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3808
#include<stdio.h>

int main(void)
{
 int height[10];
 int max[3]={0};
 int i;

 for(i = 0; i < 10; i++)
 {
  scanf("%d",&height[i]);
  if(height[i] >= max[0])
  { 
    max[2] = max[1];
    max[1] = max [0];  
    max[0] = height[i]; 
  }else if(height[i] >= max[1]){
    max[2] = max [1];  
    max[1] = height[i]; 
  }else if(height[i] >= max[2]){
    max[2] = height[i];
  }
 }
 for(i = 0; i < 3; i++)
 printf("%d\n",max[i]);
 return 0;
}

Measured memory_bytes: 0
# include <stdio.h>
int main()
{
    double a,b,c,d;
    scanf("%lf",&a);
    b=3.1415926535897932384626433*a*a;
    c=2*3.1415926535897932384626433*a;
    printf("%.6lf %.6lf\n",b,c);
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

typedef long long ll;

string match_matching(ll n, ll m, ll a[]) {
  // dp[i]: iこのマッチを使った時の桁数
  ll invalid = -100000000;
  vector<ll> dp(n+1, invalid);
  // 数字 1,2,3,4,5,6,7,8,9を1つ作るには、それぞれちょうど
  //      2,5,5,4,5,6,3,7,6 本のマッチ棒を使う 
  int b[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
  dp[0] = 0;
  for(ll i = 2;i<n+1;i++) {
    ll max_digits = invalid;
    for(int j = 0;j<m;j++) {
      ll required_match = b[a[j] - 1]; // 必要なマッチの本数
      if(i < required_match) {
	continue;
      }
      ll count = dp[i - required_match] + 1;
      // cout << "i: " << i << " " << "a[j]: "<< a[j] << " dp[" << i-required_match << "]: " << dp[i-required_match]<<  " count: " << count << " required_match: " << required_match << endl;
      max_digits =  max(count, max_digits);
      max_digits = max_digits < 0 ? invalid : max_digits;
    }
    dp[i] = max_digits;
  }
  /*
  for(ll i = 0; i<n+ 1;i++) {
    cout << i << " -> " << dp[i] << endl;
  }
  */

  ll remains = n;
  string ans = "";
  while(remains>0) {
    ll target_digit = a[0];
    // cout << "remains: " << remains << endl;
    for(ll i=0;i<m;i++) {
      ll req_match = b[a[i] - 1];
      if(remains < req_match) {
	continue;
      }
      if(remains < b[target_digit - 1]) {
	target_digit = a[i];
	continue;
      }
      /*
      cout << "a: " << a[i] << endl;
      cout << "b: " << req_match << endl;
      cout << dp[remains - req_match] << endl;
      cout << dp[remains - b[target_digit - 1]] << endl;
      cout << "====" << endl;
      */
      if(dp[remains - req_match] > dp[remains - b[target_digit - 1]]) {
	target_digit = a[i];
	continue;
      }
      if(dp[remains - req_match] == dp[remains - b[target_digit - 1]]) {
	target_digit = target_digit > a[i] ? target_digit : a[i];
	continue;
      }
    }
    remains = remains - b[target_digit - 1];
    ans = ans + to_string(target_digit);
  }

  return ans;
}
int main() {
  ll n, m;
  cin >> n;
  cin >> m;
  ll a[m];

  for(int i=0;i<m;i++) {
    cin >> a[i];
  }
  cout << match_matching(n, m, a);
}

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

int main()
{
	int x, y;

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

		if (x == 0 && y == 0)
		{
			return 0;
		}
		if (x <= y)
		{
			cout << x << " " << y << "\n";
		}
		if (x > y)
		{
			cout << y << " " << x << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 2980
#include<bits/stdc++.h>
using namespace std;
int a[100000 + 5];
int main(){
	int n;
	cin >> n;
	int fg=0,num=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int now = a[0],maxn=0;
	for(int i=1;i<n;i++){
		if(a[i] > now){
			fg=1;
			num=0;
		}
		else{
			fg=0;
		}	
		if(fg==0){
			num++;
		}
		now = a[i];
		if(num > maxn)
			maxn = num;
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
 
int main()
{
    long Q,H,S,D,N;
    cin>>Q>>H>>S>>D>>N;
    long t=min({N*4*Q,N*2*H,N*S});
    cout<<min(N/2*D+N%2*t/N,t)<<endl;
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

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

//通常
struct UnionFind {
    V par, rank;
    UnionFind(int size) { init(size); }
    void init(int size) {
        REP(i, size) {
            par.push_back(i);
            rank.push_back(0);
        }
    }
    int root(int x) {
        if(par[x] == x)
            return x;
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            swap(x, y);
        } else {
            if(rank[x] == rank[y]) rank[x]++;
        }
        par[y] = x;
    }
    bool same(int x, int y) { return root(x) == root(y); }
};

int T[100000];
bool marked[100000];
int dfs(int v) { return marked[v] ? v : dfs(T[v]); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q, _t;
    char _c;
    while(cin >> N >> Q && N) {
        memset(marked, 0, sizeof(marked));
        FOR(i, 1, N) {
            cin >> _t;
            _t--;
            T[i] = _t;
        }
        marked[0] = true;
        ll sum = 0;
        REP(i, Q) {
            cin >> _c >> _t;
            _t--;
            if(_c == 'Q')
                sum += dfs(_t) + 1;
            else
                marked[_t] = true;
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3580
#!/usr/bin/env python3

P_NUM = 1000000007


def solv(n, m, a):
    start = 0
    dists = []
    max_dist = 0
    for broken in a:
        dist = broken-1-start
        if dist < 0:
            return 0
        elif dist > max_dist:
            max_dist = dist
        dists.append(dist)
        start = broken+1
    dist = n-start
    if dist < 0:
        return 0
    elif dist > max_dist:
        max_dist = dist
    dists.append(dist)

    no_hole = [1] * (max_dist+1)
    for i in range(2, max_dist+1):
        no_hole[i] = no_hole[i-1] + no_hole[i-2]

    ans = 1
    for dist in dists:
        ans = (ans * no_hole[dist]) % P_NUM

    return ans


if __name__ == '__main__':

    n, m = map(int, input().split())
    a = [int(input()) for _ in range(m)]

    ans = solv(n, m, a)

    print(ans)


Measured memory_bytes: 460020
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

int a[N];
map<int,int>m;
int main()
{
   int n;
   Int(n);

   for(int i=1;i<=n;++i){
    Int(a[i]);
   }
   m[1+a[1]]=1;
   ll res=0ll;
   for(int i=2;i<=n;++i){
      res+=(ll)(m[i-a[i]]);
      m[i+a[i]]++;
   }

   printf("%lld\n", res);
    return 0;
}



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

int main()
{
	int a[10];
	for (int i = 0; i < 10; i++)
	{
		cin >> a[i];
	}

	for (int i = 0; i < 9; i++)
	{
		for (int j = 9; j >= i; j--)
		{
			if (a[i] > a[j])
			{
				int t = a[i];
				a[i] = a[j];
				a[j] = t;
			}
		}
	}

	for (int i = 0; i < 3; i++)
	{
		cout << a[9 - i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<string>
#include<iostream>
#include<map>

int main() {
  int x;
  std::map<int, int> m;
  std::cin >> x;
  while(x--) {
    int t;
    std::cin >> t;
    if(m[t] == 1) {
      std::cout << "NO" << std::endl;
      return 0;
    } else {
      m[t] = 1;
    }
  }
  std::cout << "YES" << std::endl;
  return 0;
}

Measured memory_bytes: 9600
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;

void main()
{
  int[] n_and_m;
  int n;
  int m;
  
  int[] a_tachi;
  int total_vote_count;
  
  n_and_m = readln.split.to!(int[]);
  n = n_and_m[0];
  m = n_and_m[1];
  
  a_tachi = readln.split.to!(int[]);
  total_vote_count = a_tachi.sum;
  
  if (a_tachi.count!(a => a * 4 * m >= total_vote_count) >= m) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
double eps=1e-8;
ll mod=1e9+7;
ll inf=1e9;
priority_queue<P,vector<P>,greater<P> > pq;




template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]

  auto L = lower_bound(v.begin(), v.end() , l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower

  return R-L;
}

int main(){
  vector<ll> v;
  
  ll n,a[200000],b[200000];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];

  ll ans=0;
  for(int id=0;id<30;id++){
    ll flg=0;

    v.clear();
    v.resize(n);
    for(int i=0;i<n;i++){
      v[i] = a[i]%(2<<id);
    }

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

    for(int i=0;i<n;i++){
      ll nb=b[i]%(2<<id);

      ll A=(1<<id);
      ll B=2*A-1;
      ll C=A+2*A;
      ll D=(1<<30);
      
      ll sum = Count(v,A -nb,B -nb) + Count(v,C -nb,D -nb);

      flg ^= (sum%2);
    }
    
    ans+= (flg<<id);
  }

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


Measured memory_bytes: 6912
import math
 
def comb(n,r):
    return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

def deff_half(l, h):
    d = abs(h/2 - l[0])
    r = 0
    for i in range(1, len(l)):
        if l[i] == h:
            continue
        if d >= abs(h/2 - l[i]):
            d = abs(h/2 - l[i])
            r = i
    return l[r]
    
n = int(input())
x = list(map(int, input().split(" ")))
 
a = max(x)
result = deff_half(x, a)

print(a , result)

Measured memory_bytes: 14180
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N = I()
cur = 0
ans = []; S = [[] for _ in range(2)]
for i in range(2):
    S[i] = str(input())
#print(S[0][0])
C = []
i = int(0)
while i<=N-1:
    if S[0][i]==S[1][i]:
        C.append(0)
        i +=1
    else:
        C.append(1)
        i +=2
#print(C)
cur = int(1)
for i in range(len(C)):
    if i==0:
        if C[i]==0:
            cur *= 3
        else:
            cur *= 6
    else:
        if not (C[i-1]==1 and C[i]==0):
            if (C[i-1]==1 and C[i]==1):
                cur *=3
            else:
                cur *= 2

ans = cur%mod
print(ans)

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

int main() {
	int n, max;
	int *data;
	int cmp,maxarray;
	int i, j, k;

	scanf("%d",&n);

	data = (int *)malloc(n * sizeof(int));

	for (i = 0; i < n; i++) {
		scanf("%d",&data[i]);
	}

	max = data[n - 1] - data[n - 2];
	maxarray = data[n - 1];

	for (i = n - 2; i > 0; i--) {
		if (data[i] > maxarray)
			maxarray = data[i];

		if (maxarray - data[i - 1] > max)
			max = maxarray - data[i - 1];
	}

	printf("%d\n", max);

	free(data);
	return 0;
}


Measured memory_bytes: 2292
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    cout << (1900 * m + 100 * (n-m)) * pow(2,m) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vpll> vvpll;
typedef unordered_map<ll, ll> um;
typedef unordered_set<ll> us;

#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ts ll t; in(t) while (t--) solve();
#define ks ll t; in(t) FOR(i, 1, t+1) out("Case #" << i << ": " << solve());
#define endl '\n'
#define ln cout << endl;
#define in(x) cin >> x;
#define out(x) cout << x << endl;
#define flush cout << flush;
#define reset(a, b) memset(a, b, sizeof(a));
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FORI(i, a, b, c) for (ll i = a; i < b; i += c)
#define FORD(i, a, b) for (ll i = a; i > b; --i)
#define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++)
#define FORALL(it, v) for (auto it : v)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define vin(v, x) vll v(x); FOR(i, 0, x) in(v[i])
#define all(v) v.begin(), v.end()
#define allr(v, r) v.begin(), v.begin() + r
#define showv(v) FORALL(it, v) cout << it << ' '; ln
#define printv(v) FORALL(it, v) out(it)
#define show2d(v) FORALL(it, v) { FORALL(j, it) cout << j << ' '; ln}
#define showm(v) FORALL(it, v) cout << it.F << ": " << it.S << ' '; ln
#define sortv(v) sort(all(v));
#define revv(v) reverse(all(v));
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
#define gcd __gcd
#define checkbit(n, i) (n >> i) & 1               // check ith bit
#define bitcount __builtin_popcount               // count set bits
#define firstbitindex __builtin_ctz               // count trailing zeros
#define lastbitindex __builtin_clz                // count leading zeros
#define bitparity __builtin_parity                // check set bits are even or odd
#define findv(v, x) (find(all(v), x) != v.end())  // find in a vector
#define findsm(u, x) (u.find(x) != u.end())       // find in a set / map
#define findstr(s, x) (s.find(x) != string::npos) // find in a string
#define sz(a) a.size()
#define precise(x) cout << fixed << setprecision(x);

const ll MAXN = 1e5, MOD = 998244353, SIZE = 2e7;//, INF = 0x7f7f7f7f7f7f7f7f;
const double EPS = 1e-9, PI = acos(-1);
const int INFi = 0x7f7f7f7f;

//<<------Declare Variables Here----->>//
ll n;
char c[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
string s;

//<<-----Implement Functions Here---->>//
void solve()
{
    in(n)
    while (n)
        --n, s = c[n % 26] + s, n /= 26;
    out(s)
}

//<<----------Start of Main---------->>//
int main()
{
    fastio
    //ts
    solve();
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

ll modpow(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * a % mod; 
        a = a * a % mod;
        n >>= 1;
    }

    return ret;
}

ll modinv(ll a, ll mod) {
    return modpow(a, mod-2, mod);
}

int main() {
    ll n, p;
    cin >> n >> p;
    vector<int> a(n);
    {
        string s;
        cin >> s;
        for (int i = 0; i < n; ++i) {
            a[i] = (s[i] - '0') % p;
        }
    }

    if (p == 2 || p == 5) {
        ll ans = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] == 0) ans += i+1;
        }
        cout << ans << endl;
        return 0;
    }

    ll s = 1, t = 0;
    vector<ll> cnt(p, 0);
    cnt[a[0]%p] = 1;

    auto inv = [&](ll n) {
        ll ret = n + p - t;
        ret %= p;
        ret = ret * modinv(s, p) % p;
        return ret;
    };

    ll ans = cnt[0];
    for (int i = 1; i < n; ++i) {
        s = s * 10 % p;
        t = (t * 10 + a[i]) % p;

        cnt[inv(a[i])] += 1;
        ans += cnt[inv(0)];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
int main(){
int a,b,n,s=0;
  std::cin>>a>>b;
  for(int i=1;i<=b;i*=10){
    n=i*10;
  }
  for(int i=1;i*i<=a*n+b;i++){
    if(a*n+b==i*i){
      s=1;
    }
  }
  if(s==0){
    std::cout<<"No"<<std::endl;
  }
  else{
  std::cout<<"Yes"<<std::endl;
  }
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll a;
    string s;
    cin >> a >> s;
    if(a >= 3200) cout << s;
    else cout << "red";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>>  p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	for (int i = 0; i < n - 2; i++) {
		if (p[i].first == p[i].second && p[i + 1].first == p[i + 1].second && p[i + 2].first == p[i + 2].second) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef		vector<ll>      vll;
#define		pb              push_back
string intostr(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}

char Uplowch(char ch)
{
    if(ch >= 'A' &&  ch <= 'Z')
        ch += 32;
    return ch;
}
char Lowupch(char ch)
{
    if(ch >= 'a' &&  ch <= 'z')
        ch -= 32;
    return ch;
}
bool Isalpha(char ch)
{
    if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
        return true;
    return false;
}
int Strtoint(string str)
{
    stringstream ss(str);
    int x = 0;
    ss >> x ;
    return x ;
}
string Intostr(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}

#define		PB              pop_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)

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

int dx[] = {0, 0, -1, 1} ;    // right , left , forward , backward
int dy[] = {1, -1, 0, 0} ;

//bool check(int x , int y) {
//    if(x <= n && y <= m && x >= 1 && y >= 1)
//        return 1 ;
//    return 0 ;
//}

int main()
{
    //freopen("in.txt","r",stdin);

    ios::sync_with_stdio(0);
    cin.tie(0);

    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC"<<nn;
    else cout<<"ABC"<<nn;

}



Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
  int total_cost,num_1en_coin;
  cin >> total_cost;
  cin >> num_1en_coin;
  int surplus = total_cost%500;
  
  if (total_cost == 0){
    cout << "No" << endl;
  }
  else if (num_1en_coin >= surplus){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
 
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N=int(input())
lst=[[] for f in range(N)]
ans=[[0 for e in range(3)] for f in range(N)]
for i in range(N):
 lst[i]=list(map(int,input().split()))
ans[0][0]=lst[0][0]
ans[0][1]=lst[0][1]
ans[0][2]=lst[0][2]
if N>1 :
 for i in range(1,N):
  ans[i][0]=max(ans[i-1][1],ans[i-1][2])+lst[i][0]
  ans[i][1]=max(ans[i-1][0],ans[i-1][2])+lst[i][1]
  ans[i][2]=max(ans[i-1][1],ans[i-1][0])+lst[i][2]
print(max(ans[N-1]))


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

int main() {
  int n, m, t, s(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> t;
    s += t;
  }
  if (s > n) {
    cout << -1 << endl;
  } else {
    cout << n - s << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,0,n){
        cin >> a[i];
    }
    sort(rall(a));
    priority_queue<ll> que;
    que.push(a[0]);
    ll ans = 0ll;
    rep(i,1,n){
        ll p = que.top();
        que.pop();
        ans += p;
        rep(j,0,2){
            que.push(a[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6876
#include <stdio.h>
#include <stdbool.h>

#define W 10
#define K 10

int Robmax(int data[], int size);

int main()
{
	int i,k;
	int Wmax, Kmax;
	int Wsum=0;
	int Ksum=0;
	int Wdata[W];
	int Kdata[K];
	for(i=0; i<W; i++){
		scanf("%d", &Wdata[i]);
	}
	for(k=0; k<K; k++){
		scanf("%d", &Kdata[k]);
	}
	for(i=0; i<3; i++){
		Wmax = Robmax(Wdata, W);
		Wsum += Wmax;
		Kmax = Robmax(Kdata, K);
		Ksum += Kmax;
	}
	printf("%d %d\n", Wsum, Ksum);
	return 0;
}

int Robmax(int data[], int size)
{
	int i;
	int idx = 0;
	int max = data[idx];
	for(i=0; i<size; i++){
		if(max < data[i]){
			max = data[i];
			idx = i;
		}
	}
	data[idx] = 0;
	return max;
}

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "YES"
#define NO "NO"
#define MOD 1000000000 + 7
#define forit(v) for (auto it = v.begin(); it != v.end(); ++it)

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  string s; cin >> s;

  int n1 = 10 * (s[0] - '0') + (s[1] - '0');
  int n2 = 10 * (s[2] - '0') + (s[3] - '0');

  if (n1 == 0) {
    if (0 < n2 && n2 <= 12)
      cout << "YYMM";
    else
      cout << "NA";
  } else if (n2 == 0) {
    if (0 < n1 && n1 <= 12)
      cout << "MMYY";
    else
      cout << "NA";
  } else {
    if (n1 > 12 && n2 > 12)
      cout << "NA";
    else if (n1 <= 12 && n2 <= 12)
      cout << "AMBIGUOUS";
    else if (n1 <= 12)
      cout << "MMYY";
    else
      cout << "YYMM";
  }
  
  
  // cout << num << endl;
  // cout << (flag ? YES : NO) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
        int N;
        string ans="Three";
        char S[100];
        cin >> N;
        for(int i=0; i<N; i++)
                cin >> S[i];
        for(int i=0; i<N; i++){
                if(S[i]=='Y'){
                        ans="Four";
                        break;
                }
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
try:
    N, Y = map(int, input().split())
    cnt = 0
    for x in range(N+1):
        for y in range(N+1):
            z = N-x-y
            if z>=0 and 10000*x+5000*y+1000*z==Y:
                cnt += 1
                print(x,y,z)
                break
        if cnt>0:
            break
    if cnt==0:
        print('-1 -1 -1')
except EOFError:
    pass

Measured memory_bytes: 3060