akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#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 < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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 N, K;
vector<lint> V;

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

  cin >> N >> K;
  V.resize(N);
  for (int i = 0; i < N; i++) cin >> V[i];

  lint res = 0;
  for (int p = 0; p <= min(K, N); p++) {
    for (int q = 0; p + q <= min(K, N); q++) {
      vector<lint> v;
      lint cur = 0;
      for (int i = 0; i < p; i++) v.push_back(V[i]), cur += V[i];
      for (int i = 0; i < q; i++)
        v.push_back(V[N - 1 - i]), cur += V[N - 1 - i];

      sort(all(v));

      for (int i = 0; i < min(K - p - q, (int)v.size()); i++) {
        if (v[i] < 0) cur -= v[i];
      }
      chmax(res, cur);
    }
  }

  cout << res << endl;

  return 0;
}

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

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



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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    if(n% 10 == 9 ||n/10 == 9)
        cout <<"Yes\n";
    else
        cout <<"No\n";
}

Measured memory_bytes: 256
import itertools
while True:
    n, x = map(int, input().split())
    if n==0 and x==0:
        break
    tmp = list(itertools.combinations(range(1, n+1), 3))
    cnt = 0
    for val in tmp:
        cnt += 1 if sum(val)==x else 0
    print(cnt)


Measured memory_bytes: 31420
import java.util.*;

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

        int H = sc.nextInt();
        int N = sc.nextInt();
        int A = 0;

        for(int i=0; i<N; i++){
            A += sc.nextInt();
        }
        if(A>=H){
            System.out.println("Yes");
        }
        else if(A<H){
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 49160
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  lli n; scanf("%lld", &n);
  lli ans = 1e18;
  for (lli i = 1, end = sqrt(n); i <= end; i ++)
    if (n % i == 0)
      ans = min(ans, i + (n / i) - 2);
  printf("%lld\n", ans);
  return 0;
}

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

int main() {
  int A;
  cin >> A;
  int B;
  cin >> B;
  int C;
  cin >> C;
  int D;
  cin >> D;
  int E;
  cin >> E;
  
  int a=A%10;
  if(A!=0 && a==0) a=10;
  int b=B%10;
  if(B!=0 && b==0) b=10;
  int c=C%10;
  if(C!=0 && c==0) c=10;
  int d=D%10;
  if(D!=0 && d==0) d=10;
  int e=E%10;
  if(E!=0 && e==0) e=10;
  
  int z=(A/10)*10+10;
  if(a==10) z-=10;
  int y=(B/10)*10+10;
  if(b==10) y-=10;
  int x=(C/10)*10+10;
  if(c==10) x-=10;
  int v=(D/10)*10+10;
  if(d==10) v-=10;
  int u=(E/10)*10+10;
  if(e==10) u-=10;
  
  int ans=0;
  
  if(a<=b && a<=c && a<=d && a<=e) ans=A+y+x+v+u;
  else if(b<=a && b<=c && b<=d && b<=e) ans=B+z+x+v+u;
  else if(c<=a && c<=b && c<=d && c<=e) ans=C+z+y+v+u;
  else if(d<=a && d<=b && d<=c && d<=e) ans=D+z+y+x+u;
  else if(e<=a && e<=b && e<=c && e<=d) ans=E+z+y+x+v;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll MAX=500000;
const ll INF=(1ll<<62)-1;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=finv[1]=finv[0]=inv[0]=inv[1]=1;
    rep(i,2,MAX){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=modpow(i,MOD-2);
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
ll N,M,Q; 
ll dfs(int cnt,vi &A,vi &B,vi &C,vi &D,vi &E){
    ll ret=0;
    if(cnt==N+1){
        rep(i,0,Q){
            if(E[B[i]]-E[A[i]]==C[i]) ret+=D[i];
        }
    }
    else{
        REP(i,E[cnt],M){
            E.pb(i);
            ret=std::max(ret,dfs(cnt+1,A,B,C,D,E));
            E.pop_back();
        }
    }
    return ret;
}
signed main(){
    cin>>N>>M>>Q;
    vi A(Q),B(Q),C(Q),D(Q);
    rep(i,0,Q) cin>>A[i]>>B[i]>>C[i]>>D[i];
    vi E(1,1);
    cout<<dfs(0,A,B,C,D,E)<<endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int dist[10][10];

int main() {
    int H, W;
    cin >> H >> W;
    rep(i, 10) rep(j, 10) {
        int c;
        cin >> c;
        dist[i][j] = c;
    }
    for (int k=0; k<10; ++k) {
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, H) rep(j, W) {
        int a;
        cin >> a;
        if (a == -1) continue;
        else ans += dist[a][1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,i;
	scanf("%d",&n);
	int a[100];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<(n-1);i++){
		printf("%d",a[n-i-1]); printf(" ");
	}
	printf("%d\n",a[0]);
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>

typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

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

    bool f = true;

    rep(i, s.size()) {
        if(s[i] != t[i]) {
            f = false;
        }
    }

    if(t.size() != s.size() + 1) {
        f = false;
    }

    string ans;
    if (f)
    {
        ans = "Yes";
    }
    else
    {
        ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
s=str(input())
t=str(input())

ans=1000

for i in range(len(s)):
    x=0
    if i+len(t)<=len(s):
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                x+=1
        if x<ans:
            ans=x
    else:
        break
print(ans)


Measured memory_bytes: 67540
n = int(input())
def cal(a):
  cn = 0
  for i in range(1,a+1):
    if a%i==0: cn+=1
  return cn == 8
ans = 0
for i in range(1,n+1):
  if  (i%2==1) :ans += cal(i) 
print(ans)


Measured memory_bytes: 9072
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
 public static void main(String[] args) throws Exception {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  int h, m, s;
  
  String str = br.readLine();
  s = Integer.parseInt(str);
  
  h = s/3600;
  m = s/60;
  m = m%60;
  s = s%60;
  
  System.out.println(h + ":" + m + ":" + s);
  
 }
}

Measured memory_bytes: 24296
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()

	for i := 1; i <= 1000; i++ {
		if a == int(float64(i)*0.08) && b == int(float64(i)*0.10) {
			fmt.Println(i)
			return
		}
	}

	fmt.Println("-1")

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;
typedef unsigned int INT;
typedef unsigned long long LONG;
typedef long long LL;
#define Foru(i, a, b) for(LONG i=(a);i<(b);++i)
#define Forl(i, a, b) for(LL i=(a);i>=(b);--i)
#define pb emplace_back
#define ft first
#define sd second
const int N = 100000 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
typedef pair<int, int> PII;

//读入输出外挂，只适用于整数，使用时流同步打开，C语言不准关流
//getchar()<<cin(关流)<<scanf()<<cin
template<class T>
inline bool read(T &ret) {
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF) return 0;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//输出只能用于正整数
template<class T>
inline void write(T x) {
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

void slove(int question_num) {
    while (question_num--) {
        int a;
        map<int, PII> key;
        for (int i = 1; i <= 3; ++i) {
            for (int j = 1; j <= 3; ++j) {
                cin >> a;
                key[a] = {i, j};
            }
        }
        int n;
        int k[4][4] = {{0}};
        cin >> n;
        for (int i = 1; i <= n; ++i) {
            int temp;
            cin >> temp;
            if (key.count(temp)) {
                k[key[temp].ft][key[temp].sd] = 1;
            }
        }
        int flag = 0;
        if ((k[1][1] && k[2][2] && k[3][3]) || (k[1][3] && k[2][2] && k[3][1]))
            flag = 1;
        for (int i = 1; i <= 3; ++i) {
            if (k[i][1] && k[i][2] && k[i][3]) flag = 1;
            if (k[1][i] && k[2][i] && k[3][i]) flag = 1;
        }
        if (flag) cout << "Yes";
        else cout << "No";
    }
}

int main() {
    //ios::sync_with_stdio(false);
    int num = 1;
    //    read(num);
    slove(num);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String [] args) {
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int num[] = new int[N];
      String S = sc.next();
      String values[] = S.split("");
      int max = 0;
      for (int i = 0; i < N  ; i++) {
        String x = values[i];
        if (x.equals("I")) {
          max = max + 1;
          num[i] = max;
        } else {
          max = max - 1;
          num[i] = max;
        }
      }
      int ret = findmax(num);
      System.out.println(ret);
  }
  private static int  findmax(int num[]) {
      int max = 0;
      for (int j = 0; j < num.length; j ++) {
          max = Math.max(max, num[j]);
      }
      return max;
  }
}

Measured memory_bytes: 23380
import javax.swing.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;


public class Main {
    /*public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(reader.readLine());
        while(q>0){
            q--;
        String[] l = reader.readLine().split(" ");
        int a = Integer.parseInt(l[0]);
        int b = Integer.parseInt(l[1]);
        int c = Integer.parseInt(l[2]);
        int n = Integer.parseInt(l[3]);
        int p=(a+b+c+n)/3;
        if((a+b+c+n)%3==0 && p-a>=0 && p-b>=0 && p-c>=0 ) System.out.println("YES");
        else System.out.println("NO");
    }}*/
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] l = reader.readLine().split(" ");
        long n = Long.parseLong(l[0]);
        long k = Long.parseLong(l[1]);
        String[] lo = reader.readLine().split(" ");
        if(k>=n){System.out.println(0);}
        else{

            long sum=0;
            long[] list = new long[lo.length];
            for(int i = 0;i<n;i++){
                list[i] = Long.parseLong(lo[i]);
            }
            Arrays.sort(list);
            for(int i = 0;i<n-k;i++){
                sum += list[i];
            }
            System.out.println(sum);
    }
    }
}



Measured memory_bytes: 69544
// template version 1.0
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n,k;cin>>n>>k;

  int cnt[k]={};

  rep(i, 1, n+1){
    cnt[i%k]++;
  }
  dump_1d(cnt, k);

  int res = 0;

  rep(a, 1, n+1){
    int r = a%k;
    int c = (k-r)%k;
    if ((c*2)%k==0){
      res += cnt[c]*cnt[c];
    }
  }
  cout << res << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, ans = 0;
    cin >> n;
    ans += (n / 500) * 1000 + ((n % 500) / 5) * 5;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
 
// 入力制約
#define NUM_MIN ( ( int ) 1 )
#define NUM_MAX ( ( int ) 100 )
#define ELEMENT_MIN ( ( int ) 0 )
#define ELEMENT_MAX ( ( int ) 100 )

// 制約判定結果
typedef enum
{
	kSuccess,
	kError
}Result;

// プロトタイプ宣言
Result checkNumRange( int num, int min, int max );
int execBubbleSort( int num, int* pArray );
void showArray( int num, int* pArray );
void swap( int* pX, int* pY );

//****************************************************/
// @brief  メイン関数
// @param  無し
// @return 正常終了なら0、異常終了なら-1を返す
//****************************************************/
int main( void )
{
	int i;
	int num;
	int array[NUM_MAX];
	int count;

	// 要素数の入力判定
	scanf( "%d\n", &num );
	if( checkNumRange( num, NUM_MIN, NUM_MAX ) == kError )
	{
		return -1;
	}

	// 要素の入力判定
	for( i = 0; i < num; i++ )
	{
		scanf( "%d", &array[i] );
		if( checkNumRange( array[i], ELEMENT_MIN, ELEMENT_MAX ) == kError )
		{
			return -1;
		}
	}

	// バブルソート実行
	count = execBubbleSort( num, &array[0] );
	// ソート回数を出力
	showArray( num, &array[0] );
	printf( "%d\n", count );

	return 0;
}

//****************************************************/
// @brief  入力値の制約判定
// @param  num : 判定対象の入力値
//         min : 最小値
//         max : 最大値
// @return 制約内ならkSuccess、制約外ならkErrorを返す
//****************************************************/
Result checkNumRange( int num, int min, int max )
{
	return ( ( num >= min ) && ( num <= max ) ) ? kSuccess : kError;
}

//****************************************************/
// @brief  バブルソートを実行し、ソート回数を返す
// @param  num    : 要素数
// @param  pArray : 要素を格納した配列先頭へのポインタ
// @return ソート回数
//****************************************************/
int execBubbleSort( int num, int* pArray )
{
	int i;
	int index = 0;	// 未ソート部分列の先頭インデックス
	int flag = 1;	// ソートしたら1, ソートしなければ0にする
	int count = 0;	// ソート回数

	while( flag )
	{
		flag = 0;
		for( i = num - 1; i >= index + 1; i-- )
		{
			if( pArray[i] < pArray[i - 1] )
			{
				// 要素入れ替え、ソート回数をカウント
				swap( &pArray[i], &pArray[i - 1] );
				flag = 1;
				count++;
			}
		}
		index++;
	}

	return count;
}
 
//****************************************************/
// @brief  変数の値を交換する
// @param  pX : 値を交換する変数1
// @param  pY : 値を交換する変数2
// @return 無し
//****************************************************/
void swap( int* pX, int* pY )
{
	int temp;

	temp = *pX;
	*pX = *pY;
	*pY = temp;
}

void showArray( int num, int* pArray )
{
	int i;

	for( i = 0; i < num; i++ )
	{
		if( i != num - 1 )
		{
			// 出力する要素の末尾以外はスペースを空ける
			printf( "%d ", pArray[i] );
		}
		else
		{
			// 出力する要素の末尾は改行を入れる
			printf( "%d\n", pArray[i] );
		}
	}
}



Measured memory_bytes: 2104
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    VS s(n);
    REP(i,n)cin>>s[i];
    LL ans = 0;
    int n_ba = 0;
    int n_b_start = 0;
    int n_a_end = 0;
    REP(i,n){
        int sz = SZ(s[i]);
        REP(j,sz-1)if(s[i][j] == 'A' && s[i][j+1] == 'B')ans++;
        if(s[i][0] == 'B' && s[i][sz-1] == 'A')n_ba++;
        else if(s[i][0] == 'B')n_b_start++;
        else if(s[i][sz-1] == 'A')n_a_end++;
    }
    if(n_ba > 0){
        ans += n_ba - 1;
        if(n_b_start > 0)ans++;
        if(n_a_end > 0)ans++;
        ans += max(0, min(n_b_start - 1, n_a_end - 1));
    }
    else{
        ans += max(0, min(n_b_start, n_a_end));
    }

    PUTS(ans);
}

Measured memory_bytes: 768
import java.util.Scanner;
  
class Main{
  public static void main(String[] arg){
    int n, m, l;
    int [][] a,b;
    long [][] c;
 
    Scanner in = new Scanner(System.in);

    n = in.nextInt();
    m = in.nextInt();
    l = in.nextInt();

    a = new int[n][m];
    b = new int[m][l];
    c = new long[n][l];

    for(int i=0; i<a.length; i++){
        in.nextLine();
        for(int j=0; j<a[0].length; j++)
            a[i][j] = in.nextInt();
    }

    for(int i=0; i<b.length; i++){
        in.nextLine();
        for(int j=0; j<b[0].length; j++)
            b[i][j] = in.nextInt();
    }

    for(int i=0; i<c.length; i++)
        for(int j=0; j<c[0].length; j++)
            c[i][j] = 0;

    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            for(int k=0; k<m; k++)
                c[i][j] += a[i][k]*b[k][j];
 
    for(int i=0,j; i<c.length; i++){
        for(j=0; j<c[0].length-1; j++)
            System.out.print(c[i][j] + " ");
        System.out.println(c[i][j]);
    }
 
  }
}

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

int main() {
    ll n,d;
    cin >> n >> d;
    ll dist=d*d;
    ll ans=0;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if(x*x+y*y<=dist) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>  // log10(int n);
#include<math.h>

//#include"PC.h"

using namespace std;


bool pitagoras_number(int data[3]){
sort(data,data+3,greater<int>());
int sum;
for(int i=1;i<3;i++)sum+=pow(data[i],2.0);

return pow(data[0],2.0)==sum;


}


int main(){

int n;
cin>>n;
	for(int i=0;i<n;i++){
	int data[3];
	for(int i=0;i<3;i++)cin>>data[i];
	
	if(pitagoras_number(data))cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	}

}

Measured memory_bytes: 1168
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int N; std::cin >> N;
    int cntAC(0), cntWA(0), cntTLE(0), cntRE(0);
    {
        std::string S;
        for(int i(0); i < N; ++i){
            std::cin >> S;
            if(S == "AC") ++cntAC;
            if(S == "WA") ++cntWA;
            if(S == "TLE") ++cntTLE;
            if(S == "RE") ++cntRE;
        }
    }
    std::cout << "AC x " << cntAC << "\n";
    std::cout << "WA x " << cntWA << "\n";
    std::cout << "TLE x " << cntTLE << "\n";
    std::cout << "RE x " << cntRE << std::endl;
    return 0;
}


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

int main () {
  int N, M;
  cin >> N >> M;
  
  int a, b;
  vector<int> vec(N, 0);
  
  for(int i = 0; i < M; i++) {
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  for(int i = 0; i < N; i++) cout << vec.at(i) << endl;
}
      

Measured memory_bytes: 256
from collections import deque

N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
color=[0]*N
color[0]=1
que=deque()
que.append(0)
nibu=True
bla=1
whi=0
while(que):
    x=que.pop()
    for i in G[x]:
        if color[i]==color[x]:
            nibu=False
            break
        if color[i]==-color[x]:
            continue
        if color[i]==0:
            color[i]=-color[x]
            if color[i]==1:
                bla+=1
            else:
                whi+=1
            que.append(i)
            continue

if not nibu:
    print(N*(N-1)//2-M)
if nibu:
    print(bla*whi-M)


Measured memory_bytes: 61600
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int n; cin >> n;
    int k; cin >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h.at(i);

    sort(h.rbegin(), h.rend());
    if(n<=k){
        cout << 0 << endl;
        return 0;
    }
    rep(i, k){
        h.at(i) = 0;
    }

    ll sum = 0;
    rep(i, n) sum += h.at(i);
    cout << sum << endl;
}


Measured memory_bytes: 1792
#pragma GCC optmize("0fast")
#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;

inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int n ,k;
    cin >> n >> k;

    vector<int> a(n);

    rep(i,n){
        cin >> a[i];
    }

    vector table(n+1, vector(64, 0));

    rep(i,n){
        table[i+1][0] = a[i];
    }

    for(int i = 0; i < 63; ++i){
        for(int j = 1; j <= n; ++j){
            table[j][i+1] = table[table[j][i]][i];
        }
    }

    int now = 1;
    for(int i = 0; i < 63; ++i){
        if(1ll << i & k){
            now = table[now][i];
        } 
    }

    cout << now << '\n';

    return (0);
}

Measured memory_bytes: 62572
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s1 = sc.next();
    String s2 = sc.next();
    String s3 = sc.next();
    String ans = "";
    ans += Character.toUpperCase(s1.charAt(0));
    ans += Character.toUpperCase(s2.charAt(0));
    ans += Character.toUpperCase(s3.charAt(0));

    System.out.println(ans);

  }
}

Measured memory_bytes: 39128
#include<bits/stdc++.h>
using namespace std;
#define Maxn 110

struct Py
{
	int x, y, h;
}p[Maxn];

inline bool cmp(const Py &a, const Py &b) { return (a.h>b.h); }

int n;

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].h);
	sort(p+1, p+n+1, cmp);
	for (int cx=0; cx<=100; cx++)
		for (int cy=0; cy<=100; cy++)
		{
			bool flag = 0;
			int Call = p[1].h + abs(cx-p[1].x) + abs(cy-p[1].y);
			for (int i=2; i<=n; i++)
			{
				if (p[i].h == 0) { if (abs(cx-p[i].x) + abs(cy-p[i].y) < Call) { flag = 1; break; } } 
				else
					if (p[i].h + abs(cx-p[i].x) + abs(cy-p[i].y) != Call) { flag = 1; break; }
			}
			if (!flag) { printf("%d %d %d\n", cx, cy, Call); return 0; }
		}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
   double a,b,c,d,e,f,x,y,xbb,xbs,ybb,ybs;
   while(scanf("%lf",&a)!=EOF){
      scanf("%lf%lf%lf%lf%lf",&b,&c,&d,&e,&f);
      xbb=a*e-b*d,xbs=c*e-b*f; //分母と分子をまず計算する
      x=xbs/xbb; //xを出す
      ybb=b*d-a*e,ybs=c*d-a*f; //xと同じことをする
      y=ybs/ybb;
      if(fabs(x)<0.0000001)
         x=0;
      if(fabs(y)<0.0000001)
         y=0;
      printf("%.3lf %.3lf\n",x,y);
   }
   return 0;
}

Measured memory_bytes: 652
n=int(input())
s=list(map(int,input().split()))
m=int(input())
a=list(map(int,input().split()))

for i in a:
    x=s[i-1]+1
    if x in s:
        continue
    if x >2019:
        continue
    else:
        s[i-1]=x
for i in range(n):
    print(s[i])
    
    


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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  int x, y;
  cin >> x >> y;

  if (y > 4 * x || y < 2 * x || y % 2) {
    cout << "No";
  } else {
    cout << "Yes";
  }
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  // }

  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<ll> > dp;

ll fun(int h,int n,vector<pair<int,int> >&arr){
    if(h<=0)return 0;
    if(n<0)return 1e9;
    if(dp[n][h] != -1)return dp[n][h];
    return dp[n][h] = min(arr[n].second+fun(h-arr[n].first,n,arr),fun(h,n-1,arr));
    
}

int main(){

    int h,n;cin>>h>>n;
    vector<pair<int,int>> A;
    dp.resize(n+1,vector<ll>(h+1,-1));
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        A.push_back({x,y});
    }
    sort(A.begin(),A.end());
    fun(h,n-1,A);
    cout<<dp[n-1][h]<<endl;
    

}

Measured memory_bytes: 79232
#include<stdio.h>
int main()
{
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	if((a>=0) && (c>=0))
		printf("%lld",b*d);
	else if((b<=0)&&(d<=0))
		printf("%lld",a*c);
	else if((b<=0)&&(c>=0))
		printf("%lld",b*c);
	else if((a>=0)&&(d<=0))
		printf("%lld",a*d);
	else if(((a<=0)&&(b>=0)) && (c>=0))
		printf("%lld",b*d);
	else if((a<=0)&&(b>=0) && (d<=0))
		printf("%lld",a*c);
	else if((c<=0)&&(d>=0)&&(a>=0))
		printf("%lld",b*d);
	else if((c<=0)&&(d>=0)&&(b<=0))
		printf("%lld",a*c);
	else if((a<=0)&&(b>=0)&& (c<=0)&&(d>=0))
	{
		if((a*c)>b*d)
			printf("%lld",a*c);
		else
			printf("%lld",b*d);
	}
}

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

template <typename T> void b_sort(T* a , int n){
	int i , j;
	for(i=n;i>=0;i--){
		for(j=0;j<n-1;j++){
			if(a[j]>a[j+1]){
				a[j]^=a[j+1];
				a[j+1]^=a[j];
				a[j]^=a[j+1];
			}
		}
	}	
} 

int main(){
	unsigned int m[10];
	for(int i=0;i<10;++i){
		cin >> m[i];
	}
	b_sort(m , 10);
	cout << m[9] << "\n" << m[8] << "\n" << m[7] << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
class dice{
public:
  int d[6];
  void rotate(char a){
    if(a=='N'){
      int top=d[0];
      d[0]=d[1];
      d[1]=d[5];
      d[5]=d[4];
      d[4]=top;
    }
    else if(a=='S'){
      int top=d[0];
      d[0]=d[4];
      d[4]=d[5];
      d[5]=d[1];
      d[1]=top;
    }
    else if(a=='E'){
      int top=d[0];
      d[0]=d[3];
      d[3]=d[5];
      d[5]=d[2];
      d[2]=top;
    }
    else if(a=='W'){
      int top=d[0];
      d[0]=d[2];
      d[2]=d[5];
      d[5]=d[3];
      d[3]=top;
    }
    return;
  }
};
int main(){
  dice d;
  string vec;
  for(int i=0;i<6;i++){
    cin>>d.d[i];
  }
  cin>>vec;
  for(int i=0;i<vec.size();i++){
    d.rotate(vec[i]);
  }
  cout<<d.d[0]<<endl;
  return 0;
}



Measured memory_bytes: 3188
import sys

sys.setrecursionlimit(10**6)
def bps(gr,p,s,num):
    if gr[s]!=-1:
        return
    gr[s]=num
    for x in p[s]:
        bps(gr,p,x,num)

N,K,L=list(map(int,input().split()))
dic={}
road=[[] for _ in range(N)]
rail=[[] for _ in range(N)]

for i in range(K):
    p,q=list(map(int,input().split()))
    road[p-1].append(q-1)
    road[q-1].append(p-1)

for i in range(L):
    r,s=list(map(int,input().split()))
    rail[r-1].append(s-1)
    rail[s-1].append(r-1)


roadG=[-1 for _ in range(N)]
num=0
for i in range(N):
    if roadG[i]==-1:
        bps(roadG,road,i,num)
        num+=1

railG=[-1 for _ in range(N)]
num=0
for i in range(N):
    if railG[i]==-1:
        bps(railG,rail,i,num)
        num+=1
dic={}
arr=[]
for i in range(N):
    key=roadG[i]*N+railG[i]
    arr.append(key)
    dic[key]=dic.setdefault(key,0)+1
print(dic[arr[0]],end='')
for x in arr[1:]:
    print(' {}'.format(dic[x]),end='')
print('')

Measured memory_bytes: 88088
#include <stdio.h>

int main(void)
{
	int h[10];
	int one, two, three;
	int x, i;
	for(i=0; i<10; i++) {
		scanf("%d", &x);
		h[i]=x;
		if(i==0) one=h[0];
		else if(i==1) {
			if(h[1]>=one) {
				one=h[1]; 
				two=h[0];
			}
			else two=h[1];
		}
		else if(i==2) {
			if(h[2]>=one) {
			three=two;
			two=one;
			one=h[2];
			}
			else if(h[2]<one && h[2]>=two) {
				three=two;
				two=h[2];
			}
			else three=h[2];
		}
		else {
			if(h[i]>=one) {
				three=two;
				two=one;
				one=h[i];
			}
			else if(h[i]<one && h[i]>=two) {
				three=two;
				two=h[i];
			}
			else if(h[i]<two && h[i]>=three) 
				three=h[i];
		}
	}
	printf("%d\n%d\n%d\n", one, two, three);
		
	return 0;
}


Measured memory_bytes: 600
#include<iostream>
using namespace std;
const int N=21;
int n,m,c,b[N],a[N][N],s,A;
int main()
{
	cin>>n>>m>>c;
	for(int i=1;i<=m;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
	{
		s=c;
		for(int j=1;j<=m;j++)
			s+=a[i][j]*b[j];
		if(s>0)
			A++;
	}
	cout<<A;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

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

c = 0

def merge(A, left, mid, right):
  inf = float('inf')
  L = A[left:mid] + [inf]
  R = A[mid:right] + [inf]
  i = 0
  j = 0
  global c
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
      c += mid - left - i

def mergesort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2
    mergesort(A, left, mid)
    mergesort(A, mid, right)    
    merge(A, left, mid, right)

mergesort(S, 0, n)

print(c)



Measured memory_bytes: 27472
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

ll N;
vector<P> insu;

int main() {
	cin >> N;
	for (ll a = 2; a * a <= N; a++) {
		if (N % a == 0) {
			insu.push_back(P(a, N / a));
		}
	}
	if (insu.size() == 0) {
		insu.push_back(P(1, N));
		//prime
	}
	ll ans = 1145141919810893;
	for (int i = 0; i < insu.size(); i++) {
		ans = min(ans, (insu[i].first - 1) + (insu[i].second - 1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

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

	if (n == 2) {
		cout << 1 << endl;
		return 0;
	}
	else if (n == 3) {
		cout << 2 << endl;
		return 0;
	}
	else if (n == 4) {
		cout << 3 << endl;
		return 0;
	}

	//n-1
	ll m = n - 1;

	ll ans = 2;
	FOR(i, 2, n + 1) {
		if ((ll)i * (ll)i == m) {
			ans++;
		}
		else if ((ll)i * (ll)i > m + 1) {
			cout << ans << endl;
			return 0;
		}
		else {
			if (m % i == 0) {
				ans += 2;
			}
			else {
				ll t = n;
				while (1) {
					if (t % i == 0) {
						t /= i;
					}
					else {
						break;
					}
				}
				if (t % i == 1) {
					ans++;
				}
			}
		}
	}
}




Measured memory_bytes: 256
# coding: utf-8
# 62

while True:
    KA = int(0)
    KB = int(0)
    r = input()
    if r=='0':
        break

    for i in range(1,len(r)):
        if r[i]=='A':
            KA += 1
        else:
            KB += 1
    if KA>KB:
        KA += 1
    elif KB>KA:
        KB += 1
    
    print(KA,KB)


Measured memory_bytes: 5564
from collections import deque
 
S = deque(list(input()))
Q = int(input())
rvs = False
 
for q in range(Q):
    query = list(input().split())
    if len(query) > 1:
        if query[1] == "1":
            if rvs:
                S.append(query[2])
            else:
                S.appendleft(query[2])
        elif query[1] == "2":
            if rvs:
                S.appendleft(query[2])
            else:
                S.append(query[2])
    else:
        rvs = not (rvs)
 
if rvs:
    S.reverse()
 
print("".join(S))

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

int main()
{
    int n;
    double s;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    s=a[0];
    for(int i=1;i<n;i++) {s=(s+a[i])*1.0/2;}
    cout<<s;
}


Measured memory_bytes: 256
import math
n = int(input())

insu = {}
for i in range(2, n + 1):
    count = 0
    for j in insu:
        while i % j == 0:
            count += 1
            if j in insu:
                insu[j] += 1
            else:
                insu[j] = 1
            i //= j
    if count == 0:
        insu[i] = 1

insu = sorted(insu.items(), key=lambda x: -x[1])

count = 0
debug = []
def dfs(now, conb, mst):
    global count, insu
    if len(conb) == len(mst):
        count += 1
        debug.append(conb)
    else:
        for i in range(now, len(insu)):
            if insu[i][1] >= mst[len(conb)]:
                dfs(i + 1, conb + [insu[i][0]], mst)
dfs(0, [], [74])
dfs(0, [], [24, 2])
dfs(0, [], [2, 24])
dfs(0, [], [14, 4])
dfs(0, [], [4, 14])
dfs(0, [], [2, 4, 4])
dfs(0, [], [4, 2, 4])
dfs(0, [], [4, 4, 2])
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

struct edge{
	ll to;
	ll cost;
};

vector<edge>g[110];

vector<P>used;

ll kaijo[500010];
void init() {
	kaijo[0] = 1;
	for (ll i = 1;i <= 500000;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}
 
ll inv(ll x,ll power) {
	ll res = 1;
	ll k = power;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}
 
ll Comb(ll n, ll k) {
	if (n < 0 || k < 0 || (n - k) < 0)return 0;
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd,N-2)) % N) % N;
}

int main(void){
	ll n,m;
	cin>>n>>m;
	init();
	ll res =(Comb(m,n)*kaijo[n])%N;
	ll ans = 0;
	for(ll i=0;i<=n;i++){
		ll tmp = Comb(n,i);
		tmp = (tmp*Comb(m-i,n-i))%N;
		tmp = (tmp*kaijo[n-i])%N;
		if(i%2==0){
			ans = (ans+tmp)%N;
			ans = (ans+N)%N;
		}
		else{
			ans = (ans-tmp)%N;
			ans = (ans+N)%N;
		}
	}
	cout<<(res*ans)%N<<endl;
    return 0;
}

Measured memory_bytes: 7520
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
bool is_prime(long long num) {
  if (num <= 1) return false;
  for (long long i = 2; i * i <= num; ++i) {
    if (num % i == 0) return false;
  }
  return true;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> ans;
  for (int i = 11; i <= 55555; i += 10) {
    if (is_prime(i)) ans.emplace_back(i);
    if (ans.size() == n) break;
  }
  REP(i, n) cout << ans[i] << (i == n - 1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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


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

   int a[n+2], b[n+1];

   for(int i = 1;i<=n+1;i++){
    cin >> a[i];
   } 
   for(int i = 1;i<=n;i++){
    cin >> b[i];
   }
   int ans  = 0;
   for(int i = 1;i<=n;i++){
    ans+=min(a[i], b[i]);
    b[i] -= min(b[i], a[i]);

    if(b[i]>0){
        
        ans+= min(a[i+1], b[i]);
        a[i+1] -= min(a[i+1],b[i]);
    }
   }
   cout << ans << endl;
}

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> vec(n);
    for (int i=0; i<n; i++){
        int a;
        cin >> a;
        vec[i] = make_pair(a, i+1);
    }
    sort(all(vec));
    rep(i, n) out(vec[i].second);
}

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

int main(){
  
  int a,b;
  cin>>a>>b;
  
  if(b==1){
    cout<<"0";
    return 0;
  }
  

  int  cnt=1;
    
  while(true){
       if(a+(a-1)*(cnt-1)>=b){
         cout<<cnt;
         return 0;
       }
      cnt++;
   }
 

  return 0;
}


Measured memory_bytes: 384
N,K=map(int, raw_input().split())
S=list(raw_input())

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

for i in range(1,min(K*2,l),2):
	s=L[i][0]
	if s=="L": L[i][0]="R"
	elif s=="R": L[i][0]="L"


ans=0
prev=None
for t in L:
	s=t[0]
	cnt=t[1]
	if prev is None:
		prev=s
		lcnt=cnt
	else:
		if prev==s:
			lcnt+=cnt
		elif prev!=s:
			ans+=(lcnt-1)
			lcnt=cnt
		prev=s
else:
	ans+=(lcnt-1)
	
print ans

Measured memory_bytes: 52956
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String str = scan.nextLine();
        String[] command = str.split(" ");

        String order = scan.nextLine();
        char[] cOrder = order.toCharArray();
        for(int i = 0; i < cOrder.length; i++){
            if(i == Integer.parseInt(command[1]) - 1 ){
                System.out.print(String.valueOf(cOrder[i]).toLowerCase());
                continue;
            }
            System.out.print(cOrder[i]);
        }
    }
}


Measured memory_bytes: 23636
package main

import "fmt"
import "sort"
func main() {
    

    a := make([]int, 3)
    for i := 0; i < 3; i++ {
      fmt.Scan(&a[i])
    }
    sort.Ints(a)
    
    if a[0] == 5 && a[1] == 5 && a[2] == 7 {
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }
    
    
}

Measured memory_bytes: 512
#n=int(input())
n,m,k=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
import bisect
A=[0]
for i in range(n):
    A.append(A[i]+al[i])
B=[0]
for i in range(m):
    B.append(B[i]+bl[i])
#B.append(max(B[m],k)+1)
mx=0
for i in range(n+1):
    rem=k-A[i]
    if rem<0:
        continue
    bnum=bisect.bisect_right(B,rem)-1
    mx=max(mx,i+bnum)

print(mx)


Measured memory_bytes: 47368
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string a;
  if(n==0){
    cout << 0 << endl;
    return 0;
  }
  while(n!=0){
    int num;
    if(n<0){
      num=(-n)%2;
      n=(1-n)/2;
    }else{
      num=n%2;
      n/=(-2);
    }
    a=to_string(num)+a;
  }

  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define K 10001

using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n;
	int *a = new int[2000001];
	int *b = new int[2000001];
	int *c = new int[K];
	cin >> n;
	for(int i = 0; i < K; i++){
		c[i] = 0;
	}
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++){
		c[a[i]]++; 
	}
	for(int i = 1; i <= K; i++){
		c[i] = c[i] + c[i - 1];
	}
	for(int i = n; i >= 1; i--){
		b[c[a[i]]] = a[i];
		c[a[i]]--;
	}
	for(int i =1; i < n; i++){
		cout << b[i] << " ";
	}
	cout << b[n ] << endl;
	delete[] a;
	delete[] b;
	delete[] c;
	return 0;
}

Measured memory_bytes: 16700
list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(list[k-1])

Measured memory_bytes: 2940