akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  ll a, b, m; cin >> a >> b >> m;
  vector<ll> ary_a(a), ary_b(b);
  rep(i, a) cin >> ary_a[i];
  rep(i, b) cin >> ary_b[i];

  ll ans = __INT_MAX__;
  for (int i = 0; i < m; i++) {
    int x, y, c; cin >> x >> y >> c;

    ans = min(ans, ary_a[x - 1] + ary_b[y - 1] - c);
  }

  sort(ary_a); sort(ary_b);
  outl(min(ans, ary_a[0] + ary_b[0]));
}

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

  solve();
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,d,w,h,i,j,k,l,m,n,x,y,z;
	ll		ans = -INFL;
	string	s;
	cin >> n >> k;
	vector<ll>	p(n+1),c(n+1),f(n+1),t,tc,tc1,tc2;
	for(i=1;i<=n;i++) cin >> p[i];
	for(i=1;i<=n;i++) cin >> c[i];

	for(i=1;i<=n;i++) {
		if (f[i]==1) continue;
		t.clear();
		j = i;
		l = m = 0;
		while(f[j]==0) {
			l++;
			f[j]=1;
			t.push_back(c[p[j]]);
			m += c[p[j]];
			j = p[j];
		}

		tc.clear();
		tc = t;
		for(x=0;x<t.size();x++) tc.push_back(t[x]);
		tc1.clear();
		tc1 = tc;
		for(j=0;j<tc.size()-1;j++) {
			tc1[j+1] = tc1[j] + tc[j+1];
		}

		if (k>l) z = l;
		else z = k;

		while(z!=0) {
			for(j=0;j<tc.size();j++) {
				if (j>=z) {
					y = tc1[j] - tc1[j-z];
					if (m>0 && (k-z)>=l) y += m*((k-z)/l);
					ans = max(ans , y);
				}
			}
			z--;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
typedef long long ll;

//nをp進数に変換
ll convert(ll n, ll p){ll y=0, i=0, z;
    while(n > 0){z = n%p;y += z*pow(10, i);n = n/p;i++;}
    return y;}

//d^k個の候補を準備。require convert
vector<string> get_zenkouho(int d,int k){
	int card = pow(d,k);
	vector<string> out;
	rep(i,card){
		int a = convert(i,d);
		int l = to_string(a).size();
		string s = to_string(a);
		rep(j,k-l){
			s = '0' + s;
		}
		out.push_back(s);
	}
	return out;
}
int main(){
	int n,a,b,c;
	cin >> n >> a >> b >> c;
	vector<int> l(n);
	rep(i,n){cin >> l[i];}
	vector<string> zenkouho = get_zenkouho(4,n);
	ll zenkouhonum = zenkouho.size();
	ll ans = -1;
	rep(k,zenkouhonum){
		string s = zenkouho[k];
		vector<ll> sum(3);
		int num0 = 0;
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		rep(i,n){
			if(s[i]=='0'){
				num0 ++;
				sum[0] += l[i];
			}
			if(s[i]=='1'){
				num1 ++;
				sum[1] += l[i];
			}
			if(s[i]=='2'){
				num2 ++;
				sum[2] += l[i];
			}
			if(s[i]=='3'){
				num3 ++;
			}
		}
		if(num0==0 || num1==0 || num2==0){
			continue;
		}
		sort(sum.begin(),sum.end());
		ll tmp_ans = abs(a-sum[2])+abs(b-sum[1])+abs(c-sum[0]) + 10*(num0+num1+num2-3);
		if(ans == -1 || tmp_ans < ans){
			ans = tmp_ans;
		}
	}	
	cout << ans;
}

Measured memory_bytes: 3832
//  Copyright © 2019 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 1000005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long ll;

const ll MOD = 998244353;
ll T;

const ll LIM = 4e5;
ll fact[LIM + 5];
ll finv[LIM + 5];

ll fastpow( ll b , ll e )
{
    ll ans = 1;
    while( e > 0 )
    {
        if( e & 1 )
            ans = ( ans * b ) % MOD;
        
        b = ( b * b ) % MOD;
        e >>= 1;
    }
    return ans;
}

ll nCk( ll n , ll k )
{
    return ( fact[n] * ( ( finv[k] * finv[n - k] ) % MOD ) ) % MOD;
}

void calcFact() {
    fact[0] = finv[0] = 1;
    for( ll i = 1; i <= LIM; i ++ )
        fact[i] = ( fact[i - 1] * i ) % MOD;
    
    finv[LIM] = fastpow( fact[LIM] , MOD - 2 );
    
    for( ll i = LIM - 1; i >= 1; i -- )
        finv[i] = ( finv[i + 1] * ( i + 1 ) ) % MOD;    
}

ll solve( ll N , ll M , ll K ) {
    if( N == K )
        return 0;
    ll ans = nCk( N , K );
    ans = ( ans * fastpow( M , N - K ) );
    return ans % MOD;
}

int main()
{
    optimiza_io
    calcFact();
    ll N, M, K;
    cin >> N >> M >> K;
    ll ans = 0;
    while( K >= 0 ) {
        ll tmp = nCk( N - 1 , K );
        tmp = ( tmp * M ) % MOD;
        tmp = ( tmp * fastpow( M - 1 , N - K - 1 ) ); 
        ans = ( ans + tmp ) % MOD;
        K--;
    }
    cout << ans; 
    return 0;  
}


Measured memory_bytes: 9928
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 処理対象個数の入力
		Scanner sc = new Scanner(System.in);
		int input_500 = sc.nextInt();
		int input_100 = sc.nextInt();
		int input_50 = sc.nextInt();
		int input_pay = sc.nextInt();
		int result = 0;
		sc.close();

		for(int i=0;i<=input_500;i++) {
			for(int j=0;j<=input_100;j++) {
				for(int k=0;k<=input_50;k++) {
					if(i*500+j*100+k*50 == input_pay) {
						result++;
					}
				}
			}
		}

		// 出力
		System.out.println(result);

	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int N; cin >> N;
  vec a(3*N); rep(i,3*N) cin >> a[i];
  sort(ALL(a), greater<int>());

  ll res = 0;
  rep(i, N) {
    res+=a[i*2+1];
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
 string a,b,c;
 cin >> a >> b >> c;
 int acnt=a.size()-1,bcnt=b.size(),ccnt=c.size(),i=0,j=0,k=0;
 char ans = a[0];
 while (acnt >= 0 && bcnt >= 0 && ccnt >= 0) {
   if (ans=='a'){
      acnt--;
      i++;
      ans = a[i];
   }
   if (ans=='b'){
     bcnt--;
     ans = b[j];
     j++;
   }
   if (ans=='c'){
     ccnt--;
     ans = c[k];
     k++;
   }
 }
 if (acnt < 0) cout << 'A' << endl;
 if (bcnt < 0) cout << 'B' << endl;
 if (ccnt < 0) cout << 'C' << endl;

}


Measured memory_bytes: 3620
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int H = sc.nextInt();
		
		NodeCBT[] nod = new NodeCBT[H+1];
		for(int i=1; i<=H; i++) {
			int key = sc.nextInt();
			nod[i] = new NodeCBT(i, key, H);
		}
		
		StringBuilder ans = new StringBuilder();
		for(int i=1; i<=H; i++) {
			ans.append("node ");
			ans.append(nod[i].id);
			ans.append(": key = ");
			ans.append(nod[i].key);
			ans.append(", ");
			if(nod[i].parent != -1) {
				ans.append("parent key = ");
				ans.append(nod[nod[i].parent].key);
				ans.append(", ");
			}
			if(nod[i].left != -1) {
				ans.append("left key = ");
				ans.append(nod[nod[i].left].key);
				ans.append(", ");
			}
			if(nod[i].right != -1) {
				ans.append("right key = ");
				ans.append(nod[nod[i].right].key);
				ans.append(", ");
			}
			ans.append("\n");
		}
		System.out.print(ans);
	}
	
	static class NodeCBT {
		int id;
		int key;
		int parent;
		int left;
		int right;
		
		NodeCBT(int id, int key, int H) {
			this.id = id;
			this.key = key;
			if(id != 1) {
				parent = id / 2;
			} else {
				parent = -1;
			}
			if(2 * id <= H) {
				left = 2 * id;
			} else {
				left = -1;
			}
			if(2 * id + 1 <= H) {
				right = 2 * id + 1;
			} else {
				right = -1;
			}
			
		}
	} 

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

Measured memory_bytes: 24448
#include <iostream>
#include <cmath>

typedef long long ll;

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

  int max_digits = std::to_string(n).length();
  int min_digits = max_digits;
  int max_bound = pow(10, (max_digits+1)/2+1);
  for (ll i = 1; i < max_bound; i++) {
    ll quotient = n / i;
    ll remainder = n % i;
    if (remainder == 0) {
      int tmp = std::max(std::to_string(i).length(), std::to_string(quotient).length());
      min_digits = std::min(tmp, min_digits);
    }
  }
  std::cout << min_digits << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define setbit(x,k) (x |= (1 << k))
#define clearbit(x,k) (x &= ~(1ll << k))
#define checkbit(x,k) (x & (1ll << k))
#define mp make_pair
#define scl(x) scanf("%lld",&x)
#define sci(x) scanf("%d",&x)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define pii pair<int,int> 
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
#define nn printf("\n") 
#define mod 1000000007
using namespace std;

string s[10000];
ll h,w;
ll dp[1005][1005];

ll solve(int r, int c)
{
    if(r==h-1 && c == w-1) return 1;
    if(dp[r][c]!=-1) return dp[r][c];

    ll res = 0;
    if(r+1<h && s[r+1][c]!='#') res += solve(r+1, c);
    if(c+1<w && s[r][c+1]!='#') res += solve(r, c+1);
    return dp[r][c] = res%mod;
}

int main()
{
    memset(dp, -1, sizeof(dp));
    cin>>h>>w;
    for(int i=0; i<h; i++) cin>>s[i];
    cout<<solve(0,0); nn;

}

Measured memory_bytes: 13748
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

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

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
        int k = sc.nextInt();
        sc.close();
        int ans = 1;
        for(int i = 0; i < n; i++){
            ans = Math.min(ans * 2, ans + k);
        }
		
        out.println(ans);
        out.flush();
	}
}

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

long long N, K, X[100], Y[100], minx = (1LL << 62);
vector<long long>AX, AY;

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i];
		AX.push_back(X[i]);
		AY.push_back(Y[i]);
	}
	sort(AX.begin(), AX.end());
	sort(AY.begin(), AY.end());
	for (int i = 0; i < AX.size(); i++) {
		for (int j = i; j < AX.size(); j++) {
			for (int k = 0; k < AY.size(); k++) {
				for (int l = k; l < AY.size(); l++) {
					int cnt = 0;
					for (int m = 1; m <= N; m++) {
						if (AX[i] <= X[m] && X[m] <= AX[j] && AY[k] <= Y[m] && Y[m] <= AY[l]) cnt++;
					}
					if (cnt >= K) minx = min(minx, (AX[j] - AX[i])*(AY[l] - AY[k]));
				}
			}
		}
	}
	cout << minx << endl;
	return 0;
}

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

int main() {
    string a, b, c;  cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

#ifdef _XCODE_DEBUG
    #include <fstream>
#endif

int main() {
    #ifdef _XCODE_DEBUG
        std::ifstream in("input.txt");
        std::cin.rdbuf(in.rdbuf());
    #endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    // input data
    int N, M;
    std::string s, t;
    std::map<std::string, int> bmp, rmp;
    std::cin >> N;
    for (int i=0; i<N; ++i) {
        std::cin >> s;
        if (bmp.find(s) == bmp.end()) bmp[s]=1;
        else bmp[s]+=1;
    }
    std::cin >> M;
    for (int i=0; i<M; ++i) {
        std::cin >> t;
        if (rmp.find(t) == rmp.end()) rmp[t]=1;
        else rmp[t]+=1;
    }
    
    // find a max value
    int ans=0;
    for (auto iter=bmp.begin(); iter!=bmp.end(); ++iter) {
        std::string key=iter->first;
        int bval = iter->second;
        if (rmp.find(key)!=bmp.end()) {
            if (bval-rmp[key] > ans) ans=bval-rmp[key];
        }
        else {
            if (bval > ans) ans=bval;
        }
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        s: String,
    };

    let mut ans = 0;

    for merge in 0..2usize.pow(s.len().saturating_sub(1) as u32) {
        let mut num_string = String::new();
        for i in 0..s.len() {
            num_string.push(s.chars().nth(i).unwrap());
            if merge & 2usize.pow(i as u32) == 0 {
                // println!("{} {:?}", merge, num_string);
                ans += num_string.parse::<u64>().unwrap_or(0);
                num_string = "".to_string();
            }
        }
        ans += num_string.parse::<u64>().unwrap_or(0);
    }

    println!("{}", ans);
}


Measured memory_bytes: 2204
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

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

  int sum = 0;
  long long weight = 0;

  long long w[N]; int v[N];
  for (int i = 0; i < N; i++){
    cin >> w[i] >> v[i];
    weight += w[i];
    sum += v[i];
  }

  long long DP[N + 1][sum + 1];
  for (int j = 0; j < sum + 1; j++){
    DP[N][j] = weight;
  }
  
  for (int i = N - 1; i >= 0; i--){
    for (int j = sum; j >= 0; j--){
      if (j + v[i] > sum){
        DP[i][j] = DP[i + 1][j];
      }else{
        DP[i][j] = min(DP[i + 1][j], DP[i + 1][j + v[i]] - w[i]);
      }
    }
  }
  
  for (int j = sum; j >= 0; j--){
    if(DP[0][j] <= W){
      cout << j << endl;
      break;
    }
  }
  

  

  return 0;
}


Measured memory_bytes: 79104
line = input().rstrip().split(' ')
n = int(line[0])
m = int(line[1])

line = input().rstrip().split(' ')
a = [0] * n
total = 0
for i in range(n):
    a[i] = int(line[i])
    total += a[i]

list.sort(a, reverse=True)
b = total / (4 * m)

ans = 'Yes'
for i in range(m):
    if a[i] < b:
        ans = 'No'

print(ans)

Measured memory_bytes: 3064
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, M;
vector<int> e[200000];

bool vis[200000] ={};
int dfs(int n){
    vis[n] = true;
    int ret = 1;
    rep(i, e[n].size()){
        if(!vis[e[n][i]]){
            ret += dfs(e[n][i]);
        }
    }
    return ret;
}

signed main(){
    cin >> N >> M;
    rep(i, M){
        int A, B;
        cin >> A >> B;
        e[A-1].pb(B-1);
        e[B-1].pb(A-1);
    }

    int ans = 0;
    rep(i, N){
        if(!vis[i]){
            ans = max(ans, dfs(i));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 24092
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
int a[MAXN], dp[MAXN][2];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> a[i];

    return true;
}

void solve() {
    dp[0][0] = dp[0][1] = 1;

    for (int i = 1; i < n; ++i) {
        if (a[i - 1] >= a[i])
            dp[i][0] = dp[i - 1][0];
        else
            dp[i][0] = dp[i - 1][0] + 1;

        if (a[i - 1] <= a[i])
            dp[i][1] = dp[i - 1][1];
        else
            dp[i][1] = dp[i - 1][1] + 1;

        dp[i][0] = min(dp[i][0], dp[i - 1][1] + 1);
        dp[i][1] = min(dp[i][1], dp[i - 1][0] + 1);
    }

    cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 5120
import java.util.Scanner;

class Main{

	public static void main(String[] args) {


		int[][] data = {{1,11},{5,3}};
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int min = Integer.MAX_VALUE;
		int[] cost = new int[6];
		cost[0] =Math.abs(A - B)+Math.abs(C - B); 
		cost[1] =Math.abs(A - C)+Math.abs(C - B);  
		cost[2] =Math.abs(B - A)+Math.abs(A - C);  
		cost[3] =Math.abs(B - C)+Math.abs(C - A);  
		cost[4] =Math.abs(C - A)+Math.abs(A - B);  
		cost[5] =Math.abs(C - B)+Math.abs(B - A);  

		for(int i= 0;i < 6;i++){
			min = Math.min(min, cost[i]);
		}
		System.out.println(min);





		//		String S = scan.next();

		//		int[] data = new int[N];
		//		for(int i= 0; i < N ;i++){
		//			data[i] = scan.nextInt();
		//		}
		//
		//		int[][] mat = new int[N][N];
		//		int[][] xor = new int[N][N];
		//
		//		for(int i = 0;i < N;i++){
		//			mat[i][i] = data[i];
		//			for(int j = i; j < N-1;j++){
		//				mat[i][j+1] = mat[i][j]+ data[j+1];
		//
		//			}	
		//		}
		//		
		//		for(int i =0 ; i<N;i++){
		//			for(int j = 0;j < N;j++){
		//			System.out.print(mat[i][j]);
		//			System.out.print(" ");
		//
		//			}
		//			System.out.println();
		//
		//		}
		//		
		//
		//		for(int i = 0;i < N;i++){
		//			xor[i][i] = data[i];
		//			for(int j = i; j < N-1;j++){
		//				xor[i][j+1] +=xor[i][j] ^ data[j];
		//
		//			}	
		//		}
		//		
		//		for(int i =0 ; i<N;i++){
		//			for(int j = 0;j < N;j++){
		//			System.out.print(mat[i][j]);
		//			System.out.print(" ");
		//
		//			}
		//			System.out.println();
		//
		//		}
		//
		//		int count = 0;
		//		for(int i= 0;i < N;i++){
		//			for(int j = i;j < N;j++){
		//				if(xor[i][j] == mat[i][j]&&mat[i][j] != 0 ){
		//					count++;
		//				}
		//			}
		//		}
		//		System.out.println(count);
		//
		//


	}
}








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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;   
typedef pair<P,P> PP;

//-----------------------------------------------------------------------------

int a, b, k;

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

	set<int> st;
	cin >> a >> b >> k;
	for (int i = 0; i < k; i++) {
		if (a + i <= b) st.insert(a + i);
		if (b - i >= a) st.insert(b - i);
	}
	for (auto x : st) cout << x << endl;

    return 0;
}


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

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

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

ll dp[110][100010];

int main() {
  int N, W;
  cin >> N >> W;
  ll w[N+1], v[N+1];
  for (int i = 1; i <= N; i++) scanf("%lld %lld", w + i, v + i);

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= W; j++) {
      if (w[i] > j) dp[i][j] = dp[i-1][j];
      else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 79360
#include "bits/stdc++.h"
 
using namespace std;
 
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define rep(i, x, n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define trav(a, x) for(auto& a: x)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define MOD 1000000007
#define endl '\n'
#define MAX 100002
#define pii pair<int, int>
#define pll pair<long long, long long>


typedef long long int ll;
typedef unsigned long long ull;
typedef vector<int> vec;

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

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
const long long INF =10000000000000;
typedef long long ll;

int main() {
   ll N;
  cin >> N;
  vector<tuple<ll,ll,ll>> t1(5);
  for(int i = 0;i<5;i++){
   cin >> get<0>(t1[i]);
   get<1>(t1[i]) = i+1;
   get<2>(t1[i]) = i;
   }

  vector<tuple<ll,ll,ll>> t2(5);
  t2 = t1;
  
  sort(t1.begin(),t1.end());
  ll min = get<1>(t1[0]);//min都市のスタートする都市number
  ll hmin = get<0>(t1[0]);//最小移動人数

  ll c = get<2>(t1[0]);//min都市の添え字

  
  vector<tuple<ll,ll,ll>> t3;
  
  ll k = 0;
  if(c >=1){
  for(int i = 0;i<c;i++){
    t3.push_back(t2[i]);
  }
  sort(t3.begin(),t3.end());
  ll min2 = get<0>(t3[0]);//min都市以前の最小移動人数

  
  k = min-1 + (N+min2-1)/min2 -1;//min都市以前に人がいなくなるまでの時間
  }
 
  ll x = N-(k-(min-1))*get<0>(t1[0]);//k分後min都市にいる人数
  ll ans = k + (6-min) + (x+get<0>(t1[0])-1)/get<0>(t1[0]) -1;
  cout << ans << endl;
  
  
}

Measured memory_bytes: 256
#!/usr/bin/env python3

YES = "YES"  # type: str
NO = "NO"  # type: str


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    a = input()
    b = input()
    if a == b[::-1]:
        print(YES)
    else:
        print(NO)
    # Failed to predict input format
    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll i,j;
    ll a[10][10];
    ll b,c;
    for(i=0;i<=9;i++){
        for(j=0;j<=9;j++){
            a[i][j]=0;
        }
    }
    for(i=1;i<=N;i++){
        b= to_string(i).front() - '0';
        c= i%10;
        ++a[b][c];
    }
    ll ans=0;
    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            ans+=a[i][j]*a[j][i];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<int>P(N);
	rep(i, N) {
		cin >> P[i];
	}
	int cnt = 0;
	for (int i = 1; i < N - 1; i++) {
		if ((P[i - 1] < P[i] && P[i] < P[i + 1]) || (P[i - 1] > P[i] && P[i] > P[i + 1])) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{  

	int a ,b,c;
	cin>> a >> b>> c;
 
	if((b-a)==(c-b))
	{
		cout<<"YES"<<"\n";
 
	}
	else
	{
		cout<<"NO"<<"\n";
	}
}

Measured memory_bytes: 3640
/* 
  		!!~~~~~~~~~~~~~~~~~~     
  	#include < ~_~ Ajay > 
 	 	~~~~~~~~~~~~~~~~~~~~!!   
*/

#include<iostream>
#include<map>
#include<list>
#include<queue>
#include<vector>
#include<algorithm>
#include<climits>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define ll long long
#define f   first
#define s   second    
#define vll    vector<ll> 
#define vpll   vector<pair<ll,ll> >
#define vpii   vector<pair<int,int> >
#define varr   vector<int> v[1000000]
#define mii    map<int,int>
#define msi    map<string,int>
#define mlist  map<int,list>

#define wloop   int t\
               ;cin>>t\
               ;while(t--)
#define forxNi(x,n) for(int i=x;i<n;i++)
#define forxNj(x,n) for(int j=x;j<n;j++)
#define forNxi(n,x) for(int i=n;i>=x;i--)
#define forNxj(n,x) for(int j=n;j>=x;j--)

#define fastio ios_base::sync_with_stdio(0)\
               ;cin.tie(0)\
               ;cout.tie(0)

//------Code begins--->

int dp[101][100005];

int solve(int wt[],int val[],int w,int i,int n){
	if(i>n or w==0)return 0;

	if(dp[i][w]!=-1)return dp[i][w];

	if(wt[i]<=w){
		return dp[i][w]=max(val[i]+solve(wt,val,w-wt[i],i+1,n),solve(wt,val,w,i+1,n));
	}
	else {
		return dp[i][w]=solve(wt,val,w,i+1,n);
	}
}

int32_t  main(){
	fastio;
	int n,w;
	cin>>n>>w;
	int wt[n+1],val[n+1];
	forxNi(1,n+1){
		cin>>wt[i]>>val[i];
	}
	forxNi(0,n+1){
		forxNj(0,w+1){
			dp[i][j]=-1;
		}
	}
	solve(wt,val,w,1,n);
	int maxim=LLONG_MIN;
	forxNi(0,n+1){
		forxNj(0,w+1){
			if(dp[i][j]>maxim)maxim=dp[i][j];
		}
	}
	cout<<maxim;
	cout<<'\n';
	
	return 0;
}

Measured memory_bytes: 82464
N = int(input())
S = input()

whites = [0]
blacks = [0]

for i in range(N):
	whites.append(whites[-1] + ('.' == S[i]))
	blacks.append(blacks[-1] + ('#' == S[i]))

min_count = blacks[0] + (whites[N] - whites[0])

for i in range(1, N+1):
	min_count = min(min_count, blacks[i] + (whites[N] - whites[i]))

print(min_count)


Measured memory_bytes: 19412
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
  int N, a, b;
  cin >> N;
  map<pair<int, int>, int> counts;
  vector<pair<int, int>> points;
  for (int i=0; i<N; i++){
    cin >> a >> b;
    points.emplace_back(pair<int, int>(a, b));
  }
  for (int i=0; i<N; i++){
    for (int j=0; j<N; j++){
      if (i == j) continue;
	  int p = points[i].first - points[j].first;
      int q = points[i].second - points[j].second;
      pair<int, int> tmp(p, q);
      counts[tmp] = counts[tmp] + 1;
    }
  }
  int max_pq = -1;
  for (auto element : counts){
    max_pq = max(max_pq, element.second);
  }
  if (N == 1){
    cout << 1 << endl;
  }
  else{
  	cout << N - max_pq << endl;
  }
  return 0;
}

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

using namespace std;

int main(void) {
    int N;
    cin >> N;

    vector<int> p(N);
    vector<bool> b(N+1);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
        b[i] = (p[i] == i+1);
    }
    b[N] = false;

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (b[i] == true && b[i+1] == true) {
            ans++;
            ++i;
        } else {
            if (b[i] == true) {
                ans++;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

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

bool comp(const int& e1, const int& e2) {
  return e1 > e2;
}

int main() {
  int n, k, i;
  vector<int> h;
  cin >> n >> k;
  for(i=0; i<n; i++){
    int tmp;
    cin >> tmp;
    h.push_back(tmp);
  }
  sort(h.begin(), h.end(), comp);
  int min = 10000000000;

  for(i=0; i<=n-k; i++){
    int hmax = h[i], hmin = h[i+k-1];
    if(min > (hmax - hmin)){
      min = hmax - hmin;
    }
  }
  cout << min << endl;
}

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

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

int N,M,Q;
vector<int>a,b,c,d;
int ans = 0;

void dfs(vector<int>A){
    if(A.size() == N+1){
        int score = 0;
        rep(i,Q){
          if(A[b[i]]-A[a[i]] == c[i]) score += d[i];
        }

        ans = max(ans,score);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= M){
      dfs(A);
      A.back()++;
    }

}


int main(){
  cin>>N>>M>>Q;
  a=b=c=d=vector<int>(Q);

  rep(i,Q){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
  }
dfs(vector<int>(1,1));
cout<<ans;
}


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

#define ll long long

const int maxn = 1e5 + 500;
ll dp[2][maxn]; //dp[0][i]表示正向走到i点获得的最大能量，dp[1][i]为反向...
ll g[2][maxn];  //g[0][i]表示正向走到i点回到x=0位置所拥有的能量，g[1][i]反之...
ll x[maxn], v[maxn];
ll n, c, sum;

int main()
{
	cin >> n >> c;
	for (int i = 1; i <= n; i++)
    {
        cin >> x[i] >> v[i];
    }

    //正向遍历
	for (int i = 1; i <= n; i++)
    {
		sum += v[i];
		dp[0][i] = max(dp[0][i - 1], sum - x[i]);
		g[0][i] = sum - 2 * x[i];
	}

	sum = 0;
	//反向遍历
	for (int i = n; i >= 1; i--)
    {
		sum += v[i];
		dp[1][i] = max(dp[1][i + 1], sum - (c - x[i]));
		g[1][i] = sum - 2 * (c - x[i]);
	}

	ll ans = max(dp[0][n], dp[1][1]);

	for (int i = 1; i <= n; i++)
    {
		ans = max(ans, g[0][i] + dp[1][i + 1]);
		ans = max(ans, g[1][i] + dp[0][i - 1]);
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#define MOD (1000000007LL)

using namespace std;
typedef long long ll;

int N;

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  cin >> N;
  printf("%lld\n", (modpow(10, N) - 2 * modpow(9, N) + modpow(8, N) + 2 * MOD) % MOD);
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,a;
	while(cin>>n>>m>>a,n){
		int ans[200];
		a--;
		for(int i = 0;i < n;i++)ans[i] = i;
		int h[1200],p[1200],q[1200];
		for(int i = 0;i < m;i++){
			cin>>h[i]>>p[i]>>q[i];
			h[i]--,p[i]--,q[i]--;
		}
		for(int i = 0;i < m;i++){
			for(int j = i+1;j < m;j++){
				if(h[i]<h[j]){
					swap(h[i],h[j]);
					swap(p[i],p[j]);
					swap(q[i],q[j]);
				}
			}
		}
		for(int i = 0;i < m;i++){
			swap(ans[p[i]],ans[q[i]]);
		}
		for(int i = 0;i < n;i++){
			if(ans[i] == a){
				cout<<i+1<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1172
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int w = sc.nextInt();
			if (n == 0 && w == 0)
				break;
			int[] app = new int[11];
			for (int i = 0; i < 11; i++)
				app[i] = 0;
			int hh = 0;
			int ww = 0;
			for (int i = 0; i < n; i++) {
				int v = sc.nextInt();
				app[v / w]++;
				hh = Math.max(hh, app[v / w]);
				ww = Math.max(ww, v / w);
			}
			double result = 0;
			for (int i = 0; i < ww; i++) {
				result += (double) app[i] / (double) hh * (double) (ww - i)
						/ (double) ww;
			}
			result += 0.01;
			System.out.println(result);
		}
		sc.close();
	}
}

Measured memory_bytes: 23644
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {

	if sc.Scan() {
		tmp := strings.Split(sc.Text(), " ")
		a, _ := strconv.Atoi(tmp[0])
		b, _ := strconv.Atoi(tmp[1])
		c, _ := strconv.Atoi(tmp[2])

		d := []int{a, b, c}

		sort.Sort(sort.IntSlice(d))

		fmt.Printf("%d %d %d\n", d[0], d[1], d[2])

	}
}



Measured memory_bytes: 1140
import java.util.*;
import java.io.*;

public class Main {	
	private static void solve(){
		//Implement solution here.
		long N = nl();
		long result = 0;
		long i = 0;
		while(i + 1 <= N) {
			i++;			
			long h = i;
			while(h / 10 > 0)h /= 10;

			long b = i % 10;			
			if(b == 0)continue;
			if(h == b)result++;
			for(int j = 1; j < 6; j++) {
				if(b * longPow(j) + h > N)continue;
				if((b + 1) * longPow(j) + h <= N) {
					result += longPow(j - 1);					
				} else {
					long tmp = b * longPow(j) + h;
					if(tmp <= N)result++;
					while(tmp + 10 <= N) {						
						result++;
						tmp += 10;
					}
				}
			}
		}
		System.out.println(result);
	}

	static long longPow(int i) {
		return (long)Math.pow(10, i);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 23124
w, h, x, y = map(int, input().split())
ans1 = w*h/2
if w % 2 != 0 or h % 2 != 0:
    print(ans1, 0)
elif x == w//2 and y == h//2:
    print(ans1, 1)
else:
    print(ans1, 0)

Measured memory_bytes: 61932
while True:
    H, W = map(lambda x: int(x), input().split(" "))
    if (H, W) == (0, 0):
        break
    for y in range(H):
        for x in range(W):
            if y == 0 or y == H - 1 or x == 0 or x == W - 1:
                print("#", end="")
            else:
                print(".", end="")
        print("")
    print("")



Measured memory_bytes: 7016
#[allow(unused_imports)]
use std::collections::HashSet;

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

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


fn main() {
    let nm = read_vec::<usize>();
    let n = nm[0];
    let m = nm[1];

    let mut bitsv : Vec<u32> = Vec::with_capacity(m);
    for _i in 0..m {
        let kss = read_vec::<usize>();
        let k = kss[0];
        let mut bits : u32 = 0;
        for j in 1..k+1 {
            let s = kss[j] as u32;
            bits = bits | (1 << (s-1));
        }
        bitsv.push(bits);
    }

    let ps = read_vec::<u32>();

    let num = solve_bits(m, n, &bitsv, &ps);

    println!("{}", num);
}

fn solve_bits(m: usize, n: usize, bitsv: &[u32], ps: &[u32]) -> u32 {
    let mut total : u32 = 0;
    for x in 0..1<<n {
        let mut tsuku : bool = true;
        for i in 0..m {
            let turned_ons = x & bitsv[i];
            let c_one = count_1(turned_ons);
            if c_one % 2 != ps[i] {
                tsuku = false;
                break;
            }
        }
        if tsuku {
            total += 1;
        }

    }
    return total;
}

fn count_1(x : u32) -> u32 {
    let mut xx = x;
    let mut c : u32 = 0;
    while  xx > 0 {
        if xx & 1 > 0 {
            c += 1;
        }
        xx = xx >> 1;
    }
    return c;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=5005;
int n,mod;
int dp[maxn][maxn];

int main(){
	scanf("%d%d",&n,&mod);
	dp[0][0]=1;
	rep(i,(n-1)/2)rep(j,n+1){
		int cur=dp[i][j];
		if(!cur)continue;
		rep(k,(n-j)/(i+2)+1){
			int coef=k+1;
			if((n&1)&&(i+1)==(n-1)/2)coef=1;
			dp[i+1][j+k*(i+2)]+=1LL*cur*coef%mod;
			if(dp[i+1][j+k*(i+2)]>=mod)dp[i+1][j+k*(i+2)]-=mod;
		}
	}
	int ans=0;
	rep(i,n+1)rep(j,n-i+1){
		ans+=1LL*dp[(n-1)/2][j]*(n-i-j)%mod;
		if(ans>=mod)ans-=mod;
	}
	printf("%d\n",ans);
	return 0;
}

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

typedef long long ll;

int main() {
    int N, K, ans = 1e9;
    cin >> N >> K;
    vector<int> x(N);
    rep(i, N) cin >> x[i];
    rep(i, N - K + 1) {
        int j = i + K - 1;
        ans = min({ans, abs(x[i]) + x[j] - x[i], abs(x[j]) + x[j] - x[i]});
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
template<typename T> T gcd(T a,T b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
string s, f = "`abcdefghijklmnopqrstuvwxyz";
si a;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  s.pb('`');
  FOR(i, 0, 27) a.insert(i);
  int l = sz(s);
  FOR(i, 0, l) a.erase(s[i] - '`');
  FORR(i, l-1, 0){
    a.insert(s[i] - '`');
    if(a.upper_bound(s[i] - '`') != a.end()){
      FOR(j, 0, i) cout << s[j];
      cout << f[*a.upper_bound(s[i] - '`')] << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

#define int long long
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int N=1e5+5;
 

 
int32_t main()
{
	IOS;
	int cnt = 0;
	string V1;
	string V2;
    cin>>V1>>V2;
	for(int i=0; i<3; i++){
	    if(V1[i]==V2[i])
	        cnt++; }
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
 int   s;long double s0;
cin>>s;
s0=s;
int a=sqrt(s0);
while(a*a<s)a++;
if(a<a*a-s){
  cout<<0<<' '<<0<<' '<<a<<' '<<1<<' '<<a*a-a-s<<' '<<a-1;
}else  cout<<0<<' '<<0<<' '<<a<<' '<<1<<' '<<a*a-s<<' '<<a;
return 0;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,k,i=1,m=1;
  double ans=0,P=1;
  cin >> n >> k;
  for(i=1;i<=n;i++){
    P=(double)1/n;
    for(m=i;m<k;){
      P=P/2;
      m=m*2;
    }
    ans=ans+P;
  }
  printf("%.10lf",ans);
  return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(long long  i = 0; i < n; i++)
#define rep2(i,a,n) for(long long  i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

using namespace std;

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

    rep2(x, 0, N+1) {
        rep2(y, 0, N+1) {
            if((x+y) > N) { continue; }
            ll z = N - (x+y);
            //printf("%ld,%ld,%ld,%ld\n", x, y, z, x*10000+y*5000+z*1000);
            if(((x+y+z) == N) && ((x*10000 + y*5000 + z*1000) == Y)) { 
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }   
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}
    



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

# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x): # 0-indexedで[i]にxを足す
        # assert i > 0
        newi=i+1
        self.el[newi] += x
        while newi <= self.n:
            self.data[newi] += x
            newi += newi & -newi
    def get(self, i, j=None): # [i,j)の部分和
        if j is None:
            i-=1
            return self.el[i]
        return self.sum(j) - self.sum(i)

n,q=map(int,input().split())
*a,=map(int,input().split())
bit=BIT(n) # BITによる配列を作成
for i in range(n):
    bit.add(i, a[i])
for i in range(q):
    t,x,y=map(int,input().split())
    if t==0:
        bit.add(x, y)
    else:
        print(bit.get(x, y))

Measured memory_bytes: 145148
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()

    return 48 - n



print(main())




Measured memory_bytes: 7748
import java.util.Scanner;

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

  private static void solve(int N) {
    int digit[] = new int[6];
    int ans = 0;
    digit[0] = N % 10;
    digit[1] = N / 10 % 10;
    digit[2] = N / 100 % 10;
    digit[3] = N / 1000 % 10;
    digit[4] = N / 10000 % 10;
    digit[5] = N / 100000 % 10;
    
    for (int i=0; i<6; i++) {
      ans += digit[i];
    }
    
    if (ans == 1) {
      ans = 10;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23892