akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int a[100010], b[100010];
signed main(void)
{
  int n, k;
  cin >> n >> k;
  REP(i, n) cin >> a[i] >> b[i];

  int ret = 0;
  REP(j, n) {
    bool flag = true;
    REP(l, 30) {
      if((a[j]>>l)&1 && !((k>>l)&1)) {flag = false; break;}
    }
    if(flag) ret += b[j];
  }

  int ans = ret;
  REP(i, 30) {
    // kの上位ibit目が1 → そこを0にしてそこより下位のbitを1に
    if(k>>i&1) {
      int c = k&~(1LL<<i);
      c |= (1LL<<i)-1;
      // a[j]でbitが立っていてcでbitが立っていない → だめ
      int ret = 0;
      REP(j, n) {
        bool flag = true;
        REP(l, 30) {
          if((a[j]>>l)&1 && !((c>>l)&1)) {flag = false; break;}
        }
        if(flag) ret += b[j];
      }
      chmax(ans, ret);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5176
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const int M=1000000007;
const int MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=5e5+5;

ll sp[N];

void fill(){
  for(int i=1;i<N;i++)sp[i]=i;

    for(int i=2;i<N;i++){
      for(int j=i;j<N;j+=i){
        if(sp[j]==j)sp[j]=i;
      }
    }
}

bool prime(ll x){
  if(x==2)return true;

for(ll i=2;i*i<=x;i++){
  if(x%i==0)return false;
}

  return true;
}

ll fac[N];

ll inv[N];

void gg(){
  fac[0]=inv[0]=1;

  for(int i=1;i<N;i++){
    fac[i]=fac[i-1]*i%M;
    inv[i]=powM(fac[i],M-2,M);
  }
}

ll c(ll a,ll b,ll M){
  if(b>a)return 0;

  return (fac[a]*inv[a-b]%M)*(inv[b])%M;
}

pll f(ll x){
  ll b=x%10;
  while(x>=10){
    x/=10;
  }
  return {x%10,b};
}

int main()
{ 

IOS;


ll n;cin>>n;

map<pll,ll>m;

//d2(f(12).ff,f(12).ss);


for(int i=1;i<=n;i++){
  m[f(i)]++;
}

//cout<<m[{3,3}]<<endl;


ll ans=0;

for(int i=1;i<=9;i++){
  for(int j=i;j<=9;j++){
    if(j==i){
      ll e=m[{i,i}];
      ans+=e*e;
    }
    else ans+=2*m[{i,j}]*m[{j,i}];
  }
}

cout<<ans;

//end_routine();

return 0;
 
}


Measured memory_bytes: 3624
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,m;
Pi p[100010];

int main(){
	cin>>n>>m;
	REP(i,m){
		int a,b;
		cin>>a>>b;
		p[i]=Pi(b,a);
	}
	sort(p,p+m);
	int last=-1;
	int ans=0;
	REP(i,m){
		if(p[i].second>=last){
			ans++;
			last=p[i].first;
		}
	}
	cout<<ans<<endl;
	return 0;
}
	

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll t1,t2,a1,a2,b1,b2;
int main(){
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    a1*=t1;
    a2*=t2;
    b1*=t1;
    b2*=t2;
    if(a1+a2==b1+b2){
        cout<<"infinity\n";
        return 0;
    }
    if(a1<b1^a1+a2>b1+b2){
        cout<<0<<endl;
        return 0;
    }
    ll c1=abs(a1-b1),c2=abs(a2-b2);
    if(c1>c2){
        ll t=c1;
        c1=c2;
        c2=t;
    }
    cout<<c1/(c2-c1)*2+(c1%(c2-c1)?1:0)<<endl;
}

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

using namespace std;

int main(){
  int n;
  std::cin >> n;
  char S[n];
  std::cin >> S;
  char origin[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  vector<vector<char>> data(1000, vector<char>(4));
  int ii = 0;
  for (int i=0; i < 10; i++){
    for (int j=0; j < 10; j++){
      for (int h=0; h < 10; h++){
        data.at(ii).at(0) = origin[i];
        data.at(ii).at(1) = origin[j];
        data.at(ii).at(2) = origin[h];
        ++ii;
      }
    }
  }
  int cnt = 0;
  vector<char> ans = vector<char>(3);
  for (int i=0; i<1000; i++) {
    ans = data.at(i);
    int f_flg=0, s_flg=0, t_flg=0;
    for (int j=0; j<n; j++) {
      if (!f_flg) {
        if (S[j] == ans.at(0)) {
          f_flg = 1;
        }
        continue;
      } else if (!s_flg) {
        if (S[j] == ans.at(1)){
          s_flg = 1;
        }
        continue;
      } else if (S[j] == ans.at(2)) {
        cnt++;
        break;
      }
    }
  }
  // char[3] ans[1000];
  // for ( int i=0;i<1000;i++){
  //   
  // }
  std::cout << cnt << std::endl;
  return 0;
}


Measured memory_bytes: 3728
n, k = map(int, input().split())
xlist = list(map(int, input().split()))

mink = pow(10, 18)
for i, x in enumerate(xlist[k-1:]):
  lx = xlist[i]
  if mink > abs(lx) + x - lx:
    mink = abs(lx) + x - lx
  if mink > abs(x) + x - lx:
    mink = abs(x) + x - lx
print(mink)


Measured memory_bytes: 14224
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
const int maxn=1e5+7;
int a[maxn];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans;
	for(int i=1;i<n;i++){
		if(i==1){
			ans=__gcd(a[i-1],a[i]);
		}
		else{
			ans=__gcd(ans,a[i]);
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 640
//In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define MAX 100011
#define mod 1000000007
#define inf 1000000000000000000
#define ll long long
#define endl '\n'
ll dp[111][MAX],sum[MAX];
int a[111];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,k;
	cin>>n>>k;
	for(int i = 0 ; i < n ; i++)cin>>a[i];
	memset(dp,0,sizeof dp);
	memset(sum,0,sizeof sum);
	for(int j = 0; j <= a[0] ; j++)dp[0][j] = 1;
	sum[0] = 1;
	for(int j = 1; j <= k ; j++)sum[j] = sum[j-1] + dp[0][j];

	for(int i = 1 ; i < n ; i++){
		dp[i][0] = 1;
		sum[0] = 1;

		for(int j = 1;j <= k; j++){
			if(j - a[i] - 1 >= 0)
				dp[i][j] = (sum[j] - sum[j - a[i] - 1] + mod)%mod;
			else
				dp[i][j] = sum[j];
		}
		for(int j = 1; j <= k ; j++)sum[j] = (sum[j-1] + dp[i][j])%mod;	
	}
	cout<<dp[n-1][k];
	return 0; 
} 

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n,m;
ll s[e5];
graph g;
ll a_cnt[e5];
ll b_cnt[e5];
ll vis[e5];
queue<ll> q;

int main(){
  cin >> n >> m;
  string s_;
  cin >> s_;
  for(ll i = 1;i <= n;i++){
    s[i] = (s_[i-1] == 'A' ? 0 : 1);
  }
  for(ll i = 0;i < m;i++){
    ll a,b;
    cin >> a >> b;
    g[a][b]++;
    g[b][a]++;
    if(s[a] == 0) a_cnt[b]++;
    else b_cnt[b]++;
    if(s[b] == 0) a_cnt[a]++;
    else b_cnt[a]++;
  }
  for(ll i = 1;i <= n;i++){
    if(a_cnt[i] == 0 || b_cnt[i] == 0){
      q.push(i);
      vis[i] = 1;
    }
  }
  // for(ll i = 1;i <= n;i++) cerr << a_cnt[i] << " ";
  // cerr << endl;
  // for(ll i = 1;i <= n;i++) cerr << b_cnt[i] << " ";
  // cerr << endl;
  ll k = n;
  while(!q.empty()){
    ll x = q.front();
    q.pop();
    for(auto y : g[x]){
      if(s[x] == 0) a_cnt[y.first] -= g[x][y.first];
      else b_cnt[y.first] -= g[x][y.first];
      if((a_cnt[y.first] == 0 || b_cnt[y.first] == 0) && vis[y.first] == 0){
        q.push(y.first);
        vis[y.first] = 1;
      }
    }
    k--;
  }
  // for(ll i = 1;i <= n;i++) cerr << a_cnt[i] << " ";
  // cerr << endl;
  // for(ll i = 1;i <= n;i++) cerr << b_cnt[i] << " ";
  // cerr << endl;
  if(k == 0) cout << "No" << endl;
  else cout << "Yes" << endl;


}


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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define printFix(n,i) cout << fixed << setprecision(i) << n << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
#define bitrep(i,n) for (int i = 0; i < (1<<(n));i++)
#define isOne(bit,i) (bit & (1 << i))
using ll = long long;
using pii = pair<int, int>;
using si = set<int>;

const ll modSeed = pow(10,9) + 7;
const int INF = 100'000'000;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

ll PowMod(ll modSeed, ll tgt, int powSeed){
  ll res = 1;
  rep(i,powSeed){
    res = (res*tgt) % modSeed;
  }
  return res;
}

string S;
ll N,cnt;

int main(){
  cin >>N;
  ll ans  = PowMod(modSeed,10,N) - PowMod(modSeed,9,N) - PowMod(modSeed,9,N) + PowMod(modSeed,8,N);
  ans %= modSeed;
  ans += modSeed;
  ans %= modSeed;
  printl(ans);
}


Measured memory_bytes: 3620
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

ll D;
vi c;
vvi s;

ll value(vi t)
{
    ll S = 0;
    vi last(26);
    REP(i, t.size())
    {
        ll k = t[i];
        last[k] = i + 1;
        S += s[i][k];
        REP(j, 26)
        {
            S -= c[j] * (i + 1 - last[j]);
        }
    }
    return S;
}

int main()
{
    cin >> D;
    c.resize(26);
    REP(i, 26)
    {
        cin >> c[i];
    }
    s.assign(D, vi(26));
    REP(i, D)
    {
        REP(j, 26)
        {
            cin >> s[i][j];
        }
    }

    vi t;
    REP(i, D)
    {
        ii opt = {0, 0};
        REP(j, 26)
        {
            t.push_back(j);
            ll res = value(t);
            if (res > opt.first)
            {
                opt = {res, j};
            }
            t.pop_back();
        }
        t.push_back(opt.second + 1);
    }
    FOR(x, t)
    {
        OUT(x);
    }
}

Measured memory_bytes: 3768
n,x=map(int,input().split())
a=[(1,1)]
for _ in range(n):
  a+=[(a[-1][0]*2+3,a[-1][1]*2+1)]

if a[-1][0] in (x,x-1):
  print(a[-1][1]);exit()

s=0
for k in range(3,len(a)*2+1):
  i,j = a[-k // 2]
  x -= k % 2
  if i <= x:
    x-=i;s+=j
    if x>=1:x-=1;s+=1

print(s)

Measured memory_bytes: 3064
n = gets.to_i
last_index = n - 1
s = gets.chomp

ng_count = 0

(0..(last_index - 2)).each{|head_index|
    (1..((last_index - head_index) / 2)).each{|step|
        mid_index = head_index + step
        tail_index = head_index + step * 2
        if s[head_index] != s[mid_index] && s[mid_index] != s[tail_index] && s[tail_index] != s[head_index]
            ng_count += 1
        end
    }
}

r_count = 0
g_count = 0
b_count = 0
s.chars.each{|c|
    if c == 'R'
        r_count += 1
    elsif c == 'G'
        g_count += 1
    else
        b_count += 1
    end
}
puts r_count * g_count * b_count - ng_count


Measured memory_bytes: 14392
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
vector<ll> A;
vector<ll> B;
vector<ll> S;

ll sum(int i,int j){
    if (i==0) return S[j];
    else return (S[j] - S[i-1]);
}

int main(){
    int N,K; SCD2(N,K);
    VSCLLD(A,N);
    S.PB(A[0]);
    REP(i,N-1){
        S.PB(S[i] + A[i+1]);
    }


    REP(i,N){
        REP(j,N){
            if (i>j) continue;
            B.PB(sum(i,j));
        }
    }

    vector<bitset<48> > bs;
    vector<int> valid;

    REP(i,B.size()){
        bitset<48> b(B[i]);
        bs.PB(b);
        valid.PB(1);
        //cout << b << "\n";
    }
    
    FORqr(i,0,47){
        int count = 0;
        REP(j,B.size()){
            if (valid[j] == 0) continue;
            if (bs[j][i]) count++;
        }
        
        if (count >= K ){
            REP(j,B.size()){
                if (!bs[j][i]) valid[j] = 0;
            }
        }
    }

    vector<int> ansset;

    REP(j,B.size()){
        if (valid[j] == 0) continue;
        ansset.PB(j);
    }

    ll ans = B[ansset[0]];
    REP(i,K){
        ans = ans & B[ansset[i]];
    }

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

Measured memory_bytes: 12152
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] v;

	static int solve(int pos, int c) {
		int tmp = v[pos];
		v[pos] = c;
		int up = pos;
		int dp = pos;
		int count = 0;
		while (0 <= up && dp < v.length && v[up] == v[dp]) {
			int color = v[up];
			int num = up == dp ? -1 : 0;
			while (0 <= up && v[up] == color) {
				--up;
				++num;
			}
			while (dp < v.length && v[dp] == color) {
				++dp;
				++num;
			}
			if (num < 4) break;
			count += num;
		}
		v[pos] = tmp;
		return count;
	}

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			v = new int[N];
			for (int i = 0; i < N; ++i) {
				v[i] = sc.next().charAt(0) - '0';
			}
			int ans = 0;
			for (int i = 0; i < N; ++i) {
				int u = i == 0 ? -1 : v[i - 1];
				int d = i == N - 1 ? -1 : v[i + 1];
				if (u != -1 && u != v[i]) {
					ans = Math.max(ans, solve(i, u));
				}
				if (d != -1 && d != v[i] && u != d) {
					ans = Math.max(ans, solve(i, d));
				}
			}
			System.out.println(N - ans);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
struct A{int slv,pe,num;};
bool comp(A a,A b){
      if(a.slv!=b.slv)return a.slv>b.slv;
      if(a.pe!=b.pe)return a.pe<b.pe;
      return a.num>b.num;
}
int main(){
      int m,t,p,r,mm,tt,pp,rr;
      while(cin>>m>>t>>p>>r&&t&&p){
            int pe[t],miss[t][p],slv[t];
            memset(miss,0,sizeof(miss));
            memset(pe,0,sizeof(pe));
            memset(slv,0,sizeof(slv));
            while(r--){
                  cin>>mm>>tt>>pp>>rr;tt--;pp--;
                  if(rr==0){
                        slv[tt]++;
                        pe[tt]+=miss[tt][pp]*20+mm;
                  }else{
                        miss[tt][pp]++;
                  }
            }
            vector<A> V;
            REP(i,t)V.PB((A){slv[i],pe[i],i});
            sort(ALL(V),comp);
            REP(i,t){
                  int s=i;
                  while(V[s].slv==V[i].slv&&V[s].pe==V[i].pe&&i<t)i++;
                  for(int j=s;j<i;j++){
                        cout<<V[j].num+1;
                        if(j!=i-1)cout<<"=";
                  }
                  if(i==t)cout<<endl;
                  else cout<<",";
                  i--;
            }
      }
}

Measured memory_bytes: 1228
n, m = map(int, input().split())
a_list = list(map(int,input().split()))
total = sum(a_list)

limit = total/(4*m)
count = 0
for a in a_list:
    if a >= limit:
        count+=1

if count >= m:
    print('Yes')
else:
    print('No')

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<int> A(n); rep(i,n) cin>>A.at(i);
  vector<int> rev(n);
  rep(i,n) rev.at(A.at(i)-1)=i+1;
  rep(i,n) cout<<rev.at(i)<<' ';  
}


Measured memory_bytes: 1664
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_sum = 0
B_sum = 0
for i in range(N):
    A_sum += A[i]
    A[i] = A_sum
    B_sum += B[i]
    B[i] = B_sum
ans = 0
for i in range(N):
    if i == 0:
        ans = A[i] + B[-1]
    else:
        ans = max(ans, A[i] + B[-1] - B[i - 1])
print(ans)


Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
N = int(input())
D = list(map(int, input().split(' ')))

frqs = [0 for _ in range(24)]
frqs[0] = 1
for d in D:
    if not d:
        print(0)
        exit(0)

    i = min(d, 24 - d)
    frqs[i] += 1



indices = []
for i in range(13):
    if frqs[i] > 2:
        print(0)
        exit(0)

    elif frqs[i] == 2:
        frqs[i] -= 1
        frqs[24-i] += 1

    elif frqs[i] == 1:
        indices.append(i)


def get(frqs):
    ret = float('inf')
    for i in range(24):
        if frqs[i]:
            for j in range(i+1, 24):
                if frqs[j]:
                    d = abs(j - i)
                    ret = min(ret, min(d, 24 - d))
    return ret

buf = [[]]
for _ in indices:
    buf2 = []
    while buf:
        b = buf.pop()
        buf2.append(b + [True])
        buf2.append(b + [False])

    buf = buf2

ans = get(frqs)
for bools in buf:
    for i, b in zip(indices, bools):
        if i and b:
            frqs[i] -= 1
            frqs[24 - i] += 1

        ans = max(ans, get(frqs))

    for i, b in zip(indices, bools):
        if i and b:
            frqs[i] += 1
            frqs[24 - i] -= 1


print(ans)


Measured memory_bytes: 46684
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <tuple>
#define ll long long
using namespace std;

int dp[1111];

int LIS(const vector<int>& V) {
    dp[0]=1;
    
    int ans = 1;
    for(int i=1;i<V.size();i++) {
        dp[i]=1;
        for(int j=0;j<i;j++)
            if (V[j]<V[i])
                dp[i]=max(dp[i],1+dp[j]);
        ans = max(ans, dp[i]);
    }
    return ans;
    
    
    
}

int ceilval(int a,int b) {
    return (a+b-1)/b;
}

vector<int> Solve(int N,int A,int B) {
    
    
    if (A < 0 || B < 0)
        return vector<int>();
    
    if (A > B) {
        vector<int> tmp = Solve(N,B,A);
        std::reverse(tmp.begin(),tmp.end());
        return tmp;
    }
    
    
    
    vector<int> suff;
    for(int i=N;i>=N-B+1;i--) {
        suff.push_back(i);
    }
    
    
    if (B == N) {
        if (A == 1) {
            return suff;
        } else {
           // printf("%d %d %d\n",N,A,B);
            return vector<int>();
        }
    }
    
    // <= B
    
    // (N-B,A-1)
    
    if (A-1 > N-B || A-1 == 0)
        return vector<int>();
    
    
    int ymax = N-B+1-(A-1);
    int ymin = ceilval(N-B,A-1);
    ymin = min(ymin, B);
    
    if (ymin > ymax)
        return vector<int>();
    
    
    vector<int> pref = Solve(N-B,A-1,ymin);
    
    
    if (pref.empty())
        return vector<int>();
    
    
    for(int x : suff)
        pref.push_back(x);
    return pref;
    
}


void SolveBrute(int N,int A,int B) {
    
    vector<int> V(N,-1);
    for(int i=0;i<N;i++)
        V[i]=i;
    
    
    do {
        vector<int> Vr = V;
        std::reverse(Vr.begin(),Vr.end());
        if (LIS(V)==A && LIS(Vr)==B) {
            for(int i=0;i<V.size();i++)
                printf("%d ",V[i]+1);
            cout << endl;
            return;
        }
        
        
    }while(next_permutation(V.begin(),V.end()));
    
}


int main() {
    int N,A,B;
    cin>>N>>A>>B;
    
    //SolveBrute(N,A,B);
    //printf("nxt\n");
    vector<int> ans = Solve(N,A,B);
    if (ans.empty()) {
        cout << -1 << endl;
        return 0;
    }
    for(int x : ans)
        printf("%d ",x);
    cout << endl;
    return 0;
    
}

Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<cstdio> 
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void) {
	string str;
	while(cin >> str) {
		for(string :: iterator it = str.begin(); it != str.end(); it++) {
			if(*it == ',')
				cout << ' ';
			else
				cout << *it;
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int num;
  for (int i = 0; i < 5; i++){
    cin >> num;
    if (num == 0)
      cout << i + 1 << '\n';
  }
  
  return 0;
}


Measured memory_bytes: 3620
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let h: usize = sc.read();
    let w: usize = sc.read();

    let mut edges = vec![];
    for _ in 0..n {
        let r = sc.read::<usize>() - 1;
        let c = sc.read::<usize>() - 1;
        let a: u64 = sc.read();
        edges.push((a, r, c + h));
    }
    edges.sort();

    let mut ans = 0;
    let mut uf = UnionFind::new(h + w);
    for (value, u, v) in edges.into_iter().rev() {
        if uf.find(u) != uf.find(v) {
            let root1 = uf.find(u);
            let root2 = uf.find(v);
            if uf.sizes[root1] + uf.sizes[root2] > uf.edges[root1] + uf.edges[root2] {
                ans += value;
                uf.unite(u, v);
            }
        } else {
            let root = uf.find(u);
            if uf.edges[root] < uf.sizes[root] {
                ans += value;
                uf.edges[root] += 1;
            }
        }
    }

    println!("{}", ans);
}

pub struct UnionFind {
    parent: Vec<usize>,
    sizes: Vec<usize>,
    size: usize,
    edges: Vec<usize>,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).map(|i| i).collect::<Vec<usize>>(),
            sizes: vec![1; n],
            size: n,
            edges: vec![0; n],
        }
    }

    pub fn find(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        } else {
            let px = self.parent[x];
            self.parent[x] = self.find(px);
            self.parent[x]
        }
    }

    pub fn unite(&mut self, x: usize, y: usize) -> bool {
        let parent_x = self.find(x);
        let parent_y = self.find(y);
        if parent_x == parent_y {
            return false;
        }

        let (large, small) = if self.sizes[parent_x] < self.sizes[parent_y] {
            (parent_y, parent_x)
        } else {
            (parent_x, parent_y)
        };

        self.parent[small] = large;
        self.sizes[large] += self.sizes[small];
        self.sizes[small] = 0;

        self.edges[large] += self.edges[small] + 1;
        self.edges[small] = 0;

        self.size -= 1;
        return true;
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
  int n;
  scanf("%d", &n);

  unordered_set<string> s;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    s.insert(str);
  }

  printf("%zu\n", s.size());

  return 0;
}

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

int main() {
    double r;
    cin >> r;
    double pi  = 3.1415926535897932384626;
    cout << fixed << setprecision(10) << r*r*pi;
    cout << ' ';
    cout << fixed << setprecision(10) << 2*r*pi << endl;
    return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
const double inf=1e-10;
int main(){
	int n;
	double res=0;
	cin>>n;
	vector <double > arr(n,0.0);
	vector <vector <double> > dp(n,vector <double > (n+1,0));
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	dp[0][0]=1-arr[0];
	dp[0][1]=arr[0];
	for(int i=1;i<n;i++){
		for(int j=0;j<n+1;j++){
			if(j>0){
				if(j<=i+1)
					dp[i][j]=arr[i]*dp[i-1][j-1]+(1-arr[i])*dp[i-1][j];
			}
			else{
					dp[i][j]=(1-arr[i])*dp[i-1][j];
			}
		}
	}/*
	for(int i=0;i<n;i++){
		for(int j=0;j<n+1;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	for(int i=n/2+1;i<n+1;i++){
		res+=dp[n-1][i];
	}
	printf("%.10lf\n", res);


}

Measured memory_bytes: 70656
I=lambda:list(map(int,input().split()))
mod=10**9+7
n,=I()
l=I()
pre=l.copy()
suf=l.copy()
for i in range(n-2,-1,-1):
	suf[i]+=suf[i+1]
ans=0
#print(suf)
for i in range(n-1):
	ans+=(l[i]*suf[i+1])
	ans%=mod
print(ans)


Measured memory_bytes: 94184
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

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


int main(){
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    
    vector<vector<int>> grid(h, vector<int>(w));
    rep(i, h)rep(j, w) grid[i][j] = 0;
    rep(i, h){
        rep(j, w){
            rep(k, 4){
                if(s[i][j] != '#') continue;
                int x = i + dx[k];
                int y = j + dy[k];

                if(x == -1 or x == h or y == -1 or y == w) continue;
                if(s[x][y] == '#') grid[i][j]++;
            }
        }
    }
    bool flag = true;
    rep(i, h)rep(j, w){
        if(s[i][j] == '#' and grid[i][j] == 0) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = STDIN.gets.to_i
a = STDIN.gets.split(" ").map(&:to_i)
b = STDIN.gets.split(" ").map(&:to_i)
c = STDIN.gets.split(" ").map(&:to_i)

prev = -1
manzoku = 0
a.each do |eat|
  manzoku += b[eat-1]

  manzoku += c[prev-1] if prev + 1 == eat
  prev = eat
end

puts manzoku

Measured memory_bytes: 1788
#include<stdio.h>

int main(void){
	int t,h,m,s;
	scanf("%d",&t);
	h = t/3600;
	t = t-h*3600;
	m = t/60;
	t = t-m*60;
	s = t;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  ll n,x;
  cin>>n>>x;
  vl a(n), b(n);
  ll ans = 0;
  rep(i,n) {
    cin>>a[i];
    b[i] = a[i];
    ans += a[i];
  }
  rep(k, n) {
    ll bsum = 0;
    rep(i, n) {
      b[i] = min(b[i], a[(i-k+n) % n]);
      bsum += b[i];
    }
    ans = min(ans, k * x + bsum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, A, B;
  cin >> N >> A >> B;
  i64 ans = 0;
  ans += (N/(A+B)) * A;
  N %= A+B;
  if(N<=A) ans += N;
  else ans += A;

  cout << ans << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int n, m;
int field[7][7][7];
const int NONE = 0, BLACK = 1, WHITE = 2;
const int NUM_OF_DIRECTION = 13;
const int dx[NUM_OF_DIRECTION] = {1, 1,  1, 0, 0,  0, 1, 1,  1,  1,  1,  1, 0};
const int dy[NUM_OF_DIRECTION] = {0, 0,  0, 1, 1,  1, 1, 1,  1, -1, -1, -1, 0};
const int dz[NUM_OF_DIRECTION] = {0, 1, -1, 0, 1, -1, 0, 1, -1,  0,  1, -1, 1};

inline bool out_range(int x, int y, int z) {
	return x < 0 || y < 0 || z < 0 || x >= n || y >= n || z >= n;
}

void put(int x, int y, int turn) {
	int z = 6;
	while(z && field[z - 1][y][x] == NONE)
		--z;

	field[z][y][x] = turn;
}

bool win(int turn) {
	for(int x = 0; x < n; ++x) {
		for(int y = 0; y < n; ++y) {
			for(int z = 0; z < n; ++z) {
				if(field[z][y][x] == turn) {
					for(int d = 0; d < NUM_OF_DIRECTION; ++d) {
						int cx = x, cy = y, cz = z;
						for(int i = 0; i < m - 1; ++i) {
							cx += dx[d];
							cy += dy[d];
							cz += dz[d];
							if(out_range(cx, cy, cz) || field[cz][cy][cx] != turn)
								goto next;
						}

						return true;
					next:;
					}
				}
			}
		}
	}

	return false;
}

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

	for(int p; cin >> n >> m >> p, n;) {
		vector<int> x(p), y(p);
		for(int i = 0; i < p; ++i)
			cin >> x[i] >> y[i];

		memset(field, NONE, sizeof(field));
		for(int i = 0; i < p; ++i) {
			const int turn = (i & 1) ? WHITE : BLACK;
			put(x[i] - 1, y[i] - 1, turn);
			if(win(turn)) {
				cout << (i & 1 ? "White " : "Black ") << i + 1 << endl;
				goto game_end;
			}
		}

		cout << "Draw" << endl;
	game_end:;
	}

	return EXIT_SUCCESS;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod>
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w) { this->w = w; fix(); }
	void inline fix() { w %= mod; if (w < 0) w += mod; }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	modulo inline operator + (modulo b) { return (*new modulo = *this) += b; }
	modulo& operator += (modulo b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	modulo inline operator - (modulo b) { return (*new modulo = *this) -= b; }
	modulo& operator -= (modulo b) { if ((w -= b.w) < 0) w -= mod; return *this; }
	modulo inline operator * (modulo b) { return (*new modulo = *this) *= b; }
	modulo& operator *= (modulo b) { w = (num) w * b.w % mod; return *this; }
	modulo inline operator / (modulo b) { return (*new modulo = *this) /= b; }
	modulo& operator /= (modulo b) { w = (num) w * b.inv() % mod; return *this; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
typedef modulo<998244353> rem;

const int nsz = int(2e5);
rem n, m, k, fac[nsz + 5], ifc[nsz + 5], ans;
 
void inline init() {
	fac[0] = ifc[0] = 1;
	cont (i, n) {
		fac[i] = fac[i - 1] * rem(i);
		ifc[i] = fac[i].inv();
	}
}
 
rem inline C(int n, int m) { return fac[n] * ifc[m] * ifc[n - m]; }
 
rem inline f(int n, int k) { return C(n - 1, k) * m * (m - rem(1)).pow(n - k - 1); }
 
int main() {
	scanf("%d%d%d", &n, &m, &k);
	if (m == 1) {
		printf("%d\n", k == n - rem(1));
		return 0;
	}
	init();
	circ (i, 0, int(k)) {
		ans += f(n, i);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 42700
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  ll A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;

  ll ans = 0LL;
  if(A+B >= 2*C){
    ll tmp = min(X,Y);
    ans += tmp * 2 * C;
    X -= tmp;
    Y -= tmp;
  }

  if(X>0 && Y>0){
    ans += X*A + Y*B;
    cout << ans << endl;
    return 0;
  }
  else if(X>0 && Y==0){
    if(A>=2*C){
      //Cで払う
      ans += X * 2 * C;
    }else{
      //Aで払う
      ans += X * A;
    }
    cout << ans << endl;
    return 0;
  }
  else if(X==0 && Y>0){
    if(B>=2*C){
      //Cで払う
      ans += Y * 2 * C;
    }else{
      //Bで払う
      ans += Y * B;
    }
    cout << ans << endl;
    return 0;
  }

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

Measured memory_bytes: 256
#include <set>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  int a = getInt();
  int b = getInt();

  vector<int> va(a);
  vector<int> vb(b);

  REP(i,a) va[i] = getInt();
  REP(i,b) vb[i] = getInt();

  int ans = 0;
  REP(i,b){
    int ptr = i;
    REP(j,a) if(ptr != b){
      if(va[j] == vb[ptr]){
        ptr++;
      }
    }
    ans = max(ans, ptr - i);
  }

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

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int p[200001];
ll a[200001];
ll b[200001];
const int C = 40001;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin>>p[i]; p[i]--;
	}
	for(int i = 0; i < n; i++)
	{
		a[i] = (i+1)*C;
		b[i] = (n-i)*C;
	}
	for(int i = 0; i < n; i++)
	{
		a[p[i]] += i;
	}
	for(int i = 0; i < n; i++)
	{
		cout << a[i];
		if(i<n-1) cout<<' ';
	}
	cout<<'\n';
	for(int i = 0; i < n; i++)
	{
		cout << b[i];
		if(i<n-1) cout<<' ';
	}
}


Measured memory_bytes: 1024
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, m, c = map(int, input().split())
    b = list(map(int, input().split()))
    cnt = 0
    for i in range(n):
        a = list(map(int, input().split()))
        ans = sum([a[j]*b[j] for j in range(m)]) + c
        if ans > 0:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

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

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll x;
cin >> x;
if (x == 3 || x == 7 || x == 5)
    cout << "YES" << endl;
else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
using namespace std;

int S[100000], n;

int main() {
	cin >> n;
	for (int i = 0;i < n;i++)
		scanf("%d", &S[i]);

	int q, k, sum = 0;
	cin >> q;
	for (int i = 0;i < q;i++) {
		scanf("%d", &k);
		//lower_bound?????????????????¬?????????????????????*??§?????§??????????????????
		if (*lower_bound(S, S + n, k) == k) sum++;
	}

	cout << sum << endl;

}

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

int main(){
    
    int array[5] = {5, 7, 5, 7, 7};

    while(1){
        int n; cin >> n;
        if(!n) break;
        vector<string> tanka(n);
        for(int i = 0; i < n; i++){
            cin >> tanka[i];
        }
        int ans;
        bool flag = false;
        for(int i = 0; i < n; i++){

            int counter = 0;
            int k = 0;
            for(int j = i; j < n; j++){
                counter += tanka[j].size();
                if(array[k] == counter){
                    counter = 0;
                    k++;
                }else if(array[k] < counter){
                    break;
                }

                if(k == 5){
                    ans = i + 1;
                    flag = true;
                    break;
                } 
            }

            if(flag) break;
        }

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

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int data;
  int sum = 0;
  for(int i = 0;i < 4;i++){
    cin >> data;
    sum += data;
  }
  cout << sum / 60 << endl << sum % 60 << endl;
  return 0;
}

Measured memory_bytes: 3052
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int n,a,i,ans=0;cin>>n;
	for(i=1;i<=n;i++){
		cin>>a;
		if(i%2==1&&a%2==1){ans++;}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#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 MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long a,b,c,d;
    scanf("%ld", &a);
    scanf("%ld", &b);
    scanf("%ld", &c);
    scanf("%ld", &d);
    printf("%ld\n", MIN(a,b)+MIN(c,d));

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] c = new int[n-1];
		int[] s = new int[n-1];
		int[] f = new int[n-1];
		for (int i = 0; i < n-1; i++) {
			c[i] = scan.nextInt();
			s[i] = scan.nextInt();
			f[i] = scan.nextInt();
		}
		int[] ans = new int[n];
		ans[n-1] = 0;
		ans[n-2] = s[n-2] + c[n-2];

		for (int i = 0; i < n-1; i++) {
			ans[i] = c[i] + s[i];
			for (int j = i+1; j < n-1; j++) {
				if (ans[i] > s[j]) {
					int M = ans[i] % f[j];
					if (M != 0) {
						ans[i] += f[j] - M;
						ans[i] += c[j];
					} else {
						ans[i] += c[j];
					}
				} else {
					ans[i] = c[j]+s[j];
				}
			}
		}


		for (int i = 0; i < n; i++) {
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 26556
h,w=map(int,input().split())
h_half=h//2
w_half=w//2
s_hw=h*w
min_x=s_hw

# H*n の範囲を探査
for n in reversed(range(1,w_half+2)):
  a=h*n
  b=h_half*(w-n)
  c=s_hw-(a+b)
  s1=max(a,b,c)-min(a,b,c)
  d=(w-n)//2*h
  e=s_hw-(a+d)
  s2=max(a,d,e)-min(a,d,e)
  min_x=min(min_x,s1,s2)

# n*W の範囲を探査
for n in reversed(range(1,h_half+2)):
  a=w*n
  b=w_half*(h-n)
  c=s_hw-(a+b)
  s1=max(a,b,c)-min(a,b,c)
  d=(h-n)//2*w
  e=s_hw-(a+d)
  s2=max(a,d,e)-min(a,d,e)
  min_x=min(min_x,s1,s2)

print(min_x)

Measured memory_bytes: 9136