akhauriyash/Code-Regression huggingface dataset:
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,c,k,t[100005]={},j=0,time,ans=0,pple=0;
  cin >> n >> c >> k;
  for(int i=0; i<n; i++) {
    cin >> t[i];
  }
  sort(t,t+n);
  while(j<n) {
    time=t[j]+k;
    j++;
    pple=1;
    while(t[j]<=time&&pple<c) {
      j++,pple++;
      if(pple==c) {
        break;
      }
    }
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
def insertion_sort(a, n, g):
    cnt = 0
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j -= g
            cnt += 1
        a[j+g] = v

    return cnt


def shell_sort(a, n):
    cnt = 0
    g = []
    h = 1
    while h <= n:
        g.append(h)
        h = 3 * h + 1
    g = g[::-1]

    for gi in g:
        cnt += insertion_sort(a, n, gi)

    return cnt, g


n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

cnt, g = shell_sort(a, n)

print(len(g))
print(' '.join([str(i) for i in g]))
print(cnt)
for i in a:
    print(i)


Measured memory_bytes: 45516
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr, n);
  console.log(arr.reduce((s, e) => s += ` ${e}`, ''));
})();

function buildMaxHeap(arr, n = arr.length) {
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(n / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140172
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    int N;
    cin >> N;

    int ans = 0;
    while (N > 0) {
        if (N % 10 == 2) ans++;
        N /= 10;
    }

    cout << ans <<endl;

}



























Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
def soinsu(n):
    dic = defaultdict(int)
    i = 2
    while i*i <= n:
        if n%i == 0:
            dic[i] += 1
            n //= i
        else:
            i += 1
    if n!= 1:
        dic[n] += 1
    return dic
n = I()
dic = soinsu(n)
#print(dic)
cnt = 0
for k,v in dic.items():
    num = 1
    while v - num >= 0:
        cnt += 1
        v -= num
        num += 1
print(cnt)


Measured memory_bytes: 9464
L, R = gets.split(' ').map{|n| n.to_i}
if R - L >= 2018
  puts 0
  exit
end

min = 2019
(L..(R - 1)).each do |i|
  ((L + 1)..R).each do |j|
    if i != j
      n = i * j % 2019
      min = n if n < min
      if n == 0
        puts 0
        exit
      end
    end
  end
end
puts min

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
/*** Template Begins ***/
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

/*** Template Ends ***/
vi dsu,sz;
void init(int n){
    dsu.resize(n,0);
    sz.resize(n,1);
    rep(i,0,n)dsu[i]=i;
}
int root(int i){
    if(dsu[i]==i)return i;
    return dsu[i]=root(dsu[i]);
}
void merge(int i, int j){
    i=root(i);
    j=root(j);
    if(i==j)return;
    if(sz[i]<sz[j])swap(i,j);
    sz[i]+=sz[j];
    dsu[j]=i;
}
void solve(){
    int n,m;
    cin>>n>>m;
    init(n);
    rep(i,0,m){
        int a,b;cin>>a>>b;
        merge(a-1,b-1);
    }
    int ans=0;
    rep(i,0,n)ans=max(ans,sz[i]);
    cout<<ans<<endl;
}
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4696
#include <stdio.h>

int main(void)
{
    long long int H,N,A[100001],sum=0;
    int i;

    scanf("%lld %lld",&H,&N);

    for(i=0; i<N; i++){
        scanf("%lld",&A[i]);
    }

    for(i=0; i<N; i++){
        sum+=A[i];
        if(sum >= H){
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>

using namespace std;

struct cmpare {
    bool operator()(const pair<int, int>& value,
                                const int& key)
    {
        return (value.first < key);
    }
    bool operator()(const int& key,
                    const pair<int, int>& value)
    {
        return (key < value.first);
    }
};

int main()
{
    int a[200000];
    pair<int,int> plu[200000];
    int n;
    int inx,iny;
    long cnt=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        plu[i].first=i+a[i];
        plu[i].second=i;
    }
    sort(plu,plu+n);
    for(int i=0;i<n;i++)
    {
        if(i-a[i]>0)
        {
           if(binary_search(plu,plu+n,i-a[i],cmpare()))
           {
               inx=lower_bound(plu,plu+n,make_pair(i-a[i],i))-plu;
               iny=lower_bound(plu,plu+n,make_pair(i-a[i],-1))-plu;
               cnt+=(long)inx-iny;
           }
        }
    }
    printf("%ld\n",cnt);
    return 0;
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && a != c) cout << "Yes" << endl;
  else if(a == c && a != b) cout << "Yes" << endl;
  else if(b == c && b != a) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int c[n-1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n-1; i++) {
    cin >> c[i];
  }
  
  int ans = b[a[0]-1];
  for (int i = 1; i < n; i++) {
    ans += b[a[i]-1];
    if (a[i]-1 == a[i-1]) {
      ans += c[a[i-1]-1];
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

from random import randint
import time

def score(t):
    last = [-1]*26
    sm = 0
    for i in range(d):
        tt = t[i]
        sm += s[i][tt]
        for j in range(26):
            sm -= c[j]*(i-last[j])
    return sm

t1 = time.time()
d = inn()
c = inl()
s = []
for i in range(d):
    s.append(inl())
t = []
for i in range(d):
    t.append(randint(0,25))
last = [[-1]*26 for i in range(d)]
for i in range(d):
    td = t[i]
    for j in range(i,d):
        last[j][td] = j-i

cnt = 0
mx = -BIG
mxt = []
while True:
    cnt += 1
    if cnt==100:
        t2 = time.time()
        if t2>t1+1.8:
            break
        cnt = 0
    v = score(t)
    if v>mx:
        mx = v
        mxt = t
    dd = randint(0,d-1)
    LAS = 4
    SD = 4
    typ = randint(0,LAS+SD)
    if typ==0:
        while True:
            qq = randint(0,25)
            if qq!=t[dd]:
                break
    elif typ<=LAS:
        mn = BIG
        td = t[dd]
        last = [-1]*26
        for k in range(dd,-1,-1):
            if last[t[k]]<0:
                last[t[k]] = k
        for j in range(26):
            if last[j]<mn and j!=td:
                mn = last[j]
                qq = j
    else:
        mx = -1
        td = t[dd]
        for j in range(26):
            if s[dd][j]>mx and j!=td:
                mx = s[dd][j]
                qq = j
    t[dd] = qq
    #ddprint(f"{i=} {v=} {len(mxt)}")

for i in range(d):
    print(mxt[i]+1)


Measured memory_bytes: 87676
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        FastReader sc = new FastReader();
        String ans = "No";
        int x = sc.nextInt();
        int y = sc.nextInt();
        int cranes, turtles;
        for (int i = 0; i < x+1; i++){
            cranes = x - i;
            turtles = i;
            if (y == ((cranes*2) + (turtles*4))) ans = "Yes";
        }
        System.out.println(ans);
    }
}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}


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

int main(){
string s;
  getline(cin,s);
  int a = s.size();
  int q=0;
  for(int i=0; i<a/2; i++){
    if(s[i] != s[a-i-1]){
      q++;
    }
    
  }
  cout << q << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
int n,m,q,A[11];
int a[51],b[51],c[51],d[51];
ll ans=0;
void f(int p,int last) {
	if(p==n+1) {
		ll sum=0;
		for(int i=1;i<=q;i++) {
			if(A[b[i]]-A[a[i]]==c[i])sum+=d[i];
		}
		ans=max(ans,sum);
		return;
	}
	for(int i=last;i<=m;i++) {
		A[p]=i;
		f(p+1,i);
	}
}
void MAIN() {
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++) {
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	f(1,1);
	cout<<ans;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3640
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        boolean ans = true;
        for(int i =0;i<n;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        int tmp = h[0];
        for(int i =1;i<n;i++){
            if(tmp<=h[i]-1){
                tmp = h[i]-1;
            } else if(tmp<=h[i]){
                tmp = h[i];
            } else {
                ans = false;
                break;
            }
        }
        System.out.println(ans?"Yes":"No");
    }
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll 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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
};

int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  int ans = INF;
  for(int bit = 1; bit < 1<<n; ++bit) {
    vector<int> r(m, 0);
    int money = 0;
    rep(i, n) if(bit & 1<<i) {
      money += c[i];
      rep(j, m) r[j] += a[i][j];
    }
    bool ok = true;
    rep(j, m) if(r[j] < x) ok = false;
    if(ok) chmin(ans, money);
  }
  if(ans != INF) cout << ans << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	int reads(){
		char ch=getchar();
		while(!isdigit(ch)&&ch!='-')
			ch=getchar();
		int sign=1;
		if(ch=='-'){
			sign=-1;
			ch=getchar();
		}
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value*sign;
	}
	void writeull(long long n){
		if(n<10)
			putchar(n+'0');
		else{
			writeull(n/10);
			putchar(n%10+'0');
		}
	}
	void run(){
		long long result=0;
		for(bool first_l: {false, true}){
			fseek(stdin, 0, SEEK_SET);
			int n=readu();
			vector<pair<int, int> > v;
			vector<bool> erased(n);
			multimap<int, int, greater<int> > by_l;
			multimap<int, int> by_r;
			for(int i=0; i<n; ++i){
				int l=reads();
				int r=reads();
				v.push_back({l, r});
				erased.push_back(false);
				by_l.insert({l, i});
				by_r.insert({r, i});
			}
			int cur=0;
			auto move=[&cur, &v](int index){
				if(cur<v.at(index).first)
					return v.at(index).first;
				else if(cur>v.at(index).second)
					return v.at(index).second;
				else
					return cur;
			};
			long long dis=0;
			bool first=true;
			while(true){
				while(!by_l.empty()){
					if(erased.at(by_l.begin()->second))
						by_l.erase(by_l.begin());
					else
						break;
				}
				while(!by_r.empty()){
					if(erased.at(by_r.begin()->second))
						by_r.erase(by_r.begin());
					else
						break;
				}
				assert(by_l.empty()==by_r.empty());
				if(by_l.empty())
					break;
				bool choose_l;
				if(first)
					choose_l=first_l;
				else
					choose_l=(abs(move(by_l.begin()->second)-cur)>abs(move(by_r.begin()->second)-cur));
				if(choose_l){
					dis+=abs(move(by_l.begin()->second)-cur);
					cur=move(by_l.begin()->second);
					erased.at(by_l.begin()->second)=true;
				}
				else{
					dis+=abs(move(by_r.begin()->second)-cur);
					cur=move(by_r.begin()->second);
					erased.at(by_r.begin()->second)=true;
				}
				first=false;
			}
			dis+=abs(cur);
			result=max(result, dis);
		}
		writeull(result);
		putchar('\n');
	}
}
int main(){
	whatever::run();
}


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

bool has3(int x){
    while(x){
        if (x % 10 == 3) return true;
        x /= 10;
    }
    return false;
}

void call(int n){
    for (int x = 1; x <= n; x++){
        if ( x % 3 == 0 || has3(x) ){
            cout << " " << x;
        }
    }
    cout << endl;
}


int main(){
    int n;
    cin >> n;
    call(n);
    
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=500005;
char str[MAX_N];
int dp[MAX_N],L[MAX_N];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",str+1); 
    for(int i=1;i<=n;i++)
    {
        if(str[i]=='1')L[i]=L[i-1];
        else L[i]=i;
    }
    for(int i=1;i<=n;i++)
    {
        dp[i]=dp[i-1];
        if(str[i]=='1')
        {
            if(str[i-1]=='0' && str[i-2]=='1')
            {
                dp[i]=max(dp[i],dp[L[i-2]]+(i-2)-L[i-2]);
                dp[i]=max(dp[i],dp[L[i-2]+1]+(i-2)-L[i-2]-1);
            }
            else if(L[i]>1 && str[L[i]-1]=='1')
            {
                dp[i]=max(dp[i],dp[L[i]-2]+i-L[i]);
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

const int N = (int)1e5 + 5;
const int M = (int)1e9 + 7;

ll n, a[N];

void init() {
  cin >> n;
  for(int i = 1 ; i <= n ; ++i) cin >> a[i];
}
void solve() {
  int cc[3] = {0};
  ll ans = 1;
  for(int i = 1 ; i <= n ; ++i) {
    int ccc = 0, k = 0;
    for(int j = 2 ; j >= 0 ; --j) if(cc[j] == a[i]) {
      ccc++;
      k = j;
    }
    cc[k]++;
    ans = ans * ccc % M;
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  init();
  solve();
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	str := []string{
		"z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y",
	}

	ans := ""
	var hoge []string
	for n != 0 {
		b := n % 26
		hoge = append(hoge, str[b])
		if b == 0 {
			n = n/26 - 1
			continue
		}
		n /= 26
	}
	for i := len(hoge) - 1; i >= 0; i-- {
		ans = fmt.Sprintf("%s%s", ans, hoge[i])
	}
	fmt.Println(ans)
}

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

int main() {
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;

  t[0] = 0;
  x[0] = 0;
  y[0] = 0;

  for (int i = 0; i < N; ++i){
    cin >> t[i+1] >> x[i+1] >> y[i+1];
  }

  bool can = true;
  for (int i = 0; i < N; ++i) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);

    if (dist > dt) can = false;
    if (dist % 2 != dt % 2) can = false;

  }

  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define N 300010
#define ll long long
int n,m,p[N],fa[N],deep[N],degree[N],q[N],t,root;
bool flag[N];
struct data{int to,nxt;
}edge[N];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
void topsort()
{
	int head=0,tail=0;
	for (int i=1;i<=n;i++) if (!degree[i]) q[++tail]=i;
	while (tail<n)
	{
		int x=q[++head];
		for (int i=p[x];i;i=edge[i].nxt)
		{
			degree[edge[i].to]--;
			if (deep[x]+1>deep[edge[i].to])
			{
				deep[edge[i].to]=deep[x]+1;
				fa[edge[i].to]=x;
			}
			if (!degree[edge[i].to]) q[++tail]=edge[i].to;
		}
	}
}
int main()
{
	n=read(),m=read();
	for (int i=1;i<n+m;i++)
	{
		int x=read(),y=read();
		addedge(x,y);degree[y]++;
	}
	topsort();
	for (int i=1;i<=n;i++) printf("%d\n",fa[i]);
	return 0;
}
 

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

ll hp[100005];
ll a, b;
int n;

bool check(ll t){
  ll sum = 0;
  for(int i = 0; i < n; i++){
    if(hp[i] - (b * t) <= 0) continue;
    sum += (hp[i] - (b * t)) / (a - b);
    if((hp[i] - (b * t)) % (a - b) != 0) sum++;
  }
  return sum <= t;
}

int main(){
  cin >> n >> a >> b;
  for(int i = 0; i < n; i++) cin >> hp[i];
  sort(hp, hp+n);
  ll maxhp = hp[n-1];
  ll left = 0, right = maxhp / b + 1;
  while(right - left > 1){
    ll mid = (left + right) / 2;
    if(check(mid)) right = mid;
    else left = mid;
  }
  cout << right << endl;
  return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){

    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    int cnt = 0;
    for(int i = 0; i < n-2; i++){
        bool flg = false;
        if((v[i] < v[i+1]) && (v[i+1] < v[i+2])) flg = true;
        if((v[i] > v[i+1]) && (v[i+1] > v[i+2])) flg = true;
        if(flg) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
	int n; 
	cin>>n;
	string s; cin>>s;
	int ans=0;
	for(int i=0; i<1000; i++)
	{
		int tmp[3];
		tmp[0]=i/100;
		tmp[1]=(i/10)%10;
		tmp[2]=i%10;
		int count=0;
		for (int j =0; j<s.length(); j++)
		{

			if ((s[j]-'0')==tmp[count])
			{
				
              count++;
			}
			if(count==3)
			{
				ans++;
              break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)

int main(){

  int n,k;
  cin>>n>>k;

  int r=k;
  loop(i,n-1)r*=(k-1);

  cout<<r;

  return 0;
}

Measured memory_bytes: 256
// FindingAWord.cc
// １つの単語 W と文章 T が与えられます。
// T の中にある W の数を出力するプログラムを作成して下さい。
//
// 文章 T に含まれるスペースまたは改行で区切られた文字列を単語 Ti とします。
// すべての Ti において単語 W と同じになるものを数えて下さい。
//
// なお、大文字と小文字は区別しません。
// 【制約】
// Wの文字列の長さは10を超えない
// Wに含まれる文字はすべてアルファベット小文字である
// Tの１行あたりの文字列の長さは1000を超えない
// 【入力】
// １行目に単語 W が与えられます。
// 続いて、複数の行にまたがった文章与えられます。END_OF_TEXT という文字列が文章の終わりを示します。
// 【出力】
// 単語 W の数を出力して下さい。
// 【例】
// 入力：
// computer
// Nurtures computer scientists and highly-skilled computer engineers
// who will create and exploit "knowledge" for the new era.
// Provides an outstanding computer environment.
// END_OF_TEXT
// 出力：
// 3
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

int main( void) {
  int counter = 0;
  string word, sentence;
  int word_size;

  cin >> word;
  // 大文字と小文字は区別しないので、小文字に変換する。
  for ( int i = 0; i < word.size(); i++) {
    word[i] = tolower( word[i]);
  }

  while ( true) {
    cin >> sentence;
    if ( sentence == "END_OF_TEXT") break;
    for ( int i = 0; i < sentence.size(); i++) {
      sentence[i] = tolower( sentence[i]);
    }
    if ( sentence == word) counter++;
  }

  cout << counter << endl;

  return 0;
}



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

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

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

    long long x = a[0];

    for (int i = 1; i < N; i++){
        x = x ^ a[i];
    }
      	
    if(x == 0) {
        cout<< "Yes" << endl;
    }
    else{
        cout<< "No" << endl;
    }
}

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int gcd(int a, int b){
    if(a < b) return gcd(b, a);

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

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

    int ans = 0;

    rep(i, n){
        rep(j, n){
            rep(k, n){
                ans += gcd(gcd(i + 1, j + 1), k + 1);
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
L=int(input())
A=[int(input()) for i in range(L)]
INF=10**16
DP=[[INF]*5 for i in range(L+1)]
DP[0]=[0]*5
for i in range(L):
  for j in range(5):
    DP[i+1][4]=min(DP[i+1][4],DP[i][j]+A[i])
  DP[i+1][0]=DP[i][0]+A[i]
  for k in [1,3]:
    for j in range(k+1):
      if A[i]:
        DP[i+1][k]=min(DP[i+1][k],DP[i][j]+(A[i]&1))
      else:
        DP[i+1][k]=min(DP[i+1][k],DP[i][j]+2)
  for j in range(3):
    DP[i+1][2]=min(DP[i+1][2],DP[i][j]+1-(A[i]&1))
print(min(DP[L]))

Measured memory_bytes: 119124
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n;
LL fact[1000005],rfac[1000005];
LL inv(LL v){
	LL ret=1LL,tms=MOD1-2LL;
	while(tms){
		if(tms&1) ret=(ret*v)%MOD1;
		v=(v*v)%MOD1;
		tms>>=1LL;
	}
	return ret;
}
LL C(int n,int m){
	if(n<m || n<0 || m<0) return 0LL;
	LL u=fact[n],d=(rfac[m]*rfac[n-m])%MOD1;
	return (u*d)%MOD1;
}
LL cntuni(int n,int sp){
	return (((C(n-sp-1,sp-2)*fact[sp-2])%MOD1)*fact[n-sp])%MOD1;
}
LL cntsin(int n,int sp){
	if(n<2) return 0;
	if(n==2) return sp==2;
	return ((((LL)(sp-2LL)*(LL)(sp-1LL))%MOD1)*cntuni(n-1,sp-1)%MOD1);
}
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    scanf("%d",&n);
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k;
	fact[0]=1LL;
	LL res=0LL;
	for(i=1;i<=n;++i){
		fact[i]=(fact[i-1]*(LL)i)%MOD1;
	}
	rfac[n]=inv(fact[n]);
	for(i=n-1;i>=0;--i){
		rfac[i]=(rfac[i+1]*(LL)(i+1))%MOD1;
	}
	for(i=1;i<n;++i){
		LL dlt=cntsin(n,n-i+1)+2LL*(LL)(n-i)*cntuni(n,n-i+1);
		res=(res+(LL)i*(dlt%MOD1))%MOD1;
	}
	printf("%lld\n",res);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

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

#define N 4010 

using namespace std;

typedef long long ll;

const int mod = 998244353 ;

int bin[N], C[N][N];

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int c(int n, int m) {
	if (m > n || m < 0) {
		return 0;
	}
	return C[n][m];
}

int calc(int v, int n, int k) {
	int ans = 0;
	int l = max(0, v / 2 - max(0, v - k - 1));
	for (int i = 0; i <= l; i ++ ) {
		ans = (ans + (ll)bin[i] * C[l][i] % mod * c(k - 2 * l + n - 1, n - i)) % mod;
	}
	return ans;
}

int rd() {
	int x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-')
			f = -1;
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
	}
	return x * f;
}


int main() {
	bin[0] = 1;
	for (int i = 1; i < N; i ++ ) {
		bin[i] = (ll)bin[i - 1] * 2 % mod;
	}
	for (int i = 0; i < N; i ++ ) {
		C[i][0] = C[i][i] = 1;
	}
	for (int i = 1; i < N; i ++ ) {
		for (int j = 1; j < i; j ++ ) {
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
		}
	}
	int k = rd(), n = rd();
	for (int i = 2; i <= 2 * k; i ++ ) {
		if (i & 1) {
			printf("%d\n", calc(i, n, k));
		}
		else {
			printf("%d\n", (calc(i - 1, n, k - 1) + calc(i - 1, n - 1, k - 1)) % mod);
		}
	}
	return 0;
}

Measured memory_bytes: 61696
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;
 
const double INF = 1e-11;
const ll MOD = 1e9 + 7;
const int MAXN = 3005;
 
double DP[MAXN][MAXN];
int n;
double p[MAXN];
 
double rek(int a, int b) {
	if (b > n - b) return 0.0;
	if (a + b == n) {
		if (a > b) return 1.0;
		return 0.0;
	}
	double &ret = DP[a][b];
	//cout << a << ' ' << b << ' ' << ret << '\n';
 	if (ret > -INF) return ret;
 	//cout << a << ' ' << b << ' ' << ret << '\n';
	return ret = p[a + b] * rek(a + 1, b) + (1.0 - p[a + b]) * rek(a, b + 1);  
}
 
int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	REP(i, MAXN) REP(j, MAXN) {
		if (i + j > n) break;
		if (j > n - j) break;
		DP[i][j] = -1.0;
	}
	REP(i, n) cin >> p[i];
	cout << fixed << setprecision(11) << rek(0, 0) << '\n';
}

Measured memory_bytes: 69504
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using _TYPE = int;
typedef tree< _TYPE, null_type, less< _TYPE >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main() {
    IO;
    ll one, zero, neg, k;
    cin >> one >> zero >> neg >> k;
    if(k <= one + zero)
        cout << min(k, one);
    else
        cout << one - (k - one - zero);
    return 0;
}


Measured memory_bytes: 3580
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
	char a[100],b[100];
	scanf("%s",a);
	getchar();
	scanf("%s",b);
	int n1=strlen(a);
	int n2=strlen(b);
	int i;
	if(n1==n2){
		for(i=0;i<n1;i++){
			printf("%c%c",a[i],b[i]);
		}
	}else if(n1>n2){
		for(i=0;i<n2;i++){
			printf("%c%c",a[i],b[i]);
		}
		printf("%c",a[n1-1]);
	}else{
		for(i=0;i<n1;i++){
			printf("%c%c",a[i],b[i]);
		}
		printf("%c",b[n2-1]);
	}
	return 0;
} 

Measured memory_bytes: 128
n = int(input())
x = input().split()
y = input().split()
dis = list()

for i in range(n):
    x[i] = int(x[i])
    y[i] = int(y[i])
    if x[i]>=y[i]:
        dis.append(x[i]-y[i])
    else:
        dis.append(y[i]-x[i])

#p=1
print(sum(dis))

#p=2
sum = 0
for elem in dis:
    sum = sum + elem**2
print(sum**(1/2))

#p=3
sum = 0
for elem in dis:
    sum = sum + elem**3
print(sum**(1/3))

#p=n
print(max(dis))


Measured memory_bytes: 5640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c;
	cin >> a >> b >> c;
	int ans = min(a+b, min(b+c, c+a));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  string s ;
  cin >> s ;
  
  if(SZ(s)==3){
    cout << s.at(2)<<s.at(1)<<s.at(0) <<endl ;
  }
  else{
    cout << s <<endl ;
  }


  return 0 ;
}




Measured memory_bytes: 256
#include <iostream>
#include <numeric>
using namespace std;
//B - Toll Gates
int main(void){
    int n,m,x;
    int a[101]={};
    std::cin >> n >> m >>x;
    for (int i = 0; i < m; i++) {
        int t;
        std::cin >> t;
        a[t]++;
    }
    int cost=min(accumulate(a,a+x,0),accumulate(a+x,a+n+1,0));
    std::cout << cost << std::endl;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. AtCoder.

       ENVIRONMENT DIVISION.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(100).
       01 A PIC 9(20).
       01 B PIC 9(20).
       01 temp1 PIC 9(15).
       01 temp2 PIC 9(15).
       01 Ninp PIC 9(15).

       PROCEDURE DIVISION.
       MAIN.
           ACCEPT INP.
           PERFORM VARYING temp1 FROM 1 BY 1 
           UNTIL INP(temp1:1) = SPACE
           END-PERFORM.
           SUBTRACT 1 FROM temp1.
           MOVE INP(1:temp1) TO A.
      *1st input
           ADD 2 TO temp1.
           PERFORM VARYING temp2 FROM temp1 BY 1
           UNTIL INP(temp2:1) = SPACE
           END-PERFORM.
           COMPUTE Ninp = temp2 - temp1.
           MOVE INP(temp1:Ninp) TO B.
      *2nd input 
      	   COMPUTE A = A * B.
           COMPUTE B = A / 2.
           COMPUTE B = B * 2.
		   IF A = B THEN
			    DISPLAY "Even"
		   ELSE 
			    DISPLAY "Odd"
		   END-IF.
        STOP RUN.
       

Measured memory_bytes: 636
import fractions, sys
input = sys.stdin.buffer.readline


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def calc(n, m):
    for i in range(cycle//m+1):
        X = m * (i + 0.5)
        if X > M:
            print(0)
            exit()
            return
        flag = True
        for x in n:
            if (X - x // 2) % x != 0:
                flag = False
                break
        if flag:
            return int(X)
    print(0)
    exit()
    return


N, M = map(int, input().split())
A = list(map(int, input().split()))
cycle = 1
ma = 0
for a in A:
    cycle = lcm(cycle, a)
    ma = max(ma, a)
start = calc(A, ma)

print((M - start) // cycle + 1)



Measured memory_bytes: 83820
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
int mod=1000000007;
int32_t main()
{
   fastio
   int n,m;
   cin>>n>>m;
   unordered_map<int,int>mp;
   while(m--)
   {
     int a;
     cin>>a;
     mp[a]=1;
   }
   int dp[n+1]={0};
   dp[0]=1;
   for(int i=1;i<=n;i++)
   {
     if(mp[i]==1)continue;
     else
     {
       if(i==1)dp[i]=dp[i-1]%mod;
       else dp[i]=((dp[i-1]%mod)+(dp[i-2]%mod))%mod;
     }
   }
   cout<<dp[n]%mod<<endl;
   return 0;
}


Measured memory_bytes: 5284
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i64 n, k;
i64 a[100000];
i64 b[100001];
i64 c[100001];

i32 main()
{
    cin >> n >> k;
    times(n, i) {
        cin >> a[i];
    }
	times(n, i) {
		b[i + 1] = b[i] + a[i];
		c[i + 1] = c[i] + max(0LL, a[i]);
	}
	i64 ans = 0;
	times(n - k + 1, i) {
		ans = max(ans, c[i] + b[i + k] - b[i] + c[n] - c[i + k]);
		ans = max(ans, c[i] + c[n] - c[i + k]);
	}
    cout << ans << endl;
    return 0;
}

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

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

const int dm = 1 << 23;
char dn[dm], * di = dn;
inline void putint(ll X, ll X2) {
	if (X == 0) {
		*di++ = '0';
	}
	else {
		if (X < 0) {
			*di++ = '-';
			X = -X;
		}
		int keta = 0;
		char C[20];
		while (X) {
			*(C + keta) = '0' + X % 10;
			X /= 10;
			keta++;
		}
		for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	}
	*di++ = ' ';
	if (X2 == 0) {
		*di++ = '0';
	}
	else {
		if (X2 < 0) {
			*di++ = '-';
			X2 = -X2;
		}
		int keta = 0;
		char C[20];
		while (X2) {
			*(C + keta) = '0' + X2 % 10;
			X2 /= 10;
			keta++;
		}
		for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	}
	*di++ = '\n';
}

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


	int Q = getint();

	ll X = 0;
	priority_queue<int> mae;
	priority_queue<int, vector<int>, greater<int>> ato;
	mae.push(-2e9);
	ato.push(2e9);
	int sa = 0;

	rep(i, Q) {
		if (getcha() == '1') {
			getcha();
			int a = getint();
			X += getint();

			if (sa) {
				int k = mae.top();
				if (a < k) {
					mae.pop();
					ato.push(k);
					mae.push(a);
					X += k + k;
					X -= a;
				}
				else {
					ato.push(a);
					X += a;
				}
				sa = 0;
			}
			else {
				int k = ato.top();
				if (a > k) {
					ato.pop();
					mae.push(k);
					ato.push(a);
					X += a;
					X -= k + k;
				}
				else {
					mae.push(a);
					X -= a;
				}
				sa = 1;
			}
		}
		else {
			getcha();
			int k = mae.top();
			ll ans = sa * k + X;
			putint(k, ans);
		}
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 7676
import itertools
import math


def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, (a % b))


K = int(input())
data = [k+1 for k in range(K)]
result = list(itertools.combinations_with_replacement(data, 3))

s = 0

for r in result:
    r0, r1, r2 = r
    g0 = gcd(r0, r1)
    g = gcd(g0, r2)
    if r0 == r1 == r2:
        s += g
    elif r0 != r1 and r1 != r2:
        s += g * 6
    else:
        s += g * 3

print(s)


Measured memory_bytes: 105612
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
	string s;
	while(cin >> s){
		char b[s.size()];
		for(int i=0;i<s.size();i++) b[i] = s[i];
		int w = 0;
		for(int i=0;i<s.length();i++){
			if(b[i]=='M') w += 1000;
			if(b[i]=='D') w += 500;
			if(b[i]=='C') w += 100;
			if(b[i]=='L') w += 50;
			if(b[i]=='X') w += 10;
			if(b[i]=='V') w += 5;
			if(b[i]=='I') w += 1;
		}
		for(int i=0;i<s.length()-1;i++){
			if(b[i]=='I' and b[i+1]!='I') w -= 2;
			if(b[i]=='V' and (b[i+1]!='V' and b[i+1]!='I')) w -= 10;
			if(b[i]=='X' and (b[i+1]!='X' and b[i+1]!='V' and b[i+1]!='I')) w -= 20;
			if(b[i]=='L' and (b[i+1]=='C' or b[i+1]=='D' or b[i+1]=='M')) w -= 100;
			if(b[i]=='C' and (b[i+1]=='D' or b[i+1]=='M')) w -= 200;
			if(b[i]=='D' and b[i+1]=='D') w -= 500;
		}
		cout << w << endl;
	}
}

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

int main(){

    ll n,k;
    cin >> n >> k;
    ll ans=0;

    for(ll i=k;i<=n+1;i++){
        ll min = (i - 1) * i / 2;
        ll max = (n + n - i + 1) * i / 2;
        ans += (max - min + 1);
        ans %= mod;
    }
    cout << ans << endl;

        return 0;
}

Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var aaa = Console.ReadLine().Split(' ');
            var alice = int.Parse(aaa[0]);
            var bobb = int.Parse(aaa[1]);

            if (alice == 1)
            {
                alice = 13;
            }
            else
            {
                alice = alice - 1;
            }
            if (bobb == 1)
            {
                bobb = 13;
            }
            else
            {
                bobb = bobb - 1;
            }

            if (alice < bobb)
            {
                Console.WriteLine("Bob");
            }
            else if (bobb < alice)
            {
                Console.WriteLine("Alice");
            }
            else
            {
                Console.WriteLine("Draw");
            }
            
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
using namespace std;
long long ruijo(int x,int jo)
{
	if(jo == 0) return 1;
	return ((x*ruijo(x,jo-1))%1000000007) ;
}
int main()
{
	long long num[60];
	for(int i = 0;i < 60;i++)
	{
		num[i] = 0;
	}
	int N;
	cin >> N;
	for(int i = 0;i < N;i++)
	{
		long long tmp;
		cin >> tmp;
		for(int j = 0;j < 60;j++)
		{
			if(tmp & (1LL<<j)) num[j]++;
		}
	}
	long long ans = 0;
	for(int i = 0;i < 60;i++)
	{
		ans += 
		((((num[i])*(N-num[i]))%1000000007)*ruijo(2,i))
		% 1000000007;
	}
	ans = ans % 1000000007;
	cout << ans << endl;
}
	

Measured memory_bytes: 256
N,M=map(int,input().split())
ans=0
for i in range(1,10**5):
    if M%i==0:
        a=max(M//i,i)
        b=min(M//i,i)
        if M//a>=N and ans<a:
            ans=a
        if M//b>=N and ans<b:
            ans=b
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007


int main(void)
{
	CIN;
	ll tc,l,k=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n;
	ll arr[3*n];
	for(ll i=0;i<3*n;i++)
		cin>>arr[i];
	sort(arr,arr+(3*n));
	for(ll i=3*n-2,j=1;j<=n;i-=2,j++)
		sum+=arr[i];
	cout<<sum<<nw;

}

Measured memory_bytes: 6000