akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int memo[100100][2];
vector<ll> v;

int f(int n,int c){
  if(n <= 0){
    return 1-c;
  }
  
  if(memo[n][c] != -1){
    return memo[n][c];
  }
  ll flag = 0;
  // 0
  if(c == 0){
    int ret = 1;
    rep(i,0,v.sz){
      if(n>=v[i]){
        flag = 1;
        ret &= f(n-v[i], 1-c);
      }
    }
    if(flag == 0)return memo[n][c] = 1-c;
    return memo[n][c] = ret;
  }
  // 1
  else{
    int ret = 0;
    rep(i,0,v.sz){
      if(n>=v[i]){
        flag = 1;
        ret |= f(n-v[i], 1-c);
      }
    }
    if(flag == 0)return memo[n][c] = 1-c;
    return memo[n][c] = ret;
  }
}

int main() {
  clr(memo,-1);
  ll n,k;
  cin>>n>>k;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll ans = f(k,0);
  if(ans == 0){
    cout << "First" << endl;
  }
  else{
    cout << "Second" << endl;
  }
	return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long
 
int main(void){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n);
    for(ll i = 1; i < n; i++){
        if(a[i]==a[i-1]){
            cout << "NO" << endl;
            break;
        }
        if(i == n-1)
            cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k;
	ll ans=1LL;
	cin >>n>>k;
	cout << (n-k+1) << endl;
}

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

Measured memory_bytes: 3620
#!/usr/bin/ruby
def check(a,l,m,_e,n)
m-=1
l.times{|k|
	if m>0&&a[k][m-1] then m-=1
	elsif m<n-1&&a[k][m] then m+=1 end
}
return m+1==_e
end
while(n=gets.to_i)>0
m=gets.to_i
_e=gets.to_i
l=gets.to_i
a=l.times.map{gets.chomp.chars.map{|e|e=='1'}}
if check(a,l,m,_e,n) then p 0;next end
begin
l.times{|j|
	(n-1).times{|i|
		next if a[j][i]
		next if (i>0&&a[j][i-1])
		next if (i<n-2&&a[j][i+1])
		a[j][i]=true
		if check(a,l,m,_e,n) then puts "#{j+1} #{i+1}";raise "ok" end
		a[j][i]=false
	}
}
rescue; next end
p 1
end

Measured memory_bytes: 2480
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF (1LL<<60)
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
#define MSB(x) (63-__builtin_clzll(x))
#define pcnt(x) (__builtin_popcountll(x))
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int r;
  cin >> r;

  cout << r*r << endl;

  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M; cin>>N>>M;
    vector<int> X(M);
    rep(m,0,M) cin>>X.at(m);

    if(N>=M){
        cout<<0<<endl;
        exit(0);
    }

    sort(ToEnd(X));
    vector<int> Dst;
    rep(m,0,M-1) Dst.push_back(X.at(m+1)-X.at(m));
    sort(ToEnd(Dst));

    int64_t ans=0;
    rep(n,0,N-1){
        ans+=Dst.back();
        Dst.pop_back();
    }

    ans=X.back()-X.front()-ans;
    cout<<ans<<endl;
}

Measured memory_bytes: 1276
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <climits>

 
using namespace std; 


int main(){

    int n;
    long long a,b;
    cin>>n>>a>>b;

    vector<long long> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }

    long long l=-1,r=1000000000LL;
    while(r-l>1){
        long long mid=(l+r)/2LL;
        long long cnt=0;
        for(int i=0;i<n;i++){
            if(h[i]>b*mid){
                cnt+=( h[i]-b*mid + a-b-1 )/(a-b);
            }
        }
        if(cnt<=mid) r=mid;
        else l=mid;
    }

    cout<<r<<endl;


	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5;
int n, k ;
int heights[N], dp[N];
int solve(int idx)
{
    if ( idx == n-1 )
    {
        return 0 ;
    }
    if ( dp[idx] != -1)
    {
        return dp[idx] ;
    }
    int ans = 2e9 , ans1 = 2e9 ;
    for ( int i =  idx+1 ; i <= k+idx ; i++)
    {
        if ( i <= n-1)
            ans = min(ans,abs(heights[idx]-heights[i]))+solve(i);
        else
            break ;
        ans1 = min(ans,ans1) ;
    }
    return dp[idx] = ans1 ;
}
int main()
{
    cin >> n >> k;
    for ( int i = 0 ; i < n ; i++)
        cin >> heights[i] ;
    memset(dp, -1, sizeof dp) ;
    cout << solve(0);
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}

void solve(){
  int n;
  cin>>n;
  vector<ll> v1(n),v2(n);
  rep(i,0,n) cin>>v1[i]>>v2[i];
  sort(all(v1));
  sort(all(v2));
  if(n%2) cout<<v2[n/2]-v1[n/2]+1LL<<endl;
  else{
    double x = (v1[n/2]+v1[(n-1)/2]), zy= (v2[n/2]+v2[(n-1)/2]);
    double z=(zy-x)+1;
    cout<<(ll)z<<endl;
  }
}
int main(){
    optimizeIO();
    // tc
    {
      solve();
    }
}


Measured memory_bytes: 6372
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l=0,cnt=0;
    char s[10000];
    cin>>n;
    scanf("%s",s);
    l=strlen(s);
    for(int i=0;i<l;i++)
    {
        if(s[i]=='A')
        {
            if(s[i+1]=='B')
            {
                if(s[i+2]=='C')
                    cnt++;
            }
        }
    }
    cout<<cnt;


    return 0;
}



Measured memory_bytes: 256
N, Y = gets.chomp.split(" ").map(&:to_i)

ans = [-1, -1, -1]
(0..N).each{|x|
  (0..(N-x)).each{|y|
    break if 10000*x + 5000*y > Y
    (ans = [x, y, N-x-y]; break) if 10000*x + 5000*y + 1000*(N-x-y) == Y
  }
  break if ans[0] > -1
}

puts ans.join(' ')


Measured memory_bytes: 1788
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	int N, K;
	cin >> N >> K;
	VI A(N);
	VI sum(N + 1);
	VI ssum(N + 1);
	sum[0] = 0;
	ssum[0] = 0;
	REP(i, N) {
		cin >> A[i];
		sum[i + 1] = sum[i] + A[i];
		ssum[i + 1] = ssum[i];
		if (A[i] > 0)ssum[i + 1] += A[i];
		//cout << sum[i + 1] << endl;
	}

	int ans = LLINF * -1;
	eFOR(i, K, N) {
		//cout << ssum[N] + (sum[i] - sum[i - K]) << " " << ssum[N] - (ssum[i] - ssum[i - K]) << endl;
		ans = max(ssum[N] + (sum[i] - sum[i - K])-(ssum[i]-ssum[i-K]), ans);
		ans = max(ssum[N] - (ssum[i] - ssum[i - K]), ans);
	}
	cout << max(0LL, ans) << endl;
	
	return 0;
}



Measured memory_bytes: 2560
class Graph():
    from collections import namedtuple
    __Pair = namedtuple("Pair", "cost point")

    def __init__(self, element_count):
        self.__element_count = element_count
        self.__adjacency_iist = [[] for _ in range(element_count)]

    def get_path(self, begin_Point, end_point, cost):
        item = self.__Pair(cost, end_point)
        self.__adjacency_iist[begin_Point].append(item)

    def dijkstra(self, begin_Point):

        from sys import maxsize as MAX_VALUE
        from queue import PriorityQueue
        state_table = {"NotVisited": 0, "Stay": 1, "Visited": 2}

        # 初期化
        pq = PriorityQueue()
        cost_table = [MAX_VALUE for _ in range(self.__element_count)]
        visit_state = [state_table["NotVisited"]
                       for _ in range(self.__element_count)]

        # 処理
        cost_table[begin_Point] = 0
        pq.put_nowait(self.__Pair(0, begin_Point))

        while not pq.empty():

            min_item = pq.get_nowait()
            min_point, min_cost = min_item.point, min_item.cost

            visit_state[min_point] = state_table["Visited"]

            if min_cost <= cost_table[min_point]:

                for cost, point in self.__adjacency_iist[min_point]:
                    if visit_state[point] != state_table["Visited"]:

                        if cost_table[min_point] + cost < cost_table[point]:
                            cost_table[point] = cost_table[min_point] + cost
                            visit_state[point] = state_table["Stay"]
                            pq.put_nowait(self.__Pair(cost_table[point], point))

        return cost_table


router_count = int(input())

graph = Graph(router_count)

for _ in range(router_count):
    data = [int(item) for item in input().split(" ")]
    data[0] -= 1

    for lp in range(data[1]):
        graph.get_path(data[0], data[2 + lp] - 1, 1)

for _ in range(int(input())):

    sender, destination, ttl = [int(item) for item in input().split(" ")]

    costs = graph.dijkstra(sender - 1)
    cost = costs[destination - 1] + 1

    if cost <= ttl:
        print(cost)
    else:
        print("NA")



Measured memory_bytes: 7080
#include<algorithm>
#include<cstdio>
using namespace std;
int n,m,s[100000],sum;
inline void in(int &s){
	s=0;
	int f=1;
	char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		s=(s<<1)+(s<<3)+c-'0';
		c=getchar();
	}
	s*=f;
}
bool cmp(int a,int b){
	return a>b;
}
int main(){
	in(n);in(m);
	for(int i=0;i<n;++i) in(s[i]);
	sort(s,s+n,cmp);
	for(int i=0;i<m;++i) sum+=s[i];
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
map < string, int > q;
void dfs(string s) {
    q[s]++;
    for (int i = 0; i + 1 < s.size(); i++) {
        string t;
        if (s[i] != s[i + 1]) {
            for (int j = 0; j < i; j++) t += s[j];
        if ((s[i] != 'a') && (s[i + 1] != 'a')) t += 'a', t += 'a';
        else if ((s[i] != 'b') && (s[i + 1] != 'b')) t += 'b', t += 'b';
        else t += 'c', t += 'c';
        for (int j = i + 2; j < s.size(); j++) t += s[j];
        if (q[t] == 0) dfs(t);
        }
    }
}
const int maxN = 2 * (int)1e5 + 10;
int dp[maxN][3][3][2];
const int mod = 998244353;
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> s;
    if (s.size() <= 6) {
        dfs(s);
        int ans = 0;
        for (auto it = q.begin(); it != q.end(); it++) {
            ans++;
        }
        cout << ans;
        return 0;
    }
    int sum = 0;
    bool get = true;
    for (int i = 0; i < s.size(); i++) {
        sum += (s[i] - 'a');
        get &= (s[0] == s[i]);
    }
    if (get) {
        cout << 1;
        return 0;
    }
    sum %= 3;
    dp[1][0][0][0] = 1;
    dp[1][1][1][0] = 1;
    dp[1][2][2][0] = 1;
    int n = s.size();
    for (int i = 1; i + 1 <= n; i++) {
        for (int sum = 0; sum < 3; sum++) {
            for (int last = 0; last < 3; last++) {
                for (int flag = 0; flag < 2; flag++) {
                    for (int to = 0; to < 3; to++) {
                        dp[i + 1][(sum + to) % 3][to][flag | (last == to)] += dp[i][sum][last][flag];
                        if (dp[i + 1][(sum + to) % 3][to][flag | (last == to)] >= mod) dp[i + 1][(sum + to) % 3][to][flag | (last == to)] -= mod;
                    }
                }
            }
        }
    }
    int ans = 0;
    bool ok = false;
    for (int i = 0; i + 1 < s.size(); i++) {
        if (s[i] == s[i + 1]) {
            ok = true;
            break;
        }
    }
    if (!ok) ans++;
    int cur = 0;
    for (int i = 0; i < 3; i++) {
        cur += dp[n][sum][i][1];
        if (cur >= mod) cur -= mod;
    }
    ans += cur;
    cout << ans << endl;
    return 0;
    /*if ((n % 3) != 0) cout << ans << endl;
    else {
        if ((sum % 3) != 0)
    }*/
    //cout << ans << endl;
    /*dfs(s);
    int anss = 0;
    for (auto it = q.begin(); it != q.end(); it++) {
        //cout << (*it).first << endl;
        anss++;
    }
    cout << anss;*/
    return 0;
}


Measured memory_bytes: 14612
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e8+1;
int coast[10][10];
int main()
{
    FASTINOUT;
    int r,c,m;
    cin>>r>>c;
    for (int i=0;i<=9;i++)
    {
        for (int j=0;j<=9;j++)
            cin>>coast[i][j];
    }
    for (int i=0;i<10;i++){
        for (int j=0;j<10;j++){
            for (int k=0;k<10;k++){
                if (coast[j][k]>coast[j][i]+coast[i][k])
                    coast[j][k]=coast[j][i]+coast[i][k];
            }
        }
    }
    ll ans=0;
    for (int i=1;i<=r;i++){
        for (int j=1;j<=c;j++){
            cin>>m;
            if (m>-1)
                ans+=coast[m][1];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val a = sc.nextLong()
    val b = sc.nextLong()
    val n = sc.nextLong()
    if (b <= n) {
        println(a * (b - 1) / b)
    } else {
        println(a * n / b - a * (n / b))
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 34320
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define ll long long
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
int n,a,b;
int main(){
	a=rd(),b=rd();
	if(a>9||b>9) rt(-1); else rt(a*b);
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 2304
N = int(input())
mod = 10**9 +7
def fur(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod
ans = (10**N) - (-8**N +9**N + 9**N)
print(int(ans%mod))

Measured memory_bytes: 11724
n = int(input())
ans = float('inf')
for factor in range(1,int(n**0.5)+2):
    if n % factor == 0:
        factor1 = factor
        factor2 = n // factor1
        bigger = max(factor1, factor2)
        num_d = len(str(bigger))
        ans = min(ans, num_d)
print(ans)

Measured memory_bytes: 3060
let n = Scanf.scanf " %d" Fun.id
let s = Scanf.scanf " %s" Fun.id

let rec loop left right n =
  if left >= right then n
  else if s.[left] = 'R' then loop (left + 1) right n
  else if s.[right] = 'W' then loop left (right - 1) n
  else loop (left + 1) (right - 1) (n + 1)

let () =
  Printf.printf "%d\n" @@ loop 0 (String.length s - 1) 0


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

int main(){
	
	int mt[10];
	int i, s, t, tmp, j;
	
	for(i=0; i<10; i++){
		cin >> mt[i];
	}
	
	for(s=0; s<9; s++){
		for(t=s+1; t<10; t++){
			if(mt[t] > mt[s]){
				tmp = mt[t];
				mt[t] = mt[s];
				mt[s] = tmp;
			}
		}
	}
	
	for(j=0; j < 3; j++){
		cout << mt[j] << endl;
	}
	

	return 0;
	
}

Measured memory_bytes: 3084
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int y = in.nextInt();
		
		Main program = new Main();
		System.out.println(program.gcd(x, y));
	}
	
	public int gcd(int x, int y) {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	}
}


Measured memory_bytes: 26324
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int n = s.size();
    int index_l, index_r;
    rep(i,n) {
        if (s[i] == 'A') {index_l = i; break;}
    }
    rep(i,n) {
        if (s[n-1-i] == 'Z') {index_r = n-1-i; break;}
    }
    cout << index_r-index_l+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k;
    cin>>n>>k;
    long long int ans=0;
    for (int i=0;i<n;i++) {
        if (i==0) {
            ans+=k;
        } else {
            ans=ans*(k-1);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll calc(ll a,ll b,ll n){
  return a * n / b - a * (n / b);
}

int main(){
  ll a,b,n;
  cin >> a >> b >> n;
  ll ans = 0;
  chmax(ans,calc(a,b,n));

  if(b > 1000000 && n > 1000000){
    t1 = b-1;
    if(t1 <= n){
      chmax(ans,calc(a,b,t1));
      t1 += b;
    }
  }else{
    t2 = min(b,n);
    rep(i,t2+1){
      chmax(ans,calc(a,b,i));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
N = int(input())
V = input()
C = input()

V = V.split(' ')
C = C.split(' ')

sagaku = []
X = 0
Y = 0

for i, kakaku in enumerate(V):
    sagaku.append(int(kakaku) - int(C[i]))
    if int(kakaku) - int(C[i]) > 0:
        X += int(kakaku)
        Y += int(C[i])
        
print(X - Y)


Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        x: i64,
    }

    if 30<=x {
        println!("Yes");
    } else {
        println!("No");
    }

}

Measured memory_bytes: 2136
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll a; cin >> a;
	cout << 3 * pow(a, 2) << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int a[n+1];
	for(int i=1; i<=n; i++) cin >> a[i];

	vector<int> b(n+1, 0);
	vector<int> ball;
	for(int i=n; i>0; i--){
		int cnt=0;
		for(int j=2; i*j<=n; j++){
			if(b[i*j]==1) cnt++;
		}
		if(cnt%2!=a[i]){
			ball.push_back(i);
			b[i]=1;
		}
	}

	cout << ball.size() << endl;
	for(int i=0; i<ball.size(); i++){
		cout << ball[i];
		if(i!=ball.size()-1) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3064
H, W, K = map(int, input().split())
C = []
for i in range(H):
    c = str(input())
    C.append(c)
from itertools import combinations
from collections import Counter

def subsets(nums):
    n = len(nums)
    out = []
    for i in range(n+1):
        subout = []
        comb(nums, i, subout)
        out += subout
    return out

def comb(seq, k, out):
    _comb(seq, len(seq), k, 0, [], out)

def _comb(seq, n, k, i, elem, out):
    le = len(elem)
    if le == k:
        out.append(elem)
        return
    for i in range(i, n):
        _comb(seq, n, k, i+1, elem + [seq[i]], out)

def powset(H, W, K, C):
    X = subsets(list(range(W)))
    N = len(X)
    A = []
    for j in range(H):
        a = [0]*N
        for k in range(N):
            for ind in X[k]:
                if C[j][ind] == '#':
                    a[k] += 1
        A.append(a)
    Y = subsets(list(range(H)))
    M = len(Y)
    ans = [0]*(N*M)
    for k in range(N):
        for l in range(M):
            for ind in Y[l]:
                ans[l*N+k] += A[ind][k]
            
    c = Counter(ans)
#     print(c)
    if K in c:
        return c[K]
    else:
        return 0
        

def Main(H, W, K, C):
    return powset(H, W, K, C)
                    
out = Main(H, W, K, C)
print(out)

Measured memory_bytes: 9504
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

long long x[60], dp[60][60][2600];

int main() {
    int N, A;
    cin >> N >> A;
    rep(i, N) cin >> x[i];
    
    dp[0][0][0] = 1;
    rep(i, N) rep(j, 50) rep(k, 2550) {
        dp[i + 1][j][k] += dp[i][j][k];
        dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
    }
    long long ans = 0;
    REP(i, N + 1) {
        ans += dp[N][i][A * i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  long long int count=1;
  int n;
  int x=0,y=0,z=0;
  cin >> n;
  for (int i=0; i<n; i++) {
    int num;
    cin >> num;
    int temp_count=0;
    if (x==num) {
      temp_count++;
      x++;
      if (y==num) {
        temp_count++;
      }
      if (z==num) {
        temp_count++;
      }
    }
    else if (y==num) {
      temp_count++;
      y++;
      if (z==num) {
        temp_count++;
      }
    }
    else if (z==num) {
      temp_count++;
      z++;
    }
    count *= temp_count;
    count %= 1000000007;
  }
  cout << count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>v(n);
	vector<int>c(n,0);
	rep(i,n)cin>>v[i];
	rep(i,n)cin>>c[i];
	int ans=0;
	rep(i,n)ans+=max(v[i]-c[i],0);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
//   /$$$$           /$$                 /$$$$  /$$$$$$            /$$
//  | $$_/          | $$                |_  $$ /$$__  $$          | $$
//  | $$    /$$$$$$$| $$$$$$$   /$$$$$$   | $$|__/  \ $$ /$$$$$$$ | $$   /$$
//  | $$   /$$_____/| $$__  $$ |____  $$  | $$  /$$$$$$/| $$__  $$| $$  /$$/
//  | $$  |  $$$$$$ | $$  \ $$  /$$$$$$$  | $$ /$$____/ | $$  \ $$| $$$$$$/
//  | $$   \____  $$| $$  | $$ /$$__  $$  | $$| $$      | $$  | $$| $$_  $$
//  | $$$$ /$$$$$$$/| $$  | $$|  $$$$$$$ /$$$$| $$$$$$$$| $$  | $$| $$ \  $$
//  |____/|_______/ |__/  |__/ \_______/|____/|________/|__/  |__/|__/  \__/
//
//
//






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


#define ll long long int
#define ull unsigned long long int
#define po2(z) 1<<(ll)z
#define fr(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define rf(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define modinv(x) powah(x,mod-2)
#define ncr(n,r) (((fact[n]*modinv(fact[n-r]))%mod*modinv(fact[r]))%mod)
#define factorial fact.pb(1);sidha(i,1,MAX)fact.pb((fact[i-1]*i)%mod)
#define tej ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod (ll)1000000007
#define MAX 100005
#define Vii  vector<ll>
#define pb  push_back
#define pii pair<ll,ll>
#define ff  first
#define ss second
#define vpii vector<pii >
#define endl '\n'


//--------------------------------------------------//
void solve(){
	ll n;
	cin>>n;
	vector<ll>h(n);
	
	for(ll i=0;i<n;i++) cin>>h[i];
	
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(ll i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<endl;
	

}

//--------------------------------------------------//


int main(){
  ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc=1;
//	cin >> tc;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }


}


Measured memory_bytes: 4740
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])

if a + b + c + d == 7:
    print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a - b + c + d == 7:
    print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a - b - c + d == 7:
    print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a - b + c - d == 7:
    print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a - b - c - d == 7:
    print('{}-{}-{}-{}=7'.format(a,b,c,d))
elif a + b - c + d == 7:
    print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a + b + c - d == 7:
    print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a + b - c - d == 7:
    print('{}+{}-{}-{}=7'.format(a,b,c,d))

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;

//io_method-------------------------------------------------------------------------------------
/*
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
*/

//main_method-----------------------------------------------------------------------------------

struct bellman_ford{
    vector<int> distance;
    bool is_negative_loop;

    bellman_ford(vector<vector<int> > edges, int s, int n){
        vector<int> dist;
        rep(i,0,n) dist.push_back(inf); dist[s] = 0;
        
        rep(i,0,n){
            bool isupdate = false;
            rep(j,0,edges.size()){
                int frm = edges[j][0], to = edges[j][1], cost = edges[j][2];
                if(dist[frm] != inf && dist[to] > dist[frm] + cost){
                    dist[to] = dist[frm] + cost;
                    isupdate = true;
                }
            }
            if(not isupdate){
                distance = dist;
                is_negative_loop = false;
                break;
            }

            if(i == n-1 && isupdate){
                is_negative_loop = true;
            }
        }
                
    }

};

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

    int n, m, r;
    cin >> n >> m >> r;

    vector<vector<int>> edges;

    rep(i,0,m){
        int f, t, c;
        cin >> f >> t >> c;
        edges.push_back({f,t,c});
    }

    bellman_ford bf = bellman_ford(edges, r, n);

    if(bf.is_negative_loop){
        cout << "NEGATIVE CYCLE" << endl;
    }else{
        for(auto e: bf.distance){
            if(e == inf) cout << "INF" << endl;
            else cout << e << endl;
        }
    }



    

    



}


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

int main() {
    int n;
    cin >> n;
    vector<float> v;
    for (int i=0; i<n; i++)
    {
        float a;
        cin >> a;
        v.push_back(a);
    }
    int k=0;
    while (v.size() != 1)
    {
        float min1Index = min_element(v.begin(), v.end()) - v.begin();
        float min1 = *(min1Index + v.begin());
        v.erase(v.begin() + min1Index);

        float min2Index = min_element(v.begin(), v.end()) - v.begin();
        float min2 = *(min2Index + v.begin());
        v.erase(v.begin() + min2Index);

        float moy = (min1 + min2) / 2.0;
        v.push_back(moy);
    }
    // cout << k;
    printf("%.5f", v[0]);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace abc148_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
            Console.WriteLine(Lcm(AB[0], AB[1]));
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b ;
        }

        /// <summary>
        /// 最小公約数：ユークリッドの互除法 
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
        
    }
}


Measured memory_bytes: 11604
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<random>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define endl "\n"
#define fi first
#define se second
#define db double
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) (x & (-x))
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template<class T> inline T qmin(T a, T b) { return a < b ? a : b; }
template<class T> inline T qmax(T a, T b) { return a > b ? a : b; }
typedef long long ll;
typedef unsigned long long ull;
const db eps = 1e-9;
const db PI = acos(-1);
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;//remember to modify it, No RE or MLE
const ll INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
ll qpow(ll x, ll y) { ll ret = 1; for( ; y; y >>= 1, x = (x * x) % mod) if(y & 1) ret = (ret * x) % mod; return ret; }

inline int read(){
	char ch = getchar();
	int x = 0, f = 1;
	while(ch < '0' || ch > '9'){
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9'){
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

int n;
int h[maxn], dp[maxn];

int main()
{
	n = read();
	rep(i, 1, n) h[i] = read();
	memset(dp, 0x3f, sizeof dp);
	dp[1] = 0;
	rep(i, 1, n){
		dp[i+1] = qmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
		dp[i+2] = qmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
	}
	printf("%d\n", dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

struct node {
	int key;
	node* left;
	node* right;
};

node *root = NULL;

// Insert new key
void insert(int key)
{
	node *n = new node();
	*n = { NULL };
	n->key = key;
	node *x = root;
	node *y;
	y = NULL;
	while (x != NULL) {
		y = x;
		if (x->key >= n->key)
			x = x->left;
		else
			x = x->right;
	}
	if (y == NULL)
		root = n;
	else if (y->key >= n->key)
		y->left = n;
	else
		y->right = n;
}

// Pre-order traversal
void preorder(node* n)
{
	cout << " " << n->key;
	if(n->left != NULL)
		preorder(n->left);
	if (n->right != NULL)
		preorder(n->right);
}

// In-order traversal
void inorder(node* n)
{
	if(n->left != NULL)
		inorder(n->left);
	cout << " " << n->key;
	if (n->right != NULL)
		inorder(n->right);
}

// Finde key
node* find(int key) 
{
	node* n = root;
	while (n != NULL) {
		if (n->key == key)
			return n;
		if (n->key >= key)
			n = n->left;
		else
			n = n->right;
	}
	return NULL;
}

// MAIN FUNCTION
int main(int argc, char** argv)
{
	// input
	string opt;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> opt;
		if (opt == "insert") {
			// insert new node
			int key;
			cin >> key;
			insert(key);
		}
		else if (opt == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
		else if (opt == "find") {
			int key;
			cin >> key;
			node* result = find(key);
			if (result != NULL)
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}

	}
	return 0;
}

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

int constexpr N = 100009;
int n, a[N], dp[N][2];
bool done[N][2];

int mx(int i, int t) {
    if(i == 1) {
        if(t) return a[1] * -1;
        else  return a[1];
    }
    if(done[i][t]) return dp[i][t];
    int v = a[i];
    if(t) v *= -1;
    int& ans = dp[i][t];
    ans = max(v * -1 + mx(i - 1, 1), v + mx(i - 1, 0));
    done[i][t] = true;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];

    cout << mx(n, 0) << endl;
}


Measured memory_bytes: 9088
def main():
    n, x = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = 0
    num_list.sort()

    for num in num_list:
        if x - num >= 0:
            x -= num
            ans += 1
        else:
            break

    if ans == n and x > 0:
        ans -= 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
a,b,c,x,y = map(int, input().split())
c *= 2
mi = a*x + b*y

for i in range(x+1):
    v = x-i
    s = a*i + b*(y-v) + c*v
    if y <= v:
        s = a*i + c*v
    if s < mi:
        mi = s

for i in range(y+1):
    v = y-i
    s = a*(x-v) + b*i + c*v
    if x <= v:
        s = b*y + c*v
    if s < mi:
        print('h', a*(x-v) + b*i + c*v)
        mi = s

if c*max((x,y)) < mi:
    mi = c*max((x,y))

print(mi)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

void test();

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,l;
	cin >> n >> l;
	vector<ll> a(n);
	ll sum = 0;
	f(i,0,n){
		a[i] = l+i;
		sum += a[i];
	}
	ll diff=1e9,ans=0;
	f(i,0,n){
		if(abs(a[i])<diff){
			diff = abs(a[i]);
			ans = sum-a[i];
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll n, m; cin >> n >> m;
    string S; cin >> S;
    vll p(0); ll cc = 1;
    rep(i, 1, n+1){
        if(S[i] == S[i-1]){
            cc++;
        }else{
            p.emplace_back(cc);
            cc = 1;
        }
    }
    p.emplace_back(cc);
    ll s = sz(p);
    bool b = false;
    rep(i, 0, s){
        if(i % 2 == 1){
            if(p[i] >= m){
                b = true;
            }
        }
    }
    vll cnt(n+1);
    ll k = 0;
    rep(i, 0, n+1){
        if(S[i] == '1'){
            cnt[i] = INF;
            k++;
        }else{
            cnt[i] = k;
            k = 0;
        }
    }
    for(auto x: cnt){
        //prtl(x);
    }
    if(b){
        prtl(-1);
        return 0;
    }
    vll dp(n+1, INF);
    dp[0] = 0;
    ll t = 0, c = 1, v = 0;
    rep(i, 1, n+1){
        if(S[i] == '1'){
            //prtl(dp[i]);
            continue;
        }
        if(i - t <= m){
            dp[i] = c;
            v = i;
        }else{
            c++;
            t = v;
            dp[i] = c;
            v = i;
        }
        //debug(t);
        //prtl(dp[i]);
    }
    vll ans(0);
    ll g = 1;
    rrep(i, n-1, -1){
        if(S[i] == '1'){
            //debug(i); debug(g);
            g++;
            continue;
        }
        if(g+cnt[i] < m){
            //debug(i); debug(g);
            g++;
        }else{
            //debug(i); debug(g);
            ans.emplace_back(g);
            g = 1;
        }
    }
    ans.emplace_back(g-1);
    reverse(all(ans));
    for(auto x: ans){
        if(x != 0){
            prt(x); prt(" ");
        }
    }
}



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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<ll> va(n);
  map<ll, ll> cnts;
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
    cnts[va[i]]++;
  }

  ll ans = 0;
  for (auto p : cnts) {
    if (p.first > p.second) {
      ans += p.second;
    } else {
      ans += p.second - p.first;
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 9896