akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
  int a,b,c,k,max;
  scanf("%d%d%d%d",&a,&b,&c,&k);
  if(k<a){
    max=k;}
  else if(k<a+b){
    max=a;}
  else{
    max= 2*a-k+b;}
  printf("%d",max);
  return 0;
}
     



Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int a[5];

  for(int i=0;i<5;i++)cin>>a[i];
  sort(a,a+5);
  for(int i=4;i>=0;i--){if(i==4)cout<<a[i];else cout <<" "<<a[i];}
  cout << "\n";
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int pare=0;
    for(int i=0;i<N;i++){
        if(a[a[i]-1]==i+1) pare++;
    }
    cout << pare/2 << endl;
    return 0;
}


Measured memory_bytes: 640
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

int a,b;
ll ans=oo*oo;

ll bat(ll a,ll b,ll c){
    ll p=oo*oo,q=-oo*oo;
    p=min(p,a);
    p=min(p,b);
    p=min(p,c);
    q=max(q,a);
    q=max(q,b);
    q=max(q,c);
    return q-p;
}

int main() {
    //file_put();

    scanf("%d%d",&a,&b);
    if (a%3==0 || b%3==0) return 0*printf("0\n");
    ans=min(a,b);
    for (int i=1; i<=a-1; i++) ans=min(ans,bat((ll)b*i,(ll)(a-i)*(b/2),(ll)(a-i)*(b-b/2)));
    for (int i=1; i<=b-1; i++) ans=min(ans,bat((ll)a*i,(ll)(b-i)*(a/2),(ll)(b-i)*(a-a/2)));
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 256
answers = Array.new
while line = $stdin.gets.chomp
	range = line.split( / / )
	a = range[ 0 ].to_i
	b = range[ 1 ].to_i

	if a == 0 && b == 0
		break
	end

	ans = Array.new
	a.upto( b ){ |year|
		leap = false
		if year % 400 == 0
			leap = true
		elsif year % 100 == 0
			leap = false
		elsif year % 4 == 0
			leap = true
		else
			leap = false
		end
		ans << year if leap
	}
	answers << ans
end

f = false
answers.each{ |years|
	puts if f
	if years.size == 0
		puts "NA"
		next
	end
	years.each{ |year|
		puts year
	}
	f = true
}


Measured memory_bytes: 6120
#include <iostream>

int main(){
    int A = 0;
    int B = 0;
    int C = 0;
    std::cin >> A >> B >> C;

    int tmp = (A-B);
    if (tmp<C) {
        std::cout << C-tmp << std::endl;
    } else {
        std::cout <<  0 << std::endl;
    }
};

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
//#include <math.h>
signed main(void) 
{
    ll h, a, r;
    r = 0;
    cin >>h >>a;
    
    while(h > 0) {
        h -= a;
        r ++;
    }
    
    
   
    cout <<r;
    return 0;
}

Measured memory_bytes: 3628
main = do
    [n,m,d] <- map read . words <$> getLine :: IO [Int]
    let p2 = if d == 0 then 0 else length [d+1..n-d]
        p1 = n - p2
        ans = fromIntegral ((p1 + 2 * p2) * (m-1)) / fromIntegral n / fromIntegral n
    print ans

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int a[250010];
using pii=pair<int,int>;
pii x[510];

int num[510],tmp[510];


int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> x[i].first,x[i].second=i+1;
	sort(x,x+n);

	
	bool ok=true;
	vector<int> cur;
	rep(i,n)rep(loop,x[i].second-1) cur.push_back(x[i].second);
	rep(i,n)rep(loop,n-x[i].second) cur.push_back(x[i].second);

	rep(i,n) a[x[i].first-1]=x[i].second;

	int idx=0;
	for(auto &elem:cur){
		while(a[idx]) idx++;
		a[idx++]=elem;
	}

	rep(i,n*n){
		num[a[i]]++;
		if(num[a[i]]==a[i]) tmp[a[i]]=i+1;
	}

	rep(i,n) if(tmp[x[i].second]!=x[i].first) ok=false;
	
	if(ok){
		puts("Yes");
		rep(i,n*n) cout << (i?" ":"") << a[i];
		cout << endl;
	}else
		puts("No");
	
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    string s;
    cin >> s;
    ll ans = -INF;
    ll cur = 0;
    for(ll i=0;i<s.size();i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') cur++;
        else cur = 0;
        ans = max(ans,cur);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    
    int n;
    string s;
    cin>>s;
    n=s.size();
    string g = s.substr(0,n/2);
    string f=s.substr(n/2+1,n/2);
    if(f==g) cout<<"Yes"<<endl;
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


int main()
{
	int n, l;
	cin >> n >> l;
	int ans = 0;
	int eat = 10000000;
	bool eatplus = 1;

	for (int i = 0; i < n; ++i)
	{
		int aji = l + i;
		ans += aji;
		if (aji < 0)
		{
			eatplus = 0;
			aji *= -1;
		}
		chmin(eat, aji);

	}
	if (eatplus)
		cout << ans - eat << endl;
	else
		cout << ans + eat << endl;

	return 0;
}

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

const int INF = 1e9;
int dp[10010];

signed main() {
    int h,n;
    cin >> h >> n;

    vector<P> a(n);
    rep(i,n){
        cin >> a[i].first >> a[i].second;
    }

    rep(i,10010) dp[i] = INF;
    dp[h] = 0;
    for(int i = 0; i < n; i++){
        for(int j = h; j >= 0; j--){
            int nt = j - a[i].first;
            if(nt <= 0) nt = 0;
            dp[nt] = min(dp[nt], dp[j] + a[i].second);
        }
    }

    cout << dp[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 1000001;
const int MOD =1000000007;
const int INV2 = (MOD+1)/2;



     signed main(){
   string s;
   cin>>s;
   if(s=="ABC")cout<<"ARC";
   else cout<<"ABC";
     

        





}


        


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
    int m,f,r;
    cin>>m>>f>>r;
    while(m!=-1 || f!=-1 || r!=-1){
        if(m==-1 || f==-1) cout<<'F'<<endl;
        else if(m+f>=80) cout<<'A'<<endl;
        else if(m+f>=65 && m+f<80) cout<<'B'<<endl;
        else if(m+f>=50 && m+f<65) cout<<'C'<<endl;
        else if(m+f>=30 && m+f<50 && r>=50) cout<<'C'<<endl;
        else if(m+f>=30 && m+f<50 && r<50) cout<<'D'<<endl;
        else if(m+f<30) cout<<'F'<<endl;
        cin>>m>>f>>r;
    }
    return 0;
}


Measured memory_bytes: 3072
N, A, B = map(int, input().split())
roop = int(N / (A + B))
nokori = N - roop * (A + B)
if nokori == 0:
    ans = roop * A
elif nokori <= A:
    ans = roop * A + nokori
else:
    ans = roop * A + A
print(ans)

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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a < b){
        cout<<"a < b"<<endl;;
    }else if(a > b){
        cout<<"a > b"<<endl;;
    }else if(a == b){
        cout<<"a == b"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3036
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define MAX 10000000
using namespace std;


int main(){
	ll n,W,w,v;
	cin >> n >> W;
	vector< pair<ll,ll> > knap;
	for(int i=0;i<n;i++){
		cin >> w >> v;
		knap.push_back({w,v});
	}
	ll k[n+1][W+1];
	for(int i=0;i<=n;i++){
		for(int s=0;s<=W;s++){
			if(i==0 || s==0){
				k[i][s]=0;
			}
			else if(knap[i-1].first <=s){
				k[i][s] = max(knap[i-1].second + k[i-1][s - knap[i-1].first], k[i-1][s]);
			}
			else{
				k[i][s] = k[i-1][s];
			}
		}
	}
	cout << k[n][W] << endl;
	return 0;
}

Measured memory_bytes: 79104
#include <iostream>

using namespace std;

int main()
{
	int a, b,c;
	cin>>a>>b>>c;
	if (a >= b)
	{
		cout<<"No"<<endl;
		return 0;
	}
	else if (b >= c)
	{
		cout<<"No"<<endl;
		return 0;
	}
	else
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 3092
N,M=(int(x) for x in input().split())

k = N + M

if N >= 0 and M <=100 and N+M >=2: 
    int((N + M) * (N + M - 1) / 2 - (N * M))
    print(int(k * (k - 1) / 2 - (N * M)))

Measured memory_bytes: 2940
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int answer = 0;
        for(int i = 1 ; i <= 5 ; i++){
            int x = scanner.nextInt();
            if(x == 0){
                answer = i;
            }
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 35776
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[6]={100,101,102,103,104,105};
int dp[110000];

signed main(){
	cin>>N;
	dp[0]=1;
	REP(i,6){
		for(int j=0;j+A[i]<=N;j++){
			dp[j+A[i]]=max(dp[j+A[i]],dp[j]);
		}
	}
	cout<<dp[N]<<endl;
	return 0;
}


Measured memory_bytes: 1024
/*for better*/
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define M 998244353
using namespace std;

int main()
{
    fast; 
    ll n,h[100005],dp[100005],i;
    cin>>n;
    f(i,0,n)
    	cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    f(i,2,n)
    	dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//abc163C
int main(void) {
  int m, n, k, i, a, cou=0, tmp;
  scanf(" %d", &n);
  int s[n];
  for(i=0; i <n; i++)s[i]=0;
  for(i=0; i <n-1; i++){
    scanf(" %d", &a);
    s[a-1]++;
  }
  for(i=0; i <n; i++) printf("%d\n", s[i]);
  return 0;
}

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

int main(){
  long long x, k;
  cin >> x >> k;
  long long div = x/k;
  long long res = x - k * div;
  long long y = k - res;
  if(res < y){
    cout << res;
  }
  else{
    cout << y;
  }
}

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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int a, b;
    cin>>a>>b;
    int ans = 0;
    if(a>=13)ans=b;
    else if(a>=6)ans=b/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main() {
    int sx, sy, tx, ty;
    scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
    for(int r = 0; r < ty-sy; r++) printf("U");
    for(int r = 0; r < tx-sx; r++) printf("R");
    for(int r = 0; r < ty-sy; r++) printf("D");
    for(int r = 0; r < tx-sx; r++) printf("L");
    printf("L");
    for(int r = 0; r <= ty-sy; r++) printf("U");
    for(int r = 0; r <= tx-sx; r++) printf("R");
    printf("D");
    printf("R");
    for(int r = 0; r <= ty-sy; r++) printf("D");
    for(int r = 0; r <= tx-sx; r++) printf("L");
    printf("U");
}

Measured memory_bytes: 128
//Compile: g++ -g -Wshadow -Wall main.cpp -o a.exe -Ofast -Wno-unused-result
//Build: g++ -g -Wshadow -Wall -o "%e" "%f" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG
//Compile and run: g++ -g -Wshadow -Wall main.cpp -o a.exe -Ofast -Wno-unused-result && a.exe

#pragma GCC optimize("Ofast")

#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

typedef long long ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<long, long> pl;
typedef std::vector<int> vi;
typedef std::vector<ll> vl;
typedef std::vector<pii> vpii;
typedef std::vector<pl> vpl;
typedef std::vector<vi> vvi;
typedef std::vector<vl> vll;
typedef std::map<int, int> mii;
typedef std::priority_queue<int> pqd;
typedef std::priority_queue<int, vi, std::greater<int>> pqi;

#define gc getchar_unlocked
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264
#define MOD 1e9 + 7
#define INF INT64_MAX;

#define fo(i, n) for (ll i = 0; i < n; ++i)
#define Fo(i, k, n) for (ll i = k; k < n ? i < n : i > n; k < n ? ++i : --i)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define deb(x) cout << #x << "=" << x << endl
#define sortall(x) sort(x.begin(), x.end())
#define tr(it, a) for (auto it = a.begin(); it != a.end(); ++it)
#define ps(x, y) std::fixed << setprecision(y) << x
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mk(arr, n, type) type* arr = new type[n]

std::mt19937_64 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());

inline void setup() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

#ifdef LOCAL_PROJECT  //run with -DLOCAL_PROJECT drung compilation
    freopen("input.txt", "r", stdin);
#else
#ifndef ONLINE_JUDGE  //runs automatically for supported online judges
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
#endif
}

inline void solve();

int main() {
    setup();

    ll t = 1;

    // std::cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}

using namespace std;

inline void solve() {
    ll n;
    cin >> n;

    cout << (1000 - n % 1000) % 1000;
}

Measured memory_bytes: 3576
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000001
using namespace std;
typedef long long ll;

int main(){
  int n;  cin >> n;
  vector<int> ds(n, 0), start(n, 0), fs(n, 0);
  rep(i, 0, n-1)  cin >> ds[i] >> start[i] >> fs[i];
  rep(i, 0, n){
    int ans = 0;
    rep(j, i, n-1){
      if(ans < start[j])  ans=start[j];
      else if(ans%fs[j]==0);
      else ans += fs[j] - ans%fs[j];
      ans += ds[j];
    }
    cout << ans << 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 fx(x) fixed<<setprecision(x)

vector<double> v(1000,0);
double exp(double x){
	if(v[x]) return v[x];
	double ans=0;
	for(int i=1; i<=x; i++) ans+=i*(1/x);
	v[x]=ans;
	return ans;
}

int main(){
	int n,k; cin>>n>>k;
	vector<int> p(n);
	rep(i,n) cin>>p[i];
	
	vector<double> e(n);
	rep(i,n) e[i]=exp(p[i]);
  
	vector<double> r(n+1,0);
	rep(i,n){
		r[i+1]=r[i]+e[i];
	}
	
	double mx=0;
	for(int i=0; i<=n-k; i++){
		double sum=(r[i+k]-r[i]);
		mx=max(mx,sum);
	}
	cout<<fx(10)<<mx<<endl;
}


Measured memory_bytes: 7220
import itertools

N = input()
K = int(input())
lN = len(N)

if K == 1:
    ans = int(N[0])+9*(lN-1)
    print(ans)

elif K == 2:
    not0 = 1000
    for i in range(1,lN):
        if int(N[i]) != 0:
            not0 = i
            break

    ans = 0
    n = [i for i in range(lN)]

    for v in itertools.combinations(n,2):
        #print(v)
        if v[0] != 0:
            ans += 9*9
        else:
            if not0 >= v[1]:
                ans += (int(N[0])-1)*9 + int(N[v[1]])
            else:
                ans += int(N[0])*9
    print(ans)

else:
    not0f = 1000
    not0s = 1000
    for i in range(1,lN):
        if int(N[i]) != 0:
            not0f = i
            break
    for i in range(not0f+1,lN):
        if int(N[i]) != 0:
            not0s = i
            break
    ans = 0
    n = [i for i in range(lN)]
    for v in itertools.combinations(n,3):
        if v[0] != 0:
            ans += 9*9*9
        else:
            if not0f == v[1]:
                if not0s >= v[2]:
                    ans += (int(N[0])-1)*9*9
                    ans += max(0,int(N[v[1]])-1)*9
                    ans += int(N[v[2]])
                else:
                    ans += (int(N[0])-1)*9*9
                    ans += int(N[v[1]])*9
            elif not0f < v[1]:
                ans += int(N[0])*9*9
            else:
                ans += (int(N[0])-1)*9*9

    print(ans)


Measured memory_bytes: 3316
from collections import Counter

def row(M, li):
    ## solve for row
    for i in range(3):
        bad = False
        r = Mat[i]
        c = Counter(r)
        for k,v in c.items():
            if li.get(k, 0) < v:
                bad = True
        if not bad:
            return True

    return False

def col(M, li):
    for Col in zip(*M):
        bad = False
        c = Counter(Col)
        for k, v in c.items():
            if li.get(k, 0) < v:
                bad = True

        if not bad:
            return True

    return False

def r_diag(M, li):
    it = []
    for i in range(3):
        it.append(M[i][i])
    c = Counter(it)
    for k,v in c.items():
        if li.get(k, 0) < v:
            return False

    return True

def l_diag(M, li):
    it = []
    for i in range(3):
        it.append(M[i][3-i-1])
    c = Counter(it)
    for k,v in c.items():
        if li.get(k, 0) < v:
            return False

    return True

def solve(M ,li):
    if row(M, li) or col(M, li) or r_diag(M, li) or l_diag(M, li):
        return "Yes"

    return "No"
Mat = []
for i in range(3):
    li = list(map(int, input().split()))
    Mat.append(li)

n = int(input())
li = {}
for i in range(n):
    a = int(input())
    li[a] = li.get(a, 0) + 1

print(solve(Mat, li))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define N 10005
#define ll long long
#define endl '\n'

using namespace std;

int main()
{
	int n,num[1000];
	int sum=0;
	cin >> n;

	for(int i=0;i<n;++i){
		cin >> num[i];
		sum+=num[i];
	}
	
	int l=0,r=sum,Min=1e9;
	for(int i=0;i<n;++i){
		Min=min(Min,abs(r-l));
		l+=num[i];
		r-=num[i];
	}
	cout << Min << endl;
	return 0;
}

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

using ll=long long;
#define int ll

#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)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

void no(){
	cout<<"No"<<endl;
	exit(0);
}
void yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

//KUPC2017J
//AOJDSL1A
//without rank
struct unionfind{
	vi p,s;
	int c;
	unionfind(int n):p(n,-1),s(n,1),c(n){}
	int find(int a){
		return p[a]==-1?a:(p[a]=find(p[a]));
	}
	//set b to a child of a
	bool unite(int a,int b){
		a=find(a);
		b=find(b);
		if(a==b)return false;
		p[b]=a;
		s[a]+=s[b];
		c--;
		return true;
	}
	bool same(int a,int b){
		return find(a)==find(b);
	}
	int sz(int a){
		return s[find(a)];
	}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);

	int n,m,q;cin>>n>>m>>q;

	if ( q == 0 ) {
	  abort();
	}

	vc<pi> dup;
	unionfind uf(n);
	rep(_,q){
		int u,v,f;cin>>u>>v>>f;
		if(f==0)
			uf.unite(u,v);
		else
			dup.eb(u,v);
	}

	if(m==n-1){
		if(dup.size())no();
		yes();
	}

	for(auto e:dup)
		if(uf.same(e.a,e.b))no();

	if(m<=n-uf.c+uf.c*(uf.c-1)/2)yes();
	else no();
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int a[300][300];
int dist[300][300];
const int inf = 1e9;
bool ch[305][305];
int main()
{
	int n;
	cin >> n;

	// floyd
	rep(i,n) rep(j,n) {
		cin >> a[i][j];
		dist[i][j] = a[i][j];
	}
	rep(i,n) dist[i][i] = 0;

	rep(k,n){
		rep(i,n){
			rep(j,n){
				chmin(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	rep(i,n){
		rep(j,n){
			if(a[i][j] != dist[i][j]){
				cout << -1 << endl;
				return 0;
			}
		}
	}

	vector<pair<ll ,P>> v;
	rep(i,n){
		For(j,i+1,n){
			v.push_back({a[i][j], {i,j}});
		}
	}
	SORT(v);
	ll ans = 0;
	rep(i,v.size()){
		// 辺を使うかどうか
		if(!ch[v[i].second.first][v[i].second.second]) {
			ch[v[i].second.first][v[i].second.second] = 1;
			pair<ll, P> now = v[i];
			ans += now.first;
			rep(j,n){
				if(now.second.first != j && now.second.second != j){
					ll dist = now.first;
					if(dist + a[j][now.second.first] == a[now.second.second][j])
						ch[min(j,now.second.second)][max(j,now.second.second)] = 1;
					if(dist + a[j][now.second.second] == a[now.second.first][j])
						ch[min(j,now.second.first)][max(j, now.second.first)] = 1;
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4972
if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    dict2={}
    count = 0
    now =1
    for i in range(n):
        if now in dict2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                dict2[now]=0
                count+=1
                now = dict[now-1]

Measured memory_bytes: 65624
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val S = rd.readString()
    val K = rd.readInt()

    val N = S.length

    var rest = K
    val ans = CharArray(N)

    for (i in 0 until N) {
        if (S[i] != 'a' && rest >= 'z' - S[i] + 1) {
            rest -= 'z' - S[i] + 1
            ans[i] = 'a'
        } else {
            ans[i] = S[i]
        }
    }

    rest %= 26
    while (rest>0) {
        ans[N-1] = if (ans[N-1]=='z') 'a' else ans[N-1] + 1
        rest--
    }

    println(ans)
}


//val rd = debug.Reader("etc", "code-festival-2016-quala", "c", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toInt() } } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    int permutation_num=1;
    for (int i=0; i<N; i++)
    {
        cin >> x[i] >> y[i];
        permutation_num*=i+1;
    }
    double sum=0;
    for (int i=0; i<N-1; i++)
    {
        for (int j=i+1; j<N; j++)
        {
            sum+=sqrt(pow(x[i]-x[j], 2) + pow(y[i]-y[j], 2));
        }
    }
    //cout << sum << endl;
    double average = sum * 2 / N;
    cout << setprecision(15) << average << endl;
}

Measured memory_bytes: 256
function main(input){
  inp=input.trim();
    var leng=inp.length;
    var str =inp.slice(-1);
    var istr=parseInt(str);
    var out='';
  
  	    if(istr==2 || istr==4 || istr==5 || istr==7 || istr==9){
            out='hon';
        }
    
        else if(istr==0 ||istr==1 || istr==6 || istr==8){
            out='pon';
        }
 
        else if(istr==3){
            out='bon';
        }
      
      console.log(out);
     
    }
     
    main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


int main(){
  int d;
  cin >> d;
  if(d == 25) cout << "Christmas" << endl;
  if(d == 24) cout << "Christmas Eve" << endl;
  if(d == 23) cout << "Christmas Eve Eve" << endl;
  if(d == 22) cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <algorithm>

using namespace std;

int main() {
    array<int, 3> a;

    for (int &n: a) {
        cin >> n;
    }

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

    cout << a.back() - a.front() << endl;

    return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>x(n);
rep(i,n){
    cin>>x[i];
}
vector<int> sort_x=x;
sort(sort_x.begin(),sort_x.end(),greater<int>());
int idx=(n/2)-1;
rep(i,n){
    if(x[i]>=sort_x[idx]){
        cout<<sort_x[idx+1]<<endl;
    }
    else{
         cout<<sort_x[idx]<<endl;
    }
}
return 0;
}

Measured memory_bytes: 3840
import heapq

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
A.append(0)
S = []
heapq.heapify(S)
c = A[0]
cnt = 1
for i in range(1, N + 1):
    if A[i] == c:
       cnt += 1
    else:
        heapq.heappush(S, (A[i - 1], cnt))
        cnt = 1
        c = A[i]


for i in range(M):
    B, v = map(int, input().split())
    flag = False #Sからの取り出し比較を1度以上終えているか
    b = B # 残りカード
    while len(S) > 0 and S[0][0] < v:
        x = heapq.heappop(S)
        if b <= x[1]:
            heapq.heappush(S, (v, B))
            if not b == x[1] : heapq.heappush(S, (x[0], x[1] - b))
            flag = False
            break
        else:
            flag = True
            b -= x[1]

    if flag: #交換しきらないで、途中で終わっているのでこの分は挿入する
        heapq.heappush(S, (v, B - b))

sumS = 0
while len(S) > 0:
    x = heapq.heappop(S)
    sumS += x[0] * x[1]
print(sumS)









Measured memory_bytes: 85656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define mit(a,b) map<a,b>::iterator
#define sit(a) set<a>::iterator
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vec4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
int gi(){
    int x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}
void print(ll x)
{
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);putchar(x % 10 + '0');
}
int main()
{
     io;
    int T=1;
    //T=gi();
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
       int x=gi();
       puts((x>=30)?"Yes":"No");
    }
    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<vector>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 100005
#define inf 100000000000

ll n, capacity;
ll price[105], wt[105];
ll dp[105][MAX];

ll solve(ll max_profit){

    for(int i=0; i<=n; i++){
        for(int j=0; j<=max_profit; j++){
            if(i==0){
                if(j==0) dp[i][j]=0;
                else dp[i][j]=inf;
            }
            else if(j>=price[i-1]){
                dp[i][j] = min(dp[i-1][j], wt[i-1]+dp[i-1][j-price[i-1]]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    ll ans=0;
    for(int i=0; i<=max_profit; i++){
        if(dp[n][i]<=capacity) ans=i;
    }
    return ans;
}

int main(){
    ll max_profit=0;
    cin>>n>>capacity;
    for(int i=0; i<n; i++){
        cin>>wt[i]>>price[i];
        max_profit += price[i];
    }
    cout<<solve(max_profit)<<endl;
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
const int inf = numeric_limits<int>::max();

int main()
{
    int n;
    cin >> n;
    vector<int> weight(n);
    for(int i = 0; i < n; i++) cin >> weight[i];
    int min_total = inf;
    for (int t = 1; t < n; t++){
        int s1 = 0, s2 = 0;
        for (int i = 0; i < t; i++) s1+= weight[i];
        for (int j = t; j < n; j++) s2+= weight[j];
        if (abs(s1 - s2) < min_total)   min_total = abs(s1 - s2);
    }
    cout << min_total << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
h = [0 for i in range(n)]
height_tmp = 0
X = 0
Y = 0
for i in range(n):
    x[i], y[i], h[i] = [int(i) for i in input().split()]
    if h[i] != 0:
        height_tmp = h[i]
        X = x[i]
        Y = y[i]
for i in range(101):
    for j in range(101):
        flag = 0
        okFlag = 1
        H = height_tmp + abs(X - i) + abs(Y - j)
        if H < 0:
            continue
        for k in range(n):
            if h[k] != max(H - abs(x[k] - i) - abs(y[k] - j), 0):
                okFlag = 0
                break
        if okFlag == 1:
            print("{} {} {}".format(i, j, H))
            exit()
"""
        flag = 0
        okFlag = 1
        height_tmp = 0
        output = [0, 0, 0]
        for k in range(n):
            if h[k] == 0:
                continue
            if flag == 0:
                height_tmp = h[k] + abs(x[k] - i) + abs(y[k] - j)
                flag = 1
            else:
                if height_tmp != h[k] + abs(x[k]-i) + abs(y[k]-j):
                    okFlag = 0
                    break
                elif k == n-1:
                    if height_tmp == h[k] + abs(x[k] - i) + abs(y[k] - j):
                        output = [i, j, height_tmp]
                        okFlag = 1
                        #print("{} {} {}".format(i, j, height_tmp))
                        #exit()
        if okFlag == 1:
            print("{} {} {}".format(i, j, height_tmp))
            exit()
"""


Measured memory_bytes: 3064
program bbb
implicit none

integer :: a, b, k, n, res

read*, a, b, k

n=min(a,b)+1
res=0
do while(res/=k)
n=n-1
if(mod(a,n)==0.and.mod(b,n)==0) then
res=res+1
end if
end do

write(*,'(i0)') n

end program

Measured memory_bytes: 256
import numpy as np
N,W = map(int,input().split())
dp = np.zeros(W+1,dtype = np.int64)
for _ in range(N):
    w,v = map(int,input().split())
    if w > W:
        continue
    else:
        np.maximum(dp[w:],dp[:-w]+v,out = dp[w:])
print(dp[W])

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e15
typedef long long ll;

int V,E;
int V_MAX = 100;

vector<vector<ll>> G(V_MAX, vector<ll>(V_MAX,INF));
//vector<int> d(V_MAX, INF);

int main() {
    cin >> V >> E;
    REP(i,E){
        int s,t,d;
        cin >> s >> t >> d;
        G[s][t] = d;
    }

    REP(i,V) G[i][i] = 0;

    // //ベルマンフォードでテスト
    // bool flag = true;
    // int count = 0;
    // while(flag){
    //     flag = false;
    //     count ++;
    //     REP(i,V){
    //         REP(v, V){
    //             if (d[i] + G[i][v] < d[v]){
    //                 d[v] = d[i] + G[i][v];
    //                 flag = true;
    //             }
    //         }
    //     }
    //     if (flag==true && count==V-1){
    //         cout << "NEGATIVE CYCLE" << endl;
    //         return 0;
    //     }
    // }

    REP(i,V){//ワーシャルフロイド
        REP(j,V){
            REP(k,V){
                G[j][k] = min(G[j][k], G[j][i]+G[i][k]);
            }
        }
    }

    REP(i,V){
        if (G[i][i] < 0){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
            

    REP(i,V){
        REP(j,V){
            if (G[i][j] > INF/1000){
                cout << "INF";
                if (j != V-1) cout << " ";
            }else{
                cout << G[i][j];
                if (j != V-1) cout << " ";
            }
        }
        cout << endl;
    }

    
    return 0;
}


Measured memory_bytes: 3256
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<utility>

//壁の実際の座標を保存
struct L{
	int a, b, c;
	L(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
};

//マスの移動 direction
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int main(){
	int n, m;
	std::cin >> n >> m;

	std::map<int, int> mpx, mpy; //<実際の座標, 圧縮後のindex>
	mpx[0] = 0;
	mpy[0] = 0;
	std::vector<L> lh, lv; //線ごとの、実際の座標情報を持つ
	for(int i=0; i<n; i++){
		int a, b, c;
		std::cin >> a >> b >> c;
		mpx[a] = 0; //この段階では、要素の値は正直なんでも良い
		mpx[b] = 0;
		mpy[c] = 0;
		lh.emplace_back(a, b, c);
	}
	for(int i=0; i<m; i++){
		int a, b, c;
		std::cin >> c >> a >> b;
		mpy[a] = 0;
		mpy[b] = 0;
		mpx[c] = 0;
		lv.emplace_back(a, b, c);
	}

	// 座標圧縮
	//index順に実際の座標を記録する
	std::vector<int> sx, sy;
	for(auto& p : mpx){
		p.second = sx.size();
		sx.push_back(p.first);
	}
	for(auto& p : mpy){
		p.second = sy.size();
		sy.push_back(p.first);
	}

	// 壁を線ではなく、面積で扱う。圧縮した座標を2倍のサイズにする。
	int h = sx.size()*2; //horizontal
	int v = sy.size()*2; //vertical
	//壁の部分を-1とする配列を作る
	std::vector<std::vector<int>> d(h, std::vector<int>(v));
	for(int i=0; i<n; i++){
		int a = mpx[lh[i].a]*2;
		int b = mpx[lh[i].b]*2;
		int c = mpy[lh[i].c]*2;
		for(int x=a; x<=b; x++){
			d[x][c] = -1;
		}
	}
	for(int i=0; i<m; i++){
		int a = mpy[lv[i].a]*2;
		int b = mpy[lv[i].b]*2;
		int c = mpx[lv[i].c]*2;
		for(int y=a; y<=b; y++){
			d[c][y] = -1;
		}
	}

	//BFS
	std::queue<std::pair<int, int>> q;
	int tmpx = mpx[0]*2;
	int tmpy = mpy[0]*2;
	d[tmpx][tmpy] = 1;
	q.emplace(tmpx, tmpy);
	while(!q.empty()){
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		//移動
		for(int i=0; i<4; i++){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx >=h || nx < 0) continue;
			if(ny >=v || ny < 0) continue;
			if(d[nx][ny] != 0) continue;
			d[nx][ny] = 1;
			q.emplace(nx, ny);
		}
	}

	//到達しているマス(d = 1)の個数を数える
	//壁に到達せず、端のマスにたどり着いた場合、ans = INF
	long long ans = 0;
	for(int x=0; x<h; x++){
		for(int y=0; y<v; y++){
			if(d[x][y] != 1){ //到達できない
				continue;
			}
			if(x == 0 || x == h-1 || y == 0 || y == v-1){
				std::cout << "INF" << std::endl;
				return 0;
			}
			if(x%2  == 0 || y%2 == 0){ //壁
				continue;
			}
			//マスの圧縮前の面積を計算
			long long ex = sx[x/2 + 1] - sx[x/2];
			long long ey = sy[y/2 + 1] - sy[y/2];
			ans += ex * ey;

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

Measured memory_bytes: 144496
n,k=map(int,input().split())
s=input()
ans=0
if s[0]=="L" and s[n-1]=="R":
    c=s.count("LR")
    if k>=c:
        ans=n-1
    elif k==c-1:
        ans=n-2
    else:
        ans=n-2-2*(c-1)+2*k
elif s[0]=="L" and s[n-1]=="L":
    c=s.count("LR")
    if k>=c:
        ans=n-1
    else:
        ans=n-1-2*c+2*k
elif s[0]=="R" and s[n-1]=="R":
    c=s.count("LR")
    if k>=c:
        ans=n-1
    else:
        ans=n-1-2*c+2*k
else:
    c=s.count("RL")
    ans=n-c*2
    if k>=c:
        ans=n-1
    else:
        ans+=2*k
print(ans)

Measured memory_bytes: 39024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 5000 + 10;

int n;
char s[MAXN], t[MAXN];
std::vector <int> pos1, pos2;
int main() {
  scanf("%d%s%s", &n, s + 1, t + 1);

  pos1.push_back(0);
  pos2.push_back(0);
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i + 1]) pos1.push_back(i);
    if (t[i] != t[i + 1]) pos2.push_back(i);
  }
  pos1.push_back(n);
  pos2.push_back(n);

  int ans = 1e9;

  for (int i = (n & 1) == (s[1] == t[1]) ? -n - 1 : -n; i <= n + 1; i += 2) {
    int tot = 0;
    for (int j = 0; j < (int) pos1.size(); j++) {
      int x = i + j;
      if (x < 0) tot += pos1[j];
      else if (x >= (int) pos2.size()) tot += n - pos1[j];
      else tot += std::abs(pos2[x] - pos1[j]);
    }
    for (int j = 0; j < (int) pos2.size(); j++) {
      int x = j - i;
      if (x < 0) tot += pos2[j];
      else if (x >= (int) pos1.size()) tot += n - pos2[j];
    }
    
    // fprintf(stderr, "%d %d\n", i, tot);
    ans = std::min(ans, tot);
  }
  printf("%d\n", ans);
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) { os << p.first << " " << p.second; return os; }

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; }return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	int n = 5;
	vector<int>v(n); rep(i, 0, n) { cin >> v[i]; }
	int m = *min_element(all(v));

	cout << 4 + (N+m-1) / m << endl;


	return 0;
}


Measured memory_bytes: 256