akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

const int oo=1e16;
int n;
int g[305][305];
long long dist[305];
bool used[305];

struct Edge
{
    int u,v;
    long long  len;
}edge[90005];
int tot;
queue<int>q;
long long ans;

struct Edge1
{
    int num;
    int next;
    long long len;
}edge1[200000];
int tot1,last[305];
int fa[305];

bool cmp(Edge a,Edge b)
{
    return a.len<b.len;
}

long long spfa(int p,int t)
{
    q.push(p);
    for (int i=1;i<=n;i++)
        {
        dist[i]=oo;
        used[i]=0;
        }
    used[p]=1;
    dist[p]=0;
    while (q.empty()==0)
        {
        int u=q.front();
        for (int k=last[u];k!=0;k=edge1[k].next)
            {
            int v=edge1[k].num;
            if (dist[u]+edge1[k].len<dist[v])
                {
                dist[v]=dist[u]+edge1[k].len;
                if (used[v]==0)
                    {
                    q.push(v);
                    used[v]=1;
                    }
                }
            }
        q.pop();
        used[u]=0;
        }
    return dist[t];
}

void Add(int i,int j,long long len)
{
    tot1++;
    edge1[tot1].num=j;
    edge1[tot1].len=len;
    edge1[tot1].next=last[i];
    last[i]=tot1;
}

int Find(int k)
{
    if (k==fa[k]) return k;
    else return fa[k]=Find(fa[k]);
}

int main()
{
    scanf ("%d",&n);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            scanf ("%d",&g[i][j]);
    for (int i=1;i<=n;i++)
        for (int j=i+1;j<=n;j++)
            {
            tot++;
            edge[tot].u=i;
            edge[tot].v=j;
            edge[tot].len=(long long)g[i][j];
            }
    sort(edge+1,edge+1+tot,cmp);
    for (int i=1;i<=n;i++)
        fa[i]=i;

    for (int i=1;i<=tot;i++)
        {
        int a,b;
        a=Find(edge[i].u);
        b=Find(edge[i].v);
        if (a!=b)
            {
            fa[a]=b;
            Add(edge[i].u,edge[i].v,edge[i].len);
            Add(edge[i].v,edge[i].u,edge[i].len);
            ans+=edge[i].len;
            }
        else
            {
            long long t;
            t=spfa(edge[i].u,edge[i].v);
            if (t>edge[i].len)
                {
                Add(edge[i].u,edge[i].v,edge[i].len);
                Add(edge[i].v,edge[i].u,edge[i].len);
                ans+=edge[i].len;
                }
            else if (t<edge[i].len) {printf ("-1"); return 0;}

            }
        }
    printf ("%lld",ans);
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>

int n, a[110];
int main()
{
    std::cin >> n;
    double ave = 0;
    for (int i = 0; i < n; ++i)
    {
        std::cin >> a[i];
        ave += a[i];
    }
    ave /= n;

    double diff = 1000000;
    int num = 0;
    for (int i = 0; i < n; ++i)
    {
        auto res = a[i] - ave;
        if (res < 0)
            res *= -1;
        if (res < diff)
        {
            diff = res;
            num = i;
        }
    }

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


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

bool hani(long long int a, long long int b, long long int c) {
	if (a <= c && c <= b) {
		return true;
	}
	return false;
}

int main() {

	long long int k;
	cin >> k;

	vector<long long int> a(k);

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

	long long int l, r;
	l = r = 2;

	for (long long int i = k - 1; i >= 0; i--) {
		long long int l2, r2;
		if (l%a[i] == 0) {
			l2 = l;
		}
		else {
			l2 = ((l / a[i]) + 1)*a[i];
		}
		if (r%a[i] == 0) {
			r2 = r + a[i] - 1;
		}
		else {
			r2 = ((r / a[i]) + 1)*a[i] - 1;
		}

		//cout << l2 << ' ' << r2 << endl;

		if (l2 <= r2) {
			l = l2;
			r = r2;
		}
		else {
			l = r = -1;
			break;
		}
	}

	if (l == -1 && r == -1) {
		cout << -1 << endl;
	}
	else {
		cout << l << ' ' << r << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
  int H, W;
  char a[101][101];
  scanf("%d%d", &H, &W);
  for(int i = 0; i < H; i++){
    scanf("%s", a[i]);
    
  }

  int b[101]; int p = 0; int l = 0;

  for(int i = 0; i < H; i++){
    l = 0; 
    for(int j = 0; j < W; j++){
      if(a[i][j] == '#'){
	l += 1;
	break;
      }
    }
    if(l != 0){
      b[p] = i;
      p++;
    }
  }

  int c[101]; int q = 0;
  for(int j = 0; j < W; j++){
    l = 0;
    for(int i = 0; i < H; i++){
      if(a[i][j] == '#'){
	l += 1;
	break;
      }
    }
    if(l != 0){
      c[q] = j;
      q++;
    }
  }

   for(int i = 0; i < p; i++){
  for(int j = 0; j < q; j++){
    printf("%c", a[b[i]][c[j]]);
  }
  printf("\n");
  }
  return 0;
}
    


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <vector>

#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DV_NUM (100000007)

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

 const int MAX_N = 100000;
 const int MAX_X = (int)INF;
 const int MAX_L = (int)INF;

 bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}


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

    vector<pair<int, int> > pairs(N);
    vector<int> X(N);
    vector<int> L(N);


    FOR(i,0,N){
        cin >> X[i] >> L[i];
    }

    FOR(i,0,N){
        pairs[i].first = X[i]+L[i];
        pairs[i].second = X[i]-L[i];
    }

    sort(pairs.begin(), pairs.end(),compare_by_b);   

    int ans = 0, t = - MAX_L;
   
    FOR(i,0,N){
      if(t <= pairs[i].second) {
          ans++;
          t = pairs[i].first;
      }

    }

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

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC122B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var dict = new[] { 'A', 'C', 'G', 'T' };

            var max = 0;
            var length = 0;
            foreach (var c in input)
            {
                if (dict.Contains(c))
                {
                    length++;
                }
                else
                {
                    if (length > max)
                    {
                        max = length;
                    }
                    length = 0;
                }
            }

            if (length > max)
            {
                max = length;
            }

            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 13268
import java.util.*;


class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int maxProfit = b - a;
        
        int min = Math.min(a,b);  // the minimum number in the dataset 

        while(sc.hasNextInt()){
            int next = sc.nextInt();
            
            maxProfit = Math.max(maxProfit, next - min);
            
            min = Math.min(min, next);
        }


        System.out.println(maxProfit);
    }
}


Measured memory_bytes: 99644
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	ll a=h2*60+m2-h1*60-m1-k;
	cout<<a<<'\n';
	return 0;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t

const int MOD = 1e9+7;
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;
    if(2*n>=m) {
        cout<<(m/2);
    }   
    else {
        cout<<n+(m-2*n)/4;
    }

    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 MOD 1000000007
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n;
    cin>>n;
    vector<int> dat(n+1);
    rep(i,n){
        cin>>dat[i];
    }
    sort(dat.begin(),dat.end());
    reverse(dat.begin(),dat.end());
    ll first=0,second=0;
    rep(i,n){
        if(dat[i]==dat[i+1]){
            if(first==0){
                first=dat[i];
                i++;
            }
            else{
                second=dat[i];
                break;
            }
        }
    }
    cout<<first*second<<endl;
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll int mod=1e9+7;
int a[100100];
int main()
{
    memset(a,0,sizeof(a));
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i,j,k,m,n;
    int flag=0,flag1=0,sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        a[m]++;
    }
    int ans=0,cnt=0;
    for(i=1;i<=100000;i++)
    {
        if(a[i])
            sum++;
        if(a[i]>1&&!ans)
        {
            ans=a[i]-1;
        }
        else if(a[i]>1&&ans)
        {
            cnt=a[i]-1;
            if(ans>cnt)
            {
                ans-=cnt;
            }
            else if(ans<=cnt)
            {
                cnt-=ans;
                ans=cnt;
            }
        }
    }
    if(ans)
    {
        ans+=1;
        if(ans%2==0)
        {
            ans=2;
        }
        else if(ans%2!=0)
            ans=1;
        sum-=(ans-1);
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
vector<int> v[405];
int main()
{
	int n,m,ans=0;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	v[i].push_back(-1);
	for (int i=0;i<m;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		v[a[i]].push_back(i);
		v[b[i]].push_back(i);
	}
	for (int i=1;i<n;i++)
	{
		for (int j=i+1;j<=n;j++)
		{
			bool ok=1;
			multiset<int,greater<int> > s({v[i].back(),v[j].back()});
			while (*s.begin()!=-1)
			{
				if (*s.begin()==*next(s.begin()))
				{
					ok=0;
					break;
				}
				int idx=*s.begin();
				s.erase(s.begin());
				s.insert(*prev(lower_bound(v[a[idx]].begin(),v[a[idx]].end(),idx)));
				s.insert(*prev(lower_bound(v[b[idx]].begin(),v[b[idx]].end(),idx)));
			}
			ans+=ok;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 2304
import numpy as np
n = int(input())
a = np.array([int(a) for a in input().split()])


# とりあえず，答え（自分）と自分以外のxorのxorは全て同じになることはわかる．
# xor 可換そうだから，２つお互いを比べればそのindexのやつらのxorと同値っぽい
# 2つのxorだと1や0の数は絞られてきそう？
# 全体のxorはすべてを一度ずつ使ったxorになる
totalxor = a[0]
for i in range(1, len(a)):
  totalxor = totalxor^a[i]

print(' '.join([str(i^totalxor) for i in a]))
  








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

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

using namespace std;
using ll=long long;
const ll INF = 100000000;

int main(){
    char c;
    cin >> c;
    if (c>64&&c<=90){
        cout<<"A";
    } else{
        cout << 'a';
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    int N; cin >> N;
    vecl A(N); REP(i,N) cin >> A[i];
    vecl B(N),C(N);
    sort(A.begin(),A.end());
    if(N == 2) {
        cout << abs(A[0]-A[1]) << endl;
        return 0;
    }
    if(N%2 == 0) {
        vecl small,large;
        ll s = 0;
        REP(i,N) if(i < N/2) small.push_back(A[i]);
        else large.push_back(A[i]);
        REP(i,N/2) {
            //cout << small[i] <<" " << large[i] << endl;
            if(i == N/2-1) {
                s -= small[i];
                s += 2*large[i];
            } else if(i == 0) {
                s -= 2*small[i];
                s += large[i];
            } else {
                s -= 2*small[i];
                s += 2*large[i];
            }
        }
        cout << s << endl;
    } else {
        deque<ll> small,large,B,C;
        REP(i,N) if(i < N/2+1) small.push_back(A[i]);
        else large.push_back(A[i]);
        ll s = 0;
        REP(i,N/2) s += 2*large[i];
        REP(i,N/2+1) if(i < N/2-1) s -= 2*small[i];
        else s -= small[i];
        large.push_front(small.back());
        small.pop_back();
        ll t = 0;
        REP(i,N/2) t -= 2*small[i];
        REP(i,N/2+1) if(i < 2) t += large[i];
        else t += 2*large[i];
        cout << max(s,t) << endl;
    }
}

Measured memory_bytes: 6680
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

/*
 * 2 3 3 3
 * 4 2 3 1
 * pos -> (cur - nextmin) * cnt(gr)
 */
int main() {
	int n;
	cin >> n;
	map <int, int> mp, first;
	set <int> st;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		if (first[x] == 0) {
			first[x] = i;
		}
		mp[x]++;
		st.insert(x);
	}
	vector<int> v(all(st));
	reverse(all(v));
	vector <ll> ans(n + 1);
	ll sum = 0;
	int mn = MOD;
	for (int i = 0; i < (int) v.size(); i++) {
		sum += mp[v[i]];
		mn = min(mn, first[v[i]]);
		if (i + 1 < (int) v.size()) {
			ans[mn] += sum * (v[i] - v[i + 1]);
		}
		else {
			ans[mn] += sum * (v[i]);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << "\n";
	}
}


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

long long p[105];
long long w[105];
long long dp[105][100005];
long long n, k;

long long f(long long i, long long k){
    if(k < 0) return 1;
    if(i == n) return 0;
    long long &r = dp[i][k];
    if(r == -1){
        r = f(i + 1, k);
        if(w[i] <= k){
            r = max(r, f(i + 1, k - w[i]) + p[i]);
        }
    }
    return r;
}

main(){
    ios::sync_with_stdio(0); cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> n >> k;
    for(long long i = 0; i < n; i++){
        cin >> w[i] >> p[i];
    }
    cout << f(0, k);
}


Measured memory_bytes: 82304
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll N=2005;
ll a[N];
ll d[N];
ll q[N],s,t;
ll n,x;
ll ans=1e15;
int dist(int x,int y){
    if(x<y)
        return y-x;
    return y-x+n;
}
void Solve(ll l){
    s=1,t=0;
    ll sum=1ll*x*l;
    for(ll i=n-l+1;i<=n;i++){
        while(s<=t&&a[q[t]]>=a[i])
            t--;
        q[++t]=i;
    }
    for(ll i=1;i<=n;i++){
        while(s<=t&&dist(q[s],i)>l)
            s++;
        d[i]=a[i];
        if(s<=t)
            d[i]=min(d[i],a[q[s]]);
        while(s<=t&&a[q[t]]>=a[i])
            t--;
        q[++t]=i;
        sum+=d[i];
    }
    ans=min(ans,sum);
}
int main()
{
    scanf("%lld%lld",&n,&x);
    for(ll i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(ll i=0;i<n;i++){
        Solve(i);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=100000000000;

void display(long j,vector<long> x){
    cout<<"data "<<j<<" display_start"<<endl;
    for(int i=0;i<x.size();i++){
        cout<<x.at(i)<<" ";
    }
    cout<<endl<<"display_end"<<endl<<endl;
}


//main
int main() {
    
    //入力
    long N;
    cin>>N;
    vector<long> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    
    
    //計算
    long minimal =INF;
    long sum=0;
    bool odd=false;
    for(int i=0;i<N;i++){
        minimal=min(abs(A.at(i)),minimal);
        sum+=abs(A.at(i));
        if(A.at(i)<0) odd=(!odd);
    }
    
    
    //出力
    cout<<sum-(odd)*2*minimal<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <sstream>
#include <cctype>
#include <cmath>
#include <cstdio>
using namespace std;
#define MPI  3.14159265358979323846

struct Dice{
	int num[6];
	void roll(int,int,int&);
};

void Dice::roll(int c1,int c2,int &ans){
	if (c1 == num[0]){
		if (c2 == num[1])ans = num[2];
		else if (c2 == num[2])ans = num[4];
		else if (c2 == num[3])ans = num[1];
		else if (c2 == num[4])ans = num[3];
		else cout << "error" << endl;
	}
	if (c1 == num[1]){
		if (c2 == num[0])ans = num[3];
		else if (c2 == num[2])ans = num[0];
		else if (c2 == num[3])ans = num[5];
		else if (c2 == num[5])ans = num[2];
		else cout << "error" << endl;
	}
	if (c1 == num[2]){
		if (c2 == num[0])ans = num[1];
		else if (c2 == num[1])ans = num[5];
		else if (c2 == num[4])ans = num[0];
		else if (c2 == num[5])ans = num[4];
		else cout << "error" << endl;
	}
	if (c1 == num[3]){
		if (c2 == num[0])ans = num[4];
		else if (c2 == num[1])ans = num[0];
		else if (c2 == num[4])ans = num[5];
		else if (c2 == num[5])ans = num[1];
		else cout << "error" << endl;
	}
	if (c1 == num[4]){
		if (c2 == num[0])ans = num[2];
		else if (c2 == num[2])ans = num[5];
		else if (c2 == num[3])ans = num[0];
		else if (c2 == num[5])ans = num[3];
		else cout << "error" << endl;
	}
	if (c1 == num[5]){
		if (c2 == num[1])ans = num[3];
		else if (c2 == num[2])ans = num[1];
		else if (c2 == num[3])ans = num[4];
		else if (c2 == num[4])ans = num[2];
		else cout << "error" << endl;
	}
}

int main(){

	Dice Dice1;

	for (int i = 0; i < 6; i++){
		cin >> Dice1.num[i];
	}

	int n;
	cin >> n;

	int ans[25];
	for (int i = 0; i < n; i++){
		int c1, c2;
		cin >> c1 >> c2;
		Dice1.roll(c1, c2, ans[i]);
	}

	for (int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}

	return 0;
}


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

using namespace std;

#define int long long
int suff[4][4005];

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, ans = 0;
    cin >> n;
    string s;
    cin >> s;
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j <= 2; ++j) suff[j][i] = suff[j][i + 1];
        if (s[i] == 'R') suff[0][i]++;
        else if (s[i] == 'G') suff[1][i]++;
        else suff[2][i]++;
    }
    for (int i = 0; i < (int)s.size(); ++i) {
        for (int j = i + 1; j < (int)s.size() - 1; ++j) {
            int T = 2;
            if (s[i] == s[j]) continue;
            if ('R' != s[i] && s[j] != 'R') T = 0;
            else if ('G' != s[i] && s[j] != 'G') T = 1;
            ans += suff[T][j];
            int k = 2 * j - i;
            if (k < n && s[k] != s[i] && s[k] != s[j]) ans--;
        }
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 3740
#include<iostream>
#include<string>
int main() {
	std::string c;
std::cin >> c;
if("a"==c || "e"==c || "i"==c || "o"==c || "u"==c) {
std::cout << "vowel" << std::endl;
}
else {
std::cout << "consonant" << std::endl;
}
	
		
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

const ull GOSENTYO = 5e+15;

int main(void) {

    string s;
    size_t k;
    cin >> s;
    cin >> k;

    for(size_t i = 0; i < min(k, s.size()); ++i) {
       if(s[i] != '1'){
           cout << s[i] << endl;
           return 0;
       }
    }

    cout << "1" << endl;
    
    return 0;
}

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

int main(){
  int a,b;
  static int A[5000],B[5000],dp[2][5001];
  scanf("%d %d",&a,&b);
  for(int i=0;i<a;i++) scanf("%d",A+i);
  for(int i=0;i<b;i++) scanf("%d",B+i);
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      if(i==0||j==0) dp[i%2][j] = 0;
      else if(A[i-1]==B[j-1]){
        dp[i%2][j] = max(dp[(i-1)%2][j],dp[(i-1)%2][j-1]+1);
      }else{
        dp[i%2][j] = dp[(i-1)%2][j];
      }
    }
  }
  int ans = 0;
  for(int i=0;i<=b;i++) ans = max(ans,dp[a%2][i]);
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 2832
#include<stdio.h>
	#include <set>
	#include<map>
	#include<string.h>
	#include <cmath>
	#include <queue>
	#include <stack>
	#include <vector>
	#include <string>
	#include <cstdio>
	#include <cstdlib>
	#include <cstring>
	#include <iomanip>
	#include <iostream>
	#include <algorithm>
	#define FOR(i,a,b) for (int i=(a);i<(b);i++)
	using namespace std;
	typedef long long ll;
	const ll INF = 0x3f3f3f3f;
	const ll MOD=1000000007;
	#define in(a) scanf("%d",&(a))
	inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
          ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
                    }
	ll i,j,k,l,n,m,sum,maxx,minn,ans,x,y,flag,cc,t;
	char ch[101];
	int main()
	{
        cin>>ch;
        for(int i=0;ch[i]!='\0';i++)
            {
                if(ch[i]=='C')
                sum=1;
            if(ch[i]=='F'&&sum)
                {cout<<"Yes"<<endl;return 0;}
            }

                cout<<"No"<<endl;
	    return 0;
    }


Measured memory_bytes: 256
import sys

def solve():
    A = []
    B = []
    for i, line in enumerate(sys.stdin):
        t = tuple(map(int, line.split()))
        if i % 2 == 0:
            A.append(t)
        else:
            B.append(t)
    
    for a, b in zip(A, B):
        hit, blow = 0, 0
        
        for i, bb in enumerate(b):
            for j, aa in enumerate(a):
                if bb == aa and i == j:
                    hit += 1
                    break
                elif bb == aa and i != j:
                    blow += 1
                    break
        print(hit, blow)
        

if __name__ == "__main__":
    solve()



Measured memory_bytes: 5600
#include <bits/stdc++.h>
 
 
using namespace std;
 
#define ll long long
#define ul unsigned long long
#define snd second
#define fst first
 

ll a,b,c,d,e,f,n,m;

int main(){
    std::ios::sync_with_stdio(false);
    cin >> a;
    ll z = 1;
    while( z <= a){
        z *= 2;
    }
    cout << z - 1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N (int)2e5
int n,k,memo[N],c[N];

int dp(int curr) {
    if (curr == n) return 0;
    if (curr > n) return 1e9;
    int &sol = memo[curr];
    if (sol != -1) return sol;
    int keep = INT_MAX;
    for (int i = 1 ; i <= k ; i++) {
        keep = min(
            dp(curr + i) + abs(c[curr] - c[curr + i]) ,
            keep
        );
    }
    return sol = keep;
}

int main() {
    scanf("%d%d" , &n , &k);
    for (int i = 1 ; i <= n ; i++)
        scanf("%d" , &c[i]);
    memset (memo , -1 , sizeof memo);
    printf("%d\n" , dp(1));
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<ll> dp(n+1);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i = 2; i < n; i++) {
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout << dp[n-1] << "\n";
    return 0;
} 

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T> T count_bit(T p){
  if(typeid(p)==typeid(int))return __builtin_popcount(p);
  else if(typeid(p)==typeid(long))return __builtin_popcountl(p);
  else return __builtin_popcountll(p);
}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  long x,a;
  in(x,a);
  if(x<a)out(0);
  else out(10);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N= 1e5+5;
int n,a[N][26];
char s[N];
int main(){
  scanf("%s",s+1);
  n=strlen(s+1);
  for(int i=1;i<=n;++i){
    for(int j=0;j<26;++j)a[i][j]=a[i-1][j];
     ++a[i][s[i]-'a'];  
  }
  for(int i=2;i<=3;++i){
    for(int j=1;j<=n;++j){
      int k1=j+i-1;if(k1>n)break;
      int p=i/2;++p;
      for(int k=0;k<26;++k){
        if(a[k1][k]-a[j-1][k]>=p){
          printf("%d %d\n",j,k1);
          return 0;
        }
      }
    }
  }
  printf("-1 -1\n");
  return 0;
}

Measured memory_bytes: 10496
l = ('A', 'T', 'C', 'G')
S = input()

ans, res = 0, 0
for i in range(len(S)):
    if S[i] in l:
        res += 1
    else:
        ans = max(ans, res)
        res = 0
ans = max(ans, res)

print(ans)

Measured memory_bytes: 8964
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};

int f(int a,int b){
    int res = 0;
    if(a >= b){
        while(a){
            a/=10;
            res++;
        }
    }else{
        while(b){
            while(b){
                b/=10;
                res++;
            }
        }
    }
    return res;
}


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

    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    ll sum = 0;
    ll ans = 0;
    vector<ll> s;
    rep(i,n){
        if(a[i] < b[i]){
            ans++;
            sum += b[i] - a[i];
        }else if(a[i] > b[i]){
            s.push_back(a[i]-b[i]);
        }
    }
    if(sum == 0){
        cout << 0 << endl;
        return 0;
    }
    sort(all(s),greater<ll>());
    rep(i,s.size()){
        sum -= s[i];
        ans++;
        if(sum <= 0){
            break;
        }
    }
    if(sum > 0){
        cout << -1 << endl;
        return 0;
    }else{
        cout << ans << endl;
    }


    cout << endl;
    return 0;
}


Measured memory_bytes: 2428
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func print(a []int) {
	var str string
	for _, v := range a {
		str += fmt.Sprintf("%d ", v)
	}
	fmt.Println(strings.TrimRight(str, " "))
}

func insertionSort(a []int) {
	print(a)
	for i := 1; i <= len(a)-1; i++ {
		now := a[i]
		leftI := i - 1
		for ; 0 <= leftI && now < a[leftI]; leftI-- {
			a[leftI+1] = a[leftI]
		}
		a[leftI+1] = now
		print(a)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, nextInt())
	}
	insertionSort(a)
}



Measured memory_bytes: 3464
INF = 10 ** 20
l, n = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)] + [[l, 0, INF]]
lst.sort()
score = {}
for p, _, _ in lst:
  score[p] = p
for i in range(n + 1):
  p, d, t = lst[i]
  for j in range(i + 1, n + 1):
    to_p, _, _ = lst[j]
    if to_p >= p + d:
      score[to_p] = min(score[to_p], score[p] + t + to_p - p - d, score[p] + to_p - p)
    else:
      score[to_p] = min(score[to_p], score[p] + to_p - p)
print(score[l])


Measured memory_bytes: 5720
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MAXX 1000000000000000000

int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int x,i,j,n,m;
	cin >> x;
	for(i=1;i<=3987;i++)
	{
		n = pow(i,5);
      	int fl = 0;
		m = n - x;
		if(m < 0)
        {
          fl = 1;
          m *= -1;
        }
		j = pow(m, 0.2);

		if(pow(j,5) == m)
		{
          	if(fl)
				j *= -1;
			cout << i << " "<<j<<endl;
			return 0;
		}

	}
	
	
	
	return 0;
}

Measured memory_bytes: 4136
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, m = MAP()
A = LIST()
B = LIST()
A_s = sorted(A)
B_s = sorted(B)
# print(A)
# print(B)
L = [LIST() for i in range(m)]

ans = A_s[0] + B_s[0]
for x, y, c in L:
    # print(x, y, c)
    v = A[x-1] + B[y-1] - c
    if ans > v:
        ans = v
print(ans)


# exit()


# D = [[0] * b for i in range(a)]
# for x,y,c in L:
#     D[x-1][y-1] = max(D[x-1][y-1], c)
# ans = INF
# C = [[0] * b for i in range(a)]
# for i in range(a):
#     for j in range(b):
#         ans = min(A[i] + B[j] - D[i][j], ans)
        
# print(ans)

# # exit()

# # for x, y, c in L:
# #     C[x-1][y-1] = min(C[x-1][y-1], C[x-1][y-1]-c)

# # print(min(C))


# # #     ans.append(A[x-1] + B[y-1] - c)
# # # print(min(ans))



# # exit()
# # s = input()
# # m= "hi"
# # # for i in range():
# # l = len(s) // 2
# # if l * m == s:
# #     print("Yes")
# # else:
# #     print("No")

# # # if s // 2



Measured memory_bytes: 42112
if __name__ == '__main__':
    islands_count, demands_count = list(map(int, input().split()))
    demands = []
    break_count = 0

    for i in range(demands_count):
        demand = list(map(int, input().split()))
        demands.append(demand)

    demands.sort(key=lambda x: x[1])
    west_edge = 0

    for demand in demands:
        if demand[0] >= west_edge:
            break_count += 1
            west_edge = demand[1]

    print(break_count)


Measured memory_bytes: 29080
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int a[2][110] = {0};
    for(int i=1; i <= n; i++) cin >> a[0][i];
    for(int i=1; i <= n; i++) cin >> a[1][i];
    for(int i=1; i<= n; i++){
        a[0][i] += a[0][i-1];
        a[1][i] += max(a[0][i], a[1][i-1]);
    }
    cout << a[1][n] << endl;
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	string s;
  cin >> s;

  int ans = 0;
  for(int i = 0; i < s.size(); ++i){
    if(s[i] == '+') ans++;
    if(s[i] == '-') ans--;
  }

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



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC diagnostic ignored "-Wunused-result"

#include <cstdio>
#include <chrono>
#include <random>

using namespace std;
using namespace chrono;

constexpr int c_max = 26;
constexpr int D = 365;
constexpr int INF = 1e9;
constexpr int time_limit = 1987;

int c[c_max];
int s[D][c_max];
int best_score[D];
int last[c_max];
int schedule[D];

inline int calc_score(const int &day, const int &examining) {
  int ret;
  if (day == 0) ret = s[day][examining];
  else ret = best_score[day - 1] + s[day][examining];
  
  for (int i = 0; i < c_max; i++) {
    if (i == examining) continue;
    ret -= (day - last[i]) * c[i];
  }

  return ret;
}

inline int calc_score_diff(const int &day1, const int &day2) {
  int prev_interval_1 = 0;
  for (int i = day1 - 1; i >= 0; i--) {
    prev_interval_1++;
    if (schedule[i] == schedule[day1]) break;
  }

  int prev_interval_2 = 0;
  for (int i = day2 - 1; i >= 0; i--) {
    prev_interval_2++;
    if (schedule[i] == schedule[day2]) break;
  }

  int new_interval_1 = 0;
  for (int i = day2 - 1; i >= 0; i--) {
    new_interval_1++;
    if (schedule[i] == schedule[day1]) break;
  }

  int new_interval_2 = 0;
  for (int i = day1 - 1; i >= 0; i--) {
    new_interval_2++;
    if (schedule[i] == schedule[day2]) break;
  }

  int ret = s[day1][schedule[day2]] + s[day2][schedule[day1]]
          - s[day1][schedule[day1]] - s[day2][schedule[day2]];
  
  ret += c[schedule[day1]] * ((prev_interval_1 + 1) * prev_interval_1 - (new_interval_1 + 1) * new_interval_1) / 2;
  ret += c[schedule[day2]] * ((prev_interval_2 + 1) * prev_interval_2 - (new_interval_2 + 1) * new_interval_2) / 2;

  return ret;
}

int main() {
  system_clock::time_point start = system_clock::now(), now;

  random_device seed;
  mt19937 rnd(seed());

  /* input */
  scanf("%*d");

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

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < c_max; j++) {
      scanf("%d", &s[i][j]);
    }
  }

  /* calc initial solution */
  for (int d = 0; d < D; d++) {
    int best = -INF;
    int contest_to_hold = 0;
    for (int type = 0; type < c_max; type++) {
      int score = calc_score(d, type);
      if (best < score) {
        best = score;
        contest_to_hold = type;
      }
    }
    last[contest_to_hold] = d;
    schedule[d] = contest_to_hold;
  }

  /* try and error */
  int day1, day2, score_diff, tmp;
  while (1) {
    now = system_clock::now();
    if (duration_cast<milliseconds>(now - start).count() > time_limit) break;
    day1 = rnd() % D;
    day2 = rnd() % D;
    score_diff = calc_score_diff(day1, day2);
    if (score_diff > 0) {
      tmp = schedule[day1];
      schedule[day1] = schedule[day2];
      schedule[day2] = tmp;
    }
  }

  /* output */
  for (const int &x : schedule) {
    printf("%d\n", x+1);
  }

  return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long b[200005],c[200005];
int main()
{
    long long n,m,i,j,k,x=0,y,z,t;
    cin>>i>>j>>k;
    if(k==i)
    {
        cout<<0<<" "<<j<<endl;
    }
    else if(k>i)
    {
        k=k-i;
        y=j-k;
        cout<<0<<" ";
        if(y<0)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<y<<endl;
        }
    }
    else
    {
        cout<<i-k<<" "<<j<<endl;
    }
 
}

Measured memory_bytes: 256
def solve():
    N = int(input())

    LIS = []
    for _ in range(N):
        LIS.append(tuple(map(int, input().split())))
    # print(LIS)

    A, B = 1, 1
    for (x, y) in LIS:
        # print("current:", A, B)
        # print("ratio  :", x, y, "\n")
        if x == y:
            m = max(x, max(A, B))
            A, B = m, m
        elif A <= x and B <= y:
            A, B = x, y
        else:
            # div = max(ceil(A / x), ceil(B / y)) 誤差でWAになる
            div = max((A + x - 1) // x, (B + y - 1) // y)
            A = x * div
            B = y * div

    return A + B


if __name__ == '__main__':
    res = solve()
    print(res)


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

using namespace std;

int main(){

	int n, sco=0;
	vector<int> v, c;

	cin>> n;
	v.resize(n);
	c.resize(n);

	for(int i=0;i<n;i++) cin>> v[i];
	for(int i=0;i<n;i++){
		cin>> c[i];
		if(c[i]<v[i]) sco+=v[i]-c[i];
	}

	cout<< sco << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }



void solve() {
   int n;
   cin>>n;
   int x=n%10;
   if(x==2 || x==4 || x==5 || x==7  || x==9) 
     cout<<"hon\n";
   else if(x==0 || x==1 || x==6 ||x==8)  
    cout<<"pon\n";
   else 
     cout<<"bon";   
     
 }

    
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	  solve();

return 0;	   
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#define rep(i, n)for(int i=0; i<n; i++)
using ll = long long int;
using namespace std;

int main() {
    string s, ss, p;
    cin >> s >> p;    
    ss = s + s;
    bool flag = false;
    rep(i, s.size()){
        if(ss.substr(i, p.size()) == p){
            flag = true;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3232
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    ans = 0
    for h in H:
        if h >= K:
            ans += 1
    print(ans)


sol()

Measured memory_bytes: 12324
#include<stdio.h>
#define inf 1000000000000ll
long long f(long long b, long long n){
	if (n<b) return n;
	else return f(b,n/b)+n%b;
}
int main(void){
	long long n,s;
	scanf("%lld%lld",&n,&s);
	if (n<s){
		printf("-1");
	}
	else if (n==s){
		printf("%lld",n+1);
	}
	else {
		long long p=n-s,ans=inf;
		for (int i=1;1ll*i*i<=p;i++)
		if (p%i==0){
			if (f(1ll*i+1,n)==s&&ans>i+1){
				ans=i+1;
			}
			if (f(p/i+1,n)==s&&ans>p/i+1){
				ans=p/i+1;
			}
		}
		if (ans!=inf){
			printf("%lld",ans);
		}
		else {
			printf("-1");
		}
	}
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if(x - r < 0 || x + r > W || y - r < 0 || y + r > H) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
		sc.close();
	}
}


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

int main()
{
  int a[100001],b[100001];
  string s;
  
  while(1){
    cin>>s;
    if(s[0]=='#')break;
    for(int i=0;i<s.length();i++)s[i]=(s[i]-'0'-1)%3+'0';

    int ansa=0,ansb=0;
    a[0]=1;b[0]=-1;
    for(int i=0;i<s.length()-1;i++){
      if(a[i]==1){
	if(s[i]<s[i+1]){
	  ansa++;
	  a[i+1]=a[i];
	}
	else a[i+1]=-a[i];
      }
      if(a[i]==-1){
	if(s[i]>s[i+1]){
	  ansa++;
	  a[i+1]=a[i];
	}
	else a[i+1]=-a[i];
      }
      if(b[i]==1){
	if(s[i]<s[i+1]){
	  ansb++;
	  b[i+1]=b[i];
	}
	else b[i+1]=-b[i];
      }
      if(b[i]==-1){
	if(s[i]>s[i+1]){
	  ansb++;
	  b[i+1]=b[i];
	}
	else b[i+1]=-b[i];
      }
    }
    cout<<min(ansa,ansb)<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int n, a, b;
    char s[100005];
    cin >> n >> a >> b;
    
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    
    int passed_dom = 0;
    int passed_ovs = 0;
    int failed = 0;
    
    for(int i=0; i<n; i++){
        if(s[i]=='a'){
            if((passed_dom + passed_ovs) < (a + b)) {
                passed_dom += 1;
                cout << "Yes\n";
            }else{
                failed += 1;
                cout << "No\n";
            }
        }else if(s[i]=='b'){
            if(((passed_dom + passed_ovs) < (a + b)) && (passed_ovs < b)){
                passed_ovs += 1;
                cout << "Yes\n";
            }else{
                failed += 1;
                cout << "No\n";
            } 
        }else{
                failed += 1;
                cout << "No\n";
        } 
    }
    
    return 0;
}

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

int n;

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

  int c = 0;
  for (pii p : m) {
    if (p.second % 2 == 1) c++;
  }

  cout << c << endl;

  return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m=0,x=0;
    cin>>n;

        x=n/500;
        n=n%500;
    m+=x*1000;
    x=n/5;
    m+=x*5;

    cout<<m<<endl;

    return 0;
}


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

int main() {
  int N,M,ans=0;
  cin >> N >> M;
  vector<int> ball(N,1);
  vector<bool> red(N,false);
  red[0] = true;
  
  for(int i=0;i<M;i++){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    
    ball[x]--;
    ball[y]++;
    if(red[x]==true) red[y] = true;
    if(ball[x]==0) red[x] = false;
  }
  
  for(int i=0;i<N;i++){
    if(red[i]==true) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
program TNEP
    implicit none
    integer n, m, i, ans
    integer :: r = 2, ansg = 1, ansk = 1
    read *, n, m
    if(n .ge. 2)then
        do i = 1, r
            ansg = ansg*(n - i + 1)/i
        end do
    end if
    if(m .ge. 2)then
        do i = 1, r
            ansk = ansk*(m - i + 1)/i
        end do
    end if
    if(n .ge. 2 .and. m .ge. 2)then
        ans = ansk + ansg
        print *, ans
    else if(n .ge. 2 .and. m .lt. 2)then
        print *, ansg
    else if(n .lt. 2 .and. m .ge. 2)then
        print *, ansk
    else if(n .lt. 2 .and. m .lt. 2)then
        print *, 0
    end if
end program

Measured memory_bytes: 2856
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

struct GetNumberOfTrailingZeros {
  constexpr GetNumberOfTrailingZeros() : table() {
    uint64_t hash = 0x03F566ED27179461UL;

    for (int i = 0; i < 64; i++)
    {
      table[hash >> 58] = i;
      hash <<= 1;
    }
  }
  int Calc(int64_t x)
  {
    if (x == 0) return 64;

    uint64_t y = (uint64_t)(x & -x);
    int i = (int)((y * 0x03F566ED27179461UL) >> 58);
    return table[i];
  }
  int table[64];
} gntz;


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int N, M;
  cin >> N >> M;
  vector<int> as(M);
  vector<int> bs(M);
  vector<vector<int>> cs(N);
  F0R(i, M) {
    int a, b;
    cin >> a >> b;
    as[i] = a;
    F0R(j, b) {
      int c;
      cin >> c;
      c--;
      cs[c].push_back(i);
      bs[i] |= 1 << c;
    }
  }
  int cl = M, ci;
  F0R(i, N) {
    if (cs[i].size() == 0) {
      cout << -1;
      return 0;
    }
    if (cs[i].size() < cl) {
      cl = cs[i].size();
      ci = i;
    }
    sort(rng(cs[i]), [&as](int l, int r) {
      return as[l] < as[r];
      });
  }

  int result = INT32_MAX;
  int all = (1 << N) - 1;
  auto dfs = [&](auto dfs, int bits, int cost, int ci)->void {

    F0R(i, cs[ci].size()) {
      int nb = bits | bs[cs[ci][i]];
      int nc = cost + as[cs[ci][i]];
      if (result <= nc) continue;
      if (nb == all) {
        result = nc;
        continue;
      }
      dfs(dfs, nb, nc, gntz.Calc(~nb));
    }
  };
  dfs(dfs, 0, 0, ci);
  cout << (result > 10000000 ? -1 : result);
}
#endif


Measured memory_bytes: 384