akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll ans=0;
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  REP(i, n) { cin >> h.at(i); }
  sort(ALL(h),greater<>());
  for (int i = k; i < n;i++){
    ans += h.at(i);
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<ll,ll>
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mit(m) for(map<int, int > :: iterator it=m.begin();it!=m.end();++it)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<ll> >
#define vll vector<ll>
#define mint map<int,int> 
#define int long long
#define sll set<int>
#define pll pair<int,int>

priority_queue<pll> od,ev;
mll odd,even;
void solve(){
	od.push(mp(0,0));
	ev.push(mp(0,0));
	int n;
	cin>>n;
	rep(i,0,n){
		int x;
		cin>>x;
		if(i%2==0){	
			odd[x]++;
		}
		else{
			even[x]++;
		}
	}
	int ans=hell;
	for(auto i:odd){
		od.push(mp(i.second,i.first));
	}
	for(auto i:even){
		if(i.first==od.top().second){
			pll k=od.top();
			od.pop();

			ans=min(ans,n-i.second-od.top().first);

			od.push(k);
		}
		else{
			ans=min(ans,n-i.second-od.top().first);
		}
	}
	cout<<ans;


}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 7676
from sys import stdin
input = stdin.readline

def solve():
    n, m = map(int, input().split())
    if n == 1 and m == 0:
        return 0
    digits = [None] * n

    for _ in range(m):
        s, c = map(int, input().split())
        s -= 1
        if digits[s] is None or digits[s] == c:
            digits[s] = c
        else:
            return -1

    num = 0
    if digits[0] == 0:
        if len(digits) == 1:
            return 0
        else:
            return -1

    for idx, digit in enumerate(digits):
        if digit is None:
            if idx == 0:
                digit = 1
            else:
                digit = 0
        num = num * 10 + digit
    return num

print(solve())



Measured memory_bytes: 3064
package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

func StrStdin() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return strings.TrimSpace(scanner.Text())
}

func Uint64Stdin() uint64 {
	stringInput := StrStdin()
	num, _ := strconv.ParseUint(strings.TrimSpace(stringInput), 10, 64)
	return num
}

func IsPrime(n uint64) bool {
	if n == 1 { return false }
	if n == 2 { return true }
	if n % 2 == 0 { return false }

	for ni := 3; uint64(ni) * uint64(ni) < n; ni += 2 {
		if n % uint64(ni) == 0 { return false }
	}

	return true 
}

func Solve() {
	X := Uint64Stdin()
	start := X

	if IsPrime(X) { 
		fmt.Println(X)
		return
	}

	if X % uint64(2) == 0 { 
		start += 1
	}

	for {
		if IsPrime(start) { break }
		start += 2
	}

	fmt.Println(start)
}

func main() {
	Solve()
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
char s[100][100];
struct shion
{
	int x;
	shion(){}
	shion(int x):x(x){}
	bool operator < (const shion &a)const{return strcmp(s[x],s[a.x])<0;}
}s1,s2;
int pa;
multiset<shion>se;
multiset<shion>::iterator it;
int xi;
int main()
{
	scanf("%d",&xi);while(xi--)s[++pa][0]='a',se.insert(shion(pa));
	scanf("%d",&xi);while(xi--)s[++pa][0]='b',se.insert(shion(pa));
	scanf("%d",&xi);while(xi--)s[++pa][0]='c',se.insert(shion(pa));
	while(se.size()>1)
	{
		it=se.begin(),s1=*it,se.erase(it);
		it=se.end(),it--,s2=*it,se.erase(it);
		int x=s1.x,y=s2.x;
		strcat(s[x],s[y]);
		se.insert(shion(x));
	}
	it=se.begin();
	s1=*it;
	int x=s1.x;
	printf("%s\n",s[x]);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int m,i,j,k,a[7],b[7],g,n[10],dp[8][1001];
	while(1)	{
		scanf("%d",&m);
		if(m==0)	break;
		for(i=0;i<m;i++)	{
			scanf("%d %d",&a[i],&b[i]);
		}
		scanf("%d",&g);
		for(i=0;i<g;i++)	scanf("%d",&n[i]);
		for(i=0;i<=m;i++)	{
			for(j=0;j<=1000;j++)	dp[i][j]=0;
		}
		
		dp[0][0]=1;
		for(i=0;i<m;i++)	{
			for(j=0;j<=1000;j++)	{
				for(k=0;k<=b[i];k++)	{
					if(j+k*a[i]<=1000)	{
						dp[i+1][j+k*a[i]]+=dp[i][j];
					}
				}
			}
		}
		for(i=0;i<g;i++)	{
			printf("%d\n",dp[m][n[i]]);
		}
	}
	return 0;
}


Measured memory_bytes: 1060
H,W,K = map(int,input().split())
L = [-1]*W
def line(n):##n本の縦線で引ける横線場合の数
  if(n<2):
    return 1
  else:
    if(L[n]!=-1):
      return L[n]
    else:
      a = 0
      for i in range(n-1):
        a += line(n-i-2)
      return a+1

arr = [[-1 for i in range(H)] for j in range(W)]
def ans(h,k):
  if(k<1 or k>W):
    return 0
  elif(h==0):
    if(k==1):
      return 1
    else:
      return 0
  else:
    if(arr[k-1][h-1]!=-1):
      return arr[k-1][h-1]
    else:
      arr[k-1][h-1]= ans(h-1,k)*(line(k-1)*line(W-k))+ans(h-1,k-1)*line(k-2)*line(W-k)+ans(h-1,k+1)*line(k-1)*line(W-k-1)
      arr[k-1][h-1] %= 1000000007
      return arr[k-1][h-1]
    
print(ans(H,K))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <ctime>
#include <string>
#include <cstring>
#include <random>
#define mp make_pair
#define pb push_back
#define NAME ""
#define y1 y1_423
#define list lista

using namespace std;

typedef long long ll;
typedef long double ld;

template<typename T>
ostream& operator << (ostream& cout, const vector<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "()");
	}
	cout << "(" << a[0];
	for (int i = 1; i < (int)a.size(); i++) {
		cout << "; " << a[i];
	}
	return (cout << ")");
}

template<typename T>
ostream& operator << (ostream& cout, const set<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T>
ostream& operator << (ostream& cout, const multiset<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T1, typename T2>
ostream& operator << (ostream& cout, const pair<T1, T2> &a) {
	return cout << "(" << a.first << "; " << a.second << ")";
}

random_device gen;
mt19937 rnd(gen());

const int nmax = 2000 * 1000;
const int inf = 2000 * 1000 * 1000;
const ll infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
const int mod = 1000 * 1000 * 1000 + 7;
const ld pi = acos(-1.0);

int n, c, k, t[nmax];

int main() {
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	//freopen(NAME".in", "r", stdin);freopen(NAME".out", "w", stdout);
	scanf("%d%d%d", &n, &c, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", t + i);
	}
	sort(t, t + n);
	int lst = -1, cnt = 0, answer = 0;
	for (int i = 0; i < n; i++) {
		if (lst < t[i]) {
			answer++;
			cnt = 1;
			lst = t[i] + k;
		} else {
			if (cnt < c) {
				cnt++;
			} else {
				answer++;
				lst = t[i] + k;
				cnt = 1;
			}
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


stack<int> Input;

int main() {
  string S; cin >> S;
  int ans = 0;
  
  for (int i = 0; i < S.size(); i++) {
    if (Input.empty()) {
      Input.push(S[i] - '0');
    } else if (S[i] - '0' != Input.top()) {
      ans++;
      Input.pop();
    } else {
      Input.push(S[i] - '0');
    }
  }

  cout << ans*2 << endl;
}


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

int main(){
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  if(K % 2 == 0){
    cout << A - B << endl;
  }
  if(K % 2 == 1){
    cout << B - A << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
n=gets.split.map &:to_i
x=[0,2,5,3]
y=[0,4,5,1]
m=->r,d{r.map{|i|n[i]}.rotate(d).map.with_index{|v,i|n[r[i]]=v}}
gets.chop.chars{|c|m[(c<?F||?V<c)?x:y,c>?R?1:-1]}
p n[0]

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


const int inf = 1e9;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n, m;
  cin >> n >> m;
  
  vector<int> d(n+1, 0);
  vector<vector<int>> g(n+1);
  for(int i=1;i<=m;++i)
  {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    ++d[v];
  }
  
  vector<int> dp(n+1, 0);
  queue<int> q;
  
  for(int i=1;i<=n;++i)
    if(!d[i]) q.push(i);
  
  
  while(!q.empty())
  {
    int u = q.front();
    q.pop();
    for(int v: g[u])
    {
      --d[v];
      if(!d[v])
        q.push(v);
      dp[v] = max(dp[v], dp[u] + 1);
    }
  }
  
  cout << *max_element(dp.begin(), dp.end()) << endl;
  
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  for (int i = 0; i < N; ++i) {
    if (i % 2 == 0) {
      if (S[i] != 'R' and S[i] != 'U' and S[i] != 'D') {
	cout << "No" << endl;
	return 0;
      }
    } else {
      if (S[i] != 'L' and S[i] != 'U' and S[i] != 'D') {
	cout << "No" << endl;
	return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
  while (1){
    int i,m,n,sum=0;
    int L[1000];
    scanf("%d %d",&n,&m);
    if (n==0 && m==0) return 0;
    for (i=0;i<n;i++){
      scanf("%d",&L[i]);
      sum+=L[i];
    }
    sort(L,L+n);
    for (i=n-m;i>=0;i-=m)
      sum-=L[i];
    printf("%d\n",sum);
  }
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct { template <typename T> operator T() { T x; cin >> x; return x; } } IN;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int a=IN,b=IN;
    string s=IN;
    auto solve=[&]() {
        REP(i,a) {
            if(s[i]=='-') return false;
        }
        if(s[a]!='-') return false;
        REP(i,b) {
            if(s[a+1+i]=='-') return false;
        }
        return true;
    };
    cout<<(solve()?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n;
string a;
void nhap()
{
    cin>>n>>a;
}
void xuli()
{
    int d=0;
    for(int i=0;i<n;i++)
        if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')
        {
            d++;
            i+=2;
        }
        cout<<d;
}
int main()
{
    nhap();
    xuli();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N >>S;
  int count =0;
for (int i = 0; i < N-2; i++) {
  if(S.at(i)== 'A' && S.at(i+1)== 'B' && S.at(i+2)== 'C'){
    count ++;
}
}
 cout << count <<endl; 
}

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

typedef long long ll;

int main() {
	int i, j, n, e = 0, w = 0;
	string s;
	cin >> n;
	cin >> s;
	for(i = 0; i < n; ++i) {
		if(s[i] == 'E')	e++;
		else	w++;
	}
	int ans = 1e9, cure = 0, curw = 0;
	for(i = 0; i < n; ++i) {
		int x = curw;
		if(s[i] == 'E')	cure++;
		else	curw++;
		x += e - cure;
		ans = min(ans, x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n, m;
int mod = 1000000007;

int fact(int n) {
	int ret = 1;
	for (int i = 1; i <= n; i++) {
		ret *= i;
		ret %= mod;
	}
	return ret;
}

signed main() {
	cin >> n >> m;
	if (n < m) swap(n, m);
	
	if ((n + m) % 2 == 0) {
		if (n == m) { cout << (2 * fact(n) * fact(n)) % mod << endl; }
		else { cout << 0 << endl; }
	}
	else {
		if (n == m + 1) { cout << (fact(n) * fact(n - 1)) % mod << endl; } 
		else { cout << 0 << endl; }
	}
	
	return 0;
}

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

using namespace std;

int main () {
	char s[10086];
	int k;
	scanf("%d%s", &k, s);
	int str = strlen(s);
	if (k >= str) {
		printf("%s\n", s);
		return 0;
	}
	for (int i = 0; i < k; i++)
		printf("%c", s[i]);
	printf("...");
	puts("");
	return 0;
}


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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

constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
class modint{
public:
  long long x;
  constexpr modint(long long x=0):x((x%MOD+MOD)%MOD){}
  constexpr modint operator-() const{return modint(-x);}
  constexpr modint& operator+=(const modint& a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator-=(const modint& a){
    if((x+=MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator*=(const modint& a){
    (x*=a.x)%=MOD;
    return *this;
  }
  constexpr modint operator+(const modint& a) const{return modint(*this)+=a;}
  constexpr modint operator-(const modint& a) const{return modint(*this)-=a;}
  constexpr modint operator*(const modint& a) const{return modint(*this)*=a;}
  constexpr bool operator==(const modint& a) const{return this->x==a.x;}
  constexpr bool operator!=(const modint& a) const{return this->x!=a.x;}
  constexpr modint pow(long long expo) const{
    if(expo==0)  return 1;
    modint a=pow(expo>>1);
    a*=a;
    if(expo&1)  a*=(*this);
    return a;
  }
  //for prime MOD
  constexpr modint inv() const{return pow(MOD-2);}
  constexpr modint& operator/=(const modint& a){return (*this)*=a.inv();}
  constexpr modint operator/(const modint& a) const{return modint(*this)/=a;}
};
istream& operator>>(istream& is,const modint& a){return is >> a.x;}
ostream& operator<<(ostream& os,const modint& a){return os << a.x;}

//for binomial coefficients
const int MAX=510000;
vector<modint> fac(MAX,0);
vector<modint> finv(MAX,0);
vector<modint> inv(MAX,0);
void COMinit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(int i=2;i<MAX;i++){
    fac.at(i)=fac.at(i-1)*i;
    inv.at(i)=-inv.at(MOD%i)*(MOD/i);
    finv.at(i)=finv.at(i-1)*inv.at(i);
  }
}
modint COM(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0)  return 0;
  return fac.at(n)*finv.at(k)*finv.at(n-k);
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  string S;
  cin >> S;

  vector<int> cnt(26,0);
  rep(i,N)  cnt.at(S.at(i)-'a')++;
  modint ans=1;
  rep(i,26) ans*=modint(cnt.at(i)+1);
  ans-=1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 15396
#include <stdio.h>
#include <math.h>
#define MAX_N 10000
#define MAX_K 9

int N, K;
int D[MAX_K];

int check(int a){
    int i, j, n, m;
    n = (int)log10((double)a)+1;
    for (i=0; i<n; i++){
        m = (a/(int)pow(10, i)) % 10;
        for (j=0; j<K; j++)
            if (m==D[j]) return 1;
    }
    return 0;
}

int main(){
    int i;
    scanf("%d%d", &N, &K);
    for (i=0; i<K; i++)
        scanf("%d", &D[i]);
    
    i=N;
    while (check(i))
        i++;
    
    printf("%d\n", i);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX = 36;

struct Card {
  char suit;
  char value;
};

void trace(struct Card data[], int n) {
  for (int i = 0; i < n; i++) {
    if (i != 0)
      cout << " ";
    cout << data[i].suit << data[i].value;
  }
  cout << endl;
}

int bubbleSort(struct Card A[], int len) {
  int count = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = len - 1; j >= i + 1; j--) {
      if (A[j].value < A[j - 1].value) {
        swap(A[j], A[j - 1]);
        count++;
        flag = 1;
      }
    }
  }
  return count;
}

int selectionSort(struct Card A[], int len) {
  int count = 0;
  for (int i = 0; i < len; i++) {
    int mini = i;
    for (int j = i; j < len; j++) {
      if (A[j].value < A[mini].value) {
        mini = j;
      }
    }
    if (i != mini) {
      swap(A[i], A[mini]);
      count++;
    }
  }
  return count;
}

int main() {
  struct Card data1[MAX + 1];
  struct Card data2[MAX + 1];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> data1[i].suit >> data1[i].value;
  for (int i = 0; i < n; i++)
    data2[i] = data1[i];

  bubbleSort(data1, n);
  selectionSort(data2, n);

  bool isStable = 1;
  for (int i = 0; i < n; i++) {
    if (data1[i].suit != data2[i].suit) {
      isStable = 0;
      break;
    }
  }

  trace(data1, n);
  cout << "Stable" << endl;
  trace(data2, n);
  cout << (isStable ? "Stable" : "Not stable") << endl;
}

Measured memory_bytes: 3092
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
const long long int N = 6999999;
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll n,m,ans = 0;
  int l = 0,cn = 0,f =0;
  cin >> n >> m;
  vector <ll> c(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> c[i];
  }
  sort(all(c));
  vector<pair<ll,ll>>v(m);
  for (int i = 0; i < m; ++i)
  {
    int a,b;
    cin >> a >> b;
    v[i].ff = b;
    v[i].ss = a;
  }
  sort(all(v));
  reverse(all(v));
  for (int i = 0; i < m; ++i)
  {
    cn = v[i].ss;
    while(cn > 0 && l < n && v[i].ff > c[l])
    {
      c[l] = v[i].ff;
      ans += c[l];
      l++;
      cn--;
    }
  }
  
  for (int i = l; i < n; ++i)
  {
    ans += c[i];
  }
  cout << ans;
  return 0;
}


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

const int v_size = 1000;
const int e_size = 2000;
int_t v, e, r;
int_t s[e_size];
int_t t[e_size];
int_t d[e_size];

bool input() {
  if (cin >> v >> e >> r) {
    rep (i, e) cin >> s[i] >> t[i] >> d[i];
    return true;
  }
  return false;
}

const int_t inf = numeric_limits<int_t>::max();
int_t mc[v_size];

void solve() {
  fill(mc, mc+v_size, inf);
  mc[r] = 0;

  int cnt = 0;
  bool updated = true;
  while (updated) {
    updated = false;

    rep (i, e) {
      if (mc[s[i]] == inf) continue;
      if (mc[t[i]] <= mc[s[i]] + d[i]) continue;
      mc[t[i]] = mc[s[i]] + d[i];
      updated = true;
    }

    cnt++;
    if (cnt > v) break;
  }

  if (cnt > v) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    rep (i, v) {
      if (mc[i] == inf) {
        cout << "INF" << endl;
      } else {
        cout << mc[i] << endl;
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (input()) {
    solve();
  }
  return 0;
}



Measured memory_bytes: 3236
n, x = map(int, input().split())
m = [int(input()) for i in range(n)]
s = x - sum(m)
min = min(m)
num = 0
if s == 0:
    print(len(m))

else:
    while s >= 0:
        s = s - min
        num += 1
    print(num-1+len(m))


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    set<char> a;
    for (char i = 'a'; i <= 'z'; i++)
        a.insert(i);

    set<char> b;
    REP(i, s.size())
        b.insert(s[i]);

    set<char> diff;
    set_difference(a.begin(), a.end(),
            b.begin(), b.end(),
            inserter(diff, diff.end()));

    if (diff.size()) {
        auto itr = diff.begin();
        cout << *itr << '\n';
    } else
        cout << "None" << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <utility>
#include <stdio.h>
using namespace std;
int main()
{
    int n,nf,pf,nc,pc;
	cin>>n;
	while(n--){
		int ans=0;
		cin>>nf>>pf>>nc>>pc;
		if(nc>=5&&pc>=2){
			ans=(nf*nc+pf*pc)*0.8;
		}else{
			int tmp=(nf*max(nc,5)+pf*max(pc,2))*0.8;
			ans=min(nf*nc+pf*pc,tmp);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

int main(void){
  int N;
  
  cin>>N;
  vector<int>vec(N);
  for (int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  /*for (int i=0;i<N;i++){
    cout<<vec.at(i)<<endl;
  }*/
  cout<<vec.at(N-1)-vec.at(0)<<endl;
  
  return 0;
}

Measured memory_bytes: 256
import Data.Char

main = do
  xs <- getLine
  print $ sigma $ map digitToInt xs

sigma :: [Int] -> Int
sigma [] = 0
sigma [a] = a
sigma (a:b:cs) = a * 2^(length cs)
               + (sigma $ (a*10 + b):cs)
               + (sigma $ b:cs)


Measured memory_bytes: 508
n,x= [int(i) for i in input().split()]
L=[int(i) for i in input().split()]
d=[0]
for i in range(1,len(L)+1):
    dd=d[i-1]+L[i-1]
    d.append(dd)
num=0
for j in range(len(d)):
    if d[j]<=x:
        num+=1
print (num)

Measured memory_bytes: 3064
#include <stdio.h>

#define HASH 100003

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int h, i, j, N, A;
	list *hash[HASH] = {}, d[200001], *p;
	scanf("%d", &N);
	for (i = 0, j = 0; i < N; i++) {
		scanf("%d", &A);
		h = A % HASH;
		for (p = hash[h]; p != NULL; p = p->next) if (p->v == A) break;
		if (p != NULL) break;
		else {
			d[j].v = A;
			d[j].next = hash[h];
			hash[h] = &(d[j++]);
		}
	}
	if (i == N) printf("YES\n");
	else printf("NO\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 5500
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
const int MAX=2e5+10;
const int MAX2=2e5+4;
const int MAAX=2e18;
const int MOD=1e9+7;
int n,a[3005];
int s1=0,s2=0;
int dp[3005][3005][2];
int fun(int s,int e,bool turn)
{
    if(s>e)
    {
        return 0;
    }
    int &ret=dp[s][e][turn];
    if(ret!=MAAX)
    {
        return ret;
    }
    if(!turn)
    {
        return ret=max(a[s]+fun(s+1,e,!turn),a[e]+fun(s,e-1,!turn));
    }
     return ret=min(-a[s]+fun(s+1,e,!turn),-a[e]+fun(s,e-1,!turn));
}
in main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
  for(int i=0;i<n;++i)
  {
      for(int j=0;j<n;j++)
      {
          for(int k=0;k<2;k++)
          {
              dp[i][j][k]=MAAX;
          }
      }
  }
    cout<<fun(0,n-1,0)<<endl;
    return 0;
}


Measured memory_bytes: 141312
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	int a,b;
	cin >> a >> b;
	cout << (b%a?b-a:a+b) << endl;
}


Measured memory_bytes: 256
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
judge=Counter([('0' if k==0 else '-1' if k<0 else '1') for k in A])

new_list=[i if i>=0 else -i for i in A]
if ((judge['0'] != 0) or (judge['-1'] % 2 == 0)):
    print(sum(new_list))
else:
    print(sum(new_list)-2*min(new_list))

Measured memory_bytes: 14668
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

long long H[200008];

int main()
{
  int i, N, K;
  long long sum = 0;
  cin >> N >> K;
  if(N <= K)
  {
    cout << 0;
    return 0;
  }
  for(i = 1; i <= N; i++)
    cin >> H[i];
  
  sort(H + 1, H + N + 1);
  for(i = 1; i <= N - K; i++)
  {
    sum += H[i];
  }
  cout << sum;
  
  return 0;
}

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

int main() {
    int h1, h2, k1, k2;
    int a, b, c, d;
    int hsum=0, ksum=0;
    cin >> h1 >> h2 >> k1 >> k2;
    cin >> a >> b >> c >> d;
    hsum = h1*a+h1/10*c+h2*b+h2/20*d;
    ksum = k1*a+k1/10*c+k2*b+k2/20*d;
    if(hsum > ksum){
        cout << "hiroshi" << endl;
    }
    else if(hsum < ksum){
        cout << "kenjiro" << endl;
    }
    else{
        cout << "even" << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	if (a <= 0 && 0 <= b) {
    		System.out.println("Zero");
    	} else if (0 < a || (a+b)%2 != 0) {
    		System.out.println("Positive");
    	} else {
    		System.out.println("Negative");
    	}
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

bool is_bad[110000];

int main() {
    int n, m;
    cin >> n >> m;
    int h[n];
    rep(i,n) cin >> h[i];
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (h[a] >= h[b]) {
            is_bad[b] = true;
        }
        if (h[a] <= h[b]) {
            is_bad[a] = true;
        }
    }
    int ans = 0;
    rep(i,n) {
        if (!is_bad[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n;
    cin >> n;
    using P = pair<int, int>;
    vector<P> v(n);
    int tot = 0;
    rep(i, n) {
        string s;
        cin >> s;
        v[i].first = v[i].second = 0;
        for (char c : s) {
            if (c == '(')
                v[i].second++;
            else
                v[i].second--;
            chmin(v[i].first, v[i].second);
        }
        tot += v[i].second;
    }
    if (tot != 0) {
        cout << "No" << endl;
        return 0;
    }
    sort(all(v), [](P a, P b) {
        if (a.first * b.first == 0) {
            return a.first > b.first;
        } else {
            return max(-a.first, -a.second - b.first) <
                   max(-b.first, -b.second - a.first);
        }
    });
    tot = 0;
    for (auto [MIN, val] : v) {
        if (tot + MIN < 0) {
            cout << "No" << endl;
            return 0;
        }
        tot += val;
    }
    cout << "Yes" << endl;
}

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

int main(){
  int n;cin>>n;
  vector<ll> a(n),vec(n+1);
  rep(i,n)cin>>a[i];
  rep(i,n)vec[i+1]=vec[i]+a[i];
  map<ll,ll> mp;
  rep(i,n+1)mp[vec[i]]++;
  ll ans=0;
  for(auto x:mp){
    ll sum=x.second;
    ans+=sum*(sum-1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 18592
// author: Saman Mahdanian
#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;

int n, m, a[N], cnt[N], f[N];

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

	for (int i = 0; i <= n; i++)
		for (int j = max(0, i - cnt[i]); j < i; j++)
			f[j]++;

	int bads = 0;
	for (int i = 0; i < n; i++)
		if (f[i] == 0)
			bads++;

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;

		if (a[x] - cnt[a[x]] >= 0 && (--f[a[x] - cnt[a[x]]]) == 0)
			bads++;
		cnt[a[x]]--;
		a[x] = y;
		cnt[a[x]]++;
		if (a[x] - cnt[a[x]] >= 0 && (f[a[x] - cnt[a[x]]]++) == 0)
			bads--;
		cout << bads << endl;
	}
}

// SamMHD :: May23-2019 :: Another SOALE-NAMAKI...

Measured memory_bytes: 3712
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long c1 = (a - 1) / c;
        long c2 = b / c;
        long cx = c2 - c1;
        long d1 = (a - 1) / d;
        long d2 = b / d;
        long dx = d2 - d1;
        
        long e = lcm(c, d);
        
        long e1 = (a - 1) / e;
        long e2 = b / e;
        long ex = e2 - e1;
        
        long answer = (b - a + 1) - (cx + dx - ex);
        
        System.out.println(answer);
        
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) return a;
        
        return gcd(b, a % b);
    }
}


Measured memory_bytes: 23124
x = int(raw_input())#,k = map(int, raw_input().split(' '))

cumul = 0
cumul += (x / 500) * 1000
x %= 500

cumul += (x / 5) * 5

print cumul
#print 'Yes ' if len(s) >= 6 and s[2] == s[3] and s[4] == s[5] else 'No' #f(n,k)


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

int main() {

    long long X;

    scanf("%lld",&X);

    for( int i=-118; i<=119; i++) {
        for(int j=-118; j<=119; j++) {
            if( (pow(i,5) - pow(j,5)) == X ) {
                printf("%d %d\n",i,j);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 4240
import java.util.*;
 
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    
    int l = sc.nextInt();
    int r = sc.nextInt();
    int d = sc.nextInt();
    int ans = 0;
    for(int i = l; i <= r;i++){
      if(i % d == 0){
        ans++;
      }
    }
    System.out.print(ans);
  }
}

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

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

signed main() {
	EmiliaMyWife

	int n, m;
	cin >> n >> m;
	vector<vector<int>> dp(n+1, vector<int>(m+1));
	vector<string> arr(n);
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	dp[0][1] = 1;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(arr[i-1][j-1] == '.')
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) %MOD;
	cout << dp[n][m] << '\n';

	return 0;
}


Measured memory_bytes: 8564
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans;
ll A[MAXN];
map<ll, ll> cnt;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>k;
	cnt[0]=1;
	for (int i=1; i<=n; i++){
		cin>>x;
		A[i]=(A[i-1]+x-1)%k;
		if (i>=k) cnt[A[i-k]]--;
		ans+=cnt[A[i]]++;
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 14336
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7

using namespace std;

bool DEBUG = false;

//https://maups.github.io/disciplinas/lab2/

main(){
    fastio;
    
    int MAX_VAL = 100;
    
    
    int n, k, x;
    cin >>n >>k;
    
    int v[n], after[n], before[n];
    for(int i=0; i<n; i++){
    	cin >>v[i];
    	after[i] = 0;
    	before[i] = 0;
    	
    	for(int j=i-1; j>=0; j--){
    		if(v[j] > v[i]){
    			after[j]++;
    		}
    		if(v[j] < v[i]){
    			before[i]++;
    		}
    	}
    }
    
    int ans = 0;
    for(int i=0; i<n; i++){
    	if(DEBUG) cout <<v[i] <<" has " <<after[i] <<" smaller after him and " <<before[i] <<" before him" <<endl;
    	ans += (after[i] * ((k*(k+1)/2) % (1000000007)));
    	ans += (before[i] * ((k*(k-1)/2) % (1000000007)));
		ans = ans % (1000000007);
    }
    
    cout <<ans <<endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = [[] for _ in range(n)]
for i in range(1,m+1):
  pi,yi = map(int,input().split())
  a[pi-1].append((yi,i))
ans = [0 for _ in range(m)]
for i in range(n):
  if a[i]:
    a[i].sort(key=lambda x:x[0])
    c = (i+1)*10**6
    for j in range(len(a[i])):
      ans[a[i][j][1]-1] = c + j+1
for xx in ans:
  xs = str(xx)
  xs = "0"*(12-len(xs)) + xs
  print(xs)
  


  

Measured memory_bytes: 33556
#include <iostream>
using namespace std;
typedef long long ll;
ll n, c;

bool chk(ll p) {
	bool v[9]={};
	for(; p; p/=10) v[p%10] = 1;
	return v[3] & v[5] & v[7];
}

void f(ll p) {
	if(p<=n) {
		if(chk(p)) c++;
		f(p*10+3);
		f(p*10+5);
		f(p*10+7);
	}
}

int main() {
	cin>>n;
	f(0);
	cout<<c;
	return 0;
}

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))
#define Ssort(v) sort((v).begin(),(v).end(),[](auto &left,auto &right){return left.second<right.second;})

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

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

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    cout<<n*800-n/15*200<<endl;
}

Measured memory_bytes: 3560
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int n; cin >> n;
	int cnt = 0,data[200000];
	for (int i = 0; i < n; ++i) cin >> data[i];
	int cur = 1;
	for (int i = 0; i < n; ++i) {
		if (cur == data[i]) ++cur;
		else  ++cnt;
	}
	if (cnt == n) cout << "-1" << endl;
	else cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair

const int N = 1e6 + 10;

queue < pair < int , int > > q;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int h, w, k, x1, y1, x2, y2;
    cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
    char ch[h + 10][w + 10];
    int dis[h + 10][w + 10];
    for (int i = 1; i <= h; i ++){
        for (int j = 1; j <= w; j ++){
            cin >> ch[i][j];
            dis[i][j] = N;
        }
    }
    dis[x1][y1] = 0;
    q.push(mp(x1, y1));
    while (!q.empty()){
        int x = q.front().X, y = q.front().Y;
        int d = dis[x][y];
        q.pop();
        int z = y - 1;
        while (max(1, y - k) <= z){
            if (ch[x][z] != '.')
                break;
            if (dis[x][z] < d + 1)
                break;
            if (d + 1 < dis[x][z])
                q.push(mp(x, z));
            dis[x][z] = d + 1;
            z --;
        }
        z = y + 1;
        while (z <= min(y + k, w)){
            if (ch[x][z] != '.')
                break;
            if (dis[x][z] < d + 1)
                break;
            if (d + 1 < dis[x][z])
                q.push(mp(x, z));
            dis[x][z] = d + 1;
            z ++;
        }
        z = x - 1;
        while (max(1, x - k) <= z){
            if (ch[z][y] != '.')
                break;
            if (dis[z][y] < d + 1)
                break;
            if (d + 1 < dis[z][y])
                q.push(mp(z, y));
            dis[z][y] = d + 1;
            z --;
        }
        z = x + 1;
        while (z <= min(x + k, h)){
            if (ch[z][y] != '.')
                break;
            if (dis[z][y] < d + 1)
                break;
            if (d + 1 < dis[z][y])
                q.push(mp(z, y));
            dis[z][y] = d + 1;
            z ++;
        }
    }
    cout << (dis[x2][y2] == N ? -1 : dis[x2][y2]);
    return 0;
}


Measured memory_bytes: 9160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



string N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    
    if (N[0] == N[1] and N[1] == N[2]) printf("Yes\n");
    else if (N[1] == N[2] and N[2] == N[3]) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	if(int(a.find('C'))!=-1 and int(a.rfind('F'))!=-1 and a.find('C')<a.rfind('F'))
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

x, n = list(map(int  , input().split()))
if n ==0  :
    arr = list(map(int ,input().split()))
    print(x)
else :
    
    arr = list(map(int ,input().split()))

    arr.sort()
    mn = arr[0]
    mx = arr[-1]
    if x > mx :
        print(x)
    elif x  <mn  :
        print(x)
    else:
        c = 1e5
        d = {}
        res = 0 
        for i in range(n) :
            d[arr[i]]= 1
        for i in range(mn-1 , mx+2):
            if not d.get(i , 0 ) :
                if abs(i - x)  <c :
                    res  = i
                    c = abs(i -x)

        print(res)
    



                    
                
                
            
                
                                   
                    
                    
               

                
            
            
        








        
                
                  
                
            
            
    
    
        


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

int main()
{
  int N;
  cin >> N;
  vector<int> avec(N);
  for (auto &a : avec)
  {
    cin >> a;
  }
  sort(avec.begin(), avec.end(), greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < avec.size(); i++)
  {
    if (i % 2 == 0)
    {
      Alice += avec[i];
    }
    else
      Bob += avec[i];
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int x1,y1,x2,y2;
	scanf("%d%d%d%d", &x1,&y1,&x2,&y2);
	int x3,y3,x4,y4;
	int a = x2 - x1;
	int b = y2 - y1;
	x3 = x2 - b;
	y3 = y2 + a;
	x4 = x3 - a;
	y4 = y3 - b;
	// printf("a = %d b = %d\n", a,b);
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return (0);
}

Measured memory_bytes: 128