akhauriyash/Code-Regression huggingface dataset:
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

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

fn solve() {
    input! {
        n: usize
    }

    let mut ans = 0;

    for i in 1..n {
        ans += (n - 1) / i;
    }

    println!("{}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet
// 約数の列挙
fn enumerate_divisor(n: usize) -> usize {
    let mut i = 1;

    let mut divisors = 0;

    while i * i <= n {
        if n % i == 0 {
            divisors += 1;
            if i != n / i {
                divisors += 1;
            }
        }
        i += 1;
    }

    divisors
}


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

typedef __int128 ll;
typedef pair<int, int> pii;
bool R(){return true;}
template<typename T, typename ... Args>
bool R(T & x, Args & ... args){return cin >> x && R(args...);}
void init_io(){ios::sync_with_stdio(false);cin.tie(0);}

#define PB push_back
#define MP make_pair
#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define SV(vec) do{int __sv;R(__sv);vec.PB(__sv);}while(0)
#define ALL(vec) (vec).begin(), (vec).end()
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF   1000000007
#define INFLL 4000000000000000007LL

ll n, p[4], cn;
map<ll, ll> dp;
vector<int> divs = {2, 3, 5};

string to_str (ll x)
{
  string res;
  while (x)
  {
    res += (x % 10) + '0';
    x /= 10;
  }
  reverse(ALL(res));
  return res;
}

ll go (ll cn)
{
  if (!cn) return 0;
  if (cn == 1) return p[3];
  if (dp.count(cn)) return dp[cn];
  ll res = cn * p[3];
  FOR(i, 0, 3)
  {
    if (!(cn % divs[i])) res = min(res, p[i] + go(cn / divs[i]));
    else
    {
      ll md = cn % divs[i];
      ll imd = divs[i] - md;
      res = min({res, md * p[3] + p[i] + go((cn - md) / divs[i]), imd * p[3] + p[i] + go((cn + imd) / divs[i])});
    }
  }
  return dp[cn] = res;
}


void solve ()
{
  dp.clear();
  long long int N, P[4];
  R(N);
  FOR(i, 0, 4) R(P[i]);
  n = N;
  FOR(i, 0, 4) p[i] = P[i];
  cout << to_str(go(n)) << endl;
}

int main ()
{
  init_io();
  int t = 1;
  R(t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 4672
// https://beta.atcoder.jp/contests/abc062

#include <bits/stdc++.h>
using namespace std;

void print_yes_no(bool cond, string yes = "Yes", string no = "No") { cout << (cond ? yes : no) << endl; }

int main() {
    int a[] = {1, 3, 5, 7, 8, 10, 12};
    int b[] = {4, 6, 9, 11};
    int c[] = {2};
    int id[12 + 1];
    for (auto i : a) id[i] = 0;
    for (auto i : b) id[i] = 1;
    for (auto i : c) id[i] = 2;

    int x, y;
    cin >> x >> y;
    print_yes_no(id[x] == id[y]);
    return 0;
}

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

using namespace std;

int main(){
    string s;
    getline(cin,s);
    std::string::iterator it;

    for(it=s.begin();it!=s.end();){
        if(*it=='h'&& *(it+1)=='i'){
            it+=2;
        }
        else{
            cout<<"No";
            return 0;}
    }
    cout<<"Yes";
    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int i, N, M, sum = 0, cnt = 0;
  int A[1000];

  unused = scanf("%d %d", &N, &M);
  for(i=0; i<N; i++){
    unused = scanf("%d", &A[i]);
    sum += A[i];
  }

  for(i=0; i<N; i++){
    if(A[i] >= (double)sum/(4*M)) cnt++;
  }
  if(cnt >= M) printf("Yes");
  else printf("No");

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

ll gcd(ll a, ll b) {
  if (b==0) return a;
  else return gcd(b,a%b);
}
ll lcm(ll a, ll b) {
  ll g=gcd(a,b);
  return a/g*b;
}

int main(){
  ll N,ans;
  cin>>N;
  ll A[N];
  for(ll i=0;i<N;i++) cin>>A[i];
  sort(A,A+N);
  reverse(A,A+N);
  ans=A[0];
  for(ll i=0;i<N;i++){
    if(ans%A[i]!=0) ans=lcm(ans,A[i]);
  }
  cout<<ans<<endl;
}


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

using namespace std;
const int N = 1000005;

string s1, s2;

void init(){
	cin >> s1 >> s2;
	if(s1.length() == s2.length()){
		int r = s1.compare(s2);
		if(!r) puts("EQUAL");
		else if(r < 0) puts("LESS");
		else puts("GREATER");
	}
	else{
		if(s1.length() > s2.length()) puts("GREATER");
		else puts("LESS");
	}
}

int main(){
	
	init();
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 10000000007
#define ff first
#define ss second
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5 + 5;

int main()
{
    IOS
    int n;
    cin>>n;
    lli dp[n],a[n];
    for(int i=0;i<n;i++) dp[i] = 1e16;
    cin>>a[0];
    dp[0] = 0;
    for(int i=1;i<n;i++)
    {
        cin>>a[i];
        if(i-1>=0) dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
        if(i-2>=0) dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2])); 
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n-1];
    return 0;
}

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

int main (){
  
  int N;
  int K;
  int num;
  
  cin >> N >> K;
  
  if(K == 1){
    cout << 0 << endl;
  }
  else{
    num = N - K;
    cout << num << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] grid = new int[h][w];
		for (int i = 0; i < h; i++) {
			String s = sc.next();
			for (int j = 0; j < w; j++) {
				if (s.charAt(j) == '#') {
					grid[i][j] = -1;
				}
			}
			for (int j = 0; j < w; j++) {
				if (i == 0 && j == 0) {
					grid[i][j] = 1;
					continue;
				}
				if (grid[i][j] == -1) {
					continue;
				}
				if (i != 0 && grid[i - 1][j] != -1) {
					grid[i][j] += grid[i - 1][j];
				}
				if (j != 0 && grid[i][j - 1] != -1) {
					grid[i][j] += grid[i][j - 1];
				}
				grid[i][j] %= MOD;
			}
		}
		System.out.println(grid[h - 1][w - 1]);
	}
	
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    string s;
    cin >> s;
    if(s.size() % 2 == 0 ^ s[0] == s[s.size()-1]){
        cout << "Second" << endl;
    }else{
        cout << "First" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
N,M=map(int,input().split())
A=list(map(int,input().split()))
A[0]%=M
for i in range(N-1):
  A[i+1]+=A[i]
  A[i+1]%=M
d={}
for i in range(N):
  if A[i] in d:
    d[A[i]]+=1
  else:
    d[A[i]]=1
count=0

for k,v in d.items():
  count+=v*(v-1)/2
  if k==0:
    count+=v

print(int(count))

Measured memory_bytes: 92876
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x <<endl; 
using namespace std; 

//int _; 

int n;
long long ans=1,a[100050];

int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",a+i);
		if(!a[i])
		{
			puts("0");
			return 0;
		}
	}
	for(int i=0;i<n;i++)
	{
		if(1000000000000000000/ans<a[i])
		{
			puts("-1");
			return 0;
		}
		ans *= a[i];
	}
	cout << ans << endl;	 
	return 0;
}

Measured memory_bytes: 4432
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

N, D = map(int, input().split())
x = []
for i in range(N):
    x.append(list(map(int, input().split())))

x = np.array(x)
count = 0
for i in range(N):
    for j in range(i+1, N, 1):
        diff_array = x[i] - x[j]
        diff = np.sqrt(np.sum(diff_array**2))
        if float(diff).is_integer():
            count += 1
print(count)




Measured memory_bytes: 12420
from collections import Counter

N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())

sum_a = sum(a.elements())

for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Measured memory_bytes: 21856
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(x) (((long long)x)%modulo)



int main(){
	int N;
	cin>>N;
	string s,t;
	cin>>s>>t;
	reverse(s.begin(),s.end());
	for(int i=0;i<N;i++){
		int x = N-i;
		string a = s.substr(0,x);
		reverse(a.begin(),a.end());
		if(a==t.substr(0,x)){
			cout<<N+i<<endl;
			return 0;
		}
	}
	
	cout<<2*N<<endl;
				
				
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

ll dp[100005];

int main(int argc, char *argv[])
{
	int N, h[100005];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < N; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout << dp[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  int ans=0;
  int num_A=0;
  int num_B=0;
  int num_XA_BX = 0;
  for(auto& s : S){
    cin >> s;
    for(int ii=0; ii<s.size()-1; ii++){
      if(s[ii]=='A' && s[ii+1]=='B') ans++;
    }
    if(s.front()=='B' && s.back()=='A'){
      num_A++;
      num_B++;
    }
    if(s.front()!='B' && s.back()=='A'){
      num_A++;
      num_XA_BX++;
    }
    if(s.front()=='B' && s.back()!='A'){
      num_B++;
      num_XA_BX++;
    }
  }
  if(num_A+num_B==0){
    cout << ans << endl;
    return 0;
  }
  ans += min(num_A, num_B);
  if(num_XA_BX==0) ans--;
  cout << max(0, ans) << endl;
  return 0;
}

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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a) {
        for (int b = 0; b + a <= N; ++b) {
            int c = N - a - b; 
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }

    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

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

using namespace std;

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

    vector<int> V(N), C(N);

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

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

    int sum = 0;

    for(int i = 0; i < N; i++) {
        if(V[i] - C[i] > 0) sum += V[i] - C[i];
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
n,m,*t=map(int,open(0).read().split())
s=sorted
a=s(t[:n])[::-1]
i=n
for c,b in s(zip(t[n+1::2],t[n::2]))[::-1]:
 while(c>a[i-1])*i*b:i-=1;a[i]=c;b-=1
print(sum(a))

Measured memory_bytes: 35420
n = int(input())
a = [int(i) for i in input().split()] 
b = [int(i) for i in input().split()] 

pass_on = 0
count = 0
for i, x in enumerate(b):
    warriors = x + pass_on
    enemies = a[i]
    if warriors >= enemies:
        if pass_on >= enemies:
            pass_on = x
        else:
            pass_on = x - (enemies - pass_on)
        count += enemies
    else:
        count += warriors
        pass_on = 0
        
last = a[i+1]

if pass_on >= last:
    count += last
else:
    count += pass_on
    
print(count)

Measured memory_bytes: 18624
N=int(input())
A=[int(x) for x in input().split()]

ans=0
cnt=0
sum=0
for i in range(N):
  while cnt < N:
    if sum&A[cnt]==0:
      sum|=A[cnt]
      cnt+=1
    else:
      break
  ans+=(cnt-i)
  sum&=(~A[i])

print(ans)

Measured memory_bytes: 24424
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
signed main(){
	int k=read(),a=read(),b=read();
	fz(i,a,b)	if(i%k==0)	return puts("OK"),0;
	puts("NG");
	return 0;
}

Measured memory_bytes: 3532
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]


ans, j = 0, M
for i in range(N + 1):
    if arui[i] > K:
        break
    while brui[j] > K - arui[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)


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

int main(){
    int a, b, k; cin >> a >> b >> k;
    for(int i = min(a, b); i; i--){
        if(!(a%i) && !(b%i)){
            k--;
            if(!k) {
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
def is_even(num):
    return num % 2 == 0


N, A, B = [int(i) for i in input().split()]
#  N, A, B = [5, 2, 4]
#  N, A, B = [5, 2, 3]
#  N, A, B = [10, 2, 3]
#  N, A, B = [10, 7, 8]
#  N, A, B = [5, 2, 5]
#  N, A, B = [10, 2, 8]
#  N, A, B = [2, 1, 2]
#  N, A, B = [2, 1, 1]
is_even_a = is_even(A)
is_even_b = is_even(B)
if (is_even_a == True and is_even_b == True) or (
    is_even_a == False and is_even_b == False
):
    print((B - A) // 2)
else:
    print(min(A - 1, N - B) + 1 + ((B - A - 1) // 2))


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

int n, k;
vector<int> h;
int main() {
	cin >> n >> k;
	int hh;
	for (int i = 0; i < n; ++i) {
		cin >> hh;
		h.push_back(hh);
	}
	sort(h.begin(), h.end());
	LL res = 0;
	for (int i = 0; i < n - k; ++i) {
		res += (LL)(h[i]);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>
#include <iostream>
#define INF 100000000
using namespace std;
typedef pair<int,int> P;
int main()
{
    for(int i=0;i<3;i++){
        int h,m,s,h2,m2,s2;cin>>h>>m>>s>>h2>>m2>>s2;
        int as=3600*(h2-h)+60*(m2-m)+(s2-s);
        int ah=as/3600;as-=ah*3600;
        int am=as/60;as-=am*60;
        printf("%d %d %d\n",ah,am,as);
    }
   
}

Measured memory_bytes: 1148
#include <stdio.h>
#include <string.h>

int main(void){

  char s[11];
  scanf("%s", s);
  for (int i = 0; i < strlen(s); i += 2) {
    if (s[i] != 'h' || s[i+1] != 'i') {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007ll
#define INF (1 << 28)    // for x <= 10^9
#define INFL (1ll << 60) // for x <=10^19
#define EPS (1e-10)

using namespace std;

using ll = long long;

ll gcd(ll a, ll b) {
  if (a < b)
    return gcd(b, a);

  while (b != 0) {
    int r = a % b;
    a = b;
    b = r;
  }

  return a;
}

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll toA = (a - 1) - ((a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d));
  ll toB = b - (b / c + b / d - b / lcm(c, d));
  cout << toB - toA << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<int> dy={-1,0,1,0},dx={0,-1,0,1};
map<int,P> mp;
int main(){
  int n;
  cin>>n;
  V<ll> a(n*n);
  for(int i=0;i<n*n;i++)cin>>a[i];
  V<V<ll>> d(n,V<ll>(n));
  int cnt=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      d[i][j]=min({i,j,n-i-1,n-j-1});
      mp[cnt++]=P(i,j);
    }
  }
  ll ans=0;
  V<V<bool>> used(n,V<bool>(n,false));
  for(int i=0;i<n*n;i++){
    int s=mp[a[i]].fi,t=mp[a[i]].se;
    ans+=d[s][t];
     queue<P> q;
     used[s][t]=true;
     q.emplace(s,t);
    while(q.size()){
    int y=q.front().fi,x=q.front().se;
    q.pop();
     for(int j=0;j<4;j++){
       int ny=dy[j]+y,nx=dx[j]+x;
       if(ny<0||ny>=n||nx<0||nx>=n)continue;
       if(d[ny][nx]>d[y][x]+(!used[y][x])){
         d[ny][nx]=d[y][x]+(!used[y][x]);
         q.emplace(ny,nx);
       }
      }
    }
}
cout<<ans<<"\n";
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int a, b, k;
    cin >> a >> b >> k;
    stack<int> stk;
    for(int i=1;i<101;i++){
        if(a%i==0 && b%i==0) stk.push(i);
    }
    int ans;
    for(int i=0;i<k;i++){
        ans = stk.top();
        stk.pop();
    }

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

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	int i, j;
	int sum;
	
	scanf("%d", &N);
	
	sum = 0;
	for (i = 1; i <= N; i++){
		sum += i;
	}
	
	printf("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;
ll MOD=1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());
    ll k=a.at(n-1);
    ll ans=-1;
    int w;
    rep(i,n){
        ll u=min(a.at(i),k-a.at(i));
        if (ans<u) {ans=u;w=a.at(i);}
    }
    cout << k << " " << w << endl;
}


Measured memory_bytes: 1024
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, b = na()

def gcd(x, y):
    while(x > 0):
        x, y = y % x, x
    return y

g = gcd(a, b)
ans = 1
for d in range(2,1000001):
    e = 0
    while g % d == 0:
        g //= d
        e += 1
    if e > 0:
        ans += 1
if g > 1:
    ans += 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
const int maxn=1e9;

int main()
{
    int n;cin>>n;
    if(n==1) cout<<"Hello World"<<endl;
    else{
        int a,b;cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


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

int main()
{
    int n,m;
    cin >> n >> m;
    priority_queue<int> a;

    for (int i=0; i<n; i++) {
        int num;
        cin >> num;
        a.push(num);
    }

    for (int i=0; i<m; i++) {
        int num = a.top() / 2;
        a.pop();
        a.push(num);
    }

    long sum = 0;
    for (int i=0; i<n; i++) {
        sum += a.top();
        a.pop();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1020
#include<cstdio>
#define re register
#define int long long
using namespace std;
int n,a,b,c,d;
signed main(){
scanf("%lld",&n);
if(n&1)puts("0");
else{
for(re int i=5;i<=n;i*=5){
	b+=n/(i*2);
}
printf("%lld",b);}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
int main(){
    int n, x,l;
    cin >> n;
    vector<P> v(n);
    for(int i=0;i<n;i++){
        cin >> x >> l;
        v[i].first = x + l;
        v[i].second = x - l;
    }
    sort(v.begin(), v.end());
    int xx = -(1e+9), ans = 0;
    for(int i=0;i<n;i++){
        if(xx <= v[i].second){
            xx = v[i].first;
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        int n = in.intNext();
        int low = in.intNext();
        int high = in.intNext();

        int lowestMult = low + (n - (low % n));
        System.out.println((low % n == 0 || lowestMult <= high) ? "OK" : "NG");

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 25424
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int count = 0;
      String[] s = new String[n];
      for(int i = 0; i < n;i++){
        s[i] = sc.next();
        if(s[i].equals("Y"))count++;
      }
      if(count > 0)System.out.println("Four");
      else System.out.println("Three");
    }
}

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

int main() {
  int n, m;
  int a, b, c;
  string s, t;

  cin >> n;
  cin >> a;

  n %= 500;

  if ( n <= a ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return(0);
}

Measured memory_bytes: 256
#include<stdio.h>
#define H 50000000
int A[H],size = 0;
int left(int);
int right(int);
int parent(int);
void maxHeapify(int);
void buildMaxHeap();
void insert(int);
int extract(void);
void increase(int);
int main() {
	int key,n = 0,j,ex[2000000],a;
	char com[20];
	while (1) {
		scanf("%s", com);
		if ('i' == com[0]) {
			scanf("%d", &key);
			insert(key);
		}
		else if ('e' == com[0] && com[1] == 'x') {
			ex[n++] = extract();
		}
		else if (com[0] == 'e' && com[1] == 'n') {
			break;
		}
	}
	for (j = 0; j < n;j++) {
		printf("%d\n",ex[j]);
	}
}
int left(int i) {
	return 2 * i;
}
int right(int i) {
	return 2 * i + 1;
}
int parent(int i) {
	return i / 2;
}
void maxHeapify(int i) {
	int swap;
	int largest, r, l;
	r = right(i);
	if (r > size) {
		A[r] = -2000000001;
	}
	l = left(i);
	if (l <= size && A[l] > A[i]) {
		largest = l;
	}
	else {
		largest = i;
	}
	if (r <= size && A[r] > A[largest]) {
		largest = r;
	}
	if (largest != i) {
		swap = A[i];
		A[i] = A[largest];
		A[largest] = swap;
		maxHeapify(largest);
	}
}
void buildMaxHeap() {
	int i;
	for (i = size / 2; i > 0; i--) {
		maxHeapify(i);
	}
}
void insert(int k) {
	size++;
	A[size] = k;
	increase(k);
}
void increase(int k) {
	int swap,i;
	i = size;
	while(i > 1 && A[parent(i)] < A[i]){
		swap = A[i];
		A[i] = A[parent(i)];
		A[parent(i)] = swap;
		i = parent(i);
	}
}
int extract() {
	int max;
	max = A[1];
	A[1] = A[size];
	size--;
	maxHeapify(1);
	return max;
}



Measured memory_bytes: 11496
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int k;
    cin >> k;
    vector<int> a(k);
    rep(i, k) cin >> a[i];

    reverse(all(a));

    bool f = 1;
    if(a[0] != 2) f = 0;
    LL mn=2, mx=2;
    rep(i, k){
        mn = (mn+a[i]-1)/a[i] * a[i];
        mx = (mx/a[i] + 1) * a[i] - 1;

        // cout << mn << " " << mx << endl;
        if(mx < mn){
            f = 0;
            break;
        }
    }
    if(!f) cout << -1 << endl;
    else cout << mn << " " << mx << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

vector<int> z_algorithm(string s) {
  const int n = s.size();
  vector<int> z(n + 1);
  z[0] = n;
  int i = 1;
  int h = 0;
  while (i < n) {
    while (i + h < n && s[h] == s[i + h]) h++;
    z[i++] = h;
    if (h == 0) continue;
    h--;
    int k = 1;
    while (z[k] < h) {
      z[i++] = z[k++];
      h--;
    }
  }
  return z;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N; cin >> N;
  vector<int> A(N); rep(i, N) cin >> A[i];
  vector<int> B(N); rep(i, N) cin >> B[i];
  vector<int> ans(N);
  rep(k, 30) {
    string s(3 * N, '*');
    string t(3 * N, '*');
    rep(i, N) s[i] = (B[i] >> k & 1) + '0';
    rep(i, N) s[i + N] = s[i + 2*N] = (A[i] >> k & 1) + '0';
    rep(i, N) t[i] = (~B[i] >> k & 1) + '0';
    rep(i, N) t[i + N] = t[i + 2*N] = (A[i] >> k & 1) + '0';
    auto z0 = z_algorithm(s);
    auto z1 = z_algorithm(t);
    rep(i, N) {
      if (ans[i] == -1) continue;
      if (z0[i + N] >= N) {
        ans[i] ^= 0 << k;
      } else if (z1[i + N] >= N) {
        ans[i] ^= 1 << k;
      } else {
        ans[i] = -1;
      }
    }
  }
  rep(i, N) {
    if (ans[i] != -1) {
      cout << i << ' ' << ans[i] << '\n';
    }
  }
}


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

int main() {
 int r, g, b;
  cin >> r >> g >> b;
  int ans;
  ans = 100 * r + 10 * g + b;
  if (ans % 4 == 0 ) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

using namespace std;

int main(){
    int m,n;
    cin >> m >> n;
    vector<vector<int>> q(m,vector<int>(n));
    int ans = INT_MIN;
    vector<int> cnt(m);
    for(int i=0;i < m;i++){
        for(int j=0;j < n;j++){
            cin >> q.at(i).at(j);
            if(q.at(i).at(j)) cnt.at(i)++;
        }
        ans = max(ans,cnt.at(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3172
import math
K=int(input())

a=[]
b=0

for i in range(1,1+K):
  for j in range(1,K+1):
    gcd=math.gcd(i,j)
    a.append(gcd)

for l in a:
  for k in range(1,K+1):
    gcd_2=math.gcd(k,l)
    b+=gcd_2
    

print(b)

Measured memory_bytes: 9440
#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>;

ll dfs(vector<int> &s, int i, ll sum, ll sa){
    int n = s.size();
    if (i == n - 1){
        if (sum < 10){
            return sa;
        }
        else{
            return sa;
        }
    }
    ll sa0 = sa + s[i + 1];
    ll sa1 = sa + sum * 9 + s[i + 1];
    return dfs(s, i + 1, s[i + 1], sa0) + dfs(s, i + 1, sum * 10 + s[i + 1], sa1);
}

int main(){
    string s0;
    cin >> s0;
    int k = s0.size();
    vector<int> s;
    for (char i : s0){
        s.emplace_back(i - '0');
    }
    ll ans;
    ans = dfs(s, 0, s[0], s[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        for(int i = 0; i < num.length; i++){
            num[i] = sc.nextInt();
        }

        System.out.println(gcd(num[0],num[1]));
    }
    
    public static int gcd(int x, int y){
        int r;
        if(x < y){
            int tmp = x;
            x = y;
            y = tmp;
        }
        while(y > 0){
            r = x % y;
            x = y;
            y = r;
        }
        return x;
    }
}


Measured memory_bytes: 26188
#include "bits/stdc++.h"
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INF 100000000
typedef long long ll;

using namespace std;


int main() {
    int N;
    vector<int> a;
    int Alice = 0;
    int Bob = 0;
    cin >> N;
    REP(i, N) {
        int j;
        cin >> j;
        a.pb(j);
    }
    sort(all(a));
    reverse(all(a));
    REP(i, N) {
        if (i % 2 == 0) {
            Alice += a[i];
        }
        else {
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t{},k;
    cin>>k;
    if(k%2==0 or k%5==0) return puts("-1"),0;
    Fr(i,k*2+1){
        t*=10;t+=7;t%=k;
        if(!t) return cout<<i<<'\n',0;
    }
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int m,d; cin >> m >> d;
  int ans = 0;
  rep(i,m){
    rep(j,d){
      int ii = i +1;
      int  jj = j + 1;
      if(jj/10 < 2 || jj %10 < 2)  continue;
      if(ii == (jj%10)*(jj/10)) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int a, b, c, ans;
	cin >> a >> b >>c;
	ans = min(abs(a - b) + abs(a - c), min(abs(b - a) + abs(b - c), abs(c - a) + abs(c - b)));
	cout << ans << "\n";

	return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int a,b,c,k,zb=0;
    cin >> a >> b >> c >> k;
    zb+=min(a,k);
    k-=min(a,k);
    k-=min(b,k);
    zb-=min(c,k);
    cout << zb;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
LL g[114514];
vector<LL> dp[5145][2];
vector<int> es[5145];

void Dfs(int v, int p) {
  rep(b, 2) dp[v][b].resize(2);
  dp[v][0][1] = 1;

  for (int u : es[v]) {
    if (u == p) continue;
    vector<LL> dst[2];

    Dfs(u, v);
    
    rep(b, 2) {
      rep(c, 2) {
        int d = b^c;
        int un = dp[u][b].size();
        int vn = dp[v][c].size();

        dst[d].resize(un+vn-1);
        rep(k, un) {
          rep(t, vn) {
            LL p = dp[u][b][k];
            LL q = dp[v][c][t];
            LL m = p*q % MOD;
            dst[d][k+t] += m;
            dst[d][k+t] %= MOD;
          }
        }
      }
    }

    rep(b, 2) dp[v][b].swap(dst[b]);
  }

  if (v != p) {
    LL tmp[2] = {0, 0};
    rep(b, 2) {
      int vn = dp[v][b].size();
      rep(k, vn) {
        tmp[b] += g[k] * dp[v][b][k];
        tmp[b] %= MOD;
      }
    }

    rep(b, 2) {
      dp[v][b][0] += tmp[b^1];
      dp[v][b][0] %= MOD;
    }

    //rep(b, 2) {
    //  printf("dp[%d][%d]:", v, b);
    //  for (LL t : dp[v][b]) {
    //    printf(" %lld", t);
    //  }
    //  puts("");
    //}
  }
}

int main() {
  scanf("%d", &N);
  rep(i, N-1) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    es[u].eb(v);
    es[v].eb(u);
  }

  g[0] = 1;
  reps(i, 2, N+10) {
    g[i] = (g[i-2] * (i-1)) % MOD;
  }

  Dfs(0, 0);

  LL ans = 0;
  rep(b, 2) {
    int vn = dp[0][b].size();
    rep(k, vn) {
      LL t = dp[0][b][k] * g[k] % MOD;

      if (b) ans += MOD - t;
      else ans += t;

      ans %= MOD;
    }   
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 138496
#include<stdio.h>
#include<stdlib.h>
#define ll long long
int cmp(const void *a,const void*b){
    return *(long long int*)a-*(long long int*)b;
}
int main(){
    int n,k;
    ll sum=0;
    scanf("%d%d",&n,&k);
    ll h[n],i;
    for(i=0;i<n;i++)
        scanf("%lld",&h[i]);
    qsort(h,n,sizeof(long long),cmp);
    for(i=0;i<n-k;i++)
        sum+=h[i];
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 3324
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main()
{
	unsigned short *A,*B;
	
	int C[VMAX + 1];
	int n,i,j;
	scanf("%d",&n);
	
	A = malloc(sizeof(short)* n + 1);
	B = malloc(sizeof(short)* n + 1);
	
	for(i = 0; i <= VMAX; i++) C[i] = 0;
	
	for(i = 0; i < n; i++)
	{
		scanf("%hu",&A[i + 1]);
		C[A[i + 1]]++;
	}
	
	for(i = 1; i <= VMAX; i++) C[i] = C[i] + C[i - 1];
	
	for(j = 1; j <= n; j++)
	{
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for(i = 1; i <= n; i++)
	{
		if(i > 1) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 9540
#include<bits/stdc++.h>
using namespace std;
signed main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> diff;
    for(int i=0;i<n-2;i++){
        int num = (s[i]-48)*100 + (s[i+1]-48)*10 + (s[i+2]-48);
        diff.push_back(abs(753-num));
    }
    cout << *min_element(diff.begin(),diff.end());
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

void solve() {

}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  int n, m, d;
  scanf("%d %d %d", &n, &m, &d);
  ld ans = (ld) (m - 1) * (n - d) / ( (ld) n * n);
  if (d != 0) ans *= 2;
  printf("%.15Lf\n", ans);
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int ice[10],n,m;
	while(cin >> n){
		if(n<1) return 0;
		for(int i=0; i<10; i++) ice[i]=0;
		for(int i=0; i<n; i++){
			cin >> m;
			ice[m]++;
		}
		for(int i=0; i<10; i++){
			if(ice[i] == 0)
				cout << '-' << endl;
			else{
				for(int j=0; j<ice[i]; j++)
					cout << '*';
				cout << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
from collections import defaultdict, deque
from math import atan, pi

a, b, x = map(int, input().split())
print(atan(a * b * b / 2 / x * (x < a * a * b / 2) or (b / a - x / a ** 3) * 2) / pi * 180)

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

int main(){
    ll n,mod=1000000007;
    cin>>n;
    vector<ll> dist(n-1);
    ll a,b;cin>>a;
    rep(i,n-1){
        cin>>b;
        dist[i]=b-a;
        a=b;
    }
    ll ans=dist[0];
    ll ex=1,ls=1;
    rept(i,2,n){
        ex=ex*(i-1)%mod;
        ls =(ls*i+ex)%mod;
        ans = (ans*i+dist[i-1]*ls)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#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;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll ans=0;
    if(n%2==1){
        rep(i,n/2){
            ans+=a.at(i);
        }
        rep(i,n/2){
            ans+=a.at(i+1);
        }
    }
    else {
        rep(i,n/2)ans+=a.at(i);
        rep(i,n/2-1)ans+=a.at(i+1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m){
    cin >> s[i] >> c[i];
  }


  string ans = "";
  rep(i, 1000){
    int count = 0;
    int tmp = i;
    if(i == 0){
      count = 1;
    }else {
      while(tmp > 0){
        tmp /= 10;
        count ++;
      }
    }

    if(count != n) continue;
    bool ok = true;
    ans = to_string(i);
    
    rep(i, m){
      if(ans[s[i] - 1] - '0' != c[i]) ok = false;
    }
    if(ok){
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

int main() {
    int n,m,ans=0;
    cin >> n >> m;
    vector<pair<pp,int>> a(m);
    vector<vector<pp>> d(n+1,vector<pp>(0));
    queue<int> q;
    pp v;
    rep(i,m){
        cin >> a.at(i).first.first >> a.at(i).first.second >> a.at(i).second;
        v.first=i;v.second=2;
        d.at(a.at(i).first.first).push_back(v);
        v.first=i;v.second=1;
        d.at(a.at(i).first.second).push_back(v);
        }
        vector<int> oo(m);
        rep(i,m) oo.at(i)=1;
    for(int i=1;i<n+1;i++){
        vector<vector<int>> b(n+1,vector<int>(0));
        vector<int> cost(n+1);
        rep(k,n+1) cost.at(k)=10000000;
        q.push(i);
        cost.at(i)=0;
        while(!q.empty()){
            int num=q.front(),ac;
            q.pop();
            rep(k,d.at(num).size()){
                if (d.at(num).at(k).second==1) ac=a.at(d.at(num).at(k).first).first.first;
                else ac=a.at(d.at(num).at(k).first).first.second;
                if (cost.at(num)+a.at(d.at(num).at(k).first).second<cost.at(ac)){
                    cost.at(ac)=cost.at(num)+a.at(d.at(num).at(k).first).second;
                    b.at(ac)=b.at(num);
                    b.at(ac).push_back(d.at(num).at(k).first);
                    //cout << 1 << endl;
                    q.push(ac);
                }
            }
        }
        for (int k=1;k<n+1;k++){
            for (int l=0;l<b.at(k).size();l++){
                oo.at(b.at(k).at(l))=0;
            }
        }
    }
    rep(i,m) ans+=oo.at(i);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
void solve()
{
	string s;
	cin>>s;
	ll c=0,ans=0;
	for(auto it:s)
	{
		if(it=='R') c++;
		else c=0;
		ans=max(c,ans);
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 3568
n = int(input())
li = []
for i in range(n):
    li.append(list(map(int,input().split())))

li_sorted = sorted(li, key=lambda x: x[1])

count = 0
for i in range(n):
    li_sorted[i][1] -= count
    count += li_sorted[i][0]
    
for i in li_sorted:
    if i[1] >= i[0]:
        continue
    elif i[0] > i[1]:
        print("No")
        exit()

print("Yes")

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

int main(){
  for(int i = 1; i < 10001; i++){
    int x;
    cin >> x;
    if(x == 0){
      break;
    }
    else{
      cout << "Case" << " " << i << ":" << " " << x << endl;
    }
  }
}



Measured memory_bytes: 3000
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();
        int sLength = s.length();
        int tLength = t.length();
        int[][] dp = new int[tLength+1][sLength+1];
        for(int i = 1 ; i<=tLength ; ++i){
            for(int j = 1 ; j<=sLength ; ++j){
                if(s.charAt(j-1)==t.charAt(i-1)){
                    dp[i][j] = dp[i-1][j-1]+1;
                }else{
                    dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        int itr =dp[tLength][sLength];
        char[] res = new char[itr];
        for(int i =tLength , j = sLength ; i> 0&&j>0 ; ){
            if(s.charAt(j-1)==t.charAt(i-1)){
                res[--itr] = s.charAt(j-1);
                --j;--i;
            }else  if(dp[i][j-1]>dp[i-1][j]){
                --j;
            }else{
                --i;
            }
        }
        System.out.println(new String(res));
    }
}


Measured memory_bytes: 87068
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,z,w;
  std::cin>>n>>z>>w;

  std::vector<ll> a(n);

  rep(i,0,n)std::cin>>a[i];

  if(n==1)std::cout<<std::abs(a[0]-w);
  else std::cout<<std::max(std::abs(a[n-1]-w),std::abs(a[n-2]-a[n-1]));

  return 0;
}


Measured memory_bytes: 256