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

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define int long long
#define TEST_CASES int t = 1; cin >> t; while(t--)
#define printmap(mm) for(map<int,int>::iterator itr = mm.begin(); itr!=mm.end(); itr++) cout << itr->first << "->" << itr->second << " "; cout << endl;
#define iterm(mm) for(map<int,int>::iterator itr = mm.begin(); itr!=mm.end(); itr++)
#define N 200009


void read_file(){
	#ifndef ONLINE_JUDGE
	//freopen("/home/divakar/programs/input.txt","r",stdin);
	//freopen("/home/divakar/programs/output.txt","w",stdout);
	#endif
}
void init(){
	FAST_IO;
	read_file();
}

signed main(){
	init();

	//TEST_CASES
	{
		int n; cin >> n;
		int a[n];
		int b[n];
		int c[n];
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 0; i < n; i++) cin >> b[i];
		for(int i = 0; i < n-1; i++) cin >> c[i];

		int ans = 0;
	    for (int i = 0; i < n; ++i)
	    {
	    	ans+=b[i];
	    }
	   
	    for (int i = 0; i < n-1; ++i)
	    {
	    	if(a[i]==a[i+1]-1) ans+=c[a[i]-1];
	    }

	    cout << ans << endl;
		
	}


	




	return 0;
}

Measured memory_bytes: 256
//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

// Boost
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>

#define REP(I, LIM) for (int I = 0; I < (LIM); I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;
using boost::irange;
using boost::multiprecision::cpp_int;

typedef long long ll;

const int MOD = 1000000007;

vector<ll> divisor(ll &_n) {
  vector<ll> head, tail;
  for (long i = 1; i * i <= _n; i++) {
    if (_n % i == 0) {
      head.push_back(i);
      if (i * i != _n)
        tail.push_back(_n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return head;
}

ll kadanes(vector<ll> &_ls) {
  ll highestMax = 0, currentMax = 0, length = _ls.size();
  for (ll i = 0; i < length; i++) {
    currentMax = max(_ls[i], currentMax + _ls[i]);
    highestMax = max(highestMax, currentMax);
  }
  return highestMax;
}

class UnionFind {
public:
  vector<ll> par;

  UnionFind(ll N) : par(N) {
    for (ll i = 0; i < N; i++)
      par[i] = i;
  }
  ll root(ll x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }
  void unite(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if (rx == ry)
      return;
    par[rx] = ry;
  }
  bool same(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    return rx == ry;
  }
};

void execution();

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  // cout<<fixed<<setprecision(20);

  execution();
  return 0;
}

/*----------------------------*/

void execution(){
  bool a;
  cin >> a;
  cout<<!a<<"\n";
}


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

bool big_order(const int &a, const int &b) {return a > b;}
int main()
{
  int N;
  cin >> N;
  vector <int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end(), big_order);
  long long ans = 0;
  int use = 0;
  
  ans = A[0];
  use = 2;

  for (; use < N; use++) {
    ans += A[use/2];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
using namespace std;

int main(){
  vector< pair<int,int> > nu(3);
  vector<int> dp(4,0);
  rep(i,3){
    int a,b;
    cin >> a >> b;
    //小さい方がa
    if(a<=b){
      nu[i].first=a;
      nu[i].second=b;
    }else{
      nu[i].first=b;
      nu[i].second=a;
    }
    dp[nu[i].first-1]++;
    dp[nu[i].second-1]++;
    if(nu[i].first == nu[i].second){
      cout << "NO" << endl;
      return 0;
    }
  }
  sort(All(nu));
  rep(i,2){
    if(nu[i].first==nu[i+1].first&&nu[i].second==nu[i+1].second){
      cout << "NO" << endl;
      return 0;
    }
  }
  sort(All(dp));
  if(dp[0]==dp[1]&&dp[0]==1&&dp[2]==dp[3]&&dp[2]==2){
    cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string s;
	while (cin >> s) {
		int joi(0), ioi(0);
		for (int i = 0; i + 2 < s.size(); i++) {
			if (s.substr(i, 3) == "JOI")joi++;
			else if (s.substr(i, 3) == "IOI")ioi++;
		}
		cout << joi << endl << ioi << endl;
	}
	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N, K, A[5000];
bool dp[5001][5000];

bool ok(ll n) {
  REP(i, 0, N + 1) REP(j, 0, K) dp[i][j] = 0;
  dp[0][0] = 1;

  REP(i, 0, N) REP(j, 0, K) if(dp[i][j]) {
    dp[i + 1][j] = 1;
    if(i != n && j + A[i] < K) dp[i + 1][j + A[i]] = 1;
  }

  bool f = 0;
  REP(i, 0, K) if(dp[N][i] && i + A[n] >= K) f = 1;
  return f;
}

int main(void) {
  cin >> N >> K;
  REP(i, 0, N) cin >> A[i];

  sort(A, A + N);

  ll l = -1, h = N;
  while(h - l > 1) {
    ll m = (l + h) / 2;
    if(ok(m)) h = m;
    else l = m;
  }
  cout << h << endl;
}


Measured memory_bytes: 24704
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        long x = in.nl();
        long a = 100;
        int count = 0;
        while(a<x){
            a *= 1.01;
            count++;
        }
        out.println(count);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

int main() {
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
using namespace std;

int main(){
	int n, w, h;
	cin >> n >> w >> h;
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > qx, qy;
	for (int i = 0; i < n; ++i) {
		int cx, cy, cw;
		cin >> cx >> cy >> cw;
		qx.push(make_pair(cx, cw));
		qy.push(make_pair(cy, cw));
	}
	int flgx = 0;
	int flgy = 0;
	for (int i = 0; i < w; ++i) {
		for (; qx.size() != 0; qx.pop())
		if (i >= qx.top().first - qx.top().second &&
				i < qx.top().first + qx.top().second) {
			break;
		}
		if (qx.size() == 0) {
			flgx = 1;
			break;
		}
	}
	for (int i = 0; i < h; ++i) {
		for (; qy.size() != 0; qy.pop())
		if (i >= qy.top().first - qy.top().second &&
				i < qy.top().first + qy.top().second) {
			break;
		}
		if (qy.size() == 0) {
			flgy = 1;
			break;
		}
	}
	if (flgx == 1 && flgy == 1) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	string s;
	cin >> s;
	SORT(s);
	if(s[0] == s[1]  && s[1] != s[2] && s[2] == s[3]){
		coY();
		return 0;
	}
		coN();

}


Measured memory_bytes: 3644
#C
N=int(input())
al=[chr(ord('a') + i) for i in range(26)]

p=[]
q=[-1]
keta=1
for i in range(10**4):
    p.append(26**i)
    q.append(q[-1]+p[i])
    if q[i]>N-1:
        keta=i-1
        break
#print(q)
#print("keta:",keta)
r=N-q[i-1]-1
#print("r:",r)
ans=""

for i in range(keta-1,-1,-1):
    s= 26**i
    t=r//s
    #print(t)
    ans += al[t]
    r %= s
print(ans)

Measured memory_bytes: 9224
T = input()

tmp = []
for i in T:
    tmp.append(i)
    
import sys
    
if len(T) == 1:
    if T[0] == '?':
        print('D')
    else:
        print(T)
    sys.exit()
    
for i in range(len(tmp)):
    if tmp[i] == '?':
        tmp[i] = 'D'
        
print(''.join(tmp))    

Measured memory_bytes: 10988
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007; 
//解答写し KujouKaren
int pd[1100];
int main(){
  int n;
  cin>>n;
  for (int i=2;i<=n;i++){//素数でないものに1を入れる
    for (int j=i+i;j<=n;j+=i){
      pd[j]=1;
    }
  }
  int ans=1;
  for (int i=2;i<=n;i++){
	if (pd[i]==0){//iが素数のとき
      int tot=0;
	  for (int j=i;j<=n;j*=i)tot+=n/j;//1乗、2乗、3乗、4乗・・・で割れる数を足す
	  ans=1ll*ans*(tot+1)%MOD;
	}
  }
  cout<<ans<<endl;
  return 0;
}
     

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = -1;
    if ((a < 10) && (b < 10)) ans = a * b;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

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

    ll k = x / 11;
    ll ans = 2 * k;
    ll res = x % 11;

    if (res != 0) {
        ans++;
    }
    if (res > 6) {
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
#include <cstdlib>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>

#include <boost/algorithm/string/predicate.hpp>

using namespace std;

#if 0
// memo
abs()

start_with(str, "hoge");
ends_with(str, "hoge");

std::sort(d.begin(), d.end());
d.erase(std::unique(d.begin(), d.end()), d.end());
#endif

using namespace boost;
using namespace boost::algorithm;

static inline bool isOdd(int v)
{
    return v & 0x01;
}

int main()
{
    int N, M;
    scanf("%d%d", &N, &M);

    auto ret = abs(((long long)N - 2) * (M - 2));
    printf("%lld\n", ret);
    #if 0
    if (N>=2 && M >= 2) {
        printf("%d\n", (N-2)*(M-2));
    }
    else if (N>=2 && M==1) {
        printf("%d\n", N-2);
    }
    else if (N==1 && M >= 2) {
        printf("%d\n", M-2);
    }
    else {
        printf("1\n");
    }
    #endif
    
    return 0;
}


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

int main() {
    int n;
    __int128_t ans = 1;
    cin >> n;
    vector<long long> a(n);
    rep(i,n){
        cin >> a.at(i);
    }
    rep(i,n){
        if(a.at(i) == 0){
            cout << '0' << endl;
            return 0;
        }
    }
    rep(i,n){
        ans *= a.at(i);
        if(ans > 1'000'000'000'000'000'000){
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << long(ans) << endl;
}


Measured memory_bytes: 4056
#include <iostream>
using namespace std;
int main(){
    int a,b,q,n[6];
    for(int i=0;i<6;i++)cin>>n[i];
    cin>>q;
    for(int s=0;s<q;s++){
        cin>>a>>b;
        if(a==n[0]&&b==n[1])cout<<n[2]<<endl;
        if(a==n[0]&&b==n[2])cout<<n[4]<<endl;
        if(a==n[0]&&b==n[3])cout<<n[1]<<endl;
        if(a==n[0]&&b==n[4])cout<<n[3]<<endl;
        if(a==n[1]&&b==n[0])cout<<n[3]<<endl;
        if(a==n[1]&&b==n[2])cout<<n[0]<<endl;
        if(a==n[1]&&b==n[3])cout<<n[5]<<endl;
        if(a==n[1]&&b==n[5])cout<<n[2]<<endl;
        if(a==n[2]&&b==n[0])cout<<n[1]<<endl;
        if(a==n[2]&&b==n[1])cout<<n[5]<<endl;
        if(a==n[2]&&b==n[4])cout<<n[0]<<endl;
        if(a==n[2]&&b==n[5])cout<<n[4]<<endl;
        if(a==n[3]&&b==n[0])cout<<n[4]<<endl;
        if(a==n[3]&&b==n[1])cout<<n[0]<<endl;
        if(a==n[3]&&b==n[4])cout<<n[5]<<endl;
        if(a==n[3]&&b==n[5])cout<<n[1]<<endl;
        if(a==n[4]&&b==n[0])cout<<n[2]<<endl;
        if(a==n[4]&&b==n[2])cout<<n[5]<<endl;
        if(a==n[4]&&b==n[3])cout<<n[0]<<endl;
        if(a==n[4]&&b==n[5])cout<<n[3]<<endl;
        if(a==n[5]&&b==n[1])cout<<n[3]<<endl;
        if(a==n[5]&&b==n[2])cout<<n[1]<<endl;
        if(a==n[5]&&b==n[3])cout<<n[4]<<endl;
        if(a==n[5]&&b==n[4])cout<<n[2]<<endl;
        }return 0;
}



Measured memory_bytes: 3104
# coding: utf-8
def main():
    a,b,c = map(int, input().split())
    A = a*b
    B = b*c
    C = c*a
    if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
        print(0)
    else:
        print(min(A,B,C))

if __name__ == '__main__':
    main()

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

int main(int argc, const char * argv[]) {



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

    /////////////////////
    // Write code below /
    /////////////////////
    int n,a,ans[200000],i;

    for(i = 0;i < 200000;i++){
        ans[i] = 0;
    }

    cin >>n;
    for(i = 0;i < n-1;i++){
        cin >>a;
        ans[a-1]++;
    }
    for(i = 0;i < n;i++){
        cout <<ans[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 4436
#include <iostream>
#include<string>
#include<iomanip>
#define N 100
using namespace std;
int main(void) {
	int a[3];
	int b[3];
	int i;
	int o = 0;
	int t = 0;
	int s = 0;
	int f = 0;
	for (i = 0; i < 3; i++) {
		cin >> a[i];
		if (a[i] == 1)
			o++;
		if (a[i] == 2)
			t++;
		if (a[i] == 3)
			s++;
		if (a[i] == 4)
			f++;

		cin >> b[i];
		if (b[i] == 1)
			o++;
		if (b[i] == 2)
			t++;
		if (b[i] == 3)
			s++;
		if (b[i] == 4)
			f++;
				
	}
	if (o <= 2 && t <= 2 && s <= 2 && f <= 2)
		cout << "YES";
	else
		cout << "NO";

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
    int N, K;
    cin >>N>>K;
    vector<int> h(N);
    for (int i=0;i<N;++i) {
        cin >> h[i];
    }

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

    auto it = lower_bound(h.begin(),h.end(),K);
    cout << distance(it,h.end()) << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main (void){
        int N,K;
        long long int ans;
        long long int a;
        scanf("%d",&N);
        scanf("%d",&K);
        ans=0;
if (K%2==0) {
  a=N+K/2;
  a=a/K;
  a=a*a*a;
ans=a;
}
a=N/K;
a=a*a*a;
ans=ans+a;
printf("%lld\n",ans);
        return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

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

  if(b % 2 == 1) b -= 1;

  if(a > b / 2) {
    cout << b / 2 << endl;
    return 0;
  }

  long long int c = b - (a * 2);
  cout << a + (c / 4) << endl;
}


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

#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
#define MOD 1e9+7
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

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

//cout << fixed << setprecision(10) << y << endl;
struct edge {int to, cost;};
vector< vector<edge> > es;
const int MAX_N = 10010;
vector<bool> seen;
vl d; //部分木からの最小距離
int V, E;

int prim() {
    int res = 0;
    priority_queue< P, vector<P>, greater<P> > que;
    que.push(P(0, 0));
    d[0] = 0;
    while(!que.empty()) {
        P p = que.top(); que.pop();
        int u = p.second;
        if (seen[u]) continue;
        seen[u] = true;
        res += p.first;
        REP(i, (int)es[u].size()) {
            edge e = es[u][i];
            if (d[e.to] > e.cost) {
                d[e.to] = e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return res;
}
int main() {
    cin >> V >> E;
    es.resize(V);
    seen.resize(V, false);
    d.resize(V, INF);
    REP(i, E) {
        int s, t, w;
        cin >> s >> t >> w;
        es[s].push_back(edge{t, w});
        es[t].push_back(edge{s, w});
    }
    int res = prim();
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6300
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int mod = 1000000007;
int n;
int c[200000];
int fact[200001];
int factInv[200001];

int comb(int n, int k) {
	if (k > n) return 0;
	return fact[n] * factInv[n - k] % mod * factInv[k] % mod;
}

signed main() {
	int i, j;
	
	fact[0] = 1;
	factInv[0] = 1;
	rep(i, 200000) {
		fact[i + 1] = ((i + 1) * fact[i]) % mod;
		factInv[i + 1] = powmod(fact[i + 1], mod - 2, mod);
	}

	cin >> n;
	rep(i, n) cin >> c[i];
	sort(c, c + n, greater<int>());
	
	int ans = 0;
	rep(i, n) {
		int s = 0;
		/*rep(j, i + 1) {
			s += comb(i, j) * (j + 1);
			cout << "comb(" << i << ", " << j << ") * " << j + 1 << endl;
			s %= mod;
		}
		cout << s << endl;*/
		if (i >= 1) s = (i + 2) * powmod(2, i - 1, mod) % mod;
		else s = 1;
		ans += s * powmod(2, n - i - 1, mod) % mod * c[i] % mod;
		ans %= mod;
	}
	
	ans *= powmod(2, n, mod);
	ans %= mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

void selectionSort(int[],int);

int main(){
  int i,N;
  int A[100];
  
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&A[i]);
  selectionSort(A,N);
  
  return 0;
}

void selectionSort(int A[],int N){
  int i,j,count=0,minj,kari;

  for(i=0;i<N-1;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    kari = A[i];
    A[i] = A[minj];
    A[minj] = kari;
    if(minj != i)count++;
  }
  
  
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i != N-1)printf(" ");
  }
  printf("\n%d\n",count);
}
  



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

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	bool g[5][5];
	memset(g, false, sizeof(g));
	
	int a,b;
	for(int i = 0; i < 3; ++i){
		cin >> a >> b;
		g[a][b] = true;
		g[b][a] = true;
	}
	
	vector<int> per{1,2,3,4};
	do{
		bool can = true;
		for(int i = 0; i < 3 && can; ++i){
			if(!g[per[i]][per[i+1]])can = false;
		}
		
		if(can){
			cout << "YES" << endl;
			return 0;
		}
	}while(next_permutation(per.begin(), per.end()));
	
	cout << "NO" << endl;
	
    return 0;   
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
double v;
while(scanf("%lf",&v) != EOF){
double y=v*v/19.6;
int z=y;
if(y==z){
if(z%5==0){
    z=y/5+1;
printf("%d\n",z);
continue;
}
}
int q=y/5;
q += 2;
printf("%d\n",q);
}
return 0;
}

Measured memory_bytes: 1056
N=int(input())
C=list()
S=list()
F=list()
for i in range(N-1):
    a,b,c=map(int,input().split())
    C.append(a)
    S.append(b)
    F.append(c)

for i in range(N):
    time=0
    for j in range(i,N-1):
        if time<S[j]:
            time=S[j]
        elif time%F[j]==0:
            time=time
        else:
            time=time+F[j]-(time%F[j])
        time+=C[j]
    print(time)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

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

    int negc = 0;
    long long negs = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < 0) {
            negc++;
            negs += -a[i];
        }
    }

    int ans = negc;
    for (int i = n - 1; i >= 0 && a[i] > 0 && negs > 0; i--) {
        ans++;
        negs -= a[i];
    }

    if (negs > 0) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define P pair
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define endl '\n'

using namespace std;

typedef long long ll;
typedef P<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int32_t main()
{
	IO_OP;
	
	string s;
	cin >> s;
	if(s == "Sunny") cout << "Cloudy" << endl;
	if(s == "Cloudy") cout << "Rainy" << endl;
	if(s == "Rainy") cout << "Sunny" << endl;
}





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

void trace(const vector<int>& a) {
  for (auto it = a.begin(); it < a.end(); ++it) {
    cout << *it << ((it + 1 != a.end())? " " : "\n");
  }
}

int times = 0;
void merge(vector<int>& A, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  vector<int> L(n1 + 1);
  vector<int> R(n2 + 1);
  for (int i = 0; i < n1; ++i) L[i] = A[left + i];
  for (int i = 0; i < n2; ++i) R[i] = A[mid + i];
  L[n1] = R[n2] = INT_MAX;
  int i = 0, j = 0;
  for (int k = left; k < right; ++k) {
    ++times;
    if (L[i] <= R[j]) {
      A[k] = L[i];
      ++i;
    } else {
      A[k] = R[j];
      ++j;
    }
  }
}

void mergeSort(vector<int>& A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; ++i) cin >> S[i];
  mergeSort(S, 0, n);
  trace(S);
  cout << times << endl;
}



Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

    ll t[n + 1]; memset(t, -1, sizeof(t));

    rep(i, 2, n){
        if(t[i] == -1){
            for(ll j = 2; j * i <= n; j++){
                t[j * i] = i;
            }
        }
    }
    
    ll ans = 0;
    rep(i, 1, n - 1){
        if(i == 1){
            ans++;
        }else if(t[i] == -1){
            ans += 2;
        }else{
            map<ll, ll> mp;
            ll x = i;
            while(t[x] != -1){
                if(mp.find(t[x]) == mp.end()){
                    mp[t[x]] = 0;
                }
                mp[t[x]]++;
                x /= t[x];
            }
            if(mp.find(x) == mp.end()){
                mp[x] = 0;
            }
            mp[x]++;

            ll y = 1;
            for(auto it = mp.begin(); it != mp.end(); it++){
                y *= (*it).second + 1;
            }

            ans += y;
        }
    }
    print(ans)

    return 0;
}

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

for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            pass
        else:
            print('DENIED')
            exit()
    else:
        pass
print('APPROVED')

Measured memory_bytes: 2940
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(' ').let { it[0].toInt() to it[1].toLong() }
    val a = readLine()!!.split(' ').map { it.toLong() }
    val b = LongArray(n)
    for (i in 0 until n - 1) {
        b[i] = a[i] + a[i + 1]
    }
    var ans = 0L
    for (i in 0 until n - 1) {
        val y = Math.max(b[i] - x, 0)
        ans += y
        b[i + 1] -= Math.min(y, a[i + 1])
    }
    println(ans)
}


Measured memory_bytes: 68480
// 間を区切ってdifでソート
// 雑な方針で進めて途中でリファクタリングしながらしたんで最初からこの形がみえていたわけではない
package main
import (
	"fmt"
	"sort"
)
func main(){
	var K, N  int
	fmt.Scan(&K, &N)
	if K>=N{
		fmt.Println(0)
		return
	}
	A := make([]int, N)
	for i:=0; i<N; i++{
		fmt.Scan(&A[i])
	}
	sort.Ints(A)
	difs := make([][2]int, N-1)
	for i:=0; i<N-1; i++{
		difs[i] = [2]int{i, abs(A[i]-A[i+1])}
	}
	sort.Slice(difs, func(i, j int)bool{
		return  difs[i][1] > difs[j][1]
	})
	splits := make(map[int]bool)
	for _, dif := range difs[:K-1]{
		splits[dif[0]] = true
	}
	ans := 0
	for i:=0; i<N-1; i++{
		if !splits[i]{
			ans += A[i+1]-A[i]
		}
	}
	fmt.Println(ans)
}

func abs(x int)int{
	if x < 0{
		return x*-1
	}
	return x
}

Measured memory_bytes: 9608
#include<stdio.h>
 int main(){
 int a[100][100],b[100][100],i,j,k,n,m,l,x;
 long long int c[100][100]={0};
 scanf("%d %d %d",&n,&m,&l);
 
 for(i=0;i<n;i++){
 for(j=0;j<m;j++){
 scanf("%d",&x);
 a[i][j]=x;
 }
 }
 
 
 for(j=0;j<m;j++){
 for(k=0;k<l;k++){
 scanf("%d",&x);
 b[j][k]=x;
 }
 }
 
 for(i=0;i<n;i++){
 for(k=0;k<l;k++){
 for(j=0;j<m;j++){
 c[i][k]+=a[i][j]*b[j][k];
 }
 }
 }
 
 for(i=0;i<n;i++){
 for(k=0;k<l;k++){
 printf("%lld",c[i][k]);
 
if(k!=l-1)
{
    printf(" ");
}
 }
 printf("\n");
 }
 
 return 0;
 }

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll n, p;
    cin>>n>>p;
    string str;
    cin>>str;
    vl a(p);
    a[0]++;
    ll pow_of_ten=1;
    ll suff=0;
    ll ans=0;
    if(p==2)
    {
        forr(i, n)
        {
            ll dig=str[i]-'0';
            if(dig%2==0)
            {
                ans+=(i+1);
            }
        }
        cout<<ans;
        return;
    }
    if(p==5)
    {
        forr(i, n)
        {
            ll dig=str[i]-'0';
            if(dig%5==0)
            {
                ans+=(i+1);
            }
        }
        cout<<ans;
        return;
    }
    for(ll i=n-1; i>=0; i--)
    {
        ll dig=str[i]-'0';
        suff=((dig*pow_of_ten)+suff)%p;
        pow_of_ten=pow_of_ten*10%p;
        ans+=a[suff];
        a[suff]++;
    }
    //for(ll i=0; i<n; i++)
    cout<<ans;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 640
n, x = input().split()
n = int(n)
x = int (x)
m = []
i_min = 0 
result = 0

for i in range(n):
 m.append(int(input()))

for i in range(len(m)):
 x = x - m[i]
 result = result + 1

for i in range(len(m)):
 if m[i_min] > m[i]:
   i_min = i

for i in range(x):
 if x >= m[i_min]:
  result = result + 1
  x = x - m[i_min]
 else:
  break

print(result)

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

int main() {
  int N;
  cin >> N;
  int C[N-1], S[N-1], F[N-1];
  for (int i = 0; i < N-1; i++)
    cin >> C[i] >> S[i] >> F[i];
  for (int i = 0; i < N; i++) {
    int t = 0;
    for (int j = i; j < N-1; j++) {
      if (t < S[j]) t = S[j];
      else if (t%F[j] == 0);
      else t = t+F[j] - t%F[j];
      t+=C[j];
    }
    cout << t << endl;
  }
  return 0;
}



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

using namespace std;

const int maxn=2e5;
int n,t,pos;
int a[maxn+5];

int main(){
	scanf("%d %d",&n,&t);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		}
		if(n==1)  pos = t;
		else if(n>1){
			pos = t;
		for(int i=2;i<=n;i++){
			if(a[i]-a[i-1]<t){
				pos = pos + a[i]-a[i-1];
				}
				else if(a[i]-a[i-1]>=t){
					pos=pos+t;
					}
			}
		}
	    printf("%d",pos);
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main{


    static int f(int x){
    return x*x;
}

    
    
    public  static void main(String[] args)throws IOException{
	InputStreamReader isr = new InputStreamReader(System.in);
	BufferedReader br=new BufferedReader(isr);
	String std = br.readLine();
	while(std!=null){
	int d=Integer.parseInt(std);
	int integral=0;
	for(int i=d;i<600;i+=d)
	    integral=integral+f(i)*d;
	System.out.println(integral);
	std = br.readLine();
	}
    }
}
	

Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {
	uint N;
	cin >> N;
	
	vector<uint> A(N);
	
	for(uint i=0; i<N; i++) {
		cin >> A[i];
	}
	
	sort(A.begin(), A.end());
	
	for(uint i=1; i<N; i++) {
		if(A[i] == A[i-1]) {
			cout << "NO";
			return 0;
		}
	}
	
	cout << "YES";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;

const int mo = 1e9 + 7;
const int maxn = 1e5 + 2;

int n;
long long f[maxn][2];
vector<vector<int> > g;

void dfs(int u, int pre) {

	f[u][0] = f[u][1] = 1;

	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i];
		if (v != pre) {
			dfs(v, u);

			f[u][0] *= (f[v][0] + f[v][1]);
			f[u][0] %= mo;

			f[u][1] *= f[v][0];
			f[u][1] %= mo;
		}
	}
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	g = vector<vector<int> >(n);

	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;

		g[u].push_back(v);
		g[v].push_back(u);
	}

	dfs(0, -1);

	// for (int i = 0; i < n; ++i)
	// {
	// 	printf("%d:%d %d\n", i+1, f[i][0], f[i][1]);
	// }

	cout << (f[0][0] + f[0][1])%mo << endl;

	return 0;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 110;
const int M = 100010;
ll w[N], v[N];
ll dp[N][M];
int n, W;

int main() {
    cin >> n >> W;
    for(int i = 1; i <= n; i ++) {
        cin >> w[i] >> v[i];
    }
    for(int i = 1; i <= n; i ++) {
        for(int j = 0; j <= W; j ++) {
            dp[i][j] = dp[i-1][j];
            if(j >= w[i]) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 79360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(n);i++)
#define fori(a,b,i) for(int i=(a);i<=(b);i++)
#define ford(a,b,i) for(int i=(a);i>=(b);i--)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
typedef long long int llint;


int main(){
	double a, b, h, m;
	cin>>a>>b>>h>>m;
	// min -> 60 -> 360
	// hour -> 24*60 -> 360
	//m = m + (h * 60);
	double a1 = 2 * PI * (h/12 + (m/(60*12))), a2 = 2 * PI * m/60;
	//(long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
	//cout<< (long double)(a * a + b * b) - (2 * a *b) * cosl(a1 - a2);
	//cout<<endl;
	//cout<<(double)sqrt(a*a + b*b  - 2*cosl(a1 - a2)*a*b);
	//long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
	long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *b) * cosl(a1 - a2);
	
	printf("%20.20Lf\n", sqrtl(rsq));
	return 0;
}


Measured memory_bytes: 4128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

int main(){
    int x,y;
    cin >> x >> y;
    int p = 4*x -y;
    int q = y - 2*x;
    if(p<0||q<0){
        cout <<"No"<< endl;
        return 0;
    }
    if(p%2!=0||q%2!=0){
        cout << "No" << endl;
        return 0;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3624
def main():
    n, k = map(int, input().split())
    lim = (n-2)*(n-1)//2
    if lim < k:
        print(-1)
    else:
        ans = []
        for i in range(2, n+1):
            ans.append([1, i])
        x = lim
        for i in range(2, n):
            for j in range(i+1, n+1):
                if x == k:
                    break
                ans.append([i, j])
                x -= 1
            if x == k:
                break
        print(len(ans))
        for u, v in ans:
            print(u, v)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9340
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 4) --> {1,2,3,4}
// rep(i, 4, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll l0 = 2;
    ll l1 = 1;
    if (n==1)
        return cout << 1, 0;
    ll li;
    rep(i, 2, n+1)
    {
        li = l0 + l1;
        l0 = l1;
        l1 = li;
    }
    cout << li;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
string s;
signed main(){
	cin>>s;
	int x=-1,y=-1;
	rep(i,s.size()){
		if(s[i]=='A'&&x==-1)x=i;
		if(x!=-1){
			if(s[i]=='Z')y=i;
		}
	}
	cout<<y-x+1<<endl;
	return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll a,b,h,m;
  cin>>a>>b>>h>>m;

  double d = abs((h+(double)m/60)*5-m);
  if(d > 30) d = 60.0 - d;
  double r = M_PI * d / 30.0;
  double cs = cos(r);

  double ans = a*a + b*b -(a*b*2*cs);
  ans = sqrt(ans);
  cout<<fixed<<setprecision(20)<<ans<<endl;
}

Measured memory_bytes: 4184
from collections import OrderedDict

cards = OrderedDict()
for s in ['S', 'H', 'C', 'D']:
    for r in range(1, 13 + 1):
        key = "{} {}".format(s, r)
        cards[key] = False

count = int(input())

for n in range(count):
    input_key = input()
    cards[input_key] = not(cards[input_key])

for k, v in cards.items():
    if not v:
        print(k)

Measured memory_bytes: 8024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pow_mod(ll fi,ll se,ll mod){
  if(se==0){
    return 1;
  }
  if(se%2){
    return pow_mod(fi,se-1,mod)*fi%mod;
  }
  ll t=pow_mod(fi,se/2,mod);
  return t*t%mod;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

vector<pair<int,int>> Dir={{-1,0},{1,0},{0,1},{0,-1}};
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/



int main(){
  ll n;
  cin>>n;
  vector<string> s(n);
  ll cnt=0;
  ll cnt2=0;
  ll cnt3=0;
  ll ans=0;
  rep(i,n){
    cin>>s[i];
    char pre;
    repf(j,1,s[i].size()){
      if(s[i][j-1]=='A'&&s[i][j]=='B')ans++;
    }
    if(s[i][s[i].size()-1]=='A'&&s[i][0]=='B')cnt++;
    else if(s[i][s[i].size()-1]=='A')cnt2++;
    else if(s[i][0]=='B')cnt3++;
  }
  if(cnt2>cnt3){
    ans+=cnt3;
    ans+=cnt;
  }else if(cnt3>cnt2){
    ans+=cnt2;
    ans+=cnt;
  }else {
    if(cnt){
      ans+=cnt-1;
      if(cnt2){
        ans+=cnt2;
        ans++;
      }
    }
    else {ans+=cnt2;}
  }
  op(ans);
  return 0;
}

Measured memory_bytes: 768
import java.util.*;
import java.text.*;
public class Main {
	public static void main(String[] args) {
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	double JPYcnt = 0;
      	double BTCcnt = 0;
      	for(int i=0;i<N;i++){
        	double x = sc.nextDouble();
          	String u =sc.next();
          	if(u.equals("JPY")){
            	JPYcnt += x;
            }else{
            	BTCcnt += x;
            }
        }
      	System.out.println(JPYcnt+BTCcnt*380000.0);
    }
}

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

using namespace std;

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

char s[1005][1005];
int d[1005][1005];

int main() {
   int n, m;
   scanf("%d %d", &n, &m);
   queue<pair<int, int>> q;
   for (int i = 1; i <= n; ++i) {
      scanf("%s", s[i] + 1);
      for (int j = 1; j <= m; ++j) {
         if (s[i][j] == '.') d[i][j] = -1;
         else { d[i][j] = 0; q.push({i, j}); }
      }
   }
   int ans = 0;
   while (!q.empty()) {
      int x = q.front().first, y = q.front().second;
      q.pop();
      ans = max(ans, d[x][y]);
      for (int i = 0; i < 4; ++i) {
         int xx = x + dx[i], yy = y + dy[i];
         if (xx <= 0 || xx > n || yy <= 0 || yy > m) continue;
         if (d[xx][yy] == -1) {
            d[xx][yy] = d[x][y] + 1;
            q.push({xx, yy});
         }
      }
   }
   printf("%d\n", ans);
}


Measured memory_bytes: 13328
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

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

int main()
{
    long long  t;
    //int n=100;
    cin>>t;
    vector<long long> a(t+1,0);
    //int x=1,y=1,z=1;
    
        for(int x=1;x*x<=t;x++)
        {
            for(int y=1;y*y<=t;y++)
            {
                for(int z=1;z*z<=t;z++)
                {
                    
                    if(x*x+y*y+z*z+x*y+y*z+x*z<=t){
          a[x*x+y*y+z*z+x*y+y*z+x*z]++;}
          else
          break;
                }
            }
        }    
        // for(int i=1;i<=n;i++)
        // {
            
        //     int k=(i+i)*(i+i)+(i+i)*(i+i)+(i+i)*(i+i);
        //     a[k/2]++;
            
            
        // }
        
    //int t;
    //cin>>t;
    for(long long  i=1;i<=t;i++)
    {
        cout<<a[i]<<"\n";
    }
    
    

    return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
int num;
int pre[40],in[40];
void post(int l,int r)
{
	if(l>r)return;
	/*if(l==r)
	{
	if(in[l]==pre[0])
	printf("%d",in[l]);
	else
	printf("%d ",in[l]);
	num++;
	return;		
	}*/
	int x=pre[num],i;
	num++;
	for(i=l;i<=r;i++)
	if(in[i]==x)
	break;
	post(l,i-1);
	post(i+1,r);
	if(x==pre[0])
	printf("%d",x);
	else
	printf("%d ",x);	
}
int main(int argc, char *argv[])
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&pre[i]);
	for(i=0;i<n;i++)
	scanf("%d",&in[i]);
	num=0;
	post(0,n-1);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,i,j,t,k;
ll a,b,c,d;
char A,C,X,Y,Z;
ll ans,MAX,MIN;
ll ax[2000500];
char cx[10000];
ll dx[12];
ll bx[2000500];
const int N = (1 << 20) + 10;

bool cmp(ll x,ll y)
{
    return x>y;
}

int main()
{
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld%lld",&n,&k);
        while(n>k)
        {
            n=n-(n/k)*k;
        }
        if(n>k-n) cout << k-n <<endl;
        else cout << n;
    }
	return 0;
}

Measured memory_bytes: 256
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 

 
void solve()
{
	string s , t; 
	cin>>s>>t;  
	int a ,b ; 
	cin>>a>>b;
	string u ; 
	cin>>u ;
	if(u==s){
		cout<<a-1<<" "<<b; 
	}
	else{
		cout<<a<<" "<<b-1;
	}
}
 
int main() {
    // #ifndef ONLINE_JUDGE
    //     // for getting input from input.txt
    //     freopen("input.txt", "r", stdin);
    //     // for writing output to output.txt
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    // ios_base::sync_with_stdio(0);
    // cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 256