akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, K;
	vector<int> A, B;
	int ans = 0;
	
	cin>>N>>K;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		B = A;
	}
	
	sort(B.begin(), B.end());
	
	
	for(int i = 0; i < N; i++){
		int con1 = 0, con2 = 0;
		
		for(int j = 0; j < N; j++){
			if(A[j] < A[i]) con1++;
		}
		for(int j = i+1; j < N; j++){
			if(A[j] < A[i]) con2++;
		}
		
		// cout<<con1<<" * "<<(K*(K-1)/2)<<" + "<<con2<<" * "<<K<<endl;
		// cout<<(K*(K-1)/2)%MOD*con1%MOD + con2*K%MOD<<endl;
		ans += (K*(K-1)/2)%MOD*con1%MOD + con2*K%MOD;
		ans %= MOD;
	}
	
	cout<<ans<<endl;
	return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T>
T SUM(V<T> v, T init_val=0){return accumulate(ALL(v),T(init_val));}

int main(){
    int n,l;
    cin>>n>>l;

    Vi aji;
    REP(i,n){
        aji.pb(l+i);
    }

    int eat=0;
    if(aji[0]>0){
        eat = aji[0];
    }else if(aji[aji.size()-1]<0){
        eat = aji[aji.size()-1];
    }

    cout<<SUM(aji)-eat<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main (void)
{
    int H,W,i,j;
    while(1)
    {
        scanf("%d %d",&H,&W);
        if (H==0 && W==0) break;

        else for(i=0;i<H;i++)
        {
            for(j=0;j<W;j++)
            {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	string s;
	cin >> s;
	if (s.front() == '>') s = '<' + s;
	if (s.back() == '<') s += '>';

	vector<int> a(s.size() + 1);
	for (int i = 0; i < (int)s.size() - 1; i++) {
		if (s[i] == '<') a[i + 1] = a[i] + 1;
	}
	for (int i = (int)s.size() - 1; i >= 0; i--) {
		if (s[i] == '>') a[i] = max(a[i + 1] + 1, a[i]);
	}
	
	cout << accumulate(a.begin(), a.end(), 0LL) << "\n";

	return 0;
}

Measured memory_bytes: 2864
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	long long n, ans, rest;
	cin >> n;
	ans = (n / 11) * 2;
	rest = n % 11;
	if (rest != 0) {
		if (rest > 6)
			ans += 2;
		else ans++;
	}
	printf("%lld\n", ans);
    return 0;
}

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

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

    int count = 0,next = 1;

    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
    }


    rep(i,n){
        next = a.at(next - 1); 
        count ++;
        if(next == 2){
            cout << count << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;


    
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>

void test_case()
{
    int n;
    string s,ans;
    cin>>n>>s;
    int i=0;
    while(i<n) {
        if(i+1<n && s[i]==s[i+1]) {
            ans+=s[i];
            char c=s[i];
            while(i<n && s[i]==c)
                i++;
        } else {
            ans+=s[i];
            i++;
        }
    }
    cout<<ans.size();
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


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

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

    vector<int>a(n);
    rep(i,0,n){
        cin>>a[i];
    }

    sort(a.begin(),a.end());
    cout<<a[a.size()-1]-a[0]<<endl;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

def modpow(n, p, m):
    if p == 0:
        return 1
    if p % 2 == 0:
        t = modpow(n, p // 2, m)
        return t * t % m
    return n * modpow(n, p - 1, m) % m

n = ni()

A = modpow(9, n, mod)
B = A
C = modpow(8, n, mod)
D = modpow(10, n, mod)

ans = (D - A - B + C) % mod

print(ans)

Measured memory_bytes: 9292
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;

int w[100], v[100];
int n, W;
long long dp[101][100001];

//long long solve(int i, int j)
//{
//	if (dp[i][j] != -1)
//		return dp[i][j];
//	long long res;
//	if (i == n)
//		res = 0;
//	else if (j < w[i])
//		res = solve(i + 1, j);
//	else 
//		res = max(solve(i + 1, j), solve(i + 1, j - w[i])+v[i]);
//	return dp[i][j] = res;
//}

int main()
{
	cin >> n >> W;
	for (int i = 0; i < n; i++)
		cin >> w[i] >> v[i];
	//memset(dp, -1, sizeof(dp));

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

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

const int maxn=2e5+10;
int a[maxn],sum[maxn];

int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    for(int i=1;i<=n;i++)
        sum[i]=sum[i-1]+(abs(a[i]-a[i-1]));
    sum[n+1]=sum[n]+abs(a[0]-a[n]);
    for(int i=1;i<=n;i++)
        cout << sum[i-1]+sum[n+1]-sum[i+1]+abs(a[i-1]-a[i+1]) << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main(){
  int n,k,i,ans=0;
  cin >> n >> k;
  int x;
  for(i=0;i<n;i++){
    cin >> x;
    if(x>k-x)ans+=(k-x)*2;
    else ans+=x*2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template <typename T>
    debugger &operator,(const T &v)
    {
        cerr << v << " ";
        return *this;
    }
} dbg;

void solve(long long N, vector<long long> A)
{
    int cnt = 0, last = -1;
    int fx = 0;
    for (auto i : A) {
        if (last == -1) {
            last = i;
            ++cnt;
            fx = 0;
        } else {
            if (fx == 0) {
                if (i == last)
                    fx = 0;
                else
                    fx = i > last ? 1 : -1;
                last = i;
            } else if (fx == -1) {
                if (i > last) {
                    last = i;
                    fx = 0;
                    ++cnt;
                } else {
                    last = i;
                }
            } else {
                if (i < last) {
                    last = i;
                    fx = 0;
                    ++cnt;
                } else {
                    last = i;
                }
            }
        }
    }
    cout << cnt << endl;
}

int main()
{
#ifdef WAAUTOMATON
    freopen("subtask_1_07.txt", "r", stdin);
#endif
    long long N;
    scanf("%lld", &N);
    vector<long long> A(N - 1 + 1);
    for (int i = 0; i <= N - 1; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, A);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,i,ma=0;
    map<string,int> v;
    string s;
    map<string,int>::iterator itr;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s;
        v[s]++;
    }

    for(itr=v.begin();itr!=v.end();itr++)
        {
            ma=max(ma,itr->second);
        }
     for(itr=v.begin();itr!=v.end();itr++)
     {
         if(itr->second==ma)
            cout<<itr->first<<"\n";
     }
  return 0;
}


Measured memory_bytes: 25216
import java.math.BigInteger;
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        
        if (A > B || (N == 1 && A != B)) {
        	System.out.println(0);
        	return;
        }
        
        //処理
        if (N == 2) {
        	System.out.println(3);
        	return;
        }
        N -=2;
        
        String ans = BigInteger.valueOf(B).multiply(BigInteger.valueOf(N)).subtract(BigInteger.valueOf(A).multiply(BigInteger.valueOf(N))).add(BigInteger.ONE).toString(10);
        
        System.out.println(ans);
    }
}



Measured memory_bytes: 22740
#include <stdio.h>

int main()
{
  int i, j, k, n, x;
  int count = 0;

  for( ; ; )
  {
    scanf("%d %d", &n, &x);
    if( n == 0 && x == 0 )
      break;
    for( i = 1 ; i <= n ; i++ )
    {
      for( j = i + 1 ; j <= n ; j++ )
      {
        for( k = j + 1 ; k <= n ; k++ )
        {
          if( i + j + k == x )
            count += 1;
        }
      }
    }
    printf("%d\n", count);
    count = 0;
  }
}



Measured memory_bytes: 2084
#include <iostream>

int main()
{
    while(true)
    {
        int m,f,r;
        std::cin >> m >> f >> r;
        
        if(m==-1 && f==-1 && r==-1) break;
        
        if(m==-1 || f==-1)          std::cout << "F" << std::endl;
        else if(m+f >= 80)          std::cout << "A" << std::endl;
        else if(m+f >= 65)          std::cout << "B" << std::endl;
        else if(m+f>=50 || r>=50)   std::cout << "C" << std::endl;
        else if(m+f >= 30)          std::cout << "D" << std::endl;
        else                        std::cout << "F" << std::endl;
    }
}


Measured memory_bytes: 3100
#include <iostream>
#include <numeric>
#include <vector>
#include <bitset>
using namespace std;

int main() {
    string s;
    cin >> s;
    long long result = 0;
    for (int i = 0; i < 1 << (s.size() - 1); i++) {
        bitset<32> bits(i);
        vector<long long> v;
        int last = -1;
        for (int j = 0; j < s.size() - 1; j++) {
            if (bits[j]) {
                v.emplace_back(stoll(s.substr(last + 1, j - last)));
                last = j;
            }
        }
        v.emplace_back(stoll(s.substr(last + 1)));
        result += accumulate(begin(v), end(v), 0ll);
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int max = 2000001;
    static int[] T = new int[max];
    static int H = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String oper;
        while (true){
            oper = sc.next();
            if("end".equals(oper)){
                break;
            }
            else if("insert".equals(oper)){
                int v = sc.nextInt();
                insert(v);
            }
            else if("extract".equals(oper)){
                System.out.println(extractX());
            }
        }
    }


    static void insert(int key){
        H++;
        heapIncreaseKey(key,H);

    }


    static void heapIncreaseKey(int key,int i){
        if(key < 0){
            return;
        }
        T[i] = key;
        while (i > 1 && T[i/2] < key){
            T[i] = T[i/2];
            T[i/2] = key;
            i = i/2;
        }
    }


    static int extractX(){
        if(H < 1) return -1;

        int max = T[1];
        T[1] = T[H];
        H--;
        maxHeapify(1);
        return max;
    }



    static void maxHeapify(int i){
        while (i <= H){
            int l = left(i);
            int r = right(i);
            int largest = i;
            if(l <= H && T[i] < T[l]){
                largest = l;
            }
            if(r <= H && T[largest] < T[r]){
                largest = r;
            }

            if(largest != i){
                int v = T[i];
                T[i] = T[largest];
                T[largest] = v;
//                maxHeapify(largest);
                i = largest;
            }else{
                break;
            }
        }

    }

    static int left(int u){
        return 2 * u;
    }

    static int right(int u){
        return 2 * u + 1;
    }
}



Measured memory_bytes: 557628
def main():
    N, K, Q = input_int_tuple()
    A = []
    for _ in range(Q):
        A.append(input_int())

    points = [0] * (N+1)

    for a in A:
        points[a] += 1

    for point in points[1:]:
        if K - (Q - point) > 0:
            print('Yes')
        else:
            print('No')


def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


def input_int_list():
    return list(map(int, input().split()))


main()


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

int main() {
  int R = 700;
  string s;
  cin >>s;
    
  int topping;
  
  if(s[0]=='o')++topping;
  if(s[1]=='o')++topping;
  if(s[2]=='o')++topping;
 
  int kingaku = R+(topping*100);
  cout<<kingaku<<endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in(),k=in();
    vector<ll>a(n);for(ll i=0;i<n;++i)a[i]=in();
    for(ll i=k+1;i<=n;++i)cout<<(a[i-(k+1)]<a[i-1]?"Yes":"No")<<endl;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll int N;
    cin >> N;
    ll int g = 0;
    ll int A[N], B[N];
    ll int f = 0;
    rep(i, N) {
        cin >> A[i];
        if(A[i] < 0) {
            B[i] = - A[i];
            g ++;

        }
        else B[i] = A[i];
        f += B[i];

    }

    if(g % 2 == 0) cout<< f << endl;
    else{
        sort(B, B+ N);

        cout << f - 2 * B[0] << endl;

    }


}

Measured memory_bytes: 1920
def prime_factor(n):
    ret = {}
    p = 2

    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1

    if n != 1: ret[n] = 1

    return ret

n = int(input())
d = {}

for i in range(2, n+1):
    t = prime_factor(i)
    for k, v in t.items():
        d[k] = d.get(k, 0) + v

ans = 1
mod = int(1e9) + 7

for _, v in d.items():
    ans *= (v+1)
    ans %= mod

print(ans)


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

long long N, MA, MB;
long long a[50];
long long b[50];
long long c[50];
long long dp[1000][1000];

int main(){
	cin >> N >> MA >> MB;

	for(long long i = 0; i < N; i++){
		cin >> a[i] >> b[i] >> c[i];
	}

	for(long long i = 0; i < 1000; i++)
		for(long long j = 0; j < 1000; j++)
			dp[i][j] = INT_MAX;

	dp[0][0] = 0;

	for(long long i = 0; i < N; i++){
		for(long long x = 999; x >= 0; x--){
			for(long long y = 999; y >= 0; y--){
				if(dp[x][y] != INT_MAX){
					if(x + a[i] < 1000 & y + b[i] < 1000){
						dp[x + a[i]][y + b[i]] = min(dp[x + a[i]][y + b[i]], dp[x][y] + c[i]);
					}
				}
			}
		}
	}

	long long ans = INT_MAX;

	for(long long i = 1; i < 1000; i++){
		for(long long j = 1; j < 1000; j++){
			if(i%MA == 0 && j%MB == 0 && i/MA == j/MB){
				ans = min(ans, dp[i][j]);
			}
		}
	}
	if(ans == INT_MAX){
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
}


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

int main(void){
    int N, x;
    int move_count = 0;
    int max_move = 0;
    int now_height, before_height;
    cin >> N;
    cin >> before_height;
    for(int i = 0;i < N - 1;i++){
        cin >> now_height;
        if(now_height > before_height){
            if(max_move < move_count) max_move = move_count;
            move_count = 0;
        }else{
            move_count++;
        }
        before_height = now_height;
    }
    if(max_move < move_count) max_move = move_count;
    cout << max_move << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
    int R;
    cin >> R;
    if (R < 1200) cout << "ABC" << endl;
    else if (R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#pragma GCC optimize("Ofast")
using namespace std;
ll int BtoPmodM(ll int b, ll int p, ll int m) { // (b ^ p) % m (Big Mod)
    if (p == 0) return 1;
    else if (p % 2 == 0) return (BtoPmodM(b, p / 2, m) * BtoPmodM(b, p / 2, m)) % m; // a^(p/2) * a^(p/2) = a^p
    else if (p % 2 == 1) return (BtoPmodM(b, (p - 1) / 2, m) * BtoPmodM(b, (p - 1) / 2, m) * b) % m; // +1
    else return 0; // a function must return something
}
ll int euclidalgo(ll int a, ll int b) { // Euclidean Algorithm
    if (b == 0) {
        return a;
    } else {
        return euclidalgo(b,a % b);
    }
}
bool coprime(ll int a, ll int b) {
    if (euclidalgo(a, b) == 1) return true;
    else return false;
}
ll int factModP(ll int n, ll int p) {
    ll int fac[n - 1];
    fac[0] = 1;
    for (ll int i = 1;i <= n;i++) {
        fac[i] = fac[i - 1] * i % p;
    }
    return fac[n];
}
ll int nCrModP(ll int n, ll int r, ll int p) {
    if (r == 0) return 1;
    ll int fac[n + 1];
    fac[0] = 1;
    for (ll int i = 1;i <= n;i++) {
        fac[i] = fac[i - 1] * i % p;
    }
    return (fac[n] * BtoPmodM(fac[r], p - 2, p) % p * BtoPmodM(fac[n - r], p - 2, p) % p) % p;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int n;
    cin >> n;
    double x = n / 3.0;
    x = pow(x, 3);
    cout << setprecision(10) << fixed << x << endl;
}

Measured memory_bytes: 512
n = gets.to_i
order = gets.split(' ').map(&:to_i)
points = gets.split(' ').map(&:to_i)
extra = gets.split(' ').map(&:to_i)
sum = 0
n.times do |a|
    if a == 0
        sum = sum + points[order[a]-1]
    else 
        if order[a-1] == order[a]-1
            sum = sum + points[order[a]-1] + extra[order[a]-2]
        else
            sum = sum + points[order[a]-1] 
        end
    end
end
puts sum



Measured memory_bytes: 1788
#include <iostream>

int main() {

    int N, V[20], C[20];
    int i, j;
    int ans = 0;

    std::cin >> N;

    for (i=0; i<N; i++)
    {
        std::cin >> V[i];
    }
    for (i=0; i<N; i++)
    {
        std::cin >> C[i];
        if(V[i]-C[i] > 0)
        {
            ans += V[i]-C[i];
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
S = input()

res = 0
if S[0] == 'p':
    res -= 1
p = 0
g = 1
for i in range(1, len(S)):
    if S[i] == 'p' and p < g:
        p += 1
    elif S[i] == 'p' and p >= g:
        g += 1
        res -= 1
    elif S[i] == 'g' and p < g:
        p += 1
        res += 1
    else:
        g += 1
            
print(res)

Measured memory_bytes: 3316
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    ll h, w; cin>>h>>w;

    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }

    if((h * w) % 2 == 0){
        cout << h * w / 2 << endl;
        return 0;
    }

    cout << (h * w) / 2 + 1 << endl;

    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    set<int> st;
    map<int, int> mp;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        st.insert(v[i]);
        mp[v[i]]++;

    }

    LL res = 0;
    for(auto it = st.begin(); it != st.end(); ++it) {
        LL t = mp[*it];
        res += (t * (t - 1) / 2);

    }

    for(int i = 0; i < n; ++i) {
        cout << res - mp[v[i]] + 1 << endl;
    
    }
    return 0;
}



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

int main(void) {

    int a, b, c;
    cin >> a >> b >> c;

    bool can;
    if (a + b == c || b + c == a || c + a == b) can = true;
    else can = false;

    cout << (can ? "Yes" : "No") << endl;
        

    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    
    int a[100];
    int i;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }
    
    sort(a, a + n, greater<int>());
    
    int alice = 0, bob = 0;
    for(i = 0; i < n; i++){
        if(i % 2 == 0){
            alice += a[i];
        }else{
            bob += a[i];
        }
    }
    
    cout << alice - bob << endl;
    
    return 0;
}


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

P f(int x){
	int a,b;
	a=x%10;
	while (x>=10){
		x/=10;
	}
	b=x;
	return (make_pair(b,a));
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
  cin>>n;
	//map(＜first,last>,num)
	map<P,int> mp;

	rep(i,n){
		P p=f(i+1);
	//	cout<<p.first<<' '<<p.second<<endl;
		mp[p]++;
	}
	int ans=0;
	rep(i,10)rep(j,10){
		ans+=mp[make_pair(i,j)]*mp[make_pair(j,i)];

	}

cout<<ans;
}


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

#define MAX 200000
#define WHITE 0
#define BLACK 1
int N, Q;
vector<int> T[MAX + 1];
int X[MAX + 1];
int ans[MAX + 1];
int col[MAX + 1];

int main() {
	cin >> N >> Q;
	for (int i = 1; i <= N; i++) {
		X[i] = 0;
		col[i] = WHITE;
	}
	for (int i = 1; i <= N - 1; i++) {
		int a, b;
		cin >> a >> b;
		T[a].push_back(b);
		T[b].push_back(a);
	}
	for (int j = 1; j <= Q; j++) {
		int p, x;
		cin >> p >> x;
		X[p] += x;
	}
	queue<pair<int, int>> Q;
	Q.push(make_pair(1, 0));
	col[1] = BLACK;
	while (!Q.empty()) {
		auto u = Q.front();
		Q.pop();
		ans[u.first] = u.second + X[u.first];
		for (auto v : T[u.first]) {
			if (col[v] == WHITE) {
				Q.push(make_pair(v, ans[u.first]));
				col[v] = BLACK;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 17908
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

int N, K, X, Y;

signed main() {
	cin >> N >> K >> X >> Y;
	int ans; // = X * min(N, K) + Y * max(N - K, 0);
	if (N < K) {
		ans = X * N;
	}
	else {
		ans = X * K + Y * (N - K);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    cout << (n-2)*180 << endl;
}

Measured memory_bytes: 3568
n,m = gets.split.map{|tmp|tmp.to_i}
ti = Array.new
prev = 0
gets.split.each_with_index do |tmp,index|
    t = tmp.to_i
    if index == 0
        ti.push(t)
    else
        ti.push(t - prev)
        prev = t.to_i       
    end
end

x = 0
sa = 0
n.times do |i|
    if i != 0
        #差を計算
        sa = m-ti[i] <0 ? 0 : m-ti[i]
    end
    #増加量を計算
    rx = m - sa
    #増加量を足す
    x+=rx
end
puts x

Measured memory_bytes: 16060
#include <stdio.h>

int main(void) {

	int min, max, n,i = 0;
	long long sum = 0;
	int num[10000] = { 0 };

	scanf("%d\n", &n);

	//配列numに全て格納、合計値(sum)
	for (i = 0; i < n; i++) {
		scanf("%d", &num[i]);
		sum += num[i];
	}

	min = num[0];
	max = num[0];

	for (int j = 0; j < n; j++) {
		if (min > num[j]) {
			min = num[j];
		}
		else if (max < num[j]) {
			max = num[j];
		}
	}

	printf("%d %d %lld\n", min, max, sum);
	
	return 0;
}



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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define int long long
 
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    int ans = 0;
    for (int i = 0; i < 29; ++i) {
        int cnt = 0;
        vector <int> b1, b2;
        for (int j = 0; j < n; ++j) {
            if((b[j] >> i) & 1) b1.push_back((b[j] & ((1 << i) - 1)));
            else b2.push_back((b[j] & ((1 << i) - 1)));
        }
        sort(all(b1));
        sort(all(b2));
        for (int j = 0; j < n; ++j) {
            int x = (a[j] & ((1 << i) - 1)); 
            if((a[j] >> i) & 1) {
                int t1 = b1.end() - lower_bound(all(b1), (1 << i) - x);
                int t2 = lower_bound(all(b2), (1 << i) - x) - b2.begin();
                cnt = (cnt + t1 + t2) & 1;
            } else {
                int t1 = lower_bound(all(b1), (1 << i) - x) - b1.begin();
                int t2 = b2.end() - lower_bound(all(b2), (1 << i) - x);
                cnt = (cnt + t1 + t2) & 1;
            }
        }
        if(cnt) ans |= (1LL << i);
    }

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

Measured memory_bytes: 6960
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>
using namespace std;
 
int main() {
    string str;
    stack<int> s;
    int a, b, n;
     
    while(cin >> str){
        if(str == "+"){
            a = s.top();
            s.pop();
            b = s.top();
            s.pop();
            s.push(a+b);
        }
        else if(str == "-"){
            a = s.top();
            s.pop();
            b = s.top();
            s.pop();
            s.push(b-a);
        }
        else if(str == "*"){
            a = s.top();
            s.pop();
            b = s.top();
            s.pop();
            s.push(a*b);
        }
        else{
            n = atoi(str.c_str());
            s.push(n);
        }
    }
    cout << s.top() << endl;
}

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

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

    for(char c: s)
    {
        if(c=='B')
        {
            if(ans.size()) ans.pop_back();
        }
        else ans.push_back(c);
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
data class Result(
    var trend: TREND = TREND.UNKNOWN,
    val list: MutableList<Long> = mutableListOf()
) {
    fun addAndCheck(value: Long): Boolean {
        return when (trend) {
            TREND.UNKNOWN -> {
                if (list.isNotEmpty()) {
                    if (list.last() > value) {
                        trend = TREND.NEGATIVE
                    } else if (list.last() < value) {
                        trend = TREND.POSITIVE
                    }
                }
                list += value
                true
            }
            TREND.POSITIVE -> {
                if (list.last() <= value) {
                    list += value
                    true
                } else {
                    false
                }
            }
            TREND.NEGATIVE -> {
                if (list.last() >= value) {
                    list += value
                    true
                } else {
                    false
                }
            }
        }
    }
}

enum class TREND {
    UNKNOWN,
    POSITIVE,
    NEGATIVE
}

fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val list = readLine()?.split(" ")?.map { it.toLong() } ?: return

    val results = mutableListOf<Result>()

    for (i in 0 until n) {
        val value = list[i]
        if (results.isEmpty()) {
            results += Result().apply { addAndCheck(value) }
        } else {
            val lastResult = results.last()
            if (!lastResult.addAndCheck(value)) {
                results += Result().apply { addAndCheck(value) }
            }
        }
    }
    println(results.size)
}

Measured memory_bytes: 58772
n = int(input())
t = []
x = []
y = []

t.append(0)
x.append(0)
y.append(0)

for i in range(n):
    t_, x_, y_ = map(int, input().split())
    t.append(t_)
    x.append(x_)
    y.append(y_)

def solve():
    for i in range(1, n+1):
        kx = x[i] - x[i-1]
        ky = y[i] - y[i-1]
        dt = (t[i] - t[i-1]) - (kx + ky)

        if dt >= 0 and dt % 2 == 0:
            pass
        else:
            print("No")
            return
    print("Yes")

solve()

Measured memory_bytes: 11828
#include <stdio.h>

int main() {
	int h, w;
	for(;;) {
		scanf("%d %d", &h, &w);
		if(h==0) break;
		for(int i=0; i<h; i++) {
			for(int j=0; j<w; j++) {
				if((i+j)%2==0) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2580
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/


void solve() {
	string s;cin>>s;
	if(s[1]=='R') cout<<"ABC\n";
	else cout<<"ARC\n";
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

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

typedef long long LL;

const int MAXN = 2e5 + 5;

int main()
{
	int N; scanf("%d", &N);
	static LL a[MAXN]; LL sum = 0;
	for (int i = 1; i <= N; i++)
	{
		scanf("%lld", &a[i]);
		sum += a[i];
	}
	
	LL pre = a[1], mDif = llabs(sum - 2 * a[1]);
	for (int i = 2; i < N; i++)
	{
		pre += a[i];
		mDif = std::min(mDif, llabs(sum - 2 * pre));
	}
	
	printf("%lld\n", mDif);
}

Measured memory_bytes: 1792
#include <iostream>
    #include <sstream>
    #include <iomanip>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #include <cstring>
    #include <vector>
    #include <list>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <map>
    #include <set>
    #include <algorithm>
    #include <iterator>
    #include <bitset>
    #include <ctime>



    using namespace std;

    #define FOR(i,a,b) for(int i = (a); i < (b); i++)
    #define rep(i,n) FOR(i,0,n)
    #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
    #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
    #define FILL(a, value) memset(a, value, sizeof(a)

    #define SZ(a) (int)a.size()
    #define ALL(a) a.begin(), a.end()
    #define PB push_back
    #define MP make_pair

    typedef  long long LL;
    typedef vector<int> VI;
    typedef pair<int, int> PII;

    const double PI = acos(-1.0);
    const int INF = 1000 * 1000 * 1000 + 7;
    const LL LINF = INF * (LL)INF;

    const double EPS = 1e-7;
    const int MAX = 20 * 1000 + 47;
    const int MAS = 1e5 * 3;
    const int MOD = 1000 * 1000 * 1000 + 7;

    double DIST(double x1, double x2, double y1, double y2)
    {
        return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    }
    


    int main()
    {
        int n, m;
        cin >> n >> m; 
        vector<string> s (n) ; 
        rep(i, n)
        {
            cin >> s[i]; 
        }
        vector<vector<int >> dp(3010, vector<int >(3010)); 
        dp[0][0] = 1; 
        rep(row, n)
        {
            rep(col, m)
            {
                for (auto v : { row , row+ 1 })
                {
                    int c = col;
                    if (v == row) c = col + 1;
                    if(c  < m && v < n && s[v][c] =='.')
                    {
                        dp[v][c] += dp[row][col];
                        dp[v][c] %= MOD; 
                    }
                }

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



    }










Measured memory_bytes: 36736
MOD = 10**9 + 7

N, A, B, C = map(int, input().split())

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
def getCombKs(n, k, invs, MOD):
    combKs = [0] * (n+1)
    combKs[k] = 1
    for x in range(k+1, n+1):
        combKs[x] = (combKs[x-1] * x * invs[x-k]) % MOD
    return combKs
def getPows(base, n, MOD):
    pows = [1] * (n+1)
    for x in range(1, n+1):
        pows[x] = (pows[x-1] * base) % MOD
    return pows

invs = getInvs(N, MOD)
combKs = getCombKs(2*N-1, N-1, invs, MOD)
powAs = getPows(A, N, MOD)
powBs = getPows(B, N, MOD)
invPowABs = getPows(pow(A+B, MOD-2, MOD), 2*N-1, MOD)

ans = 0
for m in range(N, 2*N):
    v = combKs[m-1] * (powAs[N]*powBs[m-N] + powAs[m-N]*powBs[N]) * m * invPowABs[m] % MOD
    ans = (ans+v) % MOD

ans = ans * 100 * pow(A+B, MOD-2, MOD) % MOD
print(ans)


Measured memory_bytes: 27584
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(std::string a, std::string b) {
  if (a == b) {
    cout << "H" << endl;
  } else {
    cout << "D" << endl;
  }
}

int main() {
  std::string a;
  std::cin >> a;
  std::string b;
  std::cin >> b;
  solve(a, b);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		String S = sc.next();
		long black = 0, white = 0;
		for(int i = 0; i < S.length(); i++) {
			if(S.charAt(i) == 'B') black++;
			else white++;
		}
		black = white;
		long ans = 0;
		for(int i = 0; i < S.length(); i++) {
			if(S.charAt(i) == 'B') {
				ans += black - (long)i;
				black++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 28520
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();



            if (S[0] == T[0] && S[1] == T[1] && S[2] == T[2])
            {
                Console.WriteLine(3);
            }
            else if (S[0] == T[0] && S[1] == T[1] || S[0] == T[0] && S[2] == T[2] || S[1] == T[1] && S[2] == T[2])
            {
                Console.WriteLine(2);
            }
            else if (S[0] == T[0] || S[1] == T[1] || S[2] == T[2])
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}

Measured memory_bytes: 13140
#pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));


	for (int i = 2; i <= MAX; i++){
		if (!vis[i]){

			prime[i] = 1;
			for (int j = i + i; j <= MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;

			}
		}
	}
	int sum = 0;
	for (int i = 2; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}

	int n;
	while (cin >> n){
	cout << amount[n] << endl;
}
	return 0;
}

Measured memory_bytes: 12884
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#include <cstring>
using namespace std;
typedef long long ll;
const ll maxn = 1e6+10;
const ll inf = 1e16;
const ll mod = 998244353;

int N;
int cntA,cntB,rd;
int main(){
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>N;
    string s;
    ll res = 0;
    while(N--){
        cin>>s;
        if(s[0] == 'B' && s[s.length()-1] == 'A') rd++;
        if(s[0] == 'B') cntB++;
        if(s[s.length()-1] == 'A') cntA++;
        for(int i = 1;i<s.length();i++){
            if(s[i] == 'B' && s[i-1] == 'A') res++;
        }
    }
    res = res + min(cntA,cntB);
    if(cntA == cntB && cntA == rd && cntA) res--;
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
import Data.List

main :: IO()
main = getLine >>= print.solveRPN.words

solveRPN :: [String] -> Int
solveRPN = head.foldl' f []
    where f (x:y:ys) "+" = (y + x) : ys
          f (x:y:ys) "-" = (y - x) : ys
          f (x:y:ys) "*" = (y * x) : ys
          f xs        n  = read n  : xs

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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N, tmp;
    cin >> N;
    map<int, int> list;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        list[tmp]++;
    }
    int ans = 0;
    for (auto x : list)
    {
        if (x.second % 2 == 1)
            ans++;
    }
    cout << ans;
}

Measured memory_bytes: 4992
// header {{{
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    (26)
#define EPS         (1e-10)
#define INF         (1000000005LL)
#define MOD         (1000000007LL)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
// ciling(x/y) = (x+y-1)/y

typedef long long ll;
typedef unsigned long long ull;
// }}}

int main() {
    int n, k, x, y;cin >> n >> k >> x >> y;
    cout << (x*min(k, n) + y*max(0, n-k)) << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    h, w = list(map(int, input().strip().split()))
    a = []
    for i in range(h):
        a.append(list(map(int, input().strip().split())))
    ans = []
    for i in range(h):
        for j in range(w):
            if i == h-1 and j == w-1:
                continue
            if a[i][j] % 2 == 1:
                if j == w-1:
                    a[i+1][j] += 1
                    p = i+2
                    q = j+1
                else:
                    a[i][j+1] += 1
                    p = i+1
                    q = j+2
                a[i][j] -= 1
                ans.append((i+1, j+1, p, q))
    print(len(ans))
    for t in ans:
        print(*t)
if __name__ == '__main__':
    main()


Measured memory_bytes: 75740
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int N;
set<int> s;
int main(){
    cin >> N;
    for(int i=0; i<N; ++i){
        int a, b, c; cin >> a >> b >> c;
        s.insert(a*a*a+b*b*b+c*c*c);
    }
    cout << N-s.size() << endl;
    return 0;
}


Measured memory_bytes: 3124
def main():
    import math
    a, b ,x = [int(x) for x in input().split()]

    if x > a*a*b/2:
        theta = math.atan(2*(a*a*b-x)/a/a/a)

    else:
        theta = math.atan(a*b*b/2/x)

    print(math.degrees(theta))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <limits>
#include <utility>
#include <algorithm>
#include <tuple>
#include <limits>

int main(int argc, char *argv[])
{
    int n, m;

    std::cin >> n >> m;

    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    std::vector<std::pair<int,int>> r;
    r.reserve(2 * m);
    for (int i = 0; i < m; i++) {
        int a, b;
        std::cin >> a >> b;
        r.push_back(std::make_pair(a - 1, b - 1));
        r.push_back(std::make_pair(b - 1, a - 1));
    }

    std::vector<bool> good(n, true);
    for (const auto &it : r) {
        const int a = it.first, b = it.second;
        if (h[a] <= h[b]) {good[a] = false;}
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (good[i]) {ans++;}
    }

    std::cout << ans << std::endl;

    return 0;
}


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

#define mp make_pair
#define pb push_back

#define int int64_t

const int MOD = 1e9+7;
 
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int n;
 	cin>>n;
 	string s;
 	cin>>s;
 	if(n%2)
 	{
 		cout<<"No";
 		return 0;
 	}
 	if(s.substr(0, n/2)==s.substr(n/2, n/2))
 	{
 		cout<<"Yes";
 	}
 	else
 		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(lambda x:int(x)-1,input().split()))
order = [-1] * N
a = 0
for i in range(K):
    if order[a] >= 0:
        r = i - order[a]
        K -= order[a]
        m = K%r
        print(order.index(order[a] + m) + 1)
        exit()
        break
    order[a] = i
    a = A[a]
else:
    print(a+1)

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

int main() {
  int x , a , b , d , e;
  cin >> x >> a >> b;
  if ( x-a < 0) {
    d =a-x;
  }else d= x-a ;
  if (x-b < 0 ) {
    e = b-x ;
  }else e = x-b ;
  cout << (d < e ? 'A' : 'B') << endl;
}

Measured memory_bytes: 3556