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

const long long NUM = 1000000007;

int main(){
	int N,K;
	cin>>N>>K;
	vector<vector<long long> >C;
	for(int i=0;i<3000;++i){
		vector<long long>tmpC;
		for(int j=0;j<i+1;++j){
			if(j==0 || j==i)tmpC.push_back(1);
			else{
				tmpC.push_back(C[C.size()-1][j-1]%NUM + C[C.size()-1][j]%NUM);
			}
		}
		C.push_back(tmpC);
	}
	long long ans[K+1];
	if(N==K){
		for(int i=0;i<K;++i){
			if(i==0)cout<<1<<endl;
			else cout<<0<<endl;
		}
	}
	else{
		for(int i=0;i<K;++i){
			if(i==0){
				ans[i] = N-K+1;
			}
			else{
				if(N-K>i+1){
					ans[i] = ((C[N-K-1][i+1]%NUM)*(C[K-1][i]%NUM))%NUM + 2*((C[N-K-1][i]%NUM)*(C[K-1][i]%NUM))%NUM + ((C[N-K-1][i-1]%NUM)*(C[K-1][i]%NUM))%NUM;
				}
				else if(N-K==i+1){
					ans[i] = 2*(C[N-K-1][i]%NUM)*(C[K-1][i]%NUM)%NUM + (C[N-K-1][i-1]%NUM)*(C[K-1][i]%NUM)%NUM;
				}
				else if(N-K==i){
					ans[i] = (C[N-K-1][i-1]%NUM)*(C[K-1][i]%NUM)%NUM;
				}
				else{
					ans[i] = 0;
				}
			}
		}
		for(int i=0;i<K;++i){
			cout<<ans[i]%NUM<<endl;
		}
	}
	/*
	for(int i=0;i<C.size();++i){
		for(int j=0;j<C[i].size();++j){
			cout<<C[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

main() {
    int N,M; cin >> N >> M;
    int A[N];
    rep(i,N){
        cin >> A[i];
    }
    int minn=INF,maxg=0,cnt=0;
    rep(i,N){
        if(minn == A[i]) cnt++;
        if(minn > A[i]) minn = A[i];
        if(maxg == A[i]-minn) cnt++;
        if(maxg < A[i]-minn){
            maxg = A[i]-minn; cnt=1;
        } 
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T>
struct BIT{
    //1-index
    private:
    V<T> arr;
    int n;
    public:
    BIT(int siz){
        n=siz;
        arr.assign(n+1,0);
    }
    //一点更新 aにvを加える
    void add(T a,T v){
        //x+=(x&-x) 初項a,それ以降a<=2^Nが列挙
        for(T x=a;x<=n;x+=(x&-x)){
            arr[x]+=v;
        }
    }
    T sum(T a){
        // 1からaまでの区間和
        T ret=0;
        for(T x=a;x>0;x-=(x&-x))ret+=arr[x];
        return ret;
    }
    T lower_bound(T w){// 区間和がw以上となる最小のindを返す
        if(w<=0)return 0;
        T x,r=1;//xは横の位置,rはrank
        while(r<n)r<<=1;
        for(T k=r;k>0;k>>=1){
            if(x+k<=n&&arr[x+r]<w){
                w-=arr[x+r];
                x+=k;
            }
        }
        return x+1;
    }
    T get(T x){//x番目に大きい数
        if(x<=0) return 0;
        T N=1;
        while(N*2<=n)N*=2;
        T v=0;
        for(T i=N;i>0;i/=2){
            if(v+i<=n&&arr[v+i]<x){
                x-=arr[v+i];
                v+=i;
            }
        }
        return v+1;
    }
    T query(int l,int r){
        return sum(r)-sum(l-1);
    }//1-index
};
int main(){
  int n,q;
  cin>>n>>q;
  BIT<ll> bit(n);
  while(q--){
	  ll c,x,y;cin>>c>>x>>y;
	  if(c){
		  cout<<bit.query(x,y)<<"\n";
	  }
	  else{
		  bit.add(x,y);
	  }
  }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
// until dimension reduction.

using namespace std;
typedef long long LL;

const int N = 20; 
int n, a[N], sz[N];
vector <pair <int, int> > sus[N]; 
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &sz[i]); 
    for (int j = 0; j < sz[i]; j++) {
      int x, y;
      scanf("%d%d", &x, &y);
      sus[i].push_back(make_pair(x, y)); 
    }
  }

  int ans = 0; 
  for (int i = 0; i < (1 << n); i++) {
    bool f = 0; 
    for (int j = 1; j <= n; j++) {
      if (f == 1) break; 
      if (!(i & (1 << (j - 1)))) continue;
      else {
        for (int e = 0; e < sus[j].size(); e++) {
          int f1 = sus[j][e].first, s1 = sus[j][e].second;
          if ((bool)(i & (1 << (f1 - 1))) != s1) {f = 1; break; }
        }
      }
    }
    if (!f) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << 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;

int main() {
	int n;
	cin >> n;
	long long  sum = 0;
	for (int i = 1; i <= n; ++i) {
		if (i % 3 == 0 && i % 5 == 0) continue;
		if (i % 3 == 0) continue;
		if (i % 5 == 0) continue;
		sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3620
from math import sqrt

#def area########################################

def Manhattan(x,y):
	D=0.0
	for i in range(n):
		D+=abs(x[i]-y[i])
	return D

def Euclid(x,y):
	D=0.0
	for i in range(n):
		D+=(x[i]-y[i])**2
	D=sqrt(D)
	return D

def Nazo(x,y):
	D=0.0
	for i in range(n):
		D+=abs((x[i]-y[i])**3)
	D**=1.0/3
	return D

def Infinity(x,y):
	L=list()
	for i in range(n):
		L.append(abs(x[i]-y[i]))			
	return max(L)

#################################################


n=int(input())
x=map(float,raw_input().split(" "))
y=map(float,raw_input().split(" "))

print Manhattan(x,y)
print Euclid(x,y)
print Nazo(x,y)
print Infinity(x,y)

Measured memory_bytes: 6668
#include<stdio.h>

int main(){
	int i, j;
	int count;
	int N;
	scanf("%d\n", &N);

	int A[N];
	for(i = 0; i < N; ++i)
		scanf("%d", &A[i]);
	
	count = 0;
	//BubbleSort(A)
	int flag = 1;
	while(flag) {
		flag = 0;
		for(j = N - 1; j > 0; --j) {
			if(A[j] < A[j-1]) {
				int tmp;
				tmp = A[j];
				A[j] = A[j-1];
				A[j-1] = tmp;
				flag = 1;
				++count;
			}
		}
	}
	for(i = 0; i < N; ++i) {
		if(i == N-1)
			printf("%d\n", A[i]);
		else
			printf("%d ", A[i]);
	}
	printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

ll five(ll n)
{
	ll cnt = 0;
	ll tmp = n;
	ll x = 5;
	while (tmp >= x)
	{
		cnt += (tmp / x);
		x *= 5;
	}
	return cnt;
}
void solve(int tc)
{
	ll n;
	cin >> n;
	if (n == 0 || (n % 2) == 1)
	{
		cout << 0 << ln;
		return;
	}
	//atleast 2 and even
	ll cnt = five(n / 2);
	cout << cnt << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
int main()
{
  int i, j, k, l, n, b, f, r, v;
  int count[4][3][10] = {};
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d %d %d %d",&b, &f, &r, &v);
    for(j = 0; j < 4; j++){
      if(j == b - 1){
	for(k = 0; k < 3; k++){
	  if(k == f - 1){
	    for(l = 0; l < 10; l++){
	      if(l == r - 1) count[j][k][l] += v;
	    }
	  }/*if*/
	}
      }/*if*/
    }
  }
  for(i = 0; i < 4; i++){
    for(j = 0; j < 3; j++){
      for(k = 0; k < 10; k++){
	printf(" %d",count[i][j][k]);
      }
      printf("\n");
    }
    if(i < 3) printf("####################\n");
  }
  return 0;
}

Measured memory_bytes: 612
X,N = map(int, input().split())
p = [int(x) for x in input().split()]

exist = 0
ans = -1

if N == 0:
    ans = X

for i in range(100):
    LX = X - i
    exist = 0
    for j in range(N):
        if LX == p[j]:
             exist = 1
    if exist == 0:
        ans = LX
        break

    HX = X + i
    exist = 0
    for k in range(N):
        if HX == p[k]:
            exist = 1
    if exist == 0:
        ans = HX
        break

print(ans)


Measured memory_bytes: 9144
import java.util.*;

public class Main {
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    
    	if(A < 6){
    		System.out.println(0);
    	}
    	else if (A < 13){
    		System.out.println(B/2);
    	}
    	else{
    		System.out.println(B);
    	}
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main()
{

    long long d,c,a,b;
    scanf("%lld%lld",&a,&b);
    d = a * b;
    while(b != 0){
        c = a % b;
        a = b;
        b = c;
    }
    printf("%lld\n", d / a);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


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

const int N=200005;


void solve()
{

    int k;
    cin>>k;
    string s;
    cin>>s;
    int n=s.length();
    if(n<=k)
    {
        cout<<s<<endl;
        return;
    }
    for(int i=0;i<k;i++)
        cout<<s[i];
    cout<<"...";
    cout<<endl;
    
}


int32_t main()
{
    IOS;
    
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3632
from heapq import heappush, heappop
while 1:
    N, M, L, K, A, H = map(int, raw_input().split())
    if N == 0:
        break
    F = [0]*N
    for e in map(int, raw_input().split()):
        F[e] = 1
    G = [[] for i in xrange(N)]
    for i in xrange(K):
        x, y, t = map(int, raw_input().split())
        G[x].append((y, t))
        G[y].append((x, t))
    dist = [[10**18]*(M+1) for i in xrange(N)]
    dist[A][M] = 0
    que = [(0, A, M)]
    while que:
        cost, v, rest = heappop(que)
        if dist[v][rest] < cost:
            continue
        if F[v] and rest < M and cost + 1 < dist[v][rest+1]:
            dist[v][rest+1] = cost+1
            heappush(que, (cost+1, v, rest+1))
        for t, co in G[v]:
            if rest>=co and cost + co < dist[t][rest-co]:
                dist[t][rest-co] = cost + co
                heappush(que, (cost+co, t, rest-co))
    ans = min(dist[H])
    print "Help!" if ans > 10**17 else ans

Measured memory_bytes: 8024
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	ll ans = 1;
	cin>>n>>m;
	if(abs(n-m)>1)
		cout<<0<<endl;
	else
	{
		for(int i = 1; i<=n; i++)
			ans = (ans*i)%mod;
		for(int i = 1; i<=m; i++)
			ans = (ans*i)%mod;
		if(n==m)
			ans = (2*ans)%mod;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ALL(x) x.begin(), x.end()
 
typedef long long int lld;
typedef pair<int, int> pii;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;
 
	int n = 0;
	cin >> n;
	lld ans = 0;

	vector<int> vec(n + 1);

	for (int i = 0; i <= n; i++)
		cin >> vec[i];

	for (int i = 0; i < n; i++) {
		int x = 0;
		cin >> x;

		int t = min(x, vec[i]);
		ans += t;
		x -= t;
		vec[i] -= t;

		t = min(x, vec[i + 1]);
		ans += t;
		vec[i + 1] -= t;
	}

	cout << ans << '\n';

	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int NM = 1e5+10;
const ll INF = 1LL << 60;
ll h[NM];
ll dp[NM];

int main() {
    int n, k; cin >> n >> k;
    rep(i, n) cin >> h[i];
    rep(i, NM) dp[i] = INF;

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

}

Measured memory_bytes: 1792
(n, a, b) = gets.chomp.split(' ').map(&:to_i)

s = 0

(1..n).each do |m|
  d = m.to_s.split('').map(&:to_i).reduce(:+)
  if ((a <= d) and (d <= b)) then
    s += m
  end
end

puts s.to_s

Measured memory_bytes: 2172
#include<iostream>
#include<algorithm>
#define N 202
using namespace std;
int i,j,m,n,a[N];
long long ans=0;
int main()
{
	cin>>n;
	for(i=1;i<=2*n;i++) cin>>a[i];
	sort(a+1,a+2*n+1);
	for(i=1;i<=2*n;i+=2) ans+=a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
a,b,c,d = input().split()
A = int(a)
B = int(b)
C = int(c)
D = int(d)
for i in range(A):
    C = C - B
    if C <= 0:
        print("Yes")
        break
    A = A - D
    if A <= 0:
        print("No")
        break

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
#define ld long double
#define pll pair<ll,ll>
using namespace std;

ll bin_exp_mod(ll a, ll b,ll m)
{
	a%=m;
	ll ans=1;
	if(a==0) ans=0;

	while(b>0)
	{
		if(b&1) ans=(ans*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return ans;
}

int main()
{ 
	

fast;

ll n;
cin>>n;

vector<ll> v1,v2;

for(ll i=0;i<n;i++)
{
	ll x1,y1;
	cin>>x1>>y1;

	v1.pb(x1+y1);
	v2.pb(x1-y1);
}

ll ans=max(*max_element(v1.begin(),v1.end())-*min_element(v1.begin(),v1.end()), *max_element(v2.begin(),v2.end())-*min_element(v2.begin(),v2.end()) );
cout<<ans;

}


Measured memory_bytes: 6656
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String w=sc.next();
		for(int i=0;i<w.length();i++){
			int count=0;
			for(int j=0;j<w.length();j++){
				if(w.charAt(i)==w.charAt(j)){
					count++;
				}
			}
			if(count%2!=0){
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}

}


Measured memory_bytes: 9672
N, P = map(int, input().split())
S = input()
ans = 0
rui = [0] * (N + 1)
if 10 % P == 0:
    for i in range(len(S)):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    exit()

t = 1
for i in reversed(range(N)):
    tmp = int(S[i]) * t % P
    rui[i] = (rui[i + 1] + tmp) % P
    t *= 10
    t %= P

cnt = [0] * P
for i in reversed(range(N + 1)):
    ans += cnt[rui[i]]
    cnt[rui[i]] += 1
print(ans)

Measured memory_bytes: 11080
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <cstring>
#include <algorithm>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

long long memo[2020][2020];
std::pair<long long, int> a[2020];
long long dp(int l, int r, int on) {
	if(l == r) return 0;
	long long &ans = memo[l][r];
	if(ans != -1) return ans;
	return ans = std::max(dp(l+1, r, on-1) + abs(l - a[on].second) * a[on].first, dp(l, r-1, on-1) + abs(r-1 - a[on].second) * a[on].first);
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	for(int i = 0; i < n; i++) {
		std::cin >> a[i].first;
		a[i].second = i;
	}
	std::sort(a, a + n);
	memset(memo, -1, sizeof memo);
	std::cout << dp(0, n, n-1) << '\n';
}

Measured memory_bytes: 35632
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>

#define MOD 1000000007
#define ll long long
#define ld long double

using namespace std;

bool func(pair<ll,ll>a, pair<ll,ll>b){
  return (double)(a.first/a.second) <(double)(b.first/b.second);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //price, size*4
  vector<pair<ll,ll> >P;

  ll price,size;

  size = 1;
  cin >> price;
  P.push_back(make_pair(price, size));

  size = 2;
  cin >> price;
  P.push_back(make_pair(price,size));

  size = 4;
  cin >> price;
  P.push_back(make_pair(price,size));

  size = 8;
  cin >> price;
  P.push_back(make_pair(price,size));

  ll N;
  cin >> N;
  N*=4;

  ll result = 1e18;
  for(ll i =0;i<P.size();i++){
    for(ll j =0;j<P.size();j++){
      if(j==i) continue;
      for(ll k = 0;k<P.size();k++){
	if(k==i)continue;
	if(k==j)continue;
	for(ll l =0;l<P.size();l++){
	  if(l==i)continue;
	  if(l==j)continue;
	  if(l==k)continue;
	  ll sum =0;
	  ll num ;
	  ll n=N;

	  num = n/P[i].second;
	  sum += (num*P[i].first);
	  n%=P[i].second;


	  num =n/P[j].second;
	  sum += (num*P[j].first);
	  n%=P[j].second;

	  num =n/P[k].second;
	  sum += (num*P[k].first);
	  n%=P[k].second;

	  num =n/P[l].second;
	  sum += (num*P[l].first);
	  n%=P[l].second;

	  result = min(result,sum);
	}
      }
    }
  }
  /*
  sort(P.begin(), P.end(), func);

  ll res = 0;
  for(ll i =0;i<P.size();i++){
    ll num = N/P[i].second;
    res += num*P[i].first;
    N%=P[i].second;
    if(N==0) break;
  }
  */
  cout << result << endl;
  return 0;
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#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() {
  double L;
  cin >> L;
  double ans;
  ans = L/3 * L/3 * L/3;
  cout << setprecision(8) << ans << endl;
  return 0;
}


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

using namespace std;

class dictionary {
	vector<string> field;
public:
	bool serch(string);
	void add(string);
};

void dictionary::add(string s) {
	field.push_back(s);
	int i = field.size() - 2;
	while (i >= 0 && field[i] > s) {
		field[i + 1] = field[i];
		i--;
	}
	field[i + 1] = s;
}

bool dictionary::serch(string s) {
	int left = 0, right=field.size()-1;
	int mid;

	while(left<=right){
		mid = (right + left) / 2;
		if (field[mid] == s)return true;
		if (field[mid] > s) {
			right = mid-1;
		}
		else {
			left = mid+1;
		}
	}
	return false;
}

class node {
public:
	char field;
	vector<node> children;
	node* parent;
	node(char);
	node();
	bool end;
};

node::node(){
	end = false;
}

node::node(char c) {
	field = c;
	end = false;
}

class dictionarybytree {
public:
	node root;
	void add(string);
	bool search(string);
	dictionarybytree();
};

dictionarybytree::dictionarybytree(){}

void dictionarybytree::add(string s) {
	node *n = &root;
	bool flag;
	for (int i = 0;i < s.length();i++) {
		flag = false;
		for (int j = 0;j < n->children.size();j++) {
			if (n->children[j].field == s[i]) {
				flag = true;
				n = &n->children[j];
				break;
			}	
		}
		if (!flag) {
			n->children.emplace_back(s[i]);
			n = &n->children[n->children.size() - 1];
		}
	}
	n->end = true;
}

bool dictionarybytree::search(string s) {
	node *n = &root;
	bool flag;
	for (int i = 0;i < s.length();i++) {
		flag = false;
		for (int j = 0;j < n->children.size();j++) {
			if (s[i] == n->children[j].field) {
				flag = true;
				n = &n->children[j];
				break;
			}
		}
		if (!flag)return false;
	}
	if (n->end) {
		return true;
	}
	else {
		return false;
	}
}


int main() {
	dictionarybytree d;
	int n;
	string com, param;
	cin >> n;
	string msg="";
	for (int i = 0;i < n;i++) {
		cin >> com >> param;
		if (com[0] == 'i') {
			d.add(param);
		}else {
			if (d.search(param)) {
				cout << "yes\n";
			}
			else {
				cout<< "no\n";
			}
		}
	}
	//cout << msg;
}


Measured memory_bytes: 23304
/*GRATITUDE*/
//Arise Awake and Stop Not Till the Goal is reached. You are the greatest of all. Hare Krishna
//Break through all barriers..
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define ff              first
#define ss              second
#define uint            unsigned long long
#define int             long long
#define double           long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<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 endl            "\n"
#define all(x)             x.begin(), x.end()
#define all_r(x)           x.rbegin(), x.rend()
#define sortall(x)         sort(all(x))
#define sortall_r(x)       sort(all_r(x))  
#define tr(it, a)          for(auto it = a.begin(); it != a.end(); it++)
#define PI                 acos(-1)
#define w(t)              int t; cin>>t; while(t--)
#define for_f(a,b,c)      for(int i=a;i<=b;i=i+c)
#define for_r(a,b,c)      for(int i=a;i>=b;i=i-c) 
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define trace1(x) cout << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
void ash_god()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    freopen("o.txt", "w", stdout);
#endif
}
/*************************************************************************************************/
//Write your functions here..............................



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

void solve() {
/*Write your code here*/
int a,b,c,k; cin>>a>>b>>c>>k;
int sum=0;
while (k!=0 && a!=0) {sum+=1; --k; --a; }
if(k==0) {cout<<sum; return;}
while (k!=0 && b!=0) {sum+=0; --k; --b; }
if(k==0) {cout<<sum; return;}
while (k!=0 && c!=0) {sum-=1; --k; --c; }
if(k==0) {cout<<sum; return;}
}   
int32_t main()
{
ash_god();
bool tc=0;
if(tc)  {
    w(t) solve();
}
else solve();

return 0;
} 



Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

double F(double n) {
  double ret = n * log(n) - n + log(2 * M_PI * n) / 2;
  ret += 1.0 / 12 / n - 1.0 / 360 / (n * n * n);
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  vector<ii> b(n);
  for (int i = 1; i < n; ++i) {
    int target = a[i] / 2;
    int j = lower_bound(a.begin(), a.begin() + i, target) - a.begin();
    int best = INF, best_j = -1;
    if (j < i && best > abs(a[j] - target)) {
      best = abs(a[j] - target);
      best_j = j;
    }
    --j;
    if (j >= 0 && best > abs(a[j] - target)) {
      best = abs(a[j] - target);
      best_j = j;
    }
    // trace(i, a[i], a[best_j]);
    b[i] = ii{a[i], a[best_j]};
  }
  sort(b.begin() + 1, b.end(), [](const ii& a, const ii& b) {
      return F(a.first) - F(a.second) - F(a.first - a.second)
        < F(b.first) - F(b.second) - F(b.first - b.second);
    });
  printf("%d %d\n", b.back().first, b.back().second);
  return 0;
}


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int ans = 0;
        Set<String> cache = new HashSet<>();
        while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
            if (cache.contains(A + "_" + B + "_" + C)) {
                System.out.println(-1);
                return;
            }
            cache.add(A + "_" + B + "_" + C);
            Queue<Integer> queue = new PriorityQueue<>(Comparator.naturalOrder());
            queue.add(A / 2 + B / 2);
            queue.add(B / 2 + C / 2);
            queue.add(C / 2 + A / 2);
            A = queue.poll();
            B = queue.poll();
            C = queue.poll();
            ans += 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  ll a,b,x; cin >> a >> b >> x;
  ll ans = 0;
  ans += b/x + 1;
  if(a>0) ans -= (a-1)/x + 1;

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

VI a;

int main(){
    int n, x;
    ll ans = 0;
    cin >> n >> x;
    
    for(int i = 0; i < n; i++){
        int temp;
        cin >> temp;
        if(temp > x){
            ans += temp - x;
            a.push_back(x);
        }else{
            a.push_back(temp);
        }
    }
    
    
    for(int i = 0; i < n-1; i++){
        if(a[i] + a[i+1] > x){
            ans += a[i] + a[i+1] - x;
            a[i+1] = x - a[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}










Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int main()
{
  int t;
  cin >> t;
  while( t-- ) {
    int n, k;
    vector<int> v; //v[0]:x1とx2の差
    int dist; //端と端との距離
    int bef, x;
    cin >> n >> k;
    Rep(i, n) {
      cin >> x;
      if( i == 0 ) {
	dist = -x;
	bef = x;
      } else {
	v.pb( x - bef );
	bef = x;
      }
      if( i == n-1 ) dist += x;
    }

    sort( All(v), greater<int>() );
    Rep(i, min((int)v.size(), k-1)) {
      dist -= v[i];
    }

    cout << dist << endl;
  }

}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

template <class T> int getbit(T s, int i) { return (s >> i) & 1; }
template <class T> T onbit(T s, int i) { return s | (T(1) << i); }
template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template <class T> ll cntbit(T s) { return __builtin_popcntll(s); }

#define all(a) (a).begin(), (a).end()
#define ms(a, x) memset(a, x, sizeof(a))
#define sz(a) ((ll)(a).size())
#define bot(i, n) for (int i = 0; i < (n); ++i)
#define top(i, n) for (int i = (n)-1; i >= 0; --i)
#define bot_(i, a, b) for (int i = (a); i <= (b); ++i)
#define top_(i, a, b) for (int i = (a); i >= (b); --i)
#define forv(v, it) for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); it++)
#define print(x) cout << __LINE__ << #x << " = " << x << endl
#define clear(x) v.clear(); vector<T>(v).swap(v)

#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define eps 1e-12

#define div ___div
#define next ___next
#define prev ___prev
#define left ___left
#define right ___right
#define y0 ___y0
#define y1 ___y1

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

  int x, y, z;
  cin >> x >> y >> z;

  int num_seats = 0;
  int allocated = z;

  while(allocated <= x) {
    allocated += y + z;
    if(allocated <= x) {
      num_seats++;
    }
  }

  cout << num_seats << endl;

  return 0;
}


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

ll dp[100005][4];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   
    string s;
    cin>>s;
    int n = s.size();
    dp[0][0] = 1;
    for(int i=1;i<=n;++i)
   		for(int j=0;j<=3;++j)
   		{
   			dp[i][j] = 3*dp[i-1][j]*(s[i-1]=='?') + dp[i-1][j]*(s[i-1]!='?');
   			if(j!=0 && (s[i-1]=='?' || s[i-1]==" ABC"[j]))
   				dp[i][j] += dp[i-1][j-1];
   			dp[i][j] %= 1000000007;
   		}
   	cout<<dp[n][3];
    return 0;
}   

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

int	main() {
	int N, K;
	vector<bool> D (10, true);
	cin >>N >>K;
	for (int i=0; i<K; i++) {
		int C;
		cin >>C;
		D.at(C)=false;
	}
	vector<int> DD(0);
	for (int i=0; i<10; i++)
		if (D.at(i))
			DD.push_back(i);
	int DN=DD.size()-1;
	int D4=DN;
	int D3=DN;
	int D2=DN;
	int D1=DN;
	int D0=DN;
	int DD4, DD3, DD2, DD1, DD0;
	int S;
	int DW;
	if (N>DD.at(D3)*1000+DD.at(D2)*100+DD.at(D1)*10+DD.at(D0))
		DW=5;
	else if (N>DD.at(D2)*100+DD.at(D1)*10+DD.at(D0))
		DW=4;
	else if (N>DD.at(D1)*10+DD.at(D0))
		DW=3;
	else if (N>DD.at(D0))
		DW=2;
	else
		DW=1;
	if (DW<5) {
		DD4=0;
	} else {
		while (true) {
			DD4=DD.at(D4)*10000;
			S=DD4+DD.at(D3)*1000+DD.at(D2)*100+DD.at(D1)*10+DD.at(D0);
			if (S>=N) {
				D4--;
				if (0>D4) {
					DD4=DD.at(0)*10000;
					break;
				}
			} else {
				D4++;
				DD4=DD.at(D4)*10000;
				break;
			}
		}
	}
	if (DW<4) {
		DD3=0;
	} else {
		while (true) {
			DD3=DD.at(D3)*1000;
			S=DD4+DD3+DD.at(D2)*100+DD.at(D1)*10+DD.at(D0);
			if (S>=N) {
				D3--;
				if (0>D3) {
					DD3=DD.at(0)*1000;
					break;
				}
			} else {
				D3++;
				DD3=DD.at(D3)*1000;
				break;
			}
		}
	}
	if (DW<3) {
		DD2=0;
	} else {
		while (true) {
			DD2=DD.at(D2)*100;
			S=DD4+DD3+DD2+DD.at(D1)*10+DD.at(D0);
			if (S>=N) {
				D2--;
				if (0>D2) {
					DD2=DD.at(0)*100;
					break;
				}
			} else {
				D2++;
				DD2=DD.at(D2)*100;
				break;
			}
		}
	}
	if (DW<2) {
		DD1=0;
	} else {
		while (true) {
			DD1=DD.at(D1)*10;
			S=DD4+DD3+DD2+DD1+DD.at(D0);
			if (S>=N) {
				D1--;
				if (0>D1) {
					DD1=DD.at(0)*10;
					break;
				}
			} else {
				D1++;
				DD1=DD.at(D1)*10;
				break;
			}
		}
	}
	while (true) {
		DD0=DD.at(D0);
		S=DD4+DD3+DD2+DD1+DD0;
		if (S>=N) {
			D0--;
			if (0>D0) {
				DD0=DD.at(0);
				break;
			}
		} else {
			D0++;
			DD0=DD.at(D0);
			break;
		}
	}
	S=DD4+DD3+DD2+DD1+DD0;
	cout <<S <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  ll n,t;
  cin>>n>>t;
  ll a[n+1],ans=0;
  a[0]=0;
  rep(i,n){
    cin>>a[i+1];
    ans+=min(a[i+1]-a[i],t);
    }
  ans+=t;
  cout<<ans<<endl;
  return 0;
  }
  




Measured memory_bytes: 1792
def calc_max_total_jewels_value():
  jewels = int(input())
  jewel_value = [int(x) for x in input().split()]
  jewel_cost = [int(x) for x in input().split()]
  
  max_total_jewels_value = 0
  for jewel_no in range(jewels):
    max_total_jewels_value += max([0, jewel_value[jewel_no] - jewel_cost[jewel_no]])
    
  return max_total_jewels_value

if __name__ == '__main__':
  print(calc_max_total_jewels_value())

Measured memory_bytes: 3060
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a = int(readline())
    b = int(readline())

    if a > b:
        print("GREATER")
    elif a < b:
        print("LESS")
    else:
        print("EQUAL")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61724
def c():
    n = int(input())
    a = list(map(int, input().split()))
    l = list(map(lambda i: min(8, i//400), a))
    over_rate = l.count(8)
    res = set(l)
    if 8 in res: res.remove(8)

    mi = max(1, len(res))
    ma = len(res) + over_rate
    print(mi, ma)

c()

Measured memory_bytes: 3060
#include <stdio.h>

int *sortedR(int *array, int size) {
	int i, j; int temp, index = 0;
	for (i = 0; i < size; i++) {
		index = i;
		for (j = i + 1; j < size; j++) {
			if (array[index] < array[j]) {
				index = j;
			}
		}
		temp = array[i];
		array[i] = array[index];
		array[index] = temp;
	}
  return array;
}

int main() {
  int N, i, A=0, B=0, tmp;
  scanf("%d", &N);
  int arr[N];
  for (i=0; i<N; i++) {
    scanf("%d", &arr[i]);
  }
  sortedR(arr, N);
  for (i=0; i<N; i++) {
    if (i%2==0) A+=arr[i];
    else B+=arr[i];
  }
  printf("%d\n", A-B);
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        try (InputReader reader = new InputReader(System.in)) {
            solve(reader);
        }
    }

    private static void solve(InputReader reader) throws IOException {
        String i = reader.readLine();
        if (i.length() == 2) {
            System.out.println(i);
        } else {
            StringBuilder sb = new StringBuilder(i);
            System.out.println(sb.reverse());
        }
    }
}

class Util {
    static int gcd(int m, int n) {
        int min = Math.min(m, n);
        int max = Math.max(m, n);
        while (min != 0) {
            int tmp = min;
            min = max % tmp;
            max = tmp;
        }

        return max;
    }

    static int lcm(int m, int n) {
        return m / gcd(m, n) * n;
    }
}

class InputReader implements Closeable, AutoCloseable {
    private final BufferedReader br;

    InputReader(InputStream inputStream) {
        this.br = new BufferedReader(new InputStreamReader(inputStream));
    }

    String readLine() throws IOException {
        return this.br.readLine();
    }

    int readInt() throws IOException {
        return Integer.parseInt(this.readLine());
    }

    long readLong() throws IOException {
        return Long.parseLong(this.readLine());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(this.readLine());
    }

    String[] readStringsSplitBy(String delimiter) throws IOException {
        return this.readLine().split(delimiter);
    }

    int[] readIntsSplitBy(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitBy(delimiter);

        int[] ints = new int[strings.length];
        for (int i = 0; i < strings.length; i++) {
            ints[i] = Integer.parseInt(strings[i]);
        }

        return ints;
    }

    long[] readLongsSplitBy(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitBy(delimiter);

        long[] longs = new long[strings.length];
        for (int i = 0; i < strings.length; i++) {
            longs[i] = Long.parseLong(strings[i]);
        }

        return longs;
    }

    double[] readDoublesSplitBy(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitBy(delimiter);

        double[] doubles = new double[strings.length];
        for (int i = 0; i < strings.length; i++) {
            doubles[i] = Double.parseDouble(strings[i]);
        }

        return doubles;
    }

    @Override
    public void close() throws IOException {
        this.br.close();
    }
}


Measured memory_bytes: 22612
#include <stdio.h>
int main(void){
	int n,i,a[100001],b,c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",&a[i]);}
	i=0;
	while(c<n){
		b=a[i]- 1;
		c++;
		if(b==1){printf("%d",c);return 0;}
		i=b;
	}
	printf("-1");
	return 0;
}

Measured memory_bytes: 512
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    check = [[1 for j in range(n)] for i in range(n)]
    d =  [[min(i, n-i-1, j, n-j-1) for j in range(n)] for i in range(n)]

    ans = 0
    for t in l:
        t -=1
        x = t//n
        y = t%n
        check[x][y] = 0
        ans += d[x][y]
        q = []
        q.append((x,y,d[x][y]))
        while q:
            bx,by,z = q.pop()

            if bx != 0:
                if d[bx-1][by] > z:
                    d[bx-1][by] = z
                    q.append((bx-1,by,z+check[bx-1][by]))
            if bx != n-1:
                if d[bx+1][by] > z:
                    d[bx+1][by] = z
                    q.append((bx+1,by,z+check[bx+1][by]))
            if by != 0:
                if d[bx][by-1] > z:
                    d[bx][by-1] = z
                    q.append((bx,by-1,z+check[bx][by-1]))
            if by != n-1:
                if d[bx][by+1] > z:
                    d[bx][by+1] = z
                    q.append((bx,by+1,z+check[bx][by+1]))  
    print(ans)
if __name__ =="__main__":
    main()


Measured memory_bytes: 196216
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string S,T;
cin>>S>>T;
cout<<T+S<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
      cin>>a[i];
    }
    vector<ll> r(n),l(n);
    r[0]=a[0];
    l[n-1]=a.back();
    FOR(i,1,n){
      r[i]=gcd(r[i-1],a[i]);
    }
    for(ll i=n-2;i>=0;i--){
      l[i]=gcd(l[i+1],a[i]);
    }
    //cout_vec(r);
    //cout_vec(l);
    ll ans=r.back();
    FOR(i,1,n-1){//a[i]を消す
      ll cnt=gcd(r[i-1],l[i+1]);
      if(ans<cnt){
        ans=cnt;
      }
    }
    if(ans<l[1]){
      ans=l[1];
    }
    if(ans<r[n-2]){
      ans=r[n-2];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
object Main extends App {
  val amount = Array(500,100,50)
  val in = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
      for {
        i <- 0 to in(0)
        if amount(0)*i <= in(3)
        j <- 0 to in(1)
        if amount(1)*j <= in(3)
        k <- 0 to in(2)
        if amount(0)*i + amount(1)*j + amount(2)*k == in(3)
      } yield  true
    }.size

  println(ans)
}

Measured memory_bytes: 26004
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;



int main()
{
    ll n;
    cin>>n;
    vll v1,v2;
    for(ll i=0; i<n; i++)
    {
        ll x,y;
        cin>>x>>y;
        v1.pb(x+y);
        v2.pb(x-y);
    }
    sort(all(v1));
    sort(all(v2));
    cout<<max(v1[n-1]-v1[0],v2[n-1]-v2[0])<<nn;




}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 6592
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
LL dp[100][100][5000];
int main(){
    CIN(N);CIN(A);
    I vec;
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    dp[0][0][0]=1;
    for(int a = 0;a < N;a++){
        for(int b = 0;b < N;b++){
            for(int c = 0;c < 5000;c++){
                dp[a+1][b+1][c+vec.at(a)]+=dp[a][b][c];
                dp[a+1][b][c] += dp[a][b][c];
            }
        }
    }
    LL ans = 0;
    for(int a = 1;a <= N;a++){
        for(int b =1;b <= 5000;b++){
            if(b/a == A&&b%a==0)
            ans += dp[N][a][b];
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 196864
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	//vector<ll> fact(n+1);
	//fact[0] = 1;
	//for(ll i=1;i<=n;++i) fact[i] = mod(mod(i) * mod(fact[i-1]));
	vector<ll> nums(n+1);
	for(ll i=1;i<=n;++i)
	{
		nums[i] += nums[i-1];
		nums[i] += i;
	}
	vector<ll> suff(n+1);
	suff[n] = n;
	for(ll i=n-1;i>=1;--i)
	{
		suff[i] = suff[i+1] + i;
	}
	
	
	
	ll sum = 0;
	for(ll i=k;i<=(n);++i)
	{
		ll lo = nums[i-1];
		ll hi = suff[n-i+1];
	//	cout<<lo<<" "<<hi<<" "<<i<<endl;
		sum = mod(mod(sum) + mod(hi-lo+1));
		
	}
	cout<<mod(sum+1)<<endl;
}

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

using namespace std;

string s;
int size;

int getNum(int x){
  if(x == 1 || x == 4 || x == 7){
    return 0;
  }
  if(x == 2 || x == 8){
    return 1;
  }
  return 2;
}

bool valid(int left,int right){
  left = getNum(left);
  right = getNum(right);
  if(left > right){
    return false;
  }
  return true;
}

int solve(int foot){
  int left,right,cnt = 0;
  if(foot == 0){
    left = s[0]-'0';
    right = s[1]-'0';
  }else{
    left = s[1]-'0';
    right = s[0]-'0';
  }
  if(!valid(left,right)){
    return INT_MAX;
  }
  for(int i = 2 ; i < size ; i++){
    int next = s[i]-'0';
    if(foot == 0){
      if(valid(next,right)){
        left = next;
        foot = 1-foot;
      }else{
        right = next;
        cnt++;
      }
    }else{
      if(valid(left,next)){
        right = next;
        foot = 1-foot;
      }else{
        left = next;
        cnt++;
      }
    }
  }
  return cnt;
}

int main(){
  while(cin >> s, s != "#"){
    size = s.size();
    if(size <= 2){
      puts("0");
      continue;
    }
    cout << min(solve(0),solve(1)) << endl;
  }
  return 0;
}

Measured memory_bytes: 1312