akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int p = 9973;
const int size=5005;
typedef long long int ll;
ll fast_exp(ll x,ll po)
{
    ll res = 1;
    x %= mod;
    while(po)
    {
        if(po&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        po >>= 1;
    }
    return res;
}
int dp[size][size];
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(s[i-1] == s[j-1] && (j-i)>dp[i-1][j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = 0;
            ans = max(ans,dp[i][j]);
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 96768
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>
#include <cstring>
#include <cctype>
#include <random>

using namespace std;
typedef long long  ll;
const ll INF = 1000000007;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (n); ++i)


int main() {
	ll N;
	cin >> N;
	ll ans = 0;
	for (int i = 1; i < N; i++) {
		ans += floor((double)(N - 1) / i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    ll N;
    io.read(N);
    vector<ll> L(87);
    L[0] = 2;
    L[1] = 1;
    for(int i = 2; i <= N; i++){
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[N];
    return 0;
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
const double PI=3.14159265358979323846;

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







int main() {


  cout<<fixed<<setprecision(10);

  ll n,w; cin>>n>>w;

  ll v = 1e3 * 100;
  vvint dp(n+1, vint(v+1, LLONG_MAX));

  dp[0][0] = 0;

  rep(i,n){
    ll a,b; cin>>a>>b;
    rep(j, v){
      if(dp[i][j] == LLONG_MAX) continue;
      chmin(dp[i+1][j], dp[i][j]);
      if(j + b > v) continue;
      chmin(dp[i+1][j+b], dp[i][j] + a);
    }
  }

  ll ans = 0;
  rep(j, v+1){
    if(dp[n][j] <= w) ans = j;
  }

  cout<<ans<<endl;

}

//


Measured memory_bytes: 80256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		int a = stdin.nextInt();
		int b = stdin.nextInt();
		int c = stdin.nextInt();
		
		if((10*b+c)%4==0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}


	}

}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define ln '\n'
#define MAX 1000000009
#define MOD 1000000007
#define N 500005
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pii;
ll n, k, m;
int main(){
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n >> k >> m;
  	if((m-k)-n<0)
    {
    	cout << "No";
      	return 0;
    }
    if((k * n * 4) < ((m - k) - n) * ((m - k) - n)) {
        cout << "Yes";
    }
    else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    int tmp;
    vector<int> b;
    int ans;
    cin >> n;

    for(int i=0; i<n-1; i++){
        cin >> tmp;
        b.push_back(tmp);
    }
    for(int i=0; i<n; i++){
        if(i==0){
            ans += b[0];
        }else if(i==n-1){
            ans += b[n-2];
        }else{
            ans += min(b[i], b[i-1]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 5 4" ].parse.expand.solve == "YES" );
	assert( [ "2 2 6" ].parse.expand.solve == "NO" );
	assert( [ "5 3 2" ].parse.expand.solve == "NO" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abx = input.front.split.to!( long[] );
	
	return tuple( abx[ 0 ], abx[ 1 ], abx[ 2 ] );
}

auto solve( long a, long b, long x )
{
	return ( ( a <= x ) && ( x <= a + b ) ) ? "YES" : "NO";
}


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

#define ll long long int

int main(){
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	ll dp[k+1];
	for(ll i=0;i<=k;i++){
		if(i<arr[0]){dp[i]=0;}
	}
	
	for(ll i=1;i<=k;i++){
		ll f=0;
		for(ll j=0;j<n;j++){
			if(i>=arr[j]){
				if(dp[i-arr[j]]==0){
					dp[i]=1;f=1;
				}
				else{
				//	dp[i]|=0;
				}
			}
	}
	if(f==0){dp[i]=0;}
	//cout<<dp[i]<<' ';
	
	
	
}
if(dp[k]==0){
		cout<<"Second";
	}
	else{
		cout<<"First";
	}
}

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

int main() {
  int A, B, C, D;
  string op;
  cin >> A >> B >> C>> D;

  if ( A + B > C + D ) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  /*else if (op == "*") {
    cout << A * B << endl;
  }
  else if (op == "?" || op == "=" || op == "!" || op == "=" || B == 0 ) {
    cout << "error" << endl;
  }*/
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	long long x[a+1];
	for(int i=1;i<=a;i++)
	{
		cin>>x[i];
	}
	b=min(a,b);
	b=a-b;
	sort(x+1,x+a+1);
	long long ans=0;
	for(int i=1;i<=b;i++)
	{
		ans+=x[i];
	}
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 1792
while True:    
    try:
        w = float(input())
    except:
        break
    
    if w <= 48.00:
        print("light fly")
    elif 48.00 < w <= 51.00:
        print("fly")
    elif 51.00 < w <=54.00:
        print("bantam")
    elif 54.00 < w <= 57.00:
        print("feather")
    elif 57.00 < w <= 60.00:
        print("light")
    elif 60.00 < w <= 64.00:
        print("light welter")
    elif 64.00 < w <= 69.00:
        print("welter")
    elif 69.00 < w <=75.00:
        print("light middle")
    elif 75.00 < w <= 81.00:
        print("middle")
    elif 81.00 < w <= 91.00:
        print("light heavy")
    elif 91.00 <= w:
        print("heavy")


Measured memory_bytes: 5572
K, A, B = map(int, input().split())
if (not A+2 <= B) or K<=A:
    print(K+1)
    exit()
b, y = 1, 0
K -= A-1
b += A-1
#print(b)
if K%2==1:
    K-=1
    b+=1
b += K//2 * (B-A)
print(b)


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

int main(){
  int N;
  cin >> N;
  
  vector<int>A(N);
  rep(i,N)cin >> A[i];
  
  int count = 0;
  
  rep(i,N){
    
    if((i+1) % 2 == 1){
      if(A[i] % 2 == 1)count++;
    }
  }
  
  cout << count << endl;
    
  
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    cout << (N-2)/(K-1)+1 << endl;
    return 0;
}


Measured memory_bytes: 3784
a, b, k = map(int, input().split())
if a + k < (b + 1) - k:
    for i in range(a, a + k):
        print(i)
    for i in range((b + 1) - k, b + 1):
        print(i)
else:
    for i in range(a, b + 1):
        print(i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n,k,q;
    cin >> n >> k >> q;
    vec<long> point(n);
    point.at(0) = k;

    //imosu
    for (int i = 0; i < q; i++)
    {
        int a;
        cin >> a;
        a--;
        point.at(0)--;
        point.at(a)++;
        if (a!=n-1)
        {
            point.at(a+1)--;
        }
    }
    for (int i = 0; i < n-1; i++)
    {
        point.at(i+1) += point.at(i);
    }

    for (auto &&e : point)
    {
        if(e>0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1408
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let _: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let mut a: Vec<(usize, usize)> = (0..m)
        .map(|_| {
            (
                itr.next().unwrap().parse().unwrap(),
                itr.next().unwrap().parse().unwrap(),
            )
        })
        .collect();
    a.sort_by(|x, y| x.1.cmp(&y.1));
    // できるだけ後ろ

    let mut ans = 0;
    let mut last = 0; // [0, last)は切れてる
    for i in 0..m {
        if last <= a[i].0 {
            last = a[i].1;
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5236
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define pb push_back

long long cnt = 0;
int N;
int a[1000005];
vector<int> G;

void insertionSort(int g);
void shellSort();

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

   cin >> N;
   rep(i, N)cin >> a[i];

   shellSort();

   outl( G.size() );

   for(int i=G.size()-1; i>=0; --i)
      cout << G[i] << (i? ' ' : '\n');

   outl(cnt);

   rep(i, N)
      outl(a[i]);
}

void insertionSort(int g)
{
   for(int i=g; i<N; ++i){
      int v= a[i];
      int j= i - g;
      while( j >= 0 && a[j] > v ){
         a[j+g] = a[j];
         j -= g;
         ++cnt;
      }
      a[j+g] = v;
   }
}

void shellSort()
{
   cnt = 0;
   for(int g = 1; g <= N; g = 3*g + 1)
      G.pb(g);

   for(int i=G.size()-1; i >= 0; --i){
      insertionSort(G[i]);
   }
}




Measured memory_bytes: 7076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int k;
int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
int main()
{
    scanf("%d",&k);
    int k1 = gcd(k,360);
    printf("%d\n",360/k1);
    return 0;
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

template<typename T,typename U>
void Printarray2(T f,U n){
  for(int i=0;i<n;i++) cout<<f[i]<<endl;
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b,c;cin>>a>>b>>c;
  cout<<(a+b+c>=22 ? "bust":"win")<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=155;
int n,k,M,f[N][N],g[N];
map<ll,int> Map;
ll calc(int a,int b,int c,int d,int e){
	return (ll)a*(n+2)*(n+2)*(n+2)*(n+2)+(ll)b*(n+2)*(n+2)*(n+2)+(ll)c*(n+2)*(n+2)+d*(n+2)+e;
}
int dfs(int x,int p,int q,int fp,int fq){
	if (x>=n)return 1;
	ll VV=calc(x,p,q,fp,fq);
	if (Map.count(VV))return Map[VV];
	if (x&1){
		Map[VV]=dfs(x+1,0,q,n+1,fq);
		if (fp>x+1){
			if (x+2-2*q+k<=x+1)(Map[VV]+=dfs(x+1,p+1,q,fp,min(fq,x+1-2*p+k)))%=M;
			else (Map[VV]+=dfs(x+1,p+1,q,fp,fq))%=M;
		}
	}
	else {
		Map[VV]=dfs(x+1,p,0,fp,n+1);
		if (fq>x+1){
			if (x+2-2*p+k<=x+1)(Map[VV]+=dfs(x+1,p,q+1,min(fp,x+1-2*q+k),fq))%=M;
			else (Map[VV]+=dfs(x+1,p,q+1,fp,fq))%=M;
		}
	}
	return Map[VV];
}
int main(){
	scanf("%d%d%d",&n,&k,&M);
	if (k%2==0){
		k/=2;
		f[0][0]=1;
		g[0]=1;
		for (int i=1;i<=n;i++){
			for (int j=0;j<=k;j++)
				f[i][j]=j==0?g[i-1]:f[i-1][j-1];
			for (int j=0;j<=k;j++)(g[i]+=f[i][j])%=M;
		}
		printf("%d\n",(ll)g[n/2]*g[n/2+n%2]%M);
		return 0;
	}
	printf("%d\n",dfs(0,0,0,n+1,n+1));
}


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

class Program {
    static void Main(string[] args) {
        //入力
        int N = int.Parse(Console.ReadLine());
        int[] H = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        //回答となる数値
        int ans = 1;

        //これまでの最大値
        int max = H[0];

        for (int i = 1; i < N; i++) {
            if (H[i] >= max) {
                ans++;
            }
            max = Math.Max(max, H[i]);
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-10;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,r;cin>>n>>r;
    if(n<10){
        r+=100*(10-n);
    }
    cout<<r<<endl;
}





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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;

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

    int n,k;
    cin>>n>>k;

    vector<ll> pos;
    vector<ll> neg;

    ll a;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(a < 0)
            neg.push_back(a);
        else
            pos.push_back(a);
    }

    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());

    ll ans = 1;
    if(neg.size() == 0)
    {
        for(int i = 0; i < k;i++)
            ans = (ans* pos[pos.size() - i -1]) % INF;
    }
    else if( pos.size() == 0)
    {
        if(k%2 == 0)
        {
             for(int i = 0; i < k;i+=2)
                ans = (ans* ((neg[i] * neg[i+1] )%INF)) % INF;   
        }
        else
        {
            for(int i=0; i<k;i++)
            {
                ans = (ans* neg[neg.size() - (i+1)]) % INF;
                ans = (ans < 0) ? INF +ans :ans;      
            }
        }
    }
    else{
            
            ll neg_prod, pos_prod;

            if(k == n)
            {
                for(int i=0;i<pos.size();i++)
                    ans = ( ans* pos[i])%INF;
                for(int i=0; i<neg.size();i++)
                {
                    ans = (ans* neg[i]) %INF;
                    ans = (ans < 0) ? INF + ans: ans;
                }
            }
            else{
                int i=0, j = 0;

                if(k%2 == 1)
                    ans = pos[pos.size()-1 - (i++)];

            while( (i+j) < k)
            {
                if(j < (neg.size() -1))
                {
                    neg_prod = neg[j] * neg[j+1];
                }
                else
                    neg_prod = -1;

                if( i < (pos.size() -1))
                {
                    pos_prod = pos[ pos.size() - i -1] * pos[pos.size() - i - 2];  
                }
                else
                    pos_prod = 0;


                if(neg_prod == -1)
                {
                    ans = (ans* pos[pos.size() - i -1]) %INF;
                    i++;
                }
                else if(pos_prod > neg_prod)
                {
                    ans = (ans* (pos_prod % INF))%INF;
                    i+=2;
                }
                else
                {
                    ans = (ans* (neg_prod % INF))%INF;
                    j+=2;
                }
            }
            }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 5572
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
  string e,o;
  cin >> e >> o;
  for(int i = 0; i < e.size(); i++){
    cout << e.at(i);
    if(i < o.size())
      cout << o.at(i);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> Ss(m, vector<int>(0));
    vector<int> Ps(m);
    rep(mi,m){
        int k; cin >> k;
        rep(ki,k){
            int s; cin >> s;
            Ss.at(mi).push_back(s);
        }
    }
    rep(i,m) cin >> Ps.at(i);

    int ans = 0;
    rep(i, pow(2, (float)n)){
        bitset<10> bs(i);
        bool isAns = true;
        rep(mi, m){
            int cnt = 0;
            for(int si: Ss.at(mi)){
                if(bs.test(si-1)){
                    cnt++;
                }
            }
            if(cnt % 2 != Ps.at(mi)){
                isAns = false;
                break;
            }
        }
        if(isAns) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  ll d = 0;
  d = c - a - b;
  if(d > 0 && 4 * a * b < d * d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second

using namespace std;

vector <int> g[112345];
int v[112345];
ll M = 1e9 + 7;

int main()
{
	int n,k;
	cin>>n>>k;
	for(int i = 0; i <(n-1); i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}

	int root = 0;
	for(int node = 1; node <=n; node++)
	{
		if(g[node].size() > k-1)
		{
			if (root)
			{
				cout<<0<<endl;
				return 0;
			}
			root = node;
		}
	}

	for(int node = 1; node <=n && node != root; node++)
	{
		if (g[node].size() > k-1) // because parent also there
		{
			cout<<0<<endl;
			return 0;
		}
	}

	if (!root) root = 1; 

	ll ans = k;

	v[root] = 1;

	queue <int> q;

	for(int i = 0; i < g[root].size(); i++)
	{
		 q.push(g[root][i]);
		 ans = (ans * (k-i-1)) % M;
	}

	while(!q.empty())
	{
		int node = q.front();
		q.pop();
		v[node] = 1;
		int c = 2;
		for(int i = 0; i < g[node].size(); i++)
		{
			if (v[g[node][i]]) continue;

			q.push(g[node][i]);
			ans = (ans * (ll)(k-c)) % M; 
			c++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7160
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> X(N);
    REP(i, N) cin >> X[i];
    int ans=1e9;
    REP(P,101){
        int tmp=0;
        REP(i,N) tmp+=(X[i]-P)*(X[i]-P);
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	double a,b;
	while(cin>>a>>b){
		if     (a<35.5 && b<71)	puts("AAA");
		else if(a<37.5 && b<77)	puts("AA");
		else if(a<40 && b<83)	puts("A");
		else if(a<43 && b<89)	puts("B");
		else if(a<50 && b<105)	puts("C");
		else if(a<55 && b<116)	puts("D");
		else if(a<70 && b<148)	puts("E");
		else	puts("NA");
	}
	return 0;
}

Measured memory_bytes: 0
# DP(配るDP)
INF = float('inf')

N = int(input())

c = [1]
t = 6
while t <= N:
    c.append(t)
    t *= 6
t = 9
while t <= N:
    c.append(t)
    t *= 9

dp = [INF] * (N + 1)
dp[0] = 0
for i in range(N):
    for j in c:
        if i + j <= N and dp[i + j] > dp[i] + 1:
            dp[i + j] = dp[i] + 1
print(dp[N])


Measured memory_bytes: 3828
def main():
	import sys
	input = sys.stdin.readline
	
	n = int(input())
	arr = list(map(int, input().split()))
	kek = [sum(arr[:i + 1]) for i in range(n)]
	
	ans = 0
	for i in range(1, n):
		ans += arr[i] * kek[i - 1]
	
	print(ans)
	
	return 0

main()


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<climits>
#include<cctype>
#include<map>
#include<queue>
#include<iomanip>

using namespace std;

int main(){

    int N;
    cin >> N;
    
    if(1 <= N && N <=999){
    	cout << "ABC" << endl;
    }else{
    	cout << "ABD" << endl;
    }
    
	
   return 0;

}


Measured memory_bytes: 256
N, W = map(int, input().split())
w0, v0 = map(int, input().split())
X = [[] for _ in range(4)]
X[0].append(v0)
for _ in range(N-1):
    w, v = map(int, input().split())
    X[w-w0].append(v)

X = [[0] + sorted(x)[::-1] for x in X]
for i in range(4):
    for j in range(1, len(X[i])):
        X[i][j] += X[i][j-1]
ma = 0
for i in range(N+1):
    for j in range(N+1-i):
        for k in range(N+1-i-j):
            l = min(N-i-j-k, (W - (w0 * i + (w0+1) * j + (w0+2) * k)) // (w0+3))
            if l < 0: continue
            if i < len(X[0]) and j < len(X[1]) and k < len(X[2]) and l < len(X[3]):
                ma = max(ma, X[0][i] + X[1][j] + X[2][k] + X[3][l])
print(ma)

Measured memory_bytes: 41712
#include "bits/stdc++.h"
using namespace std;

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

    if (a <= b){
        if (a <= c){
            cout << a + min(b, c) << endl;
            return 0;
        }
    }
    if (b <= c && b <= a){
        cout << b + min(c, a) << endl;
        return 0;
    }
    if (c <= a && c <= b){
        cout << c + min(a, b) << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
void square() {
	int n; cin >> n;
	vll h(n); rep(i, 0, n) cin >> h[i];
	deque<pair<ll, ll>> st;
	st.eb(-1, -1);
	ll ans = 0, pos;
	rep(i, 0, n) {
		if (st.back().fi == h[i]) continue;
		pos = i;
		while (st.back().fi >= h[i]) {
			chmax(ans, st.back().fi * (i - st.back().se));
			pos = st.back().se;
			st.pop_back();
		}
		st.eb(h[i], pos);
	}

	while (!st.empty()) {
		chmax(ans, st.back().fi * (n - st.back().se));
		st.pop_back();
	}

	P(ans);
}
int main() {
	square();
	return 0;
}

Measured memory_bytes: 5256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int get_gcd(int a, int b) {
  if (a < b)
    std::swap(a, b);
  int r;
  while (1) {
    r = a % b;
    if (r == 0) {
      return b;
    } else {
      a = b;
      b = r;
    }
  }
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;

  std::vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int gcd_neglected=a[0];
  int gcd_not_neglected=get_gcd(a[0],a[1]);
  for(int i=2;i<n;i++){
    gcd_neglected=std::max(get_gcd(gcd_neglected,a[i]),gcd_not_neglected);

    gcd_not_neglected=get_gcd(gcd_not_neglected,a[i]);
  }

  int neglect_first=a[1];
  for(int i=2;i<n;i++){
    neglect_first=get_gcd(neglect_first,a[i]);
  }

  cout<<std::max(gcd_neglected,neglect_first)<<endl;


  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
    string S;
    int Q;

    cin >> S >> Q;

    deque<char> SDeque;
    // 反転世界のSを用意
    deque<char> RSDeque;

    for (int i = 0; i < S.length(); i++)
    {
        SDeque.push_back(S[i]);
        RSDeque.push_front(S[i]);
    }

    int reverseCounter = 0;

    int T, F;
    char C;

    for (int i = 0; i < Q; i++)
    {
        cin >> T;

        switch (T)
        {
        case 1:
            reverseCounter++;
            break;
        case 2:
            cin >> F >> C;
            switch (F)
            {
            case 1:
                if (reverseCounter % 2 == 0)
                {
                    SDeque.push_front(C);
                    RSDeque.push_back(C);
                }
                else
                {
                    SDeque.push_back(C);
                    RSDeque.push_front(C);
                }
                break;
            case 2:
                if (reverseCounter % 2 == 0)
                {
                    SDeque.push_back(C);
                    RSDeque.push_front(C);
                }
                else
                {
                    SDeque.push_front(C);
                    RSDeque.push_back(C);
                }
                break;
            default:
                break;
            }
            break;
        default:
            break;
        }
    }

    string ans = "";
    if (reverseCounter % 2 == 0)
    {
        for_each(SDeque.begin(), SDeque.end(), [&ans](char c) {
            ans += c;
        });
    }
    else
    {
        for_each(RSDeque.begin(), RSDeque.end(), [&ans](char c) {
            ans += c;
        });
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1668
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll INF = 1000000000000000000LL;
const int MAX_N = 3005;

int n;
ll a[MAX_N];
bool used[MAX_N][MAX_N][2];
ll dp[MAX_N][MAX_N][2];

ll calc(int i, int j, int p)
{
	if (i == j)
		return (p == 0 ? 1 : -1) * a[i];
	if (used[i][j][p])
		return dp[i][j][p];
	
	ll result = (p == 0 ? -1 : 1) * INF;
	if (p == 0)
	{
		if (i + 1 <= j)
			result = max(result, a[i] + calc(i + 1, j, 1 - p));
		if (i <= j - 1)
			result = max(result, a[j] + calc(i, j - 1, 1 - p));
	}
	else
	{
		if (i + 1 <= j)
			result = min(result, calc(i + 1, j, 1 - p) - a[i]);
		if (i <= j - 1)
			result = min(result, calc(i, j - 1, 1 - p) - a[j]);
	}

	used[i][j][p] = true;
	dp[i][j][p] = result;
	return result;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << calc(0, n - 1, 0) << endl;
}

Measured memory_bytes: 158976
#include <stdio.h>

int main() {
    char check[4], tru[4];
    int sum = 0;

    scanf("%[^\n]%*c", check);
    scanf("%[^\n]%*c", tru);
    for (int i = 0; i < 3 ; ++i){
        //printf("%c %c\n", check[i], tru[i]);
        if (check[i] == tru[i]) {
            ++sum;
        }
    }
    printf("%d\n",sum);


    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main()
{
	long long int a, b, e, d;
	int c = 0;
	scanf("%lld%lld", &a, &b);
	e = a;
	d = b;
	while (c = a % b)
	{
		a = b;
		b = c;
	}
	printf("%lld\n", e * d / b);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    ll sum1=0, sum2=0;
    int i;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        sum1 += tmp;
        sum2 += tmp*tmp;
    }
    ll ans = sum1*sum1 - sum2;
    ans /= 2;


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


    return 0;
}



Measured memory_bytes: 128
'use strict'

function main(input) {
  const lines = input.split('\n');

  const c = [];
  for(let i=0;i<3;i++){
    c.push(lines[i].split(' ').map(x => parseInt(x)))
  }

  let result = 'Yes';

  if(c[1][1]+c[2][2] != c[1][2]+c[2][1]){result='No';}
  if(c[0][0]+c[1][1] != c[0][1]+c[1][0]){result='No';}
  if(c[0][0]+c[2][2] != c[0][2]+c[2][0]){result='No';}

  console.log(result);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import sys
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush

N = int(input())
edge = [[] for _ in range(N)]
for node in range(1, N):
    a = int(input())
    edge[a-1].append(node)

def dfs(n):
    if not edge[n]:
        return 0
    
    que = []
    for v in edge[n]:
        heappush(que, (-1) * dfs(v))

    ans = 0
    for i in range(len(edge[n])):
        ans = max(ans, (-1) * heappop(que) + i + 1)
    
    return ans

print(dfs(0))

Measured memory_bytes: 112712
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = input().strip()

if len(s) == 2:
    print(0)
    sys.exit(0)

for i in range(1, len(s) // 2 + 1):
    split_index = (len(s) - i * 2) // 2
    if s[:split_index] == s[split_index:len(s) - i * 2]:
        print(len(s) - i * 2)
        sys.exit(0)


Measured memory_bytes: 61796
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

ll count(int l, ll n, ll ret) { // n >= 0
  if(n == 0)
    return ret;
  if(l == 0) // n == 1
    return ret + 1;
  if(n >= (((ll)pow(2,l+2)-3)-1)/2) {
    if(n >= (((ll)pow(2,l+2)-3)+1)/2) {
      return count(l-1, n-(((ll)pow(2,l+2)-3)+1)/2, ret+(ll)pow(2,l)-1+1);
    } else { // n == (((ll)pow(2,l+2)-3)-1)/2
      return ret+(ll)pow(2,l)-1;
    }
  } else {
    return count(l-1, max(n-1, 0LL), ret);
  }
}

int main(){
  int N;
  ll X;
  cin >> N >> X;
  cout << count(N, X, 0LL) << endl;
  return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3

# from numba import njit
from collections import Counter
# input = stdin.readline

# @njit
def solve(n,a):
  alphabetLst = {}
  for i in range(n):
    # i番目の文字列の中の文字を数える
    d = Counter(a[i])
    for c in (chr(ord("a") + i) for i in range(26)):
      if not c in d.keys():
        alphabetLst[c] = 0
      elif not c in alphabetLst.keys():
        alphabetLst[c] = d[c]
      elif d[c] < alphabetLst[c]:
        alphabetLst[c] = d[c]


  res = []
  for k,v in alphabetLst.items():
    res += [k]*v

  return "".join(res)

def main():
  N = int(input())
  a = [input() for _ in range(N)]
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()

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

static const int N = 10000;
static const int inf = (1 << 30);
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n;
vector<pair<int, int> > adj[N];

void dijkstra(int s) {
	int color[N], d[N];
	for (int i = 0; i < n; i++) {
		color[i] = white;
		d[i] = inf;
	}
	priority_queue<pair<int, int> > PQ;
	d[s] = 0;
	color[s] = gray;
	PQ.push(make_pair(s, 0));
	while (!PQ.empty()) {
		pair <int, int> f = PQ.top();
		PQ.pop();
		int u = f.second;
		color[u] = black;
		for (int k = 0; k < adj[u].size(); k++) {
			int v = adj[u][k].first;
			if (color[v] == black)
				continue;
			if (d[v] > d[u] + adj[u][k].second) {
				d[v] = d[u] + adj[u][k].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = gray;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (d[i] == inf) {
			cout << i << " " << -1 << '\n';
		} else {
			cout << i << " " << d[i] << '\n';
		}
	}
}
int main() {
	cin >> n;
	int u, k, v, c;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}
	dijkstra(0);
	return 0;
}



Measured memory_bytes: 7980
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b != c || b == c && c != a || c == a && a != b) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
//#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(bool);
void precalc();
clock_t start;
int main() {
#ifdef AIM
  freopen("/home/alexandero/ClionProjects/ACM/input.txt", "r", stdin);
  //freopen("/home/alexandero/ClionProjects/ACM/output.txt", "w", stdout);
  //freopen("out.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  start = clock();
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
    //cout << "Case #" << testNum++ << ": ";
    //cerr << testNum << endl;
    solve(true);
    //cerr << testNum - 1 << endl;
  }
  cout.flush();
#ifdef AIM1
  while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif

  return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
  if (!w)
    return 1 % mod;
  if (w & 1)
    return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template<typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}

void precalc() {

}

template<typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}

#define int li
//const int mod = 1000000007;

void solve(bool read) {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  --n;
  for (int x = 0; x <= n; ++x) {
    int min_val = x * c - (n - x) * d;
    int max_val = x * d - (n - x) * c;
    if (min_val <= b - a && max_val >= b - a) {
      cout << "YES\n";
      return;
    }
  }

  cout << "NO\n";

}

Measured memory_bytes: 256
n=int(input())
a=[int(input()) for _ in range(n)]
b=sorted(a)
if b[n-1]==b[n-2]:
  for i in a:
    print(b[n-1])
else:
  for i in a:
    if i==b[n-1]:
      print(b[n-2])
    else:
      print(b[n-1])

Measured memory_bytes: 91036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define INF (2147483647)

const int MAX_N = 1<<17;
int N, dt[MAX_N*2-1];

void init(int n){
    N=1;
    while(N<n)N*=2;
    REP(i,2*N-1)dt[i]=INF;
}

void update(int i,int x){
    i+=N-1;
    dt[i]=x;
    while(i>0){
        i=(i-1)/2;
        dt[i]=min(dt[i*2+1],dt[i*2+2]);
    }
}

int find(int s,int t,int k,int l,int r){
    if(r<=s||t<=l)return INF;
    if(s<=l&&r<=t)return dt[k];
    else{
        int vl = find(s,t,k*2+1,l,(l+r)/2);
        int vr = find(s,t,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}

void solve() 
{
    int n,q;
    cin>>n>>q;
    init(n);
    while(q--){
        int com,x,y;
        cin>>com>>x>>y;
        if(com) cout<<find(x,y+1,0,0,N)<<endl;
        else update(x,y);
    }
}

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


Measured memory_bytes: 4196
S = list(str(input()))

a = int(S[0])*10 + int(S[1])
b = int(S[2])*10 + int(S[3])

if (1<=a and a<=12) and (1<=b and b<=12):
    print("AMBIGUOUS")
elif (1>a or a>12) and (1>b or b>12):
    print("NA")
elif (1<=a and a<=12) and (1>b or b>12):
    print("MMYY")
else:
    print("YYMM")

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

int main() {
  int n, y; cin >> n >> y;
  
  int a, b;
  int answer = 0;
  
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n-i; j++){
      if(9000*i + 4000*j +1000*n == y) {
        answer = 1;
        a = i;
        b = j;
        break;
      }
    }
    if(answer == 1) break;
  }
  
  if(answer == 1) cout << a << " " << b << " " << n-a-b << endl;
  else cout << "-1 -1 -1" << endl;
  
}

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

using namespace std;

int main()
{
    long long int i,j=2,number;
    //cout<<"Enter any number: ";
    cin>>number;
    //cout<<"Next prime number: ";




    for(i=number; i<1000000; i++)
    {
        for(j=2; j <i; j++)
        {
            if(i %j==0)
            {
                break;
            } // if
        } // for
        if(i==j || i==1)
        {
            cout<<i<<"\n";
            break;
        } // if
    }
    return 0; // outer for
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a;
long long ans;
int main(){
    cin>>a;
    if(a[0] != 'C') ans++;
    if(a[1] != 'O') ans++;
    if(a[2] != 'D') ans++;
    if(a[3] != 'E') ans++;
    if(a[4] != 'F') ans++;
    if(a[5] != 'E') ans++;
    if(a[6] != 'S') ans++;
    if(a[7] != 'T') ans++;
    if(a[8] != 'I') ans++;
    if(a[9] != 'V') ans++;
    if(a[10] != 'A') ans++;
    if(a[11] != 'L') ans++;
    if(a[12] != '2') ans++;
    if(a[13] != '0') ans++;
    if(a[14] != '1') ans++;
    if(a[15] != '6') ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/* 
3点A(x1, y1),B(x2, y2),C(x3, y3)で囲まれた3角形の内部に
P(xp, yp)が含まれるかどうかを判定
*/

#include <iostream>
using namespace std;

int main(void) {
    double x1, x2, x3, y1, y2, y3;
    double xp, yp;
    double ABAP, BCBP, CACP;
// ABとAP,BCとBP,CAとCPの傾きの大小関係を条件式に用いる。
// 不等式の両辺に負の数を掛けると大小関係が入れ替わることに注意。
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
        ABAP = (y2 - y1)*(xp - x1) - (x2 - x1)*(yp - y1);
        BCBP = (y3 - y2)*(xp - x2) - (x3 - x2)*(yp - y2);
        CACP = (y1 - y3)*(xp - x3) - (x1 - x3)*(yp - y3);
        if((ABAP > 0 && BCBP > 0 && CACP > 0) ||(ABAP < 0 && BCBP < 0 && CACP < 0)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


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

using namespace std;

typedef unsigned long long ull;

int main()
{
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int q;
    ull t;
    cin >> q;
    ull a[q], b[q];
    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < q; i++)
    {
        t = sqrt(a[i] * b[i]);
        if (a[i] == b[i])
        {
            cout << 2 * (a[i] - 1) << endl;
        }
        else if (t * t == a[i] * b[i])
        {
            cout << 2 * t - 3 << endl;
        }
        else if (t * (t + 1) >= a[i] * b[i])
        {
            cout << 2 * t - 2 << endl;
        }
        else
        {
            cout << 2 * t - 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];

	vector<ll> sum(n + 1, 0);
	for (int i = 0; i < n; ++i)
		sum[i + 1] = sum[i] + a[i];
	ll total = sum[n];
	ll ans = 10000000000000000LL;
	for (int i = 0; i <= n; ++i)
		ans = min(ans, abs(total - 2 * sum[i]));
	cout << ans << endl;

	return 0;
}

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

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p%i == 0) return false;
	}
	return true;
}

int n;

int main() {
	cin >> n;
	for (int i = 31; i <= 55555; i += 30) {
		if (isprime(i) == true) {
			if (i != 31) cout << " ";
			cout << i; n--;
		}
		if (n == 0) break;
	}
	cout << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;


void make_z(const string& str, vector<ll>& z); 

ll search(
    const string& text,
    const string& pattern
){
    string concat = pattern + "$" + text; 
    ll l = concat.size(); 
  
    vector<ll> z(l);
    make_z(concat, z);

    ll ret = 0;
    for(ll i = pattern.size() + 1; i < l; ++i){
        ret = max(ret, z.at(i));
    }
    return ret;
} 

void make_z(const string& s, vector<ll>& z) { 
    const ll n = s.size(); 
    ll L = 0, R = 0; 
    for (int i = 1; i < n; ++i) {
        if (i > R) { 
            L = R = i; 
            while (R < n && s[R-L] == s[R]){
                R++;
            }
            z[i] = R-L; 
            R--; 
        }else{  // i <= R
            const ll k = i-L; 
            if (z[k] < R-i+1){
                z[i] = z[k]; 
            }else{
                L = i; 
                while (R<n && s[R-L] == s[R]){
                    R++;
                }
                z[i] = R-L; 
                R--; 
            }
        } 
    } 
} 


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

    ll ans = 0;
    for(ll pos = 0; pos < s.size() - 1; ++pos){
        ll res = search(
            s.substr(0, pos),
            s.substr(pos, s.size() - pos)
        );
        ans = max(res, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
//#include<algorithm>
//#include<cmath>
//#include<string>
//#include<cctype>
//#include <vector>
using namespace std;
int main(){
	double a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f) {
		double x = (c*d - a*f) / (b*d - a*e);
		printf("%.3f %.3f\n", (1000*((c - b*x) / a))/1000, (1000*x)/1000);
	}
	return 0;
}

Measured memory_bytes: 3064