akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class AAtCoderContestScheduling {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;

      int d; cin >> d;
      vector<int> c(26);
      rep(i, 26) {
        cin >> c[i];
      }
      vector<vector<ll>> s(d, vector<ll>(26));
      rep(i, d) rep(j, 26) {
          cin >> s[i][j];
        }
      ll ret = 0;
      set<int> last[26];
      rep(i, 26) {
        last[i].insert(0);
        last[i].insert(d+1);
      }
      vector<ll> last2(26);
      vector<int> contests(d);
      rep(i, d) {
        int t = (i%26);
        contests[i] = t;
        ret += s[i][t];
        last[t].insert(i+1);
        last2[t] = i+1;
        rep(j, 26) {
          ret -= c[j]*(i+1-last2[j]);
        }
      }

      auto start = clock();

      while(clock() - start < 1.9 * CLOCKS_PER_SEC) {
        int day = rng()%d;
        int q = rng()%26;

        int before = contests[day];

        ll diff = 0;
        diff += s[day][q];
        diff -= s[day][before];

        day++;
        last[before].erase(day);
        auto it = last[before].upper_bound(day);
        int right = (*it);
        it--;
        int left = (*it);
        diff -= c[before]*(day-left)*(right-day);

        it = last[q].upper_bound(day);
        right = (*it);
        it--;
        left = (*it);
        diff += c[q]*(day-left)*(right-day);
        //debug(day, q, diff);

        if (diff >= 0 || rng()%10 < 0) {
          last[q].insert(day);
          contests[day-1] = q;
          ret += diff;
        } else {
          last[before].insert(day);
        }
      }

      rep(i, d) {
        cout << contests[i]+1 << '\n';
      }
      debug(ret);
    }
};

signed main() {
  AAtCoderContestScheduling solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3788
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100000
using namespace std;
int cnt[2][MAXN+5];
int main()
{
	int n,x;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		cnt[i%2][x]++;
	}
	int ans=0;
	int mx[2]={},sx[2]={};
	int mxnum[2]={};
	for(int typ=0;typ<2;typ++)
	{
		for(int val=1;val<=MAXN;val++)
			if(cnt[typ][val]>mx[typ])
			{
				mxnum[typ]=val;
				sx[typ]=mx[typ],mx[typ]=cnt[typ][val];
			}
			else
				sx[typ]=max(sx[typ],cnt[typ][val]);
	}
	if(mxnum[0]==mxnum[1])
	{
		ans=n-mx[0]-sx[1];
		ans=min(ans,n-mx[1]-sx[0]);
	}
	else
		ans=n-mx[0]-mx[1];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
n,k = map(int,input().split())
aa = list(map(int,input().split()))

dp = [-1]*(k+1)

for i in range(1,k+1):
  for j in range(n):
    if i >= aa[j]:
      dp[i] = max(dp[i],-dp[i-aa[j]])

if dp[k]>0:
  print('First')  
else:
  print('Second')      

Measured memory_bytes: 42092
use std::io::{self, BufRead};
use std::cmp::max;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (n, m, k) = (xs[0], xs[1], xs[2]);
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let ys: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let mut zs: Vec<usize> = vec![0; n + 1];
  let mut ws: Vec<usize> = vec![0; m + 1];
  for i in 0..n {
    zs[i+1] = zs[i] + xs[i];
  }
  for i in 0..m {
    ws[i+1] = ws[i] + ys[i];
  }
  let mut i = zs.iter().map(|&z| z <= k).count() - 1;
  let l = ws.iter().map(|&w| w <= k).count();
  let mut j: usize = 0;
  let mut ans: usize = 0;
  while j < l {
    if zs[i] + ws[j] <= k {
      ans = max(ans, i + j);
      j += 1;
    } else if i > 0 {
      i -= 1;
    } else {
      break;
    }
  }
  println!("{}", ans);
}

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

int main() {

	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";

	
}

Measured memory_bytes: 1128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		int n = sc.nextInt();
		
		long p = 0L;
		for(int i=0;i<n;i++){
			int a = sc.nextInt();
			p+=a;
		}
		sc.close();

		if(p>=h){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 47808
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n],b[n];
  rep(i,n) R a[i];
  rep(i,n) R b[i];
  priority_queue<P> que;
  que.push(P(0,-1));
  rep(i,n) if(b[i]>a[i]) que.push(P(b[i],i));
  ll ans=0;
  while(que.size()>1) {
    P p=que.top();que.pop();
    ll x=p.S;
    P q=que.top();
    ll z=b[(x-1+n)%n]+b[(x+1)%n];
    //ll m=max(1LL,min((b[x]-a[x])/z,(ll)ceil((double)(b[x]-q.F)/z)));
    ll m=max(1LL,(b[x]-a[x])/z);
    b[x]-=m*z;
    ans+=m;
    if(b[x]<a[x]) {
      pr(-1);
      return;
    }
    if(b[x]>a[x]) que.push(P(b[x],x));
  }
  pr(ans);
}

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


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

struct Data
{
	int lx,ly,rx,ry;
};

const int  dy[] = { 0, 0,+1,-1};
const int ldx[] = {+1,-1, 0, 0};
const int rdx[] = {-1,+1, 0, 0};

int main()
{
	int W,H;
	while(cin>>W>>H, W||H)
	{
		char L[50][51];
		char R[50][51];
		for(int y=0; y<H; y++)
		{
			cin>>L[y]>>R[y];
		}


		Data s;
		for(int y=0; y<H; y++)
		for(int x=0; x<W; x++)
		{	
			if(L[y][x]=='L') { s.lx=x; s.ly=y; }
			if(R[y][x]=='R') { s.rx=x; s.ry=y; }
		}

		queue<Data> q;
		q.push(s);

		bool v[50][50][50][50]={0};
		v[s.ly][s.lx][s.ry][s.rx]=1;

		bool ans=false;
		while(!q.empty())
		{
			Data t=q.front(); q.pop();

			if(L[t.ly][t.lx]=='%' && R[t.ry][t.rx]=='%')
			{
				ans=true; break;
			}
			if(L[t.ly][t.lx]=='%' || R[t.ry][t.rx]=='%')
			{
				continue;
			}

			for(int i=0; i<4; i++)
			{
				Data n;
				n.ly = t.ly +  dy[i];
				n.lx = t.lx + ldx[i];
				n.ry = t.ry +  dy[i];
				n.rx = t.rx + rdx[i];

				if(n.lx<0 || W<=n.lx || n.ly<0 || H<=n.ly)
				{
					n.ly = t.ly;
					n.lx = t.lx;
				}
				if(n.rx<0 || W<=n.rx || n.ry<0 || H<=n.ry)
				{
					n.ry = t.ry;
					n.rx = t.rx;
				}
				if(L[n.ly][n.lx]=='#')
				{
					n.ly = t.ly;
					n.lx = t.lx;
				}
				if(R[n.ry][n.rx]=='#')
				{
					n.ry = t.ry;
					n.rx = t.rx;
				}

				if(v[n.ly][n.lx][n.ry][n.rx]) continue;
				v[n.ly][n.lx][n.ry][n.rx]=1;
				q.push(n);
			}
		}

		cout << (ans?"Yes":"No") << endl;
	}
}

Measured memory_bytes: 7908
while True:
    height, width = [int(x) for x in input().split(" ")]
    if height == width == 0:
        break
    col1 = "#." * 150
    col2 = ".#" * 150
    col_set = col1[:width] + "\n" + col2[:width] + "\n"
    print(col_set * (height // 2) + (col1[:width] + "\n") * (height % 2))

Measured memory_bytes: 7680
#include <iostream>
#include <queue>

using namespace std;

#define N 100
#define INFTY (1<<21)

int n, M[N][N];
int d[N];

void bfs(int s){
  queue<int> q;
  q.push(s);
  for(int i=0; i<n; ++i) d[i] = INFTY;
  d[s] = 0;
  int u;
  while(!q.empty()){
    u = q.front();
    q.pop();
    for(int v=0; v<n; ++v){
      if(M[u][v] == 0) continue;
      if(d[v] != INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for(int i=0; i<n; ++i){
    cout << i+1 << " " << ( (d[i] == INFTY) ? (-1):d[i] ) << endl;
  }
}


int main(){
  int u, k, v;

  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> u >> k;
    --u;
    for(int j=0; j<k; ++j){
      cin >> v;
      --v;
      M[u][v] = 1;
    }
  }

  bfs(0);



  return 0;
}



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

string s, t;

int main(){

    cin >> s >> t;

    for (int i = 0; i < s.size(); i++){
        s = s[s.size()-1] + s;
        s.pop_back();
        if (s == t){
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#define fol(i,n) for(int i=0;i<n;i++)
#define db(a) cout << a<< endl;
using namespace std;


int main(){
    string s;
    cin >>s;
    cout << s[0]<<s.size()-2<<s[s.size()-1]<<endl;
    return 0;
}


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

int main() {
  int K, S;
  cin >> K >> S;
  int pat = 0;
  for (int i = 0; i <= K; i++) {
    int r = S-i;
    pat += max(r+1-2*max(r-K,0),0);
  }
  cout << pat << endl;
}

Measured memory_bytes: 256
import random
from random import randint
random.seed(0)

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

def score_calc(T):
    total = 0
    last = [0] * 26
    for i in range(1, D+1):
        t = T[i-1]
        total += S[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            total -= C[j] * (i - last[j])
    return total

total = 0
last = [0] * 26
ans = []
for i in range(1, D+1):
    score = [0] * 26
    for t in range(26):
        score[t] += S[i-1][t]
        for j in range(26):
            if j != t:
                score[t] -= C[j] * (i - last[j])
    total += max(score)
    last[score.index(max(score))] = i
    ans.append(score.index(max(score))+1)

N = 20000
Q = [[randint(0, (D-1)), randint(0, 25)] for i in range(N)]
for d, q in Q:
    old = ans[d]
    ans[d] = q + 1
    if score_calc(ans) > total:
        total = score_calc(ans)
    else:
        ans[d] = old

for i in range(D):
    print(ans[i])


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

ll md=1e9+7;
ll c[2010][2010];

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i=0;i<h;i++) cin >> s[i];
    vector<vector<int>> dx(h,vector<int>(w)), dy(h,vector<int>(w));
    for (int y=0;y<h;y++) {
        int l=0;
        for (int x=0;x<w;x++) {
            if (s[y][x]=='#') l=0;
            else l++;
            dx[y][x]=l;
        }
        for (int x=w-2;x>=0;x--) {
            if (dx[y][x]>0) dx[y][x]=max(dx[y][x+1],dx[y][x]);
        }
    }
    
    for (int x=0;x<w;x++) {
        int l=0;
        for (int y=0;y<h;y++) {
            if (s[y][x]=='#') l=0;
            else l++;
            dy[y][x]=l;
        }
        for (int y=h-2;y>=0;y--) {
            if (dy[y][x]>0) dy[y][x]=max(dy[y+1][x],dy[y][x]);
        }
    }
    int ans=0;
    for (int y=0;y<h;y++) {
        for (int x=0;x<w;x++) {
            ans=max(ans, dx[y][x]+dy[y][x]);
        }
    }
    cout << ans-1 << endl;
}

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

using namespace std;

int n,x,z,memo[20] = {1,6,9,36,81,216,729,1296,6561,7776,46656,59049},dp[110000];

int main() {
    cin >> n;
    for (x=1 ; x <= n ; x++) dp[x] = x;

    for (x=0 ; x<13 ; x++) {
        for (z=1 ; z<=n ; z++) {
            if (z >= memo[x]) {
                if (dp[z] > (dp[z-memo[x]]+1)) {
                    dp[z] = dp[z-memo[x]]+1;
                }
            }
        }
    }
    cout << dp[n] << "\n";


}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,k,s; 
int main()
{
	cin>>n>>k;
	if(k>(n-1)*(n-2)/2)cout<<-1,exit(0);
	s=n-1+(n-1)*(n-2)/2-k;
	cout<<s<<endl;
	for(int i=1;i<n&&s>0;i++)
		for(int j=i+1;j<=n&&s>0;s--,j++)
			cout<<i<<" "<<j<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i, j, n, k, sum_ = 0, max_ = 0;
    float exp = 0;
    scanf("%d %d", &n, &k);
    int p[n];
    for (i=0; i < n; i++){
        scanf("%d", &p[i]);
    }
    for (i=0;i<n;i++){
        sum_ += p[i];
        if (i >= k){
            sum_ -= p[i-k];
        }
        if (sum_ > max_){
            max_ = sum_;
        }
    }
    exp = (max_+k)/2.0;
    printf("%0.8f", exp);
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int N=10;

double dist(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int n,a[N],fac[N];
double x[N],y[N],g[N][N];

int main(){
    fac[0]=1;
    for(int i=1;i<N;++i) fac[i]=fac[i-1]*i;
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%lf%lf",&x[i],&y[i]);
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            g[i][j]=g[j][i]=dist(x[i],y[i],x[j],y[j]);
        }
    }
    for(int i=0;i<n;++i) a[i]=i;
    double ans=0;
    do{
        for(int i=0;i+1<n;++i) ans+=g[a[i]][a[i+1]];
    }while(next_permutation(a,a+n));
    printf("%.10lf\n",ans/fac[n]);
    return 0;
}

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

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, w, c, v, dp[100001] = {}, ans = 0;
    cin >> n >> w;
    for (int i = 0; i < n; i++)
    {
        cin >> c >> v;
        for (int j = w; j >= c; j--)
            dp[j] = max(dp[j], dp[j - c] + v);
    }
    for (int i = 0; i <= w; i++)
        ans = max(ans, dp[i]);
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    
    dp = [0] * N
    dp[1] = max(A[:2])
    odd = A[0]
    
    for i in range(2, N):
        if i % 2 == 0:
            odd += A[i]
            dp[i] = max(dp[i - 2] + A[i], dp[i - 1])
        else:
            dp[i] = max(dp[i - 2] + A[i], odd)
    print(dp[-1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 105132
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int n=0;
  if(a>b){
    n+=a;
    a--;
  }
  else{
	n+=b;
    b--;
  }
  if(a>b){
    n+=a;
    a--;
  }
  else{
	n+=b;
    b--;
  }
  cout << n;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n,c[1005],w[1005],dp[1005];
bool d[1005][1005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>c[i]>>w[i+1];
    for(int i=0;i<=n;i++)w[i+1]+=w[i];
    for(int i=0;i<n;i++)d[i][i]=true;
    for(int k=1;k<n;k++){
        for(int i=0;i+k<n;i++){
            int l=i,r=i+k;
            if(d[l][r-1]&&w[r]-w[l]<=c[r])d[l][r]=true;
            if(d[l+1][r]&&w[r+1]-w[l+1]<=c[l])d[l][r]=true;
        }
    }
    for(int i=1;i<=n;i++)dp[i]=n;
    for(int i=0;i<n;i++){
        dp[i+1]=min(dp[i+1],dp[i]+1);
        for(int j=i+1;j<n;j++)if(d[i][j])dp[j+1]=min(dp[j+1],dp[i]+1);
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 4088
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define rep1(i,n) for(int i = 1 ; i <= n ; ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  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;
  }
};

int n;
bool a[25][25];
const int JMAX = 1<<21;
mint dp[JMAX];
int main()
{
  cin >> n;
  rep(i,n) rep(j,n) cin >> a[i][j];

  dp[0].x = 1;
  
  rep(S,(1<<n)){
    int i = __builtin_popcount(S);
    rep(j,n){
      if(a[i][j] && !((S>>j)&1) ){
	dp[ S | (1<<j) ] += dp[S];  
      }
    }
  }
  cout << dp[(1<<n)-1].x << "\n";
  
  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define localin freopen("C:\\Users\\hp\\Desktop\\CPP\\inout\\inputf.in","r",stdin);
#define localout freopen("C:\\Users\\hp\\Desktop\\CPP\\inout\\outputf.in","w",stdout);
const int MAX=2e5+5;
#define ld long double
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define tot(v) v.begin(),v.end()
#define rtcheck cout<<"saurabh\n";exit(0);
#define vcheck(x) cout<<#x<<" "<<x<<endl;                                                                                                                                       
#define pint pair<int,int>
#define forn for(int i=0;i<n;i++)
const int modu=1e9+7;
const int inf=1e17;

struct knapsack{
	int wt;
	int val;
};


int solve(vector<knapsack> v , int n , int W)
{
	int dp[n+1][W+1];

	for(int w = 0 ; w<=W ; w++)
	{
		dp[1][w] = 0;
	}

	dp[1][v[1].wt] = v[1].val;

	for(int i=2;i<=n;i++)
	{
		for(int w=0;w<=W;w++)
		{
			dp[i][w] = dp[i-1][w];

			if(v[i].wt > w)
				continue;
			dp[i][w] = max(dp[i][w] , v[i].val + dp[i-1][w-v[i].wt]);
		}
	}

	return *max_element(dp[n],dp[n]+W+1);
}

int32_t main()
{
    fast;
    #ifndef ONLINE_JUDGE 
    localin;localout;
    #endif
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int W;
        cin >> W;
        vector<knapsack> v(n+1);
        for(int i=1;i<=n;i++)
        {
        	cin >> v[i].wt;
        	cin >> v[i].val;
        }

        int ans = solve(v,n,W);
        cout << ans << endl;
    }

 }


Measured memory_bytes: 81792
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())

a = make_divisors(n)

l =len(a)
if l % 2 == 0:
	print(a[l//2-1] + a[l//2] - 2)
else:
	print(a[l//2]*2 - 2)


Measured memory_bytes: 3268
// AOJ Volume 0 Problem 0006

#include <stdio.h>

int main(void)
{
    int debt;
    int weeks;
    int i;
    
    scanf("%d", &weeks);
    
    debt = 100000;
    for (i = 0; i < weeks; i++){
        debt += (debt / 20);
        debt = (debt + 999) / 1000 * 1000;
    }
    
    printf("%d\n", debt);

    return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int help(int arr[],int n,int dp[])
{
if(n==0)
return 0;
if(n==1)
return abs(arr[1]-arr[0]);
if(dp[n]!=-1)
return dp[n];


if(n<0)
return INT_MAX;
//cout<<min(help(arr,n-1)+abs(arr[n-1]-arr[n]),help(arr,n-2)+abs(arr[n-2]-arr[n]))<<endl;
dp[n]=min(help(arr,n-1,dp)+abs(arr[n-1]-arr[n]),help(arr,n-2,dp)+abs(arr[n-2]-arr[n]));
return dp[n];

}
int main()
{
 int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int dp[n];
   memset(dp,-1,sizeof(dp));
  int i=0;
  cout<<help(arr,n-1,dp)<<endl;
//  
//   dp[0]=0;
//   if(n>0)
//   dp[1]=abs(arr[1]-arr[0]);
//   if(n>1)
//   {
//   dp[2]=min(dp[0]+abs(arr[2]-arr[0]),dp[1]+abs(arr[2]-arr[1]));    
// }
//   for(int i=3;i<n;i++)
//   {
// dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));

//   }

//cout<<dp[n-1]<<endl;
}

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

#ifndef Z_ALOGORITHM_HPP
#define Z_ALOGORITHM_HPP
#include <string>
template <class A = std::string>
class Z_algorithm
{
    const A key;
    const size_t len;
    std::vector<size_t> z;
    bool is_built;
  public:
    Z_algorithm(const A &_key) : key(_key), len(_key.size()), is_built(false) {}

    const std::vector<size_t> &build()
    {
        assert(len);
        is_built = true;
        z.assign(len, 0);
        for(size_t i{1}, j{0}; i != len; ++i)
        {
            if(z[i - j] + i < z[j] + j)
            {
                z[i] = z[i - j];
            }
            else
            {
                size_t k{z[j] + j > i ? z[j] + j - i : 0};
                while(k + i < len && key[k] == key[k + i]) ++k;
                z[i] = k;
                j = i;
            }
        }
        z.front() = len;
        return z;
    }

    size_t size() const { return len; }
    size_t operator[](size_t i) const { return build(), z[i]; }

    std::vector<size_t> pattern_search(const A &str) const
    {
        A tmp(key);
        tmp.insert(end(tmp), begin(str), end(str));
        Z_algorithm other(tmp);
        const auto &nz(other.build());
        std::vector<size_t> res(nz.begin() + len, nz.end());
        for(size_t &x : res) if(x > len) x = len;
        return res;
    }
};
#endif

using namespace std;

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

    int n; cin>>n;
    vector<int> a(n),b(n);
    for(int i=0; i<n; ++i)
    {
        cin>>a[i];
    }
    for(int i=0; i<n; ++i)
    {
        cin>>b[i];
    }
    vector<int> aa(n*2),bb(n);
    for(int i=0; i<n; ++i)
    {
        bb[i]=b[i]^b[(i+1)%n];
    }
    for(int i=0; i<n*2; ++i)
    {
        int ii=i%n;
        aa[i]=a[ii]^a[(ii+1)%n];
    }

    Z_algorithm<decltype(bb)> z(bb);

    auto pref(z.pattern_search(aa));

    for(int k=0; k<n; ++k)
    {
        if(pref[k]==bb.size())
        {
            cout << k << " " << (b[0]^a[k]) << "\n";
        }
    }
}

Measured memory_bytes: 17520
a[120000],m,j;main(i){for(;i++<6e4;a[i]=m)for(!a[j=i]?m=i:0;j<6e4;a[j+=i]=1);for(;~scanf("%d",&j);printf("%d %d\n",a[j-1],m))for(m=j;a[j]==a[++m];);}

Measured memory_bytes: 0
const fs = require('fs')
const stdin = fs.readFileSync('/dev/stdin', 'utf8')

let [n, s, k] = stdin.split('\n')

const i = Number(k) - 1

const repStr = s[i]

const filtered = s.split('').filter(e=>e!==repStr)

filtered.forEach(e => {
  s = s.replace(e, '*')
})

console.log(s)


Measured memory_bytes: 7372
#include    <iostream>
#include    <cstdio>
#include    <numeric>

using namespace std;

int main() {
    int l[10], v1, v2;
    int length = 0;
    // 二点間の距離と、各点から始まる速度を与えたときに交差する点の位置を返す
    auto crossPoint = [&]() {
        // 交差した瞬間、それぞれの列車の変位は一致する
        // よって、交差する時間をt、距離をlとすると、
        // 「v1*t = l-v2*t」より、tについて解くと「t = l / (v1 + v2)」、
        // よって、変位は「(v1 * l) / (v1 + v2)」となる。
        return (double)(v1 * length) / (double)(v1 + v2);
    };

    while(~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2)) {
        length = accumulate(l, l+10, 0);
        double pos = crossPoint();          // 列車の交差時間の取得
        int i = 1, ls = l[0];               // 区間の計算

        while(ls < pos) { ls += l[i++]; }
        cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> mp(1000005);
    ll ans = 0;
    rep(i, n){
        if(mp[a[i]] != 0){
            mp[a[i]] = 2;
            continue;
        }
        for(int j = a[i]; j <= 1000000; j += a[i]){
            mp[j]++;
        }
    }
    rep(i, n){
        if(mp[a[i]] == 1) ans++;
    }
    print(ans);

}


Measured memory_bytes: 12684
#include <stdio.h>
#include <string.h>
 
int main() {
	
	char S[1001] = {'\0'};
  	char T[1001] = {'\0'};
	 
	int count = 0, min = 1000;
	 
//	gets(S);
//	gets(T);
	scanf("%s", S);
	getchar();
	scanf("%s", T);
	getchar();
	int len1 = strlen(S);
	int len2 = strlen(T);
 
	for(int i=0; i + len2 <= len1;i++){
	    count = 0;
	    for(int j=0; j<len2; j++){
	      	if(S[i+j] != T[j]){
	        	count++;
	      	}
	    }
	    if(min > count) min = count;
  	}
  	printf("%d\n",min);
 
 
  return 0;
}

Measured memory_bytes: 1712
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
static class Program
{
	static IEnumerable<int[]> ReadInts(this TextReader reader, int count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	}

	static IEnumerable<long[]> ReadLongs(this TextReader reader, long count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
	}
	
	public static void Main(string[] args)
	{
		var x = Console.In.ReadInts(1).First()[0];
		var n500 = x / 500;
		var n5 = (x - (n500 * 500)) / 5;
		Console.WriteLine(n500 * 1000 + n5 * 5);
	}
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int x,y,i,j;
  double n,l;
  cin>>x>>y;
   n=(4*x-y)/2;
  l=(y-2*x)/2;
  i=floor(n);
  j=floor(l);
  if((i==n && n>=0) &&(j==l&&l>=0) && l+n==x)
    cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;
  
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e18;
const double PI=3.1415926535897932;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod


const ll MaxN=201001;

ll f[MaxN], rf[MaxN];
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    REP(i, 1, MaxN) f[i] = (f[i - 1] * i) % mod;
    REP(i, 0, MaxN) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(ll n, ll k) {
    ll a=1;
    REP(i,n-k+1,n+1) a=(a*i)%mod;
    ll c = rf[k]; // = k
    return (a * c) % mod;
}

ll ruijou(ll n, ll k){
    if(!k) return 1;
    ll a=ruijou(n,k/2);
    a=(a*a)%mod;
    return k%2 ? (a*n)%mod : a;
}


int main(){
    init();
    ll N,A,B; cin>>N>>A>>B;
    ll ans=ruijou(2,N);
    ans=(ans+mod-C(N,A))%mod;
    ans=(ans+mod-C(N,B))%mod;
    cout<<(ans-1+mod)%mod<<endl;
}

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

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  double dmax = 0.0;
  int ansent  = 100 * a;
  int anssg   = 0;
  for (int x = 0; x <= f / 100; x++) {
	  bool flg1 = false;
	  for (int i = 0; i <= x / a; i++) {
		  if ((x - a * i) % b == 0) {
			  flg1 = true;
			  break;
			}
		}
	  if (!flg1) {
		  continue;
		}
	  for (int y = 0; y <= f; y++) {
		  bool flg2 = false;
		  for (int i = 0; i <= y / c; i++) {
			  if ((y - c * i) % d == 0) {
				  flg2 = true;
				  break;
				}
			}
		  if (!flg2) {
			  continue;
			}
		  if (100 * x + y <= f && y <= x * e && (double) y / (x + y)  > dmax) {
			  dmax   = (double) y / (x + y);
			  ansent = 100 * x + y;
			  anssg  = y;
			}
		}
	}
  cout << ansent << " " << anssg << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;++i)
#define c(a) cin>>a;
int r[18][100000],x[100000],i,j,n,L,a,b,A,N;
main(){
c(n)
rep(i,n)c(x[i])
c(L)
rep(i,n)r[0][i]=upper_bound(x,x+n,x[i]+L)-x-1;
rep(i,17)rep(j,n)r[i+1][j]=r[i][r[i][j]];
c(L)
rep(j,L){
c(a)c(b)--a;--b;
if(a>b)swap(a,b);
A=0;N=a;
for(i=17;i>=0;--i)if(r[i][N]<b){N=r[i][N];A+=1<<i;}
if(N<b)++A;
cout<<A<<endl;
}
}


Measured memory_bytes: 8320
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size()-8;i++){
		cout<<s[i];
	} 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

const int N = 100'009;

vector<pair<int, int>> g[N];
int ans[N];
int mx;

void dfs(int x, int pa, int color) {
  for (auto e : g[x]) {
    int y = e.first;
    if (y == pa) {
      continue;
    }
    color = (color + 1) % mx;
    ans[e.second] = color;
    dfs(y, x, color);
  }
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    g[x].emplace_back(y, i);
    g[y].emplace_back(x, i);
  }
  mx = 0;
  for (int i = 0; i < n; ++i) {
    mx = max(mx, (int)g[i].size());
  }
  dfs(0, -1, -1);
  printf("%d\n", mx);
  for (int i = 0; i < n - 1; ++i) {
    printf("%d\n", ans[i] + 1);
  }
}


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

int main(){

    int N;
    cin >> N;
    vector<char> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];

    string ans = "Three";
    for(int i = 0; i < N; i++) if(S[i] == 'Y') ans = "Four";

    cout << ans << endl;

    return 0;
}

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

int main()
{

  string s ;
  cin >> s  ;

  for(int i=0;i<s.size();++i){
    cout << 'x' ;
  }
  
  cout << endl;
    return 0;
}



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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    string ans = "aaa";
    ans.at(0) = s1.at(0) + ('A' - 'a');
    ans.at(1) = s2.at(0) + ('A' - 'a');
    ans.at(2) = s3.at(0) + ('A' - 'a');

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long int;

int R[200000], L[200000];
int cnt[200000];

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

  int lastR = -1;
  rep(i, s.size()) {
    if (s[i] == 'R') lastR = i;
    R[i] = lastR;
  }
  int lastL = s.size();
  for (int i = s.size() - 1; i >= 0; i--) {
      if (s[i] == 'L') lastL = i;
      L[i] = lastL;
  }

  rep(i, s.size()) {
      if (s[i] == 'L') {
          int c = i - R[i];
          cnt[R[i] + c % 2]++;
      } else {
          int c = L[i] - i;
          cnt[L[i] - c % 2]++;
      }
  }

  rep(i, s.size()) {cout << cnt[i] << ' ';}
  cout << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s==u) cout << a-1 << " " << b << endl;
  else cout << a << " " << b-1 << endl;
}

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

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;


// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int n; cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];

    map<int,int> mp;
    vector<map<int,int>> mpx(n);

    rep(i,n){
        int k = a[i];
        rep(j, sqrt(k)+1){
            if(k % (j+2) == 0){
                mpx[i][j+2]++;
                k /= (j+2);
                j--;
            }

            if(k == 1) break;
        }
        if(k != 1){
            mpx[i][k]++;
        }
    }

    rep(i,n){
        for(auto e: mpx[i]){
            if(mp[e.first] < mpx[i][e.first]) mp[e.first] = e.second;
        }
    }

    ll jud = 1;
    for(auto e: mp){
        rep(i,e.second){
            jud *= e.first;
            jud %= 1000000007;
        }
    }

    ll ans = 0;
    rep(i,n){
        ans += jud * modinv(a[i], 1000000007);
        ans %= 1000000007;
    }

    cout << ans << endl;

}

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


int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
  }

  sort(p.begin(), p.end());

  int ans = 0;
  rep(i, K) {
    ans += p[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		int N = Integer.parseInt(W);
		W = in.readLine();

		char[] s = new char[W.length()];
		for(int i=0;i<s.length;i++){
			s[i] = (char)((char)((W.charAt(i)-'A'+N)%26)+'A');
		}

		System.out.println(s);

	}


}


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

int main(){
    i64 x, y, w, h;
    i64 X, Y, W, H;
    cin >> x >> y >> w >> h;
    cin >> X >> Y >> W >> H;

    if(x > X) { swap(x ,X), swap(y, Y), swap(w, W), swap(h, H); }
    i64 width = max(min(x+w - X, W), 0ll);
    if(y > Y) { swap(x ,X), swap(y, Y), swap(w, W), swap(h, H); }
    i64 height = max(min(y+h - Y, H), 0ll);

    cout << (w*h + W*H) - 2*(width*height) << endl; 
}


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

using ll = long long;

int N;
vector<int> A(15 + 1);
vector<vector<int>> x(15 + 1, vector<int>(15 + 1));
vector<vector<int>> y(15 + 1, vector<int>(15 + 1));

void solve(){
    int max = 0;
    for(int k = 0; k < (1 << N); ++k){
        bool flag = true;
        for(int i = 0; i < N; ++i){
            if(!(k & (1 << i))) continue;
            for(int j = 0; j < A[i]; ++j){
                int b = (k >> x[i][j]) & 1;
                if(b != y[i][j]) flag = false;
            }
        }
        if(flag){
            int count = __builtin_popcount(k);
            if(max < count) max = count;
        }
    }
    cout << max;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        for(int j = 0; j < A[i]; ++j){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

ll const MAX_V = 200005;

// 辺に属性がある場合
// 頂点toへのコストcostの辺
struct edge {
    ll to, cost;
};
vector<edge> G[MAX_V];

int main() {
    INIT;
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    for (ll i = 0; i < N; i++) {
        // sからtへの辺を張る
        A[i]--;
        edge et = {A[i], 1};
        G[i].push_back(et);

        // // 無向グラフの場合はさらにtにsへの辺を張る
        // edge es = {i, 1};
        // G[A[i]].push_back(es);
    }

    vector<ll> visited(N + 5, -1);
    ll nv = 0;
    ll first_visit = -1;
    ll loop_visit, loop_v;

    rep(i, K) {
        if (visited[nv] > 0) {
            first_visit = visited[nv];
            loop_visit = i - first_visit;
            loop_v = nv;
            break;
        }
        visited[nv] = i;
        nv = G[nv][0].to;
    }

    if (first_visit == -1) {
        cout << nv + 1 << endl;
        return 0;
    }

    // rep(i, N) { cout << visited[i] << " "; }
    // cout << endl;

    rep(i, N) { visited[i] -= first_visit; }

    // rep(i, N) { cout << visited[i] << " "; }
    // cout << endl;

    ll loop_num = (K - first_visit) / loop_visit;
    ll last_k = loop_num * loop_visit + first_visit;

    // cout << "loop_v: " << loop_v << ", loop_visit:" << loop_visit << ", "
    //      << K - last_k << endl;

    rep(i, N) {
        if (visited[i] == K - last_k) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    // nv = loop_v;
    // reps(i, last_k, K) { nv = G[nv][0].to; }

    // cout << nv + 1 << endl;

    return 0;
}

Measured memory_bytes: 17188
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>

typedef long long ll;

using namespace std;

static const int MAX = 100010;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];
int id;

void dfs(int r , int c){
	stack<int> s;
	s.push(r);
	color[r] = c;
	while (!s.empty()){
		int t = s.top() ; s.pop();
		for(int i = 0 ; i<G[t].size() ; i++){
			int k = G[t][i];
			if(color[k] == NIL){
				color[k] = c;
				s.push(k);
			}
		}
	}
}

void assign(){
	id =1;
	memset(color ,NIL , sizeof(color));
	for(int i = 0 ; i<n ; i++){
		if(color[i] == NIL)
			dfs(i , id++);
	}
}

int main(){
	ios::sync_with_stdio(false);
	int s,t,m,q;
	cin>>n>>m;
	
	for(int i = 0 ; i<m ; i++){
		cin>>s>>t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	
	assign();
	

	cin>>q;
	for(int i = 0 ; i<q ; i++){
		cin>>s>>t;
		if(color[s] == color[t]){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
	}	
	return 0;
}

Measured memory_bytes: 8940
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b;
	while (cin >> a >> b) {
		int a2 = max(a, b), b2 = min(a, b);
		while (b2 > 0) {
			int r = a2 % b2;
			a2 = b2;
			b2 = r;
		}
		cout << a2 << ' ' << a / a2 * b << endl;
	}
}


Measured memory_bytes: 3020
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "YES";
const string NO = "NO";

int main() {
  string c0,c1;
  cin >> c0 >> c1;
  cout << (c0[0] == c1[2] && c0[1] == c1[1] && c0[2] == c1[0] ? YES : NO) << endl;
  return 0;
}


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

int main () {
	int sn, tn, t, c = 0;
	cin >> sn;
	int *s = new int[sn];
	for (int i = 0; i < sn; i++)
		cin >> s[i];
	cin >> tn;
	for (int i = 0; i < tn; i++) {
		cin >> t;
		for (int j = 0; j < sn; j++) {
			if (s[j] == t) {
				c++;
				break;
			}
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 3480
<?php
list($N, $K) = ints();
define("MOD", 10**9+7);
$A = ints();
$dp = array_fill(0, $N+1, array_fill(0, $K+1, 0));
$dp[0][0] = 1;
for($i = 1; $i <= $N; ++$i){
  $sum = 0;
  $a = $A[$i-1];
  $dpim = $dp[$i-1];
  $dpi = &$dp[$i];
  for($j = 0; $j <= $K; ++$j){
    $sum+=$dpim[$j];
    if($j-$a-1 >= 0){
      $sum-=$dpim[$j-$a-1];
    }
    $sum %= MOD;
    $dpi[$j] = $sum;
  }
}
echo ($dp[$N][$K] + MOD) % MOD;

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}

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

int64_t dp[500][210][210] = {};
int dj[4] = {1, 1, 0, 0};
int dk[4] = {0, 1, 0, 1};

int main(){
    int H, W;
    cin >> H >> W;

    vector<vector<int>> a(H, vector<int>(W));
    for(auto& c : a) for(auto & i : c){
        cin >> i;
    }

    dp[0][0][0] = a[0][0];
    for(int i = 0; i < H + W; ++i){
        for(int j = 0; j <= min(i, W-1); ++j){
            for(int k = 0; k <= min(i, W-1); ++k){
                for(int l = 0; l < 4; ++l){
                    int nj = j + dj[l];
                    int nk = k + dk[l];
                    if(nj >= W || nk >= W || (i+1-nj) >= H || (i+1-nk) >= H) continue;
                    if(nk == nj){
                        dp[i+1][nj][nk] = max(dp[i+1][nj][nk], dp[i][j][k] + a[i-nj+1][nj]);
                    } else {
                        dp[i+1][nj][nk] = max(dp[i+1][nj][nk], dp[i][j][k] + a[i-nj+1][nj] + a[i-nk+1][nk]);
                    }
                }
            }
        }
    }
    cout << dp[H+W-2][W-1][W-1] << endl;
}

Measured memory_bytes: 137728
N = int(input())
Ps = list(map(int, input().split()))
Sorted = [i+1 for i in range(N)]

result = [Ps[i] for i in range(N) if Ps[i] != Sorted[i]]

if len(result) == 2 or len(result) == 0:
    print("YES")
else:
    print('NO')



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S>>K;
	FOR(i,N) if(S[i]!=S[K-1]) S[i]='*';
	cout<<S<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256