akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

template <ll mod>
struct modular {
    ll value;
    modular(ll x = 0) {
        value = x % mod;
        if (value < 0) value += mod;
    }

    modular& operator+=(modular other) {
        if ((value += other.value) >= mod) value -= mod;
        return *this;
    }
    modular& operator-=(modular other) {
        if ((value -= other.value) < 0) value += mod;
        return *this;
    }
    modular& operator*=(modular other) {
        value = value * other.value % mod;
        return *this;
    }
    modular& operator/=(modular other) {
        ll a = 0, b = 1, c = other.value, m = mod;
        while (c != 0) {
            ll t = m / c;
            m -= t * c;
            swap(c, m);
            a -= t * b;
            swap(a, b);
        }
        value = value * a % mod;
        return *this;
    }
    modular& operator^=(modular other) {
        ll r = 1, x = value, n = other.value;
        while (n > 0) {
            if (n & 1) r = r * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        value = r;
        return *this;
    }
    modular operator+(modular rhs) {
        return modular(*this) += rhs;
    }
    modular operator-(modular rhs) {
        return modular(*this) -= rhs;
    }
    modular operator*(modular rhs) {
        return modular(*this) *= rhs;
    }
    modular operator/(modular rhs) {
        return modular(*this) /= rhs;
    }
    modular operator^(modular rhs) {
        return modular(*this) ^= rhs;
    }
    bool operator==(modular rhs) {
        return value == rhs.value;
    };
    bool operator!=(modular rhs) {
        return value != rhs.value;
    };
    bool operator<(modular rhs) {
        return value < rhs.value;
    }
};
template <ll mod>
string to_string(modular<mod> x) {
    return to_string(x.value);
}
template <ll mod>
ostream& operator<<(ostream& stream, modular<mod> x) {
    return stream << x.value;
}
template <ll mod>
istream& operator>>(istream& stream, modular<mod>& x) {
    stream >> x.value;
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream;
}
const ll mod = 1e9 + 7;
using mint = modular<mod>;

vector<mint> fac;
inline void cinit(int n) {
    fac.resize(n, 1);
    for (int i = 2; i < n; i++) {
        fac[i] = fac[i - 1] * i;
    }
}

mint C(int n, int k) {
    if (n < k || k < 0 || n < 0) return 0;
    return fac[n] / fac[k] / fac[n - k];
}

mint f(int r, int c) {
    return C(r + c + 2, c + 1) - 1;
}

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

    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    cinit(2001000);

    mint ans = f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    long long D[N+1][1000*(N+1)+1], w[N], v[N], M=0;
    for (int i = 0; i < N; i++)
    {
        cin >> w[i] >> v[i];
        for (int y = 0; y <= 1000*(N+1); y++)
        {
            D[i][y] = 200000000000000000;
        }
    }
    for (int y = 0; y <= 1000*(N+1); y++)
    {
        D[N][y] = 200000000000000000;
    }
    D[0][0] = 0;
    for (int i = 0; i < N; i++)
    {
        D[i+1][0] = 0;
        for (int y = 0; y <= 1000*N; y++)
        {
            D[i+1][y] = D[i][y];
        }
        for (int y = 0; y <= 1000*N; y++)
        {
            D[i+1][y+v[i]] = min(D[i][y+v[i]],D[i][y]+w[i]);
        }
    }
    for (int i = 0; i <= 1000*N; i++)
    {
        if (D[N][i] <= W)
        {
            M = i;
        }
    }
    cout << M;
    return 0;
}


Measured memory_bytes: 80000
INF = 10 ** 20

def search(rest, now, goal, dp, edges):
  if now == goal:
    return 0
  if rest == ():
    if now == goal:
      return 0
    else:
      return INF

  if (rest, now) in dp:
    return dp[(rest, now)]

  ret = INF
  for i, t in enumerate(rest):
    for dist, to in edges[now]:
      ret = min(ret, search(tuple(v for j, v in enumerate(rest) if i != j), to, goal, dp, edges) + dist / t)
  dp[(rest, now)] = ret
  return ret

while True:
  n, m, p, a, b = map(int, input().split())
  if n == 0:
    break
  a -= 1
  b -= 1
  tlst = list(map(int, input().split()))
  edges = [[] for _ in range(m)]
  for _ in range(p):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    edges[x].append((z, y))
    edges[y].append((z, x))
  tlst.sort()
  rest = tuple(tlst)
  dp = {}
  ans = search(rest, a, b, dp, edges)
  if ans == INF:
    print("Impossible")
  else:
    print(ans)
 


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

using namespace std;

int main(){
    int k;
    cin >> k;
    int n = 7 % k;
    for (int i = 0; i <= k; i++){
        if (n == 0){
            cout << i + 1 << endl;
            return 0;
        }
        n = (n * 10 + 7) % k;
    }

    puts("-1");
}

Measured memory_bytes: 3644
n, y = gets.to_s.split.map{|t|t.to_i}

y /= 1000

0.upto(y/10) do |m|
  0.upto(y/5) do |g|
    s = y - 10 * m - 5 * g
    break if s < 0
    if n == m + g + s
      puts "#{m} #{g} #{s}"
      exit
    end
  end
end

puts "-1 -1 -1"

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int,int> uoii;
typedef unordered_map<string,int> uosi;

const int MOD = 1e9+7;

const int INF = 1e10;




int32_t main()
{
    
    IOS
    int t;
    cin>>t;
    cout<<ceil(1.0*t/2);


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <tr1/unordered_map>

using namespace std;
using namespace tr1;

typedef long long ll;
typedef std::pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}
template<class T>
std::string IntToString(T num){
  std::string res;std::stringstream ss;ss<<num;
  return ss.str();
}
ll StringToInt(std::string &str){
  ll res=0;
  for(int i=0;i<(int)str.size();i++)
    res=(res*10+str[i]-'0');
  return res;
}


int main(){
  int N;
  vector<char> v;
  map<vector<char> ,int> d1;
  map<vector<char> ,int> d2;
  vector<char> sorted;
  cin>>N;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    v.push_back(a);
  }
  sorted=v;
  sort(v.begin(),v.end());
  queue<vector<char> > q1,q2;
  d1[v]=0;
  d2[sorted]=0;
  q1.push(v);
  q2.push(sorted);
  int ans=1<<30;
  while(q1.size()||q2.size()){
    {
      vector<char> now=q1.front();q1.pop();
      int ccost=d1[now];
      if(now==sorted){
  	cout<<ccost<<endl;
  	return 0;
      }
      for(int i=0;i<N;i++){
  	for(int j=i+1;j<N;j++){
  	  vector<char> nv=now;
  	  reverse(nv.begin()+i,nv.begin()+j+1);
  	  if(d2.count(nv)!=0&&d1.count(nv)==0)
  	    ans=min(ans,ccost+1+d2[nv]);
  	  else if(d1.count(nv)==0){
  	    d1[nv]=ccost+1;
  	    q1.push(nv);
  	  }
  	}
      }
    }
    {
      vector<char> now=q2.front();q2.pop();
      int ccost=d2[now];
      if(v==now){
  	cout<<ccost<<endl;
  	return 0;
      }
      for(int i=0;i<N;i++){
  	for(int j=i+1;j<N;j++){
  	  vector<char> nv=now;
  	  reverse(nv.begin()+i,nv.begin()+j+1);
  	  if(d1.count(nv)!=0&&d2.count(nv)==0)
  	    ans=min(ans,ccost+1+d1[nv]);
  	  else if(d2.count(nv)==0){
  	    d2[nv]=ccost+1;
  	    q2.push(nv);
  	  }
  	}
      }
    }
    if(q1.size()&&q2.size()
       &&d1[q1.front()]+d2[q2.front()]+1>=ans)break;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 83764
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
const long long md=1e9+7;
int val[21][21];
long long dp[1<<20];
bool pd[1<<20];
int n,m,k;
int getnext(int p,int x){
	int st=p^(((1<<x)-1)&p);
	if(!st) return p|(1<<x);
	return (p^(st&(-st)))|(1<<x);
}
void solve(int pv){
	bool bo;
	for(int i=0;i<(1<<n);i++){
		bo=1;
		for(int j=0;j<n;j++){
			if(val[pv][j]==-1) continue;
			if(((i>>j)&1)!=val[pv][j]){
				bo=0;
				break;
			}
		}
		pd[i]=bo;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<(1<<n);j++){
			if((j&(1<<i))) continue;
			(dp[getnext(j,i)]+=dp[j])%=md;
		}
	}
	for(int i=0;i<(1<<n);i++)
		if(!pd[i]) dp[i]=0;
}
int main(){
//	freopen("F.in","r",stdin);
	scanf("%d%d%d",&n,&m,&k);
	n--;
	int A,B,C;
	for(int i=0;i<=m;i++)
		for(int j=0;j<=n;j++)
			val[i][j]=-1;
	for(int i=1;i<=k;i++){
		scanf("%d%d%d",&A,&B,&C);
		B--;
		if(val[A][B]!=-1){
			if(val[A][B]!=C){
				printf("0\n");
				return 0;
			}
		}
		val[A][B]=C;
	}
	dp[0]=1;
	long long ans=0;
	for(int i=1;i<=m;i++)
		solve(i);
	for(int i=0;i<(1<<n);i++)
		ans=(ans+dp[i])%md;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5760
H,W,N=map(int,input().split())

allcase=(H-2)*(W-2)

abset=set()
for _ in range(N):
  a,b=map(int,input().split())
  abset.add((a-1,b-1))
#print(abset)

memo={}
def count_black(x,y):
  if (x,y) in memo:
    return memo[(x,y)]
  
  num_black=0
  for ii in range(3):
    for jj in range(3):
      if (x+ii,y+jj) in abset:
        num_black+=1
        
  memo[(x,y)]=num_black
  return num_black

case_list=[0]*10
for a,b in abset:
  for j in range(3):
    if a-j<0 or H-2<=a-j:
      continue    
    for k in range(3):
      if b-k<0 or W-2<=b-k:
        continue
      count_black(a-j,b-k)
#print(memo)  

case_list=[0]*10
for v in memo.values():
  case_list[v]+=1
case_list[0]=allcase-sum(case_list[1:])
#print(case_list)

for i in range(10):
  print(case_list[i])

Measured memory_bytes: 150516
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
int tt;
int head[N],to[N*2],nxt[N*2],sz[N],fa[N],g[N],k[N],v[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline void dfs(int x,int f,int d) {
    sz[x]=g[x]=d,fa[x]=f;
    for(int i=head[x];i;i=nxt[i]) {
	int y=to[i];
	if(y!=f) dfs(y,x,-d),sz[x]+=sz[y];
    }
}
inline int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
int main() {
    int n,m,A,B;
    long long ans=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<=m;i++) {
	int x=gi(),y=gi();
	if(find(x)==find(y)) A=x,B=y;
	else {
	    fa[find(x)]=find(y);
	    to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
	    to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
	}
    }
    dfs(1,0,1);
    if(m==n-1) {
	if(sz[1]) return puts("-1"),0;
    }
    else if(g[A]==g[B]) {
	if(sz[1]&1) return puts("-1"),0;
	int t=sz[1]/2;
	ans+=abs(t);
	for(int i=A;i;i=fa[i]) sz[i]-=t;
	for(int i=B;i;i=fa[i]) sz[i]-=t;
    }
    else {
	if(sz[1]) return puts("-1"),0;
	for(int i=A;i;i=fa[i]) ++k[i];
	for(int i=B;i;i=fa[i]) --k[i];
	int tp=1;
	for(int i=1;i<=n;i++) {
	    if(k[i]==1) v[++tp]=-sz[i];
	    if(k[i]==-1) v[++tp]=sz[i];
	}
	sort(v+1,v+1+tp);
	int t=v[(tp+1)/2];ans+=abs(t);
	for(int i=1;i<=n;i++) sz[i]+=k[i]*t;
    }
    for(int i=1;i<=n;i++) ans+=abs(sz[i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

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

    int cnt = std::count(s.begin(), s.end(), 'o');
    std::cout<<(700 + 100 * cnt)<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f,oo = inf;
#define pi 3.14159265358979323846
#define IL inline
#define RG register
#define rep(i,a,b) for(RG int i=(a);i<int(b);++i)
#define Rep(i,a,b) for(RG int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(RG int i=(a);i>=(b);--i)
#define pc putchar
#define gc getchar
IL ll read(){
    RG ll x=0;char f=0;RG char c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);puts("");}
IL void writeln(ll x,char c,ll y){write(x);pc(c);writeln(y);}
IL void writeln(ll x,char c,ll y,char d,ll z){write(x);pc(c);write(y);pc(d);writeln(z);}
#define debug(x) printf(#x" = %d\n",x);
#define rd() read()
#define rdb() readdb()
#define mem(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define mp make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define y1 ____y1
#define markh __markh
#define union _union
const int maxn = 1e5+233;
ll n,a[maxn],b[maxn],ans,res,l,r;
int main(){
	n = rd();
	Rep(i,1,n) a[i] = rd();
	sort(a+1,a+1+n);
	ll res1=0,res2=0;
	l=1,r=n;
	if(n&1){
		res1=0;
		Rep(i,1,(n+1)/2) res1-=a[i];
		Rep(i,1,(n+1)/2-2) res1-=a[i];
		Rep(i,(n+1)/2+1,n) res1+=a[i]*2;
		reverse(a+1,a+1+n);
		res2=0; 
		Rep(i,1,(n+1)/2) res2-=a[i];
		Rep(i,1,(n+1)/2-2) res2-=a[i];
		Rep(i,(n+1)/2+1,n) res2+=a[i]*2;
	} else{
		res1=res2=0;
		Rep(i,1,n/2) res1-=a[i];
		Rep(i,1,n/2-1) res1-=a[i];
		Rep(i,n/2+1,n) res1+=a[i];
		Rep(i,n/2+2,n) res1+=a[i];
		
		reverse(a+1,a+1+n);
		Rep(i,1,n/2) res2-=a[i];
		Rep(i,1,n/2-1) res2-=a[i];
		Rep(i,n/2+1,n) res2+=a[i];
		Rep(i,n/2+2,n) res2+=a[i];
	}
	writeln(max(res1,-res2));
	return 0;
}

Measured memory_bytes: 1024
mod = 10**9+7

def f(a, b):
    if a == 0 or b == 0:
        return 1
    if a < b:
        a, b = b, a
    x = 1
    y = 1
    for i in range(b):
        x *= (a+b-i)
        y *= b-i
    return (x//y)%mod


S = int(input())

ans = 0
i = 1
while True:
    rem = S - i*3
    if rem < 0:
        break
    ans += f(rem, i-1)
    ans %= mod
    i += 1

print(ans)

Measured memory_bytes: 67724
import scala.io.StdIn._

object Main extends App {

  val n = readInt()
  val L = readLine().split(" ").map(_.toInt)

  def solve() = {
    var ans = 0
    for {
      i <- 0 until n
      j <- i until n
      k <- j until n
    } {
      val list = Seq(L(i), L(j), L(k))
      val max = list.max
      val isTriangle = max < list.sum - max
      val isUnique = list.toSet.size == 3
      if(isTriangle && isUnique) ans += 1
    }
    ans
  }

  println(solve())

}



Measured memory_bytes: 57468
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b) { return a < b ? a : b;}

int main() {
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);
	
	for(i = 1; i <= n; i++) {
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head = 1; tail = n + 1;
	
	while (head != tail) {
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if(u.t > 0) enqueue(u);
		else{
			printf("%s %d\n", u.name, elaps);
		}
	}
	
	return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

long long SmallestWindow(const vector<long long> &v,const long long S){
  long long n = v.size(),l=0,r=0,ans = 1000000000000000007;
  long long sum = 0;
  while(l < n){
    if(sum >= S){
      ans = min(ans,r-l);
      sum -= v[l];
      l++;
    }
    else{
      if(r == n)return ans;
      sum += v[r];
      r++;
    }
  }
  return ans;
}

signed main(){
  ll N,S;
  cin >> N >> S;
  vector<ll> a(N);
  FOR(i,0,N)cin >> a[i];
  cout << (SmallestWindow(a,S) == LINF ? 0 : SmallestWindow(a,S)) << endl;
}


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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pint;
typedef pair<long, long> plong;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

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

int main() {
    int n,m;
    cin>>n>>m;
    int h[n];
    int is_good[n];
    for (int i = 0; i < n; i++) {
        cin>>h[i];
        is_good[i]=1;
    }
    for (int i = 0; i < m; i++) {
        int a,b;
        cin>>a>>b;
        a-=1;b-=1;
        if(h[a]>=h[b]) {
            is_good[b]=0;
        }
        if(h[b]>=h[a]){
            is_good[a]=0;
        }
    }
    int res=0;
    for (int i = 0; i < n; ++i) {
        res+=is_good[i];
    }
    cout<<res<<endl;
}


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

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<string> S(N);
    for(auto &e : S) cin >> e;
    vector<char> ans;

    auto solve = [&]() -> bool {
        for(int i = 0; i < N; ++i) {
            if(S[i] == "AB") {
                if(A == 0) {
                    A++, B--, ans.push_back('A');
                } else if(B == 0) {
                    A--, B++, ans.push_back('B');
                } else if(C == 0) {
                    if(i < N - 1 and S[i + 1] == "BC") {
                        A--, B++, ans.push_back('B');
                    } else if(i < N - 1 and S[i + 1] == "AC") {
                        A++, B--, ans.push_back('A');
                    } else {
                        A++, B--, ans.push_back('A');
                    }
                } else {
                    A++, B--, ans.push_back('A');
                }
            }
            if(S[i] == "BC") {
                if(B == 0) {
                    B++, C--, ans.push_back('B');
                } else if(C == 0) {
                    B--, C++, ans.push_back('C');
                } else if(A == 0) {
                    if(i < N - 1 and S[i + 1] == "AC") {
                        B--, C++, ans.push_back('C');
                    } else if(i < N - 1 and S[i + 1] == "AB") {
                        B++, C--, ans.push_back('B');
                    } else {
                        B++, C--, ans.push_back('B');
                    }
                } else {
                    B++, C--, ans.push_back('B');
                }
            }
            if(S[i] == "AC") {
                if(A == 0) {
                    A++, C--, ans.push_back('A');
                } else if(C == 0) {
                    A--, C++, ans.push_back('C');
                } else if(B == 0) {
                    if(i < N - 1 and S[i + 1] == "BC") {
                        A--, C++, ans.push_back('C');
                    } else if(i < N - 1 and S[i + 1] == "AB") {
                        A++, C--, ans.push_back('A');
                    } else {
                        C++, A--, ans.push_back('C');
                    }
                } else {
                    C++, A--, ans.push_back('C');
                }
            }
            if(A < 0 or B < 0 or C < 0) return false;
        }
        return true;
    };

    if(solve()) {
        cout << "Yes" << '\n';
        for(auto &e : ans) cout << e << '\n';
    } else {
        cout << "No" << '\n';
    }
    return 0;
}


Measured memory_bytes: 6708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr << endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

void solve() {
    ll n;
    cin >> n;
    int cnt = 0;
    auto Div = prime_factor(n);
    for (auto d : Div) {
        int i = 1;
        while(i <= d.se) {
            cnt++;
            d.se -= i;
            i++;
        }
    }
    cout << cnt << endl;
}

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


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

int main(){
  int N,x;
  cin >> N;
  for(int i = 0;i < N;i++){
    string COLOUR;
    cin >> COLOUR;
    if(COLOUR == "P"){
      x = 3;
    }
    else if(COLOUR == "G"){
      x = 3;
    }
    else if(COLOUR == "W"){
      x = 3;
    }
    else{
      x = 4;
      break;
    }
  }
  if(x == 4){
    cout << "Four";
  }
  else{
    cout << "Three";
  }
}
    

Measured memory_bytes: 256
// AtCoder Beginner Contest 127 - Problem D: Integer Cards (https://abc127.contest.atcoder.jp/tasks/abc127_d) 
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

ll solve(vector<ll>& as, vector<ii>& cs)
{
    sort(as.begin(), as.end());
    sort(cs.begin(), cs.end(), greater<ii>());

    int L = 0;

    for (auto c : cs)
    {
        auto x = c.first, m = c.second;
        int pos = lower_bound(as.begin() + L, as.end(), x) - as.begin();

        while (m-- and L < pos)
            as[L++] = x; 
    }

    ll ans = 0;

    for (auto a : as)
        ans += a;

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<ll> as(N);

    for (int i = 0; i < N; ++i)
        cin >> as[i];

    vector<ii> cs(M);

    for (int i = 0; i < M; ++i)
        cin >> cs[i].second >> cs[i].first;

    auto ans = solve(as, cs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2560
l = int(input())
n = 1
ll = l
while ll > 1:
    n += 1
    ll = ll // 2
s = 1
e = []
while l > 1:
    h = l // 2
    e.append((s, s + 1, 0))
    e.append((s, s + 1, h))
    if l > h * 2:
        e.append((s, n, l - 1))
    l = h
    s += 1

print(n, len(e))
for x, y, w in e:
    print(x, y, w)

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

int gcd(int x, int y) {
	if (x < y)gcd(y, x);
	if (y == 0)return x;
	return gcd(y, x % y);
}

int main() {
	int n, a[100000];
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int ans = a[0];
	for (int i = 0; i < n - 1; ++i) {
		ans = gcd(ans, a[i + 1]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  vector<char> front = {};
  vector<char> back(S.begin(),S.end());
  int Q;
  cin >> Q;
  bool rev = false;
  for(int i = 0; i < Q; i++){
    int T;
    cin >> T;
    if(T == 1){
      rev = !rev;
    }else{
      int F;
      char C;
      cin >> F;
      cin >> C;
      if(F == 1){
        if(rev){
          back.push_back(C);
        }else{
          front.push_back(C);
        }
      }else{
        if(rev){
          front.push_back(C);
        }else{
          back.push_back(C);
        }
      }
    }
  }
  if(rev){
    reverse(back.begin(),back.end());
    string back_(back.begin(),back.end());
    string front_(front.begin(),front.end());
    cout << back_+front_ << endl;
  }else{
    reverse(front.begin(),front.end());
    string front_(front.begin(),front.end());
    string back_(back.begin(),back.end());
    cout << front_+back_ << endl;
  }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  cin >> n ;
  vector<int> poi(n) ;
  int suma = 0 ;
  int sumb = 0 ;
  int ans ;
  REP(i,n){
    cin >> poi.at(i) ;
  }
  
  sort(ALL(poi)) ;
  reverse(ALL(poi)) ;
  
  for(int i=0; i<n;i+=2){
    suma += poi.at(i) ;
  }
  for(int i =1; i<n; i+=2){
    sumb += poi.at(i) ;
  }
  ans = suma-sumb ;
  
  cout << ans <<endl ;

  return 0 ;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <stack>

#define INF 0x3fffffff

using namespace std;

int main(){
	int n;
	while(cin>>n, n){
		int to[900], ds[900], to_num[900]={0}, ds_sum=0, ans=0;
		int w[900][900];
		set<int> sg;
		vector<int> tosg[900], dssg[900];
		fill( w[0], w[0]+900*900, INF );
		for(int i=1; i<n; i++){
			cin >> to[i];
			to[i]--;
			to_num[ to[i] ]++;
			to_num[ i ]++;
		}
		for(int i=1; i<n; i++){
			cin >> ds[i];
			ds_sum += ds[i];
			if( to[i] == 0 ){
				to[0] = i;
				ds[0] = ds[i];
			}
		}

		// ????????¨???????±???????
		int ds_ha = 0;
		for(int i=0; i<n; i++){
			if( to_num[i] == 1 ){
				ds_ha += ds[i]; 
				sg.insert( to[i] );
			}
		}

		// ??¨?????´???
		for(int i=1; i<n; i++){
			int j = to[i], sum = ds[i];
			if( sg.count(i) )
				while(1){
					w[i][j] = min( w[i][j], sum);
					w[j][i] = min( w[j][i], sum);
					for(int k=0; k<tosg[j].size(); k++){
						w[i][ tosg[j][k] ] = min(w[i][ tosg[j][k] ], sum + dssg[j][k]);
						w[ tosg[j][k] ][i] = min(w[i][ tosg[j][k] ], sum + dssg[j][k]);
					}
					tosg[j].push_back( i );
					dssg[j].push_back( sum );
					if( j == 0 ) break;
					else {
						sum += ds[j];
						j = to[j];
					}
				}
		}
		int maxlen=0;
		for(int i=0; i<n; i++){
			for(int j=0; j<i; j++){
				if( sg.count(i) && sg.count(j) && w[i][j] < INF ){
					maxlen = max( maxlen, w[i][j] );
				}
			}
		}

		// ??????
		ans = (3 * ds_sum) - (2 * ds_ha) - maxlen;
		//	cout << ds_sum << " " << ds_ha << " " << maxlen << endl;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4640
#include <iostream>
#include <cstring>

using namespace std;

const int N = 100, W = 10000;
int values[N], weights[N];
int dp[N + 1][W + 1];

int main(){
	int n,w;
	memset(dp, 0, sizeof(dp));
	cin >> n >> w;
	for(int i = 0;i < n;++i){
		cin >> values[i] >> weights[i];
	}
	for(int i = n;0 <= i;--i){
		for(int j = 0;j <= w;++j){
			if(i == N) dp[i][j] = 0;
			else if(j < weights[i]) dp[i][j] = dp[i + 1][j];
			else dp[i][j] = max(dp[i + 1][j], max(dp[i][j - weights[i]] + values[i], dp[i][j - weights[i]] + values[i]));
		}
	}
	cout << dp[0][w] << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int cnt[10];

int main()
{
  rep(i, 4){
    int n;
    cin >> n;
    cnt[n]++;
  }

  if(cnt[1] and cnt[9] and cnt[7] and cnt[4]) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
gets
r = gets.split.map(&:to_i)
min = 0
pos = 0
r.each do |x|
  min += x**2
end

for i in (r.min..r.max)
  c = 0
  r.each do |x|
    c += (x-i) ** 2
  end
  if c < min
    min = c
    pos = i
  end
end
puts min


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

using namespace std;

int main() 
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    int MIN = min(a, min(b, c));
    int MAX = max(a, max(b, c));
    
    printf("%d %d\n", MIN, MAX);
    
    return 0;
}


Measured memory_bytes: 3228
N=int(input())
A=[int(input()) for i in range(N)]
from bisect import bisect_left
from collections import deque
l=deque()
for a in A:
    i=bisect_left(l,a)
    if i==0:
        l.appendleft(a)
    else:
        l[i-1]=a
print(len(l))

Measured memory_bytes: 8092
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){

	int L,N,i;
	cin >> L >> N;
	int m=0;
	REP(i,N){
		int x,w;
		cin >> x >> w;
		m+=x*w;
	}

	if(m==0){
		cout << 0 << endl;
		return 0;
	}

	if(m>0){
		for(i=-1;i>=-L;i--){
			if(m%i==0){
				cout << 1 << endl;
				cout << i << ' ' << m/(-i) << endl;
				return 0;
			}
		}
	}

	if(m<0){
		for(i=1;i<=L;i++){
			if(m%i==0){
				cout << 1 << endl;
				cout << i << ' ' << (-m)/i << endl;
				return 0;
			}
		}
	}

	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int N=1000000;
double dp[N],dp2[N];

int main()
{
    int n,m,k;
    while(cin >>n >>m >>k,n|m|k)
    {
        memset(dp,0,sizeof(dp));
        dp[0]=1;

        rep(i,n)
        {
            memset(dp2,0,sizeof(dp2));

            for(int j=i; j<=m*i; ++j)
            {
                for(int k=1; k<=m; ++k)
                {
                    if(j+k>=N) break;
                    dp2[j+k]+=dp[j]/m;
                }
            }

            rep(j,N) dp[j]=dp2[j];
        }

        double ans=0;
        rep(i,N) ans+=max(1,i-k)*dp[i];

        printf("%.10lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 18804
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
typedef long long ll;
using namespace std;
const int maxn=201100;
const int mod=1000000000+7;
int h,w,a,b;
ll inv[maxn],F[maxn],Finv[maxn];

void init(){
    inv[1]=1;
    for(int i=2;i<maxn;i++){
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    }
    F[0]=1;
    Finv[0]=1;
    for(int i=1;i<maxn;i++){
        F[i]=F[i-1]*i%mod;
        Finv[i]=Finv[i-1]*inv[i]%mod;
    }
}

ll C(ll n,ll m){
    if(n<0||m<0||m>n) return 0;
    return F[n]*Finv[m]%mod*Finv[n-m]%mod;
}


int main(){
    init();
    scanf("%d%d%d%d",&h,&w,&a,&b);//2 3 1 1
    ll ans=0;
    for(int i=1;i<=h-a;i++){
        //cout<<b+i-2<<"  "<<i-1<<endl;
        //cout<<h+w-b-i-2<<" "<<w-b-1<<endl;
        ans=(ans+C(b+i-2,i-1)*C(h+w-b-i-1,w-b-1)%mod)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4992
import math


def main():
    N = int(input())
    ans = N - 1
    rt = int(math.sqrt(N))
    for x in range(2, rt+1):
        if N % x == 0:
            y = N // x
            ans = min(ans, (x + y - 2))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39024
#include <stdio.h>

int main(void) {
  int n;
  long long int x,ans=0;
  scanf("%d %lld",&n,&x);
  long long int a[n];
  for (int i = 0; i < n; i++) scanf("%lld",&a[i]);
  
  for (int i = 0; i < n-1; i++) {
    if (a[i]+a[i+1] > x) {
      long long int tmp = a[i]+a[i+1]-x;
      if (a[i+1] > tmp) {
        a[i+1] -= tmp;
      }
      else {
        a[i+1] = 0;
        a[i] -= a[i] - x;
      }
      ans += tmp;
    }
  }
  printf("%lld\n",ans);
  
  return 0;
}

Measured memory_bytes: 896
L,R = map(int,input().split())

if(R-L>=2018):
    print(0)
else:
    ans = 2018
    for i in range(L,R):
        for j in range(i+1,R+1):
            tmp = i*j%2019
            if(tmp < ans):
                ans = tmp
    
    print(ans)

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

using namespace std;

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

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

	double ave = 0;
	int Ave = 0;
	for (int i = 0; i < N; i++) {
		ave += A.at(i);
	}
	ave = ave / N;
  if (ave > 0)
    ave += 0.5;
  else ave += -0.5;
	Ave = ave;

	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += (A.at(i) - Ave) * (A.at(i) - Ave);
	}
	cout << sum;

	return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 1000000007
#define M 2200000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}

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

	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int x=(a+d-1)/d,y=(b+c-1)/b;
	if(x<y)no;
	else yes;
}


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

#define mp make_pair

using namespace std;

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

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

const int MAX_N = 50;
int n,m;
bool g[MAX_N][MAX_N] = {};
vector<pii> edges;
bool found[MAX_N];

void dfs(int v, int p)
{
  if (found[v]) return;
  found[v] = true;

  for (int c = 0; c < n; c++) {
    if (!g[v][c] || p == c || v == c) continue;
    dfs(c,v);
  }
}

int main()
{
  cin >> n >> m;
  int a,b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    edges.push_back(mp(a-1,b-1));
    g[a-1][b-1] = g[b-1][a-1] = true;
  }

  int res = 0;
  for (pii p : edges) {
    fill_n(found,n,false);
    g[p.first][p.second] = g[p.second][p.first] = false;
    dfs(0,-1);
    if (!all(found,found+n)) res++;
    g[p.first][p.second] = g[p.second][p.first] = true;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans=0;
        int l[]=new int[N];
        for(int i=0;N>i;i++){
            l[i]=sc.nextInt();
        }
        Arrays.sort(l);
        for(int j=0;K>j;j++){
            ans+=l[N-1-j];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
if 1 in A:
    if 4 in A: A.remove(4)
    if 6 in A: A.remove(6)
    if 9 in A: A.remove(9)
if 3 in A:
    if 2 in A: A.remove(2)
if 5 in A:
    if 3 in A: A.remove(3)
    if 2 in A: A.remove(2)
if 7 in A:
    if 6 in A: A.remove(6)
    if 9 in A: A.remove(9)
if 9 in A:
    if 6 in A: A.remove(6)

def MatchNum(i):
    if i == 1: return 2
    elif i == 4: return 4
    elif i in [2, 3, 5]: return 5
    elif i == 7: return 3
    elif i == 8: return 7
    elif i in [6, 9]: return 6

MatchUse = []
for a in A:
    MatchUse.append((a, MatchNum(a)))

DP = [-1] * (N+1)
for a, num in MatchUse:
    if num <= N: DP[num] = a

for i in range(2, N):
    if DP[i] > 0:
        temp = DP[i]*10
        for a, num in MatchUse:
            if i + num <= N:
                DP[i + num] = max(DP[i + num], a + temp)
print(DP[N])

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

int n, m;
int t[5002], s[5002];

int main(){
  while(cin >> n >> m){
    for(int i = 0; i < n; i++){
      cin >> t[i];
    }
    for(int i = 0; i < m; i++){
      cin >> s[i];
    }

    int ans = 0;

    for(int i = 0; i < m; i++){
      int j, k = 0;

      for(j = i; j < m; j++){
        while(k < n && t[k] != s[j]) k++;
        if(k == n) break;
        k++;
      }

      ans = max(ans, j - i);
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int> t(n);
  int ans = 0;
  for(int i = 0; i < n; i++) {
    cin >> t[i];
    ans += t[i];
  }
  int m;
  cin >> m;
  vector<int> p(m), x(m);
  for(int i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }
  for(int i = 0; i < m; i++){
    cout << ans - t[p[i] - 1] + x[i] << '\n';
  }

  return 0;
}

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

using namespace std;

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

// chmax, chmin
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;
}


int dp[1000010];
int vis[1000010];

vector<int> es[1000010];

int dfs(int x) {
    if( vis[x]){
        cout << -1 << endl;
        exit(0);
    }
    if (x == 1000000) return 0;
    if (dp[x] != -1) return dp[x];

    vis[x] = true;


    int ans = -1e9;
    for (auto i : es[x]) {
        ans = max(ans, dfs(i) + 1);
    }
    vis[x] = false;
    return dp[x] = ans;
}

void solve(long long N, std::vector<std::deque<long long>> A) {
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 1; j++) {
            A[i][j]--;
            int I = A[i][j];
            int J = i;
            if (I > J) swap(I, J);
            A[i][j] = I * 1000 + J;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 2; j++) {
            es[A[i][j]].push_back(A[i][j + 1]);
        }
        es[A[i].back()].push_back(1000000);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, dfs(A[i][0]));
    }


    cout << ans << endl;

}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<std::deque<long long>> A(N, std::deque<long long>(N - 1));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 1; j++) {
            scanf("%lld", &A[i][j]);
        }
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 55680
import sys
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def SI(): return input()


def main():
    P, Q, R = LI()
    ans = min(min(P+Q, Q+R), P+R)
    print(ans)


main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <queue>
#define llint long long int

using namespace std;

llint N, M;
vector<int> G[100005];
int color[100005];

bool bfs()
{
	queue<int> Q;
	Q.push(1);
	color[1] = 1;
	
	int u, v;
	while(Q.size()){
		u = Q.front();
		Q.pop();
		for(int i = 0; i < (int)G[u].size(); i++){
			v = G[u][i];
			if(color[v] == color[u]) return false;
			if(color[v] == -color[u]) continue;
			Q.push(v);
			color[v] = -color[u];
		}
	}
	
	return true;
}

int main(void)
{
	cin >> N >> M;
	
	int a, b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	bool nibu = bfs();
	
	llint ans;
	if(nibu){
		llint bcnt = 0, wcnt = 0;
		for(int i = 1; i <= N; i++){
			if(color[i] == 1) bcnt++;
			else wcnt++;
		}
		ans = bcnt * wcnt - M;
	}
	else{
		ans = N * (N-1) / 2 - M;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6272
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int[] a = new int[100005];
    	for(int i=0;i<N;i++) {
    		a[sc.nextInt()]++;
    	}
    	long ans=0;
    	int ecnt=0;
    	for(int i=0;i<100005;i++) {
    		if(a[i]==0)continue;
    		ans=ans+a[i]-1;
    		ecnt=ecnt+((a[i]+1)%2);
    	}
    	ans=ans+(ecnt%2);
    	
        System.out.println(N-ans);
        
        		
    }
}

Measured memory_bytes: 50644
import numpy as np

n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n):
	a.append(a[i]*2+3)
	p.append(p[i]*2+1)

def f(N,X):
	if N==0:
		return 0 if X<=0 else 1
	elif X <=1+a[N-1]:
		return f(N-1,X-1)
	else:
		return p[N-1]+1+f(N-1,X-2-a[N-1])
	
print (f(n,x))


def inputList():
	a=list(map(int,input().split()))
	return a

def multisort(li,index):
	return sorted(li,key=lambda x: x[index])


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    fastIO;
    int N;
    cin >> N;
    map<string, int> m;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        m[s]++;
    }  
    vector<string> verdicts({"AC", "WA", "TLE", "RE"});
    for (string s : verdicts) {
        cout << s << " x " << m[s] << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,sum=0;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
         cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++) sum+=a[i];
    cout << sum << endl;
}


Measured memory_bytes: 3628
h,w = map(int,input().split())
L = []
dp = []
for i in range(h):
    d = [0]*w
    dp.append(d)
M = []
for i in range(h):
    s = input()
    M.append(s)
if M[0][0] == '#':
    dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            None
        elif i == 0:
            if M[i][j-1] == '.' and M[i][j] == '#':
                dp[i][j] = dp[i][j-1]+1
            else:
                dp[i][j] = dp[i][j-1]
        elif j == 0:
            if M[i-1][j] == '.' and M[i][j] == '#':
                dp[i][j] = dp[i-1][j]+1
            else:
                dp[i][j] = dp[i-1][j]
        else:
            k = 0
            l = 0
            if M[i-1][j] == '.' and M[i][j] == '#':
                k = 1
            if M[i][j-1] == '.' and M[i][j] == '#':
                l = 1
            dp[i][j] = min(dp[i-1][j]+k, dp[i][j-1]+l)
print(dp[h-1][w-1])


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		char[][] c = new char[h][w];
		
		int count = 0;
		for(int i = 0; i < h; i++) {
			String s = sc.next();
			for(int j = 0; j < w; j++) {
				c[i][j] = s.charAt(j);
				if(c[i][j] == '#') count++;
			}
		}
		
		int ans = 0;
		
		// bit全探索 縦
		for(int i = 0; i < 1 << h; i++) {
			
			//　bit全探索 横
			for(int j = 0; j < 1 << w; j++) {
				
				int count_temp = 0;
				
				// 縦　h回
				for(int ii = 0; ii < h; ii++) {
					
					// 横　w回
					for(int jj = 0; jj < w; jj++) {
						
						if((i >> ii & 1) == 1) {
							// 赤く塗りつぶすと考える
							continue;
						}
						
						if((j >> jj & 1) == 1) {
							// 赤く塗りつぶすと考える
							continue;
						}
					
						// 塗り潰されなかった全マスのii jj の1つ1つのマスが＃ならインクリメント
						if(c[ii][jj] == '#')count_temp++;	
						
					}
					
				}
				
				// 2^h*w パターンの各々の回で求める#の数ならインクリメント
				if(count_temp == k) ans++;
				
			}
			
		}
		
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 35920
def solve(N,K):
    if K == 0:
        return N**2
    else:
        ans = 0
        for b in range(K+1,N+1):
            #b <= a <= Nで a mod b >= Kを満たすaの個数
            q,r = N//b,N%b
            ans += (q*(b-K) + max(0,r-K+1))
        return ans

def main():
    N,K = map(int,input().split())

    print(solve(N,K))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
long n, tn[100001], sumt=0, m, pm, xm ,result[100001];
cin>>n; for (int i=0 ; i<n; i++){cin >>tn[i];sumt+=tn[i];}
cin >>m;
for (int i=0 ; i<m; i++){
cin>>pm >>xm;
result [i]= sumt -tn[pm-1]+xm;
}
for (int i=0 ; i<m; i++)cout <<result[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int bits[] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x27, 0x7F, 0x6F };
	int n;
	int i, j;

	while (scanf("%d", &n), ~n){
		int state = 0x00;
		for (i = 0; i < n; i++){
			int display, xor;
			scanf("%d", &display);

			xor = bits[display] ^ state;
			for (j = 6; j >= 0; j--){
				putchar("01"[(xor >> j) & 1]);
			}
			puts("");
			state ^= xor;
		}
	}
	return (0);
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S.at(1)==S.at(2)&&S.at(1)==S.at(0)&&S.at(2)==S.at(0)){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256