akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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

ll R, C, N;

ll cyc(ll x, ll y) {
	if (x == 0) { return y; }
	if (y == C) { return C + x; }
	if (x == R) { return C + R + C - y; }
	if (y == 0) { return C + R + C + R - x; }
	return -1;
}


int main() {
	cin >> R >> C >> N;

	vector<pair<ll,ll>> hashi;

	repn(i, N) {
		ll x, y, z, w;
		cin >> x >> y >> z >> w;

		if (cyc(x, y) != -1 && cyc(z, w) != -1) {
			hashi.push_back({ cyc(x, y),i });
			hashi.push_back({ cyc(z, w),i });
		}
	}

	sort(hashi.begin(), hashi.end());

	string ans = "YES";

	vector<bool> b(N + 1, 0);

	stack<ll> st;

	

	rep(i, hashi.size()) {
		//cout << hashi[i].second << hashi[i].first << endl;
		ll v = hashi[i].second;
		if (b[v] == 0) { st.push(v); b[v] = 1; }
		else {
			ll w = st.top();
			if (w != v) { ans = "NO"; break; }
			st.pop();
		}
	}

	cout << ans;

	system("PAUSE");

}





Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int main(){
int N,M;
  cin>>N>>M;
  vector<int64_t>A(N+1); A.at(0)=0;
  vector<int64_t>B(M+1);B.at(0)=0;
  for(int i=1;i<=N;i++)
    cin>>A.at(i);
  for(int i=1;i<=M;i++)
    cin>>B.at(i);
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  if(!(A.at(N)==N*M && B.at(M)==N*M))
    cout<<0<<endl;
  else{
  int64_t ans=1;
    int64_t I=N-1;
    int64_t J=M-1;
    for(int64_t k=N*M-1;1<=k;k--){
       
       if(A.at(I)<k && B.at(J)<k){
          int64_t a=(M-J)*(N-I)-(N*M-k);
         if(a<=0){ans=0; break;}else{ans=(a*ans)%mod;}
       }else if(A.at(I)==k && B.at(J)<k){
            ans=((M-J)*ans)%mod; I--;
       }else if(B.at(J)==k && A.at(I)<k){
       ans=((N-I)*ans)%mod; J--;
       }else if(A.at(I)==k && B.at(J)==k){
            I--; J--;
       }else{ans=0; break;}
    }  cout<<ans<<endl;
 
  }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int getSum(int n){
	int sum=0;
	while(n>0){
		sum+=n%10;
		n/=10;
	}
	return sum;
}

int main(){
	int N;
	cin>>N;
	
	if(N%getSum(N)==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;

  int res = a % b;
  for (int i = 0; i < b; i++)
  {
    if (res * (i + 1) % b == c)
    {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var A = cin.ReadInt;
            var B = cin.ReadInt;

            var ans = 0;
            var count = 1;
            while (count < B)
            {
                count += A - 1;
                ans++;
            }

            Console.WriteLine(ans);

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }



void func(long long N, std::vector<long long> A, std::vector<long long> B){

    lli ans = 0;
    REP(i,0,N){
        lli num = min(A[i],B[i]);
        A[i] -= num;
        B[i] -= num;
        ans += num;

        num = min(A[i+1],B[i]);
        A[i+1] -= num;
        B[i] -= num;
        ans += num;
    }

    cout<<ans<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N+1);
    for(int i = 0 ; i < N+1 ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    func(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 1792
/*
the top of the losers
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    Lcm(a,b)  ((a*b)/(__gcd(a,b)))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define    x            real()
#define    y            imag()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     point        complex<double>
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
typedef  long long     ll ;
typedef  unsigned long long     ull ;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
priority_queue<pair<long double,int> > pq;
int D[100009],a[100009];
int main(){
     GO();
     int n,m;
     cin>>n>>m;
     //cout<<powl(2,100000)<<endl;
     for(int i=0;i<n;i++){
        int no;
        cin>>no;
        a[i]=no;
        pq.push(mp(no,i));
     }
     while(m>0){
        long double cur=pq.top().first/2;
        int id=pq.top().second;
        pq.pop();
        pq.push(mp(cur,id));
        D[id]++;
        m--;
     }
     ll ans=0;
     while(sz(pq)>0){
        ans+= floor(pq.top().first);
        pq.pop();
     }
     cout<<ans<<endl;
}



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

const int maxN=1e5+5;
int N;
int A[maxN], B[maxN];

int main()
{
    cin >> N;
    for (int i=0; i<=N; i++) cin >> A[i];
    for (int i=0; i<N; i++) cin >> B[i];
    long long cnt=0;
    for (int i=0; i<N; i++) {
        int defeat = min(A[i],B[i]);
        cnt += defeat;
        A[i]-=defeat, B[i]-=defeat;
        defeat = min(A[i+1],B[i]);
        cnt += defeat;
        A[i+1]-=defeat, B[i]-=defeat;
    }
    cout << cnt;
    return 0;
}



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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.first << ", " << p.second << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    long long n, m;
    cin >> n;
    umap<string, long long> points;
    string temp;
    for (int i = 1; i <= n; i++) {
        cin >> temp;
        points[temp]++;
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        cin >> temp;
        points[temp]--;
    }
    long long best_point = 0;
    for (auto &p : points) {
        best_point = max(best_point, p.second);
    }
    cout << best_point;
}


Measured memory_bytes: 3644
import Control.Applicative
import Control.Monad
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = do
  n <- f
  unless (n == 0) $ do
    solve <$> g >>= print
    main
  where
    f = readi B.readInt <$> B.getLine
    g = readil B.readInt <$> B.getLine

solve :: [Int] -> Int
solve = minimum . (tail >>= zipWith (-)) . sort

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')



Measured memory_bytes: 4056
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;

#define mod 1000000007

int n;
vector<vector<int> > graph(100001);
vector<int> node(100001, -1);
vector<int> parent(100001, -1);
vector<pair<int, int> > range(100001);

bool cansolve(int x)
{
    int l = -1000000, r = 2000000;
    for(int i = 0; i < graph[x].size(); i++){
        int nextnode = graph[x][i];
        if(parent[nextnode] != -1) continue;
        parent[nextnode] = x;
        bool tmp = cansolve(nextnode);
        if(!tmp) return false;
        if(range[nextnode].first == -1000000 && range[nextnode].second == 2000000) continue;
        if(!(l == -1000000 && r == 2000000) && (l - range[nextnode].first + 1) % 2 != (r - range[nextnode].second - 1) % 2) return false;
        l = max(l, range[nextnode].first - 1);
        r = min(r, range[nextnode].second + 1);
        if((r - l) % 2 == 1) return false;
    }
    if(node[x] != -1){
        l = max(l, node[x]);
        r = min(r, node[x]);
    }
    if(r - l < 0 || (r - l) % 2 == 1) return false;
    // cout << x << " " << l << " " << r << endl;
    range[x] = make_pair(l, r);
    return true;
}

bool definenode(int x)
{
    // cout << x << endl;
    int tmp = node[x];
    for(int i = 0; i < graph[x].size(); i++){
        int nextnode = graph[x][i];
        // cout << nextnode << " " << parent[nextnode] << endl;
        int l = range[nextnode].first, r = range[nextnode].second;
        if(parent[nextnode] != x) continue;
        if(l <= tmp - 1 && tmp - 1 <= r){
            node[nextnode] = tmp - 1;
            if(definenode(nextnode)) continue;
        }
        if(l <= tmp + 1 && tmp + 1 <= r){
            node[nextnode] = tmp + 1;
            if(definenode(nextnode)) continue;
        }
        return false;
    }
    return true;
}

int main()
{   
    cin >> n;    
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    int k;
    cin >> k;
    int v, p;
    for(int i = 0; i < k; i++){
        cin >> v >> p;
        node[v] = p;
    }
    parent[v] = 0;
    bool result = cansolve(v), ans = false;
    if(result) ans = definenode(v);
    if(result && ans){
        cout << "Yes" << endl;
        for(int i = 1; i <= n; i++){
            cout << node[i] << endl;
        }
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
  int h,w,k;
  cin>>h>>w>>k;
  int ans=0;
  char table[h][w];
  for (int i=0;i<h;i++){
    for (int j=0;j<w;j++){
      cin>>table[i][j];
    }
  }
  for (int row=0;row<(1<<h);row++){
    for (int col=0;col<(1<<w);col++){
      int cnt=0;
      for (int i=0;i<h;i++){
        for (int j=0;j<w;j++){
          if(((row >> i) & 1) == 1 || ((col >> j) & 1) == 1) continue;
          if (table[i][j]=='#') cnt++;
        }
      }
      if (cnt==k) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3600
from itertools import groupby
n = int(input())
list_S = input()
list_E = input()
list_MAP = []
list_C = groupby(list_S)
for num, gr in list_C:
    list_MAP.append(len(list(gr)))
ans = 1
if list_MAP[0] == 2:
    ans *= 6
else:
    ans *= 3

for i in range(1, len(list_MAP)):
    if list_MAP[i-1] == 1 and list_MAP[i] == 1:
        ans *= 2


    if list_MAP[i-1] == 1 and list_MAP[i] == 2:
        ans *= 2


    if list_MAP[i-1] == 2 and list_MAP[i] == 1:
        ans *= 1


    if list_MAP[i-1] == 2 and list_MAP[i] == 2:
        ans *=3



ans = ans % 1000000007
print(ans)

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

int main() {
	int a[2], b[2];
	for (int i = 0; i < 3; i++) {
		cin >> a[i] >> b[i];
	}
	
	string s = "YES";
	if (a[0] == a[1] || a[0] == b[1]) {
		if (a[0] == a[2] || a[0] == b[2]) {
			s = "NO";
		}
	}
	if (b[0] == a[1] || b[0] == b[1]) {
		if (b[0] == a[2] || b[0] == b[2]) {
			s = "NO";
		}
	}

	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//解説参考.
int main(){
	string s;
	cin>>s;
	
	vi cnt(2019,0);
	cnt[0]=1;
	int tmp=0;
	int weight=1;
	llong ans=0;
	REP(i,s.size()){
		tmp=(tmp+weight*(s[s.size()-1-i]-'0')%2019)%2019;
		ans+=cnt[tmp];
		cnt[tmp]++;
		weight=(10*weight)%2019;
	}
	
	cout<<ans<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};

ll n,m;
vector<P> es;
ll cnt[3];

int main(){
  cin>>n>>m;
  UnionFind uf(n);
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    es.push_back(P(a,b));
    uf.unite(a,b);
  }
  cnt[0]=1;
  cnt[1]=1;
  repl(i,2,n){
    if(uf.same(i,0))cnt[0]++;
    else if(uf.same(i,1))cnt[1]++;
    else cnt[2]++;
  }
  ll res=0;
  rep(i,cnt[2]+1){
    ll rest=cnt[2]-i;
    ll p1=cnt[0]+i,p2=cnt[1]+rest;
    maxch(res,p1*(p1-1)/2+p2*(p2-1)/2-m);
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 2804
#include <stdio.h>

int main()
{
	int m, f, r;

	while (1) {
		scanf("%d%d%d", &m, &f, &r);
		if (m + f + r == -3) break;
		else {
			if (m == -1 || f == -1)
				printf("F\n");
			else if (m + f < 30)
				printf("F\n");
			else if (m + f >= 30 && m + f < 50) {
				if (r >= 50)
				printf("C\n");
				else printf("D\n");
			}
			else if (m + f >= 30 && m + f < 50 && r >= 50)
				printf("C\n");
			else if (m + f >= 50 && m + f < 65)
				printf("C\n");
			else if (m + f >= 65 && m + f < 80)
				printf("B\n");
			else if (m + f >= 80)
				printf("A\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;
int main()
{
       long n;
       while(cin>>n)
       {
           long  long x;
           x=n*800-(n/15)*200;
           cout<<x<<"\n";

       }
    return 0;

}



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


int main() {
int N;
  cin>>N;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
int A=1;

  for(int i=0;i<N;i++){
  if(A==vec[i]){  
    A++;}
  }
  if(A-1==0){cout<<-1<<endl;}
  else{
  cout<<N-(A-1)<<endl;}
    
      

}


Measured memory_bytes: 1024
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A.sort(reverse=True)
    
    m = (N+1) // 2
    
    ans = sum(A[:m]) + sum(A[1:N-m])
    print(ans)
    return


if __name__ == '__main__':
    main()


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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 200005;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s;
	cin >> s;
	int w;
	cin >> w;
	int l = s.length();
	string ans = "";
	for ( int i= 0; i < l; i += w)
		ans += s[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

val = [0] * (N)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    val[p] += x


def dfs(n, pre):
    for nxt in G[n]:
        if nxt == pre:
            continue
        val[nxt] += val[n]
        dfs(nxt, n)


dfs(0, 0)

answer = ' '.join(map(str, val[:]))
print(answer)


Measured memory_bytes: 232184
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int tmp[10]={512,256,128,64,32,16,8,4,2,1};
  int in;
  while(cin>>in){
    vector<int>out;
    rep(i,10)if(in>=tmp[i]){in-=tmp[i];out.pb(tmp[i]);}
    sort(all(out));
    rep(i,out.size()-1)cout<<out[i]<<" ";
    cout<<out[out.size()-1]<<endl;
  }
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int no_of_people;
    string direction;
    cin >> no_of_people >> direction;

    vector <int> west_till(no_of_people, 0);
    for(int i = 1; i < no_of_people; i++)
        west_till[i] = west_till[i - 1] + (direction[i - 1] == 'W');

    vector <int> east_from(no_of_people, 0);
    for(int i = no_of_people - 2; i >= 0; i--)
        east_from[i] = east_from[i + 1] + (direction[i + 1] == 'E');

    int minimum_turns = no_of_people + 1;
    for(int i = 0; i < no_of_people; i++)
        minimum_turns = min(minimum_turns, west_till[i] + east_from[i]);

    cout << minimum_turns;
    return 0;
}


Measured memory_bytes: 2948
import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args)throws IOException{
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		if (n > k){
			int a = (n - k)*y;
			int b = k * x;
			System.out.println(a + b);
		}

		if (n <= k){
			System.out.println(n * x);
		}
		
		sc.close();
	}
}


Measured memory_bytes: 9940
#include <bits/stdc++.h>
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define wh(t) while(t--)
#define fi(n) for(long long i = 0; i < n; i++)
#define fj(n) for(long long j = 0; j < n; j++)
#define fu(i,s,e) for(ll i = s; i <=e; i++)
#define fd(i,s,e) for(ll i = s; i >=e; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define sll stack<ll>
#define qll queue<ll>
using namespace std;
const ll M = 1e9+7;
//const ll M = 998244353;

ll pmp(ll x,ll n){
	ll a = 1;
	while(n > 0){
		if(n & 1) a = (a * x)%M;
		x = (x * x) % M;
		n = n>>1;
	}
	return a;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t = 1;
	// cin >> t;
	wh(t){
		string s;
		cin >> s;
		if(s == "ABC")
			cout << "ARC";
		else
			cout << "ABC";
	}
	return 0;
}

Measured memory_bytes: 3612
from itertools import combinations
n = int(input())
dic = {"M":0, "A":0, "R":0, "C":0, "H":0}
march = ["M", "A", "R", "C", "H"]
for i in range(n):
  kashira = input()[0]
  if kashira in march:
    dic[kashira] += 1

ans = 0
for items in combinations(march, 3):
  ans += dic[items[0]] * dic[items[1]] * dic[items[2]]
print(ans)

Measured memory_bytes: 43496
def f(x):
    if x % 2 == 0:
        x /= 2
    else:
        x = 3 * x + 1
    return x

s = int(input())

tplist = [s]
x = 1
while True:
    temp = f(tplist[-1])
    x += 1
    if temp in tplist:
        break
    tplist.append(temp)


print(x)

Measured memory_bytes: 2940
# include "cstdio"
# define max(a,b) ((a)>(b)?(a):(b)) 

int main(){
	int a,b,ans;
	scanf("%d%d",&a,&b);
	ans=max(a+b,max(a-b,a*b)); 
	printf("%d",ans); 
	return 0; 
} 

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	double pi = 3.1415926535897932384626433832795028841971;
	double a;
	cin >> a;
	double s = a*a*pi;
	double s2 = a*2*pi;
	printf("%7lf %7lf\n",s, s2);

	return 0;
}

Measured memory_bytes: 1240
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
int G[701][701]={}, n;
bitset<351> b;
inline void operator+=(pii& p, pii p2){
    p.ff+=p2.ss, p.ss+=p2.ff;
}
pii dfs(int i, int p = 1){
    pii ans = {1, 0};
    G[i][i] = p;
    for(int j = 1; j <= n; j++)
        if(!G[i][j] && i != j)
            if(!G[j][j])
                ans += dfs(j, -p);
            else if(G[j][j] != -p)
                throw -1;
    return ans;
}
signed main(){
    int m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        G[a][b] = G[b][a] = 1;
    }
    int targ = n/2;
    try{
        b[0] = 1;
        for(int i = 1; i <= n; i++){
            if(G[i][i])continue;
            pii p = dfs(i);
            b = (b << p.ff) | (b << p.ss);
        }
        for(int i = targ; i >= 0; i--){
            if(b[i])return cout << i*(i-1)/2 + (n-i)*(n-i-1)/2 << endl, 0;
        }
    }catch(int e){
        cout << "-1" << endl;
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N=200005;

ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }

bool ch(int num, set <int> st) {
    while(num>0) {
        int dig=num%10;
        if(st.find(dig)!=st.end()) return 0;
        num/=10;
    }
    return 1;
}



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   
    cout<<fixed<<setprecision(15);
    
    int n,k;
    cin>>n>>k;
    set <int> st;

    for(int i=0;i<k;i++) {
        int x;
        cin>>x;
        st.insert(x);
    }

    for(int i=n;i<1000000;i++) {
        if(ch(i, st)) {
            cout<<i;
            return 0;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100005
#define INF 1000000005
#define INFLL 4000000000000000003
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
vector<int>Lang[N];
vector<int>Peop[N];
bool color[N][2];
map<int,int>mp;
void dfs(int no,int p,int w){
    if(w==0){
        for(auto s:Lang[no]){
        if(s==p||color[s][1])continue;
            color[s][1]=true;
        dfs(s,no,1);
        }
    }else{
        for(auto s:Peop[no]){
        if(s==p||color[s][0])continue;
            color[s][0]=true;
            mp[s]++;
        dfs(s,no,0);
        }
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    
    REP(i,n){
        int k;
        cin>>k;
        REP(j,k){
            int p;
            cin>>p;
            p--;
            Lang[i].push_back(p);
            Peop[p].push_back(i);
        }
    }
    mp[0]++;
    dfs(0,-1,0);
    if(SZ(mp)==n)OUT("YES");
    else OUT("NO");
    return 0;
}


Measured memory_bytes: 13312
import sys

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  
  ans = 1
  for i in range(min(K, len(S))):
    c = int(S[i])
    if c != 1:
      ans = c
      break
  print(ans)


if __name__ == '__main__':
  main()

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int l, r, d;
    cin >> l >> r >> d;

    int ld, rd;
    ld = ( l - 1 ) / d;
    rd = r / d;
    cout << rd - ld << endl; 
    return 0;
}


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

#define pb push_back
#define ppp pop_back
#define fi first
#define se second
#define pii pair<int,int>

const ll p = 1e9 + 7;

struct matrix {
	int size;
	vector<vector<ll>> A;
	matrix(int size_, bool identity = 0) {
		size = size_;
		A = vector<vector<ll>> (size, vector<ll>(size));
		if (identity) {
			for (int i=0; i<size; i++) {
				for (int j=0; j<size; j++) {
					if (i == j) A[i][j] = 1;
					else A[i][j] = 0;
				}
			}
		}
	}
};

void add(ll &a, ll b) {
	a += b;
	if (a >= p) a -= p;
}

matrix mult(matrix &a, matrix &b) {
	int n = a.size;
	matrix res = matrix(n);
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			res.A[i][j] = 0;
			for (int k=0; k<n; k++) {
				add(res.A[i][j], (a.A[i][k] * b.A[k][j]) % p);
			}
		}
	}
	return res;
}

void print(matrix a) {
    int n = a.size;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cout << a.A[i][j] << " ";
        }
        cout << endl;
    }
}

matrix binpow(matrix a, ll b) {
	matrix res = matrix(a.size, 1);
	while (b) {
		if (b & 1) res = mult(res, a);
		b >>= 1;
		a = mult(a, a);
	}
	return res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n;
	ll k;
	cin >> n >> k;
	matrix a = matrix(n);
	for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cin >> a.A[i][j];
        }
	}
	matrix b = binpow(a, k);
	ll sum = 0;
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			add(sum, b.A[i][j]);
		}
	}
	cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


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

	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i*j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
S = input()
A, B, C = 0, 0, 0
q = 0

for i, s in enumerate(S, start=1):
    if s == "A":
        A = (A + pow(3, q, MOD))%MOD
    elif s == "B":
        B = (B + A)%MOD
    elif s == "C":
        C = (C + B)%MOD
    elif s == "?":
        A, B, C = (3*A + pow(3, q, MOD))%MOD, (3*B + A)%MOD, (3*C + B)%MOD
        q += 1

print(C)

Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>

std::vector<std::vector<int>> ki;
std::vector<int> count;

//深さ優先探索：O(ノード数)で木に纏わる処理をできる
void dfs(int now, int par) {// }, std::vector<std::vector<int>>& ki, std::vector<int>& count) {
    for (auto chi : ki[now]) if (chi != par) {
        //繋がったノードを取り出す
        //繋がったノードが親なら無視
        //子なら値を分配
        count[chi] += count[now];
        dfs(chi, now);//, ki, count);
    }
}

int main() {
    //std::ifstream in("in01.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int n, q;
    std::cin >> n >> q;
    
    //つながりのあるノードを保存する
    //0が存在しているので、無を指定するには-1などにする
    //std::vector<std::vector<int>> ki;
    //std::vector<int> count;
    ki.resize(n+1);
    count.resize(n+1);
    
    for (int i = 1; i < n; i++) {
        int a, b;
        std::cin >> a >> b;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    
    for (int i = 0; i < q; i++) {
        int p, x;
        std::cin >> p >> x;
        count[p] += x;
    }
    
    dfs(1, -1);//, ki, count);
    
    for (int i = 1; i <= n; i++) {
        std::cout << count[i] << " ";
    }
    std::cout << std::endl;
    
    return 0;
}


Measured memory_bytes: 23424
N = int(input())
h = [list(map(int, input().split())) for _ in range(N)]

x = [(val[0],i) for i,val in enumerate(h)]
y = [(val[1],i) for i,val in enumerate(h)]

x.sort()
y.sort()
edge = []
for i in range(1,N):
    # (cost, start, end)
    edge.append((x[i][0]-x[i-1][0], x[i-1][1], x[i][1]))
    edge.append((y[i][0]-y[i-1][0], y[i-1][1], y[i][1]))
edge.sort()
par = list(range(N))
rank = [0]*N

def find(val):
    if par[val]==val:
        return val
    else:
        par[val] = find(par[val])
        return par[val]

def unite(val1, val2):
    val1 = find(val1)
    val2 = find(val2)
    if val1==val2:
        return
    if rank[val1] < rank[val2]:
        par[val1] = val2
    else:
        par[val2] = val1
        if rank[val1] == rank[val2]:
            rank[val1] += 1
def same(val1, val2):
    return find(val1)==find(val2)

res = 0
for e in edge:
    start = e[1]
    end = e[2]
    if same(start, end):
        continue
    res += e[0]
    unite(start, end)
print(res)






Measured memory_bytes: 75544
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
char s[N][5];
string ans="";
int main(){
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1); 
	for(int i=1;i<=n;i++){
		if(s[i][1]=='A'&&s[i][2]=='B'){
			if(a>b){
				a--;b++;
				ans+='B';
			}else if(a<b){
				a++;b--;
				ans+='A'; 
			}else{
				if(s[i+1][1]=='A'){
					a++;b--;
					ans+='A';
				}
				else{
					a--;b++;
					ans+='B';
				}
			}
		}else if(s[i][1]=='A'&&s[i][2]=='C'){
			if(a>c){
				a--;c++;
				ans+='C';
			}
			else if(a<c){
				a++;c--;
				ans+='A'; 
			}
			else{
				if(s[i+1][1]=='A'){
					a++;c--;
					ans+='A';
				}
				else{
					a--;c++;
					ans+='C';
				}
			}
		}
		else{
			if(b>c){
				b--;c++;
				ans+='C';
			}
			else if(b<c){
				b++;c--;
				ans+='B'; 
			}else{
				if(s[i+1][2]=='C'){
					b--;c++;
					ans+='C';
				}
				else{
					b++;c--;
					ans+='B';
				}
			}
		} 
		if(a<0||b<0||c<0) return cout<<"No"<<endl,0;
	}
	puts("Yes");
	int t=ans.size();
	for(int i=0;i<t;i++)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 4388
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
#define MAX_N 100000
int a[MAX_N];
int main(){
    int N,x;
    ll ans;
    cin >> N >> x;
    REP(i,N) cin >> a[i];
    ans = max(0,a[0]-x);
    a[0] -= ans;
    REP(i,N-1){
        if(a[i] + a[i+1] <= x) continue;
        ans += a[i+1]-(x-a[i]);
        a[i+1] = x-a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exist(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;

using ftype = double;
const ftype PI = 3.1415926535897932;

void FFT(vector<complex<ftype> > &a) {
    int n = a.size();
    if(n == 1) return;
    vector<complex<ftype> > b(n/2), c(n/2);
    for(int i=0; i<n; ++i) {
        if(i%2 == 0) b[i/2] = a[i];
        if(i%2 == 1) c[i/2] = a[i];
    } 
    FFT(b);
    FFT(c);
    complex<ftype> theta(0.0,2*PI/n);
    for(int i=0; i<n; ++i) {
        a[i] = b[i%(n/2)] + c[i%(n/2)] * exp(complex<ftype>(i,0)*theta);
    }
    return; 
}

void IFFT(vector<complex<ftype> > &a) {
    int n = a.size();
    vector<complex<ftype>> b(n);
    for(int i=0; i<n; ++i) b[i] = a[(n-i)%n];
    FFT(b);
    for(int i=0; i<n; ++i) a[i] = b[i]/complex<ftype>(n,0);
    return;
}

template<typename T, typename U>
T round(U x) {
    if(x<0) return x-0.5;
    else return x+0.5; 
}

int main(){
    int N; ll M; cin >> N >> M;
    int L = 1<<18;
    vector<complex<ftype>> a(L), c(L);
    vector<ll> d(L);
    int x0;
    REP(i,N) {
        scanf("%d",&x0);
        a[x0] += complex<ftype>(1.0,0.0);
    }
    FFT(a);
    REP(i,L) c[i] = a[i]*a[i];
    IFFT(c);
    REP(i,L) d[i] = round(c[i].real());
    ll ans = 0;
    for(ll i=L-1; i>=0; --i) {
        ans += i * min(M,d[i]);
        M -= min(M,d[i]);
    }
    // REP(i,L) cout << d[i] << ' '; cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 24860
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            Point[] red = new Point[n];
            Point[] blue = new Point[n];
            for (int i = 0; i < n; i++) {
                red[i] = new Point(in.nextInt(), in.nextInt());
            }

            for (int i = 0; i < n; i++) {
                blue[i] = new Point(in.nextInt(), in.nextInt());
            }

            Arrays.sort(red, new Comparator<Point>() {

                public int compare(Point o1, Point o2) {
                    return o2.y - o1.y;
                }
            });


            Arrays.sort(blue, new Comparator<Point>() {

                public int compare(Point o1, Point o2) {
                    return o1.x - o2.x;
                }
            });

            int cnt = 0;
            for (Point redPoint : red) {
                for (Point bluePoint : blue) {
                    if (bluePoint.x > redPoint.x &&
                            bluePoint.y > redPoint.y) {
                        if (!bluePoint.isPair && !redPoint.isPair) {
                            cnt++;
                            bluePoint.isPair = true;
                            redPoint.isPair = true;
                            break;
                        }
                    }
                }
            }

            out.print(cnt);
        }

    }

    static class Point {
        int x;
        int y;
        boolean isPair;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
            this.isPair = false;
        }

    }
}



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

int gcd(int x , int y){
  int z=x%y;
  if(z != 0){
    return(gcd(y,z));
  } else {
    return(y);
  }
}

signed main(){
  int n , a[100005];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i>0){
      a[i]=gcd(a[i],a[i-1]);
    }
  }
  
  cout<<a[n-1]<<endl;
  return(0);
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

int a[maxn] ;
int x[3] ;

int main()
{
    int n ;
    scanf("%d",&n) ;

    for(int i=1 ; i<=n ; i++) scanf("%d",&a[i]) ;

    int ans = 1 ;

    for(int i=1 ; i<=n ; i++)
    {
        int c = 0 ;
        for(int j=0 ; j<3 ; j++)
        {
            if( x[j]==a[i] ) c++ ;
        }
        ans = (1LL*ans*c)%mod ;
        for(int j=0 ; j<3 ; j++)
        {
            if( x[j]==a[i] )
            {
                x[j]++ ;
                break ;
            }
        }
    }

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

    return 0 ;
}


Measured memory_bytes: 640
def Draw(pattern, rowRange, colRange):
    s = ""

    for row in rowRange:
        for col in colRange:
            s += pattern[row][col]
        s += "\n"

    print(s, end="")


def Draw2(pattern, colRange, rowRange):
    s = ""

    for col in colRange:
        for row in rowRange:
            s += pattern[row][col]
        s += "\n"

    print(s, end="")


pattern = [input() for lp in range(8)]

print("90")
Draw2(pattern, range(0, 8), range(7, -1, -1))

print("180")
Draw(pattern, range(7, -1, -1), range(7, -1, -1))

print("270")
Draw2(pattern, range(7, -1, -1), range(0, 8))



Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> masu(H, vector<char>(W));
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> masu.at(i).at(j);
        }
    }
    
    vector<vector<int>> R(H, vector<int>(W));
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(masu.at(i).at(j)=='#') R.at(i).at(j) = 0;
            else {
                if(j==0) R.at(i).at(j) = 1;
                else R.at(i).at(j) = R.at(i).at(j-1) + 1;
            }
        }
    }
    
    vector<vector<int>> L(H, vector<int>(W));
    for(int i = 0; i < H; i++) {
        for(int j = W-1; j >= 0; j--) {
            if(masu.at(i).at(j)=='#') L.at(i).at(j) = 0;
            else {
                if(j==W-1) L.at(i).at(j) = 1;
                else L.at(i).at(j) = L.at(i).at(j+1) + 1;
            }
        }
    }
    
    vector<vector<int>> D(H, vector<int>(W));
    for(int j = 0; j < W; j++) {
        for(int i = 0; i < H; i++) {
            if(masu.at(i).at(j)=='#') D.at(i).at(j) = 0;
            else {
                if(i==0) D.at(i).at(j) = 1;
                else D.at(i).at(j) = D.at(i-1).at(j) + 1;
            }
        }
    }
    
    vector<vector<int>> U(H, vector<int>(W));
    for(int j = 0; j < W; j++) {
        for(int i = H-1; i >= 0; i--) {
            if(masu.at(i).at(j)=='#') U.at(i).at(j) = 0;
            else {
                if(i==H-1) U.at(i).at(j) = 1;
                else U.at(i).at(j) = U.at(i+1).at(j) + 1;
            }
        }
    }
    
    int ans = -1;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            ans = max(ans, R.at(i).at(j) + L.at(i).at(j) + D.at(i).at(j) + U.at(i).at(j) - 3);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 67072
#include<stdio.h>
#include<string.h>

int main()
{
    int i;
    char s[3][8]={"Sunny","Cloudy","Rainy"};
    char ss[8];
    scanf("%s",ss);
    if(strcmp(ss,s[0])==0)
        printf("%s\n",s[1]);
    else if(strcmp(ss,s[1])==0)
        printf("%s\n",s[2]);
    else
        printf("%s\n",s[0]);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
    ll n,k;cin >> n >>k;
    string s;cin >> s;
    rev(all(s));
    rep(i,k)s+='1';
    ll i=0;
    vl ans;
    while(i<n){
        bool check=true;
        per(j,k){
            ll d=j+1;
            if(s[d+i]=='0'){
                check=false;
                ans.pb(d);
                i+=d;
                break;
            }
        }
        if(check){
            cout << -1 <<endl;
            return 0;
        }
    }
    rev(all(ans));
    rep(i,ans.size()){
        cout << ans[i] <<" ";
    }
    cout <<endl;
}

Measured memory_bytes: 1528