akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;


int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> adj[n];
	for(int i = 0; i < m; i++){
		int x,y;
		cin >> x >> y;
		adj[--x].push_back(--y);
		adj[y].push_back(x);
	}
	queue<int> q;
	int dis[n], vis[n];
	memset(dis,0,sizeof(dis));
	memset(vis,0,sizeof(vis));
	vis[0] = 1;
	q.push(0);
	while(!q.empty()){
		int s = q.front(); q.pop();
		
		for(auto e : adj[s]){
			if(vis[e]) continue;
			dis[e] = s;
			vis[e] = 1;
			q.push(e);
		}
	}
	for(int i = 0; i<n; i++ ){
		if(!vis[i]){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes\n";
	for(int i = 1; i < n; i++){
		cout << dis[i]+1 << "\n";
	}
}


Measured memory_bytes: 10812
#include <cstdio>

const int MAXN = 1e5 + 5;

int n;
int height[MAXN];

bool judge() {
    for (int i = n - 1; i; --i) {
        if (height[i] > height[i + 1])
            --height[i];
        if (height[i] > height[i + 1])
            return false;
    }
    return true;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i<= n; ++i) {
        scanf("%d", &height[i]);
    }
    if (judge())
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 512
from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = int(readline())
    if N == 0:
        return False
    P = [tuple(map(int, readline().split())) for i in range(N)]
    YS = set(y for x, y in P)
    Q = P[:]
    for i in range(N-1):
        x0, y0 = P[i]; x1, y1 = P[i+1]
        if y0 != y1:
            for y in YS:
                if y0 < y < y1 or y1 < y < y0:
                    x = (x1 - x0)/(y1 - y0)*(y - y0) + x0
                    assert x0 < x < x1 or x1 < x < x0
                    Q.append((x, y))
    Q.sort()
    def f(px, py, qx, qy):
        if py == qy:
            return abs(px - qx)
        return ((px - qx)**2 + (py - qy)**2)**.5
    L = len(Q)
    INF = 10**18
    que = [(0, 0, L-1)]
    dist = {(0, L-1): 0}
    dd = ((1, -1), (1, 0), (0, -1), (-1, 0), (0, 1), (1, 1), (-1, -1), (-1, 1))
    while que:
        cost, a, b = heappop(que)
        if cost < dist[a, b]:
            continue
        if a == b:
            write("%.16f\n" % cost)
            break
        ax, ay = Q[a]; bx, by = Q[b]
        for da, db in dd:
            na = a + da; nb = b + db
            if not 0 <= na <= nb < L:
                continue
            cx, cy = Q[na]; dx, dy = Q[nb]
            if cy != dy:
                continue
            n_cost = cost + f(ax, ay, cx, cy) + f(bx, by, dx, dy)
            key = (na, nb)
            if n_cost < dist.get(key, INF):
                dist[key] = n_cost
                heappush(que, (n_cost, na, nb))
    else:
        write("-1\n")
    return True
while solve():
    ...


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 301;

double dp[maxn][maxn][maxn];

int n;

int tot;

double solve(int cnt1, int cnt2, int cnt3) {
	// printf("cnt1: %d cnt2: %d cnt3: %d\n",cnt1, cnt2, cnt3);
	if(cnt1 == 0 && cnt2 == 0 && cnt3 == 0){
		// printf("halo\n");
		return 0;
	}
	if(fabs(dp[cnt1][cnt2][cnt3] + 1) > eps){return dp[cnt1][cnt2][cnt3];}
	double ans1 = 0, ans2 = 0, ans3 = 0;
	int sisa = n - cnt1 - cnt2 - cnt3;

	if(cnt1 > 0){
		ans1 = ((double)cnt1/(double)(n - sisa))*solve(cnt1-1, cnt2, cnt3);	
	}
	if(cnt2 > 0){
		ans2 = ((double)cnt2/(double)(n - sisa))*solve(cnt1+1, cnt2-1, cnt3);	
	}
	if(cnt3 > 0){
		ans3 = ((double)cnt3/(double)(n - sisa))*solve(cnt1, cnt2+1, cnt3-1);
	}
	// printf("ans1 : %lf ans2 : %lf ans3 : %lf\n",ans1,ans2,ans3);
	// printf("cnt1: %d cnt2: %d cnt3: %d\n",cnt1, cnt2, cnt3);
	
	return dp[cnt1][cnt2][cnt3] = ((double)n / (double)(n - sisa)) +  ans1 + ans2 + ans3;
}

int main(){
	int i,j,k;
	for(i=0;i<maxn;i++){
		for(j=0;j<maxn;j++){
			for(k=0;k<maxn;k++){
				dp[i][j][k] = -1;
			}
		}
	}

	scanf("%d",&n);
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(i=0;i<n;i++){
		int bil;
		scanf("%d",&bil);
		if(bil == 1){cnt1++;}
		else if(bil == 2){cnt2++;}
		else{cnt3++;}
	}
	// printf("cnt1: %d cnt2: %d cnt3: %d\n",cnt1,cnt2,cnt3);
	tot = cnt1 + cnt2 + cnt3;
	printf("%.10lf\n",solve(cnt1, cnt2, cnt3));
	return 0;
};

Measured memory_bytes: 213376
N,M = map(int,input().split())
A = [int(a) for a in input().split()]
BC = [[int(x) for x in input().split()] for _ in range(M)]

BC.sort(key=lambda x:x[1], reverse=True)

Added_list = []
for B,C in BC:      
    Added_list += [C]*B
    if len(Added_list)>=N:
        Added_list = Added_list[:N]
        break

A += Added_list
A.sort(reverse=True)
print(sum(A[:N]))


Measured memory_bytes: 90776
// Problem : D - RGB Triplets
// Contest : AtCoder - AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n;
string s;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>s;
    int cntR = 0, cntG = 0, cntB = 0;
    for(int i=n-1;i>=0;i--){
        cntR += (s[i] == 'R');
        cntG += (s[i] == 'G');
        cntB += (s[i] == 'B');
    }
    int ans = 0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            int k = 2*j-i;
            if(k >= n) continue;
            if(s[i] == s[j] || s[i] == s[k] || s[j] == s[k]) continue;
            ans++;
        }
    }
    cout<<cntR*cntG*cntB - ans<<endl;
    return 0;
}


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

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

typedef long long ll;
const ll MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
  int N, M;
  static std::pair<int, int> AB[MAX_N];

  std::cin >> N >> M;
  rep(i, N) {
    int A, B;
    std::cin >> A >> B;
    AB[i] = std::make_pair(A, B);
  }
  std::sort(AB, AB + N);

  std::priority_queue<int> pq;
  ll ans = 0;
  int i = 0;
  for(int t = 1; t <= M; ++t) {
    while(i < N and AB[i].first <= t) {
      pq.push(AB[i].second);
      ++i;
    }
    if(not pq.empty()) {
      ans += pq.top(); pq.pop();
    }
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    string S;
    int K;
    cin >> S >> K;
    int B = S.size();
    set<string> T;
    for (int i = 0; i < B; i++){
        string A = "";
        A += S.at(i);
        T.insert(A);
    }
    for (int i = 0; i < B - 1; i++){
        string A = "";
        A += S.at(i);
        A += S.at(i + 1);
        T.insert(A);
    }
    for (int i = 0; i < B - 2; i++){
        string A = "";
        A += S.at(i);
        A += S.at(i + 1);
        A += S.at(i + 2);
        T.insert(A);
    }
    for (int i = 0; i < B - 3; i++){
        string A = "";
        A += S.at(i);
        A += S.at(i + 1);
        A += S.at(i + 2);
        A += S.at(i + 3);
        T.insert(A);
    }
    for (int i = 0; i < B - 4; i++){
        string A = "";
        A += S.at(i);
        A += S.at(i + 1);
        A += S.at(i + 2);
        A += S.at(i + 3);
        A += S.at(i + 4);
        T.insert(A);
    }
    for (int i = 0; i < K - 1; i++) {
        T.erase(*begin(T));
    }
    cout << *begin(T) << endl;

}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
char s[5];
int main() {
	//freopen("in.txt","r",stdin);
	scanf("%s",s);
	int a=0,b=0;
	for(int i=0;s[i];i++) {
		if(s[i]=='A') a++;
		else b++;
	}
	printf("%s\n",a&&b?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (i=a;i<n;i++)
#define per(i,a,n) for (i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE 1000001
#define ONLINE_JUDGE
#define rd
#define PI acos(-1)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
auto clk=clock(); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;

int main(){

	

	// Write after this

	int i,n,m,a,sum=0;
	cin>>n>>m;
	rep(i,0,m){
		cin>>a;
		sum+=a;
	}
	if(sum>n) cout<<-1;
	else cout<<n-sum;
	return 0;
}

Measured memory_bytes: 3672
#include <iostream>
 
using namespace std;
int main() 
{
     int hello, bye, another, i;
     cin >> hello >> bye;
     for (i=1;hello!=0||bye!=0;i++)
     {
     if (hello>bye)
     {
         another=hello;
         hello=bye;
         bye=another;
     }
     cout << hello << " " << bye << endl;
     cin >> hello >> bye;
     }
     
     

 
}



Measured memory_bytes: 2988
import numpy as np
N = int(input())
a = np.array(input().split(), np.int64)
MOD = 10**9+7
U = 10**6+10
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
  if p*p>U:
    break
  if is_prime[p]==1:
    is_prime[p*p::p+p] = 0

M = 10**3
small_primes = np.where(is_prime[:M])[0].tolist()

B = a.copy()
lcm = 1
for p in small_primes:
  e = 0
  while np.any(a%p==0):
    a[a%p==0] //= p
    e += 1
  lcm *= p**e
  lcm %= MOD

for x in set(a.tolist()):
  lcm *= x
  lcm %= MOD

answer = sum(pow(x, MOD-2, MOD) for x in B.tolist())%MOD
answer *= lcm
answer %= MOD
print(answer)

Measured memory_bytes: 14280
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll h, w, d;
  cin >> h >> w >> d;
  vector <pair <ll, ll>> v(h*w, pair <ll, ll> ());
  rep(i, h) {
    rep(j, w) {
      ll a;
      cin >> a;
      a--;
      v.at(a) = make_pair(i, j);
    }
  }
  vector <ll> u(h*w);
  rep(i, h*w) {
    if (0 <= i-d) {
      u.at(i) = u.at(i-d) + abs(v.at(i).first-v.at(i-d).first) 
        + abs(v.at(i).second-v.at(i-d).second);
    } else {
      u.at(i) = 0;
    }
  }
  ll n;
  cin >> n;
  rep(i, n) {
    ll l, r;
    cin >> l >> r;
    l--; r--;
    cout << u.at(r) - u.at(l) << endl;
  }
}

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

int main(){
    int n; cin >> n;
    int a[n+1];
    for(int i = 0; i < n; i++) cin >> a[i];
    a[n] = INT_MAX;
    int ans = 0, c = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == a[i+1]) c++;
        else {ans += (c+1)/2; c = 0;}
    }   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string a;   
    bool v[2]={0}; 
    cin>>a;
    for(int i=0;i<a.length();i++)
    {
        if(a[i]=='C')v[0]=1;
        if(a[i]=='F'&&v[0]) v[1]=1;
    }
    if(v[1])cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

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

ll INF = LLONG_MAX / 10;

int main() {
	int N, K; cin >> N >> K;
	N -= K;
	int ans = 1;
	for (; N > 0; N -= K - 1) ans++;
	cout << ans << endl;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m; cin >> n >> m;
    cout << (n-1) * (m-1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<int> L(n);
    rep(i, n) {
        cin >> L[i];
    }
    sort(L.begin(), L.end());

    int ans = 0;
    rep(b, n) {
        rep(a, b) {
            int ab = L[a] + L[b];
            int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
            int l = b+1;
            ans += r-l;
        }
    }

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

Measured memory_bytes: 256
/*
  Esteban Arango Medina
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

using ll=long long;
#define int ll

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <char,int> mci;
typedef map <int,int> mii;
typedef map <string,string> mss;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define endl '\n' // Normal `cout << endl` flushes the output every time wich hit performance badly
#define INF 1000000000
#define deb(x) cout<<#x<<": "<<x<<endl;
#define printArray(arr) for(auto x: arr) { cout<<x<<", "; }
#define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; }
#define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; }

signed main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); // Fast input
  #ifdef LOCAL_PROJECT
    freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
  #endif

  int T = 1; //cin>>T;
  while(T--) {
    int n, k; cin>>n>>k;
    vi stones(n);
    rep(i,0, n) { cin>>stones[i]; }
    vi DP(n, 0);
    DP[0] = 0;
    DP[1] = abs(stones[0] - stones[1]);
    rep(i,2,n) {
      int minSteps = INT_MAX;
      int j = 1;
      while(j <= k && i - j >= 0) {
        minSteps = min(minSteps, DP[i-j] + abs(stones[i] - stones[i-j]));
        j++;
      }
      DP[i] = minSteps;
    }
    cout<<DP[n-1];
  }
  return 0;
}

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

int n,a;
long long x[55];
long long sol[55][2505];

int main()
{
    long long rez=0;
    int i,j,k,l;
    cin>>n>>a;
    for(i=1;i<=n;i++)
        cin>>x[i];

    int tot=n*a;
    for(i=1;i<=n;i++)
    {
        for(l=i;l>=1;l--)
            for(j=x[i];j<=tot;j++)
                sol[l][j]+=sol[l-1][j-x[i]];
        sol[1][x[i]]++;
    }

    for(i=1;i<=n;i++)
        rez+=sol[i][i*a];
    cout<<rez;
    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>

int main(void){
    int a[3][3], n, b[10], i, j, k;

    for(i=0; i<3; i++){  
        for(j=0; j<3; j++){  
            scanf("%d",&a[i][j]);
        }
    }   
    scanf("%d",&n);
    for(k=0; k<n; k++){
        scanf("%d",&b[k]);
        for(i=0; i<3; i++)
            for(j=0; j<3; j++){
                if(a[i][j] == b[k]){
                    a[i][j] = -1;
                }
            }
    }

    if((a[0][0] == a[1][1]) && (a[0][0] == a[2][2])){
        printf("Yes\n");
        return 0;
    }
    if((a[1][1] == a[0][2]) && (a[1][1] == a[0][2])){
        printf("Yes\n");
        return 0;
    }

    for(i=0; i<3; i++){
        if((a[i][0] == a[i][2])&&(a[i][1] == a[i][0])){
            printf("Yes\n");
            return 0;
        }
        else if((a[0][i] == a[1][i])&&(a[0][i] == a[2][i])){
            printf("Yes\n");
            return 0;
        }
    } 
    
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
int n,k,c;
char s[N];
int f[N],b[N];
int main()
{
	scanf("%d%d%d%s",&n,&k,&c,s+1);
	f[0]=b[0]=1;
	for(int i=1;i<=n;i+=c+1){
		while(s[i]=='x') ++i;
		f[f[0]++]=i;
	}
	for(int i=n;i>=1;i-=c+1){
		while(s[i]=='x') --i;
		b[b[0]++]=i;
	}
//	for(int i=1;i<f[0];++i) printf("f[%d]=%d ",i,f[i]);
//	printf("\n");
//	for(int i=1;i<b[0];++i) printf("b[%d]=%d ",i,b[i]);
//	printf("\n");
	for(int i=1;i<=k;++i){
		if(f[i]==b[k+1-i]) printf("%d\n",f[i]);
	}
}

Measured memory_bytes: 3200
import sys
if __name__ == "__main__":
    N = int(input())
    buf = (N-1) // 999
    if N == 1 or buf == 0:
        print('ABC')
        sys.exit()
    elif buf == 1:
        print('ABD')
        sys.exit()
    else:
        print('ABE')
        sys.exit()

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			int R = sc.nextInt();
			if (N >= 10) {
				System.out.print(R);
			} else {
				System.out.print(R + 100 * (10 - N));
			}
		}
	}

}


Measured memory_bytes: 21972
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
      Scanner input=new Scanner(System.in);
      String in=input.next();
      StringBuilder Builder=new StringBuilder();
      for(int i=0;i<in.length();++i){
        if(in.charAt(i)=='?'){
          Builder.append('D');
        }else{
          Builder.append(in.charAt(i));
        }
      }System.out.println(Builder.toString());
    }
}

Measured memory_bytes: 41508
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;
typedef uint_fast64_t u64;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/

const int MOD = 1000000007;

struct ModInt{
    u64 a;
    ModInt() : a(0) {}
    ModInt(u64 x) : a(x%MOD) {}

    ModInt operator+=(const ModInt p){
        a+=p.a;
        if( a>=MOD ) a-=MOD;
        return *this;
    }
    ModInt operator-=(const ModInt p){
        a-=p.a;
        if(a<0) a+=MOD;
        return *this;
    }
    ModInt operator*=(const ModInt p){
        a=(a*p.a)%MOD;
        return *this;
    }

    ModInt operator+(const ModInt p){
        ModInt x(a);
        return x+=p;
    }
    ModInt operator-(const ModInt p){
        ModInt x(a);
        return x-=p;
    }
    ModInt operator*(const ModInt p){
        ModInt x(a);
        return x*=p;
    }
    ModInt operator=(ll p){
        a=p;
        return *this;
    }

    bool operator==(const ModInt p){
        return a==p.a;
    }

    bool operator!=(const ModInt p){
        return a!=p.a;
    }

    ModInt pow(u64 N){
        ModInt ans(1),p(a);
        while(N>0){
            if(bit(N,0)){
                ans*=p;
            }
            p*=p;
            N>>=1;
        }
        return ans;
    }
    ModInt inverse(){
        return pow(MOD-2);
    }
};

signed main(void){
    int N;
    cin>>N;
    ModInt t(1);
    ModInt i(1);
    for(;i.a<=N-1;i.a++){
        t*=i;
    }
    ModInt S[110000],x[110000];
    for(i.a=1;i.a<=N-1;i.a++){
        S[i.a]+=S[i.a-1]+t*i.inverse();
    } 
    for(int a=1;a<=N;a++) cin>>x[a].a;
    ModInt ans(0);
    for(int a=1;a<=N-1;a++){
        ans+=S[a]*(x[a+1]-x[a]);
    }
    cout<<ans.a<<endl;

}

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

long long int N, ans;
char s[303][303];

bool issymmetric(int i){
    for(int I = 0; I < N; ++I){
        for(int J = 0; J < N; ++J){
            if(s[(i + I) % N][J] != s[(J + i) % N][I])return 0;
        }
    }
    return 1;
}

int main(){
    scanf("%lld ", &N);
    for(int i = 0; i < N; ++i){
        scanf("%s", s[i]);
    }
    for(int i = 0; i < N; ++i){
        ans += issymmetric(i);
    }
    cout << ans * N << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define Z -1
using namespace std;
struct NO{int p,l,r;};
struct NO T[100000];
int D[100000]={Z};
int rec(int u,int p){
  D[u]=p;
  if(T[u].r!=Z)rec(T[u].r,p);
  if(T[u].l!=Z)rec(T[u].l,p+1);
}
int main(){
  int a,b,c,n,l,r,j,k,i;
  for(cin>>n,i=0;i<n;i++)T[i].p=T[i].l=T[i].r=Z;
  for(i=0;i<n;i++)for(cin>>a>>b,j=0;j<b;j++){
    cin>>c;
    if(!j)T[a].l=c;
    else T[l].r=c;
    l=c;
    T[l].p=a;
  }
  for(i=0;i<n;i++)if(T[i].p==Z)r=i;
  rec(r,0);
for(i=0;i<n;i++){
  printf("node %d: parent = %d, depth = %d, ",i,T[i].p,D[i]);
  if(T[i].p==Z)cout<<"root, [";
  else if(T[i].l==Z)cout<<"leaf, [";
  else cout<<"internal node, [";
  for(j=0,c=T[i].l;c!=Z;c=T[c].r){
    if(j++)cout<<", ";
    cout<<c;
  }
  cout<<"]"<<endl;
}
}

Measured memory_bytes: 7920
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

int N, M, val[200005], v[200005];

bool ok(int k){
    FOR(i,M) v[i] = (val[i] >= k);
    int l = N, r = N;
    while(l>1 && v[l]!=v[l-1]) l--;
    while(r<M && v[r]!=v[r+1]) r++;
    return v[(M-r+1 > l) ? r : l];
}

int main(){

    ios :: sync_with_stdio(false);
    cin >> N;
    M = 2*N-1;
    FOR(i,M) cin >> val[i];

    int ans = 0, lo = 1, hi = M;
    while(lo<=hi){
        int mid = (lo+hi)/2;
        if(ok(mid)){
            ans = mid;
            lo = mid+1;
        }
        else hi = mid-1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		as[a-1] = i + 1
	}

	p := ""
	for i := 0; i < n; i++ {
		fmt.Printf("%s%d", p, as[i])
		p = " "
	}
	fmt.Println()
}


Measured memory_bytes: 6348
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
	string s, key = "keyence";
	cin >> s;

	bool tf = true;

	if (s[0]==key[0]) {
		int idx = 0;
		for (int i = 0; i < key.size(); ++i) {
			if (key[i]!=s[i]) {
				idx = i;
				break;
			}
			idx++;
		}
		if (s.substr(0, idx)+s.substr(s.size()-7+idx, 7-idx)!=key) tf = false;
	}
	else {
		int idx = 0;
		for (int i = 0; i < s.size(); ++i) {
			if (key[0]==s[i]) {
				idx = i;
				break;
			}
			idx++;
		}
		if(s.substr(idx, s.size()-idx)!=key) tf = false;
	}

	if (tf) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_bacn
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	int h, n;
	cin >> h >> n;
	vll dp(h + 1, 1e8 + 1);
	dp[0] = 0;
	FOR(n)
	{
		int c, d;
		cin >> c >> d;
		FOR(j, h + 1)
		dp[j] = min(dp[j], dp[max(0, j - c)] + d);
	}
	cout << dp[h];
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;

int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
         
    // }
    string s,t;
    cin>>s>>t;
    ll n=s.length();
    ll m=t.length();
    ll ans=1e18;
    for(int i=0;i<=n-m;i++)
    {
        ll cnt=0;
        for(int j=0;j<m;j++)
        {
            if(s[i+j]!=t[j])
            cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}

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

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

    int count =0;
    for(int i=1; i<=N; i++){
        if(1<=i && i<=9){
            count++;
        }
        else if(100<=i && i<=999){
            count++;
        }
        else if(10000<=i && i<=99999){
            count++;
        }
    }
    cout << count << endl;
}

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

int main() {
	string s;
	int d;
	cin>>s;
	if(s=="SAT")d=1;
	else if(s=="FRI")d=2;
	else if(s=="THU")d=3;
	else if(s=="WED")d=4;
	else if(s=="TUE")d=5;
	else if(s=="MON")d=6;
	else d=7;
	cout<<d;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        int n = sc.nextInt();
        string s = sc.next();

        char prev = ' ';
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (prev != s[i])
            {
                //Console.Write(s[i]);
                prev = s[i];
                ans++;
            }
        }

        //Console.Write("\n");
        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13124
n, a, b = gets.split.map(&:to_i)
cities = gets.split.map(&:to_i)
walking_costs = []
tmp = cities.first
cities.each do |city|
  walking_costs << (city - tmp) * a
  tmp = city
end
costs = walking_costs.map { |c| [c, b].min }
puts costs.inject(:+)


Measured memory_bytes: 12676
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
ll vis[2003][2003];
string s[2003];
int main()
{
	sync;
	ll n,m;
	cin>>n>>m;
	input(s,n);
	for(ll i=0;i<n;i++)
	{
		ll cnt=0;
		for(ll j=0;j<m;j++)
		{
			if(s[i][j]=='#')
			cnt=0;
			else
			{
				cnt++;
				vis[i][j]=cnt;
			}
		}cnt=0;
		for(ll j=m-1;j>=0;j--)
		{
			if(s[i][j]=='#')
			cnt=0;
			else
			{
				vis[i][j]+=cnt;
				cnt++;
			}
		}
	}
	//col
	for(ll i=0;i<m;i++)
	{
		ll cnt=0;
		for(ll j=0;j<n;j++)
		{
			if(s[j][i]=='#')
			cnt=0;
			else
			{
				vis[j][i]+=cnt;
				cnt++;
			}
		}cnt=0;
		for(ll j=n-1;j>=0;j--)
		{
			if(s[j][i]=='#')
			cnt=0;
			else
			{
				vis[j][i]+=cnt;
				cnt++;
			}
		}
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	for(ll j=0;j<m;j++)
	ans=max(ans,vis[i][j]);
	cout<<ans;
}

Measured memory_bytes: 35840
#include<bits/stdc++.h>
using namespace std;
vector<long long> vaal;
int main(){
    int n,k;
    cin >> n >> k;
    long long harr[n];
    for(int i=0;i<n;i++) cin >> harr[i];
    vaal = vector<long long>(n+1,0);
    vaal[1] = abs(harr[1]-harr[0]);
    if(n>2){
        if(k>1){
            vaal[2] = min(abs(vaal[1]+abs(harr[2]-harr[1])),abs(harr[2]-harr[0]));
        }else{
            vaal[2] = abs(vaal[1]+abs(harr[2]-harr[1])); 
        }

    } 
    for(int i=3;i<n;i++){
        long long kv = LONG_LONG_MAX;
        for(int j=i-1,cnt =0;j>=0 && cnt<k;j--,cnt++){
            long long val = vaal[j] + abs(harr[i]-harr[j]);
            if(val<kv) kv = val;
        }
        vaal[i] = kv;
    }
    cout << vaal[n-1] << "\n";
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
mod_arr = list(map(int,input().split()))
arr = [0]*N
in_arr = []
# iが大きい方から決めていく
for i in range(N,0,-1):
  if i > N//2:
    if mod_arr[i-1] == 0:
      continue
    else:
      arr[i-1] = 1
      in_arr.append(str(i))
      
  else:
    S = 0
    for j in range(2*i,N+1,i):
      S += arr[j-1]
    if S%2 == mod_arr[i-1]:
      arr[i-1] = 0
    else:
      arr[i-1] = 1
      in_arr.append(str(i))

print(len(in_arr))
print(' '.join(in_arr))

Measured memory_bytes: 17592
# -*- coding: utf-8 -*-
"""
"""
#
from collections import Counter
from operator import itemgetter

def main():
    n = int(input())
    rods = [int(x) for x in input().split(' ')]

    candidates = []
    for r in Counter(rods).most_common():
        if r[1] >= 4:
            candidates.append(r[0])
            candidates.append(r[0])
        elif r[1] >= 2:
            candidates.append(r[0])
        else:
            break

    if len(candidates) >= 2:
        candidates.sort(reverse=True)
        print(candidates[0] * candidates[1])
    else:
        print('0')


if __name__ == '__main__':
    main()


Measured memory_bytes: 21540
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		long mod=0;
		int n=in.nextInt();
		int p=in.nextInt();
		String s=in.next();
		int [] r=new int [p];
		long ans=0;
		long pow=1;
		for(int i=n-1;i>=0;i--)
		{
			int t=s.charAt(i)-'0';
			if(p==2||p==5)
			{
					if(t%p==0)
					{
						ans=ans+i+1;
					}
			}
			else
			{
				mod=(mod+t*pow)%p;
				pow=(pow*10)%p;
				if(mod==0)
					ans++;
				ans=ans+r[(int)mod];
				r[(int)mod]++;
			}
		}
		System.out.println(ans);
	}
}
	

Measured memory_bytes: 28116
n = gets.to_i
c = gets.split.to_a
h = {}
n.times do |i|
  if h[c[i].to_i]
    h[c[i].to_i] += 1
  else
    h[c[i].to_i] = 1
  end
end
s = h.select{|k, v| v >= 4}.keys.sort{|a, b| b<=>a}
t = h.select{|k, v| v >= 2}.keys.sort{|a, b| b<=>a}
ans = 0
if s.size > 0
  ans = s[0] * s[0]
end
if t.size > 1
  ans = [ans, t[0] * t[1]].max
end
puts ans

Measured memory_bytes: 14220
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MN 100005
int n,m;
LL sum;
int vis[25][25];
char ch[25][25];
const int fx[4]={1,-1,0,0},fy[4]={0,0,-1,1};
queue<int>Qx,Qy;
int bfs(int x,int y){
	memset(vis,0,sizeof(vis));
	vis[x][y]=1;
	Qx.push(x);Qy.push(y);
	int res=1;
//	cerr<<"==========="<<x<<" "<<y<<endl;
	while(!Qx.empty()){
		int x=Qx.front(),y=Qy.front();
//		cerr<<"? "<<x<<" "<<y<<endl;
		Qx.pop();Qy.pop();
		for(int i=0;i<4;++i){
			int X=x+fx[i],Y=y+fy[i];
			if(X<1||X>n||Y<1||Y>m)continue;
			if(ch[X][Y]=='#')continue;
			if(!vis[X][Y]){vis[X][Y]=vis[x][y]+1;
				res=max(res,vis[X][Y]);
				Qx.push(X);Qy.push(Y);
			}
		}
	}
	return res-1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",ch[i]+1);
	}
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			if(ch[i][j]!='#')ans=max(ans,bfs(i,j));
		}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n, k;
    cin >> n >> k;
    double ans = 0;

    for (int i = 1; i <= n; i++) {
        ll fact = 1;
        ll j = i;
        while (j < k) {
            j *= 2;
            fact *= 2;
        }

        ans += ((double) 1 / n) / fact;
    }

    cout << ans;
}

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

int main(){
  int a, b, c, count = 0;
  cin >> a >> b >> c;
  for(int i = a;i <= b;i++){
    if(c % i == 0) count++;
  }

  cout << count << "\n";
  return 0;
}



Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define N 1000000

void mergeSort(int [ ], int , int);
void merge(int [ ], int , int , int );

int cnt=0;

int main()
{
  int i,S[N],n;

  while(1)
    {
      scanf("%d",&n);
      if(n <= N && n > 0) break;
    }

  for(i=0;i<n;i++)
      scanf("%d",&S[i]);

  mergeSort(S,0,n);

  for(i=0;i<n-1;i++)
    printf("%d ",S[i]);
  
  printf("%d\n%d\n",S[i],cnt);
  
  return 0;
}

void mergeSort(int A[ ], int left, int right)
{
  int mid;
  if(left+1 < right)
    {   
      mid = (left + right) / 2;
      mergeSort(A,left,mid);
      mergeSort(A,mid,right);
      merge(A,left,mid,right);
    }
}

void merge(int A[ ], int left, int mid, int right)
{
  int i,j,k,n1,n2;
  int *sl,*sr;

  n1 = mid - left;
  n2 = right - mid;

  sl = malloc(sizeof(int) * n1 + 1);
  sr = malloc(sizeof(int) * n2 + 1);
  
  for (i = 0; i < n1; i++)
    sl[i] = A[left + i];
  
  sl[n1] = (int)INFINITY;
  
  for (j = 0; j < n2;j++)
    sr[j] = A[mid + j];
  
  sr[n2] = (int)INFINITY;
  i = 0;         
  j = 0;       

  for (k = left; k < right; k++)
    {
      if (sl[i] <= sr[j])
	{
	  A[k] = sl[i];
	  i++;
	}
      else
	{
	  A[k] = sr[j];
	  j++;
	}
      cnt++;
    }

  free(sl);
  free(sr);
}





Measured memory_bytes: 5472
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
    sum = C
    for j in range(M):
        sum += A[i][j] * B[j]
    if sum > 0:
        ans += 1
print(ans)


Measured memory_bytes: 62320
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 
int a,b;
scanf("%d%d",&a,&b);
 
if(a>12) cout << b << endl;
else if (6>a) cout << 0 << endl;
else cout << b/2 << endl;
return 0;
 
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,a,b,sum;
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>a>>b;
		sum+=b-a+1;
	}
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n;
  cin>>n;
  vector<string>a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  set<string>st;
  for(int i=0;i<n;i++)
    st.insert(a[i]);
  cout<<st.size();
    
}

Measured memory_bytes: 25088
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
ll binaryNum[62];
void decToBinary(ll n)
{
    forn(i,62) binaryNum[i]=0;

    int i = 0;
    while (n > 0) {
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }
}

int main() {
    FIN;
    ll n;
    cin >> n;
    ll arreglo[n][n];
    ll verdad[n];
    forn(i,n)
    {
        forn(j,n) arreglo[i][j]=-1;
    }
    ll x, y, z;
    forn(i,n)
    {
        cin >> x;
        forn(j,x)
        {
            cin >> y >> z;
            arreglo[i][y-1]=z;
        }
    }
    bool posta;
    ll resp=0, porahora;
    forn(i,pow(2,n))
    {
        decToBinary(i);
        forn(j,n) verdad[j]=binaryNum[j];
        posta=true;
        porahora=0;
        forn(j,n)
        {
            if(verdad[j]==1)
            {
                forn(k,n)
                {
                    if(arreglo[j][k]==0)
                    {
                        if(verdad[k]==1) posta=false;
                    }
                    if(arreglo[j][k]==1)
                    {
                        if(verdad[k]==0) posta=false;
                    }
                }
            }
        }
        if(posta==true)
            {
                forn(k,n)
                {
                    porahora+=verdad[k];
                }
            }
        resp=max(resp,porahora);
    }
    cout << resp << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char ch;
int a[30];
int main()
{
	for(ch=getchar();isalpha(ch);ch=getchar())
		a[ch-'a']++;
	for(int i=0;i<26;i++)
	if(a[i]==0)
	{
		putchar(i+'a');
		return 0;
	}
	puts("None");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
string LCS(string &a,string &b){
	const int LMAX=300;
	int m=a.size(),n=b.size();
	int dp[LMAX+1][LMAX+1],from[LMAX+1][LMAX+1];
	rep(i,m+1)dp[i][0]=0,from[i][0]=-1;
	rep(i,n+1)dp[0][i]=0,from[0][i]=-1;
	rep(i,m)rep(j,n){
		if(a[i]==b[j]){
			dp[i+1][j+1]=dp[i][j]+1;
			from[i+1][j+1]=2;
		}else{
			if(dp[i][j+1]<dp[i+1][j]){
				dp[i+1][j+1]=dp[i+1][j];
				from[i+1][j+1]=1;
			}else{
				dp[i+1][j+1]=dp[i][j+1];
				from[i+1][j+1]=0;
			}
		}
	}
	int idx=dp[m][n];
	string out(idx,'!');
	for(int i=m,j=n;~from[i][j];){
		switch(from[i][j]){
			case 0:i--;break;
			case 1:j--;break;
			case 2:i--;j--;idx--;out[idx]=a[i];break;
		}
	}
	return out;
}
int main(){
	string s;
	while(cin>>s,s!="#END"){
		int out=0;
		string ans="";
		rep(i,s.size()-1){
			string a=s.substr(0,i+1);
			string b=s.substr(i+1);
			string t=LCS(a,b);
			if(t.size()>out){
				out=t.size();
				ans=t;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int k;
  cin >> k;

  for (int i = 0; i < k; ++i) {
    if (g <= r) {
      g *= 2;
    } else if (b <= g) {
      b *= 2;
    }
  }
  bool ret = (b > g) and (g > r);
  // cout << ret << endl;
  if (ret) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){

int N,L;
cin>>N>>L;
string value;


vector<string>vec;
for(int i=0; i<N; i++){
        cin>>value;
vec.push_back(value);

}
sort( vec.begin(), vec.end() ) ;

for(int i=0; i<N; i++){
cout<<vec[i];
}





return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt().toMutableList()
    A.add(0, 0)
    val C = IntArray(N + 1) { 0 }
    fun even(n: Int): Boolean = (n % 2 == 0)
    for (i in (1..N).reversed()) {
        var sum = 0
        for (n in i .. N step i) {
            if (n % i == 0) sum += C[n]
        }
        if (A[i] == 0 && !even(sum)) C[i] = 1
        if (A[i] == 1 && even(sum)) C[i] = 1
    }
    var ans = C.mapIndexed { index, v -> if (v == 0) 0 else index }.filter { it != 0 }
    println(ans.count())
    println(ans.joinToString(separator = " "))
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 77748
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector<pair<int ,int> >vepa;
typedef set<ll>se;
typedef map<string ,ll> mpp;
const ll N=1e5+1 ,OO=1e18;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,x,y,cnt,arr[N];
bool f,vis[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
        cin>>n;
        string s;
        mpp mp;
        while(n--)
        {
            cin>>s;
            mp[s]++;
        }
         cout<<"AC x "<<mp["AC"]<<"\n";
        cout<<"WA x "<<mp["WA"]<<"\n";
        cout<<"TLE x "<<mp["TLE"]<<"\n";
        cout<<"RE x "<<mp["RE"]<<"\n";

 go;
}


Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B___Roller_Coaster
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var NK = line.Split();

            var N = int.Parse(NK[0]);
            var K = int.Parse(NK[1]);

            var line2 = Console.ReadLine();
            var sh = line2.Split();
            int[] nh = sh.Select(s => int.Parse(s)).ToArray();

            int cnt = 0;

            for (int i = 0; i < N; i++)
            {
                if (nh[i]>=K)
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);

        }
    }
}


Measured memory_bytes: 17248
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int N;
int A[3][3];

int main() {
    for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) cin >> A[i][j];
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int b; cin >> b;
        for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) if (A[j][k] == b) A[j][k] = 0;
    }

    bool ok = false;
    for (int i = 0; i < 3; ++i) {
        bool tmp = true;
        for (int j = 0; j < 3; ++j) if (A[i][j]) tmp = false;
        if (tmp) ok = true;

        tmp = true;
        for (int j = 0; j < 3; ++j) if (A[j][i]) tmp = false;
        if (tmp) ok = true;
    }

    bool tmp = true;
    for (int i = 0; i < 3; ++i) if (A[i][i]) tmp = false;
    if (tmp) ok = true;

    tmp = true;
    for (int i = 0; i < 3; ++i) if (A[i][2-i]) tmp = false;
    if (tmp) ok = true;

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<char> ALP(26);
  ALP = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  int M = S.size();
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 26; j++) {
      if (S.at(i) == ALP.at(j)) {
        S.at(i) = ALP.at((j + N) % 26);
        break;
      }
    }
  }
  cout << S << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n, m;
vector<int> g[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    
    cin>>n>>m;
    for (int i=0; i<m; i++) {
	int u,v; cin>>u>>v;
	u--;
	v--;
	g[u].push_back(v);
	g[v].push_back(u);
    }

    vector<int> dist(n, -1);
    vector<int> par(n, -1);
    dist[0]=0;
    
    queue<int> qq;
    qq.push(0);
    while (qq.size()) {
	int at = qq.front();
	qq.pop();
	for (int to: g[at]) {
	    if (dist[to]==-1) {
		dist[to]=1+dist[at];
		par[to]=at;
		qq.push(to);
	    }
	}
    }
    if (*min_element(dist.begin(),dist.end())<0) out("No");

    cout<<"Yes\n";
    for (int i=1; i<n; i++) {
	cout<<par[i]+1<<"\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 31668