akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
    ll a, b, c, d, e , m, n, k, x,l,r;
    string s;
    ll ans = 0;
    double dans = 0;
    string sans = "Yes";
    vector<ll> ar;

    cin >> a;

    ll index = 0;
    while(1){
        index++;

        if(index==1){
            ar.push_back(a);
        }
        else{
            ll tail = *(ar.rbegin());
            ll ma;
            if(tail%2==0) ma = tail/2;
            else ma = 3 * tail + 1;

            auto it = find(all(ar), ma);
            if(it != ar.end()){
                break;
            }
            else ar.push_back(ma);
        }
    }

    ans = index;
    std::cout << ans << endl; 

    // std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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



int main(){
    int N, A; std::cin >> N;
    long long ans(0);
    std::map<int, int> mp;
    for(int i(0); i < N; ++i){
        std::cin >> A;
        ans += mp[A-i];
        ++mp[-i-A];
    }
    std::cout << ans << std::endl;
    return 0;
}


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

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

int main() {
  int x, K, s=0;
  cin >> K;
  for(int a = 1; a <= K; a++) {
    for(int b = a+1; b <= K; b++) {
      x = gcd(a,b);
      for(int c = b+1; c <= K; c++) {
        s += gcd(x,c)*6;
      }
    }
  }
  for(int a = 1; a <= K; a++) {
    for(int b = a+1; b <= K; b++) {
      s += gcd(a,b)*6;
    }
  }
  s += K*(K+1)/2;
  cout << s << endl;
}



Measured memory_bytes: 3612
N,L=map(int,input().split()[:2])

snum=sum([L+i-1 for i in range(1,N+1,1)])
if L>0:
    print(snum-L)
else:
    if L+N>0:
        print(snum)
    else:
        print(snum-L-N+1)

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

    vector<int> m(N);

    int sum = 0;
    for (int i = 0; i < N; i ++){
        cin >> m[i];
        sum += m[i];
    }
    sort(m.begin(), m.end());
    int M = (X - sum) / m[0];

    cout << N + M << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100005;
char ss[N];
int n;
int X[N],Y[N];
int num=0;
int main()
{
	scanf("%s",ss+1);
	n=strlen(ss+1);
	if (ss[1]=='0'||ss[n]=='1')	{printf("-1\n");return 0;}
	for (int u=1;u<n;u++)
	{
		if (ss[u]!=ss[n-u])
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("1 2\n");
	int tp=1,sum=2;
	for (int u=2;u<n;u++)
	{
		sum++;
		printf("%d %d\n",sum,tp);
		if (ss[u]=='1') tp=sum;
	}
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N;

  cin >> N;

  int ans = 0;

  for (int i=1; i<=N; i++) {
    int log10 = 0, tmp = i;
    while(tmp) {
      log10++;
      tmp /= 10;
    }
    ans += log10 % 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int n;
    int res;

    scanf ( "%d", &n );
    if ( !n ) break ;

    for ( res = 0; n != 1; ++res )
    {
      if ( !( n % 2 ) ) n >>= 1;
      else              n   = n * 3 + 1;
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

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

typedef long long int ll;
typedef unsigned long long int ull;

#define REP(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

  int minr = n, maxl = 0;
  REP(i, m)
  {
    int l, r;
    cin >> l >> r;

    minr = min(r, minr);
    maxl = max(l, maxl);
  }

  if (minr - maxl + 1 > 0)
  {
    cout << minr - maxl + 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans=0;
  for(int r=0;R*r<=N;r++){
    for(int g=0;R*r+G*g<=N;g++){
      int f = N - R*r - G*g;
      if(f%B==0)ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll A,B,C,D;
  cin>>A>>B>>C>>D;
  ll c=B/C-A/C;
  ll X=C;
  ll Y=D;
  if(A%C==0) {
c++;
  }
  ll d=B/D-A/D;
  if(A%D==0) {
d++;
  }
 
  
  ll cd=1;
  ll K=min(C,D);
  for(ll i=2;i<=sqrt(K);i++) {
if(C%i==0&&D%i==0) {
while(C%i==0&&D%i==0) {
C/=i;
  D/=i;
  cd*=i;
}
}
    
    if(C%i==0) {
while(C%i==0) {
C/=i;
}
    }
    if(D%i==0) {
while(D%i==0) {
D/=i;
}
    }
  }
  if(D%C==0) {
cd*=C;
  }
  else if(C%D==0) {
cd*=D;
  }
  
  cd=cd*(X/cd)*(Y/cd);
  ll ans=B/cd-A/cd;
  if(A%cd==0) {
ans++;
  }
 
  
  cout<<B-A+1-c-d+ans<<endl;
}
  
  
  
  
  
  

  
  


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
  int n,ans=1,ans2=0,d,i;
  scanf("%d %d",&d,&n);
  for(i=1;i<=d;i++){
    ans*=100;
  }

  for(i=1;i<=n;i++){
    ans2+=ans;
    }

  if(n==100){
    ans2+=ans;
  }

    printf("%d",ans2);

  return 0;

}


Measured memory_bytes: 128
from sys import exit

def mod_pow(a, n, p):
    """累乗 O(logN)

    Args:
        a (int): 対象の値
        n (int): 指数
        p (int): 除数

    Returns:
        int: a^n mod p
    """
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % p
        a = a * a % p
        n >>= 1
    return res

def mod_comb_k(n, k, p):
    """二項係数 0(1)

    Args:
        n (int): 添字
        k (int): 添字
        p (int): 除数

    Returns:
        int: nCk mod p
    """
    if n < k or n < 0 or k < 0:
        return 0
    else:
        return fact[n] * fact_inv[k] * fact_inv[n-k] % p

def com_init(n, p):
    """二項係数の計算の前処理 O(N)

    Args:
        n (int): 上限値
        p (int): 除数
    """
    for i in range(n):
        fact.append(fact[-1] * (i+1) % p)

    fact_inv[-1] = pow(fact[-1], p-2, p)
    for i in range(n-1, -1, -1):
        fact_inv[i] = fact_inv[i+1] * (i+1) % p


n = int(input())

mod = 10 ** 9 + 7

if n == 1:
    print(0)
    exit()

res1 = mod_pow(10, n, mod)
res2 = mod_pow(8, n, mod)
res3 = 0
fact = [1]
fact_inv = [0] * (n+1)
com_init(n, mod)
for i in range(1, n+1):
    res3 = (res3 + mod_pow(8, n-i, mod) * mod_comb_k(n, i, mod) % mod) % mod
print(((res1 - res2) % mod - res3 * 2 % mod) % mod)

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

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll p = pow(10, 9) + 7;
  
  vector<ll> inv(max(a, b) + 10);
  vector<ll> inf(max(a, b) + 10);

  inv[0] = 1; inv[1] = 1;
  inf[0] = 1; inf[1] = 1;

  for(ll i = 2; i <= max(a,b); i++){
    inv[i] = p - inv[p % i] * (p / i) % p;
    inf[i] = inf[i-1] * inv[i] % p;
  }

  ll aa = 1;
  for(ll i = 0; i < a; i++){
    aa *= n-i;
    aa %= p;
  }
  aa *= inf[a];
  aa %= p;
  ll bb = 1;
  for(ll i = 0; i < b; i++){
    bb *= n-i;
    bb %= p;
  }
  bb *= inf[b];
  bb %= p;

  ll res = 1;
  ll syou = n/32;
  ll amari = n%32;

  for(ll i = 0; i < syou; i++){
    res *= pow(2, 32);
    res %= p;
  }
  for(ll i = 0; i < amari; i++){
    res *= 2;
    res %= p;
  }
  res -= 1 + bb + aa;
  while(res < 0){res += p;}
  cout << res << endl;

}       

Measured memory_bytes: 3328
sub downGrade {
  my ($x, $i) = @_;
  my $b = 1 << $i;
  if ($x & $b) {
    return (($x & ~$b) | ($b - 1));
  }else {
    return undef;
  }
}

sub indCondSum {
  my ($ceil, $q) = @_;
  my $revceil = ~(0 + $ceil);
  my $sum = 0;
#  print "q = $q\n";
  foreach my $p (@$q) {
    my ($a, $b) = @$p;
    if (($a & $revceil) == 0) {
#    if (included($a, $ceil)) {
#      print "added $b\n";
      $sum += $b;
    }
  }
  return $sum;
}

sub condSum {
  my ($k, $q) = @_;
  my $max = indCondSum($k, $q);
  for (my $i; $i < 32; $i++) {
    my $dg = downGrade($k, $i);
    if (!defined($dg)) { next; }
    my $vv = indCondSum($dg, $q);
    if ($vv > $max) { $max = $vv; }
  }
  return $max;
}

sub getInts {
  $_ = <STDIN>;
  chomp($_);
  chop if (/\r$/);
  my ($a, $b) = split(' ');
  return ($a, $b);
}

my ($n, $k) = getInts();
my $ab = [];
for (my $i = 0; $i < $n; $i++) {
  $ab->[$i] = [getInts()];
}
# print "ab is @$ab\n";
print condSum($k, $ab), "\n";


Measured memory_bytes: 29312
import sys
from itertools import islice, repeat


def _resolve(costs, k):
    sum_ = sum(costs)
    v = 0
    if k >= len(costs):
        if sum_ > 0:
            x = k // len(costs) - 1
            v = x * sum_
            k -= x * len(costs)
        else:
            k = len(costs)

    points = [v] * (len(costs) * (k + 1))
    for i in range(k):
        for n in range(len(costs)):
            points[(i + 1) * len(costs) + n] = points[i * len(costs) + n] + costs[(i + n) % len(costs)]
    
    ans = max(points)
    if ans == 0:
        y = max(costs)
        if y < 0:
            ans = y
    return ans


def resolve(in_):
    N, K = map(int, next(in_).split())
    P = [0] + list(map(int, next(in_).split()))
    C = [0] + list(map(int, next(in_).split()))

    graphs = []
    used = [False] * len(P)
    for index in range(1, len(P)):
        if used[index]:
            continue
        used[index] = True
        graph = [C[index]]
        index = P[index]
        while not used[index]:
            graph.append(C[index])
            used[index] = True
            index = P[index]
        graphs.append(graph)

    ans = max(map(_resolve, graphs, repeat(K)))
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


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

int main(){
  string S;
  cin>>S;
  int64_t N=S.size();
  int64_t K;
  cin>>K;
  int64_t ans=0;

  if(S[0]==S[N-1]){
    int64_t a=0,b=N-1;
    int64_t cnt=0;
    while(a<N && S[a]==S[0]){
      ++a;
      ++cnt;
    }
    if(a==N) cout<<(K*N)/2<<endl;
    else{
      while(b>=0 && S[b]==S[N-1]){
        --b;
        ++cnt;
      }
    for(int i=a;i<b+1;++i){
      if(i<b){
        int64_t j=i+1;
        while(j<b+1 && S[j]==S[i]) ++j;
        ans += (j-i)/2;
        i=j-1;
      }
    }
    ans *= K;
    ans += a/2;
    ans += (N-b-1)/2;
    ans += (K-1)*((a+N-b-1)/2);
    cout<<ans<<endl;
  }
  }
  else{
    for(int i=0;i<N;++i){
      if(i<N-1){
        int j=i+1;
        int cnt=0;
        while(j<N && S[i]==S[j]){
          ++j;
        }
        ans += (j-i)/2;
        i=j-1;
      }
    }
    cout<<K*ans<<endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b=0,c=0;cin>>a;
  rep(i,a){
    char d;cin>>d;
    if(d=='I')b++;
    else b--;
    c=max(c,b);
  }
  cout<<c;
}


Measured memory_bytes: 27056
#include<iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if((a == 1 && b == 2) || (a == 2 && b == 1 )){
        cout << "3" << endl;
    }else if((a == 2 && b == 3) || (a == 3 && b == 2 )){
        cout << "1" << endl;
    }else{
        cout << "2" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define endl '\n'
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int32_t main()
{
	IO_OP;
	
	string s;
	vector<string> v;
	cin >> s;
	v.PB(s.substr(0, 1));
	for(int i=1;i<s.size();) {
		int j = i+1;
		while(j <= s.size() && s.substr(i, j-i) == v.back()) {
			j++;
		}
		if(s.substr(i, j-i) != v.back())  v.PB(s.substr(i, j-i));
		i = j;
	}
	// for(string s:v)
	// 	cout << s << " ";
	cout << v.size() << endl;
}



Measured memory_bytes: 11016
#include<bits/stdc++.h>
using namespace std;
string s;
int ans=0,ans1=0;
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //freopen("milkvisits.in","r",stdin);
    //freopen("milkvisits.out","w",stdout);
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(i%2&&s[i]=='1')ans++;
        if(i%2&&s[i]=='0')ans1++;
        if(i%2==0&&s[i]=='0')ans++;
        if(i%2==0&&s[i]=='1')ans1++;
    }
    cout<<min(ans,ans1);
}


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

int main() {
    string str;
    cin >> str;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        string odr;
        cin >> odr;
        if(odr == "replace"){
            int x, y;
            string z;
            cin >> x >> y >> z;
            str.replace(x, y-x+1, z);
            //cout << str << endl;
        }
        if(odr == "reverse"){
            int x, y;
            cin >> x >> y;
            reverse(str.begin()+x, str.begin()+y+1);
            //cout << str << endl;
        }
        if(odr == "print"){
            int x, y;
            cin >> x >> y;
            cout << str.substr(x, y-x+1) << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 3188
#include <iostream>
#include<cstdio>
using namespace std;
int main(void){
    int a, b;
    char grid[100][100];
    scanf("%d%d",&a,&b);
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            grid[i][j] = i < 50 ? '.' : '#';
        }
    }
    for (int i = 0; i < a - 1; i++)
        grid[i / 50 * 2 + 51][i % 50 * 2] = '.';
    for (int i = 0; i < b - 1; i++)
        grid[i / 50 * 2][i % 50 * 2] = '#';
    cout << "100 100" << endl;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            cout << grid[i][j];
        }
        puts("");
    }
}



Measured memory_bytes: 256
import sys
import numpy as np
from collections import Counter

read = sys.stdin

N, K = map(int, read.readline().split())
k = 2 * K
xyc = np.array(read.read().split(), np.str).reshape(-1, 3)
x = xyc[:, 0].astype(int)
y = xyc[:, 1].astype(int)
c = xyc[:, 2]

x[c == 'B'] -= K
x %= k
y %= k

'''
# grid[[1,1],[2,2]]+=1 としてもgrid[1,2]=1であり重複は考慮されない。
# uniqueを使って(x,y)の重複をカウントする
# return_countはver1.9からだった・・・ ダメじゃん
xy, cnt = np.unique(x + y * 10000, return_counts=True)
x = xy % 10000
y = xy // 10000
'''
xy = Counter(zip(x.tolist(), y.tolist()))
cnt = np.array(list(xy.values()), np.int64)
xy = np.array(list(xy.keys()), np.int64)
x = xy[:, 0]
y = xy[:, 1]

grid = np.zeros((3 * K, 3 * K), np.int64)
grid[x, y] += cnt
grid[x + K, y + K] += cnt
grid[x + K, y] -= cnt
grid[x, y + K] -= cnt
np.cumsum(grid, axis=0, out=grid)
np.cumsum(grid, axis=1, out=grid)

p1 = grid[:K, :K] + grid[k:, k:] + grid[K:k, K:k] + grid[k:, :K] + grid[:K, k:]
p2 = grid[K:k, :K] + grid[K:k, k:] + grid[:K, K:k] + grid[k:, K:k]
print(max(p1.max(), p2.max()))


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	// cout << s.length() << endl;

	if(s.length() <= k){
		cout << s;
	}
	else{
		rep(i, k){
			cout << s[i];
		}
		cout << "...";
	}

	return 0;
}

Measured memory_bytes: 3596
S=input()
s,w,n,e=0,0,0,0
for i in range(len(S)):
  if S[i]=='N':
    n+=1
  elif S[i]=='S':
    s+=1
  elif S[i]=='W':
    w+=1
  else:
    e+=1
ns=False
ew=False
if (n>0 and s>0) or (n==0 and s==0):
  ns=True
if (e>0 and w>0) or (e==0 and w==0):
  ew=True
if ns and ew:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import sys
a = []
while True:
    x = map(int, raw_input().split())
    if x[0] == 0 and x[1] == 0:
        break
    a.append(x)
for i in range(len(a)):
    for j in range(a[i][0]):
        if j%2 == 0:
            for k in range(a[i][1]):
                if k%2 == 0:
                    sys.stdout.write('#')
                else:
                    sys.stdout.write('.')
        else:
            for k in range(a[i][1]):
                if k % 2 == 0:
                    sys.stdout.write('.')
                else:
                    sys.stdout.write('#')
        print ''
    print ''

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

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

  long long int power = 1, mod = pow(10, 9) + 7;

  
  for(int i = 1; i <= num; ++i){
    power *= i;
    power %= mod;
  }

  cout << power << endl;

  return 0;
  
}


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

/* define const */
const int Max = 100;
/* finish defineing const */

char ain[Max+1][Max+1];
char aout[2*Max+2][Max+1]; // arr[Y][X]

int main()
{
  int H,W; // W..x,H..y
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++) {
      ain[i][j] = s[j];
    }
  }
  // finish inputting

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (ain[i][j] == '.') {
        aout[i*2][j] = '.';
        aout[i*2+1][j] = '.';
      }
      else {
        aout[i*2][j] = '*';
        aout[i*2+1][j] = '*';
      }
    }
  }
for (int i = 0; i < 2*H; i++) {
    for (int j = 0; j < W; j++) {
      cout << aout[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
from itertools import accumulate
from bisect import bisect_left, bisect_right
import sys

input = sys.stdin.buffer.readline
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AA = list(accumulate([0] + A))
BB = list(accumulate([0] + B))
apos = bisect_right(A, k)

ans = 0
for i in range(apos, -1, -1):
    temp_a = AA[i]
    remain = k - temp_a
    if remain < 0:
        continue
    pos = bisect_right(BB, remain)
    ans = max(ans, pos + i - 1)

print(ans)


Measured memory_bytes: 132332
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        Deque<String> dq = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                dq.addLast(Integer.toString(a[i]));
            } else {
                dq.addFirst(Integer.toString(a[i]));
            }
        }

        List<String> list = new ArrayList<>();
        while (!dq.isEmpty()) {
            if (n % 2 == 0) {
                list.add(dq.pollFirst());
            } else {
                list.add(dq.pollLast());
            }
        }
        String result = String.join(" ", list);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 80244
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<=25;++i)
    if(n>=4*i)
    {
        if((n-4*i)%7==0)
        {cout<<"Yes";return 0;}
    }
    cout<<"No";
    return 0;
}

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


class UnionFind(object):
    def __init__(self, n):
        self.parent={i:i for i in range(1,n+1)}
        self.size={i:1 for i in range(1,n+1)}
    def find(self, a):
        if self.parent[a]!=a:
            self.parent[a]=self.find(self.parent[a])
        return self.parent[a]
    def getsize(self, a):
        return self.size[self.find(a)]
    def unite(self, a, b):
        a=self.find(a)
        b=self.find(b)
        if a==b:return
        if self.size[a]>self.size[b]:
            self.size[a]+=self.size[b]
            self.parent[b]=a
        else:
            self.size[b]+=self.size[a]
            self.parent[a]=b
    def isunited(self, a, b):
        return self.find(a)==self.find(b)


def solve():
    N, M, K = map(int, input().split())
    uft = UnionFind(N)
    d = {i:set() for i in range(1, N+1)}
    e = {i:0 for i in range(1, N+1)}
    f = {i:0 for i in range(1, N+1)}

    for _ in range(M):
        A, B = map(int, input().split())
        d[A].add(B)
        d[B].add(A)
        f[A] += 1
        f[B] += 1
        uft.unite(A, B)

    for _ in range(K):
        C, D = map(int, input().split())
        if uft.isunited(C, D):
            if D not in d[C]:
                e[C] += 1
            if C not in d[D]:
                e[D] += 1
    
    g = lambda x:uft.getsize(x)-e[x]-f[x]-1
    print(*map(g, range(1, N+1)))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 88772
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005
 
// it's swapnil07 ;)

int dp[105][100005];
int w[105], v[105];

signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    int n, W; cin>>n>>W;
    for(int i=1; i<=n; i++){
        cin>>w[i]>>v[i];
    }
    For(i, 0, n+1){
        For(j, 0, 100005){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    int ans = 0;
    int vv = 1e5;
    For(i, 1, n+1){
        For(j, 0, vv+1){
            if(dp[i-1][j]==INF)
                continue;
            dp[i][j+v[i]]=min(dp[i-1][j]+w[i], dp[i][j+v[i]]);
            dp[i][j]=min(dp[i-1][j], dp[i][j]);
            if(dp[i][j+v[i]] <= W){
                ans = max(ans, j+v[i]);
            }
        }
    }
    cout<<ans;
    return 0;
}

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

int main(void) {

    int N; cin >> N;
    vector<int> s(N);
    bool flag = true;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        if (flag && s[i]%10 != 0) flag = false;
    }

    if (flag) {
        cout << 0 << endl;
    } else {
        sort(s.begin(), s.end());
        int ans = 0;
        for (int i = 0; i < N; i++) ans += s[i];

        if (ans%10 == 0) {
            for (int i = 0; i < N; i++) {
                if (s[i]%10 != 0) {
                    ans -= s[i];
                    break;
                }
            }
        }
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[],int N) {
    int i;
    for(i=0;i<N;i++) {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N) {
    int i,j,v;
    for(i=1;i<N;i++) {
        v=A[i];
        j=i-1;
        while(j>=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(void)
{
    int N, i;
    int A[100];
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);
    
    trace(A,N);
    insertionSort(A,N);
    return 0;
}



Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;
ll x[200100],y[200100];
string s,str;
int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>x[i];
  }
  for(int i=0;i<n-1;i++){
    if(x[i]<=i+1)y[x[i]-1]++;
  }
  for(int i=0;i<n;i++){
    cout<<y[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 6704
'''
先頭から値を確認していき、値が増加/減少した後に値が減少/増加した場合に数列の分割数を増やす
'''

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

ans = 1
flg = 0
for i in range(N-1):
    if flg == 0:
        if A[i+1] > A[i]:
            flg = 1
        elif A[i+1] < A[i]:
            flg = -1
        else:
            pass
    elif flg == 1:
        if A[i+1] > A[i]:
            pass
        elif A[i+1] < A[i]:
            flg = 0
            ans += 1
        else:
            pass
    else:
        if A[i+1] > A[i]:
            flg = 0
            ans += 1
        elif A[i+1] < A[i]:
            pass
        else:
            pass

print(ans)

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

int main(){
  int a, b, k; cin >> a >> b >> k;
  
  int now = a;
  for(int i = 0; i < k; i++){
    if(now > b) break;
    cout << now << ' ';
    now++;
  }
  
  if(now < b - k + 1) now = b - k + 1;
  for(int i = 0; i < k; i++){
    if(now > b) break;
    cout << now << ' ';
    now++;
  }
}

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

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	set<int> s;
	rep(i, n) {
		int d; cin >> d;
		s.insert(d);
	}
	printf("%d\n", s.size());
	return 0;
}

Measured memory_bytes: 256
_, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).uniq.map { |x| x / 2 }
x = a.inject(&:lcm)

if a.any? { |i| (x / i).even? }
  puts 0
  exit 0
end

count = (m >= x ? 1 : 0) + (m - x) / (2 * x)
puts count < 0 ? 0 : count


Measured memory_bytes: 8836
import java.util.Scanner;

public class Main {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

        int ans = solve(N, K, x);

        System.out.println(ans);
    }

    private static int solve(int N, int K, int[] x) {
        int count = 0;

        for (int i=0; i<N; i++) {
            int min = Math.min(x[i], Math.abs(K - x[i]));
            count += min*2;
        }

        return count;
    }

}


Measured memory_bytes: 21460
#include<iostream>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
typedef string::const_iterator Cursol;
int num(Cursol&);
string calc(Cursol&);
string expr(Cursol&);

int pos ;

int num(Cursol& p){
  int ret = 0;
  while(isdigit(*p)){
    ret = ret * 10 + *p - '0';
    p++;
  }
  return ret;
}

string calc(Cursol& p){
  string ret;
  if(isdigit(*p)){
    int number = num(p);
    if( *p == '(') {
      p++;
      string res = expr(p);
      p++;
      while(number--){
        ret += res;
        if(pos < ret.size()) break;
      }
    } else {
      char c = *p;
      p++;
      while(number--){
        ret += c;
        if(pos < ret.size()) break;
      }
    }
  }else{
    while(isalpha(*p)){
      ret += *p;
      p++;
      if(pos < ret.size()) break;
    }
  }
  return ret;
}


string expr(Cursol& p){
  string ret;
  while( isalpha(*p) || isdigit(*p)){
    ret += calc(p);
    if(pos < ret.size()) break;
  }
  return ret;
}
int main(){
  string str;
  while(cin >> str >> pos, str!="0"||pos){
    Cursol idx = str.begin();
    string ret = expr(idx);
    if(pos < ret.size()) cout << ret[pos] << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 6088
def main():
    n, m = map(int, input().split())

    if m == 0:
        if n == 1:
            print(0)
        elif n == 2:
            print(10)
        else:
            print(100)
        return

    s_ls =[]
    c_ls =[]
    for _ in range(m):
        s, c = map(int, input().split())
        s_ls.append(s)
        c_ls.append(c)

    if n == 1:
        for i in range(0, 10):
            all_ok = True
            for j in range(m):
                if c_ls[j] != i:
                    all_ok = False
                    break
            if all_ok:
                print(i)
                return
        print(-1)
    elif n == 2:
        for i in range(10, 100):
            all_ok = True
            for j in range(m):
                if s_ls[j] == 1:
                    if c_ls[j] == 0:
                        all_ok = False
                        break
                    else:
                        if c_ls[j] != i // 10:
                            all_ok = False
                            break
                else:
                    if c_ls[j] != i % 10:
                        all_ok = False
                        break
            if all_ok:
                print(i)
                return
        print(-1)
    else:
        for i in range(100, 1000):
            all_ok = True
            for j in range(m):
                if s_ls[j] == 1:
                    if c_ls[j] == 0:
                        all_ok = False
                        break
                    else:
                        if c_ls[j] != i // 100:
                            all_ok = False
                            break
                elif s_ls[j] == 2:
                    if c_ls[j] != (i % 100) // 10:
                        all_ok = False
                        break
                else:
                    if c_ls[j] != i % 10:
                        all_ok = False
                        break
            if all_ok:
                print(i)
                return
        print(-1)


main()


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>>LR(2, vector<int>(M));
  for(int i =0; i<M; i++){
    cin >> LR.at(0).at(i) >> LR.at(1).at(i);
  }
  
  int Lmax =0;
  int Rmin =1000000;
  
  for(int i=0; i<M; i++){
    if(Lmax<LR.at(0).at(i))Lmax=LR.at(0).at(i);
    if(Rmin>LR.at(1).at(i))Rmin=LR.at(1).at(i);
  }
  
  int ans=Rmin-Lmax+1;
  if(ans<0)ans=0;
  
  cout << ans << endl;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int n;
	cin >> n;
	int highest = 0,res=0;
	FOR(i, 1, n) {
		int h;
		cin >> h;
		highest = max(highest, h);
		if (highest == h) {
			res++;
		}
	}
	pv(res);
	return 0;
}

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


int N, K;
vector<int> p;

int main(void)
{
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }

    sort(p.begin(), p.end());
    int ans = 0;

    for (int i = 0; i < K; i++)
    {
        ans += p[i];
    }

    cout << ans;
}

Measured memory_bytes: 3644
using System;
using System.Collections;
using System.Linq;

public class MainApp
{
    static public void Main(string[] args)
    {
        var s = Console.ReadLine();
        int length = s.Length;
        int output = 0;
        for(int i = 1; ;i++)
        {
            s = s.Substring(0, s.Length - 1);
            length = s.Length;
            if (length % 2 != 0) continue;
            else
            {
                string one = s.Substring(0, length / 2);
                string two = s.Substring(length / 2, length/2);
                if (one == two)
                {
                    output = length;
                    break;
                }


            }

        }
        Console.WriteLine(output);
    }

}

Measured memory_bytes: 11092
n, k = map(int, input().split())

MOD = 10**9+7
n += 1
ans = 0
for i in range(k, n+1):
    p = i*(2*n - (i-1)) // 2
    m = i*(2 + i-1) // 2
    ans += p - m + 1
print(ans % MOD)

Measured memory_bytes: 9084
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let s = input::<String>();
    let t = input::<String>();

    let s = s.chars().collect::<Vec<char>>();
    let mut temp = String::new();
    let mut ok = false;
    for i in 0..s.len() {
        temp.clear();
        let l = s[..i].iter().map(|&c| c).collect::<String>();
        let r = s[i..].iter().map(|&c| c).collect::<String>();
        temp.push_str(&r);
        temp.push_str(&l);
        if temp == t {
            ok = true;
        }
    }

    println!("{}", if ok { "Yes" } else { "No" });
}


Measured memory_bytes: 4476
#include <iostream>
#include <vector>

using namespace std;

int dp[10010][100][2];

const int MOD = 1e9 + 7;

int main()
{
    string k;
    int d;

    cin >> k;
    cin >> d;

    int n = k.length();

    vector <int> number(n);

    for (int i = 0; i < n; i++)
        number[i] = k[i] - '0';

    dp[0][0][0] = 1;

    for(int i = 0; i < n; i++)
    {
        int maxDigit = number[i];

        for (int j = 0; j < d; j++)
        {
            for (int digit = 0; digit < 10; digit++)
            {
                int rest = (j + digit) % d;

                dp[i + 1][rest][1] = (dp[i + 1][rest][1] + dp[i][j][1]) % MOD;
            }

            for (int digit = 0; digit < maxDigit; digit++)
            {
                int rest = (j + digit) % d;

                dp[i + 1][rest][1] = (dp[i + 1][rest][1] + dp[i][j][0]) % MOD;
            }

            int rest = (j + maxDigit) % d;

            dp[i + 1][rest][0] = (dp[i + 1][rest][0] + dp[i][j][0]) % MOD;
        }
    }
    int answer = dp[n][0][1]+dp[n][0][0] - 1;

    cout << (answer + MOD) % MOD << endl;

    return 0;
}


Measured memory_bytes: 8064
// Problem: D - Redistribution
// Contest: AtCoder - AtCoder Beginner Contest 178
// URL: https://atcoder.jp/contests/abc178/tasks/abc178_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define ll long long
const int N = 2e5+5;
const int mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
#pragma GCC optimize("-O2")
const int INF = 10000000;

int getIInput() {
	cout.flush();
	#ifdef LOCAL
	return generateLocalInputOrAnythingYouWant();
	#else
	int x;
	cin>>x;
	return x;
	#endif
}

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(9);
}
 
//3. Structure or classes
class Val{
	public:
	int val=-1;
};
//3. Ends here
 
//1. Data structures declaration here
map<int,int>dp;
//1. Ends here
 
//2. Extra Functions here
void init(){
	for(int i=1;i<=2;i++){
		dp[i]=0;
	}
}

int yo(int n){
	if(dp[n]!=0)return dp[n];
	
	int ans=0;
	for(int i=3;i<=n-3;i++){
		ans=(ans+yo(i)+1+mod)%mod;
	}
	dp[n]=ans;
	return ans;
}
//2. Ends here
 
 
void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}
 
 
 
void solve()
{	
	int n;
	cin>>n;
	init();
	if(n<=2){
		cout<<"0";return;
	}
	int ans = yo(n)+1;
	cout<<(ans+mod)%mod;
    return;
}
// how r u bro

Measured memory_bytes: 3728
x,y,z,k = map(int,input().split())
lia = sorted(list(map(int,input().split())),reverse = True)
lib = sorted(list(map(int,input().split())),reverse = True)
lic = sorted(list(map(int,input().split())),reverse = True)
li = []

for s in range(x):
    for t in range(y):
        if s*t > k: break
        for u in range(z):
            if s*t*u <= k:
                li.append(lia[s]+lib[t]+lic[u])
            else: break
ans = sorted(li,reverse = True)[:k]

print('\n'.join(map(str,ans)))


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
constexpr long long MOD(long long in) {
	return in % mod;
}

ll l, r;
int main()
{
	std::cin >> l >> r;

	bool b = l + 2019 <= r;

	l %= 2019;
	r %= 2019;

	if (b)
		r += 2019;

	int ans = 2018;
	for (int i = l; i <= r; ++i)
		for (int j = i + 1; j <= r; ++j)
			ans = std::min(ans, (i * j) % 2019);

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


Measured memory_bytes: 256
from collections import deque, Counter
N, M = map(int, input().split())

L = deque()
for i in range(N):
    L.append(list(map(int, input().split())))

ans = list(L[0][1:len(L[0])])
for i in range(N - 1):
    for j in range(L[i][0]):
        if L[i][j + 1] in L[i + 1][1:L[i + 1][0] + 1]:
            ans.append(L[i][j + 1])

c = Counter(ans)
count = 0
for k, v in c.items():
    if (v == N):
        count += 1
    else:
        continue
print(count)


Measured memory_bytes: 3444
n=int(input())
b=list(map(int,input().split()))


ans=[]
for _ in range(n):
    for idx in range(1,len(b)+1)[::-1]:
        if idx==b[idx-1]:
            ans+=idx,
            del b[idx-1]
            break


if len(b)>0:
    print(-1)
    exit()

  
for j in ans[::-1]:
    print(j)
       

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

int main()
{
    int n;
    long long c, *x, *v, max = 0, *(table[4]), *dp;
    scanf("%d%lld", &n, &c);
    x = new long long[n + 2];
    v = new long long[n + 2];
    for (int i = 0; i < 4; i++) table[i] = new long long[n + 2];
    x[0] = v[0] = 0;
    x[n + 1] = c;
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld%lld", x + i, v + i);
        v[i] += v[i - 1];
    }
    v[n + 1] = v[n];

    for (int i = 0; i <= n + 1; i++)
    {
        table[0][i] = v[i] - x[i];
        table[1][i] = v[i] - 2 * x[i];
    }
    for (int i = n + 1; i > 0; i--)
    {
        table[2][i] = (v[n + 1] - v[i - 1]) - (x[n + 1] - x[i]);
        table[3][i] = (v[n + 1] - v[i - 1]) - 2 * (x[n + 1] - x[i]);
    }
    for (int l = 1; l <= n + 1; l++)
    {
        table[0][l] = std::max(table[0][l - 1], table[0][l]);
        table[1][l] = std::max(table[1][l - 1], table[1][l]);
    }
    for (int r = n; r > 0; r--)
    {
        table[2][r] = std::max(table[2][r + 1], table[2][r]);
        table[3][r] = std::max(table[3][r + 1], table[3][r]);
    }
    for (int l = 0; l <= n; l++)
    {
        long long tmp = table[0][l] + table[3][l + 1];
        if (tmp > max) max = tmp;
        tmp = table[1][l] + table[2][l + 1];
        if (tmp > max) max = tmp;
    }
    printf("%lld\n", max);

    delete[] x;
    delete[] v;
    for (int i = 0; i < 4; i++)
        delete[] table[i];

	return 0;
}

Measured memory_bytes: 4992
S = str(input())[::-1]
d1 = 'dream'[::-1]
d2 = 'dreamer'[::-1]
d3 =  'erase'[::-1]
d4 =  'eraser'[::-1]

result = True
i = 0
while i < len(S):
  if S[i:i+5] == d1:
    i += 5
  elif S[i:i+7] == d2:
    i += 7
  elif S[i:i+5] == d3:
    i += 5
  elif S[i:i+6] == d4:
    i += 6
  else:
    result = False
    break

if result:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3188
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 5*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, M = map(int, input().split())
ans = 0
for i in range(N+1):
    ans += cmb(N,i,mod)*((-1)**i)*g1[M]*g2[M-i]*((g1[M-i]*g2[M-N])**2)
    ans %= mod
print(ans)

Measured memory_bytes: 192148
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,p) scanf("%d %d %d %d",&n,&m,&o,&p)
#define SINT5(n,m,o,p,q) scanf("%d %d %d %d %d",&n,&m,&o,&p,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 0x2aaaaaaa; // 715,827,882
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second



int main() {
	int n;
	int c[3] = {};

	cin >> n;
	rep(i, n) {
		int a;
		cin >> a;

		if (a % 4 == 0)c[2]++;
		else if (a % 2 == 0) c[1]++;
		else c[0]++;
	}

	if (c[0]<= c[2]) {
		puts("Yes");
	} else if (c[1] == 0 && c[0] <= c[2] + 1) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}

/*

*/




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

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

    int ans;
    if (K & 1) {
        ans = K / 2 * ((K + 1)/ 2);
    } else {
        ans = K / 2 * K / 2;
    } 

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


Measured memory_bytes: 256
#include <iostream>
 using namespace std;
 
int main() {
  int a,b,c,i;
  
  cin >> a >> b >> c;
  
  for(i=0; a <= b;a++){
      if(c%a==0){
          i++;
      }
  }
  cout << i << endl;

  return 0;
}



Measured memory_bytes: 3088