akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i,n) cin >> L[i];
  sort(L.begin(), L.end());

  int distance, ab;
  int ans = 0;
  int l;
  rep(b,n) rep(a,b) {
      ab = L[a] + L[b];
      int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
      l = b + 1;
      ans += r - l;
  }

  cout << ans << endl;

}

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def solve(): 
    S = input()
    count = 0
    count_a = 0
    s_ = ''

    for s in S:
        if s == 'A':
            if s_ == 'B':
                count_a = 0
            count_a += 1 
        elif s == 'B' and s_ == 'B':
            count_a = 0
        elif s == 'C':
            if s_ =='B':
                count += count_a
            else:
                count_a = 0
        s_ = s

    res = count
    return str(res)

if __name__ == '__main__':
    print(solve())



Measured memory_bytes: 3500
package main

import (
	"fmt"
)

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

func solve(n int) string {
	if n == 0 {
		return ""
	}
	return solve((n-1)/26) + string([]byte{byte((n-1)%26) + 'a'})
}


Measured memory_bytes: 1768
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <algorithm>
#define mp make_pair

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;

const int MAXN = 310;

template<typename T> inline T read() {
	T res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

template<typename T> inline void chkmax(T &a, T b) { if(a < b) a = b; }
template<typename T> inline void chkmin(T &a, T b) { if(a > b) a = b; }

double dp[MAXN][MAXN][MAXN];

int n, b[4], sum;

double dfs(int x, int y, int z) {
   if (dp[x][y][z] != -1) return dp[x][y][z];
   double res = n;
   if(x) res += dfs(x - 1, y, z) * x;
   if(y) res += dfs(x + 1, y - 1, z) * y;
   if(z) res += dfs(x, y + 1, z - 1) * z;
   if(x + y + z) res /= x + y + z;
   return dp[x][y][z] = res;
}

void solve() {
	n = read<int>();
	for(int i = 1; i <= n; ++i) { int x = read<int>(); ++b[x]; }
	for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j)
			for(int k = 0; k <= n; ++k) dp[i][j][k] = -1;

	printf("%.10lf\n", dfs(b[1], b[2], b[3]) - n);
}

int main() {

	solve();

	return 0;
}



Measured memory_bytes: 227584
# -*- coding: utf-8 -*-
import sys
from collections import deque
import copy

N,M,Q=map(int, sys.stdin.readline().split())
X=[ map(int, sys.stdin.readline().split()) for _ in range(Q) ]

qq=deque()
for m in range(1,M+1):
    q=deque()
    q.append([m])
    while q:
        if N<len(q[0]):
            qq+=q
            break
        fro=q.popleft()
        if N<len(fro):break
        last=fro[-1]
        for to in range(last,M+1):
            q.append(fro+[to])

ans=float("-inf")
for L in qq:
    temp_ans=0
    for a,b,c,d in X:
        if L[b-1]-L[a-1]==c:
            temp_ans+=d
    ans=max(ans,temp_ans)
print ans


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

int n,l;

int main(){
    cin>>n>>l;
    if(l>0){cout<<n*(n-1)/2+l*(n-1)<<endl;}
    else if(l>-n){cout<<n*(n-1)/2+l*n<<endl;}
    else{cout<<(n-2)*(n-1)/2+l*(n-1)<<endl;}
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc152/tasks/abc152_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  // 末尾は 0 でない
  VVL cts(10, VL(10));

  rep1(f, 9) rep1(b, 9) {
    if (f == b && f <= N) {
      cts[f][b]++;
    }

    ll digit = 2;
    for (ll digit = 2; f * pow(10, digit - 1) + b <= N; digit++) {
      ll low = f * pow(10, digit - 1) + b;
      ll high = (f + 1) * pow(10, digit - 1) - 10 + b;

      if (high <= N) {
        cts[f][b] += pow(10, digit - 2);
        continue;
      }

      // N の先頭と末尾を除いた数 + 0 only
      ll mid_ct = N / 10 - f * pow(10, digit - 2) + 1;

      if (N % 10 >= b) {
        cts[f][b] += mid_ct;
      } else if (N % 10 < b) {
        cts[f][b] += mid_ct - 1;
      }
    }
  }

  ll res = 0;

  rep1(f, 9) rep1(b, 9) { res += cts[f][b] * cts[b][f]; }

  cout << res << endl;
}

void solve2() {
  ll N;
  cin >> N;

  // 末尾は 0 でない
  VVL cts(10, VL(10));

  rep1(num, N) {
    string str = to_string(num);

    ll f = str.front() - '0';
    ll b = str.back() - '0';

    if (b == 0) continue;

    cts[f][b]++;
  }

  ll res = 0;

  rep1(f, 9) rep1(b, 9) { res += cts[f][b] * cts[b][f]; }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

int calc_diameter(vec<vec<int>>&);
pint farthest_node_from(int, vec<vec<int>>&);
int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vec<vec<int>> adj(N, vec<int>());
    range(i, 0, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj.at(a).emplace_back(b);
        adj.at(b).emplace_back(a);
    }
    int diameter = calc_diameter(adj);
    // cout << diameter << "\n";
    string ans = (diameter % 3 == 2) ? "Second" : "First";
    cout << ans << "\n";
    return 0;
}

int calc_diameter(vec<vec<int>>& adj) {
    pint farthest_node = farthest_node_from(0, adj);
    pint node_of_diameter = farthest_node_from(farthest_node.first, adj);
    return node_of_diameter.second + 1;
}

pint farthest_node_from(int node, vec<vec<int>>& adj) {
    int num_nodes = adj.size();
    vec<int> distance_of(num_nodes, -1);
    vec<int> stack;
    stack.emplace_back(node);
    distance_of.at(node) = 0;
    while (!stack.empty()) {
        int node = stack.back(); stack.pop_back();
        for (auto neighbor : adj.at(node)) {
            if (distance_of.at(neighbor) != -1) continue;
            distance_of.at(neighbor) = distance_of.at(node) + 1;
            stack.emplace_back(neighbor);
        }
    }
    pint node_with_maxdist = {-1, -1};
    range(node, 0, num_nodes) {
        if (distance_of.at(node) > node_with_maxdist.second) {
            node_with_maxdist = {node, distance_of.at(node)};
        }
    }
    return node_with_maxdist;
}

Measured memory_bytes: 14548
a = gets.to_i
b = gets.to_i
if a == b
    puts 1
    exit
end

while a.bit_length == b.bit_length
    c = 1<<(a.bit_length-1)
    a -= c
    b -= c
end

bitA = a.bit_length - 1
bitB = b.bit_length - 1
bitB2 = (b - (1<<bitB)).bit_length - 1

if bitA <= bitB2
    ans = 2 * (1<<bitB) - a
else
    ans = (1<<bitB) - a + (1<<(bitB2+1))
    while bitA >= 0
        ans += (1<<bitB) - (1<<(bitA+1))
        bitB = bitA
        a -= 1<<bitA
        bitA = a.bit_length - 1
    end
    ans += 1<<bitB
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define __dist_rep(a1,a2,a3,f,...) f
#define __rep2(i,n) for (int i=0; i<n; ++i)
#define __rep3(i,a,b) for (int i=(a); i<(b); ++i)
#define rep(...) __dist_rep(__VA_ARGS__,__rep3,__rep2)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n)-1; i>=0; --i)
#define fore(a,x) for (auto &(a):(x))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = 1LL<<60;

int n;
string s[100000];

int main() {
  cin>>n;
  map<string,ll> mp;
  map<string,ll> mp2;
  rep(i,n) {
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
    mp[s[i]]=mp2[s[i]]=0;
  }
  rep(i,n) {
    mp[s[i]]+=mp2[s[i]];
    mp2[s[i]]++;
  }
  ll ans=0;
  fore(v,mp) {
    ans+=v.second;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 29184
#include <vector>
#include <complex>
#include <cmath>
using namespace std;

vector<complex<double>> FFT(vector<complex<double>> v, bool inv)
{
    double pi = acos(-1.);

    int n = int(v.size());
    int b = 0;
    while (1<<b<n)
        b++;
    
    vector<complex<double>> f(n);
    for (int i=0; i<n; i++)
    {
        int t=0;
        for (int j=0; j<b; j++)
            t = t<<1 | i>>j&1;
        f[t] = v[i];
    }

    vector<complex<double>> w(n);
    for (int i=0; i<n; i++)
    {
        double t = (inv?2:-2)*pi*i/n;
        w[i] = complex<double>(cos(t), sin(t));
    }

    for (int i=0; i<b; i++)
    for (int j=0; j<n; j+=1<<-~i)
    for (int k=0; k<1<<i; k++)
    {
        int l = k+(1<<i);
        complex<double> x = f[j+k];
        complex<double> y = f[j+l];
        f[j+k] = x + y*w[k<<(b-i-1)];
        f[j+l] = x + y*w[l<<(b-i-1)];
    }

    if (inv)
        for (int i=0; i<n; i++)
            f[i] /= n;

    return f;
}

//  ret[i] = ΣA[t]B[i-t]
vector<double> convolution(vector<double> A, vector<double> B)
{
    int n = 1;
    while (n<(int)A.size()+(int)B.size()-1)
        n *= 2;
    vector<complex<double>> a(n), b(n);
    for (int i=0; i<(int)A.size(); i++)
        a[i] = A[i];
    for (int i=0; i<(int)B.size(); i++)
        b[i] = B[i];
    vector<complex<double>> at = FFT(a, false);
    vector<complex<double>> bt = FFT(b, false);
    vector<complex<double>> ct(n);
    for (int i=0; i<n; i++)
        ct[i] = at[i]*bt[i];
    vector<complex<double>> c = FFT(ct, true);
    vector<double> C((int)A.size()+(int)B.size());
    for (int i=0; i<(int)C.size(); i++)
        C[i] = c[i].real();
    return C;
}

#include <iostream>

int main()
{
    int N;
    cin>>N;
    vector<long long> A(N);
    for (long long &a: A)
        cin>>a;

    long long P = 200003;
    
    vector<long long> pow(P);
    long long g = 1;
    for (int i=0; i<P; i++)
    {
        pow[i] = g;
        g = g*2%P;
    }
    vector<long long> log(P);
    for (int i=0; i<P; i++)
        log[pow[i]] = i;

    vector<double> C(P);
    for (long long a: A)
        if (a>0)
            C[log[a]] += 1.0;
    vector<double> C2 = convolution(C, C);

    long long ans = 0;
    for (int i=0; i<2*P-1; i++)
        ans += pow[i%(P-1)]*(long long)(C2[i]+.5);
    for (long long a: A)
        ans -= a*a%P;
    ans /= 2;
    cout<<ans<<endl;
}


Measured memory_bytes: 78340
def dijkstra(g, s)

  # inf = 10 ** 12
  inf = Float::INFINITY
  dist = Array.new(g.size, inf)
  dist[s] = 0

  # que = PriorityQueue.new
  q = []
  q << [0, s]

  while q.any?

    d, v = q.pop
    next if dist[v] < d
    # p g[v]
    g[v].each do |(u, c)|
      if dist[u] > d + c
        t = d + c
        dist[u] = t
        q.push( [t, u ] )
      end
    end
    # p que
  end

  # dist.map!{|d| d == inf ? "INF" : d }
  dist
end

n = gets.to_s.to_i
# n = gets.to_s.split.map{|t|t.to_i}

G = Array.new(n){ [] }
(n-1).times do
  s, t, d = gets.to_s.split.map{|t|t.to_i}
  s -= 1
  t -= 1
  G[s] << [t, d]
  G[t] << [s, d]
end
# pp G
q, k = gets.to_s.split.map{|t|t.to_i}
k -= 1
dist = dijkstra(G, k)
ans = []
q.times do
  x, y = gets.to_s.split.map{|t|t.to_i-1}
  ans << (dist[x] + dist[y])
end

puts ans


# judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
# http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4445328


Measured memory_bytes: 29180
//https://atcoder.jp/contests/dp/tasks/dp_b
//B - Frog 2

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

const int inf=1e9+7;

int main() {
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	vector<int> h(n);
	for(int& x:h) cin>>x;
	
	vector<int> dp(n, inf);
	dp[0]=0;
	for(int i=0; i<n; ++i){
		for(int j=i+1; j<=i+k; ++j){ // skoki i+1,i+2,…,i+K :-)
			if(j<n){
				dp[j]=min(dp[j], dp[i]+abs(h[i]-h[j]));
			}
		}
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





// けんちょんさんの記事
// 定義式を変形する

ll dp[2004][2004];
ll acc[2004][2004];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n, m;
    cin >> n >> m;
    
    vector<int> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    
    
    dp[0][0] = 1;
    acc[1][1] = 1;
    
    rep(i, n + 1) rep(j, m + 1) {
        if (i + j == 0) continue;
        if (i && j && s[i - 1] == t[j - 1]) dp[i][j] = acc[i][j];
        (acc[i + 1][j + 1] = acc[i + 1][j] + acc[i][j + 1] - acc[i][j] + dp[i][j] + inf) %= inf;
    }
    
    // rep(i, n + 2) { rep(j, m + 2) cout << acc[i][j] << " "; cout << endl; }
    cout << acc[n + 1][m + 1] << endl;
}




Measured memory_bytes: 62848
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
ll INF = 1e10;

int main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n)cin >> h[i];
	vector<int>dp(n);
	rep(i, n)
	{
		if (i == 0)dp[i] = 0;
		else if (i == 1)dp[i] = abs(h[i] - h[i - 1]);
		else dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	co(dp[n - 1]);
	return 0;
}


Measured memory_bytes: 1024
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var L = int.Parse(line[1]);
        var a = new string[n];
        for (int i = 0; i < n; i++) a[i] = Console.ReadLine().Trim();
        var used = new bool[n];
        var ans1 = getAns1(a, n, used);
        var ans = getAns2(a, used, ans1, n);
        Console.WriteLine(ans);
    }
    static bool check(string s)
    {
        var imax = s.Length / 2;
        for (int i = 0; i < imax; i++)
            if (s[i] != s[s.Length - 1 - i]) return false;
        return true;
    }
    static string getAns2(string[] a, bool[] used, List<string> ans1, int n)
    {
        var ans2 = new List<string>();
        for (int i = 0; i < n; i++)
            if (!used[i] && check(a[i])) ans2.Add(a[i]);
        ans2.Sort();
        var sb = new StringBuilder();
        for (int i = 0; i < ans1.Count(); i++) sb.Append(ans1[i]);
        var ans3 = sb.ToString();
        var ans4 = getRev(ans3);
        if (ans2.Count() > 0) return ans3 + ans2[0] + ans4;
        else return ans3 + ans4;
    }
    static string getRev(string s)
    {
        var a = s.ToCharArray();
        Array.Reverse(a);
        return new string(a);
    }
    static List<string> getAns1(string[] a, int n, bool[] used)
    {
        var ans1 = new List<string>();
        for (int i = 0; i < n; i++)
            if (!used[i])
            {
                var w = getRev(a[i]);
                for (int j = i + 1; j < n; j++)
                    if (!used[j] && w == a[j])
                    {
                        var t = a[i].CompareTo(w);
                        if (t <= 0) ans1.Add(a[i]);
                        else ans1.Add(w);
                        used[i] = true;
                        used[j] = true;
                        break;
                    }
            }
        ans1.Sort();
        return ans1;
    }
}



Measured memory_bytes: 21084
#include <iostream>
#include <cstdlib>

void get_input(int& n, int& sum) {
    int a, b;
    std::cin >> a >> b;
    if (a == 0 && b == 0) {
        exit(0);
    } 
    n = a;
    sum = b;
    return;
}

int solve(int n, int sum, int max) {
   if (n == 1) {
        if (sum <= max) {
//            std::cout << "return: " << 1 << std::endl;
            return 1;
        } else {
//            std::cout << "return: " << 0 << std::endl;
            return 0;
        }
    } 

    if (sum <= max) {
        max = sum;
    }
/*    std::cout << "n: " << n << ' '
              << "sum: " << sum << ' ' 
              << "max: " << max << std::endl; */
 
    int result = 0;
    for (int i = 0; i < max; i++) {
        result += solve(n-1, sum - (max - i), max - (i + 1));
    }
//    std::cout << "return: " << result << std::endl;
    return result;
}


int main(void) {
    int n, sum;
    while (true) {
        get_input(n, sum);
        std::cout << solve(n, sum, 9) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int A,B;
  cin >> A >> B;
  cout << (A + B + 1)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, m, i, j, k, a, b, c;
	cin >> n >> m;
	a = 0; b = 1LL << 60;
	while (a < b) {
		c = (a + b + 1) / 2;

		bool valid = false;
		if ((m >= 2 * c) && ((m - 2 * c) / 2 + n >= c)) valid = true;
		
		if (valid) a = c;
		else b = c - 1;
	}
	cout << a << "\n";

	return 0;
}



Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

s=get_nsp
k=gets.to_i
N=s.size
ab=("a".."z").to_a
N.times do|i|
    if s[i]!="a" and k>="z".ord-s[i].ord+1
      k-="z".ord-s[i].ord+1
      s[i]="a"
    end
end
if k>0
  s[N-1]=ab[(s[N-1].ord-"a".ord+k)%26]
end
puts s.join("")

Measured memory_bytes: 22920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) {if (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int MOD = 1000000007;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
    int n;
    cin >> n;
    vs s(n);
    rep(i, n) cin >> s[i];
    map<char, int> dict;
    rep(i, n) {
        
        if (i == 0) rep(j, s[i].size()) {
            int x = count(s[i].cbegin(), s[i].cend(), s[i][j]);
            if (dict.count(s[i][j])) {
                chmin(dict[s[i][j]], x);
            } else if (i == 0) {
                dict[s[i][j]] = x;
            }
        }
        else {
            for (auto p : dict) {
                int x = count(s[i].cbegin(), s[i].cend(), p.first);
                if (x > 0) {
                    chmin(dict[p.first], x);
                } else {
                    dict.erase(p.first);
                }
            }
        }
    }
    string ans = "";
    for (char c = 'a' ; c <= 'z'; c++) {
        if (dict.count(c)) {
            rep(i, dict[c]) ans += c;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
const int n=1000005;
int num[n];

int main(){
    long long a,b;
    cin>>a>>b;
    int t1=0;
    int n1=n;
    for(int i=0;i<n1;i++){
        num[i]=0;
    }
    vector<int> array(n1);
    for(int i=2;i<n1;i++){
		if (num[i] == 0) {
			array[t1] = i;
			t1++;
			int k = 1;
			while (i*k < n1) {
				num[i*k] = 1;
				k++;
			}
		}
    }
//    cout<<"ok";
    int sum=1;
    int sup=1000001;
    long long min=a;
    if(min>b)min=b;
    int root=sqrt(min)+2;
    int t=0;
    int prime=0;
    int tmp;
    while(array[t]<root){
        if(min%array[t]==0){
            while(min%array[t]==0){
                min=min/array[t];
            }
            if(a%array[t]==0 && b%array[t]==0)sum++;
        }
/*        if(a%array[t]==0 && b%array[t]==0){
            sum++;
        }*/
        t++;
    }
    if(min>1){
        if(a%min==0 && b%min==0) sum++;
    }
    if(a==1 || b==1)sum=1;

    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>

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

using namespace std;

int A, B, C, X, Y;

int main() {
    int ans = 0, c_count = 0;
    cin >> A >> B >> C >> X >> Y;

    if (A > 2 * C * A / (A + B))
        c_count = X;
    if (B > 2 * C * B / (A + B) && Y < c_count)
        c_count = Y;
    ans += 2 * C * c_count;

    if (X > c_count) {
        if (A > 2 * C)
            ans += 2 * C * (X - c_count);
        else
            ans += A * (X - c_count);
    }
    if (Y > c_count) {
        if (B > 2 * C)
            ans += 2 * C * (Y - c_count);
        else
            ans += B * (Y - c_count);
    }
    cout << ans << endl;

    return 0;
}

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

#define ff first
#define ss second
#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define endl "\n"      // Comment in INTERACTIVE(there just use endl which flushes output , no need of fflush(sdtout)).
//  for counting setbits -> __builtin_popcountll(x)
// for counting zerobits -> __builtin_ctzll(x)
#define fastio() ios_base::sync_with_stdio(false);        cin.tie(NULL); //(unties i/o buffer).
            // DON'T USE SCANF/PRINTF WITH IT (c/c++ -> seperates buffer).

const int mod = 1000000007;
 const int N = 3000 + 2;
 int dp[N][N];

int32_t main(){
    fastio()
    // #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    // #endif

     // ***** AC_chahiye EK BAR MEIN

     // BEGIN CODE HERE
    char s1[3001] , s2[3001];
    cin>>s1>>s2;

    int l1 = strlen(s1);
    int l2 = strlen(s2);

    for(int i = 0;i <= l1; ++i)
        dp[i][0] = 0;
    for(int i = 0;i <= l2; ++i)
        dp[0][i] = 0;
    

    for(int i = 1;i <= l1; ++i){
        for(int j = 1;j <= l2; ++j){
            if(s2[j - 1] == s1[i - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i][j -1], dp[i - 1][j]);
        }
    }
    //cout<<dp[l2][l1];
    char str[3001];
    int l = dp[l1][l2];
    str[l] = 0;
    int i = l1 , j = l2;
    while(i && j){
        if(s1[i - 1] == s2[j-1]){
            str[--l] = s1[i - 1];
            i--;  j--;
        }
        else if(dp[i][j - 1]  > dp[i - 1][j])
            j--;
        else
            i--;
    }
    cout<<str<<endl;
    //getch();
}


Measured memory_bytes: 70784
#include <deque>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool balance(string line) {
  deque<char> stack;
  for (auto c : line) {
    switch (c) {
      case '(':
      case '[':
        stack.push_back(c);
        break;
      case ')':
      case ']':
        if (stack.empty()) {
          return false;
        }

        if ((stack.back() == '(' && c == ')') ||
            (stack.back() == '[' && c == ']')) {
          stack.pop_back();
          break;
        } else {
          return false;
        }
      default:
        break;
    }
  }

  return 0 == stack.size();
}

int main() {
  string line;
  while (getline(cin, line)) {
    if ("." == line) {
      break;
    }

    cout << (balance(line) ? "yes" : "no") << endl;
  }
  return 0;
}


Measured memory_bytes: 3176
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;

int main(int argc, const char * argv[]) {
    double R;
    cin >> R;
    cout << fixed << setprecision(20) << R*2.0*M_PI << endl;
    return 0;
    
}




Measured memory_bytes: 3772
def examC():
    N, T = LI()
    t = LI()
    cur = T
    before = 0
    for i in t[1:]:
        cur += min(T,i-before)
        before = i
    print(cur)

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

int main(){

  int card[50];
  int esc[50];
  int n,r;
  int p,c;

  while(cin >> n >> r){
    if(n==0 && r==0){ break; }
    
    for(int i=0; i<n; i++){
      card[i]=n-i;
    }

    for(int i=0; i<r; i++){
      cin >> p >> c;

      /*
      cout << "prev:";
      for(int j=0; j<n; j++)cout << card[j] << ' ';
      cout << endl;
      */

      for(int j=0; j<c; j++){
	esc[j] = card[p-1+j];
      }
      for(int j=p-2; j>=0; j--){
	card[j+c]=card[j];
      }
      for(int j=0; j<c; j++){
	card[j] = esc[j];
      }

      /*cout << "now:";
      for(int j=0; j<n; j++)cout << card[j] << ' ';
      cout << endl;
      cout << "esc:";
      for(int j=0; j<c; j++)cout << esc[j] << ' ';
      cout << endl;
      */
   }

    
    cout << card[0] << endl;
  }
      

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

__attribute__ ((constructor))
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}

signed main(){
  vector<int> v(5);
  rep(i, 5) cin >> v[i];
  sort(v.begin(), v.end());
  int k;
  cin >> k;
  bool ok = 1;
  if(v[4] - v[0] > k)
    ok = 0;
  if(ok)
    cout << "Yay!" << endl;
  else
  {
    cout << ":(" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3612
/*
  AtCoder Beginner Contest 095
  A - Something on It
*/

#include<iostream>
using namespace std;

char memo[4];

int main() {
  scanf("%s", memo);
  int sum = 700;
  for (int i = 0; i < 3; ++i) {
    if (memo[i] == 'o') sum += 100;
  }

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

Measured memory_bytes: 256
#include <cstdio>

int main(void){
  int  a[4];
  char in[5], ans[10];
  scanf("%s", in);
  for (int i=0; i<4; i++){
    a[i] = in[i] - '0';
  }
  sprintf(ans, "%d %d %d %d=7", a[0],a[1],a[2],a[3]);
  for (int i=0; i < 1<<3; i++){
    int sum = a[0];
    for (int j=0; j<3; j++){
      if (i & 1<<j){
        sum += a[j+1];
        ans[j*2+1] = '+';
      } else {
        sum -= a[j+1];
        ans[j*2+1] = '-';
      }
    }
    if (sum == 7){
      puts(ans);
      i = 1<<3; // finish search
    }
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

struct edge{ int to, cost; };

int V,E;// number of (vertices, edges)
vector<vector<edge>> graph;
vector<long long int> d;// shortest distances

void Dijkstra(int s){// s = starting point
    priority_queue<
        pair<long long int, int>// temporarily keeping (shortest distance, vertex)
        , vector<pair<long long int, int>>, greater<pair<long long int, int>>// shorter ones first
    > pq;

    // initialize (INF)
    for(int i=0; i<V; i++){
        d[i] = INF;
    }
    d[s] = 0;
    pq.push({0,s});

    // search
    pair<long long int, int> current;// (shortest-distance confirmed, vertex)
    while(!pq.empty()){
        current = pq.top(); pq.pop();

        int v = current.second;
        if(d[v] < current.first){
            continue;// ignore (not the shortest path)
        }
        // else (need to check)
        for(edge e : graph[v]){// adjacent nodes
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;// update minimum cost
                pq.push({d[e.to], e.to});
            }
        }
    }
}

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s -= 1;
    t -= 1;
    V = n;
    E = m;

    vector<vector<edge>> graphJPY(n);
    vector<vector<edge>> graphSNK(n);
    for(int i=0; i<m; i++){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u -= 1;
        v -= 1;
        graphJPY[u].push_back({v,a});
        graphJPY[v].push_back({u,a});
        graphSNK[u].push_back({v,b});
        graphSNK[v].push_back({u,b});
    }

    graph = graphJPY;
    d.assign(n, 0);
    Dijkstra(s);
    vector<long long int> d1 = d;

    graph = graphSNK;
    d.assign(n, 0);
    Dijkstra(t);
    vector<long long int> d2 = d;

    vector<long long int> ans(n+1);
    ans[n] = INF;
    for(int i=n-1; i>=0; i--){
        //cout << d1[i] << " " << d2[i] << endl;
        ans[i] = min(ans[i+1], d1[i] + d2[i]);
    }
    for(int i=0; i<n; i++){
        cout << (long long int)(1e15 - ans[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 23920
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

lli n;

int main(void){
    cin >> n;
    vector<lli> A(n);
    rep(i, n) cin >> A[i];
    vector<lli> c1(n), c2(n);
    lli a, b, p, q;
    a = 1, b = -1;
    p = 0, q = 1;
    while(p < n && q < n){
        c1[p]+=a;
        c1[q]+=b;
        c2[p]-=a;
        c2[q]-=b;
        p++;
        q++;
        swap(p, q);
    }
    sort(A.begin(), A.end());
    sort(c1.begin(), c1.end());
    sort(c2.begin(), c2.end());
    lli u, v;
    u = v = 0;
    rep(i, n) u+=A[i]*c1[i];
    rep(i, n) v+=A[i]*c2[i];
    cout << max(u, v) << endl;
    return 0;
}


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

int main(void) {
	int a, b;
	cin >> a >> b;
	int c = (a + b) / 2;
	if (abs(a-c) == abs(b -c)) cout << c << endl;
	else cout << "IMPOSSIBLE" << 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;
using ll = long long;
using P = pair<int, int>;

int main() {
	string	word, s;
	cin >> word >> s;
	rep(i, word.size())
		word.at(i) = tolower(word.at(i));
	int		n;
	n = 0;
	while (s != "END_OF_TEXT")
	{
		rep(i, s.size())
			s.at(i) = tolower(s.at(i));
		if (s == word)
			n++;
		cin >> s;
	}
	cout << n << endl;
}



Measured memory_bytes: 3180
#include <cstdio>
#include <utility>
#include <cctype>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename head, typename... tail>
bool scan(head &h, tail&&... t){return scan(h) && scan(t...);}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	int n = 0;
	for (int c; (c = gcu()) != EOF;)
		if (isdigit(c))
			n += in(c);
	out(n, '\n');
}


Measured memory_bytes: 2564
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define MAX 10000
#define all(n) (n).begin(),(n).end()
using namespace std;
struct Pox
{
  int from,to,cost;
  Pox(int from=-1,int to=-1,int cost=-1):from(from),to(to),cost(cost){}
  bool operator < (const Pox &a)const
  {
    return cost < a.cost;
  }
};

int n,m;
int par[MAX+1];

void init()
{
  rep(i,MAX)par[i] = i;
}

int find(int x)
{
  if(x == par[x])return x;
  return par[x] = find(par[x]);
}

void unit(int x,int y)
{
  x = find(x);
  y = find(y);
  if(x != y)par[x] = y;
}

bool same(int x,int y)
{
  return find(x) == find(y);
}

int kruskal(vector<Pox> &G)
{
  sort(all(G));
  init();
  int res = 0;
  int gsize = G.size();
  rep(i,gsize)
    {
      Pox pox = G[i];
      if(!same(pox.from,pox.to))
	{
	  unit(pox.from,pox.to);
	  res += pox.cost;
	}
    }
  return res;
}

int main()
{
  while(cin >> n >> m,n|m)
    {
      vector<Pox> G;
      int cost;
      rep(i,n)
	{
	  //cout << "from " << i << " : " << endl;
	  REP(j,n,n+m)
	    {
	      cin >> cost;
	      if(cost == 0)cost = inf;
	      //cout << 0 << " to " << j << " : " << cost << endl;
	      G.push_back(Pox(0,j,cost));
	    }
	  //cout << endl;
	}     
      
      REP(i,n,n+m-1)
	{
	  //cout << "from " << i << " : " << endl;
	  REP(j,i+1,n+m)
	    {
	      cin >> cost;
	      if(cost == 0)cost = inf;
	      //cout << i << " to " << j << " : " << cost << endl;
	      G.push_back(Pox(i,j,cost));
	    }
	  //cout << endl;
	}
      cout << kruskal(G) << endl;
    }
  return 0;
}

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

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


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

int main() {
  int H, W;
  int N;
  int a[10100] = {0};
  int grid[110][110] = {0};
  cin >> H >> W;
  cin >> N;
  for(int i = 1; i <= N; ++i) {
    cin >> a[i];
  }

  int ai = 1;
  for(int h = 1; h <= H; ++h) {
    for(int w = 1; w <= W; ++w) {
      auto x = (h % 2 == 0) ? w : W - w + 1;
      grid[h][x] = ai;
      a[ai]--;
      if(a[ai] == 0) {
        ai++;
      }
    }
  }

  for(int h = 1; h <= H; ++h) {
    for(int w = 1; w <= W; ++w) {
      cout << grid[h][w] << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int count = 2;
  int total = 0;
  do {
    if (A > B) {
      total = total + A;
      count--;
      A--;
    } else {
      total = total + B;
      count--;
      B--;
  	}
  } while (count > 0);
  cout << total << endl;
}

Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

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

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

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

void solve(ll A, ll B) { cout << A * B << endl; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll A;
  scanf("%lld", &A);
  ll B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}


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

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)
//点を表す構造体
class Point {
  public:
  double x,y;
  Point(double x=0,double y=0): x(x),y(y){}

  //各種演算
  Point operator+ (Point p) { return Point(x+p.x,y+p.y); }
  Point operator- (Point p) { return Point(x-p.x,y-p.y); }
  Point operator* (double a) {return Point(a*x,a*y); }
  Point operator/ (double a) {return Point(x/a,y/a); }

  double abs() { return sqrt(norm()); }
  double norm() { return x*x+y*y; }

  bool operator< (const Point &p) const{
    return x!=p.x ? x<p.x : y<p.y;
  }

  bool operator== (const Point &p) const{
    return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
  }
};

//ベクトルを表す構造体
typedef Point Vector;

//線分を表す構造体
struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}
};

//直線を表す構造体
typedef Segment Line;

//円を表すクラス
class Circle{
  public:
  //円の中心
  Point c;
  //半径
  double r;
  Circle(Point c=Point(),double r=0.0): c(c),r(r) {}
};

//多角形の表現
typedef vector<Point> Polygon;

//ベクトルaとbの内積
double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}

//ベクトルaとbの外積
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

//ベクトルaとbの直交判定
bool isOrthogonal(Vector a,Vector b){
  return equals(dot(a,b),0.0);
}
bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}
bool isOrthogonal(Segment s1,Segment s2){
  return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

//ベクトルaとbの平行判定
bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}
bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}
bool isParallel(Segment s1,Segment s2){
  return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

//線分s1と線分s2の交点(ダメらしい)
Point getCrossPoint(Segment s1,Segment s2){
  Vector base=s2.p2-s2.p1;
  double d1=abs(cross(base,s1.p1-s2.p1));
  double d2=abs(cross(base,s1.p2-s2.p1));
  double t=d1/(d1+d2);
  return s1.p1+(s1.p2-s1.p1)*t;
}


int main(){
  int q;
  cin>>q;
  int x,y;
  for(int i=0;i<q;i++){
    int x0,x1,x2,x3,y0,y1,y2,y3;
    cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
    Point p0(x0,y0),p1(x1,y1),p2(x2,y2),p3(x3,y3);
    Line l1(p0,p1),l2(p2,p3);
    if(isOrthogonal(l1,l2)){
      cout<<1;
    }
    else if(isParallel(l1,l2)){
      cout<<2;
    }
    else{
      cout<<0;
    }
    cout<<'\n';    
  }
  return(0);
}


Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double[] x = new double[(n)];
        double[] y = new double[(n)];
        
        for (int i = 0; n > i; i++) {
            x[i]=scanner.nextDouble();
        }
        
        for (int i = 0; n > i; i++) {
            y[i]=scanner.nextDouble();
        }

        double man = 0;
        for (int i = 0; n > i; i++) {
            man += Math.abs((x[i] - y[i]));
        }

        double euk = 0;
        for (int i = 0; n > i; i++) {
            euk += ((x[i] - y[i]) * (x[i] - y[i]));
        }

        double euk2 = Math.sqrt(euk);

        double sanj = 0;
        for (int i = 0; n > i; i++) {
            sanj += (Math.abs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i])));
        }

        double sanj2 = Math.pow(sanj, (0.3333333333333));
        
        double max=0;
        for (int i = 0; n > i; i++) {
            if(Math.abs(x[i]-y[i])>max){
                max=Math.abs(x[i]-y[i]);
            }
        }
        System.out.println(man);
        System.out.println(euk2);
        System.out.println(sanj2);
        System.out.println(max);

    }
}

Measured memory_bytes: 29040
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void max_self(ll& a, ll b) {
    a = max(a, b);
}

// O(n * W)

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<ll> dp(W + 1); // 0 ... W
    // dp[i] - the maximum total value of items with total weight exactly i
    for(int item = 0; item < n; ++item) {
        int weight, value;
        scanf("%d%d", &weight, &value);
        // dp[0] -> dp[3] -> dp[6]
        for(int weight_already = W - weight; weight_already >= 0; --weight_already) {
        //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            max_self(dp[weight_already+weight], dp[weight_already] + value);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= W; ++i) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int N;
ll A,B;

int main()
{
	cin >> N >> A >> B;
	ll cost = 0;
	ll p,q;
	cin >> p;
	rep(i,0,N-1){
		cin >> q;
		cost += min((q-p)*A,B);
		p = q;
	}
	cout << cost << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

ll k,x,y;

pll solve(ll k, ll sx, ll sy, ll tx, ll ty){
    // DEBUG(sx); DEBUG(sy); DEBUG(tx); DEBUG(ty); DEBUG(k);
    REP(i,2)REP(j,3){
        ll y = (sy + ty + (i==0?1:-1)*(sx-tx) + (j==0?1:j==1?-1:0)*2*k)/2;
        REP(ii,2){
            ll x = sx + (ii==0?1:-1)*(k-abs(y-sy));
            // DEBUG(x); DEBUG(y);
            if(abs(x-sx)+abs(y-sy)!=k)continue;
            if(abs(x-tx)+abs(y-ty)!=k)continue;
            return pll(x,y);
        }
    }
}

int main(){
    cin>>k>>x>>y;
    if(k%2==0 && (abs(x)+abs(y))%2==1){
        puts("-1");
        return 0;
    }
    vector<pll> path;
    ll cx = 0, cy = 0;
    while(cx!=x || cy!=y){
        ll d = abs(cx-x) + abs(cy-y);
        if(d == k){
            path.push_back(pll(x,y));
            break;
        }else if(d < 2*k && d % 2 == 0){
            // 2-step
            pll P = solve(k,cx,cy,x,y);
            path.push_back(P);
            path.push_back(pll(x,y));
            break;
        }else if(d < k && d % 2 == 1){
            // 3-step
            if(abs(cx-k-x)+abs(cy-y)<k){
                cx -= k;
            }else if(abs(cx+k-x)+abs(cy-y)<k){
                cx += k;
            }else if(abs(cx-k)+abs(cy-k-y)<k){
                cy -= k;
            }else{
                cy += k;
            }
            path.push_back(pll(cx,cy));
            pll P = solve(k,cx,cy,x,y);
            path.push_back(P);
            path.push_back(pll(x,y));
            break;
        }else{
            // naive step
            ll dx = x - cx; ll dxir = x==cx ? 0 : (x-cx) / abs(x-cx);
            ll dy = y - cy; ll dyir = y==cy ? 0 : (y-cy) / abs(y-cy);
            ll ex=0, ey=0;
            ll sb = min(k, abs(dx));
            ex += sb * dxir;
            ey += (k-sb) * dyir;
            cx += ex;
            cy += ey;
            path.push_back(pll(cx,cy));
        }
    }
    printf("%d\n",(int)path.size());
    for(pll P : path){
        printf("%lld %lld\n",P.first,P.second);
    }
    return 0;
}


Measured memory_bytes: 5872
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    int n, x[100]={0}, y[100]={0}, z[100]={0}, i;
    double d1=0, d2=0, d3=0, d=0; 
    
    scanf("%d\n", &n);
    
    for(i=0; i<n; i++){
        scanf("%d", &x[i]);
    }
    
    for(i=0; i<n; i++){
        scanf("%d", &y[i]);
    }
    
    for(i=0; i<n; i++){
        z[i] = abs(x[i]-y[i]);
    }
    
    for(i=0; i<n; i++){
        d1 += z[i];
        
        d2 += pow(z[i], 2.0);
        
        d3 += pow(z[i], 3.0);
        
        if(d < z[i]){
            d = z[i];
        }
    }
    
    printf("%f\n%f\n%f\n%f\n", d1, sqrt(d2), cbrt(d3), d);
    
    return 0;
}



Measured memory_bytes: 2104