akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	vector<vector<ii>> a(n);
	for (int i = 0; i < n; ++i) {
		int num; cin >> num;
		for (int j = 0; j < num; ++j) {
			int p, f; cin >> p >> f;
			a[i].push_back({ p - 1, f + 1 });
		}
	}
	int ans = 0;
	for (int i = 1; i < (1 << n); ++i) {
		map<int, int> check;
		bool flag = true;
		int cnt = 0;
		for (int j = 0; j < n; ++j) {
			if (i & (1 << j)) {
				check[j] = 2;
				cnt++;
			}
			else check[j] = 1;
		}

		for (int j = 0; j < n; ++j) {
			if (i & (1 << j)) {
				for (int k = 0; k < a[j].size(); ++k) {
					if (check[a[j][k].first] == 0) continue;
					if (a[j][k].second != check[a[j][k].first]) flag = false;
				}
			}
		}
		if (flag) ans = max(ans, cnt);
	}
	cout << ans << endl;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n,d,x;
  vector<int> a;
  Solver(LL n) : n(n),a(n){};

  void solve() {
    cin>>d>>x;
    for(int i = 0;i<n;++i){
      cin>>a[i];
    }
    int ans =x;
    for(int i =0;i<n;++i){
      ans+=(d-1)/a[i]+1;
    }
    cout<<ans<<endl;
  }
};
class Solver2 {
 public:
  int n, m;
  Solver2(LL n, LL m) : n(n), m(m){};

  void solve() {
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p;
string s, t;
ld w;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	vll a(3);
	cin>>a[0]>>a[1]>>a[2];
	sort(all(a));
	cout<<a[0]+a[1];
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 1e3 + 9, M = 1e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<int> ZFun(string str) {
  vector<int> Z(str.size(), 0);
  int L = 0, R = 0, K;
  for (int i = 1; i < (int)str.size(); ++i) {
    if(i > R) {
      L = i, R = i;
      while(R < (int)str.size() && str[R] == str[R - L])
        ++R;
      Z[L] = R - L;
      --R;
    } else {
      K = i - L;
      if(Z[K] < R - i + 1) {
        Z[i] = Z[K];
      } else {
        L = i;
        while(R < (int)str.size() && str[R] == str[R - L])
          ++R;
        Z[L] = R - L;
        --R;
      }
    }
  }
  return Z;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n;
  string str;
  cin >> n >> str;
  vector<int> Z;
  int best = 0;
  while(n--) {
    Z = ZFun(str);
    for (int i = 0; i < n; ++i)
      best = max(best, min(i, Z[i]));
    str = str.substr(1);
  }
  cout << best;
  return 0;
}


Measured memory_bytes: 384
public class Main {
	public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		String b = sc.next();

		if (b.equals("A")) {
			System.out.println("T");
		}

		if (b.equals("C")) {
			System.out.println("G");
		}

		if (b.equals("T")) {
			System.out.println("A");
		}

		if (b.equals("G")) {
			System.out.println("C");
		}

	}
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    int[] v = new int[n];
    int sum = 0;

    for (int i = 0; i < n; ++i) {
      v[i] = sc.nextInt();
    }

    for (int i = 0; i < n; ++i) {
      int c = sc.nextInt();
      sum = (v[i] > c) ? sum + v[i] - c : sum;
    }

    System.out.println(sum);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>dp(3);
    for(int i=0;i<n;i++){
        int a[3];
        for(int j=0;j<3;j++)
            {
                cin>>a[j];
            }
        vector<int>temp(3,0);
        for(int j=0;j<3;++j){
            for(int k=0;k<3;++k){
                if(j!=k){
                    temp[k]=max(temp[k],dp[j]+a[k]);
                }
            }
        }
        dp=temp;
    }
    cout<<(max({dp[0],dp[1],dp[2]}));
}

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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    cin>>n>>m;
    vector<pair<ll,ll> > v;
    ll is[m]={0};
    ll ans=0;
    set<ll> s;
    for(i=0;i<m;i++)
    s.insert(i);
    for(i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x<=m)
        {
            v.pb(mp(y,x));
        }
    }
    sort(all(v));
    reverse(all(v));
    for(i=0;i<v.size();i++)
    {
        auto it = s.lower_bound(m-v[i].Y);
        if(it==s.begin() && (*it)!=m-v[i].Y)
        continue;
        if((*it)!=m-v[i].Y)
        it--;
        if((*it)<=m-v[i].Y)
        {
            is[m-v[i].Y]=1;
            ans+=v[i].X;
            s.erase(s.find(*it));
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 7928
#include <stdio.h>

int main(void){
    int N, K, Q;
    scanf("%i %i %i", &N, &K, &Q);
    int A[Q];
    for (int i = 0; i < Q; i++){
        scanf("%i", &A[i]);
    }
    int P[N];
    for (int i = 0; i < N; i++){
        P[i] = K - Q;
    }
    for (int i = 0; i < Q; i++){
        P[A[i] - 1]++;
    }
    for (int i = 0; i < N; i++){
        if (P[i] <= 0){
            puts("No");
        } else {
            puts("Yes");
        }
    }
}

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

int n;
vector<double> pn;
vector<vector<double>> dp;

int main(){
  cin>>n;
  pn.resize(n+1);
  for(int i=0;i<n;i++)cin>>pn[i];
  
  dp.assign(n+1,vector<double>(n+1,0));
  
  dp[0][0]=1;
  for(int i=0;i<n;i++)for(int j=0;j<=i;j++){
    dp[i+1][j]+=dp[i][j]*(1-pn[i]);
    dp[i+1][j+1]+=dp[i][j]*pn[i];
  }
  
  double ans=0;
  for(int i=0;i<=n;i++)if(i>n/2)ans+=dp[n][i];
  cout<<fixed<<setprecision(10);
  cout<<ans<<endl;
}

Measured memory_bytes: 70784
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		final Scanner in = new Scanner(System.in);
		final int a = in.nextInt(), b = in.nextInt();
		boolean result = true;
		if ((a + b) > 16 || a > 8 || b > 8) {
			result = false;
		}
		if (result) System.out.println("Yay!");
		else System.out.println(":(");
	}

}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main(){
    int a,b,ans =-1;
    cin >> a >> b;

    for(int i=0; i<2000; ++i){
        ll t1 = i*0.08, t2 = i*0.1;
        if(t1 == a && t2 == b){
            if(ans == -1){
                ans = i;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String [] s = br.readLine().split(" ");
		int n = Integer.parseInt(s[0]);
		int m = Integer.parseInt(s[1]);
		boolean[] probFlag = new boolean[n];
		int[] probWa = new int[n];
		int correct = 0 ,wa = 0 ;
		
		for(int i = 0 ; i < m ; i++) {
			s = br.readLine().split(" ");
			int p = Integer.parseInt(s[0]);
			String res = s[1];
			if(res.equals("WA") && !probFlag[p-1]) {
				probWa[p-1]++;
			}else if(res.equals("AC") && !probFlag[p-1]) {
				probFlag[p-1] = true;
				correct ++;
				wa += probWa[p-1];
			}
		}
		
		System.out.println(correct +" "+wa);
	}

}


Measured memory_bytes: 47156
N, @K = gets.chop.split.map(&:to_i)
ab = Array.new(N+1, [0, 0])
(1..N).to_a.each do |i|
  ab[i] = gets.chop.split.map(&:to_i)
end

ab.sort! do |a, b|
  a[0] <=> b[0]
end

result = (1..N).to_a.each do |i|
  @K -= ab[i][1]
  break ab[i][0] if @K <= 0
end

puts result

Measured memory_bytes: 12048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
char s[100010];
int vis[30]={0};
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0;i<n;i++)
        vis[s[i]-'a']++;
    ll ans=1;
    for(int i=0;i<26;i++)
        if(vis[i]!=0)ans=(ans*(vis[i]+1))%mod;

    printf("%lld\n",(ans-1)%mod);
   return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
  int n,k,x,y;
  scanf("%d%d%d%d",&n,&k,&x,&y);
  int sum=0;
  if(n>k) sum=x*k + y*(n-k);
  else sum=x*n;
  
  printf("%d",sum);
  
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
S = input()
if S[:N // 2] == S[N // 2:]:
    print("Yes")
else:
    print("No")



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


int main(void) {
    using namespace std;

    long n;
    cin >> n;

    vector<pair<int,int>> a(n);
    for(int i=0; i<n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());

    long r = 0;
    for(int i=0; i<n; i++) {
        if(~i&1) r += a[i].second&1;
    }
    cout << r << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back

int main(){
    ios_base::sync_with_stdio(0);
    ll a,b;
    cin>>a>>b;
    if(a>=10)cout<<b;
    else cout<<b+(100*(10-a));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int, int, int> ti;

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

    int H, W;
    cin >> H >> W;
    vector<string> map(H);
    for (int i = 0; i < H; i++)
    {
        string M;
        cin >> M;
        map.at(i) = M;
    }
    vector<int> dh = {-1, 1, 0, 0};
    vector<int> dw = {0, 0, -1, 1};
    queue<ti> moves;
    //全マスを起点で全探索
    int answer = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(map.at(i).at(j) == '#'){
                continue;
            }
            vector<vector<bool>> alreadyMoved(H, vector<bool>(W, false));
            moves.push(make_tuple(i, j, 0));
            alreadyMoved.at(i).at(j) = true;
            while(moves.size()){
                ti move = moves.front();
                moves.pop();
                int curH, curW, count;
                tie(curH, curW, count) = move;
                answer = max(answer, count);
                int nextH, nextW;
                for(int k = 0; k < 4; k++){
                    nextH = curH + dh.at(k);
                    nextW = curW + dw.at(k);
                    if(0 <= nextH && nextH < H
                    && 0 <= nextW && nextW < W                    
                    && map.at(nextH).at(nextW) == '.' 
                    && !alreadyMoved.at(nextH).at(nextW)){
                        moves.push(make_tuple(nextH, nextW, count + 1));
                        alreadyMoved.at(nextH).at(nextW) = true;
                    }
                }
            }
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    string S;
    cin >> S;
    ll ans = 0;
    rep(i, 3) if (S[i] == 'R') ans = 1;

    rep(i, 2) if (S.substr(i, 2) == "RR") ans = 2;

    if (S == "RRR") ans = 3;

    cout << ans << endl;
}

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    i64 h, w, n;
    cin >> h >> w >> n;
    vector<vector<i64>> v(h, vector<i64>(w, -MOD));
    priority_queue<tuple<i64,i64,i64>> que;
    for(i64 i = 0; i < n; ++i){
        i64 x, y, d;
        cin >> x >> y >> d;
        --x, --y;
        v[x][y] = d;
        que.emplace(d, x, y);
    }
    vector<i64> dx{1, 0, -1, 0};
    vector<i64> dy{0, 1, 0, -1};
    while(!que.empty()){
        i64 x, y, d;
        tie(d, x, y) = que.top();
        que.pop();
        if(d != v[x][y])
            continue;
        for(i64 i = 0; i < 4; ++i){
            i64 nx = x + dx[i];
            i64 ny = y + dy[i];
            if(nx < 0 || ny < 0 || nx >= h || ny >= w || v[nx][ny] != -MOD)
                continue;
            v[nx][ny] = d - 1;
            que.emplace(d - 1, nx, ny);
        }
    }

    for(i64 i = 0; i < h; ++i)
        for(i64 j = 0; j < w; ++j){
            for(i64 d = 0; d < 4; ++d){
                i64 nx = i + dx[d];
                i64 ny = j + dy[d];
                if(nx < 0 || ny < 0 || nx >= h || ny >= w)
                    continue;
                if(abs(v[i][j] - v[nx][ny]) > 1){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    i64 sum = 0;
    for(i64 i = 0; i < h; ++i)
        for(i64 j = 0; j < w; ++j){
            sum += v[i][j];
        }
    cout << sum << endl;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, k;
    cin >> n >> k;
    bool ng_num[10];
    rep(i, 10) ng_num[i] = 0;
    rep(i, k) {
        int tmp_num;
        cin >> tmp_num;
        ng_num[tmp_num] = 1;
    }
    rep(i, 100001) {
        int tmp_num = i;
        bool ok = 1;
        while(1) {
            if ( tmp_num == 0 ) {
                break;
            }
            if ( ng_num[tmp_num % 10] ) {
                ok = 0;
            }
            tmp_num /= 10;
        }
        if ( ok && i >= n ) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <vector>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <string>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;

    string ans = "";
    if (a > b) {
        for (int i = 0; i < a; i++) {
            ans += to_string(b);
        }
    } else {
        for (int i = 0; i < b; i++) {
            ans += to_string(a);
        }

    }

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

Measured memory_bytes: 256
from collections import deque, defaultdict

N, X, Y = map(int, input().split())
# 全探索でいけるのでは？
# 有向グラフとしてN回幅優先すれば良いのでは？
tree = [[] for _ in range(N)]
for i in range(N-1):
    tree[i].append(i+1)
    tree[i+1].append(i)
tree[X-1].append(Y-1)
tree[Y-1].append(X-1)
ans = defaultdict(int)
q = deque()
# 更新されない時はqに追加しない
for i in range(N):
    distant = [N]*N
    q.append(i)  # 始まりのノード
    distant[i] = 0
    while len(q):
        # vは数字, 親のノードのインデックス
        v = q.pop()
        for e in tree[v]:
            if distant[e] < distant[v]+1:  # 到達済みなら次のノードへ
                continue
            distant[e] = distant[v]+1
            q.append(e)
    for d in distant:
        ans[d] += 1
for i in range(1, N):
    print(ans[i]//2)


Measured memory_bytes: 50268
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
using P = pair<int, int>;

void solve()
{
    int n; cin >> n;
    vector<vector<P>> say(n);
    for(int i = 0; i < n; i++)
    {
        int a; cin >> a;
        for(int j = 0; j < a; j++)
        {
            int x, y; cin >> x >> y;
            x--;
            say[i].push_back(P(x, y));
        }
    }
    int ans = 0;
    for(int bit = 0; bit < (1<<n); bit++)
    {
        int check = 0;
        bool ok = true;
        for(int i = 0; i < n; i++)
        {
            if(!(bit & (1<<i))) continue;
            check |= (1<<i);
            for(const auto &s : say[i])
            {
                int target = s.first;
                int flag = s.second;
                if(flag)
                {
                    if(!(bit & (1<<target))) ok = false;
                    else check |= (1<<target);
                }
                else
                {
                    if(bit & (1<<target)) ok = false;
                    else check &= ~(1<<target);
                }
            }
        }
        if(check == bit && ok)
        {
            // for(int i = 0; i < n; i++) cout << (bit & (1<<i)); cout << endl;
            ans = max(ans, __builtin_popcount(bit));
        }
    }
    cout << ans << endl;
}

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

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

#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define ins insert
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'

int n, k, val;
vi a, vis, v;

void dfs(int i) {
    if(vis[i]) {
        val = i;
        return;
    }
    v.pb(i);
    vis[i] = 1;
    dfs(a[i - 1]);
}

signed main() {
    int n, k;
    cin >> n >> k;
    a.resize(n);
    read(a);
    vis.assign(n + 1, 0);
    dfs(1);
    vi x;
    bool has = false;
    for(int i : v) {
        if(i == val)
            has = true;
        if(has)  {
            x.pb(i);
        }
    }
    int diff = v.size() - x.size();
    if(k <= diff) {
        cout << v[k];
    }
    else {
        k -= diff;
        int ans = x[k % x.size()];
        cout << ans;
    }
}

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

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i <= _##i poi  i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i < _##i poi  i++)
#define downto(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i >= _##i poi  i--)
#define downtil(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i > _##i poi  i--)

#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define poi ;
#define poipoi << "\n"

#define do {
#define end }

#define fuwafuwa(n, c) dokidoki((n) + (c) - 1, c)
#define dokidoki(n, c) ((n) / (c) * (c))

template<class T> bool read(T& t){
    return cin >> t poi
}
template<class T, class...U> bool read(T& t, U&... u){
    unless(cin >> t) return false poi
    return read(u...) poi
}

template<class T> T lov_yet(T t){
    if(t) return t poi
    else return 0 poi
}

const long double PI = 3.141592653589793238462643383279502884L poi

int main() do
    double x = 0, y = 0 poi
    int r = 90, d, nr poi
    char comma poi
    while(read(d, comma, nr), d) do
        x += d * cos(r * PI / 180) poi
        y += d * sin(r * PI / 180) poi
        r -= nr poi
    end
    cout << (int)x poipoi << (int)y poipoi poi
    return 0 poi
end

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

int main(void)
{
    int x, y; cin >> x >> y;
    string ans;
    int diff = y - 2 * x;
    if (diff >= 0 && diff % 2 == 0 && diff / 2 <= x) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 3616
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.range, std.typecons;


void main() {
    long n;
    readf("%d\n", &n);

    alias T = Tuple!(long, long);
    T[][] nexts = new T[][](n);
    foreach (_; 0..n-1) {
        auto uvw = readln.split.map!(to!long).array;
        long u = uvw[0]-1, v = uvw[1]-1, w = uvw[2];
        nexts[u] ~= T(v, w % 2);
        nexts[v] ~= T(u, w % 2);
    }

    auto dists = new int[](n);
    dists[] = -1;

    void dfs(long cur, long prev, long dist) {
        dists[cur] = dist % 2;
        foreach (next; nexts[cur]) {
            if (next[0] == prev) {
                continue;
            }
            dfs(next[0], cur, (dist + next[1]) % 2);
        }
    }
    dfs(0, -1, 0);

    foreach (ans; dists) {
        writeln(ans);
    }
}


Measured memory_bytes: 27132
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    mod2 = 10**9+9
    sa = [S() for _ in range(2)]
    ml = min(map(len, sa))
    ss = []
    r = 0
    for si in range(2):
        s = sa[si]
        a = [0]
        a2 = [0]
        b = [set() for _ in range(ml)]
        b2 = [set() for _ in range(ml)]
        for c in s:
            k = 97 ** (ord(c) - ord('a'))
            a.append((a[-1] + k) % mod)
            a2.append((a2[-1] + k) % mod2)
        if si == 1:
            for i in range(len(a)):
                for j in range(i+1,len(a)):
                    if j - i > ml:
                        break
                    if j - i <= r:
                        continue
                    if (a[j]-a[i]) % mod in ss[0][j-i-1] and (a2[j]-a2[i]) % mod2 in ss[1][j-i-1]:
                        r = j-i

        else:
            for i in range(len(a)):
                for j in range(i+1,len(a)):
                    if j - i > ml:
                        break
                    b[j-i-1].add((a[j]-a[i]) % mod)
                    b2[j-i-1].add((a2[j]-a2[i]) % mod2)
            ss = [b,b2]

    return r


print(main())



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

void Main() {
  int n;
  R n;
  ll c[n][n];
  rep(i,n)rep(j,n)R c[i][j];
  vector<int> v(n);
  rep(i,n) v[i]=i;
  map<vector<int>,int> m;
  m[v]=0;
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,v));
  ll ans=0;
  while(!que.empty()) {
    P p=que.top();que.pop();
    ll cc=p.F;
    vector<int> a=p.S;
    if(m[a]<cc) continue;
    ans=max(ans,cc);
    rep(i,n) {
      REP(j,i+1,n) {
        vector<int> b=a;
        swap(b[i],b[j]);
        if(!m.count(b)||m[b]>cc+c[i][j]) {
          m[b]=cc+c[i][j];
          que.push(P(cc+c[i][j],b));
        }
      }
    }
  }
  pr(ans);
}

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


Measured memory_bytes: 10796
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

//  COMMAND TO USE WHEN RUNNING CODE: g++ day6.cpp -o day6 -std=c++11 -O2  | to run: ./(name of file)  //

int N, C, T;
int P = 0;

int main() {
    cin >> N;
    int p[N];
    for ( int i=0; i < N; i++ ) {
        cin >> p[i];
    }
    for ( int i=0; i < N; i++ ) {
        if ( p[i] > P ) {
            P = p[i];
            C = i;
        }
    }
    p[C] = p[C]/2;
    for ( int i=0; i < N; i++ ) {
        T += p[i];
    }
    cout << T;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))#モンスターの数
b = list(map(int,input().split()))#勇者が倒せる数

count = 0
for i in range(n):
	if b[i] > a[i]:
		count += a[i]
		b[i] = b[i]-a[i]
		a[i] = 0
		count += min(b[i],a[i+1])
		a[i+1] = a[i+1] - min(b[i],a[i+1])
	else:
		count += b[i]

print(count)

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

int main(){
    int n,ans=0; cin>>n;
    vector<int>d(n);
    for(int i=0;i<n;i++){
        cin>>d.at(i);
        }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int k=d.at(i)-d.at(j);
            if(k<0){k=-k;}
            if(ans<k){ans=k;}
            }
        }
        cout<<ans<<endl;
        }


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        // 主処理
        int result = 0;
        int index = (s.length() - 2) / 2;
        while (1 <= index) {
            boolean isEvenString = true;
            for (int i = 0; i < index; i++) {
                if (s.charAt(i) != s.charAt(index + i)) {
                    isEvenString = false;
                }
            }
            if (isEvenString) {
                result = index * 2;
                break;
            }
            index--;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 22996
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
string s,t;
cin>>s>>t;
int n=s.length(),m=t.length();
int ans=m;int cnt;
for(int i=0;i<=n-m;i++)
{
    cnt=0;
    for(int j=i;j<(i+m);j++)
    if(s[j]!=t[j-i])
    cnt++;
    ans=min(ans,cnt);
}
cout<<ans<<endl;



}

int32_t main()
{
   IOS;
    int t;
    t=1;
    //cin>>t;
    
    while(t--)
    {
       
        
        solve();
    }
    return 0;
}






Measured memory_bytes: 3648
N=int(input())
ans=1e5
for i in range(N+1):
    j=N-i
    cnt=0
    while i>0:
        cnt+=i%6
        i=i//6
    while j>0:
        cnt+=j%9
        j=j//9
    ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 3060
#include <queue>
#include <iostream>
using namespace std;
const int inf = 1012345678;
int N, M, K, d[16], v[109][109], dist[65555], f[109];
int main() {
	cin >> N >> M >> K;
	fill(f, f + N, -1);
	for (int i = 0; i < M; i++) cin >> d[i], f[--d[i]] = i;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < K; j++) {
			cin >> v[i][j];
			v[i][j] = f[v[i][j] - 1];
		}
	}
	fill(dist, dist + (1 << M), inf);
	dist[(1 << M) - 1] = 0;
	queue<int> que; que.push((1 << M) - 1);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i = 0; i < K; i++) {
			int bit = 0;
			for (int j = 0; j < M; j++) {
				if (u & (1 << j)) {
					if (v[d[j]][i] != -1) bit |= 1 << v[d[j]][i];
				}
			}
			if (dist[bit] == inf) {
				dist[bit] = dist[u] + 1;
				que.push(bit);
			}
		}
	}
	cout << dist[0] << endl;
	return 0;
}

Measured memory_bytes: 3520
#include <stdio.h>
#include <cstdio>
#include <vector>
#include <iostream>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

int main(){
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	int cnt = 0;
	while(a[0] != a[1] || a[1] != a[2] || a[2] != a[0]){
		VSORT(a);
		if((a[0] + 2) <= a[2]) a[0] += 2;
		else{
			a[0] += 1;
			a[1] += 1;
		}
		cnt += 1;
	}
	cout << cnt << "\n";
}


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

int main() {
  int N; cin>> N;
  bool f = false;
  for ( int i = 0; i <= 100; i+=4 ) {
    for ( int j = 0; j <= 100; j+= 7 ) {
      if ( i + j == N ) {
	f = true;
	break;
      }
    }
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import javax.swing.*;
import java.awt.datatransfer.SystemFlavorMap;
import java.util.*;
import java.io.*;


public class Main {
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }


    }
    public class pair {
        int a;
        int b;

        pair(int p, int q) {
            a = p;
            b = q;
        }
        public int hashCode() {
            return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
        }
    }

    public static int gcd(int a, int b) {
        if (a == 1 || b == 1)
            return 1;
        if (a == 0)
            return b;
        if (b == 0)
            return a;
        return gcd(b % a, a);
    }






    public static void main(String[] args) {
        FastReader s = new FastReader();
        String str=s.next();
        for(int i=0;i<str.length();i++)
        {
            System.out.print("x");
        }

    }


}









Measured memory_bytes: 22484
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int 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 modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int x, y,ans=0;
	cin >> y >> x;
	x /= y;
	while (x / 2 > 0) {
		x /= 2;
		ans++;
	}
	cout << ans+1 << endl;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n=in();
    int k=in();
    vector<int> a(n);
    REP(i,n){
        a[i]=in();
    }
    int sum=accumulate(a.begin(),a.end(),0);
    for(int t=sum;t>0;t--){
        if(sum%t==0){
            //debug(t);
            vector<int> r(n);
            REP(i,n){
                r[i]=a[i]%t;
            }
            sort(all(r));
            vector<ll> ruiseki;
            ruiseki.pb(0);
            REP(i,n){
                ruiseki.pb(ruiseki[i]+r[i]);
            }
            REP(i,n+1){
                if(ruiseki[i]<=k){
                    ll cnt;
                    cnt=ruiseki[i]-(t*(n-i)-(ruiseki[n]-ruiseki[i]));
                    if(cnt>=0&&cnt%t==0){
                        print(t);
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#define N 1000

int LCS[N+1][N+1];

int LCSLength(char X[], int m, char Y[], int n){
	for(int i=0;i<=m;i++)
		LCS[i][n] = 0;
	for(int j=0;j<=n;j++)
		LCS[m][j] = 0;
	for(int i=m-1;i>=0;i--){
		for(int j=n-1;j>=0;j--){
			LCS[i][j] = LCS[i+1][j+1];
			if(X[i] == Y[j])
				LCS[i][j]++;
			if(LCS[i][j+1] > LCS[i][j])
				LCS[i][j] = LCS[i][j+1];
			if(LCS[i+1][j] > LCS[i][j])
				LCS[i][j] = LCS[i+1][j];
		}
	}
	return LCS[0][0];
}

int main(){
	char X[N+1],Y[N+1];
	int num;
	scanf("%d",&num);
	for(int i=1;i<=num;i++){
		scanf("%s %s",X,Y);
		int m = strlen(X);
		int n = strlen(Y);
		printf("%d\n",LCSLength(X,m,Y,n));
	}
	return 0;
}

Measured memory_bytes: 6512
#include <stdio.h>

int main() {
  int X=0, Y=0, Z=0;
  scanf ("%d %d %d", &X, &Y, &Z);
  int tmp = Y;
  Y = X;
  X = tmp;
  tmp = Z;
  Z = X;
  X = tmp;
  printf ("%d %d %d", X, Y, Z);
  return 0;
}

Measured memory_bytes: 128
import sys
while True:
 list=[]
 a=0
 b=0
 c=0
 for i in range(0,5):
  n=input()
  if(n==0):sys.exit()
  list.append(n)
  if(n==1):a+=1
  if(n==2):b+=1
  if(n==3):c+=1
 if a>0 and b>0 and c>0 or a==5 or b==5 or c==5:
  for i in range(0,5):
   print "3"
 elif a>0 and b>0:
  for i in range(0,5):
   if list[i]==1:print 1
   else :print 2
 elif b>0 and c>0:
  for i in range(0,5):
   if list[i]==2:print 1
   else :print 2
 else:
  for i in range(0,5):
   if list[i]==3:print 1
   else :print 2

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

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

Z = A[0]

for i in range(N):
    Z = gcd(Z ,A[i])

flag = 0
i = 0

while flag == 0:
    if Z % pow(2,i) == 0:
        i += 1
    else :
        flag = 1

print(i-1)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  int n,j,g,h,gh;
  int j2,g2,h2,gh2;
  int ansj,ansg,ansh,ansgh;
  int i = 0;
  while(1){
    i++;
    cin >> n;
    if(n == 0) break;
    if(i != 1) cout << '\n';
    cin >> j >> g >> h >> gh;
    int sum = 0;
    sum = j*10 + g * 50 + h * 100 + gh * 500;
    int ans = 0;
    ans = sum - n;
    gh2 = ans/500;
    ans = ans%500;
    h2 = ans/100;
    ans = ans%100;
    g2 = ans/50;
    ans = ans%50;
    j2 = ans/10;
    ans = ans%10;

    if((j - j2) > 0){
      ansj = j - j2;
      cout << 10 << ' ' << ansj << '\n';
    }

    if((g - g2) > 0){
      ansg = g - g2;
      cout << 50 << ' ' << ansg << '\n';
    }

     if((h - h2) > 0){
       ansh = h - h2;
      cout << 100 << ' ' << ansh << '\n';
    }
    
    if((gh - gh2) > 0){
      ansgh = gh - gh2;
      cout << 500 << ' ' << ansgh << '\n';
    }
   
  }
}

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

#include <iostream>
#include <tuple>

using namespace std;
using sz = size_t;

tuple<size_t, string> stdinput() {
  size_t N;
  string S;
  cin >> N;
  cin >> S;

  return {N, S};
}

tuple<sz, sz, sz, sz> count_ng_tuples(sz N, string& S) {
  sz num_ng_tuples = 0;
  sz numRs = 0, numGs = 0, numBs = 0;

  for (sz i = 0; i < N; ++i) {
    switch (S[i]) {
      case 'R':
        numRs += 1;
        break;
      case 'G':
        numGs += 1;
        break;
      case 'B':
        numBs += 1;
        break;
    }

    for (sz j = i + 1, k = i + 2; k < N; j += 1, k += 2) {
      char a = S[i], b = S[j], c = S[k];
      if (a != b and b != c and c != a) num_ng_tuples += 1;
    }
  }
  return {numRs, numGs, numBs, num_ng_tuples};
}

int main(int argc, char *argv[]) {
  auto [N, S] = stdinput();
  auto [numRs, numGs, numBs, num_ng_tuples] = count_ng_tuples(N, S);
  cout << numRs * numGs * numBs - num_ng_tuples << endl;

  return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, K;
ll A[int(2e5+5)];

bool Solve(ll now){
  ll cnt = 0;
  for (int i = 0; i < N; i++){
    cnt += (A[i] - 1) / now;
  }
  if (cnt <= K) return true;
  else return false;
}

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];

  ll L = 0, R = 1e16;
  while (R - L > 1){
    ll now = (L + R) / 2;
    if (Solve(now)) R = now;
    else L = now;
  }
  cout << R << endl;

  return 0;
}


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

int main() {
  long long n,k,q;
  cin >> n >> k >> q;
  vector<long long> p(n+1, 0); //正解した数
  vector<long long> d(n+1, k);
  
  for(int i=0; i<q; i++){
    int l;
    cin >> l;
    p.at(l-1) = p.at(l-1) + 1;
  }
  
  for(int i=0; i<n; i++){
    d.at(i) = d.at(i) - q + p.at(i);
    
    if(d.at(i) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
  }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <cmath>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);

int main()
{
//thanks	
    int n;
    string s;
    cin >> n;
    cin >> s;
    unsigned ll rgb = 0;
    unsigned ll r = 0, g = 0, b = 0;
    rep(i, n)
    {
        if (s[i] == 'R') { ++r; }
        else if (s[i] == 'G')
        {
            ++g;
        }
        else
        { // b
            ++b;
        }

    }
    rgb=r*g*b;
    rep(i,n){
	    for(int j=1;j<=n;++j){
		    int ni=i-j,nj=i+j;
		    if(ni<0 ||nj>=n)break;
		    if(s[i]!=s[ni]&&s[i]!=s[nj]&&s[ni]!=s[nj]){--rgb;}//naritatanaikarahiku
	    }
    }
cout<<rgb<<endl;
    return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


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

int main()
{
    ll n, r;
    cin >> n >> r;
    if (n >= 10)
    {
        cout << r << endl;
    }
    else
    {
        cout << r + 100 * (10 - n) << endl;
    }
    return 0;
}

Measured memory_bytes: 256