akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

bool ok(ll x,int N,int K,vector<ll> &A) {
    ll cnt = 0;
    rep(i,N) {
        cnt += (A[i] + x - 1)/x - 1;
    }
    return cnt <= K;
}

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

    ll r = 10000000000;
    ll l = 0;
    while (r - l > 1) {
        ll m = (r + l)/2;
        if (ok(m,N,K,A)) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << '\n';
    return 0;
}

Measured memory_bytes: 4768
#include<bits/stdc++.h>
using namespace std;
#define lli long long int 
const int mod = 1e9  + 7;
const lli hehe = -1e18 - 10;

int main(){
	int n,m;
	cin>>n>>m;

	char arr[n][m];
	lli dp[n][m];

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

	dp[0][0] = 1;
	for(int i=1;i<m;i++){
		if(arr[0][i]=='#'){
			dp[0][i]=hehe;
		}else{
			dp[0][i]=dp[0][i-1];
		}
	}

	for(int i=1;i<n;i++){
		if(arr[i][0]=='#'){
			dp[i][0]=hehe;
		}else{
			dp[i][0]=dp[i-1][0];
		}
	}

	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(arr[i][j]=='#'){
				dp[i][j] = hehe;
				continue;
			}else{
				if(dp[i-1][j]<0 && dp[i][j-1]<0){
					dp[i][j] = hehe;
				}else{
					if(dp[i-1][j]<0){
						dp[i][j] = dp[i][j-1]%mod;
					}else if(dp[i][j-1]<0){
						dp[i][j] = dp[i-1][j]%mod;
					}else{
						dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod )%mod;
					}
				}
			}
		}
	}

	// for(int i=0;i<n;i++){
	// 	for(int j=0;j<m;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	if(dp[n-1][m-1]<0)
		cout<<0;
	else
		cout<<dp[n-1][m-1];
	return 0;
}

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

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

ll n,a,b;
cin>>n>>a>>b;
if(!((abs(a-b))%2))
cout<<(b-a)/2;
else
{
	ll x,y,aa,bb;
	aa=a;
	bb=b;
	x=(min(a,b)-1);

	x++;

	b-=a-1;

	b--;
	//	cout<<x<<" "<<b<<endl;
	if(b>1)
	x=x+(b-1)/2;
	y=n-bb;
//	cout<<aa<<" "<<bb<<endl;
	y++;
	aa+=n-bb;
	aa++;
//	cout<<aa<<" "<<y<<endl;
	if(aa<n)
	y=y+(n-aa)/2;
//	cout<<x<<" "<<y<<endl;
	cout<<min(x,y);
}



}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<set>
#include<complex>
#include<map>
using namespace std;
inline int ri()
{
	register int x=0;
	bool f=0;
	register char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')	f=1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	if(f)	return -x;
	else	return x;
}
void wi(int x)
{
	if(x<0)	putchar('-'),x=-x;
	if(x>9)	wi(x/10);
	putchar(x%10+'0');
}
const int N=2e5+7;
struct data
{
	int id,a;
	bool operator <(const data &t)const
	{
		return a<t.a;
	}
}q[N];
int ans[N];
int main()
{
	int n=ri(),i;
	for(i=1;i<=n;i++)	q[i].id=i,q[i].a=ri();
	sort(q+1,q+1+n);
	for(i=1;i<=n/2;i++)	ans[q[i].id]=q[n/2+1].a;
	for(i=n/2+1;i<=n;i++)	ans[q[i].id]=q[n/2].a;
	for(i=1;i<=n;i++)	wi(ans[i]),putchar('\n');
	return 0;
}
/*
4
2 4 4 3





*/

Measured memory_bytes: 4480
#define _GLIBCXX_DEBUG
#define MIN 1000000
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;

int main(void){
    int n;
    cin >> n;
    vi X(n);
    for(int &x : X) cin >> x;
    int min = MIN;
    for(int i=1; i<=100; i++){
        int hp = 0;
        for(int &x : X) hp += (x-i)*(x-i);
        if(hp < min) min = hp;
    }
    cout << min << '\n';
    return 0;
}

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

using namespace std;

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

    int ans = INT_MAX;
    for (int i=0; i+k-1<n; i++) {
        ans = min(ans, abs(a[i]) + abs(a[i+k-1] - a[i]));
        ans = min(ans, abs(a[i+k-1]) + abs(a[i] - a[i+k-1]));
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for i in range(N)]


def book_comb_test(book_comb):
    for skill_ind in range(M):
        skill_point = 0
        for book in book_comb:
            skill_point += book[skill_ind+1]
        if skill_point < X:
            return False
    return True


min_cost = float('inf')
bit_num = 2**N
for i in range(bit_num):
    book_comb = [books[j] for j in range(N) if (i >> j) & 1]
    if book_comb_test(book_comb):
        cost_sum = 0
        for k in book_comb:
            cost_sum += k[0]
        min_cost = min(min_cost, cost_sum)
print(min_cost if min_cost != float('inf') else -1)

Measured memory_bytes: 9224
#include<iostream>
#include<string>
using namespace std;
#define MAX 1100
#define INF ((int)1e9+9)

int main(){
	int A[MAX],temp[MAX], n, q, b, e, m;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>A[i];
	}
	
	cin>>q;
	
	for(int i = 0; i < q; i++){
		cin>>b>>m>>e;
		for(int j = b; j < e; j++){
			temp[j] = A[j];
		}
		for(int k = 0; k < e-b; k++){
			A[b+(k+(e-m))%(e-b)] = temp[b+k];
		}
	}

	for(int i = 0; i < n; i++){
		cout<<(i?" ":"")<<A[i];
	}
	cout<<endl;
	
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 9000000000000000000
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int calcarea(int x1, int x2, int y1, int y2, int N, vector<int> &x, vector<int> &y, int K){
    int xm = min(x1, x2);
    int xM = max(x1, x2);
    int ym = min(y1, y2);
    int yM = max(y1, y2);

    int num = 0;
    REP(i, N){
        if(xm <= x[i] && x[i] <= xM && ym <= y[i] && y[i] <= yM) num++;
    }
    if(num >= K) return (xM - xm) * (yM - ym);
    return -1;
}

signed main(){

    int N, K;
    cin >> N >> K;
    vector<int> x(N), y(N);
    REP(i, N) cin >> x[i] >> y[i];

    int ans = INF;

    REP(i1, N){
        REP(i2, N){
            REP(j1, N){
                REP(j2, N){
                    int tmp = calcarea(x[i1], x[i2], y[j1], y[j2], N, x, y, K);
                    if(tmp != -1) ans = min(ans, tmp); 
                }
            }
        }
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int main(){
    int n; ll k;
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    int start,loop;
    vector<int>x;
    set<int>se;
    int now=0;
    while(1){
        x.push_back(now);
        if(se.find(now)!=se.end())break;
        se.insert(now);
        now=a[now];
    }
    int m=x.size();
    rep(i,m-1){
        if(x[i]==x[m-1])start=i,loop=m-1-i;
    }
    if(k<start)cout<<x[k]+1<<endl;
    else cout<<x[start+(k-start)%loop]+1<<endl;
}

Measured memory_bytes: 13936
n, q = gets.chomp.split(' ').map(&:to_i)
ps = readlines.map(&:chomp).map{|l| a = l.split(' '); a[1] = a[1].to_i; a}

t = 0
while ps.length > 0
  p = ps.shift
  if p[1] <= q
    t += p[1]
    puts "#{p[0]} #{t}"
  else
    t += q
    p[1] -= q
    ps.push(p)
  end
end


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

class Main{
    public static void main(String args[]){
        try{
            BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
            String s=reader.readLine();
            StringTokenizer st=new StringTokenizer(s," ");
            
            String a=st.nextToken();
            String b=st.nextToken();
            
            int an=Integer.parseInt(a);
            int bn=Integer.parseInt(b);
            
            if(an<bn){
                System.out.println("a < b");
            }else if(an==bn){
                System.out.println("a == b");
            }else{
                System.out.println("a > b");
            }

        }catch(IOException e){
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24096
using System;
using System.Collections.Generic;

namespace kozaiyApp
{
    public class FactorsOfFactorial
    {
        static void Main()
        {
            long N = int.Parse(Console.ReadLine());
            Dictionary<long, long> count = new Dictionary<long, long>(); // 素数xが何個あるか
            long mod = 1000000007;

            for (long i = 2; i <= N; i++) // N!... 1*2*3*4*...N
            {
                List<long> factorList = PrimeFactor(i); // 素因数分解
                foreach (var f in factorList) // 素数をカウント
                {
                    // Dictionaryに記録
                    if (count.ContainsKey(f))
                    {
                        count[f] += 1;
                    }
                    else
                    {
                        count.Add(f, 1);
                    }
                }
            }

            long ans = 1;
            foreach (var c in count)
            {
                ans *= (c.Value + 1) % mod;
                ans %= mod;
            }

            Console.WriteLine(ans);
        }

        // 素因数分解
        static List<long> PrimeFactor(long n)
        {
            List<long> result = new List<long>();
            for (long i = 2; i * i <= n; i++)
            {
                while (n % i == 0)
                {
                    result.Add(i);
                    n /= i;
                }
            }
            if (n != 1) result.Add(n);
            return result;
        }
    }
}


Measured memory_bytes: 13268
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

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

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  static int[] LUT;
  static {
    LUT = new int[10001];
    LUT['m'] = 1000;
    LUT['c'] = 100;
    LUT['x'] = 10;
    LUT['i'] = 1;
    LUT[1000] = 'm';
    LUT[100] = 'c';
    LUT[10] = 'x';
    LUT[1] = 'i';
  }

  int encode(String str) {
    int sum = 0;
    int stack = 1;
    for(char c : str.toCharArray()) {
      switch(c) {
        case 'm':
        case 'c':
        case 'x':
        case 'i':
          sum += stack * LUT[c];
          stack = 1;
          break;
        default:
          stack = c - '0';
      }
    }
    return sum;
  }

  String decode(int num) {
    String str = "";
    for(int i = 1000; 0 < i; i /= 10) {
      int k = num/i;
      if (k > 1) {
        str += k;
      }
      if (k != 0) {
        str += (char)LUT[i];
      }
      num %= i;
    }
    return str;
  }

  void run() {
    int n = ni();
    for (int i = 0; i < n; ++i) {
      String left = sc.next();
      String right = sc.next();
      System.out.println(decode(encode(left) + encode(right)));
    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 38880
use proconio::{fastout, input};
use proconio::marker::Chars;
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        mut c : (usize,usize),
        mut d : (usize,usize),
        s: [Chars;h],
    }

    let mut q = VecDeque::new();
    let mut b = vec![vec![1000000000;w];h];

    c.0 -= 1;
    c.1 -= 1;
    d.0 -= 1;
    d.1 -= 1;

    b[c.0 ][c.1] = 0;
    for i in 0..h{
        for j in 0..w{
            if s[i][j] == '#'{
                b[i][j] = -1000000000;
            }
        }
    }
    q.push_back(c);

    while !q.is_empty(){
        let x = q.pop_front().unwrap();
        let dx = vec![1,0,-1,0];
        let dy = vec![0,1,0,-1];
        for i in 0..4{
            let nx = (x.0 as i32)+ dx[i];
            let ny = (x.1 as i32)+ dy[i];

            if nx < 0 || ny < 0 || nx >= (h as i32) || ny >= (w as i32) {
                continue;
            }

            let nx = nx as usize;
            let ny = ny as usize;
            if s[nx][ny] == '#'{
                continue;
            }

            if b[nx][ny] > b[x.0][x.1]{
                b[nx][ny] = b[x.0][x.1];
                q.push_front((nx,ny));
            }
        }
        let dx = vec![1,1,-1,-1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1];
        let dy = vec![-1,1,1,-1,2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2,2,2];
        for i in 0..20{
            let nx = (x.0 as i32)+ dx[i];
            let ny = (x.1 as i32)+ dy[i];

            if nx < 0 || ny < 0 || nx >= (h as i32) || ny >= (w as i32){
                continue;
            }
            
            let nx = nx as usize;
            let ny = ny as usize;
            if s[nx][ny] == '#'{
                continue;
            }

            if b[nx][ny] > b[x.0][x.1]{
                b[nx][ny] = b[x.0][x.1] + 1;
                q.push_back((nx,ny));
            }
        }
    }
    if b[d.0][d.1] == 1000000000{
        println!("-1");
    }else{
        println!("{}",b[d.0][d.1]);
    }

}


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

using ll = long long int;

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

/////////////////////////////////////////////////////////////
map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i] += 1;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}
/////////////////////////////////////////////////////////////

ll a, b;

int main(void) {
  // Here your code !
  scanf("%lld %lld", &a, &b);

  auto cand_a = prime_factorization(a);

  auto cand_b = prime_factorization(b);

  map<ll, ll> merge;

  int ans = 1;

  for (auto &e : cand_a) {
    auto ptr = cand_b.find(e.first);

    if (ptr == cand_b.end()) continue;

    ans += 1;
  }

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

  return 0;
}


Measured memory_bytes: 256
loop do
        c = gets.chomp.split
case c[1]
when '+'
        puts c[0].to_i + c[2].to_i
when '-'
        puts c[0].to_i - c[2].to_i
when "*"
        puts c[0].to_i * c[2].to_i
when "/"
        puts c[0].to_i / c[2].to_i
else
        break
end
end

Measured memory_bytes: 6100
//AOJ0032

#include<iostream>

using namespace std;

int main(){

	int x,y,z;
	int sum1=0,sum2=0;
	char tmp;

	while(cin>>x){
		cin>>tmp;
		cin>>y;
		cin>>tmp;
		cin>>z;

		if(x==y){
			sum2++;
		}

		if(x*x+y*y==z*z){
			sum1++;
		}
	}

	cout<<sum1<<endl<<sum2<<endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int a,c;
  cin>>a>>c;
  if(a%2*c%2)cout<<"Odd"<<endl;
  else cout<<"Even"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int stack;
    int num;
    int diff;
    int diff_min = 753;
    
   	for(int i = 0; i < s.length() -2; i++){
      stack = 0;
      for(int j = 0;j < 3;j++){
      	num = (int)s.charAt(i+j) - 48;
        stack += num * Math.pow(10,2-j);
      }
      diff = Math.abs(753 - stack);
      if(diff < diff_min) diff_min = diff;
      
    }
    
    System.out.println(diff_min);
  }
}


Measured memory_bytes: 35604
#include<stdio.h>

int main(void){
  char s;
  scanf("%c",&s);
  if(s=='A'){
    printf("T\n");
  }else if(s=='T'){
    printf("A\n");
  }else if(s=='C'){
    printf("G\n");
  }else if(s=='G'){
    printf("C\n");
  }
  return 0;
}

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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    for(int i = 0; i < K; i++){
        if(B <= A){
            B *= 2;
        }else if(C <= B){
            C *= 2;
        }else{
            break;
        }
    }

    if(C > B && C > A){
        if(B > A){
            cout << "Yes";
        }
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 3632
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions
fn bisect(x: i64, v: &Vec<i64>) -> (i64, i64) {
    match v.binary_search(&x) {
        Ok(i) => (v[i], v[i]),
        Err(i) => if i == 0 {
            (v[i], v[i])
        } else if i == v.len() {
            (v[i-1], v[i-1])
        } else {
            (v[i-1], v[i])
        }
    }
}

// Main
fn main(){
    input!{
        A: usize,
        B: usize,
        Q: usize,
        mut S: [i64; A],
        mut T: [i64; B],
        X: [i64; Q]
    }
    const INF:i64 = 1<<60;
    S.push(INF);
    S.push(-INF);
    S.sort();
    T.push(INF);
    T.push(-INF);
    T.sort();

    for x in X.into_iter(){
        let (s0,s1) = bisect(x,&S);
        let (t0,t1) = bisect(x,&T);
        let mut ans = INF;
        for &(s,t) in [(s0,t0), (s0,t1), (s1,t0), (s1,t1)].into_iter(){
            ans = min(ans, min((x-s).abs(),(x-t).abs()) + (s-t).abs());
        }
        println!("{}",ans);
    }
}

Measured memory_bytes: 11516
#include <iostream>
#include <string>

#define rap(N) for(int i = 0; i < N; i++)

using namespace std;

int main(void){

  char S;
  cin >> S;

  if(S >= 'a'){
    cout << 'a' << endl;
  }else {
    cout << 'A' << endl;
  }

  return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;
	cout << "ABC" << N << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 512
#include<cstdio>

int dijkstra(int start,int goal,int n);
const int INF=1000000000;
int edge[20][20];

int main()
{
	char buf[64];
	int n,m;
	
	fgets(buf,64,stdin);
	sscanf(buf,"%d",&n);
	fgets(buf,64,stdin);
	sscanf(buf,"%d",&m);
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			edge[i][j]=INF;
		}
	}
	
	for(int i=0;i<m;i++)
	{
		char buf[64];
		int a,b,c,d;
		fgets(buf,64,stdin);
		sscanf(buf,"%d,%d,%d,%d",&a,&b,&c,&d);
		
		edge[a-1][b-1]=c;
		edge[b-1][a-1]=d;
	}
	int start,goal,income,pay,reward;
	fgets(buf,64,stdin);
	sscanf(buf,"%d,%d,%d,%d",&start,&goal,&income,&pay);
	
	reward=income-pay-dijkstra(start-1,goal-1,n)-dijkstra(goal-1,start-1,n);
	printf("%d\n",reward);
	return 0;
}

int dijkstra(int start,int goal,int n)
{
	int cost[20];
	bool visited[20];
	
	for(int i=0;i<n;i++)
	{
		cost[i]=INF;
		visited[i]=false;
	}
	
	cost[start]=0;
	while(1)
	{
		int u=-1;
		for(int i=0;i<n;i++)
		{
			if(!visited[i]&&(u==-1||cost[i]<cost[u]))//未訪問でcost最小の町=u
			{
				u=i;
			}
		}
		if(u==-1)break;
		
		visited[u]=true;
		for(int i=0;i<n;i++)//cost更新
		{
			cost[i]=cost[i]>cost[u]+edge[u][i]?cost[u]+edge[u][i]:cost[i];
		}
	}
	return cost[goal];
}

Measured memory_bytes: 0
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 

inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=998244353; 
const int N=1e6 + 3 , M=5;
int OO=1e6; 
 
ll n,m,k,T,cnt,SU;
string str,ans;
vector<pair<char,int>> vec;

ll Sum(ll x){
	return (x*(x+1)) >> 1;
}

 
int main(){
	
	cin>>n>>m;
	
	cout<<Sum(n-1) + Sum(m-1)<<endl;
	
	


}









Measured memory_bytes: 256
from collections import Counter

N = int(input())
sss = [input() for _ in range(N)]
M = int(input())
tss = [input() for _ in range(M)]

cntS = Counter(sss)
cntT = Counter(tss)

ans = 0
for key in cntS.keys() | cntT.keys():
    num = 0
    if key in cntS:
        num += cntS[key]
    if key in cntT:
        num -= cntT[key]
    ans = max(ans, num)
print(ans)


Measured memory_bytes: 3316
from collections import Counter

def solve():
    MOD = 10**9 + 7

    def getPrimeFactors(x):
        anss = []
        for d in range(2, int(x**0.5)+1):
            while x%d == 0:
                anss.append(d)
                x //= d
        if x != 1:
            anss.append(x)
        return anss

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

    PFss = []
    Primes = set()
    for A in As:
        PFs = getPrimeFactors(A)
        cnt = Counter(PFs)
        PFss.append(cnt)
        Primes |= cnt.keys()

    cntP = Counter()
    for PFs in PFss:
        for key, num in PFs.items():
            cntP[key] = max(cntP[key], num)

    lcmA = 1
    for key, num in cntP.items():
        lcmA *= pow(key, num, MOD)
        lcmA %= MOD

    def getInvs(n, MOD):
        invs = [1] * (n+1)
        for x in range(2, n+1):
            invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
        return invs

    invs = getInvs(10**6, MOD)

    ans = 0
    for A in As:
        ans += lcmA * invs[A]
        ans %= MOD

    print(ans)

solve()


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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, l, r;
    cin >> l >> r >> n;
    int ans = 0;
    for(int i = l; i <= r; i++) {
        ans += (i % n == 0);

    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
const int N = 1e5 + 5;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f; 
using namespace std;

int n, m, a[N], b[N], id[N], pa[N], vis[N];
ll f[N], sum[N]; 
vector<int> g[N], son; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int getf(int x) { return pa[x] == x ? x : pa[x] = getf(pa[x]); }

bool cmp(int x, int y) { return a[x] < a[y]; }

int main()
{
	n = read <int> (), m = read <int> ();
	for(int i = 1; i <= n; i++)
	{
		a[i] = read <int> (), b[i] = read <int> ();
		a[i] = max(a[i] - b[i], 0), id[i] = pa[i] = i; 
	}
	sort(id + 1, id + n + 1, cmp);
	for(int u, v, i = 1; i <= m; i++)
		u = read <int> (), v = read <int> (), g[u].push_back(v), g[v].push_back(u);
	for(int u, i = 1; i <= n; i++)
	{
		son.clear(), u = id[i];
		vis[u] = 1, sum[u] = b[u];
		for(int v, j = 0; j < g[u].size(); j++)
		{
			v = g[u][j]; if(!vis[v] || getf(v) == getf(u)) continue;
			sum[u] += sum[getf(v)], son.push_back(getf(v)), pa[getf(v)] = getf(u); 
		}
		if(!son.size()) { f[u] = a[u] + b[u]; continue; }
		f[u] = INF; 
		for(int v, j = 0; j < son.size(); j++)
			v = son[j], f[u] = min(f[u], sum[u] - sum[v] + max(1ll * a[u], f[v])); 
	}
	printf("%lld\n", f[id[n]]); 
	return 0; 
}


Measured memory_bytes: 12684
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = Long.parseLong(sc.next());
		long sum = 0;
		long pow = 1;
		while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		}

		System.out.println(sum);

		sc.close();
	}
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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 T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N, D;
int X[50][50];
set<int> Z;

int calc(int i, int j) {
	int ret = 0;
	rep (k, D) {
		int t = X[i][k] - X[j][k];
		t = t * t;
		ret += t;
	}
	return ret;
}

signed main() {
	cin >> N >> D;
	rep (i, N) {
		rep (j, D) {
			cin >> X[i][j];
		}
	}

	for (int i = 1; i <= 1000; i++) {
		Z.insert(i*i);
	}
	Z.insert(0);

	// for (int x : Z) {
		// cout << x << endl;
	// }

	int ans = 0;
	rep (i, N) {
		repp (j, i+1, N) {
			int t = calc(i, j);
			// dbg(t)
			if (Z.count(t)) {
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll cnt1[2005];
ll cnt2[2005];

class Mod{
  public:
    ll mod;
    // mod must be a prime number
    Mod(ll m){
        mod = m;
    }
    //a^p
    ll modpow(ll a, ll p){
        if(p == 0) return 1;
        if(p%2 == 0){
            ll half = modpow(a, p/2);
            return half * half % mod;
        }
        else return a * modpow(a,p-1) % mod;
    }

    //nCr
    ll comb(ll n, ll r){
        if(r > n-r) return comb(n,n-r);
        ll mul = 1;
        ll div = 1;
        for (int i = 0;i < r;i++){
            mul *= n-i;
            mul %= mod;
            div *= i+1;
            div %= mod;
        }
        return mul * modpow(div,mod-2) % mod;
    }
};

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

    ll N,K; cin >> N >> K;

    Mod m(1e9+7);
    ll div2 = m.modpow(2,m.mod-2);

    ll A[2005];

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

    ll ans = 0;
    ll mod = 1e9+7;

    for (int i = 0;i < N;i++){
        cnt2[A[i]]++;
    }

    for (int i = 0;i < N;i++){
        cnt1[A[i]]++;
        ll sum1 = 0;
        ll sum2 = 0;
        for (int j = 0;j <= A[i];j++){
            sum1 += cnt1[j];
            sum2 += cnt2[j];
        }
        ll a = (i+1)-sum1;
        ll d = N-sum2;
        //cout << a << " " << d << endl;
        ans += ((((((a+a+d*(K-1)%mod)%mod))%mod*K)%mod)*div2)%mod;
        ans %=mod;
        //cout << a << " " << d << " " << (a+a+d*(K-1)) << " " << ans << endl;
    }

    cout << ans << endl;

    return 0;

}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a, b, va, vb, t;
  cin >> a >> va >> b >> vb >> t;
  if (va <= vb) {
    cout << "NO\n";
  } else {
    if (llabs(a - b) > (va - vb) * t) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
  return 0;
}

Measured memory_bytes: 3652
MOD = 998244353
inpl = lambda: tuple(map(int,input().split()))
N, K = inpl()
LR = [inpl() for _ in range(K)]
dp = [0]*N

c = 1
for i in range(N):
    c = (c + dp[i]) % MOD
    for L, R in LR:
        if i + L < N:
            dp[i+L] = (dp[i+L] + c) % MOD
            if i + R + 1 < N:
                dp[i+R+1] = (dp[i+R+1] - c) % MOD
print(dp[-1])


Measured memory_bytes: 69752
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
ll euclidean_gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}


int main() {
  int a, b, c, d;
  cin >> a >> b >> c >>d;
  int s = max(a,c);
  int t = min(b,d);
  cout << max(0,t-s) << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>

#define int long long
#define MAX 1000000000000000000
int A[100000];

using namespace  std;

signed main() {
    int n;
    int ans = 1;
    bool flag = false;
    bool flagZero = false;
    cin >> n;
    for(int i = 0;i < n; i ++){
        cin >> A[i];
    }

    for(int i = 0; i < n; i ++) if(A[i] == 0) flagZero = true;
    if(flagZero){
        cout << 0;
        return 0;
    }

    for(int i = 0; i < n; i ++){
        if(A[i] <= MAX/ans){
            ans *= A[i];
        }else{
            cout << -1;
            return 0;
        }
    }

    cout << ans;


    return 0;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,y; cin >> n >> y;
    rep(man,n){
        rep(gosen,n-man){
            int sen = n - man - gosen;
            if(y == man*10000 + gosen*5000 + sen*1000){
                cout << man << " " << gosen << " " << sen << endl;
                return 0;
            }
        }
    }
 
    cout << -1 << " " << -1 << " " << -1 << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)
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; }

typedef long long ll;
using namespace std;

bool is_in(int i, int j, int h, int w) {
    return 0 <= i && i < h && 0 <= j && j < w;
}

int main() {
    
    int h, w;
    cin >> h >> w;
    vector<string> sorg(h, "");
    vector<string> s   (h, "");
    REP(i, h) {
        cin >> s[i];
        sorg[i] = s[i];
    }

    REP(i, h) REP (j, w) {
        if ((i + j) % 2) {
            s[i][j] = s[i][j] == '.' ? '#' : '.';
        }
    }

    vector<vector<bool>> visited(h, vector<bool>(w, false));
    ll ans = 0;

    REP(i, h) REP(j, w) {

        if (visited[i][j]) continue;

        deque<ll> q;
        ll black = 0, white = 0;

        q.push_back(j + i * w);
        visited[i][j] = true;
        char rootc = s[i][j];

        while (!q.empty()) {

            ll v = q.back();
            int k = v / w, l = v % w;
            q.pop_back();

            if (sorg[k][l] == '.') white++; else black++;
            
            if (is_in(k-1, l, h, w)) if (rootc == s[k-1][l] && !visited[k-1][l]) {
                q.push_back((k - 1) * w + l);
                visited[k-1][l] = true;
            }
            if (is_in(k+1, l, h, w)) if (rootc == s[k+1][l] && !visited[k+1][l]) {
                q.push_back((k + 1) * w + l);
                visited[k+1][l] = true;
            }
            if (is_in(k, l-1, h, w)) if (rootc == s[k][l-1] && !visited[k][l-1]) {
                q.push_back(k * w + l - 1);
                visited[k][l-1] = true;
            }
            if (is_in(k, l+1, h, w)) if (rootc == s[k][l+1] && !visited[k][l+1]) {
                q.push_back(k * w + l + 1);
                visited[k][l+1] = true;
            }

        }

        ans += black * white;

    }

    cout << ans << endl;

}

Measured memory_bytes: 1280
import std.stdio,std.string,std.conv;

int main()
{
	string s;
	int a[4] = [0,0,0,0];
	while((s = readln.chomp).length != 0)
	{
		string[] _s = s.split(",");
		if(_s[1] == "A") a[0]++;
		if(_s[1] == "B") a[1]++;
		if(_s[1] == "AB") a[2]++;
		if(_s[1] == "O") a[3]++;
	}

	foreach(i;0..4) a[i].writeln;
	return 0;
}

Measured memory_bytes: 1052
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef std::vector<ll> lls;
#define MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
#define MAX(a, b) ( ((a)>(b)) ? (a) : (b) )

void cinv(lls& llVec, ll n) {
	ll val;
	llVec.reserve((size_t)(n));
	for (ll i = 0; i < n; i++) {
		cin >> val;
		llVec.push_back(val);
	}
}


int main()
{
	ll N;
	cin >> N;
	lls A;
	cinv(A, N);
	lls outAry(N);


	for (int i = 0; i < N; i++) {
		ll idx = i + 1;
		outAry[A[i] - 1] = idx;
	}

	for (ll i = 0; i < N; i++){
		cout << outAry[i];
		if (i == N - 1) cout << '\n';
		else cout << " ";
	}

	return 0;
}



Measured memory_bytes: 2432
/*
name:       Egyptian Tourist
PlatForm:   CodeForces/SPOJ...etc
LANG:       C++
DIV:        Training
TIME:       *
RATE:       *
*/

/*
Time Consumed:*
Problem Topics: *
*/
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
//----------------------------------//

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

//-------------------------------------------------------//
#define rep(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define repr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define lp(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define lpr(i,n) for (int i = (n) - 1; ~i; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
//-------------------------------------------------------------------------------------//

#define clr(ar, val) memset(ar, val, sizeof(ar))
//----------------------------------------------//

#define inn freopen("in.in","r",stdin)
#define outt freopen("out.out","w",stdout)
#define PI 3.1415926535897932385
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define pob pop_back
#define bit(n) (1<<(n))
#define Last(i) ( (i) & (-i) )
#define all(v) ((v).begin()), ((v).end())
#define sq(x) ((x) * (x))
#define INF INT_MAX
#define Ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

//-------------------------------------------------------------//
#ifndef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1<<" | ";
    __f(comma+1, args...);
}
#else
#define debug(...)
#endif
#define _ist_ cout << "\nSTART OF INPUT DISPLAYING CHECK\n";
#define _iend_ cout << "\nEND OF INPUT DISPLAYING CHECK\n";
//------------------------------------------------------------//
template<class T, class T2>
T _f_pow(T a, T2 b)
{
    T res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
#define N (int)1e5+5
ll dp[N];
ll n, s;
ll _w[105];
ll _v[105];
int main()
{
    Ios;
    //inn;//outt;
    //auto tt = clock();
    cin >> n >> s;
    rep(i, 1, n)
    {
        cin >> _w[i] >> _v[i];
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = s; ~j; j--)
        {
            if(j >= _w[i])
                dp[j] = max(dp[j - _w[i]] + _v[i], dp[j]);
        }
    }
//    ll mx = 0;
//    rep(i, 1, s)
//        mx = max(dp[i], mx);
    cout << dp[s] << "\n";
    //cout << (double(clock() - tt)/CLOCKS_PER_SEC * 1.00) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << lmax(a*c, tmax(a*d, b*c, b*d)) << endl;
}


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

unsigned long gcm(unsigned long _a, unsigned long _b){
        unsigned long a, b;
        unsigned long r=0;
        if(_a<_b){
                a = _b;
                b = _a;
        }
        else{
                a = _a;
                b = _b;
        }
        r = a % b;
        while(r!=0){
                a = b;
                b = r;
                r = a % b;
        }
        return b;
}

unsigned long lcm(unsigned long a, unsigned long b){
        return (a*b)/gcm(a, b);
}

long count_multiple(long a, long b, long c){
        long ret = 0;
        ret = b/c - (a-1)/c;
#ifdef DEBUG2
        printf("count_multiple: a=%ld, b=%ld, c=%ld, ret=%ld\n", a, b, c, ret);
#endif
        return ret;
}

int main(int argc, char* argv[]){
        char buf[64]={0};
        char* p=NULL;
        long A = 0;
        long B = 0;
        long C = 0;
        long D = 0;
        long ret = 0;

        if(fgets(buf, sizeof(buf)-1, stdin)==NULL){
                return 1;
        }

        p = strtok(buf, " ");
        A = atol(p);
        if(A<0){return 1;}

        p = strtok(NULL, " ");
        B = atol(p);
        if(B<0){return 2;}

        p = strtok(NULL, " ");
        C = atol(p);
        if(C<0){return 3;}

        p = strtok(NULL, " ");
        D = atol(p);
        if(D<0){return 4;}

#ifdef DEBUG1
        printf("input: A=%ld, B=%ld, C=%ld, D=%ld\n", A, B, C, D);
#endif
        ret = B-A+1;
        ret -= count_multiple(A, B, C);
        ret -= count_multiple(A, B, D);
        ret += count_multiple(A, B, lcm(C, D));

        printf("%ld\n", ret);
        return 0;
}

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

int main(void) {
	int N;
	vector<double> A;

	cin >> N;
	A.resize(N);
	double M = 1.0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		M *= A[i];
	}
	double S = 0.0;
	for (int i = 0; i < N; ++i)
		S += M / A[i];
	double ans = M / S;

	cout << fixed << setprecision(7) << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

M = [[0] * n for i in range(n)]
for i in range(1, n):
    M[0][i] = int(s[0] == s[i])

for i in range(1, n):
    for j in range(i+1, n):
        if s[i] == s[j] and M[i-1][j-1] + 1 <= j-i: 
            M[i][j] = M[i-1][j-1] + 1

M[n//2-1][n-1] = 0

#print(M)

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if M[i][j] == j-i:
            ans = max(ans, j-i)

print(ans * 2)

Measured memory_bytes: 3316
// How Many Divisors?

#include <iostream>
#include <cassert>

int main()
{
  int a = 0, b = 0, c = 0;
  std::cin >> a >> b >> c;

  assert(1 <= a && a <= 10000);
  assert(1 <= b && b <= 10000);
  assert(1 <= c && c <= 10000);
  assert(a <= b);

  int divisors = 0;
  for (int i = a; i <= b; ++i) {
    if (c % i == 0) ++divisors;
  }

  std::cout << divisors << std::endl;

  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;

int main(int argc, char* argv[])
{
  int A, B, C;
  std::cin >> A >> B >> C;

  ll ans = INF;
  if (A == B) {
    ans = C;
  } else if (A == C) {
    ans = B;
  } else {
    ans = A;
  }

  std::cout << ans << std::endl;
}


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

n = int(input())

ans = 0
# 3つすべて同じ場合
for i in range(1,n+1):
    ans += i


# 2つ同じ時
if n> 1:
    for i in range(1,n+1):
        for k in range(i+1,n+1):

            ans += gcd(i,k) * 6


# 3つ違う時
if n > 2:
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for l in range(j+1,n+1):
                ans += gcd(i,gcd(j, l)) * 6


print(ans)


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;
    return 0;
}


Measured memory_bytes: 3652
# 距離的に到達可能か、経過時間と距離差の偶奇が一致してるか

N = int(input())
pt = 0
px = 0
py = 0
#ans = True
for _ in range(N):
    t,x,y = map(int,input().split())
    if abs(x-px) + abs(y-py) > t-pt:
        print('No')
        exit()
    if (abs(x-px) + abs(y-py))%2 != (t-pt)%2:
        print('No')
        exit()
    pt = t
    px = x
    py = y
print('Yes')

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b,c;
	cin>>a;
	if(a==1){
		cout<<"Hello World"<<endl;
	}
	else{
		cin>>b>>c;
		cout<<b+c<<endl;
	}
    return 0;
}

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

long long x, a, b;

long long pangkat(long long s) {
	return s*s*s*s*s;
}

int main() {
	cin>>x;
  	for(a=-120; a<=120; a++) {
      for(b=-120; b<=120; b++) {
        if(pangkat(a)-pangkat(b)==x) {
          cout<<a<<" "<<b<<"\n";
          return 0;
        }
      }
    }
  	return 0;
}

Measured memory_bytes: 3608
N, K = map(int, input().split())

# 下限 0 : 完全グラフ -> 全部お互いつながってる
# 上限: うに型, star 型
#  (N - 1) * (N-2) / 2: 中心以外の組の個数
# 全頂点の組 N(N-1) / 2
# n**2 - n - 2n + 2 = (n-1)(n-2)
# n-1 組は連結しないと全てがつながらないため, n-1 組は必ず距離が1
# 上限 - 1 は一つだけ外の辺を 追加すれば 達成できる
# 先に上限を作ればできた

mx = (N-1)*(N-2)/2
if mx < K:
    print("-1")
    exit()

ans = list()

# 全て N につなげたスターを作る
for i in range(N-1):
    ans.append((i+1, N))

# 追加する候補
add = int(mx - K)
edge = list()
for i in range(N-1):
    for j in range(i):
        edge.append((j+1, i+1))

# 追加する
for i in range(add):
    ans.append(edge[i])
# 出力する
print(len(ans))
for a in ans:
    print("{} {}".format(a[0], a[1]))

Measured memory_bytes: 42600
import sys
from collections import Counter

N = int(input())
s1 = list(map(int,input().split()))
M = int(input())
s2 = list(map(int,input().split()))

c1 = Counter(s1)
c2 = Counter(s2)

for k,v in c2.items():
    if k in c1:
        if v > c1[k]:
            print('NO')
            sys.exit()
    else:
        print('NO')
        sys.exit()
print('YES')


Measured memory_bytes: 57056