akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] dist = new int[n + 10];
		int before = 0, sum = 0,  max = 0;
		int start = sc.nextInt(); int goal = 0;
		//最後は埋めない
		for(int i = 1; i < n; i++) {
			goal = sc.nextInt();
			dist[i] = goal - start;
			if (max < dist[i]) max = dist[i];
			sum += dist[i];
			start = goal;
		}
		dist[n] = k - sum;
		if(max < dist[n]) max = dist[n];
		
		int ans = k - max;
		
		out.println(ans);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 22856
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int n = sc.nextInt();
long[] a=new long[n];
long[] B=new long[n];
long b;
for (int i = 0; i < n; i++) {a[i]=sc.nextLong();B[i]=a[i]-i-1;}
Arrays.sort(B);
b=B[n/2];
long ans=0;
for (int i = 0; i < n; i++) {
    ans+=abs(a[i]-b-i-1);
}
out.println(ans);
}}

Measured memory_bytes: 92536
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]

n,a,b=ipt()

cnt=0
for i in range(1,n+1):
    temp = sum(map(int,list(str(i))))
    if temp >= a and temp <= b:
        cnt += i
print(cnt)

Measured memory_bytes: 3064
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        p: [i64; n],
    }

    let mut p = p;
    p.sort();
    p.reverse();

    p[0] /= 2;

    let ans = p.iter().sum::<i64>();

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


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
S=input()
N = len(S)
result = 0
for i in range(2**(N-1)):
    T = str(S[0])
    for k in range(N-1):
        if (i>>k )& 1 == 1:
            T += "+" + str(S[k+1])
        else:
            T += str(S[k+1])
           
    result += eval(T)

print(result)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int p=s.length();
    int q=t.length();
    int ans=0;
    if(p==q){
        for(int i=0;i<p;i++){
            if(s[i]!=t[i]){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3820
import sys
import math
import numpy as np

N = int(input())
H = [int(_) for _ in input().split()]

memo = [1e10] * (N + 1)
memo[0] = 0

for i in range(N - 1):
    memo[i + 1] = min(abs(H[i] - H[i + 1]) + memo[i], memo[i + 1])
    if i < N - 2:
        memo[i + 2] = min(abs(H[i] - H[i + 2]) + memo[i], memo[i + 2])
print(memo[N - 1])


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

using namespace std; 
int main()
{
	char s1[10],s2[10],s3[10];
	cin>>s1>>s2>>s3;
char a,b,c;

a=toupper(s1[0]);
	
b=toupper(s2[0]);

c=toupper(s3[0]);
cout<<a<<b<<c;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	ll ss =(ll) H * W;
	//cout << ss << endl;
	ll tmp = ss;

	for (int i = 1; i<H; i++) {
		int w = W / 2;
		vector<ll>s(3);
		s[0] = (ll)i * W;
		s[1] = (ll)(H - i)*w;
		s[2] = ss-s[0]-s[1];
		ll a = *max_element(all(s))
			-*min_element(all(s));
		int h = (H - i) / 2;
		s[0] =(ll) i * W;
		s[1] =(ll)h * W;
		s[2] = ss-s[0]-s[1];
		ll b = *max_element(all(s))
			- *min_element(all(s));
		tmp = min(tmp, min(a, b));
	}
//	cout << tmp << endl;
	for (int i = 1; i < W; i++) {
		vector<ll>s(3);
		s[0] = (ll)i * H;
		s[1] = (ll)(W - i)*(H/2);
		s[2] = ss- s[1] - s[0];
		ll a = *max_element(all(s))
			- *min_element(all(s));

		int w = (W - i) / 2;
		s[0] =(ll) i * H;
		s[1] = (ll)w * H;
		s[2] = ss - s[0] - s[1];
		ll b = *max_element(all(s))
			- *min_element(all(s));
		tmp = min(tmp, min(a, b));
	}
	cout << tmp << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<array>
using namespace std;
using UL = unsigned;
using LL = long long;
using ULL = unsigned long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)
void Solve() {
	UL n; cin >> n;
	bool dp1[10] = {};
	bool dp2[100] = {};
	bool dp3[1000] = {};
	rep(i, n) {
		char c; cin >> c;
		UL d = c - '0';
		rep(p, 100) if (dp2[p]) dp3[p * 10 + d] = true;
		rep(p, 10) if (dp1[p]) dp2[p * 10 + d] = true;
		dp1[d] = true;
	}
	UL ans = 0;
	rep(p, 1000) {
		if (dp3[p])ans++;
	}
	cout << ans << endl;
}
int main() { Solve(); return 0; }


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

int main()
{
  	int n;
  	cin>>n;
  	int odd=0,even=0;
  	for(int i=1 ; i<=n ;++i)
    {
    	if(i%2)
        ++odd;
      	else
        ++even;
    }
  	cout<<odd*even<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x;cin>>n>>m>>x;
    vector<int> a;
    a.resize(110);
    for(int i=1;i<=m;i++){
        int t;cin>>t;
        a[t] = 1;
    }
    int a1=0, a2=0;
    for(int i=x;i>=0;i--){
        a1 += a[i];
    }
    for(int i=x;i<=n; i++){
        a2 += a[i];
    }
    cerr<<a1<<" "<<a2<<endl;
    cout<<min(a1,a2)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define REP(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

using namespace std;

typedef long long int lli;

int main(){
  lli A,B,C;
  cin>>A>>B>>C;
  if(A%2 == 0 || B%2 == 0 || C%2 == 0) cout<<0<<endl;
  else{
    lli ans = min(A*B,B*C);
    cout<<min(ans,C*A)<<endl;
    
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using ll = long long;

using namespace std;

const int char_num = 26;

int main() {
  ll num;

  cin >> num;

  string name = "";

  ll left_num = num;
  while(true) {
    if(left_num == 0) {
      break;
    }
    left_num--;
    ll quotient = left_num % char_num;

    name = string(1, 'a' + quotient) + name;

    left_num /= char_num;
  }

  cout << name << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int n;
	cin >> n;
	vi d(n);
	rep(i,n) cin >> d[i];
	ll ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    //150a
    static final long DIV = 100000007L;
    static final int MAX = 2000000000;
    //static long[] fac = new long[MAX];
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //String[] s = new String[40320];
        ArrayList<Integer> num = new ArrayList<Integer>();

        for(int i = 1;i <= n;i++)num.add(i);
        int a = 0;
        for(int i = 0;i < n;i++){
            int hoge = sc.nextInt();
            for(int j = 0;j < n;j++){
                if(num.get(j) == hoge){
                    num.remove(j);
                    hoge = j;
                    //System.out.println("poyo");
                    break;
                }
            }

            if(i == n-1)break;

            a += fact(num.size())*(hoge);
            
        }
        num.clear();
        for(int i = 1;i <= n;i++)num.add(i);

        int b = 0;
        for(int i = 0;i < n;i++){
            int hoge = sc.nextInt();     
            for(int j = 0;j < n;j++){
                if(num.get(j) == hoge){
                    num.remove(j);
                    hoge = j;
                    //System.out.println("poyopoyo");
                    break;
                }
            }
            if(i == n-1)break;
            b += fact(num.size())*hoge;
        }
        //System.out.println(a);
        //System.out.println(b);
        a -= b;
        if(a<0)a*=-1;
        System.out.println(a);
        
    }

    static int fact(int i){
        if(i == 0)return 1;
        return i * fact(i-1);
    }

    static long modpow(long n){
        long ans =1;
        long a = 2;
        long m = n;
        while(m>0){
            if((m&1)==1)ans = ans*a % DIV;
            a = a * a % DIV;
            m >>= 1;
        }
        return ans;
    }

    static long modcomb(long n,long r){
        return 1;
    }
    
}

Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char a[100001],b[100001];

int main() {
	scanf("%s",a);
	int n=strlen(a);
	for(int i=0;i < n;i++) {
		b[i]=a[i];
		if(b[i]=='b') {b[i]='d';continue;}
		if(b[i]=='d') {b[i]='b';continue;}
		if(b[i]=='p') {b[i]='q';continue;}
		if(b[i]=='q') {b[i]='p';continue;}
	}
	//cout<<b;
	for(int i=0,j=n-1;i < n;i++,j--)
		if(a[i]!=b[j]) {cout<<"No\n";return 0;}
	cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    vector<int> a(3);
    for(auto &i : a)cin>>i;
    sort(a.begin(),a.end());
    if(a[0]+a[1]==a[2])cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
 
N, Q = map(int, input().split())
root = [[] for _ in range(N)]
ans = [0]*N
 
for _ in range(N-1):
  a,b=map(int, input().split())
  a,b=a-1,b-1
  root[a].append(b)
  root[b].append(a)

for _ in range(Q):
  p,x=map(int, input().split())
  ans[p-1]+=x
  
visitted=[False]*N
def dfs(v):
  visitted[v] = True
  for go in root[v]:
    if visitted[go]:
      continue
    ans[go] += ans[v]
    dfs(go)

dfs(0)
print(*ans)

Measured memory_bytes: 223552
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
ll n,a,b,h[100010];

bool c(ll t){
	
	ll cou=0;
	REP(i,0,n) if(h[i]>b*t) cou+=(h[i]-b*t)/(a-b)+!!((h[i]-b*t)%(a-b));
	
	return (cou<=t?1:0);
}

int binary(){
	int ok=INF, ng=0;
	
	while(abs(ok-ng)>1){
		int mid=(ok+ng)/2;
		if(c(mid)) ok=mid;
		else ng=mid;
	}
	
	return ok;
}

int main(){
	cin >> n >> a >> b;
	REP(i,0,n) cin >> h[i];
	
	cout << binary() << endl;
	return 0;
}



Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
      
      //入力
      int x =sc.nextInt();//整数
      int n =sc.nextInt();//数列の長さ
      int ans = 0;
      int min = 100;
      
      //数列listの空箱用意
      List<Integer> s = new ArrayList<Integer>();
      
      //数列のlist作成
      for(int i =0; i<n; i++){
      		s.add(sc.nextInt());
      } 
      //数列がないとき
		if(n == 0 || !(s.contains(x))) {
			System.out.println(x);
		}
      
      	else {
			for(int i =0; i<=200; i++) {
                //数列に含まれていない整数か
				if(!(s.contains(i))) {
                    //絶対値が小さい整数を求める
					if(Math.abs(x - i) < min) {
                        //最小値を更新する
						min = Math.abs(x - i);
						ans = i;
                    }
                }
            }
          System.out.println(ans);
        }
    }
}

Measured memory_bytes: 35820
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

int N, M;
void main() {
    while(true) {
        int[] input = readln.split.to!(int[]);
        if (input == [0, 0]) break;
        N = input[0];
        M = input[1];
        Edge[] edges = new Edge[M];
        foreach(int i; 0..M) {
            input = readln.split.to!(int[]);
            int a = input[0];
            int b = input[1];
            edges[i] = Edge(input[2], min(a, b), max(a, b));
        }
        sort!("a.cost<b.cost")(edges);
        int[] usedNode = [0];
        int ans = 0;
        foreach(int i; 1..N) {
            for (int j=0; j<edges.length; j++) {
                bool flg1 = usedNode.canFind(edges[j].from);
                bool flg2 = usedNode.canFind(edges[j].to);
                if (flg1 && !flg2) {
                    usedNode ~= edges[j].to;
                    ans += edges[j].cost;
                    break;
                } else if (!flg1 && flg2)  {
                    usedNode ~= edges[j].from;
                    ans += edges[j].cost;
                    break;
                }
            }
        }
        ans.writeln;
    }
}
struct Edge {
    int cost;
    int from, to;
    this(int cost, int from, int to) {
        this.cost = cost;
        this.from = from;
        this.to = to;
    }
}

Measured memory_bytes: 2484
#include<stdio.h>
#define NUM 100

int main(){
  int n;
  int a[NUM];
  int ans = 0;
  /*入力*/
  scanf("%d",&n);
  for(int i = 0;i < n;i++){
    scanf("%d",&a[i]);
    if((a[i]%2 == 0)&&((a[i]%3 != 0)&&(a[i]%5 != 0))){
      ans = -1;
    }
  }
  if(ans == 0){
    printf("APPROVED\n");
  }
  else{
    printf("DENIED\n");
  }
  return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)

type divisor struct{ list [100]int }

func (d *divisor) add(num int) {
	i := 2
	for i < 11 {
		if num%i == 0 {
			d.list[i]++
			num /= i
		} else {
			i++
		}
	}
	if num > 1 {
		d.list[num]++
	}
}

func (d *divisor) count() [5]int {
	var res [5]int
	th := [5]int{2, 4, 14, 24, 74}
	for i := 1; i < 100; i++ {
		for j := 0; j < 5; j++ {
			if d.list[i] >= th[j] {
				res[j]++
			}
		}
	}
	return res
}

func main() {
	var num int
	ans := 0
	fmt.Scan(&num)
	divisors := divisor{[100]int{}}
	for n := num; 0 < n; n-- {
		divisors.add(n)
	}
	res := divisors.count()
	ans += res[4]
	ans += res[3] * (res[0] - 1)
	ans += res[2] * (res[1] - 1)
	ans += res[1] * (res[1] - 1) * (res[0] - 2) / 2
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef map<ll,ll> mpll;
typedef set<ll> setll;
typedef multiset<ll> msetll;
 
#define F first
#define S second
#define pb push_back
#define mp make_pair 

const ll inf = ll(1e18);
const ll MOD = (1e9 + 7);

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG_
		freopen("input.txt","r",stdin);
	#endif
	cout.setf(ios::fixed), cout.precision(20);
    ll a,b;
    cin >> a;
    cin >> b;
    if(1!=a && 1!=b) cout<<1<<"\n";
    else if(2!=a && 2!=b) cout<<2<<"\n";
    else cout<<3<<"\n";
	return 0;
}

Measured memory_bytes: 256
from math import sqrt

N, D = [int(i) for i in input().split()]

XS = [list(int(i) for i in input().split()) for _ in range(N)]

cnt = 0
for i in range(N):
  for j in range(i+1, N):
    if sqrt(sum((y - z) ** 2 for y, z in zip(XS[i], XS[j]))).is_integer():
      cnt += 1
      
print(cnt)


Measured memory_bytes: 8936
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 1

lli abs2(lli a){
	if(a>=0)return a;
	else return -a;
}

int main(){

	lli n;
	vector<lli> a;

	cin>>n;
	REP(i,n){
		lli tmp;
		cin>>tmp;
		a.push_back(tmp-i-1);
		
	}

	sort(a.begin(),a.end());
	lli centerNum;

	if( n%2 == 0){
		centerNum = (a[n/2]+a[n/2-1])/2;
	}
	else{
		centerNum = a[n/2];
	}

	lli ans=0;
	REP(i,n){
		ans += abs2(a[i]-centerNum);
	}

	cout<<ans<<endl;



	return 0;
}

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

//create arrays outside of main()

int a[100];

int main(){

    int a;
    int b;
    
    cin >> a >> b;

    int totalPieces = a*3+b;

    int pies;

    pies = totalPieces/2;

    cout << pies;

    return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

class SqrtDecomposition
{
public:
  int n, k, d;
  vector<int> data, bucket, lazy;
  vector<bool> lazyflag;
  int block;

  SqrtDecomposition(int n_, int d_, int block_=512): n(n_), d(d_), block(block_)
  {
    k = (n+block-1) / block;
    data.assign(k*block, d);
    bucket.assign(k, d);
    lazy.assign(k, 0);
    lazyflag.assign(k, false);
  }

  void eval(int x)
  {
    if(lazyflag[x]){
      lazyflag[x] = false;
      for(int i = x*block; i < (x+1)*block; i++){
        data[i] = lazy[x];
      }
    }
  }

  void update(int s, int t, int x)
  {
    for(int i = 0; i < k; i++){
      int l = i*block, r = (i+1)*block;
      if(r <= s or t <= l) continue;
      if(s <= l and r <= t){
        bucket[i] = x;
        lazy[i] = x;
        lazyflag[i] = true;
      }else{
        eval(i); 
        for(int j = max(s, l); j < min(t, r); j++){
          data[j] = x;
        }
        bucket[i] = d;
        for(int j = l; j < r; j++){
          bucket[i] = max(bucket[i], data[j]);
        }
      }
    }
  }

  void update(int i, int x)
  {
    update(i, i+1, x);
  }

  int find(int s, int t)
  {
    int res = d;
    for(int i = 0; i < k; i++){
      int l = i*block, r = (i+1)*block;
      if(r <= s or t <= l) continue; 
      if(s <= l and r <= t){
        res = max(res, bucket[i]); 
      }else{
        eval(i);
        for(int j = max(s, l); j < min(t, r); j++){
          res = max(res, data[j]);
        }
      }
    }

    return res;
  }

  int find(int i)
  {
    return find(i, i+1);
  }
};

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

  vi h(n), a(n);
  rep(i, 0, n) cin >> h[i];
  rep(i, 0, n) cin >> a[i];

  SqrtDecomposition sd(n, 0);
  rep(i, 0, n){
    int t = sd.find(0, h[i]);
    sd.update(h[i], t+a[i]);
  }

  cout << sd.find(0, n+1) << endl;

  return 0;
}


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


int main() {
  int A, B, K; cin >> A >> B >> K;
  vector<int> N;

  for(int i=A; i<A+K && i<=B; i++){
    auto f = find(N.begin(), N.end(), i);
    if(f == N.end()) N.push_back(i);
  }

  for(int i=B; i>B-K && i>=A; i--){
    auto f = find(N.begin(), N.end(), i);
    if(f == N.end()) N.push_back(i);
  }

  sort(N.begin(), N.end());
  for(int i=0; i<N.size(); i++){
    cout << N[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int c = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    int remainK = k;

    int numA = Math.min(remainK, a);
    int ans = 0;
    ans += numA;
    remainK -= numA;
    if (remainK == 0) {
      pw.println(ans);
      return;
    }
    int numB = Math.min(remainK, b);
    remainK -= numB;
    if (remainK == 0) {
      pw.println(ans);
      return;
    }
    ans -= remainK;
    pw.println(ans);
  }
}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
int maxtime(int x) {
    //１の位を切り上げる
    return(x + 9) / 10 * 10;
}
int remitime(int x) {
    //ロスする時間
    return maxtime(x) - x;
}
int main (){
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e ;
    int sum = maxtime(a)+maxtime(b)+maxtime(c)+maxtime(d)+maxtime(e) - max({remitime(a),remitime(b),remitime(c),remitime(d),remitime(e)});

    cout << sum << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
int main(){
    string S; cin >> S;
    int n = S.size();
    bool ans = true;
    for(int i = 0; i<n; i+=2){
        if(S[i] == 'L') ans = false;
    }

    for(int i = 1; i<n; i+=2){
        if(S[i] == 'R') ans = false;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int asc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	int a[100050];
	map<int, int> sc;
	for(int i = 1; i <= q; i++){
		cin >> a[i];
		sc[a[i]]++;
	}
	for(int i = 1; i <= n; i++){
		if(k-q+sc[i] > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 5760
r,g,b,n=io.read("*n","*n","*n","*n")

counter=0
for i=0,n do
    for j=0,n-i do
        rg=r*i+g*j
        if n>=rg and (n-rg)%b==0 then
            counter=counter+1
        end
    end
end
print(counter)

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

int main() {
  int N;
  cin >> N;
  
  vector<int> mochi(N);
  for (int i=0; i<N; i++) cin >> mochi.at(i);
  sort (mochi.begin(),mochi.end(),greater<int>());
  
  int cnt=1;
  
  for (int i=0; i<N-1; i++)
    if (mochi.at(i)>mochi.at(i+1)) cnt++;
  
  cout << cnt << endl;
    
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
struct node{
	int x,y; ll z;
}w[400001];
int cnt,minn,n,q,fa[200001],k;
ll ans,f[200001];
inline bool cmp(node c,node d){return c.z<d.z;}
inline void add(int x,int y,ll z){
	w[++cnt].x=x; w[cnt].y=y; w[cnt].z=z;
}
int find(int x){
	if (fa[x]!=x) fa[x]=find(fa[x]);
	return fa[x];
}
int main(){
	int a,b; ll c;
	scanf("%d%d",&n,&q);
	memset(f,10,sizeof(f));
	for (int i=1; i<=q; i++){
		scanf("%d%d%lld",&a,&b,&c);
		a++,b++; add(a,b,c);
		f[a%n+1]=min(f[a%n+1],c+1);
		f[b%n+1]=min(f[b%n+1],c+2);
	}
	for (int i=1; i<=n; i++){
		if (f[i]<f[minn]) minn=i;
		fa[i]=i;
	}
	int j=minn;
	for (int i=minn%n+1; i!=minn; i=i%n+1)
		f[i]=min(f[j]+2,f[i]),j=i;
	for (int i=2; i<=n; i++) add(i-1,i,f[i]);
	add(n,1,f[1]); sort(w+1,w+cnt+1,cmp);
	for (int i=1; i<=cnt; i++){
		a=find(w[i].x),b=find(w[i].y);
		if (a!=b){
			k++; fa[a]=b; ans+=w[i].z;
			if (k==n-1) break;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

A = list(map(int,input().split()))

ans = 0
oneloop = 0
base = [0] * 2001

num = [0] * 2001


for i in range(N):

    na = A[i]

    oneloop += num[na]

    for j in range(na):

        num[j] += 1


ans += oneloop * K

#print (oneloop)


for i in range(N):

    na = A[i]
    ans = ( ans + num[na] * K * (K-1) // 2 ) % (10 ** 9 + 7)

print (ans)

Measured memory_bytes: 40940
fun main(args: Array<String>) {
    val (N, L) = listOfInt()
    val A = Array<Int>(N, {0})
    var sum = 0
    for (n in 0 until N) {
        A[n] = L + n
        sum += A[n]
    }
    var q = Int.MAX_VALUE
    A.forEach { if (Math.abs(it) < Math.abs(q)) q = it }
    println("${sum - q}")
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 37820
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
int n;
struct edge
{
    int v,nxt;
}e[N<<1];
int head[N],etot;
int dis;
int p[N],siz[N];
int X,Y;
inline void ad(int u,int v)
{
    e[++etot].v=v;e[etot].nxt=head[u];head[u]=etot;
}
bool flag=false;
void dfs(int u,int fa,int dep)
{
    if(flag)return;
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].v;
        if(v==fa)continue;
        p[v]=u;
        if(v!=n)dfs(v,u,dep+1);
        else
        {
            dis=dep;flag=true;
            return;
        }
    }
}
void dfs2(int u,int fa)
{
    siz[u]=1;
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].v;
        if(v==fa)continue;
        dfs2(v,u);
        siz[u]+=siz[v];
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;++i)
    {
        int x,y;scanf("%d%d",&x,&y);
        ad(x,y),ad(y,x);
    }
    dfs(1,0,0);
    int hal=dis/2;
    int P=n;
    for(int it=1;it<=hal;it++)
    {
        P=p[P];
    }
    Y=P;X=p[P];
    dfs2(X,Y);
    dfs2(Y,X);
    if(dis&1)
    {
        if(siz[Y]>siz[X])puts("Snuke");
        else puts("Fennec");
    }
    else
    {
        if(siz[Y]>=siz[X])puts("Snuke");
        else puts("Fennec");
    }
    return 0;
}

Measured memory_bytes: 7680
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main() {
  int N; cin >> N;
  string str = "";
  while (N != 0) {
  int r = N % 2;
  if (r < 0) r += 2;

  N = (N - r) / (-2);

  str += (char)('0' + r);
  }

  reverse(str.begin(), str.end());
  if (str == "") str = "0";
  cout << str << endl;
}


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

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

using namespace std;

int a[35][35],w,h,m,q;

int main(){
  while(cin>>w>>h>>m>>q,h){
    
    memset(a,0,sizeof(a));

    r(i,h){
      r(j,w)a[i][j]=1;
    }

    r(i,m){//cout<<h<<' '<<w<<endl;
      int d,c;
      cin>>d>>c;
      if(d==1){
	int p[35][35]={};
	for(int i=0;i<h;i++){
	  for(int j=c-1,k=0;j>=0;j--,k++){
	    p[i][k]=a[i][j];
	  }
	}
	for(int i=0;i<h;i++){
	  for(int j=c;j<w;j++){
	    a[i][j-c]=a[i][j];
	  }
	}
        int W=c;
	if(w<=c);
	else W=w-c;
	r(i,h)for(int j=W;j<w;j++)a[i][j]=0;
	w=max(w-c,c);
	for(int i=0;i<h;i++){
	  for(int j=0;j<w;j++){
	    a[i][j]+=p[i][j];
	  }
	}
      }
      else{
	int p[35][35]={};
	for(int i=c-1,k=0;i>=0;i--,k++){
	  for(int j=0;j<w;j++){
	    p[k][j]=a[i][j];
	  }
	}
	for(int i=c;i<h;i++){
	  for(int j=0;j<w;j++){
	    a[i-c][j]=a[i][j];
	  }
	}
	int H=c;
	if(h<=c);
	else H=h-c;
	for(int i=H;i<h;i++)r(j,w)a[i][j]=0;
	h=max(h-c,c);
	for(int i=0;i<h;i++){
	  for(int j=0;j<w;j++){
	    a[i][j]+=p[i][j];
	  }
	}
      }

    }
    int ans=0;
    r(i,q){
      int x,y;
      cin>>x>>y;
      cout<<a[y][x]<<endl;;
    }
    // cout<<ans<<endl;
  }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <chrono> 
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fr(i,a,b) for (ll i=(a); i<(b);++i)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);--i)
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<ll,ll> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a,k) sort(a,a+k,greater<ll>())
#define rsrt(a) sort(a.begin(),a.end(),greater<ll>())
#define sz(a) (ll)a.size()
//#define endl "\n"
#define po(a,b) (ll)(pow(a,b)+0.5)
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define setbits(a) __builtin_popcount(a)
const ll M=1e9+7;
const ll mxx=3001;

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;   
    x = x % p;    
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 

        y = y>>1;
        x = (x*x) % p; 
    } 
    return res; 
}

int main()
{  
  
  ll n;cin>>n;
  ll c[n];
  fr(i,0,n)cin>>c[i];
  sort(c,c+n);
  ll ans=0;
  fr(i,0,n)
  {
      ll cur=power(2,2*n-1,M);
      cur+=(((power(4,i,M)*(n-i-1))%M)*power(2,2*(n-i-1),M));
      cur%=M;
      cur*=c[i];cur%=M;
      ans+=cur;
      ans%=M;
  }
  cout<<ans;

}



Measured memory_bytes: 5196
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) {
    list($a[], $b[]) = ints();
}
array_multisort($a, SORT_DESC, $b);
echo ($a[0] + $b[0]) . PHP_EOL;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 32532
int main()
{
  int n, k, q;
  scanf("%d %d %d", &n, &k, &q);
  int point[n], i;
  for (i = 0; i < n; i++)
    point[i] = 0;
  int a[q];
  for (i = 0; i < q; i++)
  {
    scanf("%d", &a[i]);
    point[a[i] - 1]++;
  }
  int tmp = q - k;
  for (i = 0; i < n; i++)
  {
    if (point[i] > tmp)
      printf("Yes\n");
    else
      printf("No\n");
  }
}

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

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

    int a=C/B;
    int b=A/D;

    if(C-a*B!=0){
        a=a+1;
    }
    if(A-b*D!=0){
        b=b+1;
    }

    if(a>b){
        cout << "No" << endl;
    }
    else{
        cout<< "Yes" << endl;
    }

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int gcd(int x, int y) {
    if (y == 0ll) {
        return x;
    } else {
        return gcd(y, x%y);
    }
}

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

    vector<ll> L(N);
    vector<ll> R(N);

    L[0] = A[0];
    for (int i=0; i<N-1; ++i) {
        L[i+1] = gcd(L[i], A[i+1]);
    }

    R[N-1] = A[N-1];
    for (int i=N-1; i>0; i--) {
        R[i-1] = gcd(R[i], A[i-1]);
    }

    int ans = max(L[N-2], R[1]);
    rep(i, N-2) {
        int t = gcd(L[i], R[i+2]);
        ans = max(t, ans);
    }

    print(ans);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 500005;

ll modexp(ll x, ll n)
{
    if(n==0)
        return 1LL;
    if(n%2==0)
    {
        ll y = modexp(x,n/2)%mod;
        return (y*y)%mod;
    }
    return (x*modexp(x,n-1)%mod)%mod;
}

ll powr(ll x, ll n)
{
    ll ans = 1;
    for(int i=1;i<=n;i++)
        ans=ans*x;
    return ans;
}

int main()
{
    int a,b,c;
    si(a),si(b),si(c);
    pfi(min(c,b/a));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define int long long
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define mod %1000000007
#define ld long double
#define pll pair<ll,ll>
bool comp(P p1,P p2)
{
    if(p1.ff.ff!=p2.ff.ff)
        return p1.ff.ff<p2.ff.ff;
    else
        return p1.ss<p2.ss;
}

int32_t main()
{
     IOS;
    
     ll x,y;
     cin>>x>>y;
     if(y==1 || x%y==0)
        cout<<-1;
    else
        cout<<x*(y-1);

     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


signed main(void){
    int A,B,N;
    cin >> A >> B >> N;
    int x = min(B-1,N);
    int Ans=0;
    Ans+=(A*x)/B;
    Ans-=A*(x/B);
    cout << Ans << endl;
    
    return 0;
}




Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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


int main(){
    int n, q, b, c;
    cin >> n;
    vint a_count(100010, 0);
    ll ans = 0;
    rep(i,n){
        int tmp;
        cin >> tmp;
        a_count[tmp]++;
        ans += tmp;
    }
    cin >> q;
    // cout << "test" << endl;
    rep(i,q){
        cin >> b >> c;
        ans += (c-b) * a_count[b];
        a_count[c] += a_count[b];
        a_count[b] = 0;
        cout << ans << endl;
    }
}



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

int32_t main(){
    int W{},H{},N{};    cin>>W>>H>>N;
    int xl{},xr{},yu{},yd{};    xr=W,yu=H;
    while(N--){
        int x{},y{},a{};    cin>>x>>y>>a;
        switch(a){
            case 1 : xl=max(x,xl);
                    break;
            case 2 : xr=min(xr,x);
                    break;
            case 3 : yd=max(yd,y);
                    break;
            case 4 : yu=min(y,yu);
                    break;
        }
    }
    int l = xr-xl;  l=max(l,0LL);
    int b = yu-yd;  b=max(b,0LL);
    cout<<l*b<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

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

    int a, b, q; cin>>a>>b>>q;
    vector<ll> s, t;
    s.emplace_back(-INF);
    t.emplace_back(-INF / 2);
    s.emplace_back(-INF / 3);
    for(int i=0; i<a; i++){
        ll S; cin>>S;
        s.emplace_back(S);
    }
    for(int i=0; i<b; i++){
        ll T; cin>>T;
        t.emplace_back(T);
    }
    s.emplace_back(INF / 3);
    t.emplace_back(INF / 2);
    s.emplace_back(INF);

    while(q--){
        ll x; cin>>x;

        // 左神社、近い寺
        ll sum1 = 0;
        auto shrine = lower_bound(all(s), x);
        shrine--;
        sum1 += abs(x - *shrine);
        auto templer = lower_bound(all(t), *shrine);
        auto templel = templer--;
        sum1 += min(abs(*shrine - *templer), abs(*shrine - *templel));

        // 右神社、近い寺
        ll sum2 = 0;
        shrine = lower_bound(all(s), x);
        sum2 += abs(x - *shrine);
        templer = lower_bound(all(t), *shrine);
        templel = templer--;
        sum2 += min(abs(*shrine - *templer), abs(*shrine - *templel));

        // 左寺、近い神社
        ll sum3 = 0;
        auto temple = lower_bound(all(t), x);
        temple--;
        sum3 += abs(x - *temple);
        auto shriner = lower_bound(all(s), *temple);
        auto shrinel = shriner--;
        sum3 += min(abs(*temple - *shriner), abs(*temple - *shrinel));

        // 右寺、近い神社
        ll sum4 = 0;
        temple = lower_bound(all(t), x);
        sum4 += abs(x - *temple);
        shriner = lower_bound(all(s), *temple);
        shrinel = shriner--;
        sum4 += min(abs(*temple - *shriner), abs(*temple - *shrinel));

        ll ans = min({sum1, sum2, sum3, sum4});

        cout << ans << endl;
    }

    return 0;
}

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

vector<int> get_divisor(int a, int b, int k) {
  vector <int> d;
  int n;
  if (a > b) n=a;
  else n=b;
  
  int cnt = 0;
  for (int i=n; i>0; i--) {
  	if ((a % i) == 0 & (b % i) == 0) {
      d.push_back(i);
      cnt++;
    }
    if (cnt == k) break;
  }
  return d;
}

int main() {
  int A,B,K,cnt;
  cin >> A >> B >> K;
  auto a_divisor = get_divisor(A,B,K);  
  cout << a_divisor.at(K-1) << endl;
}

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if (abs(x - a) < abs(x - b))
        cout << "A" << endl;
    else
        cout << "B" << endl;
    return 0;
}


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

int main(){
        int w,h;
        cin>>h>>w;
        string z[h];
        for(int i=0;i<h;i++)
              cin>>z[i];
        for(int i=0;i<h;i++)
                cout<<z[i]<<endl<<z[i]<<endl;


}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#define PI 3.141592653589793238462643383279


void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}

int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main(void){
	char s[100001];
	scanf("%s", &s);
	int zero=0;
	int one=0;
	for(int i=0;i<strlen(s);i++){
		if(s[i]=='0')	zero++;
		else one++;
	}
	if(zero<one)	printf("%d", zero*2);
	else	printf("%d", one*2);
	
  	//printf("%d", '0');
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100010];
int a[100010],b[100010];
int main()
{
	int n,t1,t2,i;
	scanf("%s",s+1);
	n=strlen(s+1);
	t1=0;
	for(i=1;i<=n;i++)
	{
		a[i]=i%2;
	}
	t2=0;
	for(i=1;i<=n;i++)
	{
		b[i]=(i+1)%2;
	}
	for(i=1;i<=n;i++)
	{
		if((s[i]-'0')!=a[i])t1++;
	}
	for(i=1;i<=n;i++)
	{
		if((s[i]-'0')!=b[i])t2++;
	}
	printf("%d",min(t1,t2));
	return 0;
}

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

int main(){
    int n; cin >> n;
    int a[100000];
    rep(i, n){
        cin >> a[i];
    }

    map<int, int> mp;
    rep(i, n){
        mp[a[i]]++;
    }

    int ans = 0;
    for(auto p:mp){
        int x = p.first;
        int nx = p.second;
        if (nx<x) ans += nx;
        else ans += nx-x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5120
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    li = [(k, v) for k, v in c.items() if v >= 2]
    li.sort(reverse=True)
    if li and li[0][1] >= 4:
        return print(li[0][0] * li[0][0])
    elif len(li) <= 1:
        return print(0)
    else:
        return print(li[0][0] * li[1][0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 68760
package main

import (
	"fmt"
)

func opreation(a, b int, op string) int {
	var number int
	if op == "+" {
		number = a + b
	} else if op == "-" {
		number = a - b
	} else if op == "*" {
		number = a * b
	} else if op == "/" {
		number = a / b
	}

	return number
}

func main() {
	var a, b int
	var op string
	var numbers []int
	numbers = make([]int, 0, 20000)
	for i := 0; i < 5000; i++ {
		fmt.Scanf("%d", &a)
		fmt.Scanf("%s", &op)
		if op == "?" {
			break
		}

		fmt.Scanf("%d\n", &b)
		numbers = append(numbers, opreation(a, b, op))

	}
	for _, v := range numbers {
		fmt.Println(v)
	}

}


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

using namespace std;

int main() {
    string name;
    cin>>name;
    long long sum=0;
    for(int i=0;i<name.size();i++)
    {
        int x=name[i]-'0';
        sum+=x;
    }
    (sum%9==0)?cout<<"Yes\n":cout<<"No\n";
  
	return 0;
}


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int&v : h) cin >> v;
  vector<int> bad(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (h[a] >= h[b]) bad[b] = 1;
    if (h[b] >= h[a]) bad[a] = 1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans += !bad[i];
  cout << ans << endl;
}


Measured memory_bytes: 4000
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define INF 1e15
typedef long long llong;
using namespace std;

int main(){
	llong n,a[5];
	cin>>n;
	llong tmp=INF;
	REP(i,5){
		cin>>a[i];
		tmp=min(tmp,a[i]);
	}
	
	llong time=5-1+n/tmp+(n%tmp?1:0);
	
	cout<<time<<endl;
	return 0;
}

Measured memory_bytes: 256