akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const int INF = 1e+8;

// 変数 'a' - 'k' を value に置き換え
void change(string& s, char x, char value){
	for(int i=0 ; i < s.size() ; i++ ){
		if( s[i] == x ) s[i] = value;
	}
}

// 式から "--" の除去
void minus_erase(string& s){
	for(int i=1 ; i < s.size() ; i++ ){
		if( s[i-1] == '-' && s[i] == '-' ){
			s.erase( i-1 , 2 );
			i = 0;
		}
	}
}

int eval(string s, int& pos){
	if( s[pos] == 'F' ){ pos++; return 0; }
	if( s[pos] == 'T' ){ pos++; return 1; }
	if( s[pos] == '-' ){ pos++; return 1 - eval(s,pos) ; }
	if (s[pos] == '(') { 
		++pos; 
		int a = eval(s, pos);
		char c = s[pos++];
		int b = eval(s, pos);
		++pos;
		if( c == '*' ){
			return a & b;
		}else if( c == '+' ){
			return a | b;
		}else if( c == '>' ){
			return (a == 1 && b == 0)? 0 : 1 ;
		}
	}
}

int main(){
	string s;
	while( cin >> s ){
		if( s == "#" ) break;
		
		// "->" を ">" に置き換えておく
		string s_;
		for(int i=0 ; i < s.size() ; i++ ){
			if( i+1 < s.size() && s[i] == '-' &&s[i+1] == '>' ){
				s_.push_back( '>' );
				i++;
			}else{
				s_.push_back( s[i] );
			}
		}
		s = s_;
		// '=' の左側を ex1, 右側を ex2 とする
		string ex1, ex2;
		bool flag = false;
		for(int i=0 ; i < s.size() ; i++ ){
			if( s[i] == '=' ){
				flag = true;
			}else if( flag ){
				ex2.push_back( s[i] );
			}else{
				ex1.push_back( s[i] );
			}
		}
		// 登場する変数('a' - 'k')をチェック
		int f[256] = {0};
		for(int i = 0 ; i < s.size() ; i++ ){
			f[ s[i] ] = 1;
		}
		vector<char> vc;
		for(char c = 'a' ; c <= 'k' ; c++ ){
			if( f[c] ){
				vc.push_back( c );
			}
		}
		// N := 登場する変数の種類.
		int N = vc.size();
		// 変数の置き換えを 2^N 通り試し すべての式の評価で右辺と左辺が等しいか調べる.
		bool ans = true;
		for(int bits = 0 ; bits < (1<<N) ; bits++ ){
			string ex1_ = ex1;
			string ex2_ = ex2;
			// 変数を "T" or "F" に置き換えておく
			for(int i=0 ; i < N ; i++ ){
				// i 番目の文字を'T' か 'F'にしておく
				if( bits & (1<<i) ){
					change( ex1_ , vc[i] , 'T' );
					change( ex2_ , vc[i] , 'T' );
				}else{
					change( ex1_ , vc[i] , 'F' );
					change( ex2_ , vc[i] , 'F' );
				}
			}
			// "--" の除去
			minus_erase( ex1_ );
			minus_erase( ex2_ );
			
			// 式 の評価
			int t=0;
			int val_1 = eval( ex1_ , t );
			t=0;
			int val_2 = eval( ex2_ , t );
			// 式 ex1 と 式 ex2 が等しいかどうか
			if( val_1 != val_2 ){ 
				ans = false;
				break;
			}
		}
		// 出力 
		if( ans ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 908
a,b,c,x,y = map(int,input().split())

ans = a * x + b * y

if x < y:
    e = c * 2 * x
    f = b * (y-x)
    ans = min(ans, f+e)
    g = c * 2 * y
    ans = min(ans,g)
else:
    e = c * 2 * y
    f = a * (x-y)
    ans = min(ans, f+e)
    g = c * 2 * x
    ans = min(ans,g)
print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define M 1000000007
typedef long long ll;
ll dp[1005],n,m;
char s[1005],t[1005];
int main(void){
	cin>>s>>t;
	n=strlen(s);
	m=strlen(t);
	dp[0]=1;
	for(int i=0;i<n;i++)for(int j=m-1;j>=0;j--)if(s[i]==t[j])dp[j+1]=(dp[j+1]+dp[j])%M;
	cout<<dp[m]<<endl;
}


Measured memory_bytes: 3120
#include <algorithm>
    #include <bitset>
    #include <cctype>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <deque>
    #include <fstream>
    #include <functional>
    #include <iostream>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <vector>
    using namespace std;
    using ll = long long;
    #define fst first
    #define snd second
     
    /* clang-format off */
    template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
    template <class T> struct _vec<T, 0> { using type = T; };
    template <class T, size_t D> using vec = typename _vec<T, D>::type;
    template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
    template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
    /* clang-format on */
     
    int N;
    vector<ll> A;
     
    ll dp[200010][20];
     
    int lg(ll A, int x, ll B) {
      for (int i = 0; i < x; i++) A *= 4;
      // A*4^x <= B*4^y
      for (int y = 0;; y++) {
        if (A <= B) {
          return y;
        }
        B *= 4;
      }
    }
     
    ll solve(int i, int x) {
      if (i == N - 1) return 0;
      if (x > 15) {
        return solve(i, 15) + (ll)(N - i - 1) * (x % 15);
      }
      ll& res = dp[i][x];
      if (res != -1) return res;
      int y = lg(A[i], x, A[i + 1]);
      return res = y + solve(i + 1, y);
    }
     
    int main() {
      while (cin >> N) {
        A.resize(N);
        for (int i = 0; i < N; i++) cin >> A[i];
        vector<ll> costA(N + 1, 0);
        {
          memset(dp, -1, sizeof(dp));
          for (int i = 0; i < N; i++) costA[i] = solve(i, 0) * 2;
        }
        vector<ll> costB(N + 1, 0);
        {
          reverse(A.begin(), A.end());
          memset(dp, -1, sizeof(dp));
          for (int i = 0; i < N; i++) costB[i] = solve(i, 0) * 2;
        }
        reverse(costB.begin(), costB.end());
        ll res = 1ll << 60;
        for (int i = 0; i <= N; i++) {
          ll cost = i + costA[i] + costB[i];
          res = min(res, cost);
        }
        cout << res << endl;
      }
      return 0;
    }

Measured memory_bytes: 54912
n, m = map(int, input().split())

# p: city number
# y: year

id_dic = {}
city_num = []
for i in range(m):
    p, y = map(int, input().split())
    city_num.append((p, y))
    if p not in id_dic:
        id_dic[p] = []
    id_dic[p].append(y)

for p in id_dic.keys():
    id_dic[p].sort()

ans = {}
for p in id_dic.keys():
    for i, y in enumerate(id_dic[p]):
        ans[(p, y)] = i + 1

for p, y in city_num:
    num = ans[(p, y)]

    print("{:0>6}".format(p) + "{:0>6}".format(num))

Measured memory_bytes: 51396
n = int(input())
s = input()

stdata = [chr(s) for s in range(ord("A"),ord("Z") + 1)]
ans = []
for i in range(len(s)):
  ind = stdata.index(s[i])
  ind = (ind + n) % 26
  ans.append(stdata[ind])
for i in range(len(s)):
  print(ans[i],end="")


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

vector<string> s;

int main()
{
    int n, L;
    cin >> n >> L;
    while (n--) {
        string tmp;
        cin >> tmp;
        s.push_back(tmp);
    }

    sort(s.begin(), s.end());
    for (auto x : s) cout << x;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,k; cin>>n>>k;
    set<int> s;
    rep(i,k){
        int d; cin>>d;
        rep(j,d){
            int a; cin>>a;
            s.insert(a);
        }
    }
    cout<<n-s.size()<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pairSS
int main(){
  #define int long long
  int n;
  cin >> n;
  int a[n+1];
  int b[n];
  rep(i,n+1){
    cin >> a[n-i];
  }
  rep(i,n){
    cin >> b[n-1-i];
  }
  int right[n],left[n];
  int ans =0;
  for(int i=0;i<n;i++){
    if(i==0){
      right[0]=min(a[0],b[0]);
      if(b[0]>=a[0]){
        left[0]=min(b[0]-a[0],a[i+1]);
      } else {
        left[0]=0;
      }
    } else {
      right[i]=min(a[i]-left[i-1],b[i]);
      if(right[i]<0){
        right[i]=0;
      }
      if(b[i]>=right[i]){
        left[i]=min(b[i]-right[i],a[i+1]);
      } else {
        left[i]=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    ans = ans + left[i]+right[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define M 1000000007
#define endl '\n'
#define ll long long
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll n{0};
	cin>>n;

	ll arr[n];
	for(ll i=0;i<n;i++)
		cin>>arr[i];

	sort(arr,arr+n);

	ll count{0};
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			for(ll k=j+1;k<n;k++){
				if( (arr[i]!=arr[j]) && (arr[i]!=arr[k]) && (arr[j]!=arr[k]) && ((arr[i]+arr[j])>arr[k]) ){
					count++;
				}
			}
		}
	}

	cout<<count<<endl;

	
	return 0;
}



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

signed main(){
	int n;cin>>n;
	vector<int> a(n),b(n),c(n);
	for(auto&& w:a)cin>>w;
	for(auto&& w:b)cin>>w;
	for(auto&& w:c)cin>>w;
	sort(a.begin(),a.end());
//	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	int ans=0;
	for(int i=0;i<n;i++){
	int x=lower_bound(a.begin(),a.end(),b[i])-a.begin();
	int y=c.end()-upper_bound(c.begin(),c.end(),b[i]);
 //       int z=n-(lower_bound(c.begin(),c.end(),b[i])-c.begin());
 	ans+=x*y;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
from collections import Counter

N,K,L = map(int, input().split())
pq_list = []
for _ in range(K):
    pq_list.append(list(map(int, input().split())))

rs_list = []
for _ in range(L):
    rs_list.append(list(map(int, input().split())))

class UnionFind():
    def __init__(self):
        self.roots = {}
        self.ranks = {}

    def connect(self,x,y):
        root_x = self.pick_root(x)
        root_y = self.pick_root(y)
        
#         # 経路圧縮（のつもり）
#         self.roots[x] = root_x
#         self.roots[y] = root_y
        
        if not root_x == root_y:
            if self.ranks[root_x] >= self.ranks[root_y]:
                # 短い方の根を長い方の根にする
                # 等しいときはxにくっつける
                self.roots[root_y] = root_x
            else:
                self.roots[root_x] = root_y

            if self.ranks[root_x]==self.ranks[root_y]:
                # 等しいときxにくっつけると、xのランクが1増える
                self.ranks[x] += 1

    def pick_root(self,k):
        if not k in self.roots:
            self.roots[k] = k
            self.ranks[k] = 1
            return k

        k_root = self.roots[k]
        if k_root == k:
            return k
        else:
            # pick_rootで毎回見に行くのが無駄にも思えるが、いつ根ノードがくっつくかわからないので必要な気がしている
            self.roots[k] = self.pick_root(self.roots[k_root])
            return self.roots[k]
#             return self.pick_root(k_root)

UF_pq = UnionFind()
for p,q in pq_list:
    UF_pq.connect(p, q)

UF_rs = UnionFind()
for r,s in rs_list:
    UF_rs.connect(r, s)

root_tuples = []
for i in range(1,N+1):
    # rootsにないということは、一度もconnectしてないということ
    # それであれば最終的な解答ではその街は1（自分のみ）でよいので
    # (None, None)で保存しcounterを１に変更する
    if not i in UF_pq.roots:
        root_tuples.append((None,None))
        continue
    if not i in UF_rs.roots:
        root_tuples.append((None,None))
        continue
    pq_root = UF_pq.pick_root(i)
    rs_root = UF_rs.pick_root(i)
    
    # ある都市のpqのroot,rsのrootを保存。
    # これが両方共一致する都市は、「どちらでも連結している」といえる
    root_tuples.append((pq_root,rs_root))

counter = Counter(root_tuples)
counter[(None,None)] = 1

kotae_list = []
for i in range(N):
    kotae_list.append(counter[root_tuples[i]])

print(" ".join(map(str,kotae_list)))

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    
    ll n,m; cin>>n>>m;
    vector<vector<ll>> s(m);
    rep(i,m){
        ll k; cin>>k;
        rep(j,k){
            ll a; cin>>a;
            a--;
            s[i].push_back(a);
        }
    }
    vector<ll> p(m);
    rep(i,m) cin>>p[i];

    ll ans=0;

    for(int bit=0; bit < (1<<n); bit++){
        //どのスイッチがonか
        bool ok=true;
        for(int i=0;i<m;i++){
            //onの数をカウント
            ll cnt=0;
            for(auto on:s[i]){
                if(bit & (1<<on)) ++cnt;
            }
            if(cnt%2!=p[i]) ok=false;
        }
        if(ok) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

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

	  int b = sc.nextInt();
      
      int c = a * b;
      
      if (c % 2 == 0){
      System.out.println("Even");
      }
      else{
      System.out.println("Odd");
      }
  }
}


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

struct UnionFind{
  vector<int>par;
  UnionFind(int n){
    par.resize(n);
    rep(i,n) par[i] = i;
  }

  int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  void unite(int x,int y){
    x = find(x), y = find(y);
    if(y > x) par[y] = x;
    else par[x] = y;
  }

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



int main(){

  int N, M;
  cin >> N >> M;
  int a[M],b[M];

  rep(i,M) cin >> a[i] >> b[i], a[i]--,b[i]--;


  int ans = 0;
  rep(i,M){
    UnionFind uf(N);
    rep(j,M) if(i != j){
      uf.unite(a[j], b[j]);
    }
    int flg = false;
    forep(j,1,N)if(uf.find(j-1) != uf.find(j)){
       flg = true;
    }
    if(flg) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    s = input()
    ans = True

    for i in range((len(s) - 1) // 2):
        if s[0 + i] != s[(len(s) - 1) // 2 - i - 1] or s[(len(s) + 3) // 2 + i - 1] != s[len(s) - i - 1] or s[0 + i] != s[len(s) - i - 1]:
            ans = False
    if ans:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<ii,int>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 2000000000
#define N 100005
#define LOG 30
using namespace std;

struct Trie {

	int c[2];
	ll deg;

} T[N*(LOG+3)];

int n,k,a,b,say;
ll ans;

ll gez(int val,int node,int log,int lim) {

	if(log==-1) {
		return T[node].deg;
	}
	ll res=0;
	int bit=(1<<log)&val;
	int go=(bit>0);
	if(go || log<=lim) {
		if(T[node].c[0])
			res+=gez(val,T[node].c[0],log-1,lim);
		if(T[node].c[1])
			res+=gez(val,T[node].c[1],log-1,lim);	
	}
	else {
		if(T[node].c[0])
			res+=gez(val,T[node].c[0],log-1,lim);
	}
	return res;

}

void solve(int val) {

	for(int i=LOG;i>=0;i--) {
		int bit=(val&(1<<i));
		int go=(bit>0);
		if(go) {
			ans=max(ans,gez(val-(1<<i),0,LOG,i-1));
		}
	}
	ans=max(ans,gez(val,0,LOG,-1));

}

void add(int val,int util) {

	int node=0;
	for(int i=LOG;i>=0;i--) {
		int bit=(val&(1<<i));
		int go=(bit>0);
		if(!T[node].c[go]) {
			say++;
			T[node].c[go]=say;
		}
		node=T[node].c[go];
	}
	T[node].deg+=util;

}

int main() {

	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++) {
		scanf("%d %d",&a,&b);
		add(a,b);
	}
	solve(k);
	printf("%lld",ans);

}

Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
int fun(int x,int n)
{
    int ans=1;
    while(n>0)
    {
        if(1&n)
        ans=(ans*x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return ans;
}
int ncr(int n,int r)
{
    int ans=1;
    for(int i=0;i<r;i++)
    {
        ans=(((ans*(n-i))%mod)*fun(i+1,mod-2))%mod;
    }
   return ans;
}
signed main()
{
   
  int n;
  cin>>n;
  int k=n/3;
  int ans=0;
  for(int i=1;i<=k;i++)
  {
      int p=n-3*i;
      ans=(ans+ncr(p+i-1,i-1))%mod;
  }
  cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3596
#include<cstdio>
using namespace std;

const int MAXN = 510;

char str[MAXN], red[MAXN][MAXN], blue[MAXN][MAXN];

int main(){
	int H, W;
	scanf("%d %d", &H, &W);
	for (int i = 1; i <= H; ++i){
		scanf("%s", str + 1);
		for (int j = 2; j < W; ++j)
			if (i & 1) red[i][j] = '#', blue[i][j] = str[j];
			else blue[i][j] = '#', red[i][j] = str[j];
		red[i][1] = blue[i][W] = '#';
		red[i][W] = blue[i][1] = '.';
	}
	for (int i = 1; i <= H; ++i)
		printf("%s\n", red[i] + 1);
	for (int i = 1; i <= H; ++i)
		printf("%s\n", blue[i] + 1);
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>

int main(){
    int e;//入力記録
    int x;//i格納
    int er;//合計-i格納
    int is;//合計
    int es;//合計２
    int data;//最小値
    e=0;
    is=0;
    es=0;
    data=100000;
    scanf("%d",&e);
        for(int i=1;i<e;i++){
            is=0;
            es=0;
            x=i;
            er=e-i;
            while(x>0){
                is=is+x%10;
                x=x/10;
            }
            while(er>0){
                es=es+er%10;
                er=er/10;
            }
            if(is+es<data){
                data=is+es;
            }
        }
    printf("%d\n",data);
    return 0;
}

Measured memory_bytes: 128
from collections import deque
h,w=map(int,input().split())
l=list()
l.append('#'*(w+2))#壁
for i in range(h):
    l.append('#'+input()+'#')
l.append('#'*(w+2))#壁
p=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='#':
            continue
        s=[[-1 for a in b] for b in l]
        q=deque([[i,j]])
        s[i][j]=0
        while len(q)>0:
            a,b=q.popleft()
            for x,y in [[1,0],[0,1],[-1,0],[0,-1]]:
                if l[a+x][b+y]=='#' or s[a+x][b+y]>-1:
                    continue
                q.append([a+x,b+y])
                s[a+x][b+y]=s[a][b]+1
        r=0
        for x in s:
            for y in x:
                r=max(y,r)
        p=max(r,p)
print(p)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}

int main(){
FIO
ll k;
cin>>k;
map<ll,ll> mymap;
ll count=1;
ll num=7;
bool flag=true;
   while(num%k!=0){
      if(mymap.find(num%k)!=mymap.end()){
        flag=false;
        break;
      }
      mymap[num%k]=1;
      num=num*10+7;
      num=num%k;
      count++;
   }
   if(flag)
   cout<<count<<endl;
else
    cout<<"-1"<<endl;
}


Measured memory_bytes: 66136
#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X)< 0 ? -(X): (X))
#define LCM(X, Y)  ( ( (X) / (GCD( (X)  , (Y) ))) * (Y) )
#define MEM( A,  B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL ) fill( V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A,I) cout<<"at pos "<< I <<"  value is: "<< A[I]
#define TURBO ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0)
const double EPS =1e-9 ;
const double PI = 3.1415926535897932384626433832795 ;
using namespace std ;
inline ll GCD(ll A, ll B){
      if ( B == 0 ) return A;
      return GCD( (B) ,  (A % B) );
}
inline ll POW(ll BASE, ll EXP) {
   ll RES = 1;
   for(ll I= 0; I < EXP; I++) RES *= BASE ;
   return RES;
}

inline ll BIGMOD  ( ll a, ll p, ll m ) {
   ll res = 1 % m;
   ll x = a % m;
   while ( p > 0 ) {
       if ( (p & 1) > 0 ) res = ( res * x ) % m;
       x = ( x * x ) % m; p >>= 1;
   }
   return res;
}
inline void FILE_HANDLE( ){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

int main()
{

            TURBO;
            //FILE_HANDLE() ;
            string s;
            cin >> s ;
            int ans = 0 ;
            if(s[1] == 'R' && s[2] == 'R' && s[0] == 'R') ans = 3 ;
            else if(s[1] == 'R' && s[2] == 'R' ) ans = 2 ;
            else if(s[1] == 'R' && s[0] == 'R' ) ans = 2 ;
            else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') ans = 1 ;
            cout << ans << endl ;
}



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

using namespace std;

int main(void) {
  int N, M; cin >> N >> M;
  vector<int> A;
  int total = 0;

  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    total += a;
    A.push_back(a);
  }

  sort(A.begin(), A.end(), greater<int>());

  for (int i = 0; i < M; ++i) {
    if (A[i] * 4 * M < total) {
      cout << "No" << endl;
      return 0;
    }
  } 

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

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

using ll = unsigned long long;
using namespace std;

int main(void) {

    int a,b;
    cin >> a >> b;

    cout << max({a+b, a-b, a*b}) << endl;

    return 0;
}

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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ldb long double 
#define db double
#define str string
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}
vector<int> v[100005];
int n,m;
int dp[100005];
bool vis[100005];

int fun(int s)
{
    vis[s]=true;
    if(dp[s]!=-1)
     return dp[s];
     int res=0;
    for(int j=0;j<v[s].size();j++)
    {
        res=max(res,fun(v[s][j])+1);
    }
    return dp[s]=res;
}

int32_t main()
{
    fast;
    memset(dp,-1,sizeof(dp));
     cin>>n>>m;
     for(int i=0;i<m;i++)
     {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
     }
     for(int i=0;i<100005;i++)
      vis[i]=false;
     for(int i=1;i<=n;i++)
     {
        if(!vis[i])
        {
            int z=fun(i);
        }
     }
     int res=0;
     for(int i=1;i<=n;i++)
      res=max(res,dp[i]);
      cout<<res<<"\n";
      return 0;
}

Measured memory_bytes: 8704
#include <stdio.h>

int main(void)
{
    int N, A, B, C, D;
    int n;
    int x, y;

    scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);
    
    n = N;
    x = n / A * B;
    n -= n / A * A;
    if (n > 0){
        x += B;
    }
    
    n = N;
    y = n / C * D;
    n -= n / C * C;
    if (n > 0){
        y += D;
    }
    
    if (x < y){
        printf("%d\n", x);
    }
    else {
        printf("%d\n", y);
    }
    
    return (0);
}



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

const int N = (int(1e6)) + 5;
int minPrime[N];

void sieve() {
    for (int i=0; i<N; i++) minPrime[i] = i;
    minPrime[0] = 1;
    for (int i=2; i<N; i++)
        if (minPrime[i] == i)
            for (int j=2*i; j<N; j+=i)
                minPrime[j] = (minPrime[j] == j ? i : minPrime[j]); // might be wrong    
}

map<int, int> factors[N];
map<int, int> lcm_factors;

void factorize(int k, int index) {
    //vector<int>& f = factors[index];
    map<int, int>& f = factors[index];
    int mp = 1;
    while (k != 1) {
        if (mp != minPrime[k]) {
            mp = minPrime[k];
            //f.push_back(mp);
            while (minPrime[k] == mp) {
                k /= mp;
                lcm_factors[mp]++;
                f[mp]++;
            }
        }
    }
}

int n;
int a[N];

void solve() {
    sieve();
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        factorize(a[i], i);
    }

    //for (auto p:lcm_factors) cout << p.first << ' ' << p.second << '\n';
    
    bool flag1 = true;
    for (int i=0; i<n; i++)
        for (auto ppf : factors[i])
            flag1 &= (lcm_factors[ppf.first] == ppf.second);
    if (flag1) {
        cout << "pairwise coprime\n";
        return;
    }
    
    int g = a[0];
    for (int i=1; i<n; i++) g = __gcd(g, a[i]);
    if (g == 1) {
        cout << "setwise coprime\n";
    } else {
        cout << "not coprime\n";
    }

}

int main() {
    solve();
}

Measured memory_bytes: 294928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r][c];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	}
}



Measured memory_bytes: 63324
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;

int dx[] = {1, -1, 0, 0, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1};

int T, N;
int maze[500][500];

struct State{
	int x, y, t;
	State(int _x, int _y, int _t){
		x = _x;
		y = _y;
		t = _t;
	}
};

bool check(int x, int y){
	return x >= 0 && x < 500 && y >= 0 && y < 500 && maze[x][y] != 2;
}

int main() {
	while(cin >> T >> N && (T || N)){
		memset(maze, 0, sizeof(maze));
		int a, b;
		for(int i = 0; i < N; ++i){
			cin >> a >> b;
			maze[a + 250][b + 250] = 2;
		}
		int sx, sy, count = 0;
		cin >> sx >> sy;
		queue<State> q;
		q.push(State(sx + 250, sy + 250, 0));
		while(!q.empty()){
			State st = q.front(); q.pop();
			if(st.t > T || maze[st.x][st.y] == -1)
				continue;
				
			maze[st.x][st.y] = -1;
			count++;
			for(int i = 0; i < 6; ++i){
				int nx = st.x + dx[i];
				int ny = st.y + dy[i];
				if(check(nx, ny))
					q.push(State(nx, ny, st.t + 1));
			}
			
		}
		cout << count << endl;
	}	
	return 0;
}

Measured memory_bytes: 2212
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)
for i in range(n - 1):
    if a[i] + 1 == a[i + 1]:
        ans += c[a[i] - 1]
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    string t;
    cin >> t;
    string ans = t;
    rep(i,t.size()) {
        if (t[i] == '?') ans[i] = 'D';
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
#define SIZE 200005
using namespace std;

int A[SIZE];
bool id[SIZE];

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	int cnt=0;
	for(int i=1;i<k;i++) cnt+=(A[i]>A[i-1]);
	for(int i=0;i+k<=n;i++)
	{
		id[i]=(cnt==k-1);
		if(i==n-k) break;
		cnt-=(A[i+1]>A[i]);
		cnt+=(A[i+k]>A[i+k-1]);
	}
	set <int> st;
	set <int>::iterator it;
	for(int i=0;i<k;i++) st.insert(A[i]);
	int ret=(id[0]?0:1);
	for(int i=1;i+k<=n;i++)
	{
		bool up=false;
		st.insert(A[i+k-1]);
		it=st.end();it--;
		up|=!(*it==A[i+k-1]);
		it=st.begin();
		up|=!(*it==A[i-1]);
		up&=!id[i];
		ret+=up;
		st.erase(A[i-1]);
	}
	for(int i=0;i<n;i++)
	{
		if(id[i])
		{
			ret++;
			break;
		}
	}
	printf("%d\n",ret);
}

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

int main(){

  int n, r;
  for(;cin >> n >> r, n|r;){
    vector < int > v;
    for(;n;v.push_back(n--));
    for(int p,c;r--;){
      cin >> p >> c;
      for(int tmp,q=c;q--;){
	tmp = v[p+c-2];
	v.erase(v.begin()+p+c-2);
	v.insert(v.begin(), tmp);
      }
    }

    cout << v[0] << endl;
  }

}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define PUT(a, n) FOR(i, n) cin >> a[i]
#define OUT(a, n) FOR(i, n) cout << a[i] << ' '

using namespace std;

const int N = 1e5 + 5;

int main() {
	fast;
    int n; cin >> n;
    int a[n][3];
    FOR(i, n, 0)
    {
        FOR(j, 3, 0)cin >> a[i][j];
    }
    int dp[n][3] = {};
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    FOR(i, n, 1)
    {
        FOR(j, 3, 0)
        {
            FOR(x, 3, 0)
            {
                if(x == j)continue;
                else dp[i][j] = max(dp[i][j], dp[i - 1][x] + a[i][j]);
            }
        }
    }
    int ans = 0;
    FOR(i, 3, 0)ans = max(ans, dp[n - 1][i]);
    cout << ans;
    return 0;
}

Measured memory_bytes: 2560
M, D = [int(x) for x in input().split(' ')]
ret = 0

for m in range(1, M+1):
  for d in range(1, D+1):
    
    d_10 = int(d) // 10
    d_1 = int(d) - d_10 * 10
    
    if d_10 >= 2 and d_1 >= 2 and m == (d_10 * d_1):
      ret += 1
      
print(ret)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <string>

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); ++i)

int main()
{
    cin.tie(nullptr);

    int N;
    std::cin >> N;

    auto const V = N % 10;
    std::cout << (V == 3 ? "bon" : (V == 0 || V == 1 || V == 6 || V == 8) ? "pon" : "hon") << std::endl;

    return 0;
}

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

using ll = long long;
int ans;
int n, m, q;
vector<vector<int>> tuples;

void check(vector<int>& a) {
    assert((int)a.size() == n+1);
    int tempans = 0;
    for(int i = 0; i < (int)tuples.size(); i++) {
        int ai = tuples[i][0], bi = tuples[i][1], ci = tuples[i][2], di = tuples[i][3];
        if(a[bi]-a[ai] == ci) {
            tempans += di;
        }
    }
    ans = max(ans, tempans);
}

void dfs(vector<int>& cur) {
    if((int)cur.size() == n+1) {
        check(cur);
        return;
    }
    int d = cur.back();
    for(int i = d; i <= m; i++) {
        cur.push_back(i);
        dfs(cur);
        cur.pop_back();
    }
}

int main()
{
    cin >> n >> m >> q;
    tuples.resize(q, vector<int>(4));
    for(int i = 0; i < q; i++) {
        for(int j = 0; j < 4; j++) {
            cin >> tuples[i][j];
        }
    }
    ans = 0;
    vector<int> v = {1};
    dfs(v);
    assert(v == vector<int>{1});
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<stdio.h>

int main(void){
	int N,i,count=0;
	int M,sig=0;
	double lim;
	scanf("%d %d",&N,&M);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
		sig=sig+A[i];
	}
	lim=(double)sig/4/M;
	for(i=0;i<N;i++){
		if((double)A[i]>=lim){
			count++;
		}
	}
	if(count>=M){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>

#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <string>
#include <stdbool.h>

#include <cstring>

#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfb(a) printf("%.10lf\n",a);
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%.12lf ",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"

#define MOD  ( int)(1e9 + 7)
#define MAXN (ll) ((1e6+5))
#define K 25
#define  ALPHABET_SIZE  26
#define N (int)(1e5+10)
#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define INF (ll )1e18
#define int ll
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int,int>>> vvpi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;


signed main() {

    ll a, b , m ;
     cin >> a>> b >> m ;
     vi vec(a + 1);
    for (int i = 1; i <= a ; ++i) {
        cin >> vec[i];
    }
    vi vec2( b +1);
    for (int j = 1; j <= b  ; ++j) {
        cin >> vec2[ j ];
    }
    ll mn = INF;
    for (int x ,y , z, k = 0; k <m ; ++k) {
        cin >> x>> y >> z;
        x= vec[x];
        y = vec2[y];
        z= x + y - z;
        mn= min(mn , z);
    }
    sort(BEND(vec));
    sort(BEND(vec2));
    ll temp = vec[1] + vec2[1];
    cout << min(temp , mn);
    return 0;









}

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

int main()
{
	int q,i,j,x,y;
	cin>>q;
	int a[100005],b[100005],c[100005];
	for(i=2;i<=100000;i++)
		a[i]=1;
	for(i=2;i<=int(sqrt(100000));i++)
		if(a[i]==1)
		{
			for(j=i+i;j<=100000;j+=i)
				a[j]=0;
		}
	for(i=3;i<=100000;i++)
	{
		if(a[i]==1 && a[(i+1)/2]==1)
			b[i]=1;
		else
			b[i]=0;
	}
	c[1]=0;
	c[2]=0;
	for(i=3;i<=100000;i++)
		c[i]=c[i-1]+b[i];
	for(i=1;i<=q;i++)
	{
		cin>>x>>y;
		cout<<c[y]-c[x-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
H,W,K=map(int,input().split())
grid=["" for i in range(H)]
for i in range(H):
  grid[i]=list(input())
  
# ans=[[0 for i in range(W)] for j in range(H)]

def canExtendL(L,R,U,D):
  if L==0:
    return False
  for p in range(U,D+1):
    if grid[p][L-1]!=".":
      return False
  return True
    
def extendL(L,R,U,D,ichigo):
  for p in range(U,D+1):
    grid[p][L-1]=ichigo
  
def canExtendR(L,R,U,D):
  if R+1==W:
    return False
  for p in range(U,D+1):
    if grid[p][R+1]!=".":
      return False
  return True
    
def extendR(L,R,U,D,ichigo):
  for p in range(U,D+1):
    grid[p][R+1]=ichigo

def canExtendU(L,R,U,D):
  if U==0:
    return False
  for p in range(L,R+1):
    if grid[U-1][p]!=".":
      return False
  return True
    
def extendU(L,R,U,D,ichigo):
  for p in range(L,R+1):
    grid[U-1][p]=ichigo

def canExtendD(L,R,U,D):
  if D+1==H:
    return False
  for p in range(L,R+1):
    if grid[D+1][p]!=".":
      return False
  return True
    
def extendD(L,R,U,D,ichigo):
  for p in range(L,R+1):
    grid[D+1][p]=ichigo

ichigo=0
for i in range(H):
  for j in range(W):
    if grid[i][j]=="#":
      ichigo+=1
      grid[i][j]=ichigo
      L=j
      R=j
      U=i
      D=i
      while canExtendL(L,R,U,D):
        extendL(L,R,U,D,ichigo)
        L-=1
      while canExtendR(L,R,U,D):
        extendR(L,R,U,D,ichigo)
        R+=1
      while canExtendU(L,R,U,D):
        extendU(L,R,U,D,ichigo)
        U-=1
      while canExtendD(L,R,U,D):
        extendD(L,R,U,D,ichigo)
        D+=1
        
for i in range(len(grid)):
  print(*grid[i])


Measured memory_bytes: 7592
#include<iostream>
using namespace std;
int main()
    {
      int n;
	  cin>>n;
	  int a,b,c;
	  c=n%10;
	  b=(n%100)/10;
	  a=n/100;
	  if(a==1)
	     a=9;
	  else
	     a=1;
	  if(b==1)
	     b=9;
	  else
	     b=1;
	  if(c==1)
	     c=9;
	  else
	     c=1;
	  n=a*100+b*10+c;
	  cout<<n;
	  return 0;   	
    	
    	
    	
	 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
 
using namespace std;
const double PI=3.14159265358979323846;
 
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {

	int n, k;

	cin >> n >> k;

	bool sunuke[n] = {false};

	int d, hoge;
	for (int i = 0; i < k; i++) {
		cin >> d;

		for (int j = 0; j < d; j++) {
			cin >> hoge;
			sunuke[hoge - 1] = true;
		}	
	}

	int cut = 0;
	for (int i = 0; i < n; i++) {
		if (!sunuke[i]) cut++;
	}

	cout << cut << endl;
}



Measured memory_bytes: 3636
#include<iostream>
#include <string>
using namespace std;
int main()
{
	long n;
	cin >> n;
  	long ans;
  	long sum = 0;
	long a[n+2];
  	int t;
  	a[0] = 0;
  	a[n+1] = 0;
	for(t = 1;t<n+1;t++){
      cin >> a[t];
    }
  	for(t = 0;t<n+1;t++){
      sum += abs(a[t+1]-a[t]);
    }
  	for(t = 0;t<n;t++){
      ans = 0;
      ans = sum - abs(a[t+1]-a[t]) - abs(a[t+2]-a[t+1]) + abs(a[t+2]-a[t]);
      cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 2048
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int k;
	string s;
	
	cin >> s >> k;
	for(int i = 0; i < s.length() - 1; i++){
		if(s[i] == 'a') continue;
		if('z' - s[i] + 1 <= k){
			k -= 'z' - s[i] + 1;
			s[i] = 'a';
			if(k == 0){
				break;
			}
		}
	}
	if(k > 0){
		k %= 26;
		while(k-- > 0){
			if(s[s.length() - 1] < 'z'){
				s[s.length() - 1]++;
			}else{
				s[s.length() - 1] = 'a';
			}
		}
	}
	
	cout << s << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int n,a,b;
	int c,r = 0;
	scanf("%d %d %d",&n,&a,&b);
	int i,j,t;
	for(i=1;i <= n;i++){
			c = 0;
		       	t = i;
			for(j = 0;j < 5;j++){
				c += t % 10;
				t = t / 10;
			}
			if(a <= c&&c <= b)r += i;
	}
	printf("%d\n",r);
	return 0;
}


Measured memory_bytes: 128
// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace ::std;
// clang-format off
template<typename T> T nxt() {T res; cin >> res; return res;}
#define tests() for (int _ = nxt<int>(); _ >= 0; _--)
#define nxt1(t,n) t (n); cin >> n
#define nxt2(t,n,m) t (n),(m); cin >> n >> m
#define nxt3(t,n,m,k) t (n),(m),(k); cin >> n >> m >> k
#define rep(i, A) for (int i = 0 ; i < A ; i++)
#define ll long long
typedef pair<int,int> pii;typedef pair<ll, ll> pll;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<ll> vl;typedef vector<vl> vvl;
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){for(T ti : t)s<<ti<<" ";return s; }
#define all(x) (x).begin(), (x).end()
#define last(vec) vec[vec.size()-1]
#define has(c,x) ((c).find(x) != (c).end())
// clang-format on

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

    nxt2(string, s, t);

    vector<vector<pair<int, pii>>> dp(s.size() + 1, vector<pair<int, pii>>(t.size() + 1, {0, {0, 0}}));
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], make_pair(1 + dp[i][j].first, make_pair(i, j)));
            }
            dp[i + 1][j] = max(dp[i + 1][j], make_pair(dp[i][j].first, make_pair(i, j)));
            dp[i][j + 1] = max(dp[i][j + 1], make_pair(dp[i][j].first, make_pair(i, j)));
        }
    }

    pii best = {0, 0};
    for (int i = 0; i < s.size() + 1; i++) {
        for (int j = 0; j < t.size() + 1; j++) {
            if (dp[i][j].first > dp[best.first][best.second].first) {
                best = {i, j};
            }
        }
    }

    int biggest = 0;
    pii curr = best;
    string ans = "";
    while (curr != make_pair(0, 0)) {
        pii next = dp[curr.first][curr.second].second;
        if (next.first + 1 == curr.first && next.second + 1 == curr.second) {
            ans += s[next.first];
        }
        curr = next;
    }
    // if (s == "aa")
    //     for (auto i : dp) {
    //         cout << i << endl;
    //     }
    reverse(all(ans));
    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n,m;
    cin >> n >> m;
    vector<P> sc(m);
    rep(i,m)  {
        int s,c;
        cin >> s >> c;
        sc[i] = (P(s,c));
    }

    vector<int>ans(n);

    rep(i,m){
        int index = sc[i].first -1;
        if((ans[index] != 0 && ans[index] != sc[i].second)
        ||(n >= 2 && index == 0 && sc[i].second == 0)){
            //すでに値が入っているまたは先頭が0
            cout << -1 << endl;
            return 0;
        }
        ans[index] = sc[i].second;
    } 
    if(n == 1) {
        if( m == 0)  
            cout << 0 << endl;
        else
            cout << ans[0] << endl;
        return 0;
    }

    if(ans[0] == 0) {
        ans[0] = 1;
    }

    rep(i,n) cout << ans[i];
    cout  << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	string t;
	cin>>s>>t;
	int cnt=0;
	for(int i=0; i<s.size(); i++)
	{
		if(s[i]!=t[i])
		{
			cnt++;
		}
	}
	cout<<cnt;
	
	
}

Measured memory_bytes: 3740
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
import math

def resolve():
    import sys
    input = sys.stdin.readline
    a, b, k = [int(x) for x in input().rstrip().split(" ")]

    if (b - a + 1)  <= k * 2:
        print("\n".join([str(num) for num in range(a, b+1)]))
    else:
        print("\n".join([str(num) for num in range(a, a+k)]))
        print("\n".join([str(num) for num in range(b-k+1, b+1)]))



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 62140
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(input())
	x := make([]float64, n)
	y := make([]float64, n)
	for i := 0; i < n; i++ {
		x[i], _ = strconv.ParseFloat(input(), 64)
		y[i], _ = strconv.ParseFloat(input(), 64)
	}

	ans := 0.0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			dx := x[i] - x[j]
			dy := y[i] - y[j]
			dist := math.Pow(dx*dx+dy*dy, 0.5)
			ans += dist * 2 / float64(n)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
	void solve(){
		lli N,i,j,res=0,llevo=0,l1,l2,c;
		cin>>N;
		for(i=1;i<=N;i++){
			cin>>arr[i];
		}
		sort(arr+1,arr+N+1);
		l1=arr[N],c=0,l2=-1;
		arr[0]=-1;
		for(i=N;i>=0;i--){
			if(arr[i]==l1){
				c+=1;
			}
			else {
				//cout<<l1<<" "<<c<<"\n";
				if(l2==-1){
					if(c>=4){
						cout<<l1*l1;
						return;
					}
					if(c>=2){
						l2=l1;
					}
				}
				else {
					if(c>=2){
						cout<<l2*l1;
						return;
					}
				}
				l1=arr[i],c=1;
			}
		}
		cout<<res;
	}
int main(){
	cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}

Measured memory_bytes: 1024
S = input()
N = len(S)
subS1 = S[0: (N - 1) // 2]
subS2 = S[(N + 3) // 2 - 1:N]

# print(subS1, subS2)
# print(S[::-1], subS1[::-1], subS2[::-1])

if S == S[::-1] and subS1 == subS1[::-1] and subS2 == subS2[::-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060