akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[]) {
    int N;
    std::cin >> N;

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

    if (N == 2) {
        if (v[0] != v[1]) {
            printf("0\n");
        } else {
            printf("1\n");
        }
        return 0;
    }


    auto bucket1 = new int[100001];
    auto bucket2 = new int[100001];
    for (int i = 1; i < 100001; i+=1) {
        bucket1[i] = 0;
        bucket2[i] = 0;
    }
    // else, N > 2
    for (int i = 0; i < N; i+=2) {
        bucket1[v[i]]++;
    }

    for (int i = 1; i < N; i+=2) {
        bucket2[v[i]]++;
    }

    int max1 = 0;
    int index1 = 0;
    int max2 = 0;
    int index2 = 0;
    for (int i = 1; i < 100001; i+=1) {
        if (max1 < bucket1[i]) {
            max1 = bucket1[i];
            index1 = i;
        }
        if (max2 < bucket2[i]) {
            max2 = bucket2[i];
            index2 = i;
        }
    }
    std::sort(bucket1, bucket1 + 100001, std::greater<int>());
    std::sort(bucket2, bucket2 + 100001, std::greater<int>());
    int max12 = bucket1[1];
    int max22 = bucket2[1];
    //printf("%d %d\n", max12, max22);
    // same number is max!
    if (index1 == index2) {
        if (max12 == 0) {
            max2 = max22;
        } else if (max22 == 0) {
            max1 = max12;
        } else {
            if (max22 > max12) {
                max2 = max22;
            } else {
                max1 = max12;
            }
        }
        printf("%d\n", (N / 2 - max1) + (N / 2 - max2));
    } else
        printf("%d\n", (N / 2 - max1) + (N / 2 - max2));

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(a+b-c>=0) cout<<"No"<<endl;
  else{
    if(a*a-2*a*b+b*b-2*a*c+c*c-2*b*c>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	
	static Scanner sc = new Scanner(System.in);
	static long a, b, tmp, max, min, mod, x, y;

	public static void main(String[] args) {
		
		while(read()){
			solve_max();
			solve_min();
			System.out.println(max + " " + min);
		}
	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
			
		a = sc.nextInt();
		b = sc.nextInt();
		
		if(a < b){
			tmp = a;
			a = b;
			b = tmp;
		}
		
		return true;
	}
	
	public static void solve_max(){
		
		x = a;
		y = b;
		
		while((mod = (x % y)) != 0){
			x = y;
			y = mod;
		}
		
		max = y;
	}
	
	public static void solve_min(){
		min = (a * b) / max;
	}

}

Measured memory_bytes: 11000
#include<stdio.h>
#include<stdlib.h>
int ms[300001]={0,1},i,j,N;
int main()
{
	for(i=6;i<=300001;i++)
		if((i%7==1||i%7==6)&&ms[i]!=-1)
		{
			ms[i]=1;
			for(j=i*2;j<300001;j+=i)
				ms[j]=-1;
		}
	for(;scanf("%d",&N),N!=1;)
	{
		printf("%d:",N);
		for(i=2;i<=N;i++)
			if(ms[i]==1&&N%i==0&&ms[N/i]!=0)
				printf(" %d",i);
		puts("");
	}
	return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    for(int i = 1;(a*i) % b != 0;i++){
        if((a*i) % b == c){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

ll N;
ll cnt=2;



int main(void) {
  ll i, j, k;

  ll N, K;
  cin >> N >> K;
  ll cnt[111]={};
  
  for(i=0; i<K; i++) {
    ll d;
    cin >> d;
    
    for(j=0; j<d; j++) {
      ll a;
      cin >> a;
      a--;
      cnt[a]++;
    }
  }
  
  ll ans=0;
  for(i=0; i<N; i++) if(cnt[i]==0) ans++;
  pt(ans);
  
  
  
}
 


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

int main(){
    int year, month, day;
    char a, b;

    cin >> year >> a >> month >> b >> day;
    
    if (month < 5){
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int main(){
    int a,b;
    char s[11],t[11],u[11];
    scanf("%s%s%d%d%s",&s,&t,&a,&b,&u);
    for(int i=0;i<10;i++){
        if(u[i]!=s[i]){
            printf("%d %d\n",a,b-1);
            break;
        }
        if(u[i]!=t[i]){
            printf("%d %d\n",a-1,b);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int W, H, x, y ,r;
  cin >> W >> H >> x >> y >> r;
  if (x - r < 0) { cout << "No" << endl; return 0; }
  if (y - r < 0) { cout << "No" << endl; return 0; }
  if (x + r > W) { cout << "No" << endl; return 0; }
  if (y + r > H) { cout << "No" << endl; return 0; }
  if (x + r > W) { cout << "No" << endl; return 0; }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1156
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define deba(a) cout << #a << " " << a << endl;
int main()
{
	fast;
#ifndef ONLINE_JUDGE
	freopen("/home/kushagra/Desktop/Kushagra/input.txt", "r", stdin);
	freopen("/home/kushagra/Desktop/Kushagra/output.txt", "w", stdout);
#endif
	int t = 1;
	// cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		ll a[n];
		rep(i, 0, n)
		cin >> a[i];

		ll sum = a[0], end = a[0];

		rep(i, 1, n)
		{
			if (a[i] > end)
				sum += (a[i] - end);
			end = a[i];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC143D_Triangles
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Array.Sort(l);

            int count = 0;
            for (int a = 0; a < n - 2; a++)
            {
                for (int b = a + 1; b < n - 1; b++)
                {
                    //以下のやり方だとTLE
                    //for (int c = b + 1; c < n; c++)
                    //{
                    //    if (l[c] < l[a] + l[b])
                    //    {
                    //        count++;
                    //    }
                    //    else
                    //    {
                    //        break;
                    //    }
                    //}

                    //以下のやり方だとTLE解除
                    for (int c = n - 1; b + 1 <= n; c--)
                    {
                        if (l[c] < l[a] + l[b])
                        {
                            count += c - (b + 1) + 1;
                            break;
                        }
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int Takahashi[2], Aoki[2];
  string ans;
  cin >> Takahashi[0] >> Takahashi[1] >> Aoki[0] >> Aoki[1];

  while (true)
  {
    if (Aoki[0] - Takahashi[1] <= 0)
    {
      ans = "Yes";
      break;
    }
    else
      Aoki[0] -= Takahashi[1];

    if (Takahashi[0] - Aoki[1] <= 0)
    {
      ans = "No";
      break;
    }
    else
      Takahashi[0] -= Aoki[1];
  }
  
  cout << ans << endl;
  return 0;
}

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

const int INF = 1 << 29;

int n,m,cost[400][400];
vector<int> G[400], rG[400], vs;
bool used[400];
int cmp[400];

void add_edge(int from, int to){
  G[from].push_back(to);
  rG[to].push_back(from);
}
void dfs(int v){
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    if(!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}
void rdfs(int v, int k){
  used[v] = true;
  cmp[v] = k;
  for(int i=0;i<rG[v].size();i++){
    if(!used[rG[v][i]]) rdfs(rG[v][i],k);
  }
}
int scc(){
  fill(used,used+n,false);
  vs.clear();
  for(int v=0;v<n;v++){
    if(!used[v]) dfs(v);
  }
  fill(used,used+n,false);
  int k = 0;
  for(int i=vs.size()-1;i>=0;i--){
    if(!used[vs[i]]) rdfs(vs[i],k++);
  }
  return k;
}

void solve(){
  int dp[400],cost2[400][400];
  fill(dp,dp+400,0);
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) cost2[cmp[i]][cmp[j]] = cost[i][j];

  for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)
      if(cost2[i][j] > 0 && dp[i] + cost2[i][j] > dp[j])
        dp[j] = dp[i] + cost2[i][j];

  cout << dp[n-1] << endl;
}     

int main(){
  while(cin >> n >> m){
    fill(cost[0],cost[n],0);
    for(int i=0;i<n;i++) G[i].clear(), rG[i].clear();

    for(int i=0;i<m;i++){
      int a,b,c;
      cin >> a >> b >> c;
      cost[a][b] = c;
      add_edge(a,b);
    }

    scc();
    solve();
  }
}

Measured memory_bytes: 2512
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	ll k = (v - w) * t;
	ll j = abs(a - b);
	if (a == b)cout << "YES" << endl;
	else if (j <= k)cout << "YES" << endl;
	else cout << "NO" << endl;
}
int main() {
	solve();
}

Measured memory_bytes: 3628
from itertools import product
import numpy as np
MOD = 1000000007

H,W,K = map(int,input().split())
K -= 1

transition = [[0]*W for _ in range(W)]

for n in range(2**(W-1)):
  memo = [0]*W
  for i,e in enumerate(map(lambda x: x=='1',bin(n)[:1:-1])):
    if e:
      if memo[i] == 0:
        memo[i] = 1
        memo[i+1] = -1
      else:
        memo = None
        break

  if memo is not None:
    for i,d in enumerate(memo):
      transition[i][i+d] += 1


transition = np.array(transition,dtype=np.int64) % MOD


dp = np.zeros((W,1),dtype=np.int64)
dp[0,0] = 1
for b in map(lambda x: x=='1', bin(H)[:1:-1]):
  if b:
    dp = np.dot(transition, dp)
    dp %= MOD
  transition = np.dot(transition, transition)
  transition %= MOD

print(dp[K,0])

Measured memory_bytes: 12460
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i ++)
#define pb push_back
#define mp make_pair

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
const ll power = 49999;

ll n, k;
vector<ll> le, oldle, ri;
int main()
{

	/*

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	*/
	cin >> n >> k;
	bool f = true;
	ri.push_back(0);
	le.push_back(0);
	forn(i, 0, n)
	{
		ll a;
		cin >> a;
		if (a > 0)
			ri.push_back(a);
		else
			oldle.push_back(a);
	}
	while (oldle.size())
	{
		le.push_back(oldle.back());
		oldle.pop_back();
	}
	ll left = 0, right = 0;
	ll sum = 0;
	while (left < k && left < le.size()-1)
	{
		sum += le[left] - le[left + 1];
		left++;
	}
	while (left + right < k)
	{
		sum += ri[right + 1] - ri[right];
		right++;
	}
	ll res = sum + min(-le[left], ri[right]);
	left--;
	right++;
	while (right < ri.size() && left >= 0)
	{
		sum = sum + le[left+1] - le[left] + ri[right] - (right>0?ri[right - 1]:0);
		res = min(res, sum + min(-le[left], ri[right]));
		right++;
		left--;
	}

	cout << res;
	return 0;
}

Measured memory_bytes: 2548
import math

A,B,H,M = map(int,input().split())
hun = H * 60 + M

long = 6 * M
short = 0.5 * hun

rad = abs(long-short)
if rad > 180:
  rad = 360 - rad

if rad != 90 or 180:
  print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(rad))))
elif rad == 90:
   print(math.sqrt(A**2 + B**2))
else:
  print(A+B)

Measured memory_bytes: 9588
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}


//vc alp ={'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'};
//vc Alp ={'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'};
//cout<<""<<endl;

int main(void){
  ll N,K;cin>>N>>K;
    ll ans=0;
  for(ll i=K;i<=N+1;i++){
     ans +=((N-i+1)*i)%MOD+1;
     ans =ans%MOD;
  }
  cout<<ans<<endl;
}






Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void){
    int W,H,x,y,r;
    cin >> W;
    cin >> H;
    cin >> x;
    cin >> y;
    cin >> r;
    
    if(((x-r)>=0)&&(x<=(W-r))&&((y-r)>=0)&&(y<=(H-r)))
        cout << "Yes";
        else   cout << "No";
        
        cout << endl;
        
}


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

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	string S;
	cin >> S;

	int start = 0, end = S.length() - 1;
	while (S[start] != 'A') start++;
	while (S[end] != 'Z') end--;

	cout << end - start + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 640
def cake123(k, a, b, c)
  a.sort_by! { |x| -1 * x }
  b.sort_by! { |x| -1 * x }
  c.sort_by! { |x| -1 * x }

  abc = []
  a.each_with_index do |x, a_i|
    b.each_with_index do |y, b_i|
      break if (a_i + 1) * (b_i + 1) > k
      c.each_with_index do |z, c_i|
        break if (a_i + 1) * (b_i + 1) * (c_i * 1) > k
        abc << x + y + z
      end
    end
  end

  abc.sort_by! { |x| -1 * x }
  k.times do |i|
    puts abc[i]
  end
end

x, y, z, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
cake123(k, a, b, c)

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

int main() {
  int A,B;
  cin >> A >>B;

  if(A>=13){
    cout << B <<endl;
  }  
  else if(A<=5){
    cout << 0 <<endl;
  }
  else{
    cout << B/2 <<endl;
  }


}

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

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

    for(int i=0; i<s.size(); i++)    {
        if(i%2 == 0){
            if(s[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(s[i] =='R') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int N;
const int N_MAX = 1e5;

int main(){
  cin >> N;
  vector<int> odd(N_MAX+1, 0);
  vector<int> eve(N_MAX+1, 0);
  for(int i = 1; i <= N; i++){
    int v; cin >> v;
    if(i % 2 == 0) eve[v]++;
    else odd[v]++;
  }
  
  int in1 = -1, in2 = -1;
  int m11 = 0, m12 = 0, m21 = 0, m22 = 0;
  for(int i = 0; i <= N_MAX; i++){
    if(odd[i] >= m11) {
      in1 = i; m12 = m11; m11 = odd[i];
    }else if(odd[i] >= m12){
      m12 = odd[i];
    }
    if(eve[i] >= m21) {
      in2 = i; m22 = m21; m21 = eve[i];
    }else if(eve[i] >= m22){
      m22 = eve[i];
    }
  }
  int ans;
  if(in1 != in2) ans = N - m11 - m21;
  else ans = min(N - m11 - m22, N - m12 - m21);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1024
import sys

n = int(input())
nums = [int(num) for num in input().split(" ")]

if n == 1:
    print(nums[0])
else:
    for i in range(0, n):
        v = nums[i]
        j = i - 1
        while j >= 0 and v < nums[j]:
            nums[j+1] = nums[j]
            j -= 1
        nums[j+1] = v

        result = ""
        for k in range(0, n - 1):
            result += str(nums[k])
            result += " "
        result += str(nums[n - 1])
        print(result)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
using namespace std;

ll n,k;
int main() {
    //freopen("input.txt", "r", stdin) ;
    //freopen("output.txt", "w", stdout) ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    cin>>n>>k;
    vector<ll> p(n);
    vector<ll> c(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        --p[i];
    }
    for(int i=0;i<n;i++) cin>>c[i];
    ll maxv=-10000000000000000;
    for(int i=0;i<n;i++){
        int iter=i;
        ll seq_sum=0;
        ll seq_cnt=0;
        while(true){
            ++seq_cnt;
            seq_sum+=c[iter];
            iter=p[iter];
            if(iter==i) break;
        }
        ll one=0;
        ll cnt=0;
        while(true){
            cnt++;
            one+=c[iter];
            if(cnt>k) break;
            ll num=(k-cnt)/seq_cnt;
            ll score=one+max(0ll,seq_sum) * num;
            maxv=max(maxv,score);
            iter=p[iter];
            if(iter==i) break;
        }
    }
    cout<<maxv;
    return 0;
}




Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 100002;

int n;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    cin >> n;
    int a, b, c, x = 0, y = 0, z = 0;

    for (int i = 0; i < n; ++i) {
        cin >> a >> b >> c;

        int xx = x, yy = y, zz = z;
        x = max(zz, yy) + a;
        y = max(xx, zz) + b;
        z = max(xx, yy) + c;
    }

    cout << max(x, max(y, z)) << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a, b, c = 1, 0, 0
for i in range(80)[::-1]:
    if N>>i & 1: a, b, c = a, a+b, 2*b+3*c
    else: a, b, c = a+b, b, b+3*c
print((a+b+c) % (10**9+7))

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let mut list = Vec::new();
    list.push(vec![0]);
    for i in 0..n-1 {
        let mut new_list = Vec::new();
        for i in 0..list.len() {
            let mx = list[i].iter().max().unwrap();
            for j in 0..mx+2 {
                let mut e = list[i].clone();
                e.push(j);
                new_list.push(e);
            }
        }
        list = new_list;
    }

    for i in 0..list.len() {
        let mut s = String::new();
        for &e in &list[i] {
            s.push((e as u8 + 'a' as u8) as char);
        }
        println!("{}",s);
    }
}


Measured memory_bytes: 23872
#include <stdio.h>
int main(){
  int a,i,j,flag=0;
  scanf("%d",&a);
  for(i=1;i<=9;i++){
  	for(j=1;j<=9;j++){
    	if(i*j==a)flag=1;
    }
  }
  if(flag==0)printf("No\n");
  else printf("Yes\n");
}

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

int main(int args, char *argv[])
{
  int N;
  cin >> N;
  int A[2][N];
  for (int i = 0; i < 2; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cin >> A[i][j];
    }
  }

  int mx = 0;
  for (int i = 0; i < N; i++)
  {
    int tmp = 0;
    for (int j = 0; j < N; j++)
    {
      if (j <= i)
      {
        tmp += A[0][j];
      }
      if (j >= i)
      {
        tmp += A[1][j];
      }
    }

    if (tmp > mx)
    {
      mx = tmp;
    }
  }

  cout << mx << endl;
  return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,p[8],q[8],ans=INF;
vector<int> v;
vector<pair<int,int>> V;

signed main() {
    cin >> n;
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    rep1(i,n) v.pb(i);
    int a=0,b=0,z=0;
    do {
        bool is_a=true, is_b=true;
        rep(i,n) is_a &= p[i]==v[i], is_b &= q[i]==v[i];
        if (is_a) a = z;
        if (is_b) b = z;
        z++;
    } while(next_permutation(all(v)));
    cout << abs(a-b) << endl;
}






Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n;
	int a[100];
	int i,j,minj,s,c=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	
	for(i=0;i<n;i++)
	{
		minj=i;
		
		for(j=i;j<n;j++)
		{
			if(a[j]<a[minj])
			{
				minj=j;
			}
		}
		if(a[i]>a[minj])
		{
			s=a[i];
			a[i]=a[minj];
			a[minj]=s;
			c++;
		}
	}
	
	for(i=0;i<n;i++)
	{
		printf("%d",a[i]);
		if(i!=n-1)
		{
			printf(" ");
		}
		else
		{
			printf("\n");
		}
	}
	printf("%d\n",c);
	
	return 0;
}


Measured memory_bytes: 1996
#include<bits/stdc++.h>
#define ll long long 
using namespace std ; 

int main()
{
	ll g[3], b[3], s[3], cnt = 0, n; 
	cin >> n >> g[1] >> s[1] >> b[1] >> g[2] >> s[2] >> b[2];
	ll p1 = 0, p2 = 0, p3 = 0;
	p1 ^= ( g[1] >= g[2] );
	p2 ^= ( s[1] >= s[2] ); 
	p3 ^= ( b[1] >= b[2] );
	if (p1 == 0 && p2 == 0 && p3 == 0) 
	{
		for (int i = 0 ; i <= n / g[1] ; i++) 
		{
			for (int j = 0; j <= (n - i * g[1]) / s[1]; j++) 
			{
				int k = (n - i * g[1] - j * s[1]) / b[1];
				cnt = max(cnt, i * (g[2] - g[1]) + j * (s[2] - s[1]) + k * (b[2] - b[1])) ; 
			}
		}
		n += cnt ; 
	}
	else if (p1 && p2 && p3) 
	{
		for (int i = 0; i <= n / g[2]; i++) 
		{
			for ( int j = 0 ; j <= (n - i * g[2]) / s[2]; j++ ) 
			{
				int k = (n - i * g[2] - j * s[2]) / b[2] ; 
				cnt = max(cnt, i * (g[1] - g[2]) + j * (s[1] - s[2]) + k * (b[1] - b[2])) ;
			}
		}
		n += cnt ; 
	}
	else if ( p1 && p2 )
	{	
		n += n / b[1] * (b[2] - b[1]) ; 
		for ( int i = 0 ; i <= n / g[2] ; i++ ) 
		{
			int k = (n - i * g[2]) / s[2] ; 
			cnt = max(cnt, i * (g[1] - g[2]) + k * (s[1] - s[2])) ; 
		}
		n += cnt ; 
	}		
 	else if ( p2 && p3 ) 
	{
 		n += n / g[1] * (g[2] - g[1]) ; 
 		for ( int i = 0 ; i <= n / s[2] ; i++ ) 
		{
			int k = (n - i * s[2]) / b[2] ; 
			cnt = max(cnt, i * (s[1] - s[2]) + k * (b[1] - b[2])) ; 
		}
		n += cnt ; 
 	}
	else if ( p1 && p3 ) 
	{
		n += n / s[1] * (s[2] - s[1]) ;
		for ( int i = 0 ; i <= n / g[2] ; i++ ) 
		{
			int k = (n - i * g[2]) / b[2] ; 
			cnt = max(cnt, i * (g[1] - g[2]) + k * (b[1] - b[2])) ; 
		}
		n += cnt ;
	}
	else if ( p1 ) {
		for ( int i = 0 ; i <= n/s[1] ; i++ ) {
			int k = (n-i*s[1])/b[1] ; 
			cnt = max(cnt,i*(s[2]-s[1])+k*(b[2]-b[1])) ; 
		}
		n += cnt ;
		n += n/g[2]*(g[1]-g[2]) ;
	}
	else if ( p2 ) {
		for ( int i = 0 ; i <= n/g[1] ; i++ ) {
			int k = (n-i*g[1])/b[1] ; 
			cnt = max(cnt,i*(g[2]-g[1])+k*(b[2]-b[1])) ; 
		}
		n += cnt ; 
		n += n/s[2]*(s[1]-s[2]) ;
	}
	else if ( p3 ) {
		for ( int i = 0 ; i <= n/g[1] ; i++ ) {
			 int  k = (n-i*g[1])/s[1] ; 
			cnt = max(cnt,i*(g[2]-g[1])+k*(s[2]-s[1])) ; 
		}
		n += cnt ; 
		n += n/b[2]*(b[1]-b[2]) ;
	}
	cout << n ; 
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
       	int C = Integer.parseInt(sc.next());
      	int min = Math.min(A,B);
      	int  max = Math.max(A,B);
      	if ((min <= C) && (C <= max)) System.out.println("Yes");
      	else System.out.println("No");
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
T intceil(T a, T b) {
    return (a + (b - 1)) / b;
}

signed main() {
    INIT;
    cin >> S;
    REP(i, S.size()) {
        ans += int(S[i] - '0');
    }
    if (ans % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3740
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Node[] nodes = new Node[n];
        boolean[] isRoot = new boolean[n];
        Arrays.fill(isRoot, true);
        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            int k = sc.nextInt();
            int[] children = new int[k];
            for (int j = 0; j < k; j++) {
                children[j] = sc.nextInt();
                isRoot[children[j]] = false;
            }
            nodes[id] = new Node(children);
        }

        for (int i = 0; i < n; i++) {
            if (isRoot[i]) {
                solve(nodes, -1, i, 0);
                break;
            }
        }

        StringBuilder sb = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            sb.append(nodes[i].output).append("\n");
        }
        System.out.print(sb);
    }

    public static void solve(Node[] nodes, int parent, int id, int depth) {
        StringBuilder sb = new StringBuilder("");
        sb.append("node ").append(id).append(": parent = ").append(parent).append(", depth = ").append(depth).append(", ");

        if (parent == -1) sb.append("root");
        else if (nodes[id].children.length == 0) sb.append("leaf");
        else sb.append("internal node");

        sb.append(", [");
        for (int i = 0; i < nodes[id].children.length; i++) {
            sb.append(nodes[id].children[i]);
            if (i != nodes[id].children.length - 1) sb.append(", ");

            solve(nodes, id, nodes[id].children[i], depth + 1);
        }
        sb.append("]");
        nodes[id].output = sb.toString();
    }
}

class Node {
    public int[] children;
    public String output;
    public Node(int[] children) {
        this.children = children;
    }
}

Measured memory_bytes: 142704
a,b,c,d = map(int, input().split())

if c%b == 0:
    s = c//b
    if a - (s-1)*d > 0:
        print("Yes")
    else:
        print("No")
else:
    s = c//b + 1
    if a - (s-1)*d > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 9108
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace atcoder;
using namespace std;

#define rep(i,s,n) for (int i = s; i < (int)(n); i++)
using ll = long long;
using pll = pair<ll,ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
using vstr = vector<string>;
using mint = modint1000000007;

int a,b,c,x,y,z,h,i,j,k,l,m,n,r;
ll res,sum,ans;

template <class type> void printVector(vector<type> vec){
    stringstream ss;
    ll n=vec.size();
    for(ll i=0;i<n;i++)
    {
        ss<<vec[i]<<" ";
        if(i!=n-1)ss<<" ";
    }
    cout<<ss.str()<<endl;
}

template <class type> void inputVector(vector<type>& vec){
    for(ll i=0;i<vec.size();i++)
    {
        cin>>vec[i];
    }
}
int main(){
    cin>>n>>m;
    dsu d(n);
    rep(i,0,m)
    {
        cin>>a>>b;
        a--;
        b--;
        d.merge(a,b);
    }
    cout<<d.groups().size()-1;
    return 0;
}

Measured memory_bytes: 8940
n = int(input())
a = [int(i) for i in input().split()]

h = sum(a)/2
s = 0
s2 = 0
for i in a:
    s += i
    if s >= h:
        break
a.reverse()
for i in a:
    s2 += i
    if s2 >= h:
        break

s = min([s,s2])
print(2*s-sum(a))


Measured memory_bytes: 26764
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, x, t;
  cin >> n >> x >> t;
  int y = ((n + x - 1) / x);
  cout << y * t << '\n';
  return (0);
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  double ans = a[0];
  for(int i = 1; i < n; i++) {
    ans = (ans + double(a[i]))/2.;
  }
  cout << setprecision(10);
  cout << fixed << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for(int i = (a); i > (b); --i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define endl '\n'
#define mp make_pair
#define pb push_back
#define pf push_front
#define ins insert
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define unmap unordered_map
#define pq priority_queue
#define lb lower_bound //first pos >= val
#define ub upper_bound // first pos > val
#define bp __builtin_popcount
#define debug(a) cout << a << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef pair <ll, ld> pld;
typedef pair <ll, pll> pllp;
typedef pair <pll, ll> ppll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pll> vpll;
typedef vector <pii> vpii;
typedef string BigNum;

const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const ld PI = acos(-1);

//Remember limit for IT, etc..., and +1 in limit of any array
const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;
const ll limit2 = 1e3 + 5;
//If TLE let's use int instead of ll because it's as slow as your WPM :)))

/*----IMPORTANT THINGS----*/
pll dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
/*------------------------*/

string s;

void solveProblem() {
    ll bl = 0, ans = 0;

    for (auto it : s) {
        if (it == 'B') ++bl;
        else ans += bl;
    }

    cout << ans << endl;
}

void fastInput() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void readInput() {
    cin >> s;
}

int main() {
    fastInput();
    readInput();
    solveProblem();
}



Measured memory_bytes: 3732
import java.util.Scanner;

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

    public void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] as = new long[N+1];

        for(int i=1; i<=N; ++i) {
            as[i] = sc.nextLong();
        }

        long[][] dp = new long[N+1][N+1];

        // d_{i,j} i와 j가 서로 같은 경우
        // d_{2,2}는 as_2와 같음
        for(int i=0; i<dp.length; ++i) {
            dp[i][i] = as[i];
        }

        for(int d_ij=1; d_ij<N; ++d_ij) {
            for(int k=1; k<=N; ++k) {
                int i = k;
                int j = i+d_ij;
                if(j<=N) {
//                    System.out.printf("%dx%d ", i, j);
                    dp[i][j] = Math.max(as[i] - dp[i+1][j], as[j] - dp[i][j-1]);
                }
            }
//            System.out.printf("\n");
        }

        System.out.println(dp[1][N]);
    }
}


Measured memory_bytes: 128460
(defun lower-bound (predicate &optional (ok 0) (ng (expt 10 10)))
  (if (<= (abs (- ng ok)) 1)
      ok
      (let ((mid (floor (+ ng ok) 2)))
        (if (funcall predicate mid)
            (lower-bound predicate mid ng)
            (lower-bound predicate ok mid)))))


(defun smaller-p (xs index b-size)
  (< (aref xs index) b-size))


(defun bigger-p (xs index b-size)
  (> (aref xs index) b-size))


(defun solve (a b c &optional (res 0))
  (dotimes (j (length b) res)
    (incf res (* (lower-bound #'(lambda (x)
                                  (smaller-p a x (aref b j)))
                              0
                              (length a))
                 (lower-bound #'(lambda (x)
                                  (bigger-p c x (aref b j)))
                              0
                              (length c))))))


(defparameter *inf* (expt 10 10))

(let* ((n (read))
       (a (make-array (1+ n) :element-type 'fixnum))
       (b (make-array n :element-type 'fixnum))
       (c (make-array (1+ n) :element-type 'fixnum)))
  (setf (aref a (1- (length a))) 0)
  (setf (aref c (1- (length c))) *inf*)
  (dotimes (i n)
    (setf (aref a i) (read)))
  (dotimes (i n)
    (setf (aref b i) (read)))
  (dotimes (i n)
    (setf (aref c i) (read)))
  (sort a #'<)
  (sort c #'>)

  (princ (solve a b c))
  (fresh-line))



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

int main(){
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  
  for(int i = A; i < B+1; i++){
    int s = i%10, t = i/10000 % 10;
    int u = i / 10 % 10, v = i / 1000 % 10;
    if (s == t && u == v) cnt++;
  }
  cout << cnt << endl;
}

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

typedef long long ll;
const ll INF = 1e18;

ll get_num(ll x) {
  ll ret = 0;
  while (x > 0) {
    ret++;
    x /= 10;
  }
  return ret;
}

int main()
{
  ll N;
  scanf("%lld", &N);

  ll ans = INF;
  for (ll A = 1; A * A <= N; A++) {
    if (N % A != 0) continue;

    ll B = N / A;
    ll F = std::max(get_num(A), get_num(B));
    ans = std::min(ans, F);
  }

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


Measured memory_bytes: 256
from networkx import*
H, W = map(int, input().split())
X = [[a for a in input()] for _ in range(H)]
G = Graph()
G.add_nodes_from(range(-2, H + W))
for i in range(H):
    for j in range(W):
        if X[i][j] == "o":
            G.add_edge(i, j + H, capacity = 1)
        elif X[i][j] == "S":
            si, sj = i, j
        elif X[i][j] == "T":
            ti, tj = i, j
        
G.add_edge(-1, si, capacity = 1 << 20)
G.add_edge(-1, sj + H, capacity = 1 << 20)
G.add_edge(-2, ti, capacity = 1 << 20)
G.add_edge(-2, tj + H, capacity = 1 << 20)

mf = maximum_flow(G, -1, -2)[0]
print(-1 if mf > 1 << 19 else mf)

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

int main(){
    double r;
    cin >> r;
    printf("%.10f %.10f\n",
        M_PI * r * r, M_PI * r * 2);
    return 0;
}



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

using namespace std;

void solve() {
    char c;
    cin >> c;
    c++;
    cout << c;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 256