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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, x; cin >> N >> x;
    vector<int> ans(2*N - 1);
    
    if (x == 1 or x == 2*N - 1) {
        cout << "No" << endl;
    } else if (x < 2*N - 2) {
        cout << "Yes" << endl;
        ans[N - 2] = 2*N - 1;
        ans[N - 1] = x;
        ans[N] = 1;
        ans[N + 1] = x + 1;

        int pos = 0;
        for (int i = 1; i <= 2*N - 1; i++) {
            if (i != 2*N - 1 and i != x and i != 1 and i != x + 1) {
                while (ans[pos] > 0) pos++;
                ans[pos] = i;
            }
        }

        for (int i = 0; i < 2*N - 1; i++) {
            cout << ans[i] << endl;
        }
    } else {
        cout << "Yes" << endl;
        ans[N - 2] = 1;
        ans[N - 1] = x;
        ans[N] = 2*N - 1;
        ans[N + 1] = 2;

        int pos = 0;
        for (int i = 1; i <= 2*N - 1; i++) {
            if (i != 1 and i != x and i != 2*N - 1 and i != 2) {
                while (ans[pos] > 0) pos++;
                ans[pos] = i;
            }
        }

        for (int i = 0; i < 2*N - 1; i++) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}

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

int row,col;
char s[20][20],c[22];
string f[20];
bool g_row[20][20],g_col[20][20];
int a[20];

bool dfs_col(int j,int mask)
{
	if(j==-1){return true;}
	int u=col-j-1;
	if(u==j){
		for(int k=0;k<col;k++){
			if(dfs_col(j-1,mask|(1<<k))) return true;
		}
	}
	else{
		int cnt=0;
		while(mask&(1<<cnt)) cnt++;
		mask|=1<<cnt;
		for(int k=0;k<col;k++) if((mask&(1<<k))==0&&g_col[cnt][k]){
			if(dfs_col(j-1,mask|(1<<k))) return true;
		}
	}
	return false;
}

bool dfs_row(int i,int mask)
{
    //cout<<i<<endl;
	if(i==-1){
		for(int k1=0;k1<col;k1++){
			for(int k2=0;k2<col;k2++){
				bool f=true;
				for(int k=0;k<row;k++){
					if(s[a[k]][k1]!=s[a[row-k-1]][k2]){
						f=false;
						break;
					}
				} 
				g_col[k1][k2]=f;
			}
		}
		return dfs_col((col-1)/2,0);
	}
	int u=row-i-1;
	if(u==i){
		for(int k=0;k<row;k++){
			a[i]=k;
			if(dfs_row(i-1,mask|(1<<k))) return true;
		}
	}
	else{
		int cnt=0;
		while(mask&(1<<cnt)) cnt++;
		a[i]=cnt;
		mask|=1<<cnt;
		for(int k=0;k<row;k++){
			if((mask&(1<<k))==0&&g_row[cnt][k]){
				a[u]=k;
				if(dfs_row(i-1,mask|(1<<k))) return true;
			}
		}
	}
	return false;
}

int main()
{
	cin>>row>>col;
	for(int i=0;i<row;i++) cin>>s[i];
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			c[j]=s[i][j];
		}
		sort(c,c+col);
		for(int j=0;j<col;j++) f[i]+=c[j];
	}
	for(int i=0;i<row;i++) for(int j=0;j<row;j++) g_row[i][j]=(f[i]==f[j]);
	printf(dfs_row((row-1)/2,0)?"YES":"NO");
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }



void solve(){
    int q; cin >> q;
    map<ll,ll> mp;
    ll allnum = 0;
    while(q--){
        int com; cin >> com;
        if(com == 0){
            int x; cin >> x;
            mp[x]++;
            allnum++;
            cout << allnum << endl;
        }
        if(com == 1){
            int x; cin >> x;
            cout << mp[x] << endl;
        }
        if(com == 2){
            int x; cin >> x;
            allnum -= mp[x];
            mp[x] = 0;
        }
        if(com == 3){
            ll L,R; cin >> L >> R;
            for(auto it = mp.lower_bound(L); it != mp.end() ; it++){
                if(it->first > R) break;
                for(int j = 0; j < it->second;j++){
                    cout << it->first << endl;
                }
            }
        }
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 14428
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n;
    cin>>n;
    map<ll,ll>mp;
    loop(n,i,0){
        ll x;
        cin>>x;
        mp[x]++;
    }
    vll v;
    for(auto x:mp){
        if(x.s>=2)
            v.pb(x.f);
    }
    sort(allv(v));
    if(!sz(v))
        cout<<0<<endl;
    else if(mp[v.back()]>=4)
        cout<<v.back()*v.back()<<endl;
    else if(sz(v)>=2)
        cout<<v.back()*v[sz(v)-2]<<endl;
    else
        cout<<0<<endl;

}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 9708
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int ans = 0;
    for (int i = 0; i < n; i++){
        for (int k = 0; k < n; k++){
            ans = max(ans, abs(a[i] - a[k]));
        }
    }
    cout <<  ans << endl;

    return 0;
}








Measured memory_bytes: 256
'''N, K = map(int, input().split())
H = list(map(int, input().split()))

for i in range(K):
    if len(H)!=0:
        H.remove(max(H))
        #print(H)
    else:
        #print(0)
        break
print(sum(H))'''

N, K = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)

print(sum(H[K:]))


Measured memory_bytes: 26024
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  x <- getInt

  let ans | x >= 1800 = 1
          | x >= 1600 = 2
          | x >= 1400 = 3
          | x >= 1200 = 4
          | x >= 1000 = 5
          | x >= 800  = 6
          | x >= 600  = 7
          | otherwise = 8

  print ans


Measured memory_bytes: 3768
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    x,y = inputMap()
    
    UF = UnionFind(13)
    
    UF.union(1,3)
    UF.union(1,5)
    UF.union(1,7)
    UF.union(1,8)
    UF.union(1,10)
    UF.union(1,12)
    
    UF.union(4,6)
    UF.union(4,9)
    UF.union(4,11)
    
    tmp = UF.is_same(x,y)
    if tmp == True:
        print("Yes")
    else:
        print("No")
    
    
class UnionFind(object):
	def __init__(self, n=1):
		self.par = [i for i in range(n)]
		self.rank = [0 for _ in range(n)]
		self.size = [1 for _ in range(n)]
		
	# x が属するグループを探索
	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]
		
	# x と y のグループを結合
	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x != y:
			# メンバ数の更新
			sum = self.size[x] + self.size[y]
			self.size[x] = sum
			self.size[y] = sum
			# 短いリストを長いリストのルートに繋ぎ直す
			if self.rank[x] < self.rank[y]:
				x, y = y, x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1
			self.par[y] = x
	
	# x と y が同じグループがどうか
	def is_same(self, x, y):
		return self.find(x) == self.find(y)
		
	# x が属するグループのメンバ数を返却
	def getSize(self, x):
		par_x = self.find(x)
		return self.size[par_x]
	
if __name__ == "__main__":
	main()


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

const int mod = 1000000007;

int dp[2010][2010];
int s[2010], t[2010];
int sum[2010][2010];

int main(){
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++){
		scanf("%d", &s[i]);
	}
	for (int i = 1; i <= m; i++){
		scanf("%d", &t[i]);
	}
	sum[0][0] = 1;
	for (int i = 1; i <= n; i++){
		sum[i][0] = sum[i - 1][0];
	}
	for (int j = 1; j <= m; j++){
		sum[0][j] = sum[0][j - 1];
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			sum[i][j] = (1ll * sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mod) % mod;
			dp[i][j] = s[i] == t[j] ? sum[i - 1][j - 1] : 0;
			sum[i][j] = (sum[i][j] + dp[i][j]) % mod;
			ans = (ans + dp[i][j]) % mod;
		}
	}
	printf("%d\n", (ans + 1) % mod);
	return 0;
}


Measured memory_bytes: 31744
from itertools import accumulate
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
prime_set = set(get_sieve_of_eratosthenes(10**5+1))
like_2017_list =  [0 for _ in range(10**5+1)]
like_2017_set = set()
for n in range(1, 10**5, 2):
    if n in prime_set and (n+1)//2 in prime_set:
        like_2017_list[n] = 1
        like_2017_set.add(n)
like_2017_list = list(accumulate(like_2017_list))
# print(like_2017_list[:14])
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(like_2017_list[r]-like_2017_list[l-1])

Measured memory_bytes: 54108
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main()
{
    int n;
    
    while (true) {
        cin >> n;
        if (!n) {
            break;
        }
        vector<vector<int> > v(n + 1, vector<int>(n + 1, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[i][n] += v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[n][i] += v[j][i];
            }
            v[n][n] += v[n][i];
        }
        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                cout << setw(5) << v[i][j];
            }
            cout << '\n';
        }
    }
}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n,r;
	cin>>n>>r;
	if(n>=10){
		cout<<r<<endl;
	}else{
		cout<<100*(10-n)+r<<endl;
	}
}


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

int main() {
  int64_t A,B,K;
  
  cin >> A >> B >> K;
  
  if(A >= K){
  	A = A - K;
  }else if(A + B >= K){
  	B += A - K;
    A = 0; 
  }else{
  	A = 0;
    B = 0;
  }
  
  cout << A << " " << B << endl;
  
  return 0;
}


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

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

  int sum = 0;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;

    if (x < K-x){
      sum = sum + 2 * x;
    } else{
      sum = sum + 2 * (K-x);
    }
  }
  cout << sum << endl; 
}


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

int sum(vector<int> A,int N){
    int res = 0;
    rep(i,N) res += A[i];
    return res;
}

template <typename T>
int minimum(vector<T> A){
    int m = 100000;
    for (T a : A) if (a < m) m = a;
    return m;
    }




int main(){
    int N,X;
    cin >> N >> X;
    int ans = 0;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    ans += N;
    X -= sum(A,N);
    int min_A = minimum(A);
    ans += X / min_A;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]

AB.sort(key=lambda x:x[1])

NOW=0
for x,y in AB:
    NOW+=x
    if NOW>y:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 84444
#include<stdio.h>

int main(){
	
    int a,b;
    char op;
    
    for(int i=0 ; ; i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+'){
            printf("%d\n",a+b);
        }
        else if(op=='-'){
            printf("%d\n",a-b);
        }
        else if(op=='*'){
            printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }
        else{
            break;
        }
    }
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 2028
//********************************************************************//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fi first 
#define se second 
#define RANGE(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DFOR(i, a, b) for(int i = a; i > b; --i)
#define DEB(x) cout << #x << ": " << x << endl
#define ALL(v) v.begin(), v.end() 
#define SORT(v) sort(ALL(v))
#define DISPV(v) { for(auto x___: v) cout << x___ << " "; cout << endl; }
#define DISPM(m) { for(auto x____: m){ cout << x____.first << ": " << x____.second << endl; } };
#define DISPMV(m) { for(auto x_____: m){ cout << x_____.first << ": " ;DISPV(x_____.second);} };
using LL = long long;
using VI = vector <int>;
using VC = vector <char>;
using VS = vector <string>;
using VL = vector <long long>;
using VVI = vector<VI>;
using VVL = vector <VL>;
using MII = map<int, int>;
using MIVI = map<int, VI>;
using MSS = map<string, string>;
using MLL = map<LL, LL>;
int READ_INT(){int temp;cin>>temp;return temp;}      // read an int
LL READ_LONG(){LL temp;cin>>temp;return temp;}      // read a long long
void mcs(VI &series, int &max_sum){                    // maximum contigous sub sum(kadane)
    int s=0;
    for(auto x: series){
        s += x;
        max_sum = max(max_sum, s);
        if(s < 0)s = 0;
    }
}
template<typename T>
T MAX(T t){ return t;}
template <typename T, typename... Args>
T MAX(T t, Args... args){ return max(t, MAX(args...)); }
const int MOD = int(1e9) + 7;
const int INF = 1e9 + 5;
const double PI = acos(-1.0); //M_PI;
const double EPS = 1e-9;
//********************************************************************//

int n;
VI sequence;

LL score(int k){
    LL s = 0;
    for(auto x: sequence)s += abs(k - x);
    return s;
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;
    RANGE(i,n)sequence.push_back(READ_INT() - (i+1));
    SORT(sequence);
    // DISPV(sequence);

    int l = sequence[0], r = sequence[n-1], m1 = l+1, m2;
    while(r - l > 2){
        m1 = l + (r-l)/3;
        m2 = r - (r-l)/3;
        LL s1 = score(m1), s2 = score(m2);
        if(s1 < s2)r = m2;
        else l = m1;
    }
    LL ans = min(score(m1), min(score(l), score(r)));
    cout << ans << endl;

    return 0;
}



/* complie flags
-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector
*/


Measured memory_bytes: 1400
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N, P;
    scan(N, P);
    auto A = aryread();
    long[2] cnt;
    foreach (a; A)
        cnt[a & 1]++;
    long ans;
    foreach (x; 0 .. cnt[1] + 1)
    {
        if (cnt[1] < x * 2 + P)
            break;
        ans += combination(cnt[1], x * 2 + P);
    }
    ans *= 2 ^^ cnt[0];
    writeln(ans);
}

/// Number of k-combinations
T combination(T = long)(T n, T k)
{
    assert(0 <= k);
    assert(0 <= n);
    if (n < k)
        return 0;
    k = min(n - k, k);
    if (k == 0)
        return 1;
    if (k == 1)
        return n;
    return memoize!combination(n - 1, k - 1) + memoize!combination(n - 1, k);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
#define M 1000000
#define INF 1000000000

struct edge{
    LL to;
    LL cost;
};

LL V;
vector<edge> graph[M];
LL d[M];

void dijkstra(LL s){
    priority_queue<P, vector<P>, greater<P>>    que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        LL v = p.second;
        if(d[v] < p.first)  continue;
        for(int i = 0;i < graph[v].size();i++){
            edge e = graph[v][i];
            if(d[e.to] > d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
int main(){
    LL H, W;
    cin >> H >> W;
    LL D[10];
    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 10;j++){
            int cij;
            cin >> cij;
            edge e1 = {j, cij};
            graph[i].emplace_back(e1);
        }
    }
    V = 10;
    for(LL i = 0;i < 10;i++){
        dijkstra(i);
        D[i] = d[1];
    }
    LL ans = 0;
    for(int i = 1;i <= H;i++){
        for(int j = 1;j <= W;j++){
            int Aij;
            cin >> Aij;
            if(Aij >= 0 && Aij != 1) ans += D[Aij];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 25344
x,y,z,k = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
b = sorted(list(map(int,input().split())),reverse=True)
c = sorted(list(map(int,input().split())),reverse=True)

buf = []
for i in range(x):
    for j in range(y):
        buf.append(a[i]+b[j])

buf = sorted(buf,reverse=True)[:k]
ans = []

for i in buf:
    for j in range(z):
        ans.append(i+c[j])

ans = sorted(ans,reverse=True)
[print(ans[i]) for i in range(k)]


Measured memory_bytes: 152448
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	ll k;
	cin >> k;
	vector<ll> a(50,(k+49)/50+49);
	if(k % 50 != 0){
		for(ll i = 0;i < 50 - k % 50;i++){
			sort(a.begin(),a.end());
			for(int j = 0;j < 49;j++)a[j]++;
			a[49] -= 50;
		}
	}
	cout << 50 << endl;
	for(int i = 0;i < 50;i++)cout << a[i] << " ";
	cout << endl;
}


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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
	int n,w;
	cin>>n>>w;
	pii item[n];
	fr(i,0,n)
	cin>>item[i].first>>item[i].second;
	ll ans=0;
	ll dp[2][100001];
	fr(i,0,2)
	fr(j,0,100001)
	dp[i][j]=-1;
	dp[0][0]=0;
	int k=0;
	fr(i,0,n){
		k^=1;
		fr(j,0,100001)
		dp[k][j]=dp[k^1][j];
		for(int j=0;j+item[i].second<=100000;j++){
			if(dp[k^1][j]+item[i].first>w || dp[k^1][j]==-1)
				continue;
			dp[k][j+item[i].second]=(dp[k][j+item[i].second]==-1)?dp[k^1][j]+item[i].first:min(dp[k][j+item[i].second],dp[k^1][j]+item[i].first);
		}
	}
	fri(i,100000,0){
		if(dp[k][i]!=-1){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 5180
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var list = nextIntArray();
  var count = 0;
  var max = 0;
  for(var i = 0; i < N; i++){
    max += list[i];
  }
  for(var i = 0; i < N; i++){
    if(list[i] >= (max / (4 * M))){
      count++;
    }
  }
  if(count >= M){
    myout("Yes");
  }else{
    myout("No");
  }
}

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

int main(){
  int n;
  cin >> n;
  int a[n] = {0}; 
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n,greater<int>());
  int al=0,bo=0;
  for(int i=1;i<=n;i++){
    if(i%2 != 0) al+=a[i-1];
    else bo+=a[i-1];
  }
  cout << al-bo<< endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int total_days,total_predetermined_pastas;
int predetermined_pastas[101];
int dp[101][4][4];

int dfs(int day,int pasta,int successive){
  if(successive == 3) return 0;
  if(predetermined_pastas[day] != -1
     && predetermined_pastas[day] != pasta){
    return 0;
  }
  if(dp[day][pasta][successive] != -1){
    return dp[day][pasta][successive];
  }

  if(day >= total_days){
    return 1;
  }

  int res = 0;

  if(predetermined_pastas[day+1] != -1){
    if(predetermined_pastas[day+1] == pasta){
      res = dfs(day+1,predetermined_pastas[day+1],successive+1);
    }
    else{
      res = dfs(day+1,predetermined_pastas[day+1],1);
    }
  }
  else{
    for(int next = 1; next<=3; next++){
      if(next == pasta){
	res += dfs(day+1,next,successive+1);
      }
      else{
	res += dfs(day+1,next,1);
      }
    }
  }
  return dp[day][pasta][successive] = (res % 10000);
}

int main(){

  while(~scanf("%d %d",&total_days,&total_predetermined_pastas)){
    memset(predetermined_pastas,-1,sizeof(predetermined_pastas));
    for(int pasta_idx = 0; pasta_idx < total_predetermined_pastas; pasta_idx++){
      int day,type;
      scanf("%d %d",&day,&type);
      predetermined_pastas[day] = type;
    }

    memset(dp,-1,sizeof(dp));

    if(predetermined_pastas[1] == -1){
      printf("%d\n",(dfs(1,1,1)+dfs(1,2,1)+dfs(1,3,1)) % 10000);
    }
    else{
      printf("%d\n",dfs(1,predetermined_pastas[1],1));
    }
  }
}

Measured memory_bytes: 1196
def areas(updown: str):
    stack1, stack2 = [], []

    for i, c in enumerate(updown):
        if c == "\\":
            stack1.append(i)
        elif c == "/":
            if len(stack1) == 0:
                continue

            match = stack1.pop()

            # ToDo
            total = 0
            while stack2 and match < stack2[-1][0]:
                _, x = stack2.pop()
                total += x

            total += i - match
            stack2.append((match, total))

        elif c == "_":
            # 何もする必要がない
            pass
        else:
            raise Exception("Invalid Input")

    print(sum(x for _, x in stack2))
    print("{} {}".format(len(stack2), " ".join([str(x) for _, x in stack2])).strip())


# in1 = r"\\//"
# in2 = r"\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/" + "\\"

s = input().strip()
areas(s)



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

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define str string
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Forrev(i,s,e) for (ll i=(s); i>=(e); i--)
#define all(v) v.begin(),v.end()

#define vll vector<ll>
#define vs vector<string>
#define mapll map<ll,ll>
#define pll pair<ll,ll>
#define initialise(a, x) memset(a, x, sizeof(a))
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>

#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
const ll mod=1e9 + 7;

ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

ll gcd(ll a, ll b) { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);        
}

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

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

void solve()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;

    if(k<=a)
        cout<<k<<endl;
    else if(k<=a+b)
        cout<<a<<endl;
    else
        cout<<a-(k-a-b)<<endl;
    
}

signed main() 
{
    fast_cin();
    // #ifndef ONLINE_JUDGE
    // freopen("C:/IO/in.txt", "r", stdin);
    // freopen("C:/IO/out.txt", "w", stdout);
    // #endif
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    
    
    return 0;    
}

Measured memory_bytes: 3656
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#define  go return 0
#define pb push_back
#include<utility>
#include <algorithm>
#include<iterator>
typedef long long ll;
typedef double db;
#define lp1(i, n)  for(int i=0; i<(int)(n); ++i)
#define lp2(i, n)  for(int i=0; i<(int)(n-1); ++i)
#define lp3(j, n)  for(int j=1; j<=(int)(n); ++j)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
typedef vector<int> vi;
const int N=1e5+5;
int arr[N];
int main(){
    int a,b;
    cin>>a>>b;
    int s=b-a+1;
    int e=a+b-1;
    for(int i=s;i<=e ; i++)
    cout<<i<< " ";

go;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int inf = 1000000000; // 10^9

int main(){
   int n,m,x;scanf("%d%d%d",&n,&m,&x);
   int a[101];
   for(int i = 0;i < m;i++){
      scanf("%d",&a[i]);
   }
   int c1=0,c2=0;
   for(int i = 0;i < m;i++){
      if(a[i]<x)c1++;
      else c2++;
   }
   //printf("%d,%d\n",c1,c2);
   printf("%d",MIN(c1,c2));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
#define ld long long double
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;  
int main() 
{
	FAST
	ll n;
	cin>>n;
	if(n%2==0) cout<<"0.50000000000";
	else if(n==1) cout<<"1.0000000000";
	else printf("%.10f",(float)(n-(n/2))/n);
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 4e5 + 10;
int cnt[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i < N; i++)
	{
		cnt[i] = cnt[i >> 1] + (i & 1);
	}
	vector<int> v1, v2;
	for (int i = 0; i < m; i++)
	{
		int sz;
		cin >> sz;
		int o = 0;
		while (sz--)
		{
			int x;
			cin >> x;
			o |= 1 << (x - 1);
		}
		v1.push_back(o);
	}
	v2.resize(m);
	for (auto& x : v2) cin >> x;
	int ans = 0;
	for (int i = 0; i < (1 << n); i++)
	{
		int c = 0;
		for (int j = 0; j < m; j++)
		{
			if ((cnt[i & v1[j]] & 1) == v2[j])
				c++;
		}
		if (c == m)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
s = list(input())
a =[]
n = len(s)
for i in range(1,n):
    if len(a) == 0:
        a.append(1)
    if s[i] == s[i-1]:
        a[-1] += 1
    else:
        a.append(1)
if a[0] == n:
    print(1,n)
    exit()
if max(a) > 1:
    for i in range(len(a)):
        if a[i] >1:
            if i == len(a)-1:
                print(n-a[i],n)
            else:
                print(sum(a[0:i])+1,sum(a[0:i+1])+1)
            exit()

else:
    for i in range(n-2):
        if s[i] == s[i+2]:
            print(i+1,i+3)
            exit()


    print(-1,-1)


Measured memory_bytes: 5288
#include<stdio.h>
#include<stdlib.h>
#define NMIN 1
#define NMAX 36

struct card{
  char mark;
  char value;
};

void bubble(struct card A[],int n){
  int i,j;
  struct card t;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(A[j].value<A[j-1].value){
	t=A[j];
	A[j]=A[j-1];
	A[j-1]=t;
      }
    }
  }
}
void selection(struct card A[],int n){
  int i,j,mi;
  struct card t;
  for(i=0;i<n;i++){
    mi=i;
    for(j=i;j<n;j++){
      if(A[j].value<A[mi].value)mi=j;
    }
    t=A[i];
    A[i]=A[mi];
    A[mi]=t;
      }
    }
void print(struct card A[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%c%c",A[i].mark,A[i].value);
  }
  printf("\n");
}
int isStable(struct card c1[],struct card c2[],int n){
  int i;
  for(i=0;i<n;i++){
    if(c1[i].mark!=c2[i].mark) return 0;
  }
  return 1;
}

int main(){
  int n,i,j;
  struct card c1[NMAX],c2[NMAX];
  char ch;

  scanf("%d",&n);
  if(n<NMIN || n>NMAX)exit(1);
  for(i=0;i<n;i++){
    scanf(" %c%c",&c1[i].mark,&c1[i].value);
  }
  for(i=0;i<n;i++){
    c2[i]=c1[i];
  }
  bubble(c1,n);
  selection(c2,n);

  print(c1,n);
  printf("Stable\n");
  print(c2,n);
  if(isStable(c1,c2,n)==1){
    printf("Stable\n");
  }
  else {printf("Not stable\n");
  }
  return 0;
}
    



Measured memory_bytes: 2108
//checking brute2
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
double pi = acos(-1.0);
const double EPS=1e-9;
#define MOD ll(1e9L+7)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define t() ll tt;cin>>tt;while(tt--) 
#define t2() ll tt2; cin>>tt2; for(ll tti=1;tti<=tt2;tti++)
#define printcj "Case #"<<tti<<": "
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cout << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define debugarray(arr,n,x) { cout << "[" ; for(ll i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"] , "<<#x<<" = "<<x<<'\n';}

const ll N=21;
ll n,a[N][N],dp[1<<N];

ll solve(ll men_index,ll selected_women)
{
    if(men_index==n){
        if(selected_women == (1LL<<n)-1) return 1;
        return 0;
    }
    if(dp[selected_women]!=-1) return dp[selected_women];
    ll count=0;
    for(ll i=0;i<n;i++)
        if(a[men_index][i] && !(selected_women & (1LL<<i)))
            count = (count+solve(men_index+1,selected_women | (1LL<<i)) )%MOD;
    return dp[selected_women]=count;
}


int main()
{
    fastio;
    cin>>n;
    for(ll j=0;j<(1<<n);j++) dp[j]  = -1;
    for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)cin>>a[i][j];
    cout<<solve(0,0);


    
}


Measured memory_bytes: 20004
n=int(input())
s=input()

wnum=[0]*n
for i in range(n):
  if s[i]=='W':
    wnum[i]+=1
  if i>0:
    wnum[i]+=wnum[i-1]

arr=[0]*n
for i in range(n):
  if i!=0:
    arr[i]+=wnum[i-1]
  arr[i]+=n-i-1-(wnum[-1]-wnum[i])

print(min(arr))

Measured memory_bytes: 45148
import java.util.*;

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

        int ans = 0;
        for(int i = n; i < 1000; i++){
            int k = i / 10;
            int l = i - (int)((i / 100) * 100);
            if(k == l){
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;
using std::pair;
using std::make_pair;

using std::min;
using std::max;
using std::min_element;
using std::max_element;
using std::sort;
using std::count;
using std::abs;

pair<int, int> solve(const string& s) {
    int len = s.length();

    int p = -1;
    for (int i = 0; i < len - 1; i++) {
        if (s[i] == '(' && s[i + 1] == ')') {
            p = i;
            break;
        }
    }

    if (p != -1) {
        string tmp(s);
        tmp.erase(p, 2);
        return solve(tmp);
    }

    int l = count(s.begin(), s.end(), '(');
    int r = count(s.begin(), s.end(), ')');

    return make_pair(l, r);
}

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

    string s;
    cin >> s;

    string tmp(s);
    pair<int, int> p = solve(tmp);

    string ans;
    for(int i = 0; i < p.second; i++){
        ans.append("(");
    }
    ans.append(s);
    for(int i = 0; i < p.first; i++){
        ans.append(")");
    }

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


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

#define rep(i, n) for(long long i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	string s;
	ll k;
	cin >> s >> k;
	bool is1 = true;
	char ans = '1';
	rep(i, k){
		if(s[i] != '1'){
			is1 = false;
			ans = s[i];
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch PopularVote | diff PopularVote.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address PopularVote.cpp && ./a.out

/*
 
 4/4/2020
 
 5:02-5:13 WA
 
 */

const int MAX_N=1e6+1;
int A[MAX_N];
int N,M;

bool solve() {
  int sum=accumulate(A,A+N,0);
  long double t=1.0*sum/(4*M);
  int cnt=0;
  REP(i,N) if(A[i]>=t) ++cnt;
  return cnt>=M;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REP(i,N) cin>>A[i];
  cout<<(solve()?"Yes":"No")<<endl;
  
  return 0;
}


Measured memory_bytes: 256
s=input()
s2=list(s)
s1=""
if s2[-1]=="?":
    s2[-1]="D"
if s2[0]=="?" and s2[1]=="D":
    s2[0]="P"
elif s2[0]=="?" and (s2[1]=="P" or s2[1]=="?"):
    s2[0]="D"
for i in range(1,len(s2)-1):
    if s2[i]=='?':
        if s2[i-1]=="D" and (s2[i+1]=="D" or s2[i+1]=="?"):
           s2[i]="P"
        else:
            s2[i]="D"
for i in s2:
    s1+=i
print(s1)

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

int main(void)
{
    int K;
    cin >> K;
    int N=7;
    for (int i = 0; i < K; i++){
        if (N%K==0)
        {
            cout << i+1 << endl;
            return 0;
        }
        N=(10*N+7)%K;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3644
// https://beta.atcoder.jp/contests/abc080
// status:

#define SUBMIT

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

void solve(int x) {
    int x_copy = x;
    int sum = 0;
    while (x != 0) {
        sum += x % 10;
        x /= 10;
    }

    if (x_copy % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    auto s = std::string(R"(12
)");

    stringstream stream(s);
#endif
    int N;
    stream >> N;
    solve(N);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N,K,X,Y,sum;
	scanf("%d%d%d%d",&N,&K,&X,&Y);
	if(N>=K)
	sum=K*X+(N-K)*Y;
	else
	sum=N*X;
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int N=200009;
char s[N];
int cnt,ans;

int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='S')
			cnt++;
		else if(cnt>0)
			cnt--,ans++;
	}
	printf("%d\n",n-ans*2);
	return 0;
}


Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, m := iScan(), iScan()
	ab := make([][2]int, n)
	for i := 0; i < n; i++ {
		ab[i][0] = iScan()
		ab[i][1] = iScan()
	}
	sort.Slice(ab, func(i, j int) bool { return ab[i][0] < ab[j][0] })
	ans := 0
	for _, v := range ab {
		a, b := v[0], v[1]
		ans += a * smaller(b, m)
		m -= smaller(b, m)
		if m == 0 {
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5052
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }

  return 0;
}

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

int main(){
    int n;
    scanf("%d", &n);
    vector<ll> bs;
    ll b;
    ll xall = 0;
    for(int i=0;i<n;i++) {
        scanf("%lld",&b);
        xall ^= b;
        bs.push_back(b);
    }
    for(int i=0;i<n;i++){
        if(i) printf(" ");
        printf("%lld", xall^bs[i]);
    }
}


Measured memory_bytes: 5360
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
        int N,A;
        int X;

        cin >> N >> A;
        X = N % 500;
        if(X==0){
            cout << "Yes" << endl;
        }else if(X<=A){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#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<pair<int,int> > a(n);
  rep(i,n){cin >> a[i].first; a[i].second=i+1;}
  sort(a.begin(),a.end());

  rep(i,n){cout << a[i].second << " ";}

  return 0;
}


Measured memory_bytes: 1536