akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn prime_factors(n: u64) -> HashMap<u64, u64> {
    let limit = n;
    let mut n = n; 
    let mut prime_numbers: HashMap<u64, u64> = HashMap::new();
    let mut candidate = 2;
    while n > 1 {
        if candidate * candidate > limit {
            prime_numbers.insert(n, 1);
            return prime_numbers;
        }
        while n % candidate == 0 {
            let val = prime_numbers.entry(candidate).or_insert(0);
            *val += 1;
            n /= candidate;
        }
        candidate += 1;
    }
    return prime_numbers;
}

struct CombinationCalculator {
    f: Vec<u64>,
    finv: Vec<u64>,
}

impl CombinationCalculator {
    fn new(n: usize) -> CombinationCalculator {
        let mut f = vec![1u64; n];
        let mut inv = vec![1u64; n];
        let mut finv = vec![1u64; n];
        for i in 2..n {
            f[i] = f[i - 1] * i as u64 % MOD;
            inv[i] = MOD - inv[MOD as usize % i] * (MOD / i as u64) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
        CombinationCalculator {f: f, finv: finv}
    }

    fn calc(&self, n: u64, m: u64) -> u64 {
        if n < m {
            return 0;
        } 
        self.f[n as usize] * (self.finv[m as usize] * self.finv[(n - m) as usize] % MOD) % MOD
    }
}

fn main() {
    let (n, m) = input_tuple();
    let factor_map = prime_factors(m);
    let combination_calculator: CombinationCalculator = CombinationCalculator::new(n as usize + 30);
    let mut sum = 1;
    for v in factor_map.values() {
        sum *= combination_calculator.calc(v + n - 1, *v);
        sum %= MOD;
    }
    println!("{}", sum);
}


Measured memory_bytes: 4440
import numpy

def solve(string):
    n, *p = map(int, string.split())
    p = numpy.asarray(p)
    asc=(p[:-2]<p[1:-1]) & (p[1:-1]<p[2:])
    desc=(p[:-2]>p[1:-1]) & (p[1:-1]>p[2:])
    return str(sum(asc | desc))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 12492
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAXBC solver = new CAXBC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CAXBC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int ans = 0;
            for (int a = 1; a < n; a++) {
                for (int b = 1; b < n; b++) {
                    int c = n - a * b;
                    if (c <= 0) break;
                    ans++;
                }
            }
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35780
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'

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

  int a, b; cin >> a >> b;
  cout << a * b << " " << 2 * a + 2 * b << '\n';

  return 0;
}


Measured memory_bytes: 3124
#include<iostream>
using namespace std;
int have[4],sum;
int coin[4]={10,50,100,500};

int main(){
  bool first=true;
  while(cin>>sum,sum){

    if(first!=true)cout << endl;
    first=false;

    int price=0;
    for(int i=0;i<4;i++) cin>>have[i];

    for(int i=0;i<4;i++)price+=have[i]*coin[i];
    price-=sum;

    for(int i=3;i>=0;i--){
      while(price>=coin[i]){
	price-=coin[i];
	have[i]--;
      }
    }

    for(int i=0;i<4;i++){
      if(have[i]>0)
	cout <<  coin[i] << " " << have[i]<< endl; 
    }

  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

priority_queue<P > pq;

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

    int N;
    std::cin >> N;

    for(int i=0;i<N;++i){
        int a;
        std::cin >> a;

        pq.emplace(a, i);
    }

    int p[2] = {0, 0}, cur = 0;
    while(!pq.empty()){
        p[cur] += fst(pq.top());
        pq.pop();
        cur = !cur;
    }

    std::cout << (p[0] - p[1]) << std::endl;
}


Measured memory_bytes: 256
N = int(input())
def n_ary(l,d): # リストl中の文字でd桁までを全列挙(sorted)
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i for i in n_ary(['3','5','7'],9)] # 制約が10**9なので9
print(len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)]))

Measured memory_bytes: 6060
import numpy as np

N = int(input())
A = list(map(int,input().split()))
sumA = [max(A[0],1)]
ans1 = abs(sumA[0]-A[0])
for i in range(1,N):
    sumA.append(sumA[-1]+A[i])
    if np.sign(sumA[-2]) == np.sign(sumA[-1]) or np.sign(sumA[-1]) == 0:
        ans1 += abs(sumA[-1] + np.sign(sumA[-2]))
        sumA[-1] = -np.sign(sumA[-2])
sumA = [min(A[0],-1)]
ans2 = abs(sumA[0]-A[0])
for i in range(1,N):
    sumA.append(sumA[-1]+A[i])
    if np.sign(sumA[-2]) == np.sign(sumA[-1]) or np.sign(sumA[-1]) == 0:
        ans2 += abs(sumA[-1] + np.sign(sumA[-2]))
        sumA[-1] = -np.sign(sumA[-2])
print(min(ans1,ans2))


Measured memory_bytes: 23224
#include<iostream>
#include<bitset>
using namespace std;
const int N=4e6+10;
bitset<N>s;
int n;
int main()
{
	cin>>n;
	int x,res=0;
	s[0]=1;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		res+=x;
		s|=s<<x;
	}
	for(int i=(res+1)/2;;i++)
	if(s[i])
	{
		printf("%d\n",i);
		break;
	}
} 

Measured memory_bytes: 4208
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	A := make([]int, n)
	for i := range A {
		A[i] = nextInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	Q := []int{A[0]}
	ans := 0
	for i := 1; i < n; i++ {
		q := Q[0]
		ans += q
		if q == A[i] {
			Q = append(Q, A[i])
		} else {
			Q = Q[1:]
			Q = append(Q, A[i])
			Q = append(Q, A[i])
		}
	}
	fmt.Println(ans)
}


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


int main(void) {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  rep(i, M) {
    cin >> A[i];
  }

  // 0へ向かう
  int to0 = 0;
  int toN = 0;
  rep(i, M) {
    if (A[i] < X) {
      to0++;
    } else {
      toN++;
    }
  }

  cout << min(to0, toN) << endl;
  
  return 0;
}

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

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

	int n,k;
	cin>>n>>k;
	vector<int> cnt(n,0);
	for(int i=0; i<k; ++i){
		int d; cin>>d;
		for(int j=0; j<d; ++j){
			int x; cin>>x; x--; cnt[x]++;
		}
	}
	int ans = 0;
	for(int i=0; i<n; ++i){ if(cnt[i] == 0 ){ ans++;} }
	cout<<ans<<'\n';
	return 0;
}


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

void trace(int A[], int N) {
    cout << A[0];
    for (int i=1; i < N; i++) {
        cout << " " << A[i];
    }
    cout << endl;
}

void selectionSort(int A[], int N) {
    int cnt = 0;
    int minj;
    for (int i=0; i < N-1; i++) {
        minj = i;
        for (int j=i; j < N; j++) {
            if (A[j] < A[minj]) minj = j;
        }
        if (i != minj) {
            swap(A[i], A[minj]);
            cnt++;
        }
    }

    trace(A, N);
    cout << cnt << endl;
    return;
}


int main(){
    int n;
    int A[110];

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


Measured memory_bytes: 3080
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int nmax = 1e5 + 10;
int n, m; 
int p[nmax];
int lab[nmax];
int getroot(int x) {
    while (lab[x] > 0) x = lab[x];
    return x;
}
void Union(int u, int v) {
    int r1 = getroot(u);
    int r2 = getroot(v);
    if (r1 != r2) {
        int tmp = lab[r1] + lab[r2];
        if (lab[r1] > lab[r2]) {
            lab[r1] = r2;
            lab[r2] = tmp;
        }
        else {
            lab[r2] = r1;
            lab[r1] = tmp;
        }
    }
}
int main() {
    IO;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) lab[i] = -1;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        Union(u, v);
    }
    int res = 0;
    for (int i = 1; i <= n; i++) 
        if (getroot(i) == getroot(p[i])) res++;
    cout << res;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
nu = [int(x) for x in input().split()]
r2 = [None] * N
 
for i in range(len(nu)):
  r2[nu[i] - 1] = i
#for i in nu:
#  r2[i] = nu.index(i)
ans = ""
for i in range(len(r2)):
  ans += str(r2[i] + 1) + " "
print(ans)
#print(" ".join([str(x + 1) for x in r2]))

Measured memory_bytes: 13880
#include <iostream>

using namespace std;

int main() {
    long long a, b, c;
    cin >> a >> b >> c;
    if (c - a - b <= 0) {
        cout << "No" << endl;
    } else if (4 * a * b < (c - a - b) * (c - a - b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    int N;
    cin >> N;
    std::map<std::string,long> list;
    
    for(int i =0; i < N; i++){
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        list[str] += 1;
    }
    long sum = 0;

    for( auto i = list.begin(); i != list.end() ; ++i ) {
        sum += (((long)i->second - 1) * (long)i->second) / 2;
    }
    cout << sum << endl;
}

Measured memory_bytes: 11428
#include<stdio.h>
int main(){
    int i;
    int x;
    int a[10000];
    int cnt=0;
    for(i=0;i<10000;i++){
        scanf("%d",&a[i]);
        if(a[i]==0)break;
        cnt++;
    }
    for(i=0;i<cnt;i++){
        printf("Case %d: %d\n",i+1,a[i]);
    }
    return 0;
}


Measured memory_bytes: 2628
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
ll go(ll h, ll w){
	ll y,z,a,b,c,res=100000000;
	for(ll i=1 ; i<h ; i++){
		a = i*w;
		b = floor((h-i)/2.0)*w;
		c = ceil((h-i)/2.0)*w;
		y = max({a,b,c});
		z = min({a,b,c�});
		res = min(res,y-z);
		b = floor(w/2.0)*(h-i);
		c = ceil(w/2.0)*(h-i);
		y = max({a,b,c});
		z = min({a,b,c});
		res = min(res,y-z);
		}
	return res;
	}
int main()
{
	ll h,w,ans;
	cin>>h>>w;
	if(h%3==0 || w%3==0) ans=0;
	else{
		ans = min(go(h,w),go(w,h));
		}
	
	cout<<ans<<nw;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int main() {
	string p;
	string r;
	cin >> p;
	cin >> r;
	int c = 0;
	for (int i = 0; i < 3; ++i) {
		if (p[i] == r[i])++c;
	}
	PRI(c);
	return 0;
}

Measured memory_bytes: 3500
use std::cmp;
use std::cmp::max;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let b: Vec<usize> = sc.vec(n);

    let mut ans = 0;
    for i in 1..30 {
        let mask = (1 << i) - 1;
        let mut b: Vec<_> = b.iter().map(|&b| b & mask).collect();
        b.sort();

        let t1 = (mask + 1) / 2;
        let t2 = mask + 1;
        let t3 = t1 + t2;

        let mut count = 0;
        for &a in a.iter() {
            let a = a & mask;
            let i1 = b
                .binary_search_by_key(&(t1 * 2), |&b| (a + b) * 2 + 1)
                .err()
                .unwrap();
            let i2 = b
                .binary_search_by_key(&(t2 * 2), |&b| (a + b) * 2 + 1)
                .err()
                .unwrap();
            let i3 = b
                .binary_search_by_key(&(t3 * 2), |&b| (a + b) * 2 + 1)
                .err()
                .unwrap();
            count += n - i3 + i2 - i1;
        }
        let t = count & 1;
        ans |= t << (i - 1);
    }
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 13364
#include<stdio.h>
#include<math.h>
int main(){

  double x1,x2,y1,y2,ans;

  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

  ans=(x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);

  printf("%lf\n",sqrt(ans));


  return 0;
}


 

Measured memory_bytes: 1084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
	static long[] ary;
	static int N;
	static int min,max;
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		/*二分探索でいけそう
		 * でかいやつが小さいものから食っていく。
		 *
		 *そのでかいやつが何番目までならOKか？
		 *
		 */
		N=sc.nextInt();
		ary=new long[N];
		for(int i=0; i<N; i++) {
			ary[i]=sc.nextLong();
		}
		Arrays.sort(ary);
		min=0;
		max=N-1;
		while(max-min>1) {
			int mid=(max+min)/2;
			if(bs(mid)) {
				max=mid;
			}
			else {
				min=mid;
			}
		}
		boolean mmn=bs(min);
		boolean mmx=bs(max);

		if(mmn && mmx) {
			pl(Math.max(N-min,0));
		}
		else if(!mmn && mmx) {
			pl(Math.max(N-max,0));
		}
		else if(!mmn && !mmx) {
			pl(Math.max(N-1-max,0));
		}
	}
	public static boolean bs(int index) {
		long tmp=ary[index];
		for(int i=0; i<index; i++) {
			if(ary[i]<=tmp*2) {
				tmp+=ary[i];
			}
			else {
				return false;
			}
		}
		for(int i=Math.min(index+1,N-1); i<N; i++) {
			if(ary[i]<=tmp*2) {
				tmp+=ary[i];
			}
			else {
				return false;
			}
		}
		return true;
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


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


int main(){
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    int now = n;
    vector<int> ans;
    while (now > 0){
        bool found = false;
        for(int i=min(now, m); i>0; i--){
            if (s[now-i] == '0'){
                // cout << now << " " << i << " " << s[now-i] << endl;
                ans.push_back(i);
                now -= i;
                found = true;
                break;
            }
        }
        if(!found){
            cout << -1 << endl;
            return 0;
        }
    }

    for(int i=0; i<ans.size(); i++){
        cout << ans[ans.size() - i - 1];
        if(i != ans.size()-1) cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1144
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] check = new String[N];
		for(int i = 1; i<=N;i++) {
			check[i-1] = sc.next() + " " + (1100-sc.nextInt()) + " " + i;
		}
		Arrays.sort(check);
		for(String st : check) {
			String s = st.split(" ")[2];
			System.out.println(s);
		}
	}
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long k, a[5];
	cin >> k;
	for (int i = 0; i < 5; i++){
		cin >> a[i];
	}
	cout << (k - 1) / *(min_element(a, a + 5)) + 5;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>


using namespace std;

int main(){
    string str;
    cin >> str;
    int count = 0;
    int first, last;
    bool flag = false;
    for(int i = 0; i < str.size(); i++){
        if(str[i] == 'A'){
            first = i;
            break;
        }
    }
    for(int i = 0; i < str.size(); i++){
        if(str[i] == 'Z') last = i;
    }
    cout << last - first + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const double PI = 3.14159265358979323846264338327950;
const LL MOD = 1000000007;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int A[100000] = {1};
int B[100000] = {0};
int main(void)
{
	int N, M;
	cin >> N >> M;
	Rep(i, M){
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		B[x]--;
		B[y]++;
		if(A[x]){
			A[y] = 1;
		}
		if(B[x] < 0) A[x] = 0;
	}
	int ans = 0;
	Rep(i, N){
		if(B[i] >= 0){
			ans += A[i];
		}
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N, M) for (int i = N; i < M; i++)
#define pb push_back



typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef priority_queue<pll, vector<pll>, greater<pll>> greater_pq;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>

int main() {
	ll N;
	cin >> N;
	vector<pll> L(N), R(N);
	rep(i, N) {
		cin >> L.at(i).first >> R.at(i).first;
		L.at(i).second = i;
		R.at(i).second = i;
	}

	sort(all(L));
	sort(all(R), greater<pll>());
	auto L_2 = L;
	auto R_2 = R;
	ll x = 0;
	ll res=0;
	//case r
	rep(i, N) {
		if (i % 2 == 0) {
			res += max(L.back().first - x, 0LL);
			x += max(L.back().first - x, 0LL);
			L.pop_back();
		}
		else {
			res += max(x-R.back().first , 0LL);
			x -= max(x-R.back().first, 0LL);
			R.pop_back();
		}
	}
	res += abs(x);
	//case l
	x = 0;
	ll res_2 = 0;
	L = L_2;
	R = R_2;
	rep(i, N) {
		if (i % 2 ==1) {
			res_2 += max(L.back().first - x, 0LL);
			x += max(L.back().first - x, 0LL);
			L.pop_back();
		}
		else {
			res_2 += max(x - R.back().first, 0LL);
			x -= max(x - R.back().first, 0LL);
			R.pop_back();
		}
	}
	res_2 += abs(x);
	
	cout << max(res, res_2)<<endl;
	return 0;
}



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

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

ans = len(divisor(n-1))-1
for i in divisor(n):
    if i == 1: continue
    n_ = n
    while n_ % i == 0:
         n_ //= i
    if n_ % i == 1:
        ans += 1
        
print(ans)

Measured memory_bytes: 3188
#include <iostream>

 using namespace std;

 int main()
{
   int a ,b, temp, i;
   
   for(i=1; i<=3000; i++)
   {
   
       cin >> a >> b;
       if(a==0 && b==0)break;
       if(a > b)
       {
           temp = a;
           a = b;
           b = temp;
       }
       cout << a << " " << b << endl;
   }                                                                                        
}                                                                                                                                                                                                  


Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long A, long long B, long long T){
    cout << (B * (T/A)) << endl;
}

int main(){

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



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

using namespace std;
using ll =long long;
using db = double;

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; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
int main()
{
	cout << setprecision(10);
	ll n ,k ;
	cin >> n >> k;
	vector<ll> h(n);
	rep(i,n) cin >>h[i];

	vector<ll> dp(101000,INF);

	dp[0]=0;
	for(int i = 0; i < n; i ++){
		for(int j = 1; j <= k ; j++){
			chmin(dp[i+j], dp[i] + abs( h[i] - h[i+j]));
		}
	}
	cout << dp[n-1] << endl;
}


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

long long N;

bool check(long long n, long long k) {
	if(n == 1) {
		return true;
	}
	if(n<k) {
		return false;
	}
	if(n%k == 0) {
		return check(n/k, k);
	} else {
		if(n%k == 1) {
			return true;
		}
		return false;
	}
}

int main(){
	cin >> N;

	long long ans = 0;
	for(long long i = 2; i * i <= N; i++) {
		if(N%i == 0) {
			if(check(N, i)) {
				ans++;
			}
			if(i != N/i && check(N, N/i)){
				ans++;
			}
		}
	}

	//K = N
	ans++;


	N--;
	for(long long i = 2; i * i <= N; i++) {
		if(N%i == 0) {
			if(check(N+1, i)) {
				ans++;
			}
			if(i != N/i && check(N+1, N/i)){
				ans++;
			}
		}
	}
	//K = N - 1
	if(N!=1){
	ans++;
	}

	cout << ans << endl;


}


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

#define SIZE 100001

enum TYPE{root, node, leaf, null};
char* strtype[] = {"root", "internal node", "leaf"};

typedef struct Vec{
	int lenght;
	int size;
	int maxsize;
	int* buff;
}VEC;

typedef struct VecIt{
	int i;
	VEC* vp;
}VECIT;

struct TREE{
	int parent;
    int depth;
	int type;
	VEC* vp;
};

struct TREE tree[SIZE];
int treeroot;

VEC* newVec(void)
{
	VEC* vp = (VEC*)malloc(sizeof(VEC));
	vp->lenght = 0;
	vp->size = 10;
	vp->maxsize = SIZE;
	vp->buff = (int*)calloc(vp->size, sizeof(int));
	return(vp);
}

void delVec(VEC* vp)
{
	free(vp->buff);
	free(vp);
	return;
}

void resizeVec(VEC* vp)
{
	vp->size += vp->size;
	vp->buff = (int*)realloc(vp->buff, vp->size*sizeof(int));
	return;
}

void addVec(VEC* vp, int n)
{
	if(vp->size <= vp->lenght){
		resizeVec(vp);
	}
	vp->buff[vp->lenght] = n;
	vp->lenght++;
	return;
}

int getVec(VEC* vp, int n)
{
	if(n < vp->lenght){
		return(vp->buff[n]);
	}
	return(-1);
}

int lenghtVec(VEC* vp)
{
	return(vp->lenght);
}

VECIT* newVecIt(VEC* vp)
{
	VECIT* vpit = (VECIT*)malloc(sizeof(VECIT));
	vpit->vp = vp;
	vpit->i = 0;
	return(vpit);
}

void delVecIt(VECIT* vp)
{
	free(vp);
	return;
}

int nextVecIt(VECIT* vp)
{
	return(getVec(vp->vp, vp->i++));
}

void init(void)
{
	int i;
	for(i = 0; i < SIZE; i++){
		tree[i].parent = -1;
		tree[i].depth = 0;
		tree[i].type = null;
		tree[i].vp = newVec();
	}
	return;
}

void end(void)
{
	int i;
	for(i = 0; i < SIZE; i++){
		delVec(tree[i].vp);
	}
	return;
}

void tr(int node, int lv)
{
	int n;
	VECIT* it = newVecIt(tree[node].vp);
	while((n = nextVecIt(it)) != -1){
		tr(n, lv + 1);
	}
	tree[node].depth = lv;
	return;
}

int main(int argc, char* argv[])
{
	int i, j, k, n, c, id, itn;
	VECIT* it;

	init();

	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &id);
		scanf("%d", &k);
		for(j = 0; j < k; j++){
			scanf("%d", &c);
			if(tree[c].type == null){
			  tree[c].type = leaf;
			}
			tree[c].parent = id;
			addVec(tree[id].vp, c);
		}
		if(0 < lenghtVec(tree[id].vp)){
			tree[id].type = node;
		}else{
			tree[id].type = leaf;
		}
	}

	for(i = 0; i < n; i++){
		if(tree[i].parent == -1){
			treeroot = i;
			break;
		}
	}
	tree[treeroot].type = root;
	tr(treeroot, 0);

	for(i = 0; i < n; i++){
		printf("node %d: parent = %d, depth = %d, ", i, tree[i].parent, tree[i].depth);
		printf("%s, [", strtype[tree[i].type]);
		it = newVecIt(tree[i].vp);
		itn = lenghtVec(tree[i].vp);
		for(j = 0; j < itn-1; j++){
			printf("%d, ", nextVecIt(it));
		}
		if(itn == 0){
			printf("]\n");
		}else{
		    printf("%d]\n", nextVecIt(it));
		}
		
		delVecIt(it);
	}
	
	end();

	return(0);
}

Measured memory_bytes: 14024
#include "bits/stdc++.h"
using namespace std;

#define ll long long 
ll n, ans;
vector<ll> v;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	for(ll i=1;i<=sqrt(10000000000);i++){
		v.push_back(i * i);
	}
	cin>>n;
	for(ll i=0;i<v.size();i++){
		if(v[i] > n)
			break;
		ans = v[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1400
while True:
    n,x=map(int,input().split())
    if n==0:break
    cnt=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    cnt+=1
                    break
    print(cnt)


Measured memory_bytes: 5592
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const ll INF = INT64_MAX/10;

struct edge{
    int to;
    ll cost1, cost2;
    edge(int x=0, ll y=0LL, ll z=0LL):to(x), cost1(y), cost2(z) {}
};

vector<vector<edge> > G;

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s;
    --t;
    G.resize(n);
    rep(i, m) {
        int a, b;
        ll c, d;
        cin >> a >> b >> c >> d;
        a--;
        b--;
        G[a].push_back(edge(b, c, d));
        G[b].push_back(edge(a, c, d));
    }

    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > q;
    q.push(make_pair(0LL, s));
    vector<ll> d(n, INF);
    d[s] = 0LL;
    vector<ll> ans(n);
    while(!q.empty()) {
        auto now = q.top();
        q.pop();

        if(d[now.second] != now.first) continue;
        for(auto next:G[now.second]) {
            if(d[next.to] > now.first+next.cost1) {
                d[next.to] = now.first+next.cost1;
                q.push(make_pair(d[next.to], next.to));
            }
        }
    }
    vector<ll> d2(n, INF);
    d2[t] = 0;
    q.push(make_pair(0LL, t));
    while(!q.empty()) {
        auto now = q.top();
        q.pop();

        if(d2[now.second] != now.first) continue;
        for(auto next:G[now.second]) {
            if(d2[next.to] > now.first+next.cost2) {
                d2[next.to] = now.first+next.cost2;
                q.push(make_pair(d2[next.to], next.to));
            }
        }
    }
    ll mm = 1e15;

    rep(i, n) {
        ans[i] = d[i] + d2[i];
    }
    rep(i, n-1){ 
        if(ans[n-1-i] < ans[n-2-i]) {
            ans[n-2-i] = ans[n-1-i];
        }
    }

    rep(i, n) {
        cout << mm-ans[i] << endl;
    }
}

Measured memory_bytes: 13944
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int h, a;
	cin >> h >> a;

	int ans = (h + a - 1) / a;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;
ll ans=0;
vector<int> G[MAX];
ll rui[MAX],revrui[MAX];

map<ll,int> MA;

ll DFS(int u,int p,int d){
    
    ll ha=rui[d];
    
    for(int to:G[u]){
        if(to==p) continue;
        
        ha+=DFS(to,u,d+1);
        ha%=mod;
    }
    
    ha*=revrui[d];
    ha%=mod;
    
    if(MA.count(ha)) ans+=MA[ha];
    MA[ha]++;
    
    ha*=rui[d];
    ha%=mod;
    
    return ha;
}

ll ru(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    rui[0]=1;
    revrui[0]=1;
    
    for(int i=1;i<MAX;i++){
        rui[i]=rui[i-1]*100003;
        rui[i]%=mod;
        
        revrui[i]=ru(rui[i],mod-2);
    }
    
    DFS(0,-1,0);
    
    cout<<ans<<endl;
    
}



Measured memory_bytes: 27404
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const double PI = 3.14159265358979323846;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};



int main(){
  int N,M;
  cin >> N >> M;
  map<int,vector<int>> v;
  for(int i=0; i<N; i++){
    int a,b;
    cin >> a >> b;
    v[a].push_back(b);
  }
  priority_queue<int> que;
  ll sum=0;
  for(int i=1; i<=M; i++){
    for(auto B: v[i]){
      que.push(B);
    }
    if(que.empty()){
      continue;
    }
    sum += que.top();
    que.pop();
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 10880
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,s,f) for(int i=(int)s;i<(int)f;i++)
#define INF 1<<31-1
using ll=long long;
using namespace std;


ll max_v=0;
void dfs(int i,int prev,int N,int M,int Q,vector<int> A,vector<vector<ll>> info)
{
	if(i==N)
	{
		ll val=0;
		rep(k,Q)
		{
			if((A[info[k][1]]-A[info[k][0]])==info[k][2]) val+=info[k][3];
		}	
		max_v=max(val,max_v);
	}
	else
	{
		Rep(k,prev,M+1)
		{
			A[i]=k;
			dfs(i+1,k,N,M,Q,A,info);
		}
	}
}
int main()
{
	int N,M,Q;
	cin>>N>>M>>Q;
	vector<vector<ll>> abcd(Q,vector<ll>(4));
	rep(i,Q)
	{
		cin>>abcd[i][0]>>abcd[i][1]>>abcd[i][2]>>abcd[i][3];
		abcd[i][0]--;
		abcd[i][1]--;
		abcd[i][2];
		abcd[i][3];
	}
	vector<int> A(N,0);
	dfs(0,1,N,M,Q,A,abcd);
	cout<<max_v<<endl;
	return 0;
}


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

string s;

int main(void)
{
     cin >> s;
  
     if (s == "SUN")
         cout << 7;
     else if (s == "MON")
         cout << 6;
     else if (s == "TUE")
         cout << 5;
     else if (s == "WED")
         cout << 4;
     else if (s == "THU")
         cout << 3;
     else if (s == "FRI")
         cout << 2;
     else
         cout << 1;
     return 0;
}

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t,n;
  
    cin>>n;
    int*arr=new int[n];

    std::map<int, int> map;
    for(int i=0;i<n-1;i++)
    {
    	int a;
    	cin>>a;
    	map[a]++;
    }
    int sum=0;
    
    for(int i=1;i<=n;i++)
    {
    	cout<<map[i]<<endl;
    }
    
   
    return 0;
}

Measured memory_bytes: 13040
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int W, H, N;
	cin >> W >> H >> N;
	int top = H, bottom = 0, left = 0, right = W;
	int x, y, a;
	rep(i, N) {
		cin >> x >> y >> a;
		if (a == 1)left = max(left, x);
		else if (a == 2)right = min(right, x);
		else if (a == 3)bottom = max(bottom, y);
		else top = min(top, y);
	}
	if (left > right || top < bottom)cout << 0;
	else cout << (right - left) * (top - bottom);
}

Measured memory_bytes: 256
h = gets.to_i
w = gets.to_i
n = gets.to_i
count_w = 0
count_h = 0
i = 0
cell_count = 0

while i*h < n
  count_h += 1
  i += 1
end

i = 0
while i*w < n
  count_w += 1
  i += 1
end

if count_h > count_w
  count = count_w
else
  count = count_h
end

puts count

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
enum{ROW=0,COLUMN=1};

int getindex(int a,map<int,int> &M){
  int index=M.size();
  if (M.find(a) == M.end())M[a]=index;
  return M[a];
}

main(){
  ll r,c,q;
  while(cin>>r>>c>>q){
    if (r == 0 && c == 0 && q == 0)break;
    map<int,int> M[2];
    vector<pii> in[2];
    for(int i=0;i<q;i++){
      int a,b,order;
      cin>>a>>b>>order;
      int index=getindex(b,M[a]);
      if (index == in[a].size()){
	in[a].push_back(make_pair(order,i));
      }else {
	in[a][index]=make_pair(order,i);
      }
    }
    ll ans=0;
    //!Intersection Point
    for(int k=0;k<2;k++){
      for(int i=0;i<in[k].size();i++){
	if (in[k][i].first == 1){
	  ans+=(k==0?c:r)-in[1-k].size();
	}
      }
    }
    vector<int> queryStand,querySit;
    for(int i=0;i<in[1].size();i++){
      if (in[1][i].first == 1){
	queryStand.push_back(in[1][i].second);
      }else {
	querySit.push_back(in[1][i].second);
      }
    }
    sort(queryStand.begin(),queryStand.end());
    sort(querySit.begin(),querySit.end());
    //Intersection Point
    for(int i=0;i<in[0].size();i++){
      if (in[0][i].first == 1){
	ans+=queryStand.size();
	int num=lower_bound(querySit.begin(),querySit.end(),in[0][i].second)-querySit.begin();
	ans+=num;
      }else if(in[0][i].first == 0) {
	int num=lower_bound(queryStand.begin(),queryStand.end(),in[0][i].second)-queryStand.begin();
	ans+=queryStand.size()-num;
      }
    }
    cout << ans << endl;
    //cout << in[0].size() <<" " << in[1].size() << endl;
  }
  return false;
}

Measured memory_bytes: 2812
from collections import deque
H,W = map(int,input().split())
A = [input().strip() for _ in range(H)]
B = [[0 for _ in range(W)] for _ in range(H)]
que = []
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            que.append((i,j,0))
que = deque(que)
while que:
    y,x,d = que.popleft()
    if x+1<W and A[y][x+1]=="." and B[y][x+1]==0:
        B[y][x+1]=d+1
        que.append((y,x+1,d+1))
    if y-1>=0 and A[y-1][x]=="." and B[y-1][x]==0:
        B[y-1][x]=d+1
        que.append((y-1,x,d+1))
    if x-1>=0 and A[y][x-1]=="." and B[y][x-1]==0:
        B[y][x-1]=d+1
        que.append((y,x-1,d+1))
    if y+1<H and A[y+1][x]=="." and B[y+1][x]==0:
        B[y+1][x]=d+1
        que.append((y+1,x,d+1))
bmax = 0
for i in range(H):
    for j in range(W):
        bmax = max(bmax,B[i][j])
print(bmax)

Measured memory_bytes: 205132
// " In the Name of God, the Beneficent, the Merciful "
#include <bits/stdc++.h>
using namespace std;

const int oo = -INT_MAX;
const int N = 1e5 + 10;
int a[N], n, m, comp[N], c;
bool mark[N];
set <pair <int, int>> s;
vector <int> adj[N];

void input() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s.insert({oo, a[i]}); 
	}
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}				
}

void dfs(int u) {
	mark[u] = true;
	comp[u] = c;
	s.erase({oo, u});
	s.insert({c, u});
	for (auto v: adj[u]) {
		if (!mark[v])
			dfs(v);	
	}
}

void findComp() {
	while (s.begin() -> first == oo) {
		dfs(s.begin() -> second);
		c++;
	}
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
	
	input();
	findComp();
	
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (comp[a[i]] == comp[i + 1])
			cnt++;	
	}
	cout << cnt;
	
	return 0;
}



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

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int n, m;
    cin >> n >> m;

    if (n > m)
        swap(n, m);
    
    if(n == 1)
    {
        if(m == 1)
            cout << 1 << "\n";
        else if(m >= 3)
            cout << m - 2 << "\n";
        
        return 0;
    }

    if(n == 2)
        cout << 0 << "\n";
    else
        cout << 1LL * (n-2) * (m-2) << "\n";

    return 0;
}


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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 505;
int arr[N];
ll sum = 0;
ll ans = 1;
int n, k;

bool can(ll x) {
    ll rem = 0;
    loop(i, n)rem += (arr[i] % x);
    if (rem % x)return false;
    vector<ll> v, acc(n);
    loop(i, n)v.push_back(arr[i] % x);
    sort(ALL(v));
    acc[n - 1] = v[n - 1];
    rloop(i, n - 2)acc[i] = acc[i + 1] + v[i];
    ll sum = 0;
    loop(i, n - 1) {
        sum += v[i];
        if (sum == x * (n - i - 1) - acc[i + 1])return sum <= k;
        if (sum > k)return false;
    }
    return false;
}

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    loop(i, n)cin >> arr[i], sum += arr[i];

    for (ll i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            if (can(i))ans = max(ans, i);
            if (sum / i != i && can(sum / i))ans = max(ans, sum / i);
        }
    }

    cout << ans << endl;

    return 0;
}

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

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int N, K;
    cin >> N >> K;

    int cnt = 0;
    while (N>0)
    {
        ++cnt;
        N /= K;
    }
    cout << cnt << endl;
    return 0;
}


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

A = [int(s) for s in input().split()]

cnt = 0
flag = True
while flag:
    flag = False
    for j in range(n-1, 0, -1):
        if A[j] < A[j-1]:
            A[j-1], A[j] = A[j], A[j-1]
            flag = True
            cnt += 1

print(*A)
print(cnt)


Measured memory_bytes: 5612
H, W = map(int, input().split())
#pading
S = [['P' for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
    s = list(input()) 
    for j in range(W):
        S[i+1][j+1] = s[j]
for i in range(H):
    for j in range(W):
        if S[i+1][j+1]=='.':
            counter = 0
            for k in [i, i+1, i+2]:
                for l in [j, j+1, j+2]:
                    if S[k][l] == '#':
                        counter += 1
            S[i+1][j+1] = str(counter)
for i in range(1,H+1):
    print(''.join(S[i][1:W+1]))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int a,p;
	cin>>a>>p;
	a *= 3;
	cout << (a+p)/2 << endl;

	return 0;
}

Measured memory_bytes: 764
import java.util.*;

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

    }
}

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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int main(){
    int n;
    cin>>n;
    vector<long> v;
    v.push_back(2);
    v.push_back(1);
    for(int i=2;i<=n;i++){
        v.push_back(v[i-1]+v[i-2]);
    }
    cout << v[n] << endl;
    return 0;
}



Measured memory_bytes: 256