akhauriyash/Code-Regression huggingface dataset:
import java.awt.*;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        char s[]=sc.next().toCharArray();
        int sum[][]=new int[3][n+1];
        for (int i=n-1;i>=0;i--){
            sum[0][i]=sum[0][i+1]+(s[i]=='R'?1:0);
            sum[1][i]=sum[1][i+1]+(s[i]=='G'?1:0);
            sum[2][i]=sum[2][i+1]+(s[i]=='B'?1:0);
        }
        long ans=0;
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                if (s[i]!=s[j]){
                    int k=2*j-i;
                    if ((s[i]=='B' && s[j]=='R') || (s[i]=='R' && s[j]=='B')){
                        if (k>=n){
                            ans+=sum[1][j+1];
                        }else if (s[k]=='G')ans+=sum[1][j+1]-1;
                        else ans+=sum[1][j+1];
                    }
                    if ((s[i]=='G' && s[j]=='R') || (s[i]=='R' && s[j]=='G')){
                        if (k>=n){
                            ans+=sum[2][j+1];
                        }else if (s[k]=='B')ans+=sum[2][j+1]-1;
                        else ans+=sum[2][j+1];
                    }
                    if ((s[i]=='B' && s[j]=='G') || (s[i]=='G' && s[j]=='B')){
                        if (k>=n){
                            ans+=sum[0][j+1];
                        }else if (s[k]=='R')ans+=sum[0][j+1]-1;
                        else ans+=sum[0][j+1];
                    }
                }
            }
        }
        System.out.println(ans);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 33700
#include <bits/stdc++.h>
using namespace std;
long long int i,n,ar[100005],ans,a,b,a1,a2,dp[100005];

int main(){
	cin>>n;
	for(i=0;i<n;i++)cin>>ar[i];
	dp[1]=abs(ar[1]-ar[0]);
	for(i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));	
	}
	cout<<dp[n-1];
}

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

int main()
{
  long long x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<long long> red_apple(a);
  vector<long long> green_apple(b);
  vector<long long> clear_apple(c);
  for (long long i = 0; i < a; i++) {
    cin >> red_apple.at(i);
  }
  for (long long i = 0; i < b; i++) {
    cin >> green_apple.at(i);
  }
  for (long long i = 0; i < c; i++) {
    cin >> clear_apple.at(i);
  }
  sort(red_apple.rbegin(), red_apple.rend());
  sort(green_apple.rbegin(), green_apple.rend());
  sort(clear_apple.rbegin(), clear_apple.rend());
  priority_queue<int, vector<int>, greater<int>> red_pq;
  priority_queue<int, vector<int>, greater<int>> green_pq;
  for (long long i = 0; i < x && i < a; i++) {
    red_pq.push(red_apple.at(i));
  }
  for (long long i = 0; i < y && i < b; i++) {
    green_pq.push(green_apple.at(i));
  }
  for (auto apple : clear_apple) {
    if ((long long)red_pq.size() < x) {
      red_pq.push(apple);
      continue;
    }
    if ((long long)green_pq.size() < y) {
      green_pq.push(apple);
      continue;
    }
    if (apple <= min(red_pq.top(), green_pq.top())) {
      continue;
    }
    if (red_pq.top() < green_pq.top()) {
      red_pq.pop();
      red_pq.push(apple);
    } else {
      green_pq.pop();
      green_pq.push(apple);
    }
  }
  long long res = 0;
  while (!red_pq.empty()) {
    res += red_pq.top();
    red_pq.pop();
  }
  while (!green_pq.empty()) {
    res += green_pq.top();
    green_pq.pop();
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3704
import sys
input = sys.stdin.readline

import bisect

N = int(input())
s = input().split() 
s = list(s[0])

dp = [[0]*(N+1) for _ in range(N+1)]
ans=0
for i in reversed(range(N)):
    for j in reversed(range(N)):
        if s[i]==s[j]:
            dp[i][j]=min(abs(j-i),dp[i+1][j+1]+1)
            ans = max(ans,dp[i][j])
#print(dp)
print(ans)
        


Measured memory_bytes: 232456
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, M, K, Q, W, H;
long long int ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	if (N <= 0 && M >= 0) {
		cout << "Zero\n";
		return 0;
	}
	if (N < 0) {
		if ((min(M, (long long int)0) - N) % 2)cout << "Positive\n";
		else cout << "Negative\n";
		return 0;
	}
	cout << "Positive\n";
	return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    string s, t;
    cin >> s >> t;

    map<char, char> rea, reb;
    int ro = s.size();
    bool ans = true;
    for (int i = 0; i < ro; i++) {
        if (!rea.insert({s[i], t[i]}).second || !reb.insert({t[i], s[i]}).second) {
            if (rea[s[i]] != t[i] || reb[t[i]] != s[i]) {
                ans = false;
            }
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main() {
  int N; cin >> N;
  long long sum = 0;
  for (int i = 1; i <= N-1; i++) {
    sum += i;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/
const ll MOD=998244353;

void solve(){
	string n;
	cin>>n;

	if(n[n.size()-1]=='2' ||n[n.size()-1]=='4' || n[n.size()-1]=='5' ||n[n.size()-1]=='7' || n[n.size()-1]=='9' ){
		cout<<"hon"<<endl;
	}
	else if(n[n.size()-1]=='0' ||n[n.size()-1]=='1' ||n[n.size()-1]=='6' ||n[n.size()-1]=='8'){
		cout<<"pon"<<endl;
	}else{
		cout<<"bon"<<endl;
	}
	
}


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


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

void solve(){
  int q; cin >> q;
  for(int i = 0; i < q; i++){
    string x, y; cin >> x >> y;
    int xn = x.size(), yn = y.size();
    vector<vector<int> > lcs(xn + 1, vector<int>(yn + 1));
    for(int i = 0; i <= xn; i++) lcs[i][0] = 0;
    for(int i = 0; i <= yn; i++) lcs[0][i] = 0;
    for(int j = 1; j <= xn; j++){
      for(int k = 1; k <= yn; k++){
        if(x[j - 1] == y[k - 1]) lcs[j][k] = lcs[j - 1][k - 1] + 1;
        else lcs[j][k] = max(lcs[j - 1][k], lcs[j][k - 1]);
      }
    }
    cout << lcs[xn][yn] << endl;
  }
  return;
}

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



Measured memory_bytes: 6856
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(stdin.readline().rstrip())
ans = 0
for_c = []

for b in range(1,K+1):
    for a in range(1,K+1):
        if math.gcd(a,b) == 1:
            ans += K
        else:
            for_c.append(math.gcd(a,b))

for c in range(1,K+1):
    for ab in range(len(for_c)):
        ans += math.gcd(for_c[ab],c)

print(ans)

Measured memory_bytes: 10080
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {

    int N;
    cin >> N;
    string out = "Yes";
    for(int i=0;i<N;i++){
        int t,x,y;
        cin >> t >> x >> y;
        if(t < x+y || t%2 != (x+y)%2){
            out = "No";
            break;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
const int N=2e5+5;
int cnt[N],n,m;
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		if(a==1||a==n)cnt[b]++;
		if(b==1||b==n)cnt[a]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(cnt[i]>=2)
		{
			cout<<"POSSIBLE\n";
			return 0;
		}
	}
	cout<<"IMPOSSIBLE\n";

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int n = fetch<int>();
	int m = fetch<int>();

	vector<int> cnt(n, 0);

	for(int i = 0; i < m; ++i) {
		int v = fetch<int>() - 1;
		int u = fetch<int>() - 1;

		cnt[v] ^= 1;
		cnt[u] ^= 1;
	}

	int total = 0;

	for(auto& elem: cnt) {
		total += elem;
	}

	cout << (total <= 1 ? "YES\n" : "NO\n");
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;

    map<int, int> m;
    REP(i, n) {
        int a; cin >> a;
        m[a]++;
    }

    int ans = 0;
    for(auto &p: m) {
        if (p.fi > p.se) {
            ans += p.se;
        } else if (p.fi < p.se) {
            ans += p.se - p.fi;
        }
    }

    print(ans);

}

Measured memory_bytes: 8144
typedef long long W;i,j,N,M;W a[8<<14],v,r;c(W*a,W*b){return*a-*b;}main(){for(scanf("%d%d",&N,&M);~scanf("%lld",++i+a);a[i]=(a[i]+a[i-1])%M);qsort(a+1,N,8,c);for(i=j=0;i++<N;)if(a[i]-a[j]){r=i-j;v+=r*=r-1;j=i;}r=i-j;v+=r*=r-1;printf("%lld\n",v/2);i=0;}

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
   long long a,b;
    while(cin>>a>>b)
    {
        int n=a+b;
        if(a%3==0)  printf("Possible\n");
        else if(b%3==0)  printf("Possible\n");
        else if(n==0) printf("Impossible\n");
        else if(n%3==0) printf("Possible\n");
        else printf("Impossible\n");

    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

int lr_occurence[500][500];
int cum_sum[500][500];
int p[100000];
int q[100000];

int main() {
	int N;
	int M;
	int Q;
	cin >> N >> M >> Q;
	int l;
	int r;
	for (int i = 0; i < M; i++) {
		cin >> l >> r;
		lr_occurence[l - 1][r - 1] ++;
	}
	for (int i = 0; i < Q; i++) {
		cin >> p[i] >> q[i];
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cum_sum[i][j] = lr_occurence[i][j];
			if (i > 0) {
				cum_sum[i][j] += cum_sum[i - 1][j];
			}
			if (j > 0) {
				cum_sum[i][j] += cum_sum[i][j - 1];
			}
			if (i > 0 && j > 0) {
				cum_sum[i][j] -= cum_sum[i - 1][j - 1];
			}
		}
	}

	for (int i = 0; i < Q; i++) {
		if (p[i] > 1) {
			cout << cum_sum[N - 1][q[i] - 1] - cum_sum[p[i] - 2][q[i] - 1] << endl;
		}
		else {
			cout << cum_sum[N - 1][q[i] - 1] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int x;
	char s;
	cin>>s;
	if(s=='S') x=2;
	if(s=='C') x=3;
	if(s=='R') x=1;
	if(x==1) cout<<"Sunny"<<endl;
	if(x==2) cout<<"Cloudy"<<endl;
	if(x==3) cout<<"Rainy"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <cstdlib>
#include <iterator>
#include <algorithm>
using namespace std;

const int mod = 1e9 + 7;


long long modInverse(long long a, int m)
{
	long long m0 = m;
	long long y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		// q is quotient
		int q = a / m;
		int t = m;

		// m is remainder now, process same as
		// Euclid's algo
		m = a % m, a = t;
		t = y;

		// Update y and x
		y = x - q * y;
		x = t;
	}

	// Make x positive
	if (x < 0)
		x += m0;

	return x;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	long long s = 0;
	for (int i = 0; i < n; i++)
	{
		s = s + a[i];
		s = s % mod;
	}
	long long p = ((s) * (s )) % mod;
	long long x = 0;
	for (int i = 0; i < n; i++)
	{
		x += a[i] * a[i];
		x = x % mod;
	}
	cout << ((((p - x) * 500000004) % mod) + mod ) % mod ;
	return 0;
}

Measured memory_bytes: 4784
import sys

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

if a[3] > a[0]:
    b = a[0]
    a[3] = a[3]-a[0]
elif a[3] <= a[0]:
    b = a[3]
    print(b)
    sys.exit()

if a[3] > a[1]:
    a[3] = a[3] - a[1]
elif a[3] <= a[1]:
    print(b)
    sys.exit()
c = (-1) * a[3]
b = c + b
print(b)


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

int main() {
int64_t n,m,a,b,c;
  c=0;
  cin>>n>>m;
  vector<int64_t> vec(n);
  vector<int64_t> ans(n);
  for(int64_t i=0;i<n;i++){
  cin>>vec.at(i);
  }
  for(int64_t i=0;i<m;i++){
  cin>>a>>b;
    if(vec.at(a-1)>=vec.at(b-1)){ans.at(b-1)=1;}
    if(vec.at(a-1)<=vec.at(b-1)){ans.at(a-1)=1;}
  }
  for(int64_t i=0;i<n;i++){
  if(ans.at(i)==0){c++;}}
  cout<<c<<endl;
 
}


Measured memory_bytes: 4792
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define rep(i,n) for(LL i=0;i<n;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) ((int)s.size())
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 10000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<int>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;

#pragma endregion


//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) {
			return false;
		}
	}
	return true;
}

void y_n(bool p) {
	if (p)_y();
	else _n();
}

void Y_N(bool p) {
	if (p) _Y();
	else _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion

/************************************************************************/
signed main(void) {
	cin.tie(0); ios::sync_with_stdio(false);

	st s;
	cin >> s;
	int a = s[0] - '0';
	int b = s[1] - '0';
	int c = s[2] - '0';
	int d = s[3] - '0';
	if (a + b + c + d == 7) {
		cout << a << "+" << b << "+" << c << "+" << d << "=7";
	}
	else if (a + b + c - d == 7) {
		cout << a << "+" << b << "+" << c << "-" << d << "=7";
	}
	else if (a + b - c + d == 7) {
		cout << a << "+" << b << "-" << c << "+" << d << "=7";
	}
	else if (a - b + c + d == 7) {
		cout << a << "-" << b << "+" << c << "+" << d << "=7";
	}
	else if (a + b - c - d == 7) {
		cout << a << "+" << b << "-" << c << "-" << d << "=7";
	}
	else if (a - b + c - d == 7) {
		cout << a << "-" << b << "+" << c << "-" << d << "=7";
	}
	else if (a - b - c + d == 7) {
		cout << a << "-" << b << "-" << c << "+" << d << "=7";
	}
	else if (a - b - c - d == 7) {
		cout << a << "-" << b << "-" << c << "-" << d << "=7";
	}
	return 0;
}

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

int main()
{
	int N, M;
	while (cin >> N >> M, N | M) {
		vector<int> A(N);
		for (int i = 0; i < N; i++) {
			cin >> A[i];
		}
		int res = 0, p = 0;
		for (int i = 0; i < M; i++) {
			int X;
			cin >> X;
			if (!res) {
				p += X;
				if (p >= N - 1) {
					res = i + 1;
					continue;
				}
				p += A[p];
				if (p >= N - 1) {
					res = i + 1;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
using namespace std;
 
int b[1000];
 
int main(){
    int y[2][6];
    int x[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
    int a[6];
    int MAX;
    
    for(int i=0;i<2;i++){
        for(int j=0;j<6;j++){
            cin>>y[i][j];
            b[y[i][j]] ++;
        }
    }
    for(int i=0;i<1000;i++){
        MAX=max(MAX,b[i]);
    }
    if(MAX>=6){
        cout<<"Yes"<<endl;
        goto Exit;
    }
    for(int i=0;i<6;i++){
        for(int j=0;j<6;j++){
            if(y[0][j]==y[1][i]){
                a[i]=j;
            }
        }
    }
    if(x[a[0]][a[1]]==a[2]+1){
        cout<<"Yes"<<endl;
        goto Exit;
    }
    cout<<"No"<<endl;
    Exit:;
    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    int n, m, a; cin >> n >> m >> a, --a;
    if (n == 0) break;
    V< tuple<int, int, int> > l;
    for (int i = 0; i < m; ++i) {
      int h, p, q; cin >> h >> p >> q, --p, --q;
      l.emplace_back(h, p, q);
    }
    sort(begin(l), end(l));
    V<> id(n);
    iota(begin(id), end(id), 0);
    for (int i = 0; i < m; ++i) {
      swap(id[get<1>(l[i])], id[get<2>(l[i])]);
    }
    cout << id[a] + 1 << '\n';
  }
}


Measured memory_bytes: 3156
import Data.Sequence

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- (map read . words) <$> getLine :: IO [Int]
  let q = fromList []
  let q' = if odd n
          then (Prelude.reverse . toList []) $ loop q as n n
          else toList [] $ loop q as n n
  putStrLn $ unwords $ map show q'

toList l q =
  case viewl q of
    EmptyL -> Prelude.reverse l
    a :< q' -> toList (a:l) q'

loop q _ total 0 = q
loop q (a:as') total n =
  if (total - n + 1) `mod` 2 == 1
    then
      let q' = q |> a in loop q' as' total (n - 1)
    else
      let q' = a <| q in loop q' as' total (n - 1)


Measured memory_bytes: 152828
import java.util.Scanner;

//Cubist Artwork
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), d = sc.nextInt();
			if((n|d)==0)break;
			int[] h = new int[21];
			int res = 0;
			while(n--!=0){
				int x = sc.nextInt();
				res+=x; h[x]++;
			}
			while(d--!=0){
				int x = sc.nextInt();
				if(h[x]>0)h[x]--;
				else res+=x;
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
int A[N];
int frq[N];
int rid[N];   
int n , q;

int bit[N + 1];
void update(int id, int val)
{
	for (int i = id; i <= N; i += i & (-i) ) bit[i] += val;
}
 
int get(int id)
{
	int sum = 0;
	for ( int i = id; i > 0; i -= i & (-i) ) sum += bit[i];
	return sum;
}
 
int query(int r)
{
	return get(r);
}
 

void solve()
{

	cin >> n >> q;

    mset(rid, -1); 

	loop(i,0,n)
	{
		cin >> A[i];
	}

	vector<pair<int,pii>> vec;

	loop(i,0,q)
	{
		int l , r;
		cin >> l >> r;
		l--,r--;
		vec.pb({r , {l,i}});
	}

	S(vec);

	// loop(i,0,q)
	// {
	// 	cout << vec[i].ss.ss << " " << vec[i].ss.ff<< " " << vec[i].ff << endl;
	// }
  	
    vector<int> ans(q);

    int j = 0; 

   	loop(i,0,n)
    { 
        if (rid[A[i]] !=-1)update(rid[A[i]], -1); 
        rid[A[i]] = i+1; 
        update(i + 1, 1); 
        while (j < q && vec[j].ff == i) 
        { 
            ans[vec[j].ss.ss] = query(vec[j].ff + 1)-query(vec[j].ss.ff); 
            j++; 
        } 
    } 
 
   	loop(i,0,q)cout << ans[i] << endl; 
	
}			
 	
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

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

using namespace std;

void A_Remaining_Balls(void) {

	string S, T;
	cin >> S >> T;

	int A, B;
	cin >> A >> B;

	string U;
	cin >> U;

	if (S.compare(U) == 0)	A--;
	else					B--;

	cout << A << " " << B;
	return;
}

void B_I_Miss_You(void) {

	string S;
	cin >> S;

	for (int loop = 0; loop < S.size(); loop++) cout << "x";
	cout << flush;
	return;
}

int main(void) {

	//A_Remaining_Balls();
	B_I_Miss_You();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int x=0;
    for(int i=1;i<=b;i++){
        if((i*a)%b==c){
            x=1;
            break;
        }
    }
    if(x==1) cout<<"YES";
    else cout<<"NO";
}

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

int main() {
	int n; cin >> n;
	vector<pair<pair<string, int>, int>>sp(n);
	for (int i = 0; i < n; i++) {
		string tmp1; cin >> tmp1;
		int tmp2; cin >> tmp2;
		sp[i] = make_pair(make_pair(tmp1, -1*tmp2),i);
	}
	sort(sp.begin(), sp.end());
	
	for (auto x : sp) {
		cout << x.second + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def toint(l, r):
    return int(''.join(map(str, S[l:r])))


def test():
    ans = 0
    for l, r in itertools.combinations_with_replacement(range(N), r=2):
        s = toint(l, r + 1)
        ans += s % P == 0
    print(ans)


def solve25():
    ret = 0
    for d in range(N):
        if S[d] % P == 0:
            ret += d + 1
    return ret


def mod_invs(max, mod):
    """
    逆元 0, 1/1, 1/2, 1/3, ..., 1/max
    :param int max:
    :param int mod:
    """
    invs = [1] * (max + 1)
    invs[0] = 0
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


N, P = list(map(int, sys.stdin.buffer.readline().split()))
S = list(map(int, list(sys.stdin.buffer.readline().decode().rstrip())))

# 10 mod P で割れない
if P in [2, 5]:
    ans = solve25()
    print(ans)
    exit()

# test()

powers = []
p = 1
for _ in range(N):
    powers.append(p)
    p = p * 10 % P
# int(S[1:1]), int(S[1:2]), int(S[1:3]), ...
s_additions = [0]
s = 0
for i in range(1, N):
    s = (s * 10 + S[i]) % P
    s_additions.append(s)
invs = mod_invs(max=P - 1, mod=P)


def to_index(i, p):
    # もともと x だったのが、i 番目で p になっているときの x を返す
    if i == 0:
        return p % P
    return (p - s_additions[i]) * invs[powers[i]] % P


mod_counts = [0] * P
ans = 0
for i, c in enumerate(S):
    mod_counts[to_index(i, c)] += 1
    ans += mod_counts[to_index(i, 0)]
print(ans)


Measured memory_bytes: 20616
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007

int main(){
    int N,W;cin >> N >> W;
    vector<int> v(N),w(N);
    for(int i = 0; i < N ; i++){
        cin >> v[i] >> w[i];
        
    }
    vector<vector<int> > dp(N+1);
    for(int i = 0 ; i <= N ; i++){
            dp[i].resize(10001,INF);
    }
    dp[1][v[0]] = w[0];
    dp[1][0] = 0;
    for(int i = 2 ; i <= N ; i++){
        dp[i][v[i-1]] = w[i-1];
        for(int j = 0 ; j <= 10001 ; j++){
            if(j - v[i-1]>= 0){
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    int ans = 0;
    for(int i = 10000 ; i > 0 ; i--){
        if(dp[N][i] <= W){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6780
a,b=input().split()
a,b=int(a),int(b)
#回文数でa以上で最小のもの、b以下で最大のものをそれぞれ求める
#10~99で、それぞれ10個
def kaibun(n):
    return (n//100)*100+n//10000+((n//1000)%10)*10
ka=kaibun(a)
if a>ka:
    ka+=100
kb=kaibun(b)
if b<kb:
    kb-=100
print(kb//100-ka//100+1)


Measured memory_bytes: 3060
#include<iostream>
#include<set>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<iterator>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    unordered_map<int, int> pm;
    for (int i = 0; i < N; i++){
        cin >> p.at(i);
        pm[p.at(i)] = i;
    }
    set<int> ps;
    ps.insert(-1);
    ps.insert(pm[N]);
    ps.insert(N);
    set<long long> ps2;
    ps2.insert(1);
    ps2.insert(-pm[N]);
    ps2.insert(-N);
    long long r = 0;
    for (int i = N-1; i > 0; i--){
        auto x = ps.upper_bound(pm[i]);
        auto xm = ps2.upper_bound(-pm[i]);
        auto xp = ps.upper_bound(*x);
        auto xmm = ps2.upper_bound(*xm);
        if(xp != ps.end()){
            r += i * ((pm[i] + *xm) * (*xp - *x));
        }
        if(xmm != ps2.end()){
            r += i * ((-*xm + *xmm) * (*x - pm[i]));
        }
        ps.insert(pm[i]);
        ps2.insert(-pm[i]);
    }
    cout << r << endl;
}


Measured memory_bytes: 14116
/*
 A Submission by $%U%$
 at time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "billboard.inp"
#define FILE_OUT "billboard.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define bi BigInt
#define pi 3.1415926535897
typedef long long ll;
//------------xúc xích normie tám muoi tám phan tram não----------//
ll n,m,k,cnt[100001],t,t1,i,j,minn=1e9,maxx,cur,lu,lv;
ll arr[100002];
string s;
ll cint,cval;
vector<ll> lis;
int main() {
//	ofile;
	fio;
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>arr[i];
		lis.push_back(i);
	}
	sort(lis.begin(),lis.end(),[](ll a, ll b) {
		if (arr[a]-arr[b]) return (arr[a]>arr[b]);
		return (a<b);
	});
	for (i=0;i<n;i++)
	{
		if (i==0)
		{
			cint=lis[0];
			cval=0;
		}
		else
		{
			cval+=(-arr[lis[i]]+arr[lis[i-1]])*i;
			if (lis[i]<cint) 
			{
				cnt[cint]=cval;
				cint=lis[i];
				cval=0;
			}
		}
	}
	
			cval+=(arr[lis[i-1]])*i;
				cnt[cint]=cval;
				cint=lis[i];
				cval=0;
	for (i=0;i<n;i++) cout<<cnt[i+1]<<endl;
}

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

int main() {
    int n,m;
	cin >> n >> m;
	int cnt = 0;
	if(!n==0) cnt += (n*(n-1)/2);
	if(!m==0) cnt += (m*(m-1)/2);
	cout << cnt << "\n";
}

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

string h(int a , string str){
    string head = str.substr(0,a);
    string tail = str.substr(a,str.size()-a);
    return tail + head;

}

int main(){
    int  x, b;
    string card;

    while(1){
        cin >> card;
        if (card == "-"){
            break;
        }
        
        cin >> x;
        for(int i = 0; i < x ; i++){
            cin >> b;
            card = h(b,card);

        }
        

        cout << card << endl;;

    } 

    return 0;
}


Measured memory_bytes: 3212
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
condition = True
for i in range(0, n - 3) :
    if a[i] == a[i + 1] :
        for j in range(i + 2, n - 1) :
            if a[j] == a[j + 1] :
                print(a[i] * a[j])
                break
        break
else :
    print(0)

Measured memory_bytes: 14244
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long Int;
int main(){
  priority_queue<int> pque;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    pque.push(a);
  }
  int ans=pque.top();
  pque.pop();
  ans/=2;
  while(!pque.empty()){
    ans+=pque.top();
    pque.pop();
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <string.h>
#include<stdio.h>
#include <vector>
#include <math.h>


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


int main(){
	long long int N;
	cin >> N;
	string ans;
	while (N) {
		N--;
		ans += 'a' + N % 26;
		N /= 26;

	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;

return 0;
}


Measured memory_bytes: 3128
import numpy as np

N,K=map(int,input().split())
A=list(map(int,input().split()))
arr = np.array(A)
diff = np.diff(arr)

start_to_end=A[0]+N-A[K-1]

if max(diff) < start_to_end:
    print(sum(diff))
else:
    print(sum(diff)-max(diff)+start_to_end)

Measured memory_bytes: 36196
S = str(input())
a = [0] * len(S)

for i in range(0, len(S), 2):
    a[i] = 1
    
count = 0
for j in range(0, len(S)):
    if int(S[j]) != a[j]:
        count += 1
        
print(min(count, len(S)-count))

Measured memory_bytes: 3956
m = 0
a = 0
r = 0
c = 0
h = 0

N = int(input())

for _ in range(N):
    s = input()
    if s[0] == "M":
        m += 1
    elif s[0] == 'A':
        a += 1
    elif s[0] == 'R':
        r += 1
    elif s[0] == 'C':
        c += 1
    elif s[0] == 'H':
        h += 1

if m == 0 and a == 0 and r == 0 and c == 0 and h == 0:
    print(0)
    exit()

ans = 0
l = [m, a, r, c, h]
for i in range(len(l)):
    for j in range(i+1, len(l)):
        for k in range(j+1, len(l)):
            ans += (l[i] * l[j] * l[k])
print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

def main():
	N = int(input())
	japan = 0
	bitcoin = 0.0
	for _ in range(N):
		X = input().split()
		if X[1] == 'JPY':
			japan += int(X[0])
		else:
			bitcoin += float(X[0])
	print(japan + bitcoin * 380000.0)

if __name__ == '__main__':
	main()

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

using namespace std;

int solve(){
    vector<int> p(5,0);
    int t;
    for (int i = 0; i < 10; ++i) {
        cin>>t;
        if(i==1&&t==0)return 1;
        p[i/2]+=t;
    }
    int ans=0;
    int ansn=-1;
    for (int i = 0; i < 5; ++i) {
        if(ans<p[i]){
            ans=p[i];
            ansn=i;
        }
    }
    auto ansc= static_cast<char>('A' + ansn);
    cout<<ansc<<" "<<ans<<endl;
    return 0;
}

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


Measured memory_bytes: 3096
n = int(input())
h_ls = list(map(int, input().split()))
h_ls = h_ls

# ここからはh_lsのインデックスを基準に
one_cost = [0] * (n)
for i in range(n-1):
    one_cost[i+1] = abs(h_ls[i+1] - h_ls[i])
two_cost = [0] * (n)
for i in range(n-2):
    two_cost[i+2] = abs(h_ls[i+2] - h_ls[i])

mincost_ls = [0] * (n)
mincost_ls[1] = one_cost[1]
for i in range(n-2):
    mincost_ls[i+2] = min(mincost_ls[i+1] + one_cost[i+2], mincost_ls[i] + two_cost[i+2])
print(mincost_ls[-1])


Measured memory_bytes: 18836
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<(n);i++)
typedef long long ll;

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

ll u = 100100;

int main(){
    ll n, x, m;
    ll ans = 0;
    cin >> n >> x >> m;
    vector<ll> a(u,0);
    a[1] = x;
    ans += a[1];
    rep2(i,u){
        
        a[i+1] = a[i]*a[i]%m;
        // if(i<=5) cout << a[i] << endl;
        if(i<u-1 || i == n-1) ans += a[i+1];
        if(i == n-1) {
            cout << ans << endl;
            return 0;
        }
    }

    // uから下に向かって一致するものを探す。
    for(ll i=u-1;i>0;i--){
        if(a[i] == a[u]){
            // どこかで必ず一致するから、このカッコ内で全ての処理を行う。
            ll loopSet = 0;
            for(ll j=i;j<u;j++){
                loopSet += a[j];
            } 
            // ループの輪の長さ
            ll loopcnt = u-i;

            // u〜nでのループの回数（セットの個数）及び、余りを求める。
            ll SetNum = (n-u+1)/loopcnt;
            ll amari = (n-u+1)%loopcnt;
            // cout << "now ans:" << ans << endl; 

            ans += SetNum * loopSet;
            // cout << "now 2 ans: " << ans << endl;
            // cout << SetNum * loopSet << endl;
            for(ll j=i;j<i+amari;j++){
                ans += a[j];
            }
            cout << ans << endl; 
            // cout << "loopcnt = " << loopcnt << endl << "loopSet = " << loopSet << endl << "SetNum = " << SetNum << endl; 
            return 0;
        }
    }
}

// 632660880097787
// 492443256176507

Measured memory_bytes: 4064
#include <iostream>
using namespace std;
typedef long long ll;

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

  auto keta = [&](ll n) {
    int res = 0;
    while (n) {
      n /= 10;
      res++;
    }
    return res;
  };

  int ans = 0;
  int keta_n = keta(n);
  for (int i = 1; i <= n; i++) {
    if (keta(i) % 2 != 0) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {string s;


    cin>>s;
    ll a = 1;
    for(auto it:s){
a+=1;
bool b = false;
if(a%2 == 0) {
    if ( it == 'R' || it == 'U' || it == 'D') b=true;
}
else {
    if ( it == 'L' || it == 'U' || it == 'D') b=true;
}
if (!b) {pr("No");return 0;}
    
}
pr("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<b; i++)
#define REP(i, n)    for(int i=0; i<(n); i++)
#define fst first
#define pb push_back
#define mp make_pair
#define ALL(obj) (obj).begin(), (obj).end()
using ul = unsigned long;
using ll = long long;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;

int absint(int a, int b){
  if(a>b) return a-b;
  return b-a;
}

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

  int a[5], k;
  cin >> a[0] >>a[1] >>a[2] >>a[3] >>a[4] >> k;

  bool f=true;
  REP(i, 4){
    if( absint(a[i], a[i+1])>k ) f = false;
    if( absint(a[i], a[(i+2)%5])>k) f=false;
    if( absint(a[i], a[(i+3)%5])>k) f=false;
    if( absint(a[i], a[(i+4)%5])>k) f=false;
  }

  if(!f){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// Problem: C - Sum of product of pairs
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define int long long
#define endl "\n"
#define deb(x) cout << #x << " -> " << x << endl;
#define print(x)                         \
    for (auto x_ : x) cout << x_ << " "; \
    cout << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define mod 1000000007  // 1e9 + 7
#define prec(x, y) fixed << setprecision(y) << x

void solve() {
    int n;
    cin >> n;
    int sum = 0;
    int prefix[n] = {};
    int a[n];
    for (auto &x : a) cin >> x, sum += x;
    prefix[0] = a[0];
    for (int i = 1; i < n; ++i) prefix[i] = ((prefix[i - 1] + a[i]));
    int res = 0;
    for (int i = 0; i < n; ++i) {
        int t = ((a[i] % mod) * ((prefix[n - 1] - prefix[i]) % mod)) % mod;
        res = (t + res) % mod;
    }
    cout << (res % mod) << endl;
}

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

    int tc = 1;
    // cin >> tc;
    while (tc--) {
        solve();
    }
}

Measured memory_bytes: 6740
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;

double getDistance(double x, double y, double x2, double y2) {
    double distance = sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));

    return distance;
}

int main(){
    ll N;
    cin >> N;
    vector<vector<double>> A(N, vector<double>(2));
    double Count=0;
    for(ll i=0; i<N; i++){
        cin >> A[i][0];
        cin >> A[i][1];
        }
    for(ll i=0; i<N; i++){
        for(ll k=0; k<N; k++){
            if(i==k) continue;
            Count += getDistance(A[i][0], A[i][1], A[k][0], A[k][1]);
            }
        }
        cout << std::setprecision(12) <<Count/N;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;

int main()
{
     string a;
     cin>>a;
     int k=a.size();
     int x,y;
     for(int i=0;i<k;i++)
     {
     	if(a[i]=='C')
     	{
     		x=i;break;
     	}
     }
     for(int i=0;i<k;i++)
     {
     	if(a[i]=='F')
     	{
     		y=i;
     	}
     }
     if(y>x)	cout<<"Yes"<<endl;
     else	cout<<"No"<<endl;
     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vi h(n + 1);
  rep(i, n) cin >> h[i + 1];
  vi dp(n + 1);
  dp[0] = 1e9;
  dp[1] = 0;
  rep2(i, 2, n + 1) {
    dp[i] =
        min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1024