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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e18 + 5);

const int MAX_N = (int)(2e5 + 5);
const ll MAX_K = (int)(1e12 + 5);
const int MAX_LOG_NK = (int)(67);

int n;
ll k;
int a[MAX_N];

vector<int> s;
bool exist[MAX_N];
ll doubling[MAX_LOG_NK][MAX_N];

int make_doubling() {
  unordered_map<int, int> ump;

  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < n; ++j) {
      int ind = i * n + j;

      if (ump.find(a[ind % n]) == ump.end()) {
        ump[a[ind % n]] = ind;
      } else {
        int start = ump[a[ind % n]];

        if (start >= n) continue;

        doubling[1][start] = ind + 1 - start;
        ump.erase(a[ind % n]);
        ump[a[ind % n]] = ind;
      }
    }
  }

  int upper = min((int)(ceil(log2(n * k))), MAX_LOG_NK);

  for (int i = 2; i < upper; ++i) {
    for (int j = 0; j < n; ++j) {
      ll fst_buff = doubling[i - 1][j];
      int fst_ind = ((ll)(j) + fst_buff) % n;
      ll snd_buff = doubling[i - 1][fst_ind];

      doubling[i][j] = (fst_buff + snd_buff);
      doubling[i][j] = (doubling[i][j] >= INF) ? INF : doubling[i][j];
    }
  }

  // for (int i = 1; i < upper; ++i) {
  //   printf("%d: ", i);
  //   for (int j = 0; j < n; ++j) {
  //     printf("%lld ", doubling[i][j]);
  //   }
  //   printf("\n");
  // }

  return upper;
}

ll fast_simulate(int upper) {
  ll last = 0LL;

  while (true) {
    int ind = (int)(last % (ll)(n));
    bool flg = false;

    for (int i = upper - 1; i >= 1; --i) {
      if (last + doubling[i][ind] < (ll)(n) * k) {
        last += doubling[i][ind];
        flg = true;
        break;
      }
    }

    // printf("%lld\n", last);

    if (!flg) {
      return last;
    }
  }
}

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &k);

  for (int i = 0; i < n; ++i) {
    scanf("%d", &(a[i]));
  }

  int upper = make_doubling();

  ll jump = fast_simulate(upper);

  for (ll j = jump; j < (ll)(n) * k; ++j) {
    int ind = (int)(j % (ll)(n));

    bool flg = false;

    while (exist[a[ind]]) {
      flg = true;
      exist[s.back()] = false;
      s.pop_back();
    }

    if (!flg) {
      s.push_back(a[ind]);
      exist[a[ind]] = true;
    }

    // printf("ind: %3lld - ", j);
    // for (auto &e : s) {
    //   printf("%d ", e);
    // }
    // printf("\n");
  }

  for (auto &e : s) {
    printf("%d ", e);
  }
  printf("\n");

  return 0;
}


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

wa = [0] * n
ac = [False] * n
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "WA":
        if not ac[p]:
            wa[p] += 1
    else:
        ac[p] = True

wa_count = 0
for i in range(n):
    if ac[i]:
        wa_count += wa[i]

print(sum(ac), wa_count)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=1e9+7107;
int n,m,k,s;
int main()
{
	scanf("%d%d%d",&n,&m,&s);
	if(n>m) swap(n,m);
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++) 
		{
			//printf("i=%d j=%d ans=%d\n",i,j,i*n+j*m-2*i*j);
			if(i*n+j*m-2*i*j==s)
			{
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h> 
#include<string>
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define IN insert
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define NL cout<<endl
#define ll long long int
#define ld long double
#define vl vector<ll>
#define sl set<ll>
#define ml map<ll,ll>
#define sc set<char>
#define li list<ll>
#define vp vector<pair<ll, ll> >
#define vs vector<string>
#define ss set<string>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define REPIT(it,a) for(auto it=a.begin();it!=a.end();it++)
#define DB(x) cout<<"Debug "<<x<<endl
#define N 1e16
#define mod (ll)1000000007
using namespace std;

int main()
{

ios::sync_with_stdio(0);
cin.tie(0);
ll n,k;
cin>>n>>k;
ll h[n];
REP(i,0,n) cin>>h[i];
vl dp(n,N);
dp[0]=0;
REP(i,0,n){
 REP(j,1,k+1){
  if(i+j<n)
   dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
 }
}
cout<<dp[n-1]<<endl;
return 0;
}

Measured memory_bytes: 1792
// 問題の URL を書いておく
// 

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
#include <string>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

const int M = 2019;
int main(int, const char**)
{
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    vector<int> counts(M, 0);
    int sum = 0;
    int64_t ans = 0;
    int mul = 1;
    for(auto ss : s)
    {
        counts[sum]++;
        auto adder = ((ss - '0') * mul) % M;
        sum = (sum + adder) % M;
        ans += (counts[sum]);
        mul = (mul * 10) % M;
    }

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


Measured memory_bytes: 3728
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main (string[] args) {
        var inp = Console.ReadLine().Split(' ');
        //char[] T = inp[0].ToCharArray();

        char[] T = new char[inp[0].Length];
        for(int i = 0;i < T.Length;i++) {
            T[i] = inp[0][i] == '?' ? 'D' : inp[0][i];
        }

        Console.WriteLine(T);
    }
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        String a = sc.next();

        if (a.equals("ABC"))
            System.out.println("ARC");
        else
            System.out.println("ABC");
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 25448
N, M = [int(_) for _ in input().split()]
T = [[int(_) - 1 for _ in input().split()] for i in range(M)]

graph = [[] for i in range(N)]
for a, b in T:
    graph[a].append(b)
    graph[b].append(a)


def dfs(node, prev, visited):
    visited.append(node)
    if len(visited) == N:
        return 1

    res = 0
    for edge in graph[node]:
        if edge == prev:
            continue
        if edge in visited:
            continue

        res += dfs(edge, prev, visited[:])

    return res

print(dfs(0, -1, []))

Measured memory_bytes: 3064
#include<stdio.h>
int BinarySearch(int*,int,int);
int main(){

  int i;
  int n,q;
  int count=0;

  scanf("%d",&n);
  int data1[n];
  for(i=0;i<n;i++){
    scanf("%d",&data1[i]);
  }
  
  scanf("%d",&q);
  int data2[q];
  for(i=0;i<q;i++){
    scanf("%d",&data2[i]);
  }

  for(i=0;i<q;i++){
    if(BinarySearch(data1,n,data2[i])==1){
      count++;
    }
  }
  printf("%d\n",count);
  
  return 0;
}
int BinarySearch(int *data,int n,int key){
  
  int left=0,mid,right;
  
  right=n;
  while(left<right){
    mid=(left+right)/2;
    if(key==data[mid]) return 1;
    if(key>data[mid]) left=mid+1;
    else if(key<data[mid]) right=mid;
  }
  return 0;
}



Measured memory_bytes: 2296
N = int(input())
S = list(input())
before = ""
after = ""
if N % 2 != 0:
  print("No")
else:
  for i in range(N//2):
  	before += S[i]
  for j in range(N//2, N):
    after += S[j]
  if before == after:
    print("Yes")
  else:
    print("No")
    


Measured memory_bytes: 3060
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
(S,T) = input().split()
(A, B) = list(map(int,input().split()))
U = input()

if U == S:
    print(A-1,B)
else:
    print(A,B-1)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int ans[100000],check[100000];
int main(){
  int n;
  cin>>n;
  vector<int> v;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a;
    if(a==0){
      cin>>b;
      v.push_back(b);
    }
    if(a==1){
      cin>>b;
      cout<<v[b]<<endl;
    }
    if(a==2){
      v.pop_back();
    }
  }
      
  return 0;
}


Measured memory_bytes: 3852
import java.io.*;
   
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String line;
        LOOP: while ((line = input.readLine()) != null) {
            int line_len = line.length();
            if (line_len == 1 && line.charAt(0) == '0')
                break LOOP;
            long total = 0;
            for (int i = 0; i < line_len; i++) {
                total += line.charAt(i) - '0';
            }
            System.out.println(total);
        }
    }
}

Measured memory_bytes: 24268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			List<Integer> ret = new ArrayList<Integer>();
			int n, x;
			do {
				String[] inputList = br.readLine().split(" ");
				n = Integer.parseInt(inputList[0]);
				x = Integer.parseInt(inputList[1]);
				if (n == 0 && x == 0) {
					break;
				} else {
					if (x < 6) {
						ret.add(0);
					} else {
						List<int[]> hoge = new ArrayList<int[]>();
						int a, b, c;
						for (a = 1; a <= n; a++) {
							for (b = 1; b <= n; b++) {
								for (c = 1; c <= n; c++) {
									if (!(a == b || b == c || a == c) && a + b + c == x) {
										boolean flg = true;
										for (int[] list : hoge) {
											if ((list[0] == a || list[0] == b || list[0] == c)
													&& (list[1] == a || list[1] == b || list[1] == c)
													&& (list[2] == a || list[2] == b || list[2] == c)) {
												flg = false;
												break;
											}
										}
										if (flg) {
											int[] tmp = new int[3];
											tmp[0] = a;
											tmp[1] = b;
											tmp[2] = c;
											hoge.add(tmp);
											break;
										}
									}
								}
							}
						}
						ret.add(hoge.size());
					}
				}
			} while (true);
			for (int num : ret) {
				System.out.println(num);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 27284
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, ans = 1;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int64_t a;
        cin >> a;
        ans = ans / __gcd(ans, a) * a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<int64_t> a(n),b(n),d(n);
  for(auto&& e: a) {
    cin>>e;
  }
  for(auto&& e: b) {
    cin>>e;
  }
  for (int i = 0; i < n; ++i)
  {
    d[i]=a[i]-b[i];
  }
  int64_t cnt=0;
  for(auto&& e: d) {
    if(e>0) cnt-=e;
    else cnt+=abs(e)/2;
  }

  cout<<(cnt<0? "No":"Yes");

}

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

int main(void){

  int r, c;
  int i, j;

  scanf("%d %d", &r, &c);

  int s[r][c];
  int sumr[r], sumc[c];
  int sum = 0;

  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      scanf("%d", &s[i][j]);
    }
  }

  for(i = 0; i < r; i++){
    sumr[i] = 0;
    for(j = 0; j < c; j++){
      sumr[i] += s[i][j];
    }
  }

  for(j = 0; j < c; j++){
    sumc[j] = 0;
    for(i = 0; i < r; i++){
      sumc[j] += s[i][j];
    }
  }

  for(i = 0; i < r; i++){
    sum += sumr[i];
  }

  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      printf("%d ", s[i][j]);
    }
    printf("%d\n", sumr[i]);
  }
  for(j = 0; j < c; j++){
    printf("%d ", sumc[j]);
  }
  printf("%d\n", sum);

  return 0;
}


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


int main() {

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] = s[k-1] - 'A' + 'a';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
// ARC093
// D - Grid Components

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int H = 100, W = 100;
char wb[2] = {'.', '#'};

int AB[2];
char ans[H][W];

void solve() {
    int cnt[2] = {0, 0};
    for (int i = 0; i < H; i++) {
        int p = i / (H / 2);
        for (int j = 0; j < W; j++) {
            int q = ((i - p * (H / 2)) % 2) * (j % 2);
            cnt[p] += q;
            int r = (cnt[p] <= AB[p] - 1) ? 1 : 0;
            ans[i][j] = wb[(p + q * r + 1) % 2];
        }
    }
}

int main() {
    cin >> AB[0] >> AB[1];

    solve();

    cout << H << " " << W << endl;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define 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))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
int H, W;
vector<string> A;
int d[1000][1000];
vector<vector<bool>> went;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    cin >> H >> W;
    A.resize(H);
    REP(i, H) cin >> A[i];
    queue<Pair> q;
    REP(i, H) REP(j, W) {
        d[i][j] = INF;
        if(A[i][j] == '#') {
            q.push({i, j});
            d[i][j] = 0;
        }
    }
    while(!q.empty()) {
        Pair p = q.front();
        q.pop();
        REP(i, 4) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(0 <= nx && nx < H && 0 <= ny && ny < W && A[nx][ny] == '.') {
                A[nx][ny] = '#';
                q.push({nx, ny});
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int ans = 0;
    REP(i, H) REP(j, W) { ans = max(ans, d[i][j]); }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 13328
n = int(input())
s = [input() for i in range(n)]
ss = ""
ans = 0
t1, t2, t3 = 0, 0, 0
for e in s:
  ans += e.count("AB")
  if e[0] == "B" and e[-1] == "A":
    t3 += 1
  elif e[0] == "B":
    t1 += 1
  elif e[-1] == "A":
    t2 += 1
if t3:
  ans += t3-1
if t3 and t1:
  t1 -= 1
  ans += 1
if t3 and t2:
  t2 -= 1
  ans += 1
ans += max(0, min(t1, t2))
print(ans)

Measured memory_bytes: 44248
#!python3

LI = lambda: list(map(int, input().split()))

# input
N = int(input())
UV = [LI() for _ in range(N - 1)]


def main():
    ans = N * (N + 1) * (N + 2) // 6
    for u, v in UV:
        if u > v:
            u, v = v, u
        ans -= u * (N - v + 1)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 45364
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();

			if(n * a < b) {
				System.out.println(n * a);
			} else {
				System.out.println(b);
			}
		}
	}
}


Measured memory_bytes: 22608
import java.util.Scanner;

class Crop{
	String name;
	double re;//revenue efficiency
	int sum;
	
	Crop(String str,int p,int a,int b,int c,int d,int e,int f,int s,int m){
		this.name=str;
		sum=a+b+c+(d+e)*m;
		re=((s*m*f-p)*1.0)/(sum*1.0);
	}
}

public class Main {
	void run(){
		Scanner sc=new Scanner(System.in);
		int n;
		Crop c[];
		while(true){
			n=sc.nextInt();
			if(n==0) break;
			c=new Crop[n];
			for(int i=0;i<n;i++){
				c[i]=new Crop(sc.next(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
			}
			int max;
			for(int i=0;i<n;i++){
				max=i;
				for(int j=i;j<n;j++){
				if(Math.abs(c[j].re-c[max].re)<0.0000000001){
						if(c[max].name.compareTo(c[j].name)>0){
							max=j;
						}
					}
					else if(c[max].re<c[j].re){
						max=j;
					}
				}
				Crop temp=c[i];
				c[i]=c[max];
				c[max]=temp;
			}
			for(int i=0;i<n;i++){
				//System.out.println(c[i].name+" "+c[i].re+" "+c[i].sum);
				System.out.println(c[i].name);
			}
			System.out.println("#");
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();
        s = s.Substring(0, 4) + s.Substring(5, 2) + s.Substring(8, 2);
        int i = int.Parse(s);

        string answer = i <= 20190430 ? "Heisei" : "TBD";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll ceil(ll a, ll b) {
    if(a%b == 0) {
        return a/b;
    }
    else {
        return a/b + 1;
    }
}

int main() {
    int n;
    cin >> n;
    ll T[n+1], A[n+1];
    for(int i = 1; i <= n; i++) {
        cin >> T[i] >> A[i];
    }

    ll takahashi[n+1], aoki[n+1];
    takahashi[0] = 1LL;  aoki[0] = 1LL;

    for(int i = 0; i < n; i++) {
        ll s = ceil(takahashi[i], T[i+1]);
        ll t = ceil(aoki[i], A[i+1]);
        ll m = max(s, t);
        takahashi[i+1] = m*T[i+1];
        aoki[i+1] = m*A[i+1];
    }

    cout << takahashi[n] + aoki[n];    
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int Max(int x,int y){
        return x>y?x:y;
}
int Min(int x,int y){
        return x>y?y:x;
}
int recoursion(int x , int y){
        if(y==0)
                return x;
        return recoursion(y,x%y);
}
int main(){
        int x,y;
        cin >> x>>y;
        cout << recoursion(Min(x,y),Max(x,y)%Min(x,y)) << endl;
        return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M 			200011
#define LN             14
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
}

vii g[26];
ll a[M],B[M];

ll get(ll x){
	ll r=0;
	for(;x>=1;x-=x&-x)r+=B[x];return r;
}
ll up(ll x,ll val){
	for(;x<M;x+=x&-x)B[x]+=val;
}

int main(){
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    cin>>s1>>s2;
    n=s1.size();m=s2.size();
    for(i=0;i<n;++i)g[s1[i]-'a'].pb(i+1);
    ll c=0;
	ll ans=0;
	for(i=0;i<m;++i){
		ll id=s2[i]-'a';
		// trace(c,id);
		if(g[id].sz()==0){
			cout<<"-1\n";die();
		}
		if(g[id].back()>c){
			// trace(g[id].back());
			x=-1;p=g[id].size();
			for(;p>=1;p/=2){
				while(x+p<g[id].sz()&&g[id][x+p]<=c)x+=p;
			}
			x++;
			c=g[id][x];
			// trace(c);

		}
		else{
			ans++;
			c=g[id][0];
		}
	}
	cout<<ans*n+c<<"\n";





    





    	






    

}



Measured memory_bytes: 1736
use proconio::input;

fn main() {
    input! {
        n: usize,
        p: [f64; n],
    };

    let mut dp = vec![0f64;n+1];
    dp[0] = 1.;

    for i in 0..n {
        for j in (1..=i+1).rev() {
            dp[j] = dp[j]*(1.-p[i]) + dp[j-1]*p[i];
        }
        dp[0] = dp[0]*(1.-p[i]);
    }

    let mut ans = 0.;
    for j in (n/2+1)..=n {
        ans += dp[j];
    }

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


Measured memory_bytes: 2260
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
  ll n,p;
  cin >> n >> p;

  vector<ll> div;
  for(ll i = 1;i * i <= p;i++){
    if(p % i == 0){
      div.push_back(i);
      div.push_back(p/i);
    }
  }

  ll ans = 1;
  for(ll now:div){
    if(now == 1)continue;
    ll cnt = 0;
    ll pp = p;
    while(true){
      if(pp % now == 0){
        cnt++;
        pp /= now;
      }
      else break;
    }
    if(cnt >= n)ans = max(ans,now);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define umapii unordered_map<int,int>
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
using namespace std;

int32_t main(){
    FAST;
    int n;  cin>>n;
    int a[n];   for(int x=0;x<n;x++)    cin>> a[x];

    int x = 0;

    for(int i =0 ;i<n;i++)
        x ^= a[i];

    cout << ( x== 0 ? "Yes" : "No") << endl;


    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

using namespace std;

int main() {
  int h, w, x, y;
  cin >> h >> w >> x >> y;
  cout << (h -x) * (w - y) << '\n';
  return 0;
}


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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,c,k,ans=0,sum=0;
    cin>>n>>c>>k;
    ll a=-1000000009,t[n];
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    sort(t,t+n);
    for(int i=0;i<n;i++){
        if(sum!=c&&a+k>=t[i]){
            sum++;
        }
        else{
            a=t[i];
            ans++;
            sum=1;
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 4e5 + 5, M = 2 * N + 5;

int n, a[N];
map<int, int> cnt;

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    scanf("%d", &n);
    for(int i = 0 ; i < n ; ++i){
        scanf("%d", a + i);
        ++cnt[i - a[i]];
    }
    ll ans = 0;
    for(int i = 0 ; i < n ; ++i){
        --cnt[i - a[i]];
        int nw = i + a[i];
        if(nw < n)
            ans += cnt[nw];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 14776
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,m:usize,
        s:[i64;n],
        t:[i64;m],
    }
    let mut dp = vec![vec![0; m + 1]; n + 1];
    dp[0][0] = 1;
    for i in 0..=n {
        for j in 0..=m {
            if i >= 1 && j >= 1 && s[i - 1] == t[j - 1] {
                dp[i][j] += dp[i - 1][j - 1];
            }
            if i >= 1 {
                dp[i][j] += dp[i - 1][j];
            }
            if j >= 1 {
                dp[i][j] += dp[i][j - 1];
            }
            if i >= 1 && j >= 1 {
                dp[i][j] -= dp[i - 1][j - 1];
            }
            dp[i][j] = (dp[i][j] + MOD) % MOD;
        }
    }
    println!("{}", dp[n][m]);
}
const MOD: i64 = 1000000007;


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

using namespace std;

using int64 = long long;

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

  int h, w;
  cin >> h >> w;
  int count = 0;
  for (int i = 0; i < h; i++) {
    string line;
    cin >> line;
    for (char c : line) {
      if (c == '#') count++;
    }
  }
  if (count == h + w - 1) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}


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

int main(){
  int A,B,Q;
  cin >> A >> B >> Q;
  vector<long long> s(A),t(B),x(Q);
  for(int i=0;i<A;i++)cin >> s[i];
  for(int i=0;i<B;i++)cin >> t[i];
  for(int i=0;i<Q;i++)cin >> x[i];
  for(int i=0;i<Q;i++){
    int su=upper_bound(s.begin(),s.end(),x[i])-s.begin();
    su=min(su,A-1);
    int sd=su-1;
    sd=max(sd,0);
    int tu=upper_bound(t.begin(),t.end(),x[i])-t.begin();
    tu=min(tu,B-1);
    int td=tu-1;
    td=max(td,0);
    long long ans=LLONG_MAX;
    for(auto k=sd;k<=su;k++){
      for(auto j=td;j<=tu;j++){
        ans=min(ans,abs(x[i]-s[k])+abs(s[k]-t[j]));
        ans=min(ans,abs(x[i]-t[j])+abs(s[k]-t[j]));
      }
    }
    cout << ans << endl;
  }
}

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

int main(){
    int D;
	cin >> D;
  	if(D == 25){
    	cout << "Christmas" << endl;
    }else if (D == 24){
    	cout << "Christmas Eve" << endl;
    }else if (D == 23){
    	cout << "Christmas Eve Eve" << endl;
    }else if (D == 22){
    	cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#define N 100001

using namespace std;

vector<int> adj[N];
int prenum[N], parent[N], lowest[N], timer = 1;
bool visited[N];

void dfs (int u, int prev) {
  prenum[u] = lowest[u] = timer++;
  visited[u] = true;

  //printf("u = %d, deep = %d\n", u, deep);

  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];

    if (!visited[v]) {
      parent[v] = u;

      dfs(v, u);

      lowest[u] = min(lowest[u], lowest[v]);
    } else if (v != prev) {
      lowest[u] = min(lowest[u], prenum[v]);
    }
  }
}

int main () {
  int V, E, u, v;

  cin >> V >> E;

  for (int i = 0; i < V; i++)
    visited[i] = false;

  for (int i = 0; i < E; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  dfs(0, -1);

  int np = 0;
  set<int> S;

  for (int v = 1; v < V; v++) {
    int p = parent[v];

    // cout << "p = " << p << endl;

    if (p == 0)
      np++;
    else if (prenum[p] <= lowest[v])
      S.insert(p);
  }

  // cout << "np = " << np << endl;

  if (np > 1) {
    S.insert(0);
  }

  for (set<int>::iterator it = S.begin(); it != S.end(); it++)
    cout << *it << endl;

  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n;
  cin >> n;
  int sum = 0;
  rep (i, n) {
    int a;
    (cin >> a);
    sum += a - 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import sys

class Solution(object):
    def __init__(self):
        a = sys.stdin.readline().split()
        if len(a) != 2: return
        self.A = int(a[0])
        self.B = int(a[1])

    def get_open_window(self):
        if 2*self.B >= self.A:
            return 0
        return self.A - (2*self.B)

if __name__ == "__main__":
    s = Solution()
    print(s.get_open_window())

Measured memory_bytes: 3060
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);

	int a = scan.nextInt();
	int b = scan.nextInt();




	System.out.println((a-1)*(b-1));

	}
}


Measured memory_bytes: 21716
#include <stdio.h>
    #include <stdlib.h>

    int main()
    {   int n,m,i,j,a,b,c,d;
        while(~scanf("%d %d %d %d",&a,&b,&c,&d))
        {
            if(a>=b)
            {
                n=b;
            }
            else
            {
                n=a;
            }
            if(c>=d)
            {
                m=d;
            }
            else
            {
                m=c;
            }
            printf("%d\n",n+m);
        }
        return 0;
    }


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    int x,y,z;
    while(scanf(" %d %d %d",&x,&y,&z),x|y|z)
    {
        //????????¬????????????
        vector<int> v(x);
        rep(i,x) scanf(" %d", &v[i]);

        //i???????????§?????????????????????
        vector<pi> event(y+1,pi(0,0));
        rep(i,z)
        {
            int n,e,a;
            scanf(" %d %d %d",&n,&e,&a);
            event[n]=pi(e,a);
        }

        //i??????????????????j?????§???????¢????
        double dp[51][5000]={0};
        dp[0][0]=1;

        rep(i,y)
        {
            rep(j,x)
            {
                int next=i+v[j];
                if(next>y)
                {
                    //goal
                    rep(k,5000) dp[y][k]+=dp[i][k]/x;
                }
                else
                {
                    if(event[next].fi==0)
                    {
                        //no event
                        rep(k,5000) dp[next][k]+=dp[i][k]/x;
                    }
                    else if(event[next].fi==1)
                    {
                        //go ahead
                        next+=event[next].se;
                        next=min(next,y);
                        rep(k,5000) dp[next][k]+=dp[i][k]/x;
                    }
                    else if(event[next].fi==2)
                    {
                        //earn money
                        for(int k=0; k+event[next].se<5000; ++k)
                        dp[next][k+event[next].se]+=dp[i][k]/x;
                    }
                    else if(event[next].fi==3)
                    {
                        //lose money
                        rep(k,event[next].se) dp[next][0]+=dp[i][k]/x;
                        for(int k=event[next].se; k<5000; ++k)
                        dp[next][k-event[next].se]+=dp[i][k]/x;
                    }
                }
            }
        }

        double ans=0;
        rep(i,5000) ans+=i*dp[y][i];
        printf("%d\n", (int)ans);
    }
    return 0;
}

Measured memory_bytes: 5192
<?php
$n = fgets(STDIN);
$ans=0;
for($i=1;$i<=$n;$i++){
	$hati=0;
	if($i%2==1){
		for($k=1;$k<=$i;$k++){
			if($i%$k==0){
				$hati++;
			}
		}
		if($hati==8){
			$ans++;
		}
	}
}
echo $ans;

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void){
  
  IN(N);
  vl a(N);
  REP(i, N) {
    IN(a[i]);
  }
  ll next = 1;
  REP(i, N) {
    if (a[i] == next) next++;
    else ret++;
  }
  PRINT((ret==N)?-1:ret);

}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S, T;
  cin >> S >> T;

  bool ans = false;
  for(int i=0;i<=SZ(S);++i){
    ans |= (S == T);
    char t = S.back();
    for(int i=SZ(S)-1;i>0;--i) S[i] = S[i-1];
    S[0] = t;
  }
  cout << (ans? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
count = 0
for v in c.values():
    if v != 1:
        count += v-1
#print(count)
if count % 2 == 0:
    print(len(c.keys()))
else:
    print(len(c.keys())-1)



Measured memory_bytes: 98324
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define fi first
#define se second
#define pb push_back
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define L(i,u) for (int i=head[u]; i!=0; i=edge[i].nxt)
#define abs(a) ((a)>0 ? (a) : -(a))
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
typedef long long ll;
typedef long double ld;
const int N = 100200;
int s[35],t[35];
int n,k,l,Bit[35];
int a[N],b[N];
ll ans;

inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
	while (c>='0'&&c<='9') {x=10*x+c-'0'; c=getchar();} x*=f;
}
inline int getnum(int *t) {
	int num=1,res=0;
	rep(i,1,l) {
		res+=num*(t[i]);
		num<<=1;
	}
	return res;
}
inline void getans(int k) {
	ll res=0;
	per(i,n,1) if ((k&a[i])==a[i]) res+=b[i];
	ans=max(ans,res);
//	printf("%d %d %d %d %lld\n",t[1],t[2],t[3],k,res);
}
int main() {
	read(n); read(k);
	while (k) {s[++l]=(k&1); k>>=1;}
	rep(i,1,n) read(a[i]),read(b[i]);
	Bit[0]=1; rep(i,1,30) Bit[i]=Bit[i-1]<<1;
	getans(getnum(s));
	rep(i,1,l) if (s[i]==1) {
		memcpy(t,s,sizeof(s));
		t[i]=0; 
	//	if (i==3) printf("%d %d %d\n",t[1],t[2],t[3]);
		rep(j,1,i-1) t[j]=1; //i!=j
	//	if (i==3) printf("%d %d %d\n",t[1],t[2],t[3]);
		int x=getnum(t); getans(x);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1152
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: HashSet<_> = (0..n + 1).collect();
    let mut r2: BTreeSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    let mut cnt = 1;
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            r2.remove(&s_idx);
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            // if let Some(destv) = dests.remove(&s_num) {
            //     for dest in destv {
            //         q.push_back(dest);
            //     }
            // }
            if let Some(destv) = dests.get_mut(&s_num) {
                for &dest in destv.iter() {
                    q.push_back(dest);
                }
                destv.clear();
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
        if let Some(&_) = r2.iter().next() {
            cnt += 1;
        }
    }
    if cnt > 1e9 as u64{
        println!("{}", "hoge");
    }
    println!("{}", ans);
    std::process::exit(0);
}


Measured memory_bytes: 27576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,d,x;
    cin>>n>>d>>x;
    ll ans=x;
    rep(0,i,n){
        ll a;
        cin>>a;
        ans+=(d+a-1)/a;
        //cout<<ans<<endl;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
#define NIL -1
void depth(int,int);
void print(int);

typedef struct{
    int parent;
    int left;
    int right;
} Node;
Node node_all[N];
int n;
int depth_node[N];

int main(){
    int i,j,n_num,degree,data,n_child,flag;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        node_all[i].parent = node_all[i].left = node_all[i].right = NIL;
    }
    for(i=0;i<n;i++){
        scanf("%d%d",&n_num,&degree);
        for(j=0;j<degree;j++){
            scanf("%d",&data);
            if(j==0){
                node_all[n_num].left = data;
            }
            else{
                node_all[n_child].right = data;
            }
            n_child = data;
            node_all[data].parent = n_num;
        }
    }
    for(i=0;i<n;i++){
        if(node_all[i].parent == NIL) flag = i;
    }
    depth(flag,0);
    for(i=0;i<n;i++){
        print(i);
    }
    return 0;
}

void depth(int first,int count){
    depth_node[first] = count;
    if(node_all[first].right != NIL){
        depth(node_all[first].right,count);
    }
    if(node_all[first].left != NIL){
        depth(node_all[first].left,count+1);
    }
}

void print(int k){
    int i,data;
    
    printf("node %d: ",k);
    printf("parent = %d, ",node_all[k].parent);
    printf("depth = %d, ",depth_node[k]);
    if(node_all[k].parent == NIL){
        printf("root, ");
    }
    else if(node_all[k].left == NIL){
        printf("leaf, ");
    }
    else printf("internal node, ");

    printf("[");
    for(i=0,data=node_all[k].left;data!=NIL;i++){
        printf("%d",data);
        data=node_all[data].right;
        if(data!=NIL){
            printf(", ");
        }
    }
    printf("]\n");
}


Measured memory_bytes: 6400