akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

void dfs(int node, vector<int> &ord, vector<bool> &used, vector<vector<int> > &adj){
	if(used[node]) return;
	used[node] = true;
	for(int to: adj[node]){
		dfs(to, ord, used, adj);
	}
	ord.push_back(node);
}

vector<vector<int> > scc_decomposition(vector<vector<int> > &adj){
	int n = adj.size();
	vector<vector<int> > revadj(n);
	for(int i=0; i<n; i++){
		for(int to: adj[i]){
			revadj[to].push_back(i);
		}
	}
	
	vector<bool> used(n, false);
	vector<int> ord;
	for(int i=0; i<n; i++){
		if(used[i]) continue;
		dfs(i, ord, used, adj);
	}
	used = vector<bool>(n, false);
	vector<vector<int> > res;
	for(int i=n-1; i>=0; i--){
		if(used[ord[i]]) continue;
		res.emplace_back();
		dfs(ord[i], res.back(), used, revadj);
		sort(res.back().begin(), res.back().end());
	}
	return res;
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<double> wake(n);
		vector<vector<int> > adj(n);
		for(int i=0; i<n; i++){
			cin >> wake[i];
			int k;
			cin >> k;
			adj[i].resize(k);
			for(int j=0; j<k; j++){
				cin >> adj[i][j];
				adj[i][j]--;
			}
		}
		
		vector<vector<int> > scc = scc_decomposition(adj);
		vector<vector<int> > revadj(n);
		for(int i=0; i<n; i++){
			for(int to: adj[i]){
				revadj[to].push_back(i);
			}
		}
		
		double ans = 1;
		int m = scc.size();
		for(int i=0; i<m; i++){
			bool root = true;
			for(int v: scc[i]){
				for(int s: revadj[v]){
					auto f = lower_bound(scc[i].begin(), scc[i].end(), s);
					if(f == scc[i].end() || *f != s){
						root = false;
					}
				}
			}
			if(!root) continue;
			double w = 1;
			for(int v: scc[i]) w *= wake[v];
			ans *= 1-w;
		}
		cout << fixed;
		cout << setprecision(10);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3376
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
typedef pair<long long,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
long long n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<long long> st;
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<long long,long long> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<long long> sta;   
    //queue<long long> que;


int main(){
	
	long long A,B,C,D,E,F,G,H,I,J,L,N,M,K,O,P,Q,R,S,T,U,V,W,X,Y,Z;
	long long ans;
	ans=0;
	string s;
    long long sum,sum1;
	sum=0;
	sum1=0;
	long long flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	long long max;
	long long max1;
	max=0;
	max1=0;
	long long min;
	long long min1;
	min=INF;
	min1=INF;

	long long work,work1,work2,work3,work4;
	work=0;
	work1=0;
	work2=0;
	work3=0;
	work4=0;
    
	std::cin >> N >> K;
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
    
	std::vector<long long> v(N);
	std::vector<long long> w(N-K+1);
    //std::cin >> s;
    
    
    // 配列入力1
    
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	std::sort(v.begin(),v.end());//昇順ソート
    
	// 配列入力2
	/*
	for(long long i=0; i<N; i++){
		std::cin >> w[i];
	}
	*/
    
	
	//通常
	
    for(long long i=0; i<N-K+1; i++){
		w[i]=v[i+K-1]-v[i];
	}
	std::sort(w.begin(),w.end());//昇順ソート
	

	//文字列入力
	/*
	for(long long i=0; i<s.length(); i++){
		
		if(s[i]!='1'){
	}
	*/

	
	
	//ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    //std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
    /*
    
    //S.substr(i, 5);
    //S.size();
    
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
		if(st.find(v[i])==st.end()){
			st.insert(v[i]);
		}
		else{
			st.erase(v[i]);
		}
	}
	*/


	/*
	long long a[4];
	long long value;
	value=0;
	
	a[0] = (value % 10); 
	value /= 10;// 1桁目を取り出す
	a[1] = (value % 10); 
	value /= 10;// 2桁目を取り出す
	a[2] = (value % 10); 
	value /= 10;// 3桁目を取り出す
	a[3] = (value % 10); 
	value /= 10;// 4桁目を取り出す
    work1=a[0]+10*a[1];
    work2=a[2]+10*a[3];
    */
	
	
    if(1){
    	printf("%lld",w[0]);
    	//printf("%lld",N);
    	//puts("Yes");
    	//printf("%d",st.size());
    	//文字列の出力
    	//std::cout << s << std::endl;
    	//printf("%.12f\n",ret);
    	//cout << sum << endl;
	}
	else{
		//puts("No");
	}
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[2][n];
  int i,j,k;
  int max = 0;
  int tmp;
  for(i=0;i<2;i++){
    for(j=0;j<n;j++){
      cin >> a[i][j];
    }
  }
  for(i=0;i<n;i++){
    tmp = 0;
    for(j=0;j<=i;j++){
      tmp += a[0][j];
    }
    for(j=i;j<n;j++){
      tmp += a[1][j];
    }
    if(tmp > max)max = tmp;
  }

  cout << max;
  

  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

#define mod 1000000007
using namespace std;
typedef long long ll;

const int maxn = 1e8 + 8;
int main()
{
    int n;
    cin>>n;
    char s[105][11];
    int flag=0;
    int flag1=0;
    getchar();
    scanf("%s",s[0]);
    for(int i=1; i<n; i++)
    {
        getchar();
        scanf("%s",s[i]);
    }

    for(int i=0; i<n-1; i++)
    {
        int k=strlen(s[i])-1;
        if(s[i][k]!=s[i+1][0])
        {
            flag=1;
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i==j)
            {
                continue;
            }
            else{
                if(strcmp(s[i],s[j])==0)
                {
                    flag=1;
                }
            }
        }
    }
    if(flag==0&&flag1==0)
    {
        printf("Yes");
    }
    else{
        printf("No");
    }




    return 0;
}





Measured memory_bytes: 256
// id: ALDS1_1_A
#include <stdio.h>

#define MAX_N 100

void print_array(int a[], int n);
void insertion_sort(int a[], int n);

int main(void)
{
	int n;
	int arr[MAX_N];

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

	print_array(arr, n);
	insertion_sort(arr, n);

	return 0;
}

void print_array(int a[], int n)
{
	printf("%d", a[0]);

	for ( int i = 1; i < n; ++i )
		printf(" %d", a[i]);

	printf("\n");
}

void insertion_sort(int a[], int n)
{
	int tmp;
	int j;

	for ( int i = 1; i < n; ++i ) {
		tmp = a[i];

		for ( j = i; j > 0 && a[j - 1] > tmp; --j )
			a[j] = a[j - 1];

		a[j] = tmp;

		print_array(a, n);
	}
}


Measured memory_bytes: 2108
from collections import deque, defaultdict

N = int(input())
A = [deque(map(lambda a: int(a) - 1, input().split())) for _ in range(N)]

D = [0] * N
canBattle = defaultdict(lambda: False)
que = deque(range(N))

while que:
    i = que.popleft()
    j = A[i].popleft()
    canBattle[(i, j)] = True

    if canBattle[(j, i)]:
        day = max(D[i], D[j])
        D[i] = D[j] = day + 1

        if A[i]:
            que.append(i)
        if A[j]:
            que.append(j)

if all(len(a) == 0 for a in A):
    print(max(D))
else:
    print(-1)


Measured memory_bytes: 154196
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	int x, y; cin >> x >> y;
	if(abs(x) == abs(y)) cout << 1 << "\n";
	else if(abs(x) < abs(y)) {
		int cnt = 0;
		if(x < 0) {
			cnt++; x *= -1;
		}
		cnt += abs(y) - abs(x);
		x = abs(y);
		if(x != y) cnt++;
		cout << cnt << "\n";
	}
	else {
		int cnt = 0;
		if(x > 0) {
			cnt++; x *= -1;
		}
		cnt += abs(x) - abs(y);
		x = abs(y) * -1;
		if(x != y) cnt++;
		cout << cnt << "\n";
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[200];
int main() {
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 0 ; i < n ; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if(sum % 10 != 0) cout << sum << endl;
    else {
        int gg = 0;
        for(int i = 0 ; i < n ; i++) {
            if((sum - a[i]) % 10 != 0) {
                gg = max(gg , sum - a[i]);
            }
        }
        cout << gg << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

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()

ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x;}

const int mod = 1000000007;
const int INF = 1001001001;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> key;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        int s = 0;
        rep(j, b) {
            int c;
            cin >> c;
            --c;
            s |= 1 << c;
        }
        key.emplace_back(s, a);
    }

    vector<int> dp(1 << n, INF);
    dp[0] = 0;
    rep(s, 1 << n) {
        rep(i, m) {
            int t = s | key[i].first;
            int cost = dp[s] + key[i].second;
            dp[t] = min(dp[t], cost);
        }
    }

    int ans = dp.back();
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#define read(X) scanf("%d",&X);
#define readLL(X) cin>>X;
#define readN(N,a) for(int i=0;i<N;i++)scanf("%lld",&a[i]);
#define LL long long
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define pii pair<int,int>
using namespace std;
long long N, M;
long long res;
long long wow[100];
void coba(long long a, long long b){
	if (a==1 || b==1) return;
	for (long long i=1;i<a;i++){
		wow[0] = b*i;
		long long c = b/2;
		long long d = b - c;
		wow[1] = c*(a - i);
		wow[2] = d*(a - i);
		sort(wow, wow + 3);
		res = min(res, wow[2] - wow[0]);
	}
}

int main(){
	readLL(N);
	readLL(M);
	res = min(N,M);
	coba(N,M);
	coba(M,N);
	if (N % 3==0 || M%3 == 0) res=0;

	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int H, W, K;
vector<string> fi;

int solve() {
    int res = 1<<29;
    for (int bit = 0; bit < (1<<(H-1)); ++bit) {
        bool gok = true;
        int N = 0;
        vector<int> ord(H, 0);
        for (int i = 0; i < H-1; ++i) {
            if (!(bit & (1<<i))) ord[i+1] = ord[i];
            else ord[i+1] = ord[i]+1, ++N;
        }
        int add = 0;
        vector<int> nums(N+1, 0);
        for (int w = 0; w < W; ++w) {
            vector<int> one(N+1, 0);
            bool ok = true;
            for (int h = 0; h < H; ++h) {
                one[ord[h]] += fi[h][w] - '0';
                nums[ord[h]] += fi[h][w] - '0';
                if (one[ord[h]] > K) gok = false;
                if (nums[ord[h]] > K) ok = false;
            }
            if (!ok) ++add, nums = one;
        }
        if (gok) chmin(res, N + add);
    }
    return res;
}

int main() {
    cin >> H >> W >> K;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int A[2][100];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) cin >> A[i][j];
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			int x = 0;
			if (i > 0) x = max(x, A[i - 1][j]);
			if (j > 0) x = max(x, A[i][j - 1]);
			A[i][j] += x;
		}
	}
	cout << A[1][N - 1] << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 510000;

ll addM(ll a, ll b){
	return (a + b) % MOD;
}

ll mulM(ll a, ll b){
	ll temp = ((a % MOD) * (b % MOD)) % MOD;
  	return temp;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a % MOD;
  	else if(b%2==0) return mulM(powM(a, b/2), powM(a, b/2));
  	else return mulM(a, mulM(powM(a, (b-1)/2), powM(a, (b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a, powM(b, MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/
void Main() {
    string s; cin >> s;
    reverse(all(s));
    
    int n = s.size();
    
    vi dp(13, 0);
    dp[0] = 1;
    
    int tenpow = 1;
    rep(i, n){
        vi p(13, 0);
        swap(p, dp);
        if(s[i] == '?'){
            rep(nn, 10){
                int now = (nn * tenpow) % 13;                
                rep(j, 13){
                    dp[(j+now) % 13] = addM(dp[(j+now) % 13], p[j]);
                }
            }
        }else{
            int now = s[i] - '0';
            now = (now * tenpow) % 13;
            rep(j, 13){
                dp[(j+now) % 13] = addM(dp[(j+now) % 13], p[j]);
            }
        }
        /*
        cout << i << " " << tenpow << " " << s[i] << ": ";
        rep(j, 13) cout << dp[j] << " ";
        cout << endl;
        */
        tenpow = (tenpow * 10) % 13;
    }
    
    cout << dp[5] << endl;
}

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

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] m = new int[N];
		for(int i = 0;i < N;++i)
			m[i] = sc.nextInt();
		sc.close();
		
		int res = X;
		int ans = N;
		Arrays.sort(m);
		for(int i = 0;i < N;++i)
			res -= m[i];
		ans += res / m[0];
		System.out.println(ans);
	}
}


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

using ll = long long int;
const int maxn = 100000 + 5;
struct T
{
	ll price;
	ll num;
};
ll N, M;
T mem[maxn];

int cmp(T &a , T &b)
{
	return a.price < b.price;
}

ll solve()
{
	sort(mem, mem+N, cmp);
	//for(int i = 0; i < N; i++) printf("%lf ", mem[i].price); printf("\n");
	ll total = 0;
	for(int i = 0; i < N & M > 0; i++)
	{
		if(M >= mem[i].num) 
		{
			total += mem[i].price * mem[i].num;
			M -= mem[i].num;
		}
		else 
		{
			total += mem[i].price * M;
			M = 0;
		}
	}
	return total;
}

int main()
{
	cin >> N >> M;
	for(int i = 0; i < N; i++)
	{
		cin >> mem[i].price;
		cin >> mem[i].num;
	}
	printf("%lld\n", solve());
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
#define eps 1e-7
#define maxi 100005
long long  h[maxi];
long long hi[maxi];
long long  n,a,b;
long long in=10000000000;
bool C(long long  x)
{
    long long t=x;
    for(long long i=0; i<n; i++)
        hi[i]=h[i];
    for(long long i=0; i<n; i++)
    {
        hi[i]-=x*b;
        if(hi[i]<=0) continue;
        long long y;
        if(hi[i]%(a-b)==0)
            y=hi[i]/(a-b);
        else
            y=hi[i]/(a-b)+1;
        t-=y;
    }
    if(t>=0) return true;
    return false;
}
void solve()
{
    sort(h,h+n);
    long long  lb=0,ub=in;
    while(ub-lb>1)
    {
        long long mid=(lb+ub)/2;
        if(C(mid)) ub=mid;
        else  lb=mid;
    }
    cout<<ub<<endl;
}
int main()
{
    while(cin>>n>>a>>b)
    {
        for(int i=0; i<n; i++)  scanf("%d",&h[i]);
    solve();
    }
    return 0;
}


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

int N ;
int table[] = {0,1,2,3,5,7,8,9} ;

void Solve( int x ){
	if( x >= 8 ) Solve( x/8 ) ;
	cout << table[ x%8 ] ;
}

int main(){
	
	while( cin >> N , N ){
		Solve( N ) ;
		cout << endl ;
	}
	
	return 0 ;
}

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

int main(){
    ll n,a[100009],dp[100009],k;
    cin >> n ;
    k=2;
    for(int i=1; i<=n; i++)cin >> a[i];
    dp[n]=0;
    for(int i=n-1; i>=1; i--){
        ll z=1e15;
        for(int j=1; j<=k && i+j<=n; j++){
        	z=min(z,dp[i+j]+abs(a[i]-a[i+j]));
        }
        dp[i]=z;
    }
    cout << dp[1] << endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() 
{
 
	ll n,s=0,k;
	cin>>n>>k;
	ll h[n];
	for(ll i=0;i<n;i++)
	{
	    cin>>h[i];
	   
	}
ll	dp[n+1];
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	ll m=INT_MAX;
	for(ll i=2;i<n;i++)
	{
	    m=INT_MAX;
	    for(ll j=1;j<=k && j<=i;j++)
	    {
	        m=min(m,dp[i-j]+abs(h[i]-h[i-j]));
	    }
	    dp[i]=m;
	    
	}
	cout<<dp[n-1]<<endl;
}



Measured memory_bytes: 1792
import java.util.*;

class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        list.sort(Comparator.naturalOrder());
        int half = n/2-1;
        int result = 0;
        if (list.get(half).equals(list.get(half+1))) {
            System.out.println(result);
            return;
        }
        result = list.get(half+1) - list.get(half);
        System.out.println(result);
    }
}

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

long long int s, w;

void solve() {
	cin >> s >> w;
	if (w >= s)
		cout << "unsafe";
	else
		cout << "safe";
}

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

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	return 0;
}

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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int count=0;
    for(int i=0;i<=100;i++){
        if(i>=a&&i<=b&&i>=c&&i<=d){
            count++;
        }
    }
    if(count>0){
        cout << count-1 << endl;
    }
    else cout << 0 << endl;
}

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

int main()
{
    int n,m;
    char C[20];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        scanf("%s",C);
        int f=1;
        for (int i=0;i<n;i++)
            if (!(C[i]>='0'&&C[i]<='9')) f=0;
        if (C[n]!='-') f=0;
        for (int i=n+1;i<n+m+1;i++)
            if (!(C[i]>='0'&&C[i]<='9')) f=0;
        if (f==0) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long int
long long  INF=1e9+5;

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; string s; cin >> n >> s;
    ll ans = 0, x = 0;
    rep(i, n){
        (s[i] == 'I') ? x++ : x--;
        chmax(ans, x);
    }
    cout << ans << endl;
}

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

int findDigits(int n) {
  int cnt = 0;
  int kaibun[5];
  rep(i, 5) {
    kaibun[i] = n % 10;
    n /= 10;
  }
  if (kaibun[0] == kaibun[4] && kaibun[1] == kaibun[3]) cnt++;

  return cnt;
}

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;

  for (int i = a; i <= b; i++) {
    ans += findDigits(i);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
 
int main(void){
    int i,j,k,n,a,b,dice[7],
        side[5] = {2,3,5,4,2};
    char order[7][3] = {"","","N","W","E","S","NN"};
     
    for(i=1;i<7;i++)
        scanf("%d", &dice[i]);
     
    scanf("%d", &n);
     
  //上面を合わせる
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
     
        for(j=1;dice[j]!=a;j++);
         
       //回転  
     
        for(k=0;order[j][k]!='\0';k++){
         
            dice[0] = dice[1];
         
            switch(order[j][k]){
                 
                case 'E':
                    dice[1] = dice[4];
                    dice[4] = dice[6];
                    dice[6] = dice[3];
                    dice[3] = dice[0]; 
                    break;
             
                case 'N':
                    dice[1] = dice[2];
                    dice[2] = dice[6];
                    dice[6] = dice[5];
                    dice[5] = dice[0]; 
                    break;
             
                case 'S':
                    dice[1] = dice[5];
                    dice[5] = dice[6];
                    dice[6] = dice[2];
                    dice[2] = dice[0]; 
                    break;
                 
                case 'W':
                    dice[1] = dice[3];
                    dice[3] = dice[6];
                    dice[6] = dice[4];
                    dice[4] = dice[0]; 
                    break;
 
            }
        }
         
        for(j=0;b!=dice[side[j]];j++);
         
        printf("%d\n",dice[side[j+1]]);
         
    }
     
    return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int h[N];
int dp[N];
int n, k;

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; i ++) {
        cin >> h[i];
    }
    dp[0] = 0x3f3f3f3f;
    for(int i = 2; i <= n; i ++) {
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        for(int j = 1; j <= k && i - j >= 1; j ++){
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

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

int main(){
	long long A,B,C,K;
	cin>>A>>B>>C>>K;
	long long M=max(A,B);
	M=max(M,C);
	int rem=A+B+C-M;
	long long ans=0;
	REP(i,K){
		M=M*2;
	}
	ans=M+rem;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_V 100000
#define MAX_LOG_V 30
using namespace std;
vector<int> G[MAX_V];  //??°???????????£??\??????????????¨???
int root;              //?????????????????????

int parent[MAX_LOG_V][MAX_V];//??????2^k????????£?????°???????????????(???????????????????????´??????-1??¨??????)
int depth[MAX_V];            //??????????????±???

void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0;i<G[v].size();i++)
    if(G[v][i] != p)dfs(G[v][i],v,d+1);
}

//?????????
void init(int V){
  //parent[0]??¨depth?????????????????????
  dfs(root,-1,0);
  //parent??????????????????
  for(int k=0; k+1<MAX_LOG_V ;k++)
    for(int v=0; v<V ;v++)
      if(parent[k][v] < 0)parent[k+1][v] = -1;
      else parent[k+1][v] = parent[k][parent[k][v]];
}

//u??¨v???LCA????±???????
int lca(int u,int v){
  //u??¨v?????±??????????????????????????§????????????
  if(depth[u]>depth[v]) swap(u,v);
  
  for(int k=0; k<MAX_LOG_V ;k++)
    if((depth[v]-depth[u])>>k&1)v=parent[k][v];
  
  if(u==v) return u;
  //????????¢?´¢??§LCA????±???????
  for(int k=MAX_LOG_V-1; k>=0 ;k--)
    if(parent[k][u] != parent[k][v]){
      u=parent[k][u];
      v=parent[k][v];
    }
  return parent[0][u];
}

int main(){
  root=0;
  int V;
  cin>>V;
  for(int i=0;i<V;i++){
    int k;
    cin>>k;
    for(int j=0,a;j<k;j++)cin>>a,G[i].push_back(a);
  }
  init(V);

  int q;
  cin>>q;
  while(q--){
    int u,v;
    cin>>u>>v;
    cout << lca(u,v)<<endl;
  }

  
  return 0;
}

Measured memory_bytes: 25324
#include <iostream>
#include <stdio.h>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;

char abcd[4] = {'0'};
char op[3] = {'+'};
char ans[10];

int atoi(char s){
    return s-'0'; 
}

int dfs(int num){
    if(num == 3){
	//judge
	int tmp = atoi(abcd[0]);
	for(int i = 1; i <= 3; i++){
	    (op[i-1] == '+')?tmp+=atoi(abcd[i]):tmp-=atoi(abcd[i]);
	}
	if(tmp == 7){
	    ans[1] = op[0];
	    ans[3] = op[1];
	    ans[5] = op[2];
	}
    }else{
	op[num] = '+';	dfs(num+1);
	op[num] = '-';	dfs(num+1);
    }
}

int main(){
    /*input*/
    rep(i, 4){
	cin >> abcd[i];
	ans[i*2] = abcd[i];
    }
    /*calculation*/
    ans[7] = '=';
    ans[8] = '7';
    ans[9] = '\0';
    dfs(0);
    /*output*/
    rep(i, 9){
	printf("%c", ans[i]);
    }
    printf("\n");
}


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

int main() {
    int N;
    int A[210];

    cin >> N;

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

    int cnt = 0;
    bool flag = true;

    while (flag) {
        for (int i=0; i<N; i++) {
            if (A[i] % 2 == 0 ) {
                A[i] = A[i] / 2;
            } else {
                flag = false;
                break;
            }
        }

        if (flag) {
            cnt++;
        }

    }
    cout << cnt << endl;

}

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

void solve() {
	char s1[3],s2[3];
	cin >> s1[0] >> s1[1];
	cin >> s2[0] >> s2[1];
	s1[2] = '\0';
	s2[2] = '\0';

	int n1 = atoi(s1);
	int n2 = atoi(s2);

	bool yymm = false, mmyy = false;
	if (n2 >= 1 && n2 <= 12) {
		yymm = true;
	}

	if (n1 >= 1 && n1 <= 12) {
		mmyy = true;
	}

	if (yymm && mmyy) {
		cout << "AMBIGUOUS\n";
	} else if (yymm) {
		cout << "YYMM\n";
	} else if (mmyy) {
		cout << "MMYY\n";
	} else {
		cout << "NA\n";
	}
}


/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
const int INF = 999999999;
using namespace std;
int check(int n, int x, int a[100], int b[100], int va[100], int vb[100]) {
	queue<int> q;
	if(x < 100) {
		if(a[x]==1) {
			while(a[++x]==1) {}
			x--;
		} else if(a[x]==2) {
			return INF;
		}
		q.push(x);
		va[x] = 0;
	} else {
		x-=100;
		if(b[x]==1) {
			while(b[++x]==1) {}
			x--;
		} else if(b[x]==2) {
			return INF;
		}
		q.push(x+100);
		vb[x] = 0;
	}
	while(!q.empty()) {
		int t = q.front();
		
		if(t== n-1 || t == n+99) break;
		q.pop();
		if(t < 100) {
			int cnt = va[t];
			rep(i,3) {
				int c = t+i;
				if(c>=n) break;
				if(b[c]==1) {
					while(b[++c]==1) {}
					c--;
				} else if(b[c]==2) {
					while(b[--c]==2) {}
				}
		
				if(vb[c] == -1) {
					vb[c] = cnt+1;
					q.push(c+100);
				}
			}
		} else {
			t -= 100;
			int cnt = vb[t];
			rep(i,3) {
				int c = t+i;
				if(c>=n) break;
				if(a[c]==1) {
					while(a[++c]==1) {}
					c--;
				} else if(a[c]==2) {
					while(a[--c]==2) {}
				}
				
				if(va[c] == -1) {
					va[c] = cnt+1;
					q.push(c);
				}
			}
		}
	}
	if(q.empty()) {
	
		return INF;
	} else {
		if(q.front() < 100) return va[q.front()];
		else return vb[q.front()-100];
	}
}
int main(){
	int n;
	while(cin >> n, n) {
		int a[110] = {}, b[110] = {};
		int va[100], vb[100];
		rep(i,100) {
			va[i] = vb[i] = -1;
		}
		rep(i,n) {
			cin >> a[i];
		}
		rep(i,n) {
			cin >> b[i];
		}
		int ret1 = check(n,0,a,b,va,vb);
		rep(i,100) {
			va[i] = vb[i] = -1;
		}
		int ret2 = check(n,100,a,b,va,vb);
		int ret = min(ret1, ret2);
		if(ret == INF) cout <<"NA" << endl;
		else cout << ret << endl;
	}
}

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

#define endl '\n'
#define rep(n)      for (int i = 0 ; i < n ; i++)
#define all(a)      a.begin(),a.end()
#define NumofDigits(n)    ((long long)log10(n)+1)
#define Unique(n)         (n).erase(unique(all(n)), (n).end())



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

void readFromText ()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
}

void time()
{
#ifndef ONLINE_JUDGE
    cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}

const double Pi = acos(-1.0);
const int MAX = 1e5 ;
bool on [MAX+1];


int main()
{
    quick();
//    readFromText();
    long long x ; cin >> x; long long start = 100 , counter = 0 ;
    while (start<x){
        start+=(start/100);
        counter++;
    }
    cout << counter ;
    return 0;
}

unsigned long long pow(long long base, long long power){
    if(power==0)
        return 1;
    if(power==1)
        return base;
    unsigned long long ans = pow(base, power/2);
    ans *= ans;

    if(power&1)
        return ans*base;
    return ans;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  double sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    double a;
    cin>>a>>s;
    if(s=="JPY")sum+=a;
    else{
      sum+=a*380000;
    }
  }
  printf("%f\n",sum);
  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}

ll getdigit(ll n){
	string s=to_string(n);
	return s.size();
}
	
int main(){
	init();
	ll a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b){
		cout<<"YES"<<endl;
	}else cout<<"NO"<<endl;
}


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

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

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

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

int main(){
    int n,k;
    cin >> n >> k;
    ll cnt = 0;
    vector<ll> dp(n+2,0);
    vector<ll> dp_f(n+2,0);
    vector<ll> dp_b(n+2,0);
    dp[0] = 0;
    dp[0] = 1;
    for(ll i = 0; i < n+1 ; i++ ){
        if ( i == 0) continue;
        dp_f[i] = (0+(i-1))/2 * i ;
        dp_b[i] = (n+ n-(i-1) )/2 * i ;                     
    }
    for(int i = k;i<n+2;i++){
        dp[i] = dp_b[i]-dp_f[i]+1;
        //if (i > n){
        //    dp[i][1] = 0;
        //}else{
        //    dp[i][1] = (dp_b[i] - max(dp_f[i],dp_b[i-1]+1) + 1)%(1000000000+7);
        //}
        //dp[i][2] = (dp[i][0] + dp[i][1])%(1000000000+7);
        cnt += dp[i];
        cnt %= MOD;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 8020
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cstdlib>
using namespace std;

string s;
long long num[10][10];

int main() {
  cin >> s;
  long long ans = 0;
  int len = s.length();

  if(len == 1){
    cout << atol(s.c_str()) << endl;
    return 0;
  }
  fill( num[0], num[10], 0);

  num[0][0] = atoll(s.c_str());
  ans = atoll(s.c_str());

  for(int i = 1; i < len; i++){
    for(int j = 0; j < i+1; j++){
      int tmp = atoll(s.substr(j,len-i).c_str());
      int left = j;
      int right = i-j;

      if(left > 1)
        tmp *= pow(2,left-1);
      if(right > 1)
        tmp *= pow(2,right-1);
      ans += tmp;
    }
  }

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

ll x, y;

int main()
{
  cin>>x>>y;
  ll ans;

  if (y > 0) {
    if (x > y) ans = x-y+2;
    else if (x >= 0) ans = y-x;
    else if (y >= -x) ans = y+x+1;
    else ans = -x-y+1;
  } else if (y < 0){
    if (y >= x) ans = y-x;
    else if (0 > x) ans = -y+x+2;
    else if (-y >= x) ans = -y-x+1;
    else ans = x+y+1;
  } else {
    if (x >= 0) ans = x+1;
    else ans = -x;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import math
S = list(input())
count = 0

for i in range(len(S)):
    if len(S)%2 == 0:
        if S[i] != S[-i-1]:
            count += 1/2
    else:
        if S[i] != S[-i-1]:
            if S[(int(len(S))-1)//2] == S[(int(len(S))-1)//2]:
                count += 1/2
print(math.ceil(count))


Measured memory_bytes: 3060
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);
function main(){
  var a = o.a();
  var b = o.a();
  var c = "", d = "";
  for(var i = 0; i < a; i++){
    c += b;
  }
  for(var i = 0; i < b; i++){
    d += a;
  }
  return c > d ? d : c;
}

Measured memory_bytes: 21064
package main

import (
	"fmt"
)

func main() {
	var n, m int
	var s, t string
	fmt.Scan(&n, &m, &s, &t)
	mp := map[int]int{}
	for i := 0; i < len(s); i++ {
		mp[m*i+1] = i
	}
	for i := 0; i < len(t); i++ {
		if v, ok := mp[n*i+1]; ok {
			if s[v] != t[i] {
				fmt.Println(-1)
				return
			}
		}
	}
	fmt.Println(lcm(n, m))
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}


Measured memory_bytes: 7168
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 998244353
N, S = lr()
A = lr()
dp = [0] * (S+1)
answer = 0
for a in A:
    dp[0] += 1 # Lの数は１個ずつ加わる
    prev = dp.copy()
    for i in range(S-a+1):
        dp[i+a] += prev[i]
    answer += dp[-1] # その位置Rとした時

print(answer % MOD)
# 26

Measured memory_bytes: 3828
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=2e5+5;
char s[maxn];
int main(){
    int i,n,ans;
    scanf("%s",s);
    n=strlen(s); ans=0;
    for (i=0;i<n;i++){
        if (!i||(s[i]!=s[i-1])) ans++;
        else{
            if (i==n-1) break;
            if (i==n-2){
                ans++; break;
            }
            i+=2; ans+=2;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int n;

signed main(){
    while(cin >> n, n){
        vector<int> t(n);
        rep(i, 0, n) cin >> t[i];
        sort(all(t));
        int ans = 0;
        rep(i, 0, n){
            ans += t[i] * (n - 1 - i);
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,a,i,gu=0,ki=0,mgu,mki;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a;
		if(a%2==0) gu++;
		if(a%2==1) ki++;
	}
	while(1){
		mgu=gu;
		mki=ki;
		//printf("%d %d\n",ki,gu);
		if(ki-2>-1){
			ki-=2;
			gu++;
		}
		else if(gu-2>-1){
			gu-=1;
		}
		
		if(mgu==gu && mki==ki){
			if(gu==1 && ki==0){
				cout << "YES" << endl;
				break;
			}
			if(gu==0 && ki==1){
				cout << "YES" << endl;
				break;
			}
			else{
				cout << "NO" << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 201;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    ll sum = 0;
    rep(i,n) sum += a[i];
    sum %= MOD;
    sum = sum*sum%MOD;
    ll sum2 = 0;
    rep(i,n){
        sum -= a[i]*a[i]%MOD;
        (sum += MOD)%=MOD;
    }
    (sum *= 500000004) %= MOD;
    PRINT(sum);
}



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

#define endl "\n"
typedef long long LL;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  LL l, r;
  cin >> l >> r;
  if (r - l + 1 >= 2019) return cout << 0 << endl,0;
  LL mn = INF;
  for (LL i = l; i <= r; i++) {
    for (LL j = l; j <= r; j++) {
      if (i != j) mn = min(mn, (i * j)%2019);
    }
  }
  cout << mn << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int X;
   cin>>X;
   if(X==3||X==5||X==7){
       cout<<"YES"<<endl;
   }
   else{
       cout<<"NO"<<endl;
   }
  
   
   
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   cout << (n + 1) / 2 << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int h,w,c=0;
    int l[4]={0,0,1,-1},m[4]={1,-1,0,0};
    cin >> h >> w;
    vector<vector<char>> mp(h,vector<char> (w));
    rep(i,h)rep(j,w){
        cin >> mp[i][j];
        if(mp[i][j]=='.') c++;
    }
    queue<pair<int,int>> d;
    vector<vector<int>> dist(h,vector<int> (w,-1));
    if(mp[0][0]=='.'){
        d.push(make_pair(0,0));
        dist[0][0]=0;
    }
    while(!d.empty()){
        pair<int,int> f=d.front();
        int x,y;
        tie(x,y) = f;
        d.pop();
        rep(i,4){
            if(x+l[i]<0||h<=x+l[i]) continue;
            if(y+m[i]<0||w<=y+m[i]) continue;
            if(mp[x+l[i]][y+m[i]]=='#') continue;
            if(dist[x+l[i]][y+m[i]]!=-1) continue;
            dist[x+l[i]][y+m[i]] = dist[x][y] + 1;
            d.push(make_pair(x+l[i],y+m[i]));
        } 
    }
    if(dist[h-1][w-1]==-1) cout << -1 << endl;
    else cout << c-dist[h-1][w-1]-1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a, int b) {
    while (b > 0) {
        int t = a; a = b; b = t % b;
    }
    return a;
}

int main() {
    int n, k; cin >> n >> k;
    int g; cin >> g;
    int mx = g;
    for (int i = 1; i < n; i++) {
        int x; cin >> x;
        g = gcd(g, x);
        mx = max(mx, x);
    }
    cout << (k % g || k > mx ? "IMPOSSIBLE" : "POSSIBLE") << endl;
}


Measured memory_bytes: 256