akhauriyash/Code-Regression huggingface dataset:
N = int(input())
u, v, w = [0]*(N-1), [0]*(N-1), [0]*(N-1)
n = [-1] * N
# n[][0] 色　n[][1] 連結先一覧リスト n[][2] mod2 
for i in range(N):
    n[i] = [0]*4
    n[i][1] = []
    n[i][2] = []

for i in range(N-1):
    u[i], v[i], w[i] = list(map(int, input().split()))
    n[u[i]-1][1].append(v[i]-1)
    n[v[i]-1][1].append(u[i]-1)
    n[u[i]-1][2].append(w[i]%2)
    n[v[i]-1][2].append(w[i]%2)

stack = [u[0]-1]

while True:
    num = stack.pop()
    n[num][3] = 1
    for i in range(len(n[num][1])):
        if n[n[num][1][i]][3] == 0:
            stack.append(n[num][1][i])
            if n[num][2][i] == 0:
                n[n[num][1][i]][0] = n[num][0]
            else:
                n[n[num][1][i]][0] = -1 * n[num][0] + 1
    if len(stack) == 0:
        break

for i in n:
    print(i[0])

Measured memory_bytes: 57044
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    ll k,a,b;
    cin >> k >> a >> b;
    ll ans = k + 1;
    if(b<=a+2){
        ans = k + 1;
    }else{
        if(k<=a-1){
            ans = k + 1;
        }else{
            k -= a-1;
            ll num = k/2;
            ll hoge = a + num*(b-a);
            k -= num*2;
            if(k==1)hoge++;
            ans = hoge;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//グラフ

#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N, M;
  cin >> N >> M;
  vector <int> H(N);
  vector <bool> ok(N, true);
  rep(i,N) cin >> H[i];
  rep(i,M){
    int a, b;
    cin >> a >> b;
    a--; b--;  //0-indexedに直す
    if (H[a] <= H[b]) ok[a] = false;
    if (H[b] <= H[a]) ok[b] = false;
  }
  int ans = 0;
  rep(i,N) if (ok[i]) ans ++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3796
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
bool comp(vector<ll> v1, vector<ll> v2)
{
    if(v1[0]>v2[0]) return true;
    return false;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k; cin>>n>>k;
    vector<vector<ll>> v(n);
    for(int i=1;i<=n;i++){
        ll a,x; cin>>a>>x;
        a--;
        v[a].push_back(x);
    }
    for(int i=0;i<n;i++){
        if(v[i].size()==0) v[i].push_back(INT_MIN);
        else {
            sort(v[i].rbegin(),v[i].rend());
        }
    }
    sort(v.begin(),v.end(),comp);
    priority_queue<ll> pq;
    ll ans=k*k;
    ll sum=0;
    for(int i=0;i<k;i++){
        sum+=v[i][0];
        for(int j=1;j<v[i].size();j++) pq.push(v[i][j]);
    }
    ans=ans+sum;
    
    for(int i=k;i<n;i++){
        for(int j=0;j<v[i].size();j++) pq.push(v[i][j]);
    }
    for(int i=k-1;i>=1;i--)
    {
        ll a=v[i][0]; ll b=pq.top();
        if(a>=b) break;
        pq.pop();
        sum-=a; sum+=b;
        pq.push(a);
        ans=max(ans,sum+(ll)i*i);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 11576
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string, int> P;

int main() {
	int h, w;
	while(scanf("%d %d", &h, &w), h && w) {
		rep(i, h) {
			rep(j, w) {
				if(i % 2 == 0) {
					if(j % 2 == 0) printf("#");
					else printf(".");
				}
				else {
					if(j % 2 == 0) printf(".");
					else printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3104
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

n = int(input())
a = list(map(int, input().split()))
r = []
l = []
t = a[0]
for i in a:
    t = gcd(t, i)
    l.append(t)
t = a[-1]
for i in a[::-1]:
    t = gcd(t, i)
    r.append(t)
r = r[::-1]
ans = 0
for i in range(n):
    if i == 0:
        ans = max(ans, r[1])
        continue
    if i == n - 1:
        ans = max(ans, l[-2])
        continue
    ans = max(ans, gcd(l[i-1], r[i+1]))

print(ans)


Measured memory_bytes: 14428
use whiteread::parse_line;

fn main() {
    let (q, h, s, d): (usize, usize, usize, usize) = parse_line().unwrap();
    let n: usize = parse_line().unwrap();
    let ans;

    let h = h.min(q * 2);
    let s = s.min(h * 2);
    let d = d.min(s * 2);

    if s * 2 < d {
        ans = n * s;
    } else {
        ans = n / 2 * d + n % 2 * s;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2148
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>

using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
int DX[4]={1,0,-1,0};
int DY[4]={0,1,0,-1};

typedef pair<int,int> Pii;


#define SUPnl 100002

int nl;
Pii pt[SUPnl];	//pt[n].F == n's parent, pt[n].S == w[pt[n].F]-w[n]

void init(){REP(ni,nl){pt[ni]=MP(ni,0);}}

Pii getRoot(int n){
	if(pt[n].F==n) return pt[n];
	Pii rpnt = getRoot(pt[n].F);
	pt[n]= MP(rpnt.F, rpnt.S+pt[n].S);
	return pt[n];
}

void printW(int a, int b){
	Pii rat=getRoot(a); Pii rbt=getRoot(b);
	if(rat.F!=rbt.F) //cout<<"UNKNOWN"<<endl;
					printf("UNKNOWN\n");
	else //cout<< rbt.S - rat.S << endl;
		printf("%d\n", rbt.S - rat.S );
}

void setW(int a, int b, int w){
	Pii rat=getRoot(a); Pii rbt=getRoot(b);
	if(rat.F==rbt.F) return;
	if(rat.S+w>=rbt.S){
		pt[rbt.F]=MP(rat.F, rat.S+w-rbt.S);
	}else{
		pt[rat.F]=MP(rbt.F, rbt.S-w-rat.S);
	}
}

int main(){
	while(true){
		int ol;
		cin>>nl>>ol;	//scanf("%d%d", &nl, &ol);
							if(!nl) return 0;
		init();
		REP(oi,ol){
			char ot; int a,b,w;
			cin>>ot;		//scanf(" %c ", &ot);
			if(ot=='!'){
				cin>>a>>b>>w;		//scanf("%d%d%d",&a,&b,&w);
				setW(a-1,b-1,w);
			}
			if(ot=='?'){
				cin>>a>>b;			//scanf("%d%d",&a,&b);
				printW(a-1,b-1);
			}
		}
	}
}

Measured memory_bytes: 2968
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int comb(int n, int r){
  if(r < 0 || n < r) return 0;
  if(r == 1) return n;
  if(r == 2) return n*(n-1)/2;
  return n*(n-1)*(n-2)/6;
}

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

  cout << comb(N, 2)+comb(M, 2) << "\n";

  return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/22  Problem: ABC 052 D / Link: http://abc052.contest.atcoder.jp/tasks/abc052_d  ----- */


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

	LL N, A, B; cin >> N >> A >> B;
	vector<LL> x(N);
	for (int i = 0; i < N; ++i) {
		cin >> x[i];
	}
	LL ans = 0LL;
	FOR(i, 0, N - 1) {
		ans += min(B, A*(x[i + 1] - x[i]));
	}

	
	
	cout << (ans) << "\n";

	return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N; string S, T;
  cin >> N;
  cin >> S >> T;
  REP(n,N) {
    cout << S[n] << T[n];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W = read().rstrip()

N = len(W)

def Z_algorithm(S):
    # 共通接頭辞の長さを返す
    N=len(S)
    arr = [0]*N
    arr[0] = N
    i,j = 1,0
    while i<N:
        while i+j<N and S[j]==S[i+j]:
            j += 1
        arr[i]=j
        if not j:
            i += 1
            continue
        k = 1
        while i+k<N and k+arr[k]<j:
            arr[i+k] = arr[k]
            k += 1
        i += k; j -= k
    return arr

def is_periodic_left(W):
    Z = Z_algorithm(W)
    is_periodic = [False] * N
    for p in range(1,N//2 + 1):
        if is_periodic[p-1]:
            continue
        for i in range(p,N,p):
            if Z[i] >= p:
                is_periodic[p + i - 1] = True
            else:
                break
    return is_periodic

L = is_periodic_left(W)
R = is_periodic_left(W[::-1])[::-1]

if not L[-1]:
    answer = (1,1)
elif len(set(W)) == 1:
    answer = (N,1)
else:
    x = sum(not(x or y) for x,y in zip(L,R[1:]))
    answer = (2,x)
print('\n'.join(map(str,answer)))

Measured memory_bytes: 72196
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K = MI()
A = LI()

from itertools import accumulate

for _ in range(min(K,100)):
    B = [0]*(N+1)
    for i in range(N):
        a = A[i]
        B[max(i-a,0)] += 1
        B[min(N,i+a+1)] -= 1
    C = list(accumulate(B))
    A = C

print(*[A[i] for i in range(N)])


Measured memory_bytes: 241372
n = list(map(int,list(input())))

num = n[0]
total = 0
for i in range(1,len(n)):
    if n[i] == n[i-1]:
        total += 1
        if n[i] == 1:
            n[i] = 0
        else:
            n[i] = 1

print(total)

Measured memory_bytes: 4652
import sys
from collections import deque
from collections import defaultdict
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
 
n,q = map(int,input().split())
x = []
for i in range(n):
        x.append(list(map(int,input().split())))
x.sort(key = lambda x : x[2])
dd = []
zaa = []
for i in range(q):
        a = int(input())
        dd.append(a)
        zaa.append(a)
y = []
 
for i in range(n):
        a = x[i][0]-x[i][2]
        b = x[i][1]-1-x[i][2]
        y.append([a,b])
        zaa.append(a)
        zaa.append(b)
import bisect
ans = [-1]*q
tobi = [-1]*q
#print(dd,y)
for i in range(n):
        xx = bisect.bisect_left(dd,y[i][0])
        yy = bisect.bisect_left(dd,y[i][1]+1)
        j = xx
 #       print(xx,yy)
 #       print(ans,tobi)
        while j < yy:
                if ans[j] == -1:
                        ans[j] = x[i][2]
                        tobi[j] = yy
                        j += 1
                        
                else:
                        tmp = tobi[j]
                        tobi[j] = yy
                        j = tmp
for i in ans:
        print(i)

Measured memory_bytes: 106480
n=int(input())
a=[input().split() for i in range(n)]
l=[]
for j in range(13):
    ll=[]
    ll.append("S")
    ll.append(str(j+1))
    l.append(ll)
for j in range(13):
    ll=[]
    ll.append("H")
    ll.append(str(j+1))
    l.append(ll)
for j in range(13):
    ll=[]
    ll.append("C")
    ll.append(str(j+1))
    l.append(ll)
for j in range(13):
    ll=[]
    ll.append("D")
    ll.append(str(j+1))
    l.append(ll)
for k in range(len(l)):
    if l[k] not in a:
        o=" ".join(l[k])
        print(o)


Measured memory_bytes: 5604
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>

using namespace std;

int main(void)
{
    long long N, M, i, ans=0, a, b;

    cin >> N >> M;

    vector<pair<long long, long long>> pairs(N);

    for(i=0; i<N; i++){
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }

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

    for(i=0; i<N; i++){
        if(M > pairs[i].second){
            ans += pairs[i].first * pairs[i].second;
            M -= pairs[i].second;
        }
        
        else{
            ans += pairs[i].first * M;

            break;
        }
    }

    cout << ans << endl;

    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vpll v(n);
  rep(i,n){
    ll a,b; cin>>a>>b;
    v[i]={a,b};
  }
  vsort(v);
  ll cnt=0;
  rep(i,n){
    cnt+=v[i].second;
    if(k<=cnt){
      cout<<v[i].first<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1792
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int A = int.Parse(str[0]);
        int B = int.Parse(str[1]);
        if(A == B){
            sb.Append("Draw");
        }
        else if(A == 1 || (A > B && B != 1)){
            sb.Append("Alice");
        }
        else{
            sb.Append("Bob");
        }
        sb.Append("\n");
    }
}

Measured memory_bytes: 11092
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long l = sc.nextLong();
    long[] a = new long[n];
    long max = 0;
    int p = 0;
    for(int i = 0;i < n;i++)a[i]=sc.nextLong();
    for(int i = 0;i < n-1;i++){
      max = Math.max(max,a[i]+a[i+1]);
      if(a[i]+a[i+1]==max)p=i;
    }
    if(a[p]+a[p+1]<l)System.out.println("Impossible");
    else{
      System.out.println("Possible");
      for(int i = 1;i <= p;i++)System.out.println(i);
      for(int i = n-1;i>=p+1;i--)System.out.println(i);
    }
  }
}


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

vector < int > v , c ; 

int main() {

    int n, k ; 
    cin >> n >> k ; 
    v.resize(n) ;
    c.resize(n) ;
    
    c[0] = 0 ; 
    
    for ( int i = 0 ; i < n ; ++i ){
        cin >> v[i] ;
        
        if ( i > 0 ){
            c[i] = 1e9 ; 
            
            for ( int j = 1 ; j <= k && j <= i ; ++j ){
                c[i] = min ( c[i] , abs ( v[i] - v[i-j] ) + c[i-j] ) ;
            }
            
        }
    }
    
    cout << c[n-1] ; 
    

  return 0 ; 
}

Measured memory_bytes: 1024
n, k, q = map(int, input().split())
p = [k]*n
a = []
ans = ['No'] * n
counts = {}

for i in range(q):
    a.append(int(input()))

for i in range(len(a)):
    key = a[i]
    if key in counts:
        counts[key] += 1
    else:
        counts[key] = 1

for key, value in counts.items():
    idx = key - 1
    p[idx] += value

#print('p: ' + str(p))
for i in range(len(p)):
    p[i] -= q

for i in range(len(p)):
    if p[i] > 0:
        ans[i] = 'Yes'

# print('counts: ' + str(counts))
# print('p: ' + str(p))
# print(a)
# print(ans)

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

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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i += 2)
    {
        int cnt = 0;
        for(int j = 1; j <= i; j ++)
            cnt += (i % j == 0);
        ans += (cnt == 8);
    }
    cout << ans;











    getchar();
    getchar();
    return 0;
    //ios::sync_with_stdio(false);
    //cin.tie(0);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int n, A, B;
int main() {
	int i, j, k;
	scanf("%d%d%d", &n, &A, &B);
	if((A+B)&1) printf("Borys\n");
	else printf("Alice\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 6001001001001001001;
long double EPS = 1e-6;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll N;
string S;
ll fact[1000010];

void fill(){
    fact[0] = 0;
    FOR(i,1,1000010){
        ll cnt = 0,I = i;
        while(I % 2 == 0 && I != 0){
            cnt++;
            I /= 2;
        }
        fact[i] = cnt + fact[i-1];
    }
}

int main(){
    cin >> N >> S;
    rep(i,N){
        S[i] = S[i] - 1;
    }
    fill();
    ll  cnt = 0;
    rep(i,N) if(S[i] == '1' && fact[N-1] == fact[i] + fact[N-i-1]) cnt++;
    if(cnt % 2 == 1){
        cout << 1 << endl;
        return 0;
    }
    bool flag = 0;
    rep(i,N) if(S[i] == '1') flag = 1;
    if(flag){
        cout << 0 << endl;
        return 0;
    }
    rep(i,N) if(S[i] == '2') S[i] = '1';
    cnt = 0;
    rep(i,N) if(S[i] == '1' && fact[N-1] == fact[i] + fact[N-i-1]) cnt++;
    if(cnt % 2 == 1){
        cout << 2 << endl;
        return 0;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 9220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n + 1];
		int[] b = new int[n];

		long ans = 0;
		int i;
		for(i = 0; i < n + 1; i++) {
			a[i] = scan.nextInt();
			ans += a[i];
		}
		for(i = 0; i < n; i++)
			b[i] = scan.nextInt();
		for(i = n - 1; i >= 0; i--) {
			int temp = b[i];
			if(a[i + 1] >= temp) {
				a[i + 1] -= temp;
			}else {
				int temp2 = temp - a[i + 1];
				a[i + 1] = 0;
				if(a[i] >= temp2) {
					a[i] -= temp2;
				}else {
					a[i] = 0;
				}
			}
		}
		for(i = 0; i < n + 1; i++) {
			ans -= a[i];
		}
		System.out.println(ans);
	}
}

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

long long N, K, l[1000009];

int main()
{
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> l[i];
    sort(l, l + N, greater<int>());
    long long sum = 0;
    for (int i = 0; i < K; i++){
        sum += l[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll h, w, x, y;
    cin >> h >> w >> x >> y;

    out(min(h, w) + min(x, y));
    
    
    re0;
}

Measured memory_bytes: 256
MOD=10**9+7
n,kk=map(int,input().split())

dp=[[[0]*(n**2+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0]=1

for i in range(1,n+1):
  for j in range(i+1):
    for k in range(n**2+1):
      if k-2*j<0:
        continue
      dp[i][j][k]=(2*j+1)*dp[i-1][j][k-2*j]  
      if j+1<=n:
        dp[i][j][k]+=(j+1)**2*dp[i-1][j+1][k-2*j]
      if j-1>=0:
        dp[i][j][k]+=dp[i-1][j-1][k-2*j]
      dp[i][j][k]%=MOD
      
print(dp[n][0][kk])

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    string s;cin >> s;
    lint k;cin >> k;
    REP(i,SZ(s)){
        lint x = 'z' - s[i] + 1;
        if(s[i]!='a'&&k>=x){
            k -= x;
            s[i] = 'a';
        }

        if(i==SZ(s)-1&&k>0){
            k %= 26;
            lint tmp = s[i] + k;
            if(tmp>'z')
                tmp -= 26;
            s[i] = (char)tmp;
        }
    }
    //lint ans=0;

    cout << s <<"\n";

    return 0;
}

Measured memory_bytes: 512
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>

using namespace std;

int main() {
	long long h;cin>>h;
	long long ans=0;
	while(h){
		ans*=2;ans+=1;
		h/=2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))

min_diff_temp = 710
out_i = 0
for i, x in enumerate(h):
    diff_temp = abs(a - (t - x * 0.006))
    if diff_temp < min_diff_temp:
        min_diff_temp = diff_temp
        out_i = i + 1

print(out_i)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool isReversible(string s) {
  // debug(s);
  string t = s;
  reverse(t);
  return s == t;
}

void solve() {
  string s; cin >> s;

  if (!isReversible(s)) {
    No();
    return;
  }

  int n = s.size(), len = (n-1)/2;
  if (isReversible(s.substr(0, len)) && isReversible(s.substr((n+1)/2, len))) Yes();
  else No();
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int n;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n;
  vv<double> v(n);
  cin >> v;

  sort(ALL(v));
  rep(i, 0, n-1) {
    v[i+1] = (v[i+1] + v[i]) / 2.0;
  }
  cout << fixed << setprecision(10) << v[n-1] << endl;
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

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;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

int dp[22][3000000];//dp[i][S]=i番目の男性までマッチング済み、集合Sの女性がマッチング済みの時の場合の数
int a[22][22];
int N;
int func(int i,int S) {
	if (dp[i][S] != -1) {
		//printf("%lld %lld: %lld\n", i, S, dp[i][S]);
		return dp[i][S];
	}
	int res = 0;
	int cnt = 0;
	REP(i, N) {
		if (S&(1 << i))cnt++;
	}
	if (i == cnt) {
		REP(j, N) {
			if (a[i - 1][j]) {
				if (S & (1 << j)) {
					//add(res, func(i - 1, S & ~(1 << j)));
					res += func(i - 1, S & ~(1 << j));
					res %= MOD;
				}
			}
		}
	}
	
	dp[i][S] = res;
	//printf("%lld %lld: %lld\n", i, S, res);
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	 cin >> N;
	REP(i, N) {
		REP(j, N) {
			cin >> a[i][j];
		}
	}
	REP(i, N + 1) {
		REP(j, 1 << N) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 1;
	int S = 0;
	REP(i, N) {
		S |= (1 << i);
	}
	print(func(N, S));
}


Measured memory_bytes: 405888
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
import bisect
A.sort()
B.sort()
C.sort()
ans = 0
for i in B:
    idx_1 = bisect.bisect_left(A, i)
    idx_2 = N - bisect.bisect(C, i)
    ans += idx_1 * idx_2
print(ans)

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

using namespace std;

typedef long long ll;

int main(){
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll gcd_CD = C*D/__gcd(C, D);
  ll not_ans = (B/C-(A-1)/C)+(B/D-(A-1)/D)-(B/gcd_CD-(A-1)/gcd_CD);
  cout << (B-A+1)-not_ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define RI register int
const int mod=1e9+7,N=2005;
int n,m,K,ans,f[N<<1][N][2],s[N];
int qm(int x) {return x>=mod?x-mod:x;}
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	f[0][0][0]=1;
	for(RI i=1;i<=max(n,m)*2;++i) {
		s[0]=qm(f[i-1][0][0]+f[i-1][0][1]);
		for(RI j=1;j<=n;++j)
			s[j]=qm(s[j-1]+qm(f[i-1][j][0]+f[i-1][j][1]));
		for(RI j=0;j<=n;++j) {
			f[i][j][0]=qm(s[j]-s[j-1]+mod);
			if(j) f[i][j][1]=qm(s[j-1]-(j-K>=0?s[j-K]:0)+mod);
		}
		for(RI j=0;j<=n;++j)
			if(j%(K-1)==n%(K-1)&&(i*(K-1)-j+1)%(K-1)==m%(K-1)&&i*(K-1)-j+1<=m)
				ans=qm(ans+f[i][j][1]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int H, N;
	cin >> H >> N;
	Int sum = 0;
	for (int i = 0; i < N; ++i) { 
		Int a;
		cin >> a;
		sum += a;
	}
	cout << (sum >= H ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a[1000005],u;
template<typename T>void read(T &a)
{
    T x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(; isdigit(c);c=getchar())x=x*10+c-'0';
    a=x*f;
}
int main()
{
	int n;
	cin>>n;
	int ans=0,k=0;
	char a;
		scanf("%c",&a);
	while(n--)
	{
		scanf("%c",&a);
		if(a=='I')k++;
		else k--;
		ans=max(ans,k);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))

for line in table:
    line.append(sum(line))

table.append([sum([line[i] for line in table]) for i in range(c + 1)])

for line in table:
    print(*line)



Measured memory_bytes: 6232
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#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 all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		vvi in(n,vi(m));
		rep(i,n)rep(j,m)cin>>in[i][j];
		int out=0;
		rep(i,n)rep(j,m)rep(k,n)rep(l,m)if(i+1<k&&j+1<l){
			int mi=inf,sum=0,ma=-1;
			loop(x,i,k+1)loop(y,j,l+1){
				if(x==i||x==k||y==j||y==l)mi=min(mi,in[x][y]);
				else{
					ma=max(ma,in[x][y]);
					sum+=in[x][y];
				}
			}
			if(ma<mi)out=max(out,(k-i-1)*(l-j-1)*mi-sum);
		}
		cout<<out<<endl;
	}
}













Measured memory_bytes: 3124
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,avx512f")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
using namespace std;
signed main() {
  int n;cin >> n;
  vector<int> a, b;
  a.reserve(n);
  b.reserve(n);
  for (int i = 0; i < n; ++i) { int t; cin >> t; a.emplace_back(t); }
  for (int i = 0; i < n; ++i) { int t; cin >> t; b.emplace_back(t); }
  int ans = 0;
  for (int i = 0; i < n; ++i)for (int j = 0; j < n; ++j) {
    ans ^= (a[i] + b[j]);
  }cout << ans << endl;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll l[100];
int main(void){
    cin>>n;
    l[0]=2; l[1]=1;
    for(int i=2;i<=n;i++){
        l[i]=l[i-1]+l[i-2];
    }
    cout<<l[n]<<endl;
    
}


Measured memory_bytes: 3552
import java.util.*;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		int[] ar = new int[N];
		
		for(int i=0; i < K; i++){
			int a =  scan.nextInt();
			for(int j =0; j<a; j++){
				ar[scan.nextInt() - 1]++;
			}
		}

		int con =0 ;
		for(int x :ar){
			if(x == 0) con++;
		}
		System.out.println(con);

	}

}

Measured memory_bytes: 37556
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
s = readline().rstrip().decode()
cumsum = []
check = []
flag = True
for i in range(n):
    if s[i] == '0':
        if flag:
            cumsum.append(i)
        flag = False
    else:
        if not flag:
            check.append(i)
        flag = True
if not flag:
    check.append(n)
cumsum.append(n)
if len(cumsum) - 1 <= k:
    print(n)
else:
    ans = cumsum[k]
    for i in range(k, len(cumsum) - 1):
        ans = max(ans, cumsum[i + 1] - check[i - k])
    print(ans)


Measured memory_bytes: 7168
S = list(input())
count = 0
pop = 0
AC = 0
    
for i in range(2,len(S)-1):
    if S[i] == 'C':
        count = count + 1
        pop = i
    
if S[0] == 'A':
    if count == 1:
        S[0] = 'a'
        S[pop] = 'c'
        m = ''.join(S)
        if str.islower(m):
            print('AC')
            AC = 1
            
            
if AC != 1:
    print('WA')

Measured memory_bytes: 3064
#include<iostream>
#include<queue>
using namespace std;
using ll = long long;

int main() {
  queue<ll> q;
  for(int i=1;i<10;++i)q.push(i);
  int k;
  cin>>k;
  ll x;
  for(int i=0;i<k;++i) {
    x=q.front();
    q.pop();
    ll _x=x*10+x%10;
    if(x%10)q.push(_x-1);
    q.push(_x);
    if(x%10!=9)q.push(_x+1);
  }
  cout<<x<<endl;
}

Measured memory_bytes: 5072
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        char s[] = sc.next().toCharArray();
        char t[] = sc.next().toCharArray();
        sc.close();

        System.out.println(n < m ? check(n, m, s, t) : check(m, n, t, s));
    }

    private long check(int min, int max, char s[], char t[]) {
        int g = gcm(max, min);
        int minp = min / g;
        int maxp = max / g;
        for (int i = 0; i < g; i++) {
            if (s[i * minp] != t[i * maxp]) {
                return -1;
            }
        }

        return ((long) min) * maxp;
    }

    private int gcm(int a, int b) {
        return b == 0 ? a : gcm(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
    }
}


Measured memory_bytes: 28712
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[505][505];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==1)putchar('#');
            else if(s[i][j]=='#'||(i!=n&&j%2==0))putchar('#');
            else putchar('.');
        }
        puts("");
    }
    puts("");
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==n)putchar('#');
            else if(s[i][j]=='#'||(i!=1&&j%2==1))putchar('#');
            else putchar('.');
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int x,a,b,c,i,n,p,q,y[10000],k=0;
bool sw=false;
int main(){
	while(cin>>n>>a>>b>>c>>x&&n!=0){
	p=x;q=(a*p+b)%c;
	for(int j=0;j<n;j++){
	cin>>y[j];}
		for(i=0;i<10001;i++){
			if(y[k]==p){
			k++;}
			if(k==n){
			cout<<i<<endl;sw=true;i=100000;}
		p=q;q=(a*p+b)%c;
		if(i==10000&&sw==false){
		cout<<-1<<endl;}}
    i=0;k=0;sw=false;
	}
    return 0;}


Measured memory_bytes: 1168
#include <algorithm>
#include <iostream>
#include <memory>
#include <stdio.h>
#include <string>

#define MAX_N 100'000

typedef long long ll;

using namespace std;

int S[5]{};
bool B[5]{};

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    if (s[0] == 'M') {
      ++S[0];
    } else if (s[0] == 'A') {
      ++S[1];
    } else if (s[0] == 'R') {
      ++S[2];
    } else if (s[0] == 'C') {
      ++S[3];
    } else if (s[0] == 'H') {
      ++S[4];
    }
  }
  memset(B, 1, 3);
  ll res = 0;
  do {
    ll t = 1;
    for (int i = 0; i < 5; ++i) {
      if (B[i]) {
        t *= S[i];
      }
    }
    res += t;
  } while (prev_permutation(B, B + 5));
  printf("%lld\n", res);
}

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

using namespace std;
const int inf = 1e9 + 7;
const int N = 1e6 + 1;
signed main () {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);
    int x;
    cin >> x;
    for (int i = 1;;i++) if (x * i % 360 == 0) return cout << i, 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	string s;
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s == "Y") {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
vi b_v;void bin(unsigned int n) { if (n > 1) bin(n>>1); b_v.pb(n & 1); }
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;osit;
	int n,l;
	cin>>n>>l;
	int a[n];
	int sum=0;
	rep(i,1,n+1){
		a[i]=l-1+i;
		sum+=a[i];
	}
	int ans;
	int mn=1e18;
	rep(i,1,n+1){
		int tsum=sum-a[i];
		if(abs(tsum-sum)<mn){
			mn=abs(tsum-sum);
			ans=tsum;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<random>
using namespace std;
using ll = int64_t;

int main() {
    ll L;
    cin >> L;
    double i = log(L) / log(3);
    ll j = ceil(i);
    ll last = j + 1;

    struct Edge {
        ll from, to, cost;
    };

    vector<Edge> ans;
    ll add = 0;
    for (ll i = 2; i <= last; i++) {
        ll curr = pow(3, last - i);
        for (ll j = 0; j < L / (ll)pow(3, last - i); j++) {
            ans.push_back({ 1, i, j * (ll)pow(3, last - i) + add });
        }
        add += curr * (L / curr);

        L %= (ll)pow(3, last - i);
    }
    for (ll i = 2; i < last; i++) {
        for (ll j = 0; j < 3; j++) {
            ans.push_back({ i, i + 1, j * (ll)pow(3, last - i - 1) });
        }
    }

    cout << last << " " << ans.size() << endl;
    for (Edge e : ans) {
        cout << e.from << " " << e.to << " " << e.cost << endl;
    }
}

Measured memory_bytes: 512