akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
static const long long MOD = 1000000007LL;
int n;
char s[100005];
long long unsigned int dp[100005][13];
int main () {
int i, j, ki;
long long unsigned int res = 0;

 scanf("%s", s);
 n = strlen(s);

 dp[0][0] = 1;
 for (i = 0; i < n; i++) {
 int c;
 if (s[i] == '?') c = -1;
 else c = s[i] - '0';

 for (j = 0; j < 10; j++) {
 if (c != -1 && c != j) continue;
 for (ki = 0; ki < 13; ki++) {
 dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki];
 }
 }
 for (j = 0; j < 13; j++) dp[i + 1][j] %= MOD;
 }
 res = dp[n][5];

 printf("%llu\n", res);
 return 0;
 }


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int K, X;
    cin >> K >> X;
    int minimum = -1000000;
    int maximum = 1000000;

    if (X - (K - 1) < minimum) {
        cout << minimum;
        FOR(i, minimum + 1, minimum + K) cout << " " << i;
        cout << endl;
    }
    else if (X + (K - 1) > maximum) {
        cout << maximum - K + 1;
        FOR(i, maximum - K + 2, maximum + 1) cout << " " << i;
        cout << endl;
    }
    else {
        cout << X - (K - 1);
        FOR(i, X - (K - 1) + 1, X + K) cout << " " << i;
        cout << endl;
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 1000010

template< typename T >
class CumulativeSum
{
public:
    vector< T > m_data;
    CumulativeSum() {};
    CumulativeSum(int sz) : m_data(sz, 0) {};

    // k に x を加える O(1)
    void Add(int k, int x) {
        assert(m_data.size() >= k);
        if(m_data.size() <= k) { m_data.push_back(x); }
        else { m_data[k] += x; }
    }

    // 累積和の構築 O(m_data.size())
    void Build() { for(int i = 1; i < m_data.size(); i++) { m_data[i] += m_data[i - 1]; } }

    // 区間 [0, k] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int k) {
        if(k < 0) { return 0; }
        return (m_data[min(k, (int) m_data.size() - 1)]);
    }

    // 区間 [l, h] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int l, int h) { return this->Query(h) - this->Query(l-1); }
};

ll N, K;
vector<ll> pattern;

signed main()
{
    cin >> N >> K;
    CumulativeSum<ll> cs(N);
    REP(i, N) {
        ll a;
        cin >> a;
        cs.Add(i, a);
    }
    cs.Build();
    // pattern の作成
    for(ll i = 0; i < N; ++i) {
        for(ll j = i; j < N; ++j) {
            pattern.push_back(cs.Query(i, j));
        }
    }
    sort(pattern.begin(), pattern.end(), greater<ll>());
    vector<bool> isUse(pattern.size(), true);
    for(ll i = 60; i >= 0; --i) {
        ll cnt = 0;
        REP(j, pattern.size()) {
            if( isUse[j] && ((pattern[j] >> i) & 1) ) { cnt++; }
        }
        if(cnt >= K) {
            // ビットが立ってないやつは消す
            REP(j, pattern.size()) {
                if( isUse[j] && !((pattern[j] >> i) & 1) ) {
                    isUse[j] = false;
                }
            }
        }
    }
    ll ans = -1;
    ll cnt = 0;
    REP(i, pattern.size()) {
        if( isUse[i] ) {
            ans &= pattern[i];
            cnt++;
            if(cnt >= K) { break; }
        }
    }
    assert(cnt >= K);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
    int n;cin>>n;
    vector<int>a(n);int cnt=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==1&&i%2==0) cnt++;
    }
    cout<<cnt;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);	 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  cout << (n <= k ? n * x : k * x +  (n - k) * y);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
table = [[] for _ in range(n+1)]
for i in range(1, n+1):
  a = list(map(int, input().split()))
  table[i] = a
cursor = [0]*(n+1)
is_matched = set()
d = 0
match = 0
while match < n * (n-1) //2:
  now_match = match
  for i in range(1, n):
    if cursor[i] < n-1 and i not in is_matched:
      j = table[i][cursor[i]]
      if i < j and j not in is_matched and table[j][cursor[j]] == i :
        match += 1
        cursor[i] += 1
        is_matched.add(i)
        cursor[j] += 1
        is_matched.add(j)
  if now_match == match:
    print(-1)
    exit()
  if d > 30000:
    print(499500)
    exit()  
  d += 1
  is_matched.clear()
print(d)

Measured memory_bytes: 54236
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val S = input.next()
    
    if (N % 2 == 1) {
      println("No")
    } else {
      if (S.substring(0, N / 2).equals(S.substring(N / 2))) {
        println("Yes")
      } else {
        println("No")
      }
    }
  }
}

Measured memory_bytes: 36460
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] arr = reader.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int M = Integer.parseInt(arr[1]);
        System.out.println(N == M ? "Yes" : "No");
    }
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int f[100][100];
int w, h;
int gx, gy;

int solve() {

  int memo[h+2][w+2];
  rep (i, h + 2) {
    rep (j, w + 2) {
      memo[i][j] = 0;
    }
  }

  queue<pair<int, pair<int, int>>> q;
  q.push(cons(1, cons(0, 0)));

  while (!q.empty())
  {
    int d = car(q.front());
    int x = cadr(q.front());
    int y = cddr(q.front());
    q.pop();

    assert(x % 2 == 0);
    assert(y % 2 == 0);

    if (memo[x/2][y/2]) continue;
    memo[x/2][y/2] = 1;

    //cerr << cons(x, y) << endl;
    if (x == gx && y == gy) return d;

    if (x > 0 && f[x-1][y] == 0)
      q.push(cons(d + 1, cons(x - 2, y)));
    if (y > 0 && f[x][y-1] == 0)
      q.push(cons(d + 1, cons(x, y - 2)));
    if (x < gx && f[x+1][y] == 0)
      q.push(cons(d + 1, cons(x + 2, y)));
    if (y < gy && f[x][y+1] == 0)
      q.push(cons(d + 1, cons(x, y + 2)));
  }
  return 0;
}

int main() {

more:;

  cin >> w >> h;

  if (!w && !h) return 0;

  gx = h + h - 2;
  gy = w + w - 2;

  rep (i, h + h - 1) {
    rep (j, w + w - 1) {
      int d = 0;
      if ((i + j) % 2) {
        cin >> d;
      }
      f[i][j] = d;
    }
  }

  cout << solve() << endl;

  goto more;
}

Measured memory_bytes: 1240
#include <stdio.h>
void solve(void)
{
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if( (a+b-c)*(b+c-a)*(c+a-b) ){
		printf("No\n");
	} else {
		printf("Yes\n");
	}
}
int main(int argc, char **argv)
{
	solve();
	return 0;
}


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

#define eb emplace_back
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Vi = vector<int>;

void run() {
	string s;
	cin >> s;
	int cnt = 0;

	for (int i = 0, j = s.size()-1; i < j; ++i, --j) {
		if(s[i]!=s[j]) {
			++cnt;
		}
	}   
	cout << cnt << endl;
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    double st = clock();

    run();

    cerr << "\n" << "time = " << (clock() - st) / CLOCKS_PER_SEC << "\n";
    return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main() -> None:
    x, y, z = [int(next_str()) for _ in range(3)]

    for i in range(1, 10 ** 9):
        if x < z + (i + 1) * (y + z):
            print(i)
            break


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
#define MAX_N 100001
#define INF 2147483647
#define REP(i,COUNT) for(int i=0;i<(int)(COUNT);i++)
struct edge{
  int to, cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int, int> P;
typedef long long int ll;

void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
vector<int> dist;
vector<int> prever;
void dijkstra(int n,int s){
  dist = vector<int>(n,INF);
  prever = vector<int>(n,-1);
  dist[s] = 0;

  priority_queue<P, vector<P> , greater<P> > que;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(dist[v] < p.first)
      continue;
    REP(i,graph[v].size()){
      edge e = graph[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        prever[e.to] = v;
        que.push(P(dist[e.to],e.to));
      }

    }

  }
}

bool bellman_ford(int n,int s){
  dist = vector<int>(n,INF);
  dist[s] = 0;
  REP(i,n)REP(v,n)REP(k,graph[v].size()){
    edge e = graph[v][k];
    if(dist[v] != INF && dist[e.to] > dist[v] + e.cost){
      dist[e.to] = dist[v] + e.cost;
      if(i == n - 1) return true;
    }
  }
  return false;
}

vector<vector<ll> > d,v; //d[u][v]は辺e=(u,v)のコスト, 辺が存在しないときINF
void warshall_floyd(int n){
  REP(i,n)REP(j,n)REP(k,n){
    d[j][k] = min(d[j][k],d[j][i] + d[i][k]);
   
  }
}

int main()
{
  int N,M,R,A,B,C;
  
  cin >> N >> M;
  d = vector<vector<ll > >(N+2,vector<ll>(N+2,INF));
  v = vector<vector<ll > >(N+2,vector<ll>(N+2,INF));
  vector<P> m(0);
  REP(i,M){
    cin >> A >> B >> C;
    A--;B--;
    d[A][B] = C;
    d[B][A] = C;
    v[B][A] = C;
    v[A][B] = C;
    m.push_back(P(A,B));
  }
  warshall_floyd(N+1);
  REP(i,N){
    d[i][i] = 0;
  }
  ll res=0;
  for(int i=0;i<M;i++){
    bool flag = true;    
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
        if(d[j][k] == d[j][m[i].first] + v[m[i].first][m[i].second] + d[m[i].second][k]){
            flag=false;
            j = N;
            k = N;
        }
      }
    }
    if(flag)
      res++;
  }
  
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 2000010
//#define int long long
#define INF 1e9
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
inline int read()
{
	register char cc = getchar();register int cn(0), flus(1);
	while(cc > '9' || cc < '0') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus; 
}
bool flag[N];
int wa[N], ac[N];
queue<int> q;
signed main()
{
	int n, m;
	int ac1(0), wa1(0);
	n = read();
	m = read();
	while(m -- )
	{
		string st;
		int num;
		num = read();
		cin >> st;
		if(st == "AC") 
		{
			if(!flag[num]) 
			{
				flag[num] = 1;
				q.push(num);
				ac1 ++;
			}
		}
		if(st == "WA")
		{
			if(!flag[num]) 
			{
				wa[num] += 1;
			}
		}
	}
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		wa1 += wa[u];
	}
	printf("%d %d\n",ac1,wa1);
	return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=100005;
int n,x;
int main(){
    cin>>n;
    x=n%10;
    n/=10;
    if(n/10==7||n%10==7||x==7) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define int ll

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

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

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);


    int A, B; cin >> A >> B;
    cout << A * B << endl;
}

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


int main() {
    int q;
    cin >> q;
    long long brac_diff = 0;
    for (int j = 0; j < q; ++j) {
        int p, n;
        char c;
        cin >> p >> c >> n;
        if(c == '(') {
            brac_diff += n;
        } else {
            brac_diff -= n;
        }
        cout << (brac_diff == 0 ? "Yes" : "No") << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    string str;
    cin >> str;
    bool flag = true;
    int idx = -1;
    if(str[0] != 'A') flag = false;
    int cnt = 0;
    for(int i=2; i<str.length()-1; i++){
        if(str[i] == 'C'){
            cnt++;
            idx = i;
        }
    }
    if(cnt != 1) flag = false;
    for(int i=1; i<str.length(); i++){
        if(i == idx) continue;
        if(str[i] >= 'A' && str[i] <= 'Z') flag = false;
    }
    if(flag) cout << "AC";
    else cout << "WA";
}


Measured memory_bytes: 256
function main(input){
    input = input.split('\n');
    const a = parseInt(input[0],10);
    const b = parseInt(input[1],10);
    const c = parseInt(input[2],10);
    const sum = parseInt(input[3],10);
    var count = 0;
    
    
    for(var i = 0; i <= a; i++){
        for(var j = 0; j <= b; j++){
            for(var z = 0; z <= c; z++){
                if((500*i) + (100*j) + (50*z) === sum){
                    count++;
                }
            }
        }
    }
    console.log(count);
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
    int dp[2][2][9][9]; //turn,last_l/r,left,right 
    string S;
    while(cin>>S,S!="#"){
        for(int lr=0;lr<2;lr++){
            for(int l=0;l<9;l++){
                for(int r=0;r<9;r++){
                    dp[0][lr][l][r]=((l==r||l%3>r%3)?100000000:0);
                }
            }
        }
        for(int s=1;s<=S.size();s++){
            //?????????
            for(int lr=0;lr<2;lr++){
                for(int l=0;l<9;l++){
                    for(int r=0;r<9;r++){
                        dp[s&1][lr][l][r]=100000000;
                    }
                }
            }
            int place = S[s-1]-'1';
            //????¶???§????????´???
            for(int r=0;r<9;r++){
                if(place%3>r%3||r==place) continue;
                for(int pre_l=0;pre_l<9;pre_l++){
                    dp[s&1][0][place][r]=min({dp[s&1][0][place][r],dp[s&1^1][1][pre_l][r],1+dp[s&1^1][0][pre_l][r]});
                }
            }

            //????¶???§????????´???
            for(int l=0;l<9;l++){
                if(l%3>place%3||l==place) continue;
                for(int pre_r=0;pre_r<9;pre_r++){
                    dp[s&1][1][l][place]=min({dp[s&1][1][l][place],dp[s&1^1][0][l][pre_r],1+dp[s&1^1][1][l][pre_r]});
                }
            }
        }
        int ans = 100000000;
        for(int lr=0;lr<2;lr++){
            for(int l=0;l<9;l++){
                for(int r=0;r<9;r++){
                    ans = min(ans, dp[S.size()&1][lr][l][r]);
                }
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3268
#include <stdio.h>
int main()
{
    int n,i;
    scanf("%d", &n);
    long int num[n];
    for(i=0; i<n; i++)
    {
        scanf("%ld",&num[i]);
    }
    long int sum=0;
    long int s=num[0];

    for(i=1; i<n; i++)
    {
        if(s>num[i])
        {
            int p = s-num[i];
            sum=sum+ p ;
            s=s;
        }
        else
        {
            s=num[i];
        }

    }
    printf("%ld\n\n",sum);

}


Measured memory_bytes: 3228
import java.util.Scanner;
         
                    public class Main{
                     public static void main (String[]args){
                    Scanner s=new Scanner(System.in);
                    String str=s.next();
                    if (str.contains("a")&&str.contains("b")&&str.contains("c")){
                         System.out.println("Yes");
                      }
                    else{
                    System.out.println("No");
                    }
                }
                }

Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
int main() {
    const int64_t l = 1000000007;
    int64_t  n,m;
    cin >> n >> m;
    queue<int64_t> a;
    int64_t aa;
    for(int64_t i = 0;i < m;i++) {
        cin >> aa;
        a.push(aa);
    }
    vector<int64_t> p(n + 1,1);
    p.at(0) = 1;
    p.at(1) = 1;
    for(int i = 0;i < m;i++) {
        p.at(a.front()) = 0;
        a.pop();
    }
    for(int64_t i = 0;i < n - 1;i++) {
        if(p.at(i + 2) != 0) {
            p.at(i + 2) = (p.at(i + 1) + p.at(i)) % l;
        }
    }
    cout << p.at(n) << endl;
}


Measured memory_bytes: 1792
//long time no ac
#include<bits/stdc++.h>
using namespace std;


#define     SPEED     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	ll          long long int
#define 	pb          push_back
#define 	pii         pair<int,int>
#define 	vi          vector<int>
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(i=0;i<n;i++)
#define 	repe(i,a,b) for(i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search
#define 	mp          make_pair

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}


int main()
{
	SPEED;
	ll n,k,t,c=0,i,j=0,m,cs=0;
	t=1;

	//cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>m>>k;
		// n=s.length();
		vll a(n);
		rep(i,n)
			cin>>a[i];
		// c=(n-m+1)*(n-k+1);
		for(auto v:a)
		{
			if(v<=m)
				c++;
			else if(v<=k)
				cs++;
			else
				j++;
		}
		cout<<min({c,cs,j});
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
vector<int>g[100000];
map<int,map<int,int>>c;
map<int,map<int,int>>idx;
map<int,map<int,int>>idx_g;
int ans[100000];
void dfs(int v,int pc){
    int tmp=0;
    for(int i=0;i<g[v].size();i++){
        if(c[v][g[v][i]]!=0)
            continue;
        tmp++;
        if(tmp==pc)
            tmp++;
        c[v][g[v][i]]=c[g[v][i]][v]=tmp;
        dfs(g[v][i],c[v][g[v][i]]);
    }
}
signed main(){
    int n,a,b;
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        g[--a].push_back(--b);
        g[b].push_back(a);
        idx_g[a][b]=g[a].size()-1;
        idx_g[b][a]=g[b].size()-1;
        idx[a][b]=i;
        idx[b][a]=i;
    }
    int k=0;
    for(int i=0;i<n;i++)
        k=max(k,(int)g[i].size());
    dfs(0,mod);
    for(int i=0;i<n;i++)
        for(int j=0;j<g[i].size();j++)
            ans[idx[i][g[i][j]]]=c[i][g[i][j]];
    cout<<k<<endl;
    for(int i=0;i<n-1;i++)
        cout<<ans[i]<<endl;
}


Measured memory_bytes: 72960
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
int main() {
    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    int z=-1;
    for (int i=0;i<n;i++) cin >> x[i];
    int ans=1e9;
    for (int l=0;l<=n-k;l++) {
        int r=l+k-1;
        ans=min(ans,min(abs(x[l])+abs(x[r]-x[l]),abs(x[r])+abs(x[r]-x[l])));
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
/*
    ->->->->-> Vora Mahammasasim <-<-<-<-<-
*/
#include<bits/stdc++.h>
#define Quick std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define MOD 1e7+7;
using namespace std;





void solve(){

    int a,b,c;
    cin>>a>>b>>c;
    if((float)a/c <= b) cout<<"Yes";
    else cout<<"No";

}

signed main(){

    Quick;
    int tt=1;
    //cin>>tt;
    for(int cas=1;cas<=tt;cas++){

        solve();

    }

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; ++i){
        int digit = to_string(i).length();
        if (digit % 2 == 1) ans += 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
n = gets.to_i
strings = []
n.times do
  strings << gets.chomp.split("").sort.join
end
strings.sort!
successive_nums = []
previous = ""
successive = 1
strings.each do |string|
  if string == previous
    successive += 1
  else
    previous = string
    if successive > 1
      successive_nums << successive
    end
    successive = 1
  end
end
if successive > 1
  successive_nums << successive
end

combinations = [0, 0]
2.upto(100001) do |index|
  combinations[index] = index * (index - 1) / 2
end

sum = 0
successive_nums.each do |successive_num|
  sum += combinations[successive_num]
end
puts sum


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

int main()
{
    int N;
    cin >> N;
    int A[N], B[N], C[N - 1];
    for (int i = 0; i < N; i++)
        cin >> A[i];
    for (int i = 0; i < N; i++)
        cin >> B[i];
    for (int i = 0; i < N - 1; i++)
        cin >> C[i];

    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += B[A[i] - 1];
        if (i > 0 && A[i] - A[i - 1] == 1)
            sum += C[A[i - 1] - 1];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

S = sys.stdin.readline().rstrip()
not_x = []

for i, s in enumerate(S):
    if s != "x":
        not_x.append(s)

not_x_nums = len(not_x)
mid = not_x_nums // 2

if not_x_nums % 2 == 1:
    left = not_x[:mid]
    right = not_x[mid + 1:][::-1]
else:
    left = not_x[:mid]
    right = not_x[mid:][::-1]

if left == right:
    ans = 0
    left = []
    right = []
    tmp = 0
    cnt = 0
    if not_x_nums % 2 == 1:
        mid += 1
    for s in S:
        if s != "x":
            left.append(tmp)
            tmp = 0
            cnt += 1
        else:
            tmp += 1
        if cnt == mid:
            break
    tmp = 0
    cnt = 0
    for s in S[::-1]:
        if s != "x":
            right.append(tmp)
            tmp = 0
            cnt += 1
        else:
            tmp += 1
        if cnt == mid:
            break
    for l, r in zip(left, right):
        ans += abs(l - r)
    print(ans)
else:
    print(-1)

Measured memory_bytes: 5244
#include <stdio.h>

long kaijo(long a){
    if(a>0)
        return(a*kaijo(a-1));
    else
        return(1);
}

int main(int argc, const char * argv[]) {
    unsigned long n;
    while(scanf("%ld",&n)!=EOF)
    printf("%ld\n",kaijo(n));
    
    return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const{
    for(int i=0;i<N2;i++){
      if(f[i]==p.f[i]) continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};

static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};

bool isT(Puzzle p){
  for(int i=0;i<N2;i++)
    if(p.f[i]!=(i+1)) return false;
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle,bool> V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;

  while(!Q.empty()){
    u=Q.front(); Q.pop();
    if(isT(u)) return u.path;
    int sx=u.space/N;
    int sy=u.space%N;
    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
       int ty=sy+dy[r];
       if(tx<0||ty<0||tx>=N||ty>=N) continue;
       v=u;
       swap(v.f[u.space],v.f[tx*N+ty]);
       v.space=tx*N+ty;
       if(!V[v]){
         V[v]=true;
         v.path+=dir[r];
         Q.push(v);

       }
    }
  }

  return "unsolvable";
}


int main(){
  Puzzle in;

  for(int i=0;i<N2;i++){
    cin >> in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans=bfs(in);
  cout << ans.size() << endl;

  return 0;
}





Measured memory_bytes: 30560
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 2*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   cin>>n;

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

   vector<int> v(n+1);

   vector<int> ans;

   for (int i = n; i >= 1; --i)
   {
      int tot = 0;
      for (int j = 2*i; j <= n; j+=i)
      {
         tot += v[j];
      }
      v[i] = (a[i] - tot + 2) % 2;
      if(v[i])
         ans.pb(i);
   }

   cout<<sz(ans)<<endl;
   for(auto i: ans)
      cout<<i<<' ';

   return 0;
}

Measured memory_bytes: 5108
import sys

INF = float('inf')


def Bellmanford(n, edges, r):  # r: 始点
    d = [INF] * n
    d[r] = 0

    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n - 1 and v == n - 1:
                    return 'inf'

    return -d[n - 1]


N, M = map(int, sys.stdin.readline().split())
Edges = [None] * M

for i in range(M):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    Edges[i] = (ai - 1, bi - 1, -ci)

ans = Bellmanford(N, Edges, 0)

print(ans)

Measured memory_bytes: 40304
#  --*-coding:utf-8-*--

MOD = 998244353

def modPow(a, b, mod):
    x = 1
    
    while b > 0:
        if b & 1:
            x = (x*a)%mod

        a = (a**2)%mod
        b //= 2

    return x


def main():
    N = int(input())
    D = list(map(int, input().split()))

    if D[0] != 0:
        print(0)
        return

    A = [0]*(max(D)+1)

    for d in D:
        A[d] += 1

    if A[0] > 1:
        print(0)
        return
    
    x = 1

    for i in range(1, len(A)):
        x *= modPow(A[i-1], A[i], MOD)
        x %= MOD

    print(x)



if __name__ == '__main__':
    main()


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

using namespace std;
#define ll long long int

void solve(){

	int N,n=1000;
	cin>>N;
    
    while(n<N){
    	n=n+1000;
    }

    cout<<n-N<<"\n";

}




int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

   
    solve();
   
    return 0;
}


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

int n, m;

int min_checkpoint_no(int aa, int bb, int c[], int d[]) {
    long dist = 10e8 * 4;
    int no;

    for (int i = 0; i < m; i++) {
        long dd = abs(aa - c[i]) + abs(bb - d[i]);
        if (dd < dist) {
            no = i;
            dist = dd;
        }
    }

    return no + 1;
}

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

    int a[n], b[n], c[m], d[m];

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

    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < n; i++) {
        cout << min_checkpoint_no(a[i], b[i], c, d) << endl;
    }

    return 0;
}


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

int main()
{
    int h;
    int max1 = 0, max2 = 0, max3 = 0;
    while (cin >> h)
    {
	if (max1 <= h)
	{
	    max3 = max2; max2 = max1; max1 = h;
	}
	else if (max2 <= h)
	{
	    max3 = max2; max2 = h;
	}
	else if (max3 <= h)
	{
	    max3 = h;
	}
    }
    cout << max1 << endl;
    cout << max2 << endl;
    cout << max3 << endl;
    return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int Q = sc.nextInt();

        long[] s = new long[A + 2];
        s[0] = (long) - 1e12;
        s[A + 1] = (long) 1e12;
        for (int a = 0; a < A; a += 1) {
            s[a + 1] = Long.parseLong(sc.next());
        }
        long[] t = new long[B + 2];
        t[0] = (long) - 1e12;
        t[B + 1] = (long) 1e12;
        for (int b = 0; b < B; b += 1) {
            t[b + 1] = Long.parseLong(sc.next());
        }

        for (int q = 0; q < Q; q += 1) {
            long xq = Long.parseLong(sc.next());
            long eastS = east(s, xq);
            long westS = west(s, xq);
            long eastT = east(t, xq);
            long westT = west(t, xq);
            search(xq, eastS, westS, eastT, westT);
        }
    }


    private static void search(long x, long eastS, long westS, long eastT, long westT) {
        long sFirst;
        long sFirstE = search(x, eastS, eastT, westT);
        long sFirstW = search(x, westS, eastT, westT);
        if (sFirstE < sFirstW) {
            sFirst = sFirstE;
        } else {
            sFirst = sFirstW;
        }

        long tFirst;
        long tFirstE = search(x, eastT, eastS, westS);
        long tFirstW = search(x, westT, eastS, westS);
        if (tFirstE < tFirstW) {
            tFirst = tFirstE;
        } else {
            tFirst = tFirstW;
        }

        if (sFirst < tFirst) {
            System.out.println(sFirst);
        } else {
            System.out.println(tFirst);
        }
    }

    private static long search(long x, long first, long toE, long toW) {
        long dist = Math.abs(first - x);
        long toEast = Math.abs(toE - first);
        long toWest = Math.abs(toW - first);
        if (toEast < toWest) {
            return dist + toEast;
        } else {
            return dist + toWest;
        }
    }


    private static long east(long[] st, long x) {
        int index = Arrays.binarySearch(st, x);
        if (index < 0) {
            index = -(index + 1);
        }

        if (st[index] - x > 0) {
            return st[index - 1];
        } else {
            return st[index];
        }
    }

    private static long west(long[] st, long x) {
        int index = Arrays.binarySearch(st, x);
        if (index < 0) {
            index = -(index + 1);
        }

        if (st[index] - x < 0) {
            return st[index + 1];
        } else {
            return st[index];
        }
    }

}


Measured memory_bytes: 96136
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

int waf(int from, int to)
{
	int d = to - from;
	if(d <= 0)
		return -d;
	if(d % 2 == 0)
		return d / 2;
	return (d + 1) / 2 + 1;
}

int main()
{
	int a, b, c;

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

	if(a > b)
		swap(a, b);
	if(a > c)
		swap(a, c);
	if(b > c)
		swap(b, c);

	int x = b - a;
	int y = c - a;

	int ans = 100000;

	for(int r = -1000; r < 1000; ++r) {

		int s = waf(0, r) + waf(x, r) + waf(y, r);
		ans = min(ans, s);
	}

	printf("%d\n", ans);

	return 0;
}

/* waffle */


Measured memory_bytes: 128
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		int count = 1;
		int now = 0;
		for (int i = 0; i < n; i++) {
			now += l[i];
			if (now <= x) {
				count++;
			}
		}
		System.out.println(count);
	}
}



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

int main()
{
    int n;
    std::cin>>n;
    std::string ans;

    while(n){
        if(n % 2 == 1 || n % 2 == -1)ans.push_back('1');
        else ans.push_back('0');
        //std::cerr << n << std::endl;
        if(n < 0){
            n--;
            n /= (-2);
        }else{
            n /= -2;
        }
    }
    if(ans.empty())ans = "0";
    std::reverse(ans.begin(),ans.end());
    std::cout<<ans<<std::endl;
}

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

bool Harmony(long A, long B){

    if((A+B)%2==0)
        return true;
    else
        return false;

}
int main(){

    long a,b;
    cin>>a>>b;

    if(Harmony(a,b))
        cout<< (a+b)/2<<endl;
    else
        cout<<"IMPOSSIBLE"<<endl;


    return 0;
}

Measured memory_bytes: 3640
import math


def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X % n)
    return str(X % n)


N, K = map(int, input().split())
res = int(Base_10_to_n(N, K))
ans = int(math.log10(res) + 1)
print(ans)


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

int pton(int p) {
	int cnt = 0;
	while ((p - 500) >= 0) {
		p -= 500;
		cnt++;
	}
	while ((p - 100) >= 0) {
		p -= 100;
		cnt++;
	}
	while ((p - 50) >= 0) {
		p -= 50;
		cnt++;
	}
	while ((p - 10) >= 0) {
		p -= 10;
		cnt++;
	}
	return cnt;
}

int main() {
	int flag = 0;
	while (1) {
		int i, j, k, l, a, b, c, d, ansa = 0, ansb = 0, ansc = 0, ansd = 0, minn = (1 << 20), p;
	
		cin >> p;
		if (p == 0)break;
		if (flag == 1)cout << endl;
		cin >> a >> b >> c >> d;

		for (i = 0; i <= a; i++) {
			for (j = 0; j <= b; j++) {
				for (k = 0; k <= c; k++) {
					for (l = 0; l <= d; l++) {
						if (10 * i + 50 * j + 100 * k + 500 * l >= p) {
							if (a - i + b - j + c - k + d - l + pton((10 * i + 50 * j + 100 * k + 500 * l) - p) < minn) {
								minn = a - i + b - j + c - k + d - l + pton((10 * i + 50 * j + 100 * k + 500 * l) - p);
								ansa = i;
								ansb = j;
								ansc = k;
								ansd = l;
							}
							break;
						}
					}
				}
			}
		}

		if (ansa > 0)cout << 10 << " " << ansa << endl;
		if (ansb > 0)cout << 50 << " " << ansb << endl;
		if (ansc > 0)cout << 100 << " " << ansc << endl;
		if (ansd > 0)cout << 500 << " " << ansd << endl;

		flag = flag | 1;
	}
	return 0;
}

Measured memory_bytes: 3028
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

typedef long long int ll;

int main(){


    ll n,k;
    cin >> n >> k;

    ll ans = 0;

    if(k % 2 == 1){
        ll tmp = n/k;
        ans = tmp*tmp*tmp;
    }else{


        ll puni = n/(k/2);

        ll odd = puni/2;
        ll even = puni-odd;

        ans = odd*odd*odd + even*even*even;
    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
set_dict = {}
chech_list = [0] * (n + 1)
for i in range(m):
    a, b = map(int, input().split())
    if a in set_dict:
        set_dict[a].add(b)
    else:
        set_dict[a] = {b}
    if b in set_dict:
        set_dict[b].add(a)
    else:
        set_dict[b] = {a}
    chech_list[a] = 1
    chech_list[b] = 1

ans = 1
for i in range(1, n + 1):
    if chech_list[i] == 0:
        continue
    count = 0
    temp_set = set_dict[i]
    while len(temp_set) > 0:
        x = temp_set.pop()
        count += 1
        chech_list[x] = 0
        for y in set_dict[x]:
            if chech_list[y] == 1:
                temp_set.add(y)
    ans = max(count, ans)
print(ans)


Measured memory_bytes: 86372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

int a[100005];

signed main(){
	
	int n;cin>>n;
	rep(i,n) a[i]=0;
	
	int ans = 0;
	rep(i,n)
	{
		int x;cin>>x;
		if(x>n)ans++;
		else a[x]++;
	}
	
	rep(i,n+1)
	{
		if(i<a[i]) ans += a[i]-i;
		else if (i>a[i]) ans +=a[i];
	}
	
	cout << ans << endl;
	
	
}
 

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N;
int d[50];

int main() {
    cin >> N;
    rep(i,N) cin >> d[i];
    ll ans = 0;
    rep(i,N) {
        for (int j = i+1; j < N; j++) {
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int num(string s,int& i);
int calc(string s,int& i);
int x;

bool isnum(char c){
    int y=c-'a';
    return (y>=0)&&(y<=3);
}
int calc(string s,int& i){
    if(isnum(s[i]))return num(s,i);
    i++;
    char op=s[i];
    i++;
    int ret=calc(s,i);
    int res=calc(s,i);
    i++;
    if(op=='+')return ret|res;
    if(op=='*')return ret&res;
    if(op=='^')return ret^res;
    return 0;
}

int num(string s,int& i){
    i++;
    if(s[i-1]=='a')return x/1000;
    if(s[i-1]=='b')return (x/100)%10;
    if(s[i-1]=='c')return (x/10)%10;
    if(s[i-1]=='d')return x%10;
    return 0;
}
int main(){
    string s;
    while(cin>>s,s!="."){
        map <int,int> mp; 
        rep(i,10000){
            x=i;
            int j=0;
            mp[calc(s,j)]++;
        }
        int n;cin>>n;
        x=n;
        int j=0;
        int ans=calc(s,j);
        cout<<ans<<" "<<mp[ans]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define int long long 
const long long INF = 1LL << 60;
#define MAX_V 100100
using P = pair<int,int>;
struct edge{
    int to;
    int cost;
};
vector <edge> G[MAX_V]; //グラフ
vector <int> d(MAX_V, INF);// 距離

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    d[s] = 0;
    que.push(P(0,s)); // 今までのコストと現在地
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v]< p.first) continue;
        
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

signed main(void){
    int n; cin>>n;
    
    for(int i=0;i<n-1;i++){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    int q,k; cin>>q>>k;
    k--;
    dijkstra(k);
    for(int i=0;i<q;i++){
        int a,b; cin>>a>>b; a--; b--;
        cout<<d[a] + d[b]<<endl;
    }
}


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

const int MAX = 1000000;
bool A[MAX];

int main() {
    int n;
    string s, t;
    cin >> n;
    cin >> s >> t;
    for (int i = 0; i < n; ++i) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
from collections import defaultdict


def main():
    h, w = map(int, input().split())

    d = defaultdict(int)
    for _ in range(h):
        for i in input():
            d[i] -= 1
    char = list(d.values())
    heapq.heapify(char)

    hd, hm = divmod(h, 2)
    wd, wm = divmod(w, 2)
    pair = [-2] * hd + [-1] * hm
    pair = [i * 2 for i in pair]*wd + pair*wm
    heapq.heapify(pair)

    while char:
        tmp = heapq.heappop(char) - heapq.heappop(pair)
        if tmp > 0:
            return "No"
        if tmp == 0:
            continue
        heapq.heappush(char, tmp)
    return "Yes"


if __name__ == "__main__":
    ans = main()
    print(ans)


Measured memory_bytes: 3316
from collections import deque

n, k = map(int, input().split())
v = list(map(int, input().split()))

m = min(k, n)
res = 0
for A in range(0, m + 1):
    for B in range(0, m + 1):
        if A + B > m:
            continue
        if B == 0:
            L = v[:A]
        else:
            L = v[:A] + v[-B:]
        L.sort()
        L = deque(L)
        num = k - (A + B)
        for i in range(num):
            if len(L) == 0:
                continue
            elif len(L) == 1:
                if L[0] < 0:
                    L.pop()
            else:
                Remove = L.popleft()
                if Remove > 0:
                    L.appendleft(Remove)
        res = max(res, sum(L))

print(res)

Measured memory_bytes: 42600
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        int m = (int)1E9 + 7;
        long sum = 1;

        for (int i = 1; i <= n; i++) {
            sum *= i;
            sum %= m;
        }

        System.out.println(sum);

    }
}


Measured memory_bytes: 22740
n=int(input())
said=[]
for i in range(n):
    a=int(input())
    said.append([list(map(int,input().split())) for _ in range(a)])
ans=0
for i in range(2**n):
    l=[0]*n
    for j in range(n):
        if (i>>j&1):
            l[j]=1
    flag=True
    for k in range(n):
        if l[k]==1 and (not all(said[k][x][1]==l[said[k][x][0]-1] for x in range(len(said[k])))):
            flag=False
            break
    if flag==True and l.count(1)>ans:
        ans=l.count(1)
print(ans)

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
const int N = 200000 * 2;

vector<bool> isPrime(N, true);

void makePrime(){
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i < N; i++){
        if(!isPrime[i]) continue;
        for(int j = i + i; j < N; j += i) isPrime[j] = false;
    }
}

int main(){
    makePrime();
    int n;
    while(cin >>n && n){
        int ans = 0;
        FOR(i, n + 1, 2 * n + 1) if(isPrime[i]) ans++;
        cout <<ans <<endl;
    }
    return 0;
}

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

int i, j, k, n, m, s, t, z, w, a[10001];

int main()
{
	cin >> n >> z >> w;
	for (i = 1; i <= n; i++) cin >> a[i];
	if (n == 1) cout << abs(a[1] - w) << endl;
	else cout << max(abs(a[n] - w), abs(a[n - 1] - a[n])) << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N,T=map(int,input().split())
A=list(map(int,input().split()))

m=A[N-1]
maxlist=[A[N-1]]
for i in range(1,N):
    a=A[-i-1]
    m=max(m,a)
    maxlist.append(m)

maxlist=maxlist[::-1]

benefit=defaultdict(int)

for i in range(0,N-1):
    b=-A[i]*(T//2)+maxlist[i+1]*(T//2)
    benefit[b]+=1

ans=0
for key in benefit.keys():
    if benefit[key]>0 and key>ans:
        ans=key

print(benefit[ans])

Measured memory_bytes: 71828
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	string s; cin >> s;
	int n = s.size();
	int ans = 0;

	rep(i, n / 2) {
		if (s[i] != s[n - 1 - i]) ans++;
	}

	dunk(ans);
	return 0;
}


Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, Z, W = map(int, input().split())

A = list(map(int, input().split()))

if N == 1:
    print(abs(A[-1] - W))
else:
    print(max(abs(A[-1] - W), abs(A[-1] - A[-2])))


Measured memory_bytes: 3804