akhauriyash/Code-Regression huggingface dataset:
require 'prime'

class Solver

  def initialize
    @nums = []
  end

  def main
    a, b, k = gets.split.map(&:to_i)
    # puts a, b, k

    m = a.gcd(b)
    # puts m

    pd = Prime.prime_division(m)  #=> [[5, 1], [197, 1], [461, 1]]
    # puts pd

    dnum(pd, 0, 1)

    @nums.uniq!
    @nums.sort!
    @nums.reverse!

    puts @nums[k-1]
  end

  # 約数
  def dnum(pdnum, idx, acc)
    if pdnum.length == idx
      @nums << acc
      return
    end

    k, v = pdnum[idx]
    0.upto(v) do |n|
      dnum(pdnum, idx + 1, acc * (k ** n))
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 3964
#template
from collections import Counter
def inputlist(): return [int(i) for i in input().split()]
#template
A,B,M = inputlist()
a = inputlist()
b = inputlist()
ma = sorted(a)[0]
mb = sorted(b)[0]
mc = ma+mb
for i in range(M):
    x,y,c = inputlist()
    x -=1
    y -=1
    mc = min(mc,a[x]+b[y]-c)
print(mc)

Measured memory_bytes: 18872
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  n %= 10;
  if(n == 3) {
    cout << "bon" << endl;
  }
  else if(n == 0 || n == 1 || n == 6 || n == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int k = sc.nextInt();
    HashSet<String> set = new HashSet<String>();
    for(int i = 0; i < s.length(); i++) {
      for(int j = i + 1; j <= Math.min(s.length(), i + k); j++) {
        String str = s.substring(i, j);
        set.add(str);
      }
    }
    ArrayList<String> list = new ArrayList<String>();
    for(Iterator<String> i = set.iterator(); i.hasNext();) {
      list.add(i.next());
    }
    Collections.sort(list);
    System.out.println(list.get(k - 1));
  }
}

Measured memory_bytes: 24636
s=int(input())
l=[s]
c=2
for i in range(1000001):
    a=0
    if s%2==0:
        s//=2
    else:
        s=3*s+1
    for j in range(len(l)):
        if s==l[j]:
            print(c)
            a+=1
            break
    if a==1:
        break
    l.append(s)
    c+=1

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]


def solve():
    n = int(input())
    x = n
    a = []
    c = defaultdict(int)
    for _ in range(n):
        a.append(int(input()))
        c[a[-1]] += 1
    b = a[:]
    a = list(set(a))
    a.sort(reverse=True)
    for e in b:
        i = 0
        while e == a[i] and c[e] == 1:
            i += 1
        print(a[i])

        
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""

1 4
7
RRRR
1 1 0 1
----
4

1 4
47
RCRR
1 1 0 1
----
-1

2 2
10
RR
RR
1 7
4 1
----
4

2 2
10
RR
RR
7 4
7 4
----
-1

3 3
8
RCR
RRC
RRR
1 1 1
1 1 1
1 3 1


3 3
1
RCR
RRC
RRR
1 1 1
1 1 1
1 3 1


"""





Measured memory_bytes: 25744
#include <iostream>
#include <unordered_set>

int parent[100010];
int rank[100010];

void init(int n) {
	for(int i = 0; i < n; i++) {
		parent[i] = i;
		rank[i] = 0;
	}
}

int root(int x) {
	if(parent[x] == x) {
		return x;
	}
	return parent[x] = root(parent[x]);
}

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

void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if(x == y) {
		return;
	}
	if(rank[x] < rank[y]) {
		parent[x] = y;
	} else {
		parent[y];
		if(rank[x] == rank[y]) {
			rank[x]++;
		}
	}
	parent[x] = y;
}

int numGroup(int n) {
	int result = 0;
	for(int i = 0; i < n; i++) {
		if(parent[i] == i) {
			result++;
		}
	}
	return result;
}

int main() {
	int N, M;
	std::cin >> N >> M;

	init(N);

	for(int i = 0; i < M; i++) {
		int X, Y, Z;
		std::cin >> X >> Y >> Z;

		unite(X - 1, Y - 1);
	}

	std::cout << numGroup(N) << std::endl;

	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#define F first
#define S second
#define len(s) (int)s.length()
#define pb push_back
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<LL>
using namespace std;
typedef long long LL;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int n = len(s);
    string s1 = s.substr(0, (n - 1) / 2);
    string s2 = s.substr((n + 3) / 2 - 1);
    string s3 = s, s4 = s1, s5 = s2;
    reverse(all(s3));
    reverse(all(s4));
    reverse(all(s5));
    if (s.compare(s3) == 0 && s1.compare(s4) == 0 && s2.compare(s5) == 0)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define SIZE 26 
int main()
{
  //FAST IO       
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin>>n;
string s;
s=to_string(n);
int l=s.size();
ll pos=s.find('7');
if(pos>=0 && pos<=(n-1) )
cout<<"Yes"<<"\n";
else
cout<<"No"<<"\n";
return 0;
}

Measured memory_bytes: 3716
N=int(input())
lis=list(map(int, input().split()))

even=[]
for i in lis:
    if i%2==0:
        even.append(i)

flag=True
for i in even:
    if i%3==0 or i%5==0:
        pass
    else:
        flag=False

if flag:
    print('APPROVED')
else:
    print('DENIED') 

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

int main() {
	// your code goes here
	int n,k,sum=0,p=0,t;
	int b[200001]={0};
	cin>>n>>k;
	int a[n],i;
	for(i=0;i<n;i++)
	{
	    cin>>a[i];
	    b[a[i]]++;
	}
	for(i=0;i<200001;i++)
	{
	    if(b[i]!=0)
	    p++;
	}
	t=p-k;
	sort(b,b+200001);
	for(i=0;i<200001&&t>0;i++)
	{
	    if(b[i]!=0)
	    {
	        sum+=b[i];
	        t--;
	    }
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf

int n;
long long x;
long long len[55], p[55];

int main() { 

  cin >> n >> x;

  len[0] = 1; p[0] = 1;
  for (int i = 1; i <= n; i++) {
    len[i] = len[i - 1] * 2 + 3;
    p[i] = p[i - 1] * 2 + 1;
  }

  long long ans = 0;

  while (x > 0 && n >= 0) {
    if (n == 0) {
      ans += 1;
      break;
    }
    long long mid = len[n] / 2 + 1;
    if (x == 1) {
      break;
    }
    if (x == mid) {
      ans += p[n - 1] + 1;
      break;
    }
    if (x == len[n]) {
      ans += p[n];
      break;
    }
    if (x < mid) {
      x--;
      n--;
      continue;
    }
    ans += p[n - 1] + 1;
    x -= len[n - 1] + 2; 
    n--;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    cout << ((N==M) ? "Yes" : "No") << endl; 
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	//string masu[H] = {};
	vector<vector<char>> c ( H, vector<char>(W));
	int m[H][W] = {};
	rep(i, H) {
		rep(j, W) {
			cin >> c[i][j];
		}
	}
	rep(i, H) {
		rep(j, W) {
			if (c[i][j] == '#') {
				for (int dx = -1; dx <= 1; dx++) {
					for (int dy = -1; dy <= 1; dy++) {
						int nx = i + dx;
						int ny = j + dy;
						if (0 <= nx && nx < H && 0 <= ny && ny < W) {
							m[nx][ny]++;
						}
					}
				}
			}
		}
	}

	rep(i, H) {
		rep(j, W) {
			if (c[i][j] == '#') {
				cout << "#";
			}
			else {
				cout << m[i][j];
			}
		}
		cout << endl;
	}
}

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

vector<int>dp;
vector<int>A;



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k; cin >> n >> k;
	for(int i = 0; i < k; i++){
		dp.emplace_back(0);
	}
	for(int i = 0; i < n; i++){
		int a; cin >> a;
		A.emplace_back(a);
		
	}
	dp[0] = 0;
	for(int i = 1; i <= k; i++){
		bool bl = true;
		for(int j = 0; j < n; j++){
			if(i < A[j]){
				;
			}
			else{
				if(dp[i - A[j]] == 0){
					dp[i] = 1;
				}
				//dp[i - 1] = min(dp[i - A[j] - 1] + 1, dp[i - 1]);
				
			}
			
		}
	}
	
	if(dp[k] == 1){
		cout << "First\n"; 
		return 0;
	}
	cout << "Second\n" ;
	
	
	
	
	return 0;

}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ash[100001];
ll ans=0;
ll f(ll a[],ll start,ll size,ll k)
{
   if(start==size-1)
   return 0;
   if(ash[start]!=-1)
   return ash[start];
   ll cost=f(a,start+1,size,k)+abs(a[start]-a[start+1]);
    for(int i=2;i<=k;i++)
                 {
                  if(start+i<size) 
   cost=min(cost,(f(a,start+i,size,k)+abs(a[start]-a[start+i])));
                 }
     return ash[start]=cost;
}
int main()
{
    memset(ash,-1,sizeof(ash));
  ll n,k;
  cin>>n>>k;
  ll a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  ll start=0,ans1;
  ans1=f(a,start,n,k);
  cout<<ans1;
  
}
  

Measured memory_bytes: 12916
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int product = a*b;
		if((product % 2) == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}
	}
}


Measured memory_bytes: 20820
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  ll X,K,D;
  cin>>X>>K>>D;

  X=abs(X);
  ll need=X/D;
  if(need>=K) cout<<X-D*K<<endl;
  else{
    ll rest=K-need;
    if(rest%2==0) cout<<X-D*need<<endl;
    else cout<<abs(X-D*(need+1))<<endl;
  }

  return 0;
}


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

using namespace std;

const int MOD = 1000000007;

int main(){
    int N, K;
    while(cin >> N >> K){
        vector<int> A(N);
        for(auto& t : A) cin >> t;
        long long m = (long long)K*(K-1)/2 % MOD;
        long long res = 0;
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(A[i] > A[j]) res = (res+m)%MOD;
                if(i < j && A[i] > A[j]) res = (res+K)%MOD;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  int K, X;
  std::cin >> K >> X;

  int l = X - K + 1;
  int r = X + K - 1;
  chmax(l, -1000000);
  chmin(r, 1000000);
  for (int i = l; i <= r; ++i)
    std::cout << i << " ";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	ll ret=1;
	REP(i,n) {
		if(a[i]%2==0) ret*=2;
		else ret*=1;
	}
	ll buf=1;
	REP(i,n) {
		buf*=3;
	}
	cout<<buf-ret<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

typedef long long ll;

const ll MOD = 1E9 + 7, MAXD = 60;

ll n;
ll f[MAXD + 1][3];

int main(){
	scanf("%lld", &n);

	f[MAXD][0] = 1;
	for (int i = MAXD - 1; i >= 0; --i){
		int z = n >> i & 1;
		if (z == 0){
			f[i][0] = (f[i + 1][0] + f[i + 1][1]) % MOD;
			f[i][1] = (f[i + 1][1]) % MOD;
			f[i][2] = (f[i + 1][1] + f[i + 1][2] * 3) % MOD;
		}
		else{
			f[i][0] = (f[i + 1][0]) % MOD;
			f[i][1] = (f[i + 1][0] + f[i + 1][1]) % MOD;
			f[i][2] = (f[i + 1][1] * 2 + f[i + 1][2] * 3) % MOD;
		}
	}

	printf("%lld\n", (f[0][0] + f[0][1] + f[0][2]) % MOD);
	return 0;
}


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

/*
提出前に確認!
- setとmultisetを間違えない
*/

int	main(void)
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	long long all = 0;
	for (int i = 0; i < n; i++) all += a[i];
	vector<int> count_a(1e5 + 1, 0);
	for (int i = 0; i < n; i++) count_a[a[i]]++;
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int b, c;
		cin >> b >> c;
		all += (long long)(c - b) * count_a[b];
		count_a[c] += count_a[b];
		count_a[b] = 0;
		cout << all << endl;
	}
	return (0);
}


Measured memory_bytes: 4000
from itertools import groupby
import numpy as np


def solve(s, k):
    sgrp = [len(list(itr)) for c, itr in groupby(s)]
    if len(sgrp) == 1:
        return 1

    one_bucket = []
    MOD = 998244353

    if s[0] == '1':
        one_bucket.append(sgrp[0])
        sgrp = sgrp[1:]
    else:
        one_bucket.append(0)

    cur = 0
    for l in sgrp:
        if cur == 0:
            one_bucket.extend([0] * (l - 1))
        else:
            one_bucket.append(l)
        cur ^= 1

    k = min(k, sum(one_bucket))
    dp = np.zeros((k + 1, k + 1), dtype=np.int64)
    dp[0, 0] = 1

    for i, c in enumerate(one_bucket):
        ndp = np.add.accumulate(dp, axis=0)
        if c > 0:
            for j in range(1, c + 1):
                ndp[:, j:] += dp[:, :-j]
            ndp = np.tril(ndp)
        dp = ndp % MOD

    return np.diag(dp).sum() % MOD


s, k = input().split()
k = int(k)

print(solve(s, k))


Measured memory_bytes: 28832
#include <iostream>
#include <array>
#include <algorithm>
using namespace std;
const int maxn = 3e5+6;
using ll = long long;
array<ll,maxn>arr;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int num;
    ll tot = 0;
    cin >> num;
    for(int i = 0;i<num;++i)
    {
        cin >> arr[i];
        arr[i] += arr[i-1];
    }
    ll dis = 1e17;
    ll tmp = 0;
    for(int i = 0;i<num-1;++i) {
        dis = min(dis,abs(arr[i]-arr[num-1]+arr[i]));
    }
    cout << dis << endl;
}

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

int gcd(int x, int y){
    int tmp;
    while(x%y != 0){
        tmp = x;
        x = y;
        y = tmp%y;
    }

    return y;
}

int main(){
    int x, y;
    cin >> x; 
    cin >> y;

    cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3096
lines = $stdin.read
array = lines.split("\n")

def knapsack(n,w,items)

  dp = Array.new(N+1).map{Array.new(W+1, 0)}

  for i in 1...N+1
    for w in 1...W+1
      if items[i].w <= w
        dp[i][w] = [items[i].v + dp[i-1][w - items[i].w], dp[i-1][w]].max
      else
        dp[i][w] = dp[i-1][w]
      end
    end
  end

  dp
end

Item  = Struct.new(:v, :w)
N,W   = array[0].split(" ").map(&:to_i)

items = [Item.new(0,0)]
array[1..array.length].each do |s|
  item = Item.new
  item.v, item.w = s.split(" ").map(&:to_i)
  items << item
end

dp = knapsack(N,W,items)
puts dp.max.max

Measured memory_bytes: 14764
A = [
    list(map(int, input().split())),
    list(map(int, input().split())),
    list(map(int, input().split()))
]
N = int(input())
B = list()
for i in range(N):
    B.append(int(input()))
if ((A[0][0] in B and A[0][1] in B and A[0][2] in B)
    or (A[1][0] in B and A[1][1] in B and A[1][2] in B)
    or (A[2][0] in B and A[2][1] in B and A[2][2] in B)
    or (A[0][0] in B and A[1][0] in B and A[2][0] in B)
    or (A[0][1] in B and A[1][1] in B and A[2][1] in B)
    or (A[0][2] in B and A[1][2] in B and A[2][2] in B)
    or (A[0][0] in B and A[1][1] in B and A[2][2] in B)
    or (A[0][2] in B and A[1][1] in B and A[2][0] in B)):
    print("Yes")
else:
    print("No")

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll n;cin>>n;
  ll a[n],b[n],c[n];
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)cin>>b[i];
  rep(i,0,n)cin>>c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);

  ll ans=0;
  rep(i,0,n){

    // ll top=n-(a+n-lower_bound(a,a+n,b[i]));
    ll top=(lower_bound(a,a+n,b[i])-a);
    ll bottom=c+n-(upper_bound(c,c+n,b[i]));
    // out(top<<":"<<bottom);
    ans+=top*bottom;
  }

  out(ans);



  return 0;
}


Measured memory_bytes: 2560
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            int e = sc.nextInt();
            int f = sc.nextInt();
            
            float delta = a * e - b * d;
            
            if (Math.abs((e * c - b * f) / delta)< 1e-3){
                float x = 0;
                System.out.printf("%.3f ", x);
            }else{
                float x = (e * c - b * f) / delta;
                System.out.printf("%.3f ", x);
            }
            
            if (Math.abs((a * f - d * c) / delta) < 1e-3){
                float y = 0;
                System.out.printf("%.3f\n", y);
            }else{
                float y = (a * f - d * c) / delta;
                System.out.printf("%.3f\n", y);
            }
        }
    }
}

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

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

    vector<int> v(n, 0);

    for (int i = 0; i < n; i++){
        v[a[i] - 1] = i + 1;
    }

    for (int i = 0; i < n; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    cout << n*n*n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  long long int N, count=0, i, M;
  scanf("%lld", &N);
  for (i = 1; i*i <= N; i++) {
    if (N % i == 0) {
      M = N/i;
      if (i+2 <= M) {
        count += M-1;
      }
    }
  }
  printf("%lld\n", count);
  return 0;
}

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

typedef struct Node{
  int key;
  struct Node *parent, *left, *right;
}Node;

Node *root,*NIL;

void insert(int key){
  Node *x,*y,*z; 

  y = NIL;
  x = root;

  z = (Node *)malloc(sizeof(Node));

  z->key = key;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;

    if(z->key < x->key)
      x = x->left;

    else
      x = x->right;
  }

  z->parent = y;

  if(y == NIL)
    root = z;

  else if(z->key < y->key)
    y->left = z;

  else
    y->right = z;
}

void printi(Node *a){
  if(a == NIL)
    return;

  printi(a->left);
  printf(" %d", a->key);
  printi(a->right);
}

void printp(Node *a){
  if(a == NIL)
    return;

  printf(" %d", a->key);
  printp(a->left);
  printp(a->right);
}

int main(){
  int n,i,a;
  char s[100];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s", s);

    if(strcmp(s, "insert") == 0){
      scanf("%d", &a);
      insert(a);
    }

    else if(strcmp(s, "print") == 0){
      printi(root);
      printf("\n");
      printp(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;

pair<double, int> vml[4];  //1Lあたりの価値とミリリットル

signed main()
{
    int Q, H, S, D;
    int N;

    cin >> Q >> H >> S >> D;
    vml[0].first = Q / 0.25;
    vml[0].second = 250;
    vml[1].first = H / 0.5;
    vml[1].second = 500;
    vml[2].first = S;
    vml[2].second = 1000;
    vml[3].first = D / 2.0;
    vml[3].second = 2000;

    sort(vml, vml + 4);
    //reverse(vml, vml + 4);

    /*
    REP(i,4) {
        cout << vml[i].first << " : " << vml[i].second << endl;
    }
    */

    cin >> N;
    N *= 1000;

    int ans = 0;
    REP(i,4) {
        if (vml[i].second == 250) {
            ans += N / 250 * Q;
            N %= 250;
        } else if (vml[i].second == 500) {
            ans += N / 500 * H;
            N %= 500;
        } else if (vml[i].second == 1000) {
            ans += N / 1000 * S;
            N %= 1000;
        } else if (vml[i].second == 2000) {
            ans += N / 2000 * D;
            N %= 2000;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	
	
		ll n,i,j,k,u,v,a,b=0;
		cin>>n>>k;
		while(n>0)
		{
			n=n/k;
			b++;
			}	
			cout<<b<<endl;
	
}

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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	
	int n, a[100000];
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) a[i]--;
	
	int curr = 0;
	for(int i = 0; i < 100000; i++) {
		curr = a[curr];
		if(curr == 1) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	
	cout << -1 << endl;
}

Measured memory_bytes: 640
n = int(input())
nums = list(map(int,input().split()))

operation = []
for i in range(n):
    for j in range(len(nums)):
        if nums[len(nums)-j-1] == len(nums)-j:
            operation.append(nums[len(nums)-j-1])
            del nums[-j-1]
            break

if len(nums) == 0:
    for elem in reversed(operation):
        print(elem)
else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

long double dp[301][301][301];
long double N;

long double solve(int ones, int twos, int threes){
	if(dp[ones][twos][threes] >= 0) return dp[ones][twos][threes];
	long double cur = 1;
	if(threes > 0) cur += (threes/N) * (solve(ones,twos+1,threes-1));
	if(twos > 0) cur += (twos/N) * (solve(ones+1,twos-1,threes));
	if(ones > 0) cur += (ones/N) * (solve(ones-1,twos,threes));
	cur *= N / (ones+twos+threes);
	return dp[ones][twos][threes] = cur;
}


void solution(){
	// expected value dp -- states are messed up, use top down to simplify implementation
	int n; cin >> n;
	N = (long double)n;
	vector<int> a(n); for(auto& x : a) cin >> x;
	int ones = 0, twos = 0, threes = 0;
	for(int x : a){
		if(x == 1) ones++;
		else if(x == 2) twos++;
		else threes++;
	}
	memset(dp,-1,sizeof(dp));
	dp[0][0][0] = 0;
	printf("%0.14Lf\n", solve(ones,twos,threes));
}	


int main(){ 

	fio; // fast input output
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// GOOGLE //
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}


Measured memory_bytes: 429928
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

    let mut ans = "APPROVED";
    for ai in a {
        if ai % 2 != 0 {
            continue;
        }
        if !(ai % 3 == 0 || ai % 5 == 0) {
            ans = "DENIED";
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int>x(n);
	REP(i, n) cin >> x[i];
	int sum = 0;
	REP(i, n){
		if(abs(x[i] - k) > x[i]) sum += x[i];
		else sum += abs(x[i] - k);
	}

	cout << sum * 2 << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    if ((a < 0 and b > 0) or (a == 0 or b == 0)) cout << "Zero\n";
    else if (a > 0) cout << "Positive\n";
    else if (b < 0) {
        if ((abs(a - b)+1) % 2 == 0) cout << "Positive\n";
        else cout << "Negative\n";
    }
    
    return 0;
}

Measured memory_bytes: 3664
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
        String b[] = a.split("");
      
        int count = 0;
        int half = a.length() / 2;
        for(int i = 0; i < half;i++){
          if(!b[i].equals(b[a.length() - 1 - i])){
            count += 1;
          }
        }
        
      	System.out.println(count);
 
    }
}

Measured memory_bytes: 35632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

int main(){
    ll N, M, X; cin >> N >> M >> X;
    vector<ll> c(N);
    vector<vector<ll>> a(N, vector<ll>(M));
    rep(i, N){
        cin >> c[i];
        rep(j, M) cin >> a[i][j]; 
    }
    ll ans = INF;
    rep(con, 1LL << N){
        ll cnt = 0;
        vector<ll> p(M, 0);
        rep(i, N){
            if (((con >> i) & 1 )== 0) continue;
            cnt += c[i];
            rep(j, M) p[j] += a[i][j];
        }
        bool ok = true;
        rep(i, M) if (p[i] < X) ok = false;
        if (ok) chmin(ans, cnt);
        // pt(con, cnt);
    }
    pt(ans == INF ? -1 : ans);

}

Measured memory_bytes: 3632
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

def f(x):
    if x == 0:
        return 1
    if x == 1:
        return x
    else:
        return x * f(x-1)

nlist = list(range(1, n+1))

po = 0
for i in range(n):
    po += f(n-i-1)*nlist.index(p[i])
    nlist.remove(p[i])
po+=1
nlist = list(range(1, n+1))
qo = 0
for i in range(n):
    qo += f(n-i-1)*nlist.index(q[i])
    nlist.remove(q[i])
qo+=1
print(abs(po-qo))

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

//解説pdfより
const int nmax = 8;
bool graph[nmax][nmax];//セグ木を表すジャグ配列

//再起関数dfs
int dfs(int v, int N, bool visited[nmax]) { //vは今いるnodeの番号-1
    bool allvisited = true;//今のルートがすべてのnodeを網羅したかどうか
    for (int i = 0; N > i; i++) if (visited[i] == false) allvisited = false;//上記を調べる
    if (allvisited) return 1;//網羅したらパターンとしてretに１を足して１階層戻ってみる
    
    int ret = 0;
    for (int i = 0; N > i; ++i) {
        if (graph[v][i] == false) continue;//vからiへ行けるかどうか
        if (visited[i]) continue;//今の階層の前の階層か
        //もしvからiに行けかつ前の階層でなければ
        visited[i] = true;//次の階層に行く前にvisitedをtrueに
        ret += dfs(i, N, visited);//再起
        visited[i] = false;//他の階層を探索するためにvisitedをfalseに戻す
    }

    return ret;//今の合計を戻し一つ前の階層の合計に足し合わせる
    //retに足す数字はallvisitedが成り立った時の1しかないのでretは答えとなる
}

//nodeは常にnodenum-1で保持
int main(void){
    int N, M;
    cin >> N >> M;

    for (int i = 0; M > i; ++i) {
        int A, B;
        cin >> A >> B;
        graph[A - 1][B - 1] = graph[B - 1][A - 1] = true;//互いの頂点同士行き来できるかどうか
    }

    bool visited[nmax];//訪れたかどうか
    for (int i = 0; N > i; ++i) visited[i] = false;

    visited[0] = true;//１は二度と戻ってこないためtrue
    cout << dfs(0, N, visited) << endl;//探索開始
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

ans=[[0 for i in range(W)] for j in range(H)]

color=1
cnt=0

for i in range(H):
    for j in range(W):
        if i%2==0:
            k=j
        else:
            k=-(1+j)
        
        ans[i][k]=color
        cnt+=1
        if cnt==A[color-1]:
            color+=1
            cnt=0


for i in range(H):
    print(*ans[i])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()
#define triple pair<ll, pill>


using namespace std;

const ll N = 11;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;

ll n, m, q;

vector<triple> x[N]; 

ll cur[N];

ll rec(ll i = 0, ll lst = 1) {
	if(i == n) 
		return 0;
	ll mx = 0;
	for(int j = lst; j <= m; j++){
		cur[i] = j;
		ll ans = rec(i + 1, j);
		for(auto u : x[i])
			ans += (j - cur[u.f] == u.s.f ? u.s.s : 0);
		mx = max(ans, mx); 
	}
	return mx;
}

int main() {
	speed;
	cin >> n >> m >> q;
	while(q--) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		x[b - 1].pb({a - 1, {c, d}});
	}
	cout << rec();
}

/*

0 133 14 135 28 137 42 139 56 141 70 143

*/



Measured memory_bytes: 3652
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int> > s(H, vector<int>(W, 0));
    for (int i = 0; i < H; ++i) {
        string row;
        cin >> row;
        for (int j = 0; j < W; ++j) {
            s[i][j] = (row[j] == '#') ? 1 : 0;
        }
    }

    vector<vector<int> > minFlip(H, vector<int>(W, -1));
    for (int i = H - 1; i >= 0; --i) {
        for (int j = W - 1; j >= 0; --j) {
            if (i == H - 1 && j == W - 1) {
                minFlip[i][j] = (s[i][j] == 1) ? 1 : 0;
                continue;
            }
            int nflip = 1000;
            // go to i + 1
            if (i < H - 1) {
                nflip = min(
                    nflip,
                    minFlip[i + 1][j] + ((s[i][j] == 1 && s[i + 1][j] == 0) ? 1 : 0)
                );
            }
            // go to j + 1
            if (j < W - 1) {
                nflip = min(
                    nflip,
                    minFlip[i][j + 1] + ((s[i][j] == 1 && s[i][j + 1] == 0) ? 1 : 0)
                );
            }
            minFlip[i][j] = nflip;
        }
    }
    cout << minFlip[0][0] << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 384
N, M = map(int, input().split())
H = list(map(int, input().split()))
A=[0]*M
B=[0]*M
Nset=set(range(N))

for i in range(M):
    A[i], B[i] = map(int, input().split())
    if H[A[i]-1] < H[B[i]-1]:
        Nset -= set([A[i]-1])
    elif H[A[i]-1] > H[B[i]-1]:
        Nset -= set([B[i]-1])
    else:
        Nset -= set([B[i]-1])
        Nset -= set([A[i]-1])
print(len(Nset))


Measured memory_bytes: 28300
#include<stdio.h>
 
 
int main(){
  int N,i,j,sum=1;
  int flag;
  
  scanf("%d", &N);
  int H[N];
  for(i=0;i<N;i++){
    scanf("%d", &H[i]);
  }
  for(i=1;i<N;i++){
    flag=0;
    for(j=0;j<i;j++){
      if(H[j]>H[i]){
        flag = 1;
        break;
      }
    }
    if(flag==0) sum++;
  }
  printf("%d",sum);
  
  return 0;
  
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main() {
  int n=0;
  cin >> n;
  for (int i=0; i < 10; ++i) {
      for (int j=0; j < 10; ++j) {
       if (n == i*j) {
  		 cout << "Yes";
         return 0;
       }
  	}
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 111111;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin>>s;
    for(auto c:s){
        if(c!='x')t+=c;
    }
    int ts=t.size();
    for(int i=0;i<ts;i++){
        if(t[i]!=t[ts-i-1]){
            cout<<-1<<endl;
            return 0;
        }
    }
    int r=s.size()-1,l=0,res=0;
    while(l<r){
        if(s[l]!=s[r]){
            res++;
            if(s[l]=='x')l++;
            else r--;
        }
        else{
            l++;
            r--;
        }
    }
    cout<<res<<endl;
}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;

/*************************************************************************/

bool check(int mid, int n, int m, VVI &perm) {
    VI pos(n, 0);
    VB alive(m, true);
    
    while (true) {
        if (*max_element(pos.begin(), pos.end()) == m) {
            return false;
        }
        
        VI cnt(m, 0);
        FOR(i,0,n-1) {
            cnt[perm[i][pos[i]]]++;
        }
        
        auto it = max_element(cnt.begin(), cnt.end());
        
        if (*it <= mid) {
            return true;
        }
        
        int toKill = it - cnt.begin();
        alive[toKill] = false;
        
        FOR(i,0,n-1) while (pos[i] < m && !alive[perm[i][pos[i]]]) {
            pos[i]++;
        }
    }
}

/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n, m;
    cin >> n >> m;
    
    VVI perm(n, VI(m));
    FOR(i,0,n-1) FOR(j,0,m-1) {
        cin >> perm[i][j];
        perm[i][j]--;
    }
    
    int l = 0, r = n;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        
        if (check(mid, n, m, perm)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    
    cout << r;

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 640
<?php
$WORD = trim(fgets(STDIN));
$LEN = strlen($WORD);

$ALPHA = [
    'index'    => range('a', 'z'),
    'indexRev' => array_flip(range('a', 'z')),
];

$nextWord = '';
if ($LEN < 26) {
    foreach ($ALPHA['index'] as $char) {
        if (strpos($WORD, $char) === false) {
            $nextWord = $WORD . $char;
            echo $nextWord;
            exit;
        }
    }
} else {
    $nextWord = $WORD;
    for ($i=$LEN-1; $i >= 0; $i--) {
        $lastChar = substr($nextWord, -1);
        $nextWord = substr($nextWord, 0, -1);

        if ($lastChar === 'z') {
            continue;
        }

        for ($j=$ALPHA['indexRev'][$lastChar]+1; $j < 26; $j++) {
            $nextChar = $ALPHA['index'][$j];
            if (strpos($nextWord, $nextChar) === false) {
                $nextWord = $nextWord . $nextChar;
                echo $nextWord;
                exit;
            } else {
                continue;
            }
        }
    }
}

echo '-1';

Measured memory_bytes: 4604
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int a,b;
  cin>>a>>b;
  if(a==1) a=14;
  if(b==1) b=14;
  if(a<b) cout<<"Bob"<<endl;
  else if(a>b) cout<<"Alice"<<endl;
  else cout<<"Draw"<<endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

const int MAX = 2e3+10;
const int MOD = 1e9+7;

int N, M;
vi S, T;
ll dp[MAX][MAX];
ll s[MAX][MAX];

int solve() {
    int ans = 1;
    REP (n, N) REP (m, M) {
        if (S[n] == T[m]) {
            dp[n][m] = (s[n][m]+1) % MOD;
        }
        ans = (ans + dp[n][m]) % MOD;
        s[n+1][m+1] = (MOD + s[n+1][m] + s[n][m+1] - s[n][m] + dp[n][m]) % MOD;
    }
    return ans;
}

int main() {
    cin >> N >> M;
    S = vi(N);
    T = vi(M);
    REP (i, N) cin >> S[i];
    REP (i, M) cin >> T[i];

    cout << solve() << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL MOD;
LL mod(LL x, LL m = MOD) { return (x % m + m) % m; }
pair<LL, LL> ex_gcd(LL a, LL b) {
	if(b == 0) { return MP(1, 0); }
	auto p = ex_gcd(b, a % b);
	return MP(p.SE, p.FI - (a / b) * p.SE);
}
LL inv(LL x, LL m = MOD) {
	assert(gcd(x, m) == 1);
	auto p = ex_gcd(x, m);
	return mod(p.FI, m);
}
LL promod(LL x, LL y, LL m = MOD) { return mod((x % m) * (y % m), m); }
LL divmod(LL x, LL y, LL m = MOD) { return promod(x, inv(y, m), m); }

// ----

struct CombMod {
	LL lim = 0, mod;
	LL * fact; // fact[i]: i の階乗
	LL * finv; // finv[i]: i の階乗の逆元
	
	CombMod() { }
	CombMod(LL lim, LL mod = MOD) { init(lim, mod); }
	void init(LL arg_lim, LL arg_mod = MOD) {
		lim = arg_lim;
		mod = arg_mod;
		fact = new LL[lim + 1];
		finv = new LL[lim + 1];
		fact[0] = 1;
		inc1(i, lim) { fact[i] = promod(fact[i - 1], i, mod); }
		finv[lim] = inv(fact[lim], mod);
		dec(i, lim) { finv[i] = promod(finv[i + 1], i + 1, mod); }
	}
	LL P(LL a, LL b) {
		assert(inII(a, 0, lim) && inII(b, 0, lim));
		return (a < b ? 0 : promod(fact[a], finv[a - b], mod));
	}
	LL C(LL a, LL b) {
		assert(inII(a, 0, lim) && inII(b, 0, lim));
		return (a < b ? 0 : promod(P(a, b), finv[b], mod));
	}
	LL H(LL a, LL b) {
		assert(inII(a, 0, lim) && inII(b, 0, lim) && inII(a + b - 1, -1, lim));
		return (a == 0 ? (b == 0) : C(a + b - 1, b));
	}
};

// ----


LL n, a, b, k, ans;

int main() {
	cin >> n >> a >> b >> k;
	
	MOD = 998244353;
	CombMod cm(n);
	
	incII(i, 0, n) {
		LL v = k - i * a;
		if(v % b == 0) {
			LL j = v / b;
			if(! inII(j, 0, n)) { continue; }
			(ans += cm.C(n, i) * cm.C(n, j) ) %= MOD;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4992