akhauriyash/Code-Regression huggingface dataset:
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    int x = 0, flag = 1;
    char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}

inline long long readlong() {
	long long x = 0, flag = 1;
	char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong

const int maxn = 2e5 + 100;
const int maxS = 1e6 + 30;
int n;
string s[maxn], rev[maxn];
int go[maxS][30], cnt;
int Size[maxS][30], fa[maxS];
int pd[maxS], js[maxn];
inline void insert(string s, int i) {
	int pp = 0;
	for (int i = 1; i <= 26; i++) pd[i] = -1;
	for (int i = s.size(); i >= 0; i--) {
		if (pd[s[i] - 'a' + 1] == -1) {
			pd[s[i] - 'a' + 1] = i;
		}
	}
	vector<int> pos;
	for (int i = 0; i < s.size(); i++) {
		if (go[pp][s[i] - 'a' + 1] == 0) go[pp][s[i] - 'a' + 1] = ++cnt, fa[cnt] = pp;
		if (pd[s[i] - 'a' + 1] == i) Size[pp][s[i] - 'a' + 1] ++;
		pp = go[pp][s[i] - 'a' + 1];
	}
	js[i] = pp;
}
void dfs(int x) {
	for (int i = 1; i <= 26; i++) {
		if (go[x][i] == 0) continue;
		dfs(go[x][i]);
		for (int p = 1; p <= 26; p++) {
			Size[x][p] += Size[go[x][i]][p];
		}
	}
}
int main() {
	n = ri(); 
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		rev[i] = s[i];
		reverse(rev[i].begin(), rev[i].end());
		insert(rev[i], i);
	}
	dfs(0);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int tag = js[i];
		int faa = fa[tag];
		ans += Size[faa][s[i][0] - 'a' + 1] - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 298804
import java.util.Scanner;

public class Main {
  private static double r;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    r = stdIn.nextDouble();
    double Pi = Math.PI;
    System.out.printf("%.6f %.6f\n", (r * r * Pi), (2 * Pi * r));
  }
}

Measured memory_bytes: 28248
from collections import deque
N, M = map(int, input().split())
path = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1] += [b-1]
    path[b-1] += [a-1]

next_vec = [0]
visited = [1] + [0] * (N-1)
parent = [-1] + [0] * (N-1)
flag = 1


while next_vec:
    current_vec = next_vec[:]
    next_vec = []
    while current_vec:
        u = current_vec.pop()
        visited[u] = 1
        for v in path[u]:
            if visited[v] == 0:
                visited[v] = 1
                parent[v] = u
                next_vec.append(v)

ans_flag = 1
for i in visited:
    if i == 0:
        ans_flag = 0
if ans_flag:
    print('Yes')
    for i in range(1,N):
        print(parent[i]+1)
else:
    print('No')


Measured memory_bytes: 100372
def temparture(t, x):
    return t - x * 0.006


n = int(input())
t, a = list(map(int, input().split()))
h = [int(x) for x in input().split()]

dist_min = h[0]

for i in range(1, n):
    if abs(a - temparture(t, h[i])) < abs(a - temparture(t, dist_min)):
        dist_min = h[i]
print(h.index(dist_min) + 1)


Measured memory_bytes: 3060
//#define LOCAL

#include <cstdio>

#define M 100010
int A[M];

int partition(int p, int r) {
    int i = p-1, a = A[r], j, t;
    for(j=p; j<r; ++j) {
        if(A[j] <= a) {
            ++i;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    A[r] = A[i+1]; A[i+1] = a;
    return i+1;
}

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int i, n, q;
    scanf("%d", &n);
    for(i=0; i<n; ++i) scanf("%d", &A[i]);
    
    q = partition(0, n-1);
    for(i=0; i<n; ++i) {
        if(i) printf(" ");
        if(i == q) printf("[%d]", A[i]);
        else printf("%d", A[i]);
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pib = pair<int, bool>;
int main() {
    vector<vector<pib>> A(3,vector<pib>(3));
    for (int i=0;i<3;i++) for (int j=0;j<3;j++) {
        int a; cin >> a;
        A[i][j].first = a;
    }
    int N; cin >> N;
    for (int i=0;i<N;i++){
        int b; cin >> b;
        for (int j=0;j<3;j++){
            for (int k=0;k<3;k++){
                if (A[j][k].first == b) A[j][k].second = true;
            }
        }
    }
    string ans = "No";
    for (int i=0;i<3;i++){
        bool can = true;
        for (int j=0;j<3;j++){
            if (A[i][j].second==false) can = false;
        }
        if (can) ans = "Yes";
    }
    for (int i=0;i<3;i++){
        bool can = true;
        for (int j=0;j<3;j++){
            if (A[j][i].second==false) can = false;
        }
        if (can) ans = "Yes";
    }
    bool can = true;
    for (int i=0;i<3;i++){
        if (A[i][i].second==false) can = false;
    }
    if (can) ans = "Yes";
    can = true;
    for (int i=0;i<3;i++){
        if (A[i][2-i].second==false) can = false;
    }
    if (can) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, k; cin >> n >> k;

    if (n == 2) {
        if (k != 0) {
            cout << -1 << endl;
        } else {
            cout << 1 << endl << "1 2" << endl;
        }
        return 0;
    }
    
    ll cmp = (n - 1) * (n - 2) / 2;

    if (k > cmp) {
        cout << -1 << endl;
        return 0;
    }

    ll elme = cmp - k;
    ll m = n-1 + elme;
    cout << m << endl;
    REP(i, n-1) {
        cout << "1 " << i+2 << endl;
    }
    RANGE(i, 2, n) RANGE(j, i+1, n) {
        if (elme <= 0) break;
        elme--;
        cout << i << " " << j << endl;
    }
    
}

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

typedef long long ll;
const int maxn = 2e5 + 10;
int a[22];

int main(){
//    freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int res = 0;
    for(int i = 0; i < n; ++i){
        bool flag = true;
        for(int j = 0; j < i;++j){
            if(a[j] > a[i]){flag = false; break;}
        }
        if(flag)res++;
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(void) {
	long long int N; cin >> N;
	vector<long long int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	long long int fumidai = 0;
	long long int kizyun = A[0];
	for (int i = 0; i < N-1; i++) {
		if (kizyun > A[i + 1]) {
			fumidai += (kizyun - A[i + 1]);//同じ高さにする。基準に変動は無し
		}
		else if(kizyun < A[i + 1]) {
			kizyun = A[i + 1];//自分の方が高い。基準高さが変動
		}
	}
	cout << fumidai << endl;
}

Measured memory_bytes: 4740
import java.util.*;
public class Main {
	
	class Node {
		int cost;//秒数
		String state;//現在の状態
		Node(int cost, String state) {
			this.cost = cost;
			this.state = state;
		}
	}
	
	private int solve(String start) {
		int len = start.length();
		char[] work = new char[len];
		for(int r =0; r < work.length; r++) work[r] = 'r';
		String r_goal = new String(work);
		for(int r = 0; r < work.length; r++) work[r] = 'g';
		String g_goal = new String(work);
		for(int r = 0; r < work.length; r++) work[r] = 'b';
		String b_goal = new String(work);
		int color_sum = 'r' + 'g' + 'b';
		Queue<Node> open = new LinkedList<Node>();
		TreeSet<String> closed = new TreeSet<String>();
		open.add(new Node(0, start));
		closed.add(start);
		while(!open.isEmpty()) {
			Node temp = open.poll();
			int cost = temp.cost;
			String state = temp.state;
			if(state.equals(r_goal) || state.equals(g_goal) || state.equals(b_goal)) {
				return(cost);
			}
			for(int r = 1; r < len; r++) {
				if(state.charAt(r) != state.charAt(r - 1)) {
					char color = (char)(color_sum - state.charAt(r) - state.charAt(r - 1));
					StringBuilder nstate_b = new StringBuilder(state);
					nstate_b.setCharAt(r, color);
					nstate_b.setCharAt(r - 1, color);
					String nstate = new String(nstate_b);
					if(!closed.contains(nstate)) {
						open.add(new Node(cost + 1, new String(nstate)));
						closed.add(new String(nstate));
					}
				}
			}
		}
		return(-1);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		
		while(true) {
			String worm = stdIn.next();
			if(worm.equals("0")) break;
			int ans = new Main().solve(worm);
			System.out.println((ans != -1) ? ans:"NA");
		}
	}

}

Measured memory_bytes: 75676
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define	PI	3.14159265358979323846
#define	DEG2RAD(x)	((x) * PI / 180.)

void inputStr(char *str, size_t len) {
	fgets(str, len, stdin);
	if (str[(len = (strnlen(str, len) - 1))] == '\n') {
		str[len] = '\0';
	} else {
		fflush(stdin);
	}
}

void inputData(int &a, int &b) {
	char *str = new char[512], *tok;
	static const char period[] = ",";
	inputStr(str, 512);
	tok = strtok(str, period);
	if (tok != NULL) {
		a = atoi(tok);
		tok = strtok(NULL, period);
		if (tok == NULL) {
			inputStr(str, 512);
			tok = strtok(str, period);
		}
		b = atoi(tok);
	}
	delete [] str;
}

int main(void) {
	std::complex<double> r(0., 0.);
	int direction = 90;
	int distance, rotateRight;

	for (;;) {
		inputData(distance, rotateRight);
		if (distance == 0 && rotateRight == 0) { break; }
		r += std::polar<double>((double)distance, DEG2RAD((double)direction));
		direction -= rotateRight;
	}
	printf("%d\n%d\n", (int)r.real(), (int)r.imag());
	return 0;
}

Measured memory_bytes: 0
read n
p=(`dd`)
c=0
for i in `seq 1 $[n-2]`;do
 if [ ${p[i-1]} -gt ${p[i]} -a ${p[i]} -gt ${p[i+1]} -o ${p[i+1]} -gt ${p[i]} -a ${p[i]} -gt ${p[i-1]} ];then
  c=$[c+1]
 fi
done
echo $c

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

int main() {
 string n;
  cin >> n;
  if(n.at(0) == '7'){
  cout << "Yes" << endl;
  }
  else if(n.at(1) == '7'){
  cout << "Yes" << endl;
  }
  else if(n.at(2) == '7'){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int a[maxn],c[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]),c[i]=a[i];
    sort(a,a+n);
    sort(c,c+n);
    int newn=unique(c,c+n)-c;
    int l=0,r,ans=0;
    for(int i=0;i<newn;i++)
    {
        int r=lower_bound(a,a+n,c[i]+1)-a;
        if(r>=n) r=n-1;
        else r--;
        if((r-l+1)>c[i]) ans+=(r-l+1)-c[i];
        else if((r-l+1)<c[i]) ans+=(r-l+1);
        l=r+1;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;

const int mx=200010;
const ll mod=1e9+7;

int n, h[100010],hight;
ll ans = 0;

int main() {
  cin >> n >> h[0];
  hight = h[0];
  for(int i = 1; i<n; i++){ 
    cin >> h[i];
    if(h[i] >= hight){
      hight = max(h[i]-1, hight);
    } else {
      cout << "No" << endl; return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}  


Measured memory_bytes: 640
n = int(input())
c = list(input())
R_frag = 0
W_frag = 0
ans = 0
r = n - 1
l = 0
while l < r:
    if c[l] == "R":
        l += 1
    if c[r] == "W":
        r -= 1
    if c[l] == "W" and c[r] == "R":
        c[l] = "R"
        c[r] = "W"
        ans += 1
        l += 1
        r -= 1
print(ans)


Measured memory_bytes: 10592
X = int(input())
rank = -1
if X <= 599:
  rank = 8
elif X <= 799:
  rank = 7
elif X <= 999:
  rank = 6
elif X <= 1199:
  rank = 5
elif X <= 1399:
  rank = 4
elif X <= 1599:
  rank = 3
elif X <= 1799:
  rank = 2
else:
  rank = 1
print(rank)

Measured memory_bytes: 61884
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    ll n;
    cin >> n;
    ll arr[n];
    for (ll i=0;i<=n-1;i++)
    {
        cin >> arr[i];
    }

    vector<ll> left;
    vector<ll> right;
    for (ll i=0;i<=n-1;i++)
    {
        ll a=arr[i];
        left.push_back(i-a);
        right.push_back(i+a);
    }

    sort(left.begin(),left.end());
    sort(right.begin(),right.end());
    ll ans=0;
    for (auto it=left.begin();it!=left.end();it++)
    {
       ans=ans+upper_bound(right.begin(),right.end(),*it)-lower_bound(right.begin(),right.end(),*it);
    }

    cout << ans << endl;
}

Measured memory_bytes: 8236
N,K= list(map(int, input().split()))
A =list(map(int, input().split()))

count_self = 0
for i in range(N):
    for j_ in range(1,N-i):
        j = i+j_
        if A[i] > A[j]: 
            count_self = count_self + 1

count_ = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]: 
            count_ = count_ + 1

m = (K-1)*K//2
val = count_ * m + count_self * K
            
print(divmod(val, 10**9+7)[1])



Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>

#define int long long

using namespace std;

signed main()
{
	int l, r;

	cin >> l >> r;

	int ans = 2019;
	for(int i = l; i < min(l + 2019, r + 1); ++i)
	{
		for(int j = i + 1; j < min(l + 2019, r + 1); ++j)
		{
			ans = min(ans, (i * j) % 2019);
		}
	}

	cout << ans << endl;
}

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



int main(void){
  int N, M;
  cin >> N >> M;
   char a[50][50], b[50][50];
  
  for (int i = 0; i< N; i++) {
    cin >> a[i];
  }
  
  for (int j =0; j<M; j++){
    cin>> b[j];
  }
  
  
  for (int i = 0; i<= N - M+1; i++){
    for (int j = 0; j<= N-M+1; j++){
		int count = 0;
     	for (int k = 0; k < M; k++){
              for (int l =0; l<M; l++){
                if (a[i+k][j+l] == b[k][l]) count+= 1; 
              }
        }

      if (count == M*M) {cout << "Yes" << endl; return 0;}
    }
  }
  cout << "No" << endl; 
  
}

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

int main(){
    int W, H, x, y, r, p, q;
    cin >> W >> H >> x >> y >> r;
    
    if( x - r >= 0 && W >= x + r) p = 1;
    else p = 0;
    if( y - r >= 0 && H >= y + r) q = 1;
    else q = 0;
    if( p == 1 && q ==1) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    ll k; cin >> k;
    ll a[n];
    ll sum[n] = {};
    map<ll, ll> mp;
    rep(i,n){
        cin >> a[i];
        a[i]--;
        a[i] %= k;
        sum[i] = a[i];
        if(i > 0)sum[i] += sum[i-1];
        sum[i] %= k;
        if(i < k - 1){
            ll tmp = mp[sum[i]];
            tmp++;
            mp[sum[i]] = tmp;
        }
    }

    ll ans = 0;

    ll now = 0;
    rep(i,n){
        ll tmp = k - now;
        tmp %= k;
        ans += mp[tmp];
        // cout << i << ' ' << tmp << ' ' << mp[tmp] << endl;
        now += k - a[i];
        now %= k;
        ll tmp2 = mp[sum[i]];
        tmp2--;
        mp[sum[i]] = tmp2;
        if(i + k - 1 < n){
            ll tmp = mp[sum[i+k-1]];
            tmp++;
            mp[sum[i+k-1]] = tmp;
        }
    }

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


Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

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

    map<int, bool> m;

    int n;
    cin >> n;

    int r = 0;
    for (int i = 0; i < n; ++i) {
        int d;
        cin >> d;

        if (m.count(d) == 0) {
            m[d] = true;
            ++r;
        }
    }

    out(r);

    int ttttttt;
    cin >> ttttttt;
}

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

int main(void){
  int N, K;
  cin >> N >> K;
  vector<int> h(N), diff(N - K + 1);
  for(int i = 0; i < N; i++){
    int h_;
    cin >> h_;
    h[i] = h_;
  }
  sort(h.begin(), h.end());
  for(int i = 0; i < N - K + 1; i++){
    diff[i] = h[i + K - 1] - h[i];
    //cout << diff[i] << " ";
  }
  //cout << endl;
  sort(diff.begin(), diff.end());
  cout << diff[0];
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define pb push_back
#define pc __builtin_popcount
#define pcll __builtin_popcountll
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
using namespace std;
ss s, t;
int main() {
  speed;
  oprecision;
  // code
  cin >> s;
  cout << (s == "ABC" ? "ARC" : "ABC");
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 3636
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3 1000
120
100
140"# => r#"9"#,

r#"4 360
90
90
90
90"# => r#"4"#,

r#"5 3000
150
130
150
130
110"# => r#"26"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize, x: usize,
        m: [usize; n],
    }
    let total = m.iter().sum::<usize>();
    let min = m.iter().min().unwrap();
    ((x - total) / min + n).to_string()
}

Measured memory_bytes: 4352
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Shortest Path on a Line
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
ll ds[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) {
    int l, r, c;
    scanf("%d%d%d", &l, &r, &c);
    l--, r--;
    nbrs[l].push_back(pii(r, c));
  }
  for (int i = 1; i < n; i++) nbrs[i].push_back(pii(i - 1, 0));

  fill(ds, ds + n, LINF);
  ds[0] = 0;
  
  priority_queue<pli> q;
  q.push(pli(0, 0));

  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll ud = -u.first;
    int &ui = u.second;
    if (ds[ui] != ud) continue;

    if (ui == n - 1) break;

    vpii &nbru = nbrs[ui];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vd = ud + vit->second;
      if (ds[vi] > vd) {
	ds[vi] = vd;
	q.push(pli(-vd, vi));
      }
    }
  }

  ll &gd = ds[n - 1];
  printf("%lld\n", (gd >= LINF) ? -1LL : gd);
  return 0;
}


Measured memory_bytes: 8056
s = input()

def kaibun(s):
    if s == s[::-1]:
        return 1
    else:
        return 0
        
q = len(s)
d = int((q-1)/2)
ket = s[0:d]
mat = s[int((q+1)/2):q]

if (kaibun(s) + kaibun(ket) + kaibun(mat)) == 3:
    print('Yes')
else:
    print('No')


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

int main(){
    int n;
    cin >> n;
    vector<int> array(n,0);
    for(int i=0;i<n-1;i++){
        int num;
        cin >> num;
        array.at(num-1)++;
    }

    for(int i=0;i<n;i++) cout << array.at(i) << endl; 
}

Measured memory_bytes: 3980
# 写経AC
N = int(input())
T = [int(i) for i in input().split()]
V = [int(i) for i in input().split()]

Ts = sum(T)

# Vmax[t]: t秒での最大速度 (0.5秒間隔)
Vmax = [float("inf")] * (Ts * 2 + 1)

ts = 0
for i in range(N):
    for t in range(T[i]):
        t1 = (ts + t) * 2
        t2 = (ts + t) * 2 + 1
        Vmax[t1] = min(Vmax[t1], V[i])
        Vmax[t2] = min(Vmax[t2], V[i])

    # 時間の区切りの部分は閉区間が重なっている
    Vmax[(ts + T[i]) * 2] = min(Vmax[(ts + T[i]) * 2], V[i])

    ts += T[i]

# 0秒とT秒
Vmax[0] = Vmax[Ts * 2] = 0
# 左から右に
for t in range(Ts * 2):
    Vmax[t + 1] = min(Vmax[t + 1], Vmax[t] + 0.5)
# 右から左に
for t in range(Ts * 2 - 1, 0, -1):
    Vmax[t] = min(Vmax[t], Vmax[t + 1] + 0.5)

ans = 0.0
for i in range(Ts * 2):
    # 台形の公式
    ans += (Vmax[i] + Vmax[i + 1]) * 0.5 / 2

print(ans)

Measured memory_bytes: 3444
def show(A):
    N = len(A)
    for i in range(N):
        if i :
            print(' ', end = '')
        print(A[i], end = '')
    print()

def selectionSort(A, N):
    exchange = 0
    for i in range(N):
        min_j = i
        for j in range(i, N):
            if A[j] < A[min_j]:
                min_j = j
        if min_j != i:
            A[i], A[min_j] = A[min_j], A[i]
            exchange += 1
    show(A)
    print(exchange)

N = int(input())
A = [int(i) for i in input().split()]

selectionSort(A, N)


Measured memory_bytes: 5624
import sys
input=sys.stdin.readline
from collections import deque

def main():
    N,Q = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(N-1)]
    Y = [list(map(int,input().split())) for _ in range(Q)]

    con = [[] for _ in range(N)]
    for i in range(N-1):
        con[X[i][0]-1]+=[X[i][1]-1]
        con[X[i][1]-1]+=[X[i][0]-1]

    dif = [0]*N
    for i in range(Q):
        dif[Y[i][0]-1] += Y[i][1]

    root = deque([0])
    go = [True for _ in range(N)]
    go[0] = False
    while root:
        cur = root.pop()
        for fol in con[cur]:
            if go[fol]:
                dif[fol] += dif[cur]
                go[fol] = False
                root.append(fol)

    print(*dif)

if __name__ == "__main__":
    main()


Measured memory_bytes: 143784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll K; cin >> K;
  cout << 50 << endl;
  ll a[50];
  fill(a,a+50,49+K/50);
  for (ll i = 0; i < K%50; i++) {
    for (ll j = 0; j < 50; j++) {
      if (j == i) {a[j]+=50;}
      else {a[j]--;}
    }
  }
  for (ll i = 0; i < 50; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 256
s = str(input())

ans = ''
for i in range(len(s)):
    if s[i] == '1':
        ans = ans + '1'
    elif s[i] == '0':
        ans = ans + '0'
    elif s[i] == 'B':
        if len(ans) >= 2:
            ans = ans[:-1]
        else:
            ans = ''

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();
int main() {
    ll N;

    cin >> N;
    vector<ll> values(N);
    REP(i, N) {
        cin >> values[i];
    }

    ll sum = values[N - 1];
    ll ans = 0;

    for (ll i = N - 2; i >= 0; --i) {
        ans += values[i] * sum % MOD;
        ans %= MOD;
        sum += values[i];
        sum %= MOD;
    }

    PR(ans);

    return 0;
}

Measured memory_bytes: 4836
n,d=map(int,input().split())
data = []
ans = 0
for i in range(n):
    lista=[int(l) for l in input().split()]
    data.append(lista)
    for j in range(i):
        dist = 0
        for _ in range(d):
            dist += (data[i][_]-data[j][_])**2
        dist = dist**(1/2)
        if dist == int(dist):
            ans+=1
print(ans)

Measured memory_bytes: 38384
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using std::min; using std::max;
using std::swap; using std::sort;
using std::set;
typedef long long ll;
typedef std::pair<int, int> pii;

template<typename T>
void read(T &x) {
	int flag = 1; x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= flag;
}

const int _ = 2e5 + 10, P = 1e9 + 7;
int h, w, a, b, fac[_], ifac[_], now[_];

int qpow(int a, int b) {
	int r = 1;
	for(; b; b >>= 1, a = 1ll * a * a % P)
		if(b & 1) r = 1ll * r * a % P;
	return r;
}

int C(int n, int m) {
	if(m > n) return 0;
	return (int)(1ll * fac[n] * ifac[m] % P * ifac[n - m] % P);
}

int main () {
	read(h), read(w), fac[0] = 1;
	int mx = h + w;
	for(int i = 1; i <= mx; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
	ifac[mx] = qpow(fac[mx], P - 2);
	for(int i = mx; i >= 1; --i) ifac[i - 1] = 1ll * ifac[i] * i % P;
	read(a), read(b);
	for(int y = b + 1; y <= w; ++y) {
		int x = h - a;
		now[y] = C(x - 1 + y - 1, x - 1);
	}
	ll ret = 0;
	for(int y = b + 1; y <= w; ++y)
		(ret += 1ll * now[y] * C(w - y + a - 1, a - 1) % P) %= P;
	printf("%lld\n", ret);
	return 0;
} 


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n) cin>>a[i];
    repi(i,1,n){
        if(a[i-1]>a[i]){
            sum+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<sum;
}

Measured memory_bytes: 4840
N = int(input())
ans = 1
divine = [1 for _ in range(N+1)]

for i in range(1, N+1):
    for j in range(2, i+1):
        while i%j== 0:
            i //= j
            divine[j] += 1

for k in divine:
    ans *= k

print(ans%1000000007)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

template<typename T>
T lcm(T a, T b){
  return a * b / gcd(a, b);
}
int main(){
    ull A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}


Measured memory_bytes: 3600
N = int(input())
A = list(map(int, input().split()))
B = set(A)

MAX = 10 ** 6

fdp = [False for _ in range(MAX+1)]
tdp = [True for _ in range(MAX+1)]

for i in A:
    if tdp[i]:
        fdp[i] = True
        tdp[i] = False
    else:
        fdp[i] = False

for i in range(1, MAX+1):
    if not tdp[i]:
        for j in range(i*2, MAX+1, i):
            fdp[j] = False

ans = 0
for i in B:
    if fdp[i]:
        ans += 1
print(ans)

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

using namespace std;
using ll = long long;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if (ll(4 * a * b) < d * d && d > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int n;
    cin >> n;
    vector<int> vec;
    for(int i=0;i<n-1; i++){
        int a;
        cin >> a;
        vec.push_back(a);
    }
    int ans =0;
    vec[n-1] = INT32_MAX;
    for(int i=n-1; i>0; i--){
        ans += min(vec[i],vec[i-1]);
    }
    cout << ans+vec[0] <<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

bool isPrime(int n)
{
    if (n < 2)
        return false;
    for (int i = 2;i <= n / i; i++)
        if (n % i == 0)
            return false;
    return true;
};
int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    while (!isPrime(N))
        N++;
    cout << N << endl;
    return 0;
};

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		int sum = 0;
		for(int i = 0; i < 9; ++i)
		{
			int a;
			cin >> a;
			sum += a;
		}
		cout << n - sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    vector<double> v(N); REP(i,N) cin >> v[i];
    SORT(v);
    double ans = v[0];
    REP(i,N-1) ans = (ans+v[i+1]) /2;
    cout << fixed << setprecision(10) << ans << en;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string S;
	cin >> S;
	int l = S.size();
	for (int i = 0; i < l; i++) {
		if (S[i] == ',') {
			S[i] = ' ';
		}
	}
	cout << S << endl;
}

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

char m[100][100];

int main()
{
	int h, w;
	while (cin >> h >> w, h+w)
	{
		for (int y = 0; y < h; y++)
		{
			for (int x = 0; x < w; x++)
			{
				cin >> m[x][y];
			}
		}
		int x = 0;
		int y = 0;
		for (int i = 0; i <= w * h; i++)
		{
			if (m[x][y] == '.')
			{
				cout << x << ' ' << y << endl;
				break;
			}
			else if (m[x][y] == '>') x++;
			else if (m[x][y] == '<') x--;
			else if (m[x][y] == 'v') y++;
			else if (m[x][y] == '^') y--;
			if (i == w * h) cout << "LOOP" << endl;
		}
	}

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    
    int x=1;
    int n=1;
    while(n < N){
        x++;
        n = floor(x * 1.08);
    }
    if (n == N){
        cout << x << endl;
    } else{
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int r,g;
	cin >> r >> g;
	cout << 2 * g - r << endl;
}

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

ans = []
for k in sorted(Ac.keys())[::-1]:
  if len(ans) == 2:
    break
  if Ac[k] >=4:
    if ans:
      ans.append(k)
    else:
      ans.append(k)
      ans.append(k)
  elif Ac[k] >= 2:
    ans.append(k)
if len(ans) == 2:
  print(ans[0]*ans[1])
else:
  print(0)

Measured memory_bytes: 18600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();

		int count = 0;
		for (int i = 0; i <= A; i++) {
			for (int j = 0; j <= B; j++) {
				for (int k = 0; k <= C; k++) {
					if (X == (500*i+100*j+50*k))
					{
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 23508
import scala.io.StdIn.{readInt, readLine}

object Main extends App {

  val n = readInt()
  val arr = readLine().split(" ").map(_.toInt)

  for (i <- 1 to n -1) {
    println(arr.mkString(" "))
    val key = arr(i)
    var j = i - 1
    while (j >= 0 && key < arr(j)) {
      arr(j + 1) = arr(j)
      j -= 1
    }
    arr(j + 1) = key
  }

  println(arr.mkString(" "))
}



Measured memory_bytes: 45348
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    void solve(Scanner sc, PrintWriter pw) {
        int N = sc.nextInt();
        List<Integer> data = new ArrayList<>(N);
        for (int i = 0; i < N; i++) {
            data.add(sc.nextInt());
        }
        data.sort(Collections.reverseOrder());
        long result = 0;
        for (int i = 1; i < N; i++) {
            result += data.get(i / 2);
        }
        pw.println(result);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 64152
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scn = new Scanner(System.in);
        int X = scn.nextInt();
        
        int ans = 0;
        ans += (X/500)*1000;
        X %= 500;
        ans += (X/5)*5;
        System.out.println(ans);
    }
}


Measured memory_bytes: 35684
#include <stdio.h>

void swap(int *x, int *y);

int main()
{
  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  if (a > b) swap(&a,&b);
  if (b > c) swap(&b,&c);
  if (a > b) swap(&a,&b);
  printf("%d %d %d\n", a , b, c);
  return 0;
}
  
void swap(int *x,int *y)
{
  int tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

    
  

Measured memory_bytes: 596
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
int last_safe[100001];
using namespace std;
int main(void){
  int N;
  int M;
  cin >> N >> M;
  string S;
  cin >> S;

  int cur_last_safe = S.size();
  for(int i = S.size() - 1; i >= 0; i--){
    if(S[i] == '1'){
      last_safe[i] = cur_last_safe;
    } else {
      cur_last_safe = i;
      last_safe[i] = i;
    }
  }

  vector <int> ans;
  int prev_pos = S.size() - 1;
  int cur_pos = S.size() - 1;
  while(true){
    cur_pos = max(0, prev_pos - M);
    cur_pos = last_safe[cur_pos];
    if(cur_pos >= prev_pos){
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(prev_pos - cur_pos);
    if(cur_pos == 0){
      break;
    }
    prev_pos = cur_pos;
  }
  reverse(ans.begin(), ans.end());
  for(int i = 0; i < ans.size(); i++){
    if(i == (ans.size() - 1)){
      cout << ans[i] << endl;
    } else {
      cout << ans[i] << " ";
    }
  }
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (n % 2 == 1) {
    cout << b[(n - 1) / 2] - a[(n - 1) / 2] + 1 << endl;
  } else {
    cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << endl;
  }
  return 0;
}

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

int main() {
  int H, N;
  cin >> H >> N;
  int s = 0;
  rep(i, N) {
    int a;
    cin >> a;
    s += a;
  }

  if (s >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var hi = new long[N];
            for (var i = 0; i < N; ++i)
                hi[i] = Sarray()[0];
            Array.Sort(hi);
            var ans = Mod;
            for (var i = 0; i + K - 1 < N; ++i)
                ans = Min(ans, hi[i + K - 1] - hi[i]);
            WriteLine(ans);

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 18244
#include <iostream>

int main() {

	int n;
	std::cin >> n;

	int maxBenefit = -999999999;

	int minPrice;
	std::cin >> minPrice;

	for (int i = 1; i < n; ++i) {
		int price;
		std::cin >> price;

		if (price - minPrice > maxBenefit) {
			maxBenefit = price - minPrice;
		}

		if (price < minPrice) {
			minPrice = price;
		}
	}
	std::cout << maxBenefit << std::endl;

	return 0;
}

Measured memory_bytes: 3088
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    ab = [LI() for _ in range(m)]
    e = collections.defaultdict(set)
    for a,b in ab:
        e[a].add(b)
        e[b].add(a)

    v = set()
    v.add(1)
    r = [0] * (n+1)
    q = [1]
    qi = 0
    while len(q) > qi:
        t = q[qi]
        qi += 1
        for u in e[t]:
            if u not in v:
                v.add(u)
                r[u] = t
                q.append(u)

    return JA(["Yes"] + r[2:], "\n")

print(main())





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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  vector<int> b(n);
  rep(i,n) b.at(i) = a.at(i);
  sort(b.begin(), b.end());
  int maxi = b.at(n-1);
  int semimaxi = b.at(n-2);
  rep(i,n) {
    if(a.at(i) == maxi) cout << semimaxi << endl;
    else cout << maxi << endl;
  }
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int black(ll x, ll y, set<pair<ll,ll>> &q){
  int cnt=0;
  rep(i,3){
    rep(j,3){
      auto z=mp(x+i,y+j);
      if(q.count(z)) cnt++;
    }
  }
  return cnt;
}


int main(){
  ll h,w,n;
  cin>>h>>w>>n;

  vector<ll> p(10);
  p[0]=(h-2)*(w-2);

  set<pair<ll,ll>> q;
  rep(i,n){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    auto z=mp(a,b);
    
    if(a-2>=0&&b-2>=0) {
      int c=black(a-2,b-2,q);
      p[c]--;p[c+1]++;
    }
    if(a-1>=0&&a+1<h&&b-2>=0) {
      int c=black(a-1,b-2,q);
      p[c]--;p[c+1]++;
    }
    if(a+2<h&&b-2>=0) {
      int c=black(a,b-2,q);
      p[c]--;p[c+1]++;
    }

    if(a-2>=0&&b-1>=0&&b+1<w) {
      int c=black(a-2,b-1,q);
      p[c]--;p[c+1]++;
    }
    if(a-1>=0&&a+1<h&&b-1>=0&&b+1<w) {
      int c=black(a-1,b-1,q);
      p[c]--;p[c+1]++;
    }
    if(a+2<h&&b-1>=0&&b+1<w) {
      int c=black(a,b-1,q);
      p[c]--;p[c+1]++;
    }

    if(a-2>=0&&b+2<w) {
      int c=black(a-2,b,q);
      p[c]--;p[c+1]++;
    }
    if(a-1>=0&&a+1<h&&b+2<w) {
      int c=black(a-1,b,q);
      p[c]--;p[c+1]++;
    }
    if(a+2<h&&b+2<w) {
      int c=black(a,b,q);
      p[c]--;p[c+1]++;
    }

    q.insert(z);
  }

  rep(i,10){
    cout << p[i] << endl;
  }

}

Measured memory_bytes: 9888
a = ['SUN','MON','TUE','WED','THU','FRI','SAT'].cycle
s = gets.chomp
count = 0
s1 = ''
while s1 != s
    s1 = a.next
end
if s1 == 'SUN'
  s1 = a.next
  count += 1
end
while s1 != 'SUN'
  s1 = a.next
  count += 1
end

puts count

Measured memory_bytes: 1788