akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cctype>
 
using namespace std;
 
typedef long long LL;
 
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}
 
const int N=100005;
const int E=N<<1;
 
int last[N],que[N],size[N],fa[N],f[N];
int len[E],tov[E],nxt[E];
LL up[N];
int n,tot,c,head,tail;
LL ans;
 
inline void insert(int x,int y,int z){tov[++tot]=y,len[tot]=z,nxt[tot]=last[x],last[x]=tot;}
 
inline int core(int og)
{
	int rets=n,ret=0,tmp,i,x,y;
	for (fa[que[head=0,tail=1]=og]=0;head<tail;)
		for (i=last[x=que[++head]],size[x]=1;i;i=nxt[i])
			if ((y=tov[i])!=fa[x]) fa[que[++tail]=y]=x;
	for (head=tail;head>1;--head) size[fa[que[head]]]+=size[que[head]];
	for (head=1;head<=tail;++head)
	{
		for (tmp=size[og]-size[x=que[head]],i=last[x];i;i=nxt[i])
			if ((y=tov[i])!=fa[x]) tmp=max(tmp,size[y]);
		if ((f[x]=tmp)<rets) rets=tmp,ret=x;
	}
	return ret;
}
 
void dfs(int x)
{
	size[x]=1,ans+=up[x];
	for (int i=last[x],y;i;i=nxt[i])
		if ((y=tov[i])!=fa[x]) up[y]=up[fa[y]=x]+len[i],dfs(y),size[x]+=size[y];
}
 
int main()
{
	//freopen("hamilton.in","r",stdin),freopen("hamilton.out","w",stdout);
	n=read();
	for (int i=1,x,y,z;i<n;++i) x=read(),y=read(),z=read(),insert(x,y,z),insert(y,x,z);
	dfs((fa[c=core(1)]=0,c)),ans<<=1;
	for (int i=last[c];i;i=nxt[i])
		if (f[tov[i]]==f[c])
			ans-=len[i],head=-1;
	if (~head)
	{
		int mi=-1;
		for (int i=last[c];i;i=nxt[i])
			if (!~mi||len[i]<mi) mi=len[i];
		ans-=mi;
	}
	printf("%lld\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	long long k = 1,c = 7 + pow(10,9);
	for(int i = 1;i <= N;i++)
	{
		k = i * k % c;
	}
    cout << k << endl;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int A, B, C;
signed main() {
    cin >> A >> B >> C;
    cout << min(B / A, C) << endl;
}


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

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = x2 - (y2 - y1);
    y3 = y2 + (x2 - x1);
    x4 = x1 - (y2 - y1);
    y4 = y1 + (x2 - x1);
    printf("%d %d %d %d\n", x3, y3, x4, y4);
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 計算
		String result = "dangerous";
		if(b-a <= 0) result = "delicious";
		if(0 < b-a && b-a <= x) result = "safe";
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s1, s2; cin >> s1 >> s2;
  vector<bool> p; 
  int i = 0;
  while (i < n) {
    if (s1[i] == s2[i]) {
      p.push_back(false);
      i++;
    } else {
      p.push_back(true);
      i += 2;
    }
  }
  long long res = p[0] ? 6 : 3;
  for (i = 1, n = p.size(); i < n; i++) {
    int m;
    if (not p[i - 1]) m = 2;
    else if (not p[i]) m = 1;
    else m = 3;
    res = res * m % mod;
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N;
    long long ans=0;

    cin >> N;
    rep(i,N){
        long long r,l;
        cin >> l >> r;
        ans+=(r-l)+1;
    }

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



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

inline double distance(double x1,double y1,double x2,double y2){
	return sqrt( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) );
}

int main(){
	int dataSetNum;
	std::cin >> dataSetNum;

	std::deque<int> number;

	for(int i = 0; i < dataSetNum; ++i){
		double xa, ya, ra, xb, yb, rb;
		std::cin >> xa >> ya >> ra >> xb >> yb >> rb;
		double dis = distance(xa, ya, xb, yb);
		//"0" if A and B do not overlap
		if(dis > ra + rb) number.push_back(0);
		//"2" if B is in A
		else if(dis + rb < ra) number.push_back(2);
		//"-2" if A is in B
		else if(dis + ra < rb) number.push_back(-2);
		//"1" if circumference of A and B intersect
		else number.push_back(1);
	}
	for(int i = 0; i < dataSetNum; ++i){
		std::cout << number.front() << std::endl;
		number.pop_front();
	}
	return 0;
	}

Measured memory_bytes: 1236
#include<stdio.h>
int selectionSort(int A[],int N)
{
    int i,j,t,sum=0,minj;
    for(i=0;i<N-1;i++){
    minj=i;
    for(int j=i;j<N;j++){
    if(A[j]<A[minj]) minj=j;
    }
    t=A[i];A[i]=A[minj];A[minj]=t;
    if(i!=minj) sum++;
    }
    return sum;
    }
int main(){
int A[100],N,sum,i;
scanf("%d",&N);
for(i=0;i<N;i++) scanf("%d",&A[i]);
sum=selectionSort(A,N);
for(int i=0;i<N;i++){
if(i>0)  printf(" ");
printf("%d",A[i]);
}
printf("\n");
printf("%d\n",sum);
return 0;
}

Measured memory_bytes: 2692
/*
 * @Author: BilyHurington
 * @Date: 2020-03-22 20:53:17
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-03-22 21:13:36
 */
#include<bits/stdc++.h>
using namespace std;
int n,s,a[3010];
long long f[3010];
const int mod=998244353;
int main(){
    scanf("%d %d",&n,&s);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    long long ans=0;
    for(int i=1;i<=n;i++){
        for(int j=s-a[i];j>=0;j--){
            f[j+a[i]]=(f[j+a[i]]+f[j])%mod;
        }
        f[a[i]]+=i;
        ans+=f[s]%mod;
        ans%=mod;
        // for(int i=0;i<=s;i++) printf("%lld ",f[i]);
        // printf("\n");
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














string N; int K;
ll dp[101][2][5];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;

	int n = N.length();

	dp[0][0][0] = 1;
	rep(dgt, 0, n) rep(isless, 0, 2) rep(k, 0, K + 1) {
		int c = N[dgt] - '0';
		rep(nxt, 0, 10) {
			if (c < nxt && isless == 0) continue;

			int dgt2 = dgt + 1;
			int isless2 = isless;
			if (nxt < c) isless2 = 1;
			int k2 = k;
			if (nxt != 0) k2++;
			
			dp[dgt + 1][isless2][k2] += dp[dgt][isless][k];
		}
	}
	ll ans = dp[n][0][K] + dp[n][1][K];
	cout << ans << endl;
}







Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,Q=map(int,input().split())
a=tuple(map(int1,input().split()))
lr=[() for i in range(Q)]
for i in range(Q):
    l,r=map(int1,input().split())
    lr[i]=(l,r,i)
lr.sort(key=lambda t: t[1],reverse=1)
class BIT:
    def __init__(self,n):
        self.num=n
        self.dat=[0]*(self.num+1)
        self.depth=n.bit_length()
    
    def add(self,i,x):
        i+=1
        while i<=self.num:
            self.dat[i]+=x
            i+=i&-i
    
    def sum(self,i):
        i+=1
        s=0
        while i>0:
            s+=self.dat[i]
            i-=i&-i
        return s
    
    def lower_bound(self,x):
        sum_=0
        pos=0
        for i in range(self.depth,-1,-1):
            k=pos+(1<<i)
            if k<=self.num and sum_+self.dat[k]<x:
                sum_+=self.dat[k]
                pos+=1<<i
        return pos, sum_

b=BIT(N)
lastap=[-1]*N
ans=[-1]*Q
l,r,j=lr.pop()
for i,x in enumerate(a):
    if lastap[x]!=-1:
        b.add(lastap[x],-1)
    b.add(i,1)
    lastap[x]=i
    while r==i:
        ans[j]=b.sum(r)-b.sum(l-1)
        if lr:
            l,r,j=lr.pop()
        else:
            l,r,j=-1,-1,-1
print(*ans,sep='\n')

Measured memory_bytes: 235784
using System;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            long[] input = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long A = input[0];
            long B = input[1];
            long C = input[2];
            long D = input[3];
            long gcd = C*D/Gcd(C,D);
            Console.WriteLine(B-A+1 - (B/C - (A-1)/C + B/D - (A-1)/D - (B/gcd-(A-1)/gcd)));     
        }

        static long Gcd(long m,long n){
            long temp;
            while(m%n!=0){
                temp =n;
                n = m%n;
                m = temp;
            }
            return n;
        }
    }
}

Measured memory_bytes: 13140
[h1, h2] = [int(num) for num in input().split()]
[k1, k2] = [int(num) for num in input().split()]
[a, b, c, d] = [int(num) for num in input().split()]

counth = a * h1 + b * h2 + c * (h1 // 10) + d * (h2 // 20)
countk = a * k1 + b * k2 + c * (k1 // 10) + d * (k2 // 20)
if (counth > countk):
    print('hiroshi')
elif (counth < countk):
    print('kenjiro')
else:
    print('even')

Measured memory_bytes: 7740
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>

bool enough(const std::vector<int>& a, int k) {
  std::map<int, int> mp;
  for(int i = 1; i < a.size(); i++){
    if (a[i-1] < a[i]) continue;
    if (k == 1) return false;

    // case: a[i-1] >= a[i]
    int v = a[i];
    mp.erase(mp.upper_bound(v), mp.end());
    while(mp[v] == k-1) {
      --v;
      if (v == 0) return false;
    }

    ++mp[v];
    mp.erase(mp.upper_bound(v), mp.end());
  }
  return true;
}

int main(){
  int n; std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }

  int l = 0, r = n;
  while(r - l > 1) {
    int mid = (r + l) / 2;
    if (enough(a, mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }

  std::cout << r << std::endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
 
const pii Dir[8] = { //?????????
    { 0,1 },{ 0,-1 },{ 1,0 },{ -1,0 },
    { 1,1 },{ 1,-1 },{ -1,-1 },{ -1,1 }
};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
    std::fill((T*) array, (T*) (array + N), val);
}
 
signed main() {
    int n;
    scanf("%d", &n);
    vector<pii> foo(n);
    REP(i, n) {
        scanf("%d %d", &foo[i].second, &foo[i].first);
    }
    sort(ALL(foo),greater<pii>());
 
    int l = 0, r = n+1;
    while (1) {
        int m = (l + r) / 2;
 
        bool f = 0;
 
        priority_queue<int> out;
        ll sum = 0;
        REP(i, n) {
            out.push(foo[i].second);
            sum += foo[i].second;
            if (out.size() > m) {
                sum -= out.top();
                out.pop();
            }
            if (out.size() == m && sum <= (ll)foo[i].first*m) {
                f = 1;
                break;
            }
        }
 
        if (f) {
            l = m;
        }
        else {
            r = m;
        }
 
        if (r - l <= 1) {
            printf("%d\n", l);
            break;
        }
    }
 
    return 0;
}

Measured memory_bytes: 8340
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
int main (){
    int a ,k ;
    int value=1;

    cin >> a >> k;
    while (a--){

            if (value *2 > value + k)
                value += k;
            else
                value *= 2;


    }

    printf("%d\n",value);


return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){ 
    string S;
    cin >> S;
    if(S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
        cout << "Yes" << endl;
}
else {
    cout << "No" << endl;
}
    
}


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

int main() {
  //int n, a,b,c;
  string s;
cin>>s;
  int arr[26];
  int cc=0;
  memset(arr,0,sizeof(arr));
  //cin>>s;
  for(int i=0;i<4;i++)
  {
   arr[s[i]-'A']++;
  }
  for(int i=0;i<26;i++)
  {
    if( arr[i]==2)
    {
        cc++;
    }
  }
  if(cc==2)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 3005;
int n;
int a[maxn];
vector<int> g[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
  	g[i].clear();
  }
  for (int i = 0; i < n; i++) {
  	scanf("%d", &a[i]);
  }
  for (int i = 0; i < n - 1; i++) {
  	int v, u;
  	scanf("%d%d", &v, &u);
  	v--;
  	u--;
  	g[v].push_back(u);
  	g[u].push_back(v);
  }
  return true;
}

int dp[maxn];

void dfs(int v, int p) {
	dp[v] = false;
	for (int i = 0; i < sz(g[v]); i++) {
		int u = g[v][i];
		if (u == p || a[u] >= a[v]) {
			continue;
		}
		dfs(u, v);
		if (!dp[u]) {
			dp[v] = true;
		}
	}
}

void solve() {
	for (int i = 0; i < n; i++) {
		dfs(i, -1);
		if (dp[i]) {
			printf("%d ", i + 1);
		}
	}
	printf("\n");
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Measured memory_bytes: 512
import sys
a=[]
for i in range(3):
  a1,a2,a3=map(int,input().split())
  a.append([a1,a2,a3])
  
check=[[0]*3 for i in range(3)]
n=int(input())
b=[]
for i in range(n):
  b.append(int(input()))
for i in b:
  for j in range(3):
    if i in a[j]:
      check[j][a[j].index(i)]=1

naname=[0]*3

for i in range(3):
  if sum(check[i])==3:
    print('Yes')
    sys.exit()

for j in range(3):
  num=0
  for i in range(3):
    if check[i][j]==1:
      num+=1
      if num==3:
        print('Yes')
        sys.exit()
        
if check[0][0]==check[1][1]==check[2][2]==1:
  print('Yes')
  sys.exit()
if check[0][2]==check[1][1]==check[2][0]==1:
  print('Yes')
  sys.exit()
  
print('No')
  
  


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		long[] a = new long[100010];
		long[] b = new long[100010];
		for (int i = 0;i < n;i++) {
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();
		}
		long ret = 0;
		for (int i = n-1;i >= 0;i--) {
			long ai = a[i] + ret;
			long bi = b[i];
			if (ai%bi!=0) {
				ret += bi-(ai%bi);
			}
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 64848
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
  
  
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }

  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
  
  cout << (f?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3124
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	cin>>s;
	for(int i=0;i<(int)s.size()-1;i++){
		if(s[i]==s[i+1]){cout<<i+1<<" "<<i+2<<endl;return 0;}
	}
	for(int i=0;i<(int)s.size()-2;i++){
		if(s[i]==s[i+1] || s[i]==s[i+2] || s[i+1]==s[i+2]){cout<<i+1<<" "<<i+3<<endl;return 0;}
	}
	cout<<"-1 -1\n";
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int r,d;
	cin>>r>>d;
	int p = 2*d;
	p += 1;
	//cout<<r%p<<endl;
	if(r%p==0)
	{
		cout<<r/p<<endl;
	}
	else
	{
		int q = r/p;
		cout<<q+1<<endl;
	}
}

Measured memory_bytes: 256
def comb(n,k):
    if k==0:
        return 1
    elif k==1:
        return n
    elif k==2:
        return n*(n-1)/2

n = input()
k = int(input())
ans=0
for dgt in range(1,len(n)):
    if dgt<len(n):
        ans+=9**k*comb(dgt-1,k-1)
dgt=len(n)
cnt=0
for i in range(len(n)):
    if n[i] != '0' and cnt<k:
        cnt+=1
        ans+=(int(n[i])-1)*9**(k-cnt)*comb(dgt-i-1, k-cnt)
        if i:
            ans+=9**(k-cnt+1)*comb(dgt-i-1, k-cnt+1)

if cnt==k:
    ans+=1
print(int(ans))





Measured memory_bytes: 38400
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int I[100][20];
char s[100][100];

int main() {
	int h, w;
	cin >> h >> w;
	bool flag = true;
	rep(i, h) {
		rep(j, w) {
			cin >> s[i][j];
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#') {
				int flag2 = 0;
				rep(k, 4) {
					if (s[i + dx[k]][j + dy[k]] == '#')flag2++;
				}
				if (flag2 == 0)flag = false;
			}
		}
	}
	if (flag)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1000000000000000000LL;//1e18
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

struct unionfind{
    vec<int> par;int num;
    unionfind(int n):num(n),par(n,-1){}
    int find(int x){
        if(par[x]==-1)return x;
        else return par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x),y=find(y);
        if(x==y)return;
        par[x]=y;
        num--;
        return;
    }
};

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

    int n;cin >> n;
    vector<pair<P,int>> x(n);
    vector<pair<P,int>> y(n);
    rep(i,n){
        int xx,yy;cin >> xx >> yy;
        x[i].first.first=xx,x[i].first.second=yy;
        y[i].first.first=yy,y[i].first.second=xx;
        x[i].second=i,y[i].second=i;
    }
    sort(all(x)),sort(all(y));
    priority_queue<pair<int,P>,vec<pair<int,P>>,greater<pair<int,P>>> q;
    rep(i,n-1){
        q.push(pair<int,P>(abs(x[i].first.first-x[i+1].first.first),P(x[i].second,x[i+1].second)));
        q.push(pair<int,P>(abs(y[i].first.first-y[i+1].first.first),P(y[i].second,y[i+1].second)));
    }
    
    unionfind uf(n);
    ll cost=0;
    while(uf.num>1){
        pair<int,P> now=q.top();q.pop();
        if(uf.find(now.second.second)==uf.find(now.second.first))continue;
        uf.unite(now.second.second,now.second.first);
        cost+=now.first;
    }
    cout << cost << endl;
}

Measured memory_bytes: 14196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

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

    for(int i = 0; i < h; i++){
        string s = v[i];
        bool ok = all_of(s.begin(), s.end(), [](char x){return x == '.';});
        if(ok){
            for(auto &c: v[i])
                c = 's';
        }
    }

    for(int i = 0; i < w; i++){
        if(v[0][i] == '.' || v[0][i] == 's'){
            bool ok = true;
            for(auto s: v)
                if(s[i] == '#')
                    ok = false;

            if(ok)
                for(auto &s: v)
                    s[i] = 's';
        }
    }
    for(auto s: v){
        int cnt = 0;
        for(auto c: s){
            if(c != 's')
                cout << c;
            else
                cnt++;
        }
        if(cnt == w)
            continue;
        cout << '\n';
    }
}


Measured memory_bytes: 256
#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(){
    string s;
    cin >> s;

    string ans = "";
    rep(i, s.size()) {
        if (s[i] == '0') ans.push_back('0');
        if (s[i] == '1') ans.push_back('1');
        if (s[i] == 'B') {
            if(ans.size() == 0) ;
            else ans.pop_back();
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

friend = [() for i in range(m)]
uf = UnionFind(n)
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    uf.union(a, b)
    friend[i] = (a,b)

block = [[]]*k
for i in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    block[i] = (c,d)

ans = [uf.size(i) - 1 for i in range(n)]
for i,j in friend:
    if uf.same(i,j):
        ans[i] -= 1
        ans[j] -= 1
for i,j in block:
    if uf.same(i,j):
        ans[i] -= 1
        ans[j] -= 1

print(*ans)

Measured memory_bytes: 91568
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std; 
 
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)

int main() {
    ll lucas[87];
    int n;
    cin >> n;

    lucas[0] = 2;
    lucas[1] = 1;
    REP(i, 2, n+1) lucas[i] = lucas[i-1] + lucas[i-2];
    
    cout << lucas[n] << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
bit = [0] * 41
for i in A:
    for j in range(41):
        bit[j] += (i >> j) & 1
x = {}
for i in range(41):
    x[i, 0] = 2 ** i * bit[i]
    x[i, 1] = 2 ** i * (N - bit[i])
ans = sum(A)
for i in range(41):
    if ((K + 1) >> i) & 1 == 0:
        continue
    f = 0
    for j in range(i):
        f += max(x[j, 0], x[j, 1])
    f += x[i, 0]
    for j in range(i + 1, 41):
        f += x[j, ((K + 1) >> j) & 1]
    ans = max(ans, f)
print(ans)

Measured memory_bytes: 69008
N = int(input())
Inf = [[0,0,0]]

for i in range(N):
    Inf += [list(map(int,input().split()))]

for i in range(N):
    dist = abs(Inf[i][1]-Inf[i+1][1]) + abs(Inf[i][2]-Inf[i+1][2])
    dt = Inf[i+1][0] - Inf[i][0]
    if dt < dist:
        print("No")
        break
    else:
        if (dt % 2) == (dist % 2):
            continue
        else:
            print("No")
            break
else:
    print("Yes")


Measured memory_bytes: 27380
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int MOD = 1e9 + 7;

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  int ans = 1;
  vector<int> v;
  for(int i = 0; i < n; i++){
    if(a[i] == 0){
      v.push_back(1);
      ans = (ans * (3 - v.size() + 1)) % MOD;
    }else {
      int cnt = 0;
      for(int j = 0; j < v.size(); j++){
        if(v[j] == a[i]){
          cnt++;
        }
      }
      if(cnt == 0){
        cout << 0 << endl;
        return 0;
      }else {
        ans = (ans * cnt) % MOD;
        for(int j = 0; j < v.size(); j++){
          if(v[j] == a[i]){
            v.erase(v.begin() + j);
            v.push_back(a[i] + 1);
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2168
package main

import (
	"fmt"
)

func chmax(a *int, b int) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}

func count(N int, abc [][3]int) int {
	dp := make([][3]int, N+1)

	for i := 0; i < N; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if j == k {
					continue
				}
				chmax(&dp[i+1][k], dp[i][j]+abc[i][k])
			}
		}
	}

	var result int
	for i := 0; i < 3; i++ {
		chmax(&result, dp[N][i])
	}

	return result
}

func main() {
	var N int
	fmt.Scan(&N)

	abc := make([][3]int, N)
	for i := 0; i < N; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&abc[i][j])
		}
	}

	fmt.Println(count(N, abc))
}


Measured memory_bytes: 8064
n = int(input())
a = list(map(int, input().split()))

nums = {}
for i in range(n):
    if not a[i] in nums.keys():
        nums[a[i]] = 1
    else:
        nums[a[i]] += 1

ans = 0
for k in nums.keys():
    if nums[k] > k:
        ans += nums[k]-k
    elif nums[k] < k:
        ans += nums[k]
print(ans)


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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;

int main(){
  double r;
  cin >> r;
  double pi=3.14;
  double ca = r*r*M_PI;
  double ce = 2*r*M_PI;
  cout << fixed << setprecision(6) << ca << " " << fixed << setprecision(6) << ce << endl;
}



Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;

int main(){
  int N, M;
  cin >> N >> M;
  int64_t A[N];
  priority_queue<int> que;
  for(int i=0;i<N;i++){
    cin >> A[i];
    que.push(A[i]);
  }
  pair<int, int> P[M];
  for(int i=0;i<M;i++){
    int a, b;
    cin >> a >> b;
    P[i].first = b;
    P[i].second = a;
  }
  int64_t ans1 = 0;
  sort(P, P+M);
  reverse(P, P+M);
  int coun = 0;
  for(int i=0;i<M;i++){
    int a = 0;
    while(a < P[i].second){
      que.push(P[i].first);
      coun++;
      a++;
      ans1 += que.top();
      que.pop();
      if(coun >= N) break;
    }
    if(coun >= N) break;
  }
  while(coun < N){
    ans1 += que.top();
    que.pop();
    coun++;
  }
  cout << ans1 << endl;
}

Measured memory_bytes: 2296
/*
h3110_fr13nd,
 
AUTHOR : @sam_jn
*/
 
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<pair<int, int>, null_type, less_equal<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define NN 1000002
#define in(a, n) for(int i = 0; i < n; i++) cin >> a[i];
#define ot(a, n) for(int i = 0; i < n; i++) cout << a[i] << " ";
#define ot2(a, n) for(int i = 0; i < n; i++) cout << a[i] << "\n";
ll pwr(ll a, ll b);
ll pwr(ll a, ll b, ll m);
int baap[200002];
int prime[NN];
int find(int i);  
bool Union(int x, int y);
ll inv(ll x) {return pwr(x, MOD - 2, MOD);}
void init();
ll max(ll x, ll y, ll z) {return max(x, max(y, z));}
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
//----------------------------------SOLUTION-BELOW-------------------------------------------// 

void solve(){
    int n, cnt = 0;
    cin >> n;
    int a[n];
    in(a, n);
    for(int i = 0; i < n; i++){
        if((i + 1) % 2 && a[i] % 2) cnt++;
    }
    cout << cnt;
    
}
int main(){


                                                            #ifndef ONLINE_JUDGE    
                                                            freopen("/home/samyak/Desktop/CP/input.txt", "r", stdin);
                                                            freopen("/home/samyak/Desktop/CP/output2.txt", "w", stdout);
                                                            #else
                                                            // online submission
                                                            #endif
// 

    boost
    int _ = 1;
    // cout << 0 << endl;
    // cin >> _;
    while(_--){
        solve();
        cout << endl;
    }
}
 
 
//--------------------------------------DEFININTIONS---------------------------------------
ll pwr(ll a, ll b){
    if(b == 0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b == 0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
int find(int i)  
{  
    if (baap[i] != i)  
        baap[i] = find(baap[i]);  
  
    return baap[i];  
}
 
bool Union(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y) return false;
    baap[x] = y;
    return true;
}
void init(){
  for(ll i = 2; i < NN; i++){
      if(prime[i]) continue;
      for(ll j = 2*i; j < NN; j += i)
          prime[j] = i;
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];

    ll ans = 0;
    int S = 0, XorSum = 0;
    int left = 0, right = 0;
    while(right < n){
        XorSum ^= a[right];
        S += a[right];
        if(XorSum != S){
            int len = right - left;
            ans += (ll)len * (len + 1) / 2;
            while(XorSum != S){
                XorSum ^= a[left];
                S -= a[left];
                ++left;
            }
            len = right - left;
            ans -= (ll)len * (len + 1) / 2;
        }
        ++right;
    }
    int len = right - left;
    ans += (ll)len * (len + 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a; i < n; i++)
#define per(i,a,n) for (int i=n-1; i >= a; i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
using namespace std;
int main(){
    uint64 ans = 0;
    int n; cin >> n;
    rep(i,1,n){
        for(int j = 1 ; j*i < n; j++){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3536
n = int(input())
#a, b, c, x, y = map(int, input().split())
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
x = 1
mn = n-1
while x**2 <= n:
    if n % x == 0:
        y = n//x
        mn = min(mn, x+y-2)
    x+=1
    
print(mn)


Measured memory_bytes: 9096
import java.util.Scanner;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        PriorityQueue<Integer> P = new PriorityQueue<>(Comparator.reverseOrder());
        P.add(Math.abs(A-B));
        P.add(Math.abs(B-C));
        P.add(Math.abs(C-A));
        P.poll();
        System.out.println(P.poll()+P.poll());
        sc.close();
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX_P = 10000;

ll nums[MAX_P + 5];

int main() {
    int n, p;
    string s;
    cin >> n >> p >> s;
    if (p == 2) {
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % 2 == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }
    if (p == 5) {
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') == 0 || (s[i] - '0') == 5) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }
    ll num = 0, t = 1;
    nums[0] = 1;
    for (int i = n - 1; i >= 0; i--, t *= 10) {
        t %= p;
        num = (num + (s[i] - '0') * t) % p;
        nums[num]++;
    }
    ll ans = 0;
    for (int i = 0; i < MAX_P; i++) {
        ans += nums[i] * (nums[i] - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 644
#include<stdio.h>
int main()
{
int n,i,j,l=0,m=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
l=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
l++;
}



}

if(l==8)
{

m++;

}




}





}
printf("%d\n",m);
return 0;

}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {
        
        public static void Main() {
            var A = NextInt();
            var B = NextInt();
            var X = NextInt();
            var list = IntList();

            Console.WriteLine(Math.Min(list.Count(n => n < X), list.Count(n => n > X)));
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include<string>
#include <algorithm>
#define NIL -1
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

struct Node { int p, l, r; };
struct Node t[100000];
int D[100000];

void print(int u) {
	cout << "node " << u << ": parent = " << t[u].p << ", depth = "<<D[u]<<", ";
	if (t[u].p == NIL) {
		cout << "root, ";
	}
	else if (t[u].l == NIL) {
		cout << "leaf, ";
	}
	else {
		cout << "internal node, ";
	}
	cout << "[";
	for (int i = 0, c = t[u].l; c != NIL; i++, c = t[c].r) {
		if (i) {
			cout << ", " << c;
		}
		else {
			cout << c;
		}
	}
cout << "]"<<endl;
}
int rec(int u, int p) {
	D[u] = p;
	if (t[u].r != NIL) {
		rec(t[u].r, p);
	}
	if (t[u].l != NIL) {
		rec(t[u].l, p+1);
	}
	return 0;
}

int main()
{
	int r;
	int n; cin >> n;
	REP(i, n) {
		t[i].p = t[i].l = t[i].r = NIL;
	}
	REP(i, n) {
		int id, k,j; cin >> id >> k;
		REP(i, k) {
			int c; cin >> c;
			if (i == 0) {
				t[id].l = c;
			}
			else {
				t[j].r = c;
			}
			j = c;
			t[c].p = id;
		}
	}
	REP(i, n) {
		if (t[i].p == NIL) {
			r = i; break;
		}
	}
	rec(r, 0);
	REP(i, n) {
		print(i);
}
	return 0;
}

Measured memory_bytes: 7732
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
   public static void main(String[] args) {
     
        //sec--1
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] p = new int[N];
        for(int i=0; i<N; i++) {
          p[i] = sc.nextInt();
        }
     
        //sec--2
        Arrays.sort(p); //配列要素を昇順（値が小さい順）で並べ替え
     
        //sec--3
        int cnt = 0;
        for(int i=0; i<K; i++) {
          cnt += p[i];
        }
     
        //sec--4
        System.out.println(cnt);
   }
}


Measured memory_bytes: 38992
#include <bits/stdc++.h>    
#include <unordered_map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cerr<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,x,n) for(int i=x;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define w(x) int x;cin>>x;while(x--)
#define display(a,n) {fo(i,n) {cout<<a[i]<<" ";}cout<<endl;}
#define fil(a,n,val) {fo(i,n) a[i]=val; }
#define sp(x,y) cout<<fixed<<setprecision(y)<<x<<endl;
const ll MOD   = 1000*1000*1000+7;
const ll MOD2  = 998244353;
const ll N = 1000*1000+5;
const double PI  = 3.14159265;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
ll search(vl arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
const int maxn=3e5+5;

int dp[maxn];
int n,k;
int a[105];
// int f=0;

// int solve(int stones, int flag){
// 	if(stones==0){
// 		f=flag;
// 		// cout<<f<<endl;
// 		return dp[stones]=flag;
// 	}
// 	if(dp[stones]!=-1)
// 		return dp[stones];
// 	int leaf=1;
// 	fo(i,n){
// 		if(stones>=a[i]){
// 			leaf=0;
// 			solve(stones-a[i],1-flag);
// 		}
// 	}
// 	if(leaf) f=flag;
// 	return dp[stones]=flag;
// }

int main(){
	fastio();
	fill(dp,-1);
	cin>>n>>k;
	fo(i,n) cin>>a[i];

	fo(i,k+1){
		if(dp[i]!=-1)
			continue;
		fo(j,n){
			if(i+a[j]>k)
				break;
			dp[i+a[j]]=0;
		}
	}

	(dp[k]==0)?cout<<"First"<<endl:cout<<"Second"<<endl;

}

Measured memory_bytes: 4812