akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; ++i) cin >> x[i];

  vector<int> b = x;
  sort(b.begin(), b.end());

  for (int i = 0; i < n; ++i) {
    if (x[i] < b[n / 2 - 1]) {
      cout // << "1 "
          << b[n / 2];
    } else if (x[i] == b[n / 2 - 1]) {
      cout // << "2 "
          << b[n / 2];
    } else if (x[i] > b[n / 2 - 1] && x[i] < b[n / 2]) {
      cout // << "3 "
          << b[n / 2];
    } else if (x[i] == b[n / 2]) {
      cout // << "4 "
          << b[n / 2 - 1];
    } else if (x[i] > b[n / 2]) {
      cout // << "5 "
          << b[n / 2 - 1];
    }
    cout << endl;
  }

  // for (int i = 0; i < n; ++i) {
  //   int j = n / 2 - 1;

  //   if (b[j] >= x[i]) {
  //     // j--;
  //     j++;
  //   } else {
  //     // j++;
  //     j--;
  //   }
  //   cout << b[j] << endl;
  // }
}


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

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(1, n + 1):
    if ab[n - i][0] != 0:
        ab[n - i][0] += cnt
        if ab[n - i][0] <= ab[n - i][1]:
            cnt += ab[n - i][1] - ab[n - i][0]
        else:
            if ab[n - i][0] % ab[n - i][1] != 0:
                cnt += ab[n - i][1] - (ab[n - i][0] % ab[n - i][1])
print(cnt)


Measured memory_bytes: 31348
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
int n, k;
vector<int> w;

bool enough(int cap) {
    int kk = 1;
    int cc = cap;
    for (int i = 0; i < n; ++i) {
        if(cc >= w[i]){
            cc -= w[i];
        } else {
            if(cap >= w[i])
             cc = cap - w[i];
            else
                return false;
            kk++;
            if(kk > k) return false;
        }
    }
   return true;
}
int main() {
    cin >> n >> k;
    w.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }

    int l = 0;
    int r = INT_MAX;
    while(r - l > 1) {
        int m = (l+r)/2;
        if(enough(m)) {
            r = m;
        }  else {
            l = m;
        }
    }
    cout << r << endl;
    return 0;
}



Measured memory_bytes: 3132
n = int(input())
a = list(map(int,input().split()))
ans = 'APPROVED'
for x in a:
    if x % 2 == 1:
        continue
    if not (x % 2 == 0 and (x % 3 == 0 or x % 5 == 0)) :
        ans = 'DENIED'
print(ans)

Measured memory_bytes: 2940
'use strict';

function Main(input) {
  const reg = /[ATGC]+/
  let ans = 0;
  for (let i = 0; i < input.length; i++) {
    const mat = input.slice(i).match(reg)
    let len = 0
    if (mat !== null) {
      len = mat[0].length
    }
    if (ans < len) {
      ans = len
    }
  }
  console.log(ans)
};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int x[n], y[n], h[n];
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> h[i];
    }
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            int H = -1;
            int contflg = 0;
            for (int k = 0; k < n; ++k) {
                if (h[k] == 0) continue;
                int tmp = abs(x[k] - i) + abs(y[k] - j);
                if (H == -1) {
                    H = h[k] + tmp;
                    if (H < 1) { contflg = 1; break; }
                } else {
                    if (h[k] + tmp != H) { contflg = 1; break; }
                }
            }
            // h[k] == 0でとばしたやつにも当てはまるか
            for (int k = 0; k < n; ++k) {
                if (h[k] != 0) continue;
                int tmp = abs(x[k] - i) + abs(y[k] - j);
                if (H - tmp > 0) { contflg = 1; break; }
            }
            if (contflg == 0) {
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
}
/*
 制約により、ピラミッドの中心座標、高さは一意に決まる
 関係ない、hが0(地面)の座標は無視する
 
 */


Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	if minimum(a)==0
		println(0)
	else
		f = 0
		x::BigInt = 1
		for i in 1:n
			x = x*a[i]
			if x>10^18
				f = 1
				break
			end
		end
		println(f==1 ? -1 : x)
	end
end

main()

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

int main() {
	int A,B,C,D,x,y;
	cin >> A >> B >> C >> D;
	if (A >= B)
	  x = B;
	else
	  x = A;
	if (C >= D)
	  y = D;
	else
	  y = C;
	cout << (x+y);
	return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())
i = 2
ans = 1
while P > 1:
  if i * i > P:
    if N == 1:
      ans *= P
    break
  x = 0
  while P % i == 0:
    x += 1
    P //= i
  ans *= i ** (x // N)
  i += 1
print(ans)

Measured memory_bytes: 63692
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { Long a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
#define DB if(0) 
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}

#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
    
    Long d=LL(),n=LL();
    if(n==100) n++;
    cout << n*(int)pow(100,d) << endl;
	
	return 0;
}



Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int n, m;
	std::cin >> n >> m;
	std::cout << ((n-1)*(m-1)) << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define INF 1000000
#define W 0
#define G 1
#define B 2

int n,A[N][N];

int prim();

int main(){
  int i,j,e;
  
  scanf("%d",&n);

  for(i=0;i<n;i++) {
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e==-1) A[i][j] = INF;
      else A[i][j] = e;
    }
  }
  printf("%d\n",prim());
  
  return 0;
}


int prim(){
  int k,min,i,j,sm;
  int dt[N],pat[N],clr[N];

  for(i=0;i<n;i++){
    dt[i] = INF;
    pat[i] = -1;
    clr[i] = W;
  }
  dt[0]=0;

  while(1){
    min = INF;
    k = -1;
    for(i=0;i<n;i++){
      if(min>dt[i]&&clr[i]!=B){
	k=i;
	min=dt[i];
      }
    }
    if(k==-1) break;
    clr[k] = B;
    for(j=0;j<n;j++){
      if(clr[j]!=B&&A[k][j]!=INF){
	if(dt[j]>A[k][j]){
	  dt[j] =A[k][j];
	  pat[j]=k;
	  clr[j]=G;
	}
      }
    }
  }
  sm = 0;
  for(i=0;i<n;i++){
    if(pat[i]!=-1) sm +=A[i][pat[i]];

  }


  return sm;
}



Measured memory_bytes: 2048
import java.io.*;

public class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        try{
            String line;
            int i = 0, j = 0, k = 0, l = 0;
            int[][] data;

            data = new int[300][2];

            while(true){
                line = reader.readLine();
                String[] tmp = line.split(" ",2);
                data[i][0] = Integer.parseInt(tmp[0]);
                data[i][1] = Integer.parseInt(tmp[1]);

                if(data[i][0] == 0 && data[i][1] == 0){
                    break;
                }
                i++;
            }
            for(j = 0; j <= i-1; j++){
                for(k = 0; k < data[j][0]; k++){
                    for(l = 0; l < data[j][1]; l++){
                        if(k % 2 == l % 2){
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                        }
                    }
                    System.out.print("\n");
                }
                System.out.print("\n");
            }
        }catch(NumberFormatException e){
            System.out.println(e);
        }catch(IOException e){
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 36044
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i).sort

stack = []
2.times do |j|
  i = 1
  while i <= a[j] / i
    if a[j] % i == 0
      stack << i if !stack.include?(i)
      stack << a[j] / i if !stack.include?(a[j] / i)
    end
    i += 1
  end
end

stack.sort.reverse.each do |i|
  cnt = 0
  n.times do |j|
    cnt += 1 if a[j] % i != 0
  end
  if cnt <= 1
    puts i
    exit
  end
end


Measured memory_bytes: 11256
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int r;
    scan(r);
    print(r * r);

    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    while a>0 and b >0:
        if a > b:
            a %= b
        else:
            b %= a
    return a + b

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


forwards = [A[0]]
backwards = [A[-1]]
for i in range(1, N):
    forwards.append(gcd(forwards[-1], A[i]))
    backwards.append(gcd(backwards[-1], A[-(i+1)]))
backwards = list(reversed(backwards))

ans = 0
for i in range(1, N-1):
    a = gcd(forwards[i-1], backwards[i+1])
    if a > ans:
        ans = a

if N > 2:
    ans = max([ans, forwards[-2], backwards[1]])
elif N == 2:
    ans = max(A)
else:
    ans = A[0]

print(ans)


Measured memory_bytes: 16136
exp = [False, True] + [False for i in range(1000-1)]

for i in range(2, 32):
    j = 2
    while(i ** j <= 1000):
        e = i ** j
        exp[e] = True
        j+=1

X = int(input())

for i in range(X, 0, -1):
    if(exp[i]):
        print(i)
        break

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long


signed main(void) {
  int H, W;
  int h, w;
  cin >> H >> W;
  cin >> h >> w;

  int ans;
  ans = H * W - h * W - w * H + h * w;
  cout << ans << endl;

  return 0;
}


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

int main(){
    while(1){
        int n,t,l,b;
        cin >> n >> t >> l >> b;
        if(n==0) break;

        vector<bool> isL(n+1, false), isB(n+1, false);
        for(int i=0; i<l; i++){
            int c;
            cin >> c;
            isL[c] = true;
        }
        for(int i=0; i<b; i++){
            int c;
            cin >> c;
            isB[c] = true;
        }

        vector<double> prob(n+1, 0.0);
        vector<double> skip(n+1, 0.0);
        prob[0] = 1.0;
        for(int i=0; i<t; i++){
            vector<double> next(n+1, 0.0);
            for(int j=0; j<n+1; j++){
                next[j] += skip[j];
                skip[j] = 0.0;
            }
            for(int j=0; j<n; j++){
                for(int d=1; d<=6; d++){
                    int dest = (j+d>n)? (2*n-d-j) : (j+d);
                    if(isB[dest]) dest = 0;
                    if(isL[dest]){
                        skip[dest] += prob[j]/6;
                    }else{
                        next[dest] += prob[j]/6;
                    }
                }
            }
            next[n] += prob[n];
            for(int j=0; j<n+1; j++){
                prob[j] = next[j];
            }
        }
        cout << fixed;
        cout << setprecision(7);
        cout << prob[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 3156
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    from functools import reduce
    def lcm_base(n1,n2):
        return (n1*n2)//math.gcd(n1,n2)
    def lcm(*numbers):
        return reduce(lcm_base, numbers)
    a,b,c,d = LI()
    cd = lcm(c,d)
    lst = [c,d,cd]
    ans_lst = []
    for ex in lst:
        before = a if a % ex == 0 else a+ex-(a%ex)
        after = b - (b%ex)
        # print(ex,before,after)
        if before > after:
            ans_lst.append(0)
        else:
            bnum = before//ex
            anum = after//ex
            num = anum - bnum +1
            ans_lst.append(num)
            # print(anum,bnum,num)
    ans =(b-a +1) - (ans_lst[0] + ans_lst[1] - ans_lst[2])
    # print(ans_lst)
    print(ans)

main()

Measured memory_bytes: 74628
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  ill n;
  cin >> n;
  string s;
  for(int i = 0; 1; i++) {
    char c = 'a';
    int a = 0;
    if(n % 26 == 0) {
      c = 'z';
      a = 1;
    }
    else c += n % 26 -1;
    s += c;
    n /= 26;
    if(a == 1) n--;
    if(n == 0 /*|| a == 1*/) break;
  }
  reverse(s.begin(), s.end());
  cout << s;
}

Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author kouki
 */
public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        if (A > B) {
            for (int i = 1; i < B+1; i++) {
                if (B % i == 0 && A % i == 0) {
                    list.add(i);
                }
            }
        } else if (B > A) {
            for (int i = 1; i < A+1; i++) {
                if (A % i == 0 && B % i == 0) {
                    list.add(i);
                }
            }
        } else if (A == B) {
            for (int i = 1; i < A+1; i++) {
                if (A % i == 0 && B % i == 0) {
                    list.add(i);
                }
            }
        } else {
        }
        Collections.sort(list, Collections.reverseOrder());
        System.out.println(list.get(K-1));
    }

}

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

int count_digit(long long number)
{
    return std::to_string(number).length();
}
int f(int a, int b)
{
    return max(count_digit(a), count_digit(b));
}

int main(void)
{
    long long n;
    cin >> n;
    int answer = count_digit(n);
    for (long long a = 1LL; a*a <= n; a++)
    {
        if(n % a != 0) continue;    // 割り切れない場合はA×B=Nにならない
        long long b = n / a;
        int count = f(a, b);
        if(answer > count)
        {
            answer = count;
        }
    }
    
    cout << answer << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 22:58:03 2020

@author: liang
"""

N,X,M=map(int,input().split())
a = X
hist = [a]
indices = [-1]*M
indices[a] = 0
flag=0
for i in range(1,min(10**6,N)):
  a = a**2 % M
  if indices[a] != -1:
    idx = indices[a]
    flag=1
    break
  hist.append(a)
  indices[a] = i
  
if flag==0:
  print(sum(hist))
  exit()
  
cycle = hist[idx:]
margin = hist[:idx]
q,r = divmod((N-len(margin)),len(cycle))
ans = 0
ans += sum(margin)
ans += sum(cycle)*q
#print(q,sum(cycle))
ans += sum(cycle[:r])
#print(r)
#print(cycle[:10])
print(ans)


Measured memory_bytes: 13940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S, T;
    cin >> S >> T;
    
    int cnt = 0;
    
    for (int i = 0; i < 3; ++i)
    {
        if (S[i] == T[i])
        {
            ++cnt;
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 888
N,M=list(map(int,input().split()))
L=list(map(int,input().split()))
if N not in L:
  print(N)
  exit()
c=N
d=N
while True:
  if c not in L:
    break
  else:
    c-=1
while True:
  if d not in L:
    break
  else:
    d+=1
if abs(d-N)>=abs(c-N):
  print(c)
else:
  print(d)

Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <limits.h>
using namespace std;
typedef long long ll;
const int MAX_N = 126;

int main()
{
	ll K;
	cin >> K;
	for (ll i = -MAX_N; i <= MAX_N; i++)
	{
		for(ll j=-MAX_N;j<=MAX_N;j++)
			if (i*i*i*i*i - j*j*j*j*j == K)
			{
				cout << i << " "<<j;
				return 0;
			}
	}
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		int h, m, s;
		h = i / 60 / 60;
		m = (i - (h * 60 * 60)) / 60;
		s = (i - (h * 60 * 60) - (m * 60));
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 26240
using System;
using System.Linq;

class Problem {
    class Dice {
        int t, s, e, w, n, b;
        public Dice(int[] nums) {
            t = nums[0];
            s = nums[1]; e = nums[2]; w = nums[3]; n = nums[4];
            b = nums[5];
        }
        public void Roll(string coms) {
            foreach (var com in coms) {
                var tmp = t;
                switch (com) {
                    case 'E': t = w; w = b; b = e; e = tmp; break;
                    case 'N': t = s; s = b; b = n; n = tmp; break;
                    case 'S': t = n; n = b; b = s; s = tmp; break;
                    case 'W': t = e; e = b; b = w; w = tmp; break;
                }
            }
        }
        public int Top { get { return t; } }
    }
    
    public static void Main() {
        var d = new Dice(Console.ReadLine().Split().Select(int.Parse).ToArray());
        d.Roll(Console.ReadLine());
        Console.WriteLine(d.Top);
    }
}


Measured memory_bytes: 9612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC141
{
    class ABC141_B
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToArray();

            bool f = false;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'U' | s[i] == 'D')
                {
                    continue;
                }
                if (!((i%2 == 0 && s[i] == 'R') || (i % 2 == 1 && s[i] == 'L')))
                {
                    f = true;
                    break;
                }
            }

            if (f)
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int a[25], b[25];

int main()
{
	int n, x, y, s = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int j = 1; j <= n; j++)
		cin >> b[j];
	for (int i = 1; i <= n; i++ )
		if (a[i] > b[i])
			s += a[i] - b[i];
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 500030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{
		ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll x=1,y=1;
	ll n;
	cin>>n;
	while(n--)
	{
		ll a,b;
		cin>>a>>b;
	
			ll aa=(x+a-1)/a;


			ll bb=(y+b-1)/b;


			ll z=max(bb,aa);
		//	cout<<y<<endl;
			y=z*b;
			x=z*a;
			
			

		
	
		//cout<<x<<" "<<y<<endl;
	}
	cout<<x+y<<endl;
}

Measured memory_bytes: 256
class PriorityQueue
  def initialize(&comp)
    @heap = []
    @node_num = 0
    if !block_given?
      @comp = Proc.new { |x, y| x <= y }
    else
      @comp = comp
    end
  end

  attr_reader :heap

  def push(x)
    current_node_num = @node_num
    @node_num += 1
    while current_node_num > 0
      parent_node_num = (current_node_num - 1) / 2
      break if @comp.call(@heap[parent_node_num], x) # 逆転してないなら抜ける
      # 親ノードを下ろして自分を上に
      @heap[current_node_num] = @heap[parent_node_num]
      current_node_num = parent_node_num
    end
    @heap[current_node_num] = x
  end

  alias_method(:<<, :push)

  def pop
    # 最(小|大)値
    ret = @heap[0]
    # 根にもってくる値
    @node_num -= 1
    x = @heap[@node_num]
    # 根から下ろしていく
    i = 0
    while (a = i * 2 + 1) < @node_num
      # 子どうしを比較
      b = a + 1
      a = b if b < @node_num && @comp.call(@heap[b], @heap[a])
      break unless @comp.call(@heap[a], x)
      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    return ret
  end

  def get
    @node_num == 0 ? nil : @heap[0]
  end

  def empty?
    return get.nil?
  end
end

#
# dijkstra
#   O(|E|log|V|)
#   隣接表現グラフgraph, 始点start, inf
#
def dijkstra(graph, start, inf = Float::INFINITY)
  vertex_num = graph.size
  que = PriorityQueue.new { |x, y| x[0] <= y[0] }
  dist = Array.new(vertex_num, inf)
  dist[start] = 0
  que.push([0, start])
  while !que.empty?
    d, v = que.pop
    next if dist[v] < d
    graph[v].size.times do |i|
      # e is an instance of Edge
      #   Edge = Struct.new(:to, :cost)
      e = graph[v][i]
      if dist[e.to] > dist[v] + e.cost
        dist[e.to] = dist[v] + e.cost
        que.push([dist[e.to], e.to])
      end
    end
  end
  return dist
end

Edge = Struct.new(:to, :cost)
n, m = gets.split.map(&:to_i)
g = Array.new(n) { [] }

(n - 2).times do |i|
  g[i + 1] << Edge.new(i, 0)
end

m.times do
  l, r, c = gets.split.map(&:to_i)
  l -= 1
  r -= 1
  g[l] << Edge.new(r, c)
end
ans = dijkstra(g, 0)[n-1]
puts ans == Float::INFINITY ? -1 : ans


Measured memory_bytes: 29728
import sys
N=int(sys.stdin.readline().strip())
XY=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
X=[]
Y=[]
for x,y in XY:
    X.append(x-y)
    Y.append(x+y)
X.sort()
Y.sort()
print max(abs(X[0]-X[-1]),abs(Y[0]-Y[-1]))

Measured memory_bytes: 117316
let len = 101010

let modulo = 1000000007

let (+@) a b = (a + b) mod modulo
let ( *@) a b = (a * b) mod modulo
let rec (^@) a n =
  if n = 0 then 1
  else if n mod 2 = 1 then a *@ (a ^@ (n-1))
  else let h = a ^@ (n/2) in h *@ h

let inv_mod a = a ^@ (modulo - 2)

let facts =
  let res = Array.make len 1 in
  for i = 1 to len-1 do res.(i) <- i *@ res.(i-1); done;
  res

let inv_facts = Array.map inv_mod facts

let comb n k =
  if n < k then 0 else facts.(n) *@ inv_facts.(k) *@ inv_facts.(n-k)

let rec factorize x =
  let rec f d c n =
    if d * d > x then
      if n > 1 then [(n, 1)] else []
    else if n mod d = 0 then f d (c+1) (n / d)
    else if c > 0 then (d, c) :: f (d+1) 0 n else f (d+1) 0 n
  in f 2 0 x

let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  factorize m |> List.fold_left (( fun ans (d, c) ->
    ans *@ comb (n+c-1) c )) 1
  |> Printf.printf "%d\n"


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

const int N = 200005;
const int INF = 1000000005;
const int MOD = 998244353;
typedef long long i64;

int a[5];

int main ()
{
    for (int i = 1; i <= 3; ++i) cin >> a[i];
    sort(a + 1, a + 4);
    int ans = a[3] - a[2];
    a[1] += ans;
    if ((a[3] - a[1]) % 2 == 0) ans += (a[3] - a[1]) / 2;
    else ans += (a[3] - a[1] + 1) / 2 + 1;
    printf("%d\n", ans);
    return 0;
}


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

#define MAX_D     61
typedef unsigned long long ull;

int main(void) {
	ull A, B;
	int r, k;

	cin >> A >> B;
	bitset<MAX_D> bA(A);
	bitset<MAX_D> bB(B);
	if (A == B) {
		cout << "1\n";
		return 0;
	}
	r = MAX_D - 1;
	while (true) {
		if (bB[r] != bA[r])
			break;
		if (bB[r] == 1 && bA[r] == 1) {
			bB.reset(r);	bA.reset(r);
		}
		--r;
	}
	k = r - 1;
	while (k >= 0) {
		if (bB[k] == 1)
			break;
		--k;
	}

	A = bA.to_ullong();
	B = bB.to_ullong();

	bitset<MAX_D> bt(0);
	bt.set(r);
	ull t = bt.to_ullong();

	bitset<MAX_D> bu(0);
	bu.set(k + 1);
	ull u = bu.to_ullong() - 1;

	ull ans;
	if (u >= A)
		ans = (2 * t - 1) - A + 1;
	else
		ans = (t + u - A + 1) + (t - A);

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


Measured memory_bytes: 256
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [l]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    return `${Math.pow(l / 3, 3)}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if (s == t) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3640
N, C, K = map(int, input().split())
T = []
for _ in range(N):
    T.append(int(input()))
T = sorted(T)

# print(N, C, K)
# print(*T, end="\n")

# 現在の時刻
# 前から詰めていく (容量制約を忘れない)
count = 0
i = 0
while i < N:
    timax = T[i] + K
    # 乗せた人数
    c = 0
    count += 1
    while i < N and c < C and T[i] <= timax:
        c += 1
        i += 1
print(count)

Measured memory_bytes: 51416
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define 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;

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

int main(){
	int w, h, n;
	cin >> w >> h >> n;
	int lx=0, rx=w;
	int by=0, ty=h;
	int x, y, a;
	REP(i, n){
		cin >> x >> y >> a;
		switch (a)
		{
			case 1:
				lx = max(lx, x);
				break;
			case 2:
				rx = min(rx, x);
				break;
			case 3:
				by = max(by, y);
				break;
			case 4:
				ty = min(ty, y);
				break;
		}
	}
	if(lx >= rx || by >= ty) cout << 0 << '\n';
	else cout << (rx-lx)*(ty-by) << '\n';

	return 0;
}


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

int main () {
  char a, b;
  cin >> a >> b;
  if (a > b) {
    for (int i = 0; i<a-'0'; i++) cout << b;
  } else {
    for (int i = 0; i<b-'0'; i++) cout << a;
  }
  cout << "\n";
  return 0;
}

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

constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

int Grundy(int n, const int k) {
    int m;
    while(n % k != 0) {
        m = n / k + n % k;
        m -= m % (n / k + 1);
        n -= m;
    }
    return n / k;
}

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

    int N, A, K;
    cin >> N;

    int ret = 0;
    rep(i, N) {
        cin >> A >> K;
        ret ^= Grundy(A, K);
    }

    cout << (ret ? "Takahashi" : "Aoki") << endl;

    return 0;
}

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

using namespace std;

int main(){

	int N, K;

	cin >> N >> K;

	int A = 1;
	int i = 0;

	for( ; i < N ; ){

		A *= 2;

		i++;

			if( A > K )
			break;

		}

	cout << ( N - i ) * K + A <<endl;
	
	}

Measured memory_bytes: 3620
INF = 10 ** 10
while True:
  n = int(input())
  if n == 0:
    break

  costs = [[INF] * 10 for _ in range(10)]
  for i in range(10):
    costs[i][i] = 0
  
  city = set()
  for _ in range(n):
    a, b, c = map(int, input().split())
    city = city | {a, b}
    costs[a][b] = c
    costs[b][a] = c 
  
  city = sorted(list(city))
  
  for k in range(10):
    for i in range(10):
      for j in range(10):
        costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j])
  
  min_total = INF
  best_city = -1
  for fr in city:
    total = 0
    for to in city:
      total += costs[fr][to]
    if total < min_total:
      min_total = total
      best_city = fr
  print(best_city, min_total)


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

int main()
{
       ll a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    ll ma = max({a1, a2, a3});
    ll mi = min({a1, a2, a3});

    cout<<ma-mi<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	ll N;

	cin >>  N;

	ll H[100];

	repn(i, N) {
		cin >> H[i];
	}

	ll ans = 0;

	ll max = 0;

	repn(i, N) {
		if(H[i]>=max){
			ans++;
			max = H[i];
		}
	}

	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   string s;
   cin>>s;
   
   if(n<3)
   {
       cout<<0;
       return 0;
   }
   ll ans = 0;
   for(ll i=0;i<n-2;i++)
   {
       map<char,ll> ma;
       ma[s[i+1]]++;
       for(ll j=i+2;j<n;j++)
       {
           if(s[i] == s[j])
           {
               ma[s[j]]++;
               continue;
           }
           ll cnt = 0;
           unordered_map<char,ll> ma1;
           ma1[s[i]]++;
           ma1[s[j]]++;
           char ch;
           if(ma1['R'] == 0)
                cnt = ma['R'], ch = 'R';
           else if(ma1['B'] == 0)
                cnt = ma['B'], ch = 'B';
           else cnt = ma['G'], ch = 'G';
           if((j+i)%2 == 0 && s[(j+i)/2] == ch)
                cnt--;        
           ans+=cnt;
           ma[s[j]]++;
       }
   }
   cout<<ans;
   
   return 0;        
}  
   


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

class Dice {
public:
	int face[6];
	int temp;

	Dice() {
	}

	void north() {
		temp = face[0];
		face[0] = face[1];
		face[1] = face[5];
		face[5] = face[4];
		face[4] = temp;
	}
	void south() {
		temp = face[0];
		face[0] = face[4];
		face[4] = face[5];
		face[5] = face[1];
		face[1] = temp;
	}
	void west() {
		temp = face[0];
		face[0] = face[2];
		face[2] = face[5];
		face[5] = face[3];
		face[3] = temp;
	}
	void east() {
		temp = face[0];
		face[0] = face[3];
		face[3] = face[5];
		face[5] = face[2];
		face[2] = temp;
	}
	void roll(char order) {
		if (order == 'N') north();
		if (order == 'S') south();
		if (order == 'W') west();
		if (order == 'E') east();
	}
	void spin() {
		temp = face[1];
		face[1] = face[2];
		face[2] = face[4];
		face[4] = face[3];
		face[3] = temp;
	}
	void findTop(int top) {
		string order = "NNNWNNN";
		for(int i = 0; i < 7; i++) {
			if (face[0] == top)break;
			roll(order[i]);
		}
	}
	void findFront(int front) {
		for (int i = 0; i < 4; i++) {
			if (face[1] == front)break;
			spin();
		}
	}
	void rightSide(int top, int front) {
		findTop(top);
		findFront(front);
		cout << face[2] << endl;
	}
	bool isSame(Dice dice1) {
		string order = "NNNWNNN";
		for (int i = 0; i < 7; i++) {
			for (int j = 0; j < 4; j++) {
				if (face[0] == dice1.face[0] && face[1] == dice1.face[1] && face[2] == dice1.face[2] && face[3] == dice1.face[3] && face[4] == dice1.face[4] && face[5] == dice1.face[5]) {
					return true;
				}
				spin();
			}
			roll(order[i]);
		}
		return false;
	}
};

int main()
{
	int input[6], n, count = 0;
	Dice dice[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++) {
			cin >> dice[i].face[j];
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)continue;
			if (dice[i].isSame(dice[j])) {
				count++;
				break;
			}
		}
	}
	string res = count<1 ? "Yes" : "No";
	cout << res << endl;

}

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

//mapのKeyとペアを選ぶ(keyはstring)
//→stringの数に応じてペアのintの数が増える
map<string , int> mp;

int main()
{
  int n,i;
  string s;
  cin>>n;
  
  //順番に文字列を読み込む→mapに取り込む
  for(i=0;i<n;i++)
  {
    cin>>s;
    mp[s]++;
  }
  
  int m=0;//最大値の定義
  
  //auto pは：の後にくるペア(今回で言えばmap)をすべて走査する
  for(auto p:mp)
    m=max(m,p.second);//二つの数字の大きいほうを返す．secondすなわち数字の部分を比較
  
  //最大値が求まった
  
  //最大値の場合だけcout
  for(auto p:mp)
  {
    if(p.second==m) cout<<p.first<<"\n";//firstすなわちKeyの部分を返す．
  }
  
  return 0;
    
}

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

int main()
{
	int n, k;

	scanf("%d%d", &n, &k);

	int maximum = (n - 1) * (n - 2) / 2;

	if(maximum < k) {
		printf("-1\n");
		return 0;
	}

	int diff = maximum - k;

	vector<pair<int,int>> edges;

	for(int i = 1; i < n; i++) {
		edges.push_back({0, i});
	}

	int rem = diff;

	for(int i = 1; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(rem > 0) {
				rem -= 1;
				edges.push_back({i, j});
			}
		}
	}

	printf("%d\n", (int)edges.size());
	for(auto& e : edges) {
		printf("%d %d\n", e.first + 1, e.second + 1);
	}

	return 0;
}


Measured memory_bytes: 384
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)

int n, m;
int POW[16];

int calc(int A, int B, int C) {
	int res = 0;
	for_(i,0,n) {
		int k = n - i - 1;
		if (A >> i & 1) res += 2 * POW[k];
		if (B >> i & 1) res += POW[k], swap(A, C);
	}
	return res;
}

void solve() {
	int cup[3] = { 0 };
	
	for_(i,0,3) {
		int d; cin >> d;
		for_(j,0,d) {
			int p; cin >> p; --p;
			cup[i] |= 1 << p;
		}
	}
	
	int ans = min(calc(cup[0], cup[1], cup[2]), calc(cup[2], cup[1], cup[0]));
	cout << ( (ans > m) ? -1 : ans) << endl;
}

int main() {
	POW[0] = 1;
	for_(i,1,16) POW[i] = POW[i - 1] * 3;
	while (cin >> n >> m, n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll k;
    cin >> k;
    vector<ll> a(n), f(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    ll ok = 1e12, ng = -1;
    while(ok - ng > 1){
    	ll mid = (ok + ng) / 2;
    	ll cnt = 0;
    	rep(i, n){
    		cnt += max(a[i] - min(a[i], mid / f[i]), 0LL);
    	}
    	(cnt <= k ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 3456
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
a,b,c,d = map(int,input().split())

m = a*c
m = max(m,a*d)
m = max(m,b*c)
m = max(m,b*d)
print(m)
            








Measured memory_bytes: 10592
import itertools
import collections

def main():
    n = int(input())
    S = [input()[0] for _ in range(n)]

    array = ['M','A','R','C','H']
    S_after = []
    for s in S:
        if s in array:
            S_after.append(s)
    if len(S_after) < 3:
        print(0)
        return
    S_after_set = set(S_after)
    combs = itertools.combinations(S_after_set, 3)
    coll = collections.Counter(S_after)

    ans = 0
    for comb in combs:
        if comb[0] != comb[1] != comb[2]:
            ans += coll[comb[0]]*coll[comb[1]]*coll[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 60760
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  int n = readNum!int;
  auto work = new long[][](n, 2);

  foreach(ref e; work){
    e = readNums!long;
  }

  work.sort!("a[1] < b[1]");

  long t;
  foreach(e; work){
    t += e[0];
    if(t > e[1]){
      writeln("No");
      return;
    }
  }

  writeln("Yes");
}


Measured memory_bytes: 37628
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef unsigned int ui;
typedef vector <int> vi;
const ll mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const ll INF = 1e18;

const int C = 400, maxn = 1000;
vector <int> v[maxn];
int in[maxn], out[maxn], n, h, a, b, c, d;

inline void addEdge(int x, int y)
{
	v[x].pb(y);
	v[y].pb(x);
	in[y]++;
	out[x]++;
}
bool ans = 0;
bool odw[maxn];
void dfs(int x)
{
	odw[x] = 1;
	if (in[x] != out[x]) ans = 1;
	for (auto u : v[x])
		if (!odw[u]) dfs(u);
}
int main()
{
	boost;
	cin >> n >> h;
	FOR(i, 1, n)
	{
		cin >> a >> b >> c >> d;
		int l = (c == 0)?a:-c, r = (d == 0)?-b:d;
		addEdge(l + C, r + C);
	}
	
	FOR(i, 1, h)
		if (in[i + C] > out[i + C]) OUT("NO");
	
	FOR(i, -h, -1)
		if (in[i + C] < out[i + C]) OUT("NO");
	
	FOR(i, -h, h)
		if (!odw[i + C] && (int)v[i + C].size() > 0) 
		{
			ans = 0;
			dfs(i + C);
			if (!ans) OUT("NO");
		}
	cout << "YES";
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

//  freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vec<pair<int, int>, 2> adjEdge(n);
  while (m--) {
    int u, v, w; cin >> u >> v >> w; --u; --v;
    adjEdge[u].emplace_back(v, w);
    adjEdge[v].emplace_back(u, -w);
  }

  vec<bool, 1> vis(n);
  vec<int, 1> a(n);
  function<void(int)> dfs = [&](int u) {
    vis[u] = true;
    for (auto& i : adjEdge[u]) {
      int v = i.first, w = i.second;
      if (!vis[v]) {
        a[v] = a[u] + w;
        dfs(v);
      } else if (a[v] != a[u] + w) {
        cout << "No\n";
        exit(0);
      }
    }
  };
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      dfs(i);
    }
  }

  cout << "Yes\n";

  return 0;
}


Measured memory_bytes: 15800
import bisect


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N, M, X = get_next_ints()
    costs = get_next_ints()
    costs = sorted(costs)
    x_index = bisect.bisect(costs, X)
    left_cost = len(costs[0:x_index])
    right_cost = len(costs[x_index:])
    if left_cost < right_cost:
        print(left_cost)
    else:
        print(right_cost)
solve()

Measured memory_bytes: 3064