akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,Ma,Mb = LI()
a,b,c = LIR(N,3)

n = N//2

d1 = [[5000]*401 for _ in range(401)]
d2 = [[5000]*401 for _ in range(401)]

for bit in range(1<<n):
    val_a = 0
    val_b = 0
    cost = 0
    for i in range(n):
        if bit>>i&1:
            val_a += a[n-1-i]
            val_b += b[n-1-i]
            cost += c[n-1-i]
    d1[val_a][val_b] = min(d1[val_a][val_b],cost)

for bit in range(1<<(N-n)):
    val_a = 0
    val_b = 0
    cost = 0
    for i in range(N-n):
        if bit>>i&1:
            val_a += a[N-1-i]
            val_b += b[N-1-i]
            cost += c[N-1-i]
    d2[val_a][val_b] = min(d2[val_a][val_b],cost)


vals = []
now = 1
while True:
    if Ma*now <= sum(a) and Mb*now <= sum(b):
        vals.append((Ma*now,Mb*now))
        now += 1
    else:
        break

ans = 5000
for ka in range(401):
    for kb in range(401):
        if d1[ka][kb] != 5000:
            for v in vals[::-1]:
                left_a = v[0]-ka
                left_b = v[1]-kb
                if left_a < 0 or left_b < 0:
                    break
                if d1[ka][kb]+d2[left_a][left_b] < ans:
                    ans = d1[ka][kb]+d2[left_a][left_b]

if ans == 5000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 47324
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 1e2 + 1 , W = 1e5 + 1;
int n , w;
ll  dp[W] , mx;
int main(){
	scanf("%d%d",&n,&w);
	for (int i = 1,x,val; i <= n; ++i){
		scanf("%d%d",&x,&val);
		for (int j = w; j >= x; --j){
			dp[j] = max(dp[j] ,dp[j-x] + val );
			//cout << i << " " << j <<" " << dp[j] <<endl;
		}
		//puts("");
	}
	cout << dp[w] << endl;



}	

Measured memory_bytes: 4524
#57b
N,M = map(int, input().split())

student_xy = []
for i in range(N):
    a,b = map(int, input().split())
    student_xy.append((a,b))
    
check_point_xy = []
for i in range(M):
    c,d = map(int, input().split())
    check_point_xy.append((c,d))

#1点目だけ初期化用に分ける
point_no_distance = []

cd = check_point_xy[0]
c = cd[0]
d = cd[1]
point_no = 1

for i in range(N):
    ab = student_xy[i]
    a = ab[0]
    b = ab[1]
    distance = abs(c-a) + abs(d-b)
    point_no_distance.append((point_no,distance))

#2点目以降
for j in range(1,M):
    cd = check_point_xy[j]
    c = cd[0]
    d = cd[1]
    point_no = j + 1
    
    for i in range(N):
        ab = student_xy[i]
        a = ab[0]
        b = ab[1]
        distance = abs(c-a) + abs(d-b)
        if distance < point_no_distance[i][1]:
            point_no_distance[i] = (point_no,distance)
            
for i in range(N):
    pd = point_no_distance[i]
    print(pd[0])

Measured memory_bytes: 3064
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7
import heapq

def ddprint(x):
  if DBG:
    print(x)

x,y,z,k = inm()
a = inl()
b = inl()
c = inl()

h = []
for i in a:
    for j in b:
        if len(h)<k:
            heapq.heappush(h,i+j)
        else:
            heapq.heappushpop(h,i+j)
g = []
for i in c:
    for j in h:
        if len(g)<k:
            heapq.heappush(g,i+j)
        else:
            heapq.heappushpop(g,i+j)

d = []
for i in range(k):
    d.append(heapq.heappop(g))
for i in range(k-1,-1,-1):
    print(d[i])


Measured memory_bytes: 54236
#include <iostream>

int main()
{
  int N;
  int A[100];
  std::cin >> N;
  for (int i = 0; i < N; ++i)
  {
    std::cin >> A[i];
    std::cout << A[i];
    if (i < N - 1)
      std::cout << ' ';
  }
  std::cout << std::endl;

  for (int i = 1; i < N; ++i)
  {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v)
    {
      A[j + 1] = A[j];
      --j;
    }
    A[j + 1] = v;
    
    for (int i = 0; i < N; ++i)
    {
      std::cout << A[i];
      if (i < N - 1)
      {
        std::cout << ' ';
      }
    }
    std::cout << std::endl;
  }
}
/*
1 insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
2   for i が 1 から N-1 まで
3     v = A[i]
4     j = i - 1
5     while j >= 0 かつ A[j] > v
6       A[j+1] = A[j]
7       j--
8     A[j+1] = v
*/



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;

    cout << T + S << endl;
}

Measured memory_bytes: 256
//File Name: arc074_C.cpp
  //Created Time: 2017年06月17日 星期六 18时25分11秒
                                   
#include <bits/stdc++.h>
#define LL long long
#define pii pair<int,int>
#define fir first
#define sec second
using namespace std;
const int MAXN = 303;
const int P = (int)1e9 + 7;
LL f[MAXN][MAXN][MAXN];
vector<pii> que[MAXN];
void add(LL &x,LL y){
	x += y;
	if(x >= P) x -= P;
}
bool check(int i,int j,int k){
	int ma = max(i,max(j,k));
	int mi = min(i,min(j,k));
	int mid(-1);
	if(mi < i && i < ma) mid = i;
	else if(mi < j && j < ma) mid = j;
	else if(mi < k && k < ma) mid = k;
	if(mid == -1) mid = 0;
	for(auto cur:que[ma]){
		int l = cur.fir;
		int x = cur.sec;
		if(mi == 0 && mid == 0){
			if(x != 1) return false;
		}
		else{
			if(x == 3 && l <= mi) continue;
			if(x == 2 && mi < l && l <= mid) continue;
			if(x == 1 && mid < l && l <= ma) continue;
			return false;
		}
	}
	return true;
}
LL solve(const int n,const int m){
	f[0][0][0] = 1;
	for(int i(0);i<n;++i){
		for(int j(0);j<n;++j){
			if(j && (j == i)) continue;
			for(int k(0);k<n;++k){
				if(k && (k == i || k == j)) continue;
				if(!f[i][j][k]) continue;
				int nxt = max(i,max(j,k)) + 1;
				if(check(nxt,j,k)) 
					add(f[nxt][j][k],f[i][j][k]);
				if(check(i,nxt,k))
					add(f[i][nxt][k],f[i][j][k]);
				if(check(i,j,nxt))
					add(f[i][j][nxt],f[i][j][k]);
			}
		}
	}
	LL res(0);
	for(int i(0);i<n;++i){
		for(int j(0);j<n;++j){
			if(i && i == j) continue;
			LL tmp = f[i][j][n] + f[i][n][j] + f[n][i][j];
			tmp %= P;
			add(res,tmp);
		}
	}
	return res;
}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i(1),l,r,x;i<=m;++i){
		scanf("%d %d %d",&l,&r,&x);
		que[r].push_back(pii(l,x));
	}
	printf("%lld\n",solve(n,m));
	return 0;
}


Measured memory_bytes: 217344
#include <bits/stdc++.h>
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)

using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main()
{
    int X, A;
    cin >> X >> A;
    if (X < A) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n));i>0;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(){
	string a, b;
	cin >> a >> b;
	string S = a + b;
	int N = stoi(S);
	double X = sqrt(N);
	N = sqrt(N);
	cout << ((X == N) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
K = [0] * N
A = [[0 for j in range(M)] for i in range(N)] 
for i in range(N):
    inpt = list(map(int, input().split())) 
    K[i] = inpt[0] 
    for j in range(1, K[i]+1, 1): 
        A[i][j-1] = inpt[j]
count = 0
for j in range(1, M+1, 1): 
    likecount = 0
    for i in range(N): 
        for k in range(K[i]): 
            if A[i][k] == j:
                likecount += 1
    if likecount == N: 
        count += 1
print(count)


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 200'000
i64 N;
i64 A[MAX_N];

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];

    vector<i64> C(N + 1, 0);
    REP(i, N) {
        C[i + 1] = C[i] + A[i];
    }

    i64 cnt = 0;
    map<i64, i64> dist;
    REP(i, N + 1) {
        cnt += dist[C[i]];
        dist[C[i]]++;
    }
    cout << cnt << endl;

    return 0;
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;

struct UnionFind {
    int N;
    vector<int> siz, par, Rank;
    UnionFind(int n) : siz(n, 1), par(n), Rank(n, 0) {
        N = n;
        REP(i, N) par[i] = i;
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else
            return par[x] = find(par[x]);
    }

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

vector<int> X[100010], Y[100010];
void solve() {
    int N, W, H;
    cin >> N >> W >> H;
    int cnt = 0;
    int valid = 0;
    UnionFind uf(N);
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        if (x == W || y == H || x == 1 || y == 1) {
            valid++;
        }
        x--, y--;
        X[x].push_back(i);
        Y[y].push_back(i);
    }
    REP(i, W) {
        REP(j, (int)X[i].size() - 1) { uf.unite(X[i][j], X[i][j + 1]); }
    }
    REP(i, H) {
        REP(j, (int)Y[i].size() - 1) { uf.unite(Y[i][j], Y[i][j + 1]); }
    }
    vector<bool> done(N + 1);
    int ans = -2;

    REP(i, N) {
        if (done[uf.find(i)])
            continue;
        else {
            cnt++;
            ans += 2;
            ans += uf.siz[uf.find(i)] - 1;
            done[uf.find(i)] = true;
        }
    }
    if (cnt >= 2 && valid == 0) {
        ans++;
        // cerr << "invalid" << endl;
    }
    cout << ans << endl;
}

signed main() {
    // while (solve())
    solve();
}


Measured memory_bytes: 10436
#include <cmath>
#include <iostream>
#include <set>

int main() {
  uint32_t n = 0;
  std::cin >> n;

  std::set<uint32_t> divisors;
  uint32_t remain = n;
  while (remain % 2 == 0) {
    remain /= 2;
    divisors.insert(2);
  }

  for (size_t i = 3; i * i <= remain; i += 2) {
    while (remain % i == 0) {
      remain /= i;
      divisors.insert(i);
    }
  }
  if (remain != 1) divisors.insert(remain);

  uint64_t numerator = 1, denominator = 1;
  for (auto &&d : divisors) {
    numerator *= d - 1;
    denominator *= d;
  }
  std::cout << n * numerator / denominator << std::endl;

  return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>//next_permutation
using namespace std;


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

    sort(v,v+n) ;
    double tmp = (v[0]+v[1])/2.0 ;
    for(int i=2;i<n;++i){
    tmp = (tmp+v[i])/2.0 ;
    }

    cout << tmp << endl;

  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int s = 0;
		for (int j = 0; j < i; j++) {
			if (h.at(i) - h.at(j) >= 0)s++;
		}
		if (s == i)cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
xx, yy, zz, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=1)
b.sort(reverse=1)
c.sort(reverse=1)
ans = []

for x in range(min(xx, k)):
    for y in range(min(yy, k // (x + 1))):
        for z in range(min(zz, k // ((x + 1) * (y + 1)))):
            ans.append(a[x] + b[y] + c[z])
ans.sort(reverse=1)

for i in range(k):
    print(ans[i])


Measured memory_bytes: 46064
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        PrintWriter out = new PrintWriter(System.out);

        for (int i = 0; i < S.length() - 1; i++) {
            if (S.charAt(i + 1) == (S.charAt(i))) {
                out.println("NO");
                sc.close();
                out.flush();
                return;
            }
        }

        String[] s = S.split("A");
        String kihbr = "";

        for (int i = 0; i < s.length; i++) {
            kihbr += s[i];
        }

        if (kihbr.equals("KIHBR")) {
            if (S.charAt(0) == 'A') {
                if (S.charAt(2) == 'A' || S.charAt(3) == 'A') {
                    out.println("NO");
                    sc.close();
                    out.flush();
                    return;
                }
            } else {
                if (S.charAt(1) == 'A' || S.charAt(2) == 'A') {
                    out.println("NO");
                    sc.close();
                    out.flush();
                    return;
                }
            }
            out.println("YES");
        } else {
            out.println("NO");
        }

        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 39520
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	ll X;
	scanf("%lld",&X);

	ll left = 0,right = 1000000,mid = (left+right)/2;
	ll ans = 1000000;

	while(left <= right){

		if((mid*(mid+1)/2) >= X){

			ans = mid;
			right = mid-1;
		}else{

			left = mid+1;
		}
		mid = (left+right)/2;
	}

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

	return 0;
}


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

int main() {

	int N, A;
	cin >> N >> A;
	const int coin = 500;

	/*if (A >= N % coin)cout << "Yes" << endl;
	else cout << "No" << endl;*/
	cout << (A >= N % coin ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

char calcClassOfStudent(int math, int english, int japanese);

int main()
{
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        for (int i = 0; i < n; ++i) {
            int math, english, japanese;
            std::cin >> math >> english >> japanese;
            std::cout << calcClassOfStudent(math, english, japanese) << std::endl;
        }
    }
    return 0;
}

char calcClassOfStudent(int math, int english, int japanese)
{
    if (math == 100 || english == 100 || japanese == 100) {
        return 'A';
    }
    if ((math + english) / 2 >= 90) {
        return 'A';
    }
    const int average_of_all = (math + english + japanese) / 3;
    if (average_of_all >= 80) {
        return 'A';
    }
    if (average_of_all >= 70) {
        return 'B';
    }
    if (average_of_all >= 50 && (math >= 80 || english >= 80)) {
        return 'B';
    }
    return 'C';
}

Measured memory_bytes: 3064
def lcs_fast(x, y):
    len_x = len(x)
    len_y = len(y)

    c = [0] * (len_y + 1)
    for i in range(len_x):
        c_prev = c[:]
        for j in range(len_y):
            if x[i] == y[j]:
                c[j+1] = c_prev[j] + 1
            elif c[j+1] < c[j]:
                c[j+1] = c[j]
    return c[-1]


if __name__ == "__main__":
    n = int(input())
    for i in range(n):
        x = input()
        y = input()
        # print(lcs(x, y))
        print(lcs_fast(x, y))



Measured memory_bytes: 5632
def solve(n):
    p = {}
    for m in range(1,n+1):
        for q in range(2,m+1):
            while m % q == 0:
                if not q in p:
                    p[q] = 0
                p[q] += 1
                m /= q
    S = set()
    # 5 x 5 x 3
    for k1, v1 in p.items():
        for k2, v2 in p.items():
            for k3, v3 in p.items():
                if (v1 >= 2) and (v2 >= 4) and (v3 >= 4) and (k1 != k2) and (k2 != k3) and (k1 != k3):
                    S.add((k1**2) * (k2**4) * (k3**4))
    # 25 x 3
    for k1, v1 in p.items():
        for k2, v2 in p.items():
            if (v1 >= 24) and (v2 >= 2) and (k1 != k2):
                S.add((k1**24) * (k2**2))
    # 15 x 5
    for k1, v1 in p.items():
        for k2, v2 in p.items():
            if (v1 >= 14) and (v2 >= 4) and (k1 != k2):
                S.add((k1**14) * (k2**4))
    # 75
    for k1, v1 in p.items():
        if (v1 >= 74):
            S.add(v1**74)
    return len(S)
print solve(input())

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

struct HopcroftKarp {
    vector<vector<int>> g;
    vector<int> d, mch;
    vector<bool> used, vv;

    HopcroftKarp(int n, int m) : g(n), mch(m, -1), used(n) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
    }

    void bfs() {
        d.assign(g.size(), -1);
        queue<int> que;
        for (int i = 0; i < g.size(); i++) {
            if (!used[i]) {
                que.emplace(i);
                d[i] = 0;
            }
        }

        while (!que.empty()) {
            int a = que.front();
            que.pop();
            for (auto &b : g[a]) {
                int c = mch[b];
                if (c >= 0 && d[c] == -1) {
                    d[c] = d[a] + 1;
                    que.emplace(c);
                }
            }
        }
    }

    bool dfs(int a) {
        vv[a] = true;
        for (auto &b : g[a]) {
            int c = mch[b];
            if (c < 0 || (!vv[c] && d[c] == d[a] + 1 && dfs(c))) {
                mch[b] = a;
                used[a] = true;
                return (true);
            }
        }
        return (false);
    }

    int bipartite_matching() {
        int ret = 0;
        while (true) {
            bfs();
            vv.assign(g.size(), false);
            int flow = 0;
            for (int i = 0; i < g.size(); i++) {
                if (!used[i] && dfs(i)) ++flow;
            }
            if (flow == 0) return ret;
            ret += flow;
        }
    }
};


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

  int n; cin >> n;
  vvi a(n, vi(n));
  for(int i=0;i<n;++i) {
    for(int j=0;j<n;++j) {
      cin >> a[i][j];
    }
  }
  vvll dp(n+1, vll(1<<n));
  dp[0][0] = 1;
  for(int i=0;i<n;++i) {
    for(int j=0;j<n;++j) {
      if(!a[i][j]) continue;
      for(int k=0;k<(1<<n);++k) {
        if(!((k>>j)&1)) {
          dp[i+1][k|(1<<j)] += dp[i][k];
          dp[i+1][k|(1<<j)] %= MOD;
        }
      }
    }
  }

  cout << dp[n][(1<<n)-1] << endl;

}


Measured memory_bytes: 377216
# -*- coding: utf-8 -*-
from sys import stdin

def bubble_sort(A, N):  #N個の要素を含む0-オリジンの配列 A
  flag = True  #逆の隣接要素が存在する
  exchange_cnt =0
  while flag:
    flag = False
    for j in range(N - 1, 0, -1):
      if A[j] < A[j - 1]:
        A[j], A[j - 1] = A[j - 1], A[j]
        flag = True
        exchange_cnt += 1
  return A, exchange_cnt

n = int(stdin.readline().rstrip())
A = list(map(int, stdin.readline().split()))
ans = bubble_sort(A, n)
print(' '.join(map(str,ans[0])))
print(ans[1])


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

ll mod = 1e9+7;
const ld error = 1e-5;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll

inline ll MOD(ll x, ll m = mod)
{
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = 80+5;
///===========================================  template  =======================================================

bitset<25600> dp[nmax][nmax];
int K = 12800;
int main(){
    FASTIO;

    int n, m;
    cin>>n>>m;
    vector<vector<int> >A(n, vector<int>(m));
    vector<vector<int> >B(n, vector<int>(m));

    for(int i = 0; i<n; i++){
        for(int j = 0; j<m; j++)
            cin>>A[i][j];
    }

    for(int i = 0; i<n; i++){
        for(int j = 0; j<m; j++)
            cin>>B[i][j];
    }
    dp[0][0][K] = 1;
    for(int i = 0; i<n; i++){
        for(int j = 0; j<m; j++){
            int diff = abs(A[i][j] - B[i][j]);

            dp[i][j] = (dp[i][j] << diff) | (dp[i][j] >> diff);

            dp[i+1][j] |= dp[i][j];
            dp[i][j+1] |= dp[i][j];
        }
    }

    int ans = inf;
    for(int i = 0; i<25600; i++){
        if(dp[n-1][m-1][i] == 1){
            ans = min(ans, abs(i-K));
        }
    }
    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 22784
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;

int main()
{
	int n, u, k, v1, c1;
	const int INF = 1000000;
	
	cin >> n;
	
	vector<vector<int> > v(n), c(n);
	vector<int> w(n, INF);
	typedef pair<int, int> wt;
	priority_queue<wt, vector<wt>, greater<wt> > que;

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v1 >> c1;
			v[u].push_back(v1);
			c[u].push_back(c1);
		}
	}

	w[0] = 0;
	que.push(wt(0, 0));

	while (!que.empty()) {
		wt g = que.top();
		que.pop();

		int k = g.second;

		if (w[k] < g.first)
			continue;

		for (int i = 0; i < (int)v[k].size(); i++) {
			if (w[v[k][i]] > w[k] + c[k][i]) {
				w[v[k][i]] = w[k] + c[k][i];
				que.push(wt(w[v[k][i]], v[k][i]));
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 7832
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2e5+2;

int main()
{
    fastio;
    ll i, j, k, n, u, v, t;
    vll a;

    cin>>n;
    for ( i = 0; i < n; i++)
    {
        cin>>j;
        a.pb(j);
    }
    ll ans=0;
    for ( i = 0; i < n; i++)
    {
        if(a[i]%2==1 && i%2==0)
        ans++;
    }
    
    cout<<ans<<endl;
        
    return 0;
}

Measured memory_bytes: 3612
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    int AB, BC, CA;

    AtCoder(FastScanner sc) {
        AB = sc.nextInt();
        BC = sc.nextInt();
        CA = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(BC * AB / 2);
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22868
#include<iostream>
using namespace std;
int main()
{
	long int n,m;cin >> n >> m;
	long int k,check = 0;
	long int temp;
	if(n > m)
	{
		temp = n;
		n = m;
		m = temp;
	}
	for(long int i = n;i <= m;i++)
	{
		if(i - n == m - i)
		{
			check = 1;
			cout << i;
			break;
		}
	}
	if(check == 0)cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	ll l, r, d;
	cin >> l >> r >> d;
	cout << r / d - l / d + (l % d == 0) << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<iostream>
#include<algorithm>
#define maxn 200010
using namespace std;
int a[maxn],b[maxn],n,x,c[maxn],d[maxn],i,j,k,ans;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
		scanf("%d",&b[i]);
	for(i=0;i<30;i++)
	{
		x=0;
		for(j=1;j<=n;j++)
		{
			if(a[j]&(1<<i))x^=n&1;
			c[j]=a[j]%(1<<i);
		}
		sort(c+1,c+n+1);
		for(j=1;j<=n;j++)
		{
			if(b[j]&(1<<i))x^=n&1;
			d[j]=b[j]%(1<<i);
		}
		//cout<<"??? "<<i<<" "<<x<<endl;
		sort(d+1,d+n+1);
		//cout<<i<<":"<<endl;
		//cout<<d[1]<<" "<<d[2]<<endl;
		//cout<<c[1]<<" "<<c[2]<<endl;
		//if(i==2)cout<<x<<endl;
		for(j=1,k=n;j<=n;j++)
		{
			while(k&&c[k]+d[j]>=(1<<i))k--;
			//if(i==2)cout<<j<<" "<<k<<" "<<d[j]<<" "<<c[k]<<endl;
			x^=(n-k)&1;
		}
		if(x)ans+=1<<i;
	}
	cout<<ans<<endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	vector<lli> a(n),b(n);
	REP(i,0,n)cin>>a[i];
	REP(i,0,n)cin>>b[i];

	lli sumA=0,sumB = 0;

	REP(i,0,n){
		if(a[i]<b[i]){
			sumA+=(b[i]-a[i])/2;
			if((b[i]-a[i])%2==1){
				sumA++;
				sumB++;
			}
		}
		else sumB += abs(a[i]-b[i]);
	}
	if(DEBUG)cout<<"sumA="<<sumA<<" sumB="<<sumB<<endl;
	if(sumB > sumA)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 384
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

input = sys.stdin.readline

# input = sys.stdin.readline
sys.setrecursionlimit(2147483647)


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


def main():
    X = int(input())

    if X == 7 or X == 5 or X == 3:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
import java.util.*;

class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int e = sc.nextInt();
    if (a != 0) {
      if (b != 0) {
        if (c != 0) {
          if (d != 0) {
            if (e == 0) {
              System.out.println(5);
            }
          } else {
            System.out.println(4);
          }
        } else {
          System.out.println(3);
        }
      } else {
        System.out.println(2);
      }
    } else {
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 35712
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, ll> P;

const ll MOD = ll(1e9 + 7);
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e3) + 5;
const double EPS = 1e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    int n, cnt=0;
    cin >> n;
    REP(i,n){
        int a;
        cin >> a;
        while(a%2==0){
            a/=2;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: u64,
        m: u64,
        abs: [(u64, u64); n],
    }
    let mut absm = abs.clone();
    absm.sort();

    let mut sum_num: u64 = 0;
    let mut all_cost: u64 = 0;
    for ab in absm {
        if sum_num < m {
            if sum_num + ab.1 < m {
                sum_num += ab.1;
                all_cost += ab.0 * ab.1;
            } else {
                println!("{}", ab.0 * (m - sum_num) + all_cost);
                return;
            }
        } else {
            println!("{}", all_cost);
            return;
        }
    }
}

Measured memory_bytes: 10492
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    ll N, M, K;
    ll a, b;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    REP(i, N){
        cin >> a;
        A[i] = i == 0 ? a: min(1e9 + 100, A[i-1] + a);
    }
    REP(i, M){
        cin >> a;
        B[i] = i == 0 ? a: min(1e9 + 1000, B[i-1] + a);
    }
    ll ans = 0;
    REP(i, N + 1){
        ll tmp = i == 0 ? K: K - A[i-1];
        if (tmp < 0) continue;
        auto iter = upper_bound(B.begin(), B.end(), tmp);
        ans = max(ans, i + iter - B.begin());

    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5948
#include <bits/stdc++.h>
using namespace std;
long long cal(long long n)
{
	if (n==1) return 1;
	else return cal(n/2)*2+1;
}
int main()
{
	long long N=0;
	cin>>N;
	cout<<cal(N)<<endl;
	return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    N = parseInt(readline())
    s = readline()
    s = s[1:length(s)-1]
    r = 0
    for i in 1:N
        if s[i]=='R'
            r+=1
        end
    end
    if r>N-r
        println("Yes")
    else
        println("No")
    end
end

main()


Measured memory_bytes: 108156
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

vector<int> dp(2000);
int main(){
    ll n;cin >> n;
    map<ll,ll> m;
    ll mx = 0;
    rep(i,n){
        ll x;cin >> x;
        if(!i and x){
            cout << 0 << endl;
            return 0;
        }
        m[x]++;
        maxs(mx, x);
    }
    if(m[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    ll mod = 998244353;
    for(int i = 1;i <= mx;i++){
        ans *= qp(m[i-1],m[i],mod);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int dp[42][42][42][42];
// x1, x2, y1, y2

int psums[41][41];

int q(LL a1, LL a2, LL b1, LL b2){
    return psums[a2][b2] - psums[a1][b2] - psums[a2][b1] + psums[a1][b1];
}
int main(){
    int h, w;
    cin >> h >> w;
    string g[h];
    for(int i = 0; i < h; i++){
        cin >> g[i];
    }
    int px, py;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(g[i][j] == 'P'){
                g[i][j] = '+';
                px = i;
                py = j;
            }
        }
    }
    for(int i = 0; i <= h; i++){
        for(int j = 0; j <= w; j++){
            psums[i][j] = 0;
            if(i == 0 || j == 0) continue;
            psums[i][j] = psums[i][j-1] + psums[i-1][j] - psums[i-1][j-1];
            if(g[i-1][j-1] == '#') psums[i][j]++;
        }
    }

    for(int a1 = h; a1 >= 0; a1--){
        for(int a2 = a1; a2 <= h; a2++){
            for(int b1 = w; b1 >= 0; b1--){
                for(int b2 = b1; b2 <= w; b2++){
                    dp[a1][a2][b1][b2] = 1000000;
                    int k = 1000000;
                    for(int am = a1; am <= a2; am++){
                        for(int bm = b1; bm <= b2; bm++){
                            int al = a1;
                            int ar = a2;
                            int bl = b1;
                            int br = b2;
                            if(px >= am) al = am;
                            if(px < am) ar = am;
                            if(py >= bm) bl = bm;
                            if(py < bm) br = bm;
                            k = min(k, q(al, ar, bl, br));
                            int ans2 = dp[al][ar][bl][br];
                            ans2 += q(al,ar,b1+bm-bl,bm+b2-br);
                            ans2 += q(a1+am-al,am+a2-ar,bl,br);
                            k = min(k, ans2);
                        }
                    }
                    dp[a1][a2][b1][b2] = min(dp[a1][a2][b1][b2], k);
                }
            }
        }
    }
    cout << dp[0][h][0][w] << endl;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	
  	int2(a, b); int2(c, d);
  	cout << max(a * b, c * d) << endl;
  
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int id[200009][26],n,dp[200009],idx;
string s,ans;

void build_table(){
  int cnt[26];
  r(i,26)cnt[i]=n+1;
  for(int i=n-1;i>=0;i--){
    r(j,26)id[i][j]=cnt[j];
    cnt[s[i]-'a']=i;
  }
}

void solve(){
  for(int i=n-1;i>=0;i--){
    int p=0;
    r(j,26)p=max(p,id[i][j]);
    dp[i]=dp[p]+1;
  }
  while(idx<n){
    r(i,26){
      if(dp[id[idx][i]]+1==dp[idx]){
        idx=id[idx][i];
        ans+=('a'+i);
        break;
      }
    }
  }
  cout<<ans<<endl;
}

signed main(){
  cin>>s;
  s='@'+s;
  n=s.size();
  build_table();
  solve();
}

Measured memory_bytes: 21696
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]

x = 0
y = 0
for i in range(n):
    t = l[i][0]
    x = l[i][1]
    y = l[i][2]
    d = x + y
    if d <= t and (d - t) % 2 == 0:
        continue
    else:
        print('No')
        quit()
print('Yes')

Measured memory_bytes: 27300
#include<iostream>
using namespace std;
int gcd(int x, int y){
    int r;
    if (x < y){
        swap(x, y);
    }
    while (y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
int main() {
    int x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
    return 0;
}


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

int f(long h[2], const int a[2], const int b[2]){
	if(a[0]*b[1]>a[1]*b[0]){
		long r = (h[1]+a[1]-1)/a[1];
		h[0] = r*a[0];
		h[1] = r*a[1];
	}else{
		long r = (h[0]+a[0]-1)/a[0];
		h[0] = r*a[0];
		h[1] = r*a[1];
	}
}

int main(void){
	int n, i;
	long h[2]={1,1};
	int a[2], b[2]={1,1};
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d%d", a, a+1);
		f(h, a, b);
		b[0]=a[0], b[1]=a[1];
	}
	printf("%ld\n", h[0]+h[1]);
}


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

#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b)  for(int i=(a);i<(b);++i)
#define rep(i,n)    FOR(i,0,n)
#define rrep(i,n)   for(int i=n-1;i<=0;--i)
#define loop        while(true)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const ll MAX = 10000000;
const ll MIN = 0;
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; }
using pint = pair<int, int>;
using pstring = pair<int, string>;

int main() {
    ll N;
    string stone;
    cin >> N >> stone;
    ll red = 0;
    for(ll i = 0; i < N; i++) {
        if(stone.at(i)=='R') red++;
    }
    ll ans = 0;
    for(ll i = 0; i < red; i++) {
        if(stone.at(i) == 'W') ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

 class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            var data = line.Split(new char[] {' ' });
            var num = new int[data.Length];
            for (int i = 0; i < data.Length; i++)
            {
                num[i] = Convert.ToInt32(data[i]);
            }
            var start = new DateTime(2000,12,20,num[0],num[1],0);
            var end = new DateTime(2000, 12, 20, num[2], num[3], 0);
            var span = end - start;
            var ans = span - new TimeSpan(0, num[4],0);
            Console.WriteLine(ans.TotalMinutes);
        }
  }

Measured memory_bytes: 27644
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        
        int[] v = new int[N];
        for (int i=0; i<N; i++) {
            v[i] = sc.nextInt();
        }

        int[] c = new int[N];
        for (int i=0; i<N; i++) {
            c[i] = sc.nextInt();
        }

        int[] sa = new int[N];
        for (int i=0; i<N; i++) {
            sa[i] = v[i] - c[i];
        }

        int total = 0;
        for (int i=0; i<N; i++) {
            if (sa[i] >= 0) {
                total += sa[i];
            }
        }

        System.out.println(total);
    }
}

Measured memory_bytes: 22100
N = int(input())
A = list(map(int, input().split()))
A_max = max(A)

is_start_increase = [0]*N
is_end_increase = [0]*N
is_increasing = [0]*N

# for i in range(1, N):
#     if A[i-1] <= A[i]:
#         is_increasing[i] = 1
# next_is_end = 0
# is_total_start = 0
# for i in range(0, N-1):
#     if next_is_end:
#         if is_increasing[i] == 1 and is_increasing[i+1] == 0:
#             is_end_increase[i] = 1
#             next_is_end = 0

#     if not is_total_start:
#         if is_increasing[i+1] == 1:
#             is_start_increase[i] = 1
#             is_total_start = 1
#             next_is_end = 1
#     # if i == 0 and is_increasing[i+1] == 1:
#     #     is_start_increase[i] = 1
#     #     continue
#     # if i == 1 and is_start_increase[i-1]==1:
#     #     continue
#     elif next_is_end == 0:
#         if is_increasing[i] == 1 and is_increasing[i-1] == 0:
#             is_start_increase[i] = 1
#             next_is_end = 1

for i in range(N-1):
    if A[i] <= A[i+1]:
        is_increasing[i] = 1
if is_increasing[0] == 1:
    is_start_increase[0] = 1
for i in range(1, N):
    if is_increasing[i] == 1 and is_increasing[i-1] == 0:
        is_start_increase[i] = 1
    if is_increasing[i] == 0 and is_increasing[i-1] == 1:
        is_end_increase[i] = 1

money = 1000
stock = 0
stocks = []
for i in range(N):
    if i==N-1:
        # print("last", i)
        money += stock * A[i]
        break
    if is_start_increase[i]:
        # print("start", i)
        stock += money // A[i]
        money -= A[i] * stock
    if is_end_increase[i]:
        # print("end", i)
        money += stock * A[i]
        stock = 0
    stocks.append(stock)

print(money)

Measured memory_bytes: 62056