akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;




void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    int[] b;
    auto c = new int[](n);

    foreach_reverse (i ; 1 .. n + 1) {
        int t;

        for (int j = i; j <= n; j += i) {
            t ^= c[j - 1];
        }

        if (t != a[i - 1]) {
            b ~= i;
            c[i - 1]++;
        }
    }

    auto M = b.length.to!int;
    writeln(M);
    writefln("%(%s %)", b);
}




















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 8052
#include <iostream>
using namespace std;
int main(){
  int N;cin>>N;
  int a[N];
  bool ok[N];
  for(int i = 0; N > i; i++){
    cin >> a[i];
    ok[i] = false;
  }
  int nw = 1;
  int kaisu = 0;
  bool cn = false;
  while(true){
    if(ok[nw-1])break;
    if(a[nw-1] == 2){
      cn = true;
      break;
    }
    ok[nw-1] = true;
    nw = a[nw-1];
    kaisu++;
  }
  if(cn)cout << kaisu+1 <<endl;
  else cout << -1 << endl;
}

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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
const int N = 1e5 + 55;
int arr[N];
int ans[N];
void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> arr[i], arr[i] *= 2;
	int s = 1;
	ans[1] = 0;
	for (int i = 1; i <= n; ++i) {
		ans[1] += arr[i] * s;
		s *= -1;
	}
	ans[1] /= 2;
	for (int i = 2; i <= n; ++i) {
		ans[i] = arr[i - 1] - ans[i - 1];
	}
	for (int i = 1; i <= n; ++i) {
		cout << ans[i] << ' ';
	}
}

Measured memory_bytes: 2944
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    n += 1
    a = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    ans = [0] * n
    for i in range(n):
        ans[i] = c[n] - c[i]
    if n == 1 and a[0] == 0:
        print(-1)
        return
    if n > 1 and a[0] > 0:
        print(-1)
        return
    ans[0] = min(1, ans[0])
    if ans[0] < a[0]:
        print(-1)
        return
    for i in range(1, n):
        ans[i] = min(ans[i], (ans[i-1]-a[i-1]) * 2)
        if ans[i] < a[i]:
            print(-1)
            return

    print(sum(ans))
main()


Measured memory_bytes: 83076
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int main(){
	int n;
	cin>>n;
	map<string,int>ma;
	bool h=true;
	vs in(n);
	rep(i,n)cin>>in[i];
	rep(i,n-1)if(in[i+1][0]!=in[i][in[i].size()-1])h=false;
	rep(i,n){
		if(ma[in[i]])h=false;
		ma[in[i]]=1;
	}
	if(h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}







Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())
from collections import defaultdict
ns = defaultdict(set)

for i in range(m):
    a,b = map(int, input().split())
    ns[a-1].add(b-1)

seen = [False] * n
done = [False] * n
hist = []
def dfs(u, pos):
    # uからdfs
    seen[u] = True
    hist.append(u)
    for v in ns[u]:
        if done[v]:
            continue
        elif seen[v]:
            # サイクルを検出
            pos = v
            return pos
        else:
            pos = dfs(v, pos)
            if pos>=0:
                return pos
    done[u] = True
    hist.pop()
    return pos
def cycle(hist, pos):
    for i, u in enumerate(hist):
        if u==pos:
            break
    return hist[i:]

for u in range(n):
    pos = dfs(u, -1)
    if pos>=0:
        hist = cycle(hist, pos)
        while True:
            us = set(hist)
            update = False
            for i,u in enumerate(hist):
                nu = hist[(i+1)%len(hist)]
                pu = hist[(i-1)]
                if (ns[u]&us)-set([nu, pu]):
                    for v in (ns[u]&us)-set([nu, pu]):
                        break
                    j = hist.index(v)
                    if i<j:
                        hist = hist[i:] + hist[:j+1]
                    else:
                        hist = hist[j:i+1]
                    update = True
                    break
            if not update:
                break
        print(len(hist))
        write("\n".join(map(lambda x: str(x+1), hist)))
        break
else:
    print(-1)

Measured memory_bytes: 40432
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextLong() }.toMutableList()
    val m = (n + 1) / 2
    val left = Array(m + 1) { 0L }
    val right = Array(m + 1) { 0L }
    for (i in 0 until m) {
        left[i + 1] = left[i] + a[2 * i]
    }
    for (i in m - 1 downTo 0) {
        right[i] = right[i + 1] + if (n % 2 == 1 && i == m - 1) a[n - 1] else a[2 * i + 1]
    }
    if (n % 2 == 0) {
        var max = Long.MIN_VALUE
        for (i in 0..m) {
            val v = left[i] + right[i]
            max = Math.max(max, v)
        }
        println(max)
    } else {
        a.add(a.last())
        val maxL = Array(m + 1) { 0L }
        val maxR = Array(m + 1) { 0L }
        for (i in 0 until m) {
            maxL[i + 1] = Math.max(maxL[i] + a[2 * i + 1], left[i + 1])
        }
        for (i in m - 1 downTo 0) {
            maxR[i] = maxR[i + 1] + a[2 * i]
        }
        var max = Long.MIN_VALUE
        for (i in 0 until m) {
            val v = maxL[i] + maxR[i + 1]
            max = Math.max(max, v)
        }
        println(max)
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 69548
#include <bits/stdc++.h>
#define re(i, n) for(int i = 0; i < n; ++i)
using namespace std;
const int MXN = 210, mol = 998244353;
int n, ans = 0, pow2[MXN] = {1};

struct point {
    int x, y;
}p[MXN];

int multi(point a, point b, point c) {
    return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
}

int main() {
    cin >> n;
    re(i, n) cin >> p[i].x >> p[i].y, pow2[i + 1] = pow2[i] * 2 % mol;
    ans = (pow2[n] + mol - n - 1) % mol;
    re(i, n)
        re(j, i) {
            int t = 0;
            re(k, j) {
                if (multi(p[i], p[j], p[k]) == 0) ++t;
            }
            ans = (ans + mol - pow2[t]) % mol;
        }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,c;
	cin>>a>>b>>c;
	puta(min(c,b/a));
	return 0;
}

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

using namespace std;

#define ll long long
#define vi vector<int>
#define pb push_back
#define loop(i,n) for(int i=0; i<n; i++)
#define pii pair<int, int>

const int MXN = 1e5 + 5;
int n, a[MXN], ht[MXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin>>n;
    loop(i, n) {
        cin>>a[i];
        ht[a[i]]++;
    }
    int res = 0;
    int evens = 0;
    loop(i, MXN) {
        if (ht[i]) {
            res++;
            if ( (ht[i] % 2) == 0) evens++;
        }
    }
    if (evens % 2) res--;
    cout<<res<<endl;
    return 0;
} 

Measured memory_bytes: 1024
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn get_vec_by_lines<T : FromStr>(n : usize) -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for _i in 0..n {
        let x : T = get_one();
        v.push(x);
    }
    return v;
}

fn main() {
    let s : Vec<u64> = get_one::<String>().chars().map(|e| e as u64 - '0' as u64).collect();
    let mut falldown = false;
    let mut ans = 0;
    for i in 0..s.len()-1{
        if falldown {
            ans += 9;
        }
        else if s[i+1] != 9 {
            ans += s[i] - 1;
            falldown = true;            
        }
        else if s[i] == 9 {
            ans += 9;
        }
        else if s[i+1] == 9{
            ans += s[i]
        } else {
            ans += s[i] - 1;
            falldown = true;
        }
    }
    if falldown {
        ans += 9;
    }
    else {
        ans += s[s.len()-1];
    }
    println!("{}", ans);
}


Measured memory_bytes: 2140
# -*- coding: utf-8 -*-
# 文字列の入力
S = input()
T = ''
for i in range(len(S)):
	if S[i] == '0':
		T += '0'
	elif S[i] == '1':
		T += '1'
	elif S[i] == 'B':
		T = T[:-1]
print(T)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main()
{
  int n;
  int a[10000];
  int max, min;
  long long sum;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  max = min = a[0];
  for(int i = 0; i < n; i++){
    if(min > a[i]) min = a[i];
    if(max < a[i]) max = a[i];
  }
  cout << min << " " << max << " " << sum << '\n';
    
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e6 + 10;
ll s[ 41 ];
int a[ N ];
int n , cnt;
map< int, int > e;
int check1( int x ){//二分寻找第一个比他大的2次幂 
   int l = 0 , r = 32;
   while( l < r ){
   	int mid = ( l + r )/2;
   	if( s[ mid ] > x ) r = mid  ;else
   	l = mid + 1 ;
   }
   return l;
}
int main( ){
	scanf("%d" , &n );
	s[ 0 ] = 1;
	for( int i = 1 ; i <= 32 ; i ++ ) s[ i ] = s[ i - 1 ] * 2; 
	for( int i = 1 ; i <= n ; i ++ ){
	 scanf("%d" , &a[ i ] );
	 e[ a[ i ] ]++;
    }
	sort( a + 1  , a + n + 1 );
    for( int i = n ; i >= 1 ; i -- ){
     if( e[ a[ i ] ] == 0 ) continue;
	 int p = check1( a[ i ] );
//	 cout<<p << " "<<i <<" "<<a[ i ]<<" "<<e[ a[ i  ]]<<endl;
	 int q = s[ p ] - a[ i ];
	 if( q == a[ i ] ){
	  if( e[ q ] >= 2 ){
	  	cnt ++;
	  	e[ q ] -= 2;
	  }
	 }else
	 if ( e[ q ] >= 1 ){
	 	cnt++;
	 	e[ q ]--;
	 	e[ a[ i ] ]--;
	 }
   }
	cout<<cnt;    
} 

Measured memory_bytes: 19712
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
using namespace std;
ll n, x[200009], y[200009];
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>x[i]>>y[i];
    }
    ll res = 0, smallest, cur;
    for (ll p : {1, -1}) {
        for (ll q : {1, -1}) {
            //cout<<p<<" "<<q<<":"<<endl;
            smallest = p * x[1] + q * y[1];
            for (int i = 2; i <= n; ++i) {
                cur = p * x[i] + q * y[i];
                //cout<<i<<" "<<smallest<<" "<<cur<<endl;
                res = max(res, cur - smallest);
                smallest = min(smallest, cur);
            }
        }
    }
    cout<<res;
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


Measured memory_bytes: 6776
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		
		String result = x <= 500*k ? "Yes" : "No";
		System.out.println(result);
	}		
}

Measured memory_bytes: 22100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-10;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 1e6+10;
const int MAXM = (int) 1e6+10;
const int sigma_size = (int) 26;

///--------------------START-------------------------
int L;
struct Edge{
    int u,v,w;
}e;
vector<Edge> ans;

void work(){
    scanf("%d",&L);
    L--;
    int N=20;
    for(int i=1;i<=N-2;i++){
        e.u=i,e.v=i+1,e.w=(1<<(i-1));
        ans.push_back(e);
        e.u=i,e.v=i+1,e.w=0;
        ans.push_back(e);
    }
//    printf("%d\n",(1<<(N-2))-1);
    for(int j=N+2;j>=1;j--){
        int val;
        if(j<=N-1) val=(1<<(j-1))-1;
        else val=(1<<(N-2))-1;
        if(L>=val){
//            printf("j = %d , val = %d , LL = %d\n",j,val,L);
            e.u=j>N-1 ? N-1 : j;
            e.v=N,e.w=L-val;
            ans.push_back(e);
            L=L-val-1;
//            printf("L = %d\n",L);
        }
    }
    printf("%d %d\n",N,ans.size());
    for(int i=0;i<ans.size();i++){
        printf("%d %d %d\n",ans[i].u,ans[i].v,ans[i].w);
    }
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mn(a, b) (a < b ? a : b)
#define mx(a, b) (a > b ? a : b)
#define f first
#define s second
#define all(v) (v).begin(), (v).end()
#define base 331

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int const MAXn = 1e5 + 2;

int dp[MAXn];
int arr[MAXn];

int main(){

    //freopen(".in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    fill(dp + 1, dp + n + 1, INT_MAX);
    dp[1] = 0;
    for(int i = 1; i <= n; i++){
        cin>>arr[i];
        if(i == 1) continue;
        if(i > 1)
            dp[i] = mn(dp[i], dp[i - 1] + abs(arr[i] - arr[i - 1]));
        if(i > 2)
            dp[i] = mn(dp[i], dp[i - 2] + abs(arr[i] - arr[i - 2]));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <algorithm>
// #include <iostream>
#include <cstdio>
#include <tuple>
#include <utility>
using namespace std;

struct UnionFind {
    vector<int> node;
    int components;
    UnionFind(int n) : node(n, -1), components(n) {}
    void reset() {
        fill(node.begin(), node.end(), -1);
        components = node.size();
    }
    int find(int x) { return node[x] < 0 ? x : node[x] = find(node[x]); }
    int size(int x) { return -node[find(x)]; }
    int size() { return components; }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        if(size(x) > size(y)) swap(x, y);
        node[x] += node[y];
        node[y] = x;
        components--;
        return true;
    }
};

int solve_testcase() {
    int N, M; scanf("%d%d", &N, &M);
    if(N == 0 and M == 0) return 1;

    vector< tuple<int, int, int> > edges;
    for(int i=0; i<M; i++) {
        int u, v, c; scanf("%d%d%d", &u, &v, &c);
        u--; v--;
        edges.emplace_back(c, u, v);
    }

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

    UnionFind uf(N);
    const int INF = 1 << 29;
    int ans = INF;
    for(int i=0; i<M; i++) {
        uf.reset();
        int j = i;
        for(j=i; j<M and uf.size() > 1; j++) {
            int u = get<1>(edges[j]), v = get<2>(edges[j]);
            uf.unite(u, v);
        }

        if(uf.size() > 1) continue;
        ans = min(ans, get<0>(edges[j-1]) - get<0>(edges[i]));
    }
    if(ans == INF) printf("-1\n");
    else printf("%d\n", ans);
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



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

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 7;
ll N, W, dp[101][MAXN], w, v;

int main() {
    cin >> N >> W;
    for (ll i = 0; i <= W; ++i) dp[0][i] = 0;
    for (ll i = 1; i <= N; ++i) {
        cin >> w >> v;
        for (ll j = 0; j <= W; ++j)
            if (w > j)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max(dp[i-1][j-w] + v, dp[i-1][j]);
    }
    cout << dp[N][W] << endl;
    return 0;
}

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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll ADD( ll a, ll b )
{
	return ( ( a % MOD ) + ( b % MOD ) ) % MOD;
}

ll SUB( ll a, ll b )
{
	return ( ( a % MOD ) - ( b % MOD ) + MOD ) % MOD;
}

ll MUL( ll a, ll b )
{
	return ( ( a % MOD ) * ( b % MOD ) ) % MOD;
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a , POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ) + 1; ++i )
		if ( x % i )
			return false;
	return true;
}

string s;

int main()
{
	cin >> s;
	bool ok = true;
	FOR( i, 0, ( int )s.size() )
	{
		if ( i % 2 == 0 && s[ i ] == 'L' )
			ok = false;
		if ( i % 2 == 1 && s[ i ] == 'R' )
			ok = false;
	}
	
	puts( ok ? "Yes" : "No" );
	return 0;
}


Measured memory_bytes: 256
N,x=map(int, input().split())
A=list(map(int, input().split()))

#2つどこを見ても和がx以下
ans=0
pre=0
for i in range(N):
    if i==0:
        if A[i]>x:
            ans+=A[i]-x
            A[i]=x
        pre=A[i]
    else:
        if pre+A[i]>x:
            ans+=A[i]-(x-pre)
            A[i]=x-pre
        pre=A[i]
print(ans)



Measured memory_bytes: 14060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define N (1000000000+7)
#define INF (ll)1e16
typedef pair<int,int> P;
typedef long long ll;
ll kaijo[100010]={0};

int main(void){
    string s;
    int n;
    cin>>n;
    map<string,ll>m;
    kaijo[0]=0;
    kaijo[1]=0;
    kaijo[2]=1;
    for(int i=3;i<=100000;i++)kaijo[i]=kaijo[i-1]+i-1;
    for(int i=0;i<n;i++){
        cin>>s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    ll ans=0;
    for(auto itr=m.begin();itr!=m.end();++itr){
        ans+=kaijo[itr->second];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int n;
bool same(int x){
    int a,b,c;
    a = x%10;
    x/=10;
    b = x%10;
    x/=10;
    c = x%10;
    if(a==b && a==c)return true;
    else return false;
}
int main(){
    cin>>n;
    for(int i=n;i<=999;i++){
        if(same(i)){cout<<i<<endl;break;}
    }


}


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

int main()
{
	int n, k;
	cin >> n >> k;
	map<int, int> mp;
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int a;
			cin >> a;
			if (mp.count(a)) mp[a]++;
			else mp[a] = 1;
		}
	}
	cout << n - mp.size() << endl;
}


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

using namespace std;

int main()
{
    long long int n,d;
    cin>>n>>d;
    long long int a[n],b[n];
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i];
    long long int c=0;
    d=d*d;
    for(int i=0;i<n;i++)
    {
        if((a[i]*a[i]+b[i]*b[i])<=d)
            c++;
    }
    cout<<c;
    return 0;
}

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

int N, K;
vector<int> D(10);

bool isOK(int n) {
  while(n != 0) {
    int d = n % 10;
    rep(i, 0, K) if(d == D[i]) return false;
    n /= 10;
  }
  return true;
}

int main() {
  cin >> N >> K;
  rep(i, 0, K) cin >> D[i];
  int ans = N;
  while(1) {
    if(isOK(ans)) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 100005;
const lo mod = 1000000007;

int n,mx,x,y,m,b,a[li],k,flag,yes,vis[li],tut[li],mx1;
int cev;
string s;
vector<int> v[li];
vector<int> vv[li];

void dfs(int node,int ata,int der){
	vv[der].pb(node);
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i];
		if(go==ata) continue;
		dfs(go,node,der+1);
	}
	//~ cout<<der<<endl;
	mx1=max(mx1,der);
}

int main(void){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d %d",&x,&y);
		vis[x]++;
		vis[y]++;
		if(mx<vis[x]) yes=x;
		mx=max(mx,vis[x]);
		if(mx<vis[y]) yes=y;
		mx=max(mx,vis[y]);
		v[x].pb(y);
		v[y].pb(x);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		cev+=a[i];
	}
	int at=n;
	sort(a+1,a+n+1);
	printf("%d\n",cev-a[n]);
	dfs(1,0,0);
	//~ cout<<mx1<<endl;
	for(int i=0;i<=mx1;i++){
		//~ cout<<at<<" **&&((*&& "<<endl;
		for(int j=0;j<(int)vv[i].size();j++){
			tut[vv[i][j]]=a[at];
			//~ printf("^^");
			at--;
		}
	}
	FOR{
		printf("%d ",tut[i]);
	}
	return 0;
}


Measured memory_bytes: 6016
S = input()
if S == "SUN":
    n = 7
elif S=="MON":
    n=6
elif S =="TUE":
    n=5
elif S=="WED":
    n=4
elif S == "THU":
    n=3
elif S=="FRI":
    n=2
else:
    n=1
print(n)


Measured memory_bytes: 2940
#include <stdio.h>

void SelectionSort(char ch[],char A[], int n)
{
  int i,j,mini;
  char t;
  for(i=0;i<n;i++){
    mini=i;
    for(j=i;j<n;j++){
      if (A[j]<A[mini]){
        mini=j;
      }
    }
    t=A[i];
    A[i]=A[mini];
    A[mini]=t;
    t=ch[i];
    ch[i]=ch[mini];
    ch[mini]=t;
  }
}

void BubbleSort(char ch[],char A[], int n)
{
  int i,j;
  char t;
  for(i=0;i<n;i++){
    for(j=n-1;i<j;j--){
      if (A[j]<A[j-1]){
        t=A[j];
        A[j]=A[j-1];
        A[j-1]=t;
        t=ch[j];
        ch[j]=ch[j-1];
        ch[j-1]=t;
      }
    }
  }
}

int main()
{
  int n,i;
  char ori_num[36],ori_ch[36],num0[36],ch0[36],num1[36],ch1[36];
  char str[2];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",str);
    ch0[i]=str[0];
    num0[i]=str[1];
    ori_ch[i]=str[0];
    ori_num[i]=str[1];
  }

  BubbleSort(ch0,num0,n);
  for(i=0;i<n-1;i++){
    printf("%c%c ",ch0[i],num0[i]);
  }
  printf("%c%c\n",ch0[n-1],num0[n-1]);
  printf("Stable\n");

  for(i=0;i<n;i++){
    ch1[i]=ori_ch[i];
    num1[i]=ori_num[i];
  }
  SelectionSort(ch1,num1,n);
  for(i=0;i<n-1;i++){
    printf("%c%c ",ch1[i],num1[i]);
  }
  printf("%c%c\n",ch1[n-1],num1[n-1]);

  if ((strncmp(num0,num1,n)==0) && (strncmp(ch0,ch1,n)==0)){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }
return 0;
}

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

int q=0;

struct tranp{
  char gara;
  int atai;
};

int partition(struct tranp CC[],int N,int p,int r){
  int i=0,j=0;
  struct tranp x;
  struct tranp tmp;
  x=CC[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(CC[j].atai<=x.atai){
      i=i+1;
      tmp=CC[i];
      CC[i]=CC[j];
      CC[j]=tmp;
    }
  }
  tmp=CC[i+1];
  CC[i+1]=CC[r];
  CC[r]=tmp;
  return i+1;
}

void quicksort(struct tranp CC[], int N, int p, int r){
  int q;
  if(p<r){
    q=partition(CC,N,p,r);
    quicksort(CC,N,p,q-1);
    quicksort(CC,N,q+1,r);
  }
}
void marge(struct tranp C[],int N, int left, int mid, int right){
  int i,j,k;
  int n1=0,n2=0;
  struct tranp L[500010];
  struct tranp R[500010];
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=C[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=C[mid+i];
  }
  L[n1].atai=2000000000;
  R[n2].atai=2000000000;
  j=0;
  i=0;
  for(k=left;k<right;k++){
    if(L[i].atai<=R[j].atai){
      C[k]=L[i++];
      
    }
    else {
      C[k]=R[j++];
    }
  }
}

void margesort(struct tranp C[],int N, int left, int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    margesort(C,N,left,mid);
    margesort(C,N,mid,right);
    marge(C,N,left,mid,right);
  }
}

int main(){
  struct tranp C[100000];
  struct tranp CC[100000];
  int n=0,i=0;
  int N=0;
  int left=0,right=0;
  char gara1[10];
  int atai1;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s %d",gara1,&atai1);
    C[i].gara=CC[i].gara=gara1[0];
    C[i].atai=CC[i].atai=atai1;
  }
  margesort(C,N,0,N);
  quicksort(CC,N,0,N-1);
  for(i=0;i<N;i++){
    if(C[i].gara!=CC[i].gara){
      printf("Not stable\n");
      break;
    }
  }
  if(i==N)printf("Stable\n");
  for(i=0;i<N;i++){
    cout<<CC[i].gara<<" "<<CC[i].atai<<endl;
    
  }
  return 0;
}



Measured memory_bytes: 5476
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

#define MAX_N 200005

class UnionFind
{
public:
  int par[MAX_N];
  int depth[MAX_N];
  int nGroup[MAX_N];

  UnionFind(int n) {
    init(n);
  }

  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }

  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }

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

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--; z--;
    uf.unite(x, y);
  }
  int ans = 0;
  rep(i, n) if(i == uf.root(i)) ans++;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4844
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	/*
	0: 「直進」命令
	1: 「右折」命令
	2: 「反転」命令
	3: 「左折」命令
	4: 「停止」命令
	 */
	static int H,W;
	static int[][] field;
	static int[][][] dp;
	static int[] cost;
	static int[] v1={0,1,0,-1};
	static int[] v2={1,0,-1,0};
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			W=cin.nextInt();
			H=cin.nextInt();
			if(H+W==0)break;
			field=new int[H][W];
			dp=new int[H][W][5];
			cost=new int[4];
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					field[i][j]=cin.nextInt();
					Arrays.fill(dp[i][j], 1<<30);
				}
			}
			for(int i=0;i<4;i++){
				cost[i]=cin.nextInt();
			}
			dp(0,0,0,0);
			int min=1<<30;
			for(int i=0;i<5;i++){
//				System.out.println(dp[H-1][W-1][i]);
				if(min>dp[H-1][W-1][i]){
					
					min=dp[H-1][W-1][i];
				}
			}
			System.out.println(min);
		}
	}
	static int dp(int h,int w,int dir,int c){
//		System.out.println(h+" "+w+" "+dir+" "+c);
		if(dp[h][w][dir]<=c)
			return dp[h][w][dir];
		int re=-1;
		dp[h][w][dir]=c;
		// 床に書いてあるまま動く
		 if(field[h][w]!=4){
			int newDir=change(field[h][w],dir);
			int hh=h+v1[newDir];
			int ww=w+v2[newDir];
			if(hh<0||ww<0||hh>=H||ww>=W){
				
			}
			else{
				dp(hh,ww,newDir,c);
			}
		}
		
		// 命令を実行
		for(int i=0;i<4;i++){
			if(field[h][w]==i)continue;
			int newDir=change(i,dir);
			int hh=h+v1[newDir];
			int ww=w+v2[newDir];
			if(hh<0||ww<0||hh>=H||ww>=W){
				
			}
			else{
				re=Math.min(re,dp(hh,ww,newDir,c+cost[i]));
			}
		}
		return re;
	}
	
	static int change(int command,int dir){
		if(command==0||command==4)return dir;
		else if(command==1){
			return (dir+1)%4;
		}
		else if(command==2){
			return (dir+2)%4;
		}
		else if(command==3){
			return (dir+3)%4;
		}
		return 0;
	}
}

Measured memory_bytes: 45488
#!python3.8
# -*- coding: utf-8 -*-
# abc167/abc167_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    T = i2s()
    if S == T[:-1]:
        print('Yes')
    else:
        print('No')
    return

main()


Measured memory_bytes: 9148
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: i32 = itr.next().unwrap().parse().unwrap();
    let b: i32 = itr.next().unwrap().parse().unwrap();
    let c: i32 = itr.next().unwrap().parse().unwrap();

    for i in 1..=b {
        if a * i % b == c {
            println!("YES");
            return;
        }
    }
    println!("NO");
}


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

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

    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    int x = 1;
    vector<int> cards;
    for(int i=0; i<n; i++){
        if(a[i] == a[i+1]) x += 1;
        if(a[i] != a[i+1]){
            cards.push_back(x);
            x = 1;
        }
    }

    int m = cards.size();
    cout << m - (1 - m % 2) << endl;
    return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define int long long
const int MOD = 1e9 + 7;
using namespace std;
void solve() {
    string s,p;
    cin>>s>>p;
    int cnt=0;
    for(int i=0;i<=s.size()-p.size();++i){
        int st=i;
        int en=i+p.size()-1;
        int l=0;
        int w=0;
        for(int j=st;j<=en;++j){
            if(s[j]==p[w++]) l++;
        }
//        cout<<l<<" ";
        cnt=max(cnt,l);
    }
//    cout<<cnt<<"\n";
    cout<<p.size()-cnt;


}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include <stdlib.h>

int main(void) {

	char mozi[200] = "";
	char temp_mozi[200] = "";
	char temp_shuffle_t[100]="";
	int mozi_n = 0;//文字の数
	int shuffle;//合計シャッフル回数
	int shuffle_t;//シャッフル時に何枚後ろにするか

	while (1) {
		scanf("%s", &mozi);

		if (mozi[0] == '-') {
			break;
		}

		scanf("%d", &shuffle);

		for (int i = 0; i < shuffle; i++) {

			scanf("%d", &shuffle_t);

			


			for (int n = 0; mozi[n] != '\0'; n++) {//文字の数、計測、コピー
				temp_mozi[n] = mozi[n];
				mozi_n++;
			}

			for (int j = 0; j < (mozi_n)-(shuffle_t); j++) {//前に文字詰め
				mozi[j] = mozi[(shuffle_t + j)];
			}

			for (int k = 0; k < shuffle_t; k++) {//後ろに挿入
				mozi[(mozi_n - shuffle_t) + k] = temp_mozi[k];
			}

			mozi_n = 0;
		}

		printf("%s\n", mozi);
	}
	return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod=1e9+7;
ll inf=1e18;


int main(void){
	ll a[3];
	rep(i,3)cin>>a[i];
	sort(a,a+3);
	cout<<a[0]+a[1]+10*a[2]<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int len[252521];
vi alp[30];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	string a;
	cin>>a;
	int n=a.size();
	map<int, int> mp;
	int cnt=0;
	FORR(i, 0, n){
		++mp[a[i]-'a'];
		len[i+1]=cnt;
		alp[a[i]-'a'].push_back(i);
		if(mp.size()==26){
			mp.clear();
			++cnt;
		}
	}
	len[0]=cnt;
	len[n+1]=-1;
	REP(i, 26){
		reverse(ALL(alp[i]));
		alp[i].push_back(n);
	}
	string ans="";
	int sz=-1, now=-1;
	while(sz<cnt){
		++sz;
		REP(i, 26){
			// DEBUG(len[now+1]);
			// DEBUG(len[*lower_bound(ALL(alp[i]), now+1)+1]);
			if(len[now+1]!=len[*lower_bound(ALL(alp[i]), now+1)+1]){
				ans+='a'+i;
				now=*lower_bound(ALL(alp[i]), now+1);
				break;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

int main(){
    std::vector<int> a;
    int n,a_buf;

    std::cin>>n;

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

    int n_q,q_buf;
    std::vector<int> q;

    std::cin>>n_q;
    for(int i=0;i<n_q;i++){
        std::cin>>q_buf;
        q.push_back(q_buf);
    }

    for(int i=0;i<n_q;i++){
        if(std::binary_search(a.begin(),a.end(),q[i])){
            std::cout<<"1"<<std::endl;
        }else{
            std::cout<<"0"<<std::endl;
        }
    }

    return 0;
}



Measured memory_bytes: 4312
#include<iostream>
#include<vector>
#include<climits>

using namespace std;

class Heap{
private:
public:
 Heap(){ node.push_back(0);};

 void print(){
  long n = node.size();
  for(long i = 1; i < n; ++i)
   cout << " " << node[i];
  cout << endl;
 };
 
 void insert(long num){
  node.push_back(num);
 };
 
 long left(long i){ return (2 * i); };
 long right(long i){ return (2 * i + 1); };
 long parent(long i){ return (i / 2); };

 void maxHeapify(long i){
  long l = left(i);
  long r = right(i);
  long nodeSize = node.size() - 1;
  long largest = 0;

  if(l <= nodeSize && node[l] > node[i]){
   largest = l;
  }else{
   largest = i;
  }

  if(r <= nodeSize && node[r] > node[largest])
   largest = r;
  
  if(largest != i){
   long buf = node[i];
   node[i] = node[largest];
   node[largest] = buf;
   maxHeapify(largest);
  }
  
 };

 void buildMaxHeap(){
  long nodeSize = node.size() - 1;
  for(long i = nodeSize; i > 0; --i)
   maxHeapify(i);
 };
 
 long getNodesize(){
  return node.size();
 };
protected:
 vector<long> node;
};

class PriorityQueue : public Heap{
private:
 void heapIncreaseKey(long i, long num){
  node[i] = num;
  while(i > 1 && (node[parent(i)] < node[i]) ){
   long pi = parent(i);
   long buf = node[i]; node[i] = node[pi]; node[pi] = buf;
   i = pi;
  } 
 };
public:
 void maxHeapInsert(long num){  
  insert(LONG_MIN);
  long i = getNodesize() - 1;
  heapIncreaseKey(i, num);
 };

 long extractMax(){
  long heapSize = getNodesize() - 1;
  if(heapSize < 1) return LONG_MIN;
  
  long max = node[1];
  node[1] = node[heapSize];
  node.pop_back();
  maxHeapify(1);
  return max;
 }; 
protected:
};

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

 PriorityQueue priorityQueue;
 do{
  string str = ""; cin >> str;
  if(str == "insert"){
   long num = 0; cin >> num;
   priorityQueue.maxHeapInsert(num);
  }else if(str == "extract"){
   cout << priorityQueue.extractMax() << endl;
  }else if(str == "end"){
   break; 
  }
 }while(true);
 return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;

	std::set<char> chars;
	bool all_varied(true);
	for (int i = 0; i < s.size(); i++) {
		if (chars.find(s[i]) != chars.end()) {
			all_varied = false;
			break;
		}
		chars.insert(s[i]);
	}

	cout << ((all_varied) ? "yes" : "no") << endl;
	return 0;
}


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

int main(){
  string s,t;
  cin >> s;
  t = s;
  reverse(s.begin(),s.end());
  if(s == t){
    puts("Yes");
  }
  else{
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 256
N,M = gets.chomp.split.map(&:to_i)

from = 1
to = N

M.times do
  l, r = gets.chomp.split.map(&:to_i)
  from = l if l > from
  to = r if r < to
end

ans = to - from + 1
ans = 0 if (to - from + 1) < 0
puts ans


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

int judge(int);

int main(void){
  int n,age;

  for(;;){
    int cnt[7]={0};

    cin >> n;
    if( n == 0 ) break;

    for( int i = 0 ; i < n ; i++ ){
      cin >> age;
      cnt[judge(age)]++;
    }

    for( int i = 0 ; i < 7 ; i++ ) cout << cnt[i] << endl;
  }

  return 0;
}

  int judge(int age){
   
    switch(age/10){

    case 0:return 0;
    case 1:return 1;
    case 2:return 2;
    case 3:return 3;
    case 4:return 4;
    case 5:return 5;
    default:return 6;

    }

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e5+5;
vector<pair<int,int>>g[maxn];
int w[maxn][2];
int n,m,s,t;

vector<int>spfa(int s,int p){
	vector<int>dis(n+1,1e15);
	vector<int>inq(n+1);
	queue<int>q;
	dis[s]=0;
	q.push(s);
	inq[s]=1;
	while( q.size() ){
		int u = q.front(); q.pop(); inq[u]=0;
		for(auto [v,i]:g[u]){
			if( dis[v] > dis[u] + w[i][p] ){
				dis[v] = dis[u] + w[i][p];
				if( !inq[v] ){
					q.push(v);
					inq[v]=1;
				}
			}
		}
	}
	return dis;
}
int32_t main(){
	IOS
	cin>>n>>m>>s>>t;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v>>w[i][0]>>w[i][1];
		g[u].push_back({v,i});
		g[v].push_back({u,i});
	}
	vector<int>d0 = spfa(s,0);
	vector<int>d1 = spfa(t,1);
	vector<pair<int,int>>ans;
	ans.push_back({0,1e18});
	for(int i=n;i>=1;i--){
		int cur = d0[i] + d1[i] ;
		if( cur < ans.back().second ){
			ans.push_back({i,cur});
		}
	}
	for(int i=1;i<=n;i++){
		while( ans.back().first < i ){
			ans.pop_back();
		}
		cout << (int)(1e15-ans.back().second) << endl;
	}


}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 16352