akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;
int inSort(int A[],int n,int g){
  int i,j,v;
  int cnt=0;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      ++cnt;
    }
    A[j+g]=v;
  }
  return cnt;
}
void shSort(int A[],int n){
  int i,j,k,l,G[20];

  int m=0; for(i=1;i<=n;i=i*3+1) G[m++]=i;

  int c=0; for(i=m-1;0<=i;i--) c+=inSort(A,n,G[i]);

  printf("%d\n%d",m,G[m-1]);
  for(i=m-2;0<=i;i--) printf(" %d",G[i]);
  printf("\n%d\n",c);
  for(i=0;i<n;i++) printf("%d\n",A[i]);
}
int main(){
  int i,n,A[1000000];
  cin>>n;
  for(i=0;i<n;i++) cin>>A[i];
  shSort(A,n);
  return 0;
}

Measured memory_bytes: 7096
using System;

namespace ALDS1_11_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            int[,] ans = new int[n, n];
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < n; j++)
                {
                    ans[i, j] = 0;
                }
            }
            for (var i = 0; i < n; i++)
            {
                var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                var k = str[1];
                for (var j = 0; j < k; j++)
                {
                    ans[i, str[j + 2] - 1] = 1;
                }
            }

            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < n; j++)
                {
                    if (j > 0)
                    {
                        Console.Write(" ");
                    }
                    Console.Write(ans[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 15952
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; ++i)
    	cin >> a[i];
  sort(a.begin(), a.end());
  if (a[0] == a[1] && a[1] != a[2])
    return (0 & puts("Yes"));
  if (a[1] == a[2] && a[1] != a[0])
    return (0 & puts("Yes"));
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] arr = new long[n];
		long h = (long)Math.pow(10,18);
		//System.out.println(h);
		//int flag =0;
		for(int i=0;i<n;i++){
			arr[i]=sc.nextLong();
			// if(arr[i]==0){
			// 	flag = 1;
			// }
		}
		//if(flag==0){
		Arrays.sort(arr);
		long ans =1;
		for(int i=0;i<n;i++){
			//ans=ans*arr[i];
			if(ans*1.0*arr[i]>1e18){
				System.out.println(-1);
				return;
			}
			ans=ans*arr[i];
		}
		System.out.println(ans>(long)1e18 ? -1:ans);
		//}
		// else{
		// 	System.out.println(0);
		// }
	}
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> x;
  load(x, n);

  int index = -1;
  double mi = 1e9;
  for (int i = 0; i < n; ++i) {
    double dif = abs(a - (t - x[i] * 0.006));
    if (dif < mi) {
      index = i;
      mi = dif;
    }
  }
  p(index + 1);
}

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

int a,b,c,lim1,lim2,tp;

void exgcd(int a,int b,int &x,int &y) {
	if(!b) { x=1;y=0;return; }
	exgcd(b,a%b,y,x);y-=a/b*x;
}

int inv(int a,int p) {
	int x,y;exgcd(a,p,x,y);
	return (x+p)%p;
}

struct dat {
	int x,y,cnt;
} st[110];

void get(int c,int d) {
	tp=0;int a=1,b=0;
	while(d) {
		++tp;st[tp]=(dat){st[tp-1].x+c/d*a,st[tp-1].y+c/d*d,c/d};
		for(int t=0;t<2&&d;t++) {
			if(!t) b+=c/d*a; else a+=c/d*b;
			swap(c,d);d%=c;
		}
	}
}

ll Div(ll a,ll b) {
	if(a<0) return -1;
	return a/b;
}

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int T;cin>>T;
	while(T--) {
		cin>>a>>lim1>>b>>lim2>>c;
		int g=__gcd(a,b);a/=g,b/=g,c/=__gcd(c,g);
		g=__gcd(a,c),a/=g,c/=g,lim2/=g;
		g=__gcd(b,c),b/=g,c/=g,lim1/=g;
		a%=c;b%=c;
		if(c==1) { cout<<lim1+lim2<<'\n';continue; }
		int d=1ll*a*inv(b,c)%c;get(c,d);int ans=0;
		if(st[tp].x!=c) st[++tp]=(dat){c,c,1};
		for(int i=1;i<=tp;i++) {
			int lx=st[i-1].x,ly=c-st[i-1].y,rx=st[i].x,ry=c-st[i].y;
			int dx=(rx-lx)/st[i].cnt,dy=(ly-ry)/st[i].cnt;
			//cerr<<lx<<' '<<ly<<' '<<rx<<' '<<ry<<' '<<dx<<' '<<dy<<' '<<st[i].cnt<<'\n';
			int l=ans,r=lim1+lim2;
			while(l<r) {
				int mid=(1ll+l+r)>>1;
				if(max(0ll,Div(1ll*mid*ly-lim2+dy-1,dy))<=min(1ll*st[i].cnt*mid,Div(lim1-1ll*mid*lx,dx))) l=mid;
				else r=mid-1;
			}
			ans=max(ans,l);
		}
		cout<<ans<<'\n';
	}
	return 0;
}


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

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

    ll money = 1000;
    ll kabu = 0;
    for (int i = 0; i < N-1; ++i) {
    
        if (A[i] < A[i+1]) {
            kabu = money / A[i];
            money = money % A[i];
            money += (kabu * A[i+1]);
        }

    }
    cout << money << endl;

    




}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        String s = new Scanner(System.in).nextLine();
        if (s.indexOf('A') != -1 && s.indexOf('B') != -1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

//返り値は合計の攻撃回数
ll attack (ll H) {
  ll count = 1;
  if (H == 1) {
    return 1;
  } else {
    count += 2 * attack(H/2);
  }
  return count;
}

int main() {
  ll H;
  cin >> H;
  
  cout << attack(H);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	string S;
	cin >> S;
	for(int i = 0; i < S.length() - 1; i++){
		if(S[i] == 'A' && S[i + 1] == 'C'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


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

using namespace std;

using int64 = long long;

namespace FastFourierTransform
{
  using C = complex< double >;

  void DiscreteFourierTransform(vector< C > &F, bool rev)
  {
    const int N = (int) F.size();
    const double PI = (rev ? -1 : 1) * acos(-1);
    for(int i = 0, j = 1; j + 1 < N; j++) {
      for(int k = N >> 1; k > (i ^= k); k >>= 1);
      if(i > j) swap(F[i], F[j]);
    }
    C w, s, t;
    for(int i = 1; i < N; i <<= 1) {
      for(int k = 0; k < i; k++) {
        w = std::polar(1.0, PI / i * k);
        for(int j = 0; j < N; j += i * 2) {
          s = F[j + k];
          t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(), F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
          F[j + k] = s + t, F[j + k + i] = s - t;
        }
      }
    }
    if(rev) {
      double temp = 1.0 / N;
      for(int i = 0; i < N; i++) F[i] *= temp;
    }
  }

  vector< long long > Multiply(const vector< int > &A, const vector< int > &B)
  {
    int sz = 1;
    while(sz <= A.size() + B.size()) sz <<= 1;
    vector< C > F(sz), G(sz);
    for(int i = 0; i < A.size(); i++) F[i] = A[i];
    for(int i = 0; i < B.size(); i++) G[i] = B[i];
    DiscreteFourierTransform(F, false);
    DiscreteFourierTransform(G, false);
    for(int i = 0; i < sz; i++) F[i] *= G[i];
    DiscreteFourierTransform(F, true);
    vector< long long > X(A.size() + B.size() - 1);
    for(int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
    return (X);
  }
};

int main()
{
  int N, M, Q, A[40001], B[40001], C[100000];
  vector< int > F(200001), G(200001);

  scanf("%d %d %d", &N, &M, &Q);
  for(int i = 0; i < N; i++) scanf("%d", &A[i + 1]), A[i + 1] += A[i];
  for(int i = 0; i < M; i++) scanf("%d", &B[i + 1]), B[i + 1] += B[i];
  for(int i = 0; i < Q; i++) scanf("%d", &C[i]);

  for(int i = 1; i <= N; i++) {
    for(int j = 0; j < i; j++) {
      ++F[A[i] - A[j]];
    }
  }
  for(int i = 1; i <= M; i++) {
    for(int j = 0; j < i; j++) {
      ++G[B[i] - B[j]];
    }
  }
  reverse(begin(G), end(G));
  auto X = FastFourierTransform::Multiply(F, G);
  for(int i = 0; i < Q; i++) {
    if(C[i] == 0) printf("%lld\n", X[200000]);
    else printf("%lld\n", X[200000 - C[i]] + X[200000 + C[i]]);
  }
}

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

const double pi = 3.141592653589793;

vector<int> tuuro[200005];
int shirube[100005] = {0};

void wps(int shirube[]){
	queue<int> q;

	q.push(0);
	shirube[0] = 1;
	while(q.size() != 0){
		int tmp = q.front();
		q.pop();
		for(int i=0; i<tuuro[tmp].size(); i++){
			int x = tuuro[tmp][i];
			if(shirube[x] != 0){
				continue;
			}
			shirube[x] = tmp+1;
			q.push(x);
		}
	}
}

int main(){
	int n, m;

	cin >> n >> m;

	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		tuuro[a].push_back(b);
		tuuro[b].push_back(a);
	}

	wps(shirube);

	cout << "Yes" << endl;
	for(int i=1; i<n; i++){
		cout << shirube[i] << endl;
	}
}


Measured memory_bytes: 12820
#include <algorithm>
#include <array>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define vint vector<int>

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> c;
    rep(i, N) {
        int a;
        cin >> a;
        c.push_back({a, i + 1});
    }
    sort(all(c));
    for (auto v : c) {
        cout << v.second << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1780
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int A, B, C, D, E, F;
	int water, sugar, possible;
	int ans1 = 0, ans2 = 0;
	double tmp, den = -1.0;
	set<int> su;
	set<int>::iterator it;
	
	cin >> A >> B >> C >> D >> E >> F;

	repc(c, 0, 3000) {
		if (c * C > F) break;
		repc(d, 0, 3000) {
			if (d * D > F) break;
			su.insert(c * C + d * D);
		}
	}

	repc(a, 0, 30) {
		if (100 * A * a > F) break;
		repc(b, 0, 30) {
			water = 100 * A * a + 100 * B * b;
			if (water > F) break;
			possible = min(F - water, (A * a + B * b) * E);

			it = upper_bound(su.begin(), su.end(), possible);
			if (it == su.begin()) continue;
			else it--;

			sugar = (*it);
			tmp = (double)sugar / (water + sugar);

			if (den < tmp) {
				den = tmp;
				ans1 = water + sugar;
				ans2 = sugar;
			}
		}
	}

	cout << ans1 << ' ' << ans2 << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;

if(N > 64 && N < 91){
cout << "1" << endl;
}
else if(N > 96 && N < 123){
cout << "2" << endl;
}
else{
cout << "0" << endl;
}
}


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

int sa[100005], sb[100005], ta[100005], tb[100005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    rep(i,s.size()){
        sa[i+1] = sa[i] + (s[i] == 'A');
        sb[i+1] = sb[i] + (s[i] == 'B');
    }
    rep(j,t.size()){
        ta[j+1] = ta[j] + (t[j] == 'A');
        tb[j+1] = tb[j] + (t[j] == 'B');
    }
    int q;
    cin >> q;
    rep(qi,q){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int Sa = (sa[b] - sa[a-1]) % 3;
        int Sb = (sb[b] - sb[a-1]) % 3;
        int Ta = (ta[d] - ta[c-1]) % 3;
        int Tb = (tb[d] - tb[c-1]) % 3;
        bool ok = false;
        rep(i,3){
            int A = (Sa + i) % 3;
            int B = (Sb + i) % 3;
            if(A == Ta && B == Tb){
                ok = true;
                break;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}


Measured memory_bytes: 5336
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main()  {
    fastio;
    int n ,k;
    cin>>n>>k;
    vector<ll>p(n+1) , c(n+1);

    for(int i =1 ; i <=n ; i ++ ) cin>>p[i];
    for(int i =1 ; i <=n ; i ++ ) cin>>c[i];

    ll ans = -INF;

    for(int i =1 ; i <=n ; i++ ) {

        vector<ll>rec;

        int now = i;
        
        while(1) {
            now = p[now];
            rec.push_back(c[now]);
            if(now == i) break;
        }
        ll sum = 0;

        int nn = rec.size();
        for(int i =0 ; i < min(k , nn) ; i++ ) {
            sum += rec[i];
            ans = max(ans , sum);
        }


        ll x = k / nn;
        ll y = k % nn;

        if(x == 0 ) continue;

        x--;
        for(int i =0 ; i < y ; i++ ) rec.push_back(rec[i]);

        sum *= x;
        if(x) ans = max(ans , sum);

        for(auto x : rec) {
            sum += x;
            ans = max(ans , sum);
        }

    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3848
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;


vll par(MAX),siz(MAX);

//par[i]=iならiは根（はじめは全て根）
void init(ll n){
  rep(i,0,n){
    par[i]=i;siz[i]=1LL;
  }
  return;
}
//xの根
ll root(ll x){
  return (par[x]==x)?x:par[x]=root(par[x]);
}
//xが根の木とyが根の木を繋げる
void unite(ll x,ll y){
  x=root(x);y=root(y);
  if(x==y){return;}
  if(siz[x]<siz[y]){swap(x,y);}
  siz[x]+=siz[y];
  par[y]=x;
}
//根が同じかどうか
bool same(ll x,ll y){
  return root(x)==root(y);
}
int main(){
  ll n,m;cin>>n>>m;
  init(n);
  rep(i,0,m){
    ll a,b;cin>>a>>b;
    a--;b--;
    unite(a,b);
  }
  ll ans=0;
  rep(i,0,n){
    ans=max(ans,siz[i]);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 10992
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
using namespace std;


#define N_MAX 100
int flg[N_MAX+1];

int main()
{
    int n, k;
    cin >> n >> k;
    
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            flg[a] = 1;
        }
    }
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!flg[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define L long long
using namespace std;
int n;
bitset<4000010> f;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k=0;
	scanf("%d",&n);
	f[0]=1;
	for(i=1;i<=n;i++)
	  {
       scanf("%d",&j);
       f|=f<<j;
       k+=j;
      }
    for(i=(k+1)/2;!f[i];i++);
    printf("%d\n",i);
	return 0;
}


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

using namespace std;

const double pi = 3.141592653589793;

int main(int argc, const char *argv[]) {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double m_rad = (m * 6);
  double h_rad = (h + m / 60.) * 30.;
  double theta = abs(m_rad - h_rad);
  theta /= 180.;
  theta *= pi;
  double ans = a * a + b * b - 2. * a * b * cos(theta);
  cout << fixed << setprecision(9) << sqrt(ans) << '\n';
  return 0;
}

Measured memory_bytes: 4100
#include <algorithm>
#include <cstdio>
int st[2005], len[2005]; 
char str[2005][2005]; 
int main()
{
	// freopen("ARC081-F.in", "r", stdin); 
	int n, m; 
	scanf("%d%d", &n, &m);  
	for (int i = 0; i < n; i++)
		scanf("%s", str[i]); 
	int ans = std::max(n, m);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m - 1; j++)
		{
			if (i && !(str[i - 1][j] ^ str[i][j] ^ str[i - 1][j + 1] ^ str[i][j + 1]))
				len[j]++; 
			else
				len[j] = 1; 
		}
		int tp = 0; 
		for (int j = 0; j < m; j++)
		{
			while (tp && len[st[tp - 1]] >= len[j])
			{
				int x = st[--tp]; 
				if (!tp)
					ans = std::max(ans, (j + 1) * len[x]); 
				else
					ans = std::max(ans, (j - st[tp - 1]) * len[x]); 
			}
			st[tp++] = j; 
		}
	}
	printf("%d\n", ans);
	return 0; 
}


Measured memory_bytes: 4096
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<string>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<queue>
#include<stack>
#include<list>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ll,ll> pll;

#define Max 1000001
#define intinf 2147483647
#define longlonginf 9223372036854775807
#define MOD 998244353
#define MOD2 1000000007
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define vint vector<int>
#define vll vector<long long>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define F(i,n) for(int i = 0;i<n;i++)
#define Fr(i,l,r) for(int i = l;i <= r;i++)
#define rF(i,n) for(int i = n-1;i>=0;i--)


//#define min(a,b) a>b?b:a
//#define max(a,b) a>b?a:b
#define all(arr) arr.begin(),arr.end()
//#define sort(vec) sort(vec.begin(),vec.end())
//#define reverse(vec) reverse(vec.begin(),vec.end())

const ll m = 1e9 + 9;


ll Lpow(ll a,ll b)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b%2)
            ans = (ans*a)%m;
        a = (a*a)%m;
        b = b/2;
    }
    return ans;
}

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


signed main()
{
    fastio;
    
    int h1,m1,h2,m2,k;
    
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    
    int ans = (h2-h1)*60 + m2 - m1;
    
    if(ans <= 0)
        ans += 24*60;
    
    ans = max(ans-k,0);
    
    cout << ans << endl;
   
    return 0;
}


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

int main() {
	int m,n;
	while(cin>>m>>n){
		int arr[102]={};
		int a;
		for(int i=0;i<n;i++){
			cin>>a;
			arr[a]=1;
		}
		for(int i=0;i<100;i++){
			if(arr[m-i]==0){
				cout<<m-i<<'\n';
				break;
			}else if(arr[m+i]==0){
				cout<<m+i<<'\n';
				break;
			}
		}
	}
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    set<int> A;
    rep(i,n){
        int Ai; cin >> Ai;
        A.insert(Ai);
    }
    int m; cin >> m;
    set<int> B;
    rep(i,m){
        int Bi; cin >> Bi;
        B.insert(Bi);
    }
    // 和集合
    set<int> C;
    for(auto Ai: A){
        if(B.count(Ai)) C.insert(Ai);
    }
    for(auto Ci: C){
        cout << Ci << endl;
    }
}


Measured memory_bytes: 23648
#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 Main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N); rep(i, N){ll tmp; cin >> tmp; A.at(i) = tmp - 1;}

    vector<ll> history; // n回目の場所を逐一記録 (0-index)
    map<ll, ll> visited; // 何回目に通った街か？が大事
    history.push_back(0);
    visited[0] = 0;

    ll cnt = 1;
    ll prev = 0;
    ll loop_size;
    vector<ll> loop_array;

    while (true){
        ll next = A.at(prev);
        history.push_back(next);

        if (visited.find(next) != visited.end()){
            loop_size = cnt - visited[next];
            for(ll i=0; i < (ll)(loop_size); i++){
                loop_array.push_back(history.at(visited[next] + i));
            }
            break;
        } else {
            visited[next] = cnt;
        }
        prev = next;
        cnt++;
    }

    // cout << "Loop Size " << loop_size << endl;

    // for (auto h: history){cout << h << " ";}
    // cout << endl;
    // cout << endl;

    // for (auto l: loop_array){cout << l << " ";}
    // cout << endl;
    // cout << endl;

    if (K <= cnt){ // ループ検出前
        cout << history.at(K) + 1 << endl;
    } else { // ループ検出後
        ll tmp = (K - cnt) % loop_size;
        cout << loop_array.at(tmp) + 1 << endl;
    }
}

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


Measured memory_bytes: 20564
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,k;
    cin >> a >> b >> k;
    if(a <= k){
        b -= (k-a);
        a = 0;
    }else{
        a -= k;
    }
    a = max(0LL, a);
    b = max(0LL, b);
    print(a, b);

    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, k, a[1024], sum;
signed main () {
	scanf ("%lld %lld", &n, &k);
	for (int i = 1; i <= n; ++i) scanf ("%lld", a + i);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= k; ++i) sum += a[i];
	printf ("%lld\n", sum); return 0;
}

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;
#define ll long long
double pi=3.141592653589793238462643383279;

ll a[100005];
ll n,k;
ll check(ll d)
{
    ll res=0;
    for(ll i=0;i<n-1;i++)
    res+=(a[i+1]-a[i]-1)/d;
    if(res<=k)
    return 1;
    else
    return 0;
}
int main() {
 ll x,n;
 cin>>x>>n;
 ll s=0;
 FOR(i,0,n)
 {
     ll y;
     cin>>y;
     s+=y;
 }
 cout<<((s>x)?-1:x-s);
}


Measured memory_bytes: 3648
h, w = gets.chomp.split(' ').map(&:to_i)

c = Array.new( w, nil )

# あとで判定を簡単にするため, ダミー枠を作成                                    
c[0] = ['.']*(w+2)
[*1..h].each{|i|
  ary = gets.chomp.split('').map(&:to_s)
  c[i] = ['.'] + ary + ['.']
}
c[h+1] = ['.']*(w+2)

#p c                                                                            


[*1..h].each{|i|
  [*1..h].each{|j|
    if c[i][j] == "#" then
      if (c[i-1][j] == ".") and (c[i+1][j] == ".") and (c[i][j-1] == ".") and (\
c[i][j+1] == ".") then
	puts "No"
	exit 0
      end
    end
  }
}

puts "Yes"

Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
int n,x[45],y[45],jc[10];
int chose(int a[],int x)
{
	int restart=0;
    for(int i=1;i<=n;i++)
	{
        int c=0;
        for(int j=i+1;j<=n;j++)
        {
        	c+=(a[j]<a[i]);
//        	cout<<a[j]<<" "<<a[i]<<" "<<c<<"\n";
		}
        restart+=c*jc[n-i];
    }
	return restart;
}
int main()
{
	jc[0]=1;
	for(int i=1;i<10;i++)
		jc[i]=jc[i-1]*i;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i];
	for(int i=1;i<=n;i++)
		cin>>y[i];
	cout<<abs(chose(x,n)-chose(y,n));
	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    if 0 in A:
        return print(0)
    ans = A[0]
    for a in A[1:]:
        ans *= a
        if 10**18 < ans:
            ans = -1
            break
    print(ans)


if __name__ == '__main__':
    main()


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

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define base 402653189
#define mod 998244353
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define MX 200005

ll n,k;
ll a[MX];
ll sp[MX][65];
int LOG;
void make(){

    for(int j=1;j<=LOG;j++){
        for(int i=1;i<=n;i++){
            if(sp[i][j-1]) sp[i][j]= sp[sp[i][j-1]][j-1];
        }
    }
}
int query(ll node,ll rem){
    if(rem==0) return node;
    int now= LOG;
    while(now>=0 && (1LL<<now)>rem) now--;
    return query(sp[node][now],rem-(1LL<<now));
}

int main(){
	optimize();
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

    cin>>n>>k;
    LOG= log2(k)+1;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sp[i][0]= a[i];
    }
    make();
    cout<<query(1,k)<<endl;
	return 0;
}


Measured memory_bytes: 106884
import numpy as np
import math

n, d = map(int, input().split())
x = np.array([0 for i in range(n)], dtype = np.int64)
y = np.array([0 for i in range(n)], dtype = np.int64)
cnt = 0

for i in range(n):
    wkX, wkY = map(int, input().split())
    x[i] = wkX
    y[i] = wkY
for i in range(n):
    if math.sqrt((x[i] ** 2) + (y[i] ** 2)) <= d:
        cnt += 1
print(cnt)


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

int main(){
    int n;
    cin >> n;
    
    long int ans=0;
    
    for(int i = 1; i <= n; i++){
        if(i%3==0)continue;
        if(i%5==0)continue;
        ans += i;
    }
    cout << ans << endl;
    
    return 0;
}

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

l = []
d = dict()
for v in a:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
        
    if d[v] == 2 or d[v] == 4:
        l.append(v)

if len(l) < 2:
    print(0)
else:
    l.sort()
    print(l[-1] * l[-2])

Measured memory_bytes: 98840
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 300000
#define ll long long
#define ld double
#define mod 998244353
#define MOD 998244353
using namespace std;
ll inv = (mod + 1) / 2; 
ll ksm(ll a, ll b)
{
	if(!b) return 1;
	ll ns = ksm(a, b >> 1);
	ns = ns * ns % mod;
	if(b & 1) ns = ns * a % mod;
	return ns;
}
void FWT(int a[],int n){
    for(int d=1;d<n;d<<=1)
        for(int m=d<<1,i=0;i<n;i+=m)
            for(int j=0;j<d;j++){
                long long x=a[i+j],y=a[i+j+d];
                a[i+j]=(x+y)%MOD;
                a[i+j+d]=(x-y+MOD)%MOD;
            }
}
void IFWT(int a[],int n){
    for(int d=1;d<n;d<<=1)
        for(int m=d<<1,i=0;i<n;i+=m)
            for(int j=0;j<d;j++){
                long long x=a[i+j],y=a[i+j+d];
                a[i+j]=(x+y)%MOD;
                a[i+j+d]=(x-y+MOD)%MOD;
                a[i+j]=(ll)a[i+j]*inv%MOD;
                a[i+j+d]=(ll)a[i+j+d]*inv%MOD;
            }
}
int a[maxn];
int b[maxn];
int c[maxn];
int main()
{
	int N;
	cin>>N;
	int n = 1 << N;
	ll s = 0;
	for(int i = 0; i < n; i++)
		cin>>a[i], s += a[i];	
//	cout<<s<<endl;
	s = ksm(s, mod - 2);

	for(int i = 0; i < n; i++)
		a[i] = 1ll * a[i] * s % mod;
	for(int i = 0; i < n; i++)
		b[i] = 1;
	b[0] -= n;
	FWT(a, n);
//	for(int i = 0; i < n; i++)
//		cout<<a[i]<<" ";
//	cout<<endl;
	FWT(b, n);
	for(int i = 0; i < n; i++)
		c[i] = 1ll * b[i] * ksm(1 - a[i], mod - 2) % mod;
	IFWT(c, n);
	for(int i = 0; i < n; i++)
	{
		ll ns = 1ll * c[i] * a[i] + b[i] - c[i];
		ns %= mod;
	}
	for(int i = 0; i < n; i++)
	{
		ll ans = c[i] - c[0];
		ans %= mod;
		if(ans < 0) ans += mod;
		cout<<ans<<endl;
	}
	return 0;
 } 

Measured memory_bytes: 5888
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        k: usize,
        hs: [usize; n],
    }
    let ans = hs.iter().filter(|h| k <= **h).count();
    println!("{}", ans);
}


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

int main(){
 
  //入力
  int N;
  cin >> N;
  int A[N][N];
  for(int i=0;i<N;i++) for(int j=0;j<N;j++) A[i][j] = 0 ;
  for(int i=0;i<N;i++){
    int X;
    cin >> X;
    for(int j=0;j<X;j++){
      int p; int q;
      cin >> p >> q;
      p--; q++;
      A[i][p]=q;
    }
  }
  
  int MaxNum=0;
  
  for(int i=0;i<(1<<N);i++){
    bitset<15> ibit = static_cast<bitset<15>>(i);
    bool ok = true;
    for(int j=0;j<N;j++){
      if(ibit[j]==0) continue;
      for(int k=0;k<N;k++){
        if(A[j][k]==0) continue;
        if((A[j][k]==2 && ibit[k]==0)||(A[j][k]==1 && ibit[k]==1)){
          ok = false;
          break;
        }
      }
    }
    
    if(ok){
      if(ibit.count() > MaxNum) MaxNum = ibit.count();
    }
    
  }
  
  cout << MaxNum << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int n;
int a[3][3];
bool mark[3][3];
bool used[105];
int b[15];
int main(void){
	REP(i,3)REP(j,3){
		cin>>a[i][j];
		used[a[i][j]]=1;
	}
	cin>>n;
	REP(i,n){
		cin>>b[i];
		if(used[b[i]]){
			REP(j,3)REP(k,3){
				if(a[j][k]==b[i]){
					mark[j][k]=1;
				}
			}
		}	
	}
	bool flag=0;
	REP(i,3){
		if(mark[i][0]&&mark[i][1]&&mark[i][2])flag=1;
	}
	REP(i,3){
		if(mark[0][i]&&mark[1][i]&&mark[2][i])flag=1;
	}
	if(mark[0][0]&&mark[1][1]&&mark[2][2])flag=1;
	if(mark[0][2]&&mark[1][1]&&mark[2][0])flag=1;
	if(flag)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
a,b = map(int, input().split())
s=input()
fd=s.find('-')
t=str.maketrans({
	'-':'',
})
#文字列Wの要素を変換する
#'変換前':'変換後'
T=s.translate(t)
c=len(T)
d=len(s)
if fd+1==a+1:
	if c==d-1:
		print('Yes')
	else:
		print('No')
else:
	print('No')

Measured memory_bytes: 3064
N, W = map(int, input().split())
dp = [[float("inf")] * (10**5 + 1) for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
  w, v = map(int, input().split())
  for j in range(10**5 + 1):
    dp[i+1][j] = min(dp[i][j], (dp[i][j-v] if j >= v else 0) + w)

ans = 0
for i in range(10**5 + 1):
  if dp[-1][i] <= W:
    ans = i
print(ans)

Measured memory_bytes: 313400
w = raw_input()

words = []
while True:
	line = raw_input()
	if line == "END_OF_TEXT":
		break
	else:
		line_list = line.split(" ")
		words += line_list
#print words

cnt = 0
for word in words:
	if w.lower() == word.lower():
		cnt += 1
print cnt

Measured memory_bytes: 6440
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
	int N;
	cin >> N;
	string S = "hon";
	if (N%10==3) {
		S = "bon";
	}
	else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) {
		S = "pon";
	}
	cout << S << endl;

}

Measured memory_bytes: 3628
import java.awt.*;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        String s=sc.next();
        for (int i=0;i<3;i++){
            if (s.charAt(i)=='7'){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 32576
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int x[] = new int[N];
		int y[] = new int[M];

		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
		}
		for (int i = 0; i < M; i++) {
			y[i] = sc.nextInt();
		}

		Arrays.sort(x);
		Arrays.sort(y);

		int x_max = x[N-1];
		int y_min = y[0];

		boolean ans = false;

		for (int i = x_max + 1; i <= y_min; i++) {
			if (X < i && i <= Y) {
				ans = true;
				break;
			}
		}
		if (ans) {
			System.out.println("No War");
		} else {
			System.out.println("War");
		}
	}
}


Measured memory_bytes: 23636
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"io"
	"os"
	"strconv"
)

type IntHeap []int

func (h IntHeap) Len() int {
	return len(h)
}

func (h IntHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h IntHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n - 1]
	*h = old[0:n-1]
	return x
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := bufio.NewScanner(stdin)

	/* 単語ごとに入力するならこれ */
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	m, _ := strconv.Atoi(sc.Text())

	jobs := make(map[int][]int)

	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		jobs[a] = append(jobs[a], b)
	}

	sal := 0

	h := &IntHeap{}
	heap.Init(h)

	for i := 1; i < m + 1; i++ {
		if _, ok := jobs[i]; ok {
			for _, v := range jobs[i] {
				heap.Push(h, v)
			}
		}

		if h.Len() > 0 {
			sal += heap.Pop(h).(int)
		}
	}

	/* 出力用 */
	_, _ = fmt.Fprintf(stdout, "%v\n", sal)
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

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

pair<bool, int> is_ok(int n) {
    int m = 0, sz = 0;
    bool ok = false;
    for (int i = 1; m < n; i++) {
        m += i; sz = i;
        if (m == n) ok = true;
    }
    return make_pair(ok, sz);
}

void print_ans(const vector<vector<int>>& ans) {
    cout << "Yes" << endl;
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i].size() << ' ';
        for (int j = 0; j < ans[i].size(); j++) {
            cout << ans[i][j] << (j+1 == ans[i].size() ? '\n' : ' ');
        }
    }
}

void solve1(int n, int sz) {
    int value = 1, pos = 0, id = 1, p = sz;
    vector<bool> use(n+1, false); use[0] = true;
    vector<vector<int>> ans(sz+1, vector<int>(sz, -1));
    
    // 対角線
    for (int j = 0; j < sz; j++) {
        ans[pos][j] = ans[++pos][j] = value;
        use[value] = true; value += p--;
    }
    
    for (int i = 0; i <= sz; i++) {
        for (int j = i; j < sz; j++) {
            if (ans[i][j] != -1) continue;
            while (use[id]) id = id % n + 1;
            ans[i][j] = id++;
        }
    }
    
    for (int j = 0; j < sz; j++)  {
        for (int i = j; i <= sz; i++) {
            if (ans[i][j] != -1) continue;
            while (use[id]) id = id % n + 1;
            ans[i][j] = id++;
        }
    }
    
    print_ans(ans);
    return;
}

int main() {
    int n, sz;
    bool ok;
    cin >> n;
    tie(ok, sz) = is_ok(n);
    
    if (ok) { solve1(n, sz); return 0; }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define mod 1000000007
    #define f(i,n) for(int i=0;i<(int)n;i++)
    #define Fre(i,a,b) for(int i = a; i < b; i++)
    #define sf(n) scanf("%d", &n)
    #define sff(a,b) scanf("%d %d", &a, &b)
    #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
    #define pfn(n) printf("%d\n", n)
    #define pfs(n) printf("%d ", n)
    #define ff first
    #define ss second
    #define mem(a,b) memset(a,b,sizeof(a))
    #define READ freopen("in.txt", "r", stdin)
    #define WRITE freopen("out.txt", "w", stdout)
    #define sz size()
    #define number_of_digit(n) __builtin_ffs(n);
    #define ll long long
    #define T int
    #define ld long double
    #define endl "\n"

    bool sortbyf(const pair <int,int> a,const pair <int,int> b)
    {   
        if(a.ff==b.ff){
            return (a.ss<b.ss);
        }
        // return (a.ss< b.ss); 
        return (a.ff < b.ff);
    } 

    // int cnt;
    // bool sortbyabs(const pair <ll,ll> a, const pair <ll,ll> b){
    // // {   if(abs(a.ss)==abs(b.ss)){
    // //         return (abs(a.ff)<abs(b.ff));
    // //     }

    //     return (abs(abs(a.ss)-abs(a.ff)) > abs(abs(b.ss)-abs(b.ff))); 
    // } 


    
    
    int main(){   
        ios_base::sync_with_stdio(false); cin.tie(NULL);
        int n;
        cin>>n;
        int a[n];
        f(i,n)cin>>a[i];
        ll dp[n];
        dp[0]=0,dp[1]=abs(a[1]-a[0]);
        for(int i=2;i<n;i++){
            dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]), dp[i-2]+abs(a[i-2]-a[i]));
        }
        cout<<dp[n-1];
    } 

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  int n = b - a;
  int po = 0;
  REP(i, n)
  {
    po += i;
  }
  cout << po - a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	int count;
	vector<int> alphabet(26);						// アルファベットは26文字
	string w;
	cin >> w;

	rep(i, w.length()) alphabet[int(w[i]) - 97]++;	// a(92)～z(122)を0～26にしてカウント

	rep(i, alphabet.size())
	{
		if (alphabet[i] % 2 != 0)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		for(int i = 0; i < 9; ++i)
		{
			String str = stdIn.next();
			int am = stdIn.nextInt();
			int pm = stdIn.nextInt();
			System.out.println(str + " " + (am + pm) + " " + (200 * am + 300 * pm));
		}
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string s;
	cin>>s;
	rep(i, 8){
		int x = s[0]-'0';
		rep(j, 3) x += (s[j+1]-'0')*((i>>j)&1?-1:1);
		if(x==7){
			cout<<s[0];
			rep(j, 3) cout<<((i>>j)&1?'-':'+')<<s[j+1];
			cout<<"=7"<<endl;
			return 0;
		}
	}
	return 0;
}


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

int st[MAX];

int main(){
	string s;
	cin>>s;
	int l = s.length();
	int i = 0;
	int top = -1;
	while(i<l){
		if (s[i]=='S') st[++top] = 1;
		else{
			if (st[top]==1) top--;
			else st[++top] = 2;
		}
		i++;
	}
	cout << top+1;
	return 0;
}


Measured memory_bytes: 1284
N=int(input())
sum=[0]*N
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            a=x*x+y*y+z*z+x*y+y*z+x*z
            if a<=N:
                sum[a-1]=sum[a-1]+1

for i in sum:
    print(i)

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

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int ans1 = 100;
    int ans2 = 0;
    double res = -1.0;
    unordered_set<int> sugars;
    int tmp;
    for (int i = 0; i <= F; ++i) {
        for (int j = 0; j <= F; ++j) {
            tmp = i * C + j * D;
            if (tmp >= 0 && tmp <= F) {
                sugars.insert(tmp);
            }
        }
    }
    for (int sugar : sugars) {
        for (int i = 0; i * 100 * A + sugar <= F; ++i) {
            for (int j = 0; j * 100 * B + sugar <= F; ++j) {
                int water = i * 100 * A + j * 100 * B;
                if (water > 0 && water + sugar <= F && E * water >= 100 * sugar) {
                    if (sugar * 100.0 / (water + sugar) > res) {
                        res = sugar * 100.0 / (water + sugar);
                        ans1 = water + sugar;
                        ans2 = sugar;
                    }
                }
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
    Scanner scan = new Scanner(System.in);
    long H;

    Main(){
        H = scan.nextLong();
        System.out.println(f(H));
    }
    public long f(long H){
        if(H == 1){return (long)1;}
        else{
            return 2*f(H/(long)2)+1;
        }
        
    }


    public static void main(String[] args){
        new Main();
    }
}

Measured memory_bytes: 22228
n, m = map(int, input().split())
info = [[] for _ in range(n)]
for _ in range(m):
    p, s = input().split()
    info[int(p) - 1].append(s)

AC = 0
WA = 0

for meta in info:
    if meta.count('AC') == 0:
        continue
    for s in meta:
        if s == 'AC':
            AC += 1
            break
        else:
            WA += 1
        

print(AC, WA) 


Measured memory_bytes: 20272
// Own template

#include<bits/stdc++.h>

using namespace std;

#define fo(i,n) for(int i=0;i<n;i++);
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define ll long long
#define N 100001
#define MX 1000000001


int main()
{
    string a;
    string b;
    cin>>a;
    int n=a.size();
    cin.sync();
    cin>>b;

    int i,c=0;

    for(i=0;i<n;i++)if(a[i] != b[i])c++;
    cout<<c<<endl;

    return 0;
}
// Happy Coding  (:


Measured memory_bytes: 3916