akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

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

int n;
int a[1000000];
int vcnt[1000001];
bool isPrime[1000001];
int cnt[1000001];	//cnt[p] = 素因数pを持つa[i]の個数

bool checkPair() {
	int i, j;
	
	int MAX = 1000000;
	for (i = 2; i <= MAX; i++) isPrime[i] = true;
	for (i = 2; i <= MAX; i++) {
		if (isPrime[i]) {
			cnt[i] += vcnt[i];
			for (j = i * 2; j <= MAX; j += i) {
				isPrime[j] = false;
				cnt[i] += vcnt[j];
			}
		}
	}
	
	for (i = 2; i <= MAX; i++) {
		if (cnt[i] >= 2) break;
	}
	if (i > MAX) { return true; }
	return false;
}

signed main() {
	int i, j;
	
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", a + i);
		vcnt[a[i]]++;
	}
	
	if (checkPair()) {
		cout << "pairwise coprime" << endl;
		return 0;
	}
	
	int g = a[0];
	rep(i, n) { g = gcd(g, a[i]); }
	if (g == 1) { cout << "setwise coprime" << endl; return 0; }
	
	cout << "not coprime" << endl;
	return 0;
}

Measured memory_bytes: 16448
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const ll MAX=9187201950435737471;
const int N=1000006;
const ll INF=-1e12;
const long double PI=acos(-1);



void solve(int T){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)cout<<k;
    else {
        k-=a;
        k-=b;
        if(k>0){
            a-=k;
        }
        cout<<a;
    }
}

int main() {
    //fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
    }
	return 0;
}


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

long long n;
long long a[5];
long long m=0;

void solve(){
  cin >> n;
  rep(i, 5) cin >> a[i];
  for(int i=0; i<5; i++){
    if(n%a[i]!=0) m = max(m, n/a[i]);
    else m=max(m, n/a[i]-1);
  }
  cout << 5+m << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  ll sum=0;
  ll ans=0;
  rep(i,N){
    ans+=A[i]*sum%MOD;
    ans%=MOD;
    sum+=A[i];
    sum%=MOD;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4780
#include<iostream>
#include<cmath>

using namespace std;

int main(void) {
    int N;
    int s[100];
    int score = 0;
    int m = 100;

    cin>>N;
    for(int i = 0;i < N;i++) {
	cin>>s[i];
	score += s[i];
	if(s[i] % 10 != 0)
	    m = min(m,s[i]);
    }

    if(score % 10 == 0)
	score -= m;

    if(score % 10 == 0)
	cout<<0<<endl;
    else
	cout<<score<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int N; cin >> N;
    int M; cin >> M;
    vector<int> A(M), B(M); REP(i, 0, M) cin >> A[i] >> B[i];

    vector<vector<int>> link(N);
    REP(i, 0, M){
        link[A[i] - 1].push_back(B[i] - 1);
        link[B[i] - 1].push_back(A[i] - 1);
    }
    REP(i, 0, N){
        if (link[i].size() == 0){
            cout << "No" <<endl;
            return 0;
        }
    }

    vector<int> guide(N, -1);
    queue<int> que;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        // vから辿れる頂点をすべて調べる
        for (auto v_new: link[v]){
            if (guide[v_new] != -1) continue; // すでに発見済みの頂点は探索しない

            guide[v_new] = v;
            que.push(v_new);
        }
    }

    cout << "Yes" <<endl;
    REP(i, 1, N){
        cout << guide[i] + 1 << endl;
    }

    return 0;
}


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

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

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

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

#define MOD 1000000007

int main(){
	int n,m;
	cin>>n>>m;
	// ans = max{x | m%x==0 && m>=nx}
	int ans = 1;
	for(int x=1;x*x<=m;x++){
		if(m%x!=0)continue;
		if(m/x >= n){
			CHMAX(ans, x);
		}
		if(x >= n){
			CHMAX(ans, m/x);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
	int N, D, X, A, i;
	scanf("%d%d%d", &N, &D, &X);
	for(i = 0; i < N; i++){
		scanf("%d", &A);
		X += (D + A - 1) / A;
	}
	printf("%d\n", X);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	cin >> N;
	vl A(N);
	rep(i, N)
		cin >> A[i];
	ll ans = 1000;
	rep(i, N - 1) {
		if (A[i] < A[i + 1]) {
			ll K = ans / A[i];
			ans += K * (A[i + 1] - A[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
import sys
# input = sys.stdin.buffer.readline
def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        sys.exit()
    p = tuple(map(int, input().split()))
    cnt = 0
    while True:
        xt = x - cnt
        if xt not in p:
            print(xt)
            sys.exit()
        xt2 = x + cnt
        if xt2 not in p:
            print(xt2)
            sys.exit()
        cnt += 1

if __name__ == '__main__':
    main()



Measured memory_bytes: 9212
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int a;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	int N;
	long long a[10000];

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

	int n[10000];
	for(int i=0;i<N;i++) n[i] = 0;
	for(int i=0;i<N;i++){
		while(a[i]%2==0){
			n[i]++;
			a[i]/=2;
		}
	}

	int ans = 0;
	for(int i=0;i<N;i++) ans += n[i];

	printf("%d\n", ans);

	return 0;
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int x; cin >> x;
    x -= 400;
    x/=200;
    cout << 8-x << "\n";
}

Measured memory_bytes: 3628
#include<stdio.h>

int main (void)
{
    int n, m;

    scanf("%d", &n);

    if (400 <= n && 599 >= n) {
        m = 8;
    }
    else if (600 <= n && 799 >= n) {
        m = 7;
    }
    else if (800 <= n && 999 >= n) {
        m = 6;
    }
    else if (1000 <= n && 1199 >= n) {
        m = 5;
    }
    else if (1200 <= n && 1399 >= n) {
        m = 4;
    }
    else if (1400 <= n && 1599 >= n) {
        m = 3;
    }
    else if (1600 <= n && 1799 >= n) {
        m = 2;
    }
    else if (1800 <= n && 1999 >= n) {
        m = 1;
    }
    printf("%d", m);
    return 0;
}

Measured memory_bytes: 1732
N = int(input())
As = list(map(int, input().split()))


def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x % y, y)


L = []
R = []

L.append(0)
R.append(0)

for i in range(N - 1):
    L.append(gcd(L[i], As[i]))
    R.append(gcd(R[i], As[N-i-1]))


ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[N-i-1]))

print(ans)


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

int main(){
  int n;cin>>n;
  int v[n],vv[n];
  for(int i=0;i<n;i++){
    cin>>v[i];vv[i]=v[i];
  }
  sort(v,v+n);
  int b=v[n/2-1],u=v[n/2];
  for(int i=0;i<n;i++){
    if(vv[i]<u)cout<<u<<endl;
    else cout<<b<<endl;
  }
}

Measured memory_bytes: 3712
n,t=list(map(int,input().split(" ")))
list_ct=[]
list_ctT=[]
for count in range(n):
    list_ct.append(list(map(int,input().split(" "))))

for count in range(n):
    if list_ct[count][1]<=t:
        list_ctT.append(list_ct[count][0])
    else:
        pass
if list_ctT!=[]:
    print(min(list_ctT))
else:
    print("TLE")

Measured memory_bytes: 3064
a = input().split()
A = int(a[0])
V = int(a[1])
b = input().split()
B = int(b[0])
W = int(b[1])
T = int(input())
aida = abs(A - B)
if aida +  W * T <= V * T:
    print("YES")
else:
    print("NO")


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

int main(){
    int n,k;
    cin >> n >> k;
    int ctr=0;
    rp(i,n){
        int h;
        cin>> h;
        if(h>=k) ctr++;
    }
    cout << ctr << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC161
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_A();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var i = Ex.ReadIntArray();
            Ex.Cw($"{i[2]} {i[0]} {i[1]}");
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {

        }
    }
    public static class Ex
    {
        public static void Cw(object s)
        {
            Console.WriteLine(s);
        }
        public static void Cw(bool b)
        {
            if (b) Cw("Yes");
            else Cw("No");
        }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

using namespace std;

#define ll long long

const int N=1e6+5,MOD=1000000007;

int n,idx[N],a[N],q,m,u,v,tc,k,l,x,y,ans;

char s[N];

int main(){ 
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    scanf("%d%d",&n,&x);
    for(int i=-1000000;i<=1000000;i++){
        if (abs(x-i)<n)
            printf("%d ",i);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int LOW = INT_MIN;
int main(){
  int minv;
  int mx = LOW;
  int n;
  int data;
  cin >> n;
  cin >> data;
  minv = data;
  for(int i = 1;i < n;i++){
    cin >> data;
    mx = max(mx,data - minv);
    minv = min(minv,data);
  }
  cout << mx << endl;
  exit(0);
}

Measured memory_bytes: 1160
module.exports=function(e){var n={};function r(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)r.d(t,o,function(n){return e[n]}.bind(null,o));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=0)}([function(e,n,r){r(1)(r(2).readFileSync("/dev/stdin","UTF-8"))},function(e,n){e.exports=function(e){for(var n=e.split("\n")[0],r=n.length,t=0;t<r;t++)for(var o=r-1;o>=t;o--){if("keyence"==n.slice(0,t)+n.slice(o,r))return void console.log("YES")}console.log("NO")}},function(e,n){e.exports=require("fs")}]);

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

long long d[100009], md = 1000000007;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	int n = s.length();
	d[n - 1] = 1;
	for (int i = n - 2; i >= 0; i--)
		d[i] = (d[i + 1] * 3) % md;
	long long ans = 0, p = 1;
	for (int i = 0; i < n; i++) 
		if (s[i] == '1') {
			ans = (ans + p * d[i]) % md;
			p = (p * 2) % md;
		}
	ans = (ans + p) % md;
	cout << ans << '\n';
	return 0;
}	

Measured memory_bytes: 1232
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    int N, M;
    cin >> N >> M;
    vector<pair<int, int> > G[N], GG[N];

    rep(i, 0, M) {
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        G[l].push_back(make_pair(r, d));
        GG[r].push_back(make_pair(l, -d));
    }

    int vis[N], col[N];
    memset(vis, 0, sizeof(vis));
    memset(col, 0, sizeof(col));
    rep(i, 0, N) {
        if(not vis[i]) {
            col[i] = 0;
            vis[i] = 1;
            queue<int> q;
            q.push(i);
            while(!q.empty()) {
                int v = q.front(); q.pop();
                rep(p, 0, G[v].size()) {
                    if(vis[G[v][p].first]) {
                        if(col[v] + G[v][p].second != col[G[v][p].first]) {
                            cout << "No" << endl;
                            return 0;
                        }
                    } else {
                        col[G[v][p].first] = col[v] + G[v][p].second;
                        vis[G[v][p].first] = 1;
                        q.push(G[v][p].first);
                    }
                }

                rep(p, 0, GG[v].size()) {
                    if(vis[GG[v][p].first]) {
                        if(col[v] + GG[v][p].second != col[GG[v][p].first]) {
                            cout << "No" << endl;
                            return 0;
                        }
                    } else {
                        col[GG[v][p].first] = col[v] + GG[v][p].second;
                        vis[GG[v][p].first] = 1;
                        q.push(GG[v][p].first);
                    }
                }
            }
        }
    }
    cout << "Yes" << endl;

}


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

int main(){
	int n;
	cin>>n;
	rep(k,0,n){
		int d[10]={},a[11]={},b[11]={},at=0,bt=0;
		rep(i,0,10) cin>>d[i];
		bool f=1;
		rep(i,0,10){
			if(a[at]<d[i]){
				a[at+1]=d[i]; at++;
			}else if(b[bt]<d[i]){
				b[bt+1]=d[i]; bt++;
			}else{
				f=0; break;
			}
		}
		cout<<(f?"YES":"NO")<<endl;
	}
}

Measured memory_bytes: 1152
n,x = gets.split.map(&:to_i)
aa = gets.split.map(&:to_i).sort

if aa.inject(:+) == x
  puts n
  exit
end

ans = 0
aa.each do |a|
  if x >= a
    ans += 1
    x -= a
  else
    break
  end
end

puts [ans, n-1].min

Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define all(v) (v).begin(),(v).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    int n;
    lvec c(5,0);
    ll ans=0;
    cin>>n;
    svec s(n);
    rep(i,n){
        cin>>s[i];
        if(s[i][0]=='M') c[0]++;
        if(s[i][0]=='A') c[1]++;
        if(s[i][0]=='R') c[2]++;
        if(s[i][0]=='C') c[3]++;
        if(s[i][0]=='H') c[4]++;
    }
    sort(all(c));
    if(c[2]==0||c[3]==0||c[4]==0) cout<<0;
    else{
        if(c[1]==0) cout<<c[2]*c[3]*c[4];
        else{
            for(int i=0;i<3;i++){
                for(int j=i+1;j<4;j++){
                    for(int k=j+1;k<5;k++){
                        ans+=c[i]*c[j]*c[k];
                    }
                }
            }
             cout<<ans;
        }
    }
}

Measured memory_bytes: 6144
fn main() {
    proconio::input! {
        n: usize,
    }
    let mut r = vec![1u128; n];

    for m in 1..n {
        let mut i = m;
        while i < n {
            r[i] += 1;
            i += m + 1;
        }
    }
    for i in 0..n {
        r[i] *= i as u128 + 1;
    }
    let r: u128 = r.iter().sum();
    println!("{}", r);
}


Measured memory_bytes: 158296
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 3e2 + 10;

int f[maxn][maxn][maxn];

int main()
{
	int n, K, Mod;
	scanf("%d%d%d", &n, &K, &Mod);
	int ans = 0;
	for (int j = 1; j <= K; ++ j)
	{
		f[1][j][1] = 1;
		f[1][j][2] = j - 1;
		if (n == 1 && j == K)
		{
			(ans += f[1][j][1]) %= Mod;
			(ans += f[1][j][2]) %= Mod;
		}
	}
	for (int i = 2; i <= n; ++ i)
	{
		for (int j = 1; j <= K; ++ j)
		{
			int s = 0;
			for (int k = 1; k <= i + 1; ++ k)
				(s += f[i][j - 1][k]) %= Mod;
			f[i][j][i + 1] = s;
			s = 0;
			for (int k = 1; k <= i; ++ k)
				(s += f[i - 1][j - 1][k]) %= Mod;
			for (int k = 1; k <= i; ++ k)
				(f[i][j][k] += s) %= Mod;
			s = 0;
			for (int k = i - 1; k; -- k)
			{
				(s += f[i - 1][j][k]) %= Mod;
				(f[i][j][k] += s) %= Mod;
			}
			for (int k = 1; k <= i; ++ k)
			{
				f[i][j][k] = 1ll * f[i][j][k] * k % Mod;
			}
			if (i == n && j == K)
				for (int k = 1; k <= i + 1; ++ k)
					(ans += f[i][j][k]) %= Mod;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 114432
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    vector<long long int> h(n);
    for(int i = 0;i < n;i++){
        cin >> h[i];
    }

    h[0]--;
    for(int i = 1;i < n - 1;i++){
        if(h[i] - 1 <= h[i + 1] && h[i - 1] <= h[i] - 1){
            h[i]--;
        }
    }

    for(int i = 0;i < n - 1;i++){
        if(h[i] > h[i + 1]){
            cout << "No";

            return 0;
        }
    }

    cout << "Yes";

    return 0;
}

Measured memory_bytes: 1024
a = list(map(int,input().split()))

b = list(map(int,input().split()))

b.sort()

su = 0

for i in range(a[0]):
	if i == a[0]-1 and (a[1] > b[i] or a[1] < b[i]):break
	elif a[1] >= b[i]:
		su += 1
		a[1] -= b[i]
	else:
		break
print(su)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
  int n,k,a,sum = 0; cin >> n >> k;
  for(int i = 0; i < k;i++){
    cin >> a;sum +=a;
  }
  if(sum >= n) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#coding: utf-8
A, B, K = map(int,input().split())
if B-A < K:
    for i in range(B-A+1):
        print(A+i)
else:

    for i in range(K):
        print(A+i)
    if A+2*K-B > 0:
        KD = B-A-K+1
    else: KD = K
    for i in range(KD):
        print(B-KD+1+i)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define MOD 1000000007;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n {}, b {};
    cin >> n >> b;

    cout<<floor(log(n)/log(b)) + 1<<endl; 
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a%2==0){
		cout<<0<<endl;return 0;
	}
	if(b%2==0){
		cout<<0<<endl;return 0;
	}
	if(c%2==0){
		cout<<0<<endl;return 0;
	}
	long long d=(long long)a*b,e=(long long)a*c,f=(long long)b*c;
	if(d>e)d=e;
	if(d>f)d=f;
	cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);

int main(){
  ll x;
  cin >> x;
  if(x==1){
    cout << 1 << endl;
    return 0;
  }
  for(int i=1;i<1e5;i++){
    if(i*(i+1)/2 < x && x<=(i+1)*(i+2)/2){
      cout << i+1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a<=b){
			if(b <= c){
				System.out.println(a+b);
			}else{
				System.out.println(a+c);
			}
		}else{
			if(a <= c){
				System.out.println(a+b);
			}else{
				System.out.println(b+c);
			}
		}
	}

}


Measured memory_bytes: 23764
#include <stdio.h>
int main(void){
    int n, y, s, t, u, i, j, k, f=0;
    
    scanf("%d %d", &n, &y);
    
    f = 0;
    for(i=0; i<=n; i++){  
        for(j=0; j<=n-i; j++){
             if(i*10000+j*5000+(n-i-j)*1000 == y){
                 printf("%d %d %d\n", i, j,(n-i-j));
                 f = 1; break;
             }
         }
         if(f == 1)break;
     }
     if(f == 0){
         printf("-1 -1 -1\n");
      }
 
    return 0;
}


Measured memory_bytes: 128
import numpy as np
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
bs = [int(input()) for _ in range(N)]

A = np.array([A1, A2, A3])
mask = np.zeros_like(A)
for b in bs:
    mask += (A==b).astype(int)

mask = mask>0
if np.any(np.all(mask, axis=0)):
    print('Yes')
elif np.any(np.all(mask, axis=1)):
    print('Yes')
elif np.all(np.diag(mask)):
    print('Yes')
# elif np.all(np.diag(mask.T)):
elif mask[0][2]&mask[1][1]&mask[2][0]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 12444
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>

using namespace std;

int main() {
	string s, t, n;
	int ans = 0;


	cin >> s >> t;

	for (int i = 0; i<3; i++) {
		if (s[i] == t[i]) {
			ans++;
		}
	}


	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main()
{
    const long long d = 20;
    std::vector<bool> set(d, false);

    long long n;
    std::cin >> n;
    std::vector<long long> a(n);
    for (long long i = 0; i < n; ++i)
        std::cin >> a[i];

    long long b = 0, e = 0;
    long long ans = 0;
    while (b != n) {
        bool is_ok = e != n;
        if (is_ok)
            for (long long i = 0; i < d; ++i)
                is_ok &= !(((a[e] >> i) & 1) && (set[i]));
        if (is_ok) {
            for (long long i = 0; i < d; ++i)
                if ((a[e] >> i) & 1) set[i] = true;
            ++e;
        } else {
            ans += e - b;
            for (long long i = 0; i < d; ++i)
                if ((a[b] >> i) & 1) set[i] = false;
            ++b;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 4756
#include <iostream>
using namespace std;
#define ll long long int
int main() {
    
    ll n;
    cin>>n;
    
    ll arr[n];
    
    for(ll i=0;i<n;i++)
    cin>>arr[i];
    
    ll minyet[n+1]={0};
    
    minyet[0]=arr[0];
    
    for(ll i=1;i<n;i++)
    minyet[i]=min(minyet[i-1],arr[i]);
    
    // for(ll i=0;i<n;i++)
    // cout<<arr[i]<<" ";
    // cout<<"\n";
    // for(ll i=0;i<n+1;i++)
    // cout<<minyet[i]<<" ";
    // cout<<"\n";
    
    
    ll ans=0;
    for(ll i=n-1;i>=0;i--)
    if(arr[i]<=minyet[i])
    ans++;
    
    cout<<ans;
}

Measured memory_bytes: 3328
{-# LANGUAGE OverloadedStrings #-}

import           Data.Bool
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = uncurry solve <$> getParams >>= B.putStrLn

getParams :: IO (Int, B.ByteString)
getParams = (,) <$> readLn <*> B.getLine

solve :: Int -> B.ByteString -> B.ByteString
solve n s = bool "No" "Yes" $ x == y
  where (x, y) = B.splitAt center s
        center = n `div` 2


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;++i) cin>>arr[i];
    int dp[n]={0};
    for(int i=0;i<n;++i)
    {
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<i+k+1;++j)
        {
            if(j<n)
            dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
        }
        /*for(auto k:dp)
        {
            cout<<dp[i]<<" ";
        }
        cout<<endl;*/
    }
    /*for(int i=0;i<n;++i)
    {
       cout<<dp[i]<<" ";
    }*/
    //cout<<endl;
    cout<<dp[n-1]<<endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

using elem = tuple<int, int, int>;

const int MAX_H = (int)(1e3 + 5);
const int MAX_W = (int)(1e3 + 5);

int h, w;
char a[MAX_H][MAX_W];

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

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &w);

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

  queue<elem> que;
  set<pair<int, int>> visited;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[i][j] == '#') {
        que.push(elem(i, j, 0));
        visited.insert(make_pair(i, j));
      }
    }
  }

  while (!que.empty()) {
    elem cur = que.front(); que.pop();

    int x = get<0>(cur);
    int y = get<1>(cur);

    int phase = get<2>(cur);

    // printf("%d\n", phase);

    ans = phase;

    for (int i = 0; i < 4; ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];

      if (visited.find(make_pair(nx, ny)) != visited.end()) continue;
      if (!(0 <= nx && nx < h && 0 <= ny && ny < w)) continue;

      que.push(elem(nx, ny, phase + 1));
      visited.insert(make_pair(nx, ny));
    }
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 60176
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
if sum(a) < sum(b):
    ans = -1
else:
    c = [b[i] - a[i] for i in range(n)]
    c.sort()
    c_minus = [cc for cc in c if cc > 0]
    if len(c_minus) == 0:
        ans = 0
    else:
        aaa = 0
        point = sum(c_minus)
        for i in range(n):
            point += c[i]
            if point <= 0:
                break
        ans = len(c_minus) + i + 1
print(ans)

Measured memory_bytes: 18356
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int n;
	cin >> n;
	auto a = vector<int>(n);
	for(auto&& aa : a) cin >> aa;
	sort(a.begin(), a.end(), greater<int>());
	long long int ans = a[0];
	for(int i = 1; i < n - 1; ++i){
		ans += a[(i + 1) / 2];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4052
#include "bits/stdc++.h"

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

using namespace std;
const long long INF = 1LL << 61;

void printVec(vector<int> vec) {
	rep(i, vec.size())cout << vec[i] << " ";
}



int main() {
	string S; cin >> S;
	vector<int> num(S.size(), 1);
	vector<pair<int, int>> sets;

	int countR = 1;
	int countL = 1;
	bool isR = true;

	rep(i, S.size()-1) {
		if (S[i] == S[i + 1]) {
			if (isR)++countR;
			else countL++;
		}
		else {
			if (!isR) {
				sets.push_back(make_pair(countR, countL));
				countR = countL = 1;
			}
			isR = !isR;
		}
	}
	sets.push_back(make_pair(countR, countL));

	rep(i, sets.size()) {
		rep(j, sets[i].first - 1)cout << 0 << " ";
		int num = sets[i].first + sets[i].second;
		//cout << num << endl;
		if (num % 2 == 0) {
			cout << num / 2 << " " << num / 2 << " ";
		}
		else {
			if (sets[i].first > sets[i].second) {
				if ((sets[i].first - 1) % 2 != 0)cout << num / 2 << " " << (num / 2) + 1 << " ";
				else cout << (num / 2) + 1 << " " << num / 2 << " ";
			}
			else {
				if ((sets[i].second - 1) % 2 != 0)cout << (num / 2) + 1 << " " << num / 2 << " ";
				else cout << num / 2 << " " << (num / 2) + 1 << " ";
			}
		}
		rep(j, sets[i].second - 1)cout << 0 << " ";
	}
}

Measured memory_bytes: 1528
#include<stdio.h>
int main()
{
    long n, m;
    scanf("%ld %ld", &n, &m);
    if ((n >= 2) && (m >= 2))
    {
        printf("%ld\n", (n - 2)*(m - 2));
    }
    else
    {
        if (n == 1)
        {
            if (m == 1)
                printf("1\n");
            else
                printf("%ld\n", m - 2);
        }
        else
            printf("%ld\n", n - 2);
    }
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

A=[input() for _ in range(N)]
B=[input() for _ in range(M)]

for i in range(len(A)-len(B)+1):
  tmp=A[i].find(B[0])
  if tmp==-1:
    continue
  else:
    newA=[a[tmp:tmp+len(B[0])] for a in A[i:i+len(B)]]
    if newA==B:
      print('Yes')
      break
else:
  print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>

//AOJ0078
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int n,y,x;

	while(cin >> n){
		if(n==0 || cin.eof()) break;
		vector<vector<int> > ms(n,vector<int>(n,-1));
		y=n/2+1; x=n/2;
		ms[y][x]=1; 
		int zz=2;
		x++; y++;
		while(zz<=n*n){
		  	
			if(x>=n ) x=0;
			if(x<0 ) x=n-1;
			if(y>=n ) y=0;
			if( ms[y][x]>0) {x--; y++;}
			if( x>=0 && x<n && y<n && y>=0 && ms[y][x]<1  ){
				ms[y][x]=zz; zz++;
				x++; y++;
			}
			
			
		}
		rep(i,n){
			rep(j,n) printf("%4d",ms[i][j]);
			printf("\n");
		}
		
	}
	
	return 0;
	
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int a, b;
	cin >> a >> b;
	if (a == b)
		cout << a + b << endl;
	else
		cout << max(a, b) * 2 - 1 << endl;
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c=0, d[100000], e[100000],f=0, count = 0;
	char uc[100000];
	for (int i = 0; i < 6; i++) {
		cin >> uc[i];
	}
	if (uc[0] == uc[5] && uc[1] == uc[4] && uc[2] == uc[3]) {
		cout << "YES"<<endl;
	}
	else { cout << "NO" << endl; }
	
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, K; cin >> N >> K;
    vector<int> H(N); for (int& h : H) cin >> h;
    vector<int> cost(N, 1000000000);
    cost[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            if (i+j < N) cost[i+j] = min(cost[i+j], cost[i] + abs(H[i] - H[i+j]));
        }
    }
    cout << cost[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;
  cin>>n>>k;
  vector<pair<ll,ll>>su(n);
  rep(i,n)
  {
    ll a,b;
    cin>>a>>b;
    su[i]={b,a};
  }
  //su[n]={0,1e9+7};
  sort(all(su),greater<pair<ll,ll>>());
  set<ll>used;
  vector<ll>id;
  rep(i,n)
  {
    if(!used.count(su[i].second)){used.insert(su[i].second);id.push_back(i);}
  }
  //cout<<"su"<<endl;
  //for(auto t:su)//cout<<t.first<<" "<<t.second<<endl;
//  for(auto t:id)//cout<<t<<endl;
  ////cout<<"idsize"<<id.size()<<endl;




  vector<ll>sum1(n+1),sum2(id.size()+1);
  rep(i,n)sum1[i+1]=su[i].first+sum1[i];
  rep(i,id.size())sum2[i+1]=su[id[i]].first+sum2[i];
  ll syurui=used.size();
  ll res=0LL;
  ll inid=upper_bound(all(id),k-1)-id.begin();
  res=(ll)inid*inid+sum1[k];
  inid--;
  ll idx=k-1;
  repi(i,inid+2,1+min(k,syurui))
  {
    ll tres=i*i;
    while(idx==id[inid])
    {
      inid--;
      idx--;
    }
    idx--;
    //cout<<"inid"<<inid<<endl;
    tres-=sum2[inid+1];
    tres+=sum2[i];
    tres+=sum1[idx+1];
    chmax(res,tres);
    //cout<<res<<endl;
  }
  cout<<res<<endl;

  return 0;

}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int X, A, B;
    cin >> X >> A >> B;

    if (B <= A) {
        puts("delicious");
    } else if (B <= A + X) {
        puts("safe");
    } else {
        puts("dangerous");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// Harshad Number
int main() {
  int N, c;
  cin >> N;

  int n = N;
  while (n != 0) {
    c += n % 10;
    n /= 10;
  }
  
  if (N % c == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3576
n = int(input())
a_s = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for a in a_s:
    ans += sum(a)

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        for k in range(n):
            if i == k or j == k:
                continue
            if a_s[i][j] > a_s[i][k] + a_s[j][k]:
                print(-1)
                exit()
            if a_s[i][j] == a_s[i][k] + a_s[j][k]:
                ans -= a_s[i][j]
                break

ans //= 2
print(ans)

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

void fnInput(vector<int>& rvnTrg, vector<int>& rvnSch)
{
  int nSchCnt;
  cin >> nSchCnt;

  rvnSch.resize(nSchCnt + 1);
  for (int i = 0; i < nSchCnt; i++)
    cin >> rvnSch[i];

  int nTrgCnt;
  cin >> nTrgCnt;

  rvnTrg.resize(nTrgCnt);
  for (int i = 0; i < nTrgCnt; i++)
    cin >> rvnTrg[i];

}

void fnLinSch(const vector<int>& cnrvnTrg, vector<int>& rvnSch, int& rnFnd)
{
  size_t nMaxSiz = rvnSch.size() - 1;
  for (size_t ni = 0; ni < cnrvnTrg.size(); ++ni)
  {
    rvnSch[nMaxSiz] = cnrvnTrg[ni];
    size_t nj = 0;
    while (cnrvnTrg[ni] !=rvnSch[nj])
      ++nj;
    if (nj != nMaxSiz)
      ++rnFnd;
  }
}

void fnResult(int nFnd)
{
  cout << nFnd << endl;
}

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

  vector<int> vnTrg, vnSch;
  int nFnd = 0;

  fnInput(vnTrg, vnSch);
  fnLinSch(vnTrg, vnSch, nFnd);
  fnResult(nFnd);

  return 0;
}

Measured memory_bytes: 3144
#include <stdio.h>

int main(void){
  int Q;
  scanf("%d",&Q);

  int is_prime[100001];
  int dp[100001];

  for(int i = 2;i <= 100000;i++){
    is_prime[i] = 1;
    dp[i] = 0;
  }
  for(int i = 2;i <= 100000;i++){
    if(is_prime[i]){
      for(int j = 2*i;j <= 100000;j += i){
        is_prime[j] = 0;
      }
    }
  }

  for(int i = 3;i <= 100000;i += 2){
    if(is_prime[i] && is_prime[(i+1)/2]){
      dp[i] = 1;
    }
  }

  for(int i = 1;i <= 100000;i++){
    dp[i] += dp[i-1];
  }

  int l,r;
  for(int i = 0;i < Q;i++){
    scanf("%d%d",&l,&r);
    printf("%d\n",dp[r]-dp[l-1]);
  }

  return 0;
}

Measured memory_bytes: 1280
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <iomanip>
#include <cassert>
#include <numeric>
using namespace std;
 
#define ff first
#define ss second
#define pb push_back 
 
using LL = long long int;
using VL = vector<LL>;
using VI = vector<int>;
using VVL = vector<VL>;
using PLL = pair<LL,LL>;
using PII = pair<int ,int>;
 
#ifdef DEBUG
void _print()
{
  cout << endl;
}
template<typename T, typename... Args >
void _print(const T first_elem, const Args... args)
{
  cout << first_elem << " ";
  _print(args...);
}
#else
void _print()
{
}
template<typename T, typename... Args >
void _print(const T first_elem, const Args... args)
{
}
#endif
 
 
// NOTE: Please dont implement _print() as function in your program. It is reserved
// for debug purpose.

int main()
{
    ios::sync_with_stdio(false);
    LL n, x, m;
    cin >> n >> x >> m;
    LL sum = 0;
    map<LL, LL> vals;
    LL current = x;
    LL cycleLen = 0;
    LL initial = 0;
    LL len = 0;
    for (int i = 0; i < n; i++) {
        if (vals.count(current)) {
            initial = vals[current];
            cycleLen = i;
            len = i - initial;
            break;
        }

        vals[current] = i;
        current = (current * current) % m;
    }

    LL ans = 0;
    current = x;
    for (int i = 0; i < initial; i++) {
        ans += current;
        current = (current * current) % m;
    }

    LL cycleSum = 0;
    LL currentAtInitial = current;
    for (int i = initial; i < cycleLen; i++) {
        cycleSum += current;
        current = (current * current) % m;
    }

    LL totalCycle = len ? (n - initial) / len : 0;
    ans += (cycleSum * totalCycle);

    n -= (len * totalCycle);
    n -= initial;
    _print(totalCycle, initial, len, n, currentAtInitial, ans);

    current = currentAtInitial;
    for (int i = 0; i < n; i++) {
        ans += current;
        current = (current * current) % m;
    }

    cout << ans << endl;

    return 0;
}

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

ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }

using LL = long long;
using PII = pair<int, int>;

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

	int n;
	cin >> n;
	vector<PII> inv(n);
	int ans = 0;
	REP(i, n) {
		int l, r;
		cin >> l >> r;
		inv[i] = {l, r};
	}

	sort(inv.begin(), inv.end());

	int min_end = 1e9;
	vector<int> pref(n);
	REP(i, n) {
		min_end = min(min_end, inv[i].ND);
		pref[i] = min_end;
	}

	auto get_size = [&](int end, int i) {
		int res = end - inv[i].ST + 1;
		res = max(0, res);
		return res;
	};

	min_end = 1e9;
	vector<int> suff(n);
	for(int i = n - 1; i >= 1; i--) {
		min_end = min(min_end, inv[i].ND);
		suff[i] = min_end;
		ans = max(ans, get_size(pref[i - 1], i - 1) + get_size(suff[i], n - 1));
	}

	debug(ans);

	FOR(i, 1, n - 2) {
		int width = inv[i].ND - inv[i].ST + 1;
		int rest = get_size(min(pref[i - 1], suff[i + 1]), n - 1);
		ans = max(ans, width + rest);
	}

	cout << ans << "\n";
}


Measured memory_bytes: 1792
using System.Collections.Generic;
using System.Linq;
public class PictureMatching
    {
        private static int[] item;

        public static void Main(string[] args)
        {
            Input();
            Method();
            System.Console.ReadLine();
        }

        private static void Input()
        {
            item = ToIntArray(System.Console.ReadLine().Split(' '));
        }

        private static void Method()
        {
            System.Console.WriteLine(item.Aggregate(Gcd));
        }

        private static int Gcd(int x, int y)
        {
            return y == 0 ? x : Gcd(y, x % y);
        }

        private static int[] ToIntArray(string[] str)
        {
            IEnumerable<int> intArray = str.Select(x => int.Parse(x));
            return intArray.ToArray();
        }
}

Measured memory_bytes: 9620
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

void solve(){
  int h, n; cin >> h >> n;
  vector<int> dp(h + 1, 100000000);
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    int a, b; cin >> a >> b;
    for(int j = 0; j < h; j++){
      int nj = min(j + a, h);
      dp[nj] = min(dp[nj], dp[j] + b);
    }
    /*for(int j = 0; j <= h; j++){
      cout << dp[j] << " ";
    }
    cout << endl;*/
  }
  cout << dp[h] << endl;

  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string x;
  cin >> x;
 
  if (x == "a" ||x=="i"||x=="u"||x=="e"||x=="o") {
    cout << "vowel" << endl;
  }
  else {
      cout <<"consonant"<<endl;
  }
  
}

Measured memory_bytes: 256
s = input()
#Rならその右に連続するRの数
l = []
for i in range(len(s)):
    if i ==0 :
        l.append(0)
    else:
        if s[i] == "L":
            l.append(l[i-1] + 1)
        else:
            l.append(0)

r = [0]*len(s)
for i in range(len(s)):
    if i == 0:
        r[len(s)-1] = 0
    else:
        if s[len(s)-1-i]=="R":
            r[len(s)-1-i] = r[len(s)-i]+1
        else:
            r[len(s)-1-i] = 0

ans = [0]*len(s)

for i in range(len(s)):
    if s[i] == "R":
        if r[i]%2 == 0:
            ans[i+r[i]] += 1
        else:
            ans[i+r[i]-1] += 1
    else:
        if l[i]%2 == 0:
            ans[i-l[i]] += 1
        else:
            ans[i-l[i]+1] += 1

a = " ".join(map(str,ans))
print(a)

Measured memory_bytes: 53428
from fractions import gcd


N, X = map(int, input().split())
xs = sorted(map(int, input().split()))
diffs = []
for i in range(N):
    diffs.append(abs(xs[i] - X))

gcds = [0]
for i in range(N):
    gcds.append(gcd(gcds[i], diffs[i]))
print(gcds[-1])


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


int main() {
  int n;
  cin >> n;
  bool ans = false; 
  rep(i,n/4+1){
    rep(j,n/7+1){
      if(4*i+7*j == n) ans = true;
    }
  }
  if (ans == true) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
h = [0] + list(map(int, input().split()))
dp = [0] * (N+1)
dp[2] = abs(h[2] - h[1])
for i in range(3, N+1):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
print(dp[N])

Measured memory_bytes: 13908
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

long long gcd(long long x, long long y)
{
    if(x < y ) swap(x, y);
    if(y == 0) return x;
    x = x % y;
    return gcd(x, y);
}

const int MAX = 3;

long long m[MAX], a[MAX], jump[MAX];

int main()
{
    long long px, nx;
    while(cin >> a[0] >> m[0] >> a[1] >> m[1] >> a[2] >> m[2] && m[0])
    {
        REP(3)
        {
            jump[i] = 0;
            px = 1; nx = 0;
            while(nx != 1)
            {
                nx = a[i] * px % m[i];
                jump[i]++;
                px = nx;
            }
        }
        long long lcm1 = jump[0] * jump[1] / gcd(jump[0], jump[1]);
        long long ans = lcm1 * jump[2] / gcd(lcm1, jump[2]);
        cout << ans << endl;

    }
    
    return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const double eps = 1e-9;
const ll N = 1e5 + 10;
const int M = 1e9 + 7;
const ll MAX = 1e18 + eps;
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};


int main() {
    int n;
    cin >> n;
    vll v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(all(v));
    if (v.front() == 0)
        return cout << 0 << endl, 0;
    ll mult = 1;
    for (int i = 0; i < n; ++i) {
        if (v[i] > (MAX / mult))
            return cout << -1 << endl, 0;
        mult *= v[i];
      if(mult > MAX)
            return cout << -1 << endl, 0;
    }
    cout << mult << endl;
}

Measured memory_bytes: 4052