akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
	int a,b,c;
	bool f = false;
	cin >> a >> b >> c;
	if(a == 7)
	{
		if(b == 5 && c == 5)
			f = true;
	}
	else if(b == 7)
	{
		if(a == 5 && c == 5)
			f = true;
	}
	else if(c == 7)
	{
		if(a == 5 && b == 5)
			f = true;
	}
	cout << (f ? "YES\n" : "NO\n");
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
ans = 0
temp = set(S)
for i in temp:
    if S.count(i) - T.count(i) > ans:
        ans = S.count(i) - T.count(i)
print(ans)


Measured memory_bytes: 3060
while True:
    H, W = [int(n) for n in input().split()]
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i == 0 or i == H-1:
            print('#'*W)
        else:
            print('#'+'.'*(W-2)+'#')
    print()



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

int main()
{
    int k,n;
    cin>>k>>n;
    int a[n+2],s[n+2];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n-1;i++)
        s[i]=a[i+1]-a[i];
        s[n-1]=k-a[n-1]+a[0];
    int maxx=0;
    for(int i=0;i<n;i++)
        if(s[i]>s[maxx]) maxx=i;
    cout<<k-s[maxx]<<endl;
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
XY = list([list(map(int, input().split())) for _ in range(N)])
sum = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum += ((XY[j][0]-XY[i][0])**2 + (XY[j][1]-XY[i][1])**2) ** 0.5
ans = sum * 2 / N
print(ans)


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

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

const int N = 1e5 + 10;

int n;
char s[N];

int main()
{
	cin >> n;
	cin >> s + 1;
	int d = strlen(s + 1);
	for (int i = 1; i <= d; i ++)
	{
		s[i] = (s[i] - 'A' + n) % 26  + 'A';
	}
	cout << s + 1 << endl;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b; cin >> a >> b;
    if( a > 0 )
    {
        cout << "Positive" << endl;
    }
    if( a < 0 && b > 0)
    {
        cout << "Zero" << endl;
    }
    if(b < 0)
    {
        if( (b - a)%2 == 0)
        {
            cout << "Negative" << endl;
        }
        else
        {
            cout << "Positive" << endl;
        }
    }
}

Measured memory_bytes: 256
<?php
 
$rooms     = array_fill_keys(range(1, 10), 0);
$floors    = array_fill_keys(range(1, 3), $rooms);
$buildings = array_fill_keys(range(1, 4), $floors);
 
fscanf(STDIN, '%d', $n);
 
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d %d %d %d', $b, $f, $r, $v);
 
    $buildings[$b][$f][$r] += $v;
}
 
foreach ($buildings as $floors) {
    $floor = array();
    foreach ($floors as $rooms) {
        $floor[] = sprintf(' %s%s', implode(' ', $rooms), PHP_EOL);
    }
    $tenant[] = implode('', $floor);
}
 
echo implode(str_repeat('#', 20) . "\n", $tenant);

Measured memory_bytes: 15408
# -*- coding: utf-8 -*-


# def main():
#     n, m, k = map(int, input().split())
#     A = list(map(int, input().split()))
#     B = list(map(int, input().split()))
#     a = A[0]
#     A2 = [a]
#     b = B[0]
#     B2 = [b]
#     for i in range(1, n):
#         a += A[i]
#         A2.append(a)
# 
#     for i in range(1, m):
#         b += B[i]
#         B2.append(b)
#     max = -2
#     for ia, aa in enumerate(A2):
#         for ib, bb in enumerate(B2):
#             if aa + bb > k:
#                 break
#             if ia + ib > max:
# 
#                 max = ia + ib
#     print(max + 2)
# 

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


    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i + j)
    print(ans)
if __name__ == '__main__':
    answer()

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

void solve(std::vector<long long> A){
    if (A[0]+A[1]+A[2] >= 22) cout << "bust" << '\n';
    else cout << "win" << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::vector<long long> A(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
	int L, R, d, a, b = 0;
	scanf ("%d %d %d", &L, &R, &d);
	
	for (int i = 1; i < 150; i++) {
		a = i * d;
		if (a <= R && a >= L) {
			b++;
		}
	}
	printf ("%d", b);
	return 0;
}	

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

int main() {
  string N;
  cin >> N;
  if (N[1] != N[2]) cout << "No\n";
  else if (N[0] != N[1] && N[2] != N[3]) cout << "No\n";
  else cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 256
// D - joisino's travel
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void warshall_floyd(vvi &D){//1_origin
	rp(relay,1,D.size()) rp(from,1,D.size()) rp(to,1,D.size())
		D[from][to] = min(D[from][to], D[from][relay] + D[relay][to]);
}

#define DIST_MAX 1000000000
#define N_MAX 200
#define R_MAX 8
int N,M,R;
vi RR(R_MAX+1);
vvi D(N_MAX+1, vi(N_MAX+1, DIST_MAX));
int ans_dist = DIST_MAX;

vi visited(R_MAX+1, false);

void dfs(int p, int depth, int dist){
	if(depth >= R) ans_dist = min(ans_dist, dist);
	else
		rp(r, 1, R+1){
			if(visited[r]) continue;
			visited[r] = true;
			dfs(RR[r], depth+1, dist+D[p][RR[r]]);
			visited[r] = false;
		}
}

int main(){
	cin>>N>>M>>R;
	rp(i, 1, R+1) cin>>RR[i];
	rp(i, 0, N+1) D[i][i] = 0;
	rp(i, 1, N+1) D[0][i] = D[i][0] = 0;
	rp(i, 0, M) rp(j, 0, 3){ int a,b,c; cin>>a>>b>>c; D[a][b] = D[b][a] = c; }
	warshall_floyd(D);
	dfs(0, 0, 0);
	cout<< ans_dist <<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> es(n+1), ws(n+1);
    for(int i=0; i<n; ++i){
        es[i+1]=es[i]+(s[i]=='E');
        ws[i+1]=ws[i]+(s[i]=='W');
    }
    int ans=n;
    for(int i=0; i<n; ++i){
        ans=min(ans, ws[i]+(es[n]-es[i+1]));
    }
    cout << ans << endl;
    return 0;
}


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

static const int N = 36 + 1;

class Card {
  public:
    int value;
    char suit;
};

void bubbleSort(Card* c, int n);
void selectionSort(Card* c, int n);
void stable(Card* c1, Card* c2, int n);
void trace(Card* c, int n);

int main() {
  Card c1[N], c2[N];
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c1[i].suit >> c1[i].value;
    c2[i] = c1[i];
  }

  bubbleSort(c1, n);
  selectionSort(c2, n);

  trace(c1, n);
  printf("Stable\n");
  trace(c2, n);
  stable(c1, c2, n);

  return 0;
}

void trace(Card* c, int n) {
  for (int i = 0; i < n; ++i) {
    if (i) { printf(" "); }
    printf("%c%d", c[i].suit, c[i].value);
  }
  printf("\n");
}

void bubbleSort(Card* c, int n) {
  for (int i = 0; i < n; ++i) {
    for (int j = n - 1; j > i; --j) {
      if (c[j].value < c[j - 1].value) {
        Card t = c[j];
        c[j] = c[j - 1];
        c[j - 1] = t;
      }
    }
  }
}

void selectionSort(Card* c, int n) {
  for (int i = 0; i < n; ++i) {
    int mini = i;
    for (int j = i + 1; j < n; ++j) {
      if (c[j].value < c[mini].value) { mini = j; }
    }
    Card t = c[i];
    c[i] = c[mini];
    c[mini] = t;
  }
}

void stable(Card* c1, Card* c2, int n) {
  for (int i = 0; i < n; ++i) {
    if ((c1[i].value != c2[i].value) || (c1[i].suit != c2[i].suit)) { printf("Not stable\n"); return; }
  }
  printf("Stable\n");
}

Measured memory_bytes: 1152
n,m=[int(s)for s in input().split(" ")]
intr=[int(input())for i in range(n)]
crit=[int(input())for i in range(m)]
vote=[0 for i in range(n)]
for c in crit:
    for i in range(n):
        if intr[i]<=c:
            vote[i]+=1
            break
print(vote.index(max(vote))+1)

Measured memory_bytes: 7792
import math
D,G = map(int, input().split())

p = [0] * D
c = [0] * D

for i in range(D):
    p[i], c[i] = map(int, input().split())


ans = 10000
for n in range(2**D):
    bnum = (bin(n)[2:]).zfill(D)
    score = 0
    cnt = 0
    for i,s in enumerate(bnum):
        if s == "1":
            #print(i, p[i], s[i])
            score += (i+1)*100*p[i] + c[i]
            cnt += p[i]
    
    #print(score, bnum)
    if score >= G:
        ans = min(ans, cnt)
    else:
        for i,s in enumerate(reversed(bnum)):
            if s == "0":
                rest = G - score
                if rest / ((D-i)*100) <= p[i]:
                    #print(bnum, i, rest, cnt , math.ceil(rest / ((D-i)*100)))
                    cnt += math.ceil(rest / ((D-i)*100))
                    ans = min(ans, cnt)


print(ans)

Measured memory_bytes: 3188
function main(input){
  const S = input.split('\n')[0].split('');
  const K = parseInt(input.split('\n')[1]);

  for(var i=0;i<S.length && i<K;i++){
    if(S[i]!='1'){
      console.log(S[i]);
      return;
    }
  }
  console.log(1);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,q;
    cin>>n>>k>>q;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        a[i]=k-q;
    }
    for(int i=0;i<q;i++){
        int score;
        cin>>score;
        a[score-1]++;
    }
    for(int i=0;i<n;i++){
        if(a[i]<=0)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}


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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    string s, t;
    cin >> s >> t;

    int ns = s.size();
    int nt = t.size();

    s += s;
    map<char, vi> m;
    REP(i, ns * 2) m[s[i]].pb(i+1);
    REP(i, nt) {
        if (m.count(t[i]) == 0) {
            cout << "-1" << endl;
            return 0;
        }
    }

    int pos = 0;
    ll ans = 0;
    REP(i, nt) {
        char c = t[i];
        auto it = upper_bound(m[c].begin(), m[c].end(), pos);
        ans += *it - pos;
        pos = *it > ns ? *it - ns : *it;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

LL k,a,b;

int main()
{
    cin>>k>>a>>b;
    if(k<a||a+2>=b)cout<<k+1<<endl;
    else cout<<a+(k-(a-1))/2*(b-a)+(k-(a-1))%2<<endl;
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;




int main() {

	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout << "No" << endl;
	}
	else if (a == b || b == c || a == c) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#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;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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);}

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

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

  ll n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> block(n);
  vector<vector<int>> friends(n);
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    friends[a].push_back(b);
    friends[b].push_back(a);
    uf.unite(a,b);
  }
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    --c;
    --d;
    block[c].push_back(d);
    block[d].push_back(c);
  }
  vector<int> ans(n);
  rep(i, n) {
    ans[i] = uf.size(i)-friends[i].size()-1;
    for(int hater: block[i]) {
      if (uf.same(i, hater)) ans[i]--;
    }
  }
  rep(i,n) {
    printf("%d%c", ans[i], (i == n-1)?'\n':' ');
  }
  return 0;
}


Measured memory_bytes: 12664
// AOJ 2784 Similarity of Subtrees
// 2018.4.15 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 数値のハッシュ関数
#define HASHSIZ 500009
typedef struct { unsigned long long id; int c; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;

void insert(unsigned long long id)
{
	HASH *p = hash + (int)(id % HASHSIZ);
	while (p->id) {
		if (p->id == id) { p->c++; return; }
		if (++p == hashend) p = hash;
	}
	p->id = id, p->c = 1;
}

// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define M   1000000007
#define MAX 100002
int hi[MAX], *to[MAX];

long long dfs(int node)
{
	int i;
	unsigned long long ans;
	
	ans = 1;
	for (i = 0; i < hi[node]; i++) ans += (long long)dfs(to[node][i]) * M;
	insert(ans);
	return ans;
}

int main()
{
	int N, a, b, i, j;
	long long ans;
	int *memo;

	N = in();
	memo = malloc(N<<3);
	j = 0; for (i = 1; i < N; i++) {
		memo[j++] = a = in(), memo[j++] = b = in();
		hi[a]++;
	}
	for (i = 1; i <= N; i++) if (hi[i]) to[i] = malloc(hi[i]<<2);
	memset(hi, 0, N<<2);
	j = 0; for (i = 1; i < N; i++) {
		a = memo[j++], b = memo[j++];
		to[a][hi[a]++] = b;
	}

	dfs(1);

	ans = 0;
	for (i = 0; i < HASHSIZ; i++) {
		if (j = hash[i].c) ans += (long long)j*(j-1) >> 1;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 19420
h, w = map(int, input().split())

m = []

for i in range(h):
    l = list(input())
    m.append([ '#' if i=='#' else 0 for i in l])

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            for u in range(3):
                for v in range(3):
                    if u==1 and v==1:
                        pass
                    else:
                        try:
                            y = i+u-1
                            x = j+v-1
                            if y < 0 or x < 0:
                                continue

                            if m[y][x] != '#':
                                m[y][x] += 1

                        except:
                            pass

for l in m:
    s = map(str, l)
    print(''.join(s))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int mod = 1000000007;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	if (s.substr(0, n / 2) == s.substr(n / 2, n / 2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<int> p(n);
  set<int> q;
  rep(i,n){
    cin>>p[i];
    q.insert(p[i]);
  }

  int m=q.size();

  cout << ((n-m)%2==0?m:m-1) << endl;

}

Measured memory_bytes: 5376
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
      
      	if(a+b+1<c){
                System.out.println(a+b*2+1);
        }
      else{
              System.out.println(b+c);
      }
        // 出力

    }
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

std::vector<ll> fac(510000, 1), finv(510000, 1), inv(510000, 1);

void c4_init(ll m) {
  for (ll i = 2; i < 510000; i++) {
    fac[i] = fac[i - 1] * i % m;
    inv[i] = m - inv[m % i] * (m / i) % m;
    finv[i] = finv[i - 1] * inv[i] % m;
  }
}

ll c4(ll n, ll k, ll m) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % m) % m;
}

const ll M = 1000000007;

signed main() {
  c4_init(M);
  ll N, K;
  cin >> N >> K;
  vector<ll> v(N);
  rep(i, N) cin >> v[i];
  sort(begin(v), end(v));
  ll _max = 0, _min = 0;
  rep(i, N) {
    _max += (v[i] * c4(i, K - 1, M)) % M;
    _max %= M;
  }
  rep(i, N) {
    _min += M - (v[i] * c4(N - 1 - i, K - 1, M)) % M;
    _min %= M;
  }

  ll ans = (_max + _min) % M;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13056
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int W = sc.nextInt();
    int[] w = new int[N];
    int[] v = new int[N];
    for (int i = 0; i < N; i++) {
      w[i] = sc.nextInt();
      v[i] = sc.nextInt();
    }
    sc.close();

    int v_sum = 0;
    for (int vi : v) v_sum += vi;

    long[] dp = new long[v_sum + 1];
    Arrays.fill(dp, -1);
    dp[0] = 0;

    long ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = v_sum; v[i] <= j; j--) {
        if (dp[j - v[i]] < 0) continue;
        long dpj = dp[j - v[i]] + w[i];
        if (W < dpj) continue;
        if (dp[j] < 0 || dpj < dp[j]) {
          dp[j] = dpj;
          ans = Math.max(ans, j);
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23380
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //String[] vals = sc.nextLine().split(" ");
        int N = getInt(sc.nextLine());
        List words = new ArrayList<String>();
        String before = sc.nextLine();
        words.add(before);

        for(int i = 1;i < N;i++){
            String now = sc.nextLine();
            if(words.contains(now)){
                System.out.println("No");
                return;
            }
            if(before.charAt(before.length()-1) != now.charAt(0)){
                System.out.println("No");
                return;
            }
            before = now;
            words.add(now);
        }
        System.out.println("Yes");

        sc.close();
    }
    static int getInt(String val) {return Integer.parseInt(val);}
    static long getLong(String val) {return Long.parseLong(val);}
}

Measured memory_bytes: 23380
#include <iostream> 
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 100000 +5;
int n, m, tot, head[maxn], color[maxn];
struct edge {
	int to, nxt;
} G[maxn << 1];

inline void add_edge (int u, int v) {
	tot ++;
	G[tot].to = v;
	G[tot].nxt = head[u];
	head[u] = tot;
}

void dfs(int x, int now = 0, int fa = 0) {
	color[x] = now, now ^= 1;
    for (int j = head[x]; j; j = G[j].nxt) {
        if (color[G[j].to] == -1) dfs(G[j].to, now, x);
        if (color[G[j].to] != now) {
        	printf ("%lld\n", (long long)n * (n - 1) / 2 - m);
        	exit(0);
		}
    }
}

int main() {
	scanf ("%d %d", &n, &m);
	int u, v;
	for (int i = 1; i <= m; i++) {
		scanf ("%d %d", &u, &v);
		add_edge (u, v); add_edge(v, u);
	}
	memset (color, 255, sizeof (color));
	dfs(1);
	int a = 0, b = 0;
	for (int i = 1; i <= n; i++) {
		if (color[i]) a++;
		else b++;
	}
	printf ("%lld", (long long)a * b - m);
	return 0;
}

Measured memory_bytes: 2944
def yakusu(n):
        result = []
        for i in range(1,int(n**0.5)+1):
                if n % i == 0:
                        result.append(i)
                        if i != n // i:
                                result.append(n//i)
        result.sort()
        return result
yakusu = yakusu(int(input()))
m = len(yakusu)
if m % 2 ==0:
        print(yakusu[m//2-1]+yakusu[m//2+1-1]-2)
else:
        print((yakusu[m//2]-1)*2)

Measured memory_bytes: 3316
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2/9/2019, 9:03:35 PM
# Powered by Visual Studio Code
#

ary = Array.new(4){0}
3.times{
  a, b = gets.chomp.split(" ").map{|i| i.to_i}
  a -= 1
  b -= 1
  ary[a] += 1
  ary[b] += 1
}
if ary.max == 3
  puts "NO"
else
  puts "YES"
end

Measured memory_bytes: 1916
def solve(N, A):
    ret = 0
    ref = {}
    for idx, a in enumerate(A):
        ith_val = idx - a
        ret += ref[ith_val] if ith_val in ref else 0
        ref[idx + a] = ref.get(idx + a, 0) + 1
    return ret

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

Measured memory_bytes: 111408
using System;

namespace ABC055D
{
    class Program
    {
        static readonly bool SHEEP = true;
        static readonly bool WOLF = false;
        static void Main(string[] args)
        {
            int N = Int32.Parse(Console.ReadLine());
            string str = Console.ReadLine();

            bool[] arr = new bool[N];

            foreach (var item in new bool[][] 
            {
                new bool[]{ SHEEP, SHEEP }, 
                new bool[]{ SHEEP, WOLF },
                new bool[]{ WOLF, SHEEP },
                new bool[]{ WOLF, WOLF }
            })
            {
                arr[0] = item[0];
                arr[1] = item[1];

                bool tail = arr[1] ^ (arr[0] ^ ('o' == str[0]));

                for (int i = 1; i < N - 1; i++)
                {
                    arr[i + 1] = arr[i - 1] ^ (arr[i] ^ ('o' == str[i]));
                }

                bool head = arr[N - 2] ^ (arr[N - 1] ^ ('o' == str[N - 1]));

                if (tail == arr[N - 1] && head == arr[0])
                {
                    foreach (bool res in arr)
                    {
                        Console.Write(res ? 'S' : 'W');
                    }
                    Console.WriteLine();
                    return;
                }

            }

            Console.WriteLine(-1);
            return;
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
    ios::sync_with_stdio(false);
    cin>>s;
    int n = s.length();
    s="s"+s;
    bool flag = true;
    if(s[1]!='1'||s[n]!='0'){
        flag = false;
    }
    int l = 1,r=n-1;
    while (l<r){
        if(s[l]!=s[r]){
            flag = false;
        }
        l++,r--;
    }
    if(!flag){
        cout<<-1<<endl;
        return 0;
    }
    int tmp = 1;
    for(int i=1;i<n;i++){
        if(s[i]=='1'){
            cout<<tmp<<' '<<i+1<<endl;
            tmp = i+1;
        } else{
            cout<<tmp<<' '<<i+1<<endl;
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)



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

 ll k,x;
  cin >> k >> x;
 if(500*k>=x) cout << "Yes" << endl;
 else cout << "No" << endl; 
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios std::ios::sync_with_stdio(false)
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", (n))
#define pdd(n,m) printf("%d %d\n", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define mm(a,n) memset(a, n, sizeof(a))
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define il inline
#define int long long
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define pi 3.14159265358979323
#define debug(x) 			  cout <<#x<<": "<<x<<endl;
#define debug2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
using namespace std;
const ll INF (0x3f3f3f3f3f3f3f3fll);
const int inf (0x3f3f3f3f);
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
template<typename T>void Out(T x){if(x<0)putchar('-'),x=-x;if(x>9)Out(x/10);putchar(x%10+'0');}
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);}
double pow_mod(double x , int n)
{
	double res = 1;
	while(n)
	{
		if(n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res; 
}
const int N = 2e5 + 10;
int n , a[N] , aa[N] , ans , res;
signed main()
{
	ios;
	int a = 100;
	int x;
	cin >> x; 
	rep(i , 1 , 1e7)
	{
		a *= 1.01;
		if(a >= x) return cout << i << '\n' , 0; 
	}
	return 0;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define F first 
#define S second 
#define endl "\n"
#define Endl "\n"
#define emdl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
bool sortBy(const pair<int,int> &a,const pair<int,int> &b){
	if(a.F==b.F)
		return a.S<b.S;
	return a.F>b.F;
}

// #define MAXN 1001
// int pf[MAXN]; 
// void sieve(){
// 	long long int i,j; 
//     pf[1] = 1; 
//     for (i=2; i<MAXN; i++) 
//     pf[i] = i;   
//     for (i=2; i*i<MAXN; i++){ 
//         if (pf[i] == i){
//             for (j=i*i; j<MAXN; j+=i) 
//                 if (pf[j]==j) 
//                     pf[j] = i; 
//         } 
//     } 
// }
// vector<int> factors(int x){ 
//     vector<int> ret; 
//     while (x != 1){ 
// 		int fact=pf[x];
//         ret.push_back(pf[x]); 
// 		while(fac!=1&&x%fact==0)
//         x/=fact; 
//     } 
//     return ret; 
// } 
// set<long long int>poww;
// void init(){
// 	long long int temp=1;
// 	for(int i=1;i<43;i++){
// 		poww.insert(temp);
// 		temp*=2;
// 	}
// }  


int main() {		
	ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
	int qwe=1;
	//cin>>qwe;
	//init();
	// sieve();
	while(qwe--){
       int s,d,t;
       cin>>d>>t>>s;

       if(s*t>=d){
           cout<<"Yes";
       }else{
           cout<<"No";
       }



	}

	return 0;
}


Measured memory_bytes: 3604
from collections import Counter
N=int(input())
a=list(map(int,input().split()))

answer=0
count_sum=0

counter = Counter(a)
for num, cnt in counter.most_common():
#  print (num, cnt)
  count_sum+=cnt
  if cnt>num:
    answer += cnt-num
  elif cnt<num:
    answer += cnt
answer+=N-count_sum
print(answer)


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

import sys
from collections import defaultdict

dyna_list = defaultdict(list)   # Key String, Value List

n,q = map(int, sys.stdin.readline().split())
for i in range(q):
    query = sys.stdin.readline().split()  # use in string
    ope = query[0]
    list_id = query[1]

    if ope == '0':      # Push back
        dyna_list[list_id].append(query[2])
    elif ope == '1':    # Print
        print(' '.join(dyna_list[list_id]))
    elif ope == '2':    # Clear
        dyna_list[list_id].clear()




Measured memory_bytes: 44304
#include<bits/stdc++.h>
const int N=133333;
typedef long long i64;
#define LC lc[ns]
#define RC rc[ns]
int n;
i64 L=0,R=0,M;
struct pos{
	i64 x,y;
}mem[N*40],*mp=mem;
struct node{
	int lc,rc,sz,ap;
	i64 dep;
	pos*as;
	void ac(int x){(lc?rc:lc)=x;}
	void alloc(int n){as=mp,mp+=n;}
	void push(const pos&w){
		if(ap&&as[ap-1].y<=w.y)return;
		as[ap++]=w;
	}
	void mg(node&a,node&b){
		pos*ls=a.as,*rs=b.as;
		int lp=a.ap,rp=b.ap,pp=0;
		i64 lim=M+dep*2;
		ap=0;
		int i,j;
		for(i=0,j=0;i<rp;++i){
			for(;j<lp&&ls[j].x+rs[i].y<=lim;++j);
			if(j)mp[pp++]=(pos){rs[i].x,ls[j-1].y};
		}
		j=0;
		for(i=pp-1;i>=0;--i){
			for(;j<pp&&mp[j].x<mp[i].y;push(mp[j++]));
			push((pos){mp[i].y,mp[i].x});
		}
		for(;j<pp;push(mp[j++]));
	}
}ns[N];
void f1(int x){
	node&w=ns[x];
	if(w.lc){
		w.LC.dep+=w.dep;
		w.RC.dep+=w.dep;
		f1(w.lc);
		f1(w.rc);
		w.sz=w.LC.sz+w.RC.sz;
		if(w.LC.sz<w.RC.sz)std::swap(w.lc,w.rc);
		w.alloc(w.RC.sz*2);
	}else{
		w.sz=1;
		w.alloc(1);
	}
}
void f2(int x){
	node&w=ns[x];
	if(w.lc){
		f2(w.lc);
		f2(w.rc);
		w.mg(w.LC,w.RC);
	}else{
		w.ap=0;
		w.push((pos){w.dep,w.dep});
	}
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;++i){
		int f,d;
		scanf("%d%d",&f,&d);
		ns[i].dep=d;
		ns[f].ac(i);
		R+=d;
	}
	f1(1);
	while(L<R){
		M=L+R>>1;
		f2(1);
		if(ns[1].ap)R=M;
		else L=M+1;
	}
	printf("%lld\n",L);
	return 0;
}

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



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

#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << "\n"
#define _ << " _ " <<
#define ll long long

using namespace std;

int arr[200100];
map <int, int> fil, num;

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

  int n, m;
  cin >> n >> m;
  FOR(i, 1, n + 1) {
    int x;
    cin >> x;
    arr[i] = x;
    fil[x - num[x]]++;
    num[x]++;
  }
  int tr = 0;
  REP(i, n) {if (!fil[i + 1]) tr++;}

  REP(i, m) {
    int a, b;
    cin >> a >> b;
    /*REP(i, n + 1) {cout << fil[i] << " ";}
    cout << endl;*/

    int bef = arr[a];
    num[bef]--;
    fil[bef - num[bef]]--;
    if (fil[bef - num[bef]] == 0 && bef - num[bef] > 0) tr++;
   /* REP(i, n + 1) {cout << fil[i] << " ";}
    cout << endl;*/

    arr[a] = b;
    fil[b - num[b]]++;
    if (fil[b - num[b]] == 1 && b - num[b] > 0) tr--;
    num[b]++;
  /* REP(i, n + 1) {cout << fil[i] << " ";}
    cout << endl;*/

    cout << tr << endl;
  }


  return 0;
}


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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

void dfs(string s, char mx, ll N)
{
    if (s.length() == N)
    {
        cout << s.c_str() << endl;
    }
    else
    {
        for (char c = 'a'; c <= mx; c++)
        {
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx), N);
        }
    }
}

int bfs(int a, int b, int h, int w, char tmp[][101])
{
    int ans[101][101] = {0};
    char c[101][101] = {0};
    queue<pair<int, int>> s;

    for (int i = 0; i<=h; i++){
        for(int j=0; j<=w; j++){
            c[i][j] = tmp[i][j];
        }
    }

    s.push(make_pair(a, b));

    while (s.size() > 0)
    {

        pair<int, int> tmp = s.front();
        s.pop();
        c[tmp.first][tmp.second] = '#';
        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (tmp.first + i < 1 || tmp.first + i > h)
                {
                    continue;
                }
                if (tmp.second + j < 1 || tmp.second + j > w)
                {
                    continue;
                }
                if (i != 0 && j != 0)
                {
                    continue;
                }
                if (i == 0 && j == 0)
                {
                    continue;
                }
                if (c[tmp.first + i][tmp.second + j] == '#')
                {
                    continue;
                }
                c[tmp.first + i][tmp.second + j] = '#';
                if (ans[tmp.first + i][tmp.second + j] == 0)
                {
                    ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1;
                }
                else
                {
                    ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1);
                }
                s.push(make_pair(tmp.first + i, tmp.second + j));
            }
        }
    }

    int asd = 0;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            asd = max(a, ans[i][j]);
        }
    }

    return asd;
}


int main()
{
    ll N;
    cin >> N;

    map<ll, ll> m;

    for(int i=0; i<N; i++){
        ll tmp;
        cin >> tmp;

        if(tmp != 0){
            m[tmp-1]++;
        }
        m[tmp]++;
        if(tmp < 100000){
            m[tmp+1]++;
        }
    }

    int ans = 0;
  for( auto i = m.begin(); i != m.end() ; ++i ) {
      ans = max(ans, (int)i->second);
  }

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

Measured memory_bytes: 6144
N,W = map(int, input().split())
wvs = []
for i in range(N):
    w,v = map(int, input().split())
    wvs.append((w,v))
# dp : n個入っていて、合計がwのときの最大値
w0 = wvs[0][0]
dp = [[[-1]*(330) for i in range(110)] for k in range(110)]
dp[0][0][0] = 0
for i in range(N):
    w, v = wvs[i]
    dw = w-w0
    for j in range(i+1):
        for k in range(310):
            # if k - dw >= 0:
            # if dp[i][j][j] == -1:continue
            dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k])
            dp[i+1][j+1][k+dw] = max(dp[i][j][k]+v, dp[i+1][j+1][k+dw])

d = dp[N]
ans = 0
for j in range(N+1):
    if W-j*w0 >= 0:
        a = max(d[j][:W-j*w0+1])
        ans = max(ans, a)
print(ans)

Measured memory_bytes: 106616
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdlib>  // abs() for integer
#include <math.h>     // math.h をインクルードする！
#include <iomanip> // 小数点以下のやつ
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    ll a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    ll speed = v - w;
    ll dis = max(a,b) - min(a,b);
    if (speed * t >= dis) cout << "YES";
    else cout << "NO";
    
}

Measured memory_bytes: 3632
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias INCOME = Tuple!(long, "after", long, "salary");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    auto a = new string[](n);
    auto b = new string[](m);
    foreach (ref e; a)
        e = sread();
    foreach (ref e; b)
        e = sread();
    bool flag;
    foreach (i; iota(n - m + 1))
    {
        foreach (j; iota(n - m + 1))
        {
            bool check = true;
            foreach (col; iota(m))
            {
                foreach (row; iota(m))
                {
                    if (a[i + col][j + row] != b[col][row])
                        check = false;
                }
            }
            flag = flag || check;
        }
    }

    if (flag)
        writeln("Yes");
    else
        writeln("No");
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int g[15][15];

int main() {
    int n;
    cin >> n;
    rep(i,n)rep(j,n) g[i][j] = -1;
    rep(i,n) {
        int a;
        cin >> a;
        rep(j,a) {
            int x, y;
            cin >> x >> y;
            x--;
            g[i][x] = y;
        }
    }
    int ans = 0;
    rep(i,1<<n) {
        vector<int> d(n);
        rep(j,n) {
            if (i>>j&1) d[j] = 1;
        }
        bool ok = true;
        rep(j,n) {
            if (d[j]) {
                rep(k,n) {
                    if (g[j][k] == -1) continue;
                    if (g[j][k] != d[k]) ok = false;
                }
            }
        }
        if (ok) ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Lining up the cards
public class Main{

	int n, K;
	int[] a;
	boolean[] u;
	Set<String> s;
	
	void f(int k, String t){
		if(k==K){
			s.add(t);return;
		}
		for(int i=0;i<n;i++){
			if(u[i])continue;
			u[i] = true;
			f(k+1, t+a[i]);
			u[i] = false;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			K = sc.nextInt();
			if((n|K)==0)break;
			a = new int[n];
			for(int i=0;i<n;i++)a[i]=sc.nextInt();
			u = new boolean[n];
			s = new HashSet<String>();
			f(0,"");
			System.out.println(s.size());
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <vector>
#include <memory>

using namespace std;

enum {
	NA = -1,
};


struct node {
	int id;
	int l;
	int r;
	node() :id(NA), l(NA), r(NA) {
	}
};


inline void show_preorder(vector<node> v, int node_id) {
	cout << " " << v[node_id].id;
	if(v[node_id].l != NA)	show_preorder(v, v[node_id].l);
	if(v[node_id].r != NA)  show_preorder(v, v[node_id].r);
}

inline void show_inorder(vector<node> v, int node_id) {
	if (v[node_id].l != NA)	show_inorder(v, v[node_id].l);
	cout << " " << v[node_id].id;
	if (v[node_id].r != NA)  show_inorder(v, v[node_id].r);
}

inline void show_postorder(vector<node> v, int node_id) {
	if (v[node_id].l != NA)  show_postorder(v, v[node_id].l);
	if (v[node_id].r != NA)  show_postorder(v, v[node_id].r);
	cout << " " << v[node_id].id;
}

int main() {
	const int N_MAX = 25;
	int n;
	cin >> n;

	vector<node> nodes;
	nodes.resize(n);

	vector<bool> is_root_flags;
	is_root_flags.resize(n, true);

	for (int i = 0; i < n; i++) {
		int id, l, r;
		cin >> id >> l >> r;
		nodes[id].id = id;
		nodes[id].r = r;
		nodes[id].l = l;
		if(l != NA)is_root_flags[l] = false;
		if(r != NA)is_root_flags[r] = false;
	}

	int root_id = NA;
	root_id = 0; 
	for (int i = 0; i < n; i++) {
		if (is_root_flags[i])
			root_id = i;
	}

	cout << "Preorder\n";
	show_preorder(nodes, root_id);
	cout << "\n";

	cout << "Inorder\n";
	show_inorder(nodes, root_id);
	cout << "\n";

	cout << "Postorder\n";
	show_postorder(nodes, root_id);
	cout << "\n";

	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll n, m, q;
ll ans;
vector<tuple<ll, ll, ll, ll>> g;

void rec(int num, int ko, vector<ll> A) {
    if (ko == n) {
        //計算する
        ll sum = 0;
        for (ll i = 0; i < q; ++i) {
            ll a = get<0>(g[i]);
            ll b = get<1>(g[i]);
            ll c = get<2>(g[i]);
            ll d = get<3>(g[i]);

            if (A[b] - A[a] == c) {
                sum += d;
            }
        }
        ans = max(ans, sum);
        return;
    }

    for (ll i = num; i <= m; ++i) {
        if (i == 0) continue;

        A.push_back(i);
        rec(i, ko + 1, A);
        A.pop_back();
    }
}

int main() {

    cin >> n >> m >> q;

    for (ll i = 0; i < q; ++i) {
        ll a, b, c, d; cin >> a >> b >> c >> d;
        --a; --b;
        g.push_back(make_tuple(a, b, c, d));
    }

    ans = 0;
    vector<ll> tmp;
    rec(0, 0, tmp);

    cout << ans << endl;
}

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N, M, X;
    cin>>N>>M>>X;
    vi C(N);
    vvi A(N, vi(M));
    REP(i, 0, N){
        cin >> C[i];
        REP(j, 0, M){
            cin >> A[i][j];
        }
    }
    int count = (1<<N);
    int min_price = __INT_MAX__;
    vi bitA(N);
    REP(i, 0, count){
        int bit = i;
        REP(j, 0, N){
            bitA[j] = bit % 2;
            bit = (bit >> 1);
            //cout << bitA[j] << " ";
        }
        //cout << endl;
        vi sum(M, 0);
        int price = 0;
        REP(j, 0, N){
            if(bitA[j]){            
                REP(k, 0, M){
                    sum[k] += A[j][k];
                }
                price += C[j];
            }
        }

        bool match = true;
        REP(k, 0, M){
            if(sum[k] < X) match = false;
        }
        if(match) min_price = min(price, min_price);
    }
    if(min_price == __INT_MAX__) min_price = -1;
    cout << min_price << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,x) for(int i = 0; i < x; i++)
typedef long long ll;
using namespace std;
const ll N = 1e9+7;

int main(){
    int n,l; cin >> n >> l;
    ll sum = 0;
    rep(i,n){
        sum += i;
    }
    sum += l*n;
    ll ans = sum;
    if(l >= 0) ans -= l;
    else if(l < 0 && l + n <= 0) ans -= l + n-1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng,l,ans,q;
ll x[500005],y[500005],r[500005];
char s[500005],t[500005];
bool flag,dame;

int main(){
    cin >> a >> b >> c;
	if(b >= a * c){
		p(c);
	}else{
		p(b/a);
	}

	return 0;
}


Measured memory_bytes: 24064