akhauriyash/Code-Regression huggingface dataset:
/*
595 ms	104520 KB
*/
import java.util.*;

public class Main {
    public static void main(String args[]) {
 		Scanner scan = new Scanner(System.in);
      	int v = scan.nextInt();
      	int e = scan.nextInt();
      	Graph graph = new Graph(v);
      
      	for(int edge = 0; edge < e; edge++){
          int a = scan.nextInt();
          int b = scan.nextInt();
         graph.addEdge(a, b);
        }
      	scan.close();
      	System.out.println(graph.longestPath(v));
	}
  
  public static class Graph{
 	public int size; 
    public ArrayList<Integer> edge[]; 
  
    public Graph(int vertices)  
    { 
        this.size = vertices; 
        edge = new ArrayList[vertices+1]; 
        for (int i = 0; i <= vertices; i++)  
            edge[i] = new ArrayList<>(); 
    } 
    public void addEdge(int a,int b) 
    { 
        edge[a].add(b); 
    } 
   public void visit(int node, ArrayList<Integer> adj[], int dp[], 
                                    boolean visited[]) 
    { 
        // Mark as visited 
        visited[node] = true; 
  
        // Traverse for all its children 
        for (int i = 0; i < adj[node].size(); i++)  
        { 
  
            // If not visited 
            if (!visited[adj[node].get(i)]) 
                visit(adj[node].get(i), adj, dp, visited); 
  
            // Store the max of the paths 
            dp[node] = Math.max(dp[node], 1 + dp[adj[node].get(i)]); 
        } 
    } 
    public int longestPath(int n) 
    { 
        ArrayList<Integer> adj[] = edge; 
        int[] dp = new int[n+1]; 
        boolean[] visited = new boolean[n + 1]; 
      
        for (int i = 1; i <= n; i++)  
         if (!visited[i]) visit(i, adj, dp, visited); 
         
  
        int answer = 0; 
  
        for (int i = 1; i <= n; i++)  answer = Math.max(answer, dp[i]); 
        return answer; 
    } 
  }
}

Measured memory_bytes: 95548
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
bool isable(string s,int a, int b, int no=0){
	int n=s.size();
	vb can(n,false);
	can[a]=true;
	range(i,a,b+1){
		if(!can[i])continue;
		if(i+1<n and s[i+1]=='.') can[i+1]=true;
		if(i+2<n and s[i+2]=='.') can[i+2]=true;
	}
	return can[b];
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	a--,b--,c--,d--;
	string s;
	cin>>s;
	if(c<d){//fu
		bool fu=isable(s,b,d) and isable(s,a,c,d);
		// puta(isable(s,a,c));
		Yn(fu);
	}else{
		bool su=isable(s,a,c) and isable(s,b,d,c);
		range(i,b,d+1){
			if(s[i-1]=='.' and s[i]=='.' and s[i+1]=='.'){
				Yn(su);
				return 0;
			}
		}
		Yn(false);
	}
	return 0;
}

Measured memory_bytes: 976
#line 1 "main_b.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 a,b,c,d;
  std::cin>>a>>b>>c>>d;

  i64 ans=std::max({a*c,a*d,b*c,b*d});

  bool zero=false;
  if(a<=0&&0<=b)zero=true;
  if(c<=0&&0<=d)zero=true;

  if(zero)chmax(ans,0);

  std::cout<<ans<<"\n";
  
  return 0;
}


Measured memory_bytes: 3688
N = int(input())
S = input()
E_cost = S.count("E")
W_cost = 0
ans = N
for s in S:
    if s == "E":
        E_cost -= 1
    ans = min(ans, E_cost + W_cost)
    if s == "W":
        W_cost += 1
print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll H, W, K; cin >> H >> W >> K;
  ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; x1--; y1--; x2--; y2--;
  string C[H]; rep(i,H) cin >> C[i];

  ll d[H][W] = {}; rep(i,H) fill_n(d[i],W,LLINF); d[x1][y1] = 0;
  queue<p_ll> q; q.push(make_pair(x1,y1));

  while (q.size()) {
    p_ll now = q.front(); q.pop();
    ll x = now.first, y = now.second;
    // cout << x << "," << y << "->" << d[x][y] << endl;
    repr(i,1,K+1) {
      if (x-i<0||C[x-i][y]=='@') break;
      if (d[x-i][y]<=d[x][y]) break;
      if (d[x-i][y]!=d[x][y]+1) {
        d[x-i][y] = d[x][y]+1;
        q.push(make_pair(x-i,y));
      }
    }
    repr(i,1,K+1) {
      if (x+i>=H||C[x+i][y]=='@') break;
      if (d[x+i][y]<=d[x][y]) break;
      if (d[x+i][y]!=d[x][y]+1) {
        d[x+i][y] = d[x][y]+1;
        q.push(make_pair(x+i,y));
      }
    }
    repr(i,1,K+1) {
      if (y-i<0||C[x][y-i]=='@') break;
      if (d[x][y-i]<=d[x][y]) break;
      if (d[x][y-i]!=d[x][y]+1) {
        d[x][y-i] = d[x][y]+1;
        q.push(make_pair(x,y-i));
      }
    }
    repr(i,1,K+1) {
      if (y+i>=W||C[x][y+i]=='@') break;
      if (d[x][y+i]<=d[x][y]) break;
      if (d[x][y+i]!=d[x][y]+1) {
        d[x][y+i] = d[x][y]+1;
        q.push(make_pair(x,y+i));
      }
    }
  }

  ll result = d[x2][y2]; if (result==LLINF) result = -1;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
string s;
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
const mint B1 = 10000027;
const mint B2 = 100000007;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<P,P>;
map<PP,ll> cnt;
P calchash(string s){
	int N = s.size();
	mint x = 0;
	mint y = 0;
	rep(i,N){
		x = x*B1 + s[i];
		y = y*B2 + s[i];
	}
	return P(x.v,y.v);
}

void calc1(string s){
	rep(b,1<<N){
		string x,y;
		rep(i,N){
			if((b>>i)&1) x += s[i];
			else y += s[i];
		}
		cnt[PP(calchash(x),calchash(y))]++;
	}
}
ll calc2(string s){
	ll ans = 0;
	rep(b,1<<N){
		string x,y;
		rep(i,N){
			if((b>>i)&1) x += s[i];
			else y += s[i];
		}
		ans += cnt[PP(calchash(x),calchash(y))];
	}
	return ans;
}

using ll = long long;
int main(){
	cin>>N;
	cin>>s;
	calc1(s.substr(0,N));
	string t = s.substr(N,N);
	reverse(all(t));
	cout<<calc2(t)<<endl;
}


Measured memory_bytes: 41216
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int N, D;
  cin >> N >> D;
  cout << (N - 1) / (2 * D + 1) + 1 << endl;
  return 0;
}


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

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

int main(void)
{
    ll x,n; cin>>x>>n;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    if(n==0){
        cout<<x<<endl;
        return 0;
    }

    sort(p.begin(),p.end());
    ll dist=1e9,tmp,ans=1e9;
    bool skip=false;
    for(int i=0;i<=101;i++){
        skip=false;
        rep(j,n){
            if(i==p[j]){
                skip=true;
                continue;
            }
        }
        if(skip) continue;
        tmp=abs(x-i);
        if(tmp<dist){
            dist = tmp;
            ans = i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    VB a(3,1);
    REP(i,2){
        int n; cin >> n; n--; a[n] = 0;
    }
    REP(i,3) if(a[i]) out(i+1);

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define INFINITY 1000000000

int A[500000];
int num=0;
int n1,n2;
int L[5000000];
int R[5000000];

void merge(int A[],int left,int mid,int right){
  int i,k,j;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=INFINITY;
  R[n2]=INFINITY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
num++;
    }
   else{
     num++;
  A[k]=R[j];
  j=j+1;
    }
  }
}
void mergesort(int A[],int left,int right){
  if(left+1<right){
    int mid;
    mid = (left + right)/2;
    mergesort(A, left, mid);
    mergesort(A, mid, right);
    merge(A, left, mid, right);
  }
}
int main(){
  int n,i;
  scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&A[i]);
}
mergesort(A,0,n);
for(i=0;i<n;i++){
if(i==n-1){
printf("%d\n",(int)A[i]);
break;
}
printf("%d ",(int)A[i]);
}
printf("%d\n",num);

return 0;
}



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

int main() {
  std::string s, tmp;
  std::cin >> s;

  tmp.push_back(s[0]);
  for (int i = 1; i < s.length(); i++) {
    if (tmp.back() != s[i]) {
      tmp.push_back(s[i]);
    }
  }
  s = tmp;

  std::cout << s.length() - 1 << "\n";

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> a(N);
  int b = 0;
  int j = 0;
  for(int i = 0; i < N; i++) {
    if(S.at(i) == 'I') {
      if(i == 0) {
        a.at(j) = b + 1;
      }
      else {
        a.at(j) = a.at(j-1) + 1;
      }
      j++;
    }
    else {
      if(i == 0) {
        a.at(j) = b - 1;
      }
      else {
        a.at(j) = a.at(j-1) - 1;
      }
      j++;
    }
  }
  sort(a.begin(), a.end());
  cout << max(0,a.at(N-1));
}


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

int main() {
    int N, K, Q; cin >> N >> K >> Q;
    vector<int> A(N, K);
    for (int i = 0; i < Q; i++) {
        int x; cin >> x;
        A.at(x-1)++;
    }
    for (int i = 0; i < N; i++) {
        if (A.at(i) - Q > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 3788
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, ma, mb) = scan!(usize, usize, usize);
    let vs = scan!(usize, usize, usize; n);
    let mut dp = vec![vec![vec![1usize << 30; 10 * n + 1]; 10 * n + 1]; n + 1];
    dp[0][0][0] = 0;

    for (i, &v) in vs.iter().enumerate() {
        for j in 0..dp[i + 1].len() {
            for k in 0..dp[i + 1][j].len() {
                if j >= v.0 && k >= v.1 {
                    dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - v.0][k - v.1] + v.2)
                } else {
                    dp[i + 1][j][k] = dp[i][j][k]
                }
            }
        }
    }

    let mut ans = 1usize << 30;
    for i in 0..dp[n].len() {
        for j in 0..dp[n][i].len() {
            if !(i == 0 && j == 0) && mb * i == ma * j {
                ans = min(ans, dp[n][i][j]);
            }
        }
    }

    if ans == 1usize << 30 {
        println!("-1")
    } else {
        println!("{}", ans)
    }
}


Measured memory_bytes: 63740
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  ll n,k;
  cin>>n>>k;

  n=n%k;

  //cout<<abs(n-k)<<" "<<n<<endl;
  cout<<min(abs(n-k),n)<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>

int isPrime(int x)
{
	int i;
	if(x<2)return 0;
	if(x==2)return 1;
	if(x%2==0)return 0;
		for(i=3;i*i<=x;i+=2)
		{
			if(x%i==0)return 0;
		}
	return 1;
}
int main(void)
{
	int count,n,x,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&x);
		count+=isPrime(x);
	}
	
	printf("%d\n",count);
	
	return 0;
}


Measured memory_bytes: 2096
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
                Scanner scan = new Scanner(System.in);
                int count=1;
                String rain;
                rain=scan.nextLine();
                if(rain.charAt(0)=='S' && rain.charAt(1)=='S' && rain.charAt(2)=='S'){
                    System.out.print(0);
                }else {
                    for (int i = 1; i < rain.length(); i++) {
                        if (rain.charAt(i) == 'R' && rain.charAt(i - 1) == 'R') {
                            count++;
                        }
                    }
                    System.out.print(count);
                }
    }
}


Measured memory_bytes: 27008
#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>;

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    if (dist[i][j] != d) continue;
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


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

int main()
{
  std::string a, b;
  std::cin >> a >> b;
  std::string str;
  if (a.size() > b.size()) str = "GREATER";
  else if (a.size() < b.size()) str = "LESS";
  else {
    for (int i = 0; i < a.size(); i++) {
      if (a[i] > b[i]) {
        str = "GREATER";
        break;
      } else if (a[i] < b[i]) {
        str = "LESS";
        break;
      }
    }
    if (str == "") str = "EQUAL";
  }
  std::cout << str << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll n,m;
vl a(1);

int main(){
	cin>>n>>m;
	a[0]=n;
	if(!m){
		for(int i=0;i<n;i++) cout<<1<<endl;
		return 0;
	}
	for(int i=0;i<m;i++){
		ll A;
		cin>>A;
		while(a.size()&&a.back()>=A) a.pop_back();
		a.push_back(A);
	}
	int N=a.size();
	vl b(N),c(n);
	b[N-1]++;
	for(int i=N-1;i>0;i--){
		ll L=a[i]%a[i-1],t=b[i];
		b[i-1]+=a[i]/a[i-1]*t;
		while(a[0]<L){
			int I=lower_bound(a.begin(),a.end(),L)-a.begin()-1;
			b[I]+=L/a[I]*t;
			L%=a[I];
		}
		if(L) c[L-1]+=t;
	}
	c[a[0]-1]+=b[0];
	for(int i=n-1;i>0;i--) c[i-1]+=c[i];
	for(int i=0;i<n;i++) cout<<c[i]<<endl;
	cout<<endl;
}

Measured memory_bytes: 4212
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

int main(){

    int K;
    string S;
    cin>>K>>S;

    if(S.size()<=K){
        cout<<S<<endl;
    }else{
        cout<<S.erase(K)<<"..."<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3580
n, m = map(int,input().split())
l = sorted(list(map(int,input().split())), reverse=True)


l_sum = sum(l)/(m*4)

ans = 0
for i in range(m):
    if l[i] >= l_sum:
        ans += 1

if ans == m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
N=int(input())
A=list(input())
B=list(input())
C=list(input())

a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

L=[0 for i in range(N)]
same=0
for i in range(N):
    if A[i]==B[i] and B[i]==C[i] and C[i]==A[i]:
        same+=3
    elif A[i]==B[i] or B[i]==C[i] or C[i]==A[i]:
        same+=2
    else:
        same+=1
print(3*N-same)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll fiv(ll i){
  for(ll j=1;j<=i;j++) if(j*j*j*j*j==i) return(j);
  return(0);
}
int main(){
  ull x;
  cin>>x;
  set<ull> s;
  for(ull i=1;i<=300;i++){
    s.insert(i*i*i*i*i);
  }
  //for(auto i:s) cout<<i<<endl;
 	for(ull i=1;i<=300;i++){
      ull j=i*i*i*i*i;
      
      if(j==x) {cout<<j<<" "<<0;return(0);}
      
      
      else if(j<x && s.count(x-j)) {cout<<fiv(x-j)<<" -"<<i;return(0);}
        
      else if(j>x && s.count(j-x)) {cout<<i<<" "<<fiv(j-x);return(0);}
    }
    return(0);
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
using P = pair<int, int>;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

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

signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9+7;
    int q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    s=min(s,min(q*4,h*2));
    if(s*2<d)cout<<n*s<<endl;
    else cout<<(n/2)*d+(n%2)*s<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, P: "List[int]"):
    m = P[0]
    ans = 1
    for p in P:
        if p < m:
            ans += 1
            m = p
    print(ans)

    return



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25984
def solve():
    n, m = [int(i) for i in input().split()]

    s = [-1 for _ in range(m)]
    c = [-1 for _ in range(m)]

    for i in range(m):
        s[i], c[i] = [int(j) for j in input().split()]

    a = [-1 for _ in range(n)]

    for _s, _c in zip(s, c):
        if a[_s - 1] == -1:
            a[_s - 1] = _c

        elif a[_s - 1] != _c:
            print(-1)
            return
    
    if a[0] == -1 and n != 1:
        a[0] = 1
    for i in range(len(a)):
        if a[i] == -1:
            a[i] = 0
    
    if a[0] == 0 and n != 1:
        print(-1)
        return

    char_a = [str(_a) for _a in a]
    str_a = "".join(char_a)
    print(str_a)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	static int[][] field;
	static int[] v1 = {1,-1,-1,1,1,0,-1,0};
	static int[] v2 = {1,-1,1,-1,0,1,0,-1};
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int w = cin.nextInt();
			int h = cin.nextInt();
			if(w+h==0){
				break;
			}
			field = new int[h+2][w+2];
			for(int i = 1; i <= h;i++){
				for(int j = 1; j <= w;j++){
					field[i][j]=cin.nextInt();
				}
			}
			int count=0;
			for(int i = 1; i <= h;i++){
				for(int j = 1; j <= w;j++){
					if(field[i][j]==1){
						dfs(i, j);
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
	static void dfs(int x, int y){
		field[x][y]=0;
		for(int i = 0; i < 8;i++){
			int xx=x+v1[i];
			int yy=y+v2[i];
			if(field[xx][yy]==1){
				dfs(xx,yy);
			}
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)

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

    map<char, int> cnt;
    for (int i = 0; i < n; i++) cnt[s[i]]++;
    ll ans = cnt['R'] * cnt['G'] * cnt['B'];

    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            int k = j + (j - i);
            if (k >= n) continue;
            if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ans--;
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3160
#include<stdio.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

bool flag = true;

void solve(queue<int> left, queue<int> right, queue<int> all) {
	if (all.size() > 0) {
		if (left.size() > 0) {
			if (all.front() > left.back()) {
				left.push(all.front());
				all.pop();
				solve(left, right, all);
			}
			else {
				if (right.size() > 0) {
					if (all.front() > right.back()) {
						right.push(all.front());
						all.pop();
						solve(left, right, all);
					}
					else if(all.size() == 0){
					
					}
					else {
						flag = false;
					}
				}
				else {
					right.push(all.front());
					all.pop();
					solve(left, right, all);
				}
			}
		}
		else {
			left.push(all.front());
			all.pop();
			solve(left, right, all);
		}
	}
}

int main() {

	int n;
	cin >> n;
	for (; n > 0; n--) {
		queue<int> all;
		queue<int> left;
		queue<int> right;
		for (int i = 0; i < 10; i++) {
			int temp;
			cin >> temp;
			all.push(temp);
		}
		solve(left, right, all);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}



	
				   
}

Measured memory_bytes: 1224
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int x=sc.nextInt(),y=sc.nextInt(),a,b,f=0;
    if(y%2!=0){
      System.out.println("No");
    }else{
      for(int i=0;i<=x;i++){
        a=i;
        b=x-i;
        
        if((2*a+4*b)==y){
          System.out.println("Yes");
          f++;
          break;
        }
      }
      if(f==0){
        System.out.println("No");
      }
    }
  }
}


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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  ll n, h; std::cin >> n >> h;
  vector<pair<ll, bool>> values;
  rep(i, n) {
    ll a, b;  std::cin >> a >> b;
    values.eb(a, true);
    values.eb(b, false);
  }
  sort(values.rbegin(), values.rend());
  int ans = 0;
  for (int i = 0; i < n * 2 && h > 0; i++) {
    if (values[i].se) {
      ans += (h + values[i].fi - 1) / values[i].fi;
      break;
    } else {
      ans++;
      h -= values[i].fi;
    }
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 6512
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define ll long long

int main(){
  int n;
  scanf("%d",&n);
  if(n%2==0)
  printf("%d",n/2);
  else
    printf("%d",n/2+1);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define MAX 100
#define INF (1<<21)
int n, L[MAX][MAX], S[MAX];

int bfs( int s, int t ){
    queue<int> q; q.push(s);
    int u, v, d[MAX];
    rep(i, n) d[i] = INF;
    d[s] = 1;
    while( !q.empty() ){
	u = q.front(); q.pop();
	rep(i, S[u]){
	    v = L[u][i];
	    if ( d[v] == INF ){
		d[v] = d[u] + 1;
		q.push(v);
	    }
	}
    }
    return d[t];
}

main(){
    int s, t, tl, q, c;
    cin >> n;
    rep(i, n){
	cin >> s; s--; cin >> S[s];
	rep(j, S[s]){
	    cin >> L[s][j]; L[s][j]--;
	}
    }
    cin >> q;
    rep(i, q){
	cin >> s >> t >> tl;
	c = bfs(s-1, t-1);
	if ( c <= tl ) cout << c << endl;
	else cout << "NA" << endl;
    }
}

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

int main(){
  string S;
  cin >> S;
  int max=0;
  
  int n = S.size();
  
  for(int i=0;i<n;i++){
    int count=0;
    for(int j=i;j<n;j++){
      if(S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T'){
        count++;
        if(count > max){
          max = count;
        }
      } else {
        break;
      }
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
A = LI()
ans = -INF
for x, y in combinations(A, 2):
    ans = max(ans, abs(x-y))
print(ans)

Measured memory_bytes: 63980
import java.util.*;
public class Main{
		
  	public static void main(String args[]){
    	Scanner s=new Scanner(System.in);
      	int d=s.nextInt();
      	int t=s.nextInt();
      	int speed=s.nextInt();
      	float er=(float)d/speed;
      	//System.out.println("er "+er);
      	if(er<=t){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 35704
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int x,y; cin >> x >> y;

  int ans = 1 << 30;
  if(x * y >= 0 && y <= x) ans = min(ans,1 + abs(y - x) + 1);
  if(x * y <= 0 && -y <= x) ans = min(ans,1 + x - (-y));
  if(x * y <= 0 && -y >= x) ans = min(ans,(-y) - x + 1);
  if(x * y >= 0 && y >= x) ans = min(ans,y - x);
  cout << ans << endl;

  return 0;
}


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

int main(void) {
    long n, m;
    cin >> n >> m;
    
    vector<vector<long>> G(n);
    for(long i=0; i<m; i++) {
        long a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<long> idx(n, -1), l(n);
    long r = 0;
    {
        auto dfs = [&](auto dfs, long cur, long prev, long &x) -> void {
            l[cur] = idx[cur] = x++;
            for(auto &v: G[cur]) {
                if(v == prev) continue;
                if(idx[v] == -1)
                    dfs(dfs, v, cur, x);
                l[cur] = min(l[cur], l[v]);

                if(idx[cur] < l[v])
                    r++;
            }
        };

        long x = 0;
        dfs(dfs, 0, -1, x);
    }

    cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;cin>>n;
	vi v(n);
	rep(i,n)cin>>v[i];

	vector<pii> cnt1(1e5+1,make_pair(0,0)),cnt2(1e5+1,make_pair(0,0));

	rep(i,1e5+1){
		cnt1[i].second=i;
		cnt2[i].second=i;
	}

	rep(i,n/2){
		cnt1[v[2*i]].first++;
		cnt2[v[2*i+1]].first++;
	}
	sort(all(cnt1));
	sort(all(cnt2));
	reverse(all(cnt1));
	reverse(all(cnt2));



	if(cnt1[0].second!=cnt2[0].second){
		cout<<n-cnt1[0].first-cnt2[0].first<<endl;
	}else if(cnt1[1].first+cnt2[0].first>=cnt1[0].first+cnt2[1].first){
		cout<<n-cnt1[1].first-cnt2[0].first<<endl;
	}else{
		cout<<n-cnt1[0].first-cnt2[1].first<<endl;
	}
	return 0;


}


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

int main(void) {
  long long N, B, R;
  
  cin >> N >> B >> R;
  
  long long set = N / (B + R);
  
  long long mod = min(B, N % (B + R));
  
  cout << set * B + mod << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/math/common_factor.hpp>
using namespace std;
 
int main()
{
	long long int a , b;
	cin >> a >> b;
  	if((a == 0||b==0)|| a==0&&b==0){
  	    if(a==0){cout << b<<endl;} 
  	    else if(b==0){cout << a<<endl;}
  	    else{cout << 0 << endl;}
  	    
  	}
 	else{
  		cout <<boost::math::lcm(a,b) << endl;
    }
}

Measured memory_bytes: 256
def c160(k , n , al):

    ans = 0
    count = 0

    for i in range(n):
        if i == n - 1:
            count = max(count , (k - al[i]) + al[0])
        else:
            count = max(count , al[i + 1] - al[i])

    return k - count

def main():
    k , n = map(int , input().split())
    al = list(map(int , input().split()))
    print(c160(k , n , al))
if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long int L;
//RECURSIVE SOLUTION
/*L mx(L* a, L n){        //function returns the max sum u can get by moving first
    if(n == 1){
        return a[0];
    }if(n == 2){
        return max(a[0], a[1]);
    }
    return max(a[0] + min(mx(a + 2, n - 2), mx(a + 1, n - 2)), a[n-1] + min(mx(a + 1, n - 2), mx(a, n - 2)));
}
*/

       
       
L answerDP(L* a, L n){
    
    
    vector<vector<L>> ans (n, vector<L> (n, 0));
    
    //ans[i][j] stores the answer for array starting from i and ending at j; hence j >= i;
    //only the right upper half of the square matrix is filled
    //ans[0][n-1] gives the answer
    
    //Base Case - i == j
    
    for(L i = 0; i<n; i++){
        ans[i][i] = a[i];
    }
    
    //Second base case - (j - i == 1)
    
    for(L i = 0; i<(n-1); i++){
        ans[i][i+1] = max(a[i], a[i+1]);
    }
    
    for(L count = 1; count <= (n-2); ++count){
        
        L i = 0;
        L j = count + 1;
        
        while(i < (n -  count - 1)){
            L op1 = a[i] + min(ans[i+2][j], ans[i+1][j-1]);
            L op2 = a[j] + min(ans[i+1][j-1], ans[i][j-2]);
            
            ans[i][j] = max(op1, op2);
            i++;
            j++;
        }
    }
  /*  for(L i = 0; i<n; i++){
        for(L j = 0; j<n; j++){
            cout << ans[i][j] << "     ";
        }cout << endl;
    }*/
    
    return ans[0][n-1];
    
}

int main() {
    L n, a[3005];
    scanf("%lld", &n);
    L s = 0;
    for(L i = 0; i<n; i++){
        scanf("%lld", &a[i]);
        s += a[i];
    }
    // cout << s << endl;
    // cout << 2*mx(a, n) - s << "\n";
    cout << 2*answerDP(a, n) - s << "\n";
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
int main(){
  int R,G,B,N,a=0;
  cin>>R>>G>>B>>N;
  for(int r=0;r<=N/R;r++){
    for(int g=0;g<=(N-R*r)/G;g++){
      if((N-R*r-G*g)%B==0)a++;
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
s = input()
ans = [-1, -1]
for i in range(len(s)):
    if i <= len(s) - 2:
        if s[i] == s[i + 1]:
            ans = [i + 1, i + 2]
            break
    if i <= len(s) - 3:
        if s[i] == s[i + 2]:
            ans = [i + 1, i + 3]
print(ans[0], ans[1])


Measured memory_bytes: 3188
n = int(input())
arr = []
arr = list(map(int, input().split()))
flag = 0
count = 0
for i in range(n):
  num = arr[i]
  if num % 2 == 0:
    count += 1
    if(num % 6 == 0) or (num % 10 == 0):
      flag += 1
      
if flag == count:
    print("APPROVED")
else:
    print("DENIED")


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

const long long MOD = (long long)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<long long> A(N);
	for(int i=0;i<N;i++)	cin >> A.at(i);

	long long ans=0;
	long long tmp2=1;
	long long tmp3=1;
	for(int i=0;i<61;i++){
		long long cnt0=0;
		long long cnt1=0;
		for(int j=0;j<N;j++){
			if(A.at(j)&tmp3)	cnt1++;
			else	cnt0++;
		}
		long long tmp=cnt0*cnt1;
		tmp%=MOD;
		tmp*=tmp2;
		tmp%=MOD;
		ans+=tmp;
		ans%=MOD;
		//cout << cnt0 << "," << cnt1 << endl;
		//cout << i << ",";
		//cout << tmp3 << endl;
		tmp2=(tmp2*2)%MOD;
		tmp3*=2;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int main()
{
    char s[55], t[55];
    scanf("%s%s", s, t);
    int i, j;
    int n = strlen(s), m = strlen(t);
    if (n < m)
    {
        printf("UNRESTORABLE\n");
        return 0;
    }
    int x;
    for (i = n - m; i >= 0; i--)
    {
        x = 0;
        for (j = 0; j < m; j++)
        {
            if (s[i + j] != '?' && s[i + j] != t[j])
            {
                x++;
                break;
            }
        }
        if (x == 0)
        {
            for (j = 0; j < m; j++)
                s[i + j] = t[j];
            x = -1;
            break;
        }
    }
    if (x != -1)
    {
        printf("UNRESTORABLE\n");
        return 0;
    }
    for (i = 0; i < n; i++)
        if (s[i] == '?')
            s[i] = 'a';
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=0;cin>>n;
  vector<int>l(n+1);
  for(int i=0;i<n;i++)cin>>l.at(i);
  sort(l.begin(),l.end());
  l.at(0)=l.at(n)+1;
  sort(l.begin(),l.end());
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      int k=j+1;
      while(l.at(k)<l.at(i)+l.at(j)&&k<n){
        a++;
        k++;
      }
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
A, V = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
B, W = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
T = int(input())  # 入力のときに N を使う必要はありません

if B - A > 0:
    if (A + V*T) - (B + W*T) >= 0:
        print("YES")
    else:
        print("NO")
else:
    if (A - V*T) - (B - W*T) <= 0:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9220
from collections import deque
n = int(input())
a = list(map(int, input().split()))
b = deque()

for i in range(n):
    if i%2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n%2 == 1:
    b.reverse()
print(*b, sep=' ')


Measured memory_bytes: 32340
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll x; cin >> x;
    ll ans = x / 11 * 2;
    if (x % 11 >= 1 && x % 11 <= 6) ans += 1;
    else if (x % 11 >= 7) ans +=2;

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int a,b,c;
  cin >> a >> b >> c;
  int p=0,q=0,r=0;
  if(a==b)
    p=1;
  if(b==c)
    q=1;
  if(a==c)
    r=1;
  if(p==1 && q==1 && r==1)
    cout << "1" << endl;
  else if(p==0 && q==0 && r==0)
    cout << "3" << endl;
  else
    cout << "2" << endl;
  return 0;
}


Measured memory_bytes: 256