akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>

char s[100005],t[100005];
int nx[100005][35];
int book[305];
int main()
{
	int n=1;
	while(n--)
	{
		scanf("%s",s+1);
		scanf("%s",t+1);
		int slen=strlen(s+1),tlen=strlen(t+1);
		memset(book,0,sizeof(book));
		for(int i=1;i<=slen;i++) book[s[i]]=true;
		bool flg=true;
		for(int i=1;i<=tlen;i++) if(!book[t[i]])
		{
			flg=false;printf("-1\n");break;
		}
		if(flg)
		{
			memset(nx,0x3f,sizeof(nx));
			for(int i=slen-1;i>=0;i--)
			{
				for(int j=0;j<=25;j++)
					nx[i][j]=nx[i+1][j];
				nx[i][s[i+1]-'a']=i+1;
			}
			int now=0,ans=1;
			for(int i=1;i<=tlen;i++)
			{
				if(nx[now][t[i]-'a']!=nx[0][30])
					now=nx[now][t[i]-'a'];
				else
				{
					now=nx[0][t[i]-'a'];ans++;
				}
			}
			printf("%lld\n",1LL*slen*(ans-1)+now);
		}
	}
}

Measured memory_bytes: 14080
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        c=bisect_left(L,l)
        ans+=max(0,c-j-1)
print(ans)


Measured memory_bytes: 3188
#include <iostream>
//#include <memory.h>
//#include <limits.h>
//#include <math.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <algorithm>
//#include <map>
using namespace std;

#define ll long long

int main()
{
    ll n, a, b;
    cin>>n>>a>>b;
    ll x[100001];
    for(ll i=1;i<=n;i++) cin>>x[i];
    ll sum = 0;
    for(ll i=1;i<n;i++)
    {
        ll l = x[i+1] - x[i];
        sum += min(b, a*l);
    }
    cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    rep(i, A+1) {
        rep(j, B+1) {
            rep(k, C+1) {
                if (i * 500 + j * 100 + k * 50 == X) ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
d={}
import itertools
l=list(itertools.permutations(range(1,n+1)))
l.sort()
for i,k in enumerate(l):
    d[k]=i

print(abs(d[p]-d[q]))


Measured memory_bytes: 47984
import math

def keta(a):
    count=1
    while a>=10:
        a/=10
        count+=1
    return count


N=int(input())
mi=10
for i in range(1,int(N/math.sqrt(N)+1)):
    if N%i==0:
        j=int(N/i)
        if mi>max(keta(i),keta(j)):
            mi=max(keta(i),keta(j))

print(mi)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using ll = long long;

using namespace std;

struct uftree {
    int n, *par, *rank, *size;
    uftree(int N) : n(N) {
        par = new int[(size_t)N];
        rank = new int[(size_t)N];
        size = new int[(size_t)N];
        for (int i = 0; i < N; i++) {
            par[i]  = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            int r         = root(par[x]);
            size[x]       = size[par[x]];
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y])
            par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
        size[x] += size[y];
        size[y] = size[x];
    }
    int get_size(int x) {
        root(x);
        return size[x];
    }
    bool same(int x, int y) { return root(x) == root(y); }

    // 集合の数をカウントする関数
    // 1..nのつもりでやってる場合も0をカウントしちゃうので注意
    int count_sets() {
        int cnt = 0;
        bool used[n];
        fill(used, used+n, false);
        for (int i=0; i<n; i++) {
            if (used[root(i)]) continue;
            cnt++;
            used[root(i)] = true;
        }
        return cnt;
    }
};

vector<int> G[710];
int color[710] = {0};

bool dfs(int i, int c=1) {
    color[i] = c;
    for (auto &g:G[i]) {
        if ((color[g] && color[i] == color[g]) || (!color[g] && !dfs(g, c ^ 3)))
            return false;
    }
    return true;
}

int main() {
    int n, m;
    cin >> n >> m;
    bool connect[n][n];
    fill(connect[0], connect[n], true);
    for (int i=0, a, b; i<m; i++) {
        cin >> a >> b;
        a--; b--;
        connect[a][b] = connect[b][a] = false;
    }
    uftree uft(n);
    for (int i=0; i<n; i++) {
        for (int j=0; j<i; j++) {
            if (!connect[i][j]) continue;
            G[i].push_back(j);
            G[j].push_back(i);
            uft.unite(i, j);
        }
    }
    set<int> pars;
    for (int i=0; i<n; i++)
        pars.insert(uft.root(i));
    for (auto &p:pars) {
        if (!dfs(p)) {
            cout << -1 << '\n';
            return 0;
        }
    }
    int red[n];
    fill(red, red+n, 0);
    for (int i=0; i<n; i++) if (color[i] == 1) red[uft.root(i)]++;
    bitset<701> bs;
    bs.set(0);
    for (auto &p:pars) {
        bs = (bs << red[p]) | (bs << (uft.get_size(p) - red[p]));
    }
    int ans = n * (n-1) / 2;
    for (int i=0; i<=n; i++) {
        if (bs[i]) {
            ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
    }
    cout << ans << '\n';
    return 0;
}

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

#define FOR(i, l, r) for(long long int i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    int Q; cin >> Q;

    //エラトステネスの篩
    int MXN = 101010; 
    vector<bool> num(MXN, true);
    num[0] = false; num[1] = false;
    for(ll i = 2; i * i <= MXN; i++) {
        if(num[i]){
            for(ll j = i*i; j <= MXN; j += i) num[j] = false;
        }
    }
    
    vector<int> ans(MXN, 0);
    rep(i,MXN-10){
        if(i%2 == 0) {
            ans[i] = 0;
            continue;
        }
        if(num[i] && num[(i+1)/2]) ans[i]++;
        if(i >= 2) ans[i] += ans[i-2];
    }

    queue<int> que;
    rep(i,Q){
        int l,r;
        cin >> l >> r;
        que.push( ans[r] - ans[max(l-2,0)] );
    }

    while(!que.empty()) {
        cout << que.front() << "\n";
        que.pop();
    }
    return 0;
}


Measured memory_bytes: 1408
# Euclidean Algorithm
def gdc(m, n):
    m, n = (m, n) if m > n else (n, m)
    while True:
        if n == 0:
            break
        else:
            m, n = n, m % n
    return m


A, B, K = [int(x) for x in input().split(" ")]
divisor = [x for x in list(range(1, gdc(A, B)+1)) if gdc(A, B) % x == 0]

print(divisor[::-1][K-1])

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

int left(int i){ return 2*i; }
int right(int i){return 2*i+1; }

void swap(int A[], int i, int j){
    int res = A[i];
    A[i] = A[j];
    A[j] = res;
}

void maxHeapify(int A[], int i, int n){
    int l = left(i);
    int r = right(i);
    int largest;
    if (l<=n && A[l] > A[i]){
        largest = l;
    } else {
        largest = i;
    }
    if (r<=n && A[r] > A[largest]) largest = r;
    if (largest != i){
        swap(A, i, largest);
        maxHeapify(A, largest, n);
    }
}

void buildMaxHeap(int A[], int n){
    for(int i=floor(n/2); i>0; --i){
        maxHeapify(A, i, n);
    }
}

int main(){
    int n; cin >> n;
    int heap[n+1];
    for(int i=1; i<=n; ++i){
        cin >> heap[i];
    }
    buildMaxHeap(heap, n);
    for(int i=1; i<=n; ++i){
        cout << " " << heap[i];
    }
    cout << endl;
}

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

int main() {
    int N;  cin >> N;
    vector<int> H(N);
    int n = 1;

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

    int high = H[0];

    for (int j = 1; j < N; ++j) {
        if(H[j] >= high){
            high = H[j];
            n++;
        }
    }
    cout << n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

vector<int> s,c;

int main() {
    int n,m;
    cin >> n >> m;
    s.resize(m),c.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> s[i] >> c[i];
    }

    if(n == 1){
        for (int i = 0; i < 10; ++i) {
            int cnt = 0;
            for (int j = 0; j < m; ++j) {
                if(s[j] == 1 && c[j] == i) cnt++;
            }
            if(cnt == m){
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;
        return 0;
    }

    if(n == 2){
        for (int i = 10; i < 100; ++i) {
            int cnt = 0;
            for (int j = 0; j < m; ++j) {
                int ue,naka;
                ue = (i/10);
                naka = (i%10);
                if(s[j] == 1 && c[j] == ue) cnt++;  // hitoketame
                if(s[j] == 2 && c[j] == naka) cnt++;  // huta
            }
            if(cnt == m){
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;
        return 0;
    }

    if(n == 3){
        for (int i = 100; i < 1000; ++i) {
            int cnt = 0;
            for (int j = 0; j < m; ++j) {
                int ue,naka,sita;
                ue = (i/100);
                sita = (i%10);
                int tmp = i;
                tmp /= 10;
                naka = (tmp%10);
                if(s[j] == 1 && c[j] == ue) cnt++;  // hitoketame
                if(s[j] == 2 && c[j] == naka) cnt++;  // huta
                if(s[j] == 3 && c[j] == sita) cnt++;
            }
            if(cnt == m){
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;
        return 0;
    }

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> h(n);

    for (auto i = 0; i < n; i++)
    {
        int xi, yi, hi;
        cin >> xi >> yi >> hi;
        x[i] = xi;
        y[i] = yi;
        h[i] = hi;
    }

    ll ans_x, ans_y, ans_h;

    for (auto cx = 0; cx <= 100; cx++)
    {
        for (auto cy = 0; cy <= 100; cy++)
        {
            ll H;
            bool flag = true;

            for (auto i = 0; i < n; i++)
            {
                if (h[i] != 0)
                {
                    H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                }
            }

            for (auto i = 0; i < n; i++)
            {
                ll tmp_H;
                if (h[i] == 0)
                {
                    if(H - abs(cx-x[i]) - abs(cy-y[i]) > 0){
                        flag = false;
                        break;
                    }
                    continue;
                }
                tmp_H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                if (H != tmp_H)
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                ans_x = cx;
                ans_y = cy;
                ans_h = H;
            }
        }
    }

    cout << ans_x << " " << ans_y << " " << ans_h << "" << endl;
}

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

const double eps = 1e-9;
inline bool equals(double a, double b) { return fabs(a - b) < eps ;}

class Point {
public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {};

    Point operator + (Point p) { return Point(x + p.x, y + p.y); }
    Point operator - (Point p) { return Point(x - p.x, y - p.y); }
    Point operator * (double a) { return Point(a * x, a * y); }
    Point operator / (double a) { return Point(x / a, y / a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x * x + y * y; }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
    }
};
typedef Point Vector;

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

struct Segment {Point p1, p2;};

Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / base.norm();
    return s.p1 + base * r;
}

Point symmetry(Segment s, Point p) {
    return p + (project(s, p) - p) * 2.0;
}

int main(void) {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Segment s = {Point(x1, y1), Point(x2, y2)};
    int q;
    cin >> q;
    while (q--) {
        double x, y;
        cin >> x >> y;
        Point ans = symmetry(s, Point(x, y));
        printf("%.10f %.10f\n", ans.x, ans.y);
    }
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  REP(i,1,n+1) {
    if( i % 3 == 0 || i % 5 == 0 ) continue;
    sum += (ll)i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	int n;
	double D1 = 0,D2 = 0,D3 = 0,Di = 0;
	cin >> n;
	int x[n],y[n];
	for(int i = 0;i < n;i++) cin >> x[i];
	for(int i = 0;i < n;i++) cin >> y[i];
	
	for(int i = 0;i < n;i++){
		if(x[i] - y[i] < 0) D1 += y[i] - x[i];
		else D1 += x[i] - y[i];
	}
	
	for(int i = 0;i < n;i++){
		D2 += (x[i] - y[i]) * (x[i] - y[i]);
	}
	D2 = sqrt(D2);
	
	for(int i = 0;i < n;i++){
		if(x[i] - y[i] < 0) D3 += pow((y[i] - x[i]),3);
		else D3 += pow((x[i] - y[i]),3);
	}
	
	D3 = pow(D3,1/3.0);
	
	for(int i = 0;i < n;i++){
		if(x[i] - y[i] < 0){
			if(Di < y[i] - x[i]) Di = y[i] - x[i];
			}else{
				if(Di < x[i] - y[i]) Di = x[i] - y[i];
			}
	}
			
	printf("%5lf\n%5lf\n%5lf\n%5lf\n",D1,D2,D3,Di);
				return 0;
	}

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

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	ll sum = 0;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
		sum += a;
	}
	ll mn = 1000000000;
	ll b = 0;
	rep(i,0,n){
		b += v[i];
		mn = min(mn,abs(2*b-sum));
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
// #include <functional>

using namespace std;

void solve()
{
    // 入力の処理
    long long A, B;
    cin >> A >> B;

    long long x = A * B;
    if (A < B)
    {
        long long temp;
        temp = A;
        A = B;
        B = temp;
    }

    while (A % B != 0)
    {
        long long temp;
        temp = B;
        B = A % B;
        A = temp;
    }

    cout << x / B << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int main()
{
	int i,j;
	string s;
	cin>>s;
	j=0;
	for(i=0;i<s.length();i++)
	{
		if(s[i]=='7')
		{
			cout<<"Yes"<<endl;
			j=1;
			break;
		}
	}
	if(j==0)
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  ll n, x; cin >> n >> x;
  ll g = __gcd(n, x);
  n /= g, x /= g;
  cout << ((n - 1) * 3ll * g) << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long[] t = new long[n];
		long x = 1;
		for(int i=0; i<n; i++){
			a[i] = sc.nextLong();
			t[i] = sc.nextLong();
		}
		for(int i=1; i<n; i++){
			long xa, xt;
			if(x*a[i-1]%a[i] == 0){
				xa = x*a[i-1]/a[i];
			}else{
				xa = x*a[i-1]/a[i]+1;
			}

			if(x*t[i-1]%t[i]==0){
				xt = x*t[i-1]/t[i];
			}else{
				xt = x*t[i-1]/t[i]+1;
			}
			x = xa > xt ? xa : xt;
		}

		System.out.println(x * (a[n-1]+t[n-1]));
	}

}

Measured memory_bytes: 13528
#include<iostream>
#include<algorithm>
using namespace std;
using lint=int64_t;

int main()
{
	int N;
	pair<lint,lint> p[200010];

	cin >> N;
	for(int i=1;i<=N;i++)
	{
		cin >> p[i].second;
		cin >> p[i].first;
	}
	sort(p+1,p+1+N);
	
	int time=0;
	lint sum=0;
	for(int i=1;i<=N;i++)
	{
		sum+=p[i].second;
		time=p[i].first;
		if(sum>time)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



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

int main() {
  string s;
  cin >> s;
  string ans;
  if(s=="Sunny") ans="Cloudy";
  if(s=="Cloudy") ans="Rainy";
  if(s=="Rainy") ans="Sunny";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const ll inf = 1e18;

ll cost[51][51];
void build(int s){
	rep(i, 51) cost[s][i] = inf;
	cost[s][s] = 0;
	rep(it, 51){
		vector<ll> prev(51);
		rep(i, 51) prev[i] = cost[s][i];
		rep(i, 51) for(int j = 1; j <= i; j++) cost[s][i % j] = min(cost[s][i % j], max((ll)j, prev[i]));
	}
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	rep(s, 51) build(s);
	int n; cin >> n;
	vi a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	
	ll ans = 0;
	rep(i, n) if(cost[a[i]][b[i]] == inf){
		cout << -1 << endl;
		exit(0);
	}
	vector<ll> can(n);
	rep(i, n) can[i] |= 1ll << a[i];
	
	while(1){
		ll mx = 0;
		rep(i, n){
			ll mn = inf;
			rep(j, 51) if(can[i] >> j & 1) mn = min(mn, cost[j][b[i]]);
			mx = max(mx, mn);
		}
		if(mx == 0) break;
		ans += 1ll << mx;
		rep(i, n) for(int j = 1; j <= 50; j++) if(can[i] >> j & 1) can[i] |= 1ll << j % mx;
	}
	cout << ans << endl;
	
	return 0;
}

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

#define int long long

using namespace std;

int n;
int a[200001];
int sum[200001];

bool bin_check(int x) {

    int p1 = 0, p2 = 0;
    int sum1 = 0, sum2 = 0;

    // Shakutori
    for(int i = 0; i < n; ++i) {

        // 1
        while(sum1 < x) {
            sum1 += a[p1];
            if(p1 < p2) sum2 -= a[p1];
            ++p1;
        }

        // 2
        if(!i) p2 = p1;
        while(sum2 < x) {
            sum2 += a[p2];
            ++p2;
        }

        // 3
        if(sum[n + i] - sum[p2] >= x) {
            return true;
        }

        sum1 -= a[i];
    }

    return false;

}

main() {

    cin >> n;

    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        a[n + i] = a[i];
    }

    sum[0] = 0;
    for(int i = 1; i <= 2 * n; ++i) {
        sum[i] = sum[i - 1] + a[i - 1];
    }

    int l = 0, m, r = sum[n] / 3;
    while(l + 1 < r) {
        m = (l + r) / 2;
        if(bin_check(m)) {
            l = m;
        } else {
            r = m;
        }
    }

    cout << l << endl;

}

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

int const N=3e3+5, M=(N+1)/2, OO = 0x3f3f3f3f;


int n;
double arr[N];

double mem[N][M];
double solve(int i, int tcnt)
{
    if(i==n)
        return 1.0;
    if(mem[i][tcnt]>=0)
        return mem[i][tcnt];
    double ret=0;
    ret+=((tcnt+1<n-tcnt-1) ? solve(i+1,tcnt+1)*(1-arr[i]) : 0);
    ret+=solve(i+1,tcnt)*arr[i];
    return mem[i][tcnt]=ret;
}



int main()
{
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%lf",arr+i);
    for(int i=0; i<n; i++)
        for(int j=0; j<(n+1)/2; j++)
            mem[i][j]=-1.0;
    cout<<fixed<<setprecision(12)<<solve(0,0)<<endl;


    return 0;

}


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

int main (void){
  int n,w,start,goal,x,y,gosen,man,sen;
//*
  cin>>n>>w;;

  start=1000*n;
  goal=(w-start)/1000;
 // cout<<"goal:"<<goal<<endl;
  goal=goal+4;
  x=goal/9;
  x*=2;
  if(goal%9<=4)
  {
    y=goal%9;y*=2;
  }
  else
  {
    y=goal%9-4;
    y*=2;
    y--;
    x++;
  }

//cout<<"x="<<x<<",y="<<y<<endl;
  if(x+y<8||y-x<-2*n+8)
  {
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
  }
  else
  { 
    y=8-y;
    man=(x-y)/2;
    gosen=y;
    sen=n-man-gosen;
    cout<<man<<" "<<gosen<<" "<<sen<<endl;
  }
 
}



Measured memory_bytes: 3612
#include <stdio.h>
#define MIN(x,y)	((x)<(y)?(x):(y))

int main(){
    int n, m, x, a[101]={0}, b;
    scanf("%d%d%d", &n, &m, &x);

    for(int i=0; i<m; i++){
        scanf("%d", &b);
        a[b]++;
    }

    int cnt1=0, cnt2=0;
    for(int i=x; i<n; i++){
        if( a[i] ){ cnt1++; }
    }
    for(int i=x; i>0; i--){
        if( a[i] ){ cnt2++; }
    }

    printf("%d\n", MIN( cnt1, cnt2 ));
    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int n;cin>>n;
    int h, before;cin>>before;
    int cnt=0, ans=0;
    rep(i,n-1){
        cin>>h;
        if(before>=h){cnt++;}
        else{ans=max(cnt, ans);cnt=0;}
        before=h;
    }
    co(max(ans, cnt));
}

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

int h[100009], d[100009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> h[i];
	d[1] = 0; d[2] = abs(h[1] - h[2]);
	for (int i = 3; i <= n; i++)
		d[i] = min(d[i - 1] + abs(h[i] - h[i - 1]), d[i - 2] + abs(h[i] - h[i - 2]));
	cout << d[n] << '\n';
	return 0;
}

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

int main(void){

  int H,W;
  cin >>H>>W;

  int a[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >>a[i][j];
    }
  }
  int ans_x[H*W];
  int ans_xd[H*W];
  int ans_y[H*W];
  int ans_yd[H*W];
  int counter=0;

  for(int i=0;i<H-1;i++){
    for(int j=0;j<W;j++){
      if(a[i][j]%2!=0){
        a[i+1][j]+=1;
        ans_x[counter]=i+1;
        ans_xd[counter]=i+2;
        ans_y[counter]=j+1;
        ans_yd[counter]=j+1;
        counter++;
      }
    }
  }

  for(int i = 0;i < W-1;i++){
    if(a[H-1][i] % 2 != 0){
      a[H-1][i+1]+=1;
      ans_x[counter]=H;
      ans_xd[counter]=H;
      ans_y[counter]=i+1;
      ans_yd[counter]=i+2;
      counter++;
    }
  }

  cout << counter <<endl;
  //print
  for(int i = 0;i < counter;i++){
    cout << ans_x[i] << " " << ans_y[i] << " " << ans_xd[i] << " " << ans_yd[i] << endl;
  }


  return 0;
}


Measured memory_bytes: 6784
<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
//$R = trim(fgets(STDIN));
list($TM,$TA,$AM,$AA) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));


while(1) {
  $AM = $AM - $TA;
  if ($AM <= 0) {
    printf("Yes\n");
    break;
  }
  $TM = $TM - $AA;
  if ($TM <= 0) {
    printf("No\n");
    break;
  }
}

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

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


Measured memory_bytes: 3092
use proconio::{fastout, input};
use std::cmp::max;
#[fastout]
fn main() {
    input! {mut r:String};

    let mut ans: i32 = 0;
    let mut cnt: i32 = 0;
    for s in r.chars() {
        if s == 'R' {
            cnt += 1;
        } else {
            cnt = 0;
        }
        ans = max(ans, cnt);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2112
/*Infor {{{
  > File Name: d.cpp
  > Author: samcompu
  > Mail: a1592710567@126.com
  > Website: https://www.samcompu.com
  > Created Time: 2018年08月25日 星期六 20时39分16秒
  }}}*/
#include <bits/stdc++.h>

using namespace std;

/*Abbreviation {{{ */
#define FOR(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define ROF(i,a,b) for (int i = (int)(a); i >= (int)(b); i--)
#define FORLINE(i, t) for (int i = fi[t]; i; i = ne[i])
typedef long long ll;
typedef unsigned long long int ull;
/*}}}*/

/*Constant {{{*/
const long long eps = 100000;
/*}}}*/

/*Class {{{*/
/*}}}*/

/*Variable {{{*/
long long n, a[100005], b[100005], ans;
long long sum[100005], num[200005];
/*}}}*/

/*Declare {{{*/
long long check(long long);
/*}}}*/

/*Main {{{*/
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for(long long i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  long long m = unique(b + 1, b + n + 1) - b - 1;
  long long l = 1, r = m;
  long long num = n * (n + 1) / 2 - n * (n + 1) / 2 / 2;
  while(l <= r) {
    long long mid = (l + r) >> 1;
    long long mem = check(b[mid]);
    if(mem >= num) {
      ans = b[mid]; l = mid + 1;
    } else r = mid - 1;
  } 
  cout << ans << endl;
  return 0;
}
/*}}}*/

/*Define {{{*/
long long check(long long x) {
  long long res = 0;
  memset(sum, 0, sizeof(sum));
  memset(num, 0, sizeof(num));
  for(int i = 1; i <= n; i++) {
    if(a[i] >= x) sum[i] = sum[i - 1] + 1;
    else sum[i] = sum[i - 1] - 1;
  } 
  long long pre = 0; num[eps] = 1;
  for(int i = 1; i <= n; i++) {
    if(sum[i] > sum[i - 1]) pre += num[sum[i] + eps] + 1;
    else pre -= num[sum[i - 1] + eps] - 1;
    num[sum[i] + eps]++; 
    res += pre;
  }
  return res;
}
/*}}}*/


Measured memory_bytes: 4224
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()
	k := getInt()
	x := k - 1

	i := -1
	for j := 1; j <= n; j++ {
		if tmp := getInt(); tmp == 1 {
			i = j
		}
	}

	count := ((i-1)+x-1)/x + ((n-i)+x-1)/x
	if ((i-1)%x+(n-i)%x <= x) && ((i-1)%x > 0 && (n-i)%x > 0) {
		count--
	}

	fmt.Println(count)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

using namespace std;

int main() {
    string s, ans = "Yes";
    cin >> s;

    int cont = 1;
    for(char letter : s) {
        if (cont&1) {
            if (letter != 'R' && letter != 'U' && letter != 'D')
                ans = "No";
        }
        else {
            if (letter != 'L' && letter != 'U' && letter != 'D')
                ans = "No";
        }
        cont++;
    }
    cout << ans << '\n';

    return 0;
}

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;

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

    int result = 0;
    for (int i = 0; i < n; ++i) {
        int a = x[i] * 2;
        int b = (k - x[i]) * 2;
        result += min(a, b);
    }
    cout << result << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
void solve()
{
	string s,t,u;
	cin>>s>>t;
	ll a,b;
	cin>>a>>b;
	cin>>u;
//	cout<<a<<" "<<b;
	if(s==u)
	a=a-1;
	else
	b=b-1;
	cout<<a<<" "<<b;
}
int main()
{
	solve();
}

Measured memory_bytes: 256
/*

    idea: start from the end and try to reach the beginning taking the longest jumps possible.

*/


#include<bits/stdc++.h>


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 1;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;
vi ans , v;

void solve(int testCase){

    scanf("%d %d" , &n , &m);

    string s;
    cin >> s;

    // to start from the end
    reverse(s.begin() , s.end());

    // store all positions of 0's
    for(int i = 0 ; s[i] ; i ++){
            if(s[i] == '0'){
                    v.push_back(i);
            }
    }

    // initial position
    int pos = 0;

    while( pos != n ){

            // farthest place I can go
            int nxt = upper_bound(v.begin() , v.end() , pos + m) - v.begin() - 1;

            // if I'm still in my place => no solution
            if(v[nxt] == pos){
                    printf("-1\n");
                    return;
            }

            // insert the length of the jump into the answer
            ans.push_back(v[nxt] - pos);

            // update position
            pos = v[nxt];
    }

    // print the answer backwards: from begin to end.
    reverse(ans.begin() , ans.end());

    for(int A : ans)printf("%d " , A);
    printf("\n");

}

main(){

    int t = 1;
    //scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 1592
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;
typedef tuple<int, int, int, int> T;	//(w+s, w, s, v)

int INF = 1e+15;
int n;
T item[1000];
int dp[30001];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) {
		int w, s, v;
		cin >> w >> s >> v;
		item[i] = T(w + s, w, s, v);
	}
	sort(item, item + n);
	
	rep(i, 30001) dp[i] = -INF;
	dp[0] = 0;
	
	rep(i, n) {
		int w = get<1>(item[i]);
		int s = get<2>(item[i]);
		int v = get<3>(item[i]);
		rrep(j, s + 1) {
			dp[j + w] = max(dp[j + w], dp[j] + v);
		}
	}
	
	int ans = -INF;
	rep(i, 30001) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
using namespace std;
int main (){
    char s;
    string t;
    for(int i=0; i<3;i++){
        for(int j=0; j<3; j++){
            cin >> s;
            if( i == j ) {
                t += s;
            }
        }
    }
    cout << t << endl;
    return 0;
}


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

const int INF = 1e9+7;

int field[52][52];
int dist[52][52];

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

int main(){
    int h,w;
    cin>>h>>w;
    rep(i,52){
        rep(j,52){
            field[i][j] = -1;
            dist[i][j]=INF;
        }
    }
    int cnt=0;
    REP(i,h){
        string s;
        cin>>s;
        REP(j,w){
            if(s[j-1]=='.'){
                field[i][j]=0;
                cnt++;
            }else{
                field[i][j]=1;
            }
        }
    }

    queue<pii> que;
    que.push(make_pair(1,1));
    dist[1][1]=0;


    while(!que.empty()){
        pii t = que.front();que.pop();
        int x = t.first; int y = t.second;

        rep(i,4){
            if(field[x+dx[i]][y+dy[i]]==0&&dist[x+dx[i]][y+dy[i]]==INF){
                dist[x+dx[i]][y+dy[i]]=dist[x][y]+1;
                que.push(make_pair(x+dx[i],y+dy[i]));
            }
        }
    }



    if(dist[h][w]==INF){
        cout<<-1<<endl;
        return 0;
    }

    cout<<cnt-dist[h][w]-1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	cout << n * n * n << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
  
            Scanner scan = new Scanner(System.in);
  
            double r =  scan.nextDouble();
            double s,l,p = 3.141592653589;
          
            s = r*r*p;
            l = 2*r*p;
  
           System.out.printf("%f %f\n",s,l);
        }
}

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

int main() {
  string s;
  char moji = 'a';

  cin >> s;
  sort(s.begin(), s.end());

  for (int i = 0; i < (int)s.size(); i++)
    if (s[i] == moji) moji++;

  if (moji == 123)
    cout << "None";
  else
    cout << moji;

  return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  ll x;
  cin >> x;
  for (ll aa = -200; aa <= 200; aa++) {
    for (ll bb = -200; bb <= 200; bb++) {
      if ((aa * aa * aa * aa * aa - bb * bb * bb * bb * bb) == x) {
        cout << aa << " " << bb << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

#define ll long long int
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define MOD 1e9 + 7
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mt make_tuple
#define fi first
#define se second
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define sum(v) accumulate(all(v), 0)
#define cinv(v, n) rep(i, n) cin >> v[i]
#define prec(n) fixed << setprecision(n)
#define odd(n) ((n) % 2)
#define even(n) (!((n) % 2))
#define end return 0

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (0 <= a) {
    cout << "Positive" << endl;
    end;
  }
  if (a < 0 && 0 <= b) {
    cout << "Zero" << endl;
    end;
  }
  cout << (odd(b - a) ? "Positive" : "Negative") << endl;
  end;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b, c;
    cin >> a >> b >> c;
    long long x = 4 * a * b, y = c - a - b;
    if (y <= 0)
        cout << "No\n";
    else {
        y *= y;
        cout << (x < y ? "Yes\n" : "No\n");
    }
}


Measured memory_bytes: 256
n,c,k = map(int, input().split())
t = []
for i in range(n):
    t.append(int(input()))
t.sort()

ni,nt,ans = 0,0,0
while 1:
    if ni >= n:
        break
    nt = t[ni]
    for i in range(1,c+1):
        if ni>=n or t[ni] > nt + k:
            break
        ni += 1
    ans += 1
print(ans)


Measured memory_bytes: 7440
import java.util.*;


public class Main{

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

   public static void main(String[] args){
       Scanner sc =new Scanner(System.in);
       long n,x,a;
       n=sc.nextInt();
       x=sc.nextInt();
       long ans=0;
       for(long i=0;i<n;i++){
           a=sc.nextInt();
           if(i==0)ans=(long)Math.abs(a-x);
           else ans=(long)gcd(ans,Math.abs(a-x));
       }
       System.out.println(ans);
   }
}

Measured memory_bytes: 47624
#n, q = gets.chomp.split(" ").map(&:to_i);
s = gets.chomp
t = gets.chomp

# validate
t.each_char do |c|
  unless s.include?(c)
    puts "-1"
    exit 0
  end
end

count = 0
s_index = 0
t_index = 0

while true do
  if count > s.size*(10**100)
    puts "-1"
    exit 0
  end
      if (t_index == (t.size))
    break
  end
  
  result = s.index(t[t_index], s_index)
  unless result.nil?
    count += (result + 1) - s_index
#    puts "c:" + count.to_s + ":" + t[t_index]
    s_index = (result + 1)
    t_index += 1
  else
    count += s.size - s_index
 #   puts "l:" + count.to_s + ":" + t[t_index]

    s_index = 0
  end
end

puts count

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> P(N), C(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    for(int i = 0; i < N; i++) cin >> C[i];
    long long ans = -1e18;
    vector<int> used(N, 0);
    vector<vector<long long>> vec(N);
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(used[i] == 1) continue;
        int flag = 0;
        int ind = i, ind2 = i;
        while(flag == 0 || ind != ind2){
            flag = 1;
            vec[cnt].push_back(C[ind]);
            used[ind] = 1;
            ind = P[ind];
        }
        cnt++;
    }
    vector<vector<long long>> memo(cnt, vector<long long>(N, -1e18));
    for(int i = 0; i < cnt; i++){
        long long siz = vec[i].size();
        long long temp = 0;
        long long res = 0;
        for(int j = 0; j < siz; j++){
            long long t = 0;
            for(int k = 0; k < siz; k++){
                t += vec[i][(j + k) % siz];
                memo[i][k] = max(memo[i][k], t);
            }
            temp += vec[i][j];
        }
        if(temp > 0) {
            res += K / siz * temp;
            long long temp2 = 0;
            if(K / siz > 0){
                temp2 = (K / siz - 1) * temp;
                long long m = *max_element(memo[i].begin(), memo[i].begin() + siz);
                temp2 += m;
            }
            if(K % siz > 0){
                long long t = *max_element(memo[i].begin(), memo[i].begin() + K % siz);
                res += t;
            }
            ans = max(res, ans);
            ans = max(temp2, ans);
        }
        else{
            long long r = *max_element(memo[i].begin(), memo[i].begin() + min(K, siz));
            res += r;
            ans = max(res, ans);
        }
    }
    cout << ans << endl;
}


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

int main() {
  ll l, r;
  cin >> l >> r;
  r = min(l+4038, r);
  int ans = 2019;
  
  for (ll i = l; i <= (r); ++i){
    for (ll j = i+1; j <= (r); ++j){
      int x = (i*j)%2019;
      ans = min(x, ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<string>
#define mod 1000000007
#define ll long long
using namespace std;
map<int,int> mp;
int num[200000];
int main()
{
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
    int N;
    cin>>N;
    for(int i=1;i<=N;i++)
    cin>>num[i];
    int ans=0;
    for(int i=1;i<=N;i++)
    {
    	if(i==num[i])
    	{
    		
    		if(num[i+1]==i+1)
    		{
    			swap(num[i],num[i+1]);
    		    ans++;
			}
			else
			{
				ans++;
				if(abs(i-1-num[i-1])>abs(i+1-num[i+1]))
				{
					swap(num[i],num[i-1]);
				}
				else
				swap(num[i],num[i+1]);
			}
			i++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,sum=0,i,j,k;
	cin>>a>>b>>c>>d;
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			for(k=0;k<=c;k++){
				if(i*500+j*100+k*50==d){
					sum++;
				}
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

int main() {
  string n;
  cin >> n;
  long long ans=0;
  for(int i=0;i<(1<<n.size()-1);i++) {
    bitset<10> temp(i);
    int first=0;
    long long sum=0;
    for(int i=0;i<n.size()-1;i++) {
      if(temp.test(i)) {
        if(i==first) {
          sum+=int(n.at(first))-48;
        }
        else {
          sum+=stoll(n.substr(first,i-first+1));
        }
        first=i+1;
      }
    }
    if(n.size()-1==first) {
      sum+=int(n.at(first))-48;
    }
    else {
      sum+=stoll(n.substr(first));
    }
    ans+=sum;
  }
  cout << ans << endl;
}

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

using namespace std;
 
int main(){
 int N=0;
 cin >> N;
 vector<int> vec(N);
 for(int i=0; i<N; i++){
 cin>> vec.at(i);
 }
 sort(vec.begin(), vec.end());
  
 for(int i=0;i<N-1;i++){
  if(vec.at(i)==vec.at(i+1)){
  cout<<"NO"<<endl;
  return 0;
  }
  else{
  }  
 }
   cout<<"YES"<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    if(s[n-1] == 's'){
        //s.resize(n);
        s += "es";
    }
    else{
        //s.resize(n);
        s += 's';
    }
    cout << s << endl;
}

Measured memory_bytes: 3620
input = raw_input

h, w = map(int, input().split(" "))

meiro = []
coords = []
for i in range(h):
    line = list(input())
    cur_coords = [(j, i) for j in range(w) if line[j] == "."]
    coords += cur_coords
    meiro.append(line)

graphs = []
graph = {}
for cur_coord in coords:
    x, y = cur_coord
    tugi_kouhos = [(x+dx, y) for dx in [-1, 1] if 0 <= x+dx < w]
    tugi_kouhos += [(x, y+dy) for dy in [-1, 1] if 0 <= y+dy < h]
    childs = []
    for tugi_kouho in tugi_kouhos:
        if tugi_kouho in coords:
            childs.append(tugi_kouho)
    graph[cur_coord] = childs



def calc_depth(coord1):

    cur_coord = coord1
    #end_coord = coord2
    cur_depth = 0
    used_coords = [coord1]

    childs = graph[coord1]
    while len(childs) != 0:
        cur_depth += 1
        next_childs = []
        used_coords += childs

        num_res_s = []
        for child in childs:
            res = get_childs(child, used_coords)
            #print("child", child, res)
            #print(used_coords)
            num_res = len(res)
            num_res_s.append(num_res)
            next_childs += res
        if max(num_res_s) == 0:
            return cur_depth

        childs = list(set(next_childs))
        #print(childs)

    return 0

def get_childs(jibun, used_coords):
    
    childs = []
    for child in graph[jibun]:
        if child not in used_coords:
            childs.append(child)
    return childs
       
n_coords = len(coords)
max_depth = 0
for i in range(n_coords):
    coord1 = coords[i]
    cur_depth = calc_depth(coord1)
    max_depth = max(max_depth, cur_depth)

print(max_depth)

Measured memory_bytes: 34024
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int n,a;
  cin >> n >> a;
  if(n % 500 <= a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
  
}

Measured memory_bytes: 256