akhauriyash/Code-Regression huggingface dataset:
#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 rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;i++)cin>>h[i];
	vector<int> dp(n,0);
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		int ans=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
		dp[i]=ans;
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll x; cin>>x;
    ll res=1;
    for(ll b=2; b<=40; b++){
        ll p=2;
        ll tmp=b*b;
        if(tmp>x)continue;
        while(tmp*b<=x){
            p++; tmp*=b;
        }
        chmax(res,tmp);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX_N 100

int bubbleSort(int*,int);
void print(int*,int,int);

int main(){
  int N,A[MAX_N],i,cnt;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&A[i]);
  }
  cnt = bubbleSort(A,N);
  print(A,N,cnt);
  return 0;
}

int bubbleSort(int *A,int N){
  int i,j,temp,res = 0;
  for(i = 0 ; i < N ; i++){
    for(j = N-1 ; j > i ; j--){
      if(A[j-1] > A[j]){
        ++res;
        temp = A[j];
        A[j] = A[j-1];
        A[j-1] = temp;
      }
    }
  }
  return res;
}

void print(int *A,int N,int cnt){
  int i;
  for(i = 0 ; i < N ; i++){
    printf("%d%c",A[i],(i < N-1 ? ' ' : '\n'));
  }
  printf("%d\n",cnt);
}

Measured memory_bytes: 600
# 1 から n までの数の中から、重複無しで３つの数を選び
# それらの合計が x となる組み合わせの数を求める
while True:
    n, x = input().split()
    if n == x == "0":
        break
    n = int(n)
    x = int(x)
    num = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                # print("%d + %d + %d" %(i, j, k))
                if i + j + k == x:
                    num += 1
                    break
    print(num)



Measured memory_bytes: 5596
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int i = 1;
        int count = 0;
        int n = sc.nextInt();
        for (i = 1;; i++) {
            count += i;
            if (count >= n) {
                break;
            }
        }
        System.out.println(i);
        bw.flush();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n, x;
    cin >> n >> x;
    vector<ll> c;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        c.push_back(a);
    }
    c.push_back(x);
    sort(c.begin(), c.end());
    vector<ll> g;
    for(ll i = 0; i < c.size()-1; i++){
        g.push_back(c[i+1]-c[i]);
    }
    ll MAX = 0;
    ll check = g[0];
    for(ll i = 1; i < g.size(); i++){
        check = __gcd(check, g[i]);
    }
    cout << check << endl;
    return 0;
}


Measured memory_bytes: 2548
# B - Making Triangle
def main():
    n = int(input())
    l = list(map(int, input().split()))
    cnt = 0

    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i < j < k:
                    if l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[i]+l[k]>l[j]:
                        if l[i] != l[j] and l[j] != l[k] and l[i] != l[k]:
                            cnt += 1
    else:
        print(cnt)


if __name__ ==  "__main__":
    main()

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

#define ll long long
#define endl "\n"
#define M 10000001

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll div = n/1000;
    if(n%1000 == 0)
    {
        cout<<0<<endl;
    }
    else
    {
        ll mul = (div+1)*1000;
        cout<<(mul-n)<<endl;
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll countGreater(ll arr[], ll n, ll k) 
{ 
    ll l = 0; 
    ll r = n - 1; 
  
 
    ll leftGreater = n; 
  
 
    while (l <= r) { 
        ll m = l + (r - l) / 2; 
  
        if (arr[m] > k) { 
            leftGreater = m; 
            r = m - 1; 
        } 
  
 
        else
            l = m + 1; 
    } 
  
   
    return (n - leftGreater); 
}
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}

ll ans(ll A[],ll left,ll right,ll x)
{
    if(A[left]==x)return 1;

    else if(A[right==x])return 1;

   ll m=left+(right-left)/2;
   while(left<=right)
   {
    if(A[m]>x)right=m-1;
    else if(A[m]<x)left=m+1;
    else return 1;
   }
   return 0;
} 
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll n,a,q,a1,b1,temp1,temp2,i,rev=0,flag=0;

vector<char>s;
string ss;
cin>>ss;

for(i=0;i<ss.size();i++)
{
    s.push_back(ss[i]);
}

cin>>q;
ll query[q][2];

char ch[q];


for(i=0;i<q;i++)
    {
        cin>>query[i][0];
        if(query[i][0]==2)cin>>query[i][1]>>ch[i];
     }

    for(i=0;i<q;i++)
    {
        
         if(query[i][0]==1)
            {
                rev++;
                rev%=2;
            }
         else 
         {
            if(query[i][1]==1&&rev==0)
            {
                   s.insert(s.begin(),ch[i]);
            }
            else if(query[i][1]==1&&rev==1)
            {
                s.insert(s.end(),ch[i]);
            }
           else  if(query[i][1]==2&&rev==0)
            {
                 s.insert(s.end(),ch[i]);
            }
            else if (query[i][1]==2&&rev==1)
            {
                s.insert(s.begin(),ch[i]);
            }
         }
    }

    if(rev==0)
    {
          for(i=0;i<s.size();i++)cout<<s[i];
    }
else for(i=s.size()-1;i>=0;i--)cout<<s[i];




    return 0;
    
}


 

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

int main()
{
        int a,b;
        cin >> a >> b;
        if (a == b)
                cout << "Draw" << endl;
        else if (a == 1)
                cout << "Alice" << endl;
        else if (b == 1)
                cout << "Bob" << endl;
        else if (a > b)
                cout << "Alice" << endl;
        else
                cout << "Bob" << endl;
        return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    diff = n - sum(a)

    if diff < 0:
        print(-1)
    else:
        print(diff)


if __name__ == '__main__':
    main()


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

using pii = pair<int, int>;

constexpr int inf = 1e9;

int main() {
    int n; cin >> n;
    vector<int> p(n);
    vector<vector<int>> g(n);
    for(int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    for(int i = 0; i < n - 1; ++i) {
        int s, t; cin >> s >> t;
        g[s - 1].push_back(t - 1);
        g[t - 1].push_back(s - 1);
    }

    // 0: start, 1: last, 2: start & last, 3: inter
    int ans = -inf;
    vector<vector<int>> dp(n, vector<int>(4, -inf));
    function<void(int, int)> dfs = [&] (int v, int par) {
        dp[v][0] = dp[v][1] = dp[v][2] = dp[v][3] = p[v];
        vector<int> ch0, ch1, ch2;
        vector<pii> sub0, sub1;
        int sum2 = 0, max_sub3 = 0;
        for(auto to : g[v]) {
            if(to == par) continue;
            dfs(to, v);
            ch0.push_back(max(0, dp[to][0] - 1));
            ch1.push_back(max(0, dp[to][1] - 1));
            ch2.push_back(max(0, dp[to][2] - 2));
            sub0.emplace_back(ch0.back() - ch2.back(), to);
            sub1.emplace_back(ch1.back() - ch2.back(), to);
            max_sub3 = max(max_sub3, max(0, dp[to][3] - 2) - ch2.back());
            sum2 += ch2.back();
        }
        const int sz = ch0.size();
        sort(rbegin(sub0), rend(sub0));
        sort(rbegin(sub1), rend(sub1));
        for(int i = 0; i < sz; ++i) {
            dp[v][0] = max(dp[v][0], sum2 + ch0[i] - ch2[i] + p[v]);
            dp[v][1] = max(dp[v][0], sum2 + ch1[i] - ch2[i] + p[v]);
        }
        dp[v][2] = max(dp[v][2], sum2 + p[v]);
        // inter
        dp[v][3] = max(dp[v][3], sum2 + max_sub3 + p[v]);
        if(sz >= 2) {
            for(int i = 0; i < 2; ++i) {
                for(int j = 0; j < 2; ++j) {
                    if(i == j || sub0[i].second == sub1[j].second) continue;
                    dp[v][3] = max(dp[v][3], sum2 + sub0[i].first + sub1[j].first + p[v]);
                }
            }
        }
        ans = max(ans, *max_element(begin(dp[v]), end(dp[v])));
    };
    dfs(0, -1);

    cout << ans << endl;
}



Measured memory_bytes: 43776
#include<stdio.h>
#define MAX 100000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u)
{
    if (u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u)
{
    if (u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u)
{
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main()
{
    int i, v, l, r, root;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        T[i].p = NIL;
    }

    for (i = 0; i < n; i++)
    {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }

    for (i = 0; i < n; i++)
    {
        if (T[i].p == NIL)
        {
            root = i;
        }
    }

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2040
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/

/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K,X,Y;
    cin >> N >> K >> X >> Y;

    cout << min(K,N)*X + max(N-K, 0)*Y << endl;
}


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

ll n, s, ans = -1;

inline ll read() {
	ll s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline ll f(ll b, ll n) {
	ll ans = 0;
	while(n)	ans += n % b, n /= b;
	return ans;
}

int main() {
	n = read(), s = read();
	ll u = sqrt(n) + 1;
	for(ll i = 2; i <= u; ++i)	if(f(i, n) == s) { ans = i; break; }
	if(n == s) { ans = n + 1; }
	if(ans == -1 && n > s) {
		ll c = n - s;
		u = c / (u - 1) + 1;
		for(ll i = u; i >= 1; --i) {
			ll b = c / i + 1;
			if(!(c % i) && s >= i && (s - i) < b && i < b) {
				ans = b;
				break;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,k;
	cin >> a >> b >> k;
	ll t = min(a,k);
	a -= t;
	k -= t;
	b -= k;
	b = max(ll(0),b);
	cout << a << " " << b << endl;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N, D, X;
	cin >> N >> D >> X;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		ans += (D - 1) / A + 1;
	}
	cout << ans + X << endl;
}


Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().split()))
sumv=0
d={}
for i in arr:
    sumv+=i
    try:
        d[i]+=1
    except:
        d[i]=1

q=int(input())

while q:
    
    b,c=map(int,input().split())
    if b in d:
        sumv+=(c-b)*d[b]
   
        try:
            d[c]+=d[b]
        except:
            d[c]=d[b]
    d[b]=0
    print(sumv)


    q-=1


Measured memory_bytes: 23540
#k分たったときには机Aの本を上から何冊か、机Bの本を上から何冊か読んでることになる
#つまり机A,Bの方で読んだ本の合計時間は累積和で計算可能
#あとはその範囲内で全探索すればいい
#その際Aの読む数を決めておけばBの方は2分探索で決められる
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
from itertools import accumulate
a=[0]+list(accumulate(a))
b=[0]+list(accumulate(b))
from bisect import bisect_right
c=bisect_right(a,k)
ans=0
for i in range(c):
  ans=max(ans,i+bisect_right(b,k-a[i])-1)
  
  
print(ans)


Measured memory_bytes: 41216
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

fn main() {
    let S = rl().chars().collect::<Vec<_>>();
    let N = S.len();

    // dp[i][r] ≡ n (mod P):
    //   S[..i] の '?' に数字を埋めたときに得られる整数全体の集合を T としたとき、
    //   T の要素のうち 13 で割った余りが r に等しいものの集合の要素数が n に等しい
    let mut dp = vec![vec![0; 13]; N + 1];

    // 初期条件
    // 10進表記の "" が 0 を表すということにしておくと都合がいい。
    dp[0][0] = 1;

    for i in 0..N {
        // S[i] = d

        // 数字 d としてありえる値の最小値
        let u = if S[i] == '?' {
            0
        } else {
            (S[i] as u8 - b'0') as usize
        };

        // 数字 d の最大値
        let v = if S[i] == '?' {
            9
        } else {
            (S[i] as u8 - b'0') as usize
        };

        for r in 0..13 {
            for d in u..v + 1 {
                let s = (10 * r + d) % 13;
                dp[i + 1][s] += dp[i][r];
                dp[i + 1][s] %= P;
            }
        }
    }

    println!("{}", dp[N][5])
}


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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

const int N = 53;
string s[N];

vector <int> e[N];

int deg[N];
bool solve() {
	memset(deg, 0, sizeof deg);
	queue <int> q;
	for(int i = 0; i < N; i ++)
		for(int j : e[i])
			deg[j] ++;
	for(int i = 0; i < N; i ++)
		if(!deg[i]) q.push(i);
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int i : e[x]) {
			deg[i] --;
			if(!deg[i])
				q.push(i);
		}
	}
	for(int i = 0; i < N; i ++)
		if(deg[i]) return 0;
	return 1;
}

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	int t; cin >> t;
	while(t --) {
		int n, m; cin >> n >> m;
		for(int i = 1; i <= n; i ++) {
			cin >> s[i];
			s[i] = '\0' + s[i];
		}

		for(int i = 0; i < N; i ++) e[i].clear();	
		for(char c = 'A'; c <= 'Z'; c ++) {
			int ix = N, iy = N;
			int ax = 0, ay = 0;
			for(int i = 1; i <= n; i ++)
				for(int j = 1; j <= m; j ++) if(s[i][j] == c) {
					ix = min(ix, i); ax = max(ax, i);
					iy = min(iy, j); ay = max(ay, j);
				}
			for(int i = ix; i <= ax; i ++)
				for(int j = iy; j <= ay; j ++)
					if(s[i][j] == '.') e[c - 'A'].pb(c - 'A');
					else if(s[i][j] != c) e[s[i][j] - 'A'].pb(c - 'A');
		}
		cout << (solve() ? "SAFE" : "SUSPICIOUS") << '\n';
	}

	return 0;
}

Measured memory_bytes: 3108
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int main(void)
{
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    int d = n % 10;
    if (d == 1) {
      d = 9;
    }
    else if (d == 9) {
      d = 1;
    }
    ans += d * (int)pow(10, i);
    n /= 10;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    long long p=n-1,sum=0;
    vector<int> d(n);
    for(int i=n-1;i>=0;i--){
        if(b[p]<c[i]){
            sum++;
        }
        else{
            d[p]=sum;
            p--;
            i++;
        }
    }
    for(int i=p;i>=0;i--){
        d[i]=sum;
    }
    p=n-1;
    sum=0;
    long long ans=0;
    for(int i=n-1;i>=0;i--){
        if(a[p]<b[i]){
            sum+=d[i];
        }
        else{
            ans+=sum;
            p--;
            i++;
        }
    }
    for(int i=p;i>=0;i--){
        ans+=sum;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int count = 0;

    for (int i = 0; i < n; i = i)
    {
        if (s[i] == 'A')
        {

            if (s[i + 1] == 'B')
            {

                if (s[i + 2] == 'C')
                {

                    count++;
                    i += 3;
                }
                else
                {
                    i += 2;
                }
            }
            else
            {
                i += 1;
            }
        }
        else
        {
            i += 1;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

signed main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			sum += a[i] * a[j];
		}
	}
	cout << sum << "\n";
}



Measured memory_bytes: 256
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

def main():
    #全体に同じものを足すときは累積和を考えたい
    N,Q = map(int,input().split())
    AB = [list(map(int,input().split())) for _ in range(N-1)]
    PX = [list(map(int,input().split())) for _ in range(Q)]

    graph = [[] for _ in range(N+1)]

    for a,b in AB:
        graph[a].append(b)
        graph[b].append(a)
    #どちらが親か分からないがとりあえずつながっている
    #どちらが親かは後で判断

    counter = [0 for _ in range(N+1)]
    #counter[i]:i番目の頂点のカウンター
    parent = [None for _ in range(N+1)]

    for p,x in PX:
        counter[p] += x

    dfs(graph,parent,counter,1)

    ans = " ".join(map(str,counter[1:]))
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 141160
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
char a2[27];int num1,num2;
string a;
int main()
{
    cin>>a;int d=a.length();
    cout<<a[0]<<a.length()-2<<a[d-1]<<endl;
    return 0;
    
}


Measured memory_bytes: 256
def func(s):
    try:
        return(int(s))
    except ValueError:
        return False

expression = input().split()
stack = []
for i in range(len(expression)):
    s = func(expression[i])
    if s:
        stack.append(expression[i])
    else:
        op1 = stack.pop()
        op2 = stack.pop()
        result = eval(op2+expression[i]+op1)
        stack.append(str(result))
print(stack[0])



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
 
const ll INF = 2e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod){ll x=1;while(b){while(!(b&1)){(a*=a)%=mod;b>>=1;}(x*=a)%=mod;b--;}return x;}
void YES(bool cond){ if(cond){ p("YES");}else{ p("NO");} return;}
void Yes(bool cond){ if(cond){ p("Yes");}else{ p("No");} return;}

/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k, ans;

ll x[500005], y[500005], z[500005];
ll dp[5005][5005];
string s;

void solve(){
    cin >> k;
    cin >> s;
    n = s.size();
    if(n <= k){
        p(s);
    }else{
        pu(s.substr(0, k));
        p("...");
    }

    return;
}

int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if(multicase){
        cin >> q;
    }else{
        q = 1; 
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}
















Measured memory_bytes: 3648
#include <stdio.h>

static int N = 100;

int main(){
  int M[N][N];
  int n,u,k,v,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j] = 0;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>

int main(void){

	int n, i, cnt = 0;
	scanf("%d", &n);
	
	char a[n+1], b[n+1], c[n+1];
	
	scanf("%s %s %s", a, b, c);

	for(i = 0; i < n; i++){
		if(a[i] == b[i]){
			if(a[i] == c[i]){

			}else{
				cnt+= 1;
			}
		}else{
			if(a[i] == c[i]){
				cnt += 1;
			}else{
				if(b[i] == c[i]){
					cnt += 1;
				}else{
					cnt += 2;
				}
			}
		}
	}
	
	printf("%d", cnt);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
 
int main(){
    int N,M;
    cin >> N >> M;
    
    int A[N],sum=0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }
 
    int selectedProduct = 0;
    for(int i=0;i<N;i++){
        if(A[i] >= (double) sum / (4*M)){
            selectedProduct++;
        }
    }
    if(selectedProduct >= M){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 5e4+10;
int a[maxn];
string str;
bool cmp(int a,int b)
{
    return a > b;
}
int Max;
int main()
{
    int n;
    Max = 0;
    scanf("%d",&n);
    ll ans = 0;
    for(int i = 0;i < n;i++)
    {
        int cur;
        scanf("%d",&cur);
        if(Max < cur)
        {
            Max = cur;
            continue;
        }
        else{
            ans += (Max - cur);
        }
    }
    cout<<ans<<endl;

}


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

int main()
{
    int n;
    while(cin>>n)
    {
        int i=n;
        for(i=n;;i++)
        {
            int ii=i;
            int mod=ii%10;
            bool flag=true;
            while(ii)
            {
                if(ii%10!=mod)
                {
                    flag=false;
                    break;
                }
                ii/=10;
            }
            if(flag)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> v[4];
int sum[4][110];

int main()
{
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n,w,a,b,x,sol=0;
    scanf("%d%d",&n,&w);
    scanf("%d%d",&a,&b);
    v[0].push_back(b);
    for(int i=2;i<=n;i++)
    {
        scanf("%d%d",&x,&b);
        v[x-a].push_back(b);
    }
    for(int i=0;i<4;i++)
    {
        sort(v[i].begin(),v[i].end());
        reverse(v[i].begin(),v[i].end());
        for(int j=0;j<v[i].size();j++)
            sum[i][j+1]=sum[i][j]+v[i][j];
    }
    for(int i=0;i<=v[0].size();i++)
        for(int j=0;j<=v[1].size();j++)
            for(int q=0;q<=v[2].size();q++)
            {
                long long s=1LL*a*i+1LL*(a+1)*j+1LL*(a+2)*q;
                if(s>w) continue;
                int k=min((int)v[3].size(),(int)(w-s)/(a+3));
                sol=max(sol,sum[0][i]+sum[1][j]+sum[2][q]+sum[3][k]);
            }
    printf("%d",sol);
    return 0;
}


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

int main(){ 
  int N; cin >> N;
  vector<vector<int>> to(N);
  vector<pair<int,int>> Edges;
  
  for(int i = 1; i < N; i++){
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
    Edges.push_back({a,b});
  }
  
  map<pair<int,int>,int> mp;
  vector<bool> visited(N,false);
  vector<int> parent(N,0);
  int S = 0;
  queue<int> Q; Q.push(0); visited[0] = true;  //0を根とする
  
    while(!Q.empty()){
      int p = Q.front(); Q.pop();
      S = max(S,(int)to[p].size());
      int color = 1;
      for(auto ne : to[p]){
        if(visited[ne]){ continue;}
        
        if(color == parent[p]){ color++;}
        
        parent[ne] = mp[{p,ne}] = mp[{ne,p}] = color++;
        visited[ne] = true;
        Q.push(ne);
      }
    }
  
  cout << S << endl;
  for(auto ne : Edges){ cout << mp[ne] << endl;}
  
  return 0;
}
           
        
  
  

Measured memory_bytes: 19700
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>

int gcm(int a,int b);

int main(){
  ll n,m;
  cin >> n >> m;
  vector<vll> store(n,vll(2));
  rep(i,n){
    cin >> store[i][0] >> store[i][1];
  }
  sort(store.begin(),store.end());
  ll sum = 0;
  ll i = 0;
  while(m != 0){
    if(m > store[i][1]){
      m -= store[i][1];
      sum += store[i][0]*store[i][1];
    }
    else{
      sum += store[i][0]*m;
      m = 0;
    }
    i++;
  }
  cout << sum << endl;
}

int gcm(int a,int b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcm(a%b,b);
}

//i番目までにはいくつ入ってる、っていう配列を作って
//それを参照するようにしたらいけそう

Measured memory_bytes: 5760
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int K = sc.nextInt();
            int[] H = new int[N];
            for (int i = 0; i < N; i++) {
                H[i] = sc.nextInt();
            }

            Arrays.sort(H);

            long sum = 0;
            for (int i = 0; i < N - K; i++) {
                sum += H[i];
            }

            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 50856
import java.util.*;

public class Main {
    static final int SIZE = 40;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		boolean[] base = getArray(k);
		long[] nums = new long[n];
		boolean[][] arrs = new boolean[n][];
		for (int i = 0; i < n; i++) {
		    nums[i] = sc.nextLong();
		    arrs[i] = getArray(nums[i]);
		}
		boolean[] ans = new boolean[SIZE];
		boolean isFirst = true;
		for (int i = SIZE - 1; i >= 0; i--) {
		    if (isFirst && !base[i]) {
		        ans[i] = false;
		    } else {
		        int count = 0;
		        for (int j = 0; j < n; j++) {
		            if (arrs[j][i]) {
		                count++;
		            }
		        }
		        if (count * 2 >= n) {
		            ans[i] = false;
		            if (isFirst && base[i]) {
		                isFirst = false;
		            }
		        } else {
		            ans[i] = true;
		        }
		    }
		}
		long fin = 0;
		for (int i = SIZE - 1; i >= 0; i--) {
		    fin <<= 1;
		    if (ans[i]) {
		        fin++;
		    }
		}
		long total = 0;
		for (long x : nums) {
		    total += (x ^ fin);
		}
		System.out.println(total);
    }
    
    static boolean[] getArray(long x) {
        boolean[] ans = new boolean[SIZE];
        for (int i = 0; i < SIZE; i++) {
            if (x % 2 == 1) {
                ans[i] = true;
            }
            x /= 2;
        }
        return ans;
    }
    
}



Measured memory_bytes: 67316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)



int main(){
   string s,t;
   cin >> s;
   t = "";
   for (int i= 0;i < s.size();i++){
      if (s[i] == '0') t+='0';
      else if (s[i] == '1') t+='1';
      else if (s[i] == 'B'){
         if (t.size() == 0) continue;
         else t.erase(t.size()-1);
      }
   }
   cout << t << endl;
   
   return 0;
}

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

vector<int> sieve_of_eratosthenes(int n) {
	vector<int> primes(n);
	for (int i = 2; i < n; ++i)
		primes[i] = i;
	for (int i = 2; i*i < n; ++i)
		if (primes[i])
			for (int j = i*i; j < n; j+=i)
				primes[j] = 0;

//	primes.erase(remove( primes.begin(), primes.end(),0 ), primes.end() );
	return primes;
}

int main()
{
	vector<int> prime=sieve_of_eratosthenes(200000);
	int N,P;
	while(cin>>N>>P && N>=0){
		vector<int> use;
		for(int i=N+1;i<prime.size();i++){
			if(prime[i]!=0) use.push_back(i);
			if(use.size()>100) break;
		}

		vector<int> L;
		for(int i=0;i<=P;i++){
			for(int j=i;j<=P;j++){
				L.push_back(use[i]+use[j]);
			}
		}
		
		sort(L.begin(),L.end());
		cout<<L[P-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    v = a[i]
    j = i -1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    
    for i in range(n-1):
        print(str(a[i]) + " ", end="")
    print(a[n-1])

Measured memory_bytes: 8060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"


int check = 1000;

ll func(int n, int W, int wt[], ll val[]){
  check--;
  if(n == 0 || check==0){
    return 0;
  }
  if(W < wt[n - 1]){
    return func(n-1, W, wt, val);
  }else{
    return max(func(n-1, W, wt, val), val[n-1] + func(n-1, W - wt[n-1], wt, val));
  }
}

ll func2(int n, int W, int wt[], ll val[]){
  ll t[n+1][W+1];
  // init
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= W; j++){
      if(i == 0 || j == 0){
        t[i][j] = 0;
      }
    }
  }
  // logic
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= W; j++){
      if(j < wt[i-1]){
        t[i][j] = t[i-1][j];
      }else{
        t[i][j] = max(t[i-1][j], val[i-1] + t[i-1][j - wt[i-1]]);
      }
    }
  }

  // for(int i = 0; i <= n; i++){
  //   for(int j = 0; j <= W; j++){
  //     cout << t[i][j] << " ";
  //   }cout << endl;
  // }
  return t[n][W];

}

void solve() {
  int n,W;
  cin >> n >> W;
  int wt[n];
  ll val[n];
  for(int i = 0; i < n; i++){
    cin >> wt[i] >> val[i];
  }
  cout << func2(n, W, wt, val);
}
int main(){
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 82492
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    
    String aStr = sc.next();
    
    char[] aChr = aStr.toCharArray();
    
    aChr[0]++;
    
    System.out.println(aChr[0]);
  }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main (void) {
    int A[90], N, K;
    int i, j, count=0;
    long long maisuu=0, money=1000;
    
    scanf("%d", &N);
    for(i=0; i<N; i++) {
        scanf("%lld", &A[i]);
        
    }
    A[N] = 0;
    
    for(i=0; i<N; i++){
        if(A[i] < A[i+1] && count == 0) { /*買えばいい*/
            
            maisuu = money/A[i];
            money = money % A[i];
            count = 1;
        }
        
        if(A[i] > A[i+1] && count == 1) { /*売ればいい*/
            money += maisuu*A[i];
            maisuu = 0;
            
            
            count = 0;
        }


    }
    
    
    printf("%lld\n",money);
    
    return 0;
}


Measured memory_bytes: 1656
#include <iostream>
using namespace std;
int main(void){
    int n,y;
    cin >> n >> y;
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= n-i;j++){
            int k = n-i-j;
            if(10000*i+5000*j+1000*k == y){
                cout << i << " "<< j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 50005;
const int MAXM = 1e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXM]; bitset <MAXN> a[MAXN];
int n, m, t, x[MAXM], y[MAXM], b[MAXN], c[MAXN];
int main() {
	read(n), read(m), read(t);
	if (t == 1) {
		for (int i = 1; i <= n; i++)
			a[i].set(i);
		for (int i = 1; i <= m; i++) {
			read(x[i]), read(y[i]);
			a[x[i]] = a[y[i]] = a[x[i]] | a[y[i]];
		}
		for (int i = 1; i <= n; i++)
			if (a[i].count() == n) {
				static bool vis[MAXN];
				vis[i] = true;
				for (int i = m; i >= 1; i--) {
					if (vis[x[i]]) {
						s[i] = '^';
						vis[y[i]] = true;
					} else if (vis[y[i]]) {
						s[i] = 'v';
						vis[x[i]] = true;
					} else s[i] = '^';
				}
				printf("%s\n", s + 1);
				return 0;
			}
		puts("-1");
	} else {
		if (n == 2) puts("-1");
		else {
			for (int i = 1; i <= n; i++)
				b[i] = i, c[i] = 1;
			for (int i = 1; i <= m; i++)
				read(x[i]), read(y[i]);
			for (int i = m; i >= 1; i--) {
				if (b[x[i]] == b[y[i]]) s[i] = '^';
				else if (c[b[x[i]]] >= 2) {
					c[b[x[i]]]--;
					b[x[i]] = b[y[i]];
					c[b[x[i]]]++;
					s[i] = 'v';
				} else {
					c[b[y[i]]]--;
					b[y[i]] = b[x[i]];
					c[b[y[i]]]++;
					s[i] = '^';
				}
			}
			printf("%s\n", s + 1);
		}
	}
	return 0;
}


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

typedef long long lint;


int main() {
	lint N,Q;
	cin >> N;
	cin >> Q;

	string S;
	cin >> S;

	vector<lint> l(Q);
	vector<lint> r(Q);
	for (lint i=0; i < Q; i++) {
		cin >> l[i] >> r[i];
	}

	// add: 
	lint sums[N+1] = {};// 0に初期化される？

	lint sum=0;
	for (lint i=1;i<N;i++){
		if (S[i] == 'C' && S[i-1] == 'A'){
			sum ++;
		}
		sums[i] = sum;
	}

	for (lint i = 0; i < Q; i++) {

		cout << sums[r[i]-1] - sums[l[i]-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define mod 1000000007
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi 3.1415926535897932384626433832795
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define lo lower_bound
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
void cp()
{
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); 
    #ifndef ONLINE_JUDGE  
    freopen("input.txt", "r", stdin);  
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    //cp();
    //w(x)
    de(n);
    string s,t;
    cin>>s>>t;
    re(i,n)
    cout<<s.at(i)<<t.at(i);
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
typedef long long ll;
using namespace std;

int main()
{
    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1000000000;
const ll MAX_N = 10001;
const ll MAX_M = 10;
ll A[MAX_M];

ll num(ll a) {
  if(a == 1) return 2;
  if(a == 2) return 5;
  if(a == 3) return 5;
  if(a == 4) return 4;
  if(a == 5) return 5;
  if(a == 6) return 6;
  if(a == 7) return 3;
  if(a == 8) return 7;
  if(a == 9) return 6;
  else return -1;
}

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, M;
  cin >> N >> M;
  for(ll i = 0; i < M; i++) cin >> A[i];
  sort(A, A + M, greater<ll>() );
  
  ll dp[N + 1];
  dp[0] = 0;
  for (ll i = 1; i <= N; i++) {
    ll ans = -INF;
    for(ll j = 0; j < M; j++) {
      if(i - num(A[j]) >= 0) ans = max(ans, dp[i - num(A[j])] + 1);
    }
    dp[i] = ans;
  }

  vector<ll> v;  
  ll n_match = N;
  while(n_match > 0) {
    bool flag = false;
    for(ll j = 0; j < M; j++) {
      if(flag) continue;
      if(n_match - num(A[j]) >= 0) {
	if( dp[n_match - num(A[j])] == dp[n_match] - 1){
	  v.push_back(A[j]);
	  n_match -= num(A[j]);
	  flag = true;
	}
      }
    }
  }

  for (ll i = 0; i < v.size(); i++) cout << v[i];
  cout << endl;
  return 0;
}



Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;


int main(){
   int H,W,h,w;
   cin >> H >> W >> h >> w;
   cout << H*W-h*W-w*H+h*w << endl;
   return 0;
}


Measured memory_bytes: 256