akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e5 + 5;

int n,w[105],v[105],W;

long long dp[N];

int main(){
     cin >> n >> W;
     for(int i = 1; i <= n; i++){
     	cin >> w[i] >> v[i];
     }
     /// dp[i] -> the maximum total value of items with total weight exactly i
     for(int i = 1; i <= n; i++){
     	for(int weight_already = W - w[i]; weight_already >= 0; weight_already--){
     		dp[weight_already + w[i]] = max(dp[weight_already + w[i]],dp[weight_already] + v[i]);
     	}
     }
     long long ans = 0;
     for(int i = 0; i <= W; i++){
     	ans = max(ans,dp[i]);
     }
     cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10;
int n,m,col[N],cnt[2],tot,flag; long long res;
vector<int> g[N];
inline void add(int a,int b){g[a].push_back(b),g[b].push_back(a);}
void dfs(int x,int co){
	col[x]=co; cnt[co]++;
	for(int to:g[x]){
		tot++;
		if(col[to]==-1)	dfs(to,co^1);
		else if(col[to]==co)	flag=1;
	}
}
signed main(){
	cin>>n>>m; memset(col,-1,sizeof col);
	for(int i=1,a,b;i<=m;i++)	scanf("%d %d",&a,&b),add(a,b);
	for(int i=1;i<=n;i++)	if(col[i]==-1){
		tot=cnt[0]=cnt[1]=flag=0; dfs(i,1); tot/=2;
		if(flag)	res+=1LL*(cnt[0]+cnt[1])*(cnt[0]+cnt[1]-1)/2-tot;
		else	res+=1LL*cnt[0]*cnt[1]-tot;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 10308
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var m     = int.Parse(spl[1]);

        return Combination(n,2) + Combination(m,2);
    }

    static long Combination(long m, long n) {
        if (m == n || n == 0) return 1;

        long ans = 1;
        for (long i = 1; i <= n; i++) {
            ans = ans * (m - i + 1) / i;
        }
        return ans;
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
#include<string.h>
int main()
{
	char a[101];
	int x,k,i;
	scanf("%d",&k);
	scanf("%s",a);
	x=strlen(a);
	if(x<=k){
		printf("%s\n",a);
	}
	else {
		for(i=0;i<k;i++){
			printf("%c",a[i]);
		}
		printf("...\n");
	}
	return 0;
}

Measured memory_bytes: 1620
data1 = input()
data2 = input()
circle = int(data1.split()[0])
house = int(data1.split()[1])
distance = [int(s) for s in data2.split()]
#隣接間の最大距離を省いてみる
between = []
for i,d in enumerate(distance):
  if i != house-1:
    between.append(distance[i+1]-d)
  else:
    between.append(circle-d+distance[0])
print(sum(between)-max(between))

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

int main() {
  cin >> k;
  queue<long long> que;
  for (int i = 1; i < 10; i++ ) {
    que.push(i);
  }
  for (int i = 0; i < k-1; i++) {
    long long top = que.front(); que.pop();
    int mod = top % 10;
    if (mod != 0) { que.push(top * 10 + mod - 1 ); }
    que.push(top * 10 + mod );
    if (mod != 9) { que.push(top * 10 + mod + 1 ); }
  }

  cout << que.front();
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(void) {
  int n;
  long a[1000], max = - 1, min = 999999999999999;

  if(scanf("%d", &n) == 1);

  for(int i = 0; i < n; i++) {
    if(scanf("%ld", &a[i]) == 1);
    if(a[i] < min) {
      min = a[i];
    }
    if(a[i] > max) {
      max = a[i];
    }
  }



  printf("%ld", max - min);

  return 0;
}


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

#define int long long

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

int A, B, C;

signed main() {
    int ans = LLONG_MAX;
    cin >> A >> B >> C;
    ans = min(ans, (A % 2) * B * C);
    ans = min(ans, (B % 2) * A * C);
    ans = min(ans, (C % 2) * B * A);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
const long long INF = 1LL << 60;
ll mod = 1e9 + 7;

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans;
    if (a % x == 0)
    {
        ans = b / x - a / x + 1;
    }
    else
    {
        ans = b / x - a / x;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
  ll s;cin >>s;
  ll r,d;
  ll m=1e9;
  d=(s-1)/m+1;
  r=(m-s%m)%m;
  P a,b,c;
  a={0,0};
  b={m,1};
  c={r,d};
  cout <<a.first<<" "<<a.second<<" "<<b.first<<" "<<b.second<<" "<<c.first<<" "<<c.second<<endl;
}


Measured memory_bytes: 3540
import System.Exit

-- H W をうけて枠を返す
type Height = Int
type Width = Int
type Frame = [String] -- ["####", "#..#", .. , "####"]
getFrame :: Height -> Width -> Frame
getFrame h w = let hf = replicate w '#'
                   ii = '#' : (replicate (w-2) '.') ++ "#"
                in hf : (replicate (h-2) ii) ++ [hf]

main = do
    line <- getLine
    let (h:w:[]) = map read (words line)
    case (h, w) of
        (0, 0) -> exitSuccess
        _      -> let frame = getFrame h w
                   in mapM_ putStrLn frame
    putStrLn ""
    main


Measured memory_bytes: 4104
#include<stdio.h>
 
int n,pos;
int a[40],b[40];
 
void solve(int l,int r){
  if(l>r)return;
  if(l==r){
    if(b[l]==a[0])printf("%d",b[l]);
    else printf("%d ",b[l]);
    pos++;
    return;
  }
 
  int x=a[pos],i;
  pos++;
  for(i=l;i<=r;i++){
    if(b[i]==x)break;
  }
  solve(l,i-1);
  solve(i+1,r);
   
  if(x==a[0])printf("%d",x);
  else printf("%d ",x);
}
 
int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=0;i<n;i++)scanf("%d",&b[i]);
  pos=0;
  solve(0,n-1);
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] exist = new int[n];
        for(int i = 0;i < n;i++){
            a[i] = sc.nextInt();
        }
        boolean can = true;
        long cnt = 1;
        for(int i = 0;i < n;i++){
            if(a[i] % 2 == 0 && n % 2 == 0){
                can = false;
                break;
            }
            if(a[i] % 2 == 1 && n % 2 == 1){
                can = false;
                break;
            }
            if(exist[a[i]] >= 2){
                can = false;
                break;
            }
            if(exist[a[i]] >= 1 && a[i] == 0){
                can = false;
                break;
            }
            if(exist[a[i]] == 0 && a[i] != 0){
                exist[a[i]]++;
                cnt *= 2;
                cnt %= 1000000007;
            }
            else{
                exist[a[i]]++;
            }
        }
        if(can){
            System.out.println(cnt);
            return;
        }
        System.out.println(0);
    }
}


Measured memory_bytes: 50696
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int l[1000000],i,j,k,c=0,p=0;
    string s;
    cin >> s;
    c=s.size();
    for(i=0;i<c;i++)
    {
        p+=s.at(i)-'0';
    }
    if(p%9==0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;

}


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

int main(){
  int n;
  cin>>n;
  if(n==2){
    cout<<2<<endl;
    return 0;
  }
  while(1){
    int flag=1;
    
    for(int i=2;i*i<n;i++){
      if(n%i==0){
        flag=0;
        break;
      }
    }
    

      if(flag){
        cout<<n<<endl;
        return 0;
      }
    n++;
  }
  return 0;
}


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

int main() {

  int  a,b,ans;
  cin >> a >> b;
  
  ans=a*b%2;
  if(ans==0){
  cout << "Even" << endl;    
  }
  else{
      cout << "Odd" << endl;    
  }

}


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

using namespace std;

int main() {

	int n;
	cin >> n ;

	vector<int>a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	bool divflg = true;
	int counter = 0;
	while(1) {
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 != 0) { divflg = false; break; }
		}
		if (divflg) {
			for (int i = 0; i < n; i++) {
				a[i] /= 2;
			}
			counter++;
		}
		else {
			break;
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long int  i,j,n,k,x;
cin>>n>>k;
vector<long  int> a;
for(i=0;i<n;i++)
{
cin>>x;
a.push_back(x);
}
j=0;
for(i=k;i<a.size();i++)
{
if(a[i]>a[j])
cout<<"Yes\n";
else
cout<<"No\n";
j++;
}
return 0;
}

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

int powm( int x, int n, int mod )
{
	int res = 1;
	while( n ) {
		if( n % 2 ) {
			res *= x;
			res %= mod;
		}
		x *= x;
		x %= mod;
		n /= 2;
	}
	return res;
}

int main()
{
	int p;
	cin >> p;
	vector<int> a( p );
	for( int i = 0; i < p; i++ ) {
		cin >> a[i];
	}

	vector<long long> poly( p + 1 );
	poly[0] = 1;
	for( int i = 0; i < p; i++ ) {
		vector<long long> tmp( p + 1 );
		for( int j = 0; j < p; j++ ) tmp[j + 1] = poly[j];
		for( int j = 0; j < p; j++ ) tmp[j] = (tmp[j] - (poly[j] * i % p) + p) % p;
		swap( poly, tmp );
	}

	vector<long long> ans( p );
	for( int i = 0; i < p; i++ ) {
		if( a[i] == 0 ) continue;
		long long q = 1;
		for( int j = 0; j < p; j++ ) {
			if( i == j ) continue;
			q = q * (i - j) % p;
		}
		q = powm( (q % p + p) % p, p - 2, p );
		vector<long long> tmp = poly;
		for( int j = p; j > 0; j-- ) {
			ans[j - 1] += tmp[j] * q;
			ans[j - 1] %= p;
			tmp[j - 1] = (tmp[j - 1] + tmp[j] * i) % p;
		}
	}


	for( int i = 0; i < p; i++ ) {
		if( i ) cout << " ";
		cout << ans[i] % p;
	}
	cout << endl;
}


Measured memory_bytes: 384
# Problem A - Kenken Race

# input
N, A, B, C, D = map(int, input().split())
S = list(input())

# check
if C<D:
    # B check
    is_ok = True
    for i in range(B, D-1):
        if S[i]=='#' and S[i+1]=='#':
            is_ok = False
            break
    # A check
    for i in range(A, C-1):
        if S[i]=='#' and S[i+1]=='#':
            is_ok = False
            break
    # output
    if is_ok:
        print("Yes")
    else:
        print("No")
else:
    is_ok = False
    # B check
    for i in range(B, D):
        if S[i]=='#' and S[i+1]=='#':
            is_ok = False
            break
    for i in range(B-1, D):
        if S[i-1]=='.' and S[i]=='.' and S[i+1]=='.':
            is_ok = True
    # A check
    for i in range(A, C-1):
        if S[i]=='#' and S[i+1]=='#':
            is_ok = False
            break
    # output
    if is_ok:
        print("Yes")
    else:
        print("No")


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    string SS[2];
    cin >> N;
    cin >> SS[0] >> SS[1];
    rep(i, 2 * N) cout << SS[i % 2][i / 2];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3572
N = int(input())

max_n = 0
max_times = -1
for i in range(1, N + 1):
    times = 0
    original_i = i
    while i % 2 == 0:
        i //= 2
        times += 1
    if times >= max_times:
        max_n = original_i
        max_times = times
print(max_n)


Measured memory_bytes: 2940
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
int m,n,ds,ns,nc,nj,sy,sx,gy,gx,t,x1,x2,
S[20][20],D[20][20][20][20]; bool V[20][20][101][4];
void dfs(int y,int x,int t,int d){
	V[y][x][t][d]=1;
	int ny,nx,c,nt,nd;
	rep(i,4){
		nd=d+i&3,ny=y+dy[nd],nx=x+dx[nd];
		if(ck(ny,m)&&ck(nx,n)&&i!=2&&(c=D[y][x][ny][nx],nt=t+c,c)&&(!S[ny][nx]||
		nd%2==nt/S[ny][nx]%2)&&nt<101&&!V[ny][nx][nt][nd])dfs(ny,nx,nt,nd);
	}
}
int main(){
	END:while(scanf("%d%d",&m,&n),m){
		scanf("%d",&ds); rep(i,m)rep(j,n){
			S[i][j]=0; rep(k,m)rep(l,n)D[i][j][k][l]=ds;
			rep(t,101)rep(d,4)V[i][j][t][d]=0;
		}
		char y1,y2;
		scanf("%d",&ns); rep(i,ns)scanf(" %c-%d %d",&y1,&x1,&t),S[y1-'a'][x1-1]=t;
		scanf("%d",&nc); rep(i,nc)scanf(" %c-%d %c-%d",&y1,&x1,&y2,&x2),
		D[y1-'a'][x1-1][y2-'a'][x2-1]=D[y2-'a'][x2-1][y1-'a'][x1-1]=0;
		scanf("%d",&nj); rep(i,nj)scanf(" %c-%d %c-%d %d",&y1,&x1,&y2,&x2,&t),
		D[y1-'a'][x1-1][y2-'a'][x2-1]+=t,D[y2-'a'][x2-1][y1-'a'][x1-1]+=t;
		scanf(" %c-%d %c-%d",&y1,&x1,&y2,&x2),sy=y1-'a',sx=x1-1,gy=y2-'a',gx=x2-1;
		rep(d,4)dfs(sy,sx,0,d);
		rep(t,101)rep(d,4)if(V[gy][gx][t][d]){
			printf("%d\n",t); goto END;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> v[111111], w[111111];
int visit[111111], edge[111111], ans;

void dfs(int node, int previous_color)
{
	int i, next_color = 0;

    for (i = 0; i < v[node].size(); i++)
	{
		if (visit[v[node][i]])
			continue;
		visit[v[node][i]] = 1;

		++next_color;
		if (next_color == previous_color)
			++next_color;

		edge[w[node][i]] = next_color;

		dfs(v[node][i], next_color);

		ans = max(ans, next_color);
    }
}

int main(void)
{
    int n, i;

    scanf("%d" ,&n);
    for (i = 1; i < n; i++)
	{
		int a, b;

		scanf("%d %d" ,&a, &b);

		v[a].push_back(b); v[b].push_back(a);
		w[a].push_back(i); w[b].push_back(i);
	}

    visit[1] = 1;
	dfs(1, 0);

	printf("%d\n" ,ans);
	for (i = 1; i < n; i++)
		printf("%d\n" ,edge[i]);
	return 0;
}

Measured memory_bytes: 13312
#include<stdio.h>

#define MAX 2000000
#define INFTY -20000505

int H = 0,A[MAX+1];

void maxHeapify(int);
void insert(int);
int extract(void);
void increaseKey(int,int);

int main(){
  int key;
  char com[10];

  while( 1 ){
    scanf("%s",com);
    if( com[0] == 'e' && com[1] == 'n' )break;
    if( com[0]  == 'i' ){
      scanf("%d",&key);
      insert(key);
    }
    else printf("%d\n", extract() );
  }

  return 0;

}

void maxHeapify(int i){
  int  l,r,largest,t;
  l = 2 * i;
  r = 2 * i +1;

  if( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest] ) largest = r;
  if( largest != i ){
    t = A[i];
    A[i] = A[largest];
    A[largest] = t;
    maxHeapify(largest);
  }
}

void insert(int key){

  H++;
  A[H] = INFTY;
  increaseKey(H,key);
}


int extract(void){
  int maxv;

  if( H < 1 ){
    return INFTY;
  }
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);

  return maxv;
}

void increaseKey(int i,int key){
  int t;
  A[i] = key;
  while( i > 1 && A[i/2] < A[i]){
    t = A[i];
    A[i] = A[i/2];
    A[i/2] = t;
    i = i/2;


  }


}

Measured memory_bytes: 4696
#include <cstdio>

void SwapStr(char *str){
	char *st,*end,*pt,*ptr;
	st = str;
	for(end = st;*end != '\0';end++){}
	pt = st;
	ptr = end - 1;
	char c;
	while(pt < ptr){
		c = *pt;
		*pt = *ptr;
		*ptr = c;
		pt++;
		ptr--;
	}
	
}

int main(){
	char str[21];
	while(scanf("%s",str) != EOF){
		SwapStr(str);
		printf("%s\n",str);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int n, m;
    cin >> n >> m;
    priority_queue<int> pq;
    for (int i = 0; i < n; i++){
        int nxt;
        cin >> nxt;
        pq.push(nxt);
    }

    while (m--){
        int t = pq.top();
        pq.pop();
        pq.push(t/2);
    }
    ll sm = 0LL;
    while (n--){
        sm += pq.top();
        pq.pop();
    }
    cout << sm << endl;

    return 0;
}


Measured memory_bytes: 892
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
const int N=1e2+5;
string s[N];
int main()
{
   int n=D(), l=D();
   for(int i=0;i<n;++i){
    cin>>s[i];
   }
   sort(s,s+n);
   for(int i=0;i<n;++i)cout<<s[i];

}


Measured memory_bytes: 256
// In the name of Allah
// #Isart
// yedoone bashe, mashti bashe ...

#include<bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double

using namespace std;

const int MAXN = 1e5 + 10;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n, cnt = 0;
	cin >> n;
	for(int i = 0; i < n; i ++){
		int x;
		cin >> x;
		if(x % 2 == 1) cnt ++;
	}	
	if(cnt % 2 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

vector<ll> primes;
map<ll, ll> factors;
 
void erathosthenes(ll n) {
    vector<bool> primeFlags(n+10, true);
    primeFlags[0] = primeFlags[1] = false;
    vector<int> sqrtprimes;
    for (int i = 2; i*i <= n; i++) {
        bool mod0 = false;
        for (int j = 2; j*j <= i; j++) {
            if (i%j == 0) mod0 = true;
        }
        if (!mod0) sqrtprimes.push_back(i);
    }
    for (auto &&e: sqrtprimes) {
        for (int i = 2; i <= n; i++) {
            if (i%e == 0) primeFlags[i] = false;
        }
    }
    for (auto &&e: sqrtprimes) primeFlags[e] = true;
    for (int i = 1; i <= n; i++) if (primeFlags[i]) primes.push_back(i);
    return;
}
 
void factoring(ll n) {
    ll m = sqrt(n);
    erathosthenes(m);
    for (auto &&e: primes) {
        while(n%e == 0){
            factors[e]++;
            n /= e;
        }
    }
    factors[n]++;
    factors.erase(1);
}
 

int main(int argc, char const *argv[]) {
    ll a,b; cin>>a>>b;
    factoring(a);
    map<ll,ll> A(factors);
    primes.clear(); factors.clear();
    factoring(b);
    map<ll,ll> B(factors);
    
    int ans = 1;
    for (auto &&e: A) {
        if (B.count(e.first)) ans++;
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1528
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    a, b = list(map(int,ipti().split()))

    if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0:
        print("Possible")
    else:
        print("Impossible")

if __name__ == '__main__':
    main()

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

int dsum(int n){
    int a = n;
    int r = 0;
    while (a != 0)
    {
        r += a % 10;
        a /= 10;
    }
    return r;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    int tmp;
    for (int i = 1; i <= N; i++)
    {
        tmp = dsum(i);
        if(tmp >= A && tmp <= B){
            ans += i;
        }
    }
    cout << ans << endl;
}

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

int N, u, v;
vector<vector<int>> G;
vector<int> ud;
vector<int> vd;

void dfs(int s, int p, int dist, vector<int> &vec) {
    vec[s] = dist;
    for (auto e : G[s]) {
        if (e == p) continue;
        dfs(e, s, dist + 1, vec);
    }
};

int main() {
    cin >> N >> u >> v;
    u--;v--;
    G.resize(N);
    ud.resize(N);
    vd.resize(N);

    rep(i, N - 1) {
        int from, to;
        cin >> from >> to;
        from--;
        to--;

        G[from].push_back(to);
        G[to].push_back(from);
    }

    dfs(u, -1, 0, ud);
    dfs(v, -1, 0, vd);

    int ans = 0;
    rep(i,N){
        if(vd[i]>ud[i]){
            ans = max(ans,vd[i]);
        }
    }
    cout << ans - 1 << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

struct vertex { int v; int p; };

class GV {
public:
  bool operator() (vertex &x, vertex &y){
    return x.p>y.p;
  }
};

int main() {
  int N; cin >> N;
  vector<int> adj[N];
  rep(i,N-1) {
    int A, B; cin >> A >> B; A--; B--;
    adj[B].push_back(A);
    adj[A].push_back(B);
  }
  priority_queue<vertex, vector<vertex>, GV> left;
  int val[N]; fill_n(val,N,INF);
  int K; cin >> K;
  rep(i,K) {
    int V, P; cin >> V >> P; V--;
    left.push({V,P});
    val[V] = P;
  }
  while(left.size()) {
    vertex now = left.top(); left.pop();
    // cout << now.v << " " << now.p << endl;
    for (auto x: adj[now.v]) {
      if (val[x]==INF) {
        val[x] = val[now.v]+1;
        left.push({x,val[x]});
      }
      else {
        if (abs(val[x]-val[now.v])!=1) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  rep(i,N) cout << val[i] << endl;
  return 0;
}

Measured memory_bytes: 8576
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define rep(i,n)  for (i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

const int D=60;
int main(){
	int i,j,n,now=0;
	ll k;
	cin >> n >> k;
	int a[n][D];
	rep(i,n) cin >> a[i][0];
//qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
	rep(i,D-1) rep(j,n) a[j][i+1]=a[a[j][i]-1][i];
	now=1;
	rep(i,D){
		if (k>>i & 1) {
			now=a[now-1][i];
//			cout << now << endl;
		}
	}
//ooooooooooooooooooooooooooooooooooooooo
	cout << now << endl;
	return 0;
}

Measured memory_bytes: 50036
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}

int main(){
	int a,b;scanf("%d%d",&a,&b);printf("%d\n",a-b+1);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

vector<int> G[100100];
vector<int> p(100100, -1), vs, cnt(100100, 0);

void dfs(int v, int par = -1) {
  p[v] = par;
  for (int u: G[v]) {
    if (u == par) continue;
    if (p[u] != -1) continue;
    dfs(u, v);
  }
  vs.push_back(v);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  if (m & 1) {
    cout << -1 << '\n';
    return 0;
  }
  dfs(0);
  vector<pair<int, int>> ans;
  set<pair<int, int>> used;
  rep(q, n - 1) {
    int i = vs[q];
    for (int j: G[i]) {
      if (p[i] == j) continue;
      if (used.find({i, j}) != used.end()) continue;
      ans.push_back({i + 1, j + 1});
      cnt[i]++;
      used.insert({i, j});
      used.insert({j, i});
    }
    if (cnt[i] & 1) {
      ans.push_back({i + 1, p[i] + 1});
      cnt[i]++;
    }
    else {
      ans.push_back({p[i] + 1, i + 1});
      cnt[p[i]]++;
    }
    used.insert({i, p[i]});
    used.insert({p[i], i});
  }
  rep(i, m) cout << ans[i].first << ' ' << ans[i].second << '\n';

  




  
  return 0;
}

Measured memory_bytes: 22900
#include<iostream>
 using namespace std;
 
int main()
{
	int x,a,b,c,d,r;
	cin>>x;
	a=x/1000;
	b=x%1000/100;
	c=x%100/10;
	d=x%10;
	if(a==b) r++;
	if(b==c) r++;
	if(c==d) r++;
	if(r>=1) cout<<"Bad";
	else cout<<"Good";
	
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
char s[100];int it;
using namespace std;
string Read(){
    string c;
	if(s[it]=='+'){
        it++;
        c=Read();
        if(c[0]=='Z'){
            c[0]='A';
        }else if(c[0]!='?'){
            c[0]++;
        }
        return c;
	}
	else if(s[it]=='-'){
        it++;
        c=Read();
        if(c[0]=='A'){
            c[0]='Z';
        }else if(c[0]!='?'){
            c[0]--;
        }
        return c;
	}
	else if(s[it]=='['){
        it++;
        while(s[it]!=']'){
            c+=Read();
        }
		it++;
		reverse(c.begin(), c.end());
        return c;
	}
	else if(s[it]==']'){
        it++;
        return "";
	}
	else {
		c += s[it];
		it++;
		return c;
	}
};
int main(){
    while(scanf("%s",s),s[0]!='.'){
        it=0;
        string ans;
        while(s[it]!='\0'){
            ans+=Read();
        }
        for(int i=0;i<ans.length();i++){
            if(ans[i]=='?'){
                ans[i]='A';
            }
        }
        printf(ans.c_str());
		printf("\n");
    }
    return 0;
}


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

int main()
{
    int n, t;
    std::cin >> n >> t;
    std::vector<int> arr(n);
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        std::cin >> tmp;
        arr[i] = tmp;
    }

    int64_t sum = 0;
    for (int i = 0; i < n; ++i)
    {
        if (i != n - 1)
        {
            sum += std::min(arr[i + 1] - arr[i], t);
        }
        else
        {
            sum += t;
        }
    }

    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N, M;
  cin >> N >> M;
  vector<vector<int>> g(N);
  REP(i,M){
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
  }

  int mi = N+1;
  vector<int> res;
  for(int s = 0; s<N; s++){
    vector<int> dist(N, -1);
    vector<int> prev(N, -1);
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    while(q.size()){
      auto v = q.front();
      q.pop();
      for(auto u: g[v]){
        if(dist[u] == -1){
          dist[u] = dist[v] + 1;
          prev[u] = v;
          q.push(u);
        }
      }
    }

    for(int t = 0; t<N; t++){
      if(t == s || dist[t] == -1) continue;
      for(auto v: g[t]){
        if(v == s){
          vector<int> tmp({s});
          int cur = t;
          while(cur != s) tmp.push_back(cur), cur = prev[cur];
          if(mi > tmp.size()){
            mi = tmp.size();
            res = tmp;
          }
        }
      }
    }
  }

  if(mi == N+1){
    cout << -1 << endl;
  }else{
    cout << res.size() << endl;
    for(auto e: res) cout << e+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3708
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String[] s = new String[n];

		for (int i = 0; i < n; i++){
			s[i] = sc.next();
		}

		char[]charArray = s[0].toCharArray();
		Arrays.sort(charArray);

		StringBuilder sb = new StringBuilder();
		char c = 0;
		for (int i = 0 ; i < charArray.length; i++){
			int matchChrCnt = 0;
			if (c != charArray[i]){
				c = charArray[i];
				for(int j = 0; j < n; j++){
					int cnt = 0;
					String tmp = s[j];
					for (int k = 0; k < tmp.length(); k++){
						if (tmp.charAt(k) == c){
							cnt++;
						}
					}
					if (j == 0){
						matchChrCnt = cnt;
					} else {
						matchChrCnt = Math.min(matchChrCnt, cnt);
					}
				}
				if (matchChrCnt > 0){
					for (int l = 0; l < matchChrCnt; l++){
						sb.append(c);
					}
				}
			}
		}
		System.out.println(sb.toString());
	}

}


Measured memory_bytes: 22864
#include<stdio.h>
int main(){
	int a,b,c,i,count;
	while(scanf("%d%d",&a,&b) != EOF){
		count=1;
		if(a>=0 && b>=0){
			c = a+b;
			for(i=10;i<=c;i*=10){
				count++;
			}
			printf("%d\n",count);
		}
	}
	return 0;
}

Measured memory_bytes: 0
'''
Created on 2020/09/14

@author: harurun
'''
def yn(t):
  if t:print("yes")
  else:print("no")
  return
def YN(t):
  if t:print("YES")
  else:print("NO")
  return
def Yn(t):
  if t:print("Yes")
  else:print("No")
  return
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  x=int(pin())
  if x==1:
    print(0)
  else:
    print(1)
  return 
main()

Measured memory_bytes: 9144
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

		public static void main(String[] args){
			
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			// スペース区切りの整数の入力
			String a = sc.next();
			String[] strArray = a.split("");
			
			String b = strArray[3] + strArray[2] + strArray[1];
			
			if (a.equals(b)){
				System.out.println("Yes");
			    return;
			}
			
			System.out.println("No");

		}
}


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

int main(void){
    long int n = 0; 
    long long int a[100001];
    long long int ans = 1;
    int error = 0;

    scanf("%ld", &n);

    for(long long int i = 0; i < n; i++){
        scanf("%lld", &a[i]);
        if(a[i] == 0){
            ans = 0;
            printf("0\n");
            return 0;
        }
    }

    for(long long int i = 0; i < n; i++){
        if(ans > 1000000000000000000 / a[i]){
            error = 1;
            ans = -1;
        }else if (error != 1){
            ans *= a[i];
        }
    }

    if(error == 1){
        printf("-1\n");
    }else{
        printf("%lld\n", ans);
    }
    return 0;

} 


Measured memory_bytes: 4572
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int dyy[]={0,-1,0,1};
int dxx[]={-1,0,1,0};

/*#define int ll*/
signed main(){
    int n;
    cin>>n;
    int t=1;
    ll sum=0;
    while(1){
        sum+=t;
        if(sum==n){
            cout<<t<<endl;
            return 0;
        }else if(sum>n){
            cout<<t<<endl;
            return 0;
        }
        t++;
    }
    return 0;
}

Measured memory_bytes: 256
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let [n, d] = lines[0].split(' ').map( _ => parseInt(_))
    let ans = 0

    for(let i = 0; i < n; i++) {
        let[x, y] = lines[i+1].split(' ').map( _ => parseInt(_))
        if(d * d >= x * x + y * y) ans++
    }
    console.log(ans)
});

Measured memory_bytes: 79388
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    X, N = map(int, rl().split())
    p = set(map(int, rl().split()))
    
    ans = -1
    d_min = 1000
    for i in range(102):
        if i not in p:
            if abs(X - i) < d_min:
                d_min = abs(X - i)
                ans = i
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long N;cin>>N;
    vector<long> array(N);
    for(int i=0;i<N;i++)cin>>array[i];
    sort(array.begin(),array.end());
    if(array[0]==0){
        cout<<0<<endl;
        return 0;
    }
    long K=1;
    for(int i=0;i<N;i++){
        if(array[i]>1000000000000000000/K){
            cout<<-1<<endl;
            return 0;
        }
      K*=array[i];
    }
    cout<<K<<endl;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> c(H);
    rep(i,H)cin >> c[i];
    auto check = [&](ll s, ll t){
        set<pair<int,int>> st;
        rep(i,H){
            if(!(bit(i) & s)){
                rep(j,W){
                    if(bit(j) & t)continue;
                    if(c[i][j] == '#')st.insert(make_pair(i,j));
                }
            }
        }
        rep(j,W){
            if(!(bit(j) & t)){
                rep(i,H){
                    if(bit(i) & s)continue;
                    if(c[i][j] == '#')st.insert(make_pair(i,j));
                }
            }
        }
        return st.size() == K;
    };
    ll ans = 0;
    for(ll x = 0; x < bit(H); x++){
        for(ll y = 0; y < bit(W); y++){
            if(check(x, y))ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660
s = input()

a = "01"*int(len(s)/2) + "0"*int(len(s)%2)
b = "10"*int(len(s)/2) + "1"*int(len(s)%2)

a_count = 0
b_count = 0
for i, j, k in zip(a, b, s):
    if i != k:
        a_count += 1
    if j != k:
        b_count += 1

print(min(a_count, b_count))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
const ll mod = 1e9 + 7;

int nod(ll n) {
  int c = 0;
  while (n) n /= 10, c++;
  return c;
}

int f(ll a, ll b) {
  return max(nod(a), nod(b));
}

int main() {
  ll n;
  cin >> n;
  int ans = f(n, 1);
  for (ll i = 2; i*i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, f(i, n/i));
    }
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];

  ll m;
  cin >> m;

  REP(i,m){
    ll k;
    cin >> k;
    ll lb, ub;
    ll lef, rig;

    lef = -1; rig = n;
    while(rig - lef > 1){
      ll mid = (lef + rig) / 2;
      if(a[mid] >= k) rig = mid;
      else lef = mid;
    }
    lb = rig;

    lef = -1; rig = n;
    while(rig - lef > 1){
      ll mid = (lef + rig) / 2;
      if(a[mid] > k) rig = mid;
      else lef = mid;
    }
    ub = rig;

    cout << lb << " " << ub << endl;
  }
  return 0;
}




Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define poly vector<ll>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool d=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') d=0;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return d?x:-x;
}
inline void write(ll x){
	if(x<0) x=-x,putchar('-');
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1e5+5;
struct info{
	int x,y;
}a[N];
ll pre[N],suf[N];
bool operator <(const info &a,const info &b){
	return a.x-a.y>b.x-b.y;
}
multiset<int> s;
int main(){
	int n=read(),m=read(),k=read(),nn=n+m+k;
	ll ans=0;
	For(i,1,nn){
		int x=read();
		ans+=x;a[i].x=read()-x;a[i].y=read()-x;
	}
	sort(a+1,a+nn+1);
	For(i,1,nn){
		pre[i]=pre[i-1]+a[i].x;
		s.insert(a[i].x);
		if((int)s.size()>m){
			int ssw=*(s.begin());
			pre[i]-=ssw;s.erase(s.begin());
		}
	}
	s.clear();
	Rep(i,nn,1){
		suf[i]=suf[i+1]+a[i].y;
		s.insert(a[i].y);
		if((int)s.size()>k){
			int ssw=*(s.begin());
			suf[i]-=ssw;s.erase(s.begin());
		}
	}
	ll ksg=-1e17;
	For(i,m,nn-k) ksg=max(ksg,pre[i]+suf[i+1]);
	cout<<ans+ksg;
}

Measured memory_bytes: 10208
a,b,c,d = map(int,input().split())
from fractions import gcd
a -= 1
nya = c//gcd(c,d) * d # 最小公倍数
# オイラー関数
ca = a//c
da = a//d
#print(ca,da)
cda = ca + da - a//nya
ans_a = a - cda
cb = b//c
db = b//d
#print("cddb",cb,db)
cdb = cb + db - b//nya
ans_b = b - cdb
print(ans_b - ans_a)
#print(ans_a,ans_b)
#print(nya)
#ans = ans_b - ans_a
#print(ans)


Measured memory_bytes: 5076
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <cstdlib>
using namespace std;

const int mod = 2019;

char p[200010];
int a[200010], b[200010], s[200010];

int main() {
    int n;
    cin>>(p+1);
    n = strlen(p + 1);
    int c = 1, now = 0;
    long long ans = 0;
    for(int i = 1; i <= n; i++) a[i] = p[i] - '0';
    s[0] = 1;
    for(int i = n; i >= 1; i--) {
        now += a[i] * c;
        c *= 10;
        now %= mod;
        c %= mod;
        ans += s[now];
        //if(s[now] > 0) printf("%d\n", i);
        s[now]++;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4560
#include <iostream>

using namespace std;
int main() {
  int k = 1;
  int z = 5;
  for(int i = 0; i < 5 ;i++) {
    cin >> z;
    if(z == 0) {
      cout << k << endl;
      return 0;
    } else {
      k++;
    }
  }
}


Measured memory_bytes: 3584
N = int(input())
H = list(map(int,input().split()))

#height = H[0]
index = 0
maximum = 0
for i in range(1,N):
    if H[i-1] < H[i]:
        maximum = max(maximum,i-1-index)
        index = i 
    elif i == N-1:
        maximum = max(maximum,i-index)
print(maximum)

Measured memory_bytes: 20644
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++){
    if(A[j]<=x){
     i++;
     t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[r]; A[r] = t;
  return i+1;
}

int main(){
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  
  q = partition(0, n-1);
  
  for(i=0; i<n; i++){
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d", A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}  

Measured memory_bytes: 992
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


struct edge{
  int to, cost;
};
vector<vector<edge>  >g;
vector<double> p;//期待値

void dfs(int now, int par){
    int cnt = 0;
    for(auto e: g[now])if(e.to != par){
        dfs(e.to,now);
        p[now] += p[e.to];
        cnt++;
    }
    if(cnt){
        p[now] /= cnt;
        p[now] += 1;
    }
}

void dfs2(int now, double p_par, int par){
    double sum = 0;
    int cnt = 0;
    for(auto e: g[now]){
        if(e.to == par){
            sum += p_par;
        }else{
            sum += p[e.to];
        }
        cnt++;
    }
    p[now] = sum/cnt + 1;
    for(auto e: g[now])if(e.to != par){
        double p_next = sum - p[e.to];
        if(cnt > 1)p_next /= cnt-1, p_next += 1;
        dfs2(e.to, p_next, now);
    }
}

signed main(void) {
    int n;
    cin >> n;
    g.resize(n);
    p = vector<double>(n,0);
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b;
        a--,b--;
        edge e1 = {b,1};
        g[a].push_back(e1);
        edge e2 = {a,1};
        g[b].push_back(e2);
    }
    dfs(0,-1);
    //rep(i,n)cout << shosu(10) << p[i] << endl;
    dfs2(0,0,-1);
    rep(i,n){
        cout << shosu(10) << p[i] << endl;
    }
}


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

int main() {
    int N;
    string S;
    int cnt = 0;
    cin >> N >> S;
    for(int i = 0; i < N; i++)
    {
        if(S[i] == 'A')
        {
            if(S[i + 1] == 'B')
            {
                if(S[i+ 2] == 'C')
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256