akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

long long ans = 0,pow[51] = {1};
int A[51],B[51],visited[51] = {0};
bool use[51] = {0};
int N;

bool dfs(vector<vector<int>>& v, int n,int x){
	visited[n] = 1;
//	cout << n << " ";
	if(n==x){
		return true;
	}
	bool j = false;
	for(int i=0;i<v[n].size();i++){
		if(visited[v[n][i]]==0) j = (j | dfs(v,v[n][i],x));
	}
	return j;
}

int main(){
	cin >> N;
	for(int i=1;i<=50;i++){
		pow[i] = 2*pow[i-1];
		use[i] = true;
	}
	for(int i=1;i<=2*N;i++){
		if(i<=N) cin >> A[i];
		else cin >> B[i-N];
	}
	bool pos = true;
	for(int i=1;i<=N;i++){
		if((2*B[i]>=A[i] && A[i]!=B[i]) || A[i]<B[i]) pos = false;
	}
	if(!pos){
		cout << -1 << endl;
		return 0;
	}
	vector<vector<int>> v(51);
	for(int num=50;num>=1;num--){
		bool judge = false;
		for(int i=1;i<=N;i++){
			for(int j=0;j<=50;j++){
				v[j].clear();
				visited[j] = 0;
			}
			for(int j=1;j<=A[i];j++){
				for(int k=1;k<=50;k++){
					if(k!=num && use[k]){
						v[j].push_back(j%k);
					}
				}
			}
/*			for(int j=0;j<v[19].size();j++){
				cout << v[19][j] << " ";
			}
			cout << endl;
*/			if(!dfs(v,A[i],B[i])){
				judge = true;
				break;
			}
		}
//		cout << judge << endl;
		use[num] = judge;
	}
	for(int i=1;i<=50;i++){
		if(use[i]) ans += pow[i];
//		cout << ans << endl;
	}
	cout << ans << endl;
}

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


int main(){
  vector<int>A(3);
  int K;
  cin>>A.at(0)>>A.at(1)>>A.at(2)>>K;
  sort(A.begin(),A.end());
  int ans = A.at(0)+A.at(1)+A.at(2)*pow(2,K);

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

string func(char c, int n) {
    string ret;
    for(int i=0; i<n; i++) {
        ret+=c;
    }
    return ret;
}

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    tx -= sx;
    ty -= sy;
    
    string ans;
    ans += func('U', ty);
    ans += func('R', tx+1);
    ans += func('D', ty+1);
    ans += func('L', tx+1);
    ans += func('U', 1);
    ans += func('R', tx);
    ans += func('U', ty+1);
    ans += func('L', tx+1);
    ans += func('D', ty+1);
    ans += func('R', 1);
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    
    int k;
    cin>>k;
    
    int a[n];
    
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    
    for(int i=2;i<n;i++)
    {
        int m=dp[i-1]+abs(a[i-1]-a[i]);
        
        for(int j=i-2;((j>=0)&&(j>=i-k));j--)
        {
            m=min(m,dp[j]+abs(a[j]-a[i]));
        }
       
        dp[i]=m;
    }
    //for(int i=0;i<n;i++)cout<<dp[i]<<" ";
    
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
n,m,k=list(map(int,input().split()))

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

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

A,B=[0],[0]

for i in range(n):
    A.append(A[i] + a[i])

for i in range(m):
    B.append(B[i] + b[i])


ans,j =0,m

for i in range(n+1):
    if A[i] > k:
        break
    while B[j] > k-A[i]:
        j -=1

    ans =max(ans,i+j)

print(ans)


Measured memory_bytes: 47344
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(x) (ll)x.size()
#define lnt(s) (ll)s.length()
#define mt(cnt) cnt.empty()
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> osSet;

using pll = pair<ll, ll>;
using pl = pair<ll, pll>;
using tll = tuple<ll, ll, ll>;

const ll maxN = 1e5;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

ll func(ll x){
	return (x*(x+1))/2;
}

ll _pow(ll b, ll p){
	if(p == 0) return 1;
	if(p == 1) return b;
	ll exB = b*b;
	if(p&1) return b*_pow(exB, p/2);
	return _pow(exB, p/2);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	using plc = pair<ll, char>;
	vector<plc> vtc;
	ll x, y;
	for(ll i=0; i<n; i++){
		cin >> x >> y;
		vtc.emplace_back(mp(x, 'f'));
		vtc.emplace_back(mp(y, 's'));
	}
	sort(begin(vtc), end(vtc), greater<plc>());
	ll ans = 0, i=0;
	while(m > 0){
		if(vtc[i].s == 's'){
			m -= vtc[i].f;
			ans += 1;
		}
		else{
			ans += (m/vtc[i].f + (m%vtc[i].f != 0 ? 1 : 0));
			break;
		}
		i++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 7384
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for b, c in cards:
    for b_len in range(b):
        if a_idx == a_len or a[a_idx] >= c:
            break
        else:
            a[a_idx] = c
            a_idx += 1

print(sum(a))

Measured memory_bytes: 27000
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	s := getNextString(scanner)
	ans := "Sunny"
	if s == "Sunny" {
		ans = "Cloudy"
	}
	if s == "Cloudy" {
		ans = "Rainy"
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

int main(void) {
    int N;
    cin>>N;
    ll H[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    if(N==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    for(int i=N-1;i>=1;i--){
        if(H[i-1]>H[i]) H[i-1]--;
    }
    for(int i=1;i<N;i++){
        if(H[i-1]>H[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    
}

Measured memory_bytes: 1024
aryMondai = gets.split.map(&:to_i);
 
num1 = aryMondai[0];
num2 = aryMondai[1];
 
shou = num1 / num2;
jou = num1 % num2;
 
shouf = num1.to_f / num2.to_f;
 
puts shou.to_s + " " + jou.to_s + " " + "%.5f" % shouf;

Measured memory_bytes: 8736
#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 pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false),cin.tie(0);
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a,b,c,d;
const ll maxn=200005;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;
ll num[100005];
ll n,k,x,y,t;
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;

		b>>=1;
	}
	return res;
}

int main()
{
    //IOS
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(cin>>n)
    {
        cout<<3*n*n<<"\n";
    }



}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
 
int main(){
    string S;
    cin >> S;
    sort(S.begin(),S.end());
  	
  	if(S[1]==S[2]){
    	cout << "No";
      return 0;
    }	
  
    if(S[0]==S[1]){
    	if(S[2]==S[3]){
        	cout << "Yes";
          return 0;
        }
          
    }
  
  cout << "No";
 
}

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

#ifndef __SOULTCH
#define endl '\n'
#define debug(...) 
#else
#define __debug_a(v) cout << " [+] " << #v << " = " << (v) << endl
#define __debug_b(v) cout << "     " << #v << " = " << (v) << endl
#define debug1(v1) __debug_a(v1);
#define debug2(v1, v2) __debug_a(v1), __debug_b(v2);
#define debug3(v1, v2, v3) __debug_a(v1), __debug_b(v2), __debug_b(v3);
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define debug(...) GET_MACRO(__VA_ARGS__, debug3, debug2, debug1)(__VA_ARGS__)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << pai.first << ' ' << pai.second;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

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

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> s) {
    for (auto p : s) cout << '(' << p << ") ";
    return os;
}

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

int X, Y, Z, K;
ll A[1000], B[1000], C[1000];

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

    cin >> X >> Y >> Z >> K;
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];

    sort(A, A+X);
    sort(B, B+Y);
    sort(C, C+Z);

    ll l = 0, r = A[X-1]+B[Y-1]+C[Z-1];
    while(l < r) {
        ll mid = (l+r+1)/2;
        ll cnt = 0;
        rep(i, X) rep(j, Y) {
            cnt += C+Z-lower_bound(C, C+Z, mid-A[i]-B[j]);
        }
        debug(mid, cnt);
        if (cnt < K) r = mid-1;
        else l = mid;
    }

    debug(l);

    vector<ll> res;
    rep(i, X) rep(j, Y) {
        for(auto p = lower_bound(C, C+Z, l-A[i]-B[j]); p != C+Z; p++) {
            res.pb(A[i]+B[j]+*p);
        }
    }

    sort(res.begin(), res.end(), greater<ll>());
    rep(i, K) cout << res[i] << endl;
}








Measured memory_bytes: 133340
import math

A, B, H, M = [int(i) for i in input().split()]

# 中央角を計算
minutes = (H * 60) + M
short_hand_angle = 0.5 * minutes
long_hand_angle = 6 * M

diff_angle = abs(short_hand_angle - long_hand_angle)
if diff_angle > 180 :
    diff_angle = 360 - diff_angle
    
# 余弦定理
if diff_angle == 90:
    c = A**2 + B**2
    c = math.sqrt(c)
elif diff_angle == 180:
    c = A + B
else :
    c = A**2 + B**2 - 2*A*B*math.cos(math.radians(diff_angle))
    c = math.sqrt(c)

print(c)

Measured memory_bytes: 9516
#include <iostream>
#include <math.h>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;
#define n_max 1000

int main()
{
    string str;
    string ans = "";
    
    cin >> str;
    
    for(int i = 0; i < str.size(); i++) {
        if((i % 2) == 0) {
            ans += str[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll n;
    while(cin>>n){
        if(n==0){break;}
    if(n==2){
        ll p,d,p2,d2;
        cin>>p>>d>>p2>>d2;
        cout<<abs(p2-p)<<endl;
        continue;
    }
    vector<pll> A;
    vector<pll> B;
    for(int i=0;i<n;i++){
        ll p,d;
        cin>>p>>d;
        if(d>1){A.push_back({p,d});}
        else{B.push_back({p,d});}
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    vector<ll> dp(B.size()+1,E);
    dp[0]=0;
    ll ans=0;
    for(int i=1;i<A.size();i++){ans+=A[i].F-A[i-1].F;}
    if(A.size()>=2){
        for(int i=1;i+1<A.size();i++){A[i].S-=2;}
        A[0].S-=1;
        A.back().S-=1;
    }
        if(B.size()==0){cout<<ans<<endl; continue;}
    for(int i=0;i<A.size();i++){
        if(A[i].S==0){continue;}
        priority_queue<pll,vector<pll>,greater<pll>> Q;
        Q.push({dp[0],0});
        ll k=abs(A[i].F-B[0].F);
        for(int t=1;t<=B.size();t++){
            while(t-Q.top().S>A[i].S){Q.pop();}
            ll l=dp[t];
            dp[t]=min(dp[t],Q.top().F+k);
            if(t==B.size()){break;}
            Q.push({l-k,t});
            k+=abs(A[i].F-B[t].F);
        }
    }
        if(dp.back()>=E){cout<<-1<<endl; continue;}
    cout<<dp.back()+ans<<endl;
    }
    
    return 0;
}



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

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    double a = min(y*w, (h-y)*w);
    double b = min(x*h, (w-x)*h);
    cout << h*w/2.0 << endl;
    if(x == w/2.0 && y == h/2.0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 100005
int n,k,ans=0;
char s[N];
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int L=strlen(s);
    for(int i=1;i<L;i++)
        if(s[i]==s[i-1]) ans++;
    ans=min(ans+(k<<1),n-1);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0031
{
	class Program
	{
		static void Main(string[] args)
		{
			while( true ) {
				var	s	= Console.ReadLine();
				if( s == null ) {
					break;
				}

				int	w	= int.Parse( s );
				int	b	= 0x01;
				bool	first	= true;
				while( b < 1024 ) {
					if( (w & b) != 0 ) {
						if( first ) {
							Console.Write( b );
							first	= false;
						} else {
							Console.Write( " " + b );
						}
					}
					b <<= 1;
				}
				Console.WriteLine();
			}
		}
	}
}

Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

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

    int count = 0;

    rep(i,N-2) {
        if (S.substr(i,3) == "ABC") count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
line_1 = input().split()
line_2 = input().split()
line_1 = list(map(lambda x: int(x), line_1))
line_2 = list(map(lambda x: int(x), line_2))

n = line_1[0]
m = line_1[1]

if (n < m):
  print(-1)
else:
  a = sum(line_2)
  r = n - a
  
  if (r < 0):
    print(-1)
  else:
    print(r)

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


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

    string S;
    cin >> S;
    char moji;
    string ans="None";
    for(moji='a';moji<='z';moji++){
        bool z=true;
        rep(i,S.size()){
            if(moji==S[i]){
                z=false;
                break;
            }
        }
        if(z) {
            ans=moji;
            break;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >> k;

  int cnt = 0;
  int n = min(a,b);
  for(int i=n;i>0;i--){
    if(a%i==0 && b%i==0){
      cnt++;
    }
    if(cnt == k){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
int like[100100];
bool isprime(int n){
	if(n==1)return false;

	for(int i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return true;
}
signed main(){
	// vi like(100100,0);
	for(int i=1;i<=100000;i+=2){
		if(isprime(i)&&isprime((i+1)/2)) like[i]=1;
	}
	rep(i,100010){
		like[i+1]+=like[i];
	}
	
	int q;
	cin>>q;
	rep(i,q){
		int l,r;
		cin>>l>>r;
		cout<<like[r]-like[l-1]<<endl;
	}

	return 0;
}


Measured memory_bytes: 4336
#include <iostream>
using namespace std;
  int a,b,n,tx,ty;
  int stp[16][16];

int check(int x,int y){
  int ret=0;
  if (x==a-1&&y==b-1) return 1;
  if (!stp[x+1][y]&&x+1<a) ret += check(x+1,y);
  if (!stp[x][y+1]&&y+1<b) ret += check(x,y+1);
  return ret;
}

int main(){
  while (1){
    cin >> a >> b;
    if (a==0&&b==0) break;
    cin >> n;

    for (int i=0;i<16;i++)
      for (int j=0;j<16;j++)
	stp[i][j]=0;

    for (int i=0;i<n;i++){
      cin >> tx >> ty;
      stp[tx-1][ty-1]=1;
    }
    cout << check(0,0) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  string sa,sb,sc;cin>>sa>>sb>>sc;
  char t='a';
  int i=0,j=0,k=0;
  string ans;
  while(1){
    if(t=='a'){
      if(i==sa.size()){ans='A';break;}
      t=sa[i];
      i++;
    }
    else if(t=='b'){
      if(j==sb.size()){ans='B';break;}
      t=sb[j];
      j++;
    }
    else{
      if(k==sc.size()){ans='C';break;}      
      t=sc[k];
      k++;
    }
  }
  cout<<ans;
}

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

bool comp_2nd(const pair<long long, long long>& a, const pair<long long, long long>& b){
    return a.second > b.second;
}

int main(int argc, const char * argv[]) {
    
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long long n;
    cin >> n;
    
    vector<pair<long long, long long>> v(n);
    vector<long long> ind(n);
    
    for(long long i=0; i<n; i++){
        long long x, y;
        cin >> x >> y;
        v[i] = make_pair(x, y);
        ind[i] = x;
    }
    
    sort(v.begin(), v.end(), comp_2nd);
    
    
    long long time_rem = v[0].second;
    
    for(long long i=0; i<n; i++){
        if(time_rem < v[i].second){
            time_rem -= v[i].first;
        }else{
            time_rem = v[i].second - v[i].first;
        }
    }
    
    
    if(time_rem >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
#define vi vector<int>
#define vb vector<bool>
#define lli long long int
#define vvi vector<vector<int>>
#define loop(n) for (int i = 0; i < n; i++)
using namespace std;

auto SpeedUp = []() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // std::ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    // cout.tie(nullptr);
    return 0;
}();

void solve()
{
    int n;
    cin >> n;
    vector<double> arr(n, 0);
    loop(n) cin >> arr[i];
    vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0)); // dp[i][j] will store the probability of getting j heads with i coins;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (j == 0)
                dp[i][j] = (1 - arr[i - 1]) * dp[i - 1][j];
            else
                dp[i][j] = arr[i - 1] * dp[i - 1][j - 1] + (1 - arr[i - 1]) * dp[i - 1][j];
        }
    }

    double ans = 0;
    for (int i = (n / 2 + 1); i <= n; i++)
        ans += dp[n][i];

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

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 73788
#include <iostream>
#include <vector>

int main(){
    int d;
    std::cin >> d;
    std::vector<int> c(26);
    for(int i = 0; i < 26; i++){
        std::cin >> c[i];
    }
    std::vector<std::vector<int>> s(d, std::vector<int>(26));
    for(int j = 0; j < d; j++){
        for(int i = 0; i < 26; i++){
            std::cin >> s[j][i];
        }
    }
    std::vector<int> t(d);
    for(int j = 0; j < d; j++){
        t[j] = j % 26 + 1;
    }

    // int m;
    // std::cin >> m;
    // std::vector<int> d_c(m);
    // std::vector<int> q(m);
    // for(int k = 0; k < m; k++){
    //     std::cin >> d_c[k];
    //     std::cin >> q[k];
    // }

    std::vector<int> l(26);
    for(int i = 0; i < 26; i++){
        l[i] = 0;
    }

    // int old = 0;

    int v;
    // for(int k = 0; k < m; k++){
        v = 0;
        for(int i = 0; i < 26; i++){
            l[i] = 0;
        }
        // old = t[d_c[k] - 1];
        // t[d_c[k] - 1] = q[k];

        for(int j = 0; j < d; j++){
            for(int i = 0; i < 26; i++){
                if(i == t[j] - 1){
                    v = v + s[j][i];
                    l[i] = j + 1;
                }
                else{
                    v = v - c[i]*(j + 1 - l[i]);
                }
            }
        }
        // std::cout << v << std::endl;
        // t[d_c[k] - 1] = old;
    // }
    for(int j = 0; j < d; j++){
        std::cout << t[j] << std::endl;
    }
}

Measured memory_bytes: 3672
from collections import deque

N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

a = deque(A)

arrival = 1
ans = 0

while arrival < N:
    score = a.popleft()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score*min(2, N - arrival)
        arrival += 2

print(ans)

Measured memory_bytes: 33240
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
S = input()

ans = 0
for i in range(1000):
    V = str(i).zfill(3)
    p1 = S.find(V[0])
    if p1 != -1:
        p2 = S.find(V[1], p1+1)
        if p2 != -1:
            p3 = S.find(V[2], p2+1)
            if p3 != -1:
                ans += 1

print(ans)




Measured memory_bytes: 9272
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x,ll y){
    if(y==0){
        return x;
    }else{
        return GCD(y, x % y);
    }
}
ll LCM(ll x,ll y){
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main()
{
    string s;
    cin >> s;
    int k = s.size() - 1;
    while(1){
     //   cout << k << endl;
        bool h = true;
        if(s[k]=='r'){
            
            if (s.substr(k - 5, 5) == "erase")
            {
                k -= 6;
                h = false;
            }
            else if (s.substr(k - 6, 6) == "dreame"){
                k -= 7;
                h = false;
            }
            if(k<0){
                break;
            }
        }else if(s[k]=='m'){
            if(s.substr(k-4,4)=="drea"){
                k -= 5;
                h = false;
            }
        }else if(s[k]=='e'){
            if (s.substr(k - 4, 4) == "eras")
            {
                k -= 5;
                h = false;
            }
        }
        if(h){
            cout << "NO" << endl;
            return 0;
        }
        if(k==-1){
            break;
        }
        if(k<-1){
            cout<<"NO"<<endl;
            return 0;
        }
        if(k>=0&&k<=3){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111

#define TASK "1"

using namespace std;

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	int n, A, B;
	cin >> n >> A >> B;
	string s;
	cin >> s;
	int all = 0;
	int b = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'c') {
			cout << "No\n";
			continue;
		}
		if (s[i] == 'a') {
			if (all < A + B) {
				all++;
				cout << "Yes\n";
			} else {
				cout << "No\n";
			}
			continue;
		}
		b++;
		if (all < A + B && b <= B) {
				all++;
				cout << "Yes\n";
		} else {
				cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 848
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,a[200010];
bool check(int mid){
//	cout<<"check "<<mid<<'\n';
	int i;
	//其实好像不用特判全部交错的情况，只要扫完全都没有连续，就是交错图了 
	//因为是奇数所以最左边的会上位 
	//话说如果两边一个是连续0一个是连续1怎么办呢
	//（上面那行划掉）
	//因为是中间开始的奇数计数，所以本来就不会有相同的两边同时开始的连续01段吧 
	//大概是对的吧...... 
	for(i=0;i<n;i++){
//		if(((a[n-i]>=mid&&a[n-i-1]>=mid)&&(a[n+i]<mid&&a[n+i+1]<mid))||((a[n+i]>=mid&&a[n+i+1]>=mid)&&(a[n-i]<mid&&a[n-i-1]<mid)))
		if((a[n-i]>=mid&&a[n-i-1]>=mid)||(a[n+i]>=mid&&a[n+i+1]>=mid)) return 1;
		if((a[n-i]<mid&&a[n-i-1]<mid)||(a[n+i]<mid&&a[n+i+1]<mid)) return 0;
	}
	if(a[1]>=mid) return 1;
	else return 0;
}
int main(){
//	freopen("in.in","r",stdin);
	n=read();int i,l,r,mid;
	for(i=1;i<(n<<1);i++) a[i]=read();
	l=1;r=(n<<1)-1;
	while(l<r){
		mid=(l+r)>>1;mid++;
		if(check(mid)) l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 1024
while True:
    table = input().split()

    a = int(table[0])
    op = table[1]
    b = int(table[2])

    if op == '?':
        break

    if op == '+':
        print("%d"%(a+b))
    elif op == '-':
        print("%d"%(a-b))
    elif op == '/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))



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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef map<int, int> mint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b){ll ans=1; rep(i, b){ans=ans*a%MOD;} return ans;}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}

ll divisible(ll a, ll b){
    return a>=0 ? a/b+1 : 0 ;
}


int main(){

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

    ll a, b, x;
    cin >> a >> b >> x;

    ll ans = divisible(b,x) - divisible(a-1,x);


    ppp(ans);





    return 0;
}


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

int main(void) {
	int a, b;
	cin >> a >> b;

	if(a > b) {
		cout << "a > b" << endl;
	} else if(a < b) {
		cout << "a < b" << endl;
	} else {
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(q, l, r) for (int q = l; q <= r; q++)
#define mid (l + r) / 2
#define pl (i << 1)
#define pr (i << 1 | 1)
#define pb push_back
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pi;
const int maxn = 100;
const int INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll LINF = 1e14;

int main()
{
    int x;
    cin>>x;
    x=x*x*x;

    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//#define MAX 100
ll INF = 1e18 + 5;
int main()
{
	ios::sync_with_stdio(0),cin.tie(0);
	ll n,w;
	cin>>n>>w;
	vector<ll> val(n*1000+1,INF);
	val[0] = 0;
	for(ll i =0;i<n;i++)
	{
		ll weight,value;
		cin>>weight>>value;
		for(ll value_already = (n*1000+1) - value;value_already>=0;value_already--)
		{
			val[value_already+value] = min(val[value_already+value],val[value_already]+weight);
		}
	}
	//sort(val.begin(),val.end());
	ll prev =0;
	for(ll i=0;i<val.size();i++)
	{
		if(val[i] <= w )
		{	
			prev = max(prev,i);
		}
	}
	cout<<prev<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll A, B; cin>>A>>B;
    cout << 6-A-B << endl;
    return 0;
}

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

// 全体として黒色、白色の石の数は変わらない。
// スワップするごとに黒色の石は右に、白色の石は左に移動する。
// 黒色の石としては、右に白色の石が連続しているとそれだけ右に移動できるので、その方が望ましい。
// 最終的に、すべての黒石を右に寄せるまでの操作回数を求める。
// 一番右の黒石から右に寄せていく。

int main() {
    string S;
    cin >> S;
    vector<int> Black;
    for(size_t i = 0; i < S.size(); ++i) {
        if(S[i] == 'B') Black.push_back(i);
    }
    reverse(Black.begin(),Black.end());
    long long res = 0LL;
    for(int i = 0; i < Black.size(); ++i) {
        res += (long long)(S.size()-1 - Black[i] - i);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1532
// Cease to struggle and you cease to live
// C.cpp
// Created by Nickwzk on 2019-02-16 20:23
#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, ch = getchar(); bool fg = 1;
	while(ch < '0' || ch > '9') { if(ch == '-') fg = 0; ch = getchar(); } 
	while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return fg ? x : -x;
}
int main() {
	int n = read();
	int ans = read();
	for(int i = 2; i <= n; i++) {
		ans = __gcd(ans, read());
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) cout << "Yes" << '\n';
  else cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		int minPercent10 = b * 10;
		int maxPercent10 = b * 10 + 9;

		int answer = -1;
		for (int i = minPercent10; i <= maxPercent10; i++) {
			if ((int)(0.08 * i) == a) {
				answer = i;
				break;
			}
		}

		System.out.println(answer);

	}
}

Measured memory_bytes: 24148
#include <iostream>

using namespace std;

int main()
{
    int h,n;
    cin>>h>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        h-=arr[i];
    }
    if(h<=0)
        cout<<"Yes";
    else
        cout<<"No";



}



Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _Ty> static _Ty tp_abs(const _Ty& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _Ty> static _Ty tp_min(_Ty a, _Ty b) {
	return a < b ? a : b;
}
template <class _Ty> static _Ty tp_max(_Ty a, _Ty b) {
	return a > b ? a : b;
}
template<class T> static void getint(T& a) {
	const char* fmt = " %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class T> static void getint(T& a, T& b) {
	const char* fmt = " %d %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class T> static void getint(T& a, T& b, T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static const int EduDp_INF = 1100000000;
static const int MOD_NUM = 1000000007;
static void S_task();

#if 1
int main()
{
	S_task();
	fflush(stdout);
	return 0;
}
#endif

static void S_task()
{
	std::string orgs;
	std::cin >> orgs;

	int D;
	getint(D);

	int digitCount = orgs.length();
	std::vector<std::vector<std::vector<LLONG>>> dp(digitCount + 1, std::vector<std::vector<LLONG>>(2, std::vector<LLONG>(D, 0)));
	dp[0][0][0] = 1;
	for (int digit = 1; digit <= digitCount; digit++) {
		int digitNum = orgs[digit - 1] - '0';

		for (int sml = 0; sml < 2; sml++) {
			int limit = (sml ? 9 : digitNum);

			for (int d = 0; d < D; d++) {
				for (int k = 0; k <= limit; k++) {
					int nowSurp = (d + k) % D;
					dp[digit][sml || k < digitNum][nowSurp] += dp[digit - 1][sml][d] % (LLONG)MOD_NUM;
					dp[digit][sml || k < digitNum][nowSurp] %= (LLONG)MOD_NUM;
				}
			}
		}
	}
	LLONG ans = (dp[digitCount][0][0] + dp[digitCount][1][0] - 1LL) % (LLONG)MOD_NUM;
	if (ans < 0) ans += (LLONG)MOD_NUM;

	printf("%lld\n", ans);
}


Measured memory_bytes: 17024
#include<cstdio>
char s[15];

int main(){
    int n;
    scanf("%d",&n);
    int cnt0 = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 1; i <= n; i++){
        scanf("%s",s);
        if(s[0]=='A') cnt0++;
        else if(s[0]=='W') cnt1++;
        else if(s[0]=='T') cnt2++;
        else cnt3++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",cnt0,cnt1,cnt2,cnt3);
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i,n){
        cin >> p[i];
        p[i]--;
    }
    int dis = 1e9 / n;
    int cnt = 0;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
    {
        int c = p[i];
        a[c] = dis * c + 1 + cnt;
        b[c] = dis * (n - 1 - c) +1+ cnt;
        cnt++;
        //cerr << a[c] + b[c] << endl;
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < n; i++)
    {
        cout << b[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1152
N = int(input())
S = input()
S = list(map(lambda x: 0 if x=="." else 1, S))
#all_white
# all_white = sum(S)
# all_black = len(S) - all_white

# white, black, white
ans_list = []
for thresh in range(len(S)):        
    if thresh == 0:
        ans = len(S) - sum(S)
        ans_list.append(ans)
    
    else:
        ans = ans_list[-1]
        if S[thresh-1] == 1: 
            ans += 1
        else:
            ans -= 1
        ans_list.append(ans)
ans_list.append(sum(S))
        
print(min(ans_list))

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

#define scd second
#define fst first
#define mkp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef vector<bool> vbool;

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

	int n;
	cin>>n;
	vector<int> arr(n);
	for(auto &x : arr) cin>>x;
	unordered_map<int,int> cnt;
	ll ans=0;
	for(int i=n-1; i>=0; i--){
		auto itr=cnt.find(arr[i]+i+1);
		if(itr!=cnt.end()){
			ans+=itr->second;
		}
		cnt[i+1-arr[i]]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11940
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	bool n = false, w = false, S = false, e = false;
	string s;
	cin >> s;
	rep(i,s.size()){
		if(s[i] == 'N') n = true;
		if(s[i] == 'W') w = true;
		if(s[i] == 'S') S = true;
		if(s[i] == 'E') e = true;
	}
	if(n^S || w^e) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

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

    int64_t X; 
    cin >> X; 
    if (X >= 30) {
        cout << "Yes"; 
    } else {
        cout << "No"; 
    }
  return 0;
}


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

int main(){
    int n; cin>>n;
    int M=0;
    int ans=0;
    for(int i=0; i<n; i++){
        int p; cin>>p;
        M = max(p,M);
        ans += p;
    }
    cout << ans-M/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;
const ll INF=1LL<<30;
vector<int> G[MAX];
int score[MAX];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> PQ;

int main(){
    
    int N;cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int K;cin>>K;
    
    for(int i=0;i<K;i++){
        int v,p;cin>>v>>p;
        v--;
        score[v]=p+1;
        PQ.push({p+1,v});
    }
    
    bool ok=true;
    
    while(!PQ.empty()){
        pair<int,int> p=PQ.top();PQ.pop();
        int a=p.first,b=p.second;
        for(int to:G[b]){
            if(score[to]){
                if(score[to]+1==a||score[to]-1==a) continue;
                else ok=false;
            }else{
                score[to]=a+1;
                PQ.push({a+1,to});
            }
        }
    }
    
    if(ok){
        cout<<"Yes"<<endl;
        for(int i=0;i<N;i++){
            cout<<score[i]-1<<"\n";
        }
    }else cout<<"No"<<endl;
}





Measured memory_bytes: 7924
N = int(input())

xy = []
xyvec = {}

for i in range(N):
  x, y = map(int, input().split())
  for _x, _y in xy:
    if (x - _x, y - _y) in xyvec:
      xyvec[(x - _x, y - _y)].append(((_x, _y), (x, y)))
      xyvec[(_x - x, _y - y)].append(((x, y), (_x, _y)))
    else :
      xyvec[(x - _x, y - _y)] = [((_x, _y), (x, y))]
      xyvec[(_x - x, _y - y)] = [((x, y), (_x, _y))]

  xy.append((x, y))

result = N
for key in xyvec:
  temp_result = N - len(xyvec[key])
  if result > temp_result :
    result = temp_result

print(result)

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+20;
int n,a[N],b[N],Max,ans;
long long c[N*2];
inline int lowbit(int x) { return x & (-x); }
inline void insert(int p,long long v) { p += n+1; for (;p<=2*n+1;p+=lowbit(p)) c[p] += v; }
inline long long query(int p) { p += n+1; long long res = 0; for (;p;p-=lowbit(p)) res += c[p]; return res; }
inline void input(void)
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]) , Max = max( Max , a[i] );
}
inline long long check(int val)
{
    long long res = 0;
    for (int i=1;i<=n;i++)
        b[i] = a[i] <= val ? 1 : -1;
    for (int i=1;i<=n;i++)
        b[i] += b[i-1];
    memset( c , 0 , sizeof c );
    for (int i=0;i<=n;i++)
    {
        res += query( b[i] - 1 );
        insert( b[i] , 1 );
    }
    return res;
}
inline void BinarySearch(void)
{
    int l = 0 , r = Max , mid;
    while ( l + 1 < r )
    {
        mid = l + r >> 1;
        if ( check(mid) >= 1LL*n*(n+2)/2/2 + 1 ) r = mid;
        else l = mid;
    }
    check(l) == 1LL*n*(n+1)/2/2 + 1 ? ans = l : ans = r;
}
int main(void)
{
    input();
    BinarySearch();
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll A, B, N;

int main()
{
    cin >> A >> B >> N;
    ll x = min(N, B - 1);
    ll l = (A * x) / B;
    ll rb = (x / B);
    cout << l - A * rb;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define INF_LL 1LL << 40;
#define INF 1 << 31;
#define MOD 1000000007;
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vector<int>> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
struct edge {
    int to, cost;
};

int main() {
    int n, tmp;
    cin >> n;
    vl a(n + 2);
    set<ll> s = {-1, n};
    rep(i, n) {
        cin >> tmp;
        a[tmp - 1] = i;
    }
    ll ans = 0;
    rep(i, n) {
        auto it = s.lower_bound(a[i]);
        ans += (*it - a[i]) * (a[i] - *--it) * (i + 1);
        s.emplace(a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 11136