akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;

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

    int H, W, K;

    cin >> H >> W >> K;

    vector<vector<char> > S(H, vector<char>(W));

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> S[i][j];
        }
    }

    int min = H + W;


    for (int bit = 0; bit < (1 << (H - 1)); bit++) {
        vector<int> X;
        for(int i = 0; i < H - 1; i++) {
            if (bit & (1 << i)) {
                X.push_back(i);
            }
        }
        //cerr << X.size();
        vector<int> C(X.size() + 1);
        int count = X.size();
        bool checker = false;
        for(int i = 0; i < W; i++) {
            int n = 0;
            for(int j = 0; j < H; j++) {
                if(S[j][i] == '1') {
                    C[n]++;
                    //cerr << i << " " << j << " " << C[n] << endl;
                    if(C[n] > K) {
                        count++;
                        n = 0;
                        C[0] = 0;
                        for(int k = 0; k < H; k++) {
                            if(S[k][i] == '1') {
                                C[n]++;
                                if(C[n] > K) {
                                    checker = true;
                                    break;
                                }
                            }
                            if(X.size() > 0) {
                                if(k == X[n]) {
                                    n++;
                                    C[n] = 0;
                                }
                            }
                        }
                        break;
                    }
                }
                if(X.size() > 0) {
                    if(j == X[n]) {
                        n++;
                    }
                }
            }
            if(checker) {
                break;
            }
        }
        if(checker) {
            continue;
        }
        if(count < min) {
            min = count;
        }
        //for(int i = 0; i < X.size(); i++) {
          //  cerr << X[i] << " ";
       // }
        //cerr << count << endl;
    }

    cout << min << endl;
}

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

#define REP(i,n) for(int (i)=0; i<(int)(n); i++)

int dp[20010];
int a[10010],b[10010];

int main(void){
	int N,M,ans=1e9;;
	cin >> N >> M;
	for(int i=0; i<M; i++) cin >> a[i] >> b[i];
	dp[0] = 0;
	for(int i=1; i<=N+10005; i++)
	{
		dp[i] = 1e9;
		REP(j,M){
			if (a[j] > i) continue;
			dp[i] = min(dp[i],dp[i-a[j]]+b[j]);
		}
		if(i >= N) ans = min(ans,dp[i]);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 384
M,D=[int(i) for i in input().split(" ")]

retval=0

for i in range(1,M+1):
    for j in range(1,D+1):
        a=j%10
        b=int(j/10)
        if i==a*b and a>1 and b>1:
            retval+=1

print(retval)


Measured memory_bytes: 2940
#include <stdio.h>

int main(void){
        int a, b, c, i, result=0;
        do{
                scanf("%d %d %d", &a, &b, &c);
        }while(a>b);
        for(i=a;i<=b;i++){
                if(c%i==0)
                        result++;
        }
        printf("%d\n", result);
        return 0;
}


Measured memory_bytes: 2072
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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 my_abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int my_abs_B(long long num,long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}



const long long INF = 1LL << 60;

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

    cout << ans << endl;
}

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

void main()
{
    auto lr = readln.split.to!(long[]);
    auto L = lr[0];
    auto R = min(L+2020, lr[1]+1);

    long x = long.max;
    foreach (i; L..R) {
        foreach (j; i+1..R) {
            x = min(x, i*j%2019);
        }
    }
    writeln(x);
}

Measured memory_bytes: 256
N = int(input())
X = [[-1*float("inf"),0]] + [[int(inp),i] for inp,i in zip(input().split(), range(1,N + 1))]

from operator import itemgetter

def main():
    X.sort(key = itemgetter(0))
    med = N // 2
    Ans = [-1]*(N+1)
    for XX,i in zip(X[1:],range(1,N+1)):
        index = XX[1]
        if i <= med:
            Ans[index] = X[med + 1][0]
        else:
            Ans[index] = X[med][0]
    print(*Ans[1:],sep="\n")


if __name__ == "__main__":
    main()


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

int main(){
  string s;
  cin >> s;

  int ans = 700;
  if (s[0] == 'o') ans += 100;
  if (s[1] == 'o') ans += 100;
  if (s[2] == 'o') ans += 100;

  cout << ans << endl;
  return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 1e5 + 5;
int l[maxn], r[maxn];
int n;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> l[i] >> r[i];
    }
    l[n + 1] = 0, r[n + 1] = 0;
    n++;
    sort(l + 1, l + 1 + n);
    sort(r + 1, r + 1 + n);
    ll ans = 0;
    for(int i = 1;i < n + 1 - i;i++){
        ans += max(0, l[n + 1 - i] - r[i]);
    }
    ans = ans * 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env php
<?php

$inputs = [];
while (($item = fgets(STDIN)) !== false) {
    $inputs[] = $item;
}

$map = [
    'A' => 'T',
    'T' => 'A',
    'C' => 'G',
    'G' => 'C',
];
$x = trim(array_shift($inputs));
echo $map[$x].PHP_EOL;


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

#define int long long

#define pii pair<int, int>

#define x1 x1228
#define y1 y1228

#define left left228
#define right right228

#define pb push_back
#define eb emplace_back

#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   

#define matr vector<vector<int> > 

#define all(x) x.begin(), x.end()


using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 998244353, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18;
mt19937 rnd(time(0));
int n, m, q; 
struct edge {
    int a, b, c; 
};

vector<edge> e;
int pr[maxn];
int siz[maxn];

int get(int a) {
    if (pr[a] == a) return a; 
    return pr[a] = get(pr[a]); 
} 

int ctr; 
bool unite(int a, int b) {
    a = get(a); 
    b = get(b); 
    if (a == b) return 0;
    if (siz[a] > siz[b]) swap(a, b);
    pr[a] = b;
    siz[b] += siz[a];
    return 1;  
}
  
void solve() {        
    cin >> n >> m >> q;
    ctr = n;  
    for (int i = 0; i < n; ++i) {
        pr[i] = i; 
        siz[i] = 1; 
    }
    set<pair<pii, int> > kek;
    for (int i = 0; i < q; ++i) {
        int a, b, c; cin >> a >> b >> c; 
        if (a > b) swap(a, b); 
        kek.insert(mp(mp(a, b), c)); 
    }
    for (auto v : kek) {
        e.pb({v.ff.ff, v.ff.ss, v.ss}); 
    }
    for (auto v : e) {
        if (v.c == 0) {
            int t = unite(v.a, v.b); 
            ctr -= t; 
        }
    } 
    set<pii> ms; 
    int ptr = 0; 
    for (auto v : e) {
        if (v.c == 1) {
            ptr++; 
            int a = get(v.a); 
            int b = get(v.b); 
            if (a == b) {
                cout << "No" ; 
                return;             
            }
            if (a > b) swap(a, b); 
            ms.insert(mp(a, b)); 
        }
    }
    if (ctr == 2) {
        if (ptr) cout << "No"; 
        else cout << "Yes";
        return;  
    }          
    if (m == n - 1) {
        if (ptr) cout << "No";
        else cout << "Yes";
        return;   
    }
    if (m <= ctr * (ctr - 1) / 2 + n - ctr) {
        cout << "Yes"; 
        return; 
    }
    cout << "No";     
}                                 
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 18672
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;

int main() {
    int n,x;
    while (true) {
        int cnt = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (j < x - i - j && x - i - j <= n) {
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3132
def nCr(n, r):
	global fact, inv, MOD
	return (fact[n] * inv[n-r] * inv[r]) % MOD

MOD = 1000000007
MAX = 200001

h, w, a, b = map(int, input().split())

fact = [1 for i in range(MAX)]
inv = [1 for i in range(MAX)]

for i in range(1, MAX):
	fact[i] = (fact[i-1] * i) % MOD
	inv[i] = pow(fact[i], MOD-2, MOD)

ans = 0
for i in range(h - a):
	t = nCr(b-1+i, b-1) * nCr(w-1-b + h-1-i, w-1-b)
	ans = (ans + t) % MOD

print(ans)

Measured memory_bytes: 55372
#include<stdio.h>
#include<stdlib.h>
#define LINE_BUF_SIZE 1024

int main() {
  char line[LINE_BUF_SIZE];
  int a, b;
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d %d", &a, &b);
        if (a < 9 && b < 9) {
                printf("Yay!");
        } else {
                printf(":(");
        }
  return 0;
}

Measured memory_bytes: 128
/*Author : Hrishi*/

/*When I wrote this, only God and I understood what I was doing.
Now, only God knows.*/

#include <bits/stdc++.h>

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define ff first
#define ss second
#define PB push_back
#define F(i,L,R) for(auto i=L; i<R ;i++)
#define FR(i,R,L) for(auto i=R;i>L;i--)
#define all(x) (x).begin(),(x).end()
#define show(x) cout<<(#x)<<" = "<<(x)<<"\n";
#define show2(x,y) cout<<(#x)<<" = "<<(x)<<" & "<<(#y)<<" = "<<(y)<<"\n";
#define show3(x,y,z) cout<<(#x)<<" = "<<(x)<<" & "<<(#y)<<" = "<<(y)<<" & "<<(#z)<<" = "<<(z)<<"\n";
#define endln "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define M 1000000007
#define INT_MAX 2147483647

using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE

	fastio;
    int t;
    cin>>t;
    if(t>=30)
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 3636
#include<stdio.h>
#include<queue>
#include<iostream>
using namespace std;
int n,m;
int map[505][505];
int v[505][505];
struct o{
	int x,y,p,q;
}w[100000];
int main(){
	scanf("%d%d",&n,&m);
	int top=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&map[i][j]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(map[i][j]%2&&v[i][j]==0){
				v[i][j]=1;
				map[i][j]-=1;
				if(map[i+1][j]%2&&(i+1)<=n){
				map[i+1][j]+=1;
				w[top].x=i,w[top].y=j,w[top].p=i+1,w[top++].q=j;	
				}
				else if(map[i-1][j]%2&&(i-1)>=1){
					map[i-1][j]+=1;
					w[top].x=i,w[top].y=j,w[top].p=i-1,w[top++].q=j;
				}
				else if(map[i][j+1]%2&&(j+1)<=m){
					map[i][j+1]+=1;
					w[top].x=i,w[top].y=j,w[top].p=i,w[top++].q=j+1;
				}
				else if(map[i][j-1]%2&&(j-1)>=1){
					map[i][j+1]+=1;
					w[top].x=i,w[top].y=j,w[top].p=i,w[top++].q=j-1;
				}
				else if((i+1)<=n){
					map[i+1][j]+=1;
					w[top].x=i,w[top].y=j,w[top].p=i+1,w[top++].q=j;
				}
				else if((j+1)<=m){
					map[i][j+1]+=1;
					w[top].x=i,w[top].y=j,w[top].p=i,w[top++].q=j+1;
				}
			}
		}
	}
	printf("%d\n",top);
	for(int i=0;i<top;i++){
		printf("%d %d %d %d\n",w[i].x,w[i].y,w[i].p,w[i].q);
	}
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,M,ct[MAXN],cnt[MAXN];
void Solve() {
    read(N);read(M);
    for(int i = 1 ; i <= N ; ++i) cnt[i] = 1;
    ct[1] = 1;
    int x,y;
    for(int i = 1 ; i <= M ; ++i) {
	read(x);read(y);
	cnt[x]--;cnt[y]++;
	if(ct[x]) {
	    ct[y] = 1;
	}
	if(cnt[x] == 0) ct[x] = 0;
    }
    int ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
	ans += ct[i];
    }
    out(ans);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ss              second
#define ar              array
#define int             long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}
// int JUDGE_ONLINE = 1;
// if (fopen("ip1.txt", "r")) {
// 	JUDGE_ONLINE = 0;
// 	assert(freopen("ip1.txt", "r", stdin));
// 	assert(freopen("op1.txt", "w", stdout));
// }

// if (!JUDGE_ONLINE) {
// 	cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
// }
int ai(char c)
{
	return (c - '0');
}
int32_t main()
{
	k_007();
	int n;
	long double d;
	cin >> n >> d;
	int ans = 0;
	f(i, n)
	{
		int x, y;
		cin >> x >> y;
		long double a = (x * x) + (y * y);
		long double dist = sqrt(a);
		if (dist <= d)
		{
			++ans;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 3636
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
string s;
int main() {
	cin >> s;
	int ret = 1012345678;
	for (char c = 'a'; c <= 'z'; c++) {
		vector<int> v = { -1, (int)(s.size()) };
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == c) v.push_back(i);
		}
		sort(v.begin(), v.end());
		int res = 0;
		for (int i = 1; i < v.size(); i++) {
			res = max(res, v[i] - v[i - 1] - 1);
		}
		ret = min(ret, res);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
let [| N; K |] = stdin.ReadLine().Split() |> Array.map int
let A = stdin.ReadLine().Split() |> Array.map int

[| K..(N - 1) |]
|> Array.map (fun x ->
    if A.[x - K] < A.[x] then "Yes"
    else "No")
|> Array.iter stdout.WriteLine


Measured memory_bytes: 51428
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int R;
  cin >> R;
  if(R < 1200)
    cout << "ABC" << endl;
  else if(R < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	n := len(s)
	for i := 0; i < n-1; i++ {
		if s[i] == s[i+1] {
			fmt.Println(i+1, i+2)
			return
		}

		if i+2 < n && s[i] == s[i+2] {
			fmt.Println(i+1, i+3)
			return
		}
	}

	fmt.Println(-1, -1)
}


Measured memory_bytes: 1280
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;

const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=5000+10,maxn=100000+10,inf=0x3f3f3f3f;

ll dp[N][N],a[N];
int b[N][210];
int st[N],top,l[N],r[N];
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for(int i=2;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1];
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&b[i][j]);
    for(int i=1;i<=m;i++)
    {
        top=0;
        for(int j=1;j<=n;j++)
        {
            while(top&&b[j][i]>=b[st[top]][i])r[st[top--]]=j;
            st[++top]=j;
        }
        while(top)r[st[top--]]=n+1;
        for(int j=n;j>=1;j--)
        {
            while(top&&b[j][i]>b[st[top]][i])l[st[top--]]=j;
            st[++top]=j;
        }
        while(top)l[st[top--]]=0;
        for(int j=1;j<=n;j++)
        {
            dp[l[j]+1][j]+=b[j][i],dp[j+1][r[j]]+=b[j][i];
            dp[l[j]+1][r[j]]-=b[j][i],dp[j+1][j]-=b[j][i];
        }
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
        dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
    ll ans=0;
    for(int i=1;i<=n;i++)for(int j=i;j<=n;j++)ans=max(ans,dp[i][j]-a[j]+a[i]);
    printf("%lld\n",ans);
    return 0;
}
/********************

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


Measured memory_bytes: 200192
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

int ans(int n, int k, int m) {
	if(n == 2) {
		return m == 2 ? 1: 2;
	}
	if(n == m) {
		return ans(n-1, k, (k-1)%(n-1) + 1);
	} else {
		return ((ans(n, k, n) + m-1) % n) + 1;
	}
}

void main(){
	while(true) {
		auto nkm = readInts();
		auto n = nkm[0];
		auto k = nkm[1];
		auto m = nkm[2];
		if((n|k|m) == 0) return;

		writeln(ans(n, k, m));
	}
}

Measured memory_bytes: 3408
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize,
        sp: [(chars, u64); n]
    }
    let mut sp_r = sp.into_iter().enumerate().map(|(i, (s,p))| (s, Rev(p), i+1)) .collect::<Vec<_>>();
    sp_r.sort();
    for i in 0..n {
        println!("{}", sp_r[i].2);
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<std::cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> std::cmp::Ordering {
        other.0.cmp(&self.0)
    }
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String item = sc.next();
    if (item.equals("A")) {
        System.out.println("T");
    } else if (item.equals("G")) {
        System.out.println("C");
    } else if (item.equals("T")) {
        System.out.println("A");
    } else if (item.equals("C")) {
        System.out.println("G");
    }
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>

int main() {
  int n, q;
  std::cin >> n >> q;
  std::vector<int> a[n];
  for (int i = 0; i < q; ++i) {
    int c, t;
    std::cin >> c >> t;
    switch (c) {
    case 0:
      int x;
      std::cin >> x;
      a[t].push_back(x);
      break;
    case 1:
      for (size_t i = 0; i < a[t].size(); i++) {
        if (i > 0)
          std::cout << " ";
        std::cout << a[t].at(i);
      }
      std::cout << std::endl;
      break;
    case 2:
      a[t].clear();
      break;
    }
  }
}



Measured memory_bytes: 5800
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
int a[13]; int n, ans = 0;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	rep(i, n - 1)ans += a[i];
	if (a[n - 1] < ans)puts("Yes");
	else puts("No");
	getchar(); getchar(); return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int x[125252];
int sp[125252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",x+i),--x[i];
  int last = -1;
  REP(i,n){
    int nxt;
    if(i==0){
      nxt = 0;
    }else{
      nxt = min(last+2, x[i]);
    }
    x[i] = nxt;
    // DEBUG(nxt);
    last = nxt;
    sp[i] = nxt - i;
    // DEBUG(sp[i]);
  }
  ll ans = 1;
  int r = 0;
  REP(i,n-1){
    while(r<n-1 && sp[r]+i+i>=r)r++;
    ans = ans * (r+1-i) % MOD;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string>
using namespace std;
int N;
void dfs(string s, char mx);
int main(void)
{
	scanf("%d", &N);
	dfs("", 'a');
	return 0;
}
void dfs(string s, char mx)
{
	if (s.length() == N)
		printf("%s\n", s.c_str());
	else
		for (char ch = 'a'; ch <= mx; ch++)
			dfs(s + ch, ch == mx ? mx + 1 : mx);
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using tpl = tuple<int,int,int>;

ll A[7];
ll back[7];

int main(){
    
    for(int i = 0; i < 7; i++){
        cin >> A[i];
        back[i] = A[i];
    }

    ll ans = 0;
    {
        ll cand = 0;
        cand += A[0] / 2 * 2;
        cand += A[1];
        cand += A[3] / 2 * 2;
        cand += A[4] / 2 * 2;
        ans = max(ans, cand);
    }
    {
        ll cand = 0;
        if(A[0] > 0 && A[3] > 0 && A[4] > 0){
            A[0]--;
            A[3]--;
            A[4]--;
            cand+=3;
        }
        cand += A[0] / 2 * 2;
        cand += A[1];
        cand += A[3] / 2 * 2;
        cand += A[4] / 2 * 2;
        ans = max(ans, cand);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int 

//power of 2 ...n&(n-1)==0

int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	 //ll testcase;
	 //cin>>testcase;
	 //for(ll t=0;t<testcase;t++)
	{
		// use long long
		//donot memeset other than 0 or 1 or -1
		//segmentation fault-> check for uninitialized global variable or out of bounds
		//always check for bottle neck (whether original constraints can be reduced by introducing some condition)
		//dont rush to writing code think through the logic	
		//implement dijkstra again ---it is bfs because we vis all the points connected to the current point first
		//from every not visited cell we will update the distances of cell which can be visited
		ll n;
		cin>>n;
		int count=0;
		for(ll i=2;i*i<=n;i++)
		{
			if(n%i==0)
			{
				int what=0;
				while(n%i==0)
				{
					n/=i;
					what++;
				}
				int curr=1;
				while(curr<=what)
				{
					count++;
					what-=curr;
					curr++;
				}
			}
		}
		if(n>1)
		{
			count++;
		}
		cout<<count<<'\n';
	}
	return 0;
}





























































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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll A, B, N; cin >> A >> B >> N;
  ll result = B<=N ? A*(B-1)/B : A*N/B;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
result = [0]*(n+1)
for i in range(n):
  result[i] += min(a[i], b[i])
  if a[i] < b[i]:
    b[i] -= a[i]
    result[i+1] = min(a[i+1], b[i])
    a[i+1] -= result[i+1]
print(sum(result))

Measured memory_bytes: 82020
#include <stdio.h>

int main()
{
    int m,n,i,sum = 0,j;
    int S[10000],Q[500];
    scanf("%d",&m);
    for(i = 0;i < m;i++)
    {
        scanf("%d",&S[i]);
    }
    scanf("%d",&n);
    for(i = 0;i < n;i++)
    {
        scanf("%d",&Q[i]);
    }
    for(i = 0;i < n;i++)
    {
        for(j = 0;j < m;j++)
        {
            if(Q[i]==S[j])
            {
                sum++;
                break;
            }
        }
    }
    printf("%d\n",sum);
}




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

using namespace std;

int n,a[110],x,res;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>x;
    for (int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    res=0;
    for (int i=0;i<n;i++)
        if ((i<n-1 && x>=a[i]) || (i==n-1 && x==a[i])) {
            res++;
            x-=a[i];
        }
    cout<<res<<endl;
}


Measured memory_bytes: 256
n=int(input())
F=[[0]*10 for i in range(n)]
for i in range(n):
  F[i]=list(map(int,input().split()))
P=[[0]*11 for i in range(n)]
for i in range(n):
  P[i]=list(map(int,input().split()))
ans=-10**10
for i in range(1,1024):
  s=format(i,"12b")
  A=[]
  for j in range(10):
    if s[-1-j]=="1":
      A.append(j)
  p=0
  for j in range(n):
    c=sum(F[j][A[k]] for k in range(len(A)))
    p=p+P[j][c]
  if p>ans:
    ans=p
print(ans)

Measured memory_bytes: 3064
def main():
    n = int(input())
    tmp = list(map(int, input().split()))
    a = [[v, i] for i, v in enumerate(tmp)]
    a.sort(reverse=True)
    dp = [[0]*(n+1) for _ in range(n+1)]
    for i in range(n):
        v, idx = a[i]
        for j in range(i+1):
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+v*abs(idx-j))
            dp[i+1][j] = max(dp[i+1][j] , dp[i][j]+v*abs(idx - (n-1-i+j)))
    print(max(dp[n]))

if __name__ == "__main__":
    main()

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

using namespace std;

int main()
{
    int h,w;
    while (true)
    {
        cin>>h>>w;
        if(h==0 && w==0)
        {
            break;
        }
        for(int i=1; i<=h; i++)
        {
            for(int j=1; j<=w; j++)
            {
                if(i==1 || j==1 || i==h || j==w)
                {
                    cout<<"#";
                }
                else
                {
                    cout<<".";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }

    return 0;
}



Measured memory_bytes: 3080
#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

struct proc {
    string name;
    int time;
};

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(5 100
p1 150
p2 80
p3 200
p4 350
p5 20
)");
#endif
    int n, q;
    in >> n >> q;

    queue<proc> q_proc;
    for (int i = 0; i < n; ++i) {
        string name;
        int time;
        in >> name >> time;
        q_proc.push(proc{.name = name, .time = time});
    }

    int elapsed_time = 0;
    while (!q_proc.empty()) {
        auto front = q_proc.front(); q_proc.pop();
        if (front.time <= q) {
            elapsed_time += front.time;
            cout << front.name << " " << elapsed_time << endl;
        } else {
            elapsed_time += q;
            front.time -= q;
            q_proc.push(front);
        }
    }
    return 0;
}


Measured memory_bytes: 6332
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a,b;
int main(){
	scanf("%lld%lld",&a,&b);
    printf("%lld",max(max(a+b,a-b),a*b));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    ll N;
    int A[3], B[3];
    cin >> N;
    for (int i = 0; i < 3; ++i)
        cin >> A[i];
    for (int i = 0; i < 3; ++i)
        cin >> B[i];

    static ll dp[25000000];
    auto calc = [&](int M) -> void {
        memset(dp, 0, sizeof(dp));
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j <= M - A[i]; ++j) {
                dp[j + A[i]] = max(dp[j + A[i]], dp[j]);
                dp[j + A[i]] = max(dp[j + A[i]], dp[j] + B[i] - A[i]);
            }
        }
    };

    calc(N);
    N += dp[N];
    swap(A, B);
    calc(N);
    N += dp[N];

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 198976
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
#include <random>
#include <numeric>

// #include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;

// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

const int maxn = 1e7 + 5;
int isprime[maxn];
int smallestp[maxn];
int numdiv[maxn];
int expp[maxn];

int n;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    numdiv[1] = 1;
    for (int i = 2; i < maxn; i++) {
        isprime[i] = 1;
        smallestp[i] = i;
        numdiv[i] = 2;
        expp[i] = 1;
    }
    for (int i = 2; i < maxn; i++) {
        if (isprime[i]) {
            for (int j = 2 * i; j < maxn; j += i) {
                if (isprime[j]) {
                    isprime[j] = 0;
                    smallestp[j] = i;
                    if ((j / i) % i == 0) {
                        expp[j] = expp[j / i] + 1;
                    } else {
                        expp[j] = 1;
                    }
                    // cout << "j: " << j << ", expp[j]: " << expp[j] << "\n";
                    // numdiv[j] = numdiv[j / i] * (expp[j] + 1) / (expp[j]);
                }
            }
        }
    }

    for (int i = 2; i < maxn; i++) {
        if (!isprime[i]) {
            numdiv[i] = numdiv[i / smallestp[i]] * (expp[i] + 1) / expp[i];
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        // cout << i << ": " << numdiv[i] << "\n";
        ans += i * numdiv[i];
    }
    cout << ans << "\n";

}
/*
    Potential bugs:
    - Not resetting the arrays properly
    - Out of bounds
*/

Measured memory_bytes: 159896
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <numeric>

using namespace std;

typedef pair<long long, long long> pl;

#define ll long long

class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz; 

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};


long long N, M, k, a, b, c, d, e, H, W;
long long A[200000] = {};
long long B[3][100005] = {};
bool f;
bool ff;
string S;
set <long long>sll;
pl buf;
vector <long long>vl;

struct ST
{
	long long group;
	long long rank;
	long long tugi=-1;
	int siro;
};

vector <ST> vst;
ST st[100004];

double fl, fll;


int main() {

	cin >> N >> M;

	UnionFind uf(N);

	for (int i = 0; i < M; i++) {
		cin >> B[0][i] >> B[1][i] >> B[2][i];
		/*if (st[B[0][i]].group != st[B[1][i]].group) {
			st[B[0][i]].group == st[B[1][i]].group;

		}*/

		uf.merge(B[0][i]-1, B[1][i]-1);

	}

	for (int i = 0; i < N; i++) {
		A[uf.root(i)]++;
	}
	a = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] > 0) {
			a++;
		}
	}

	cout << a << endl;
	return 0;

}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;

int main()
{
	ll n, x;
	cin >> n >> x;
	cout << 3LL * n - 3LL * __gcd(n, x);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n,k; cin >>n >>k;
  int a[n]; for(auto &i:a) cin >>i;
  vector<int>dp(n,MOD); dp[0]=0;
  for(int i=0; i<n; i++) for(int j=1; j<=k; j++) if(i+j<n) dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
  cout <<dp[n-1];
return 0;}

Measured memory_bytes: 4064
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{

    static int n;
    static int c;
    static int k;
    static int lef;
    static int rig;
    static String s;
    static String anss;
    static int[] times;
    static long ans;
    static int[] w;
    static int[] ww;
    static boolean[] visit;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        n = sc.nextInt();
        ans = 0;
        String[] st = new String[n];
        long[] m = new long[5];
        for (int i = 0; i < n; i++) {
            st[i] = sc.next();
            if (st[i].charAt(0) == 'M') {
                m[0]++;
            }
            if (st[i].charAt(0) == 'A') {
                m[1]++;
            }
            if (st[i].charAt(0) == 'R') {
                m[2]++;
            }
            if (st[i].charAt(0) == 'C') {
                m[3]++;
            }
            if (st[i].charAt(0) == 'H') {
                m[4]++;
            }
        }

        System.out.println(
            m[0]*m[1]*(m[2]+m[3]+m[4]) + m[0]*m[2]*(m[3]+m[4]) + m[0]*m[3]*m[4]
                +m[1]*m[2]*(m[3]+m[4]) + m[1]*m[3]*m[4] + m[2]*m[3]*m[4]
        );

        
        sc.close();
    }

    public static long gcd(long a, long b) {
        
        if (a < b) {
            long tmpp = a;
            a = b;
            b = tmpp;
        }
        if (b == 0) {
            return a;
        }else{
            return gcd(b, a%b);
        }
    }

    public static long lcm(long a, long b) {
        long gcd = gcd(a,b);
        return a/gcd*b;
    }

    public static void dfs(int placenow) {
        // if went all -> success! 
        // if not went all -> fail...
        
        /*
         dfs
         Go All Place that there is way to and not having been yet. 

         if island 1 is start point, dfs(1);
         if there is way to island 2 and island 3,
         - island 2 changes non-visited -> visited, and dfs(2).
         - island 3 changes non-visited -> visited, and dfs(3).
         

        */

        visit[placenow] = true;
        boolean success = true;
        for (int i = 0; i < n; i++) {
            if (visit[i] == false) { // not go all place
                success = false;
                break;
            }
        }
        if (success) {
            ans++;
            visit[placenow] = false;
            return;
        }

        for (int i = 0; i < n; i++) {
            if (w[i] == placenow && visit[ww[i]] == false ) {
                dfs(ww[i]);
            }else if(ww[i] == placenow && visit[w[i]] == false){
                dfs(w[i]);
            }else{
                continue;
            }
        }
        visit[placenow] = false;
        return;
    }

}



Measured memory_bytes: 52120
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n,r; cin >> n >> r;
	if(n>=10) cout << r << endl;
	else cout << r+100*(10-n) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  map<string,int> mp;
  rep(i,N) {
    string s;
    cin >> s;
    mp[s]++;
  }
  printf("AC x %d\n",mp["AC"]);
  printf("WA x %d\n",mp["WA"]);
  printf("TLE x %d\n",mp["TLE"]);
  printf("RE x %d\n",mp["RE"]);
  return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int>>
#define fin(ar,k,n) for(int i=k;i<n;i++) cin>>ar[i]
#define fout(ar,k,n) for(int i=k;i<n;i++) cout<<ar[i]<<' '
#define all(z) z.begin(),z.end()
#define mcc ((int)1e9+7)
#define mcf 998244353
#define mi map<int,int>
#define mem(a,n) memset(a,n,sizeof(a))
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> fst;

const int N=1e5+7;
int dp[N],ar[N],n,k;

void solve()
{
	dp[0]=0;
    cin>>n>>k;
	fin(ar,0,n);
	for (int i=1;i<n;i++)
	{
		dp[i]=abs(ar[i]-ar[i-1])+dp[i-1];
		for (int j=max(i-k,0);j<i-1;j++)
		{
			dp[i]=min(abs(ar[i]-ar[j])+dp[j],dp[i]);
		}
	}	
	cout<<dp[n-1]<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 1024
#B問題
N,M = map(int,input().split())
A = [int(input()) for i in range(N)]
B = [int(input()) for j in range(M)]
C = [0 for i in range(N)]
for j in range(M):
    b = B[j]
    for i in range(N):
        if A[i] <= b:
            C[i]+=1
            break
            
c = max(C)
print(C.index(c)+1)



Measured memory_bytes: 5628