akhauriyash/Code-Regression huggingface dataset:
def inputTable(a):
	lit=[]
	for aa in range(a):
		lit.append(list(map(int,input().split())))
	return lit
n,m,l=map(int,input().split())
A=inputTable(n)
C=[[0 for q in range(l)]for p in range(n)]
B=inputTable(m)
for a in range(n):
	for b in range(l):
		for c in range(m):
			C[a][b]+=A[a][c]*B[c][b]
for aa in range(n):
	for aaa in range(l):
		if  aaa==l-1:
			print(str(C[aa][aaa]),end='')
		else:
			print(str(C[aa][aaa])+' ',end='')
	print()


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

int main() {
	ios_base::sync_with_stdio( false );

	int A, B, C;
	cin >> A >> B >> C;

	int x = max( { A,B,C } );
	int y = A+B+C;

	if( (x & 1) == (y & 1) ) {
		cout << (3*x - y) / 2 << endl;
	}
	else {
		cout << (3*(x+1) - y) / 2 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define ll long long 
const int N = 1005;

char a[N][N];
int n,b[N][N],m;

int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			int k,l;
			k = l = j;
			while(a[i][k] == '.') k--;
			while(a[i][l] == '.') l++;
			if(k == 0 && l > m) 
				for(int p = 1; p <= m; p++)
					b[i][p] = 1;
			k=l=i;
			while(a[k][j] == '.') k--;
			while(a[l][j] == '.') l++;
			if(l > n && k == 0)
				for(int p = 1; p <= n; p++)
					b[p][j] = 1;
		}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++)
			if(b[i][j]) continue;
			else cout << a[i][j];
		int tot = 0;
		for(int j = 1; j <= m; j++) if(b[i][j] == 0) tot = 1;
		if(!tot) continue;
		else cout << endl;
	}
} 

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

vector<tuple<int,int,int,int>>v;
int ans=0;
int n,m;
void dfs(vi s){
    if(s.size()==n+1){
        int res=0;
        int a,b,c,d;
        for(auto x:v){
            tie(a,b,c,d)=x;
            if(s[b]-s[a]==c)res+=d;
        }
        chmax(ans,res);
        return ;
    }
    s.push_back(s.back());
    while(s.back()<=m){
        dfs(s);
        s.back()++;
    }
    s.pop_back();
}

int main(){
    int q;
    cin>>n>>m>>q;
    v.resize(q);
    rep(i,q){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        v[i]=tie(a,b,c,d);
    }
    vi s;
    s.push_back(1);
    dfs(s);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DMazeMaster {
public:

    int h, w;
    int p(int i, int j) {
      return i*w+j;
    }


    void solve(istream& cin, ostream& cout) {
      SPEED;
      cin >> h >> w;

      vector<vector<ll>> dp(h*w, vector<ll>(h*w, LLONG_MAX/2));

      vector<vector<bool>> mat(h, vector<bool>(w));
      rep(i, h) {
        rep(j, w) {
          char c; cin >> c;
          if (c == '.') {
            mat[i][j] = true;
          }
        }
      }

      rep(i, h) {
        rep(j, w) {
          if (mat[i][j]) {
            dp[p(i,j)][p(i,j)] = 0;
            if (i>0 && mat[i-1][j]) {
              dp[p(i,j)][p(i-1,j)] = 1;
            }
            if (i<h-1 && mat[i+1][j]) {
              dp[p(i,j)][p(i+1,j)] = 1;
            }
            if (j>0 && mat[i][j-1]) {
              dp[p(i,j)][p(i,j-1)] = 1;
            }
            if (j<w-1 && mat[i][j+1]) {
              dp[p(i,j)][p(i,j+1)] = 1;
            }
          }
        }
      }

      int n = h*w;
      rep(k, n) {
        rep(i, n) {
          rep(j, n) {
            chmin(dp[i][j], dp[i][k] + dp[k][j]);
          }
        }
      }

      ll ans = 0;

      rep(i, n) {
        rep(j, n) {
          if (dp[i][j] < LLONG_MAX/2) {
            chmax(ans, dp[i][j]);
          }
        }
      }

      cout << ans << endl;







    }
};

signed main() {
  DMazeMaster solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 1536
/* Filename: AGC002A.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

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

		while (input.hasNext()) {
			int a = input.nextInt();
			int b = input.nextInt();
			
			if(a > 0){
				System.out.println("Positive");
			} else if (b < 0){
				if((b - a + 1) % 2 == 0){
					System.out.println("Positive");
				} else {
					System.out.println("Negative");
				}
			} else {
				System.out.println("Zero");
			}
		}
	}
}


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

from collections import defaultdict
from queue import deque

def main():
  n = int(input())
  graph = defaultdict(list)
  
  def is_bt():
    def bfs():
      colors = [-1] * len(graph)
      dq = deque()
      dq.append(0)
      colors[0] = 0
      while dq:
        inode = dq.popleft()
        for ichild in graph[inode]:
          if colors[ichild] == -1:
            colors[ichild] = abs(colors[inode]-1)
            dq.append(ichild)
          else:
            if colors[ichild] == colors[inode]:
              return False
      return True
    return bfs()
  
  def wf(edges):
    dp = edges
    for k in range(len(graph)):
      for i in range(len(graph)):
        for j in range(len(graph)):
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    return dp
  
  edges = [[n+1] * n for _ in range(n)]  
  for i in range(n):
    for j, c in enumerate(input().strip()):
      if c == '1':
        graph[i].append(j)
        edges[i][j] = 1
    edges[i][i] = 0
  graph = dict(graph)
    
  if not is_bt():
    print(-1)
    return
  print(max([max(x) for x in wf(edges)]) + 1)
  
if __name__=='__main__':
  main()



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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

void solve(){
   int a,v,b,w,t;
   cin >> a >> v >> b >> w >> t;

   int ok = 0;
   int dis1 = v*t;
   int dis2 = w*t;

   if(dis1 >= dis2 + abs(a-b)) ok = 1;
   cout << (ok ? "YES" : "NO") << "\n";
}

int32_t main(){
   fast;
   int t = 1;
   //cin >> t;
   while(t--)  solve();   
}


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

int main(){
	int N,W,v_,w,m,x=0;
	scanf("%d%d",&N,&W);
	vector<pair<int,int>>v;
	for(;N--;){
		scanf("%d%d%d",&v_,&w,&m);
		for(int i=1;i<m;m-=i,i*=2)v.emplace_back(v_*i,w*i);
		if(m)v.emplace_back(v_*m,w*m);
	}
	vector<int>bag(W+1);
	bag[0]=1;
	for(auto &e:v){
		x+=e.second;
		if(x>W)x=W;
		for(int j=x;j>=e.second;j--)if(bag[j-e.second]&&bag[j]<bag[j-e.second]+e.first)
			bag[j]=bag[j-e.second]+e.first;
	}
	for(int i=0;i<W;i++)bag[i+1]=max(bag[i+1],bag[i]);
	printf("%d\n",bag[W]-1);
}

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


int main(){
	int a,b,c,x,y,z;
	while(cin>>a>>b&&a){
		c=b-a;
		z=c/1000;
		c%=1000;
		y=c/500;
		c%=500;
		x=c/100;
		cout<<x<<' '<<y<<' '<<z<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long K = sc.nextLong();
		long[] A = new long[N];
		long[] B = new long[M];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		for (int i = 0; i < M; i++) {
			B[i] = sc.nextLong();
		}
		long[] a = new long[N + 1];
		long[] b = new long[M + 1];
		a[0] = 0;
		b[0] = 0;
		for (int i = 0; i < N; i++) {
			a[i + 1] = a[i] + A[i];
		}
		for (int i = 0; i < M; i++) {
			b[i + 1] = b[i] + B[i];
		}
		int ans = 0;
		int j = M;
		for (int i = 0; i <= N; i++) {
			if (a[i] > K) {
				break;
			}
			while (b[j] > K - a[i]) {
				j--;
			}
			ans = Math.max(ans, i + j);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 64876
n=int(input())
ans=[[] for i in range(n)]
a=list(map(int,input().split()))
for i in range(n):
    ans[i].append(a[i])
    ans[i].append(i+1)
ans=sorted(ans)
x=[]
for i in range(n):
    x.append(str(ans[i][1]))

print(" ".join(x))


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

int main()
{
	ll int s,w;
	cin>>s>>w;
	if (w>=s)
	
	{
		cout<<"unsafe"<<endl;
		
	}
	else
	cout<<"safe"<<endl;
	
	
	
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;

int main()
{
  int N; cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V[i];
  vector<int> C(N);
  for (int i = 0; i < N; i++) cin >> C[i];
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (V[i] - C[i] > 0)
      sum += V[i] - C[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l = np.array(l)
ans = np.sum(l, 0)[0]
ans_s = np.sum(l, 0)
if np.any(ans_s[1:] < x):
    print(-1)
    exit()
for i in range(1, n + 1):
    for j in itertools.combinations(l, i):
        tot = np.sum(j, 0)
        if np.all(tot[1:] >= x) and tot[0] < ans:
            ans = tot[0]
print(int(ans))


Measured memory_bytes: 27336
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(ll i=0; i<n; ++i)
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define FORR(i,a,b) for (ll i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int K = 4005;
int w[K][K], b[K][K], sw[K][K], sb[K][K];

int main() {
    int n, k;
    cin >> n >> k;

    int cb = 0, cw = 0;
    REP(i,n){
        char c;
        int x, y;
        cin >> x >> y >> c;
        x %= (2*k);
        y %= (2*k);
        if (c == 'B'){
            b[x][y]++;
            b[x+2*k][y]++;
            b[x][y+2*k]++;
            b[x+2*k][y+2*k]++;
            cb++;
        }else{
            w[x][y]++;
            w[x+2*k][y]++;
            w[x][y+2*k]++;
            w[x+2*k][y+2*k]++;
            cw++;
        }
    }

    REP(i,K-1) REP(j,K-1) sb[i+1][j+1] = sb[i+1][j] + b[i][j];
    REP(j,K) REP(i,K-1) sb[i+1][j] += sb[i][j];
    REP(i,K-1) REP(j,K-1) sw[i+1][j+1] = sw[i+1][j] + w[i][j];
    REP(j,K) REP(i,K-1) sw[i+1][j] += sw[i][j];

    // REP(i,4*k){
    //     REP(j,4*k){
    //         cout << sb[i][j];
    //     }
    //     cout << endl;
    // }

    int ans = 0;

    REP(i,2*k) REP(j,2*k){
        int bl = sb[i+k][j+k] - sb[i][j+k] - sb[i+k][j] + sb[i][j]
               + sb[i+2*k][j+2*k] - sb[i+k][j+2*k] - sb[i+2*k][j+k] + sb[i+k][j+k];
        int wh = sw[i+k][j+k] - sw[i][j+k] - sw[i+k][j] + sw[i][j]
               + sw[i+2*k][j+2*k] - sw[i+k][j+2*k] - sw[i+2*k][j+k] + sw[i+k][j+k];
        int tmp = bl + cw - wh;
        // cout << bl << endl;
        ans = max(tmp, ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 250752
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
typedef long long int ll;
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EFOR(i,a,b) for (int i=(a);i<=(b);i++)
const ll MOD = (10*10*10*10*10*10*10*10*10+7);

    ll N,A,odd=0,even=0;


int main(){
    scanf("%lld",&N);
    REP(i,N){
        scanf("%lld",&A);
        A % 2 == 0
            ? even++
            : odd++;
    }
    if(odd%2==0){
        //even+=(odd/2);
        cout<<"YES";
    }else cout<<"NO";


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <tgmath.h>
#include <vector>
using namespace std;


// https://atcoder.jp/contests/arc061/tasks/arc061_a

// 入力
long S;
vector<int> sVector;

int main(){
 cin >>  S;
 while(true){
    sVector.push_back(S % 10L);
    S = S /10L;
    if(S == 0){
        break;
    }
 }
 long num = pow(2, sVector.size());
 long ans = 0;
 for(int i= 0; i< sVector.size(); i++){
    for(int j = 0; j <= i ; j ++){
        if(j == i){
            ans +=  pow(10,j) * sVector[i] * pow(2,sVector.size()-i-1);
            continue;
        }
        ans +=  pow(10,j)* pow(2,i-j-1) * sVector[i] * pow(2,sVector.size()-i-1);
    }
   
 }
 cout << ans <<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
double N;

int main() {
  INCANT;
  cin >> N;
  cout << 2*N*PI << "\n";
  return 0;
}


Measured memory_bytes: 3800
N,K = map(int,input().split())
A = list(map(int,input().split()))
x = 50
lst1 = [0]*x
lst0 = [0]*x
for i in range(x):
    for Ai in A:
        if Ai >> i & 1:
            lst1[i] += 1
        else:
            lst0[i] += 1
dp = [[0,0] for _ in range(x)] # dp[i][1]はK以下確定、dp[i][0]は非確定
dp[x-1][1] = -1
for i in range(x-1)[::-1]:
    if K >> i & 1:
        if dp[i+1][1] == -1:
            dp[i][1] = lst1[i]*(1 << i)
        else:
            dp[i][1] = max((dp[i+1][1]+lst0[i]*(1 << i)),dp[i+1][0]+lst1[i]*(1 << i))
        dp[i][0] = dp[i+1][0]+max(lst1[i],lst0[i])*(1 << i)
    else:
        if dp[i+1][1] == -1:
            dp[i][1] = -1
            dp[i][0] = dp[i+1][0]+lst1[i]*(1 << i)
        else:
            dp[i][1] = dp[i+1][1]+max(lst1[i],lst0[i])*(1 << i)
            dp[i][0] = max(dp[i+1][0]+lst1[i]*(1 << i),dp[i+1][1]+lst0[i]*(1 << i))
print(dp[0][0])

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

const double PI=3.141592653589793;

double f(double a, double b, double theta){
    if(PI/2.0 < theta){
        return 0.0;
    }
    if(a*tan(theta) <= b){
        return a*b - a*a*tan(theta)/2.0;
    }else{
        return b*b/tan(theta)/2.0;
    }
}

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

    double xa = x/a;
    double r = PI/2.0;
    double l = 0.0;
    double m;
    for(int i=0; i<10000; i++){
        m = l + (r-l)/2.0;
        if(f(a,b,m)<xa){
            r = m;
        }else{
            l = m;
        }
    }

    cout<<fixed<<setprecision(10)<<m*180/PI<<endl;

    return 0;
}

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

int main() {
  int x, y;
  cin >> x >> y;
  for (int i = 0; i < x + 1; i++) {
    if (i*2+(x-i)*4 == y) {
      cout << "Yes" << endl;
      break;
    }
    else if (i == x) {
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
ll A,B,C,D;
ll solve(ll N,map<ll,ll>&ANS){
  if(N==0)return 0;
  if(N==1)return D;
  if(ANS[N])return ANS[N];
  ANS[N]=0;
  ll res=N%2*D+A+min(solve(N/2,ANS),solve((N+1)/2,ANS));
  res=min(res,N%3*D+B+solve(N/3,ANS));
  res=min(res,(3-N%3)%3*D+B+solve((N+2)/3,ANS));
  res=min(res,N%5*D+C+solve(N/5,ANS));
  res=min(res,(5-N%5)%5*D+C+solve((N+4)/5,ANS));
  if(D==min({A,B,C,D})&&D<100000)res=min(res,D*N);
  ANS[N]=res;
  return res;
}
signed main(){
  ll T,i;cin>>T;
  REP(i,T){
    ll N;map<ll,ll>ANS;
    cin>>N>>A>>B>>C>>D;
    cout<<solve(N,ANS)<<endl;
  }
  return 0;
}

Measured memory_bytes: 4360
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/




int main() {
int N,M;
cin>>N>>M;
Graph G(N+M+1);
rep(i,N){
  int K;
  cin>>K;
  rep(j,K){
    int L;
    cin>>L;
    G[i].push_back(N+L);
    G[N+L].push_back(i);
  }
}
int seen[N+M+1];
rep(i,N+M+1){
  seen[i]=-1;
}
queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    seen[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (seen[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            seen[nv] = 1;
            que.push(nv);
        }
    }

    bool judge=true;
    rep(i,N){
      if(seen[i]==-1){
        judge=false;
      }
    }
    if(judge){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
return 0;
}

Measured memory_bytes: 12624
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define mod 998244353
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000;
#define PI 3.14159265
int main()
{
    fastio;
    string s;
    cin>>s;
    int q;
    cin>>q;
    int r = 0;
    deque<char>dq;
    for(char c : s)
        dq.pb(c);
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            r=r^1;
        }
        else
        {
            int f;
            char c;
            cin>>f>>c;
            if((f==1 && r==0) || (f==2 && r==1))
                dq.push_front(c);
            else if((f==1 && r==1) || (f==2 && r==0))
                dq.push_back(c);
        }
    }
    if(r==1)
    {
        while(!dq.empty())
        {
            cout<<dq.back();
            dq.pop_back();
        }
    }
    else
    {
        while(!dq.empty())
        {
            cout<<dq.front();
            dq.pop_front();
        }
    }
    return 0;
}


Measured memory_bytes: 976
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ull res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
int gcd(int x,int y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<int,int> x,pair<int,int> y)
{
    return x.first<y.first;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
int prime[1768457]={0};
void sieve(void)
{
 int i,j;
 for(i=0;i<1768457;i++)
        prime[i]=1;
 prime[0]=0,prime[1]=0;
 for(i=2;i<=sqrt(1768457);i++){
     if(prime[i]){
         for(j=i*i;j<1768457;j+=i){
             prime[j]=0;
         }
     }
 }
    
}
void swap(ll &x,ll &y){
    int temp=x;
    x=y;
    y=temp;
}
  
unsigned int onesComplement(unsigned int n) 
{ 
   // Find number of bits in the given integer 
   int number_of_bits = floor(log2(n))+1; 
  
   // XOR the given integer with poe(2,  
   // number_of_bits-1 and print the result  
   return ((1 << number_of_bits) - 1) ^ n; 
}


void solve()
{   
    char c;
    cin>>c;
    if(c>='A' && c<='Z')
        cout<<'A';
    else
        cout<<'a';

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}   


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin >> k;
    ll ans = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int i1 = 1; i1 <= k; i1++) {
                ans += __gcd(i, __gcd(j, i1));
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3620
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();
      if(a <= 5)System.out.println("0");
      else if(a <= 12)System.out.println(b/2);
      else System.out.println(b);
    
    }
}

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

int main()
{
string s;
int x,y=0;
cin>>x>>s;
        for(int i=0;i<x;i++)
           {
              if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C' && i!=x-2)
                y++;
           }
           cout<<y;
return 0;
}


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

using namespace std;



int main() {
    long long int x, y;
    cin >> x >> y;

    long long int m;

    m = x * y;

    if (x == 1 || y == 1) {
        cout << 1;
    } else {
        if (m % 2) {
            cout << m / 2 + 1;
        } else {
            cout << m / 2;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
const ll mod=1e9+7;



int32_t main()
{
    SPEED;
    int n;
    cin>>n;
    ll h[n+1];
    for (int i = 1; i <= n; ++i)
    {
        cin>>h[i];
    }
    int dp[n+1];
    dp[1]=0;
    dp[2]=abs(h[1]-h[2]);
    for (int i = 3; i <= n; ++i)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<endl;
}



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

int main()
{
    ll  n;// = 149696127901;
    cin >> n;
    ll ans = n / 11; //5+6 = 11
    ans *= 2;

    ll rem = n % 11;
    if (rem > 6) ans += 2;
    else if (rem) ans++;

    cout << ans << "\n";
}


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

using namespace std;

#define MOD 1000000007
typedef long long int ll;

int dp[100001]={0};
bool vis[100001]={0};
vector<int>graph[100001];

void dfs(int curr){
	if(vis[curr]){
		return;
	}
	vis[curr]=true;
	for(int i=0;i<graph[curr].size();i++){
		dfs(graph[curr][i]);
		dp[curr]=max(dp[curr],dp[graph[curr][i]]);
	}
	dp[curr]++;
}


int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
        
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		graph[x].push_back(y);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs(i);
		}
	}

	cout<<*max_element(dp+1,dp+n+1)-1<<endl;


	return 0;
}

Measured memory_bytes: 8320
#include<stdio.h>

int isprime(int n) {
  int i;
  for(i = 2; i * i <= n; i++) {
    if(n % i == 0) return 0;
  }
  return 1;
}

int main() {
  int i, n, data[10001] = {0};
  for(i = 3; i < 10000; i++) {
    data[i] = isprime(i);
  }
  while(1) {
    scanf("%d", &n);
    if(n == 0) break;
    for(i = n; i >= 3; i--) {
      if(data[i] == 1 && data[i - 2] == 1) {
        printf("%d %d\n", i - 2, i);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 644
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

using namespace std;

int main(){
    lint n, a, b;
    cin >> n >> a >> b;
    vector<lint> h(n);
    lint MAX_H = 0;
    rep(i, n){
        cin >> h[i];
        MAX_H = max(MAX_H, h[i]);
    }
    SORT_INV(h);
    lint left = 1, right = (MAX_H - 1) / b + 2, mid, ans;
    while(left < right){
        mid = (left + right) / 2;
        lint cnt1 = 0, cnt2 = 0;
        rep(i, n){
            if(h[i] > mid * b){
                cnt1 += (h[i] - mid * b - 1) / (a - b) + 1;
            }
            if(h[i] > (mid - 1) * b){
                cnt2 += (h[i] - (mid - 1) * b - 1) / (a - b) + 1;
            }
        }
        if(cnt1 <= mid && cnt2 > mid - 1){
            ans = mid;
            break;
        }else if(cnt1 <= mid){
            right = mid;
        }else{
            left = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
class Array
  def sum
    res = 0
    self.each {|x| res += x}
    res
  end
end

n, k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
h.sort! {|x,y| y<=>x}
h.shift(k)
puts h.sum


Measured memory_bytes: 17648
fn main() {
    let mut v: Vec<u8> = {
        let s = read::<String>();
        s.into_bytes()
    };
    v[0] += 1;
    println!("{}", std::str::from_utf8(&v).unwrap());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
/*
luogu AT2581
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define lowbit(x) (x&-x)

int n,k,s[200005];
int ans,c[200005];
vector<int> v;

void lsh()
{
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
}

void fix(int x,int v)
{
	for(int i=x;i<=n;i+=lowbit(i))
		c[i] += v;
}

int ask(int x)
{
	int res=0;
	for(int i=x;i>=1;i-=lowbit(i))
		res += c[i];
	return res;
}

signed main()
{
	cin>>n>>k;
	for(int i=1,x;i<=n&&cin>>x;i++)
	{
		s[i] = s[i-1]+x;
		v.push_back(s[i]-k*i);
	}
	lsh();
	fix(lower_bound(v.begin(),v.end(),0)-v.begin()+1,1);
	for(int r=1;r<=n;r++)
	{
		int u=lower_bound(v.begin(),v.end(),s[r]-k*r)-v.begin()+1;
		ans += ask(u);
		fix(u,1);
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 5104
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
  
Node root;
  
Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}
  
Node treeSearch(Node u, int k){
  if(u == NIL || u->key == k) return u;
  else if(u->key > k) return treeSearch(u->left, k);
  else if(u->key < k) return treeSearch(u->right, k);
}
  
Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
  
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  if(y->left != NIL) x = y->left;
  else x = y->right;
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  if(y != z) z->key = y->key;
}
  
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
  
}
  
void inorder(Node u){
  if(u->left != NIL) inorder(u->left);
  printf(" %d", u->key);
  if(u->right != NIL) inorder(u->right);
}
void preorder(Node u){
  printf(" %d", u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}

Measured memory_bytes: 19364
def Pre(i):
    if dali[i].node != -1:
        ret = dali[i].node
        dali[i].node = -1
        order.append(ret)
    if dali[i].left != -1:
        Pre(dali[i].left)
    if dali[i].right != -1:
        Pre(dali[i].right)
def Pre2(u):
    if u == -1:
        return 
    order.append(u)
    Pre2(dali[u].left)
    Pre2(dali[u].right)
def In(i):
    if dali2[i].left != -1:
        In(dali2[i].left)
    if dali2[i].node != -1:
        
        ret = dali2[i].node
        dali2[i].node = -1
        order.append(ret)
    if dali2[i].right != -1:
        In(dali2[i].right)
def In2(u):
    if u == -1:
        return 
    In2(dali2[u].left)
    
    order.append(u)
    In2(dali2[u].right)


def Postorder(u):
    if u == -1:
        return None
    Postorder(dali3[u].left)
    Postorder(dali3[u].right)
    order.append(dali3[u].node)
    dali3[u].node = -1



    
class BiTree():
    def __init__(self, node, left, right):
        self.node = node
        self.left = left
        self.right = right


def inputdata(i):
    node, left, right = list(map(int, input().split()))
    dali[node] = BiTree(node, left, right)
    dali2[node] = BiTree(node, left, right)
    dali3[node] = BiTree(node, left, right)
def getParent(i):
    for k in range(n):
        if(dali[k].right == dali[i].node) or (dali[k].left == dali[i].node):
            dali[i].parent = dali[k].node
            return dali[i].parent
    dali[i].parent = -1
def getParent3(i):
    for k in range(n):
        if(dali3[k].right == dali3[i].node) or (dali3[k].left == dali3[i].node):
            dali3[i].parent = dali3[k].node
            return dali3[i].parent
    dali3[i].parent = -1
# Getting Root
        

n = int(input())
dali = [0] * n
dali2 = [0] * n
dali3 = [0] * n
order = []
for i in range(n):
    inputdata(i)
    """
for i in range(n):
    Pre(dali[i].node)
"""
for i in range(n):
    for j in range(n):
        if i == dali[j].left or i == dali[j].right:
            break
    if j == n-1:
        root = i
        break


order = []
for i in range(n):
    getParent(dali2[i].node)
for i in range(n):
    getParent(dali[i].node)
for i in range(n):
    getParent3(dali3[i].node)
Pre2(root)
print("Preorder")
print(" ",end = "")
print(*order)
order = []

In2(root)
print("Inorder")
print(" ",end = "")
print(*order)

order = []
print("Postorder")
print(" ",end = "")
Postorder(root)
print(*order)









Measured memory_bytes: 5640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

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

ll count(ll x,ll y,ll z){
    return (y/z)-(x-1)/z;
}

int main(){
    ll a,b,c,d;
    ll ans=0;
    cin >> a >> b >> c >> d;
    cout << b-a+1-(count(a,b,c)+count(a,b,d)-count(a,b,lcm(c,d))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
//#define mod 1000000007

using namespace std;

bool cal(ll a, ll b) {
    cout<<a<<" "<<b<<endl;
	if (a << 1 > b) 
		return 1; 
	b >>= 1; 
	if (a << 1 > b) 
		return (b - a) & 1; 
	if (b & 1) 
		return (b - a) & 1; 
	return cal(a, b >> 1); 
}
  
 
main() {
    int n;
    cin>>n;
    int ac=0,wa=0,tle=0,re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="AC")ac++;
        else if(s=="TLE")tle++;
        else if(s=="RE")re++;
        else wa++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string n;
  cin >> n;
  rep(i, 0, n.size()) {
    if (n[i] == '1')
      cout << '9';
    else
      cout << '1';
  }
  cout << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, S):
    s1 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('0'))))
    s0 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('1'))))
    if len(s0) <= K:
        return N
    if S[0] == '0':
        s1.insert(0, 0)
    if S[-1] == '0':
        s1.append(0)
    s = []
    i = 0
    for i in range(len(s0)):
        s.append(s1[i])
        s.append(s0[i])
    s.extend(s1[i+1:])

    sa = [0]
    for v in s:
        sa.append(sa[-1]+v)
        
    ans = 0
    for i in range(0, len(sa), 2):
        if i+2*K+1 < len(sa):
            ans = max(ans, sa[i+2*K+1]-sa[i])
        elif i+2*K < len(sa):
            ans = max(ans, sa[i+2*K]-sa[i])
        else:
            break
      

    return ans


def main():
    N, K = read_int_n()
    S = read_str()
    rS = ''.join(['0' if c == '1' else '1' for c in S])
    print(max(slv(N, K, S), slv(N, K-1, rS)))

    # N = 20
    # K = random.randint(1, 10)
    # S = ''.join(random.choices('01', k=N))
    # rS = ''.join(['0' if c == '1' else '1' for c in S])
    # print(max(slv(N, K, S), slv(N, K-1, rS)))

if __name__ == '__main__':
    main()


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

int main()
{
  random_device seed_gen;
  mt19937 rnd(seed_gen());
  uniform_int_distribution<int> dist(1, 26);
  
  int D; cin >> D;
  for (int d = 1; d <= D; ++d)
  {
    cout << dist(rnd) << '\n';
  }
}


Measured memory_bytes: 3640
# include <bits/stdc++.h>
# define ll long long
# define pb push_back
# define fi first
# define se second
# define mp make_pair
using namespace std;

ll dp[3005][3005];

void getlcs(string s,string t,ll l)
{
    vector <char> lcs;
    ll i=s.size(),j=t.size();
    while(l>0)
    {
        if(s[i-1]==t[j-1])
        {
            lcs.pb(s[i-1]);
            i--; j--;
            l--;
        }
        else{
            if(dp[i-1][j]>dp[i][j-1]) i--;
            else j--;
        }
    }
    for(ll i=lcs.size()-1;i>=0;i--) cout<<lcs[i];
    cout<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    ll a=-1,b=-1,ans=0;
    map <ll,ll> m;
    for(ll i=1;i<=s.size();i++)
    {
        for(ll j=1;j<=t.size();j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
                if(m[dp[i][j]]==0)
                {
                    ans = max(ans,dp[i][j]);
                    a=i,b=j;
                    m[dp[i][j]]++;
                }
            }
            else
                {
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
        }
    }
    vector <char> v;
    if(ans==0) cout<<" "<<endl;
    else{
    getlcs(s,t,ans);
    }

}


Measured memory_bytes: 74156
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret.sorted()
}

func main() {
    let N = readInt()
    let A = readInts()
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var ma = 0
    var ans = 0
    
    for i in 0..<N {
        ma = max(ma, A[i])
        if ma > A[i] {
            ans += ma - A[i]
        }
    }
    print(ans)
}
main()


Measured memory_bytes: 26332
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
const int INF = 1001001001;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<int> uni(n);
    rep(i,m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.unite(x,y);
    }
    int ans = n;
    rep(i,n) {
        if (uf.size(i) == 1) continue;
        int x = uf.find(i);
        if (uni[x] != 0) continue;
        ans -= uf.size(x)-1;
        uni[x]++; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4048
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int dp[1010][10010];

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

	int H, N;
	cin >> H >> N;
	vector<int> A(N), B(N);
	REP(i, N) cin >> A[i] >> B[i];
	
	fill(dp[0], dp[0] + H + 1, 100000000);
	REP(i, N) {
		int h = 0;
		while (h <= H) {
			for (int b = 1;b <= B[i] && h + b <= H;++b) {
				dp[i + 1][h + b] = min(dp[i][h + b], dp[i + 1][h + b - A[i]] + B[i]);
			}
			h += B[i];
		}
	}
	cout << dp[N][H] << endl;

	return 0;
}


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

int main() {
    int n; cin >> n;
    int taro = 0, hanako = 0;
    
    for (int i = 0; i < n; ++i) {
        string s_taro, s_hanako; cin >> s_taro >> s_hanako;
        
        if (s_taro < s_hanako) hanako += 3;
        else if (s_taro == s_hanako) ++taro, ++hanako;
        else if (s_taro > s_hanako) taro += 3;
    }
    printf("%d %d\n", taro, hanako);
    
    return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
int main() {
	cin >> N;
	vector<ll>a(N);
	int minusN = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] < 0) {
			minusN++;
		}
		a[i] = abs(a[i]);
		ans += a[i];
	}
	if (minusN & 1) {
		ans -= 2 * (*min_element(a.begin(), a.end()));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

N = int(input())
S = input()[:-1]
acc = [0]*(N+1)

for i in range(N):
    acc[i+1] = acc[i]+(1 if S[i]=='W' else 0)

ans = 10**18

for i in range(N):
    ans = min(ans, acc[i]+(N-i-1-(acc[N]-acc[i+1])))

print(ans)

Measured memory_bytes: 43504