akhauriyash/Code-Regression huggingface dataset:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
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 _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

def main(N):
    """
    10*5みる
    """
    ans = 0
    for i in range(0, N):
        num = N - i
        #  print(num)
        if len(str(num)) % 2 == 1:
            ans += 1
    return ans


if __name__ == '__main__':
    if 'LOCAL' in os.environ:
        # ローカル実行時のみ通る処理
        # テストしたい入力を入れておく
        input_values = [
                """
                """.strip(),
                """
                """.strip()
                ]
        for input_value in input_values:
            input_value = input_value.split('\n')
            #  N = int(input_value[0])
            #  A = list(map(int, input_value[1].split()))
            ans = main(N, A)
            expected_value = int(input_value[2])
            assert ans == expected_value, 'failed: ans: {ans}, exp: {exp}'.format(ans=ans, exp=expected_value)
    else:
        N = _I()

        print(main(N))



Measured memory_bytes: 65644
from collections import deque

N,M = map(int,input().split())

graph = [[] for i in range(N)]

for i in range(M):
    L,R,D = map(int,input().split())
    graph[L-1].append([R-1,D])
    graph[R-1].append([L-1,-D])

x = [None for i in range(N)]

def f():
    for i in range(N):
        if x[i] == None:
            x[i] = 0
            q = deque([i])
            while len(q):
                j = q.popleft()
                for k,d in graph[j]:
                    if x[k] == None:
                        q.append(k)
                        x[k] = x[j]+d
                    elif x[k] != x[j]+d:
                        return False
                        
    return True

if f():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 78784
W,H,X,Y = map(int,input().split())
xwari = min(X*H,(W-X)*H)
ywari = min(Y*W,(H-Y)*W)
if W == X*2 and H == Y*2:
    f = 1
else:
    f = 0
print(W*H/2, f)

Measured memory_bytes: 61912
s = ["1","1","1","2","1", "2", "1", "5", "2", "2", "1", "5", "1", "2", "1", "14", "1", "5", "1", "5", "2", "2", "1", "15", "2", "2", "5", "4", "1", "4", "1", "51"]

print(s[int(input()) - 1])

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

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

    long long  a = x / 500;
    long long  y = x % 500;
    long long  b = y / 5;

    long long  s = 1000*a + 5*b;
    cout << s << endl;

}

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

int main() {
  string s;
  cin>>s;
  if(s=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  else if(s=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  else{
    cout<<"Sunny"<<endl;
  }
}

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

int main()
{
    long A,B;
    std::cin >> A >> B;
    long d = (A-2*B>0)? A-2*B:0;
    std::cout << d << std::endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n, k = list(map(int, input().split()))
    S = list(input())
    count = 0
    h = 0
    for i in range(n - 1):
        if S[i] != S[i + 1]:
            count += 1
    b = max(0, count + 1 - 2 * k)
    print(min(n - 1, n - b))

if __name__ == '__main__':
    main()


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

using namespace std;

#define N 100100

int main() {
	
	vector<int> furui(N, 0);

	furui[0] = furui[1] = 1;
	for (long long int i = 2; i*i < N; i++) {
		if (furui[i] == 0) {
			for (long long int j = 2; i*j < N; j++) {
				furui[i*j] = 1;
			}
		}
	}

	vector<long long int> ff(N, 0);

	for (long long int i = 3; i < N; i++) {
		ff[i] = ff[i - 1];
		if (furui[i] == 0 && furui[(i + 1) / 2] == 0) {
			ff[i]++;
		}
	}

	long long int n;
	cin >> n;
	long long int l, r;
	for (long long int i = 0; i < n; i++) {
		cin >> l >> r;
		cout << ff[r] - ff[l - 1] << endl;
	}


	return 0;
}

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

public class Main{
    public static void main(String args[]) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	String s[]=br.readLine().split(" ");

        int n=Integer.parseInt(s[0]);
	int k=Integer.parseInt(s[1]);

	int bou[]=new int[n];

	int sum=0;

	s=br.readLine().split(" ");
	
	for(int i=0;i<n;i++){
	    bou[i]=Integer.parseInt(s[i]);
	}

	
	
	for(int i=0;i<k;i++){
	    int max=0;
	    int maxID=0;
	    for(int j=0;j<n;j++){
		if(max<bou[j]){
		    max=bou[j];
		    maxID=j;
		}
	    }
	    sum+=max;
	    bou[maxID]=0;
	}
	System.out.println(sum);
    }
}


Measured memory_bytes: 21204
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc143/tasks/abc143_c>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    string S; cin >> S;
    
    S.erase(unique(S.begin(),S.end()),S.end());
    res = S.size();
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 512
N = int(input())
LR = [None] * N
for i in range(N):
    center, length = [int(i) for i in input().split()]
    LR[i] = (center + length, center - length)  # right, left
LR.sort()
now = LR[0][0]
ans = 1
for i in range(1, N):
    right, left = LR[i]
    if now > left:
        continue
    else:
        ans += 1
        now = right
print(ans)


Measured memory_bytes: 50136
#include<iostream>
#include<queue>
#include<map>
using namespace std;

const int INF = 111111111;
typedef pair<int,int> P;

int b[2][150];
int n;
int d[2][150];
int v[3] = {0, 1, 2};

int bfs(){
  queue<P> que;
  for(int i = 0;i < 2; i++)
    for(int j = 0;j < 150; j ++) d[i][j] = INF;

  if(b[0][0] == 1){
    int i;
    for(i = 0;b[0][i] == 1 && i < n; i++) ;
    que.push(P(0,i-1));
    d[0][i-1] = 0;
  }
  else{
    que.push(P(0,0));
    d[0][0] = 0;
  }
  if(b[1][0] == 1){
    int i;
    for(i = 0;b[1][i] == 1 && i < n; i++) ;
    que.push(P(1,i-1));
    d[1][i-1] = 0;
  }
  else{
    que.push(P(1,0));
    d[1][0] = 0;
  }

  while(que.size()){
    P p = que.front(); que.pop();
    if(p.second >= n-1 && b[p.first][p.second] != 2) return d[p.first][p.second];

    for(int i = 0;i < 3; i++){
      int nx = (p.first + 1) % 2, ny = p.second + v[i];

      if(b[nx][ny] == 2){
	int i;
	for(i = ny;b[nx][i] == 2 && i >= 0; i--) ;
	ny = i;
      }
      else if(b[nx][ny] == 1){
	int i;
	for(i = ny;b[nx][i] == 1 && i < n; i++) ;
	ny = i - 1;
      }
      if(ny < n && d[nx][ny] == INF){
	que.push(P(nx,ny));
	d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return -1;
}

int main(void){
  for( ; ; ){
    cin >> n;
    if(!n) break;
    for(int i = 0;i < n; i++) cin >> b[0][i];
    for(int i = 0;i < n; i++) cin >> b[1][i];

    int res = bfs();

    if(res == -1) cout << "NA" << endl;
    else cout << res << endl;
  }
}


Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
const int M = 1e9+7;
using ll = long long;

int mul(int x,int y){
    return (ll)x*y%M;
}

int p(int x, int y){
    int res = 1;
    while(y){
        if(y%2) res = mul(res,x);
        x = mul(x,x);
        y/=2;
    }
    return res%M;
}

int inv(int x){
    return p(x,M-2)%M;
}


int main(){
    int n;cin>>n;
    vector<int> arr;
    map<int,int> div;
    while(n--){
        int t;cin>>t;
        arr.push_back(t);
        map<int,int> cnt;
        for(int i = 2; i*i<=t; i++){
            while(t%i==0){
                cnt[i]++;
                t/=i;
            }
        }
        if(t!=1) cnt[t]++;
        for(auto p : cnt){
            div[p.first] = max(div[p.first],p.second);
        }
    }
    int lcm = 1;
    for(auto p: div){
        int prime = p.first;
       int k = p.second;
       for(int i = 0; i < k; i++) lcm = mul(lcm,prime);
    }

    int res = 0;
    for(int i = 0; i < (int)arr.size(); i++){
        res = (res+mul(lcm,inv(arr[i])))%M;
    }
    cout<<res;
    
}


Measured memory_bytes: 768
#if __has_include("noamoa_atcoder_lib.h")
#include "noamoa_atcoder_lib.h"
#else
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) (x).begin(),(x).end()
namespace atcoder {
	using namespace std;
	using ll = long long;
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	constexpr ll MOD  = 1000000007;
	constexpr ll MOD9 = 1000000009;

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T& e){
		v.push_back(e);
		return v;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	void init(){
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}
using namespace atcoder;
#endif

int main(){
	init();
	intv v(3);cin>>v;cout<<v[2]<<" "<<v[0]<<" "<<v[1];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<ll,int>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
#define M 1000000
pii mx1[M],mx2[M],mx3[M];
ll dp[M],a[M];
int n,tmp;
void add(int id,pii x){
	if (x==mx1[id]||x==mx2[id])return ;
	if (x>mx1[id]){
		mx3[id]=mx2[id];
		mx2[id]=mx1[id];
		mx1[id]=x;		
	}
	else if (x>mx2[id]){
		mx3[id]=mx2[id];
		mx2[id]=x;
	}
	else if (x>mx3[id]){
		mx3[id]=x;
	}
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	read(n);
	tmp=(1<<n);
	int i,k;
	for (i=0;i<tmp;i++){
		read(a[i]);
		mx1[i]=mp(a[i],i);
		mx2[i]=mp(-1e9,-1);
		mx3[i]=mp(-1e9,-1);
	}
	tmp--;
	for (i=0;i<=tmp;i++){
		dp[i]=dp[i-1];
		for (k=0;k<n;k++)if (!((i>>k)&1)){
			add(i|(1<<k),mx1[i]);
			add(i|(1<<k),mx2[i]);
			add(i|(1<<k),mx3[i]);
		}
		Max(dp[i],mx1[i].A+mx2[i].A);
	}
	for (i=1;i<=tmp;i++){
		printf("%lld\n",dp[i]);
	}
	return 0;
}

Measured memory_bytes: 29696
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
#include <set>
#include <ctime>
#include <queue>
#include <stack>

#define ll long long


using namespace std;

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    
    int n;
    cin >> n;
    
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    
    ll ret = 0;
    
    for (int i = 0; i < n; i++)
    {
        ll canA = distance(a.begin(),lower_bound(a.begin(), a.end(), b[i]));
        ll canC = distance(upper_bound(c.begin(), c.end(), b[i]), c.end());
        
        ret += canA*canC;
        
    }
    
    cout << ret << endl;
    
    return 0;
    
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);

  int n;
  double t, a;
  cin >> n >> t >> a;
  int ans = 0;
  double absa = 10e5;
  for (int i = 0; i < n; ++i) {
    double x;
    cin >> x;
    double h = abs(a - (t - (x * 0.006)));
    cerr << h << '\n';
    if (absa > h) {
      absa = h;
      ans = i + 1;
    }
  }

  cout << ans << '\n';

  return 0;
}


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

using namespace std;
int main()
{
    long long int n,k,i,cnt=0,p,r=0,s=0,b=1,radix;
    cin>>n>>radix;
    r=0,s=0,b=1;
    while(n)
    {
        r=n%radix;
        n=n/radix;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;

}


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

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if(b-a == c-b) cout << "YES" << "\n";
	else cout << "NO" << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200010],st[200010];
long long num[200010];
int main()
{
	int n,top=0;long long sum=0;scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		char ch='+';if (i!=1) scanf(" %c",&ch);
		scanf("%d",&a[i]);
		sum+=a[i];
		if (ch=='-') st[++top]=a[i];else num[top]+=a[i];
	}
	long long ans=(top)?(-1e18):sum;
	for (int i=1;i<=top;i++)
	{
		ans=max(ans,sum-2*(st[i]+num[i]));
		sum-=2*st[i];
	}
	printf("%lld\n",ans);
}

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


int main(){
	
	while(1){
		
		int n,x,ans = 0;
		cin >> n >> x;
		
		if(n == 0 && x == 0)	break;
		for(int i = 1;i <= n-2;i++){
			for(int j = i+1;j <= n-1;j++){
				int A = x - (i + j);
				if(A > n || A <= j)	continue;
				else{
					ans++;
				}
			}
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 2996
A, B, C, D = [int(c) for c in input()]

expressions = [
    "{}+{}+{}+{}",
    "{}+{}+{}-{}",
    "{}+{}-{}+{}",
    "{}-{}+{}+{}",
    "{}-{}-{}+{}",
    "{}-{}+{}-{}",
    "{}+{}-{}-{}",
    "{}-{}-{}-{}",
]

for exp in expressions:
    exp = exp.format(A, B, C, D)
    if eval(exp) == 7:
        print(exp + "=7")
        break


Measured memory_bytes: 38384
#include<iostream>
using namespace std;
int n,ans;
int main(){
  while(1){
    cin>>n;
    if(n==-1)break;
    ans=1150;
    if(n>=10)ans+=min(10,n-10)*125;
    if(n>=20)ans+=min(10,n-20)*140;
    if(n>=30)ans+=(n-30)*160;
    cout<<4280-ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
n = int(input())
alist = [int(input())-1 for _ in range(n)]

now = 0
count = 0
while True:
    if now == 1:
        print(count)
        break
    elif count >= n:
        print(-1)
        break
    else:
        count += 1
        now = alist[now]

Measured memory_bytes: 49240
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#define f first
#define s second
#define fore(i,a,b) for(lli i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
#define deb(x) cout << #x": " << (x) << endl;

int main(){ _
    lli n,x,t;
    cin >> n >> x >> t;
    if(n%x!=0)n=n+(x-n%x);
    lli time=(n/x)*t;
    cout << time <<ENDL;
    return 0;
}


Measured memory_bytes: 3624
#![allow(unused_mut, non_snake_case,unused_imports)]
use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::{swap};
use std::collections::{HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap,VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//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)*}};}
//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<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

// 非常時
fn read_line() -> String{ let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); s.trim().to_string() }

/*
 <url:https://beta.atcoder.jp/contests/abc112/tasks/abc112_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
fn main(){
    fn read_line() -> String{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }
    let n : i32 = read_line().parse().unwrap();
    if n == 1{
        println!("Hello World");
    }else{
        let A:i32 = read_line().parse().unwrap();
        let B:i32 = read_line().parse().unwrap();
        println!("{}",A+B);
    }
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>

#define MINint -2147483648

void heapIN(int,int);
void insert(int);
int extract(void);
void Mheap(int);

int H=0,A[2000000];

int main(){
  int i,a;
  char buffer[7];

  while(1){
    scanf("%s",buffer);
    if(buffer[2]=='s') {
      scanf("%d",&a);
      insert(a);
    //  for(i=1;i<H;i++)printf(" %d",A[i]);
    //  printf("\n");
    }
    else if(buffer[2]=='t') printf("%d\n",extract());
    else if(buffer[2]=='d') break;
  }

    return 0;
}

void insert(int k){
  H++;
  A[H]=MINint;
  heapIN(H,k);
}

void heapIN(int i,int k){
  int swap;

    if (k<A[i]) return;
    A[i]=k;

    while(i>1 && A[i/2]<A[i]){
      swap=A[i/2];
      A[i/2]=A[i];
      A[i]=swap;
      i/=2;
    }
}

int extract(){
  int max;

  if(H<1) return A[0];
  max=A[1];
  A[1]=A[H];
  H--;
  Mheap(1);

  return max;
}

void Mheap(int i){
  int l,r,largest,swap;

  l = i*2;
  r = i*2+1;

  if(l <= H && A[l] > A[i]) largest = l;
  else largest=i;
  if(r <= H && A[r]>A[largest]) largest = r;

  if(largest != i){
    swap=A[largest];
    A[largest]=A[i];
    A[i]=swap;

    Mheap(largest);
  }
}


    
  



Measured memory_bytes: 5672
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		boolean[] time = new boolean[24*60];
		while (true) {
			int n = sc.nextInt();
			String sp = sc.next(), sq = sc.next();
			if (n == 0 && sp.equals("0") && sq.equals("0")) break;
			int p = Integer.parseInt(sp.substring(0, sp.length()-2))*60+Integer.parseInt(sp.substring(sp.length()-2));
			int q = Integer.parseInt(sq.substring(0, sq.length()-2))*60+Integer.parseInt(sq.substring(sq.length()-2));
			
			Arrays.fill(time, false);
			
			for (int z = 0; z < n; z++) {
				int k = sc.nextInt();
				int i = p;
				for (int y = 0; y < k; y++) {
					String s1 = sc.next(), s2 = sc.next();
					for (int j = i; j < Integer.parseInt(s1.substring(0, s1.length()-2))*60+Integer.parseInt(s1.substring(s1.length()-2)); j++) {
						time[j] = true;
					}
					i = Integer.parseInt(s2.substring(0, s2.length()-2))*60+Integer.parseInt(s2.substring(s2.length()-2));
				}
				for (int j = i; j < q; j++)
					time[j] = true;
			}
			int res = 0;
			
			int i = p;
			while (i < q) {
				if (time[i]) {
					int c = 0;
					while (i < q && time[i]) {
						i++;
						c++;
					}
					res = Math.max(res, c);
				} else {
					while (i < q && !time[i]) i++;
				}
			}
			
			out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 20148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=1e9+7;


int main(){
  int i,j;
  int n;
  cin>>n;
  vector<vector<P> > v(n);
  for(i=0;i<n;i++){
    int a;
    cin>>a;
    for(j=0;j<a;j++){
      int x,y;
      cin>>x>>y;
      v[i].pb(P(x-1,y));
    }
  }
  int ans=-1;
  for(i=0;i<(1<<n);i++){
    int cnt=0;
    vector<int> w(n);
    for(j=0;j<n;j++){
      cnt+=(i>>j)&1;
      w[j]=(i>>j)&1;
    }
    bool ok=1;
    for(j=0;j<n;j++){
      if(w[j]==0) continue;
      for(P e:v[j]){
        if(e.se!=w[e.fi]) ok=0;
      }
    }
    //cout<<i<<" "<<cnt<<" "<<ok<<endl;
    if(ok){
      ans=max(ans,cnt);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
D, X = map(int, input().split())
list_A = [int(input()) for i in range(N)]
list_n = [0] * N

for i in range(1, D + 1):
    for j in range(N):
        if (i - 1) % list_A[j] == 0:
            list_n[j] += 1
print(sum(list_n)+X)


Measured memory_bytes: 9188
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())

p = {}
for i in range(H):
    for j in range(W):
        p[A[i][j]-1] = (i, j)

d = [0]*(H*W)
for i in range(D, H*W):
    d[i] = d[i-D] + abs(p[i][0]-p[i-D][0]) + abs(p[i][1]-p[i-D][1])

for _ in range(Q):
    L, R = map(lambda x:int(x)-1, input().split())
    print(d[R]-d[L])

Measured memory_bytes: 90496
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int,n);
	VEC(int,a,n);

	int ans=1;
	int lastInc=-1;
	FOR(i,1,n){
		if(a[i]==a[i-1]) continue;
		if(lastInc<0){
			if(a[i]>a[i-1]) lastInc = 1;
			else lastInc = 0;
			continue;
		}

		if(lastInc==1){
			if(a[i]>a[i-1]) continue;
			lastInc = -1;
			++ans;
		}else{
			if(a[i]<a[i-1]) continue;
			lastInc = -1;
			++ans;
		}
		debug(i);
		debug(ans);
	}
  OUT(ans)BR;
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    ll a, b;
    string op;
    cin >> a >> op >> b;
    ll ans = op == "+" ? a+b : a-b;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
function Main(input){
	var xs = input.trim().split(' ').map(v=>parseInt(v,10));
    if(xs[0]*xs[1]>xs[2]){
    console.log(xs[2]);
    }else if(xs[0]*xs[1]<xs[2]){
    console.log(xs[0]*xs[1]);
    }else if(xs[0]*xs[1]==xs[2]){
    console.log(xs[2]);
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 19656
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

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

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
//constexpr auto MAX = 100000;

// ──────────────────────────────────────────────────────────────────

int main() {
	string s;
	cin >> s;
	if (s[0] != s[1] || s[1] != s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 384
class Dice:
    def __init__(self,a,b,c,d,e,f):
        self.face1 = a
        self.face2 = b
        self.face3 = c
        self.face4 = d
        self.face5 = e
        self.face6 = f

    def above_face(self):
        return self.face1

    def roll(self, order):
        if order == 'N':
            tmp = self.face1
            self.face1 = self.face2
            self.face2 = self.face6
            self.face6 = self.face5
            self.face5 = tmp
        elif order == 'S':
            tmp = self.face1
            self.face1 = self.face5
            self.face5 = self.face6
            self.face6 = self.face2
            self.face2 = tmp
        elif order == 'W':
            tmp = self.face1
            self.face1 = self.face3
            self.face3 = self.face6
            self.face6 = self.face4
            self.face4 = tmp
        else:
            tmp = self.face1
            self.face1 = self.face4
            self.face4 = self.face6
            self.face6 = self.face3
            self.face3 = tmp

a,b,c,d,e,f = map(int,input().split())
dice1 = Dice(a,b,c,d,e,f)
a,b,c,d,e,f = map(int,input().split())
dice2 = Dice(a,b,c,d,e,f)
import random

flag = False

for i in 'NNNNWNNNWNNNENNNENNNWNNN':
    dice1.roll(i)
    if dice1.face1 == dice2.face1 and dice1.face2 == dice2.face2 and dice1.face3 == dice2.face3 \
            and dice1.face4 == dice2.face4 and dice1.face5 == dice2.face5 and dice1.face6 == dice2.face6:
        flag = True
        break
if flag == True:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 8188
#include <stdio.h>

int GCD(int N,int M){ return N%M?GCD(M,N%M):M; }

int main(){
  int N,M,gcd,n,m,flag=0;
  char S[100001],T[100001];

  scanf("%d %d",&N,&M);
  scanf("%s %s",S,T);

  if(N>M)
    gcd = GCD(N,M);
  else
    gcd = GCD(M,N);
  n = N/gcd;
  m = M/gcd;

  
  
  for(int i=0;i<gcd;i++)
    if(S[n*i]!=T[m*i])
       flag++;

  if(flag)
    printf("-1\n");
  else
    printf("%lld\n",(long long int)N*M/gcd);

  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){

	int n;
	int max_1 = 0;
	int max_2 = 0;
	int in_1 = 0;

	cin >> n;

	rep(i,n) {
		int a;
		cin >> a;
		if (a > max_1) {
			max_2 = max_1;
			max_1 = a;
			
			in_1 = i;
		} else if (a > max_2) {
			max_2 = a;
		}
	}

	rep(i,n) {
		if (i == in_1) {
			cout << max_2 << endl;
		} else {
			cout << max_1 << endl;
		}
	}

}



Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    vvl dp(n+1, vl(13));  // dp[i+1][j] : s[i]までで13で割った余りがjのものの個数
    dp[0][0] = 1;
    rep(i, n) {
        rep(j, 13) {
            if(s[i] == '?') {
                rep(k, 10) {
                    dp[i+1][(10*j + k)%13] += dp[i][j];
                    dp[i+1][(10*j + k)%13] %= mod;
                }
            }
            else {
                ll x = s[i] - '0';
                dp[i+1][(10*j + x)%13] += dp[i][j];
                dp[i+1][(10*j + x)%13] %= mod;
            }
        }
    }

    out(dp[n][5]);
    re0;
}

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

int compute_position(vector<int>& A, int pos, int times){
  for(int i=0; i < times; i++){
          pos = A.at(pos); 
  }
  return pos; 
}

int main() {
    string str;
    cin >> str; 
    int count = 0;
    int N = str.size();
  
    vector<vector<int>> A(100, vector<int>(N));
    
    for (int i = 0; i < str.size(); i++) {
    	if (str.at(i) == 'L') A.at(0).at(i)=i-1;
        if (str.at(i) == 'R') A.at(0).at(i)=i+1;
  	}
  
    for (int i = 0; i < 99; i++) {
      for(int j=0; j<N; j++){
    	A.at(i+1).at(j)= compute_position(A.at(i), j, 10) ;
      }
  	}
/*
    // 10回移動後
    vector<int> B(N);
    for (int i = 0; i < N; i++) {
    	B.at(i)= compute_position(A, i, 10) ;
  	}

    // 10^10回移動後 >> 10*10回移動
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
    	C.at(i)= compute_position(B, i, 10) ;
  	}

    // (10^10)^10回移動後
     vector<int> D(N);
    for (int i = 0; i < N; i++) {
    	D.at(i)= compute_position(C, i, 10) ;
  	}
*/    
    vector<int> answer(N);   
    for (int i = 0; i < N; i++) {
    	answer.at( A.at(99).at(i) )++ ;
  	}
     
     for (int i = 0; i < N; i++) {
       if(i!=N-1) cout<< answer.at(i)<<' ';
       if(i==N-1) cout<< answer.at(i)<< endl; 
     }
            }

Measured memory_bytes: 40312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

class UnionFind{
public:
	vector<int> par;
	vector<int> rank;
	vector<int> size;
 
	UnionFind(int n){
		rep(i,n){
			par.push_back(i);
			rank.push_back(0);
			size.push_back(1);
		}
	}
 
	int find(int x) {
		if(par[x]==x){
			return x;
		}else{
			return par[x]=find(par[x]);
		}
	}
 
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			par[x]=y;
			size[y]+=size[x];
		}else{
			par[y]=x;
			size[x]+=size[y];
			if(rank[x]==rank[y]) rank[x]++;
		}
	}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<int> p(n);
  UnionFind uf(n);
  rep(i,n){
    cin>>p[i];
    p[i]--;
  }
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--,y--;
    uf.unite(x,y);
  }
  int ans=0;
  rep(i,n){
    if(uf.same(i,p[i])) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2028
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 500050;
const int mod = 1e9+7;
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i])
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3844
arr = []
f_arr = []
(0..3).each do |b|
  (0..2).each do |f|
    f_arr << [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  end
  arr << f_arr
  f_arr = []
end

gets
ARGF.each_line do |line|
  b, f, r, v = line.chomp.split.map(&:to_i)
  arr[b-1][f-1][r-1] += v
end

(0..3).each do |b|
  puts "#" * 20 unless b == 0
  (0..2).each do |f|
    puts "\s" + arr[b][f].join("\s")
  end
end

Measured memory_bytes: 6112
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;

signed main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    for(int i = 0;i < 2 * N;i++) {
        if(i % 2 == 0) {
            cout << S.at(i / 2);
        }
        else {
            cout << T.at(i / 2);
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	string t = s;
	reverse(all(t));
	vector<int> res;
	int now = n;
	vector<int> a(n+1, 0);
	vector<int> b(n,-1);
	b[0] = -1;
	REP(i, m+1) {
		if (t[i] == '0') {
			b[0] = i;
		}
	}
	if (b[0] == -1) {
		put(-1);
		return 0;
	}
	FOR(i, 1, n) {
		int next = min<int>(i + m, n);
		if (t[next] == '0') {
			b[i] = next;
		} else {
			b[i] = b[i - 1];
		}
	}
	int now2 = 0;
	while (now2 < n) {
		if (b[now2] == now2) {
			put(-1);
			return 0;
		}
		res.push_back(b[now2] - now2);
		now2 = b[now2];
	}
	reverse(all(res));
	put(res);
	return 0;
}


Measured memory_bytes: 1992
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   N : Integer;
   A : Integer;
begin
   Get (N);
   A := N-N/10*10;
   if A = 7 then
      Put_Line ("Yes");
   else
      N := N/10;
      A := N-N/10*10;
      if A = 7 then
         Put_Line ("Yes");
      else
         A := N/10;
         if A = 7 then
            Put_Line ("Yes");
         else
            Put_Line ("No");
         end if;
      end if;
   end if;
end Solve;

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

int main(){
 
  int n;
 
  cin >> n;
  
  long a[n+1],b[n],ans=0.0;
  
  //入力を受け取る
  rep(i,0,n)cin >> a[i]; 
  rep(i,0,n-1)cin >> b[i];
  
  rep(i,0,n-1){
    //勇者iが倒せる数が残っていないときは次の勇者へ
    if(b[i]==0)continue;

    //勇者iが倒せる数が残っているモンスターの数より少ないときは倒せるだけ倒す
    //都市iのモンスターを倒しきれないとき
    if(b[i] <= a[i]){
      ans += b[i];
      continue;
    }

    //勇者iが倒せる数が残っているモンスターの数より少ないときは倒せるだけ倒す
    //都市iのモンスターは倒せるが都市i+1のモンスターは倒しきれないとき
    if(b[i] <= a[i] + a[i+1]){
      ans += b[i];
      b[i] -= a[i];
      a[i+1] -= b[i];
      continue;
    }

    //勇者iが都市i, i+1のモンスターをすべて倒しきれるときはすべて倒す
    ans += a[i]+a[i+1];
    //a[i]も0にすべきだが、この変数はこの後使わないので省略
    a[i+1]=0;
  }
 
  cout << ans << endl;
 
  return 0;
 
}


Measured memory_bytes: 5104
#include<bits/stdc++.h>
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	int n,k; cin >> n >> k;
	vector<ll> tab;	
	ll res = 0;
	for(int i = 0; i < n; i++){
		ll x; cin >> x;
		tab.push_back(x);
	}

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

	if(k % 2 == 1){
		res = tab.back();
		tab.pop_back();
		n--;
		k--;
	} else {
		res = 1;
	}
	
	deque<ll> q;
	
	for(auto it : tab) q.push_back(it);
		
	while(k){
		//cout << res << "\n";
		ll a1 = q.front();
		q.pop_front();
		ll b1 = q.front();
		q.push_front(a1);
		ll a2 = q.back();
		q.pop_back();
		ll b2 = q.back();
		q.push_back(a2);
		if(res == 0) break;
		if(res > 0){
			if(a1 * b1 > a2 * b2){
				ll mult = (a1 * b1) % MOD;
				if(a1 * b1 >= 0) mult = abs(mult);
				res = (res * mult) % MOD;
				if(a1 * b1 >= 0) res = abs(res);
				q.pop_front();
				q.pop_front();
			} else {
				ll mult = (a2 * b2) % MOD;
				if(a2 * b2 >= 0) mult = abs(mult);
				res = (res * mult) % MOD;
				if(a2 * b2 >= 0) res = abs(res);
				q.pop_back();
				q.pop_back();
			}	
		} else {
			if(a1 * b1 < a2 * b2){
				ll mult = (a1 * b1) % MOD;
				mult = abs(mult);
				if(a1 * b1 < 0) mult = abs(mult);
				else if(mult > 0) mult = -mult;
				res = (res * mult) % MOD;
				res = abs(res);
				if(mult > 0) res = -res;
				q.pop_front();
				q.pop_front();
			} else {
				ll mult = (a2 * b2) % MOD;
				if(a2 * b2 >= 0) mult = abs(mult);
				else if(mult > 0) mult = -mult;
				res = (res * mult) % MOD;
				res = abs(res);
				if(mult > 0) res = -res;
				q.pop_back();
				q.pop_back();
			}	
		}
		k -= 2;
	}

	if(res < 0) res += MOD;
	
	cout << res;
	
	
	
	
	
	
	
	

}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

template<uint32_t mod>
struct ModInt{
    uint32_t a;
    ModInt& s(uint32_t vv){
        a=vv<mod?vv:vv-mod;
        return *this;
    }
 
    ModInt(int64_t x=0){s(x%mod+mod);}
 
    ModInt& operator+=(const ModInt &x){return s(a+x.a);}
    ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
    ModInt& operator*=(const ModInt &x){
        a=uint64_t(a)*x.a%mod;
        return *this;
    }
    ModInt& operator/=(const ModInt &x){
        *this*=x.inv();
        return *this;
    }
 
    ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
    ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
    ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
    ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
    bool operator==(const ModInt &x)const{return a==x.a;}
    bool operator!=(const ModInt &x)const{return a!=x.a;}
    bool operator<(const ModInt &x)const{return a<x.a;}
 
    ModInt operator-()const{return ModInt()-*this;}
    ModInt pow(int64_t n)const{
        ModInt res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
 
    ModInt inv()const{return pow(mod-2);}
};
 
template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
    return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
    return (out<<a.a);
}
using mint=ModInt<MOD>;

int main(void)
{
    int N,K;
    cin >> N >> K;
    mint ans;
    Rep(i, K, N+2){
        ll t(i);
        ll s = t*(t-1)/2;
        ll e = (t*(2*N-t+1))/2;
        ans += e-s+1;
    }
    pr(ans);
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

int main() {
	int a1, a2, a3, a4, b1, b2, b3, b4;
	while (cin >> a1) {
		cin >> a2 >> a3 >> a4;
		cin >> b1 >> b2 >> b3 >> b4;
		
		vector<int> a(4), b(4);
		a.at(0) = a1;
		a.at(1) = a2;
		a.at(2) = a3;
		a.at(3) = a4;
		b.at(0) = b1;
		b.at(1) = b2;
		b.at(2) = b3;
		b.at(3) = b4;
		
		int hit = 0, blow = 0;
		for (int i = 0; i < 4; i++) {
			int n = b.at(i);
			int cnt = count(a.begin(), a.end(), n);

			if (cnt == 1) {
				if (a.at(i) == n) {
					hit++;
				}
				else {
					blow++;
				}
			}
		}

		cout << hit << ' ' << blow << endl;
	}
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    int max = -1;
    int comp_max = -1;
    const long long int size = 100001;
    vector<int> a;
    vector<int> number(size,0);

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        int num;
        cin >> num;
        a.push_back(num);
    }

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

    for (int i = 0; i < a.size(); ++i)
    {
        number[a[i]] += 1;
    }

    for (int i = 0; i < number.size(); ++i)
    {
        if(number[i]!=0)
        {
            if(i==0) comp_max = number[i]+number[i+1];
            else if(i==(number.size()-1)) comp_max = number[i-1]+number[i];
            else comp_max = number[i-1]+number[i]+number[i+1];

            if(max<comp_max) max = comp_max;
        }
    }

    //sort(number.begin(),number.end());

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 1276