akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include "debug_print.hpp"
#else
void debug(...) {}
#endif

const int mod = 1000000007;
// const int mod = 998244353;

struct mint
{
    ll x;
    ll cnt;
    mint(ll x=0):x((x%mod+mod)%mod), cnt(0) {}
    mint operator-() const { return mint(-x);}
    mint &operator+=(const mint m)
    {
        if((x += m.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint m)
    {
        if((x += mod - m.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint m)
    {
        if(m.x == 0) cnt = 0;
        x *= m.x;
        if(x!=0) cnt += m.cnt;
        if(x >= mod)
        {
            cnt+=x/mod;
            x %= mod;
        }
        return *this;
    }
    mint operator+(const mint m) const
    {
        return mint(*this) += m;
    }
    mint operator-(const mint m) const
    {
        return mint(*this) -= m;
    }
    mint operator*(const mint m) const
    {
        return mint(*this) *= m;
    }
    mint pow(ll n) const
    {
        if(!n) return 1;
        mint m = pow(n>>1);
        m *= m;
        if(n & 1) m *= *this;
        return m;
    }
    mint inv() const { return pow(mod-2);}
    mint &operator/=(const mint m) { return *this *= m.inv();}
    mint operator/(const mint m) const { return mint(*this) /= m;}
};
istream &operator>>(istream &is, mint &m) { return is >> m.x;}
ostream &operator<<(ostream &os, const mint &m) { return os << m.x;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<ll> P, M;
    for(int i=0; i<N; i++)
    {
        ll a;
        cin >> a;
        if(a >= 0) P.push_back(a);
        else M.push_back(-a);
    }
    if(N==K)
    {
        mint ans = 1;
        for(auto p : P) ans *= p;
        for(auto m : M) ans *= -m;
        cout << ans << endl;
        return 0;
    }
    if(M.size() == N && K%2==1)
    {
        sort(M.begin(), M.end());
        mint ans = 1;
        for(int i=0; i<K; i++) ans *= M[i];
        ans *= -1;
        cout << ans << endl;
        return 0;
    }

    sort(P.begin(), P.end(), greater<ll>());
    sort(M.begin(), M.end(), greater<ll>());
    int pidx = 0;
    int midx = 0;
    mint ans = 1;
    while(pidx + midx < K)
    {
        ll x=-1, y=-1;
        if(pidx+1 < P.size()) x = P[pidx] * P[pidx+1];
        if(midx+1 < M.size()) y = M[midx] * M[midx+1];
        if(x > y || pidx+midx==K-1)
        {
            ans *= P[pidx];
            pidx++;
        }
        else
        {
            ans *= M[midx];
            ans *= M[midx+1];
            midx+=2;
        }
    }
    cout << ans << endl;

    return 0;
}


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

void swap(int &x, int &y)
{
	int t;
	t = x;
	x = y;
	y = t;
}
int main()
{
	int N; //????´???°
	int num = 0; //?????????????????°
	cin >> N;
	int* x = new int[N + 1];
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}

	for (int i = 0; i < N; i++) {
		for (int j = N - 1; j > i; j--) {
			if (x[j] < x[j - 1]) {
				swap(x[j], x[j - 1]);
				num++;
			}

		}
	}
	for (int i = 0; i < N-1; i++) {
		cout << x[i] << " ";
	}
	cout << x[N-1] << "\n";

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

Measured memory_bytes: 3092
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

long solve(long n, const std::vector<long>& heights)
{
  long result = 0;
  long current = heights.front();
  for (auto h : heights) {
    const auto diff = h - current;
    if (diff > 0) {
      current = h;
    } else {
      result -= diff;
    }
  }

  return result;
}

int main()
{
  long n;
  std::cin >> n;
  std::vector<long> heights(n);
  for (auto& h : heights) {
    std::cin >> h;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, heights) << std::endl;
}


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

using namespace std;

bool actg(char c){
    return (c == 'A' || c == 'C' || c == 'T' || c == 'G');
}

void count_ac(string& s, vector<int>& sum, vector<vector<int>>& target){
    for(int i = 0; i < s.size()-1; i++){
	if(s.at(i) == 'A' && s.at(i+1) == 'C'){
	    auto tt = target.at(i);
	    for(auto t: tt){
		sum.at(t)++;
	    }
	    i++;
	}
    }
}

void make_count_ac(string& s, vector<int>& ret){
    int sum = 0;
    for(int i = 0; i < s.size()-1; i++){
	if(s.at(i) == 'A' && s.at(i+1) == 'C'){
	    ++sum;
	}
	ret.at(i+1) = sum;
    }
}

int main()
{
    int N, Q;
    string s;

    cin >> N >> Q;

    cin >> s;

    vector<int> ret(N);
    make_count_ac(s, ret);
    
    vector<int> L(Q), R(Q);
    vector<int> sum(Q, 0);
    for(int i = 0; i < Q; i++){
	int l, r;
	cin >> l >> r;
	sum.at(i) = ret.at(r-1) - ret.at(l-1);
    }

    //count_ac(s, sum, target);
    
    for(int i = 0; i < Q; i++){
	cout << sum.at(i) << endl;
    }
    
    cout << endl;

}


Measured memory_bytes: 2688
using System;
using System.Linq;

namespace G
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = int.MaxValue; int sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += x[i];
                ret = Math.Min(ret, sum / (i + 1));
            }
            Console.WriteLine(ret);
        }
    }
}


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

using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
const int N=2e5 + 5;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    string s;
    cin >> s;
    string ans = "ABC";
    if(s == "ABC") ans = "ARC";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
n = int( input( ) )
t = [ int( val ) for val in input( ).rstrip( ).split( " " ) ]
q = int( input( ) )
s = [ int( val ) for val in input( ).split( " " ) ]
 
cnt = 0
for si in s:
    for ti in t:
        if si == ti:
            cnt += 1
            break
 
print( cnt )

Measured memory_bytes: 7764
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL r,g,b,n;
	cin>>r>>g>>b>>n;
	LL ans=0;
	FOR(i,0,n+1){
		FOR(j,0,n+1){
			LL rest=n-i*r-j*g;
			if(rest%b!=0||rest<0){
				continue;
			}
			ans++;
		}
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    ll h;
    cin>>h;
    int l2=log2(h);
    cout<<(ll)(pow(2,l2+1)-1)<<endl;
    return 0;
}

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

int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
 int x,y,xx,xy;
 cin>>x>>y>>xx>>xy;
 if ((x+xy-1)/xy<(xx+y-1)/y){
     cout<<"No";
 }
 else{
     cout<<"Yes";
     }
}   

Measured memory_bytes: 3648
fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { reader: sc.lock() };
    let l: usize = sc.read();

    let mut r = 0;
    while (1 << (r + 1)) <= l {
        r += 1;
    }

    let n = r + 1;
    let mut graph = vec![vec![]; n];
    for i in 0..r {
        graph[i].push((i + 1, 1 << i));
        graph[i].push((i + 1, 0));
    }

    let mut l = l;
    for i in (0..(n - 1)).rev() {
        if l >= (1 << r) + (1 << i) {
            let t = l - (1 << i);
            graph[i].push((n - 1, t));
            l = t;
        }
    }

    let mut ans = vec![];
    for i in 0..n {
        for &(next, w) in graph[i].iter() {
            ans.push((i, next, w));
        }
    }

    println!("{} {}", n, ans.len());
    for &(i, next, w) in ans.iter() {
        println!("{} {} {}", i + 1, next + 1, w);
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    int N;cin>>N;
    int x[N];
    REP(i,N)cin>>x[i];
    LL L;cin>>L;
    int logN = (int)log2(N) + 1;

    int doub[N][logN+1];
    fill(doub[0],doub[N],x[N-1]+1);
    REP(i,N-1)doub[i][0]=upper_bound(x,x+N,x[i]+L)-x-1;
    REP(k,logN)REP(i,N)doub[i][k+1]=doub[min(N-1,doub[i][k])][k];

    int q;cin>>q;
    REP(i,q){
        int a,b;cin>>a>>b;
        if(a>b)swap(a,b);
        a--;b--;

        int ans=0;
        for(int i=logN-1;i>=0;i--){
            if(doub[a][i]<b){
                ans+= 1<<i;
                a = doub[a][i];
            }
        }
        cout<<ans+1<<endl;
    }
    return 0;
}

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

int main()
{
  string s;
  int n;
  cin >> s;
  n = s.length();
  
  vector<int> a = {0};
  for (int i = 1; i < n; ++i) {
    if ((s[i-1] == 'R') && (s[i] == 'L')) {
      a.push_back(i);
    }
  }
  a.push_back(n);
  int m;
  m = a.size();
  
  int ans[n] = {};
  for (int i = 1; i < m; ++i) {
    for (int j = a[i-1]; j < a[i]; ++j) {
      if (s[j] == 'R') {
        ++ans[a[i] - (a[i] - j) % 2];
      }
      else {
        ++ans[a[i-1] - (j - a[i-1]) % 2];
      }
    }
  }
  
  for (int i = 0; i < n; ++i) cout << ans[i] << " ";
  return 0;
}

Measured memory_bytes: 1276
S = input()
N = len(S)

ans = 0
i = 0
while i < N and S[i]=='>':
    i += 1
ans += i*(i+1)//2

arr = [i]
while i < N:
    while i < N and S[i]=='<':
        i += 1
    arr.append(i)
    if i==N: break
    while i < N and S[i]=='>':
        i += 1
    arr.append(i)

arr = [b-a for a,b in zip(arr,arr[1:])]
for a,b in zip(arr[::2],arr[1::2]):
    if a<b: a,b = b,a
    ans += a*(a+1)//2
    ans += b*(b-1)//2
if len(arr)%2:
    ans += arr[-1]*(arr[-1]+1)//2

print(ans)

Measured memory_bytes: 23540
//
//  main.cpp
//  ABC139B
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int A,B;
    int ans=0;
    int p=0;
    cin >> A >> B;
    if (B>1) {
        while (p<B) {
            ans++;//差込口が足りないなら、電源タップを増やす
            p=A*ans-ans+1;//差込口の数を計算する
        }
        cout << ans<<endl;
    }else{//差込口が１つで良いなら、電源タップは使わない。
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long n;
    cin>>n;
    string s=to_string(n);
    for(int i=1;i<s.size();i++)if(s[i]!='9'){cout<<(s[0]-'1')+9*(s.size()-1);return 0;}
    cout<<(s[0]-'0')+9*(s.size()-1)<<endl;
    return 0;
}

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


int n,k,MN=1e9;


void dfs(int a,int sum){
	if(a==n){
		MN=min(sum,MN);
		return ;
	}
	dfs(a+1,sum*2);
	dfs(a+1,sum+k);
}


int main(){
	cin >> n >> k;
	dfs(0,1);
	
	cout << MN << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.2.5
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,i) upper_bound(ALL(a),i)-lower_bound(ALL(a),i)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(iY,0,a.size()){Verr(a[iY]);}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m,qw,er,ty,ui;
  cin >> n >> m;
  VPii a(m);
  rep(i,0,m) {
    cin >> qw >> er;
    a[i] = mp(er,qw);
  }
  
  sort(ALL(a));
  
  int ans = 0,now = 0;
  
  rep(i,0,m){
    if(a[i].SE >= now) {
      ans++;
      now = a[i].FI;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

ll mod = 1e9+7;

int main(){
    int n,d;
    cin >> n >> d;
    int l = 2 * d + 1;
    int ans;
    if (n%l==0){
        ans = n/l;
    } else {
        ans = n/l+1;
    }
    cout << ans << endl;
}

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

int main(){
    string s,t;
    cin>>s;
    t=s;
    reverse(t.begin(),t.end());
    for(register int i=0;i<t.size();++i){
        if(s[i]=='b')s[i]='d';
        else if(s[i]=='d')s[i]='b';
        else if(s[i]=='p')s[i]='q';
        else if(s[i]=='q')s[i]='p';
    }
    if(t==s)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 512
<?php

fscanf(STDIN,"%d%d",$n,$m);
$ab_l = array();
$cd_l = array();
$re_l = array();
for($i=0;$i<$n;$i++) $ab_l[] = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$m;$i++) $cd_l[] = explode(" ",trim(fgets(STDIN)));
$min= 10**6;
foreach($ab_l as $ab){
  foreach($cd_l as $cp=>$cd){
    $dis = abs($ab[0]-$cd[0])+abs($ab[1]-$cd[1]);;
    $re_l[$cp] = $dis;
  }
  asort($re_l);
  //print_r($re_l);
  $min_posiible = array_values($re_l);
  $min_posiible = $min_posiible[0];
  foreach($re_l as $k=>$r){
    if($min_posiible==$r){
      $k_l[] = $k;
    }
  }
  sort($k_l);
  //print_r($k_l);
  echo ($k_l[0]+1)."\n";
    $k_l = [];
  $re_l = [];
}
    

Measured memory_bytes: 4604
import collections

N = int(input())
M = []
for i in range(N):
    a = list(map(int,input().strip().split()))
    b = [int(i+1 in a[2:]) for i in range(N)]
    M.append(b)

D = [-1 for _ in range(N)]
D[0] = 0 # 始点への距離は 0, 他の距離は-1
Q = collections.deque()
Q.append(0) # 始点
while len(Q) > 0:
    #print("bfs", Q) # 各ステップでの Q の動作を確認
    cur = Q.popleft()
    for dst in range(N):
        # curからdstに移動可能かつ、dstが未訪問だったら
        if M[cur][dst] == 1 and D[dst] == -1:
            D[dst] = D[cur]+1
            Q.append(dst) # Qにdstを詰める
for v in range(N):
    print(v+1, D[v])



Measured memory_bytes: 6096
//aea ctmr
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//v.erase(unique(v.begin(),v.end()),v.end());
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.14159265358979323846
 
typedef long double ld;
typedef long long ll;
const ll N = 400500;
const ll mod = 1e9 + 7;
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

int mat[13][105000];
int ac[13][105000];

int aea(int x, int y, int z, int k){
	return ac[y][k] + ac[x][z] - ac[y][z] - ac[x][k];
}

int main(){
    fastio;
    int w, h, k;
    cin >> w >> h >> k;

	for(int i = 0; i < w; i++){
		string s;
		cin >> s;
		for(int j = 0; j < h; j++){
			if(s[j] == '1') mat[i + 1][j + 1] = 1;
			else mat[i + 1][j + 1] = 0;
		}
	}

	for(int i = 1; i <= w; i++){
		for(int j = 1; j <= h; j++){
			int aea = mat[i][j];
			ac[i][j] = ac[i - 1][j] + ac[i][j - 1] - ac[i - 1][j - 1] + aea;
		}
	}
	//ahi tienen los acumulados de mrd
	int yii = 1e+9;
    for(int i = 0; i < (1 << (w - 1)); i++){
    	int ans = 0;
    	vector <int> uwu; uwu.clear();
    	uwu.push_back(0);
    	for(int j = 0; j < w - 1; j++){
    		if((i & (1 << j)) != 0){
    			//cumple
    			ans++;
    			uwu.push_back(j + 1);
    		}
    	}
    	uwu.push_back(w);
    	int l = uwu.size();
    	int last = 0;

    	//bool no_cum = false;
    	for(int j = 1; j <= h; j++){
    		bool anad = false;

    		for(int j1 = 1; j1 < l; j1++){
    			if(aea(uwu[j1 - 1], uwu[j1], last, j) > k) anad = true;
    		}
	

    		if(anad){
    			if(last == j - 1) ans = 1e+9;
    			ans++;
    			last = j - 1;
    		}
    	}

    	yii = min(yii, ans);	
    }

    cout << yii << endl;
    return 0;
}

Measured memory_bytes: 8448
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x==0) cout << x+1 <<endl;
    else cout << x-1 << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	// 入力
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> A(Q);
	for (int i = 0; i < Q; i++)
	{
		cin >> A[i];
		// 入力値から-1することで、配列のindexとして利用
		A[i]--;
	}
	
	// 得点の割り振り
	vector<int> Point(N);
	for (int i = 0; i < N; i++)
	{
		// 全員のポイントをQ減らしておく
		Point[i] = K - Q;
	}
	
	// Q 回の正解それぞれに対して，正解者のポイントを1増やす。
	for (int i = 0; i < Q; i++)
	{
		Point[A[i]] += 1;
	}
	
	// 出力
	for (int i = 0; i < N; i++)
	{
		if (Point[i] > 0)
		{
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  ll a, b, c;
  cin >> a >> b >> c;
  long double A = sqrtl(a);
  long double B = sqrtl(b);
  long double C = sqrtl(c);
  long double eps = 1.0e-14;
  
  cout << (A + B + eps < C ?"Yes" :"No") << "\n";

}


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

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


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

Measured memory_bytes: 256
//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;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if ((i&1) == 0 and s[i] == 'L') {
			cout << "No" << endl;
			return 0;
		}
		if ((i&1) == 1 and s[i] == 'R') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

const int N = 100005;

int n;
vector <int> G[N];
int nchild[N];
int f[N], g[N], big_f[N];
vector <int> l[N], r[N], F[N];

void dfs1(int u, int p) {
	nchild[u] = 1;
	f[u] = 1;

	for (int &v : G[u]) if (v != p) {
		dfs1(v, u);
		nchild[u] += nchild[v];
		big_f[u] += (nchild[v] > 1);
		f[u] &= f[v];
		F[u].push_back(f[v]);
	}

	int sz = F[u].size();
	l[u].assign(sz + 2, 1);
	r[u].assign(sz + 2, 1);
	for (int i = 0; i < sz; ++i) {
		l[u][i + 1] = (l[u][i] & F[u][i]);
	}
	for (int i = sz - 1; i >= 0; --i) {
		r[u][i + 1] = (r[u][i + 2] & F[u][i]);
	}

	f[u] &= (big_f[u] <= 1);
}

void dfs2(int u, int p) {
	int sz = 0;
	for (int &v : G[u]) if (v != p) {
		int t = (n - nchild[u] > 1) + big_f[u] - (nchild[v] > 1);
		++sz;
		g[v] = ((t <= 1) & g[u] & l[u][sz - 1] & r[u][sz + 1]);
		dfs2(v, u);
	}
}

// -----------------------------------------------------------
void dfs(int u, int p) {
	nchild[u] = 1;
	for (int &v : G[u]) if (v != p) {
		dfs(v, u);
		nchild[u] += nchild[v];
	}
}

// trace now
int ptr;
int cur;
int last;
int a[N], b[N];
void trace(int u, int p, int x[]) {
	last = u; // remember the last one
	int sz = G[u].size() - (p != 0);
	for (int i = 2; i <= sz; ++i) {
		x[++ptr] = cur + i;
	}
	x[++ptr] = cur + 1;
	cur += sz;

	for (int &v : G[u]) if (v != p) {
		if (nchild[v] > 1) return trace(v, u, x);
	}
	for (int &v : G[u]) if (v != p) {
		return trace(v, u, x);
	}
}

void solve(int root, bool flag) {
	ptr = 0;
	cur = 0;
	dfs(root, 0);
	if (!flag) trace(root, 0, a);
	else trace(root, 0, b);
}

void out(int x[]) {
	for (int i = 1; i <= n; ++i) {
		printf("%d ", x[i]);
	}
	printf("\n");
	exit(0);
}

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

	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	dfs1(1, 0);
	g[1] = 1;
	dfs2(1, 0);

	int root = 0;
	for (int i = 1; i <= n; ++i) {
		if (G[i].size() == 1 && f[i] && g[i] && big_f[i] + (n - nchild[i] > 1) <= 1) {
			// i is valid
			root = i;
			break;
		}
	}

	if (root == 0) { // not found
		printf("-1\n"); return 0;
	}

	solve(root, 0);
	solve(last, 1);

	for (int i = 1; i <= n; ++i) {
		if (a[i] < b[i]) out(a);
		else if (b[i] < a[i]) out(b);
	}
	out(a);
}

Measured memory_bytes: 29696
n,t = map(int, input().split())
ct = [list(map(int, input().split())) for _ in range(n)]
ans = 10000
for i in range(n):
    if ct[i][1] <=t:
        tmp = ct[i][0]
        ans = min(ans, tmp)
print(ans if ans != 10000 else 'TLE')

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<int> dp(mx,inf);

int rec(int n){
  if(dp[n]!=inf){ return dp[n]; }
  if(n==0) return dp[n]=0;
  int res=rec(n-1)+1;
  int x=6;
  while(x<=n){
    res = min(res, rec(n-x)+1);
    x*=6;
  }
  x=9;
  while(x<=n){
    res = min(res, rec(n-x)+1);
    x*=9;
  }
  return dp[n]=res;
}

int main(){
  int n;
  cin >> n;
  int ans = rec(n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
  	string S;
  	cin >> n >> S;
	ll e[n] , w[n];
	e[0] = 0;
	w[0] = 0;
	if( S[0] == 'E' ) e[0] = 1;
	else w[0] = 1;
	for( int i = 1 ; i < n ; i++ ) {
	    if( S[i] == 'E' ) {
            e[i] = e[i - 1] + 1;
  	        w[i] = w[i - 1];
	    } else {
	        e[i] = e[i - 1];
	        w[i] = w[i - 1] + 1;
	    }
	}
    ll ans = e[n - 1] - e[0];
    for( int i = 1 ; i < n ; i++ ) ans = min( ans , e[n - 1] - e[i] + w[i - 1] );
    cout << ans;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20);
  int n;
  cin >> n;
  vector<int> b(n-1);
  for (int i = 0; i < n-1; i++)
    cin >> b[i];
  ll x = b[0];
  for (int i = 1; i < n-1; i++) {
    x +=  min(b[i], b[i-1]);
  }
  x += b[n-2];
  cout << x << endl;
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  auto ans = vector<vector<int>>(h, vector<int>(w));
  int idx = 0, cnt = a[0];
  for (int i = 0; i < h; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < w; j++) {
        ans[i][j] = idx + 1;
        cnt--;
        if (idx < n - 1 && cnt == 0) {
          idx++;
          cnt = a[idx];
        } 
      }
    } else {
      for (int j = w - 1; j >= 0; j--) {
        ans[i][j] = idx + 1;
        cnt--;
        if (idx < n - 1 && cnt == 0) {
          idx++;
          cnt = a[idx];
        } 
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w - 1; j++) {
      cout << ans[i][j] << " ";
    }
    cout << ans[i][w - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main (){
  vector<int> a;
  int N;
  int b;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> b;
    a.push_back(b);
  }
  sort(a.begin(),a.end());
  cout << a[a.size()-1]-a[0] << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int count = 0;
	for (char i = 'a'; i != 'z'; i++) {
		count = 0;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == i) {
				count++;
			}

		}

		if (count % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}


	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;

int n, k;
int a[N];

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  cin >> n >> k;
  for(int i = 0; i < n; ++i)
    cin >> a[i];

  sort(a, a+n);
  
  vector<int> d;
  for(int i = 1; i < n; ++i)
    d.emplace_back(a[i] - a[i-1]);

  sort(d.begin(), d.end(), greater<int>());
  while(d.size() && d.back() == 0)
    d.pop_back();

  reverse(d.begin(), d.end());
  bool all = true;
  for(int x : d)
    all &= (x % d[0] == 0);

  bool cant = true;
  for(int i = 0; cant && i < n; ++i)
    if(a[i] == k || a[i] > k && (not all || ((a[i] - k )% d[0] == 0)))
      cant = false;

  cout << (cant ? "IMPOSSIBLE" : "POSSIBLE") << endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll INF = LLONG_MAX/3;

// 区間add, 区間max
struct LazySegTree{
    int n; vector<ll> dat,lazy;
    //初期化
    LazySegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<ll>(2*n-1,-INF);
        lazy=vector<ll>(2*n-1,0);
    }
    void setLazy(int k, ll v){
        lazy[k] += v;
        dat[k] += v;
    }
    void push(int k, int l, int r){
        if(lazy[k]!=0){
            setLazy(2*k+1,lazy[k]);
            setLazy(2*k+2,lazy[k]);
        }
        lazy[k]=0;
    }
    void fix(int k, int l, int r){
        dat[k]=max(dat[2*k+1],dat[2*k+2]);
    }
    ll merge(ll x, ll y){
        return max(x,y);
    }
    //内部的に投げられるクエリ
    void _add(int a, int b, ll x, int k, int l, int r){
        if(r<=a || b<=l) return;
        if(a<=l && r<=b){
            setLazy(k,x);
            return;
        }

        push(k,l,r);
        _add(a,b,x,2*k+1,l,(l+r)/2);
        _add(a,b,x,2*k+2,(l+r)/2,r);

        fix(k,l,r);
    }
    //[a,b)に+x
    void add(int a, int b, ll x){
        return _add(a,b,x,0,0,n);
    }
    //内部的に投げられるクエリ
    ll _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return -INF;
        if(a<=l && r<=b) return dat[k];

        push(k,l,r);
        ll vl=_query(a,b,2*k+1,l,(l+r)/2);
        ll vr=_query(a,b,2*k+2,(l+r)/2,r);
        return merge(vl,vr);
    }
    //[a,b)
    ll query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

int main(){
    int n,m;
    scanf(" %d %d", &n, &m);

    vector<vector<pair<int,int>>> L(n+1),R(n+1);
    rep(i,m){
        int l,r,a;
        scanf(" %d %d %d", &l, &r, &a);
        L[l].pb({l,a});
        R[r].pb({l,a});
    }

    LazySegTree st(n+1);
    vector<ll> dp(n+1,-INF);
    dp[0] = 0;
    st.add(0, 1, INF);

    for(int i=1; i<=n; ++i){
        for(const auto &p:L[i]) st.add(0, p.fi, p.se);

        dp[i] = st.query(0,i);
        st.add(i, i+1, dp[i]+INF);

        for(const auto &p:R[i]) st.add(0, p.fi, -p.se);
    }

    printf("%lld\n", *max_element(all(dp)));
    return 0;
}


Measured memory_bytes: 31872
S = input()
T = input()

diff = len(S) - len(T)
ans = 99999

for i in range(diff + 1):
  t_s = len(T)
  moto = S[i:i+t_s]
  saki = T

  num = 0
  for j in range(len(T)):
    if moto[j] != saki[j]:
      num = num + 1

  if num <= ans:
    ans = num

print(ans)


Measured memory_bytes: 9116
N, *L,  = [list(map(int, s.split())) for s in open(0)]
order = L[0]
A = L[1]
B = L[2]

s = 0
last = 0
for i in range(len(order)):
    s += A[order[i] - 1]
    if order[i] - order[last] == 1:
        s += B[order[last] - 1]
    last = i
print(s)

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

vector<int> p = {100, 101, 102, 103, 104, 105};
bool dp[100010];

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

    memset(dp, false, sizeof(dp));
    dp[0] = true;

    for (int i = 0; i <= X; ++i) {
        if (dp[i] == false) {
            continue;
        }
        for (int j = 0; j < p.size(); ++j) {
            if (i + p[j] <= 100000) {
                dp[i+p[j]] = true;
            }
        }
    }
    cout << dp[X] << endl;
}

Measured memory_bytes: 384
function Dice(num) {
  this.top    = num[0];
  this.front  = num[1];
  this.right  = num[2];
  this.left   = num[3];
  this.back   = num[4];
  this.bottom = num[5]

  this.roll = function(direction) {
    var tmp;
    switch (direction) {
      case 'E':
        tmp         = this.top;
        this.top    = this.left;
        this.left   = this.bottom;
        this.bottom = this.right;
        this.right  = tmp;
        break;
      case 'N':
        tmp         = this.top;
        this.top    = this.front;
        this.front  = this.bottom;
        this.bottom = this.back;
        this.back   = tmp;
        break;
      case 'S':
        tmp         = this.top;
        this.top    = this.back;
        this.back   = this.bottom;
        this.bottom = this.front;
        this.front  = tmp;
        break;
      case 'W':
        tmp         = this.top;
        this.top    = this.right;
        this.right  = this.bottom;
        this.bottom = this.left;
        this.left   = tmp
        break;
    }
  }
}



var input = ""
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
 
process.stdin.on('end', function() {
  input = input.split("\n");

  var num = input[0].split(' ').map(Number);
  var direction = input[1].split('');
  var dice = new Dice(num);

  for (i = 0; i < direction.length; i++) {
    dice.roll(direction[i]);
  }
  console.log(dice.top);
});

Measured memory_bytes: 15640
#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	int n;
	int t[20001], f[20001];
	t[0] = t[1] = 0;
	t[2] = 1;
	rep2(i,3,20001) {
		t[i] = (i % 2 == 0) ? t[i / 2] + 1 : 0;
	}
	rep2(i,1,20001) {
		t[i] += t[i-1];
	}
	rep(i,5) {
		f[i] = 0;
	}
	f[5] = 1;
	rep2(i,6,20001) {
		f[i] = (i % 5 == 0) ? f[i / 5] + 1 : 0;
	}
	rep2(i,1,20001) {
		f[i] += f[i-1];
	}
	int ret[20001];
	rep(i,20001) {
		ret[i] = min(t[i], f[i]);
	}
	while(cin >> n && n) {
		cout << ret[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 1392
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
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; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n,k;
    cin>>n>>k;
    bool hoge[n];
    rep(i,0,n-1) hoge[i] = false; 
    rep(i,0,k-1){
        int d;
        cin>>d;
        int a[d];
        rep(j,0,d-1){
            cin>>a[j];
            hoge[a[j]-1] = true;
        }
    }
    int ans = 0;
    rep(i,0,n-1) if(!hoge[i]) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
import operator
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = list(range(n + 1))
        self.ranks = [0 for _ in range(n + 1)]

    def get_root(self, x):
        if self.parents[x] == x:
            return x
        self.parents[x] = self.get_root(self.parents[x])
        return self.parents[x]

    def merge(self, x, y):
        x = self.get_root(x)
        y = self.get_root(y)
        if x != y:
            if self.ranks[x] < self.ranks[y]:
                self.parents[x] = y
            else:
                self.parents[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1


def kruskal(n_nodes, edges):
    edges.sort(key=operator.itemgetter(2))
    res = []
    uf = UnionFind(n_nodes)
    for e in edges:
        if uf.get_root(e[0]) != uf.get_root(e[1]):
            res.append(e)
            uf.merge(e[0], e[1])
    return res


n = ri()
ls = rils(n)
ls = list(enumerate(ls))

edges = []
ls.sort(key=lambda x: x[1][0])
for (i, (x0, y0)), (j, (x1, y1)) in zip(ls, ls[1:]):
    edges.append((i, j, min(abs(x0 - x1), abs(y0 - y1))))

ls.sort(key=lambda x: x[1][1])
for (i, (x0, y0)), (j, (x1, y1)) in zip(ls, ls[1:]):
    edges.append((i, j, min(abs(x0 - x1), abs(y0 - y1))))

res = kruskal(n, edges)
print(sum(x[2] for x in res))

Measured memory_bytes: 65408
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int x, y;
    cin >> x >> y;
    cout << (x + (y / 2));
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  while(1){
  int n,m;
  cin>>m>>n;
  if(!n&&!m)break;

  P cnt[1001];
  for(int i=0;i<n;i++)cnt[i]=P(0,-i-1);
  
  for(int i=0;i<m;i++)
    for(int j=0,a;j<n;j++)cin>>a,cnt[j].first+=a;
  
  sort(cnt,cnt+n,greater<P>());

  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<-cnt[i].second;
  }
  cout<<endl;
  
  }
  

  return 0;
}

Measured memory_bytes: 2988
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

int N, K;
bool ok[10];

void solve() {
  int ans1 = N, ans = N;
  while (1) {
    while (ans != 0) {
      if (ok[ans % 10]) break;
      ans /= 10;
    }
    if (ans == 0) {
      break;
    }
    ans = ans1 + 1;
    ans1++;
  }
  cout << ans1 << endl;
}

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

  cin >> N >> K;
  REP(i, K) {
    int a;
    cin >> a;
    ok[a] = true;
  }
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    string s;
  cin>>s;
  int n=s.length();
  int max=0;
  for(int i=2;i<=n-2;i=i+2){
    int k=i/2;
    string sub=s.substr(0,k);
    string test=sub+sub;
    string p=s.substr(0,i);
    if(test==p){
       max=i;
    }
  }
       cout<<max;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();

        int min = Math.min(P + Q, Math.min(Q + R, R + P));
        System.out.println(min);
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>

#define SIZE 200007

int cmp(const void *a, const void *b) {
    return *(int *)b -*(int *)a;
}

int main() {
    int n, i, a[SIZE], b[SIZE];
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        b[i] = a[i];
    }
    qsort(b, n, sizeof(int), cmp);
    
    for (i = 0; i < n; i++) {
        if (a[i] == b[0]) {
            printf("%d\n", b[1]);
        } else {
            printf("%d\n", b[0]);
        }
    }
    return 0;
}

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

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

def func(s):
    return s == s[::-1]

S = input()
N = len(S)
if func(S) and func(S[:(N-1)//2]) and func(S[(N+3)//2-1:]):
    print("Yes")
else:
    print("No")




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

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define str string
#define vl vector<ll>
#define vs vector<string>

#define mapll map<ll,ll>
#define mapss map<string,string>
#define mapsl map<string,ll>
#define mapls map<ll,string>

#define pll pair<ll,ll>
#define pss pair<string,string>
#define psl pair<ll,string>
#define pls pair<string,ll>

#define minheap priority_queue<ll>
#define maxheap priority_queue<ll,vector<ll> ,greater<ll>>

#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
const ll mod=1e9 + 7;


ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

ll gcd(ll a, ll b) { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);        
}

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}
ll dp[101][100000];
ll arr[100][2];
ll n,w;
ll finalans;
ll dpfunc(ll index,ll weight)
{
    //cout<<ans<<" "<<index<<endl;
    if(index==-1)
    {
        return 0;
    }
    else
    {
        if(dp[index][weight]!=-1)
        {
            return dp[index][weight];
        }
        if(weight<arr[index][0])
            dp[index][weight]=dpfunc(index-1,weight);
        else
        {
            dp[index][weight]=max(dpfunc(index-1,weight),arr[index][1]+dpfunc(index-1,weight-arr[index][0]));
        }
        return dp[index][weight];
    }
}
signed main() 
{
    fast_cin();
    cin>>n>>w;
    For(i,0,n)
    {
        cin>>arr[i][0]>>arr[i][1];
    }
    memset(dp,-1,sizeof(dp));
    cout<<dpfunc(n-1,w)<<endl;
    return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i = 0;i <= n - 1;i++){
    cin >> a[i] >> b[i];
  }
  ll now = 0;
  //ll count = 0;
  for(int i = n - 1;i >= 0;i--){
    //a[i] += now;
    //ll add = 0;
    //if(a[i] % b[i] != 0)add = b[i] - (a[i] % b[i]),count++;
    now += b[i] - ((a[i] + now - 1 + b[i]) % b[i] + 1);
  }
  //cout << count << endl;
  cout << now << endl;
}

Measured memory_bytes: 1024
import fractions
a, b, c, d = map(int, input().split())

#a~bでnで割り切れるものの数
def func(a, b, n):
    answer = (int(b/n) - int((a-1)/n))
    return answer

def func_test(a,b,n):
    return b//n - (a-1)//n

lcm = int((c * d) / fractions.gcd(c, d))

print ((b - a + 1) - func_test(a,b,c) - func_test(a,b,d) + func_test(a,b,lcm))

Measured memory_bytes: 5048
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main(void)
{
	int i,n, k, x, y,total;

	scanf("%d%d%d%d", &n, &k, &x, &y);

	total = 0;

	for (i = 1; i <= n; i++)
	{
		if (i > k)
			total += y;
		else
			total += x;
	}

	printf("%d", total);

	return 0;
}

Measured memory_bytes: 128