akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let w: usize = sc.read();
    let h: usize = sc.read();
    let mut v: Vec<Vec<i32>> = vec![vec![0; w + 2]; h + 2];
    for i in 1..h+1 {
        for j in 1..w+1 {
            v[i][j] = sc.read();
        }
    }
    let v = v;

    let dx: [[i32; 6]; 2] = [[1, 0, -1, -1, -1, 0], [1, 1, 0, -1, 0, 1]];
    let dy: [i32; 6] = [0, 1, 1, 0, -1, -1];

    let mut visited: Vec<Vec<bool>> = vec![vec![false; w + 2]; h + 2];
    let mut que: VecDeque<(i32, i32)> = VecDeque::new();
    que.push_back((0, 0));
    visited[0][0] = true;
    let mut ans = 0;
    while let Some((y, x)) = que.pop_front() {
        for d in 0..6 {
            let (ny, nx) = (y + dy[d], x + dx[(y % 2) as usize][d]);
            if ny < 0 || nx < 0 || (h + 2) as i32 <= ny || (w + 2) as i32 <= nx {
                continue;
            }
            let (ny, nx) = (ny as usize, nx as usize);
            if v[ny][nx] == 1 {
                ans += 1;
            }
            if v[ny][nx] == 0 && !visited[ny][nx] {
                visited[ny][nx] = true;
                que.push_back((ny as i32, nx as i32));
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Nmax 100008
ll n,m,x,y,z ,k,e,r,a,b,nb,q,c,test;
ll ai[Nmax], bi[Nmax]  ;
long double h,l;
string s , s1 ;

int main ()
{
    cin>> n ;
    y = 0 ;
    for(int i= 0 ; i<n ; i++) {
        cin>> x;
        if (x<=y) nb++ ;
        else m=max(m,nb), nb=0 ;
        y= x ;
    }
    cout << max(m,nb) ;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int R, G, B, n;
  cin >> R >> G >> B >> n;
  int ans = 0;
  for(int i = 0; i <= n; ++i) {
    for(int j = 0; j <= n; ++j) {
      if(n - (i * R + j * G) < 0) continue;
      if((n - (i * R + j * G)) % B == 0) ++ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

#include <algorithm>

using namespace std;

int main() {
  long long a;
  int ans = 1000;
  scanf("%lld", &a);
  while (a > 99) {
    ans = min(ans, (int)abs(753 - a % 1000));
    a /= 10;
  }
  printf("%d\n", ans);
  return 0;
}


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



void print(vector<int> v){
	
	for(int i=0;i<v.size();i++){
		cout<<v[i];
	}
	//cout<<endl;
}
int a,b,c;
void solve(){
	
	cin>>a>>b>>c;
	cout<<a*b/2<<endl;

}


int main(){

    solve();
    return 0;
}




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

typedef long long int ll;

int main(){
  ll S, x1,y1,x2,y2,x3,y3;
  cin >> S;
  x1 = y1 = 0;
  x2 = 1e9;
  x3 = 1;
  y3 = S / x2;
  if(S % x2 != 0)y3++;
  y2 = x2 * y3 - S;
  cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << endl;
  return 0;
}


Measured memory_bytes: 3596
N,M = map(int,input().split())
A = list(map(int,input().split()))
count = 0
A_sum =sum(A)
vote_min = A_sum/(4*M)
for i in range(len(A)):
  if A[i] >= vote_min:
    count += 1
print("Yes" if count >= M else "No")

Measured memory_bytes: 9120
#include<iostream>
using namespace std;
int main()
{
	long long int a,b,c;
	string ans;
	cin >> a >> b >> c;
	ans="No";
	if (4*a*b<(c-a-b)*(c-a-b)) ans="Yes";
	if (a>c || b>c) ans="No";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
string s;
int l;
int main()
{
    cin>>s;
    l=s.size();
    for(int i=0;i<l;i++)
    {
        if(s[i]=='C')
        {
            for(int j=i+1;j<l;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes\n";
                    return 0;
                }
            }
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define for_tests(t, tt) int t; scanf("%d", &t); for(int tt = 1; tt <= t; tt++)
#ifndef ONLINE_JUDGE
#define debug(args...) fprintf(stderr,args)
#else
#define debug(args...)
#endif //ONLINE_JUDGE
template<typename T> inline T abs(T t) { return t < 0? -t : t; }
const ll modn = 1000000007;
inline ll mod(ll x) { return x % modn; }
#define IOS() ios::sync_with_stdio(0),cin.tie(0)

const int MAXN = 212345;

int n, m, k;
char s[MAXN];

int main (){
    scanf(" %s", s);
    int ans = 0;
    int cnt = 0;
    n = strlen(s);
	for(int a=0;a<n;a++){
        if(s[a] == 'R')
            cnt++;
        else
            cnt = 0;
        ans = max(ans, cnt);
	}
    printf("%d\n", ans);
}



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

int main(){
    string st;
    int ch_index[26];
    // init array
    for(int i=0; i<26; i++) ch_index[i] = 0;

    // processing inputs
    while(getline(cin, st)){
        for(int i=0; i<st.size(); i++){
            int num;
            if(st[i]>='a'&&st[i]<='z') {
                num = st[i] - 'a';
                ch_index[num] += 1;
            }
            else if(st[i]>='A'&&st[i]<='Z'){
                num = st[i] - 'A';
                ch_index[num] += 1;
            }
        }
    }

    // render outputs
    for(int i=0; i<26; i++){
        char ch_key = 'a' + i;
        cout << ch_key << " : " << ch_index[i] << endl;
    }
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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


void solve(long long A, long long B){
    ll ans = A * B;
    cout << ans << endl;

}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

int main() {
	// your code goes here
	int p,q,r;
	cin>>p>>q>>r;
	if(p<=q && q<=r){
		cout<<p<<" "<<q<<" "<<r<<endl;
	}
	else if(p<=r && r<=q){
		cout<<p<<" "<<r<<" "<<q<<endl;
	}
	else if(q<=p && p<=r){
		cout<<q<<" "<<p<<" "<<r<<endl;
	}
    else if(q<=r && r<=p){
		cout<<q<<" "<<r<<" "<<p<<endl;
	}
	else if(r<=p && p<=q){
		cout<<r<<" "<<p<<" "<<q<<endl;
	}
	else if(r<=q && q<=p){
		cout<<r<<" "<<q<<" "<<p<<endl;
	}
}

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

int main() {
  int h;
  cin >> h;
  int w;
  cin >> w;
  vector<vector <char>> a(h, vector<char>(w));
  for (int i = 0; i < h; i = i + 1) {
    for (int j = 0; j < w; j = j + 1) {
      cin >> a.at(i).at(j);
    }
  }
  //vector<vector<bool>> judge(h, vector<bool>(w, true));
  for (int i = 0; i < h; i = i + 1) {
    int count = 0;
    for (int j = 0; j < w; j = j + 1) {
      if (a.at(i).at(j) == '.') {
        count = count + 1;
      }
    }
    if (count == w) {
      for (int j = 0; j < w; j = j + 1) {
        a.at(i).at(j) = ' ';
      }
    }
  }
  
  for (int j = 0; j < w; j = j + 1) {
    int count = 0;
    for (int i = 0; i < h; i = i + 1) {
      if (a.at(i).at(j) == '.' || a.at(i).at(j) == ' ') {
        count = count + 1;
      }
    }
    if (count == h) {
      for (int i = 0; i < h; i = i + 1) {
        a.at(i).at(j) = ' ';   
      }
    }
  }
  
  for (int i = 0; i < h; i = i + 1) {
    int count = 0;
    for (int j = 0; j < w; j = j + 1) {
      if (a.at(i).at(j) != ' ') {
        cout << a.at(i).at(j);
      } else {
        count = count + 1;
      }
    }
    if (count != w) {
      cout << endl;
    }
  }
}



Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Map<Integer, List<Integer>> map = new TreeMap<>();
        for (int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next()) - 1;
            int b = Integer.parseInt(sc.next()) - 1;
            if (!map.containsKey(a)) {
                map.put(a, new ArrayList<>());
            }
            map.get(a).add(b);
            if (!map.containsKey(b)) {
                map.put(b, new ArrayList<>());
            }
            map.get(b).add(a);
        }
        int[] ans = new int[n];
        Arrays.fill(ans, -1);
        Deque<Integer> dq = new ArrayDeque<>();
        dq.add(0);
        while (!dq.isEmpty()) {
            int temp = dq.poll();
            List<Integer> list = map.get(temp);
            for (int num : list) {
                if (ans[num] == -1) {
                    ans[num] = temp;
                    dq.add(num);
                }
            }
        }
        System.out.println("Yes");
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < n; i++) {
            sb.append(ans[i] + 1);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 87684
#include<stdio.h>
int main(){
  int x,y,res=1;
 
  scanf("%d%d",&x,&y);
   
  if(y<x){
      res=y;
      y=x;
      x=res;
  }
 
  while(res!=0){
      res=y%x;
      y=x;
      x=res;
  }
 
  printf("%d\n",y);
  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	char n;
	cin>>n;
	if(n=='a'||n=='o'||n=='e'||n=='i'||n=='u')
		cout<<"vowel"<<endl;
	else
		cout<<"consonant"<<endl;
return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	static PrintWriter out = new PrintWriter(System.out); 

	public static void main(String[] args)throws Exception {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			
			int n = Integer.parseInt(br.readLine());
			
			Map<String,Integer> map = new HashMap<>();
			int max = 0,tmp = 0;
			for(int i = 0; i < n; i++) {
				String s =  br.readLine(); 
				
				if(map.containsKey(s)) {
					tmp = map.get(s)+1;
					map.put(s,tmp);
					max = Math.max(tmp, max);
				}else {
					map.put(s,1);
					max = Math.max(max, 1);
				}

				
			}
			
			List<String> list = new ArrayList<>();
			for(String key: map.keySet()) {
				if(map.get(key)==max) {
					list.add(key);
				}
			}
			
			Collections.sort(list);
			
			for(String a: list) {
				out.println(a);
			}
			out.flush();
			
		}		
		
		
	}

}


Measured memory_bytes: 55356
n = int(input())

if n==1:
    print(0);exit()
#素因数分解して、指数からいくつまで加算できるか算出すればよい
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

li = factorization(n)
ans = 0
for f in li:
    f = f[1]
    for i in range(1,f+1):
        if i>f:
            break
        f-=i
        ans+=1
print(ans)

Measured memory_bytes: 9392
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;


#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
typedef pair<int,int> pii;

vector<int> ans(100100);

int selectmin(int h, vector<pii> &data, int n){
	int mn = INT_MAX;
  	rep(i,n) {
      	if(h>=data[i].first){
      		mn = min(mn, ans[h-data[i].first] + data[i].second);
        }
      	else{
        	mn = min(mn, data[i].second);
        }
    }
  	return mn;
}

void Main()
{
	ll h,n;
  	cin >> h >> n;
  	vector<int> a(n),b(n);
  	vector<pii> data(n);
  	rep(i,n) {
    	cin >> a[i] >> b[i];
    	data[i] = make_pair(a[i],b[i]);
  	}

  	ans[0] = 0;
	rep3(i,1,h){
  		ans[i] = selectmin(i, data, n);
  	}
	cout << ans[h] << endl;
 	return;
}


int main()
{
 cin.tie(nullptr);
 ios_base::sync_with_stdio(false);
 cout << fixed << setprecision(15);
 Main();
 return 0;
}


Measured memory_bytes: 640
line1 = gets
line2 = gets

N = line1.to_i
umasas = line2.split(" ")

sum = 0
i = 0

umasas.length.times do
  break if i == umasas.length - 1
  
  nokori = umasas.length - (i+1)
  k = i + 1
  
  nokori.times do
    j = k == umasas.length - 1
    
    x = umasas[i].to_i
    y = umasas[k].to_i
    
    umasa = x * y
    sum += umasa
    
    k += 1
  end
  
   i += 1
end

p sum



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

int main() {
  int N;
  cin >> N;
  rep(i, N) {
    string S;
    cin >> S;
    if (S=="Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}


Measured memory_bytes: 3620
import math

n,m=map(int, input().split()) 
mod=10**9+7
ans=0

if abs(n-m)>=2:
    print(0)

elif abs(n-m)%2==1:
    ans=(math.factorial(n)%mod)*(math.factorial(m)%mod)%mod
    print(ans)
    
else:
    ans=2*(math.factorial(n)%mod)*(math.factorial(m)%mod)%mod
    print(ans)
    





    





Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;
}

Measured memory_bytes: 256
// D - Line++

// 全頂点間の最短距離を場合分けで計算する解法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int ans[2000];

int main(){
	int N, X, Y;
	cin >> N >> X >> Y;

	int d;
	for (int i=1; i<=N; i++) {
		for (int j=i+1; j<=N; j++) {
			if (i <= X) {
				if (j <= X) {
					d = j - i;
				} else if (j <= Y) {
					d = min(j - i, (X - i) + 1 + (Y - j));
				} else {
					d = (X - i) + 1 + (j - Y);
				}
			} else if (i < Y) {
				if (j <= Y) {
					d = min(j - i, (i - X) + 1 + (Y - j));
				} else {
					d = min(j - i, (i - X) + 1 + (j - Y));
				}
			} else {
				d = j - i;
			}

			//cout << i << " -> " << j << " : " << d << endl; // **** debug ****
			ans[d]++;
		}
	}

	for (int i=1; i<N; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    ll w,h,n,x,y,a;
    cin>>w>>h>>n;
    ll x0=0,y0=0,x1=w,y1=h;
    for(ll i=0;i<n;i++){
        cin>>x>>y>>a;
        if(a==1 && x>x0) x0=x;
        else if(a==2 && x<x1) x1=x;
        else if(a==3 && y>y0) y0=y;
        else if(a==4 && y<y1) y1=y;
    }
    cout<<(x1>x0 && y1>y0?(x1-x0)*(y1-y0):0)<<endl;
    return 0;
}

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

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

  int cnt = 0;
  int minA = 2001;
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;

    cnt += max(N - A, 0);
    minA = min(A, minA);
  }
  cnt -= max(N - minA, 0);

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long X,Y;
    cin >> X >> Y;
    
    long long ans = 0;
    while ( X <= Y ) {
        X *= 2;
        ans++;
    }
    cout << ans << endl;
    
    
    return 0;
}

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

typedef long long ll;

using namespace std;
#define m 753
int main(){
    string s;cin >> s;
    int ans=10000000;
    int x;
    for(int i=0;i<s.size()-2;i++){
        x=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        ans=min(ans,abs(x-m));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>

using namespace std;
typedef long long ll;
int gcd(int a, int b) {
	if (b == 0) {
		return a;			
	}
	return gcd(b, a % b);
}
int main(){
ll n,X;
  cin>>n>>X;
  ll x[n];
  ll memo[n];
  ll memo2[n];
  for(ll i=0;i<n;i++){
  cin>>x[i];
    memo[i]=x[i]-X;
    memo2[i]=abs(memo[i]);
  }
  sort(memo2,memo2+n);
  int flag=0;
  int ans=memo2[0];
  for(ll i=1;i<n;i++){
ans=gcd(memo2[i],ans);
    if(ans==1)
      break;
  }
  cout<<ans;
  return 0;
}



Measured memory_bytes: 2560
n,d = gets.split.map(&:to_i)
a = n.times.map{gets.split.map(&:to_i)}
ans = 0
(0..(n-2)).each do |i|
    ((i+1)...n).each do |j|
        sum = 0
        d.times do |k|
            sum += (a[i][k]-a[j][k])**2
        end
        s = Math.sqrt(sum).floor
        if (s*s == sum )
            ans += 1
        end
    end
end
puts ans

Measured memory_bytes: 1788
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**9)

def resolve():
    N = int(input())
    A = [int(input()) for i in range(5)]

    print(4 + -(-N // min(A)))


resolve()

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __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 trace(...)
#endif
const int mod = 1e9 + 7;
int main(){
	int n; sd(n);
	vector<int> a(n), b(n);
	vector<pii> P;
	for(int i = 0; i < n; i++){
		sd(a[i]);
		P.push_back({a[i], -1});
	}

	for(int i = 0; i < n; i++){
		sd(a[i]);
		P.push_back({a[i], 1});
	}

	sort(all(P));
	int ans = 1;
	int diff = 0;
	for(auto it : P){
		int col = it.S;
		if(col * diff < 0){
			ans = (ans * 1ll * abs(diff)) % mod;
		}
		diff += col;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3188
#include <stdio.h>
int main(void)
{
   int a, b;
   
   scanf("%d %d", &a, &b);
   
   if (a < b){
      printf("a < b\n");
   }
   else if (a > b){
      printf("a > b\n");
   }
   else{
      printf("a == b\n");
   }
   return (0);
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    map<int, int> C[2];
    // 前半
    for(int bit = 1; bit < (1 << (N / 2)); bit++) {
        int sum = 0, cost = 0;
        for(int i = 0; i < (N / 2); i++) {
            if(bit & (1 << i)) {
                sum += Mb * a[i] - Ma * b[i];
                cost += c[i];
            }
        }
        if(!C[0].count(sum)) {
            C[0][sum] = cost;
        } else {
            chmin(C[0][sum], cost);
        }
    }
    // 後半
    for(int bit = 1; bit < (1 << (N - N / 2)); bit++) {
        int sum = 0, cost = 0;
        for(int i = 0; i < (N - N / 2); i++) {
            if(bit & (1 << i)) {
                int j = i + N / 2;
                sum += Mb * a[j] - Ma * b[j];
                cost += c[j];
            }
        }
        if(!C[1].count(sum)) {
            C[1][sum] = cost;
        } else {
            chmin(C[1][sum], cost);
        }
    }
    int ans = INF;
    for(int i = 0; i < 2; i++) {
        if(C[i].count(0)) {
            chmin(ans, C[i][0]);
        }
    }
    for(const auto &p : C[0]) {
        if(C[1].count(-p.first)) {
            chmin(ans, p.second + C[1][-p.first]);
        }
    }
    cout << (ans == INF ? -1 : ans) << endl;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;
typedef long long ll;

ll select(ll p,ll q);
ll pow_ans(ll x, ll n);
ll select2(ll p,ll q);

vector<vector<ll> > a;
ll big=1000000007;
ll h,w,k;

int main(){
  cin>>h>>w>>k;
  if(w==1){
    cout<<"1"<<endl;
    return 0;
  }

  a.assign(h+1,vector<ll> (w,0));
  a[0][0]=1;
  for(int i=1;i<h+1;i++){
    for(int j=0;j<w;j++){
      if(j!=0){
        a[i][j]+=pow_ans(a[i-1][j-1]*(select(0,j-2)*select(j+1,w-1)),1);
        a[i][j]=pow_ans(a[i][j],1);
      }
      a[i][j]+=pow_ans(a[i-1][j]*(select(0,j-1)*select(j+1,w-1)),1);
      a[i][j]=pow_ans(a[i][j],1);
      if(j!=w-1){
        a[i][j]+=pow_ans(a[i-1][j+1]*(select(0,j-1)*select(j+2,w-1)),1);
        a[i][j]=pow_ans(a[i][j],1);
      }
    }
  }
  cout<<a[h][k-1]<<endl;
}

ll select2(ll p,ll q){
  ll re=1;
  if(p>q) return 0;
  if(p==q) return 0;
  re+=select2(p+2,q);
  re+=select2(p+1,q);
  return re;
}

ll select(ll p,ll q){
  ll re=2;
  if(p>q) return 1;
  if(p==q) return 1;
  re+=select2(p+2,q);
  re+=select2(p+1,q);
  return re;
}


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


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
const int INF=0x3f3f3f3f;
int a[15][15],val[1<<15];
int dp[1<<15][15];
void tense(int &x,int y){
	if (x<y)
		x=y;
}
int main(){
	int n,m,sum=0;
	scanf("%d%d",&n,&m);
	while(m--){
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		u--,v--;
		for(int i=0;i<(1<<n);i++)
			if ((i>>u&1) && (i>>v&1))
				val[i]+=c;
		a[u][v]=a[v][u]=c;
		sum+=c;
	}
	for(int i=0;i<(1<<n);i++)
		for(int j=0;j<n;j++)
			dp[i][j]=-INF;
	for(int i=0;i<(1<<n);i++)
		if (i&1){
			dp[i][0]=val[i];
			//printf("val[%d]=%d\n",i,val[i]);
		}
	for(int i=0;i<(1<<n);i++)
		for(int j=0;j<n;j++) 
			if (dp[i][j]>=0){
				//puts("WTF");
				int w=~i&((1<<n)-1);
				for(int k=w;k;k=(k-1)&w){
					int to=k|i;
					for(int o=0;o<n;o++)
						if ((k>>o&1) && a[j][o])
							tense(dp[to][o],dp[i][j]+val[k]+a[j][o]);
				}
			}
	printf("%d",sum-dp[(1<<n)-1][n-1]);
}

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

#define rep(i,n) for(int i;i<(int)(n);i++)
#define Rep(i,n) for(int i;i<=(int)(n);i++)
#define all(v) v.begin,v.end
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MX = 1000005;

int main(){
    int x,ans;
    cin>>x;
    if(x<=599) {
        cout<<8;
    }
    else if(600<=x&&x<=799) {
        cout<<7;
    }
    else if(800<=x&&x<=999) {
        cout<<6;
    }
    else if(1000<=x&&x<=1199) {
        cout<<5;
    }
    else if(1200<=x&&x<=1399) {
        cout<<4;
    }
    else if(1400<=x&&x<=1599) {
        cout<<3;
    }
    else if(1600<=x&&x<=1799) {
        cout<<2;
    }
    else{
        cout<<1;
    }
   return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main() {
  int n,a[101],i,j;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  int cnt=0;
  for(i=0; i<n; i++) {
    for(j=n-1; j>i; j--) {
      if(a[j]<a[j-1]) {
	int tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
	cnt++;
      }
    }
  }
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2096
l=[]
i=0

while True:
    x,y=input().split()

    x=int(x)
    y=int(y)

    if x==y and x==0:
        break
    if x>y:
        w=x
        x=y
        y=w
    l.append([x,y])
    i=i+1

for j in range(i):
    print(l[j][0],l[j][1])



Measured memory_bytes: 6136
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;



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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

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

#define int long long



void solve(){

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

	int dp[n+2];

	dp[0] = 0;
	for(int i = 1 ; i < n ; ++i){
		dp[i] = 1e12;
		for(int j = 1 ; j <= k ; ++j){

			if(i-j < 0)
				break;

			dp[i] = min(dp[i-j] + abs(a[i]-a[i-j]) , dp[i]);
		}
	}

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


}
signed main(){

    fast;
    int t = 1;
    //cin>>t;
    while(t--)
        solve();
}



Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
namespace B___Echo
{
    static class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            if (s.Length % 2 == 0)
            {
                string[] array = s.MySplit(s.Length / 2);
                if (array[0] == array[1])
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
            else
            {
                Console.WriteLine("No");
            }

        }
        static string[] MySplit(this string str, int count)
        {
            var list = new List<string>();
            int length = (int)Math.Ceiling((double)str.Length / count);

            for (int i = 0; i < length; i++)
            {
                int start = count * i;
                if (str.Length <= start)
                {
                    break;
                }
                if (str.Length < start + count)
                {
                    list.Add(str.Substring(start));
                }
                else
                {
                    list.Add(str.Substring(start, count));
                }
            }

            return list.ToArray();
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	int a = h[0], cnt = 0;
	for (int i = 1; i < n; i++) {
		if (h[i] >= a) {
			cnt++;
			a = h[i];
		}
	}
	cout << cnt+1 << endl;
	return 0;
}


Measured memory_bytes: 256
s=list(input())
d=["A","G","C","T"]
a=[]
b=[]
x=[]
for i in range(len(s)):
    a.append(s[i:])
for j in a:
    for k in range(len(j)-1):
        b.append(j[:-k-1])
ans=a+b
for i in ans:
    if set(i) <= set(d):
        x.append(len(i))
    else:
        pass
if x:
  print(max(x))
else:
  print(0)

Measured memory_bytes: 3064
// abc136b.cpp :
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define dw(i,s,e,d) for(int i=(s);i>(e);i-=(d))
#define in(x) cin>>(x)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

void p1(vi v){
  for(auto a: v){ot(a);ot(",");}
}
void p2(vvi &x){
  for(auto v: x){ot("[");p1(v);ot("]\n");}
}

int main(){
  int n;in(n);
  // ote(n);
  int c = 0;
  up(i,1,n+1,1){
    // ote((int)log10(i));
    if((int)log10(i)%2==0){
      c++;
    }
  }
  ote(c);

}

Measured memory_bytes: 512
def insertion_sort(A, N, exchange_cnt):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
            exchange_cnt += 1
        A[j + 1] = v
    return A, exchange_cnt

def shell_sort(A, N, G):
    exchange_cnt = 0
    for g in G:
        for i in range(g):
            A[i::g], exchange_cnt = insertion_sort(A[i::g], len(A[i::g]), exchange_cnt)
    return A, exchange_cnt
    

def determine_G(N):
    G = [1]
    for i in range(N):
        G.append(G[i]*3 + 1)
        if G[-1] >= N:
            del G[-1]
            break
    return G[::-1]

N = int(input().rstrip())

A = []
for n in range(N):
    A.append(int(input().rstrip()))

G = determine_G(N)

    
result = shell_sort(A, N, G)
print(len(G))
print(" ".join([str(g) for g in G]))
print(result[1])
for num in result[0]:
    print(num)


Measured memory_bytes: 60796
#include <bits/stdc++.h>
using namespace std;
template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
	~debug(){cerr<<endl;}
	template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
	template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
	template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
	template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
	template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;


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

    string s = "$", t;
    cin >> t;
    s += t;
    int n = s.length()-1;
    bool ok = s[1] == '1' && s[n] == '0';
    for(int i = 1; i <= n; i++) {
        if(s[i] == '1' && s[n-i] == '0') {
            ok = false;
        }
    }
    
    if(!ok) {
        cout << "-1\n";
        exit(0);
    }
    
    vector<pair<int,int>> edges;
    vector<int> ones;
    for(int i = 1; i <= n; i++) {
        if(s[i] == '1') {
            ones.push_back(i);
        }
    }
    
    int cnt = ones.size(), cur = 1;
    for(int i = 0; i < cnt; i++) {
        edges.emplace_back(cur, cur+1);
        cur++;
    }
    
    for(int i = 0; i < (int) ones.size() - 1; i++) {
        int dif = ones[i+1]-ones[i]-1;
        while(dif--) {
            edges.emplace_back(i+2, ++cur);
        }
    }
    debug() nav(edges);
    assert((int) edges.size() == n-1);
    for(pair<int,int> e : edges) {
        cout << e.first << ' ' << e.second << '\n';
    }
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<int> a(m);
    vector<int> b(m);
    vector<int> x(n);
    rep(i,n) cin >> h[i];
    rep(i,m) cin >> a[i] >> b[i];
    rep(i,m){
        if(h[a[i]-1]>h[b[i]-1]){
            ++x[b[i]-1];
        }else if(h[a[i]-1]<h[b[i]-1]){
            ++x[a[i]-1];
        }else{
            ++x[a[i]-1];
            ++x[b[i]-1];
        }
    }
    int counter=0;
    rep(i,n){
        if(x[i]==0){
            ++counter;
        }
    }
    cout << counter << "\n";
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
    while(cin>>m>>n>>o>>p)

    {
        if(m>n)
            m=n;
        if(p>o)
            p=o;
        cout<<m+p<<endl;
    }
    return 0;
}

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

int main(int argc, char **argv)
{
	ll n, m; cin >> n >> m;
	
	multimap<ll, string> map;
	for (int i = 0; i < m; ++i)
	{
		ll num;
		string str;
		cin >> num >> str;
		map.insert(std::make_pair(num, str));
	}

	ll ac{0}, wa{0};
	for (ll i = 1; i <= n; ++i)
	{
		auto p = map.equal_range(i);

		ll wa_{0};
		for (auto it = p.first; it != p.second; ++it)
		{
			if (it->second == "AC")
			{
				++ac;
				wa += wa_;
				break;
			}
			else
				++wa_;
		}
	}
	std::cout << ac << " " << wa << std::endl;
}


Measured memory_bytes: 11136
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  i64 A, B, C, K;

  cin >> A >> B >> C >> K;

  i64 r = 0;
  i64 a = min(A, K);

  r += 1 * a;

  K -= a;

  if (K > 0) {
    i64 b = min(B, K);

    K -= b;

    if (K > 0) {
      i64 c = min(C, K);

      K -= c;
      r -= 1 * c;
    }
  }

  cout << r;
}
#endif


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b){
	return -*(int *)a+*(int *)b;
}
int main(void){
	int a[5];
	for(int i=0; i<5; ++i){
		a[i] = 0;
		scanf("%d", a+i);
	}
	qsort(a, 5, sizeof(int), cmp);
	printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4]);
	getchar();getchar();
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
    int N,i,M,m,a[1000];
    M=0,m=1000;
    
    scanf("%d",&N);
    
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    
    for(i=0;i<N;i++)
    {
        if(a[i]>=M)
        {
            M=a[i];
        }
    }
    
    for(i=0;i<N;i++)
    {
        if(a[i]<=m)
        {
            m=a[i];
        }
    }
    
    printf("%d\n",M-m);
    
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}


vector<int> frac;
void init_frac(int N) {
   frac.push_back(1);
   for (int i = 1; i <= N; i++) {
      frac.push_back(mod(frac[i-1] * i));
   }
}
int powM(int x, int n) {
   int res = 1;
   while (n > 0) {
      if ((n & 1) == 1) {
         res = mod(res * x);
      }
      x = mod(x * x);
      n >>= 1;
   }
   return res;
}
int inverseM(int x) {
   return powM(x, MOD-2);
}
int comb(int n, int r) {
   if (n < 0 || n-r < 0 || r < 0) {
      return 0;
   }
   return mod(frac[n] * inverseM(mod(frac[n-r]*frac[r])));
}

vector<bool> isprime;
void init_isprime(int N)
{
   isprime = vector<bool>(N+1, true);
   isprime[0] = isprime[1] = false;
   for(int i = 2; i <= N; i++) {
      if (isprime[i]) {
         for (int j = 2; i*j <= N; j++) {
            isprime[i*j] = false;
         }
      }
   }
}

void factorize(map<int,int>& fact_n, int M)
{
   int tmpM = M;
   for(int i = 2; i < isprime.size(); i++) {
      if (!isprime[i]) continue;
      while (tmpM % i == 0) {
         fact_n[i]++;
         tmpM /= i;
      }
   }
   if (tmpM != 1) fact_n[tmpM]++;
}

signed main()
{
   int N, M; cin >> N >> M;

   init_isprime((int)pow(M,0.5));
   dump(isprime)

   map<int,int> fact_n;
   factorize(fact_n, M);
   dump(fact_n)

   init_frac(N + 50);
   int ans = 1;
   EACH(i, fact_n) {
      ans = mod(ans * comb(N-1 + i->second, i->second));
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
// #define multicase
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e2 + 5;

int n;
int a[N];

void solve() {
    int T = 1;
  #ifdef multicase
    cin >> T;
  #endif
    for(int tc = 1; tc <= T; tc++) {
        cin >> n;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        sort(a + 1, a + n + 1);
        int ans = INF;
        for(int i = a[1]; i <= a[n]; i++) {
            int tot = 0;
            for(int j = 1; j <= n; j++) {
                int temp = a[j] - i;
                tot += temp * temp;
            }
            ans = min(ans, tot);
        }
        cout << ans << "\n";
    }
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    solve();
    
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int rect=0,dia=0;
  int a[3]{};
  while(scanf("%d,%d,%d",&a[0],&a[1],&a[2])>0){
    if(a[0]==a[1]) dia++;
    if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2]) rect++;
  }
  printf("%d\n%d\n",rect,dia);
}

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



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

    int a,b;
    cin>>a>>b;
    int ans = 1+2+3;
    ans -= a+b;
    cout << ans << endl;
}

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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 1001001001;
  rep(i, x+1) {
    int res = a*i + b* max(y-x+i,0) + 2*c*(x-i);
    ans = min(res, ans);
  }
  rep(i, y+1) {
    int res = b*i + a* max(x-y+i,0) + 2*c*(y-i);
    ans = min(res, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;

const int N = 1e2;
int a[2][N+2];
int f[2][N+2];
int n;

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[0][i]);
	for(int i=1; i<=n; i++) scanf("%d",&a[1][i]);
	f[0][1] = a[0][1]; f[1][1] = a[0][1]+a[1][1];
	for(int i=2; i<=n; i++)
	{
		f[0][i] = f[0][i-1]+a[0][i];
		f[1][i] = max(f[0][i],f[1][i-1])+a[1][i];
	}
	printf("%d\n",f[1][n]);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
 
int cnt=0;
void shellSort(int NUM[],int num){
  int i;
  int m_count=0;
  int recursion[1000];
   
  m_count=formula(num,recursion);
  
  printf("%d\n",m_count);
  for(i=0;i<m_count;i++){
    if(i!=0) printf(" ");
    printf("%d",recursion[i]);
  }
  printf("\n");
  for(i=0;i<m_count;i++){
    insertionSort(NUM,num,recursion[i]);
  }
}
void insertionSort(int NUM[],int num,int recursion){
  int i,j;
  int mask;
 
  for(i=recursion;i<num;i++){
    mask=NUM[i];
    j=i-recursion;
    while(j>=0&&NUM[j]>mask){
      NUM[j+recursion]=NUM[j];
      j=j-recursion;
      cnt++;
    }
    NUM[j+recursion]=mask;
  }
}
int formula(int num,int array[]){
  int i,j;
  int count=1;
  int mask[1000];
   
  mask[0]=1;
 
  while(1){
    mask[i+1]=3*mask[i]+1;
    if(mask[i+1]>num)break;
    count++;
    i++;
  }
  
  j=count-1;
  
  for(i=0;i<count;i++){
    array[j]=mask[i];
    j--;
  }
  return count;
}
int main(){
  int i;
  int num;
  int array[1000000];
  
  scanf("%d",&num);
  
  for(i=0;i<num;i++){
    scanf("%d",&array[i]);
  } 
 
  shellSort(array,num);
  printf("%d\n",cnt);
  for(i=0;i<num;i++){
    printf("%d\n",array[i]);
  } 
  return 0;
}

Measured memory_bytes: 4516
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(100020, -1);
    for(ll i = 0; i < n; i++){
        ll b;
        cin >> b;
        a[b]++;
    }
    vector<ll> c;
    ll ans = 0;
    ll count = 0;
    for(ll i = 1; i <= 100000; i++){
        if(a[i]>=0) ans++;
        if(a[i]>=1 && a[i]%2!=0) count++;
    }
    //cout << count << endl;
    if(count%2==0) cout << ans << endl;
    else cout << ans-1 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	long a,b;
	int k;
	scanf("%ld%ld%d",&a,&b,&k);
	int i=0;
	while(i<k){
		if(i%2==0){
			if(a%2==1)a--;
			a=a/2;
			b+=a;
		}
		else{
			if(b%2==1)b--;
			b=b/2;
			a+=b;
		}
		i++;
	}
	printf("%ld %ld\n",a,b);
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto V=vecin(N);
	sort(ALL(V));
	V.erase(unique(ALL(V)),V.end());

	out(V.size());
	return 0;
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))
d.sort()
ans = min(d)
for i in range(n):
    if i % 2 == 0:
        d[i] = 24 - d[i]

for i in range(n):
    for j in range(n):
        if i != j:
            ans = min(ans, abs(d[i]-d[j]))

print(ans)


Measured memory_bytes: 38896
#include <iostream>

using namespace std;

void printArr(int *arr,int n) {
	for (int i=0;i<n;i++) {
		if (i) {
			cout << " ";
		}
		cout << arr[i];
	}
	cout << endl;
}
void insertionSort(int *arr,int n) {
	printArr(arr,n);
	for (int i=1;i<n;i++) {
		int key = arr[i];
		int j = i-1;
		while (j >= 0 && arr[j] > key) {
			arr[j+1] = arr[j];
			j--;
		}
		arr[j+1] = key;
		printArr(arr,n);
	}
}

int main() {
	int n;
	cin >> n;
	int *arr = new int[n];
	for (int i=0;i<n;i++) {
		cin >> arr[i];
	}
	insertionSort(arr,n);
	delete[] arr;
	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double d;
typedef vector<ll> v;
typedef pair<ll,ll> p;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	ll a;
	cin>>a;

	ll x=a+pow(a,2)+pow(a,3);
	cout<<x<<"\n";
}

Measured memory_bytes: 3916