akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> data(N);
    bool judge = 0;
    for (int i = 0; i < N; i++){
        cin >> data.at(i);
    }
    sort(data.begin(), data.end());
    for (int i = 0; i < N-1; i++){
        if(data.at(i)==data.at(i+1))
            judge = 1;
    }
    if(judge)cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include <iostream>

int main()
{
    int a[4], b[4];
    while (std::cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
        int hit = 0, blow = 0;
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 4; ++j) {
                if (a[i] == b[j]) {
                    if (i == j) ++hit;
                    else ++blow;
                }
            }
        }
        std::cout << hit << ' ' << blow << std::endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	long int n,a,b;
	long int x[100000] = {0};

	scanf("%ld %ld %ld", &n,&a,&b);

	for(int i = 0; i < n; i++)
	{
		scanf("%ld", &x[i]);
	}

	long long int sum;

	for(int i = 0; i < n-1; i++)
	{
		sum += min(b, (x[i+1] - x[i]) * a );
	}

	printf("%lld\n", sum);

	return 0;
}
	

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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(){
  while(1){

  int N,M;
  cin >> N >> M;
  if(N==0 && M==0){
    break;
  }
  vector<int> A(M+1,0);
  for(int i=0; i<N; i++){
    int d,v;
    cin >> d >> v;
    chmax(A[d],v);
  }
  int sum=0;
  for(int i=1; i<=M; i++){
    sum += A[i];
  }
  cout << sum << endl;
}
  return 0;
}



Measured memory_bytes: 3088
H, W = map(int,input().split())

sw_list = []
sw_list.append(["."]*(W+2))
[sw_list.append(["."] + list(input()) + ["."]) for _ in range(H)]
sw_list.append(["."]*(W+2))

def check():
    for h in range(1,H+1):
        for w in range(1,W+1):
            if sw_list[h][w] == "#":
                if all([sw_list[h-dh][w-dw]=="." for dh,dw in [(-1,0),(0,-1),(1,0),(0,1)]]):
                    return False
    return True

if check():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 41196
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  int a, b , c;
  cin >> a >> b >> c;
  if((a==b && b!=c) || (b==c && c!=a) || (a==c && a!= b)){
    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++)
typedef long long ll;
using namespace std;
int main()
{
  string s;
  cin >> s;
  if (s.back() == 's')
  {
    cout << s + "es" << endl;
  }
  else
  {
    cout << s + "s" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (int)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int n, k;
	cin >> n >> k;
	vector<int> arr(n), dp(n, INF);
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	dp[0] = 0;
	for(int i = 1; i < n; i++) {
		for(int j = max(0, i-k) ; j < i; j++) {
			dp[i] = min(dp[i], dp[j]+abs(arr[i]-arr[j]));
		}
	}
	cout << dp[n-1] << '\n';

	return 0;
 }


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

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int cnt=0;
    for(int i=0;i<n;i+=2){
        if(a[i]%2==1){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3596
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl
#define pb push_back

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[2];
bool r,ra,rb,rc[200010];
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc,vd,ve,vaa,vbb;

multiset<ll> st;


int main(){
    cin>>n>>m;
    va=vector<ll>(n,0);
    vb=vector<ll>(n,0);
    vc=vector<ll>(n,0);
    for(int i=0;i<n;i++){
        cin>>aa[i];
        st.insert(aa[i]);
        //bin(aa[i],va[i],vb[i],vc[i]);
    }

    for(int i=0;i<m;i++){
        //C *(--st.end());
        int zz=*(--st.end());
        st.erase(--st.end());
        st.insert(zz/2);
    }
    a=0;
    for(auto it=st.begin();it!=st.end();++it){
        a+=*it;
    }
    C a E;
    /*
    sortvecll(vc,va,vb);
    sortvecll(vb,va,vc);

    C va E;
    C vb E;
    C vc E;
    */

    
}


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

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll inc(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll h,n;
 sc(h);sc(n);
 ll a[n+1],sum=0;
 rep(i,0,n){sc(a[i]);sum+=a[i];}
 if(sum>=h)py;else pn;
  
return 0;}

Measured memory_bytes: 4344
#include <bits/stdc++.h>
using namespace std;
long long n,m,p[100007],a[100007],b[100007],c[100007],coun[100007];
long long ans=0;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)  cin>>p[i];
    for(int i=1;i<=n-1;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    for(int i=2;i<=m;i++){
        int l=max(p[i],p[i-1]);
        int k=min(p[i],p[i-1]);
        coun[l]--;
        coun[k]++;
    }
    for(int i=1;i<=n;i++){
        coun[i]+=coun[i-1];
    }
    for(int i=1;i<=n-1;i++){
        ans+=min(a[i]*coun[i],c[i]+(b[i]*coun[i]));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7096
from collections import deque
k = int(input())
queue = deque()
for i in range(1,10):
    queue.append(i)
#print(queue)
#queue = [1,2,3,4,5,6,7,8,9]
x = 0
for i in range(k):
    x = queue.popleft()
    #print(x)
    if x % 10 !=0:
        queue.append(10*x+(x%10)-1)
    queue.append(10*x + x%10)
    if x % 10 != 9:
        queue.append(10*x+(x%10)+1)
print(x)

Measured memory_bytes: 11908
import math
import sys

def p(n, r):
	if n < r:
		return 1
	return math.factorial(n) // math.factorial(n - r)

def main():
	input = sys.stdin.readline
	N,K = map(int,input().split())
	E = [[] for _ in range(N)]
	MOD = 10**9+7
	#辺の定義
	for _ in range(N-1):
	  u,v = map(int,input().split())
	  u -= 1
	  v -= 1
	  E[u].append(v)
	  E[v].append(u)

	if N == 1:
		print(K)
		sys.exit()
	#colorが塗られたかどうか
	color = [-1 for _ in range(N)]
	dp = [-1 for _ in range(N)]
	#dfsで色を塗っていく
	stack = []
	color[u] = 1
	ans = K
	for i,v in enumerate(E[u]):
		stack.append(v)
		ans *= (K-i-1)
		ans %= MOD

	while stack:
		u = stack.pop()
		color[u] = 1
		length = 0
		for v in E[u]:
			if color[v] == -1:
				stack.append(v)
				length += 1
		if dp[length] == -1:
			tmp = 1
			for i in range(K-1-length,K-1):
				tmp *= i
				tmp %= MOD
			#tmp = p(K-2,length) % MOD
			ans *= tmp
			dp[length] = tmp
		else:
			ans *= dp[length]
		ans %= MOD

	#各頂点の色を出力
	print(ans%MOD)

if __name__ == '__main__':
	main()

Measured memory_bytes: 64584
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T, typename U> inline void chmax(T &x, U y) { if (x < y) x = y; }
template<typename T, typename U> inline void chmin(T &x, U y) { if (x > y) x = y; }


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

    int ans = INF;
    rep(i, n) {
        int c, t;
        scanf("%d%d", &c, &t);
        if (t > tt) continue;
        ans = min(ans, c);
    }
    if (ans == INF) {
        cout << "TLE" << "\n";
    }
    else {
        cout << ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
N,Y=map(int,input().split())
a1=-1
a2=-1
a3=-1

for a in range(N+1):
  for b in range(N-a+1):
    c=N-a-b
    if a*10000+b*5000+c*1000==Y:
      a1=a
      a2=b
      a3=c
      break

print(a1,a2,a3)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x;
		x = sc.nextInt();
		while (true) {
			if (x >= 1 && x <= 100) {
				System.out.println(x * x * x);
				break;
			} else {
				continue;
			} 
		}
		sc.close();
	}
}

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

int main(){
  string n;
  cin >> n;
  if(n[1]!=n[2]) {
    cout << "No" << endl;
    return 0;
  }
  if(n[0]==n[1]||n[2]==n[3]){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n-1);
  for(int i=0;i<n-1;i++){
    cin >> a[i];
  }
  vector<int> cou(n);
  for(int i=0;i<n;i++){
    cou[i]=0;
  }
  for(int i=0;i<n-1;i++){
    cou[a[i]-1]++;
  }
  for(int i=0;i<n;i++){
    if(i==n-1){
      cout << cou[i];
    }else{
      cout << cou[i] << endl;
    }
  }
}


Measured memory_bytes: 4844
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
using namespace std;


int main(){
  int a,b,c,k;
  cin >>a>>b>>c>>k;
  if(a>=b&&a>=c) cout <<b+c+a*pow(2,k)<<endl;
  else if (b>=a && b>=c) cout <<a+c+b*pow(2,k)<<endl;
  else cout <<b+a+c*pow(2,k)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
const long long INF = 1LL << 60;
// map<int,int> mp;

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

  if (X >= 30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;

  }
}

Measured memory_bytes: 3640
A, B, C, K = map(int, input().split())

if A == B == C:
    print(0)
elif K == 0:
    if A - B > 10e18:
        print('Unfair')
    else:
        print(A - B)
else: 
    if K % 2 == 0:
        a = K*A + (K-1)*(B+C)
        b = K*B + (K-1)*(A+C)
        c = K*C + (K-1)*(A+B)
    else:
        a = (K-1)*A + K*(B+C)
        b = (K-1)*B + K*(A+C)
        c = (K-1)*C + K*(A+B)
    
    if a - b > 10e18:
        print('Unfair')
    else:
        print(a - b)

Measured memory_bytes: 3064
<?php
// Your code here!
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner();
$a = $sc->nextInt();
$b = $sc->nextInt();

$x = str_repeat(strval($a), $b);
$y = str_repeat(strval($b), $a);

$arr = array($x, $y);

usort($arr, "strnatcmp");

$last = end($arr);


out::println($last);

?>


Measured memory_bytes: 4728
MOD = 10**9 + 7
n, m = map(int, input().split())

ban = [False] * (n + 1)#踏めない階段の配列、最初は全てOK

for i in range(m):
    a = int(input())
    ban[a] = True#壊れている段をTrueに変える

dp = [0] * (n+1)#DPテーブルは余裕が必要
dp[0] = 1#最初は１通り
for i in range(n):
    dp[i] %= MOD#MODで割っておく
    if(ban[i]):dp[i] = 0#壊れている段に行く方法は無い
    if i + 1 <= n:#上がれるのは１段、または２段
        dp[i+1] += dp[i]#配る配列
    if i + 2 <= n:
        dp[i+2] += dp[i]

print(dp[n] % MOD)#n段目に行くのは何通りか

Measured memory_bytes: 7668
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

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

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

    // input
    ll N, M;
    cin >> N >> M;

    string s, t;
    cin >> s >> t;

    ll X_len = lcm(N, M);
    map<ll, char> mp;
    
    // sの分を置いていく
    ll interval = X_len / N;
    FOR(i, 0, s.size()){
        ll index = interval * i;
        mp[index] = s[i];
    }
    // for(auto p : mp){
    //     cout << p.first << " " << p.second << endl;
    // }

    interval = X_len / M;
    FOR(i, 0, t.size()){
        ll index = interval * i;
        if(mp.count(index)==0){
            // 置ける
        }
        else if(mp[index]==t[i]){
            // 置ける
        }else{
            p(-1);
            return 0;
        }
    }

    p(X_len);

    return 0;
}

Measured memory_bytes: 6144
#include<iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
string a;
string::iterator itr;
int aa=0;
bool light;
int main(){
	while(cin>>a){
	itr=a.begin();
	if(*itr=='y'||*itr=='u'||*itr=='i'||*itr=='o'||*itr=='p'||*itr=='h'||*itr=='j'||*itr=='k'||*itr=='l'||*itr=='m'||*itr=='n'){
		light=true;}else
			if(*itr=='#'){break;}else{
		light=false;}
		a.erase(a.begin());
		while(a.size()!=0){
			itr=a.begin();
	if(*itr=='y'||*itr=='u'||*itr=='i'||*itr=='o'||*itr=='p'||*itr=='h'||*itr=='j'||*itr=='k'||*itr=='l'||*itr=='m'||*itr=='n'){
		if(light==false){
		aa++;}light=true;}else{
		if(light==true){
		aa++;}light=false;}
		a.erase(a.begin());}
	cout<<aa<<endl;
	aa=0;}
    return 0;}


Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,m,i,k;
  bool f;
  cin>>n>>m;
  vector<int> x(n,-1);
  vector<int> s(m),c(m);
  f=true;
  for (i=0;i<m;i++) {
    cin>>s.at(i)>>c.at(i);
    if (x.at(s.at(i)-1)==-1) x.at(s.at(i)-1)=c.at(i);
    else if (x.at(s.at(i)-1)!=c.at(i)) {
      f=false;
      break;
    }
  }
  if (f==false) cout<<-1<<endl;
  else if (n>=2 && x.at(0)==0) cout<<-1<<endl;
  else {
    k=0;
    for(i=0;i<n;i++) {
      if (x.at(i)==-1) {
        if (i==0 && n>=2) x.at(i)=1;
        else x.at(i)=0;
      }
      k*=10;
      k+=x.at(i);
    }
    cout<<k<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

int main(void) {

  int n;
  int a[200100];
  cin >> n;
  rep(i, n - 1) {
    cin >> a[i + 1];
    a[i + 1]--;
  }

  int d[200100] = {};
  rep(i, n - 1) {
    d[a[i + 1]]++;
  }

  rep(i, n) cout << d[i] << endl;

}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n;
    cin >> n;
    vector<int> a(3*n);
    for(int i = 0; i < 3*n; i++)
    {
        cin >> a[i];
    }
    priority_queue<int, vector<int>, greater<int>> fq;
    vector<ll> fsum(n+1);
    for(int i = 0; i < n; i++)
    {
        fq.push(a[i]);
        fsum[0] += a[i];
    }
    for(int i = 1; i <= n; i++)
    {
        int pos = a[n-1+i];
        int cand = fq.top();
        if(pos > cand)
        {
            fq.pop();
            fq.push(pos);
            fsum[i] = fsum[i-1] + pos - cand;
        }
        else
        {
            fsum[i] = fsum[i-1];
        }
    }

    priority_queue<int> bq;
    vector<ll> bsum(n+1);
    for(int i = 0; i < n; i++)
    {
        bq.push(a[3*n-1-i]);
        bsum[0] += a[3*n-1-i];
    }
    for(int i = 1; i <= n; i++)
    {
        int pos = a[2*n-i];
        int cand = bq.top();
        if(cand > pos)
        {
            bq.pop();
            bq.push(pos);
            bsum[i] = bsum[i-1] + pos - cand;
        }
        else
        {
            bsum[i] = bsum[i-1];
        }
    }

    ll ans = -1e16;
    for(int i = 0; i <= n; i++)
    {
        ans = max(ans, fsum[i] - bsum[n-i]);
    }
    cout << ans << endl;
}


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

int main() {
	int n;
	cin >> n;
	
	int ren = 0;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		if (a == b) ++ren;
		else ren = 0;
		if (ren == 3) {
			cout << "Yes\n";
			return 0;
		}
	}
	
	cout << "No\n";
	
	return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    int n,x,t;
    cin>>n>>x>>t;

    if(n%x==0) {
        cout<<(n/x*t)<<endl;
    }
    else {
        cout<<((n/x)+1)*t<<endl;
    }
}




Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int A, B;
    cin >> A >> B;
    int a = A / 2;
    int d = 25 * a % 10;
    int t = B - 25 * a / 10;
    if (t < 0) {
        cout << "-1\n";
        return 0;
    }
    if (A % 2 == 0) {
        if (t == 0) {
            cout << 25 * a << "\n";
        } else {
            if (t > 1) cout << "-1\n";
            else {
                cout << 25 * a + 10 - d << "\n";
            }
        }
    } else {
        if (t == 0 || t > 2) {
            cout << "-1\n";
            return 0;
        }
        if (t == 1) {
            cout << 25 * a + 13 << "\n";
        } else {
            cout << 25 * a + 20 - d << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

void partition(int [], int);

int main()
{
  int i, n, A[MAX];

  scanf("%d", &n);

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

  partition(A, n - 1);

  return 0;
}

void partition(int A[], int r){
  int x, i, j, p = 0, change;

  x = A[r];
  i = p - 1;

  for(j = p; j <= r - 1; j++){
    if(A[j] <= x){
      i++;
      change = A[i];
      A[i] = A[j];
      A[j] = change;
    }
  }
  change = A[i + 1];
  A[i + 1] = A[r];
  A[r] = change;

  for(j = 0; j <= r; j++){
    if(j == i + 1)
      printf("[%d] ", A[j]);
    else if(j == r)
      printf("%d\n", A[j]);
    else
      printf("%d ", A[j]);
  }
}


Measured memory_bytes: 2120
import copy
Q = int(input())
lis = []
maximam = 1
for _ in range(Q):
    l, r = map(int, input().split())
    lis.append((l, r))
    maximam = max(maximam, r)
flag_lis = [1] * (maximam+1)
flag_lis[0] = 0
flag_lis[1] = 0
for i in range(2, int((maximam-1)/2)+1):
    if flag_lis[i] != 0:
        for j in range(2*i,maximam+1,i):
            flag_lis[j] = 0
fin_lis = [0]*(maximam+1)
count = 0
for i in range(3, maximam+1, 2):
    if flag_lis[i] == 1 and flag_lis[int((i+1)/2)] == 1:
        count += 1
    fin_lis[i] = count
for (l, r) in lis:
    if l == 1:
        print(fin_lis[r] - 0)
    else:
        print(fin_lis[r] - fin_lis[l-2])

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

const int N=2005;

int n,m,Q,SA[N][N],SB[N][N],SC[N][N];
char ch[N][N];

inline int read()
{
	int sum=0; char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) 
		sum=sum*10+(ch^48),ch=getchar();
	return sum;
}

int main()
{
	scanf("%d%d%d",&n,&m,&Q);
	for ( int i=1;i<=n;i++ ) scanf("%s",ch[i]+1);
	for ( int i=1;i<=n;i++ ) 
		for ( int j=1;j<=m;j++ ) 
		{
			SA[i][j]=SA[i-1][j]+SA[i][j-1]-SA[i-1][j-1]+(ch[i][j]^48);
			SB[i][j]=SB[i-1][j]+SB[i][j-1]-SB[i-1][j-1]+((ch[i][j]^48)&&(ch[i][j+1]^48));
			SC[i][j]=SC[i-1][j]+SC[i][j-1]-SC[i-1][j-1]+((ch[i][j]^48)&&(ch[i+1][j]^48));
		}
	for (;Q--;)
	{
		int sx,sy,ex,ey;
		sx=read(),sy=read();
		ex=read(),ey=read();
		int D=SA[ex][ey]-SA[sx-1][ey]-SA[ex][sy-1]+SA[sx-1][sy-1];
		int E=SB[ex][ey-1]-SB[sx-1][ey-1]-SB[ex][sy-1]+SB[sx-1][sy-1];
		E+=SC[ex-1][ey]-SC[sx-1][ey]-SC[ex-1][sy-1]+SC[sx-1][sy-1];
		printf("%d\n",D-E);
	}
	return 0;
}

Measured memory_bytes: 52864
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
 

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair < int , pll>           
#define    sp(x)                    setprecision(x)

int32_t main()
{       
    speed upp
    int n,k=1,ans=0;
    cin>>n;
    while(n>0)
    {
        ans+=k;
        k=2*k;
        n/=2;
    }
    cout<<ans;
}

Measured memory_bytes: 256
package main

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

func main() {
	n := readInt()
	a := readIntSlice(n)

	//
	d := make(map[int]bool)

	for i := 0; i < n; i++ {
		if _, ok := d[a[i]]; ok {
			// 2つ以上ある場合は割れる数がある
			d[a[i]] = true
		} else {
			d[a[i]] = false
		}
	}

	// fmt.Println("debug:", d)

	keys := []int{}

	for i := range d {
		keys = append(keys, i)
	}

	sort.Ints(keys)

	for _, v := range keys {
		// fmt.Println("v", v, "dv", d[v])
		if d[v] == true {
			for j := 2; j*v <= keys[len(keys)-1]; j++ {
				// fmt.Println("jv", j*v)
				if _, ok := d[j*v]; ok {
					d[j*v] = true
				}
			}
		}

		for j := 2; j*v <= keys[len(keys)-1]; j++ {
			// fmt.Println("jv", j*v)
			if _, ok := d[j*v]; ok {
				d[j*v] = true
			}
		}

	}

	// fmt.Println("d", d)
	answer := 0
	for _, v := range d {
		if v == false {
			answer++
		}
	}

	fmt.Println(answer)
}

var (
	scanner *bufio.Scanner
)

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.Atoi(t)
	if err != nil {
		log.Fatal(err)
	}

	return n

}

func readIntSlice(n int) []int {
	s := make([]int, n)
	var t string

	for i := 0; i < int(n); i++ {
		if scanner.Scan() {
			t = scanner.Text()
		}

		num, err := strconv.Atoi(t)
		if err != nil {
			log.Fatal(err)
		}
		s[i] = num
	}

	return s
}


Measured memory_bytes: 15636
import java.math.BigInteger;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ


	    //入力数字の数を入力
		Scanner sc=new Scanner(System.in);

	    int count=sc.nextInt();

		boolean isOverflow = false;  // 桁あふれしたかフラグ
		BigInteger result=BigInteger.ZERO;
		BigInteger max=BigInteger.valueOf((long)Math.pow(10, 18));

	    //入力処理
		for(int i = 0; i < count; i++) {
			long a = sc.nextLong();

			// 桁あふれしている時は、それ以降ゼロが現れるかチェックする
			if (isOverflow) {
				// 桁あふれ後にゼロが出てきたとき
				if (a == (long)0) {
					// 求める値はゼロになる
					result = BigInteger.ZERO;
					isOverflow = false;
					break;
				}
				// 次の値を処理する
				continue;
			}

			// 積を求める
			BigInteger nyuryoku=BigInteger.valueOf(a);
			result= i==0 ? result.add(nyuryoku):result.multiply(nyuryoku);
			// 桁あふれしているか？
			if (result.compareTo(max) > 0) {
				isOverflow = true;
			}
		}

		// 結果を出力する
		if(isOverflow) {
			// 桁あふれ時は「-1」
			System.out.println(-1);
		} else {
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 59932
#include<stdio.h>
int search(int a[],int n,int key){
    int i=0;
    a[n]=key;
    while(a[i]!=key) i++;
    return i!=n;
}
    
int main(void){
    int n,s[10000+1],q,key;
    int i,ans=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&s[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++){
	scanf("%d",&key);
	if(search(s,n,key)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<unsigned> a(N), b(N);
  for (size_t i=0; i<N; ++i)
    scanf("%u", &a[i]);

  for (size_t i=0; i<N; ++i)
    scanf("%u", &b[i]);

  unsigned res=0;
  for (unsigned i=(1<<28); i; i>>=1) {
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());

    size_t i1=0, i2=0, i3=0;
    unsigned cur=0;
    for (size_t j=N; j--;) {
      while (i1 < N && a[j]+b[i1] < 1*i) ++i1;
      while (i2 < N && a[j]+b[i2] < 2*i) ++i2;
      while (i3 < N && a[j]+b[i3] < 3*i) ++i3;
      cur += (i2-i1) + (N-i3);
    }
    if (cur & 1)
      res |= i;

    for (size_t j=0; j<N; ++j) {
      a[j] &= i-1;
      b[j] &= i-1;
    }
  }

  printf("%u\n", res);
}


Measured memory_bytes: 1792
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	string S;
	int c = 0;
	cin >> S;
	for (int i = 0;i < S.length();i++) {
		if (i == 0 && S[i] != 'A') {
			cout << "WA" << endl;
			return 0;
		}
		if (i >= 2 && i <= S.length() - 2 && S[i] == 'C')
			c++;
		else if (i != 0 && ( S[i] <'a' || S[i]>'z')) {
			cout << "WA" << endl;
			return 0;
		}


	}
	if(c==1)
		cout << "AC" << endl;
	else 
		cout << "WA" << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n;
ll L, ans;
int a[maxn];
ll x[maxn], presum[maxn], pre[maxn], sufsum[maxn], suf[maxn];
int main()
{
	scanf("%d%lld", &n, &L);
	for(int i = 1; i <= n; ++i)
		scanf("%lld%d", &x[i], &a[i]);
	for(int i = 1; i <= n; ++i)
	{
		presum[i] = presum[i - 1] + a[i];
		pre[i] = max(pre[i - 1], presum[i] - 2 * x[i]);
	}
	for(int i = n; i; --i)
	{
		sufsum[i] = sufsum[i + 1] + a[i];
		suf[i] = max(suf[i + 1], sufsum[i] - 2 * (L - x[i]));
	}
	for(int i = 1; i <= n; ++i)
		ans = max(ans, presum[i] - x[i] + suf[i + 1]);
	for(int i = n; i; --i)
		ans = max(ans, sufsum[i] - (L - x[i]) + pre[i - 1]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4480
N = int(input())
A = list(map(int, input().split()))
Amax = max(A)
lis = [0]*(Amax+1)
for i in range(N):
  lis[A[i]] += 1
setwise = False
for t in range(2,Amax+1):
  p = t
  cnt = 0
  while p<=Amax:
    cnt += lis[p]
    p += t
  if cnt==N:
    print('not coprime')
    break
  if 2<=cnt<N:
    setwise=True
else:
  if setwise==True:
    print('setwise coprime')
  else:
    print('pairwise coprime')


Measured memory_bytes: 199452
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	int64_t m = 1000;
	vector<int64_t> as(n); for (auto& a : as) cin >> a;

	int64_t nk = 0;
	FOR_LT(i, 0, n) {
		m += nk * as[i];
		nk = 0;
		if (i < n - 1 && as[i] < as[i + 1]) {
			nk = m / as[i];
			m -= nk * as[i];
		}
	}
	cout << m << endl;

	return 0;
}

Measured memory_bytes: 3660
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 1e5 + 10;
const int MAXK = 10;
const ll INF = 1e18;

int n;
int a[MAXN];
int sign[MAXN];

int read_sign() {
	char c;
	while (1) {
		c = getchar();
		if  (c == '-') {
			return -1;
		}
		if  (c == '+') {
			return +1;
		}
	}
	assert(0);
}

bool read() {
	if  (scanf("%d\n", &n) < 1) {
		return 0;
	}
	scanf("%d", &a[0]);
	sign[0] = 1;
	for (int i = 1; i < n; ++i) {
		sign[i] = read_sign();
		scanf("%d", &a[i]);
	}
	return 1;
}

int get_sign(int x) {
	return (x & 1) ? -1 : +1;
}

ll dp[MAXN][MAXK];

ll solve() {
	forn(i, n + 1) {
		forn(k, MAXK) {
			dp[i][k] = -INF;
		}
	}

	dp[0][0] = 0;

	// forn(i, n) {
	// 	printf("%d ", sign[i] * a[i]);
	// }
	// puts("");

	forn(i, n) forn(k, MAXK) {
		ll cur_dp = dp[i][k];
		if  (cur_dp <= -INF) {
			continue;
		}
		// printf("dp[%d][%d] = %lld\n", i, k, cur_dp);
		dp[i + 1][k] = max(dp[i + 1][k], cur_dp + sign[i] * get_sign(k) * a[i]);
		if  (k > 0) {
			dp[i + 1][k - 1] = max(dp[i + 1][k - 1], cur_dp + sign[i] * get_sign(k) * a[i]);
		}
		if  (sign[i] == -1 && k + 1 < MAXK) {
			dp[i + 1][k + 1] = max(dp[i + 1][k + 1], cur_dp + sign[i] * get_sign(k) * a[i]);
		}
	}

	ll ans = -INF;
	forn(k, MAXK) {
		ans = max(ans, dp[n][k]);
	}

	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		cout << solve() << endl;
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 8832
//https://atcoder.jp/contests/abc139/tasks/abc139_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N; cin>>N;
    ll ans=(1+(N-1))*(N-1)/2;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll k,n;
    cin>>k>>n;
    ll a[200005]={};
    REP(i,n)cin>>a[i];
    a[n]=a[0]+k;
    int max=-1;
    REP(i,n){
        ll dis = a[i+1]-a[i];
        if(max<dis)max=dis;
    }
    cout<<k-max<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

int N,M,K;
int G[3010][3010];
ll ans[3010][3010][4];
void solve(){
	if(G[1][1]) ans[1][1][1] = G[1][1];
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=M;j++){
			if(i+1<=N){
				for(int k = 0;k<=3;k++){
					if(G[i+1][j] == 0){
						ans[i+1][j][0] = max(ans[i+1][j][0],ans[i][j][k]);
					}else{
						ans[i+1][j][1] = max(ans[i+1][j][1],ans[i][j][k] + G[i+1][j]);
						ans[i+1][j][0] = max(ans[i+1][j][0],ans[i][j][k]);
					}
				}
			}
			if(j+1<=M){
				for(int k = 0;k<=3;k++){
					if(k && ans[i][j][k] == 0) continue;
					if(G[i][j+1] == 0){
						ans[i][j+1][k] = max(ans[i][j+1][k],ans[i][j][k]);
					}else{
						if(k+1<=3) ans[i][j+1][k+1] = max(ans[i][j+1][k+1],ans[i][j][k] + G[i][j+1]);
						ans[i][j+1][k] = max(ans[i][j+1][k],ans[i][j][k]);
					}
				}
			}
		}
	}
	// for(int i = 1;i<=N;i++){
	// 	for(int j = 1;j<=M;j++){
	// 		cout<<i<<" "<<j<<": \n";
	// 		for(int k = 0;k<=3;k++){
	// 			cout<<ans[i][j][k]<<" ";
	// 		}
	// 		cout<<'\n';
	// 	}
	// }
	ll res = 0;
	for(int k = 0;k<=3;k++) res = max(res,ans[N][M][k]);
	cout<<res<<'\n';
}
int main(){
	// debug;
	ios;

	cin>>N>>M>>K;
	for(int i = 1;i<=K;i++){
		int x,y,v;cin>>x>>y>>v;
		G[x][y] = v;
	}
	solve();
	
	return 0;
}


Measured memory_bytes: 321060
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
int a[1000][1000], dp[1000][1000];
int main() {
	int h, w, n;
	while (scanf("%d%d%d", &h, &w, &n), h) {
		rep(i, h)rep(j, w) {
			getchar_unlocked(); a[i][j] = getchar_unlocked() - '0';
		}
		memset(dp, 0, sizeof(dp));
		dp[0][0] = n - 1;
		rep(i, h)rep(j, w) {
			if (i) {
				if (a[i - 1][j])dp[i][j] += dp[i - 1][j] >> 1;
				else dp[i][j] += (dp[i - 1][j] + 1) >> 1;
			}
			if (j) {
				if (a[i][j - 1])dp[i][j] += (dp[i][j - 1] + 1) >> 1;
				else dp[i][j] += dp[i][j - 1] >> 1;
			}
		}
		int x = 0, y = 0;
		while (x < h&&y < w) {
			if ((dp[x][y] ^ a[x][y]) & 1)y++;
			else x++;
		}
		printf("%d %d\n", x + 1, y + 1);
	}
}

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

using namespace std;

typedef long long ll;

#define db(m)  cout<<#m<<" = "<<m<<"\n"

#define MAX 200005

void bang(){
    int n; cin>>n;
    vector<int>v(n);
    for(int i = 1; i <= n; i++) v[i - 1] = i;
    vector<int>a(n), b(n);
    for(auto& i : a) cin>>i;
    for(auto& i : b) cin>>i;
    int x, y;
    int i = 1;
    do{
        if(v == a) x = i;
        if(v == b) y = i;

        i++;
    }while(next_permutation(v.begin(), v.end()));

    cout<<abs(x - y)<<'\n';
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // int q; cin>>q;
    // while(q--)
        bang();

    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////
int main(){
	ll n,m;
	cin >> n >> m;

	if( n == 1 ){
		cout << m << endl;
		ret 0;
	}
	if( !(m % n) ){
		cout << m/n << endl;
		ret 0;
	}

	ll lim = sqrt(m)+1;
	ll M = 0;	
	int i = 1;
	while( n * i <= m && i < lim ){
		if( !(m % i) ){
			M = max( M , ll(i));
			if( m >= n*(m/i) ){
				M = max( M , m/i );
			}
		}
		i++;
	}

	cout << M << endl;

	ret 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    string s;
    cin >> n >> k >> s;
    s.at(k - 1) += 'a' - 'A';
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <queue>
#define FOR(x, y, z) for(int x = (z); y; x++)
#define rep(x, y) for(int x = 0; x < (y); x++)
#define all(x) x.begin(),x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define sp_str(str, sp_word) istringstream stream(str); string res; while(getline(stream,res,sp_word))
#define rem_space(x) x.erase(remove(all(x), ' '),x.end())
#define scl(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
using namespace std;

int main(){
 string line;
 getline(cin,line);
 FOR(i,true,0){
   line.erase(line.end() - 1);
   if(line.length() % 2 == 0){
     auto center = line.begin() + line.length() / 2;
     if(equal(line.begin(), center, center)){
       printf("%d\n", line.length());
       exit(0);
     }
   }
 }
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll a[N+2];
    ll i;
    a[0]=0;
    a[N+1]=0;
    for(i=1;i<=N;i++){
      cin >> a[i];
    }
    ll sum=0;
    for(i=1;i<=N+1;i++){
      sum+=abs(a[i]-a[i-1]);
    }
    for(i=1;i<=N;i++){
      cout<< sum+abs(a[i+1]-a[i-1])-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])<<endl;
    }
    return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

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

  int N, M;
  cin >> N >> M;

  if(N==M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b=map(int,input().split())
print((b-a)*(b-a+1)//2-b)

Measured memory_bytes: 38384
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353;
constexpr int MAX = 500050;
const double pi = acos(-1);
// constexpr double EPS = 1e-10;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;


vector<pii>bunkai(int x) {
	vector<pii>ret;
	for (int i = 2; i*i <= x; i++) {
		if (x % i == 0) {
			pii res = { i,0 };
			while (x%i == 0) {
				res.second++;
				x /= i;
			}
			ret.push_back(res);
		}
	}
	if (x != 1) {
		ret.push_back({ x,1 });
	}
	return ret;
}
void solve() {
	int N; cin >> N;
	vector<pii>v = bunkai(N);
	int ans = 0;
	for (auto p : v) {
		int c = p.second;
		int sub = 1;
		while (c >= sub) {
			ans++;
			c -= sub;
			sub++;
		}
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 3664
program main
   implicit none
   integer:: n,m,i,ans=0,a=0,b=100000
   integer,allocatable,dimension(:)::l,r
   read(*,*)n,m
   allocate(l(m),r(m))
   do i=1,m
      read(*,*)l(i),r(i)
   enddo
   a=0
   do i=1,m
     a=max(a,l(i))
     b=min(b,r(i))
   enddo
   
   write(*,*)max(b-a+1,0)
   
   
 
 
 
 
 
 
 
   
contains
  subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  
  integer ::i,k,j,l
  integer :: t
  
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort
end program main


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

 							

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a[6],i,t,tt,mn,ans=0,r;
	cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
	mn=11;
	for(i=0;i<5;i++){
		t=a[i]%10;
		if(mn>t && t!=0){
			tt=i;
			mn=t;
		}
	}
	for(i=0;i<5;i++){
		if(i==tt){
			ans+=a[i];
			continue;
		}
		if(a[i]%10==0){
			ans+=a[i];
			continue;
		}
		r=a[i]/10;
		ans+=(r+1)*10;
		
	}
	cout<<ans;
	
}
	


Measured memory_bytes: 256
def solve():
    N,M,Q = map(int,input().split())
    req = []
    for i in range(Q):
        a,b,c,d = map(int,input().split())
        a -= 1
        b -= 1
        req.append([a,b,c,d])

    res = []
    dfs(list(), res,M,N)

    mx = 0
    for p in res:
        point = 0
        for a,b,c,d in req:
            if p[b] - p[a] == c:
                point += d
        mx = max(point, mx)
    
    print(mx)


def dfs(now,res,M,N):
    if len(now) == N:
        res.append(now)
        return
    start = 1
    if len(now) != 0:
        start = now[-1]

    if start > M:
        return

    for i in range(start,M+1):
        nxt = now[:]
        nxt.append(i)
        dfs(nxt, res,M,N)
    
if __name__ == '__main__':
    solve()

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

 
int main(){
    int n;
    int arr[11][11] = {0};
    cin >> n;
    for(int i=1;i<=n;i++){
        int firstDig = i;
        while(firstDig > 9) firstDig /= 10;
        arr[firstDig][i % 10]++;
    }
    ll answer = 0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            answer += arr[i][j] * arr[j][i];
        }
    }
    cout << answer;
}


Measured memory_bytes: 384