akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

/* -- template -- */

int main() {
    int N, M; cin >> N >> M;
    if(M >= N) {
        cout << "unsafe" << endl;
    }else {
        cout << "safe" << endl;
    }

}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <utility> 
#include <algorithm>
using namespace std;

int main(){
  vector<pair<long long,int> > vepa;
  pair<long long,int> pa;
  long long n,t,d,sta,end,max;
  long long sum;
  cin>>n;
  pa.first=0;
  pa.second=0;
  vepa.push_back(pa);
  t=0;
  sum=0;
  for(int i=0;i<n;i++){
    cin>>d;
    sum+=d;
    t++;
    pa.first=sum;
    pa.second=t;
    vepa.push_back(pa);
  }
  //  for(int i=0;i<vepa.size();i++)cout<<vepa[i].first<<" "<<vepa[i].second<<endl;////
  sort(vepa.begin(),vepa.end());
  // cout<<endl;//////////
  //for(int i=0;i<vepa.size();i++)cout<<vepa[i].first<<" "<<vepa[i].second<<endl;////
  sta=vepa[0].second;
  end=0;
  max=0;
  for(int i=0;i<vepa.size();i++){

    if(vepa[i].first!=vepa[i+1].first){
      if(max<=vepa[i].second-sta){
	max=vepa[i].second-sta;
	//cout<<max<<" "<<i<<"koredesu"<<endl;////////////
      }
      sta=vepa[i+1].second;
    }else if(i==vepa.size()-1){
      if(max<vepa[i].second-sta)max=vepa[i].second-sta;
    }

    //cout<<sta<<"<==="<<endl;/////////
  }
  cout<<max<<endl;
  return 0;
}

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

int main() {
    string A, B;
    cin >> A >> B;

    if (A.size() < B.size()) cout << "LESS" << endl;
    else if(A.size() > B.size()) cout << "GREATER" << endl;
    else {
        if(A < B) cout << "LESS" << endl;
        else if(A == B) cout << "EQUAL" << endl;
        else cout << "GREATER" << endl;
    }
    
    return 0;
}

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

int main(){
    int N,count=0;
    cin >> N;
    vector<int> p(N);
    for (int i=0; i<N; i++) cin >> p.at(i);
    for (int i=0; i<N; i++){
        if (i+1 != p.at(i)) count++;
    }
    if (count <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

void sort(int a[],int n)
{
	int i = 0,j = n-1;
	int pivot = a[(i+j)/2];

	while(true)
	{
		while(a[i] < pivot)i++;
		while(a[j] > pivot)j--;

		if( i >= j )break;

		int hold = a[i];
		a[i] = a[j];
		a[j] = hold;

		i++;
		j--;
	}

	if( i > 1 )sort(a,i);
	if( n-j-1 > 1 )sort(a+j+1,n-j-1);
}

int main()
{
	int N,K,knd = 0,ans = 0;
	int *a;
	int *cnt;

	cin >> N >> K;
	a = new int[N];
	cnt = new int[N+1];

	for(int i=0;i<N+1;i++)
	{
		cnt[i] = 0;
	}

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

	for(int i=0;i<N;i++)
	{
		cnt[a[i]]++;
	}

	for(int i=0;i<N+1;i++)
	{
		if(cnt[i]>0)
		{
			knd++;
		}
	}

	if(knd <= K)
	{
		cout << 0 << endl;
		return 0;
	}
	else
	{
		knd -= K;
	}

	sort(cnt,N+1);

	for(int i=0;knd > 0;i++)
	{
		if(cnt[i]==0)
		{
			continue;
		}
		else
		{
			ans += cnt[i];
			knd--;
		}
	}

	cout << ans << endl;

	delete(a);
	delete(cnt);

	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
	int cord[4];
	int in;

	scanf("%d",&in);
  	cord[0]=in/1000;
	in=in-cord[0]*1000;
	cord[1]=in/100;
	in=in-cord[1]*100;
	cord[2]=in/10;
	in=in-cord[2]*10;
	cord[3]=in/1;
	in=in-cord[3]*1;
	if((cord[0]==cord[1])||(cord[1]==cord[2])||(cord[2]==cord[3])){
	printf("Bad\n");
    }
	else
    {
	printf("Good\n");
    }
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long int ll;

int main(){
  int h, w; cin >> h >> w;
  vector<string> map(100);
  rep(i, 0, h) cin >> map[i];

  rep(i, 0, h){
    bool check = true;
    rep(j, 0, w){
      if(map[i][j] != '.'){
        check = false;
        break;
      }
    }
    if(check){
      map.erase(map.begin()+i);
      i--;
      h--;
    }
  }

  rep(i, 0, w){
    bool check = true;
    rep(j, 0, h){
      if(map[j][i] != '.'){
        check = false;
        break;
      }
    }
    if(check){
      rep(j, 0, h){
        map[j].erase(map[j].begin()+i);
      }
      i--;
      w--;
    }
  }
  rep(i, 0, h)  cout << map[i] << endl;
  return 0;
}

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

int main()
{
int A;
int B;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> A;
	cin >> B;

	if( A >= 13 )
		cout << B << endl;
	else if( A > 5 )
		cout << B / 2 << endl;
	else
		cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//?????°?????£?¨?
		int sum = 0;

		//??\??????a?????????
		int a = sc.nextInt();
		//??\??????b?????????
		int b = sc.nextInt();
		//??\??????c?????????
		int c = sc.nextInt();
		//
		for(int i = a; i <= b; i++){
			if(c % i == 0){
				sum++;

			}
		}
		//?´???°?????°
		System.out.println(sum);
	}
}

Measured memory_bytes: 26308
n = int(input())
x = list(map(int, input().split()))
xx = sorted(x, reverse=True)

m1 = xx[n//2-1]
m2 = xx[n//2]

# print(m1, m2)

for i in range(len(x)):
    if x[i] < m1:
        print(m1)
    elif x[i] >= m1:
        print(m2)


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

int main()
{
	#ifndef ONLINE_JUDGE
     freopen("input1.txt","r",stdin);
     freopen("output1.txt","w",stdout);
   #endif
	int l,d,r,count=0;
	cin>>l>>r>>d;
	for (int i = l; i <=r; ++i)
	{
		if(i % d == 0)
			count++;
	}
	cout<<count;
}

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

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

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

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

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

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

ll n;
ll ans = 0;

void dfs(ll x, int a, int b, int c) {
	if (x > n)return;
	if (a && b && c)ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}

int main() {
	ll n;
	cin >> n;
	vector<pair<ll, ll>>work(n);
	rep(i, n) {
		ll a, b;
		cin >> a >> b;
		work.emplace_back(b, a);
	}
	sort(work.begin(), work.end());
	ll res = 0;
	bool flag = true;
	for (auto v : work) {
		res += v.second;
		if (res > v.first) {
			flag = false;
			break;
		}
	}
	if (flag)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 8320
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools

def j(q):
    if q==1: print("Heisei")
    else:print("TBD")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

def swap(s,pos):
    s[pos]-=1
    s[pos+1]+=1
    print(s)
    if pos == n-2: return s
    if s[pos+2] == 0: swap(s,pos+1)
    return s


#n = ip()                              #入力整数1つ
#h,w= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
if (int(a[0:4]) == 2019 and int(a[5:7]) >= 5) or int(a[0:4]) > 2019 :j(0)
j(1)

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

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

void calc(vector<int> &dp, int D) {
	int n;
	cin >> n;

	while(n--) {
		string s;
		int p;
		cin >> s >> p;

		const unsigned num_D = count(s.begin(), s.end(), 'D');
		if(num_D != s.size()) continue;

		for(int i = D - num_D; i >= 0; --i) {
			if(dp[i] == -1) continue;
			chmax(dp[i + num_D], dp[i] + p);
		}
	}
}

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

	vector<int> dp(D + 1, -1);
	dp[0] = 0;

	calc(dp, D);
	calc(dp, D);
	cout << *max_element(dp.begin(), dp.end()) << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
constexpr ll MAX = 1e6;
class UnionFind {
    int v[MAX];
    int deep[MAX];

  public:
    UnionFind() {
        for(int i = 1; i < MAX; i++) {
            v[i] = i;
            deep[i] = 0;
        }
    }

    int root(int x) {
        if(v[x] == x)
            return x;
        else
            return v[x] = root(v[x]);
    }

    bool same(int x, int y) {
        return (root(x) == root(y));
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(deep[x] > deep[y]) {
            v[y] = x;
        } else {
            if(deep[x] == deep[y]) deep[y]++;
            v[x] = y;
        }
        return;
    }
};

int main() {
    ll n, m, i, j, k;
    cin >> n >> k;
    vector<ll> p(n);
    for(i = 0; i < n; i++) {
        cin >> p[i];
    }
    set<ll> st;
    for(i=0;i<k;i++){
        st.insert(p[i]);
    }
    UnionFind uf;
    ll cnt = 0;
    for(i=k;i<n;i++){
        st.insert(p[i]);
        if(*st.begin()==p[i-k] && *st.rbegin()==p[i]){
            uf.unite(i-k,i-k+1);
            //cout << i-k << endl;
        }
        st.erase(p[i-k]);
    }

    vector<ll> v;
    ll r = 0;
    for(i = 0; i < n-k+1; i++) {
        r = max(r,i);
        while(p[r]<p[r+1] && r-i<k-1)r++;
        if(r - i == k-1) {
            v.push_back(i);
            //cout << i << endl;
        }else if(p[r]>p[r+1])i=r;
    }
    for(ll x:v){
        uf.unite(x,v[0]);
    }
    set<ll> t;
    for(i=0;i<n-k+1;i++){
        t.insert(uf.root(i));
    }
    ll ts = t.size();
    cout << ts << endl;
    //cout << n-k+1-ts << endl;
    return 0;
}

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

void QQ()
{
    for(int i=1; i<10; i++)
        for(int j=1; j<10; j++)
    {
        cout<<i<<"x"<<j<<"="<<i*j<<endl;
    }
}


int main(){

    QQ();
    return 0;
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
static const long long INF = 1000000;
using p = pair<int,string>;
int main(){
    int n,m;
    cin >> n >> m;
    vector <p> vec(m);
    int ans1,ans2;
    ans1 = 0;
    ans2 = 0;
    rep(i,m){
        int x;
        string s;
        cin >> x >> s;
        p pp = {x,s};
        vec[i] = pp;
    }
    set<int> st;
    map <int,int> wa;
    rep(i,m){
        if (vec[i].second == "WA"){
            wa[vec[i].first]++;
        }
        else{
            if (st.find(vec[i].first) == st.end()){
                ans2 += wa[vec[i].first];
                ans1 += 1;
                st.insert(vec[i].first);
                
            }
        }
    }
    cout << ans1 << ' ' << ans2 << endl;

}

Measured memory_bytes: 16308
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cout<<"# "<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=200005;
int a[N],n;

int chk(int c){
	static int x[N],y[N];
	int k=0;
	per(i,n,1){
		while(k&&x[k]>a[i])k--;
		int now=a[i];
		while(k&&x[k]==now&&y[k]==c-1)
			now--,k--;
		if(k&&x[k]==now)y[k]++;
		else x[++k]=now,y[k]=1;
		if(now!=a[i]&&a[i-1]==now)i--;
	}
	return x[1]>=1||x[1]==0&&k==1;
}

int main(){
	read(n);
	int flag=0;
	rep(i,1,n){
		read(a[i]);
		if(a[i]<=a[i-1])flag=1;
	}
	if(!flag){
		puts("1");
		return 0;
	}
	int l=2,r=n,mid;
	while(l<r){
		mid=(l+r)>>1;
		if(chk(mid))r=mid;
		else l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s,t;
  cin >> s >> t;
  vector<ll> pos[26];  
  rep(i,s.size()){
    ll index=s[i]-'a';
    pos[index].pb(i);
  }
  ll ans=0;
  ll j=-1;//今s内でどこか
  rep(i,t.size()){
    ll index=t[i]-'a';
    if(pos[index].empty()){
      cout << -1 << endl;
      return 0;
    }
    if(pos[index][pos[index].size()-1]<=j){
      ans+=s.size();
      j=pos[index][0];
    }
    else {
      ll n_index=upper_bound(pos[index].begin(),pos[index].end(),j)-pos[index].begin();
      j=pos[index][n_index];
    }      
  }
  cout << ans +j+1LL << endl;

  
  return 0;
    

}


Measured memory_bytes: 1736
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  map<string, int> mp;
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    string s, t;
    cin >> s >> t;
    if( s == "insert" ) mp[t]++;
    if( s == "find" ) cout << ( mp.find(t) == mp.end() ? "no" : "yes" ) << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 36348
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    bool can = false;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (((i * 4) + (j * 7)) == N) {
          can = true;
          break;
        }
      }
      if (can) { break; }
    }
    Console.WriteLine(can ? "Yes" : "No");
  }
}


Measured memory_bytes: 13140
from sys import stdin
from math import isinf
import itertools
n, e = map(int, stdin.readline().split())
d = [[float('inf')] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
for i in range(e):
    u, v, c = map(int, stdin.readline().split())
    d[u][v] = c
for k, i, j in itertools.product(range(n), repeat=3):
    if d[i][j] > d[i][k] + d[k][j]:
        d[i][j] = d[i][k] + d[k][j]
for i in range(n):
    if d[i][i] < 0:
        print("NEGATIVE CYCLE")
        exit(0)
for di in d:
    print(*['INF' if isinf(dij) else str(dij) for dij in di])

Measured memory_bytes: 8468
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    [a,b,c] <- sort . map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    print $ (b - a) + (c - b)
    



Measured memory_bytes: 380
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;
#else
#define debug 0;
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, k; std::cin >> n >> k;
  auto ret = 0;
  loop(n) {
    int x; std::cin >> x;
    ret += (x >= k);
  }
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => {
        #[cfg(debug_assertions)]
        eprintln!(">>> {} = {:?}", stringify!($x), $x)
    };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! flush {
    () => {
        std::io::stdout().flush().unwrap();
    };
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    put!(1 - n);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 2144
#include <iostream>
using namespace std;
 
int main(){
    int r, c, i, j;
    int n ,s;
    int w=0;
 
    cin >> r >> c;
 
    int a[r][c];
 
    for(i=0; i<r; i++){
        for(j=0; j<c; j++){
        cin >> a[i][j];
        }
    }
 
    for(i=0; i<r; i++){
        n=0;
        for(j=0; j<c; j++){
            n = n + a[i][j];
            cout << a[i][j] << " ";
        }
        cout << n << endl;;
    }
 
    for(j=0; j<c; j++){
        s=0;
        for(i=0; i<r; i++){
            s = s + a[i][j];
        }
        w = w + s;
        cout << s <<" ";
    }
 
    cout << w << endl;
 
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define forabr(i, a, b) for(int i = int(b)-1; i >= int(a); i--)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x;
    cin >> x;
    cout << x*x << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m;
vector<P> vec;
vector<int> rad;
P s,t;
ll sq(ll x)
{
	return x*x;
}
bool in(int x,P a)
{
	return sq(a.fi-vec[x].fi)+sq(a.sec-vec[x].sec)<rad[x]*rad[x];
}
bool check()
{
	for(int i=0;i<n;i++)
	{
		bool in1,in2;
		in1=in(i,s);in2=in(i,t);
		if(in1!=in2)return false;
		if(in1&&in2)continue;
		ll a=s.fi,b=s.sec,c=t.fi,d=t.sec,p=vec[i].fi,q=vec[i].sec;
		if(a>c)
		{
			swap(a,c);swap(b,d);
		}
		if(a==c)
		{
			if(min(b,d)<=vec[i].sec&&vec[i].sec<=max(b,d)&&abs(vec[i].fi-a)<=rad[i])
			{
				return false;
			}
			else continue;
		}
		ll A=sq(d-b)+sq(c-a);
		ll B=(b*c-a*d)*(d-b)-p*sq(c-a)-(c-a)*(d-b)*q;
		ll C=p*p*sq(c-a)+sq(b*c-a*d-q*c+q*a)-sq(rad[i])*sq(c-a);
		if(B*B-A*C<0)continue;
		else if(B*B-A*C==0)
		{
			if(a<=(-B/A)&&(-B/A)<=c)return false;
			else continue;
		}
		else
		{
			double ans1=(-B+sqrt(B*B-A*C))/A;
			double ans2=(-B-sqrt(B*B-A*C))/A;
			if(ans1>=a&&ans2<=c)return false;
			else continue;
		}
	}
	return true;
}
int main()
{
	while(1)
	{
		vec.clear();
		rad.clear();
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			P k;
			int r;
			scanf("%d %d %d",&k.fi,&k.sec,&r);
			vec.pb(k);
			rad.pb(r);
		}
		scanf("%d",&m);
		for(int i=0;i<m;i++)
		{
			scanf("%d %d %d %d",&t.fi,&t.sec,&s.fi,&s.sec);
			if(check())puts("Danger");
			else puts("Safe");
		}
	}
	return 0;
}

Measured memory_bytes: 1192
#!/usr/bin/env python3

N, K = list(map(int, input().split()))

x = N % K
done_list = [x]
min_x = x
while True:
    x = abs(x - K)
    done_list.append(x)
    min_x = min(x, min_x)
    if x in done_list:
        break
ans = min_x

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

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

    vector<pair<int,int>> v;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        v.push_back({b,a});
    }

    sort(all(v));

    int ans=0;
    int pre=0;

    rep(i,m){
        int t=v[i].first;
        int s=v[i].second;
        if(s>=pre){
            ans++;
            pre=t;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4280
# -*- coding: utf-8 -*-
# 整数の入力
num = int(raw_input())
for_sum=0
for_min=10**11
is_same=True
for i in range(num):
	# スペース区切りの整数の入力
	a, b = map(int, raw_input().split())
	for_sum+=a
	for_min=b if (a>b and for_min > b) else for_min
	is_same=is_same and (a==b)

print 0 if is_same else for_sum-for_min


Measured memory_bytes: 3332
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll h, w;
	cin >> h >> w;
	vector<string>a(h);
	for (ll i = 0; i < h; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < w+2; i++) {
		cout << "#";
	}
	cout << endl;
	for (ll i = 0; i < h; i++) {
		cout << "#";
		for (ll j = 0; j < w; j++) {
			cout << a[i][j];
		}
		cout << "#"<<endl;
	}
	for (ll i = 0; i < w+2; i++) {
		cout << "#";
	}
	cout << endl;


}



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

using namespace std;

typedef long long ll;
ll n, mx, sum, a[105];
int b[105][105];

void f(ll p)
{
    if(p > n)
    {
        sum = 0;
        for(ll i = 1; i <= n; i++)
        {
            sum += a[i];
        }
        mx = max(mx, sum);
        return;
    }
    f(p + 1);
    if(a[p] < 0) {
        for(int i = p; i <= n; i += p) b[p][i] = a[i];
        for(int i = p; i <= n; i += p) a[i] = 0;
        f(p + 1);
        for(int i = p; i <= n; i += p) a[i] = b[p][i];
    }
}

int main()
{
    scanf("%lld", &n);
    for(ll i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
    }
    for(ll i = n; i > n / 4; i--)
    {
        ll sum = 0;
        for(ll j = i; j <=n; j += i) sum += a[j];
        if(sum < 0) for(ll j = i; j <=n; j += i) a[j] = 0;
    }
    f(1);
    printf("%lld", mx);
    return 0;
}


Measured memory_bytes: 256
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL)

const ll modd=1e9+7;
const ll inff=1e18;

ll poww(ll a,ll b,ll modulo){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a)%modulo;
    a=(a*a)%modulo;
    b=b>>1LL;
  }
  return ans;
}

/*-----------------------------------------------------------------------------------------------*/

int main(){
  fastt;
   
  ll n , rem[3] = {0} , tot = 0;
  string x;

  cin >> n >> x;

  for(auto j: x) tot += (j == '1' ? 1 : 0);

  for(ll i = 0; i < n; i++){
      if(tot - 1 > 0){
          rem[0] = (rem[0] + (x[i] - '0') * poww(2,n-i-1,(tot-1))) % (tot-1);
      }
      if(tot > 0){
          rem[1] = (rem[1] + (x[i] - '0') * poww(2,n-i-1,(tot))) % (tot);
      }
      if(tot+1 > 0){
          rem[2] = (rem[2] + (x[i] - '0') * poww(2,n-i-1,(tot+1))) % (tot+1);
      }
  }


  for(ll i = 0; i < n; i++){
      ll ans = 0 , num = 0 , cnt = 0;
      if(x[i] == '1'){
          if(tot - 1 > 0) {
              ans++;
              num = (rem[0] - poww(2,n-i-1,tot-1) + 2*(tot-1)) % (tot-1);
          }
          while(tot-1 > 0 && num > 0){
              cnt = __builtin_popcount(num);
              num %= cnt;
              ans++;
          }
          cout << ans << '\n';
      }
      else{
          if(tot + 1  > 0) {
              ans++;
              num = (rem[2] + poww(2,n-i-1,tot+1)) % (tot+1);
          }
          while(tot+1 > 0 && num > 0){
              cnt = __builtin_popcount(num);
              num %= cnt;
              ans++;
          }
          cout << ans << '\n';
      }
      
  }
 
  return 0;
}


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

using ll = long long int;
using P = std::pair<int, int>;
using T = std::tuple<int, int, int>; //from,to,coin

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

constexpr int INF = 1e9;

std::vector<std::vector<int>> to, rto;

std::vector<bool> ok1, okn;

std::vector<bool> &vec(int g)
{

    return (g == 1) ? ok1 : okn;
}

int n;

void dfs(int x)
{
    if (ok1[x])
        return;
    ok1[x] = 1;
    for (int y : to[x])
    {
        dfs(y);
    }
}

void rdfs(int x)
{
    if (okn[x])
        return;
    okn[x] = 1;
    for (int y : rto[x])
    {
        rdfs(y);
    }
}

int main()
{

    int m, p;

    std::cin >> n >> m >> p;

    std::vector<T> edges;
    to.resize(n + 1, std::vector<int>());
    rto.resize(n + 1, std::vector<int>());
    ok1.resize(n + 1);
    okn.resize(n + 1);

    rep(i, m)
    {
        int a, b, c;
        std::cin >> a >> b >> c;
        edges.emplace_back(b, a, c);
        to[a].push_back(b);
        rto[b].push_back(a);
        //std::cerr << "DEBUG" << std::endl;
    }

    dfs(1);
    rdfs(n);

    /*std::cerr << "DEBUG" << std::endl;
    rep(i, n)
    {
        if (!ok1[i + 1] || !okn[i + 1])
            std::cerr << i + 1 << ' ';
    }

    std::cerr
        << std::endl;*/

    std::vector<int> d(n + 1, -INF);

    //std::cerr << "DEBUG" << std::endl;

    bool res = 1;

    d[n] = 0;

    int cnt = 0;

    while (res && cnt <= n)
    {
        //std::cerr << "AA" << std::endl;
        res = 0;

        for (T t : edges)
        {
            int from, to, coin;
            std::tie(from, to, coin) = t;
            if (d[from] == -INF || !ok1[to] || !okn[to])
                continue;
            else if (d[to] < d[from] + coin - p)
            {
                d[to] = d[from] + coin - p;

                res = 1;
            }
        }
        /*rep(i, n)
                std::cerr
            << d[i + 1] << ' ';
        std::cerr << std::endl;*/
        ++cnt;
    }

    if (cnt > n)
        std::cout << -1 << std::endl;
    else
    {
        std::cout << ((d[1] < 0) ? 0 : d[1]) << std::endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	vector<int> sum(n + 1);
	int ten = 1;
	for (int i = n - 1; i >= 0; --i) {
		int a = (s[i] - '0') * ten % p;
		sum[i] = (sum[i + 1] + a) % p;
		ten *= 10; ten %= p;
	}
	if (p == 2 || p == 5) {
		ll ans = 0;
		rep(i, n)
			if ((s[i] - '0') % p == 0) ans += (i + 1);
		printf("%lld\n", ans);
	}
	else {
		vector<int> res(p);
		ll ans = 0;
		for (int i = n; i >= 0; --i) {
			ans += res[sum[i]];
			res[sum[i]]++;
		}
		printf("%lld\n", ans);
	}
	return 0;
}


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

int main(){
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if (A >= K){
    cout << K << endl;
  }
  else if (B >= K - A){
    cout << A << endl;
  }
  else{
    cout << A - K + A + B << endl;
  }
}


Measured memory_bytes: 3636
#include <bits//stdc++.h>
using namespace std;
int main(void){
    while(1){
        int a,b,c,i,j,k,f;
    cin>>b>>a;
    if(a==0&&b==0)
    break;
    int train_cost[a][a];
    int train_time[a][a];
    for(i=0;i<a;i++){
        for(j=0;j<a;j++){
            if(i==j){
                train_time[i][j]=0;
                train_cost[i][j]=0;
            }
            else{
                train_time[i][j]=INT_MAX/2;
                train_cost[i][j]=INT_MAX/2;
            }
        }
    }
    for(i=0;i<b;i++){
        int d,e;
        cin>>d>>e;
        cin>>train_cost[d-1][e-1]>>train_time[d-1][e-1];
        train_cost[e-1][d-1]=train_cost[d-1][e-1];
        train_time[e-1][d-1]=train_time[d-1][e-1];
    }
    for(k=0;k<a;k++){
        for(j=0;j<a;j++){
            for(i=0;i<a;i++){
                train_cost[i][j]=min(train_cost[i][j],train_cost[i][k]+train_cost[k][j]);
                train_time[i][j]=min(train_time[i][j],train_time[i][k]+train_time[k][j]);
            }
        }
    }
    cin>>f;
    for(i=0;i<f;i++){
        int d,e;
        cin>>d>>e>>c;

        if(c)
        cout<<train_time[d-1][e-1]<<endl;
        else
        cout<<train_cost[d-1][e-1]<<endl;
    }
    }
    return 0;
}



Measured memory_bytes: 3164
#ALDS1_3_A
exp = input().split()
stack = []
for op in exp:
  if op not in ["+", "-", "*"]:
    stack.append(int(op))
  else:
    if op == "+":
      ans = stack[-2] + stack[-1]
    elif op == "-":
      ans = stack[-2] - stack[-1]
    elif op == "*":
      ans = stack[-2] * stack[-1]
    del stack[-2:]
    stack.append(ans)
print(ans)


Measured memory_bytes: 5600
#include "iostream"
using namespace std;
int main() {
	int a, b, c, d, s1, s2;
	cin >> a >> b >> c >> d;
	s1 = a*b;
	s2 = c*d;
	if (s1 > s2)cout << s1 << endl;
	else cout << s2 << endl;
	return 0;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m,h,w,k,a,b;
string s;
//Write From this Line
ll mod = 1e9+7;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
vector<pair<ll,ll>> factorization(ll n){
	ll k = n;
	vector<pair<ll,ll>> fact(0);
	for(int i = 2 ; i * i <= n ; i ++){
		ll count = 0 ;
		while(k % i == 0){
			count ++ ;
			k /= i;
		}
		if(count != 0){
			fact.emplace_back(i,count);
		}
	}
	if(k!=1){
		fact.emplace_back(k,1);
	}

	return fact;
}


int main()
{
	cout << setprecision(10);
	cin >> n >> m;
	vector<pair<ll,ll>> fact;
	fact = factorization(m);
	ll ans = 1;
	COMinit();
	for(auto x : fact){
		ll k;
		k = x.second;
		//n人にk個の因数を分ける。物はk+n-1、仕切りはn-1
		ans *= COM(k+n-1,n-1);
		ans %= mod;
	}

	cout << ans << endl;
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
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;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;string s;
    cin>>n>>s;
    ll ans=0;
    rep(i,n-2){
        ans+=(s.substr(i,3)=="ABC");
    }
    puta(ans);
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N,M = map(int,input().split())
# N,M=10**5,10**5
A = list(reversed(sorted(map(int,input().split()))))

# A = [i for i in range(N)]

indices = np.zeros(M, dtype = np.int)
Bs = np.empty(M, dtype=np.int)
Cs = np.empty(M, dtype=np.int)

for m in range(M):
    B,C = map(int,input().split())
    # B,C = m,m+1
    indices[m] = C
    Bs[m] = B
    Cs[m] = C

indarg = np.argsort(-indices)


i = 0
m_gen = 0
sumval = 0
c = 0
while c<N:
    if m_gen < M and A[i] < Cs[indarg[m_gen]]:
        m = indarg[m_gen]
        for b in range(Bs[m]):
            # A[i] = Cs[m]
            # A.insert(i, Cs[m])
            c += 1
            # print("cs", Cs[m])
            sumval += Cs[m]
            if c >= N:
                break
        m_gen += 1
    else:
        # print("a", A[i])
        sumval += A[i]
        i += 1
        c += 1


print(sumval)
    



Measured memory_bytes: 23400
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
using namespace::std;


long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
    for (int i=g; i<n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
//        printf("i=%d,g=%d,j=%d,v=%d\n",i,g,j,v);
//        printf("---\n");
//        for (int i = 0; i < n; i++) {
//            cout << A[i];
//            if(i != n-1){
//                cout << " ";
//            }
//        }
//        cout << endl;
    }

}


void shellSort(int A[], int n){
    for (int h=1; ; ) {
        if (h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    }
    for (int i = G.size()-1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

int main(int argc, const char * argv[]) {
    cin >> n;
    for (int i = 0; i<n; i++) {
        scanf("%d", &A[i]);
    }
    cnt = 0;
    
    shellSort(A,n);
    
    cout << G.size() << endl;
    for (int i=G.size() - 1; i >= 0; i--) {
        printf("%d", G[i]);
        if(i)printf(" ");
    }
    printf("\n");
    printf("%lld\n", cnt);
    for (int i=0; i<n; i++) {
        printf("%d\n", A[i]);
    }
    
    return 0;
    
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int n, k;
int v[60];

int main(){
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    long long sum = 0;
    long long ans = 0;
    for (int left = 0; left <= k; left++)
    {   
        for (int right = 0; right <=k; right++)
        {
            sum = 0;
            if (left + right > k || left + right > n)
                continue;
            vector<int> a;
            for (int i = 0; i <= left; i++)
            {   if(i==0)
                    continue;
                a.push_back(v[i - 1]);
            }
                for (int j = 0; j <= right; j++)
                {
                    if(j==0)
                        continue;
                    a.push_back(v[n - j]);
                }
            
            //cerr << a.size() << endl;
            if(a.size()==0)
                continue;
            /*for (int i = 0; i < a.size(); i++)
            {
                cerr << a[i] << " ";
            }
            cerr << "\n";*/
            sort(a.begin(), a.end());
             for (int s = 0; s < a.size(); s++)
            {
                sum += a[s];
            }
            //cerr << sum << endl;
            if (left + right == k)
            {
                ans = max(ans, sum);
               // cerr << sum << endl;
                continue;
            }
            for (int l = 0; l < k-(right+left); l++)
            {   if(l>=a.size())
                    break;
                if (a[l] < 0)
                    sum -= a[l];
            }
            //cerr << sum << endl;
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,u,v;cin >> n >> u >> v;
	u--;v--;
	vector<vector<int>> g(n);
	rep(i,n - 1){
		int a,b;cin >> a >> b;
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	vector<int> a(n, -1);
	queue<pii> q;
	q.push(mp(u,0));
	q.push(mp(v,1));
	a.at(u) = 0;
	a.at(v) = 1;
	while(!q.empty()){
		int cur = q.front().first, k = q.front().second;q.pop();
		rep(i,g[cur].size()){
			if(a.at(g[cur][i]) == -1){
				a.at(g[cur][i]) = k;
				q.push(mp(g[cur][i], k));
			}
		}
	}
	int dist = 0;
	vector<bool> visited(n);
	q.push(mp(v,0));
	while(!q.empty()){
		int cur = q.front().first, k = q.front().second;q.pop();
		rep(i,g[cur].size()){
			int next = g[cur][i];
			if(visited.at(next)) continue;
			if(a.at(next) == 0){
				dist = max(dist,k + 1);
			}
			q.push(mp(next, k + 1));
			visited.at(next) = true;
		}
	}
	cout << dist - 1 << endl;
}


Measured memory_bytes: 6400
L = input()
p = 10 ** 9 + 7
l = len(L)
ones = 0
cnt = 1
two = [1] * l
three = [1] * l
for i in range(1, l):
  two[i] = two[i - 1] * 2 % p
  three[i] = three[i - 1] * 3 % p
for i, b in enumerate(L):
  if b == '1':
    left = two[ones]
    right = (three[l - 1 - i] + 1) % p
    cnt += left * right
    cnt %= p
    ones += 1
print(cnt)

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

int main()
{
    string cards[3];
    cin >> cards[0] >> cards[1] >> cards[2];
    
    int now = 0;
    while(cards[now] != "")
    {
        char first = cards[now].front();
        cards[now].erase(cards[now].begin());
        
        if(first == 'a')
        {
            now = 0;
        }
        else if(first == 'b')
        {
            now = 1;
        }
        else if(first == 'c')
        {
            now = 2;
        }
    }
    
    if(now == 0)
    {
        cout << "A" << endl;
    }
    else if(now == 1)
    {
        cout << "B" << endl;
    }
    else if(now == 2)
    {
        cout << "C" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N,ans=0;cin>>N;
    int a[N+1];
    for(int i=1;i<=N;i++)cin>>a[i];
    bool flag=true;
    int b=a[1],tmp;
    while(flag){
        tmp=b;
        b=a[b];
        if(tmp==-1)flag=false;
        else ans++;
        if(tmp==2)break;
        a[tmp]=-1;
    }
    cout<<(flag?ans:-1)<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++) 

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    //int ac_num[n];
    vector<int> ac_num(n, -1);
    //vector<pair<int, int> > ac_num(n);
    vector<int> ac_count(n, 0);
    vector<int> wa_count(n, 0);
    rep(i, 0, m) {
        cin >> p[i] >> s[i];
        //ac_num[i] = -1;
    }
    
    //int ac_count = 0;
    //int wa_count = 0;
    int wa_tmp = 0;

    rep(i, 0, m) {
        if(ac_num[p[i]-1] == -1) {
            if(s[i] == "AC") {
                ac_count[p[i]-1]++;
                ac_num[p[i]-1] = i;
            }
            else if(s[i] == "WA") {
                wa_count[p[i]-1]++;
            }
        }
    }

    int ans_ac = 0;
    int ans_wa = 0;
    rep(i, 0, n) {
        if(ac_count[i] != 0) {
            ans_wa += wa_count[i];
            ans_ac++;
        }
    }
    
    cout << ans_ac << " " << ans_wa << endl;

    return 0;
}

Measured memory_bytes: 7296