akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string s,t;

int main() {
    cin >> s >> t;
    ll ls = s.size();
    ll lt = t.size();
    vector<vector<int>> lcs(ls+1,vector<int>(lt+1,0));
    REP(i,ls+1){
        REP(j,lt+1){
            if(i==0||j==0){
                lcs[i][j]=0;
            }else{
                if(s[i-1]==t[j-1]){
                    lcs[i][j]=lcs[i-1][j-1]+1;
                }else{
                    lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
                }
            }
        }
    }
    //put(lcs[ls][lt]);lcs長
    deque<char> res;
    ll ms=ls;
    ll mt=lt;
    while(lcs[ms][mt]!=0){
        if(s[ms-1]==t[mt-1]){
            res.push_front(s[ms-1]);
            ms--;mt--;
        }else if(lcs[ms-1][mt]>=lcs[ms][mt-1]){
            ms--;
        }else{
            mt--;
        }
    }
    while(!res.empty()){
        cout << res.front();
        res.pop_front();
    }
    put("");
    return 0;
}




Measured memory_bytes: 35584
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll combination(ll n,ll r){
    ll sum=1;
    rrep(i,min(r,n-r)) (sum*=(n-i+1))%=mod;
    return sum;
}

//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    ll n=0,S=0,w=0,e=0;
    rep(i,s.size()){
        if(s[i]=='N') n++;
        else if(s[i]=='E') e++;
        else if(s[i]=='S') S++;
        else w++;
    }
    if(n>=1 && e==0 && S>=1 && w==0) cout<<"Yes"<<endl;
    else if(n==0 && e>=1 && S==0 && w>=1) cout<<"Yes"<<endl;
    else if(n>=1 && e>=1 && S>=1 && w>=1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

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

  long long L, R;
  cin >> L >> R;

  if (R - L > 2019) {
    cout << 0 << endl;
  } else {
    int min = 999999;
    for (long long i = L; i < R; i++) {
      for (long long j = i + 1; j <= R; j++) {
        if ((i % 2019 * j % 2019) % 2019 < min) {
          min = i % 2019 * (j % 2019) % 2019;
        }
      }
    }
    cout << min << endl;
  }
}

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

int main(void){
  string s, t;
  cin >> s >> t;

  bool ok = false;
  for(int i = s.size() - t.size(); i >= 0; i--){
    string tmp = s.substr(i, t.size());
    bool jud = true;
    rep(j, t.size()){
      if(tmp[j] != t[j] && tmp[j] != '?') jud = false;
    }
    if(jud){
      ok = true;
      rep(j, t.size()){
        if(s[i + j] == '?') s[i + j] = t[j];
      }
    }
    if(ok) break;
  }
  if(!ok) cout << "UNRESTORABLE" << endl;
  else rep(i, s.size()) cout << (s[i] == '?' ? 'a' : s[i]);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
 
int main() 
{
     int n;
    double x1,y1,x2,y2,x3,y3,x4,y4,m1,m2;
     cin>>n;
     for(int i=0;i<n;i++)
   {
        int p=0;
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        if(x1==x2&&x3==x4){p=1;}
        else if(x1==x2||x3==x4){}
        else if((y2-y1)/(x2-x1)==(y4-y3)/(x4-x3)){p=1;}
        if(p==1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
     
    return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>

int main(){

  int S[1000000];
  int T[1000000];
  int Scount;
  int Tcount;
  int count;
  int i,j;

  scanf("%d",&Scount);

  for(count = 0;count < Scount;count++){
    scanf("%d",&S[count]);
  }

  scanf("%d",&Tcount);

  for(count = 0;count < Tcount;count++){
    scanf("%d",&T[count]);
  }
  count = 0;

  for(i = 0;i < Tcount;i++){
    for(j = 0;j < Scount;j++){
      if(S[j] == T[i]){
	count++;
	break;
}
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int D, N;
  cin >> D >> N;

  int ans;
  if (N == 100) {
    if (D == 0) ans = 101;
    else if (D == 1) ans = 10100;
    else ans = 10000 * 101;
  } else {
    if (D == 0) ans = N;
    else if (D == 1) ans = 100 * N;
    else ans = 10000 * N;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

const int N = 3e5 + 7;

int main() {
	int a, b, c; cin >> a >> b >> c;
	if(a+b >= c-1){
		cout << b + c;
		return 0;
	}else{
		cout << a + b + b + 1;
	}
	return 0;
}


Measured memory_bytes: 256
def d():
    import collections

    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    N = int(input())
    c = collections.Counter(prime_factorize(N))
    ans = 0
    for i in c.values():
        j = 1
        while j <= i:
            i -= j
            ans += 1
            j += 1

    print(ans)


##########
if __name__ == "__main__":
    d()


Measured memory_bytes: 9468
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];

  priority_queue<ll> pq;
  sort(p.begin(),p.end(), greater<ll>());
  sort(q.begin(),q.end(), greater<ll>());
  sort(r.begin(),r.end(), greater<ll>());
  rep(i, x) pq.push(p[i]);
  rep(i, y) pq.push(q[i]);
  rep(i, min(x + y, c)) pq.push(r[i]);
  ll ans = 0;
  rep(i, x + y) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 8816
#include<stdio.h>
#include<math.h>

int main(void){

  long long int L,R,i,j,k;
  scanf("%lld",&L);
  scanf("%lld",&R);
  long long int tmp,min=2019;

  for(i=L;i<R;i++){
    for(j=i+1;j<R+1;j++)
    if(i<j){
     tmp = (i*j) % 2019;
     if(min > tmp){
       min = tmp;
     }
     if(tmp == 0)
       break;
    }
    if(tmp == 0)
      break;
  }

  printf("%lld",min);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int n;

int main(){

cin>>s;
n=s.length();

int ans=1<<30;
for(char c='a';c<='z';c++){
int mx=-1;
    for(int i=0;i<n;i++){
        bool f=1;
        for(int j=i;j<n;j++)
        if( s[j]==c ){
            f=0;
            mx=max( mx,j-i );
            break;
        }
        if( f )
            mx=max(mx,n-i);
        }
ans=min(ans,mx);
}
ans=min( ans , n-ans );
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env/ python3
import math
#S = input()
#R = int(input())
#A, B, C = input().split()
A,B,C,D = map(int, input().split())

#N = int(input())
#A = [int(x) for x in input().split()]

#H, W = map(int, input().split())
#S = [input() for _ in range(H)]

if math.ceil(C/B) <= math.ceil(A/D): print("Yes")
else: print("No")


Measured memory_bytes: 9156
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	string s;
	int n,q,t,u;
	std::vector <int> a(0);
	cin >> n >> q>>s;
	a.push_back(0);
	for (int i = 1; i < n; ++i) {
		a.push_back((s.substr(i-1,2)=="AC")? a[i-1]+1:a[i-1]);
	}
	for (int i = 0; i < q; ++i) {
		cin >> t >> u;
		cout << a[u - 1] - a[t - 1] << "\n";
	}
	return 0;
}

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

X=[]
for i in range(N):
    if A[i]%2==0:
        X.append(A[i])

Y=0
for i in range(len(X)):
    if X[i]%3!=0 and X[i]%5!=0:
        Y+=1

if Y==0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
int main() 
{
     fast;
     int n;
     cin>>n;
     vi h(n);
     ffor(i,0,n)
     cin>>h[i];
     vi dp(n+1);
     dp[0]=0;
     dp[1]=abs(h[1]-h[0]);
     ffor(i,2,n)
     {
         dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
     } 
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, n-1):
    if p[i-1] < p[i] and p[i+1] > p[i]:
        count += 1
        continue
    if p[i - 1] > p[i] and p[i + 1] < p[i]:
        count += 1
print(count)

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

constexpr ll mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class combination{
private:
    vector<mint> fact,inv,finv;
public:
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    vvec<mint> dp(C+1,vec<mint>(D+1));
    dp[A][B] = 1;
    for(int i=0;i<=C;i++) for(int j=0;j<=D;j++){
        if(i<C) dp[i+1][j] += dp[i][j]*j;
        if(j<D) dp[i][j+1] += dp[i][j]*i;
        if(i<C && j<D) dp[i+1][j+1] -= dp[i][j]*i*j;
    }
    cout << dp[C][D] << "\n";
}

Measured memory_bytes: 73652
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.zeros(N+2, np.int32)
A[1:-1] = np.array([ir() for _ in range(N)])

left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print('\n'.join(answer.astype(str)))


Measured memory_bytes: 50852
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>

using namespace std; using ll=long long; const int INF=1e2; using P=pair<int,int>;

int main() {
  ll x; cin>>x;
  ll an;
  for(an=1;an*(an+1)/2<x;an++);
  cout<<an<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

struct Coin{
  int num10;
  int num50;
  int num100;
  int num500;
};

struct Coin ChangeCoinNum(int sum){
  int num500yen = (sum >= 500 ? sum/500 : 0);
  sum %= 500;

  int num100yen = (sum >= 100 ? sum/100 : 0);
  sum %= 100;

  int num50yen = (sum >= 50 ? sum/50 : 0);
  sum %= 50;

  int num10yen = (sum >= 10 ? sum/10 : 0);
  sum %= 10;

  Coin res = {num10yen,num50yen,num100yen,num500yen};
  return res;
}

int main(){
  int price;
  int num10yen,num50yen,num100yen,num500yen;
  bool is_1st = true;
  while(~scanf("%d",&price)){
    if(price == 0) break;
    scanf("%d %d %d %d",&num10yen,&num50yen,&num100yen,&num500yen);

    struct Coin res;
    
    int min_c = numeric_limits<int>::max();
    for(int i=0;i<=num10yen;i++){
      for(int j=0;j<=num50yen;j++){
	for(int k=0;k<=num100yen;k++){
	  for(int l=0;l<=num500yen;l++){
	    int sum = 10*i + 50*j + 100*k + 500*l;
	    if(sum - price < 0) continue;

	    struct Coin each_coin_num = ChangeCoinNum(sum - price);
	    if(i && each_coin_num.num10) continue;
	    if(j && each_coin_num.num50) continue;
	    if(k && each_coin_num.num100) continue;
	    if(l && each_coin_num.num500) continue;

	    int total_coin_num = 
	      +num10yen -i + each_coin_num.num10
	      +num50yen -j + each_coin_num.num50
	      +num100yen -k + each_coin_num.num100
	      +num500yen -l + each_coin_num.num500;

	    if(min_c > total_coin_num){
	      min_c = total_coin_num;
	      struct Coin tmp 
		= {i,j,k,l};
	      res = tmp;
	    }
	  }
	}
      }
    }
    if(!is_1st){
      printf("\n");
    }
    if(res.num10 > 0) printf("10 %d\n",res.num10);
    if(res.num50 > 0) printf("50 %d\n",res.num50);
    if(res.num100 > 0) printf("100 %d\n",res.num100);
    if(res.num500 > 0) printf("500 %d\n",res.num500);
    is_1st = false;
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;

int main() {
  
    string n;
    string m;
  
    cin >> n >> m;
  
    string j = n+m;
  
    int num = atoi(j.c_str());

    int kaijyo = pow(num, 0.5);
  
   if(kaijyo*kaijyo==num){
     cout << "Yes" << endl;
   }else{
      cout << "No" << endl;
   }
      
  
   // cout << pow(num, 0.5) << endl;
  
  
  return 0;
}

Measured memory_bytes: 512
hw = STDIN.gets
h = hw.chomp
N = h.to_i
r = 0
f = Array.new(N, Array.new(10, 0))
fs = Array.new(N, Array.new(10, 0))
p = Array.new(N, Array.new(11, 0))
ps = Array.new(N, Array.new(11, 0))
e = Array.new(10, 0)
for i in 0..(N - 1)
  	s = ""
	s = STDIN.gets
	s.chomp!
	fs[i] = s.split(" ")
  	f[i] = fs[i].map{|a|a.to_i}
end


for i in 0..(N - 2)
	s = STDIN.gets
	s = s.chomp
	ps[i] = s.split(" ")
    p[i] = ps[i].map{|a|a.to_i}
end

s = STDIN.gets
ps[N - 1] = s.split(" ")
p[N - 1] = ps[N - 1].map{|a|a.to_i}

v = 0
c = -10000000000000

for i in 1..1023
	r = 0
	s = i.to_s(2)
	while(s.length < 10)
		s = "0" + s
	end
	#puts s
	for j in 0..9
		e[j] = s[j].to_i
	end

	for k in 0..(N - 1)
		v = 0
		for j in 0..9
			if e[j] + f[k][j] == 2
				v = v + 1
			end
		end
		r += p[k][v]
	end
	#puts r
	if c < r
		c = r
	end
end

a = c.to_s
puts a

Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

const LLI mod = 1e9+7;

bool check(const string &s){
  if(s.find("AGC") != string::npos or s.find("GAC") != string::npos or s.find("ACG") != string::npos){
    return false;
  }

  if(s.size() == 4){
    if(s[0] == 'A' and s[2] == 'G' and s[3] == 'C') return false;
    if(s[0] == 'A' and s[1] == 'G' and s[3] == 'C') return false;
  }
  
  return true;
}

const string agct = "AGCT";

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

  LLI N;
  while(cin >> N){

    vector<map<string,LLI>> dp(N+1);

    dp[0][""] = 1;
    REP(i,N){
      for(char c : agct){
	for(auto &kv : dp[i]){
	  string s = kv.fst;
	  string t(s);
	  t.push_back(c);
	  //dump(t);
	  if(t.size() >= 5) t.erase(t.begin());

	  if(check(t)){
	    (dp[i+1][t] += dp[i][s]) %= mod;
	  }
	}
      }
      //      dump(dp[i]);
    }

    LLI ans = 0;
    for(auto &kv : dp[N]){
      (ans += kv.snd) %= mod;
    }
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=1<<19|5;
const int mo=200003;
#define E complex<long double>
#define pi acos(-1)
int R[N],n,m,f[N];
E A[N];
void FFT(E *a,int p,int f){
	for (int i=0;i<p;i++)
		if (i<R[i]) swap(a[i],a[R[i]]);
	for (int d=1;d<p;d<<=1){
		E wn(cosl(pi/d),f*sinl(pi/d));
		for (int i=0;i<p;i+=(d<<1)){
			E w(1,0);
			for (int j=0;j<d;j++,w*=wn){
				E y=a[i+j+d]*w;
				a[i+j+d]=a[i+j]-y;
				a[i+j]+=y;
			}
		}
	}
	if (f==-1){
		for (int i=0;i<p;i++)
			a[i]/=p;
	}
}
ll ans;
int main(){
	int v=1;
	For(i,0,mo-2){
		f[v]=i,v=2*v%mo;
		if (i!=mo-2) assert(v!=1);
	}
	scanf("%d",&n);
	For(i,1,n){
		int x;
		scanf("%d",&x);
		if (x){
			A[f[x]]=A[f[x]]+E(1,0); 
			ans-=1ll*x*x%mo;
		}
	}
	int p=1,L=0;
	for (;p<2*mo;p<<=1,L++);
	//cout<<p<<' '<<L<<endl;
	for (int i=1;i<p;i++)
		R[i]=(R[i>>1]>>1)|((i&1)<<(L-1));
	FFT(A,p,1);
	for (int i=0;i<p;i++) A[i]*=A[i];
	FFT(A,p,-1);
	v=1;
	For(i,0,2*mo){
		ans+=v*((ll)(A[i].real()+0.0001));
		v=2*v%mo;
	}
	cout<<ans/2;
}

Measured memory_bytes: 23260
def main():
    N = int(input())
    a = [int(input()) for _ in range(N)]

    tmp = 0

    for i in range(N):
        if a[tmp] == 2:
            print(i+1)
            exit()
        else:
            tmp = a[tmp]-1

    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12960
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n; cin >> n;
    vector<long long> a(n);
    for (auto &ai: a) cin >> ai, ai *= 2;
    long long ofs = 0;
    for (auto ai: a) ofs = ai - ofs;
    long long x = ofs / 2;
    for (int i = 0; i < n; i++) {
        cout << x << " \n"[i == n - 1];
        x = a[i] - x;
    }
    return 0;
}

Measured memory_bytes: 2048
#include <stdio.h>

int main(void)
{
	int i, j;
	char input[20], inversion[20];
	while ( scanf("%s", input) != EOF )
	{
		for (i=0; input[i] != '\0'; i++);
		i--;
		
		for (j=0; j <= i; j++)
		{
			inversion[j] = input[i-j];
		}
		
		i++;
		inversion[i] = input[i];
		printf("%s\n", inversion);
	}
	
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

void debug(const bool &rev, const deque<char> &dq) {
    string ans = "";
    if (!rev) {
        for(auto it = dq.begin(); it != dq.end(); it++) {
            ans += *it;
        }
    }
    else {
        for(auto it = dq.rbegin(); it != dq.rend(); it++) {
            ans += *it;
        }
    }
    printf("ans=%s\n", ans.c_str());
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    ll q;
    cin >> q;
    bool rev = false;
    deque<char> dq;
    rep(i, len(s)) dq.push_back(s[i]);
    rep(i, q) {
        ll t;
        cin >> t;
        if (t == 1) {
            rev = !rev;
        }
        else if (t == 2) {
            ll f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (!rev) dq.push_front(c);
                else dq.push_back(c);
            }
            else {
                if (rev) dq.push_front(c);
                else dq.push_back(c);
            }
        }
        // debug(rev, dq);
    }
    string ans = "";
    if (!rev) {
        for(auto it = dq.begin(); it != dq.end(); it++) {
            ans += *it;
        }
    }
    else {
        for(auto it = dq.rbegin(); it != dq.rend(); it++) {
            ans += *it;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

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); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int m,k;
	cin >> m >> k;
	if(m == 0){
		if(k == 0) cout << "0 0" << endl;
		else cout << -1 << endl;
		return 0;
	}
	if(m == 1){
		if(k == 0) cout << "0 0 1 1" << endl;
		else cout << -1 << endl;
		return 0;
	}
	if((1 << m) <= k){
		cout << -1 << endl;
		return 0;
	}
	int ans[1 << 18],cnt = 0;
	ans[(1 << m) - 1] = ans[(1 << (m + 1)) - 1] = k;
	for(int i = 0;i < (1 << m);i++){
		if(i != k){
			ans[cnt] = ans[(1 << (m + 1)) - 2 - cnt] = i;
			cnt++;
		}
	}
	for(int i = 0;i < (1 << (m + 1));i++) cout << (i ? " " : "") << ans[i];
	cout << endl;
}

Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <numeric>
#include <cstdint>
#include <cmath>
using namespace std;
using i64 = int64_t;
void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= 9; ++i) {
		int div = n / i, mod = n % i;
		if (div > 0 && div <= 9 && mod == 0) {
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut a = String::new();
    io::stdin().read_line(&mut a).unwrap();
    let v = a.trim().split(' ').flat_map(str::parse::<u32>).collect::<Vec<_>>();
    let min = v.iter().min().unwrap();
    let max = v.iter().max().unwrap();
    println!("{}", max - min);
}

Measured memory_bytes: 4352
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]
ikeruheya = [[] for i in range(n)]
ans = [0]*n

ans[0]=1

for i in range(m):
    ikeruheya[a[i][0]-1].append(a[i][1])
    ikeruheya[a[i][1]-1].append(a[i][0])


next=[1]

while len(next):
    imaheya = next.pop(0)-1
    for j in range(len(ikeruheya[imaheya])):
        if ans[ikeruheya[imaheya][j]-1]==0:
            ans[ikeruheya[imaheya][j]-1]= imaheya + 1           
            next.append(ikeruheya[imaheya][j])
            #ikeruheya[[imaheya-1][j]-1].remove(imaheya)
        

print("Yes")
for i in range(1, n):
    print(ans[i])


#b=ikeruheya
#michi=ans
#heya=next
#now=imaheya-1
    


Measured memory_bytes: 60232
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int main(void)
{
    sync;
    ll x;
    cin>>x;
    ll a=2*(x-x%500);
    x%=500;
    ll b=x/5*5;
    cout<<a+b<<endl;
    return 0;
}

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

main() {
  ll N, x; cin >> N >> x;
  vector<ll> a(N); for (int i = 0; i < N; i++) cin >> a[i];

  ll ans = 0;
  for (int i = 1; i < N; i++) {
    ll diff = max(0LL, a[i - 1] + a[i] - x);
    ans += diff;
    a[i] -= min(a[i], diff);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//
//bool sortcol( const vector<ll>& v1, const vector<ll>& v2 ) { 
//	return v1[1] < v2[1]; 
//}

int main(){
	int n;
	cin>>n;
	ll a[n], b[n];
	vector<vector<ll> > c(n, vector<ll> (2));
	for(int i=0; i<n; i++){
		cin>>a[i]>>b[i];
		c[i][0] = a[i]+b[i];
		c[i][1] = i;
	}
	sort(c.begin(), c.end());
	ll tka = 0, ako = 0;
	//ll ans = 0;
	reverse(c.begin(), c.end());
	for(int i=0; i<n; i++){
		if(i%2==0){
			tka+= a[c[i][1]];
			//ans += a[c[i][1]];
		}else{
			ako += b[c[i][1]];
			//ans -= b[c[i][1]];
		}
	}
	cout<<tka-ako<<'\n';
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, m;
    P a[112345];

    cin >> n >> m;
    REP(i, n)
    cin >> a[i].first >> a[i].second;

    sort(a, a + n);

    priority_queue<int> q;

    int ai = 0;

    int res = 0;
    for (int i = m; i >= 1; i--)
    {
        while (ai < n && (m + 1) - i >= a[ai].first)
        {
            q.push(a[ai].second);
            ai++;
        }

        if (q.size())
        {
            res += q.top();
            q.pop();
        }
    }

    cout << res << endl;

    return 0;
}


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

bool isGreater(int h, int w, int hh, int ww){
  if ( h*h + w*w == hh*hh + ww*ww ) return h < hh;
  else return h*h + w*w < hh*hh + ww*ww;
}

void solve(int h, int w){
  int mh = 151;
  int mw = 151;
  for ( int hh = 1; hh < 150; hh++ ){
    for ( int ww = hh+1; ww <= 150; ww++ ){
      if (isGreater(h, w, hh, ww) && !isGreater(mh, mw, hh, ww) ){
	mh = hh;
	mw = ww;
      }
    }
  }
  cout << mh << " " << mw << endl;
}

main(){
  int h, w;
  while(1){
    cin >> h >> w;
    if ( h == 0 && w == 0 ) break;
    solve(h, w);
  }
}

Measured memory_bytes: 1160
#include <cstdio>

int isPrime(int x){
    if (x<2) return 0;
    else if (x == 2) return 1;
    if (!(x%2)) return 0;
    for (int i=3; i*i <= x; i+=2){
        if (!(x%i)) return 0;
    }
    return 1;
}

int main(){
    int n,x;
    int cnt = 0;
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%d", &x);
        if (isPrime(x)) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 2740
#include<bits/stdc++.h>
using namespace std;
const string ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    string tmpS;
    int nalphabets[26];
    for(int i=0;i<26;i++) nalphabets[i] = 1e5;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> tmpS;
        int tmpnalphabets[26] = {};
        for(auto s: tmpS) tmpnalphabets[s - 'a']++;
        for(int j=0;j<26;j++) nalphabets[j] = min(nalphabets[j], tmpnalphabets[j]);
    }

    for(int i=0;i<26;i++){
        for(int j=0;j<nalphabets[i];j++){
            cout << ALPHABETS[i];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,x;
	string s;
	cin>>a>>b>>s;
	int i,f=1;
	if(s.size()!=a+b+1)
		f=0;
	if(s[a]!='-')
		f=0;
	for(i=0;i<a+b+1;i++)
	{
		if(i!=a)
		{
			if(s[i]>='0' && s[i]<='9')
				x=1;
			else
				f=0;
		}
	}
	if(f==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
lists1=list(map(int,input().split()))
lists2=list(map(int,input().split()))
diff=[0]
if n>=2:
    for i in range(n-1):
        diff.append(lists1[i+1]-lists2[i])
    cnt=0
    findlist=[]
    for i in range(n):
        cnt=cnt+diff[i]
        findlist.append((cnt,i))
    anslist=sorted(findlist,key=lambda x: x[0])
    base=lists1[0]+sum(lists2)
    print(base+anslist[-1][0])
elif n==1:
    print(lists1[0]+lists2[0])

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

set<int> sft;

int dfs(int x){
  sft.insert(x);
  if(x<=100000000){
    dfs(x*10+7);
    dfs(x*10+5);
    dfs(x*10+3);
  }
  return 0;
}

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

  int z;
  z=dfs(7);
  z=dfs(5);
  z=dfs(3);

  int ans=0;
  for(int x:sft){
    if(x<=n){
      set<int> num;
      while(x!=0){num.insert(x%10); x/=10;}
      if(num.size()==3)++ans;
    }else break;
  }

  cout<<ans<<endl;
  
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int y, x;
  int step;
};

int vy[4] = {0, 0, 1, -1};
int vx[4] = {1, -1, 0, 0};

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> v;
  rep(i, H) {
    string s;
    cin >> s;
    v.push_back(s);
  }

  queue<ST> que;
  rep(i, H) {
    rep(j, W) {
      if (v[i][j] == '#') que.push((ST){i, j, 0});
    }
  }
  int ret = 0;
  while (!que.empty()) {
    ST st = que.front();
    que.pop();
    if (st.step != 0 && v[st.y][st.x] == '#') continue;
    v[st.y][st.x] = '#';
    ret = max(ret, st.step);
    rep(k, 4) {
      int ny = st.y + vy[k];
      int nx = st.x + vx[k];
      if (0 <= ny && ny < H && 0 <= nx && nx < W) {
        if (v[ny][nx] == '.') {
          que.push((ST){ny, nx, st.step + 1});
        }
      }
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 13456
#include <iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main() {

	ll();
	
	char x, y;
	cin >> x >> y;
	if (x > y)
		cout << ">" << endl;
	else if (x < y)
		cout << "<" << endl;
	else
		cout << "=" << endl;

}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int H,W;
  cin>>H>>W;
  int c[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>c[i][j];
    }
  }
  int A[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>A[i][j];
    }
  }
  for(int k=0;k<10;k++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
  int sum=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(A[i][j]>=0){sum+=c[A[i][j]][1];}
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
    int x,a;cin>>x>>a;
    int ret;
    x<a ? ret = 0 : ret = 10;
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    int ans=0;
    for(int i = 1;i<=n;i++){
        int t=1;
        int num = i;
        while(num>=10){
            num/=10;
            t++;
        }
        if(t%2==1)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<vector<double>> dp(n+1,vector<double> (n+1,0.0));
  dp[0][0]=1;
  vector<double> p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
    for(int j=0;j<i+1;j++){
      dp[i+1][j]+=dp[i][j]*(1-p[i]);
      dp[i+1][j+1]+=dp[i][j]*p[i];
    }
  }
  double ans=0;
  for(int i=n/2+1;i<n+1;i++) ans+=dp[n][i];
  cout<<fixed<<setprecision(12)<<ans<<endl;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
const int N=100;
int arr[N];
int brr[N];
int crr[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)	scanf("%d",&arr[i]);
	for(int j=1;j<=n;j++)	scanf("%d",&brr[j]);
	for(int k=1;k<=n-1;k++)	scanf("%d",&crr[k]);
	
	int x=-1;
	int sum=0;
	for(int i=1;i<=n;i++) {
		sum+=brr[arr[i]];
		if(arr[i]==x+1) sum+=crr[x];
		x=arr[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
K = int(input())

S = [ord(i)-97 for i in s]

last = K
for i in range(len(S)):
    if S[i] != 0:
        if 26 - S[i] <= last:
            last -= 26 - S[i]
            S[i] = 0

if last > 0:
    S[-1] += last
    S[-1] %= 26

S = [chr(i+97) for i in S]
print(''.join(S))

Measured memory_bytes: 4980
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;
int A[300][300];
bool used[300][300];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  
  REP(i,N)REP(j,M){
    cin >> A[i][j];
    -- A[i][j];
  }
  int ans = INF;
  REP(ct, M){

    int part[300];
    fill(part, part + M, 0);
    REP(i,N){
      int a_i = 0;
      while(used[i][a_i]) a_i++;
      part[A[i][a_i]]++;
    }
    int res = 0, ban_spo;
    REP(i,M){
      if(part[i] > res){
        ban_spo = i;
        res = part[i];
      }
    }
    REP(i,N){
      int a_i = 0;
      while(used[i][a_i] || A[i][a_i] != ban_spo) a_i++;
      used[i][a_i] = true;
    }
    ans = min(res, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        if(a < b){
            System.out.println("a < b");
        }else if(a > b){
            System.out.println("a > b");
        }else if(a ==b){
            System.out.println("a == b");
        }
    }
}


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

int main()
{
  int A, B;
  cin >> A >> B;
  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;


int main(){
  int K,T;cin >> K >> T;
  vector<pair<int,int>> cake(T);
  for(int i = 0;i < T;i++){
    cin >> cake[i].first;
    cake[i].second = i;
  }
  if(T == 1){
    cout << K-1 << endl;
    return 0;
  }
  int ans = 0;
  int last = 0;
  for(int i = 0;i < K;i++){
    if(i == 0){
      sort(cake.begin(),cake.end());
      last = cake[T-1].second;
      cake[T-1].first--;
    }else{
      sort(cake.begin(),cake.end());
      if(last == cake[T-1].second){
        if(cake[T-2].first > 0){
          last = cake[T-2].second;
          cake[T-2].first--;
        }else{
          last = cake[T-1].second;
          cake[T-1].first--;
          ans++;
        }
      }else{
        last = cake[T-1].second;
        cake[T-1].first--;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<functional>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long long int n;
  int flag = 0;
  long long int a[1000000];
  long long int i;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  for(i=0;i<n;i++){
  if(a[i] == a[i+1]){
  cout<<"NO";
    flag = 1;
    break;
  }
  }
  if(flag==0){
  cout<<"YES";
  }
  return 0;

}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1e9+7;
vector<long long> fact, fact_inv, inv;
void init_nCk(ll SIZE){
  fact.resize(SIZE+5);
  fact_inv.resize(SIZE+5);
  inv.resize(SIZE+5);
  fact[0]=fact[1]=1;
  fact_inv[0]=fact_inv[1]=1;
  inv[1]=1;
  for(ll i=2;i<SIZE+5;++i){
    fact[i]=fact[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
  }
}
ll nCk(ll n,ll k){
  return fact[n]*(fact_inv[k]*fact_inv[n-k]%MOD)%MOD;
}
int main(){
  ll N,K,ans=0;
  cin>>N>>K;
  vector<ll> vec(N);
  for(ll i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  if(K==1){cout<<0<<endl;}
  else{
    init_nCk(100000);
    for(ll i=K-1;i<N;i++){
      ans+=vec.at(i)*nCk(i,K-1)%MOD;
      ans=(ans+MOD)%MOD;
    }
    for(ll i=N-K;i>=0;i--){
      ans-=vec.at(i)*nCk(N-i-1,K-1)%MOD;
      ans=(ans+MOD)%MOD;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3328
N, M = map(int, input().split())
dic = {}
for i in range(N):
    A = list(map(int, input().split()))
    for i in A[1:]:
        if i not in dic:
            dic[i] = 1
        else:
            dic[i] += 1

ans = 0
for i in dic.values():
    if i % N == 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repe(i,n) for (int i = 1; i <= (n); ++i)
#define reps(i,start,end,step) for (int i = start; i <= end; i+=step)
#define rep_bit(n) for (int bit = 0; bit < (1 << n); ++bit)
using namespace std;
typedef long long ll;
typedef string str;
const ll INF = 1e18;
const int MX = 2005;
const double pi = 3.141592653589793238;

int main() {

  ll A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  ll ans = 0;
  if(A+B<=2*C){
    ans = A*X+B*Y;
  }
  else{
    if(X<Y) ans = 2*C*X + min(B,2*C)*(Y-X);
    else if(X>Y) ans = 2*C*Y + min(A,2*C)*(X-Y);
    else ans = 2*C*X;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    vector<vector<int>> data(3, vector<int>(3));
    vector<vector<int>> ans(3, vector<int>(3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> data[i][j];
        }
    }
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];

    rep(i,n){
        for(int k=0;k<3;k++){
            for(int j=0;j<3;j++){
                if(A[i] == data[k][j]){
                    ans[k][j]=1;
                }
            }
        }
    }

    for(int i=0;i<3;i++){
        if(ans[i][0] == 1 &&ans[i][1]==1 && ans[i][2] ==1){
            cout << "Yes"<< endl;
            return 0;
        }
        if(ans[0][i] == 1 &&ans[1][i]==1 && ans[2][i] ==1){
            cout << "Yes"<< endl;
            return 0;
        }
        if(i==0 && ans[0][0] == 1 && ans[1][1] == 1 && ans[2][2]==1){
            cout << "Yes"<< endl;
            return 0;
        }
        if(i==2 && ans[2][0] == 1 && ans[1][1] == 1 && ans[0][2]==1){
            cout << "Yes"<< endl;
            return 0;
        }
    }
    cout << "No"<< endl;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

void sort(int *x, int *y) {
  int c;
  c = *x;
  *x = *y;
  *y = c;
}

int partition(int a[], int p, int r) {
  int x = a[r];
  int i = p - 1;
  int j;
  for (j = p; j < r; j++)
    if (a[j] <= x) {
      i = i + 1;
      sort(&a[i], &a[j]);
    }
  sort(&a[i + 1], &a[j]);
  return i + 1;
}

int main(void) {
  int n, a[100000];
  int q;
  
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  q = partition(a, 0, n - 1);

  for (int i = 0; i < n; i++) {
    if (i == q)
      printf("[%d]", a[i]);
    else
      printf("%d", a[i]);
    if (i != n - 1)
      printf(" ");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2084
//In The Name Of GOD

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 1000000007;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 20;
#define pb push_back
#define pp pop_back
#define IO ios_base::sync_with_stdio(false);

int main(){
  IO;
  ll x,y,z;
  cin>>x>>y;
  z=__gcd(x,y);
  if(z==y){
    cout<<-1;
  }else if(z==x){
    if(x*2%y){
      cout<<2*x;
    }else{
      cout<<3*x;
    }
  }else{
    cout<<x*y/z+x;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

string S;
int w;

string solve() {
    string answer = "";
    REP(i,0,S.length()) {
        if (i % w == 0) {
            answer += S[i];
        }
    }
    return answer;
}

signed main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> S >> w;
    cout << solve() << "\n";
    return 0;
}


Measured memory_bytes: 256