akhauriyash/Code-Regression huggingface dataset:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]
ans = 0

for i in range(n-1, -1, -1):
	mod = (a[i] + ans) % b[i]
	if mod != 0:
		ans += b[i] - mod

print(ans)

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

int main(){
	int n,t,s,a[3000],b[3000];
	static int dp[3002][3001] = {};
	cin >> n >> t >> s;
	for(int i = 0;i < n;i++) cin >> a[i] >> b[i];
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= s;j++){
			if(j - b[i - 1] >= 0) dp[i][j] = max(dp[i -  1][j],dp[i - 1][j - b[i - 1]] + a[i - 1]);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	for(int i = n;i >= 1;i--){
		for(int j = s + 1;j <= t;j++){
			if(j - b[i - 1] >= s + 1) dp[i][j] = max(dp[i + 1][j],dp[i + 1][j - b[i - 1]] + a[i - 1]);
			else if(j - b[i - 1] == s) dp[i][j] = max(dp[i + 1][j],a[i - 1]);
			else dp[i][j] = dp[i + 1][j];
		}
	}
	int ma = 0;
	for(int i = 0;i <= n;i++){
		ma = max(ma,dp[i][s] + dp[i + 1][t]);
		//for(int j = 0;j <= t;j++) cout << dp[i][j] << " ";
		//cout << endl;
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 38284
package main

import (
        "fmt"
)

func solution(a, v, b, w, t int) string {
        if (v-w)*t >= abs(b-a) {
                return "YES"
        }
        return "NO"
}

func abs(x int) int {
        if x < 0 {
                return -x
        }
        return x
}

func main() {
        var a, v, b, w, t int
        fmt.Scan(&a, &v, &b, &w, &t)
        fmt.Println(solution(a, v, b, w, t))
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

ll fact[1100000];
ll invfact[1100000];
int N = 1000000;
ll inv(ll a) {

	ll res = 1;
	int p = MOD - 2;
	while (p > 0) {
		if ((p & 1 )== 1) { res *= a; res %= MOD; }
		a = a * a % MOD;
		p >>= 1;
	}
	return res;
}

ll combo(int n, int k) {
	ll res = fact[n];
	res *= invfact[k];
	res %= MOD;
	res *= invfact[n - k];
	return res % MOD;
}

void factpre() {
	fact[0] = 1;
	fx(N) {
		fact[x + 1] = fact[x] * (x + 1);
		fact[x + 1] %= MOD;
	}
	invfact[N] = inv(fact[N]);
	for (int x = N - 1; x >= 0; x--) {
		invfact[x] = invfact[x + 1] * (x + 1);
		invfact[x] %= MOD;
	}
}


int main()
{
	int X, Y;
	cin >> X >> Y;
	ll ans = 0;
	factpre();
	fx(X+1) {            // x回1移動
		if ((X-x)%2==0) {
			if (x*2+(X-x)/2==Y) {
				ans += (((fact[x+(X-x)/2]*invfact[x])%MOD)*invfact[(X-x)/2])%MOD;
				ans %= MOD;
			}
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 16640
//  Author : Amit Kumar 

#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define int int64_t

signed main(void){
#ifdef HELL_JUDGE
    freopen("input","r",stdin);
    freopen("output","w",stdout);
    freopen("error","w",stderr);
#endif 
    ios::sync_with_stdio(false); // FLUSH THE STREAM IF USING puts / printf / scanf/
    cin.tie(nullptr);            // DISABLE FOR INTERACTIVE PROBLEMS
    cout.tie(nullptr);           //
#ifdef HELL_JUDGE
    auto INITIAL_TIME = high_resolution_clock::now();
#endif 
    vector<int>v(10040,0);
    for(int i=1;i<=100;++i){
        for(int j=1;j<=100;++j){
            for(int k=1;k<=100;++k){
                int x = (i*i) + (j*j) + (k*k) + (i * j) + (j*k) + (k*i); 
                if(x <= 10000){
                    v[x]++;
                }
            }
        }
    }
    int n; cin >> n; 
    for(int i=1;i<=n;++i){
        cout << v.at(i) << '\n'; 
    }
#ifdef HELL_JUDGE
    auto FINAL_TIME = high_resolution_clock::now();
    cout << "Time : "
         << duration_cast<milliseconds>(FINAL_TIME-INITIAL_TIME).count() 
         << " ms" << '\n'; 
#endif 
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto&i:a) cin>>i;
    ll ans{};
    Fr(i,n-1) ans+=max(a[i],a[i-1])-a[i],chmax(a[i],a[i-1]);
    cout<<ans<<'\n';
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    string s = in(), t = in();

    for (int i = s.length() - t.length(); i >= 0; --i)
    {
        string tmp = s.substr(i, t.length());
        int ok = true;
        rep(j, tmp.size())
        {
            if (tmp[j] == '?')
                continue;
            if (tmp[j] != t[j])
            {
                ok = false;
                break;
            }
        }
        if (ok)
        {
            string ans = s.substr(0, i) + t;
            if (i + t.length() < s.size())
                ans += s.substr(i + t.length());
            rep(j, ans.size())
            {
                if (ans[j] == '?')
                    ans[j] = 'a';
            }
            cout << ans << endl;
            return;
        }
    }
    puts("UNRESTORABLE");
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    vector<int> sum(n + 1, 0);
    rep(i, n) sum[i + 1] = (sum[i] + a[i]) % k;
    map<int, int> mp;
    mp[0]++;
    int ans = 0;
    Rep(i, 1, n + 1)
    {
        if (i - k >= 0)
            mp[sum[i - k]]--;
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << endl;
}

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

int main() {
  vector<int> a(3), b(3), c(3);
  rep(i, 3) scanf("%d", &a[i]);
  rep(i, 3) {
    scanf("%d", &b[i]);
    b[i] -= a[i];
  }
  rep(i, 3) {
    scanf("%d", &c[i]);
    c[i] -= a[i];
  }

  bool ans = true;
  if (b[0] != b[1] || b[1] != b[2] || b[0] != b[2]) ans = false;
  if (c[0] != c[1] || c[1] != c[2] || c[0] != c[2]) ans = false;
  if (ans) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
import * as readline from "readline";

const rl = readline.createInterface({
    input: process.stdin,
});

const lines = [];
rl.on("line", (line) => {
    lines.push(line);
});
rl.on("close", () => {
    main(lines);
});

function main(lines) {
    const [a, b] = lines[0].split(' ').map(n => parseInt(n));
    console.log(Math.max(a+b, a-b, a*b));
}


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

#define pb push_back
#define mp make_pair

bool a[1005][1005];
queue<pair<int, int>> Q1, Q2;
int h,w;

void push_in(int i, int j) {
	if (i > 0 && !a[i-1][j]) {
		Q2.push(mp(i-1, j));  a[i-1][j] = true;
	} if (i < h - 1 && !a[i+1][j]) {
		Q2.push(mp(i+1, j));  a[i+1][j] = true;
	} if (j > 0 && !a[i][j-1]) {
		Q2.push(mp(i, j-1));  a[i][j-1] = true;
	} if (j < w -1 && !a[i][j+1]) {
		Q2.push(mp(i, j+1));  a[i][j+1] = true;
	}
}

int main() {
	cin >> h >> w;
	char t;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> t;
			a[i][j] = (t == '#');
			if (a[i][j]) {
				Q1.push(mp(i, j));
			}
		}
	}

	bool finished = false;
	int count = 0;

	while (!Q1.empty()) {
		int i = Q1.front().first, j = Q1.front().second;
		Q1.pop();

		push_in(i, j);

		if (Q1.empty() && !Q2.empty()) {
			swap(Q1, Q2); 
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 9360
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int H, A;

int main()
{
  scanf( "%d%d", &H, &A );

  printf( "%d\n", (H+A-1)/A );

  return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        
        int N = Integer.parseInt(line);
        Map<String, Integer> map = new HashMap<>();
        long count = 0;
        for (int i = 0; i < N; i++) {
            String input = sc.nextLine();
            char[] chars = input.toCharArray();
            Arrays.sort(chars);
            String sorted = String.valueOf(chars);
            if (map.containsKey(sorted)) {
                count += map.get(sorted);
                map.put(sorted, map.get(sorted) + 1);
            } else {
                map.put(sorted, 1);
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 102756
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int a[10][10];

int f(string s){
    int ret = 0;
    rep(i,s.size()) ret = a[ret][s[i]-'0'];
    return ret;
}

int main(void) {
    int i,j;
    int n = 10000;
    rep(i,10)rep(j,10){
        string s;
        cin >> s;
        a[i][j] = s[0] - '0';
    }
    int ans = 0;
    rep(i,n){
        bool c = false;
        string s = to_string(i) + char(f(to_string(i))+'0');
        while(s.size()<5)s = "0" + s;
        string t = s;
        rep(j,5){
            rep(k,10)if(s[j]-'0' != k){
                t = s;
                t[j] = '0' + k;
                if(f(t)==0)c = true;
            }
        }
        rep(j,4){
            t = s;
            swap(t[j],t[j+1]);
            if(s != t && f(t) == 0)c = true;
        }

        if(c) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3268
#include<stdio.h>

int main(){

    int n,min,max,i;
    long int sum=0;
    int a[10000];

    scanf("%d",&n);

    for(i=0;i<n;i++)
        scanf("%d",&a[i]);

    max=a[0],min=a[0];

    for(i=0;i<n;i++){
        if(max<a[i])
            max=a[i];
        else if(max>a[i] && min>a[i])
            min=a[i];
        sum=sum+a[i];
   }

printf("%d %d %ld\n",min,max,sum);

return 0;

}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pb push_back
#define INF 1e15
int n;
int main(){
	while(1){
		ll lcm[105]={};
	vector<ll> son[105];
	P stick[105];
	bool decide[105]={};
	bool beleft[105]={},beright[105]={};
	scanf("%d",&n);
	if(!n) break;
	for(int q=1;q<=n;q++){
		ll a,b,c,d;
		scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
		if(c){
			son[q].pb(c);
			beleft[q]=true;
		}
		if(d){
			son[q].pb(d);
			beright[q]=true;
		}
		ll rp;
		for(int i=min(a,b);i>=1;i--){
			if(a%i==0 && b%i==0){
				rp=((a/i)+(b/i));
				stick[q]=make_pair(a/i,b/i);
				break;
			}
		}
		lcm[q]=rp;
		if(son[q].size()==0){
			decide[q]=true;
		}
	}
	int last=1;
	while(1){
		bool p=false;
	for(int i=1;i<=n;i++){
		if(son[i].size()!=0 && !decide[i]){
			int cou=0;
			for(int j=0;j<son[i].size();j++){
				if(decide[son[i][j]]){
					cou++;
				}
			}
			if(cou==son[i].size()){
					ll maxi1=0,maxi2=0;
					if(beleft[i]){
						for(int g=min(stick[i].second,lcm[son[i][0]]);g>=1;g--){
							if(stick[i].second%g==0 && lcm[son[i][0]]%g==0){
								maxi1=(lcm[son[i][0]]/g*(stick[i].first+stick[i].second));
								break;
							}
						}
					}
					if(beright[i]){
						for(int g=min(stick[i].first,lcm[son[i][son[i].size()-1]]);g>=1;g--){
							if(stick[i].first%g==0 && lcm[son[i][son[i].size()-1]]%g==0){
								maxi2=lcm[son[i][son[i].size()-1]]/g*(stick[i].first+stick[i].second);
								break;
							}
						}
					}
					if(maxi1 && !maxi2){
						lcm[i]=maxi1;
					}else if(!maxi1 && maxi2){
						lcm[i]=maxi2;
					}else{
						for(int q=min(maxi1,maxi2);q>=1;q--){
							if(maxi1%q==0 && maxi2%q==0){
								lcm[i]=maxi1*maxi2/q;
								break;
							}
						}
					}
					decide[i]=true;
					last=i;
					p=true;
			}
		}
	}
	if(!p){
		break;
	}
	}
	printf("%lld\n",lcm[last]);
}
}

Measured memory_bytes: 1056
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] line = br.readLine().split(" ");
		int x = Integer.parseInt(line[0]);
		int y = Integer.parseInt(line[1]);
		int r;

		while( (r = x % y) != 0 ) {
			x = y;
			y = r;
		}

		System.out.println(y);
	}
}

Measured memory_bytes: 24504
H, N = map(int,input().split())
data = []

for i in range(N):
    data.append([0, 0])
    a, b = map(int,input().split())
    data[i][0] = a
    data[i][1] = b
data.sort(key=lambda x: x[0])
cost = [float("inf")] * (H + data[-1][0])
cost[0] = 0
for i in range(1, H + data[-1][0]):
    for magic in data:
        if i < magic[0]:
            break
        if cost[i] > cost[i - magic[0]] + magic[1]:
            cost[i] = cost[i - magic[0]] + magic[1]
print(min(cost[H:]))

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

int main() {
	int N; cin >> N;
	int h[110];
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	int sum = 0;
	for (int i = 0; i < N-1; i++) {
		if (h[i] < h[i + 1]) {
			sum += h[i + 1] - h[i];
		}
	}
	cout << sum + h[0];
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=200005;
int tot=2;
long long a[N];
struct Node
{
	int op,x,y,k;
};
vector<Node>res;
void _add(int x,int y,int k)
{
	a[k]=a[x]+a[y];
	res.push_back((Node){0,x,y,k});
	return;
}
void _comp(int x,int y,int k)
{
	a[k]=a[x]<a[y];
	res.push_back((Node){1,x,y,k});
	return;
}
int getmin(int x,int y)
{
	int k=++tot;
	_comp(k,x,k);
	_comp(k,y,++tot);
	_add(k,tot,k);
	_add(x,y,tot);
	_comp(k,tot,k);
	return k;
}
int pos2[N];
int get1(int x,int y)
{
	int k=++tot;
	_add(x,y,k);
	_add(k,k,k);
	_comp(x,k,k);
	return k;
}
void get2()
{
	pos2[0]=get1(0,1);
	for(int i=1;i<=30;i++)
	{
		pos2[i]=++tot;
		_add(pos2[i-1],pos2[i-1],pos2[i]);
	}
	return;
}
int Pw(int p,int b)
{
	int r=++tot;
	_add(r,p,r);
	for(int i=1;i<=b;i++)
		_add(r,r,r);
	return r;
}
void divide(vector<int>&res,int p)
{
	int cur=++tot;
	res.resize(61);
	for(int i=30;i>=0;i--)
	{
		int tmp1=++tot;
		_add(cur,pos2[i],tmp1);
		int tmp2=++tot;
		_add(p,pos2[0],tmp2);
		res[i]=++tot;
		_comp(tmp1,tmp2,res[i]);
		_add(cur,Pw(res[i],i),cur);
	}
	return;
}
void mul(const vector<int>&A,const vector<int>&B)
{
	int res=2;
	for(int i=0;i<=30;i++)
		for(int j=0;j<=30;j++)
		{
			int c=getmin(A[i],B[j]);
			_add(res,Pw(c,i+j),res);
		}
	return;
}
int main()
{
	a[0]=2,a[1]=3;
	get2();
	vector<int>A,B;
	divide(A,0);
	divide(B,1);
	mul(A,B);
	printf("%u\n",res.size());
	for(Node u:res)
		if(u.op==0) printf("+ %d %d %d\n",u.x,u.y,u.k);
		else printf("< %d %d %d\n",u.x,u.y,u.k);
	return 0;
}

Measured memory_bytes: 4124
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int gcd(int a,int b){
    if(b==0)
    return a;
    return gcd(b,a%b);
}
int main(){
    int n,x;
    cin>>n>>x;
    set<int>st;
    for(int i=0;i<n;i++)
    {
        int element;
        cin>>element;
        st.insert(element);
    }
    st.insert(x);
    vector<int>v;
    for(auto it=st.begin();it!=st.end();it++){
        v.push_back(*it);
    }
    int result=v[1]-v[0];
    for(int i=0;i<v.size()-1;i++)
    {
        result=gcd(result,v[i+1]-v[i]);
    }
    cout<<result;
}

Measured memory_bytes: 8440
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N, K;
  cin >> N >> K;
  LINT ans=0;
  for(int b = K+1; b<N+1; ++b){
    ans += (N/b)*(b-K);
    if(K) ans += max(0, N%b - K+1);
    else ans += max(0, N%b);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;

    cout << a * b * 1/2 << endl;
    
}


Measured memory_bytes: 256
def check_MM(S_C):
    MM_Check=['01','02','03','04','05','06','07','08','09','10','11','12']    
    if S_C in MM_Check:
        return 1
    else:
        return 0
    
S=input()

S1=S[:2]
S2=S[2:]

S1_Check=check_MM(S1)
S2_Check=check_MM(S2)

if S1_Check== 1:
    if S2_Check== 1:
        out='AMBIGUOUS'
    else:
        out='MMYY'
elif S1_Check== 0:
    if S2_Check== 1:
        out='YYMM'
    else:
        out='NA'
print(out)

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(i, 1, (n))
#define pb push_back
#define f first
#define s second
#define INF 100000000000000000
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<piii> viii;

int main()
{
    FAST_IO;

    ll p, q, r;
    cin >> p >> q >> r;

    ll ans = p+q;
    ans = min(ans, p+r);
    ans = min(ans, q+r);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (true) {
            int height = input.nextInt();
            int width = input.nextInt();
            if(width == 0 || height == 0) break;
            for(int i = 0; i < height;i++){
                for(int j = 0; j < width; j++){
                    if((i == 0 || i == height - 1) || (j == 0 || j == width - 1) ){
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
        
    }
}


Measured memory_bytes: 34456
def bubbleSort(A, n):
    flag = True
    cnt = 0
    while flag:
        flag = False
        for j in range(n - 1, 0, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                cnt += 1
    print(*A)
    print(cnt)

n = int(input())
A = list(map(int, input().split()))
bubbleSort(A, n)



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

using namespace std;

int main (){

  int m, d;
  int day=0;
  
  cin>>m;
  cin>>d;
  
  for(int i=2; i<=m ;i++){
    for(int j=20 ;j<=d;j++){
    	
      
      if((i == ( j / 10 )*( j % 10))&&j % 10 != 1){
        day++;
    	}
    }
  
  }
	cout<<day<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define slld(t) scanf("%lld",&t)
#define plld(t) printf("%lld\n",t)
#define For(i,n) for(ll i=0;i<n;i++)
#define bll __builtin_popcountll
#define speed ios::sync_with_stdio(false); cin.tie(0)



using namespace std;




int main()
{
	speed;
    ll n,w;
    cin>>n>>w;
    ll wei[n+1][100005]={0};
    for(ll i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        for(ll j=0;j<x;j++)
        {
            wei[i][j]=wei[i-1][j];
        }
        for(ll j=x;j<=w;j++)
        {
            wei[i][j]=max(wei[i-1][j],y+wei[i-1][j-x]);
        }
    }
    // for(ll i=0;i<=n;i++)
    // {
    //     for(ll j=0;j<=8;j++)
    //     {
    //         cout<<wei[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    cout<<wei[n][w];
    


    
    

    
    return 0;
           
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int N;
  cin >> N;
  double d = 0;
  rep(i,0,N - 1) {
    double x;
    string s;
    cin >> x >> s;
    if(s == "JPY") d += x;
    else d += x * 380000;
  }
  cout << fixed << setprecision(9) << d << endl;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

int[][52] SS;
dchar[52] CS;

long N = 1000000007;

void main()
{
    auto n = readln.chomp.to!int;
    auto s1 = readln.chomp.to!(dchar[]);
    auto s2 = readln.chomp.to!(dchar[]);

    auto j = 0;
    for (auto i = 0; i < n; ++i) {
        if (s1[i] == s2[i]) {
            if (i == 0) {
                SS[j] = [];
            } else if (s1[i-1] == s2[i-1]) {
                SS[j] = [j-1];
            } else {
                SS[j] = [j-2, j-1];
            }
        } else {
            if (i == 0) {
                SS[j++] = [];
                SS[j] = [j-1];
            } else if (s1[i-1] == s2[i-1]) {
                SS[j] = [j-1];
                ++j;
                SS[j] = [j-2, j-1];
            } else {
                SS[j] = [j-2];
                ++j;
                SS[j] = [j-2, j-1];
            }
            ++i;
        }
        ++j;
    }

    long[immutable(dchar)[]][52] memo;

    long solve(int i) {
        if (i == n) return 1;

        immutable(dchar)[] key;
        foreach (j; (i-2 < 0 ? 0 : i-2)..i) key ~= CS[j];
        if (key in memo[i]) return memo[i][key];

        auto cls = 0b111;
        foreach (j; SS[i]) {
            switch (CS[j]) {
                case 'R':
                    cls &= 0b011;
                    break;
                case 'G':
                    cls &= 0b101;
                    break;
                case 'B':
                    cls &= 0b110;
                    break;
                default:
            }
        }

        long ret;
        if (cls & 0b100) {
            CS[i] = 'R';
            ret = (ret + solve(i+1)) % N;
        }
        if (cls & 0b010) {
            CS[i] = 'G';
            ret = (ret + solve(i+1)) % N;
        }
        if (cls & 0b001) {
            CS[i] = 'B';
            ret = (ret + solve(i+1)) % N;
        }
        return memo[i][key] = ret;
    }

    writeln(solve(0));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  ll H[N];
  rep(i,N) cin >> H[i];
  int A[M],B[M];
  rep(i,M) cin >> A[i] >> B[i];
  vector<vector<ll>> c(N);
  rep(i,M) {
    c[A[i]-1].push_back(H[B[i]-1]);
    c[B[i]-1].push_back(H[A[i]-1]);
  }
  int ans=0;
  rep(i,N) {
    bool f=true;
    rep(j,c[i].size()) {
      if(H[i]<=c[i][j]) f=false;
    }
    if(f) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 10652
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int a, b;
    cin >> a >> b;
    string ans;
    if (a > b) {
        rep(i, a) ans += to_string(b);
    } else {
        rep(i, b) ans += to_string(a);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int dat[64][32];
int main(){
	int n;	cin>>n;
	vector<string> s(n);
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=0;j<s[i].size();j++)	dat[i][s[i][j]-'a']++;
	}
	for(int i=0;i<26;i++){
		char out='a'+i;
		int times=1e9;
		for(int j=0;j<n;j++)	times=min(times,dat[j][i]);
		for(int j=0;j<times;j++)	cout<<out;
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
def resolve():
    K,N = map(int,input().split())
    A = list(map(int,input().split()))

    A.sort()

    x = A[-1] - A[0]
    x = min(x, K - A[1]+A[0])

    for i in range(1,N-1):
        x = min(x, K - A[i+1]+A[i])

    print(x)


    



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 78540
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;


int main(){
  while(true){
    int n,x; cin>>n>>x;
    if(n==0&&x==0) return 0;
    ll count=0;
    rep(i,n)for(int j=i+1;j<n;j++)for(int k=j+1;k<n;k++){
      if(i+j+k+3==x)count++;
    }
    cout<<count<<endl;
  }
}



Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();
        String ans = "";
        while (N != 0) {
            if (N % 2 != 0) {
                N -= 1;
                N /= (-2);
                ans = "1" + ans;
            } else {
                ans = "0" + ans;
                N /= -2;
            }
        }
        if (ans == "") {
            ans = "0";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    set<string> itemset;
    FOR(i, 0, N) {
        string item;
        cin >> item;
        itemset.insert(item);
    }

    cout << itemset.size() << endl;
    return 0;
};


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

int main(void){
  string str, cmd, p;
  int a,b, n;
  
  cin >> str >> n;
  for (int i=0; i<n; i++){
    cin >> cmd >> a >> b;
    if (cmd=="print"){
      cout << str.substr(a, b-a+1) << endl;
    } else if (cmd=="reverse"){
      reverse(str.begin()+a, str.begin()+b+1);
    } else { // (replace)
      cin >> p;
      str.replace(a, b-a+1, p);
    }
 //   cout << str << endl;
  }
  return 0;
}
  
  



Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
bool isprime[MAX_N];
int sum[MAX_N];

int main()
{
	for(int i = 2; i < MAX_N; ++i)
	{
		isprime[i] = true;
		for (int j = 2; j*j <= i; ++j)
		{
			if (i % j == 0) isprime[i] = false;
		}
	}
	sum[1] = 0;
	for (int i = 2; i*2-1 < MAX_N; ++i)
	{
		if (isprime[i*2-1] && isprime[i]) sum[i*2-1] = sum[i*2-3] + 1;
		else sum[i*2-1] = sum[i*2-3];
	}
	int Q;
	cin >> Q;
	rep(i,Q)
	{
		int l,r,ans;
		cin >> l >> r;
		if (l == 1) ans = sum[r];
		else ans = sum[r] - sum[l-2];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
# ABC098C - Attention (ARC098C)
def main():
    n = int(input())
    s = input()
    l, r = 0, s[1:].count("E")  # people needed to change the direction
    cnt = l + r
    for i in range(1, n):
        if s[i - 1] == "W":
            l += 1
        if s[i] == "E":
            r -= 1
        cnt = min(cnt, l + r)
    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3672
N = int(input())
a = list(map(int, input().split()))
ave = sum(a)/N
tmp = float('inf')
ans = 0
for i in range(N-1, -1, -1):
    if abs(a[i] - ave) <= tmp:
        tmp = abs(a[i] - ave)
        ans = i
print(ans)


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

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (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 all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T = int>
T in() {
  T x;
  cin >> x;
  return (x);
}

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

#pragma endregion

int main() {
  int k = in();
  int n = in();
  vector<ll> a(n);
  vector<ll> dist(n);
  rep(i, n) { a[i] = in(); }
  rep(i, n) {
    if (i == 0) {
      dist[0] = a[0] + k - a[n - 1];
    } else {
      dist[i] = a[i] - a[i - 1];
    }
  }
  cout << k - *max_element(all(dist)) << endl;
  return 0;
}


Measured memory_bytes: 3328
<?php

$in = trim(fgets(STDIN));
$item = explode(' ', $in);

$a = $item[0] * $item[2];
$b = $item[0] * $item[3];
$c = $item[1] * $item[2];
$d = $item[1] * $item[3];

echo max($a, $b, $c, $d);


Measured memory_bytes: 16224
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException ‚There is no more input";}else{var returnInput = this.list[this.index++];return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var count = 0;
  for(var i = 1; i < N - 1; i++){
    if((list[i - 1] < list[i] && list[i] < list[i + 1]) || (list[i - 1] > list[i] && list[i] > list[i + 1])){
      count++;
    }
  }
  myout(count);
}


Measured memory_bytes: 30004
n,k,q= map(int,input().split())
a=[0]*q
scr = [k-q]*n
for i in range(q):
  a[i]=int(input())
for s in a:
  scr[s-1] += 1
for s in scr:
  if s>0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 10416
n = input()

if(n == "SUN"):
    print(7)
elif (n == "MON"):
    print(6)
elif (n == "TUE"):
    print(5)
elif (n == "WED"):
    print(4)
elif (n == "THU"):
    print(3)
elif (n == "FRI"):
    print(2)
elif (n == "SAT"):
    print(1)
        


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;
const int maxn = 1e5+4;
int main()
{
    int a[maxn], n, sum = 0;
    scanf("%d", &n);
    n = n*2;
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    sort(a, a+n);
    for(int i = 0; i < n; i++){
        if(i%2 ==0) sum += a[i];
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    char[] S = (scn.nextLine() + "E").toCharArray();

    int[] answer = new int[S.length - 1];
    Arrays.fill(answer, 0);

    char prevChar = S[0];
    int prevBorderInd = 0;
    for (int i = 0; i < S.length; i++) {
      if (S[i] != prevChar) {
        if (S[i] == 'L') {
          if ((i - prevBorderInd) % 2 == 0) {
            answer[i] += (i - prevBorderInd) / 2;
            answer[i - 1] += (i - prevBorderInd) / 2;
          } else {
            answer[i] += (i - prevBorderInd) / 2;
            answer[i - 1] += (i - prevBorderInd) / 2 + 1;
          }
          prevChar = 'L';
        }

        if (S[i] == 'R' || S[i] == 'E') {
          if ((i - prevBorderInd) % 2 == 0) {
            answer[prevBorderInd] += (i - prevBorderInd) / 2;
            answer[prevBorderInd - 1] += (i - prevBorderInd) / 2;
          } else {
            answer[prevBorderInd] += (i - prevBorderInd) / 2 + 1;
            answer[prevBorderInd - 1] += (i - prevBorderInd) / 2;
          }
          prevChar = 'R';
        }
        prevBorderInd = i;

      }

    }
    for (int ans : answer) {
      System.out.printf("%d ", ans);
    }

  }
}

Measured memory_bytes: 66556
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

void solve()
{
    string s;cin>>s;
    int flag=0;
    for(int i=0;i<s.size();i+=2)
    {
        if(s[i]=='L')
        {
            flag=1;
            break;
        }
    }
    for(int i=1;i<s.size();i+=2)
    {
        if(s[i]=='R')
        {
            flag=1;
            break;
        }
    }
    if(flag)
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
}
int32_t main()
{
         rapido;
         int t;
         //cin>>t;
         t=1;
         while(t--)
         solve();
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.rbegin(), t.rend());
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a,b,c,d = gets.split.map(&:to_i)

total = b - a + 1

cf = b / c - (a-1) / c
df = b / d - (a-1) / d
lcm = c.lcm d
lcms = b / lcm - (a-1) / lcm

puts total - cf - df + lcms



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef vector<int> vint;
typedef long long ll;

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

    int k;
    cin >> k;
    string str;
    cin >> str;

    if (str.length() > k)
    {
        cout << str.substr(0, k) << "..." << endl;
    }
    else
    {
        cout << str << endl;
    }

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
//#define   Y            imag()
//#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
//#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<int>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
string s,t;
vector<int> arr[30];

int main()
{
    cin>>s>>t;
    for(int i=0;i<sz(s);i++)
    {
        arr[s[i]-'a'].pb(i);
    }
    ll lst=0;
    int pre=-1;
    for(int i=0;i<sz(t);i++)
    {
        //cout<<pre<<endl;
        auto it=upper_bound(all(arr[t[i]-'a']),pre);
        if(it!=arr[t[i]-'a'].end())
        {
            lst+=((*it)-pre);
            pre=(*it);
        }
        else
        {
            lst+=(sz(s)-1-pre);
            pre=-1;
            auto it2=upper_bound(all(arr[t[i]-'a']),pre);
            if(it2==arr[t[i]-'a'].end())
            {
                cout<<"-1\n";
                return 0;
            }
            else
            {
                pre=(*it2);
                lst+=(pre+1);
            }
        }
    }
    cout<<lst<<endl;
}






















Measured memory_bytes: 1216
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>
#include<math.h>

int max(int a, int b) {
    if(a > b) {
        return a;
    }
    else{
        return b;
    }
}

int main(void){
    int A, B, C, K;
    scanf("%d%d%d", &A, &B, &C);
    scanf("%d", &K);
    int mx = max(max(A, B), C);
    printf("%d\n", (int)pow(2.0, (double)K) * mx + A + B + C - mx);

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i, j, k;
        for(i = 0; ; i++) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 || W == 0) break;
            for(j = 0; j < H; j++) {
                if(j == 0 || j == H - 1) {
                    for(k = 0; k < W; k++) {
                        System.out.print("#");
                    }
                    System.out.println("");
                } else {
                for(k = 0; k < W; k++) {
                    if(k == 0 || k == W - 1) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println("");
            }
        }
        System.out.println("");
    }
}
}





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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 2010
const int MOD = 1000000007;

int dp[maxn][maxn];
pair<int, int> v[maxn];
int n;

int solve(int id, int l, int r) {
    if (id > n)return 0;
    int &ans = dp[l][r];
    if (ans != -1)
        return ans;
    ans = v[id].first * abs(v[id].second - l) + solve(id + 1, l + 1, r);
    ans = max(ans, v[id].first * abs(v[id].second - r) + solve(id + 1, l, r - 1));
    return ans;
}

void solve() {
    memset(dp, -1, sizeof dp);
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cin >> v[i].first;
        v[i].second = i;
    }
    sort(v + 1, v + n + 1);
    reverse(v + 1, v + n + 1);
    cout << solve(1, 1, n) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 35360
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;
const int MAX = 1e5;

int main() {
  int n, c;
  cin >> n >> c;
  vector<int> s(n), t(n), ch(n);
  rep(i, n) cin >> s[i] >> t[i] >> ch[i];

  vector<vector<bool>> a(c, vector<bool>(MAX, false));
  rep(i, n) {
    FOR(j, s[i] - 1, t[i]) {
      a[ch[i] - 1][j] = true;
    }
  }

  int ans = 0;
  rep(j, MAX) {
    int res = 0;
    rep(i, c) {
      if (a[i][j]) res++;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;
//typedef pair<int, int> P;
static const int max_n = 1000001, max_m = 102;
static const int  INF = 1000000000;
int ci;

ll x[max_m];
int main(){
    rep(i, 5) cin >> x[i];
    rep(i, 5){
        if(x[i]==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
long long knapsack(long long n,long long *w,long long *v,long long W){
    long long dp[n+1][W+1];
    memset(dp,0,sizeof(dp));
    for(long long i=1;i<=n;i++){
        for(long long j=1;j<=W;j++){
            if(j-w[i-1]>=0){
                dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    // for(long long i=0;i<=n;i++){
    //     for(long long j=0;j<=W;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    return dp[n][W];
}
int main(){
    long long n,W;
    cin>>n>>W;
    long long w[n];
    long long v[n];
    for(long long i=0;i<n;i++){
      cin>>w[i];
      cin>>v[i];
    }
    // for(long long i=0;i<n;i++){
    //     cout<<w[i]<<" ";
    // }
    cout<<knapsack(n,w,v,W);


    return 0;
}

Measured memory_bytes: 79104