akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int A[10000000], n;

int binary (int key) {
    int mid;
    int left = 0;
    int right = n;
    while (left < right) {
        mid = (right + left) / 2;
        if ( key == A[mid]) return 1;
        if ( key > A[mid]) left = mid + 1;
        else if (key < A[mid]) right = mid;
    }
    return 0;
}

int main () {
    int i;
    int q, k;
    int sum = 0;

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

    scanf("%d",&q);
    for ( i = 0; i < q; i++) {
        scanf("%d",&k);
        if (binary(k)) sum++;
    }
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 2132
N = int(input())

#約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

yaku = make_divisors(N)
if len(yaku) % 2 != 0:
    ans = yaku[-1]*2 - 2
    print(ans)
else:
    ans = yaku[-1] + yaku[-2] -2
    print(ans)

Measured memory_bytes: 3268
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

void solv() {

	ll l, r;
	cin >> l >> r;

	ll bef = INF;
	ll v = 0;
	for (ll i = l; i < min(l + 2019,r); i++)
	{
		for (ll j = i + 1; j <= min(l + 2019,r); j++)
		{
			if (bef > (i * j) % 2019) {
				bef = (i * j) % 2019;
			}
		}

	}

	cout << bef << endl;
}

int main() {
	COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 5120
//I love Nanami Chiaki
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pli pair<ll,int>
#define mp make_pair
#define fst first
#define snd second
const int maxn=1e5+7;
int n;
ll d[maxn];
pli sx[maxn];
int sz[maxn];
ll dis[maxn];
int findit(ll t){
	if (t<0) return -1;
	int l=0,r=n-1,mid;
	while (l<=r){
		mid=(l+r)>>1;
		if (sx[mid].fst==t) return mid;
		if (sx[mid].fst<t) l=mid+1;
		else r=mid-1;
	}
	return -1;
}
void badend(){
	puts("-1");
	exit(0);
}
vector<pii> ans;
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%lld",d+i);
		sx[i]=mp(d[i],i);
		sz[i]=1;dis[i]=0;
	}
	sort(sx,sx+n);
	for (int i=n-1;i>0;i--){
		int v=sx[i].snd;
		ll w=sx[i].fst;
		int u=findit(w+1ll*sz[v]*2-n);
		if (u==-1) badend();
		u=sx[u].snd;
		sz[u]+=sz[v];
		ans.push_back(mp(u+1,v+1));
		dis[u]+=dis[v]+sz[v];
	}
	if (dis[sx[0].snd]!=sx[0].fst) badend();
	for (int i=0;i<n-1;i++){
		printf("%d %d\n",ans[i].fst,ans[i].snd);
	}
	return 0;
}

Measured memory_bytes: 5876
/*input
30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr
*/
#include<bits/stdc++.h>
#define ull         unsigned long long
#define ll             long long
#define M             1000000007
#define pb             push_back
#define p_q         priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()    
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp             make_pair
#define lb             lower_bound
#define ub            upper_bound
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)    for(ll int i=0;i<n;i++) a[i]=0;
#define F            first
#define S            second
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

bool DEBUG = 0;

void solve()
{
    //initialize();
    ll n,k;cin>>n>>k;
    ll r,s,p;cin>>r>>s>>p;
    string t ; cin>>t;
    ll dp[n][3];
    rep(i,0,k)
    {
        dp[i][0] = dp[i][1] = dp[i][2] = 0;
        if (t[i] == 'r')
            dp[i][1] = p;
        if (t[i] == 'p')
            dp[i][2] = s;
        if (t[i] == 's')
            dp[i][0] = r;
    }
    rep(i,k,n)
    {
        dp[i][0] = dp[i][1] = dp[i][2] = max(max(dp[i-k][0] ,dp[i-k][1] ) , dp[i-k][2]);
        if (t[i] == 'r')
            dp[i][1] = p + max(dp[i-k][0] , dp[i-k][2]);
        if (t[i] == 'p')
            dp[i][2] = s + max(dp[i-k][1] , dp[i-k][0]);
        if (t[i] == 's')
            dp[i][0] = r + max(dp[i-k][2] , dp[i-k][1]);
    }
    ll ans = 0;
    p = (n+k-1)/k;p--;

    rep(i,0,k)
    {
        if ((i+1) + (p * k) <= n)
            ans += max(max(dp[(i) + (p * k)][0] , dp[(i) + (p * k)][1]) , dp[(i) + (p * k)][2]);
        else
            ans += max(max(dp[(i) + ((p-1) * k)][0] , dp[(i) + ((p-1) * k)][1]) , dp[(i) + ((p-1) * k)][2]);
    }
    cout<<ans<<"\n";
}


int main(void)
{
    ios
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 6116
class String
  def to_ia
    self.split(/\s+/).map {|s| s.to_i}
  end
end
 
class Array
  def rsort
    self.sort {|a, b| b <=> a}
  end

  def swap(i, j)
    t = self[i]
    self[i] = self[j]
    self[j] = t
  end
end

def bubble_sort(ary)
  n = ary.size
  flag = true
  while flag
    flag = false
    (1...n).to_a.rsort.each do |i|
      if ary[i][1].to_i < ary[i-1][1].to_i
        ary.swap(i, i-1)
        flag = true
      end
    end
  end
end
 
def selection_sort(ary)
  n = ary.size
  (0...n).each do |i|
    min = i
    (i...n).each do |j|
      if ary[j][1].to_i < ary[min][1].to_i
        min = j
      end
    end
    ary.swap(i, min) unless i == min
  end
end
 
STDIN.readline
line = STDIN.readline

ary_b = line.split(/\s/)
bubble_sort ary_b
puts ary_b.join(" ")
puts "Stable"

ary_s = line.split(/\s/)
selection_sort ary_s
puts ary_s.join(" ")
puts ary_s == ary_b ? "Stable" : "Not stable"

Measured memory_bytes: 8800
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  string s;
  cin >> s;
  if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(2)==s.at(3)) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = gets.chomp.split.map(&:to_i)
x3, y3 = (y1 - y2) + x2, (x2 - x1) + y2
x4, y4 = (y2 - y3) + x3, (x3 - x2) + y3
puts [x3, y3, x4, y4].join(' ')


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int a=0,b=0,c=0;
    if(n==3 && s[0]==s[2])
        {cout<<"Yes\n";return 0;}
    for(int i=0;i<(n-1)/4;i++)
    {
        if(s[i]!=s[(n-1)/2-i-1])
            {a++;break;}
    }
    for(int i=0;i<(n-1)/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            b++;break;
        }
    }
    int x=0;
    for(int i=(n+3)/2-1;i<(3*n+3)/4;i++)
    {
        if(s[i]!=s[n-x-1])
        {
            c++;break;
        }
        x++;
    }
    //cout<<a<<" "<<b<<" "<<c<<"\n";
    if(a==0 && b==0 && c==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

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

#define pb push_back
#define ff first
#define ss second
#define N 1503
#define mod 1000000007
#define fo(n) for(int i=1;i<=n;i++)
typedef pair<int,int> pii;
typedef long long int ll;
typedef long int li;
int mod1 = 998244353;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n,x,y,d;
    cin>>n>>x>>y;
    map<int,int> m;
    for(int i=1;i<=n;i++) {
        for(int j = i+1;j<=n;j++) {
            d = min(j-i,abs(x-i) + 1 + abs(y - j));
            m[d]++;
        }
    }
    for(int k =1;k<n;k++) cout<<m[k]<<"\n";
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int L[110];
long long int D[110];
int main() {
    int N,X;
    cin >> N >> X;
    for (int i=1; i<=N; i++) cin >> L[i];

    D[1]=0;
    for (int i=2; i<=(N+1); i++) {
        D[i]=D[i-1]+L[i-1];
    }

    int cnt=0;
    for (int i=1; i<=(N+1); i++) {
        if (D[i] <= X) cnt++;
        else break;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main(){
  char s[111111];
  cin >> s;
  bool ans = true;
  char d[]="dream", der[]="dreamer", e[]="erase", eer[]="eraser";
  while(1){
    int l = strlen(s);
    if(strcmp(&s[l-5],d)==0) s[l-5]=0;
    else if(strcmp(&s[l-7],der)==0) s[l-7]=0;
    else if(strcmp(&s[l-5],e)==0) s[l-5]=0;
    else if(strcmp(&s[l-6],eer)==0) s[l-6]=0;
    else {
      ans = false;
      break;
    }
    if(strlen(s)==0)break;
  }
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

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

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

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;


int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
    ll l,r;
    std::cin>>l>>r;
    if(r-l>=2018){
        std::cout<<0;
    }else{
        ll ans=2020;
        rep(i,l,r+1){
            rep(j,i+1,r+1){
                ans=std::min(ans,(ll)((i*j)%2019));
            }
        }
        std::cout<<ans;
    }
    return 0;
}

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

int main(){
  int n, t, i, dr;
  int mx_el = 0;

  cin>>n;
  int r[n];
  for (t = 0; t < n; t++) {
    cin>>r[t];
  }

  int mx = r[1] - r[0];

  for(t = n-1; t > 1; t--){
    if(r[t] > mx_el){
      mx_el = r[t];
      for(i = 0; (i < t); i++){
        dr = r[t] - r[i];
        if(dr > mx) mx = dr;
      }
    }
  }

  cout<<mx<<endl;
}

Measured memory_bytes: 1940
def time_shift(s):
    time={}
    time["hour"]=(s//3600)
    time["munite"]=((s%3600)//60)
    time["second"]=((s%3600)%60)
    return time
def Watch():
    S=int(input())
    time=time_shift(S)
    print("{}:{}:{}".format(time["hour"],time["munite"],time["second"]))

if __name__ == "__main__":
    Watch()


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	bool elf = false;
	for (int i = 1; i <= 9; ++i) {
		if (n % i == 0) {
			string a =to_string( n / i );
			if (a.size() == 1) elf = true;
		}
	}
	if (elf) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

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

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

int main(void){

    string str;
    cin >> str;

    if(str.back()-'0' == 2 || str.back()-'0' == 4 || str.back()-'0' == 5 || str.back()-'0' == 7 || str.back()-'0' ==  9) cout << "hon" << endl;
    else if(str.back()-'0' == 0 || str.back()-'0' == 1 || str.back()-'0' == 6 || str.back()-'0' == 8) cout << "pon" << endl;
    else cout << "bon" << endl;

    return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        int cnt = 0;
        while (true) {
            if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
                System.out.println(cnt);
                return;
            }
            if (a == b && b == c) {
                System.out.println(-1);
                return;
            }
            long tmpa = (b + c) / 2;
            long tmpb = (c + a) / 2;
            long tmpc = (a + b) / 2;
            a = tmpa;
            b = tmpb;
            c = tmpc;
            cnt++;
        }
    }

}


Measured memory_bytes: 23124
s=input()
flg=0
i=0

while i<len(s):
	if (i%2==0 and s[i]=="L") or i%2!=0 and s[i]=="R":
		flg=1
		break
	i+=1
	
if flg==0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
// https://atcoder.jp/contests/abc096/tasks/abc096_a

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;

template <class T>
inline bool chmax(T& a, T b);
template <class T>
inline bool chmin(T& a, T b);

void solve() {
  ll a, b;
  cin >> a >> b;

  ll res = a <= b ? a : a - 1;
  cout << res << endl;
}

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
#endif

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


Measured memory_bytes: 256
N=int(input())
S=input()
ans = ""
for ch in S:
    if ("a" <= ch and ch <= "z"):
        ans += chr((ord(ch) - ord('a') + N) % 26 + ord('a'))
    elif ("A" <= ch and ch <= "Z"):
        ans += chr((ord(ch) - ord('A') + N) % 26 + ord('A'))
    elif ('0' <= ch and ch <= '9'):
        ans += chr((ord(ch) - ord('0') - N) % 10 + ord('0'))

print(ans)


Measured memory_bytes: 3064
N, K = map(int, input().split())
Range = [None] * K

for i in range(K):
    Range[i] = list(map(int, input().split()))

sweep = {1: 1}
M = 998244353

value = 0
for cell in range(1, N+1):
    value += sweep.get(cell, 0)
    value = (value + M) % M
    for r in range(K):
        sweep[cell + Range[r][0]] = (sweep.get(cell + Range[r][0], 0) + value + M) % M
        sweep[cell + Range[r][1] + 1] = (sweep.get(cell + Range[r][1] + 1, 0) - value + M) % M

print(sweep.get(N, 0))

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

int main()
{
  int a, b;
  cin >> a >> b;
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    map<ll,ll>m;
    rep(i,N){
        ll a;
        cin>>a;
        m[a]++;
    }
    ll ans=0;
    for (const auto& [key, value] : m){
        if(value>=key){
            ans+=value-key;
        }else{
            ans+=value;
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 9444
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>

signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> res;
  for (int i = 1; i <= max(a, b); i++) {
    if (a % i == 0 and b % i == 0) res.push_back(i);
  }
  reverse(ALL(res));
  cout << res[c-1] << endl;
  ret;
}


Measured memory_bytes: 3564
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

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

VL prime_decomposition(ll n) {
	ll i = 2;
	VL table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace_back(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace_back(n);
		return table;
	}
}

int main() {
	string str;
	cin >> str;

	ll s = str.size();
	REP(i, s) {
		if (i < s - 1 && str[i] == str[i + 1]) {
			cout << i+1 << " " << i + 2 << endl;
			return 0;
		} else if (i < s - 2 && str[i] == str[i + 2]) {
			cout << i+1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, K, Q, ans=INF, tmp=0;
vector<ll> A;

signed main(){
    cin >> N >> K >> Q;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    for(int i=0;i<N;i++) {
        vector<ll> v, p;
        for(int j=0;j<N;j++) {
            if(A[j]<A[i]) {
                if(v.size()>=K) {
                    sort(v.begin(), v.end());
                    for(int l=0;l<v.size()-K+1;l++) {
                        p.push_back(v[l]);
                    }
                }
                v.clear();
                continue;
            }
            v.push_back(A[j]);
        }
        if(v.size()>=K) {
            sort(v.begin(), v.end());
            for(int l=0;l<v.size()-K+1;l++) {
                p.push_back(v[l]);
            }
        }
        if(p.size()>=Q) {
            sort(p.begin(), p.end());
            ans = min(ans, p[Q-1]-p[0]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <cstdio>
#include <vector>
#include <algorithm>

#define MOD 1000000007

typedef long long ll;

using namespace std;

int main() {
    ll n, ans = 1;
    scanf("%lld", &n);
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) scanf("%lld", a.begin() + i);
    sort(a.begin(), a.end());
    for (ll i = n - 1; i >= 0; --i) {
        if (a.at(i) != (i + n % 2) / 2 * 2 + (n - 1) % 2) {
            printf("0\n");
            return 0;
        }
    }
    for (ll i = 0; i < n / 2; ++i) ans = ans * 2 % MOD;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
n = gets.strip.to_i
array = gets.split.map(&:to_i)
puts array.join(' ') 
 
for i in 1..n-1 do
  key = array[i]
  j = i
  while j > 0 && array[j-1] > key do
    array[j] = array[j-1]
    j -= 1
  end
  array[j] = key
  puts array.join(' ')
end

Measured memory_bytes: 8776
from collections import Counter
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
cd=Counter(d)
ct=Counter(t).most_common()
for i,j in ct:
    if cd[i]<j:
        print("NO")
        break
else:print("YES")

Measured memory_bytes: 69080
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    D = list(map(int, input().split()))
    D.sort()

    i = N//2

    if D[i] == D[i-1]:
        print(0)
        return
    
    print(D[i]-D[i-1])

if __name__ == "__main__":
    solve()


Measured memory_bytes: 14428
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void solve() {
	lli n;
	cin >> n;
	lli ret = 0;
	for (lli i = 1; i <= n; i++) {
		if (i % 5 == 0 || i % 3 == 0) {

		} else ret += i;
	}
	cout << ret << endl;
}
void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 3612
#pragma optimization_level 3
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  1e+9 + 7;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ll n,a[N];
string s;

const ll N2 = 1e7+8;
ll p[N2];
void sieve(){
    for(ll i = 2; i*i <= N2; i++){
        if(p[i] == 0){
            for(ll j = 2*i; j < N2; j += i){
                if(p[j]==0) p[j]=i;//for spf
            }
        }
    }

    
    foo(i,1,N2-1) if(p[i]==0) p[i]=i;  // all numbers with p[i]=i, are primes
}

vector<pair<ll,ll>> prime_factorise(ll n){
    vector<pair<ll,ll>> pf;
    while(n>1){
        if(pf.size() && pf.back().f==p[n]) {
            pair<ll,ll> p = pf.back();
            pf.pop_back();
            pf.push_back({p.f,p.s+1});
        }else{
            pf.push_back({p[n],1});
        }
        n/=p[n];
    }
    return pf;
}

void MAIN(int tc){
	cin >> n;
    ll res = 0;
    for(int c = 1; c <= n - 1; c++){
        ll r = n - c, cnt = 1;
        vector<pair<ll,ll>> pf = prime_factorise(r);
        for(auto [a, b]: pf) cnt *= (b + 1);
        res += cnt;
    }
    deb1(res);
}

int main(){
    ios:: sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed; cout<<setprecision(10);

    sieve();
    int test_cases = 1;
    //cin>>test_cases;
    for(int i = 1; i <= test_cases; i++){
        MAIN(i);
    }
}

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

using namespace std;
const int N = 100000+5;

int main () {
    // L_i = gcd(A_1, A_2, A_3, ... A_i)
    // R_i = gcd(A_i, A_{i+1}, A_{i+1}, ..., A_n)
    int n;
    int A[N];
    int R[N];
    int L[N];

    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> A[i];
        L[i] = A[i];
        R[i] = A[i];
    }

    // precomputing L[i]
    for (int i=1; i<=n; i++) {
        L[i] = __gcd(L[i], L[i-1]);
    }
    // precomputing R[i]
    for (int i=n; i>0; i--) {
        R[i] = __gcd(R[i], R[i+1]);
    }

    // computing each m_i and the max value
    int res = 0;
    for (int i=1; i<=n; i++) {
        int m = __gcd(L[i-1], R[i+1]);
        if (m > res) {
            res = m;
        }
    }

    cout << res;
    return 0;
}

Measured memory_bytes: 4748
import sys
sys.setrecursionlimit(10 ** 6)

n,q = map(int,input().split())

#木構造の構築
edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x#根の部分にカウント

def dfs(now,prev):
    for next in edges[now]:#nowに直接つながる子を順番に参照
        if next == prev: #edgeでは子と親の関係が明示されていないので親につながる情報は無視
            continue
        counter[next] += counter[now]
        dfs(next,now)#行きがかり順にカウント

dfs(0,-1)
print(*counter)



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

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i=0; i<n; i++){
        if(x==v.at(i)){
            ans++;
            break;
        }else if(x<v.at(i)){
            break;
        }else{
            x -= v.at(i);
            if(i<n-1) ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
C - Same Integers
https://beta.atcoder.jp/contests/abc093/tasks/arc094_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(numbers):
    ans = 0
    while numbers[0] != numbers[1] or numbers[0] != numbers[2]:
        numbers.sort()
        if numbers[0] + 2 <= numbers[2]:
            numbers[0] += 2
            ans += 1
        else:
            numbers[0] += 1
            numbers[1] += 1
            ans += 1
    return ans


def main(args):
    numbers = [int(x) for x in input().split()]
    ans = solve(numbers)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3064
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) - 1 for _ in range(D)]
M = int(input())

d = []
q = []
for _ in range(M):
    d_, q_ = map(int, input().split())
    d.append(d_ - 1)
    q.append(q_ - 1)

N = 26


def calc_score(t):
    scores = [0] * N
    last = [-1] * N
    for d in range(D):
        last[t[d]] = d
        scores[t[d]] += s[d][t[d]]

        for i in range(N):
            if last[t[d]] != -1:
                scores[i] -= c[i] * (d - last[i])
    return sum(scores)


score = calc_score(t)


for di, qi in zip(d, q):
    # delete
    old_type = t[di]

    for next_d in range(di + 1, D):
        if t[next_d] == old_type:
            break
    else:
        next_d = D

    for prev_d in range(di - 1, -1, -1):
        if t[prev_d] == old_type:
            break
    else:
        prev_d = -1

    score -= s[di][old_type]
    score -= (next_d - di) * (di - prev_d) * c[old_type]

    # insert
    for next_d in range(di + 1, D):
        if t[next_d] == qi:
            break
    else:
        next_d = D

    for prev_d in range(di - 1, -1, -1):
        if t[prev_d] == qi:
            break
    else:
        prev_d = -1

    score += s[di][qi]
    score += (next_d - di) * (di - prev_d) * c[qi]

    print(score)

    t[di] = qi


Measured memory_bytes: 83452
#include <bits/stdc++.h>
using namespace std;
int32_t main(){
  const int32_t INF=1<<30;
  int32_t n; cin>>n;
  vector<int32_t> a(n);
  for(auto&& x:a) cin>>x;
  vector<int32_t> dp(n,INF);
  for(const auto& x:a) *lower_bound(begin(dp),end(dp),x)=x;
  cout<<(lower_bound(begin(dp),end(dp),INF)-begin(dp))<<endl;
}


Measured memory_bytes: 3612
N, W = map(int, input().split())
v = []
w = []
for i in range(N):
    x, y = map(int, input().split())
    v.append(x)
    w.append(y)

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if w[i] <= j:
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i])
        else:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

ans = dp[N][W]
print(ans)


Measured memory_bytes: 15692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}


int main(){
	int x,a,b; cin>>x>>a>>b;
	cout << (abs(x-a)<abs(x-b) ? "A": "B") << endl;
}

Measured memory_bytes: 3508
import std.conv, std.stdio;
import std.algorithm, std.array, std.string, std.range;
void main()
{
    readln;
    auto a = readln.chomp.split.to!(int[]);
    "%(%d\n%)".writefln(a.solve);
}
ulong[] solve(in int[] a)
{
    size_t[int] d;
    foreach (x; a)
        if (auto p = x in d)
            (*p)++;
        else
            d[x] = 1;
    auto s = d.byValue.map!(c => c * (c - 1) / 2).sum;
    ulong[] ret;
    foreach (x; a)
        ret ~= s - (d[x] - 1);
    return ret;
}


Measured memory_bytes: 27280
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N = I()
S = input()

for s in S:
    print(chr(65 + (ord(s) - 65 + N) % 26), end="")


Measured memory_bytes: 42472
#include <stdio.h>
#include <stdlib.h>
 
  int main (void){
   int A,B,C;
   
   scanf("%d %d %d",&A,&B,&C);
   
   if(-100>=A,B,C || A,B,C>=100){
   exit(0);
   }
   
   if(C>=A && C<=B){
   printf("Yes");
   return 0;
   }else{
   printf("No");
   return 0;
   }
  }

Measured memory_bytes: 128
#include <stdio.h>


int main(){
	int n;
	char str[50010];
	int x = 0;
	int ctr = 0;
	scanf("%d", &n);
	scanf("%s", str);

for(int i = 0;i < 10;i++){
	for(int j = 0;j<10;j++){
		for(int k = 0;k<10;k++){
			char test[] = {i,j,k};
		    x = 0;
			for(int a = 0;a <n;a++){
				if(str[a] - '0' == test[x]){
					x++;
				}
				if(x == 3){
					ctr++;
					break;
				}
			}
			
		}
	}
}
printf("%d", ctr);
	return 0;
}

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

int main(){
 	string s;
  	cin >> s;
	int t=700;
  	for(int i = 0; i < 3; i++) {
		if(s[i] == 'x')
          	continue;
      	t+=100;
	}
  	cout << t << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
L n;
int main(){
    while(scanf("%lld",&n)&&n){
        L ar[n+1],sum=0;
        for(L i=0;i<n;i++){
            scanf("%lld",&ar[i]);
        }
        sort(ar,ar+n);
        for(L i=1;i<n-1;i++)sum+=ar[i];
        cout<<sum/(n-2)<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3204
#include <cstdio>
#include <cstring>
#define HW_MAX 300

void
set_line(char *s, int w, int p_start_with_sharp) {
  int i;
  for (i = 0; i < w; i++) {
    if (i % 2 == p_start_with_sharp) {
      s[i] = '.';
    } else {
      s[i] = '#';
    }
  }
  s[i] = '\0';
  return;
}

int
main(void)
{
  int h, w, i;
  char s0[HW_MAX + 1], s1[HW_MAX + 1];
  
  while (std::scanf("%d %d", &h, &w) != EOF) {
    if (h == 0 && w == 0) {
      break;
    }

    set_line(s0, w, 0);
    set_line(s1, w, 1);

    for (i = 0; i < h; i++) {
      if (i % 2 == 0) {
        std::printf("%s\n", s1);
      } else {
        std::printf("%s\n", s0);
      }
    }
    std::printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2604
#include <iostream>

using namespace std;

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

    int a = n, b = 0;
    while (a > 0) {
        b += a % 10;
        a /= 10;
    }

    if (n % b == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

h, w = na()
maze = nsn(h)

def bfs():
    q = deque()
    q.append((0, 0))
    dx, dy = [1, 0, 0, -1], [0, 1, -1, 0]
    dist = [[inf] * w for _ in range(h)]
    dist[0][0] = 0
    while len(q):
        p = q.popleft()
        cx, cy = p
        for i in range(4):
            nx, ny = cx + dx[i], cy + dy[i]
            if nx >= 0 and nx < w and ny >= 0 and ny < h and dist[ny][nx] == inf and maze[ny][nx] != '#':
                dist[ny][nx] = dist[cy][cx] + 1
                q.append((nx, ny))
    return dist[h - 1][w - 1]

cnt = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == '#':
            cnt += 1

d = bfs()
if d == inf:
    print(-1)
else:
    print(h * w - cnt - d - 1)

Measured memory_bytes: 40432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

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

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<int> a(n);
  map<int,int> m;
  ll ans=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    ans+=a[i];
    if(m.find(a[i])==m.end()){
      m[a[i]]=1;
    }else{
      m[a[i]]++;
    }
  }
  int q;cin>>q;
  for(int i=0;i<q;i++){
    int b,c;cin>>b>>c;
    if(m.find(b)==m.end()){
      ;
    }else{
      if(m.find(c)==m.end()){
        m[c]=m[b];
      }else{
        m[c]+=m[b];
      }
      ans+=(c-b)*m[b];
      m.erase(b);
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 6536
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	bw = bufio.NewWriter(os.Stdout)
)

const cap = 1e5

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func sieveOfEratosthenes(n int) []bool {
	res := make([]bool, n+1)
	res[0], res[1] = true, true
	for i := 2; i*i <= n; i++ {
		if res[i] == false {
			for j := i * i; j <= n; j += i {
				res[j] = true
			}
		}
	}
	return res
}

func main() {
	defer bw.Flush()
	sc.Split(bufio.ScanWords)

	primes := sieveOfEratosthenes(cap + 10)

	cumSum := make([]int, cap+10)
	for i := 3; i <= cap; i++ {
		if i%2 == 1 && !primes[i] && !primes[(i+1)/2] {
			cumSum[i]++
		}
		cumSum[i] += cumSum[i-1]
	}

	q := ri()
	for i := 0; i < q; i++ {
		l, r := ri(), ri()
		fmt.Fprintln(bw, cumSum[r]-cumSum[l-1])
	}
}


Measured memory_bytes: 2688
fun main() {
    // 文字列
    var n = readLine()!!.toInt()
//    val x: String = readLine()!!
    // 数値
//    val int =readLine()!!.toInt()
    // 行
//    val list = readLine()!!.split(" ").map (String::toInt )
    val list = readLine()!!.split(" ").map(String::toInt)
//    val xys = List(n) {
////        readLine()!!.split(" ").map(String::toLong)
//        readLine()!!.toDouble()
//    }
    if (n<=2) {
        print(0)
        return
    }
    list.sorted()
    var count = 0
    for (i in list) {
        for (j in list) {
            for (k in list) {
                if (i != j && j != k && k != i) {
                    if (Math.abs(i - j) < k && k < i + j) {
                        count++
                    }
                }
            }
        }
    }
    print(count/6)
}


Measured memory_bytes: 41500
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"

using namespace std;

int N;
int num[100];
int box;
int ans;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> num[i];
	}
	ans = INT_MAX;
	for (int i = -100; i <= 100; i++) {
		box = 0;
		for (int j = 0; j < N; j++) {
			box += pow(abs(i - num[j]), 2);
		}
		ans = min(box, ans);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

template <class T>
struct BIT {
	vector<T> data;
	BIT(int n) {
		data.assign(n, 0);
	}

	T sum (int i) {
		T res = 0;
		while (i > 0) {
			res += data[i];
			i -= i & -i;
		}
		return res;
	}

	void add(int i, T x) {
		while (i < data.size()) {
			data[i] += x;
			i += i & -i;
		}
	}
};

int main() {
	int N, Q;
	cin >> N >> Q;
	BIT<Int> bit(N + 1);
	for (int i = 0; i < N; ++i) {
		Int a; cin >> a;
		bit.add(i + 1, a);
	}
	vector<Int> ans;
	for (int i = 0; i < Q; ++i) {
		int q, a, b;
		cin >> q >> a >> b;

		if (q) {
			ans.emplace_back(bit.sum(b) - bit.sum(a));
		} else {
			bit.add(a + 1, b);
		}
	}

	for (auto v : ans) { cout << v << "\n"; }

	return 0;
}


Measured memory_bytes: 10272
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

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

ll gcd(ll a, ll b) {return (b==0)?a:gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*(b/gcd(a, b));}

int main(void)
{
    int N;
    cin >> N;
    int n = 1000005;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    
    ll g = gcd(A[0], A[1]);
    Rep(i, 1, N-1){
        g = gcd(g, A[i+1]);
    }

    vector<int> s(n);
    REP(i, N){
        auto p = prime_factor(A[i]);
        REPA(x, p){
            s[x.fi]++;
        }
    }

    int d = 1;
    Rep(i, 1, n){
        chmax(d, s[i]);   
    }

    if(d==1) pr("pairwise coprime");
    else if(g == 1){
        pr("setwise coprime");
    }else{
        pr("not coprime");
    }
}

Measured memory_bytes: 11116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e9

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

string s;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	int n = s.size();
	for(int i = 0; i < n-1; i++){
		if(s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
	}
	for(int i = 0; i < n-2; i++){
		if(s[i]==s[i+2]){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<"-1 -1";
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ll n;
	cin >> n;
	vector <ll> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z];
	}
	ll ans = 0;
	while (true){
		bool ok = false;
		for (int z=0;z<n;z++){
			if (arr[z] != 0) {
				ok = true;
				break;
			}
		}
		if (!ok) break;
		ll mini = LLONG_MAX;
		for (int z=0;z<n;z++){
			if (arr[z] == 0){
				if (mini == LLONG_MAX) continue;
				for (int x=z-1;x > -1;){
					arr[x] -= mini;
					x--;
					if (arr[x] == 0) break;
				}
				ans += mini;
				mini = LLONG_MAX;
			}
			else mini = min(mini,arr[z]);
		}
		if (mini != LLONG_MAX){
			for (int x=n-1;x>-1;){
			arr[x] -= mini;
			x--;
			if (arr[x] == 0) break;
		}
		ans += mini;
		}
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
let kawaisou a b c = 
    match a, b, c with
        | a, b, c when a != b && b != c && a != c -> "No"
        | a, b, c when a = b && b != c -> "Yes"
        | a, b, c when a != b && b = c -> "Yes"
        | a, b, c when a = c && b != c -> "Yes"
        | _ -> "No";;

let () = print_endline (Scanf.scanf "%d %d %d" kawaisou);;


Measured memory_bytes: 384