akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool bfs(vvi &g, int a, int b,int s){
    queue<int> q;
    q.push(s);
    vb ispass(g.size(),false);
    ispass[s]=true;
    while(!q.empty()){
        int now=q.front();q.pop();
        if(now==b)return 0;
        rep(i,g[now].size()){
            if(ispass[g[now][i]])continue;
            if((now==a&&g[now][i]==b)||(now==b&&g[now][i]==a))continue;
            ispass[g[now][i]]=1;
            q.push(g[now][i]);
        }
    }
    return 1;
}

int main(void) {

    int n,m;
    cin>>n>>m;
    vvi g(n);
    vpii v(m);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[i]=mp(a,b);
        g[a].pb(b);
        g[b].pb(a);
    }
    int ans=0;
    rep(i,m){
        int t=bfs(g,v[i].first,v[i].second,v[i].first);
        // cout<<i<<" "<<t<<endl;
        ans+=t;
    }
    fin(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << " ";
  }
  return os;
}

void sosa(map<int,int>& mp,li& s,int b,int c){
  li cnt=mp[b];
  if(df)print(cnt,b,c);
  s+=cnt*(c-b);
  mp.erase(b);
  mp[c]+=cnt;
  if(df)print(mp);
  print(s);
}

int main(){
  int n; cin >>n;
  map<int,int> mp;
  li s=0;
  rep(i,n){
    int a; cin >>a;
    s+=a;
    mp[a]++;
  }

  int q; cin >>q;
  rep(_,q){
    int b,c; cin >>b >>c;
    sosa(mp,s,b,c);
  }
    
  
}


Measured memory_bytes: 6580
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
C_L = 0
C_R = 0
for i in range(M):
  if A[i] < X:
    C_L += 1
  elif A[i] >X:
    C_R += 1
print(min(C_L, C_R))

Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
const int INF = 1000000007;

struct P{
    int t, w;
    P(int x, int y){
        t = x;
        w = y;
    }
};

int N;
vector< vector<P> > G(100010);
vector<int> dist(100010);

void bfs(int v0){
    rep(i, N) dist[i] = -1;
    dist[v0] = 0;
    queue<int> que;
    que.push(v0);

    while(!que.empty()){
        int v1 = que.front();
        que.pop();

        rep(i, G[v1].size()){
            int v2 = G[v1][i].t, w2 = G[v1][i].w;
            if(dist[v2] != -1) continue;
            dist[v2] = dist[v1] + w2;
            que.push(v2);
        }
    }
}

int main(){
    cin >> N; 
    if(N == 1){
        cout << 0 << endl;
        return 0;
    }
    rep(i, N){
        int s, t, w;
        cin >> s >> t >> w;
        G[s].push_back(P(t, w));
        G[t].push_back(P(s, w));
    }

    bfs(0);

    int d_max = 0, v_start = 0;
    rep(i, N){
        if(d_max < dist[i]){
            d_max = dist[i];
            v_start = i;
        }
    }

    bfs(v_start);

    int ans = 0;
    rep(i, N) ans = max(ans, dist[i]);
    
    cout << ans << endl;    

}


Measured memory_bytes: 9612
a = int(input())
b = int(input())
if a == 1:
    if b == 2:
        print(3)
    elif b == 3:
        print(2)
elif a == 2:
    if b == 1:
        print(3)
    elif b == 3:
        print(1)
elif a == 3:
    if b == 1:
        print(2)
    elif b == 2:
        print(1)


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

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() { initio();
  int N; cin >> N;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  vector<ll> S(N + 1); rep(i, N) S[i + 1] = S[i] + A[i];
  ll ans = LLONG_MAX;
  for (int i = 1; i <= N - 1; i++) {
    ans = min(ans, abs((S[N] - S[i]) - S[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3456
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n) for(i64 i=(s); i < (n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;



signed main()
{
  int N, K;
  cin >> N >> K;

  auto f = [&K](int n) {
    int cnt = 0;
    while(n < K) {
      n *= 2;
      ++cnt;
    }
    return cnt;
  };

  long double ans = 0;
  long double p = 1.0 / N;
  rep(i, 1, N+1) {
    ans += p * (1.0 / (1LL << f(i)));
  }

  cout << setprecision(11) << ans << endl;

  return 0;
}



Measured memory_bytes: 256
N, M = map(int,input().split())
loads = [list(map(int, input().split())) for _ in range(M)]
dic = {i+1:0 for i in range(N)}
for load in loads:
    dic[load[0]] += 1
    dic[load[1]] += 1
for a in dic.values():
    print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int fold(int n) {
    int res = 0;

    while (n > 0) {
        res += (n % 10);
        n /= 10;
    }

    return res;
}

int main() {
    int n;
    cin >> n;
    if (n % fold(n) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
fn main() {
    let mut s = read();
    let mut ss = String::new();
    for c in 0..19 {
        if s[c] == ',' {
            s[c] = ' ';
            ss.push(s[c]);
        }
        ss.push(s[c]);
    }
    println!("{}", ss);
}

// fn read() -> u32 {
//     let s = stdin();
//     let b = s.bytes()
//         .map(|c| c.unwrap() as char)
//         .take_while(|c| !c.is_whitespace())
//         .collect::<string>();
//     b.parse::<u32>().unwrap()
// }

fn read() -> Vec<char> {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<Vec<char>>();
    b
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
    int N,M,i,j;
    int f=0;
    int sc[10]={};
    int a[3]={10,10,10};
    scanf("%d",&N);
    scanf("%d",&M);
    for(i=0;i!=M*2;i++){
        scanf("%d",&sc[i]);
    }
    for(i=0;i!=M*2;i+=2){
      	j=sc[i]-1;
        if(a[j]==10 || a[j]==sc[i+1]){
            a[j]=sc[i+1];
        }else{
            f=2;
        }
    }
    if(a[0]==10){
        a[0]=1;
        if(N==1)a[0]--;
    }
    if(a[0]%10==0) f++;
    if(a[0]==0 && N==1) f--;
    
    if(f==0){
        for(i=0;i!=N;i++){
            a[i]%=10;
            printf("%d",a[i]);
        }
    }else{
         printf("%d",-1);
    }
    return 0;
}

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

  int num = 0;
  for (int i = 0; i < n.size(); i++) {
    num += n[i] - '0';
  }
  string ans = "Yes";
  if (num % 9 != 0) {
    ans = "No";
  }

  cout << ans << endl;
}

Measured memory_bytes: 3732
h, w = gets.split(" ").map(&:to_i)

rows = []
h.times do
  rows << gets.chomp.chars
end

2.times do
  rows = rows.reject do |row|
    row.all?{|e| e == "."}
  end.transpose
end

puts rows.map{|row| row.join}.join("\n")

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s1, s2;

int main(void) {
  // Here your code !
  cin >> s1;
  cin >> s2;

  for (int i = 0; i < 3; ++i) {
    if (s1[i] != s2[2 - i]) {
      printf("NO\n");
      return 0;
    }
  }

  printf("YES\n");
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int inf = 1012345678;
int a, b, c;
int main() {
	while (cin >> a >> b >> c, a | b | c) {
		int rx = inf, ry = inf;
		for (int i = -100000; i <= 100000; i++) {
			int res = abs(c - a * i);
			if (res % b == 0) {
				int y = abs(i), z = res / b;
				if (y + z < rx + ry) rx = y, ry = z;
				else if (y + z == rx + ry && 1LL * a * y + 1LL * b * z <= 1LL * a * rx + 1LL * b * ry) rx = y, ry = z;
			}
		}
		cout << rx << ' ' << ry << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	string s1;
	string s2;
	cin >> s1;
	cin >> s2;
	if (s1[0] != s2[2]) {
		cout << "NO";
		return 0;
	}
	if (s1[1] != s2[1]) {
		cout << "NO";
		return 0;
	}
	if (s1[2] != s2[0]) {
		cout << "NO";
		return 0;
	}
	cout << "YES";
}

Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [[i for i in map(int, input().split())] for j in range(m)]
start = 0
goal = 0
if n == 1:
    start = 0
    goal = 9
elif n == 2:
    start = 10
    goal = 99
elif n == 3:
    start = 100
    goal = 999

flag = 1
ans = -1
for num in range(start, goal + 1):
    flag = 1
    for i in range(m):
        if str(num)[sc[i][0] - 1] != str(sc[i][1]):  # 両辺ともちゃんとstrで変換
            flag = 0
    if flag == 1:
        ans = num
        break

print(ans)


Measured memory_bytes: 3064
import java.io.*;
 
class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int[] iceCount = new int[10];
        int total = Integer.parseInt(br.readLine());;
        while (total != 0) {
            for (int i = 0; i < total; i++) {
                int readValue = Integer.parseInt(br.readLine());
                iceCount[readValue]++;
            }
            total = Integer.parseInt(br.readLine());
            
            for (int i = 0; i < iceCount.length; i++) {
                if (iceCount[i] <= 0) {
                    System.out.println("-");
                } else {
                    for (int j = 0; j < iceCount[i]; j++) {
                        System.out.print("*");
                    }
                    System.out.print("\n");
                }
            }
            iceCount = new int[10];
        }
    }
}

Measured memory_bytes: 35196
N = int(input())

ans = 0

now = 1

while now ** 2 <= N:

    if N % now == 0 and (N // now - 1) > 0 and N // (N // now - 1) == N % (N // now - 1):

        ans += N // now - 1

    now += 1

print (ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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




Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K; cin >> N >> K;
    vector<bool> vis(N, false);
    for (int i = 0; i < K; ++i) {
        int di; cin >> di;
        for (int i = 0; i < di; ++i) {
            int tmp; cin >> tmp;
            vis[tmp-1] = true;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (!vis[i])  ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int kazu=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='+')kazu++;
    else kazu--;
  }
  cout<<kazu<<endl;
  return 0;
}
    

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

int main()
{
    int a, b, c, r=0;
    cin >> a >> b >> c;
    for(int i=1; i<9999; i++){
		if(a*i <= c+0.5){
			r+=b;
		}
    }

    cout << r;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  
  for(int i=0; i<N; i++){
    cin >> H[i];
  }
  
  int M=H[0];
  int count=0;
  
  for(int i=0; i<N; i++){
    if(H[i]>=M){
      count++;
    }
    M=max(M,H[i]);
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

main(){
  int y, m, d, data;

  while(1){
    if(scanf("%d %d %d", &y, &m, &d)==EOF) break;

    data=y*10000+m*100+d;

    if(data<18680908){
      printf("pre-meiji\n");
    }
    else if(data<19120730){
      printf("meiji %d %d %d\n", y-1867, m, d);
    }
    else if(data<19261225){
      printf("taisho %d %d %d\n", y-1911, m, d);
    }
    else if(data<19890108){
      printf("showa %d %d %d\n", y-1925, m, d);
    }
    else{
      printf("heisei %d %d %d\n", y-1988, m, d);
    }
  }
  return 0;
}

Measured memory_bytes: 0
import sys
import numpy as np
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    x,y = IL()
    a = np.matrix([
        [1,1],
        [2,4]
    ])
    b = np.matrix([
        [x],
        [y]
    ])
    ans = np.linalg.solve(a,b)
    if np.all(0<=ans) and np.all(abs(ans-np.round(ans)<1e-5)):
        print('Yes')
    else:
        print('No')
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 27280
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int dp[4101][2101],s[4101][2101],n,m,k,ans=0;
inline int S(int x,int y){return y>=0?s[x][y]:0;}
int main()
{
	cin>>n>>m>>k;
	dp[0][0]=s[0][0]=1;
	for(int i=1;i<=n;i++)s[0][i]=s[0][i-1];
	for(int i=1;i<n+m;i++)
	{
		for(int j=0;j<=n;j++)dp[i][j]=(S(i-1,j)-S(i-1,j-k)+mod)%mod;
		for(int j=0;j<=n;j++)s[i][j]=(S(i,j-1)+dp[i][j])%mod;
		int pos=i*(k-1)-m+1;
		while(pos<=n)ans=(ans+(mod+dp[i][pos]-dp[i-1][pos])%mod)%mod,pos+=k-1;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 66688
#include<stdio.h>

int main(){
int n,c;
while(1){

scanf("%d",&n);
if(n==0)break;
c=0;
n=1000-n;
do{
if(n>=500){n=n-500;c++;}
else if(n>=100){n=n-100;c++;}
else if(n>=50){n=n-50;c++;}
else if(n>=10){n=n-10;c++;}
else if(n>=5){n=n-5;c++;}
else if(n>=1){n=n-1;c++;}
}while(n!=0);
printf("%d\n",c);
}
return 0;
}

Measured memory_bytes: 1028
package main

import (
	"fmt"
	"sort"
)

func main() {
	bb := []int{}
	cc := []int{}
	var num int
	var i int
	count := 0
	fmt.Scan(&i)
	for i > 0 {
		fmt.Scan(&num)
		bb = append(bb, num)
		i--
	}
	for _, b := range bb {
		for {
			if b%2 == 0 {
				b = b / 2
				count++
			} else {
				break
			}
		}
		cc = append(cc, count)
		count = 0
	}
	answer := minInt(cc)
	fmt.Println(answer)
}

func minInt(a []int) int {
	sort.Sort(sort.IntSlice(a))
	return a[0]
}

Measured memory_bytes: 512
#include "algorithm"
#include "iomanip"
#include "iostream"
#include "queue"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  ll N, M, Q;
  cin >> N >> M >> Q;

  struct Val {
    ll a, b, c, d;
  };

  V<Val> vs(Q);

  rep(i, Q) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b;
    vs[i] = {a, b, c, d};
  }

  ll res = 0;

  repf(a1, 1, M + 1) repf(a2, a1, M + 1) repf(a3, a2, M + 1) repf(a4, a3, M + 1)
      repf(a5, a4, M + 1) repf(a6, a5, M + 1) repf(a7, a6, M + 1)
          repf(a8, a7, M + 1) repf(a9, a8, M + 1) repf(a10, a9, M + 1) {
    V<ll> a = {a1, a2, a3, a4, a5, a6, a7, a8, a9, a10};

    ll s = 0;
    for (auto v : vs) {
      if (a[v.b] - a[v.a] == v.c) s += v.d;
    }

    chmax(res, s);
  }

  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 3656
n = int(input())
l = [_ for _ in range(1,10)]

cnt = 9
for i in range(10**5):
    if cnt >= n:
        break
    if str(l[i])[-1] == '0':
        l.append(l[i]*10 + int(str(l[i])[-1]))
        l.append(l[i]*10 + int(str(l[i])[-1]) + 1)
        cnt += 2

    elif str(l[i])[-1] == '9':
        l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
        l.append(l[i]*10 + int(str(l[i])[-1]))
        cnt += 2

    else:
        l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
        l.append(l[i]*10 + int(str(l[i])[-1]))
        l.append(l[i]*10 + int(str(l[i])[-1]) + 1)
        cnt += 3

print(l[n-1])

Measured memory_bytes: 7152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 100110;
const ll INF = 1e15;
const ll MOD = 1e9+7;
ll N,a,b,c,d,e;
ll A[MAXN];
ll B[MAXN];
vi V;

int main(){
    cin>>a>>b>>c>>d;
    e=0;
    e+=min(d,a);
    d-=(a+b);
    if(d>0)e-=d;
    cout<<e;
}

Measured memory_bytes: 3640
#include <stdio.h>

int
main(void)
{
	char s[5];
	scanf("%s", s);

	int i;
	for (i = 1; i < 4; i++) {
		if (s[i] == s[i - 1]) {
			puts("Bad");
			return (0);
		}
	}
	puts("Good");
	return (0);
}


Measured memory_bytes: 128
magic = 2019
mid = magic // 2
l, r = [int(i) for i in input().split()]
if r - l >= 2019:
    print(0)
else:
    l = l % magic
    r = r % magic
    if l >= mid and r <= mid:
        print(0)
    else:
        ans = 2019
        for i in range(min(l,r), max(l,r)+1):
            for j in range(i+1, max(l,r)+1):
                ans = min(ans, i*j % 2019)
        print(ans)

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

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout <<a[0]<<" "<<a[1]<<" "<<a[2]<< endl;
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long K, std::vector<long long> A){


  for(long long i = K; i < N; i++) {
    cout << ((A[i-K] < A[i]) ? YES : NO) << endl;
  }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	int sum = 0;
	for(int i=1;i<=n;i++) {
		if(i % 3 && i % 5) sum += i;
	}
	cout << sum << endl;
	
}





Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstdio>



int main()
{
    char s[51][51];
    int h,w,i,j,con,ans,k,l;
    ans=0;

    for(i=0; i<=50; i++)
    {
        for(j=i; j<=50; j++)
        {
            s[i][j]=s[j][i]='.';
        }
    }
    scanf("%d%d",&h,&w);
    getchar();
    ans++;

    if(ans!=1) printf("\n");
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            scanf("%c",&s[i][j]);
        }
        getchar();
    }
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            if(s[i][j]!='#')
            {
                con=0;
                for(k=-1; k<=1; k++)
                {
                    for(l=-1; l<=1; l++)
                    {
                        if(s[i+k][j+l]=='#')
                            con++;
                    }
                }
                s[i][j]='0'+con;
            }
        }
    }


    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            printf("%c",s[i][j]);
        }
        printf("\n");
    }

    return 0;
}


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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
using ll = long long int;
using ull =  unsigned long long int;

int main() {
	int N, M;
	cin >> N >> M;
	int a = 1, b = N;
	for (int i = 0; i < M; i++) {
		int a_, b_;
		cin >> a_ >> b_;
		a = max(a, a_);
		b = min(b, b_);
	}
	if (a > b) {
		cout << 0 << endl;
	}
	else {
		cout << b - a + 1 << endl;
	}
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(len(L)):
    for j in range(len(L)):
        for k in range(len(L)):
            if i < j < k:
                if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                    continue
                if L[i] + L[j] + L[k] <= max(L[i], L[j], L[k]) * 2:
                    continue
                ans += 1

print(ans)

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

int main()
{

	int n,w;
	cin >> n >> w;

	vector<int> vv(n);
	vector<int> ww(n);

	for (int i=0;i<n;++i)
	{
		cin >> vv[i] >> ww[i];
	}

	vector<int> dp(w+1);
	for (int i=0;i<n;++i)
	{
		for (int j=ww[i];j<=w;++j)
		{
			dp[j]=max(dp[j],dp[j-ww[i]]+vv[i]);
		}
	}

	int maximum=0;
	for (int i=0;i<=w;++i)
	{
		maximum=max(maximum,dp[i]);
	}
	cout << maximum << endl;
}







Measured memory_bytes: 3152
import sys
import numpy as np

pin = np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep='\n')
N = pin[0]
a = pin[1:]
b = -1 -a
c = np.zeros(N, dtype=np.int32)
for d in b:
    i = np.searchsorted(c, d, side='right')
    c[i] = d

print((c < 0).sum())

Measured memory_bytes: 15236
n = int(input())
a = list(input().split())
a1 = ['']*(n//2 + n%2)
a2 = ['']*(n//2)

for i in range(n):
	if i%2 == 0:
		a1[i//2] = a[i]
	else:
		a2[-i//2] = a[i]

if n%2 != 0 and n != 1:
	ans = ' '.join(a1[::-1]) + ' ' + ' '.join(a2[::-1])
elif n%2 == 0:
	ans = ' '.join(a2) + ' ' + ' '.join(a1)
else:
	ans = a[0]
print(ans)

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n, k;
    cin >> n >> k;
    ll d[k];
    ll a[k][100];
    ll num[n] = {};
    rep(i, k) {
        cin >> d[i];
        rep(j, d[i]) {
            cin >> a[i][j];
            num[a[i][j]-1]++;
        }
    }

    ll ans = 0;
    rep(i, n) {
        if ( num[i] == 0 ) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 10, M = 1010;

int n, m, res;
int h[N], e[M], ne[M], idx;
bool st[N];

void dfs(int u, int cnt)
{
	if (cnt >= n)
	{
		res ++ ;
		return;
	}
	
	for (int i = h[u]; ~i; i = ne[i])
	{
		int j = e[i];
		if (st[j]) continue;
		
		st[j] = true;
		dfs(j, cnt + 1);
		st[j] = false;
	}
}

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

int main()
{
	memset(h, -1, sizeof h);
	
	cin >> n >> m;
	while (m -- )
	{
		int a, b;
		cin >> a >> b;
		add(a, b), add(b, a);
	}
	
	st[1] = true;
	dfs(1, 1);
	
	cout << res << endl;
    return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if ((A == B && B != C) || (A == C && B != C) || (B == C && A != B)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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



int main() {
  int N;
  cin >> N;//10
  bool f = false;

  for(int i = 0; i <= 9; i++){
    for(int j = 0; j <= 9; j++){
      int sum = i*j;
      if(sum == N){
       f = true;
      }
    }
  }
if(f){
  cout << "Yes" << endl;
}else{ 
  cout << "No" << endl;
}


}

Measured memory_bytes: 3612
n, k = map(int, input().split())
l = [0] * (10**5 + 1)
for i in range(n):
    a, b = map(int, input().split())
    l[a] += b
s = 0
for i, v in enumerate(l):
    s += v
    if s >= k:
        print(i)
        break

Measured memory_bytes: 5748
Module _20190519

    Sub Main()

        Dim sRead As String = Console.ReadLine()
        Dim iLong As Integer = sRead.Split(" ")(0)
        Dim iOrder As Integer = sRead.Split(" ")(1)
        Dim sStr As String = Console.ReadLine()

        Dim arrChar() As Char = sStr.ToCharArray()

        Dim sNewStr As String = ""

        For i As Integer = 0 To iLong - 1

            If i + 1 = iOrder Then

                Select Case arrChar(i)
                    Case "A"

                        sNewStr = sNewStr & "a"

                    Case "B"

                        sNewStr = sNewStr & "b"

                    Case "C"

                        sNewStr = sNewStr & "c"
                End Select

            Else

                sNewStr = sNewStr & arrChar(i)

            End If

        Next

        Console.WriteLine(sNewStr)

    End Sub

End Module


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

// dfmt off
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;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N = lread();
    auto A = new long[](N);
    foreach (i; 0 .. N)
        A[i] = lread();
    auto B = A.dup;
    B.sort();
    long pm = B[$ - 2];
    long cm = long.min;
    long mi = -1;
    foreach (i; 0 .. N)
        if (cm < A[i])
        {
            cm = A[i];
            mi = i;
        }
    foreach (i; 0 .. N)
        writeln((i == mi) ? pm : cm);
}


Measured memory_bytes: 5884
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;


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

    vector<int> h(n);
    int count=0;
    int max=0;

    cin >> h.at(0);
    for (int i = 1; i < n; i++)
    {
        cin >> h.at(i);
        if (h.at(i-1)>=h.at(i))
        {
            count++;
        }
        else if (count > max)
        {
            max = count;
            count = 0;
        }
        else
        {
            count=0;
        }


    }
    if (count>max)
    {
        max=count;
    }
    
    cout << max << endl;
}


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

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

int main()
{
    fastio;
    int n;cin>>n;
    ll a[n];
    map<ll,ll> m;
    rep(i,0,n)
    cin>>a[i],m[a[i]]++;
    ll ans=0;
    for(auto x: m)
        ans+=((x.S*(x.S-1))/2);
    rep(i,0,n)
    {
        ans-=((m[a[i]]*(m[a[i]]-1))/2);
        ans+=((m[a[i]]-1)*(m[a[i]]-2))/2;
        cout<<ans<<endl;
        ans-=((m[a[i]]-1)*(m[a[i]]-2))/2;
        ans+=((m[a[i]]*(m[a[i]]-1))/2);
    }
}


Measured memory_bytes: 11136
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for l in range(K+1):
    for r in range(K+1-l):
        if l + r > N:
            break
        L = V[:l]
        R = V[N-r:]

        hoge = L + R
        hoge.sort()
        #print(l, r, hoge)
        
        ind = min(K - (l + r), len(hoge)) - 1
        while ind >= 0:
            if hoge[ind] < 0:
                break
            ind -= 1
        if ind >= 0:
            ans = max(ans, sum(hoge[ind+1:]))
        else:
            ans = max(ans, sum(hoge))
        
print(ans)


Measured memory_bytes: 42860
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
    int count=0,len1,len2,i,j;
    char w[11],t[1001];

    scanf("%s",w);
    len1=strlen(w);
    for(i=0;i<len1;i++){
      w[i]=toupper(w[i]);
    }

    while(1){
        scanf("%s",t);
        if(!strcmp(t,"END_OF_TEXT")){
            break;
        }

        len2=strlen(t);
        for(j=0;j<len2;j++){
           t[j]=toupper(t[j]);
        }
        
        if(!strcmp(t,w)){
            count++;
        }
    }

    printf("%d\n",count);

    return 0;
}

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

int n,m,X,tot=0,root,r[100005];
int lch[8000005],rch[8000005];
int minv[8000005],maxv[8000005];
int set[8000005],add[8000005];
struct Question{
    int t,a,id;
}q[100005];
int ans[100005];

bool comp(Question a,Question b){return a.t<b.t;}

int newnode(int &o,int x,int y){
    o=++tot,minv[o]=x,maxv[o]=y,set[o]=-1;
}

void pushup(int o){
    minv[o]=min(minv[lch[o]],minv[rch[o]]);
    maxv[o]=max(maxv[lch[o]],maxv[rch[o]]);
}

void pushdown(int o,int l,int r){
    int mid=l+r>>1;
    int &lc=lch[o],&rc=rch[o];
    if(!lc)newnode(lc,l,mid-1);
    if(!rc)newnode(rc,mid,r-1);
    if(~set[o]){
        minv[lc]=maxv[lc]=set[lc]=set[o];
        minv[rc]=maxv[rc]=set[rc]=set[o];
        add[lc]=add[rc]=0,set[o]=-1;
    }
    if(add[o]){
        minv[lc]+=add[o],maxv[lc]+=add[o],add[lc]+=add[o];
        minv[rc]+=add[o],maxv[rc]+=add[o],add[rc]+=add[o];
        add[o]=0;
    }
}

void Sub(int &o,int l,int r,int x){
    if(o==0)newnode(o,l,r-1);
    if(maxv[o]<=x)
        maxv[o]=minv[o]=add[o]=set[o]=0;
    else if(minv[o]>=x)
        maxv[o]-=x,minv[o]-=x,add[o]-=x;
    else{
        pushdown(o,l,r);
        int mid=l+r>>1;
        Sub(lch[o],l,mid,x),Sub(rch[o],mid,r,x);
        pushup(o);
    }
}

void Add(int &o,int l,int r,int x){
    if(o==0)newnode(o,l,r-1);
    if(minv[o]>=X-x)
        maxv[o]=minv[o]=set[o]=X,add[o]=0;
    else if(maxv[o]<=X-x)
        maxv[o]+=x,minv[o]+=x,add[o]+=x;
    else{
        pushdown(o,l,r);
        int mid=l+r>>1;
        Add(lch[o],l,mid,x),Add(rch[o],mid,r,x);
        pushup(o);
    }
}

int query(int o,int l,int r,int x){
    if(o==0)newnode(o,l,r-1);
    if(r-l==1)return minv[o];
    pushdown(o,l,r);
    int mid=l+r>>1;
    if(x<mid)return query(lch[o],l,mid,x);
    else return query(rch[o],mid,r,x);
}

int main(){
    scanf("%d%d",&X,&n);
    for(int i=1;i<=n;i++)scanf("%d",r+i);
    r[n+1]=1e9;
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&q[i].t,&q[i].a);
        q[i].id=i;
    }
    sort(q+1,q+m+1,comp);
    for(int i=0,j=1,rev=0;i<=n;i++,rev^=1){
        while(j<=m&&q[j].t<=r[i+1]){
            int tmp=query(root,1,X+1,q[j].a);
            if(rev)tmp=min(X,tmp+q[j].t-r[i]);
            else tmp=max(0,tmp-q[j].t+r[i]);
            ans[q[j++].id]=tmp;
        }
        if(j>m)break;
        int tmp=r[i+1]-r[i];
        if(rev)Add(root,1,X+1,tmp);
        else Sub(root,1,X+1,tmp);
    }
    for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
} 

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast
    ll c = 0;
    string s, t;
    cin >> s >> t;
    REP(i, 0, s.size())
        if (s[i] == t[i])
            c++;
    cout << c << endl; 
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

vector<int> g[100000];
bool use[100000];
int out[100000];
vector<P> ans;

void dfs1(int v, int p) {
  use[v] = true;
  REP(i, g[v].size()) {
    int to = g[v][i];
    if (to == p) continue;
    if (!use[to]) {
      dfs1(to, v);
    } else if (v < to) {
      ans.push_back(P(v, to));
      out[v]++;
    }
  }
}

void dfs2(int v, int p) {
  use[v] = true;
  REP(i, g[v].size()) {
    int to = g[v][i];
    if (to == p) continue;
    if (!use[to]) {
      dfs2(to, v);
    }
  }
  if (p != -1) {
    if (out[v] % 2) {
      ans.push_back(P(v, p));
      out[v]++;
    } else {
      ans.push_back(P(p, v));
      out[p]++;
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (m % 2) {
    puts("-1");
    return 0;
  }
  dfs1(0, -1);
  REP(i, n) use[i] = false;
  dfs2(0, -1);
  REP(i, ans.size()) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 16116
N = input()
keta = len(N)

cnt = 0
for i in range(1, keta + 1):
    if i != keta:
        if i % 2 != 0:
            cnt += (10 ** i) - (10 ** (i - 1))
    else:
        if i % 2 != 0:
            cnt += int(N) - (10 ** (i - 1) - 1)

print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	char a, b;
	cin >> a >> b;
	string A, B;
	for (int i = 0; i < (b - '0'); i++)A += a;
	for (int i = 0; i < (a - '0'); i++)B += b;
	puts(min(A, B));

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 305

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n, ans=0;
int A[16], x[16][16], y[16][16];

bool func(set<int> S){
  rep(i,n){
    rep(j,A[i]){
      if(S.find(i)==S.end()){//iが正直者
        if(S.find(x[i][j]-1)==S.end() && y[i][j]==0){
          return false;
        }
        if(S.find(x[i][j]-1)!=S.end() && y[i][j]==1){
          return false;
        }
      }
    }
  }
  return true;
}

int main(){
  cin >> n;
  rep(i, n){
    cin >> A[i];
    rep(j, A[i]){
      cin >> x[i][j] >> y[i][j];
    }
  }
  for (int bit = 0; bit < (1<<n); ++bit) {
        set<int> S;
    	S.clear();
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                S.insert(i);
            }
        }
        if(func(S) && ans<n-S.size()){
          ans=n-S.size();
        }
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define MAX_N 2 * 100001
using namespace std;

typedef struct edge_count {
    int A, B;
} EC;

vector<int> graph[MAX_N];
EC node_state[MAX_N];
bool deleted[MAX_N];
string s;

void dfs(int u) {
    if (deleted[u]) return;
    deleted[u] = true;
    for (int i = 0; i < graph[u].size(); i++) {
        if (s[u] == 'A') node_state[graph[u][i]].A--;
        else node_state[graph[u][i]].B--;
        if (node_state[graph[u][i]].A == 0 || node_state[graph[u][i]].B == 0) dfs(graph[u][i]);
    }
    return;
}

int main() {
    int N, M, a, b;
    cin >> N >> M >> s;
    for (int i = 0; i < N; i++) {
        node_state[i].A = node_state[i].B = 0;
    }
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--, b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        if (s[a] == 'A') node_state[b].A++;
        else node_state[b].B++;
        if (s[b] == 'A') node_state[a].A++;
        else node_state[a].B++;
        if (a == b) {
            if (s[a] == 'A') node_state[b].A--;
            else node_state[b].B--;
        }
    }
    for (int i = 0; i < N; i++) deleted[i] = false;
    for (int i = 0; i < N; i++) {
        if (node_state[i].A == 0 || node_state[i].B == 0) dfs(i);
    }
    for (int i = 0; i < N; i++) {
        if (! deleted[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int isprime(int x){
    int i = 3;
    int root_x= sqrt((float)x);
    if (x == 2) return 1;

    if( x < 2 || x % 2 == 0 ) return 0;
    while(i <= root_x ){
        if (x % i == 0) return 0;
        i += 1;
    }
return 1;
}
int main(){
    int n;
    int N[15000];
    int ans=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> N[i];
        ans +=isprime(N[i]);
        }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3096
def main():
    stack = []
    for s in input().split():
        if s == '+' or s == '-' or s == '*':
            y = stack.pop()
            x = stack.pop()
            expression = x + s + y
            stack.append(str(eval(expression)))
        else:
            stack.append(s)
    print(stack[-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 5572
#include <iostream> // cout, endl, cin
#include <iomanip>
#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 <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B + C <= 21)
    {
        cout << "win" << endl;
    }
    else
    {
        cout << "bust" << endl;
    }
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, K; cin >> A >> B >> K;
    
    REP(i, K) {
        if (i%2==0) {
            if (A % 2 == 1) A--;
            B += A / 2;
            A /= 2;
        } else {
            if (B % 2 == 1) B--;
            A += B / 2;
            B /= 2;
        }
    }    
    
    cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M;
	ll H[100001];
	vint adj[100001];
	scan(N>>M);
	rep(i,N) scan(H[i]);
	rep(i,M){
		int A,B;
		scan(A>>B);
		A--; B--;
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	int ans=0;
	rep(i,N){
		ll hmax=0;
		rep(j,adj[i].size()){
			hmax=max(hmax,H[adj[i][j]]);
		}
		if(H[i]>hmax) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 9532
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	int M;
	M = S.size();
	int i=0;
	int T=0;
	while (i < M) {
		T += S[i] - '0';
		i++;
	}
	if (T % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3360
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long ans=0;
    for(int c=1; c<n; c++){
        int lef = n-c;
        int lim;
        lim = sqrt(lef);
        //cout << lim;
        for(int a=1; a<=lim; a++){
            if(lef%a ==0 ){
                if( lef/a == a){
                    ans = ans + 1;
                }else{
                    ans = ans + 2;
                }
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3672