akhauriyash/Code-Regression huggingface dataset:
public class Main {

  private static void solve() {
    String s = next();
    String t = next();
    System.out.println(t + s);


  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 20948
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 

int main()
{ 
    
    LL a,b;
    cin>>a>>b;
    if(b>a){
        LL c;
        c=b;
        b=a;
        a=c;
    }
    LL ab=a*b;
    LL r=a%b;
    while(r!=0){//Euclid
        a=b;
        b=r;
        r=a%b;
    }
    cout<<ab/b<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
C,S,F = [0]*N,[0]*N,[0]*N
for i in range(N-1):
    C[i],S[i],F[i] = map(int,input().split())
for i in range(N-1):
    T = S[i]
    for j in range(i,N-1):
        if T <= S[j]:
            T = S[j]+C[j]
        elif T%F[j] == 0:
            T += C[j]
        else:
            T += F[j] - (T%F[j]) + C[j]
    print(T)
print(0)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0)break;
        for(int i = 0; i < H; i++ ){
            for(int j = 0; j < W; j++ ){
                cout << "#";
            }cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define mod 1000000007
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi acos(-1)
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
//18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix) 1216-C(26) 21
void cp()
{
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); 
    #ifndef ONLINE_JUDGE  
    freopen("input.txt", "r", stdin);  
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
  cp();
 //w(x)
 def(a,n);
  ll s=0;
  ll suf[n+1]={0};
  for(ll i=n-1;i>=0;i--)
  {
    suf[i]=(suf[i+1]%mod+a[i]%mod)%mod;
  }
  ll ans=0;
  //re(i,n+1)
  //cout<<suf[i]<<" ";
  re(i,n)
  {
    ans=ans%mod+((a[i]%mod)*(suf[i+1]%mod))%mod;
    ans=ans%mod;
  }
  cout<<ans<<endl;
}
// cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";


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

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        long ans = 2;
        for(int i=0;i<X;i++){
            ans = 2*ans+2;
        }
        System.out.println(ans);
    }
}


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

#define repi(i, s, n) for (long long i {s}, i##_len{n}; i < i##_len; ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) std::begin(x), std::end(x)

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
namespace xmaho
{
inline namespace integer
{
template<typename C>
constexpr auto ssize(const C& c) noexcept(noexcept(c.size()))
  -> typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type;
template <class T, ptrdiff_t N>
constexpr std::ptrdiff_t ssize(const T (&)[N]) noexcept;
}
}
using namespace xmaho;

int main()
{
  const auto n {get_value<uintmax_t>()};
  const auto k {get_value<uintmax_t>()};
  const auto r {get_value<uintmax_t>()};
  const auto s {get_value<uintmax_t>()};
  const auto p {get_value<uintmax_t>()};
  const auto t {get_value<string>()};
  const unordered_map<char, uintmax_t> score {{'r', p}, {'s', r}, {'p', s}};

  if (n <= k) {
    uintmax_t res {0};
    for (auto e : t)
      res += score.at(e);
    cout << res << '\n';
    return 0;
  }
  uintmax_t res {0};
  for (auto i {0}; i != k; ++i)
    res += score.at(t[i]);
  queue<bool> wins {};
  for (auto i {k}; i != 0; --i)
    wins.push(true);

  for (auto i {k}; i < n; ++i) {
    if (wins.front() && t[i] == t[i-k]) {
        wins.push(false);
    } else {
      res += score.at(t[i]);
      wins.push(true);
    }
    wins.pop();
  }
  cout << res << '\n';
  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}

template<typename C>
constexpr auto xmaho::integer::ssize(const C& c) noexcept(noexcept(c.size()))
  -> typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type
{ return c.size(); }

template <class T, ptrdiff_t N>
constexpr std::ptrdiff_t xmaho::integer::ssize(const T (&)[N]) noexcept
{ return N; }


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];

    ll ans = 0;
    int right = 0;
    int sum = 0;
    rep(left, 0, N)
    {
        while (right < N && (sum ^ A[right]) == (sum + A[right]))
        {
            sum += A[right];
            ++right;
        }
        ans += right - left;
        if (left == right)
        {
            ++right;
        }
        else
        {
            sum -= A[left];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  ll p,ans = 0;
  cin >> n >> m >> l >>p;
  rep(i,0,n){
    if(i < m)ans += l;
    else ans += p;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
step = list(map(int, input().split()))
INF = 10000000000
dp = [INF] * n
dp[0] = 0
for i in range(1, n):
  dp[i] = min(dp[i], dp[i - 1] + abs(step[i] - step[i - 1]))
  if (i > 1):
    dp[i] = min(dp[i], dp[i - 2] + abs(step[i] - step[i - 2]))
print(dp[-1])

Measured memory_bytes: 13976
function main(input) {
  const K = parseInt(input, 10);
  var a =(K+1)/2
  if(K%2==0){
    console.log((K/2)*(K/2));
  }else{
    console.log(a*(a-1));
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7620
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;
typedef vector<char> vchar;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<string>> vvstring;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll K, N;
	cin >> K >> N;
	vll A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}


	vll dis;
	for (int i = 1; i < N; i++)
	{
		dis.emplace_back(A[i] - A[i - 1]);
	}
	dis.emplace_back(K-(A[N - 1] - A[0] ));


	ll ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans = max(ans, dis[i]);
	}

	cout <<K- ans;

}



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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, a, b;
    cin >> n >> a >> b;

    if (a == b)
    {
        cout << 1 << endl;
        return 0;
    }
    else if (n == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    else if (a > b)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        cout << (b - a) * (n - 2) + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int a,b,c,d;cin>>a>>b>>c>>d;
    while(a>0||c>0){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;
            return 0;
        }
    }
}


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

int main()
{
    int n,m,x,y;
    cin>>n>>m;
    int a[n]= {};
    for(int i=0; i<m; i++)
    {
        scanf("%d %d",&x,&y);
        ++a[x-1];
        ++a[y-1];
    }
    for(int i=0; i<n; i++)
        printf("%d\n",a[i]);
}




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

int main(){
    char a;
    cin >> a;
    if (a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  vector<int> a(n);

  rep(i,n)cin>>a[i];
  int s=accumulate(a.begin(),a.end(),0);
  int d=1000000;
  int idx=0;
  rep(i,n) {
    if(abs(s-n*a[i])<d) {
      idx=i;
      d=abs(s-n*a[i]);
    }
  }
  cout << idx << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm> 
#include<cstring>
#include<cstdlib>
#define LL long long
using namespace std;
const int N=1e5+5;
int n,a[N];
LL ansl,ansr;
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
LL check(LL v)
{
	for(int i=1;i<=n;i++)v=v/a[i]*a[i];
	return v;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	LL l=0,r=1e15,mid;
	while(l<r)
	{
		mid=(l+r+1)>>1;
		if(check(mid)<=2)l=mid;
		else r=mid-1;
	}
	ansr=l;l=0;r=1e15;
	while(l<r)
	{
		mid=(l+r)>>1;
		if(check(mid)>=2)r=mid;
		else l=mid+1;
	}
	ansl=l;
	if(ansl>ansr)printf("-1");
	else printf("%lld %lld",ansl,ansr);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

typedef long long int Int;

int main(void) {
    int N;
    cin>>N;
    vector<int> L(2*N);

    for(int i = 0;i < 2*N;i++) {
        cin>>L[i];
    }

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

    Int sum = 0;
    for(int i = 0;i < 2*N;i += 2)
        sum += L[i];

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;

const int mod=1e9+7;

bool prime[1001];

int main(){
	rep(i,1001)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,sqrt(1001)){
		for(int j=i*2;j<1001;j+=i)prime[j]=false;
	}
	vector<int> pm;
	rep(i,1001)if(prime[i])pm.pb(i);
	int kt[1001][pm.size()];
	rep(j,1001)rep(i,pm.size())kt[j][i]=0;
	loop(j,1,1001){
		int now=j;
		rep(i,pm.size()){
			while(now%pm[i]==0){kt[j][i]++;now/=pm[i];}
			if(now==1)break;
		}
	}
	int n;
	cin>>n;
	int box[pm.size()];
	rep(i,pm.size())box[i]=0;
	loop(i,1,n+1){
		rep(j,pm.size())box[j]+=kt[i][j];
	}
	long long ans=1;
	rep(i,pm.size()){
		ans*=(box[i]+1);
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	string s, t; cin >> s >> t;
	int n = s.size();
	int cnt = 0;
	for( int i = 0; i < n; ++i ){
		if( s[i] != t[i] ) ++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3916
#include <stdio.h>
int main(){
    int m,n,x,y;
    scanf("%d%d",&m,&n);
    int a[100]={0};
    for(int i=0;i<n;i++){
        scanf("%d%d",&x,&y);
        a[x]++;
        a[y]++;
    }
    for(int i=1;i<=m;i++) printf("%d\n",a[i]);
    return 0;
}

Measured memory_bytes: 128
import sys
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(10**6)

H, W = [int(n) for n in input().split(' ')]
S = [list(input()) for i in range(H)]

dist = [[-1]*W for i in range(H)]
dist[0][0] = 1
Q = deque([])
Q.append([0,0])
while Q:
    y, x = Q.popleft()
    if [y, x] == [H-1, W-1]:
        break
    for i, j in [[1,0], [-1,0], [0,1], [0,-1]]:
        if y+i<0 or x+j<0 or y+i>=H or x+j>=W:
            continue
        if dist[y+i][x+j]==-1 and S[y+i][x+j]==".":
            dist[y+i][x+j] = dist[y][x] + 1
            Q.append([y+i, x+j])
if dist[H-1][W-1]==-1:
    print(-1)
else:
    white = 0
    for i in range(H):
        for j in range(W):
            if S[i][j]==".":
                white += 1
    print(white-dist[H-1][W-1])

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


class Main {
    public static void main(String[] args) {
        Scanner scr = new Scanner(System.in);
//        int t = scr.nextInt();
//        while (t-- > 0)
        solve(scr);
    }


    static void solve(Scanner scr) {
        int n = scr.nextInt();
        int[] a = new int[n];
        long[] b = new long[n + 1];

        for (int i = 0; i < n; i++) {
            a[i] = scr.nextInt();
            b[a[i]]++;
        }
        long s = 0;
        for (int i = 0; i < n+1; i++) {
            s += (b[i] * (b[i] - 1)) / 2;
        }

        for (int i = 0; i < n; i++) {
            long c = (b[a[i]] - 1) * (b[a[i]] - 2) / 2;
            long d = (b[a[i]]) * (b[a[i]] - 1) / 2;
            System.out.println(s - d + c);
        }


    }



}





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

int main() {
  int N;
  int fx = 0;
  cin >> N;
  
  // 桁数を求める
  int num = N;
  for(int i=100000000; i>0; i/=10){
    int digit = num / i;
    
    fx += digit;
    
    num -= digit * i;
  }
  
  if( (N % fx) == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main(){
  int n; cin >> n;
  vector<int> b(n - 1); 
  for(int i = 0; i < n - 1; i++){
    cin >> b.at(i);
  }

  int ans = b.at(0); // a0;
  for(int i = 1; i < n - 1; i++){
    ans += min(b.at(i - 1), b.at(i)); //aiを足す
  }
  ans += b.at(n-2); //a(n-1)
  cout << ans << endl;
}
    

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

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

  for (size_t i = 0; i < S.length(); ++i) {
    if (S == T)
      return (std::cout << "Yes" << std::endl), 0;
    S = S.back() + S;
    S.pop_back();
  }

  std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
for i in range(1, n+1):
    if int(i * 1.08) == n:
        print(i)
        exit()
print(':(')

Measured memory_bytes: 4080
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    k = ni()
    a,b = na()
    for i in range(a, b+1):
        if i%k == 0:
            print('OK')
            return
    print('NG')
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 61684
use std::io;
use std::io::*;
use std::str::FromStr;
 
 
fn abc(s: Vec<char>, k: i64) -> String {
    for i in 0..s.len() {
        if i as i64 == k {
            break
        }
        if s[i] != '1' {
            return s[i].to_string()
        }
    }
    return '1'.to_string()
    }
 

 
fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let k: i64 = read();

    let result = abc(s, k);
    
    println!("{}", result);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>
#include <bitset>
#include <cstdio>
// #include <complex>
#include <random>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
// const ll INF = 1e9;
const ld INF = 1e20;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
//const double PI = acos(-1);


void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ans = 0;
    sort(a.begin(), a.end());
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            int x = a[i] - a[j]; 
            int l = 0, r = i;
            while (l < r) {
                int m = (l + r) / 2;
                if (a[m] <= x) {
                    l = m + 1;
                } else {
                    r = m;
                }
            }
            ans += i - l;
            if (l <= j) {
                --ans;
            }
        }
    }
    cout << ans / 2;
}

int main() {
    // freopen("moscow.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemA solver = new ProblemA();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			long a = in.nextLong();
			long b = in.nextLong();
			long c = in.nextLong();
			long d = in.nextLong();
			b = Math.min(b, 2 * a);
			c = Math.min(c, 2 * b);
			d = Math.min(d, 2 * c);
			long n = in.nextLong();
			long ans = (n / 2) * d + (n % 2) * c;
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}



Measured memory_bytes: 21588
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>


long long int power2(long long int i){
  long long int ans = 1;
  for(long long int hoge = 0; hoge < i; hoge++){
    ans = ans*2;
  }

  return ans;
}

int main(){

  long long int H;
  scanf("%lld", &H);

  long long int ans = 0;
  long long int i = 0;

  while(H>0){
    H = H/2;
    ans += power2(i);
    std::cerr << i << " " << H << " " << ans << std::endl;
    i++;
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define MOD 1000000007
#define ll long long

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, a, b) for (int i = a; i < b; i++)
#define REPR(i, a, b) for (int i = a; i >= b; i--)

int main()
{
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    mp[0] = 1;
    int sum = 0;
    REP(i, n)
    {
        int x;
        cin >> x;
        sum += x;
        sum %= m;
        mp[sum]++;
    }
    long long ans = 0;
    for (auto &x : mp)
    {
        ans += (long long)(x.second) * (x.second - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n, flg = 0;
  cin >> n;
  
  rep(i, n)
  {
    char c;
    cin >> c;
    if(c == 'Y')
    {
      flg = 1;
      break;
    }

  }

  if(flg)
    cout << "Four" <<endl;
  else
    cout << "Three" <<endl;
  
}


Measured memory_bytes: 3524
n, m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
bc = sorted(bc, key = lambda x : x[1], reverse=True)

sum_b = 0
for b, c in bc:
    sum_b += b
    a += [c] * b
    if n < sum_b:
        break
a.sort(reverse=True)
a = a[:n]

print(sum(a))

Measured memory_bytes: 35656
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = -1
m = False
for i in range(3):
    if sum(a[i]) == -3:
        m = True
    if a[0][i] + a[1][i] + a[2][i] == -3:
        m = True
if a[0][0] + a[1][1]  + a[2][2] == -3:
    m = True
if a[0][2] + a[1][1]  + a[2][0] == -3:
    m = True

if m == True:
    print('Yes')
else:
    print('No')

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

typedef long long ll ;
typedef long double ld ;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

set <ll> st[30] ;

int main()
{
    ll n, q ;
    string s ;
    cin >> n >> s ;
    for (int i = 0; i < s.size(); i++) {
        st[s[i] - 'a'].insert(i) ;
    }

//    for (int i = 0; i < 26; i++) {
//        cout << char(i + 'a') << endl ;
//        for (auto it = st[i].begin(); it != st[i].end(); it++) {
//            cout << *it << " " ;
//        }
//        cout << endl ;
//    }

    cin >> q ;
    while (q--) {
        ll type, left, right, pos, stPos ;
        char val ;
        cin >> type ;
        if (type == 1) {
            cin >> pos >> val ;
            stPos = s[pos - 1] - 'a' ;
            st[stPos].erase(pos - 1) ;
            s[pos - 1] = val ;
            stPos = s[pos - 1] - 'a' ;
            st[stPos].insert(pos - 1) ;

//            for (int i = 0; i < 26; i++) {
//                cout << char(i + 'a') << endl ;
//                for (auto it = st[i].begin(); it != st[i].end(); it++) {
//                    cout << *it << " " ;
//                }
//                cout << endl ;
//            }
        }
        else {
            cin >> left >> right ;
            ll ans = 0, lVal = -1, rVal = -1 ;
            for (int i = 0; i < 26; i++) {
                if (st[i].size() != 0) {
                    auto it = st[i].lower_bound(left - 1) ;
                    auto jt = st[i].upper_bound(right - 1) ;
//                    cout << char(i + 'a') << endl ;
//                    cout << "L : " << lVal << " R : " << rVal << endl ;
                    if ( (it != jt) ) ans++ ;
                }
            }
            printf("%lld\n", ans) ;
        }
    }

    return 0 ;
}


Measured memory_bytes: 26244
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

char field[1000][1000];
int h,w;
int d[1000][1000];

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

void bfs()
{
    queue<P> que;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(field[i][j] == '#'){
                que.push(P(i,j));
                d[i][j] = 0;
            }else{
                d[i][j] = INF;
            }
        }
    }
    while(que.size()){
        P p = que.front(); que.pop();

        for(int i = 0; i < 4; i++){
            int nx = p.first + dx[i],ny = p.second + dy[i];
            if(0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] != '#' &&  d[nx][ny] == INF){
                if(d[nx][ny] > d[p.first][p.second] + 1){
                    d[nx][ny] = d[p.first][p.second] + 1;
                }
                que.push(P(nx,ny));
            }
        }
    }
}

int main()
{
    cin >> h >> w;
    int cnt = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> field[i][j];
        }
    }
    bfs();
    int ans = -1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            ans = max(ans,d[i][j]);
        }
    }
    cout << ans;
}

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

typedef vector <char> VC;

int main( void )
{
	int n, m;
	while ( cin >> n && n )
	{
		const int size = 2 * n + 1;
		VC ioi( size, 'I' );
		for ( int i = 1; i < size; i += 2 ) ioi[i] = 'O';

		cin >> m;
		VC s( m );
		for ( int i = 0; i < m; i++ ) cin >> s[i];

		int answer = 0;
		int cnt;
		for ( int i = 0; i < m-1; i++ )
		{
			if ( s[i] == 'I' )
			{
				cnt = 1;
				for ( int j = i+1; j < m; j += 2 )
				{
					if ( s[j] == 'O' && s[j+1] == 'I' )
					{
						cnt += 2;
						if ( cnt == size )
						{
							cnt -= 2;
							answer++;
						}
					}
					else
					{
						i = j - 1;
						break;
					}
				}
			}
		}

		cout << answer << endl;
	}
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    map<string, ll> m;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        m[s]++;
    }
    cout << m.size() << endl;
}


Measured memory_bytes: 19232
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    static ArrayList<Integer>[] vertice;
    static int ans = 0;
    static int total = 0;
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int m = in.nextInt();
        total = n;
        vertice = new ArrayList[n+1];
        for(int i=0;i<=n;i++){
            vertice[i] = new ArrayList<>();
        }
        for(int i=0;i<m;i++){
            int a = in.nextInt();
            int b = in.nextInt();
            vertice[a].add(b);
            vertice[b].add(a);
        }
        ArrayList<Integer> run = new ArrayList<>();
        bfs(run,1);
        System.out.println(ans);
    }
    static void bfs(ArrayList<Integer> arr,int node){
        arr.add(node);
        for(int v : vertice[node]){
            if(!arr.contains(v)){
                ArrayList<Integer> temp = new ArrayList<>(arr);
                bfs(temp,v);
            }
        }

        if(arr.size()==total){
            ans++;
        }

    }
}


Measured memory_bytes: 26324
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN2(a,b);
  if(a <= b) OUT(a);
  else OUT(a-1);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=2e5+5;
int n,a[N];
ll ans;

int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",a+i);
	sort(a,a+n); reverse(a,a+n);
	int R=n-1;
	rep(i,0,n) {
		int use=min(R,i?2:1);
		ans+=use*a[i];
		R-=use;
	}
	printf("%lld\n",ans);
}

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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int,int>

int main(){
	int n;
	while(cin >> n){
		int ans = 0 ;
		int cntf=0,cnte=0,cntb=0;
		f(n){
			string s;
			cin >> s;
			for(int j=0;j<(int)s.size()-1;j++){
				if(s[j]=='A'&&s[j+1]=='B')ans++;
			}
			if(s[0]=='B'&&s[s.size()-1]=='A'){
				cntb++;
			}
			else if(s[0]=='B'){
				cntf++;
			}
			else if(s[s.size()-1]=='A'){
				cnte++;
			}
		}
		if(!cntb){
				
		}
		else{
			if(cntf&&cnte){
				ans += cntb+1;
				cntf--;cnte--;
			}
			else if(cntf){
				ans += cntb;
				cntf--;
			}
			else if(cnte){
				ans += cntb;
				cnte--;
			}
			else{
				ans += cntb-1;
			}
		}
		ans += min(cntf,cnte);
		cout<<ans<<endl;

	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 200005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<lint,lint> pii;
vector<lint> V[MAX];
lint vis[MAX],sum,ans;
void dfs(lint u){
    vis[u]=1;
    sum++;
    ans=max(ans,sum);
    for(auto v:V[u]){
        if(!vis[v]){
            dfs(v);
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    lint n,m,u,v;
    cin>>n>>m;
    for(lint i=1;i<=m;i++){
        cin>>u>>v;
        V[u].pb(v);
        V[v].pb(u);
    }

    for(lint i=1;i<=n;i++){
        if(!vis[i]){
            sum=0;
            dfs(i);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 22292
from itertools import permutations

N = int(input())
place = []
for i in range(N):
    place.append(list(map(int, input().split())))

Length = []
permutation = list(permutations(range(0, N)))

for i in range(len(permutation)):
    L = 0
    for j in range(len(permutation[i]) - 1):
        L += (
            (place[permutation[i][j]][0] - place[permutation[i][j + 1]][0]) ** 2
            + (place[permutation[i][j]][1] - place[permutation[i][j + 1]][1]) ** 2
        ) ** (1 / 2)
    Length.append(L)

print(sum(Length) / len(permutation))

Measured memory_bytes: 9332
#include <algorithm>
#include <cstdio>

int Abs(int x) {return x > 0 ? x : -x;}
int a[201000];
int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] -= i;
	std::sort(a + 1, a + n + 1);
	long long ans = 0;
	int id = n / 2 + 1;
	for(int i = 1; i <= n; i++)
	{
		ans += Abs(a[i] - a[id]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 896
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
b2 = -b
c2 = -c
list_b = [b,b2]
list_c = [c,c2]
def op (n):
    if n >= 0:
        return '+'
    else:
        return '-'

for i in list_b:
    for j in list_c:
        d2 = 7 - a - i - j
        if a + i + j + d2 == 7 and abs(d2) == d:
            b_ans = i
            c_ans = j
            d_ans = d2
            print(str(a)+op(b_ans)+str(b)+op(c_ans)+str(c)+op(d_ans)+str(d)+'=7' )
            exit()

Measured memory_bytes: 38384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int fact = 1;
        int[] array = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            fact *= i;
            
            int num = 2;
            while (num <= i) {
                if (fact % num == 0) {
                    fact /= num;
                    array[num]++;
                } else {
                    num++;
                }
            }
        }
        
        long res = 1;
        for (int i = 2; i <= n; i++) {
            res = res * (array[i] + 1) % 1000000007;
        }
        System.out.println(res);
    }
}


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

int main() {
  int N; 
  cin >> N;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    ans += (a-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int h,w;
bool a[190][190];
int dp[190][190][190][19];
int main(){
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        string s;
        cin>>s;
        for(int j=1;j<=w;j++)
            a[i][j]=(s[j-1]=='#'?1:0);
    }
    for(int i=1;i<=h;i++)
        for(int l=1;l<=w;l++){
            int nowc=a[i][l];
            int j=i+1;
            while(j<=h && a[j][l]==a[i][l]) j++;
            dp[i][l][l][0]=j-i;
            //cout<<i<<" "<<l<<" "<<l<<" "<<dp[i][l][l][0]<<endl;
    }
    for(int i=h;i>=1;i--)
        for(int l=w;l>=1;l--)
            for(int r=l;r<=w;r++)
                for(int k=0;k<=18;k++){
                    if(l==r && k==0) continue;
                    if(k==0){
                        dp[i][l][r][k]=min((a[i][l]==a[i][r]?200:0),min(dp[i][l][r-1][0],dp[i][r][r][0]));
                        //cout<<" "<<i<<" "<<l<<" "<<r<<" "<<dp[i][l][r][k]<<endl;
                        continue;
                    }
                    //row
                    int x=dp[i][l][r][k-1];
                    int y=dp[i+x][l][r][k-1];
                    dp[i][l][r][k]=x+y;
                    //col
                    int lb=l,ub=r;
                    int nowans=0;
                    while(lb<ub-1){
                        int mid=(lb+ub)/2;
                        if(dp[i][l][mid][k-1]-dp[i][mid+1][r][k-1]<0)
                            ub=mid;
                        else if(dp[i][l][mid][k-1]==dp[i][mid+1][r][k-1]){
                            nowans=mid;
                            break;
                        }
                        else lb=mid;
                    }
                    if(!nowans) nowans=lb;
                    //cout<<nowans<<endl;
                    dp[i][l][r][k]=max(dp[i][l][r][k],max(min(dp[i][l][nowans][k-1],dp[i][nowans+1][r][k-1]),min(dp[i][l][nowans+1][k-1],dp[i][nowans+2][r][k-1])));
                    //cout<<i<<" "<<l<<" "<<r<<" "<<k<<" "<<dp[i][l][r][k]<<endl;
                }
    int ans=0;
    for(int i=0;i<=18;i++)
        if(dp[1][1][w][i]>=h){
            ans=i;
            break;
        }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 497920
def main():
    S = list( map( int, list( input())))
    N = len(S)
    dp = [[0,0] for _ in range(N+1)]
    dp[0][1] = 2
    for i in range(N):
        s = S[i]
        dp[i+1][0] = min(dp[i][0] + s, dp[i][1]+s)
        dp[i+1][1] = min(dp[i][0] + 11-s, dp[i][1]+9-s)
        # dp[i+1][2] = min(dp[i][1], dp[i][2])+9-s
        # 11-sは、追加で支払うものと、お釣り
        # 9-sは、追加はすでに支払われていて、繰り下がりが起こっている
    print( min(dp[N][0], dp[N][1]))
if __name__ == '__main__':
    main()

Measured memory_bytes: 238620
#include <bits/stdc++.h>
using namespace std;
using lint = long;
using ll = long long;
#define rep(i,n) for(lint (i) = 0;(i) < (lint)(n);(i)++)
#define repInRange(i,start,end) for(lint (i) = (start);(i) < (end);++(i))
using lpair = pair<lint,lint>;
using Vecint = vector<lint>;
using Llist = list<lint>;

ll pow(ll k,ll l) {
	ll ret = 1;
	rep(i,l) {
		ret *= k;
	}
	return ret;
}

template <typename T>
T sum(vector<T> vec) {
	ll ret = 0;
	rep(i,vec.size()) {
		ret += vec.at(i);
	}
	return ret;
}

void Main() {
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	lint k;
	cin >> k;
	cout << a[k-1] << '\n';
}

signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

using Graph = vector<vector<int>>;
int cnt[100010];
int par[100010];

int main() {
    int n, m; cin >> n >> m;
    Graph g(n);
    rep(i, n+m-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        cnt[b]++;
    }

    int root = -1;
    rep(i, n) if (cnt[i] == 0) root = i;

    // BFSして最長距離のedgeだけ残す
    queue<int> q;
    q.push(root);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v: g[u]) {
            cnt[v]--;
            if (cnt[v] > 0) continue;
            par[v] = u;
            q.push(v);
        }
    }

    rep(i, n) {
        if (i == root) cout << 0 << endl;
        else cout << par[i] + 1 << endl;
    }
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, 0, n) cin >> p[i];

    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, 0, k) ans += p[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3588
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(lst[k - 1])


Measured memory_bytes: 2940