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

#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define ll long long
const ll INF = 2LL<<60;

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

    int X[11][11] = {0};
    rep(i, N)   rep(j, D)   cin >> X[i][j];

    int ans = 0;
    for(int i = 0; i < N - 1; i++)
    {
        
        for(int j = 1; j < N; j++)
        {
            if(i + j >= N)  break;

            int dist = 0;
            for(int k = 0; k < D; k++)
            {
                int abs_calc = abs(X[i][k] - X[i+j][k]);
                int sq = pow(abs_calc, 2);

                dist += sq;
            }
            
            double tmp = sqrt(dist);
            if (ceil(tmp) == floor(tmp))
            {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const int MAX_T = 3000;
int M, start, goal, dice[6];
vector<int> N;
 
bool isPositionValid(int p){return 0<=p && p<M;}
 
vector<int> MakePath(int from){
    static vector<bool> visit(M);
	static vector<int> path(M);
    static auto checkPath = [](int moveto)->int{
        if(!isPositionValid(moveto))	return 2*MAX_T;
        else{
            int position = moveto+ N[moveto];
            if(!visit[position]) MakePath(position);
            return  path[position]+1;
        }
    };
 
    if(from == start)fill(path.begin(), path.end(), MAX_T+1);
 
    visit[from] = true;
    int bestpath = MAX_T;
    if(from==goal)  bestpath = 0;
    else{
        for(int d : dice){
            bestpath = min(bestpath, checkPath(from + d));
            bestpath = min(bestpath, checkPath(from - d));
        }
    }
    path[from] = bestpath;
    return path;
}
 
int main(){
    // 入力
    cin >> M;
    for(int r=0; r<6; r++)   cin >> dice[r];
    cin >> start >> goal;
	start--, goal--;
	N.resize(M);
	for(int m=0; m<M; m++)   cin >> N[m];
	
	// 最短経路の探索
    auto path = MakePath(start);
     
    // 本番
    int position = start;
    for(int t=0; t<MAX_T; t++){
        if(position == goal) break;
     
        int r;
        cin >> r;
        int d = dice[r-1];
 
        static auto tryMove = [&path](int moveto, int& position)->bool{
			if(isPositionValid(moveto)){
				int new_position = moveto + N[moveto];
                if(path[position] > path[new_position]){
					position = new_position;
					return true;
				}
			}
            return false;
        };
     
		int output;
        if     (tryMove(position + d, position)) output = 1;
		else if(tryMove(position - d, position)) output = -1;
		else output = 0;
		cout << output << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1304
(* ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out *) open Batteries 
let card = Array.init 3 
                ( fun _ -> 
                          Str.split (Str.regexp " ") (read_line ()) 
                          |> List.map int_of_string |> Array.of_list) 

let blst = Scanf.sscanf (read_line ()) "%d" 
                ( fun n -> 
                          List.init n (
                                  fun _ -> 
                                          Scanf.sscanf (read_line ()) "%d" (
                                                  fun n -> 
                                                          n
                                          )
                          )
                )

let carray = Array.make_matrix 3 3 false

let () =
        Array.iteri (fun i ie ->
                Array.iteri (fun j je ->
                        let exists = List.exists (fun a ->
                                a = je
                        ) blst in
                                if exists then
                                        carray.(i).(j) <- true
                                else
                                        carray.(i).(j) <- false
                ) ie
        ) card

let () = 
        let ans = 
                if carray.(0) = [| true; true; true |] ||
                   carray.(1) = [| true; true; true |] ||
                   carray.(2) = [| true; true; true |] ||
                   Array.init 3 (fun i ->
                           carray.(i).(0)
                   ) = [| true; true; true |] ||
                   Array.init 3 (fun i ->
                           carray.(i).(1)
                   ) = [| true; true; true |] ||
                   Array.init 3 (fun i ->
                           carray.(i).(2)
                   ) = [| true; true; true |] ||
                   Array.init 3 (fun i ->
                           carray.(i).(i)
                   ) = [| true; true; true |] ||
                   Array.init 3 (fun i ->
                           carray.(2 - i).(i)
                   ) = [| true; true; true |]
                then
                        "Yes"
                else
                        "No" 
        in Printf.printf "%s\n" ans


Measured memory_bytes: 1024
# vim: set fileencoding=utf-8:


def main():
    N, M, X, Y = map(int, raw_input().split())
    x = [int(ele) for ele in raw_input().split()]  # N
    y = [int(ele) for ele in raw_input().split()]  # M

    x.append(X)
    y.append(Y)
    if max(x) < min(y):
        print("No War")
    else:
        print("War")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2568
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int n,m,s,g1,g2; cin>>n>>m>>s>>g1>>g2, n || m || s || g1 || g2;) {
		static int v[101][101];
		rep(i,101) fill(v[i], v[i] + 101, INF);
		rep(i,101) v[i][i] = 0;
		rep(i,m) {
			int a, b, c;
			cin >> a >> b >> c;
			v[a][b] = c;
		}

		rep(k, n+1) rep(i, n+1) rep(j, n+1)
			v[i][j] = min(v[i][j], v[i][k] + v[k][j]);

		int ans = INF;
		for(int i = 0; i <= 100; i++) {
			ans = min(ans, v[s][i] + v[i][g1] + v[i][g2]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB") {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
//#define multi
#ifdef solvsh

const int MAXN = 2e5 + 100;

ll cnt_gcd_1[MAXN];

ll mod = 1e9 + 7;
ll nk[MAXN];

ll ml(ll a, ll b){
    return (a * b) % mod;
}

ll pref[MAXN];

ll bin_pow(ll b, ll p){
    if (p == 0)
        return 1;
    if (p % 2 == 1)
        return ml(b, bin_pow(b, p - 1));
    auto v = bin_pow(b, p >> 1);
    return ml(v,v);
}

void solve() {

    ll n, k;
    cin >> n >> k;

    nk[0] = 1;

    for (int i = 1; i < MAXN; ++i) {
        nk[i] = bin_pow(i, n);
    }

    cnt_gcd_1[1] = 1;
    ll sum_pref = 0;
    for (int i = 2; i <= k; ++i) {

        vector<int> v;

        for (int j = 1; j * j <= i; ++j) {
            if (i % j == 0) {
                v.push_back(j);
                if (j * j != i)
                    v.push_back(i / j);
            }
        }
        ll val = 0;
        for (auto e : v) {
            sum_pref -= pref[e];
            sum_pref += mod;
            sum_pref %= mod;

            val += cnt_gcd_1[i / e];
            pref[e] = cnt_gcd_1[i / e];
            val %= mod;
        }
        sum_pref += val;
        sum_pref %= mod;
        ll crr = nk[i] - sum_pref;
        crr += mod;
        crr %= mod;

        cnt_gcd_1[i] = crr;
    }

    ll answr = 0;

    for (ll i =1; i <= k; ++i) {
        answr += ml(i, cnt_gcd_1[k / i]);
        answr %= mod;
    }
    cout << answr;
}
#else

#endif

void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
        cout << "Case #" << (i++)  << ":} ";
        solve();
        cout << endl;
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif

}

Measured memory_bytes: 6740
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

/// idea change korte hobe------
/*
because worst case
N (10^5)   M (10^5)
1 1 1 ------------------- 1 1 1
10^5  2
10^5 3
- -
- -
- -
- -
10^5 10^5
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    int a[n+2];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a+n);
    vector<pair<int,int> >v;
    for(int i = 0; i < m; i++)
    {
        int b,c;
        cin >> b >> c;
        v.push_back({c,b});
    }
    sort(v.rbegin(), v.rend());
    int idx = 0;
    for(int i = 0; i < m; i++)
    {
        int flag = 0;
        int lmt = v[i].second;
        if(idx >= n) break;
        for(int j = idx; j < min(idx+lmt, n);  j++)
        {
            if(a[j] < v[i].first)
            {
                a[j] = v[i].first;
            }
            else
            {
                flag = 1;
                break;
            }
        }
        if(flag) break;
        idx += lmt;
    }
    long long ans = 0;
    for(int i = 0; i < n; i++) ans += a[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1784
n = int(input())
s = input()
cum_R = [0]*(n+1)
for i in range(n):
    cum_R[i+1] = cum_R[i]+(s[i] == 'E')

INF = 10**18
ans = INF
for i in range(n):
    cnt_L = i-cum_R[i]
    cnt_R = cum_R[n]-cum_R[i+1]
    ans = min(ans, cnt_L+cnt_R)
print(ans)


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

int main() {
    int a,b;
    cin >> a >> b;
    cout << a+1-b << endl;
}

Measured memory_bytes: 256
while true

h,w = STDIN.gets.split.map(&:to_i)

break if h == 0 && w == 0

  ww = w
  hh = h

  while hh > 0

    while ww > 0
      print '#'
      ww -= 1
    end

    ww = w
    puts ''
    hh -= 1
  end

h,w,hh,ww = 0
  puts ''

end

Measured memory_bytes: 8740
n, c, k = map(int, input().split())
T = sorted([int(input()) for i in range(n)])

p = 0
b = 0
for i in range(n):
    t = T[i]
    if p == 0:
        w = t
    p += 1

    if t - w > k:
        b += 1
        p = 1
        w = t    
    elif p == c or t - w == k:
        b += 1
        p = 0

    if i == n - 1 and p > 0:
        b += 1
    #print(t, w, p, b)
print(b)

Measured memory_bytes: 8280
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
// ll gcd(ll a, ll b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
ll mod(ll x) {
	x%=MOD;
	if(x<0)x+=MOD;
	return x;
}
// ll power(int base, int power) {
// 	ll prod = 1;
// 	ll b = base;
// 	while(power) {
// 		if (power & 1) {
// 			prod = mod(prod*b);
// 		}
// 		b = mod(b*b);
// 		power/=2;
// 	}
// 	return prod;
// }
// struct line {
//     int m, c;
//     ll eval(int x) { return 1LL * m * x + c; }
//     double intersectX(line l) { return (double) (c - l.c) / (l.m - m); }
//0 is white, 1 is black
int n, par[60][200001];
ll k;
void solve() {
	scanf("%d %lld",&n,&k);
	for (int i = 1; i <= n; i++) {
		scanf("%d",&par[0][i]);
	}
	for (int i = 1; i < 60; i++) {
		for (int j = 1; j <= n; j++) {
			par[i][j] = par[i-1][par[i-1][j]];
		}
	}
	int cur = 1;
	for (int i = 0; i < 60; i++) {
		if (k&(1LL<<i)) {
			cur=par[i][cur];
		}
	}
	cout << cur << endl;
}
int main() {
	int t=1;
	// cin >> t;
	for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 50588
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
signed main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i * (i + 1) / 2 >= n) {
      cout << i << endl;
      return 0;
    }
  }
}

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

using ll = long long;

using namespace std;

int main() {
    int h, n;
    cin >> h >> n;
    for (int i=0, ai; i<n; i++) {
        cin >> ai;
        h -= ai;
    }
    cout << (h <= 0 ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
n = int(input())
sum_min = 2 * 10 ** 12
for i in range(1, int(n**0.5 // 1) + 1):
  if n % i == 0:
    sum_ = i + n // i - 2
    if sum_ < sum_min:
      sum_min = sum_
      
print(sum_min)

Measured memory_bytes: 3064
import math
import sys

def gcd(x, y):
  while y:
    x, y = y, x % y
  return x
n, m = map(int, input().split())
l = (n * m) // gcd(n, m)
a = l // n
b = l // m
s = input()
t = input()
i = 0
j = 0
while((i < n) & (j < m)):
  if (s[i] != t[j]):
    print(-1)
    sys.exit()
  else:
    i += b
    j += a
print(l)

Measured memory_bytes: 3316
from math import ceil as c
a,b=map(int,input().split())
amin=c(a/0.08)
amax=c((a+1)/0.08)-1
bmin=b*10
if amax<bmin or bmin+9<amin:
    print(-1)
elif bmin<amin:
    print(amin)
else:
    print(bmin)

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int n = input();
    i64 ans = 0;

    range(i, 1, n + 1) {
        for (int j = i; j <= n; j += i) {
            ans += j;
        }
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3644
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split())
memo = [-1]*N
dic = [[] for i in range(N)]
def dfs(dic, memo, v):
    if memo[v] != -1:
        return memo[v]
    plen = 0
    for i in dic[v]:
        plen = max(plen, dfs(dic, memo, i)+1)
    memo[v] = plen
    return plen
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1].append(y-1)
    
ans = 0
for i in range(N):
    ans = max(ans, dfs(dic, memo, i))
print(ans)

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

int main(int argc, char const *argv[]) {
    int N, sum=0;
    cin >> N;
    
    vector<int> A(N+1);
    vector<int> B(N-1);

    for (int i = 0; i < N-1; i++) {
        cin >> B.at(i);
    }

    for (int i = 0; i < N+1; i++) {
        if (i == 0) {
            A.at(0) = B.at(0);
        } else if (i == N) {
            A.at(N) = B.at(N-2);
        } else {
            A.at(i) = B.at(i-1);
        }
    }

    for (int i = 0; i < N; i++) {
        sum += min(A.at(i), A.at(i+1));
    }
    
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}


int main(){
  ll n; cin >> n; vl like(n); ll count = 0;
  rep(i,n){ ll x; cin >> x; like[i] = x-1; }
  
  for(ll i=0; i < n; i++){
    
    if(like[like[i]] == i) count++;
  
  }
  
  cout << count/2 << endl;
}

Measured memory_bytes: 1024
import java.util.*;

class Main {
   public static void main(String[] args)
   {
      Scanner scan  = new Scanner(System.in);
      String  X     = scan.next();
      String  Y     = scan.next();
      int     count = 0;

      for(int i = 0; i < 3; i++){
          if(X.charAt(i) != Y.charAt(2 - i)){
             }
          else{
              count++;
              }
          }
      if(count == 3){
         System.out.println("YES");
         }
      else{
          System.out.println("NO");
          }
   }
}


Measured memory_bytes: 21844
#include <iostream>
#define MAX_NUM 100

int inputs[MAX_NUM] = {0};

using namespace std;

void swap(int *a, int *b) {
	int temp = 0;
	temp = *a;
	*a = *b;
	*b = temp;
}

void printArray(int *a, int num) {
	for (int i=0; i<num; i++) {
		if (i>0) { cout<<" "; }
		cout<<a[i];
	}
	cout<<endl;
}

int main(int argc, char const *argv[])
{
	int n = 0;
	int swapCount = 0;
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> inputs[i];
	}

	int flag = 1;
	while (flag) {
		flag = 0;
		for(int i=n-1; i>0; i--) {
			if (inputs[i] < inputs[i-1]) {
				swap(&inputs[i-1], &inputs[i]);
				swapCount ++;
				flag = 1;
			}
		}
	}
	printArray(inputs, n);
	cout<<swapCount<<endl;
	return 0;
}


Measured memory_bytes: 3080
#include<cstdio>
#include<cstring>

int main()
{
    int n, A, B;
    int num;
    int p1, p2, p3;
    p1 = p2 = p3 = 0;
    scanf("%d", &n);
    scanf("%d %d", &A, &B);
    for (int i = 0; i < n;i++)
    {
        scanf("%d", &num);
        if(num<=A)
            p1++;
        else 
            if(num>B)
                p3++;
            else
                p2++;
    }
    if(p1<=p2 && p1<=p3)
        printf("%d", p1);
    else 
        if(p2<=p3)
        printf("%d", p2);
        else
            printf("%d", p3);
    return 0;
}

Measured memory_bytes: 1728
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll H;
    cin >> H;

    ll n = int(floor(log2(H)));
    
    cout << fixed << setprecision(20);
    cout << ll(pow(2, n+1) - 1) << endl;

}


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

int main () {

    int N, L;
    cin >> N >> L;

    int original = 0;
    for (int i = 1; i <= N; i++) {
        original += L + i - 1;
    }

    int min_diff = 1000000007;
    int ans;

    for (int i = 1; i <= N; i++) {

        int real = original - (L + i - 1);
        int diff = abs(original - real);
        if (diff < min_diff) {
            min_diff = diff;
            ans = real;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

bool isPalin(string s)
{
    int n = s.size();
    for(int i = 0; i < n; i++){
        if(s[i] != s[n-i-1]){
            return false;
        }
    }

    return true;
}

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

    string str;

    cin>>str;

    int n = str.size();

    if(isPalin(str) && isPalin(str.substr(0, n / 2)) && isPalin(str.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1))){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	int dp[n+1];
	for(int i=1;i<=n;i++)
	dp[i] = 1e9;
	dp[1] = 0;
	dp[2] = abs(a[2]-a[1]);
	
	for(int i=3;i<=n;i++)
	{
		for(int j=i-1;j>=i-2;j--)
		{
			dp[i] = min(dp[i],dp[j] + abs(a[i]-a[j]));
		}
	}
	cout<<dp[n]<<endl;
	
	
	return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int a, b, c;

signed main() {
    cin >> a >> b;
    if (a <= 5)cout << 0 << endl;
    else if (a <= 12)cout << b / 2 << endl;
    else cout << b << endl;
    return 0;
}


Measured memory_bytes: 256
//50
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int m,n;cin>>m>>n,m;){
    int s;
    cin>>s;
    int g[100][100];
    fill(g[0],g[100],1<<29);
    int sh[100][100]={};
    for(int i=1;i<=s;i++){
      int x,y;
      cin>>x>>y;
      x--;
      y--;
      sh[y][x]=i;
      g[y][x]=0;
    }
    int a=0;
    int t;
    cin>>t;
    while(t--){
      int x,y;
      cin>>x>>y;
      x--;
      y--;
      int gg[100][100];
      copy(g[0],g[n],gg[0]);
      int ss[100][100];
      copy(sh[0],sh[n],ss[0]);
      ss[y][x]=-1;
      gg[y][x]=0;
      for(int i=0;i<m*n;i++){
	for(int j=0;j<n;j++){
	  for(int k=0;k<m;k++){
	    for(int l=0;l<6;l++){
	      int dy[]={-1,0,1,1,0,-1};
	      int dx[][6]={{0,1,0,-1,-1,-1},{1,1,1,0,-1,0}};
	      int ny=j+dy[l];
	      int nx=k+dx[j%2][l];
	      if(0<=min(nx,ny)&&ny<n&&nx<m){
		int c=gg[ny][nx]+1;
		if(c<gg[j][k]){
		  gg[j][k]=c;
		  ss[j][k]=ss[ny][nx];
		}else if(c==gg[j][k]){
		  if(ss[j][k]!=ss[ny][nx]){
		    ss[j][k]=0;
		  }
		}
	      }
	    }
	  }
	}
      }
      int c=0;
      for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
	  c+=ss[i][j]==-1;
	}
      }
      a=max(c,a);
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1304
<?php
fscanf(STDIN, "%d %d", $n, $k);
$s = str_split(trim(fgets(STDIN)));

$k = $k-1;
if($s[$k] == 'A'){
    $s[$k] = 'a';
}elseif($s[$k] == 'B'){
    $s[$k] = 'b';
}else{
    $s[$k] = 'c';
}
echo implode($s);
?>

Measured memory_bytes: 4604
#include <stdio.h>

int main(void) {
	int a,b;
	int s,l;
	scanf("%d", &a);
	scanf("%d", &b);
	
	s = a*b;
	l = a+a+b+b ;
	
	printf("%d %d\n",s,l);
	
	return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
 
template<class Z> map<Z, int> factorize(Z n) {
  map<Z, int> res;
  for (Z i = 2; i * i <= n; ++i) while (n % i == 0) ++res[i], n /= i;
  if (n != 1) ++res[n];
  return res;
}
 
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint a, b; cin >> a >> b;
  auto mp = factorize(__gcd(a, b));
  cout << mp.size() + 1 << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{ int count=0;
  int N,K;
  cin>>N>>K;
  for(int i=1;i<=N;i++)
    if(i%2==1)
      count++;
      if(count>=K)
      cout<<"YES";
      else
      cout<<"NO";
}


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

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,k;
    cin>>n>>m>>k;
    char ch[n+1][m+1];
    ll x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>ch[i][j];
        }
    }
    if(ch[x2][y2]=='@')
    {
        cout<<"-1";
        return 0;
    }

    ll dis[n+1][m+1];
    ll vis[n+1][m+1];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            dis[i][j]=100000000;
            vis[i][j]=false;
        }
    }
    queue<pair<ll,ll> > q;
    q.push({x1,y1});
    dis[x1][y1]=0;
    vis[x1][y1]=true;
    
    while(!q.empty())
    {
        ll ux=q.front().first;
        ll uy=q.front().second;
        q.pop();
        if(ux==x2 and uy==y2)
            break;
        ll temp=1;
        while(temp<=k)
        {
            int nx=ux+temp;
            int ny=uy;
            temp++;
            if(nx<=0 or nx>n or ny<=0 or ny>m or ch[nx][ny]=='@' or dis[nx][ny]<1+dis[ux][uy])
                break;
            if(vis[nx][ny]==false)
            {
                vis[nx][ny]=true;
                dis[nx][ny]=dis[ux][uy]+1;
                q.push({nx,ny});
            }
        }
        temp=1;
        while(temp<=k)
        {
            int nx=ux-temp;
            int ny=uy;
            temp++;
            if(nx<=0 or nx>n or ny<=0 or ny>m or ch[nx][ny]=='@' or dis[nx][ny]<1+dis[ux][uy])
                break;
            if(vis[nx][ny]==false)
            {
                vis[nx][ny]=true;
                dis[nx][ny]=dis[ux][uy]+1;
                q.push({nx,ny});
            }
        }
        temp=1;
        while(temp<=k)
        {
            int nx=ux;
            int ny=uy+temp;
            temp++;
            if(nx<=0 or nx>n or ny<=0 or ny>m or ch[nx][ny]=='@' or dis[nx][ny]<1+dis[ux][uy])
                break;
            if(vis[nx][ny]==false)
            {
                vis[nx][ny]=true;
                dis[nx][ny]=dis[ux][uy]+1;
                q.push({nx,ny});
            }
        }
        temp=1;
        while(temp<=k)
        {
            int nx=ux;
            int ny=uy-temp;
            temp++;
            if(nx<=0 or nx>n or ny<=0 or ny>m or ch[nx][ny]=='@' or dis[nx][ny]<1+dis[ux][uy])
                break;
            if(vis[nx][ny]==false)
            {
                vis[nx][ny]=true;
                dis[nx][ny]=dis[ux][uy]+1;
                q.push({nx,ny});
            }
        }
    }
    if(dis[x2][y2]>100000)
        dis[x2][y2]=-1;
    cout<<dis[x2][y2];

    
    return 0;
}

Measured memory_bytes: 21824
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    int cnt = 0;
    reps(i, n)if(i%2 != 0) ++cnt;
    fcout(7) << (double)cnt/n << endl;

return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0;  i < n; i++) cin >> d.at(i);
  
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  int ans = 0, size = 1000;
  for(int i = 0; i < n; i++){
    if(size > d.at(i)){
      size = d.at(i);
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#ifdef __APPLE__
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

const int N = (int)2e5 + 123;
const long long M = (long long)2e15 + 123;
const int MOD = (int)1e9 + 7;
const int inf = (int)5e8;
const long long infll = (long long)1e17;

long long a[N];

long long ps[N];

map<long long, int> t;


int sum(long long r) {
    int result = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) {
        if (t.count(r)) {
            result += t[r];
        }
    }
    return result;
}

void inc(long long pos) {
    for (; pos < 2 * M; pos = (pos | (pos + 1)))
        ++t[pos];
}

int calc(long long pos) {
    return sum(2 * M - 1) - sum(pos - 1);
}

void solve() {
    int n;
    long long k;
    scanf("%d %lld", &n, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &a[i]);
        a[i] -= k;
        ps[i + 1] = ps[i] + a[i];
    }
    long long ans = 0;
    for (int i = n; i >= 0; --i) {
        ans += calc(ps[i] + M);
        inc(ps[i] + M);
    }
    /*for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            long long now = ps[j + 1] - ps[i] - k * (j - i + 1);
            if (now >= 0)  {
                ++ans;
            }
        }
    }*/
    printf("%lld\n", ans);
}

int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 189696
#include <bits/stdc++.h>
#include <fstream>
#define inputtxt() std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf())
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define foreach(e, v) for (auto e : v)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int gcd(int x,int y){
    if(y==0) return x;
    return gcd(y, x%y);
}

int main(){
    int n; cin >> n;
    vector<int> a(n); collect(a, n);
    vector<int> l(n), r(n);
    l[0] = a[0]; r[n-1] = a[n-1];
    reps(i,1,n-1){
        l[i] = gcd(l[i-1], a[i]);
        r[n-1-i] = gcd(r[n-i], a[n-1-i]);
    }
    int mx = max(l[n-2],r[1]);
    rep(i,n-2){
        mx = max(mx, gcd(l[i],r[i+2]));
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int ans = m;
    int tonnel = m;
    for(int i=0; i < n; i++){
        int p, q;
        cin >> p >> q;
        tonnel += p-q;
        ans = max(ans, tonnel);
        if(tonnel < 0){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){
  int a,b,k;

  cin>>a>>b>>k;

  for(int i=(int)max(a,b);i>=1;i--){
    if(a%i==0 && b%i==0){
      k--;
      //cout<<i<<endl;
    }
    if(k==0){
      cout<<i<<endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
#define mod 1000000007
typedef long long ll;
using namespace std;
int n,m;
char s[105];
int main()  
{  
	cin>>s;
	int len=strlen(s);
	cout<<s[0]<<len-2<<s[len-1];
	return 0;  
}  


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   long long int n,x,t,a,b;
   cin>>n>>x>>t;
   a=0;
   b=x;
   while(n>x){
       a=a+t;
       x=x+b;
   }
   a=a+t;
   cout<<a<<endl;
   return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,sum=0;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3588
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 全国統一プログラミング王決定戦予選：D - Restore the Tree
import sys
sys.setrecursionlimit(1000000)
back = []


def calc(e):
    global back
    # print 'e =', e, ', b =', back[e]

    if back[e][1] == -1:
        if len(back[e][0]) == 0:
            back[e][1] = 0
            # print 'ret =', 0
            return 0
        elif len(back[e][0]) == 1:
            l = calc(back[e][0][0]) + 1
            back[e][1] = l
            # print 'ret =', l
            return l
        maxl = calc(back[e][0][0])
        maxi = 0
        for i, s in enumerate(back[e][0][1:], 1):
            l = calc(s)
            if l >= maxl:
                maxl = l
                back[e][0][maxi] = -1
                maxi = i
            else:
                back[e][0][i] = -1
        back[e][1] = maxl + 1
        # print 'ret =', maxl + 1
        return maxl + 1
    else:
        # print 'ret =', back[e][1]
        return back[e][1]


def main():
    global back
    N, M = [int(i) for i in raw_input().strip().split(' ')]

    A = []
    for _ in range(N+M-1):
        A.append([int(i)-1 for i in raw_input().strip().split(' ')])
    # H.sort(reverse=False)

    back = [[[], -1] for _ in range(N)]

    for s, e in A:
        back[e][0].append(s)
    # print 'back =', back

    for i, b in enumerate(back):
        if b[1] == -1:
            # back[i][1] = calc(i)
            calc(i)

    # print 'back =', back
    for b in back:
        if b[0] == []:
            print 0
        else:
            for s in b[0]:
                # print 's =', s
                if s != -1:
                    print s+1


if __name__ == '__main__':
    main()


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

using ll = long long;

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

  int N;
  cin >> N;
  ll res = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      for (int k = 1; k <= N; ++k) {
        res += __gcd(__gcd(i, j), k);
      }
    }
  }
  cout << res << '\n';
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    constexpr int N_MAX = 100000;
    int N;
    int h[N_MAX];
    cin >> N;
    REP(i, N) cin >> h[i];

    int dp[N_MAX];
    dp[N - 1] = 0;
    RREP(i, N - 1) {
        int cost1 = INT_MAX;
        int cost2 = INT_MAX;
        if (i + 1 < N) {
            cost1 = abs(h[i] - h[i + 1]) + dp[i + 1];
        }
        if (i + 2 < N) {
            cost2 = abs(h[i] - h[i + 2]) + dp[i + 2];
        }
        dp[i] = min(cost1, cost2);
    }
    cout << dp[0] << endl;
    return 0;
}



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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s;
    cin>>s;
    cout<<s.substr(0,5)<<' '<<s.substr(6,7)<<' '<<s.substr(14);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999LL
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int main() {
	int n;
	int v[22], c[22];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> v[i];
	for (int i = 0; i < n; i++)cin >> c[i];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (v[i] - c[i] > 0)ans += v[i] - c[i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
 public static void main(String[] agrs){
  Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  if(a*b%2==0){
   System.out.println("Even");
  }else{
   System.out.println("Odd");
  }
 }
}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
const int MAXN=5e5+5;
typedef long long ll;

ll arr[MAXN];
int main()
{
    string s;
    while(cin>>s)
    {
        memset(arr,0,sizeof(arr));
        int n=s.size();
        for(int i=0;i<n;i++)
        {
            if(s[i]=='<')arr[i+1]=max(arr[i+1],arr[i]+1);
        }
        for(int i=n-1;i>=0;i--)
        {
            if(s[i]=='>')arr[i]=max(arr[i],arr[i+1]+1);
        }
        ll sum=0;
        for(int i=0;i<=n;i++)sum+=arr[i];
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int H,W;
char grid[101][101] = {};

void dfs(int y,int x,char c){
	grid[y][x] = 'C';
	REP(i,4){
		int ny = y + dy[i];
		int nx = x + dx[i];

		if ((nx >= W) or (W < 0) or (ny >= H) or (H < 0)) continue;
		if (grid[ny][nx] == c) dfs(ny,nx,c);
	}

	return;
}

int main(){
	while(true){
		SCD2(H,W);
		int count = 0;
		getchar();

		if ((H==0) and (W==0)) break;

		REP(i,H){
			REP(j,W){
				cin >> grid[i][j];
			}
			getchar();
		}

		REP(i,H){
			REP(j,W){
				if (grid[i][j] == 'C') continue;
				dfs(i,j,grid[i][j]);
				count++;
			}
		}

		PRINTD(count);
	}
}


Measured memory_bytes: 3628
def check(l, r, s, len)
  while l >= 0 && r < len
    break if s[l] != s[r]
    l -= 1; r += 1
  end
  s[l+1..r-1] if (r - 1) - (l + 1) >= 2
end

while l = gets
  s = ''
  l.split('').each{|c| s += c.capitalize if c =~ /[a-zA-Z]/ }
  cand = []
  len = s.size
  (1..len-2).each do |c|
    cand << check(c, c, s, len)
    cand << check(c, c + 1, s, len)
  end
  cand = cand.compact.uniq
  checker = cand.map{ |s| (1...(s.size-1)/2).map{ |i| s[i...-i] }}.flatten.uniq
  ret = []
  cand.each{ |s| ret << s unless checker.include?(s) }
  puts ret.join(' ')
end

Measured memory_bytes: 8796
import java.util.Scanner;

public class Main {

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

		String output = a+b>=10 ? "error" : ((a + b) + "");
		System.out.println(output);
	}
}



Measured memory_bytes: 22740
# include <iostream>
# include <string>
# include <algorithm>
using namespace std;
string a[110];
int n,i;
int main () {
    cin>>n>>i;
    for(i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
        cout<<a[i];
    cout<<"\n";
    return 0;
}


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

int main() { 
    int n;
    cin >> n;
    int x = 1;
    while(x*2 <= n){
        x *= 2;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
bool cmp(pair<string,int>p1,pair<string,int>p2)
{
    if(p1.second==p2.second)
    {
        return p1.first<p2.first;
    }

}
int main()
{
    int n,ma=0;
    string s;
    cin>>n;
    map<string,int>mp;
    while(n--)
    {
        cin>>s;
        mp[s]++;
    }
    vector<pair<string,int>>v;
    for(auto i:mp)
    {
        ma=max(ma,i.second);

    }
    for(auto i:mp)
    {
        if(i.second==ma)
        {
            v.push_back(make_pair(i.first,i.second));
        }
    }
    sort(v.begin(),v.end(),cmp);
    for(auto i:v)
    {
        cout<<i.first<<endl;
    }

    return 0;
}


Measured memory_bytes: 29384
#include <iostream>
#include <tuple>
#include <queue>
#include <algorithm>
#define REP(a, b, c) for (int (a) = (b); (a) < (c); ++a)
using namespace std;
typedef tuple<int, int, int> tiii;
const int INF = 1 << 29;
int N, M;
int A[100][100];
int a, b, c;
queue<tiii> q;
int main(void) {
	cin >> N >> M;
	fill(A[0], A[N], INF);
	for (int i = 0; i < M; ++i) {
		cin >> a >> b >> c;
		--a; --b;
		A[a][b] = A[b][a] = c;
		q.push(tiii(a, b, c));
	}
	REP(k, 0, N) REP(i, 0, N) REP(j, 0, N) {
		A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
	}
	int ans = M;
	while (!q.empty()) {
		tie(a, b, c) = q.front(); q.pop();
		if (A[a][b] == c) --ans;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int l, n;
    cin >> l >> n;
    int sum = 0, x, w;
    while(n-- > 0){
        cin >> x >> w;
        sum += x*w;
    }
    sum *= -1;
    vector<pair<int,int>> v;
    for(int i = l; i > 0; i--){
        if(sum%i == 0 && sum/i > 0){
            v.push_back({i, abs(sum/i)});
            sum -= abs(sum/i)*i;
        }
        i *= -1;
        if(sum%i == 0 && sum/i > 0){
            v.push_back({i, abs(sum/i)});
            sum -= abs(sum/i)*i;
        }
        i *= -1;
    }
    cout << v.size() << endl;
    for(pair<int,int> p : v)    cout << p.first << " " << p.second << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string>
#include<math.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int main(void) {
	ll n, ans = 0;
	cin >> n;
	vector<ll>a(n), b(n);
	for (ll i = 0;i < n;i++) {
		cin >> a[i];
		a[i] = a[i] - i - 1;
		b[i] = a[i];
	}
	sort(b.begin(), b.end());;
	if (n %2==0) {
		ll ans1 = 0, ans2 = 0;
		for (ll i = 0;i < n;i++) {
			ans1 += abs(a[i] - b[n / 2 - 1]);
			ans2 += abs(a[i] - b[n / 2]);
		}
		cout << min(ans1, ans2) << endl;
	}
	else {
		for (ll i = 0;i < n;i++) {
			ans += abs(a[i] - b[n / 2]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(int argc, char *argv[])
{
  string s;
  int alpnum[26] = {};
  while(getline(cin, s)) {

    for(int i = 0; i < s.length(); i++) {
      if(isalnum(s[i])) {
        alpnum[tolower(s[i]) - 'a']++;
      }
    }
  }
    for(int i = 0; i < 26; i++) {
      cout << (char)('a'+ i) << " : "  << alpnum[i] << endl;
    }

  return 0;
}



Measured memory_bytes: 3192