akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <list>
using namespace std;
	
int main(){
	string S;
	cin >> S;
	int N = (int)(S.length());
	int check = 0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			string a = S.substr(0,i+1);
			string b = S.substr(j,N-j);
			string c = a + b;
			if (c == "keyence"){
				check = 1;
			}
		}
	}
	if (check == 1)
		cout << "YES" << endl;
	else 
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
 
int main()
{
    int x;
    cin >> x;
    
    int sum = 0;
    for(int i = 1; ; i++){
        sum += i;
        if(sum >= x){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int N,a=0,flag=0;
scanf("%d",&N);
for(int i=1;i<=N;i*=10){
a=(N/i)%10;
if(a==7)flag=1;
}
if(flag==1) printf("Yes\n");
else printf("No\n");
return 0;
}

Measured memory_bytes: 1592
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    X = int(input())

    ans = 0
    ans += 1000 * (X // 500)
    X %= 500
    ans += 5 * (X // 5)
    print(ans)

if __name__ == '__main__':
    resolve()


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

int main() {
  string S; cin >> S;
  if (S=="SUN") cout << 7 << endl;
  if (S=="MON") cout << 6 << endl;
  if (S=="TUE") cout << 5 << endl;
  if (S=="WED") cout << 4 << endl;
  if (S=="THU") cout << 3 << endl;
  if (S=="FRI") cout << 2 << endl;
  if (S=="SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size

    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

    def __len__(self):
        return self.size
    
#solve
def solve():
    n, d, a = LI()
    xh = LIR(n)
    xh.sort()
    ans = 0
    ldi = 0
    rdi = 0
    bit = BinaryIndexedTree(n+1)
    for i in range(n):
        x, h = xh[i]
        h -= bit.sum(i)
        if h > 0:
            t = (h - 1) // a + 1
            for rdi in range(rdi, n):
                if x + 2 * d < xh[rdi][0]:
                    rdi -= 1
                    break
            ans += t
            bit.add(rdi + 1, -t * a)
            bit.add(i, t * a)

    print(ans)

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 88796
import sys
import numpy as np

readline = sys.stdin.buffer.readline
a = np.array([])
for _ in range(3):
  a = np.append(a,list(map(int, readline().split())))
n = int(readline())

a = a.reshape(3,3)
a_2 = np.append(a,np.diag(a))
a_2 = np.append(a_2,[a[0][2],a[1][1],a[2][0]])

a_2 = a_2.reshape(5,3)
for _ in range(n):
  temp=int(readline())
  a[a==temp]=0
  a_2[a_2==temp]=0

print('Yes' if 0 in np.sum(a_2, axis=1) or 0 in np.sum(a, axis=0) else 'No')

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

int x,y,s;

int main(){
  int i,j,max=0;
  while(1){
    max = 0;
    cin >> x >> y >> s;
    if(x==y&&x==s&&x==0)break;
    for(i=1;i<s;i++)for(j=1;j<s;j++){
	if((i*(100+x))/100+(j*(100+x))/100==s){
	  if(max<(i*(100+y))/100+(j*(100+y))/100)max =(i*(100+y))/100+(j*(100+y))/100;
	}
      }
    cout << max << endl;
  }
  return 0;
}



Measured memory_bytes: 3004
#include <iostream>

using namespace std;

int main(void){
  int a,b; cin>>a>>b;
  if(a==b) cout<<"Draw"<<endl;
  else{
	if(a==1) cout<<"Alice"<<endl;
    else if(b==1) cout<<"Bob"<<endl;
    else cout<<(a>b?"Alice":"Bob")<<endl;
  }
  return 0;
}

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

int main() {
	const int N =100000;
	int n;
	long long int k;
	cin>>n>>k;
	long long int hoge[N]={};
	int a,b;
	for(int i=0;i<n;i++){
		
		cin>>a>>b;
		hoge[a-1]+=b;
	}
	long long count;
 	for(int i=0;i<N;i++){
 		count+=hoge[i];
 		if(count>=k){
 			cout<<i+1<<endl;
 			break;
 		}
 	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>


using namespace std;
/*
 入力1までの日数　−　入力2までの日数
*/


int main(){
    int n;
    cin>>n;
    for(int roop=0; roop<n; roop++){
        int puzzle[9][9];
        for(int i=0; i<9; i++){
            for(int j=0; j<9; j++){
                cin>>puzzle[i][j];
            }
        }
        /*横*/
        char ans[9][9];        
        for(int i=0; i<9; i++){
            bool checker[10]={0};
            for(int j=0; j<9; j++){
                if(checker[puzzle[i][j]]==0){
                    checker[puzzle[i][j]]=true;
                    ans[i][j]=' ';
                }else{
                    for(int k=0; k<j; k++){
                        if(puzzle[i][j]==puzzle[i][k])ans[i][k]='*';
                    }
                    ans[i][j]='*';
                }
            }
        }
        
        /*縦*/
        for(int i=0; i<9; i++){
            bool checker[10]={0};
            for(int j=0; j<9; j++){
                if(checker[puzzle[j][i]]==0){
                    checker[puzzle[j][i]]=true;
                }else{
                    for(int k=0; k<j; k++){
                        if(puzzle[j][i]==puzzle[k][i]){
                            ans[k][i]='*';
                        }
                    }
                    ans[j][i]='*';
                }
            }
        }
        
        /*四角*/
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                int i2 = i*3;
                int j2 = j*3;
                bool checker[10]={0};
                for(int k=0; k<9; k++){
                    if(checker[puzzle[i2+k/3][j2+k%3]]==0){
                        checker[puzzle[i2+k/3][j2+k%3]]=true;
                    }else{
                        for(int l=0; l<k; l++){
                            if(puzzle[i2+k/3][j2+k%3]==puzzle[i2+l/3][j2+l%3])ans[i2+l/3][j2+l%3]='*';
                        }
                        ans[i2+k/3][j2+k%3]='*';
                    }
                }
            }
        }
        
        
        
        
        for(int i=0; i<9; i++){
            for(int j=0; j<9; j++){
                cout<<ans[i][j]<<puzzle[i][j];
            }
            cout<<endl;
        }
        if(roop!=n-1)cout<<endl;
        
    }
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(){
  long long int x,a,b;
  cin >> x>> a>>b;
  a=0-a;
  if(a+b<=0) cout <<"delicious"<<endl;
  else if(a+b<=x) cout <<"safe"<<endl;
  else cout <<"dangerous"<<endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    p = list(map(int, input().split()))
    q = sorted(p)
    count = 0
    for i in range(n):
        if p[i] != q[i]:
            count += 1
    if count == 0 or count == 2:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var M = vals[1];

        var num = new char[N];
        var ok = true;
        for (int i = 0; i < M; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var s = vals[0] - 1;
            var c = vals[1].ToString()[0];
            if (num[s] != 0 && num[s] != c)
            {
                ok = false;
            }
            num[s] = c;
        }

        if (!ok || (num[0] == '0' && N > 1))
        {
            Console.WriteLine(-1);
            return;
        }

        for (int i = 0; i < N; i++)
        {
            if (num[i] == 0)
            {
                if (i == 0 && N > 1)
                {
                    num[i] = '1';
                }
                else
                {
                    num[i] = '0';
                }
            }
        }

        Console.WriteLine(num);
    }
}

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

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

  for(int i = 0;i <= N;i++){
    for(int j = 0;j <= N;j++){
      if(i + j <= N && 1000 * i + 5000 * j + (N - i - j) * 10000 == Y){
        cout << (N - i - j) << " " << j << " " << i << endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define mod 1000000007
using namespace std;
typedef long long ll;

ll kai[200001],inv[200001],sum[200001];
ll n,m,k,ans;

ll gyaku(ll x){
    ll res=x;
    ll a=mod-2;
    for(int i=1;i<30;i++){
        x=x*x;
        x%=mod;
        if(((1<<i)&a)){
            res*=x;
            res%=mod;
        }
    }
    return res;
}

void kaiinit(){
    kai[0]=kai[1]=1LL;
    for(ll i=2;i<=n*m;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    inv[n*m]=gyaku(kai[n*m]);
    for(ll i=n*m-1;i>=0;i--){
        inv[i]=inv[i+1]*(i+1LL);
        inv[i]%=mod;
    }
}
int main(){
    scanf("%lld %lld %lld",&n,&m,&k); 
    for(ll i=1;i<=200000;i++){
        sum[i]=sum[i-1]+i;
        sum[i]%=mod;
    }
    for(ll i=0;i<m;i++){
        ans+=(sum[m-i-1])*n*n;
        ans%=mod;
    }
    for(ll i=0;i<n;i++){
        ans+=(sum[n-i-1])*m*m;
        ans%=mod;
    }
    if(k!=2){
        kaiinit();
        ans*=kai[n*m-2];
        ans%=mod;
        ans*=inv[k-2];
        ans%=mod;
        ans*=inv[n*m-k];
        ans%=mod;
    }
    printf("%lld\n",ans);
}

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


int main(void) {
  int n;
  string s;
  cin >> n >> s;
  int mid = n/2;
  if((n%2) != 0) {
    cout << "No" << endl;
  } else {
    rep(i, mid) {
      if(s[i] != s[mid+i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }

  return 0;
}

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

const double INF = 1e5;

vector<double> v;
int n;
double len;
double dp[1 << 12][12];

double search(int s, int prev)
{
	if (s == (1 << n) - 1){
		return v[prev];
	}
	if (~prev && dp[s][prev] < INF){
		return dp[s][prev];
	}
	
	double res = INF;
	for (int i = 0; i < n; i++){
		int x = 1 << i;
		if (s & x) continue;
		if (s == 0){
			res = min(res, v[i] + search(x, i));
		}
		else {
			double t = sqrt((v[i] + v[prev]) * (v[i] + v[prev]) - (v[i] - v[prev]) * (v[i] - v[prev]));
			res = min(res, t + search(s | x, i));
		}
	}
	
	return dp[s][prev] = res;
}

int main()
{
	string str;
	while (getline(cin, str)){
		stringstream ss(str);
		
		len = -1;
		v.clear();
		fill((double *)dp, (double *)dp + (1 << 12) * 12, INF);
		
		while (!ss.eof()){
			double tmp;
			ss >> tmp;
			if (len != -1) v.push_back(tmp);
			else len = tmp;
			ss.ignore();
		}
		
		n = v.size();
		
		double res = search(0, -1);
		if (res < len + 1e-6) puts("OK");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1636
#include<stdio.h>
#include<math.h>
#ifdef DEBUG
#include<conio.h>
#endif // DEBUG


int main () {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif // DEBUG

    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d %d %.5f\n", a / b, a % b, (double)a / b);

#ifdef DEBUG
    getch();
#endif // DEBUG
    return 0;
}




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

int main() {
  int N; cin >> N;
  vector<long long> A(N); 
  long long mx = 0;
  for(int i = 0; i < N; i++) cin >> A[i], mx = max(mx,A[i]);

  long long key = 0;
  for(int i = 0; i < N; i++){
    if(abs(key - mx/2) > abs(A[i]-mx/2)){
      key = A[i];
    }
  }
  cout << mx << " "<< key << endl;
}

Measured memory_bytes: 4028
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if(y >= r && y <= H-r && x >=r && x <= W-r){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


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

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

   int rem=t%10;
   if(rem==2 || rem==4 || rem==5 || rem==7  || rem==9)
    cout<<"hon"<<endl;
    else if(rem==0 || rem==1 || rem==6 || rem==8)
    cout<<"pon"<<endl;
    else if(rem==3)
    cout<<"bon"<<endl;
}


Measured memory_bytes: 3620
program b
    implicit none
    integer :: N, l, i
    character(10000) :: S

    read(*, *) N
    read(*, *) S

    l = len_trim(S)

    do i = 1, l
        S(i:i) = achar(mod(ichar(S(i:i)) - 65 + N, 26) + 65)
    end do
    
    write(*, '(a)') trim(S)

end program b

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int A;
  int B;
  cin >>A>>B;
  
  int x=A+B;
  
  if(x<10) {
    cout << x<< endl;
  }
else {
cout << "error" << endl;
}
}


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

typedef long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<ll, ll >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//

ll N, M;
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    vector<P > v(N);
    ll a, b;
    LREP(i, 0, N){
        cin >> a >> b;
        v[i].first = a;
        v[i].second = b;
    }
    sort(v.begin(), v.end(), firstCompare);

    ll ans = 0;
    LREP(i, 0, N){
        if(v[i].second < M){
             M -= v[i].second;
             ans += v[i].second * v[i].first;
        }else{
            ans += M * v[i].first;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin>>n;
  if(n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[1] == n[3]){
    cout<<"Yes"<<'\n';
  }
  else{
    cout<<"No"<<'\n';
  }
  return 0;
}




Measured memory_bytes: 3636
h, w = map(int, input().split())
if h == 1 or w == 1:
    print(1)
elif h % 2 == 0 or w % 2 == 0:
    if h % 2 == 0:
        print(h//2*w)
    else:
        print(w//2*h)
else:
    print((h//2+1)*w - w//2)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

	vector<ll> enumDivisor;
	for (ll i = 1; i * i <= n-1; ++i) {
		if ((n-1) % i == 0) { 
			enumDivisor.push_back(i);
		  if (i*i != n-1) enumDivisor.push_back((n-1)/i);
		}
	}

	debug(enumDivisor)

	ll ans = enumDivisor.size()-1;

	vector<ll> enumDivisor2;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			enumDivisor2.push_back(i);
			if (i * i != n) enumDivisor2.push_back(n / i);
		}
	}

	debug(enumDivisor2)

	for (ll d : enumDivisor2) {
	  if (d == 1) continue;
	  ll m = n;
		while(m % d == 0) m /= d;
		if (m % d == 1) { ans++; cerr << d << " ";}
	}
	cerr << endl;

	cout << ans << endl;
}

Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    aa=LI()
    
    if n==0 and aa[0]!=1:
        print(-1)
        exit()

    if n>0 and aa[0]>0:
        print(-1)
        exit()

    node=[0]*(n+1)
    node[0]=1
    node[n]=aa[n]

    for i in range(n-1,0,-1):
        a=aa[i]
        if a>(1<<i):
            print(-1)
            exit()

        node[i]=min(1<<i,node[i+1]+aa[i],((1<<(i-1))-aa[i-1])*2)

    #print(node)

    for i in range(1,n+1):
        node[i]=min((node[i-1]-aa[i-1])*2,node[i])

    if node[n]!=aa[n]:
        print(-1)
        exit()
    #print(node)
    print(sum(node))


main()

Measured memory_bytes: 645996
/*input
3 3
1
3
1
3
1
3
*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<long,long>
#define vi          vector<long long>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mod         998244353
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repi(i,a,b) for(ll i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define fIO         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define tr(it, a)   for(auto it = a.begin(); it != a.end(); it++)
#define clr(x)      memset(x, 0, sizeof(x))
#define debug(x)      cerr << #x << "=" << x << endl
#define debug2(x, y)  cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define TIME        cerr << "\nTime elapsed: "<<1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; 
//#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update>;

ll sub(ll a, ll b){return (a-b+hell)%hell;}
ll add(ll a, ll b){return (a+b)%hell;}
ll mul(ll a, ll b){return (a*b)%hell;}
/*vector<ll>adj[100005];
bool vis[100005];
ll siz,edges;
void dfs(ll i)
{
    vis[i]=1;
    //siz++;
    for(ll j=0;j<adj[i].size();j++)
    {        
        edges++;
        if(!vis[adj[i][j]])
            dfs(adj[i][j]);
    }
}
ll mpow(ll base, ll exp) {
  base %= hell;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % hell;
    base = ((ll)base * base) % hell;
    exp >>= 1;
  }
  return result;
}*/
int main()
{
fIO;
ll n,sum=0,t=1,mm,ans,k,d;

//cin >> t;
while(t--){
  //string s;
  cin>>n>>k;
  vi m(n+1,0);
  rep(i,0,k){
    cin>>d;
    rep(j,0,d){cin>>mm; m[mm]++;}
  }
  rep(i,1,n+1)if(m[i]==0)ans++;
  cout<<ans<<endl;

    













}
TIME;
    
}

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

int main() {
        ll n; cin >> n;
        int ans = 0;
        int maxDiv = round(sqrt(n));
        // 素因数分解した時に、nの平方根以下のカウント
        vector<int> count(maxDiv+1,0);
        // 1の場合のみ、答えは0
        if(n==1) ans=0;
        // 他の場合は、エラストテネスの篩にかける
        else {
                // 素数だけのチェックは難しいので、rootまでは全てやってしまう
                for(int i=2; i<=maxDiv; i++) {
                        // 割り切れるときは、実際に割ってカウントを足す
                        while(n%i==0) {
                                count[i]++;
                                n = n/i;
                        }
                }
                for(auto v:count) {
                        if(v!=0) {
                                for(int i=1;; i++) {
                                        // 何乗まで使えるかチェック
                                        v-=i;
                                        if(v>=0) ans++;
                                        else break;
                                }
                        }
                }
                // もともとのnが素数の場合は、1回だけ割り切れる
                if(ans==0) ans=1;
                // 少なくとも1回は素因数分解ができた場合は、余った数字が平方根を超えているかチェック（超えていれば1回足す）
                else {
                  if(n>maxDiv) ans++;
                }
        }
        cout << ans << endl;
}


Measured memory_bytes: 7212
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1e18) + 1;

ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % MOD;
        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

ll invmod(ll x)
{
    return power(x, MOD - 2);
}

int main(void)
{
    ll n, a, b;
    ll i;
    ll ans = 0;
    ll comba = 1, combb = 1;

    cin >> n >> a >> b;

    rep(i, 0, a)
    {
        comba *= n - i;
        comba %= MOD;
        comba *= invmod(i + 1);
        comba %= MOD;
    }

    rep(i, 0, b)
    {
        combb *= n - i;
        combb %= MOD;
        combb *= invmod(i + 1);
        combb %= MOD;
    }

    ans = power(2, n);

    ans = (ans - comba - combb - 1 + MOD * 3) % MOD;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int

using namespace std;


int main(){
	int N; cin>>N;
	int x; cin>>x;
	vector <int> a; a.resize(N);
	for(int i=0;i<N;i++) cin>>a[i];
	sort(a.begin(),a.end());
	int ans =0;
	for(int i=0;i<N;i++){
		if(x < a[i]) break;
		x -= a[i];
		ans++;
		if(i == N-1){
			if(x != 0) ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
char a[],R[99];h,b;main(i){for(;scanf("%s%s",R,a)*R[1];h=b=!printf("%d %d\n",h,b/2-1-h)){for(i=4;i--;h+=R[i]==a[i])R[R[i]]++,R[a[i]]--;for(i=47;++i<58;R[i]=0)b+=!R[i];}}

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

int main(){
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;

    if(s[a]!='-'){
        cout<<"No"<<"\n";
        return 0;
    }

    rep(i,a){
        if(s[i]=='-'){
            cout<<"No"<<"\n";
            return 0;
        }
    }
        for(int i=a+1;i<=a+b;i++){
        if(s[i]=='-'){
            cout<<"No"<<"\n";
            return 0;
        }
    }
    cout<<"Yes"<<"\n";
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<(int)(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;

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

  int n;
  string s;
  cin >> n >> s;

  int ans=1;
  rep(i, n-1)if(s[i]!=s[i+1])ans++;

  cout << ans  << endl;

  return 0;
}

Measured memory_bytes: 3764
from itertools import accumulate
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n = int(input())
a = list(map(int,input().split()))
left = a[:n]
suml = sum(left)
right = [-a[i] for i in range(3*n-1,2*n-1,-1)]
sumr = sum(right)
Suml = [suml]
Sumr = [sumr]
heapify(left)
heapify(right)

#左からi(n<=i<=2*n-1)番目までの大きい方の総和と(3*n-1-i)番目までの小さい方の総和を求める
for i in range (n,2*n):
    heappush(left,a[i])
    x = heappop(left) #ここまでで常に大きい方からnことって来ている
    suml += a[i]-x
    Suml.append(suml)
for i in range(2*n-1,n-1,-1):
    heappush(right,-a[i])
    y = heappop(right)
    sumr += -a[i]-y
    Sumr.append(sumr)
ans = -inf
for i in range(n+1):
    ans = max(ans,Suml[i]+Sumr[n-i])
print(ans)


Measured memory_bytes: 120944
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main(){
    int n, c = 0, c2 = 0;
    cin >> n;
    if (n < 105){
        cout << 0 << endl;
        return 0;
    }
    for (int i = 105; i <= n; i += 2){
        for (int j = 1; j <= i; j++){
            if (i % j == 0){
                c++;
            }
        }
        if (c == 8){
            c2++;
        }
        c = 0;
    }
    cout << c2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1) {
    for (int i = 0; i < N; i++) par.at(i) = i;
  }

  int find(int x) {
    if (par.at(x) == x) return x;
    return par.at(x) = find(par.at(x));
  }

  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    if (sizes.at(rx) < sizes.at(ry)) swap(rx, ry);
    par.at(ry) = rx;
    sizes.at(rx) += sizes.at(ry);
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return sizes.at(find(x)); }

  int num_of_connected_components() {
    int ret = 0;
    for (int i = 0; i < par.size(); i++) {
      if (find(i) == i) ret++;
    }
    return ret;
  }
};

int main() {
  ll n, m;
  cin >> n >> m;
  UnionFind uf(n);
  REP(i, m) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    uf.unite(x, y);
  }
  ll ans = 0;
  REP(i, n) {
    if (uf.find(i) == i) {
      ans = max(ans, (ll)uf.size(i));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W;
vector<vector<char>> s;
vector<vector<int>> cost;

int bfs(){
    queue<pair<int, int>> Q;
    Q.push(make_pair(0, 0));
    cost[0][0] = 0;
    
    while(!Q.empty()){
        pair<int, int> p = Q.front();
        Q.pop();
        if(p == make_pair(H - 1, W - 1)){
            return cost[p.first][p.second];
        }
        for(int i = 0; i < 4; i++){
            int Y = p.first + dy[i];
            int X = p.second + dx[i];
            if(X < 0 || W <= X || Y < 0 || H <= Y)continue;
            if(s[Y][X] == '#')continue;
            if(cost[Y][X] != -1)continue;
            cost[Y][X] = cost[p.first][p.second] + 1;
            Q.push(make_pair(Y, X));
        }
    }
    
    //たどり着けない場合
    return -1;
}

int main(){
    cin >> H >> W;
    s.assign(H, vector<char>(W));
    cost.assign(H, vector<int>(W, -1));
    int white = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> s[i][j];
            if(s[i][j] == '.')white++;
        }
    }
    int min_cost = bfs();
    if(min_cost == -1)cout << -1 << endl;
    else cout << white - (min_cost + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
//Author- Vaibhav singh

//"At what speed must I live...to be able to see you again..?"

/*Endlessly expanding solitude wraps around me,
And I'm reminded of times I laughed innocently,
But I can't move, can't get loose, can't move, can't get loose,
Can't move, can't move!
unraveling the world

Something changed in me, I couldn't change;
The two mix together, both of us facing destruction.
I'm breakable, unbreakable;
I'm shakeable, unshakeable*
But I won't let you be defiled!



*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define re return 0;
// *#######################################################################################*

    

int main()
{
      
   fast
   ll a,b;
   cin>>a>>b;
   o(a*b)
   
   
   
   
   
   
   
   
   
   
   
   
    
    re
}

Measured memory_bytes: 3648
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>int LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>int UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	int i,X,Y,Z,n,m,s,t,W;cin>>X>>Y>>Z>>n>>m>>s>>t;s--;t--;
	W=X+Y+Z+n+m;
	vector<vector<int>>go(W);
	for(i=0;i<n;i++){
		int a,b;cin>>a>>b;a--;b--;
		go[X+Y+Z+i].pub(a);
		go[X+Y+Z+i].pub(X+b);
		go[a].pub(X+Y+Z+i);
		go[X+b].pub(X+Y+Z+i);
	}
	for(i=0;i<m;i++){
		int a,b;cin>>a>>b;a--;b--;
		go[X+Y+Z+n+i].pub(X+a);
		go[X+Y+Z+n+i].pub(X+Y+b);
		go[X+a].pub(X+Y+Z+n+i);
		go[X+Y+b].pub(X+Y+Z+n+i);
	}
	vector<bool>k(W);
	k[X+Y+Z+s]=true;
	queue<pair<int,int>>que;
	que.push(mp(0,X+Y+Z+s));
	while(que.size()){
		int z,b;tie(z,b)=que.front();que.pop();
		if(b==X+Y+Z+n+t){cout<<z/2<<endl;return 0;}
		for(auto it:go[b]){
			if(k[it]){continue;}
			k[it]=1;
			que.push(mp(z+1,it));
		}
	}
	cout<<-1<<endl;
	return 0;
}



Measured memory_bytes: 27936
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main() {
	ll i,j,k,l,m,n,t;
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n;
	cout<<(n*n-n)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)
//static const ll MOD = 1000000007;
//static const ll INF = 1000000000000000000;
//#define PI 3.14159265358979323846
//
//int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
//
//int findSumDigits(int s) {
//    int num = 0;
//    int temp = 0;
//    while (s) {
//        temp = s % 10;
//        num += temp;
//        s = s / 10;
//    }
//    return num;
//}
//
//int countDivisorNum(int n) {
//    int count = 0;
//    for (int i = 1; i <= n; i++) {
//        if (n % i == 0) {
//            count++;
//        }
//    }
//    return count;
//}

int main() {
    int x, n;
    cin >> x >> n;
    if (n == 0) {
        cout << x << endl;
        return 0;
    }
    int ansl[100];
    rep(i, 100, 0) {
        ansl[i] = -1;
    }
    int temp;
    rep(j, n, 0) {
        cin >> temp;
        temp = temp - 1;
        ansl[temp] = 0;
    }

    int temp_l = 0, temp_h = 0;
    rep(i, x + 1, 0) {
        temp_l = x - i;
        temp_h = x + i;
        if (temp_l == 0) {
            cout << 0 << endl;
            break;
        }
        if (ansl[temp_l - 1] != 0) {
            cout << temp_l << endl;
            break;
        }
        if (ansl[temp_h - 1] != 0) {
            cout << temp_h << endl;
            break;
        }
    }

    return 0;
}

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

typedef pair<int,int> P;
const int INF = 500000000;

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if (a <= k){
        ans += a;
    }else{
        ans += k;
    }
    k -= a;
    k -= b;
    if (k > 0){
        ans -= k;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

using namespace std;

int main() {
   string S;
   string T;
   int count = 0;
   cin >> S;
   cin >> T;

   for (int i = 0; i < S.size(); i++) {
       if (S[i] != T[i]) {
           count++;
       }
   }
   cout << count;
}

Measured memory_bytes: 3856
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int main(){
    int n,m,b,c,idx=0;
    unsigned long long ans=0ULL;
    cin>>n>>m;
    vector<int>a(n);
    vector<pair<int,int>>cb(m);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++){
        cin>>b>>c;
        cb[i]=make_pair(c,b);
    }
    sort(a.begin(),a.end());
    ans=accumulate(a.begin(),a.end(),0ULL);
    sort(cb.begin(),cb.end());
    reverse(cb.begin(),cb.end());
    for(int i=0;i<m;i++){
        for(int j=0;j<cb[i].second&&idx<n;j++){
            if(cb[i].first<=a[idx])break;
            ans+=cb[i].first-a[idx++];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	
	public static void Main(string[] args)
	{
		int[] p = Input().ToInt();
		
		int sousa = 0;
		int dif = 0;
		for(int i = 0; i < p.Length; i++)
		{
			if(p[i] % 2 != 0)
			{
				dif++;
			}
		}
		if(dif == 1)
		{
			for(int i = 0; i < p.Length; i++)
				if(p[i] % 2 == 0) p[i]++;
			sousa++;
		}
		if(dif == 2)
		{
			for(int i = 0; i < p.Length; i++)
				if(p[i] % 2 == 1) p[i]++;
			sousa++;
		}
		int max = (int)Math.Max(p[0], Math.Max(p[1], p[2]));
		
			
		sousa += (max - p[0]) / 2;
		sousa += (max - p[1]) / 2;
		sousa += (max - p[2]) / 2;
		Console.WriteLine(sousa);
	}
	
	public static long GCD(long a, long b)
	{
		if(b == 1)
			return a;
		long p = b / a;
		return GCD(a, b - a*p);
	}
	
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		int[] r = new int[str.Length];
		for(int i = 0; i < str.Length; i++)
			r[i]=str[i].ToInt();
		return r;
	 }
	
}

Measured memory_bytes: 13140
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))

def main():
    n,k=L()
    h=L()
    dp=[1e+12]*n
    dp[0]=0
    for i in range(n):
        for j in range(1,k+1):
            if i+j>=n:
                break
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
    print(dp[n-1])
    
    
if __name__ == '__main__':
    main()

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int gcd(int a,int b){
    int r;
    if(a<b) swap(a,b);
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int atcoder(){
    string s;
    cin>>s;
    if(s=="zyxwvutsrqponmlkjihgfedcba") {cout<<-1<<ENT;return 0;}
    int n=(int)s.length();
    if(n<26){
        Vi alph(26,0);
        REP(i,0,n){
            alph[s[i]-'a']++;
        }
        REP(i,0,26){
            if(alph[i]==0){
                s.push_back('a'+i);
                break;
            }
        }
    }else{
        string t;
        reverse(ALL(s));
        Vi alph(26,0);
        alph[s[0]-'a']++;
        REP(i,1,n){
            alph[s[i]-'a']++;
            REP(j,s[i]-'a'+1,26) if(alph[j]==1) {s[i]='a'+j;t=s.substr(i);goto out;}
        }
    out:
        reverse(ALL(t));
        s=t;
    }
    cout<<s<<ENT;
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}

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

int main() {
   int W,H,x,y,r;
  cin>> W >> H >> x >> y >>r;
   if(x-r>=0&&y-r>=0&&r+x<=W&&y+r<=H){
   cout<<"Yes" <<endl;
   } else {
     cout<<"No" <<endl;
   }
  return 0;
  
  
  
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  mp(a,b)  make_pair(a,b)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;


int main()
{
    int a,b;
    cin>>a>>b;
    yn(a%2&&b%2);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


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

    ll i,j,k,l,m,n,w,x,y,z,p,q,tmp,sum=0;
    string str;
    cin>>n>>q;
    UnionFind t(n);
    rep(i,q){
        cin>>w>>x>>y;
        if(w){
                        if(t.same(x,y)) cout<<"1"<<endl;
            else cout<<"0"<<endl;
        }else{
            t.unite(x,y);

        }
    }   

    return 0;
}






Measured memory_bytes: 3256
import sys

a, b, c, d = [int(i) for i in list(input())]

K = [1, -1]

for i in K:
    for j in K:
        for k in K:
            if i*b + j*c + k*d == 7 - a:
                if i*b >= 0:stb = "+{}".format(b)
                else:stb = "-{}".format(b)
                if j*c >= 0:stc = "+{}".format(c)
                else:stc = "-{}".format(c)
                if k*d >= 0:std = "+{}".format(d)
                else:std = "-{}".format(d)
                print(str(a)+stb+stc+std+"=7")
                sys.exit()

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

constexpr int MAX = 200010;

// 関数にしておくと便利
long long subcalc(long long x) { return x * (x + 1) / 2; }

int n;
int c[MAX];
vector<int> G[MAX];

int sz[MAX];
stack<int> last[MAX];
long long ans[MAX];

// 部分木のサイズを求める
void dfs1(int v, int p) {
    sz[v] = 1;
    for(int u : G[v]) {
        if(u != p) {
            dfs1(u, v);
            sz[v] += sz[u];
        }
    }
}

// 答えの計算
void dfs2(int v, int p) {
    if(v == 0) { // 根にアクセスする前に切断しておく
        for(int i = 1; i <= n; i++)
            last[i].push(n);
        dfs2(1, 0);
        for(int i = 1; i <= n; i++)
            ans[i] += subcalc(last[i].top());
    } else {
        last[c[v]].top() -= sz[v];

        for(int u : G[v]) {
            if(u != p) {
                last[c[v]].push(sz[u]);
                dfs2(u, v);
                ans[c[v]] += subcalc(last[c[v]].top());
                last[c[v]].pop();
            }
        }
    }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
        last[i].push(n);
    }
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs1(1, 0);
    dfs2(0, 0);

    for(int i = 1; i <= n; i++)
        cout << subcalc(n) - ans[i] << endl;

    return 0;
}


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

int main(){
	int a, b;
	cin >> a >> b;

	if(a == 1 && b == 1){
		cout << "Draw\n";
	}else if(a == 1){
		cout << "Alice\n";
	}else if(b == 1){
		cout << "Bob\n";
	}else{
		if(a == b){	
			cout <<"Draw\n";
		}else if(a > b){
			cout << "Alice\n";
		}else{
			cout << "Bob\n";
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> C(H, vector<char>(W));
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            cin >> C.at(i).at(j);
        }
    }
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            cout << C.at(i).at(j);
        }
        cout << endl;
        for (int j = 0; j < W; j++){
            cout << C.at(i).at(j);
        }
        cout << endl;
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  vector<int>kk({1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51});
  int k;cin>>k;
  cout<<kk[k-1];

  return 0;
}

Measured memory_bytes: 256