akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

const ll mod = 1000000007;

ll mod_pow(ll x, ll n, ll mod){
	ll res = 1;
	while(n > 0){
		if(n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

long long f[100005], fi[100005];
long long MOD = 1e9+7;

void init(int n){
	f[0] = 1;
	for(int i = 1; i <= n; i++){
		f[i] = f[i-1] * i % MOD;
	}
	fi[n] = mod_pow(f[n], MOD-2, MOD);
	for(int i = n; i > 0; i--){
		fi[i-1] = fi[i] * i % MOD;
	}
}

long long comb(int r, int c){
	if(r < c) return 0;
	return f[r] * fi[c] % MOD * fi[r-c] % MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    init(n+1);
    ll ans = 0;
    rep(i,n){
        if(i < k-1) continue;
        ans = (ans + (a[i] * comb(i, k-1)) % mod) % mod;
    }
    rep(i,n){
        if(n-i-1 < k-1) continue;
        ll sub = (a[i] * comb(n-i-1, k-1)) % mod;
        if(ans <= sub) ans += mod;
        ans = (ans - sub) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int n;
    string s, t;
    cin >> n;
    cin >> s >> t;

    string merge = "";

    REP(i,n){
        merge = merge +  s[i] + t[i];
    }

    cout << merge << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll a,b,q;
  cin >> a >> b >> q;
  vector<ll> s,t;
  REP(i,a){
    ll si; cin >> si;
    s.push_back(si);
  }
  REP(i,b){
    ll ti; cin >> ti;
    t.push_back(ti);
  }
  REP(i,q){
    ll x; cin >> x;
    ll ans = INF;
    //神社→寺
    auto itr1 = lower_bound(s.begin(),s.end(),x); //x以上の神社
    if(itr1!=s.begin()){
      auto itr2 = lower_bound(t.begin(),t.end(),*(itr1-1));
      if(itr2!=t.begin())
      ans = min(ans,abs(*(itr2-1)-*(itr1-1))+abs(*(itr1-1)-x));
      ans = min(ans,abs(*itr2-*(itr1-1))+abs(*(itr1-1)-x));
    }
    auto itr2 = lower_bound(t.begin(),t.end(),*itr1);
    if(itr2!=t.begin())
    ans = min(ans,abs(*(itr2-1)-*itr1)+abs(*itr1-x));
    ans = min(ans,abs(*itr2-*itr1)+abs(*itr1-x));

    //寺→神社
    auto itr3 = lower_bound(t.begin(),t.end(),x);
    if(itr3!=t.begin()){
      auto itr4 = lower_bound(s.begin(),s.end(),*(itr3-1));
      if(itr4!=s.begin())
      ans = min(ans,abs(*(itr4-1)-*(itr3-1))+abs(*(itr3-1)-x));
      ans = min(ans,abs(*itr4-*(itr3-1))+abs(*(itr3-1)-x));
    }
    auto itr4 = lower_bound(s.begin(),s.end(),*itr3);
    if(itr4!=s.begin())
    ans = min(ans,abs(*(itr4-1)-*itr3)+abs(*itr3-x));
    ans = min(ans,abs(*itr4-*itr3)+abs(*itr3-x));

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


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] Key = new int[M];
		for(int i=0;i<M;i++){
			for(int j=0;j<B[i];j++){
				Key[i] |= (1 << C[i][j]);
			}
		}
		
		long Inf = (long) 1e18;
		long[] dp = new long[1 << N];
		for(int i=0;i<(1<<N);i++) dp[i] = Inf;
		dp[0] = 0;
		
		bool[] used = new bool[1<<N];
		for(int i=0;i<(1<<N);i++){
			int idx = -1;
			long min = Inf;
			for(int j=0;j<(1<<N);j++){
				if(used[j]) continue;
				if(min > dp[j]){
					min = dp[j];
					idx = j;
				}
			}
			if(idx == -1) break;
			if(min == Inf) break;
			for(int j=0;j<M;j++){
				int ns = idx | Key[j];
				dp[ns] = Math.Min(dp[ns], dp[idx] + A[j]);
			}
			used[idx] = true;
		}
		
		
		Console.WriteLine(dp[(1<<N) - 1] == Inf ? -1 : dp[(1<<N) - 1]);
	}
	int N, M;
	int[] A,B;
	int[][] C;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = new int[M];
		B = new int[M];
		C = new int[M][];
		for(int i=0;i<M;i++){
			d = ria();
			A[i] = d[0]; B[i] = d[1];
			C[i] = ria();
			for(int j=0;j<B[i];j++) C[i][j]--;
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13248
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

double K, R, L;
double P, E, T;
double upper, lower;

double dfs(int num, double pro, double r, double l) {
    double h = (r + l) / 2;
    if (num == K + 1) {
        if (lower - eps <= h && h <= upper + eps) {
            return pro;
        } else {
            return 0;
        }
    }
    double pror, prol;
    if (h >= T) {
        pror = pro * (1 - P);
        prol = pro * P;
    } else {
        pror = pro * P;
        prol = pro * (1 - P);
    }
    double ans = 0;
    if (h + eps < lower) {
        ans = dfs(num + 1, prol, h, l);
    } else if (h > upper + eps) {
        ans = dfs(num + 1, pror, r, h);
    } else {
        if (lower + eps < r) {
            ans += pror;
        } else {
            ans += dfs(num + 1, pror, r, h);
        }
        if (l + eps < upper) {
            ans += prol;
        } else {
            ans += dfs(num + 1, prol, h, l);
        }
    }
    return ans;
}

int main() {
    cout << fixed << setprecision(9);
    cin >> K >> R >> L;
    cin >> P >> E >> T;
    upper = T + E;
    lower = T - E;
    double ans = dfs(1, 1, R, L);
    cout << ans << endl;
}



Measured memory_bytes: 3268
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

struct TRUMP
{
    int number, order;
    char mark;
};

int partition(vector<TRUMP> &A, int p, int r)
{
    int x = A.at(r).number;
    int i = p - 1;
    repi(j, r, p)
    {
        if (A.at(j).number <= x)
        {
            i++;
            swap(A.at(i), A.at(j));
        }
    }
    swap(A.at(i + 1), A.at(r));

    return i + 1;
}

void quicksort(vector<TRUMP> &A, int p, int r)
{
    if (p < r)
    {
        int q = partition(A, p, r);
        quicksort(A, p, q - 1);
        quicksort(A, q + 1, r);
    }
}

int main()
{
    int n;
    cin >> n;
    vector<TRUMP> A;
    repi(i, n, 0)
    {
        TRUMP tmp;
        cin >> tmp.mark >> tmp.number;
        tmp.order = i;
        A.push_back(tmp);
    }
    quicksort(A, 0, n - 1);
    bool isStable = true;
    int j = 0;

    repi(i, n, 1)
    {
        if (A.at(i).order < A.at(i - 1).order && A.at(i).number == A.at(i - 1).number)
        {
            isStable = false;
        }
    }
    isStable ? puts("Stable") : puts("Not stable");
    repi(i, n, 0)
    {
        cout << A.at(i).mark << " " << A.at(i).number << endl;
    }
    return 0;
}


Measured memory_bytes: 4520
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i];
	int ret=n, cur=1;
	for (int i=0; i<n; i++)
		if(a[i]==cur) cur++, ret--;
	cout<<(ret==n?-1:ret)<<"\n";
	return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


struct Hoge {
  LL zero;
  LL one;
  int num;
};

bool cmp(const Hoge &a, const Hoge &b) {
  return a.one > b.one;
}

int main(){
  int n;
  cin >> n;
  LL k;
  cin >> k;

  int bt[63] = {0};

  LL x;
  REP(i, n) {
    cin >> x;
    bitset<63> bs(x);
    REP (j, 63) {
      if (bs[j]) {
        bt[j]++;
      }
    }
  }

  LL now = 0;
  LL ans = 0;
  vector<Hoge> v;
  RREP (i, 63) {
    v.push_back({(LL)(pow(2, i) * bt[i]), (LL)(pow(2, i) * (n - bt[i])), i});
  }

  sort(v.begin(), v.end(), cmp);

  REP (i, 63) {
    if (v[i].one > v[i].zero && now + pow(2, v[i].num) <= k) {
      ans += v[i].one;
      now += pow(2, v[i].num);
    } else {
      ans += v[i].zero;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const objvs =(a)=>{const b=[];for(const v in a){b.push(a[v])}return b};
const main=()=>{
  let n=tn(),c=0
  let o={P:false,W:false,G:false,Y:false}
  for(let i=0;i<n;i++){
    o[ts()]=true;
  }
  if(o['P'])c++
  if(o['W'])c++
  if(o['G'])c++
  if(o['Y'])c++
  to(c==3?'Three':'Four')
}
main()


Measured memory_bytes: 7372
import scala.io.StdIn

import scala.annotation.tailrec

object Main extends App {
  val n = StdIn.readInt

  @tailrec
  def gdc(x:Long, y:Long):Long = {
    if(y == 0) x
    else gdc(y, x % y)
  }

  def lcm(x:Long, y:Long):Long = {
    if(x >= y) (x / gdc(x, y)) * y
    else (y / gdc(y, x)) * x
  }

  val ans = Iterator.continually(StdIn.readLine.toLong)
    .take(n)
    .reduce(lcm(_,_))

  println(ans)
}

Measured memory_bytes: 27156
// ALDS1_10_C.cpp
// Dynamic Programming - Longest Common Subsequence

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int LCS(string s, string t)
{
    int res = 0;
    if (s.empty() || t.empty())
        return res;
    int s_len = s.size();
    int t_len = t.size();
    int len = min(s_len, t_len);
//    int lcs[s_len][t_len];
    vector<vector<int>> lcs(s_len, vector<int>(t_len));
    bool found = false;
    for (int i = 0; i < s_len; i++) {
        if (s[i] == t[0] || found) {
            lcs[i][0] = 1;
            found = true;
        }
    }
    found = false;
    for (int j = 0; j < t_len; j++) {
        if (s[0] == t[j] || found) {
            lcs[0][j] = 1;
            found = true;
        }
    }
    for (int i = 1; i < s_len; i++) {
        for (int j = 1; j < t_len; j++) {
            if (s[i] == t[j]) {
                lcs[i][j] = 1 + lcs[i-1][j-1];
            }
            else {
                lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
            }
        }
    }
    return lcs[s_len - 1][t_len - 1];
}

int main()
{
    int n;
    cin >> n;
    string s, t;
    while (n--) {
        cin >> s >> t;
        int res = LCS(s, t);
        cout << res << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> a;
    for (int i = 0; i < n; ++i) {
        int x, l;
        cin >> x >> l;
        a.push_back(make_pair(x - l, x + l - 1));
    }
    sort(a.begin(), a.end());
    int ans = n;
    int r = a[0].second;
    for (int i = 1; i < n; ++i) {
        if (a[i].first <= r) {
            --ans;
            r = min(r, a[i].second);
        } else {
            r = a[i].second;
        }
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

struct Patient{
  int id;
  int walked;
  bool operator<(const Patient &t)const{
    return walked < t.walked;
  }
};

int main()
{
  while(true){
    int n;
    vector<Patient> v;
    cin >> n;
    if( n == 0 ) break;
    for(int i = 0; i < n; ++i){
      Patient tmp;
      int p, d1, d2;
      cin >> p >> d1 >> d2;
      tmp.id = p;
      tmp.walked = d1 + d2;
      v.push_back( tmp );
    }
    sort( v.begin(), v.end() );
    reverse( v.begin(), v.end() );
    cout << v[0].id << ' ' << v[0].walked << endl;
  }
  return 0;
}

Measured memory_bytes: 1112
h,w=map(int,input().split())
data=[]
data.append(list("#"*(w+2)))
for i in range(h):
    s=input()
    s="#"+s+"#"
    lists=list(s)
    data.append(lists)
data.append("#"*(w+2))
s=0
uselist=[]
graph={i:[] for i in range(1,h*w+1)}
for i in range(1,h+1):
    for j in range(1,w+1):
        if data[i][j]==".":
            a=w*(i-1)+j
            uselist.append(a)
            if data[i+1][j]==".":
                b=w*(i)+j
                graph[b].append(a)
                graph[a].append(b)

            if data[i][j+1]==".":
                b=w*(i-1)+j+1
                graph[b].append(a)
                graph[a].append(b)

from collections import deque

def how_far_from(s,n):
    d=deque()
#頂点sからどのくらいの距離にあるのかを返す関数
    parent=[0 for i in range(n+1)]
    visited=[False for i in range(n+1)]
    visited[s]=True
    d.append((s,0))

    how_far={i:[] for i in range(n+1)}
    while d:
        node=d.popleft()
        for point in graph[node[0]]:
            if visited[point]==False:
      
                visited[point]=True

                d.append((point,node[1]+1))
                how_far[node[1]+1].append(point)

    return how_far
maxi=0
for s in uselist:
    Q=how_far_from(s,h*w)

    for i in range(h*w,-1,-1):
        if Q[i]:
            maxi=max(maxi,i)
            break
print(maxi)   

Measured memory_bytes: 3572
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] n = sc.next().split("");
        
        for (int i=0; i<n.length; i++) {
            if (n[i].equals("1")) {
                n[i] = "9";
            } else if (n[i].equals("9")) {
                n[i] = "1";
            }
        }
        
        String result = "";
        for (String s : n) {
            result += s;
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 39492
def f(n,x):
    if n == 0:
        return 0 if x<=0 else 1

    elif x<=1 + a[n-1]:
        return f(n-1,x-1)

    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])


n ,x = map(int,input().split())
a, p = [1],[1]
for i in range(n):
    a.append(a[i]*2 + 3)
    p.append(p[i]*2 + 1)

print(f(n, x))

Measured memory_bytes: 3064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int n, m, a;
    ll sum = 0;
    cin >> n >> m;
    priority_queue<double> q;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        q.push(a);
    }
    while (m--) {
        double t = q.top();
        q.pop();
        q.push(t / 2);
    }
    for (int i = 0; i < n; ++i) {
        sum += (int)q.top();
        q.pop();
    }
    cout << sum << endl;

    return 0;
}

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

int main(void)
{


	int m1, m2, d1, d2;

	cin >> m1>>d1>>m2>>d2;

	
	if (m1 == m2) cout << 0 << endl;

	else cout << 1 << endl;



}



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

int main(){
  int n,nu=0;
  cin>>n;
  vector<int>d(n);
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  for(int i=0;i<n;i++){
    if(d[i]!=i+1){
      nu++;
    }
  }
  if(nu>2){
    cout<<"NO"<<endl;
  }
  else{
    cout<<"YES"<<endl;
  }
}
  

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

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

int main() {
	int N, K;
	cin >> K >>  N ;
	int i;
	for (i = ((N - K + 1) < (-1000000) ? (-1000000) : N - K + 1); i < N + K && i <= 1000000; i++) {
		cout << i << " ";
	}
	return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
lst = [tuple(map(int, input().split())) for _ in range(M)]
lst.sort(key=lambda x: x[1])
bridge = []
for war in lst:
    if bridge and war[0] <= bridge[-1]:
        continue
    bridge.append(war[1] - 1)
print(len(bridge))

Measured memory_bytes: 18248
#include <bits/stdc++.h>                                                        
using namespace std;
int main(){
  int n;
  int i;
  int card[4][13]={{}};
  cin >> n;
  char a;
  int b;
  for(i=0;i<n;i++) {
    cin >> a >> b;
    switch(a){
    case 'S':
      card[0][b-1]=1;
      break;
    case 'H':
      card[1][b-1]=1;
      break;
    case 'C':
      card[2][b-1]=1;
      break;
    case 'D':
      card[3][b-1]=1;
      break;
    }
  }
  for(i=0;i<52;i++) {
    switch(i/13){
    case 0:
      if(card[0][i%13]==0) cout << "S " << i+1 << endl;
      break;
    case 1:
      if(card[1][i%13]==0) cout << "H " << i%13+1 << endl;
      break;
    case 2:
      if(card[2][i%13]==0) cout << "C " << i%13+1 << endl;
      break;
    case 3:
      if(card[3][i%13]==0) cout << "D " << i%13+1 << endl;
      break;
    }
  }
  
  return 0;
}



Measured memory_bytes: 3108
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

#define N 1010
ll n;
ll a[N];

int main(){
	cin>>n;
	rep(i, n) cin>>a[i];
	ll o = 0, e = 0, mxp = 0;
	rep(i, n){
		if(a[mxp]<a[i]) mxp = i;
		if(a[i]<0) continue;
		if(i%2) e += a[i];
		else o += a[i];
	}
	if(a[mxp]<=0){
		cout<<a[mxp]<<endl;
		cout<<n-1<<endl;
		for(int i = n-1; i > mxp; i--) cout<<i+1<<endl;
		for(int i = 0; i < mxp; i++) cout<<1<<endl;
		return 0;
	}
	ll res = max(o, e);
	cout<<res<<endl;
	vector<ll> x;
	if((o<e && n%2==1)||(o>=e && n%2==0)){
		x.pb(n-1); n--;
	}
	while(a[n-1]<=0){
		x.pb(n-1);
		x.pb(n-2);
		n -= 2;
	}
	for(ll i = n-3; i >= 0; i-=2){
		if(a[i]>0){
			x.pb(i+1);
		} else {
			x.pb(i);
			if(i==0) x.pb(0);
		}
	}
	if(o<e) x.pb(0);
	cout<<x.size()<<endl;
	rep(i, x.size()) cout<<x[i]+1<<endl;
	return 0;
}


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

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

	ll z = 2;
	map<ll, ll> m;
	while (z * z <= n) {
		if (n % z == 0) {
			m[z]++;
			n /= z;
		} else
			z++;
	}
	if (n != 1)
		m[n]++;

	ll count = 0;
	for (auto p : m) {
		for (ll i = 1; i <= p.second; i++) {
			count++;
			p.second -= i;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "Yes";
        
        for(int i=0; i<s.length(); i++){
            if(i%2==0 && s.charAt(i)=='L'){
                ans = "No";
                break;
            }
            else if(i%2==1 && s.charAt(i)=='R'){
                ans = "No";
                break;
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#if     DEBUG
#define trace(var)  {cerr << "Line " << __LINE__ << ": " << #var << "=" << var << nl;}
#else
#define trace(var)	{}
#endif
#define fori(n)			for(int i = 0; i < n; ++i) 
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)

typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;typedef vector<vector<int>> vvi;

const ll N = 1001;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

int h, w;
char grid[N][N];
int mem[N][N];


int solve(int i, int j) {
	if (i == h-1 && j == w-1) return 1;
	if (mem[i][j] != -1) return mem[i][j];
	ll res = 0;
	if (i < h-1 && grid[i+1][j] != '#') {
		res += solve(i+1, j);
		res %= MOD;
	} 
	if (j < w-1 && grid[i][j+1] != '#') {
		res += solve(i, j+1);
		res %= MOD;
	}
	return mem[i][j] = (int) res;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin  >> h >> w;
	fori(h) 
		forj(w) { 
			cin >> grid[i][j];
			mem[i][j] = -1;
		}
	
	cout << solve(0,0) << nl;
	
	#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


Measured memory_bytes: 5248
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def solve(N: int, a: "List[int]"):
    total_xor = 0
    for v in a:
        total_xor = total_xor ^ v

    # for v in a:
    #     print(total_xor ^ v)
    print(" ".join((str(total_xor^v) for v in a)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 107464
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int h = Integer.parseInt(str[0]);
    int w = Integer.parseInt(str[1]);
    str = in.readLine().split(" ");
    int h_sm = Integer.parseInt(str[0]);
    int w_sm = Integer.parseInt(str[1]);
    System.out.println((h-h_sm)*(w-w_sm));
  }
}

Measured memory_bytes: 20948
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
import sys

sys.setrecursionlimit(500000)

visited = set()

n,q = nm()

tval = [0]*n
t = [[] for _ in range(n)]

for i in range(n-1):
    a,b = nm()
    t[a-1].append(b-1)
    t[b-1].append(a-1)

for i in range(q):
    p,x = nm()
    tval[p-1] += x

ans = [0]*n
def dfs(num,val):
    visited.add(num)
    now = val+tval[num]
    ans[num] = now
    for nn in t[num]:
        if nn not in visited:
            dfs(nn,now)

dfs(0,0)

for i in ans:
    print(i)


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

int kobaisu(int x, int y, int z)
{
    int p = max(x, y);
    int q = min(x, y);
    int n, m;
    while (p % q != 0)
    {
        n = q;
        q = p % q;
        p = n;
    }
    int r = max(q, z);
    int s = min(q, z);
    while (r % s != 0)
    {
        m = s;
        s = r % s;
        r = m;
    }
    return s;
}

int main()
{
    int K;
    cin >> K;
    int64_t count = 0;

    for (int i = 2; i <= K; i++)
    {
        for (int j = 2; j <= K; j++)
        {
            for (int k = 2; k <= K; k++)
            {
                count += kobaisu(i, j, k);
            }
       }
    }

    count += (3 * K * K - 3 * K + 1);
    cout << count;
}

Measured memory_bytes: 3624
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")


n=int(input())
l=list(input())

p(n,l)

r=l.count('R')
b=l.count('B')

ans="No"
if r>b: ans="Yes"

print(ans)


Measured memory_bytes: 3060
mil = [1000,1,1]

y2d :: Int -> Int
y2d y =
  let y3 = y `div` 3
      y12= y - y3
  in
    y3 * 10 * 20 + y12 * (5 * 19 + 5 * 20)

m2d :: Int -> Int -> Int
m2d y m =
  if (y`mod`3) == 0
  then m * 20
  else (m`div`2) * 39 + (m`mod`2) * 20

days :: [Int] -> Int
days [y,m,d] =
  let yd = y2d (y - 1)
      md = m2d y (m - 1)
      dd = d - 1
  in
    yd+md+dd
  

ans x@[y,m,d] =
  let i = days x
      j = days mil
  in
    j - i

main = do
  _ <- getLine
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = map ans i
  mapM_ print o



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll P,Q; cin >> N >> P >> Q;
    vector<ll> C(N);
    for (int i=0;i<N;++i) cin >> C[i];
    ll ans=0;
    for (int i=0;i<N;++i){
        ans+=P*(Q+i);
        C[i]-=P*(Q+2*N-2-i);
    }
    sort(C.begin(),C.end(),[](ll a,ll b){return a>b;});
    ll Max=0,sum=0,cnt=0;
    for (int i=0;i<N;++i){
        sum+=C[i]; cnt+=i;
        Max=max(Max,sum+2*P*cnt);
    }
    cout << ans+Max << '\n';
}


Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define int long long
using namespace std;

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int N=1e5+5;

int n,m,fa[N],val[N],al[N],hh[N],ans,tot,gs;
vector<int> g[N];

inline int find(int x)
{
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}

signed main()
{
	n=read();
	m=read();
	for ( int i=1;i<=n;i++ ) 
	{
		val[i]=read();
		fa[i]=i;
	}
	for ( int i=1;i<=m;i++ )
	{
		int x,y;
		x=read()+1,y=read()+1;
		x=find(x),y=find(y);
		if(x==y) continue;
		fa[x]=y;
	}
	for ( int i=1;i<=n;i++ ) 
	{
		int x=find(i);
		if(!al[x]) al[x]=++tot;
		g[al[x]].push_back(val[i]);
	}	
	if(tot==1) 
		return printf("0\n"),0;
	for ( int i=1;i<=tot;i++ ) sort(g[i].begin(),g[i].end());
	for ( int i=1;i<=tot;i++ ) ans+=g[i][0];
	for ( int i=1;i<=tot;i++ )
		for ( int j=1;j<g[i].size();j++ ) hh[++gs]=g[i][j];
	if(gs<tot-2) return printf("Impossible\n"),0; 
	sort(hh+1,hh+gs+1);
	for ( int i=1;i<=tot-2;i++ ) ans+=hh[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8832
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
const int maxn = 2e3 + 2;
vi v[maxn];
bool vis[maxn];
int d[maxn];
int ans[maxn];
void bfs(int u){
	vis[u] = true;
	queue<int> q;
	q.push(u);
	while(!q.empty()){
		int z = q.front();
		q.pop();
		// cout<<z<<"\n";
		for(auto x:v[z]){
			if(!vis[x]){
				d[x] = d[z]+1;
				q.push(x);
				vis[x] = true;
			}
		}
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int x,y;
	cin>>x>>y;
	rep(i,n-1){
		v[i+1].pb(i+2);
		v[i+2].pb(i+1);
	}	
	v[x].pb(y);
	v[y].pb(x);
	repa(i,1,n+1){
		rep(j,n+1)vis[j] = false;
		d[i] = 0;
		bfs(i);
		repa(j,i+1,n+1){
			ans[d[j]]++;
		}
	}
	repa(i,1,n){
		cout<<ans[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define ll long long 
#define N 200005
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define piii pair<int, pii>
#define print(x) cout << #x << "=" << x << "\t";
#define endl "\n"
#define newline cout << endl;

int n;
int k;
int a[N];
ll dp[N];

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); 
    cin >> n >> k;
    for(int i=0;i<n;i++)
        cin >> a[i];
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for(int i = 1; i < n; i++)
        for(int j = 1; i - j >= 0 && j <= k; j++)
            dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define int long long

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

  multiset<int> st;
  for(int i=0;i<N;i++){
    auto itr=st.lower_bound(a[i]);
    if(itr==st.begin()){
      st.insert(a[i]);
    }else{
      st.erase(prev(itr));
      st.insert(a[i]);
    }
  }
  cout<<st.size()<<endl;

  return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int main() {
    string s;cin>>s;
    
    int l = 0;
    int r = s.size()-1;
    int cnt = 0;
    while(l<r){
        
        if(s[l]==s[r]){
            l++;
            r--;
        }else{
            
            if(s[l]=='x') {l++;cnt++;continue;}
            if(s[r]=='x') {r--;cnt++;continue;}
            cout<<-1<<endl;
            return 0;
            
            
            
        }
        
        
    }
    
    cout<<cnt<<endl;
    
    
    return 0;
}







Measured memory_bytes: 512
//Xを選ぶ→操作する, と読み替えて大丈夫。Xを決めるとX-1以上X+1以下の値の個数がスコアになる。事前に値をcountしておけばXを全探索できる。
#include <iostream>
#include <algorithm>
using namespace std;

int n;
int a[100000];
int cnt[100000];

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < n; i++) cnt[a[i]]++;
	
	int ans = 0;
	for (i = 1; i < 99999; i++) {
		int score = cnt[i - 1] + cnt[i] + cnt[i + 1];
		ans = max(ans, score);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	double a,b,c,d,e,f;
	double x,y;
	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
	
	y=(c*d-a*f)/(b*d-a*e);
	if(y==-0)y=0;
	x=(c-b*y)/a;
	if(x==-0)x=0;
	
	printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static  ll INF = 1e9;
using namespace std;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

int main(){
	int n;
	cin>>n;
	set<int> nums;
	bool flag=true;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(nums.count(a)){
			flag=false;
		}
		nums.insert(a);

	}
	cout<<(flag ? "YES" : "NO");
    return 0;
}

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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int temp1, temp2;
    int max, min;
    for (int i = 0; i < m; i++) {
        cin >> temp1 >> temp2;
        if (i == 0) {
            max = temp1;
            min = temp2;
        }
        if (temp1 > max) {
            max = temp1;
        }
        if (temp2 < min) {
            min = temp2;
        }
    }
    if (min - max + 1 > 0) {
        cout << min - max + 1;
    }
    else { cout << 0; }

    
    return 0;
}

Measured memory_bytes: 256
D,G = list(map(int,input().split()))
P = []
C = []

for i in range(D):
    p,c = list(map(int,input().split()))
    P.append(p)
    C.append(c)

ans = 10000

for c in range(2**D):
    score = 0
    solved = 0
    remain = []
    for i,b in enumerate(format(c,'b').zfill(D)):
        if b == '1':
            score += P[i]*100*(i+1) + C[i]
            solved += P[i]
        else:
            remain.append(i)
    if score < G:
        R = G - score
        j = remain[-1]
        if (P[j]-1)*(j+1)*100 < R:
            continue
        solved += -(-R//(100*(j+1)))
    ans = min(solved, ans)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int main(){
  const int MAX=51;
  int N,M;
  cin>>N>>M;
  int a[MAX]={},b[MAX]={};
  int c[MAX]={},d[MAX]={};
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<M;i++){
    cin>>c[i]>>d[i];
  }
  for(int i=0;i<N;i++){
      int mini=INF;
      int poi=0;
    for(int j=0;j<M;j++){
      if(mini>abs(a[i]-c[j])+abs(b[i]-d[j])){
        poi=j;
        mini=min(mini,abs(a[i]-c[j])+abs(b[i]-d[j]));
      }
    }
    cout<<poi+1<<endl;
  }

  return 0; 
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#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 in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    ll plus = 0LL, ans = 0LL;
    for (int i=N-1; i>=0; i--) {
        ll now = A[i] + plus;
        if (now % B[i] != 0) {
            ans += (B[i] - (now % B[i]));
            plus += (B[i] - (now % B[i]));
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        double sum = 0.0;
        for(int i=0; i<N; i++){
            int A = scanner.nextInt();
            sum += 1.0/A;
        }
        System.out.println(1.0/sum);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	ll l,r;
	cin>>l>>r;
	if(r-l>=2019){
		cout<<0<<endl;
		return 0;
	}

	ll ans=2019;
	REP(i,l,r+1)REP(j,l,i){
		ans=min(ans,(i*j)%2019);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    
    int N;
    cin >> N;
    
    long long A;
    map<long long,int> mp;
    set<long long> st;
    for(int i = 0; i < N;i++){
        cin >> A;
        mp[A]++;
        st.insert(A);
    }
    int sum = 0;
    for(auto itr = st.begin(); itr != st.end(); ++itr){
        if(mp[*itr]==0)continue;
        else if(mp[*itr]-*itr >= 0)sum += mp[*itr] - *itr;
        else sum +=mp[*itr];
    }
    cout << sum <<endl;
    
    
    
    
}


Measured memory_bytes: 10752
A, B, M  = map(int, input().split())
ta = input().split()
tb = input().split()
a = [int(s) for s in ta]
b = [int(s) for s in tb]
mp = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    w = a[x-1] + b[y-1] - c
    if mp > w:
        mp = w
print(mp)

Measured memory_bytes: 24872
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @s = gets.chomp
  end

  def solve
    return 3 if s == "RRR"
    return 2 if s == "RRS"
    return 2 if s == "SRR"
    return 1 if s == "RSR"
    return 1 if s == "SSR"
    return 1 if s == "SRS"
    return 1 if s == "RSS"
    0
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14312
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

int N;

int main() {
    cin >> N;
    bool flag = false;
    for (int i = 1; i < 10; i++) {
        if (N % i == 0 && N / i < 10) {
            flag = true;
            break;
        }
    }
    cout << (flag? "Yes" : "No") << endl;
}


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

using namespace std;

int main() {

	long n,k;
	cin >> n >> k;

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

	vector<long> dp(k + 2);

	for (long i = 1; i <= k+1; i++) {
		for (long j = 1; j <= n; j++) {
			if (i - a[j] >= 0 && dp[i - a[j]] == 0) {
				dp[i] = 1;
			}
		}
	}

	cout <<  (dp[k]%2==1? "First" : "Second") << endl;
}

Measured memory_bytes: 1024
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi=3.1415926535897932384626433832795028841971;
pair<int,int> a[200005];
int f[200005];
bool comp (pair<int,int> x,pair<int,int> y) {
	if (x.first<y.first) return true; else return false;
}
int main ( ) {
	int x1,x2,y1,y2,s=0,i;
	bool ff=false;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	if (x1>x2) swap(x1,x2),swap(y1,y2);
	if (y1>y2) swap(y1,y2),ff=true;
	int n;
	scanf("%d",&n);
	for (i=1;i<=n;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		if (x>=x1 && x<=x2 && y>=y1 && y<=y2) {
			s++,a[s].first=x;
			if (!ff) a[s].second=y; else a[s].second=(y2-y1)-(y-y1)+y1;
		}
	}
	sort(a+1,a+s+1,comp);
	int x=x2-x1+1,y=y2-y1+1;
	if (s==0) {
		printf("%d00.00000000000000\n",x+y-2);
		return 0;
	}
	f[1]=a[1].second;
    int len=1;
    for (int i=2;i<=s;i++)
    {
        if (a[i].second>=f[len]) f[++len]=a[i].second;
        else
        {
            int j=upper_bound(f+1,f+len+1,a[i].second)-f;
            f[j]=a[i].second;
        }
    }
    if (len!=x && len!=y) printf("%.14lf\n",(double)(x+y-2)*100.0-(double)len*20.0+(double)len*pi*5.0);
    else printf("%.14lf\n",(double)(x+y-2)*100.0-(double)len*20.0+(double)(len-1)*pi*5.0+(double)pi*10.0);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll H,W;
int main(void) {
    cin >> H >> W;
    // char grid[2000][2000]={};
    vector<vector<vector<int> > > dp(4, vector<vector<int>>(H, vector<int>(W,0)));
    rep(i,H)rep(j,W){
        char tmp;
        cin >> tmp;
        if(tmp=='#'){
            rep(k,4)dp[k][i][j]=-1;
        }
    }
    // DEBUG{printf("test\n");}
    rep(i,H)rep(j,W){
        if(j>0&&dp[0][i][j]!=-1){
            if(dp[0][i][j-1]==-1)dp[0][i][j]=0;
            else dp[0][i][j]=dp[0][i][j-1]+1;
        }
        if(i>0&&dp[0][i][j]!=-1){
            if(dp[3][i-1][j]==-1)dp[3][i][j]=0;
            else dp[3][i][j]=dp[3][i-1][j]+1;
        }
        // if(i<H-1&&dp[0][H-i][j]!=-1){
        //     if(dp[1][H-i][j]==-1)dp[1][H-i-1][j]=1;
        //     else dp[1][H-i-1][j]=dp[1][H-i][j]+1;
        // }
        // if(j<W-1&&dp[0][i][W-j]!=-1){
        //     if(dp[2][i][W-j]!=-1)dp[2][i][W-j-1]=dp[2][i][W-j]+1;
        // }
    }
    for(int i=H-1;i>=0;i--)rep(j,W){
        if(i<H-1&&dp[0][i][j]!=-1&&dp[1][i+1][j]!=-1)dp[1][i][j]=dp[1][i+1][j]+1;
    }
    rep(i,H)for(int j=W-1;j>=0;j--){
        if(j<W-1&&dp[0][i][j]!=-1&&dp[2][i][j+1]!=-1)dp[2][i][j]=dp[2][i][j+1]+1;
    }
    DEBUG{
        printf("%d %d %d %d\n",dp[0][1][1], dp[1][1][1], dp[2][1][1], dp[3][1][1]);
    }
    ll res=0;
    rep(i,H)rep(j,W){
        ll s=0;
        rep(k,4){
            s+=dp[k][i][j];
        }
        s++;
        if(s>res)res=s;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 78720
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma region header
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
#pragma endregion
#pragma endregion
lint gcd(lint a, lint b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}



int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	lint a, b, c, d; cin >> a >> b >> c >> d;
	cout << max({ a * c, a * d, b * c, b * d }) << endl;

	return 0;
}

Measured memory_bytes: 3648