akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=3e5+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;

vector<int>pos[26];
ll ans;
int main()
{
    	string a,b;

    	cin>>a>>b;

    	for(int i=0;i<sz(a);i++)pos[a[i]-'a'].pb(i);
    	int curr = -1;
    	int add = 0;
    	for(int i=0;i<sz(b);i++){
    
    		int poss = upper_bound(all(pos[b[i]-'a']),curr)-pos[b[i]-'a'].begin();
    		if(poss==sz(pos[b[i]-'a'])){
    			if(curr==-1)return cout<<"-1\n",0;
    			curr=-1;
    			i--;
    			ans+=sz(a);
    			add=0;
    		}
    		else{
    			add  = pos[b[i]-'a'][poss]+1;
    			curr = pos[b[i]-'a'][poss];
    		}
    	}
    	ans+=add;
    	cout<<ans<<"\n";
}	

Measured memory_bytes: 1216
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

bool comp(const string& f, const string& s){
    return f.size() < s.size();
}
int main(void){
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];

    sort(s.begin(), s.end(), comp);
    string shortest = s[0];
    string ans = "";
    vector<vector<int>> usedIndex(n);
    for(int i = 0; i < shortest.size(); i++){
        bool allok = true;
        for(int j = 1; j < n; j++){
            bool ok = false;;
            for(int k = 0; k < s[j].size(); k++){
                bool used = false;
                for(int l = 0; l < usedIndex[j].size(); l++){
                    if(k == usedIndex[j][l]){
                        used = true;
                        break;
                    }
                }
                if(used) continue;
                if(s[j][k] == shortest[i]){
                    ok = true;
                    usedIndex[j].push_back(k);
                    break;
                }
            }
            if(!ok){
                allok = false;
                break;
            }
        }
        if(allok){
            ans += shortest[i];
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 256
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	ll n;
	cin>>n;
	if(n==1){
		cout<<1<<endl;
		return;
	}
	ll dp[n+1];
	dp[0] = 2;
	dp[1] = 1;
	for(ll i=2;i<=n;i++){
		dp[i] = dp[i-1]+dp[i-2];
	}
	cout<<dp[n]<<endl;
	
	return ;
}
 
int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();
 
	}
	return 0;
}

Measured memory_bytes: 384
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    if S[:4] == 'YAKI':
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9996
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()

"""========main code==============="""
t=1
#t=ii()
for _ in range(t):
    a,b=ml()
    if(b-a>=2019):
        print(0)
    else:
        ans=1e18
        for i in range(a,b+1):
            for j in range(i+1,b+1):
                ans=min(ans,(i*j)%2019)
        print(ans)        

Measured memory_bytes: 68516
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////



ll q;
std::vector<bool> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return is_prime;
}
Vi l,r;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>q;
    l.resize(q);r.resize(q);
    rep(i,q){
        cin>>l[i]>>r[i];
    }
    vector<bool> p = Eratosthenes(100001);
    p[1]=false;
    ll ans[100001];
    rep(i,100001)ans[i] = 0;
    rep(i,100000){
        if(i==0)continue;
        ans[i] += ans[i-1];
        if(p[i] && (i%2 == 1)){
            if(p[(i+1)/2]){
                ans[i]++;
            }
        }
    }
    rep(i,q){
        print(ans[r[i]] - ans[l[i]-1]);
    }
    return 0;
}

Measured memory_bytes: 3072
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    char[][] c = new char[2][3];
    String[] str = new String[2];
    
    for(int i=0; i<2; i++){
      str[i] = sc.next();
      for(int j=0; j<3; j++){
        c[i][j] = str[i].charAt(j);
      }
    }

    
    if(c[0][0]==c[1][2] && c[0][1]==c[1][1] && c[0][2]==c[1][0]){
      System.out.println("YES");
    }
    else{
      System.out.println("NO");
    }
  }
}
      
      


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



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

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    int a,b,c;
    cin>>a>>b>>c;

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

}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e6+10;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =   998244353;
int n;
string s[N];
bool comp(string s1,string s2)
{
	int cnt1=0,cnt2=0;
	int c1=0,c2=0;
	for(int i=0;i<s1.size();i++)
	{
		if(s1[i]=='(')
		c1++;
		else
		c1--;
		cnt1=min(cnt1,c1);
	}
	for(int i=0;i<s2.size();i++)
	{
		if(s2[i]=='(')c2++;
		else c2--;
		cnt2=min(cnt2,c2);
	}
	return min(cnt1,c1+cnt2)>min(cnt2,cnt1+c2);

}
int main()
{  fast
 cin>>n;
 for(int i=0;i<n;i++)cin>>s[i];
 sort(s,s+n,comp);
string ss="";
for(int i=0;i<n;i++)
ss+=s[i];
bool ans=true;
int cnt=0;
for(int i=0;i<ss.size();i++)
{
	if(ss[i]=='(')
	cnt++;
	else
	cnt--;
	if(cnt<0)
	ans=false;
}
if(cnt)
ans=false;
if(ans)
cout<<"Yes";
else
cout<<"No";

}


Measured memory_bytes: 37088
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[n+1];
    bitset<4000005>dp;
    int sum=0;
    for(int i=1;i<=n;i++)
    {        
        cin>>a[i];
        sum+=a[i];
    }

    if(n==1)
    {
        cout<<a[1];
        return 0;
    }
    dp.set(0);
    dp[0]=1;
    for(int i=1;i<=n;i++)
    {
        dp|=(dp<<a[i]);
    }
    if(sum%2==0)
    {
        if(dp[sum/2])
        {
            cout<<sum/2;
            return 0;
        }
    }
    sum/=2;
    for(int i=sum+1;i<=4000000;i++)
    {
        if(dp[i])
        {
            cout<<i;
            return 0;
        }
    }
} 


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>

#define MAX 1000000

using namespace std;

int main()
{
	vector<int> input;
	int n;

	while(cin>>n){
		if(n==0){
			cout<<input[input.size()-1]<<endl;
			input.pop_back();
		}
		else input.push_back(n);
	}

	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,m,v,p,a[100010];
vector<int> res;

inline bool check(int x)
{
	int val=n-x+1;
	int cnt=max(0ll,v-val);
	if(a[x]+m<a[p]) return false;
	if(cnt<p) return true; 
	cnt-=p-1;
	int sum=0ll;
	for(int i=p;i<x;i++) sum+=(a[x]+m-a[i]);
	if(sum<m*cnt) return false;
	return true;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>v>>p;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int l=p+1,r=n,ans=p;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)){
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }


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

  ll ans=0;
  if(a>b || (n==1 && a!=b)) ans=0;
  else{
    //選べるのはn-2個の数字
    //a+b+(n-2)*a~~a+b+(n-2)*b
    ans=a+(n-1)*b-b-(n-1)*a+1;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  string S;
  cin>>S;
  
  int ans=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='1'){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3572
import sys
N = int(input())
dic_work = {}
for i in range(N):
    a = [int(i) for i in input().split()]
    dic_work[i] = a

dic_work = sorted(dic_work.items(), key=lambda x: x[1][1])

time = 0
for i, dic in dic_work:
    time += dic[0]
    if time > dic[1]:
        print("No")
        sys.exit()
print("Yes")

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

using namespace std;

const int N = 1e5 + 100;

int h[N];

vector <int> g[N];

int main() {
	int n, m, cnt = 0;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		cin >> h[i];
	for (int i = 1; i <= m; ++i) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for (int i = 1; i <= n; ++i) {
		bool check = 1;
		for (int e: g[i]) {
			if (h[e] >= h[i]) {
				check = 0;
				break;
			}
		}
		if (check)
			++cnt;
	}
	cout << cnt << '\n';

}


Measured memory_bytes: 9144
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

ll n, x;

int main () {
	cin >> n >> x;
	ll ans = n;
	ll l = x, h = n - x;
	if (l < h) swap (l, h);
	while (true) {
//		cout << l << " " << h << " " << ans << endl;
		ll full = l / h;
		ans += full * 2 * h;
		if (l % h == 0) {
			ans -= h;
			break;
		}
		l %= h;
		swap (l, h);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    printf("%d %d %d", C, A, B);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){

int a,b,c,i,x=0;

double d;

scanf("%d %d %d",&a,&b,&c);

for(i=a;i<=b;i++){

d=floor(c/i);

if(c==d*i){

x++;

}


}

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

return 0;

}

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

int main() {
  int n;
  long long ans = 0;
  vector<long long> memo(5), p = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2},
                             q = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3},
                             r = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

  cin >> n;

  vector<string> s(n);

  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (s[i][0] == 'M')
      memo[0]++;
    else if (s[i][0] == 'A')
      memo[1]++;
    else if (s[i][0] == 'R')
      memo[2]++;
    else if (s[i][0] == 'C')
      memo[3]++;
    else if (s[i][0] == 'H')
      memo[4]++;
  }

  for (int i = 0; i < 10; i++) ans += memo[p[i]] * memo[q[i]] * memo[r[i]];

  cout << ans;

  return 0;
}

Measured memory_bytes: 6144
#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.at(i);
    }

    int pre = -999;
    for (int i = 0; i < n; i++)
    {
        if (pre <= a.at(i) - 1)
        {
            pre = a.at(i) - 1;
        }
        else if (pre <= a.at(i))
        {
            pre = a.at(i);
        }
        else
        {
            puts("No");
            return 0;
        }
    }

    puts("Yes");
    return 0;
}

Measured memory_bytes: 640
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:F[v]=t;heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c]+=[(e,d)];E[d]+=[(e,c)]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6308
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
int main(){
    int cnt[5];
    MEM(cnt);
    for(int i=0;i<3;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        cnt[y]++;
    }
    if(cnt[1]<3&&cnt[2]<3&&cnt[3]<3&&cnt[4]<3)printf("YES\n");
    else printf("NO\n");

}

Measured memory_bytes: 256
class dice init = object (self)
  val mutable d:int*int*int*int*int*int = init
  val mutable p:'a list = []

  method private tn (x1,x2,x3,x4,x5,x6):int*int*int*int*int*int = (x2,x6,x3,x4,x1,x5)
  method private ts l = self#tn l |> self#tn |> self#tn
  method private te (x1,x2,x3,x4,x5,x6):int*int*int*int*int*int = (x4,x2,x1,x6,x5,x3)
  method private tw l = self#te l |> self#te |> self#te

  method right x y =
    let rec find l = match l with
        [] -> raise Not_found
      | (x1,x2,x3,x4,x5,x6)::tl -> if x = x1 && y = x2 then x3 else find tl
    in find p

  method gen =
    let rec rotate d = function
        0 -> ()
      | i -> p <- (d::p);rotate (self#te d) (i-1) in
    let rotate2 n = rotate n 4 in
    rotate2 d;
    rotate2 (self#te d |> self#ts);
    rotate2 (self#tw d |> self#ts);
    rotate2 (self#tn d);
    rotate2 (self#ts d);
    rotate2 (self#tn d |> self#tn)
end;;

let split_int s = Str.split (Str.regexp_string " ") s |> List.map int_of_string;;

let () =
  let n = read_line () |> split_int |> List.nth and
      ct = read_int () in
  let l = (n 0,n 1,n 2,n 3,n 4,n 5) in
  let d = new dice l in
  let () = d#gen in
  let rec loop = function
      0 -> ()
    | i -> let read =  read_line () |> split_int |> List.nth in
           Printf.printf "%d\n" (d#right (read 0) (read 1));loop (i-1)
  in loop ct;;

Measured memory_bytes: 2292
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(){

int N;
cin>> N;
int ans=0;
for(int i=1;i<=N;i++){
    if(i>=1 && i<10){
        ans++;
        continue;
    }
    else if(i>=100 && i<1000){
            ans++;
        continue;
    }
    else if(i>=10000 && i<100000){
        ans++;
        continue;
    }
}
cout<<ans<<endl;
    

 return 0;
}

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

//template
#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 ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end



int main(){
   int n,m; cin>>n>>m;
   vector<int> a(n);
   ll sum=0;
   rep(i,0,n)cin>>a[i],sum+=a[i];
   sort(ALL(a));
   printf(4LL*m*a[n-m]>=sum?"Yes\n":"No\n");
   return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int n = int.Parse(Console.ReadLine());

			int ans = n;
			for (int i = 0; i <= n; i++) {
				int cnt = 0;
				// n 円のうち、i 円分を 9^p 円で引き出す。
				int t = i;
				int a = 1;
				//System.Diagnostics.Debug.Write($"{t}:");
				while (t > 0) {
					//System.Diagnostics.Debug.Write($"{a}*{t / a % 9} ");
					cnt += t / a % 9;
					a *= 9;
					t -= t % a;
				}
				//System.Diagnostics.Debug.Write(", ");
				// 残りの n-i 円分を 6^p 円で引き出す。
				t = n - i;
				a = 1;
				//System.Diagnostics.Debug.Write($"{t}:");
				while (t > 0) {
					//System.Diagnostics.Debug.Write($"{a}*{t / a % 6} ");
					cnt += t / a % 6;
					a *= 6;
					t -= t % a;
				}
				//System.Diagnostics.Debug.WriteLine($", {cnt}");
				ans = Math.Min(ans, cnt);
			}
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 27512
import java.util.*;
import java.io.BufferedInputStream;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner (new BufferedInputStream(System.in));
    int x = sc.nextInt();
    int y = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    Long[] pa = new Long[a];
    Long[] pb = new Long[b];
    Long[] pc = new Long[c];
    for(int i = 0; i < a; ++i) {
      pa[i] = sc.nextLong();
    }
    for(int i = 0; i < b; ++i) {
      pb[i] = sc.nextLong();
    }
    for(int i = 0; i < c; ++i) {
      pc[i] = sc.nextLong();
    }
    Arrays.sort(pa, new Comparator<Long>() {
      public int compare(Long x, Long y) {
        if(x > y) return -1;
        else return 1;
      }
    });
    Arrays.sort(pb, new Comparator<Long>() {
      public int compare(Long x, Long y) {
        if(x > y) return -1;
        else return 1;
      }
    });
    Arrays.sort(pc, new Comparator<Long>() {
      public int compare(Long x, Long y) {
        if(x > y) return -1;
        else return 1;
      }
    });
    PriorityQueue<Long> st = new PriorityQueue<>();
    for(int i = 0; i < x; ++i) {
      st.offer(pa[i]);
    }
    for(int i = 0; i < y; ++i) {
      st.offer(pb[i]);
    }
    for(int i = 0; i < c; ++i) {
      long now = st.peek();
      if(pc[i] >= now) {
        st.poll();
        st.offer(pc[i]);
      } else break;
    }
    long res = 0;
    for(Long i : st) {
      res += i;
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 103196
#include <algorithm>
#include <cstdio>
#include <map>

int n;
struct point{
	long long D;
	int id;
}num[100001];
std::map<long long,int>map;
int size[100001],fa[100001],dep[100001];
bool cmp(const point &a,const point &b){return a.D>b.D;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&num[i].D),num[i].id=map[num[i].D]=i,size[i]=1;
	std::sort(num+1,num+n+1,cmp);
	for(int i=1;i<n;i++)
		if(!(fa[i]=map[num[i].D+(size[num[i].id])-(n-size[num[i].id])])||(fa[i]==num[i].id))
			{puts("-1");return 0;}
		else size[fa[i]]+=size[num[i].id];
	for(int i=n-1;i;i--)num[n].D-=(dep[num[i].id]=dep[fa[i]]+1);
	if(num[n].D){puts("-1");return 0;}
	for(int i=1;i<n;i++)printf("%d %d\n",fa[i],num[i].id);
}

Measured memory_bytes: 10368
#include <stdio.h>
  
void rotate_S(int minase_inori[6]) {
    int hayami_saori = minase_inori[0];
    minase_inori[0] = minase_inori[4];
    minase_inori[4] = minase_inori[5];
    minase_inori[5] = minase_inori[1];
    minase_inori[1] = hayami_saori;
}
  
void rotate_NES(int kugimiya_rie[6]) {
    int kitamura_eri = kugimiya_rie[1];
    kugimiya_rie[1] = kugimiya_rie[3];
    kugimiya_rie[3] = kugimiya_rie[4];
    kugimiya_rie[4] = kugimiya_rie[2];
    kugimiya_rie[2] = kitamura_eri;
}
  
int check(const int asumi_kana[6], const int iguti_yuka[6]) {
    int sakura_ayane;
    int satou_satomi[6];
    for (sakura_ayane = 0; sakura_ayane < 6; sakura_ayane++) {
        satou_satomi[sakura_ayane] = iguti_yuka[sakura_ayane];
    }
    for (sakura_ayane = 0; sakura_ayane < 4; sakura_ayane++) {
        int tateno_kanako;
        for (tateno_kanako = 0; tateno_kanako < 6; tateno_kanako++) {
            if (asumi_kana[tateno_kanako] != satou_satomi[tateno_kanako]) break;
        }
        if (tateno_kanako >= 6) {
            return 1;
        }
        rotate_NES(satou_satomi);
    }
    return 0;
}
  
int tokui_sora(const int utida_maaya[6], const int taneda_risa[6]) {
    int igarasi_hiromi[6];
    int horie_yui;
    for (horie_yui = 0; horie_yui < 6; horie_yui++) {
        igarasi_hiromi[horie_yui] = taneda_risa[horie_yui];
    }
    if (check(utida_maaya, igarasi_hiromi)) return 1;
    for (horie_yui = 0; horie_yui < 4; horie_yui++) {
        rotate_NES(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
        if (check(utida_maaya, igarasi_hiromi)) return 1;
        rotate_S(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
    }
    rotate_S(igarasi_hiromi);
    rotate_S(igarasi_hiromi);
    return check(utida_maaya, igarasi_hiromi);
}
  
int main(void) {
    int mizuhasi_kaori;
    int ootani_ikue[100][6];
    int uesaka_sumire, suzaki_aya;
    if (scanf("%d", &mizuhasi_kaori) != 1) return 1;
    for (uesaka_sumire = 0; uesaka_sumire < mizuhasi_kaori; uesaka_sumire++) {
        for (suzaki_aya = 0; suzaki_aya < 6; suzaki_aya++) {
            if (scanf("%d", &ootani_ikue[uesaka_sumire][suzaki_aya]) != 1) return 1;
        }
    }
    for (uesaka_sumire = 0; uesaka_sumire < mizuhasi_kaori; uesaka_sumire++) {
        for (suzaki_aya = uesaka_sumire + 1; suzaki_aya < mizuhasi_kaori; suzaki_aya++) {
            if (tokui_sora(ootani_ikue[uesaka_sumire], ootani_ikue[suzaki_aya])) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
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; }

int main() {
  int a,b;
  cin >> a >> b;
  cout << (a-1) * (b-1) << endl;
  return 0;
}


Measured memory_bytes: 256
def find(grid):
    M=len(grid)
    N=len(grid[0])
    pos=[]
    cut=[[0 for j in range(N)] for i in range(M)]
    for i in range(M):
        for j in range(N):
            if grid[i][j]=="#":
                pos+=[(i,j)]
                
    has_col={} 
    pos=sorted(pos)
    for i in range(len(pos)):
        x,y=pos[i]
        cut[x][y]=i+1
        has_col[y]=1
    
    for i in range(len(pos)):
        x,y=pos[i]
        
        t=1
        while x-t>=0 and cut[x-t][y]==0:
            cut[x-t][y]=i+1
            t+=1
        t=1
        while x+t<M and cut[x+t][y]==0:
            cut[x+t][y]=i+1
            t+=1
    #print(cut)
    
    for x in range(M):
        for y in range(N):
            temp=cut[x][y]
            if cut[x][y]!=0:
                t=1
                while y+t<N and cut[x][y+t]==0 and (y+t not in has_col):
                    cut[x][y+t]=temp
                    t+=1

                t=1
                while y-t>=0 and cut[x][y-t]==0 and (y-t not in has_col):
                    cut[x][y-t]=temp
                    t+=1
    
    return cut

H,W,K=list(map(int,input().strip().split()))
grid=[]
for _ in range(H):
    grid+=[input()]
ans=find(grid)
for x in ans:
    print(*x)

Measured memory_bytes: 13616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
        int n,a,b,i;

        scanf("%d",&n);

        for(i=1;i<=9;i++){
          a = n % i;
          b = n / i;
          if((a == 0) &&(b <= 9)){
            printf("Yes\n");
            return 0;
          }
        }

        printf("No\n");

        return 0;
          


}


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

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

int main(){
	cin.sync_with_stdio(false);
    ll x,y;
    cin>>x>>y;

    if(x%y==0) cout<<-1<<endl;
    else cout<<x<<endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << '\n';
    }else {
        cout << "safe" << '\n';
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         int H=gi();
         int W=gi();
         int N=gi();

         int[] ans=new int[H*W];

         int ind=0;
         boolean f=true;
         for (int i=1; i<=N;i++) {
        	 int a=gi();
        	 for (int j=0; j<a;j++) {
        	     ans[ind]=i;
        	     if(f) {
        		     ind++;
        		     if(ind%W==0) {
        			     ind+=W-1;
        			     f=false;
        		     }
        	     } else {
        		     ind--;
        		     if(ind%W==W-1) {
        			     ind+=W+1;
        			     f=true;
        		     }
        	     }
        	 }
         }

         for (int i=0; i<H;i++) {
        	 for (int j=0; j<W;j++) {
                 int k=i*W+j;
                 if(j!=0)System.out.print(" ");
                 System.out.print(ans[k]);
             }
        	 System.out.println();
         }
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 43232
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n+1]={0},b[n+1]={0},c[n]={0};
  for(int i=1;i<=n;++i){cin>>a[i];}
  for(int i=1;i<=n;++i){cin>>b[i];}
  for(int i=1;i<=n-1;++i){cin>>c[i];}
  int sum=b[a[1]];
  for(int i=2;i<=n;++i)
  {
    sum+=b[a[i]];
    if(a[i]==a[i-1]+1){sum+=c[a[i-1]];}
  }
  cout<<sum;
}
    

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>

const int MAX_V = 1000;

using namespace std;

int nNode;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];

void AddEdge( int from, int to ) {
    G[from].push_back( to );
    rG[to].push_back( from );
}

void DFS( int v ) {
    used[v] = true;
    for ( int i=0; i<G[v].size(); ++i ) {
	if ( !used[G[v][i]] ) DFS( G[v][i] );
    }
    vs.push_back( v );
}

void RDFS( int v, int k ) {
    used[v] = true;
    cmp[v] = k;
    for ( int i=0; i<rG[v].size(); ++i ) {
	if ( !used[rG[v][i]] ) RDFS( rG[v][i], k );
    }
}

int Scc() {

    vs.clear();
    memset( used, 0, sizeof( used ) );
    for ( int v=0; v<nNode; ++v ) {
	if ( !used[v] ) DFS( v );
    }

    memset( used, 0, sizeof( used ) );
    int k = 0;
    for ( int i=vs.size()-1; i>=0; --i ) {
	if ( !used[vs[i]] ) RDFS( vs[i], k++ );
    }

    return k;
    
    /*
    vector<int> grpCount( nNode );
    for ( int i=0; i<nNode; ++i ) {
	if ( grpCount[cmp[i]] > 0 ) return 1;
	++grpCount[cmp[i]];
    }
    return 0;
    */

}

int main() {

    int nEdge;
    if ( scanf("%d %d", &nNode, &nEdge) != 2 ) assert( false );

    int s, t;
    for ( int i=0; i<nEdge; ++i ) {
	if ( scanf("%d %d", &s, &t) != 2 ) assert( false );
	AddEdge( s, t );
    }
    
    printf("%d\n", Scc() == nNode ? 0 : 1 );

    return 0;

}



Measured memory_bytes: 2888
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((int)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;




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

//全探索したらO(10^10)
ll buc[10][10];

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

    ll a, b;
    Rep(i, 1, N){
        b = i%10; //末尾
        a = i;  //先頭
        while(a/10){
            a /= 10;
        }
        buc[a][b]++;
    }
    ll ans = 0;
    Rep(i, 1, 10){
        Rep(j, 1, 10){
            ans += buc[i][j]*buc[j][i];
        }
    }
    co(ans);


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  ll n, h, w;
  cin >> n >> h >> w;
  ll cnt = 0;
  rep(i, n)
  {
    ll a, b;
    cin >> a >> b;
    cnt += (a >= h && b >= w);
  }
  cout << cnt << endl;
  return 0;
}


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

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

    vector<vector<int>> g(n);
    vector<vector<long>> cost(n, vector<long>(n));

    while (m--) {
        long a, b, c; cin>>a>>b>>c;
        --a, --b;
        g[a].push_back(b);
        cost[a][b]=-c;
    }

    const long inf=LONG_MAX;
    vector<long> d(n, inf);
    d[0]=0;
    int cnt=0;
    bool has_negative_loop=false;
    for(int cnt=0; cnt<n+n; ++cnt) {
        for(int v=0; v<n; ++v) {
            for(int u: g[v]) {
                if (d[v]==inf or d[u]<=d[v]+cost[v][u]) continue;
                d[u]=d[v]+cost[v][u];
                if (cnt>=n and u==n-1) has_negative_loop=true;
            }
        }
    }
    if (has_negative_loop)
        cout<<"inf"<<endl;
    else
        cout<<-d[n-1]<<endl;
}


Measured memory_bytes: 8192
n,w=map(int,input().split())
kind=[[] for _ in range(4)]
for i in range(n):
    w_,v=map(int,input().split())
    if i==0:
        stan=w_
    kind[w_-stan].append(v)
for i in range(4):
    kind[i].sort(reverse=True)
    if len(kind[i])>=2:
        for j in range(len(kind[i])-1):
            kind[i][j+1]+=kind[i][j]
    kind[i]=[0]+kind[i]
ans=0
for i in range(len(kind[0])):
    for j in range(len(kind[1])):
        for k in range(len(kind[2])):
            for l in range(len(kind[3])):
                if stan*i+(stan+1)*j+(stan+2)*k+(stan+3)*l<=w:
                    ans=max(ans,kind[0][i]+kind[1][j]+kind[2][k]+kind[3][l])
print(ans)

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define ll long long
int main()
{
	ll n,x;cin>>n>>x;
	ll a=x,b=n-x,ans=n;
	while(a&&b)
	{
		if(a<b) swap(a,b);
		ll t=a/b;
		ans+=t*b*2;
		a%=b;
	}
	cout<<ans-a-b;
	return 0;  
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
using namespace std;
int main(){
    int n,a,b;
    char s;
    cin>>n>>a>>b;
    int A=0,B=0;
    for(int i=0;i<=n;i++){
        scanf("%c",&s);
        if(s=='a'){
            if(A+B<a+b){
                printf("Yes\n");A+=1;}
            else printf("No\n");
        }
        if(s=='b'){
            if(A+B<a+b&&B<b){
                printf("Yes\n");B+=1;
            }
            else printf("No\n");
        }
        if(s=='c')printf("No\n");
    }
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long n = in.nextLong();
            long m = in.nextLong();
            long mod = 1000000007;

            if (Math.abs(n - m) > 1) {
                out.println(0);
                return;
            }

            long nf = 1;
            for (long i = 2; i <= n; i++)
                nf = nf * i % mod;

            long mf = 1;
            for (long i = 2; i <= m; i++)
                mf = mf * i % mod;

            long ans = nf * mf * (n == m ? 2 : 1) % mod;
            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



Measured memory_bytes: 22868
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let mut a: Vec<usize> = (0..3 * N).map(|_| read()).collect();
    a.sort();
    let mut sum = 0;
    for i in (N..).step_by(2) {
        if i >= a.len() {
            break;
        }
        sum += a[i];
    }
    println!("{}", sum);
}


Measured memory_bytes: 5432
n,x,m = map(int,input().split())
rec = [-1 for _ in range(m)]
rec[x] += 1
now = x
cnt = 1
while True:
  now = now ** 2
  now %= m
  #print(now)
  if rec[now] == -1:
    rec[now] = cnt
    cnt += 1
    #print(now,cnt)
  else:
    #print(cnt)
    #print(rec[now])
    break
end = rec[now]
cyc = cnt - end
#print(rec)
#print(end,cyc)
if n <= end:
  ans = 0
  now = x
  for _ in range(n):
    ans += now
    now **= 2
    now %= m
  print(ans)
  exit()
ans = 0
now = x
for i in range(end):
  ans += now
  now **= 2
  now %= m
  n -= 1
ans2 = 0
#print(n,ans)
for i in range(cyc):
  ans2 += now
  #print(now)
  now **= 2
  now %= m
#print(ans2)
db = n // cyc
n %= cyc
ans += ans2 * db
#print(ans,n,now)
ans3 = 0
for _ in range(n):
  ans3 += now
  now **= 2
  now %= m
  #print(now)
#print(ans3)
print(ans+ans3)

Measured memory_bytes: 73824
#include<stdio.h>
#define N 100000

void quickSort(int, int);
int partition(int, int);
int check(int);

int A[N],in1[N];
char C[N],in2[N];

int main(){
  int n,i,a,b,j,flag = 1;
  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    scanf(" %c %d",&C[i],&A[i]);
    in2[i] = C[i];
    in1[i] = A[i];
  }
  quickSort(0,n-1);
  
  if(check(n)==0) printf("Not stable\n");
  else printf("Stable\n");
  
  for(i=0 ; i<n ; i++){
    printf("%c %d\n",C[i],A[i]);
  }
  
  return 0;
}

int check(int n){
  int i,j,a,b;
  for(i=1;i<n;i++){
    if(A[i-1] == A[i]){
      for(j=0;j<n;j++){
        if(A[i-1] == in1[j] && C[i-1] == in2[j]) a = j;
        if(A[i] == in1[j] && C[i] == in2[j]) b = j;
      }
      if(a > b) return 0;
    }
  }
  return 1;
}


void quickSort(int p,int r){
  int q;
  if(p < r){
    q = partition(p,r);
    quickSort(p,q-1);
    quickSort(q+1,r);
  }
}

int partition(int p,int r){
  int x,i,j,a;
  char c;
  x = A[r];
  i = p-1;
  for(j=p ; j<r ; j++){
    if(A[j] <= x){
      i++;
      a = A[i];
      A[i] = A[j];
      A[j] = a;
      c = C[i];
      C[i] = C[j];
      C[j] = c;
    }
  }
    a = A[i+1];
    A[i+1] = A[r];
    A[r] = a;
    c = C[i+1];
    C[i+1] = C[r];
    C[r] = c;
    return i+1;
}



Measured memory_bytes: 2784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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


	//lower_boundってナニ
	int N;
	cin >> N;
	ll A[200000];
	rep(i, N) {
		cin >> A[i];
	}
	rep1(i, N - 1) {
		A[i] = A[i - 1] + A[i];
	}

	ll kotae = 1e18;

	int b;

	for (b = 1; b <= N - 3; b++) {

		auto a = lower_bound(A + 1, A + b + 1, A[b] / 2);
		if (abs(A[b] - *a * 2) > abs(A[b] - *(a - 1) * 2)) a--;

		auto c = lower_bound(A + b + 1, A + N, A[b] + (A[N - 1] - A[b]) / 2);
		if (abs(A[b] + A[N - 1] - *c * 2) > abs(A[b] + A[N - 1] - *(c - 1) * 2)) c--;

		ll retu[4] = { *a, A[b] - *a, *c - A[b], A[N - 1] - *c };
		ll minimum = *min_element(retu, retu + 4);
		ll maximum = *max_element(retu, retu + 4);
		kotae = min(kotae, maximum - minimum);

	}

	co(kotae);
  
	Would you please return 0;
}

Measured memory_bytes: 1792
import sys
N, X = map(int, input().split())
BLU = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
B, L, U = map(list, zip(*BLU))
C = [(u-l)*b for b, l, u in BLU]
D = [(X*u - c, u, c, l, b) for u, c, l, b in zip(U, C, L, B)]
D.sort(reverse = True)
SL = sum(l*b for l, b in zip(L, B))
SS = 0
for i, (d, _, _, _, _) in enumerate(D):
    SS += d
    if SS >= SL:
        break
SSb = SS - d
lans = i*X
m = 10**10
for d, u, c, l, b in D[:i]:
    m = min(m, -(-(c + SL - (SS - d))//u), -(((SS - d) - SL)//l))
    
for _, u, c, l, b in D[i:]:
    m = min(m, -(-(c + SL - SSb)//u), -((SSb - SL)//l))
lans += m

ans = (i+1) * X
m = 0
for _, u, _, _, _ in D[:i+1]:
    m = max(m, (SS - SL)//u)
print(min(lans, ans - m))

Measured memory_bytes: 87260