akhauriyash/Code-Regression huggingface dataset:
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;


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


typedef int64_t i64;


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto m = next<int>(in);
  auto k = next<i64>(in);
  vec<i64> a(n + 1);
  FOR(i, n) {
    a[i + 1] = a[i] + next<i64>(in);
  }
  vec<i64> b(m + 1);
  FOR(i, m) {
    b[i + 1] = b[i] + next<i64>(in);
  }
  int ptr = 0;
  while (ptr < b.size()) {
    if (b[ptr] > k) {
      break;
    }
    ++ptr;
  }
  --ptr;
  int res = ptr;
  FOR(i, n + 1) {
    while (ptr > 0 && a[i] + b[ptr] > k) {
      --ptr;
    }
    if (ptr == 0) {
      if (a[i] > k) {
        break;
      }
    }
    res = max(res, i + ptr);
  }
  out << res << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 6348
N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10
dp = [INF for i in range(N)]
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,N):
    for j in range(max(0,i-K),i):
        dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[N-1])


Measured memory_bytes: 56544
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((int)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;



int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>x>>k>>d;
    x=abs(x);
    p=x/d;
    r=x%d;
    if(p<=k)
    {
           if(p==k)
           cout<<r<<endl;
           else
           {
                  c=k-p;
                  if(c%2!=0)
                  {
                         cout<<min(abs(r+d),abs(r-d))<<endl;
                  }
                  else cout<<r<<endl;
           }
    }
    else{
           cout<<x-(k*d)<<endl;
    }

    //code
    return 0;
}




Measured memory_bytes: 50468
import math

N, M = list(map(int, input().split()))
x = M // N
Mx = []
m = math.floor(math.sqrt(M))
for i in range(1, m + 1):
	if M % i == 0:
		Mx.append(i)

y = len(Mx)

My = []
for i in range(y):
	My.append(int(M // Mx[- 1 - i]))



for i in range(y):
	Mx.append(My[i])

ans = 1
for i in Mx:
	if i <= x:
		ans = i
	else:
		break

print(ans)

Measured memory_bytes: 3064
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[2*M];
		for(int i = 0; i < 2*M; i++){
			a[i] = sc.nextInt();
		}

		int[] town = new int[N];
		int index = 0;
		for(int i = 0; i < 2*M; i++){
			index = a[i] - 1;
			town[index]++;
			
		}

		for(int i = 0; i < N; i++){
			System.out.println(town[i]);
		}
	}
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> G[N];
    REP(i, M)
    {
        ll l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        G[l].push_back(make_pair(r, d));
        G[r].push_back(make_pair(l, -d));
    }

    const ll INF = LONG_MAX;
    vector<ll> x(N, INF);
    bool isExist = true;
    REP(i, N)
    {
        if (G[i].size() == 0) 
        {
            x[i] = 0;
            continue;
        }
        if (x[i] != INF)
        {
            continue;
        }

        x[i] = 0;
        queue<ll> q;
        q.push(i);
        while(!q.empty())
        {
            ll p = q.front();
            q.pop();
            REPV(it, G[p])
            {
                ll next = it->first;
                ll cost = it->second;
                if (x[next] == INF)
                {
                    q.push(next);
                    x[next] = x[p] + cost;
                }
                else
                {
                    if (x[next] != x[p] + cost)
                    {
                        isExist = false;
                        break;
                    }
                }
            }
            if (!isExist)
            {
                break;
            }
        }
        if (!isExist)
        {
            break;
        }
    }
    string ans = isExist ? "Yes" : "No";

    cout << ans << endl;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == B[i] && B[i] == C[i]) {
            continue;
        } else if (A[i] == B[i] || B[i] == C[i] || C[i] == A[i]) {
            ans++;
        } else {
            ans += 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

int main(void){
    std::string S;
    std::cin >> S;

    for(int i=0; i<S.length()/2; i++){
        if(S[i]!=S[S.length()-1-i]){
            std::cout << "No" << std::endl;
            return 0;
        }
        if(S[i]!=S[S.length()/2-1-i]){
            std::cout << "No" << std::endl;
            return 0;
        }
        if(S[S.length()/2+1+i]!=S[S.length()-1-i]){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}

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

int main() {
  	string L[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string S;
	cin >> S;
  
 	rep(i,7){
     if(S == L[i]){
     	cout << (7-i) << endl;
     }
    }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int n,m,p,correct = 0,penalty = 0;
    string s;
    cin>>n>>m;
    vector<int> ac(n),wa(n);
    rep(i,m){
        cin>>p>>s;
        if(ac[p-1] == 0 && s == "AC") ac[p-1]++;
        if(ac[p-1] == 0 && s == "WA") wa[p-1]++;
    }
    rep(i,n){
        correct += ac[i];
        if(ac[i]) penalty += wa[i];
    }
    cout<<correct<<" "<<penalty<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , M ;
  cin >> N >> M ;
  vector<int> A(N) ;
  vector <int> B(N) ;
  for ( int i=0 ; i<N ; i++){
    cin >> A[i] >> B[i] ;
  }
   vector<int> C(M) ;
  vector <int> D(M) ;
    for ( int i=0 ; i<M ; i++){
    cin >> C[i] >> D[i] ;
  }
  vector<int64_t> p(N) ;
  vector<int64_t> md(N,4000000000) ;
  
    for ( int i=0 ; i<N ; i++){
    for ( int j=0 ; j<M ; j++){
   if (md[i]>abs(C[j]-A[i])+abs(D[j]-B[i])){
     p[i]=j+1 ;
     md[i]=abs(C[j]-A[i])+abs(D[j]-B[i])  ;
   }
    } 
      cout << p[i] << endl; 
  }

}

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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;


int main() {
    int a, b;
    cin >> a >> b;
    if (a > 9 || b > 9)
        cout << -1;
    else
        cout << a * b;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

#define ll long long

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

string s;

void input() {
  cin >> s;
}

void solve1() {
  string a = s.substr(0, 2);

  int num = stoi(a.c_str());

  bool flag1 = false;
  bool flag2 = false;

  if (num > 0 && num <= 12)
    flag1 = true;

  a = s.substr(2, 2);
  num = stoi(a.c_str());

  if (num > 0 && num <= 12)
    flag2 = true;

  if (flag1 && flag2) {
    cout << "AMBIGUOUS";
  } else if (flag1 && !flag2) {
    cout << "MMYY";
  } else if (!flag1 && flag2) {
    cout << "YYMM";
  } else {
    cout << "NA";
  }

  cout << '\n';
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve1();
}


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

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

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

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

int answer(int x, int y, int z) {
  return x * x + y * y + z * z + x * y + y * z + z * x;
}

int count(int x, int y, int z) {
  if (x == y && y == z) {
    return 1;
  } else if ((x != y && y == z) || (y != z && z == x) || (z != x && x == y)) {
    return 3;
  } else {
    return 6;
  }
}

int main() { 
  int N;
  cin >> N;
  
  vector<int> num(N, 0);
  
    for (int i=1; i<=sqrt(N); i++) {
      for (int j=i; j<=sqrt(N); j++) {
        for (int k=j; k<=sqrt(N); k++) {
          int ans = answer(i, j, k);
          if (ans <= N) {
            num.at(ans-1) += count(i, j, k);
          }
        }
      }
    }
  
  	for (int i=0; i<N; i++) cout << num.at(i) << endl;
}


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


void solve() {
  int N;
  scanf("%d", &N);
  int otsuri = 0;
  rep(i, 11) {
    if (i*1000 >= N) {
      otsuri = i*1000-N;
      break;
    }
  }

  cout << otsuri << "\n";
}

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


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

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

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

    int r[n + 1], c[m + 1];
    map<pair<int, int>, int> grid;

    memset(r, 0, sizeof r);
    memset(c, 0, sizeof c);

    for (int i = 0; i < k; i++) {
        int x, y;
        cin >> x >> y;
        grid[make_pair(x, y)] = 1;
        r[x]++, c[y]++;
    }
    int x, y;

    int temp = -1;
    for (int i = 1; i <= n; i++)
        if (temp < r[i]) {
            temp = r[i];
            x = i;
        }
    vector<int> xs, ys;
    for (int i = 1; i <= n; i++)
        if (r[i] == temp) xs.push_back(i);
    temp = -1;

    for (int i = 1; i <= m; i++)
        if (temp < c[i]) {
            temp = c[i];
            y = i;
        }
    for (int i = 1; i <= m; i++)
        if (c[i] == temp) ys.push_back(i);
    int ans = 0;
    bool f=false;
    for(int x : xs){
        for(int y : ys ){
            int temp=r[x]+c[y];
            if(!grid[make_pair(x,y)]){
                ans=temp;
                f=true;
                break;
            }
            else ans=temp-1;
        }
        if(f)break;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 28512
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int A[4];
  cin >> A[0] >> A[1] >> A[2] >> A[3];
  sort(A,A+4);
  int D[4] = {1,4,7,9};
  int count = 0;
  for(int i = 0; i < 4; i++){
    if(A[i] != D[i]) {
      count = count + 1;
    }
  }
 
  if(count == 0){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main()
{
  int n,a,b,c;
  cin>>n;
  int arr[n][3];
  int dp[n][3];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    dp[0][0]=arr[0][0];dp[0][1]=arr[0][1];dp[0][2]=arr[0][2];
  }
 
  for(int i=1;i<n;i++)
  {
    dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=arr[i][2]+max(dp[i-1][1],dp[i-1][0]);
  }
  
  sort(dp[n-1] , dp[n-1]+3);
  cout<<(dp[n-1][2]);
  
  //cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  return 0;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

ll calc(ll n)
{
  if (n == 1)
  {
    return 1;
  }

  return 1 + 2 * calc(n / 2);
}

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

  cout << calc(h) << endl;

  return 0;
}


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

int main() {
    uint64_t a, b, x;
    cin >> a >> b >> x;
    uint64_t count =  a > 0 ? b / x - (a - 1) / x : b / x - a /x + 1;
    cout << count << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

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

	int H,W; cin >> H >> W;

	char field[100][100];
	for (int i = 0;i < 100;i++){
		for (int j = 0;j < 100;j++){
			field[i][j] = '.';
		}
	}

	for (int i = 1;i <= H;i++){
		for (int j = 1;j <= W;j++){
			cin >> field[i][j];
		}
	}

	for (int i = 1;i <= H;i++){
		for (int j = 1;j <= W;j++){
			if(field[i][j] == '#'){ cout << '#'; continue;}
			int ans = 0;
			for (int k = 0;k < 8;k++){
				if(field[i+dy[k]][j+dx[k]] == '#') ans++;
			}
			cout << ans;
		}
		cout << endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
  int X, N;
  cin >> X >> N;
  vector <int> p(N);
  for (int i = 0; i < N; i++) cin >> p[i];
  int ans = 0;
  int mindiff = 999;
  for (int i = -101; i <= 101; i++) {
    bool inp = false;
    for (int j = 0; j < N; j++) {
      if (p[j]==i) inp = true;
    }
    if (inp) continue;
    if (abs(X-i) < mindiff) {
      ans = i;
      mindiff = abs(X-i);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
N = 123456
MOD = (10 ** 9) + 7

fs = [1 for i in xrange(N)]
for i in xrange(1, N):
    fs[i] = fs[i - 1] * i % MOD

n, k = map(int, raw_input().split())
ns = map(int, raw_input().split())
ns.sort()

def fermat(u):
    return pow(u, MOD - 2, MOD)

def C(a, b):
    if b > a:
        return 0
    if b == 0:
        return 0
    assert a - b >= 0
    res = fs[a] * fermat(fs[b]) % MOD * fermat(fs[a - b]) % MOD
    return res % MOD

assert C(5, 3) == 10

res = 0
for i in xrange(n):
    res += C(i, k - 1) * ns[i] % MOD
    res %= MOD
    res -= C(n - i - 1, k - 1) * ns[i] % MOD
    res = ((res % MOD) + MOD) % MOD

print res


Measured memory_bytes: 45288
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 100100
//#define NIL -1

int main() {
    LL x;
    cin >> x;
    LL ans;
    LL i=0;
    while(true){
        LL tmp=(i*(i+1))/2;
        if(tmp>=x){
            ans=i;
            break;
        }
        i++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
//  g++ -g -std=gnu++14 -I . main.cpp -o main
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        ([]{int n; cin>>n; return n;}())
using namespace std;
using lint = int64_t;

// int main() { cin.tie(0); ios::sync_with_stdio(false);
//     lint N=in, K=in;
//     vector<lint> A(N);
//     rep( i, N ) A[i] = in;
//
//     vector<pair<lint,lint>> lr(0);
//     lint temp = 0, kari=0;
//     rep( i, N ) {
//         temp += A[i];
//         if( temp >= K ) {
//             lr.push_back( make_pair(kari,i+1) );
//             temp = 0;
//             kari = i+1;
//         }
//     }
//
//     //for( pair<lint,lint> p : lr ) cout << p.first << " " << p.second << "\n";
//     for( pair<lint,lint> p : lr ) {
//         lint l=p.first, r = p.second;
//         lint sum = 0;
//         for( int i=r-1; i>=l; --i ) {
//             sum += A[i];
//         }
//     }
// }


int main() { cin.tie(0); ios::sync_with_stdio(false);
    lint W=in, H=in, X=in, Y=in;
    if( ((X==0)&&(Y==0)) || ((X==0)&&(Y==H)) || ((X==W)&&(Y==0)) || ((X==W)&&(Y==H)) ) {
        printf("%.70f 0\n", (double(W)*H)/2 );
        return 0;
    }

    if( ((X*2)==W) && ((Y*2)==H) ) {
        printf("%.70f 1\n", (double(W)*H)/2 );
        return 0;
    }

    printf("%.70f 0\n", (double(W)*H)/2 );
    return 0;
}


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

namespace AtTest.diverta2019
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            string[] ss = new string[n];
            for (int i = 0; i < n; i++) ss[i] = Read();

            int res = 0;
            int lastAcnt = 0;
            int firstBcnt = 0;
            int baCnt = 0;
            for(int i = 0; i < n; i++)
            {
                bool nowA = false;
                for(int j = 0; j < ss[i].Length; j++)
                {
                    if (nowA && ss[i][j] == 'B') res++;
                    nowA = ss[i][j] == 'A';
                }

                if (ss[i][0] == 'B' && ss[i][ss[i].Length - 1] == 'A') baCnt++;
                else if (ss[i][0] == 'B') firstBcnt++;
                else if (ss[i][ss[i].Length - 1] == 'A') lastAcnt++;
            }

            if (baCnt > 0)
            {
                if (lastAcnt > 0)
                {
                    res++;
                    lastAcnt--;
                }
                res += baCnt - 1;
                baCnt = 1;
            }
            res += Min(lastAcnt + baCnt, firstBcnt);
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using namespace std;

inline bool isLeapYear(int year) {
  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

inline int countLeapYear(int year) {
  return year / 4 - year / 100 + year / 400;
}

inline int getMaxDay(int year, int month) {
  const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  if (month == 2) return isLeapYear(year) ? 29 : 28;
  return days[month];
}

struct Day {
  int year, month, day;

  enum {SUN, MON, TUE, WED, THU, FRI, SAT};

  Day() : year(0), month(0), day(0) {}

  Day(int year, int month, int day) : year(year), month(month), day(day) {}

  int fairfield() const {
    int y = year, m = month;
    if (m <= 2) --y, m += 12;
    return 365 * y + countLeapYear(y) + (153 * (m + 1) / 5) + day - 428;
  }

  int operator-(const Day& day) const {
    return fairfield() - day.fairfield();
  }

  bool operator<(const Day& day) const {
    if (year != day.year) return year < day.year;
    if (month != day.month) return month < day.month;
    return this->day < day.day;
  }

  Day operator++() {
    ++day;
    if (getMaxDay(year, month) < day) {
      ++month;
      day = 1;
      if (month == 13) {
        ++year;
        month = 1;
      }
    }
    return *this;
  }

  int dayOfTheWeek() {
    return fairfield() % 7;
  }
};

bool solve() {
  int m, d;
  cin >> m >> d;
  if (m == 0 && d == 0) return false;
  Day day(2004, m, d);
  string week[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  cout << week[day.dayOfTheWeek()] << endl;
  return true;
}

int main() {
  while (solve());
}

Measured memory_bytes: 3192
def resolve():
    '''
    code here
    '''
    N = int(input())

    def get_sieved_list(x):
        dp = [1 if item % 2 == 0 else 0 for item in range(x+1)]
        dp[:3] = [2,1,1]

        for prim_candi in range(3, x+1):
            temp_num = prim_candi
            while temp_num <= x:
                dp[temp_num] += 1
                temp_num += prim_candi
            if prim_candi >= x:
                return [i  for i in range(x+1) if dp[i] == 1]
                
    
    if N > 2:
        factor_filter = set(get_sieved_list(N))
        prime_list = [0 for _ in range(N+1)]
        for i in factor_filter:
            if i >1:
                for j in range(2, N+1):
                    while j >= 1 and j % i == 0:
                        j //= i
                        prime_list[i] += 1

        res = 1
        for item in prime_list:
            res *= (item+1)
            res %= (10**9+7)
    else:
        res = N

    print(res%(10**9+7))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9252
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

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

    ll ans = 0;
    ll cnt = 0;
    rep(i, s.size()) {
        if (s[s.size() - 1 - i] == 'B') {
            ans += i - cnt;
            cnt++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
using pt = complex<double>;

const int MAXN = 4000;
int N;
ll L;
ll T[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> L;
	for (int i = 0; i < N; i++) cin >> T[i];
	sort(T, T + N);
	pt ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			double probInner = double(j-i-1) / (N-2) / N / (N-1) * 6;
			double probOuter = double(N - (j-i+1)) / (N-2) / N / (N-1) * 6;

			pt ptOuter = polar(1., M_PI / L * (T[i] + T[j]));
			pt ptInner = -ptOuter;
			//cerr << i << ' ' << j << '\n';
			//cerr << probInner << ' ' << probOuter << '\n';
			//cerr << ptInner << ' ' << ptOuter << '\n';
			ans += probInner * ptInner + probOuter * ptOuter;
		}
	}
	cout << fixed << setprecision(15);
	cout << ans.real() << ' ' << ans.imag() << '\n';

	return 0;
}


Measured memory_bytes: 640
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

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


if (b > 9 or a > 9):
    print(-1)
else:
    print(a*b)


Measured memory_bytes: 9132
i=input
r=range
N=int(i())
A=[int(i()) for _ in r(N)]
mp=A[1]-A[0]
mn=A[0]
for a in r(1,N):
    x=A[a]
    b=x-mn
    if mp<(b):
        mp=b
        if 0>b:mn=x
    if x<mn:mn=x
print(mp)

Measured memory_bytes: 13592
#include <bits/stdc++.h>
using namespace std;
 int main() {
  int N, P;
   cin >> N >> P;
  int K = P - 1;
  string S;
   cin >> S;
   
   if(S.at(K) == 'A'){
    S.at(K) = 'a';
   }
   
   else if(S.at(K) == 'B'){
    S.at(K) = 'b';
   }
   
   else if(S.at(K) == 'C'){
    S.at(K) = 'c';
   }
   cout << S << endl;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(void){
  long long n,a,b,s=0;
  cin >> n >> a >> b;
  s=s+n/(a+b)*a;
  if(a<n%(a+b))s+=a;
  else s=s+n%(a+b);
  cout << s;
}

Measured memory_bytes: 256
package main

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

func main() {
	var N int
	fmt.Scan(&N)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	A := make([]int, N)
	m := make(map[int]int)
	for i := range A {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
		m[A[i]]++
	}
	var keys []int
	for k := range m {
		keys = append(keys, k)
	}
	sort.Ints(keys)
	MAX := 1000000
	flags := make([]bool, MAX+1)
	for i := range flags {
		flags[i] = true
	}
	sum := 0
	for _, k := range keys {
		c := m[k]
		if !flags[k] {
			continue
		}
		if c == 1 {
			sum++
		}
		for num := k; num <= MAX; num += k {
			flags[num] = false
		}
	}
	fmt.Println(sum)

}


Measured memory_bytes: 19748
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

bool is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

vector<vector<int>> d(10, vector<int>(10, 1000000));

void warshall_floyd(int n) {
    rep(k,n) rep(i,n) {
        rep(j,n) {
            d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
        }
    }
}

ll g1(ll n, int p) {
    if (n == 0) return 0;
    return n/p + g1(n/p, p);
}
ll g2(ll n, int p) {
    ll res = g1(n/2, p);
    if (p == 2) res += n/2;
    return res;
}
int main()
{
    ll n; cin >> n;
    if (n % 2 == 1) {
        cout << 0 << endl;
    } else {
        cout << min(g2(n,2), g2(n,5)) << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define SORT(x) sort((x).begin(),(x).end())
#define MEMSET(x,y) memset((x),(y),sizeof(x))
#define P pair<int,int>

typedef long long ll;
using namespace std;

int INF = 100100101;
int main() {
  int n;
  cin >> n;
  vector<int> h(n+1,0);
  rep(i,n) cin >> h[i+1];
  ll dp[n+1];
  MEMSET(dp,0);
  h[0] = INF;
  FOR(i,0,n-1) {
    int hi1 = h[i+1],hi2 = h[i],hj = h[i+2];
    dp[i+2] = min(dp[i] + abs(hi2-hj),dp[i+1] + abs(hi1-hj));
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 1408
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
struct UnionFind{
    vector<int> parent;

    UnionFind(int n){
        parent.resize(n);
        for(int i = 0; i < n; i++) parent[i] = i;
    }

    int root(int node){
        if(parent[node] == node){
            return node;
        } else {
            return parent[node] = root(parent[node]);
        }
    }

    void unite(int x, int y){
        int rootx = root(x);
        int rooty = root(y);
        if(rootx == rooty) return;
        parent[rootx] = rooty;
    }

    bool isSame(int x, int y){
        return root(x) == root(y);
    }
};
int main(void){
    int n, m;
    cin >> n >> m;

    UnionFind uf(n);

    for(int i = 0; i < m; i++){
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;

        uf.unite(x,y);

    }

    set<int> st;
    for(int i = 0; i < n; i++){
        st.insert(uf.root(i));
    }
    cout << st.size() << endl;
}

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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

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

    ll cnt = 0;
    for(ll i = 0; i < n; i++) {
        cin >> p;
        if(p != i + 1) {
            cnt++;
        }
    }
    YES(cnt <= 2);
    return 0;
}

Measured memory_bytes: 3604
n = int(input())
a=[]
for _ in range(n):
  a.append(list(map(int, input().split())))

ans = 0.0
for i in range(n):
  for j in range(n):
    if i == j: continue
    ans += ((a[i][0]-a[j][0]) ** 2 + (a[i][1]-a[j][1]) ** 2) ** 0.5
ans = ans / 2

ans = 2/n *ans
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String[] tmpArray = br.readLine().split(" ");
			
			int n = Integer.parseInt(tmpArray[0]);
			int k = Integer.parseInt(tmpArray[1]);
			int s = Integer.parseInt(tmpArray[2]);
			
			if(n == 0 && k == 0 && s == 0){
				break;
			}
			
			System.out.println(solve(n, k, s));
		}
	}
	
	static int solve(int n, int k, int s){
		if(k == 1){
			if(n >= s && s >= 1){
				return 1;
			}
			else {
				return 0;
			}
		}
		int result = 0;
		for(int i = n; i >= 2; i--){
			result += solve(i - 1, k - 1, s - i);
		}
		
		return result;
	}

}

Measured memory_bytes: 24376
import java.io.BufferedReader
import java.io.BufferedWriter

open class Case(
    val input: BufferedReader = System.`in`.bufferedReader(),
    val out: BufferedWriter = System.out.bufferedWriter()
) {
    fun exec(fn: (Case) -> Unit) = input.use { out.use { fn(this) } }
    fun println(c: CharSequence?) = out.appendln(c)
}

fun solve(c: Case) {
    if (c.input.readLine().split(" ").map { it.toInt() }.any { it > 8 }) {
        c.println(":(")
    } else {
        c.println("Yay!")
    }
}

fun main() = Case().exec(::solve)


Measured memory_bytes: 36712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int a, b, n=1, cnt=0;
    cin >> a >> b;
    while(n < b){
        --n;
        n += a;
        cnt++;
    }
    cout << cnt << endl;
    
}

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

using namespace std;
using ll =long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;

const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){ cin.sync_with_stdio(0);
    ll N, K; cin >> N >> K;
    constexpr ll MAX_LOG = 62;
    vvl As(MAX_LOG, vl(N));

    FOR(i, 0, N) As[0][i] = i;
    FOR(i, 0, N) {
        cin >> As[1][i];
        As[1][i] --;
    }

    FOR(num_jumps, 2, MAX_LOG) {
        FOR(i, 0, N) {
            As[num_jumps][i] = As[num_jumps-1][As[num_jumps-1][i]];
        }
    }

    ll dest = 0;
    FOR(i, 0, MAX_LOG-1) {
        if (K & (1ll << i)) {
            // Jumping i + 1 times
            dest = As[i+1][dest];
        }
    }


    cout << (dest + 1) << endl;
} //cin.tie(0) bei schnellem Wechseln



Measured memory_bytes: 101732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N >> A;
  int rest = N - (N / 500) * 500;
  if (rest <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define gcda(x,y) gcd(abs(x),abs(y))

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    int x, n;
    cin >> x >> n;
    map<int,int> check;
    REP(i,n){
        int p;
        cin >> p;
        check[p] = 1;
    }

    REP(i,101){
        if(check[x-i]==0){
            cout << x-i << endl;
            break;
        }
        if(check[x+i]==0){
            cout << x+i << endl;
            break;
        }
    }
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,m;
  cin >> n >> m;

  string numFlag = "*";
  string num = "1";
  for(int i=1;i<n;i++){
    num += "0";
    numFlag += "*";
  }
  if(n==1){
    num = "0";
  }
  
  int s;
  string c;
  for(int i=0;i<m;i++){
    cin >> s >> c;
    if(numFlag[s-1] != '*' && num[s-1] != c[0] ){
      cout << "-1" << endl;
      return 0;
    }
    numFlag[s-1] = c[0];
    num[s-1] = c[0];
  }
  if(num[0]=='0' && n>1){
    cout << "-1" << endl;
  }
  else{
    cout << num << endl;
  }

  return 0;
}




Measured memory_bytes: 3696
#include <iostream>
using namespace std;
int main(){
  int N, mx, mn; cin >> N;
  int A[100];
  for (int i=0; i<N; i++){
    cin >> A[i];
  }
  
  mx = A[0];
  mn = A[0];
  
  for (int i=0; i<N; i++){
    if (A[i]>mx){
      mx = A[i];
    }
    if (A[i]<mn){
      mn = A[i];
    }
  }
  
  cout << mx-mn << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

inline char r(char c){
  if(c=='A') return 'B';
  else return 'A';
}

int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;

  int pos=0;
  bool rev=false;
  while(k>0 && pos<n){
    if((s[pos]=='A' && !rev) || (s[pos]=='B' && rev)) s[pos] = r(s[pos]);
    else {
      rev = !rev;
      pos++;
    }
    k--;
  }

  string t = s.substr(pos);
  if(rev) rep(i,t.size()) t[i] = r(t[i]);
  cout << t;

  bool b = pos%2==1;
  rep(i,pos){
    if(i==0 && pos==n && n%2==1 && k%2==1) cout<<"B";
    else if(b) cout << "A";
    else cout << "B";
    b = !b;
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 900
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t a, b, c, d, e, k;

    scanf("%zu\n%zu\n%zu\n%zu\n%zu\n%zu", &a, &b, &c, &d, &e, &k);

    puts((e - a <= k ? "Yay!" : ":("));

    return 0;
}


Measured memory_bytes: 128
s = gets.to_i

a = [s]
i = 1

def f(n)
  n.even? ? n/2 : 3*n+1
end

while true do
  n = f a[i-1]
  if a.include? n 
    puts i+1
    exit 0
  end
  a[i] = n
  i += 1
end


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

int is_prime(int n){
  if(n<2) return 0;
  else if(n==2) return 1;
  else if(n%2==0) return 0;

  double sqrtNum = sqrt(n);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (n % i == 0)
        {
            return 0;
        }
    }
    return 1;
}

int main(){
  int n;
  cin >> n;
  int cnt=0;
  int cal=11;
  vector<int> ans;
  while(cnt!=n){
    if(is_prime(cal)){
      if(cal%5==1){
        ans.push_back(cal);
        cnt++;
        //cout << cal << endl;
      }
    }

    cal++;
  }
  for(int i=0;i<n;++i){
    if(i!=n-1) cout << ans[i] << " ";
    else cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

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

  if ((a + b) >= 24){
    cout << (a + b) - 24 << endl;
  }
  else {
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// 条件を見落としていませんか？
int main () {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    ll ans = 1;
    ll a = 0;
    for (int i = 1; i < N; i++) {
        if (a == 0) {
            if (A[i-1] > A[i]) a = -1;
            if (A[i-1] < A[i]) a = 1;
        }
        else if (a == 1) {
            if (A[i-1] > A[i]) {
                a = 0;
                ans++;
            }
        }
        else {
            if (A[i-1] < A[i]) {
                a = 0;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h> 
#define ll long long int 
using namespace std; 
  
int main() 
{  
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL); 
    ll r;
    cin>>r;
     cout<<r*r<<endl;
    return 0; 
} 


Measured memory_bytes: 3528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(void)
{
  int H, W, h, w;
  cin >> H >> W;
  cin >> h >> w;

  cout << (H - h)*(W - w) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
   long long n;
   cin>>n;
   vector<int> v(n);
   map<int,int> g;
   for(int i=0;i<n;i++)
   {
   	 cin>>v[i];
   	 g[v[i]]++;
   }

   int ans=0;

   for(auto x:g)
   {   int t=x.second;
   	   ans+=(t*(t-1))/2;
   }

   for(int i=0;i<n;i++)
   {
   	  int k=g[v[i]];
   	  int at=ans-(k*(k-1))/2;
    k--;
   	  at+=(k*(k-1))/2;
   	  cout<<at<<"\n";
   }
}
main()
{
int t;
t=1;
while(t--)
{
solve();

}
}

Measured memory_bytes: 11008
package main

import (
  "fmt"
)

func main() {
  a := make([]int, 3)
  b := make([]int, 3)
  for i := 0; i < 3; i++ {
    fmt.Scan(&a[i])
    fmt.Scan(&b[i])
  }
  isTwoCount := 0
  isYes := true
  for i := 1; i < 5; i++ {
    count := 0
    for j := 0; j < 3; j++ {
      if a[j] == i || b [j] == i {
        count++
      }
    }
    if count > 2 {
      isYes = false
      break
    }
    if count > 1 {
      isTwoCount++
    }
  }
  if isYes || isTwoCount == 1 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}


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

int main(){
  ll N;
  cin >> N;
  ll ans=N-1;
  for(int i=1;i<=sqrt(N);i++){
    if(N%i!=0){
      continue;
    }
    ans=min(ans,i+N/i-2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*

*/

ll n,ans=0;
string a,b,c;

int main(void){
	cin>>n>>a>>b>>c;
	rep(i,n){
		if(a[i]==b[i]){
			if(b[i]==c[i]){
				//
			}else{
				ans++;	
			}
		}else{
			if(b[i]==c[i]){
				ans++;
			}else if(a[i]==c[i]){
				ans++;
			}else{
				ans+=2;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256