akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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;
}

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) { //にぶたんgreater
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<ll> Divisor(ll x) { // 約数列挙
	vector<ll> result;
	ll i=1LL;
	for( ; i*i<x; i++) {
		if(x%i) continue;
		result.push_back(i);
		result.push_back(x/i);
	}
	if(i*i==x&&x%i==0)
		result.push_back(i);
	
	sort(result.begin(),result.end());
	return result;
}

vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数}
	vector<llpair> result;
	ll ex=0LL;
	if(x%2==0) {
		while(x%2==0) {
			x/=2;
			ex++;
		}
		result.push_back({2,ex});
	}

	for(ll i=3LL; i*i<=x; i+=2) {
		if(x%i) continue;

		ex=0LL;
		while(x%i==0) {
			x/=i;
			ex++;
		}
		result.push_back({i,ex});
	}

	if(x!=1) result.push_back({x,1});

	return result;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

int main() {
	ll S; cin>>S;
	ll x1=0LL, y1=0LL;
	ll x2=1000000000LL,y2=1LL;
	ll x3=(1000000000LL-S%1000000000LL)%1000000000LL;
	ll y3=(S+x3)/1000000000LL;

	printf("%lld %lld %lld %lld %lld %lld\n",x1,y1,x2,y2,x3,y3);
}


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


int main()
{
    std::string val1, val2;
    getline(std::cin, val1);
    getline(std::cin, val2);

    const int length = val1.length();

    if (val1.substr(0, length) == val2.substr(0, length))
    {
        std::cout << "Yes";
    }
    else
    {
        std::cout << "No";
    }
}

Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 100000 + 10;
const int mod = 1e9+7;
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    IOS
    int n, x, hh = 0;
    cin >> n;
    x = n;
    while(x){
        hh += x%10;
        x/=10;
    }
    if(n%hh==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
    string S;  cin >> S;
    bool flag = true;
    int n = S.length();
    
    if(S.substr(n-7,7) == "keyence"){
        cout << "YES" << endl;
        return 0;
    }else if(S.substr(0,1) == "k" && S.substr(n-6,6) == "eyence"){
        cout << "YES" << endl;
        return 0;
    }else if(S.substr(0,2) == "ke" && S.substr(n-5,5) == "yence"){
        cout << "YES" << endl;
        return 0;
    }else if(S.substr(0,3) == "key" && S.substr(n-4,4) == "ence"){
        cout << "YES" << endl;
        return 0;
    }else if(S.substr(0,4) == "keye" && S.substr(n-3,3) == "nce"){
        cout << "YES" << endl;
        return 0;
    }else if(S.substr(0,5) == "keyen" && S.substr(n-2,2) == "ce"){
        cout << "YES" << endl;
        return 0;
    }else if(S.substr(0,6) == "keyenc" && S.substr(n-1,1) == "e"){
        cout << "YES" << endl;
        return 0;
    }else if(S.substr(0,7) == "keyence"){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int v[100009];

int main(){
	int e=0,o=0;
	DRI(n);
	REP(i,n){
		RI(v[i]);
		if(v[i]%2)o++;
		else e++;
	}
	if(n==1){
		if(v[0]%2)printf("Second");
		else printf("First");
		return 0;
	}
	REPP(i,1,n){
		if(((v[0]%2==0)&&(v[i]%2))||v[i]==1)swap(v[0],v[i]);
	}
	if((v[0]==1||o!=1)&&(o%2==n%2)){
		printf("Second");return 0;
	}
	if((v[0]==1||o!=1)&&(o%2!=n%2)){
		printf("First");return 0;
	}
	bool isp1=1;
	while(1){
		isp1^=1;
		v[0]--;
		int gc=v[0];
		REPP(i,1,n){
			gc=__gcd(gc,v[i]);
		}
		REP(i,n)v[i]/=gc;
		int ended=1;
		REP(i,n){
			ended&=(v[i]==1);
		}
		if(ended){
			if(isp1)printf("Second");
			else printf("First");
			return 0;
		}
		e=0,o=0;
		REP(i,n){
			if(v[i]%2)o++;else e++;
		}
		REPP(i,1,n){
			if(((v[0]%2==0)&&(v[i]%2))||v[i]==1)swap(v[0],v[i]);
		}
		if((v[0]==1||o!=1)&&(o%2==n%2)){
			if(isp1)printf("Second");
			else printf("First");
			return 0;
		}
		if((v[0]==1||o!=1)&&(o%2!=n%2)){
			if(isp1)printf("First");
			else printf("Second");
			return 0;
		}
	}
}


Measured memory_bytes: 768
#include<stdio.h>
 
main()
{
	int candy[3] ;
	int i , j ;
	int max ;
 
	scanf("%d %d %d", &candy[0] , &candy[1] , &candy[2]);
 
	i = 1 ;
	j = 0 ;
	max = candy[0] ;
	while(i < 3)
	{
		if(candy[i] > max)
		{
			max = candy[i] ;
			j = i ;
		}
		i++;
	}
 
	if(j != 0)
	{
		candy[j] = candy[0] ;
	}
 
	if(max == candy[1] + candy[2])
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
 
	return 0 ;
}


Measured memory_bytes: 128
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  LL N;
  cin >> N;
  vector<LL> L(N);
  LL sum = 0;
  REP(i, N)
  {
    cin >> L[i];
    sum += L[i];
  }

  BACKSORT(L);
  if(L[0]<sum-L[0]){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }


}


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

ll INF = 1LL << 60;

int
GCD(int x, int y)
{
  return y ? GCD(y, x % y) : x;
}

int 
main() {
  int N; cin >> N;
  vector<int> arr(N);
  rep(i, 0, N) cin >> arr[i];

  if(N == 2){
    int maxi = max(arr[0], arr[1]);
    cout << maxi << endl;
    return 0;
  }

  vector<int> left(N);
  left[0] = arr[0];
  rep(i, 0, N - 1){
    left[i + 1] = GCD(left[i], arr[i + 1]);
  }

  vector<int> right(N);
  right[0] = arr[N - 1];
  rep(i, 0, N - 1){
    right[i + 1] = GCD(right[i], arr[N - 2 - i]);
  }

  int ans = right[N - 2];
  rep(i, 0, N){
    int comp = GCD(left[i], right[N - i - 3]);
    if(ans < comp) ans = comp;
  }

  int comp = GCD(ans, left[N - 2]);
  if(ans < comp) ans = comp;

  cout << ans << endl;

}


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

int main(){
    int x; cin >> x;
    if(x==0) cout << 1 << endl;
    if(x==1) cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

const int MAX_N = 200005;
int n, m, t;
int h[MAX_N];
int f[MAX_N];
bool mark[MAX_N];
bool ans[MAX_N];
vector<int> G[MAX_N];

void dfs(int v){
    mark[v] = true;
    f[v] = h[v];
    for(int i = 0; i < G[v].size(); i++){
        int u = G[v][i];
        if(!mark[u]){
            h[u] = h[v] + 1;
            dfs(u);
            if(v == 0) t++;
            if(v != 0 && f[u] >= h[v]) ans[v] = true;
            f[v] = min(f[v], f[u]);
        }
        else if(h[u] < h[v] - 1) f[v] = min(f[v], h[u]);
    }
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i = 0; i < m; i++){
        int v, u;
        scanf("%d %d", &v, &u);
        G[v].push_back(u);
        G[u].push_back(v);
    }

    dfs(0);

    if(t > 1) ans[0] = true;
    for(int i = 0; i < n; i++) if(ans[i]) printf("%d\n", i);
    return 0;
}



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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0;i < n;i ++){
        cin >> s.at(i);
    }

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

    string ans1 = "",ans2 = "";

    ans1 = s.at(0);

    for(int i = 1;i < n;i ++){
        for(int j = ans1.size()-1;j >= 0;j --){
            for(int k = 0;k < s.at(i).size();k ++){
                if(ans1.at(j) == s.at(i).at(k)){
                    ans2 += ans1.at(j);
                    s.at(i).at(k) = '1';
                    break;
                }
            }
            ans1.pop_back();
            if(ans1.size() == 0){
                break;
            }
        }
        ans1 = ans2;
        ans2 = "";
        if(ans1.size() == 0){
            break;
        }
    }

    sort(ans1.begin(),ans1.end());
    cout << ans1 << endl;

}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int a,b,c;
inline void solve(){
  IN3(a,b,c);
  if(a==b&&b==c)OUT(1);
  else if(a==b||b==c||c==a)OUT(2);
  else OUT(3);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int par1[200001],par2[200001];
vector<pair<int,int>> idx;
map<pair<int,int>,int> cnt;
int rep1(int n)
{
    if(par1[n]==n)
        return n;
    return par1[n]=rep1(par1[n]);
}
int rep2(int n)
{
    if(par2[n]==n)
        return n;
    return par2[n]=rep2(par2[n]);
}
int main()
{
    int i,j;
    int n,k,l;
    int a,b,res=0;
    scanf("%d %d %d",&n,&k,&l);
    for(i=1;i<=n;i++){
        par1[i]=i;
        par2[i]=i;
    }
    for(i=0;i<k;i++){
        scanf("%d %d",&a,&b);
        int r1=rep1(a);
        int r2=rep1(b);
        par1[r1]=r2;
    }
    for(i=0;i<l;i++){
        scanf("%d %d",&a,&b);
        int r1=rep2(a);
        int r2=rep2(b);
        par2[r1]=r2;
    }
    for(i=1;i<=n;i++){
        idx.push_back(make_pair(rep1(i),rep2(i)));
    }
    /*
    sort(idx.begin(),idx.end());
    set<pair<int,int>> temp;
    for(i=0;i<idx.size();i++){
        temp.insert(idx[i]);
        cnt[idx[i]]++;
        //printf("%d %d\n",idx[i].first,idx[i].second);
    }
    for(auto itr: temp){
        res+=(cnt[itr])*(cnt[itr]);
    }
    */
    for(i=0;i<idx.size();i++){
        cnt[idx[i]]++;
        //printf("%d %d\n",idx[i].first,idx[i].second);
    }
    for(i=0;i<idx.size();i++)
        printf("%d ",cnt[idx[i]]);
}


Measured memory_bytes: 15088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  ll a,b;
  cin>>a>>b;
  if(a==b || a+1==b || a==b+1) cout<<"Brown"<<endl;
  else cout<<"Alice"<<endl;
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }			//最小公倍数(Least Common Multiple)

long long comb(long long m) {
	return (m * (m - 1)) / 2;
}


int main() {
	int a,b;
	cin >> a>>b;
	

	cout << a*b << endl;


}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;


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

    ll A;
    string B;
    cin >> A >> B;
    int b = (B[0] - '0') * 100 + (B[2] - '0') * 10 + (B[3] - '0');
    cout << (ll)(A * b / 100) <<endl;
    
    return 0;
}


Measured memory_bytes: 3652
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <stdio.h>

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    m = n*3 + m;
    printf("%d",m/2);

    return 0;
}


Measured memory_bytes: 128
n, y = map(int, input().split())
y //= 1000

ANS = []

for i in range(n + 1):
    for j in range(n + 1):
        k = n - i - j
        if (k >= 0) and (10*i + 5*j + k == y):
            ANS = [i, j, k]
            break

if len(ANS) > 0:
    print(*ANS)
else:
    print(-1, -1, -1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int timer=0;
vector<int> a[N] , tin(N) , tout(N);
long long ans[N+5];

void dfs(int x , int p=-1){
  tin[x] = ++timer;
  for(auto i : a[x])
    if(i != p)
      dfs(i,x);
  tout[x] = timer;
}

int main(){
  int n,q;
  cin>>n>>q;
  
  for(int i=1 ; i<n ; ++i){
    int u,v;
    cin>>u>>v;
    
    a[u].push_back(v);
    a[v].push_back(u);
  }
  
  memset(ans,0,sizeof ans);
  dfs(1);
  while(q--){
    int p,x;
    cin>>p>>x;
    ans[tin[p]] += x;
    ans[tout[p]+1] -= x;
  }
  
  for(int i=2 ; i<=n ; ++i)
    ans[i] += ans[i-1];
  
  for(int i=1 ; i<=n ; ++i)
    cout<<ans[tin[i]]<<" ";
    
}



Measured memory_bytes: 25856
n = int(input())
monsters = [int(value) for value in input().split()]
heros = [int(value) for value in input().split()]

#倒すことのできるモンスターの数
defeatable_monsters = 0

#リストを逆順にする
rev_monsters = monsters[::-1]
rev_heros = heros[::-1]

for offset, hero in enumerate(rev_heros):
    if hero > rev_monsters[offset]:
        defeatable_monsters += rev_monsters[offset]
        hero -= rev_monsters[offset]
        rev_monsters[offset] = 0
    else:
        defeatable_monsters += hero
        rev_monsters[offset] -= hero
        hero = 0
        continue

    if hero > rev_monsters[offset+1]:
        defeatable_monsters += rev_monsters[offset+1]
        hero -= rev_monsters[offset+1]
        rev_monsters[offset+1] = 0
    else:
        defeatable_monsters += hero
        rev_monsters[offset+1] -= hero
        hero = 0


print(defeatable_monsters)


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

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 5e5 + 10;
const int inf = 0x7ffffff;
struct nd
{
    int a, b, c, d;
}node[60];
int n, m, q;
int a[20];

ll sum = 0;
void calc()
{
    ll tmp = 0;
    for (int i = 1; i <= q;i++)
    {
        if(a[node[i].b]-a[node[i].a]==node[i].c)
            tmp += node[i].d;
    }
    sum = max(sum, tmp);
}

void dfs(int pos)
{
    if(pos==n+1)
    {
        calc();
        return;
    }
    for (int i = a[pos-1]; i <= m;i++)
    {
        a[pos] = i;
        dfs(pos + 1);
    }
}

void solve()
{
    a[0] = 1;
    cin >> n >> m >> q;
    for (int i = 1; i <= q;i++)
        cin >> node[i].a >> node[i].b >> node[i].c >> node[i].d;
    dfs(1);
    cout << sum << "\n";

}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 3652
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

N = i_inpl()
d = l_inpl()
d.sort()
# print(N//2)
# print(d[N//2 - 1])
ans = d[N//2]-d[N//2 - 1]

if ans <= 0:
    print(0)
else:
    print(ans)
# n = i_inpl()
# p = l_inpl()

# cnt = 0
# for i in range(n-2):
#     G = [p[i], p[i+1], p[i+2]]
#     G.sort()
#     if G[1] == p[i+1]:
#         cnt += 1

# print(cnt)

Measured memory_bytes: 14672
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
typedef vector<int> vi;
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void)
{
    string s; cin >> s;
    if (s[2]==s[3] && s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 100010;int ara[100010], arb[100010];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n;
	cin>>n;
	int maxa = 0, maxa1 = 0, ina, maxb = 0, maxb1 = 0, inb, a;
	mem(ara, 0), mem(arb, 0);
	fore(i, 0, n)
	{
		cin>>a;
		if(i&1)
		{
			ara[a]++;
		}
		else
			arb[a]++;
	}
	fore(i, 0, 100010)
	{
		if(ara[i] > maxa)
		{
			maxa1 = maxa;
			maxa = ara[i];
			ina = i;
		}
		else
		{
			if(ara[i] > maxa1)
			{
				maxa1 = ara[i];
			}
		}
	}
	fore(i, 0, 100010)
	{
		if(arb[i] > maxb)
		{
			maxb1 = maxb;
			maxb = arb[i];
			inb = i;
		}
		else
		{
			if(arb[i] > maxb1)
				maxb1 = arb[i];
		}
	}
	//cout<<ina<<' '<<maxa<<' '<<maxa1<<' '<<inb<<' '<<maxb<<' '<<maxb1<<'\n';
	if(ina == inb)
	{
		if(maxa1 + maxb > maxa + maxb1)
			maxa = maxa1;
		else
			maxb = maxb1;
	}
	cout<<n - maxb - maxa<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 1024
def inpl(): return [int(i) for i in input().split()]

N, M = inpl()
A = [1 for _ in range(N)]
B = [False for _ in range(N)]
B[0] = True
for _ in range(M):
    x, y = [int(i)-1 for i in input().split()]
    if B[x]:
        B[y] = True
    if A[x] == 1:
        B[x] = False
    A[x] -= 1
    A[y] += 1
print(sum(B))

Measured memory_bytes: 4656
Imports System
Module ABC108B
	Sub Main()
		Dim x1,y1,x2,y2 As Integer
		Dim x3,y3,x4,y4 As Integer
		Dim input() As String = Console.ReadLine().Split()

		x1 = Integer.Parse(input(0))
		y1 = Integer.Parse(input(1))
		x2 = Integer.Parse(input(2))
		y2 = Integer.Parse(input(3))

		Dim dx As Integer = x2-x1
		Dim dy As Integer = y2-y1
	
		x3 = x2 - dy
		y3 = y2 + dx
		
		dx = x3-x2
		dy = y3-y2
		
		x4 = x3 - dy
		y4 = y3 + dx
		Console.WriteLine("{0} {1} {2} {3}",x3,y3,x4,y4)
	End Sub
End Module


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main(void)
{
	IOS;
	int n; cin>>n;
	vi a(n);
	for(int i = 0; i < n; i++)
		cin>>a[i];
	ii dp[n][n];
	for(int i = 0; i < n; i++) {
		dp[i][i]={a[i], a[i]};
	}
	for(int i = 2; i <= n; i++) {
		for(int j = 0; j <= n-i; j++) {
			int lo=j, hi=j+i-1;
			dp[lo][hi].ff = max(a[lo]-dp[lo+1][hi].ff, a[hi]-dp[lo][hi-1].ff);
			dp[lo][hi].ss = min(a[lo]-dp[lo+1][hi].ff, a[hi]-dp[lo][hi-1].ff);	
		}
	}
	cout<<dp[0][n-1].ff<<endl;
	time();	
	return 0;
}

Measured memory_bytes: 140928
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

N,Q = map(int,input().split())
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c,d = map(int,input().split())
    graph[a].append((b,c,d))
    graph[b].append((a,c,d))
query = [[int(x) for x in input().split()] for _ in range(Q)]

depth = [0] * (N+1)
U = 17
ancestor = [[0] * (U+1) for _ in range(N+1)] # 2**i だけ遡った頂点の番号、行き過ぎは0

q = [(1,0,0)]
while q:
    qq = []
    for x,d,parent in q:
        depth[x] = d
        ax = ancestor[x]
        ax[0] = parent
        for i in range(d.bit_length() - 1):
            ax[i+1] = ancestor[ax[i]][i]
        for y, _, _ in graph[x]:
            if y == parent:
                continue
            qq.append((y, d+1, x))
    q = qq

def LCA(x,y):
    dx = depth[x]
    dy = depth[y]
    if dx > dy:
        x,y = y,x
        dx,dy = dy,dx
    diff = dy - dx
    while diff:
        step = diff & (-diff)
        y = ancestor[y][step.bit_length() - 1]
        diff -= step
    while x != y:
        j = 0
        while ancestor[x][j] != ancestor[y][j]:
            j += 1
        if j == 0:
            return ancestor[x][0]
        x = ancestor[x][j-1]
        y = ancestor[y][j-1]
    return x

tasks = [[] for _ in range(N+1)]
for i,(x,y,u,v) in enumerate(query):
    tasks[u].append((i,x,y,1))
    tasks[v].append((i,x,y,1))
    tasks[LCA(u,v)].append((i,x,y,-2))

answer = [0] * Q

def dfs(x = 1, sums = [0] * (N+1), nums = [0] * (N+1), total = 0, parent = 0):
    for i,c,d,coef in tasks[x]:
        answer[i] += coef * (total - sums[c] + nums[c] * d)
    for y,c,d in graph[x]:
        if y == parent:
            continue
        sums[c] += d
        nums[c] += 1
        total += d
        dfs(y, sums, nums, total, x)
        sums[c] -= d
        nums[c] -= 1
        total -= d
    return

dfs()

print('\n'.join(map(str,answer)))



Measured memory_bytes: 220008
#include <algorithm>
#include <cstdio>
int val[5005][5005], st[5005], pre[5005], nxt[5005]; 
long long dis[5005], sum[5005][5005], ans; 
int main()
{
	// freopen("ARC067-F.in", "r", stdin); 
	int n, m; 
	scanf("%d%d", &n, &m); 
	for (int i = 1; i < n; i++)
	{
		scanf("%lld", dis + i);
		dis[i] += dis[i - 1]; 
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
			scanf("%d", val[j] + i); 
	}
	for (int i = 0; i < m; i++)
	{
		int tp = 0; 
		st[0] = -1; 
		for (int j = 0; j < n; j++)
		{
			while (tp && val[i][st[tp]] < val[i][j])
				tp--; 
			pre[j] = st[tp] + 1; 
			st[++tp] = j; 
		}
		tp = 0; 
		st[0] = n; 
		for (int j = n - 1; j >= 0; j--)
		{
			while (tp && val[i][st[tp]] < val[i][j])
				tp--;
			nxt[j] = st[tp] - 1; 
			st[++tp] = j; 
		}
		for (int j = 0; j < n; j++)
		{
			sum[pre[j]][j] += val[i][j]; 
			sum[j + 1][j] -= val[i][j];
			sum[pre[j]][nxt[j] + 1] -= val[i][j]; 
			sum[j + 1][nxt[j] + 1] += val[i][j]; 
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i)
				sum[i][j] += sum[i - 1][j]; 
			if (j)
				sum[i][j] += sum[i][j - 1]; 
			if (i && j)
				sum[i][j] -= sum[i - 1][j - 1]; 
			if (i <= j)
				ans = std::max(ans, sum[i][j] + dis[i] - dis[j]); 
		}
	}
	printf("%lld\n", ans);
	return 0; 
}


Measured memory_bytes: 200832
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


int gyakugen(int a){
	return beki(a,modulo-2);
}

struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		if(size[x]>size[y])swap(x,y);
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};

int fact(int n){
	int ret = 1;
	for(int i=1;i<=n;i++){
		ret = mod(ret * i);
	}
	return ret;
}

int main(){
	
	int N;
	cin>>N;
	int Z = 0;
	int K = 0;
	unionfind uf(N);
	
	vector<int> P(N);
	for(int i=0;i<N;i++){
		cin>>P[i];
		if(P[i]!=-1){
			P[i]--;
			if(uf.unite(i,P[i]))Z++;
		}
		else K++;
	}
	
	vector<int> cnt(N,0);
	vector<bool> F(N,false);
	
	for(int i=0;i<N;i++){
		int p = uf.find(i);
		cnt[p]++;
		if(P[i]==-1)F[p]=true;
	}
	
	vector<vector<int>> dp(N+1,vector<int>(N+1,0));
	dp[0][0] = 1;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=N;j++){
			if(dp[i][j] == 0)continue;
			dp[i+1][j] = mod(dp[i+1][j]+dp[i][j]);
			
			if(uf.find(i)==i&&F[i]){
				dp[i+1][j+1] = mod(dp[i+1][j+1] + mod(dp[i][j] * cnt[i]));
			}
		}
	}
	int ans = mod(beki(N-1,K) * N);
	
	for(int i=2;i<=N;i++){
		if(dp.back()[i]==0)continue;
		int t=  mod(fact(i-1)*dp.back()[i]);
		t = mod(t * beki(N-1,K-i));
		ans = mod(ans - t);
	}
	

	for(int i=0;i<N;i++){
		if(uf.find(i)==i){
			if(F[i])ans = mod(ans - mod((cnt[i]-1) * beki(N-1,K-1)));
			else{
				ans = mod(ans - beki(N-1,K));
			}
		}
		
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

struct m32 {
  static unsigned mod, lg;
  static uint64_t r;
  static void set_mod(int _mod) {
    assert(_mod >= 2);
    mod = _mod;
    lg = __lg(mod - 1);
    r = ((__uint128_t(1) << (lg + 64)) + mod - 1) / mod;
  }
  unsigned v;
  m32(int x = 0) : v(x) { assert(0 <= x and x < (int)mod); }
  m32(long long x) : v((x %= mod) < 0 ? x + mod : x) {}
  m32 operator-() const { return m32() -= *this; }
  m32& operator+=(m32 b) {
    if ((int)(v += b.v - mod) < 0) v += mod;
    return *this;
  }
  m32& operator-=(m32 b) {
    if ((int)(v -= b.v) < 0) v += mod;
    return *this;
  }
  m32& operator*=(m32 b) {
    auto a = (uint64_t)v * b.v;
    v = a - (uint64_t)((__uint128_t(a) * r >> lg) >> 64) * mod;
    return *this;
  }
  friend m32 operator+(m32 a, m32 b) { return a += b; }
  friend m32 operator-(m32 a, m32 b) { return a -= b; }
  friend m32 operator*(m32 a, m32 b) { return a *= b; }
  friend bool operator==(m32 a, m32 b) { return a.v == b.v; }
};
unsigned m32::mod, m32::lg;
uint64_t m32::r;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n >> m32::mod;
  m32::set_mod(m32::mod);
  vector dp(3 * n + 1, vector<m32>(2 * n + 1));
  dp[3 * n][n] = 1;
  for (int i = 3 * n; i; --i) {
    for (int r = 0; r <= 2 * n; ++r) {
      dp[i - 1][min(r + 1, 2 * n)] += dp[i][r];
      if (i >= 2 and r) {
        dp[i - 2][r - 1] += dp[i][r] * (i - 1);
      }
      if (i >= 3) {
        dp[i - 3][r] += dp[i][r] * (i - 1) * (i - 2);
      }
    }
  }
  m32 res;
  for (int r = n; r <= 2 * n; ++r) {
    res += dp[0][r];
  }
  cout << res.v << '\n';
}


Measured memory_bytes: 97152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll X, Y;
    cin >> X >> Y;
    if(X - Y >= -1 && X - Y <= 1){
        printf("Brown\n");
    }
    else{
        printf("Alice\n");
    }
}

Measured memory_bytes: 3544
// @author: arch_

#include <bits/stdc++.h>
using namespace std;

int main(void) {
    array<int, 3> a;
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    printf("%d %d %d\n", a[0], a[1], a[2]);
    return 0;
}

Measured memory_bytes: 3180
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

  int n; cin >> n;
  int p[n];
  for(int i=0; i<n;i++){
    cin >> p[i];
  }
  int ans = 0;
  for(int i=1; i <n-1;i++){
    if(p[i-1] <= p[i] && p[i] < p[i+1]){
      ans++;
    } else if(p[i+1] <= p[i] && p[i] < p[i-1]){
      ans++;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using namespace std;

#define int long long
int tmp[10] = {};
int ans = 0;
string S;
int sum = 0;


int solve(int p,bool s,int num,int ttmp) {
	if (p == S.length()+1) {
		if (num >= sum)
		{
			if (s == false) num += ttmp;
		//	cout << sum << endl;
			ans += num;
		//	cout << "aaa " << num << endl;
		}
		return 0;

	}

	if (p == 0) {
		ttmp = tmp[0];
		solve(p + 1,true, num,ttmp);
		solve(p + 1, false, num,ttmp);

	}
	else {
		if (s == true) {
			num += ttmp;
			ttmp = tmp[p];	
			solve(p + 1, true, num, ttmp);
			if (p !=S.length()-1) {
				solve(p + 1, false, num, ttmp);
			}
		}
		else {
			ttmp = ttmp * 10 + tmp[p];
			solve(p + 1, true, num, ttmp);
			if (p != S.length()-1) {
				solve(p + 1, false, num, ttmp);
			}
		}

	}
}

signed main() {
	cin >> S;
	for (int i = 0; i < S.length(); i++) {
		tmp[i] = S[i]-48;
		sum += tmp[i];
	}
	solve(0, false, 0, 0);
	cout << ans/2 << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod ll(1e9+7)
#define inf ll(1e9)
int main()
{
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
   int h,w;
   cin>>h>>w;
   vector<string>arr(h);
   for(int i=0; i<h; i++)
    cin>>arr[i];
   vector<vector<int> >mtr1(h,vector<int>(w)),mtr2(h,vector<int>(w));
   for(int i=0; i<h; i++){
    int sum=0;
    for(int j=0; j<w; j++){
      if(arr[i][j]=='.'){
        sum++;
        mtr1[i][j]=sum;
      }
      else{
        sum=0;
      }
    }
    int temp=0;
    for(int j=w-1; j>=0; j--){
      if(arr[i][j]=='.' && temp==0){
        temp=mtr1[i][j];
      }
      else if(arr[i][j]=='.'){
        mtr1[i][j]=temp;
      }
      else
        temp=0;
    }
   }
   for(int i=0; i<w; i++){
    int sum=0;
    for(int j=0; j<h; j++){
      if(arr[j][i]=='.'){
        sum++;
        mtr2[j][i]=sum;
      }
      else
        sum=0;
     }
     int temp=0;
     for(int j=h-1; j>=0; j--){
      if(arr[j][i]=='.' && temp==0){
        temp=mtr2[j][i];
      }
      else if(arr[j][i]=='.'){
        mtr2[j][i]=temp;
      }
      else
        temp=0;
     }
   }
   int ans=0;
   for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      ans=max(ans,mtr1[i][j]+mtr2[i][j]-1);
    }
   }
   cout<<ans;
   return 0;
   
}

Measured memory_bytes: 42340
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    rep(i, N) cin >> L.at(i);

    vector<int> D(N + 1);
    D.at(0) = 0;

    int ans = 0;
    int bound = 1;
    for (int i = 1; i <= N; i++) {
        D.at(i) = D.at(i - 1) + L.at(i - 1);
        if (X < D.at(i)) {
            ans = i;
            break;
        }
        bound++;
    }

    if (bound == N + 1) {
        ans = bound;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
char s[5005];
int Next[5005];
vector<char> v[5005];
int main()
{
    int n,i,j,k,t,max=0;
    scanf("%d%s",&n,s);
    for(i=0;i<n;i++)
        for(j=i;j<n;j++)
            v[i].push_back(s[j]);
    for(i=0;i<n;i++)
    {
        Next[0]=-1;
        j=0;
        k=-1;
        while(j<n-i)
        {
            if(k==-1||v[i][j]==v[i][k])
                Next[++j]=++k;
            else
                k=Next[k];
        }
        for(j=0;j<=n-i;j++)
        {
            if(Next[j]<=j/2)
            {
                if(Next[j]>max) max=Next[j];
            }
            else
            {
                t=j-Next[j];
                t=t*(j/t/2);
                if(t>max) max=t;
            }
        }
    }
    printf("%d\n",max);
    return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++) cin >> vec[i];
    int res = 0;
    for (int i = 2; i < n; i++) {
        int mi = min({vec[i-2], vec[i-1], vec[i]});
        int ma = max({vec[i-2], vec[i-1], vec[i]});
        if (vec[i-1] != mi && vec[i-1] != ma) res++;
    }
    cout << res << endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n;
    cin >> n;
    if(n == 1){
        cout << 0 << endl;
        return 0;
    }
    ll m = n;
    map<int, int> mp;
    for(ll i = 2; i * i <= n; i++){
        if(m % i == 0){
            while(m % i == 0){
                mp[i]++;
                m /= i;
            }
        }
    }

    int ans = 0;
    if(m != 1)ans++;
    for(auto i = mp.begin(); i != mp.end(); i++){
        int num = i->second;
        ll N = 1;
        while(N*(N+1)/2 <= num)N++;
        N--;
        ans += N;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int plc = s.size() - 1;
  long N = 1 << plc;
  
  long sum = 0, sum_tmp = 0;
  for (int i = 0; i < N; i++){
    sum_tmp = (long)s[0] - (long)'0';
    
    for (int j = 0; j < plc; j++){
      if ((i >> j) & 1){
        sum += sum_tmp;
        sum_tmp = (long)s[j+1] - (long)'0';
      } else {
        sum_tmp = 10 * sum_tmp + (long)s[j+1] - (long)'0';
      }
      
    } 
    sum += sum_tmp;
  }
  cout << sum << endl;
}

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

int main(){
    int k,a,b,i=1;
    scanf("%d%d%d",&k,&a,&b);
    while (k*i<=b) {
        if (k*i>=a) {
            printf("OK");
            return 0;
        }
      i++;
    }
    printf("NG");
    return 0;
}


Measured memory_bytes: 1732
/*
memo for solution
*/
#include <cstdlib> 
#include <numeric>
#include <cstring>
#include <cstdio> 
#include <cfloat> 
#include <map> 
#include <cassert>
#include <cmath> 
#include <climits> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <iomanip>
#include<sys/time.h>
using namespace std; 
double e_time(void){static struct timeval now;gettimeofday(&now, NULL);return (double)(now.tv_sec  + now.tv_usec/1000000.0);}
#define REP(i,b,n) for(int i=b;i<n;i++) 
#define rep(i,n)      REP(i,0,n) 
#define pb push_back  
#define mp make_pair 
#define ALL(C)   (C).begin(),(C).end() 
#define fe(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr != (c).end();itr++)
#define BITSHIFT(X)     ( (1<<(X)) )
#define CONTAIN(S,X) ( ((S)&BITSHIFT(X)) != 0)
typedef complex<double>P; 
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; 
typedef vector<int> vint;
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
template<class T> T ceilUp(const T& a,const T& b){return (a+b-1)/b;}
const ll mod =   1000000009;
inline ll modadd(ll a,ll b){a %= mod;b %= mod;return (a+b)%mod;}
inline ll modsub(ll a,ll b){a %= mod;b %= mod;a-=b;a%=mod;if (a<0)a+=mod;return a;}
inline ll modmul(ll a,ll b){a %= mod;b %= mod;return (a*b)%mod;}
inline ll modeq(ll a,ll b,ll m){a = (a%m+m)%m; b = (b%m+m)%m;return a == b;}
//ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;}
//ll getinv(ll a){return mypow(a,mod-2);}

int gcd(int w,int m){
  while(1){
    if (w %  m==0)return m;
    int temp;
    temp = w%m;
    w = m;
    m = temp;
  }
}

long long lcm(long long w,long long m){
  return (w*m)/gcd(w,m) ;//w > m
}

int main(){
  long long n,m;
  string s, t;
  cin >> n >> m;
  cin >> s >> t;
  long long l = lcm(max(n,m), min(n, m));
  map<long long, char> M;
  for(long long s_i = 0;s_i < n;s_i++){
    M[s_i * l/n] = s[s_i];
  }

  bool fg = true;
  for(int t_i = 0 ;t_i < m;t_i++){
    if (M.count(t_i * l/m) != 0 && M[t_i*l/m] != t[t_i]){
      fg = false;
    }
  }
  if (fg)cout << l << endl;
  else cout << -1 << endl;
  return 0;
}
 
 


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

using namespace std;

int main()
{
    int n;
    int x;
    cin>>n>>x;
    vector<lli> vec(n);
    for(auto&t:vec)cin>>t;

    lli sum=0;
    for(lli i=0;i<n-1;++i){
  //      for(auto t:vec_)cout<<t<<" ";cout<<"tes"<<sum<<endl;
        if(vec.at(i)+vec.at(i+1)>x){
            lli t=vec.at(i)+vec.at(i+1)-x;
            sum+=t;
            if(vec.at(i+1)-t<0){vec.at(i+1)=0;t-=vec.at(i+1);vec.at(i)-=t;}
            else vec.at(i+1)-=t;

        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1152
class Chokudai
    def read()
        @inputs = STDIN.readlines.map{|line|line.strip.split()}
    end

    def think()
        @n = @inputs.shift[0].to_i
        @h_list = @inputs.shift.map{|line|line.to_i}
        @dp = Array.new(@n, 0)
        @h_list.each_index do |i|
            if i == 0 then
                @dp[i] = 0
            elsif i == 1 then
                @dp[i] = @dp[i - 1] + (@h_list[i] - @h_list[i - 1]).abs
            else
                @dp[i] = [@dp[i - 1] + (@h_list[i] - @h_list[i - 1]).abs, @dp[i - 2] + (@h_list[i] - @h_list[i - 2]).abs].min
            end
        end
    end

    def answer
        puts(@dp.pop)
    end
end

chokky = Chokudai.new
chokky.read
chokky.think
chokky.answer

Measured memory_bytes: 11908
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  sort(a.begin(),a.end());
  vector<long long> b(n+1,0);
  for(int i=0;i<n;i++){
    b[i+1]=b[i]+a[i];
  }
  int ans=1;
  for(int i=n-1;i;i--){
    if(b[i]*2 >= a[i]) ans++;
    else break;
  }
  cout << ans << endl;
  return 0;
}

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



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<ll>g(k+1,-1);
  g[0]=0;
  rep(i,k+1){
    if(i==0)continue;
    vector<ll>tg(n+1);
    rep(j,n){
      if(i-a[j]<0)break;
      tg[g[i-a[j]]]=1;
    }
    rep(j,n+1){
      if(tg[j]==0){g[i]=j;break;}
    }
  }
  if(g[k]){
    cout<<"First"<<endl;
  }
  else{
    cout<<"Second"<<endl;
  }

  return 0;

}


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

typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define pb                          push_back

const ll MX5 = 2*1e5+3;
const ll MX6 = 2*1e6+3;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ll MOD2= 998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}

ll A[MX5];
ll dp[MX5];
int main(){
    fast_io
    //file_io
    ll n,k;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    dp[0]=0;
    for(ll i=1;i<n;i++){
        dp[i]=abs(A[i-1]-A[i])+dp[i-1];
        for(ll j=max(0ll,i-k);j<=i-2;j++){
            dp[i]=min(dp[i],abs(A[j]-A[i])+dp[j]);
        }
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1792