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

immutable inf = 1<<30;
string ng = "UNRESTORABLE";

void main() {
    string s, t;
    scan(s);
    scan(t);

    int n = s.length.to!int, k = t.length.to!int;

    foreach_reverse (i ; 0 .. n - k + 1) {
        bool match = true;

        foreach (j ; i .. i + k) {
            if (s[j] == '?') continue;
            if (s[j] != t[j - i]) {
                match = false;
                break;
            }
        }

        if (match) {
            foreach (j ; 0 .. n) {
                if (i <= j && j < i + k) {
                    write(t[j - i]);
                }
                else {
                    write(s[j] == '?' ? 'a' : s[j]);
                }

                if (j == n - 1) {
                    writeln();
                }
            }

            return;
        }
    }

    writeln(ng);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    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);
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N;
  
  scanf("%d",&N);
  
  char s[N];
  scanf("%s",s);
  
  int count = 0;
  
  for(int i=0;i<N;i++){
    if(s[i] == 'A'&& s[i+1] == 'B' && s[i+2] == 'C'){
      count++;
      i = i+2;
    }
  }
  
  printf("%d",count);
  
}
  

Measured memory_bytes: 128
n = int(input())
t, a = map(int, input().split())
h_list=[int(i) for i in input().split()]

#平均気温　T-x*0.006
list=[]
for i in range(n):
    list.append(abs(a-(t-h_list[i]*0.006)))
print(list.index(min(list))+1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

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

  vector<int> broken(n+1);
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    broken[a] = 1;
  }
  vector<int> dp(n+2);
  const int mod = 1000000007;
  dp[n] = 1;
  for (int i = n-1; i >= 0; i--) {
    if (broken[i]) {
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i+1] + dp[i+2]) % mod;
  }
  cout << dp[0] << endl;

  return 0;
}

Measured memory_bytes: 3556
//Author : Vipul Sharma

// LIBRARIES
#include <bits/stdc++.h>

// MACROS
#define ll long long int
#define rep(i, a, b) for (i = a; i < b; i++)
#define rev(i,b,a) for(i=b-1;i>=a;i--)
#define s1rep(i,a,b) for( i=1;i<=b;i++)
#define itrep(at) for (auto it = at.begin(); it != at.end(); it++)
#define ld long double
#define pb push_back
#define w(t) while (t--)
#define booster                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define deb1(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << endl;
#define deb4(x, y, z, w) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << "\t" << #w << " : " << w << endl;
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define deb6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

using namespace std;
long long cost = 1e18;
// FUNCTIONS
ll power(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
        {
            res *= a;
            n--;
        }
        else
        {
            a *= a;
            n >>= 1;
        }
    }
    return res;
}













ll dp[100001];

ll solve(ll a[],ll n,ll k)
{
    ll dp[n],i;
    rep(i,0,n) dp[i]=INT_MAX;
    dp[0]=0;
    for( i=0;i<n;i++)
    {
        for(ll j=i+1;j<=i+k;j++)
        {
            if(j<n)
                dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
            
        }
    }
    return dp[n-1];
}



int main()
{
    booster;
    ll n,k,i;
    cin>>n>>k;
    ll a[n];
    rep(i,0,n) cin>>a[i];
    cout<<solve(a,n,k)<<endl;
    return 0;

}

Measured memory_bytes: 1792
#[allow(dead_code)]
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)*}
    };
}

#[allow(dead_code)]
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)*}
    };

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

#[allow(dead_code)]
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 main() {
    input! {
        ss: String,
    }
    let result = ss.chars().collect::<Vec<_>>().windows(2).map(|l| l[0] == l[1]).fold(true, |cum, a| cum && a);
    if !result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
<?php
$inputs = explode(" ", trim(fgets(STDIN)));

list($r, $c) = [(int)$inputs[0], (int)$inputs[1]];
$last_line = array_fill(0, $c + 1, 0);

for ($i = 0; $i < $r; $i++) { 
        $line = trim(fgets(STDIN));
    $items = explode(" ",$line);
    $items[] = array_sum($items);

    foreach ($items as $key => $item) {
        $last_line[$key] += (int)$item;
    }
    echo implode(" ", $items) . "\n";
}

echo implode(" ", $last_line) . "\n";

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

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


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


int main(){
  int w,h,T,p;
  int x[SIZE],y[SIZE],t[SIZE];
  int a[SIZE][SIZE];
  
  scanf("%d%d%d%d",&w,&h,&T,&p);

  for(int i=0;i<p;i++){
    scanf("%d%d%d",x+i,y+i,t+i);
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf("%d",a[i]+j);
    }
  }

  for(int i=0;i<p;i++){
    if(a[y[i]][x[i]]) a[y[i]][x[i]]++;
  }

  int ans = 0;
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans += max(0,a[i][j]-1);
    }
  }

  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 3232
function updateChildren(cid, pid, sid) {
	var node = T.filter(function(c){return c.id == cid;})[0];
	node.parent = pid;
	node.sibling = sid;
	node.depth++;

	if (node.left != -1) {
		updateChildren(node.left, node.id, node.right);
	}
	if (node.right != -1) {
		updateChildren(node.right, node.id, node.left);
	}
}
function height(id) {
	if (id == -1) {
		return -1;
	}
	var node = T.filter(function(c){return c.id == id;})[0];
	var left = height(node.left) + 1;
	var right = height(node.right) + 1;

	return left > right ? left : right;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');

var n = +lines.shift()

var T = [];
for (var i = 0; i < n; i++) {
	var u = lines.shift().split(' ');
	var id = +u[0];
	var left = +u[1];
	var right = +u[2];
	var degree = 0;
	if (left != -1) {
		degree++;
	}
	if (right != -1) {
		degree++;
	}

	T.push({id: id, left: left, right: right, parent: -1, sibling: -1, degree: degree, depth: 0});
}

T.sort(function(a, b){return a.id - b.id;});

T.forEach(function(node) {
	if (node.left != -1) {
		updateChildren(node.left, node.id, node.right);
	}
	if (node.right != -1) {
		updateChildren(node.right, node.id, node.left);
	}
	node.height = height(node.id);
});

T.forEach(function(node) {
	var type;
	if (node.parent == -1) {
		type = 'root';
	}
	else if (node.degree == 0) {
		type = 'leaf';
	}
	else {
		type = 'internal node';
	}

	console.log('node ' + node.id + ': parent = ' + node.parent
		+ ', sibling = ' + node.sibling + ', degree = ' + node.degree
		+ ', depth = ' + node.depth + ', height = ' + node.height
		+ ', ' + type);
});

Measured memory_bytes: 8712
n,x,y=map(int,input().split())
ans=[0]*(n-1)
for i in range(1,n):
	for j in range(i+1,n+1):
		ans[min(j-i,abs(x-i)+abs(y-j)+1,abs(y-i)+abs(x-j)+1)-1]+=1
for _ in ans:
	print(_)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  string s;
  cin >> s;
  if (s.size()==3) reverse(all(s));
  cout << s << endl;
}


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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T, typename U>
ostream& operator<<(ostream& o, const pair<T,U>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

const int INF = 1e18;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vi as(n);
  for (int& ai : as)
    cin >> ai;

  int cnt = 0;
  map<int,int> cntmap;
  for (int i=n-1; i>=0; --i) {
    int ci = i + as[i];
    int bi = i - as[i];
    cnt += cntmap[ci];
    ++cntmap[bi];
  }
  cout << cnt << endl;
}


Measured memory_bytes: 27416
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  double n;
  cin>>n;
  for(double i=0;i<=n;i+=1.0){
       if((int)n==(int)(i*1.08)){
           cout<<(int)i<<endl;
           return 0;
       }
  }
  cout<<":("<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll m;
ll cnt[4];
ll table[] = { 500,100,50,10 };
bool f = 0;

int main() {
	while (cin >> m&&m) {
		rep(i, 4)cin >> cnt[i];
		ll num = INF;
		ll ans[] = { -1,-1,-1,-1 };
		rep(i, cnt[0] + 1) {
			rep(j, cnt[1] + 1) {
				rep(k, cnt[2] + 1) {
					rep(l, cnt[3] + 1) {
						ll mm = 10 * i + 50 * j + 100 * k + 500 * l;
						if (mm >= m) {
							ll nm = mm - m;
							ll co[4] = {};
							rep(ii, 4) {
								ll k = nm / table[ii];
								nm -= k*table[ii];
								co[ii] = k;
							}
							ll cc = cnt[3] - i + cnt[2] - j + cnt[1] - k + cnt[0] - l;
							rep(ii, 4)cc += max((ll)0, co[ii]);
							if (num > cc) {
								/*cout << cnt << endl;
								cout << mm << endl;
								cout << i << " " << j << " " << k << " " << l << endl;*/
								ans[0] = i;
								ans[1] = j;
								ans[2] = k;
								ans[3] = l;
								num = cc;
							}
						}
					}
				}
			}
		}
		if (f)cout << endl;
		f = 1;
		rep(i, 4) {
			if (ans[i] != 0)cout << table[3 - i] << " " << ans[i] << endl;
		}
	}
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
 
 
int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    for (int i = 1; i < 6; i++) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i;
            break;
        }
    }
}


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

#include <vector>
#include <cmath>
#include <limits>
#include <functional>
using namespace std;

int main()
{
    int N, x;
    cin >> N;
    long long ans = 0;

    int a[300010];
    for (int i = 0; i < 300010; i++)
    {
        a[i] = -1;
    }

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

    sort(a, a + 300010);

    for (int i = 0; i < N; i++)
    {
        ans += a[300010 - 2 - 2 * i];
        
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4768
let x, n;
const p = [];

function getMin() {
	for (var i = x; p[0] <= i; i--) {
		if (-1 === p.indexOf(i)) {
			return i;
		}
	}
	return p[0] - 1;
}

function getMax() {
	for (i = x; i <= p[n-1]; i++) {
		if (-1 === p.indexOf(i)) {
			return i;
		}
	}
	return p[n-1]+1;
}

// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");
	const line1 = inputLines[1];
	const line1vars = line1.split(" ");

	x = parseInt(line0vars[0], 10);
	n = parseInt(line0vars[1], 10);
	
	if (n === 0) {
		console.log(x);
		return;
	}

	for (var i = 0; i < n; i++) {
		p.push(parseInt(line1vars[i], 10));
	}
	p.sort((a, b) => a - b);

	const myMin = getMin();
	const myMax = getMax();
	const absMin = Math.abs(myMin - x);
	const absMax = Math.abs(myMax - x);
	// console.log({
	// 	myMin: myMin,
	// 	myMax: myMax,
	// 	absMin: absMin,
	// 	absMax: absMax
	// });
	console.log((absMin <= absMax) ? myMin : myMax);
	

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, k;
  cin >> n >> k;
  vll p(n);
  vll c(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i, n) cin >> c[i];

  ll ans = -INF;
  rep(start, n) {
    ll x = start;
    vll sum(n);
    vll when(n);
    vb visited(n);
    visited[start] = true;

    ll cnt = 0;
    ll point = 0;
    ll mx = -INF;

    bool cycled = false;

    if (start == p[start]) {
      if (c[start] > 0) {
        mx = c[start] * k;
      } else {
        mx = c[start];
      }
      chmax(ans, mx);
      continue;
    }

    while (cnt < k) {
      cnt++;
      x = p[x];
      point += c[x];
      if (visited[x] == true && !cycled) {
        cycled = true;
        ll loop_step = cnt - when[x];
        ll loop_cnt = (k - when[x]) / loop_step;
        ll loop_point = point - sum[x];
        if (loop_cnt > 2) {
          point += loop_point * (loop_cnt - 2);
          cnt += loop_step * (loop_cnt - 2);
        }
        chmax(mx, point);
      } else {
        visited[x] = true;

        sum[x] = point;
        when[x] = cnt;
        chmax(mx, point);
      }
    }
    chmax(ans, mx);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
using ll =  long long;
#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    int n; cin>>n;
    vector<int>v(3*n);
    rep(i,3*n) cin>>v[i];
    priority_queue<int,vector<int>,greater<int>>lque;
    priority_queue<int,vector<int>>sque;
    int ls=0,ss=0;
    vector<int>lv;
    vector<int>sv;
    rep(i,n){
        lque.push(v[i]);
        sque.push(v[2*n+i]);
        ls+=v[i];
        ss+=v[2*n+i];
    }
    lv.push_back(ls);
    sv.push_back(ss);
    int ans=-INF*INF;
    cmax(ans,ls-ss);
    rep(i,n){
        lque.push(v[n+i]);
        sque.push(v[2*n-i-1]);
        ls+=v[n+i]-lque.top();
        ss+=v[2*n-i-1]-sque.top();
        lv.push_back(ls);
        sv.push_back(ss);
        sque.pop();
        lque.pop();
    }
    rep(i,lv.size())cmax(ans, lv[i]-sv[n-i]);
    cout<<ans<<endl;
}
 

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

int main(void){
    int a,b;
    cin >> a >> b;
    for(int i=0; i<10000; i++){
    if (i*8/100 == a && i*10/100 == b) {
        cout << i << endl;
        return 0;
    }
    }
    
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  int i;
  int n;
  int max=0;
  int sum=0;

  cin>>t;

  for(i=0;i<t;i++)
  {
      cin>>n;

      sum+=n;

      if(n>max)
      {
          max=n;
      }



  }

  if(max<sum-max)
      {
          printf("Yes\n");
      }


      else
        printf("No\n");



return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, Q, x;
int main() {
	while (cin >> N >> Q) {
		vector<int> c(N);
		for (int i = 0; i < N; i++) c[i] = i;
		while (Q--) {
			cin >> x;
			vector<int> a, b;
			for (int i = 0; i < N / 2; i++) b.push_back(c[i]);
			for (int i = N / 2; i < N; i++) a.push_back(c[i]);
			vector<int> f;
			while (a.size()) {
				if (a.size() >= x) {
					f.insert(f.end(), a.begin(), a.begin() + x);
					a.erase(a.begin(), a.begin() + x);
				}
				else {
					f.insert(f.end(), a.begin(), a.end());
					a.clear();
				}
				if (b.size() >= x) {
					f.insert(f.end(), b.begin(), b.begin() + x);
					b.erase(b.begin(), b.begin() + x);
				}
				else {
					f.insert(f.end(), b.begin(), b.end());
					b.clear();
				}
			}
			c = f;
		}
		cout << c.back() << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#![allow(
    dead_code,
    non_snake_case,
    unused_imports,
)]

use std::io::{self,BufRead,Read,Write};

// util {{{
fn is_even(n: i64) -> bool { n % 2 == 0 }
fn is_odd (n: i64) -> bool { n % 2 != 0 }

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 { a } else { gcd(b, a % b) }
}

fn _INPUT() -> String {
    let mut res = String::new();
    io::stdin().read_to_string(&mut res).expect("read_to_string()");
    res
}
// }}}

fn main() {
    let input  = _INPUT();
    let mut tokens = input.split_whitespace();
    macro_rules! RD { () => ( tokens.next().unwrap().parse().unwrap() ) }

    let N: i64 = RD!();
    let K: i64 = RD!();
    let mut A = Vec::<i64>::with_capacity(N as usize);
    for _ in 0..N {
        A.push(RD!());
    }

    let ok = if N == 1 {
        K == A[0]
    }
    else if K > *A.iter().max().unwrap() {
        false
    }
    else {
        let mut d = A[0];
        for a in &A[1..] {
            d = gcd(d, *a);
        }
        K % d == 0
    };

    println!("{}", if ok { "POSSIBLE" } else { "IMPOSSIBLE" });
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int a, b, c;

signed main()
{
    cin >> a >> b >> c;
    cout << b + min(a + b + 1, c) << endl;

    return 0;
}

/*


*/


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

int main() {
  int N;
  cin >> N;
  
  vector<int>p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  int count = 0;

  for (int i = 0; i < N-2; i++) {
    if (min(p.at(i),p.at(i+1)) == p.at(i+1) && max(p.at(i+1),p.at(i+2)) == p.at(i+1)){
      count++;
    }
    else if (max(p.at(i),p.at(i+1)) == p.at(i+1) && min(p.at(i+1),p.at(i+2)) == p.at(i+1)){
      count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 3608
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.server.UnicastRemoteObject;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        int a[] = sc.nextIntArray(n);
        long x=0;
        for (int i = 0; i < a.length; i++) {
        	x+=(i%2==0?1:-1)*a[i];
		}
        
        out.print(x+" ");
        for (int i = 0; i < a.length-1; i++) {
        	x = 2*a[i] - x;
			out.print(x+" ");
		}
        
//        out.println();
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x, y;
	P(int  x, int y) {
	  this.x=x;
	  this.y=y;
	}
}


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return b-p.b;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 43380
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
		ll size=0;

		string key;
		char ans[10]={};

		cin >> key;

		size=key.size();

		int p=0;
		for(int i=0;i<size;i++){
			if(key[i]=='0'){
				ans[p]='0';
				p++;
			}else if(key[i]=='1'){
				ans[p]='1';
				p++;
			}else if(key[i]=='B'){
				if(p==0){
				}else{
					ans[p-1]='\0';
					p--;
				}
			}
		}

		cout << ans << endl;

		return 0;
    }

Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int row = nxt(), col = nxt();
    int b = 0;
    int grid[row][col];
    REP(i, row) REP(j, col){
        char ch;
        cin >> ch;
        if(ch == '.') grid[i][j] = 1;
        else grid[i][j] = 0;
    }
    int dist[row][col];
    REP(i, row) REP(j, col){
        if(grid[i][j] == 0) continue;
        REP(k, row) REP(l, col) dist[k][l] = INF;
        queue<pair<int, PII>> q; q.push({0, {i, j}});
        while(!q.empty()){
            auto front = q.front(); q.pop();
            int d = front.first, x = front.second.first, y = front.second.second;
            if(d > dist[x][y]) continue;
            dist[x][y] = d;
            int rN[4] = {0, 0, 1, -1};
            int cN[4] = {1, -1, 0, 0};
            REP(a, 4){
                int nX = cN[a] + x;
                int nY = rN[a] + y;
                if(nX < 0 || nX >= row || nY < 0 || nY >= col || grid[nX][nY] == 0) continue;
                if(dist[nX][nY] > dist[x][y] + 1){
                    dist[nX][nY] = dist[x][y] + 1;
                    q.push({dist[nX][nY], {nX, nY}});
                }
            }
        }
        // REP(k, row){
        //     REP(l, col) {
        //         if(dist[k][l] != INF) printf("%d", dist[k][l]);
        //         else printf(" ");
        //     }
        //     printf("\n");
        // }
        // printf("\n");
        REP(k, row) REP(l, col){
            if(dist[k][l] != INF) b = max(b, dist[k][l]);
        }
    }
    printf("%d\n", b);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long

const LL MOD = 1e9 + 7;
const int N = 200005;

LL n, A, B, in[N];

int main()
{
    while(cin >> n >> A >> B){
        for(int i=0;i<n;i++) cin >> in[i];
        sort(in, in + n);
        LL mn = 0;
        for(int i=1;i<n;i++){
            LL dis = in[i] - in[i - 1];
            LL x = dis * A;
            if(x < B) mn += x;
            else mn += B;
        }
        cout << mn << '\n';
    }
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

vector<Vl> G;
ll n, m;
ll color[55];
const int white = 0, black = 1;

void bfs(ll a, ll b){
    queue<ll> qu;
    qu.push(1);
    color[1] = black;
    while(!qu.empty()){
        ll t = qu.front(); qu.pop();
        color[t] = black;
        rep(i, 0, G[t].size()){
            if(a == t && b == G[t][i]) continue;
            if(b == t && a == G[t][i]) continue;
            if(color[G[t][i]]) continue;
            qu.push(G[t][i]);
            color[G[t][i]] = black;
        }
    }
}

int main() {
    cin >> n >> m;
    G.resize(n+1);
    vector<pair<ll, ll>> M(m);
    rep(i, 0, m){
        ll a, b; cin >> a >> b;
        M[i].fi = a, M[i].se = b;
        G[b].push_back(a);
        G[a].push_back(b);
    }
    ll ans = 0;
    rep(i, 0, m){
        Rep(i, 1, n) color[i] = white;
        bfs(M[i].fi, M[i].se);
        Rep(i, 1, n){
            if(color[i] == white){
                ans++;
                break;
            }
        }
    }
    co(ans);

    return 0;
}


Measured memory_bytes: 256
# 参考: https://atcoder.jp/contests/exawizards2019/submissions/4780769
def c_snuke_the_wizard(N, Q, S, Magic):
    # ゴーレムが隣のゴーレムを追い抜くことはありえない
    # (複数体重なれば、その後同じように動いていくため)。
    # よって、 左端で消滅する、最初に最も右にいるゴーレムleftと、
    # 右端で消滅する、最初に最も左にいるゴーレムrightが分かればいい。
    # (left >= right とはなりえない)
    # これを二分探索で求めれば O(Qlog(N)) で解を得られる。
    def is_vanished(x, direction):
        """
        x番のゴーレムがdirection(leftまたはrightのいずれか)で指定される端で
        消滅するかどうか判定する
        """
        for t, d in Magic:
            if t == S[x]:
                # 呪文で指定されたマスに注目したゴーレムがいた。
                # 呪文の内容に従ってゴーレムを移動させる
                x = x - 1 if d == 'L' else x + 1
            # 左端/右端 で消滅することとなった
            if x == -1:
                return True if direction == 'left' else False
            if x == N:
                return False if direction == 'left' else True
        return False

    def binary_search(accept, reject, direction):
        """
        direction が 'left' の場合は accept番とその左側のゴーレムが消滅する。
        direction が 'right' の場合は accept番とその右側のゴーレムが消滅する。
        direction によって accept と reject の位置関係が逆転することに注意。
        """
        while abs(accept - reject) > 1:
            mid = (accept + reject) // 2
            if is_vanished(mid, direction):
                accept = mid
            else:
                reject = mid
        return accept + 1 if direction == 'left' else N - accept
    return N - binary_search(-1, N, 'left') - binary_search(N, -1, 'right')

N, Q = [int(i) for i in input().split()]
S = input()
Magic = [input().split() for j in range(Q)]
print(c_snuke_the_wizard(N, Q, S, Magic))


Measured memory_bytes: 41392
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int time =sc.nextInt();
        int h = time / 3600;
        int m = time % 3600 / 60;
        int s = time % 3600 % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26408
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;

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

    int n, a, b, c, x;
    while (cin >> n >> a >> b >> c >> x, n) {
        vector<int> y(n);
        rep(i, n) cin >> y[i];

        int pos = 0;
        int ans;
        for (ans = 0; ans <= 10000; ans++) {
            if (y[pos] == x) {
                pos++;
            }
            if (pos == n) break;
            x = (a * x + b) % c;
        }
        if (ans > 10000) ans = -1;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3084
import sys
import itertools
import collections
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n = int(input())
a = lmi()
a.sort()
b = [-1 for i in range(n)]
b[-1] = 1
for i in range(1, n-1):
    if a[i] > 0:
        b[i] = 1


print(sum([a[i]*b[i] for i in range(n)]))

x = a[0]
for y in [a[i] for i in range(n-1) if b[i] == 1]:
    print(x, y)
    x -= y

y = x
x = a[-1]
print(x, y)
x -= y
for y in [a[i] for i in range(1,n-1) if b[i] == -1]:
    print(x, y)
    x -= y


Measured memory_bytes: 14768
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// 
int main(){
    char str[4];
    scanf("%s", str);
    int ans=0;
    rep(i, 0, 4){
        if(str[i] == '+') ++ans;
        if(str[i] == '-') --ans;
    }
    printf("%d", ans);
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;

    vector<int> si(s.size());
    unordered_map<char, int> sm;
    rep(i, s.size()) {
        if (sm.find(s[i]) == sm.end()) {
            sm[s[i]] = i;
        }
        si[i] = sm[s[i]];
    }

    vector<int> ti(s.size());
    unordered_map<char, int> tm;
    rep(i, t.size()) {
        if (tm.find(t[i]) == tm.end()) {
            tm[t[i]] = i;
        }
        ti[i] = tm[t[i]];
    }

    rep(i, s.size()) {
        if (si[i] != ti[i]) {
            put("No");
            return 0;
        }
    }
    put("Yes")

    return 0;
}

Measured memory_bytes: 5444
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  long long N, P;
  cin >> N >> P;
  long long x = pow(P, 1.0 / N) + 1;
  while (x > 1) {
    long long temp = pow(x, N);
    if (P % temp == 0) {
      cout << x << endl;
      return 0;
    }
    --x;
  }
  cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int n;
	int p;
	int prev;
	int i;
	int flag;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		p = -1;
		flag = 0;
		for (i = 0; i < n; i++){
			prev = p;
			scanf("%d", &p);
			
			if (prev + 1 != p){
				if (prev == -1){
					printf("%d", p);
				}
				else {
					if (flag != 0){
						printf("-%d %d", prev, p);
						flag = 0;
					}
					else {
						printf(" %d", p);
					}
				}
			}
			else {
				flag = 1;
			}
		}
		if (prev + 1 == p){
			if (prev == -1){
				printf("%d", p);
			}
			else {
				printf("-%d", p);
			}
		}
		
		printf("\n");
	}
	return (0);
}

Measured memory_bytes: 604
using System;

namespace ABC106_B_105
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int yakusuu = 0;
			int value = 0;

			for (int i = 1; i <= n; i += 2)
			{
				yakusuu = 0;
				for (int j = 1; j <= i; j++) {
					if (i % j == 0)
					{
						yakusuu++;
					}
				}

				if (yakusuu == 8)
				{
					value++;
				}
			}
			
			Console.Write(value);
		}
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



//先求出长n的不合法序列个数
//dp[i][j] = 长i, 最后一段连续互不相同的长度为j的方案
//dp[i-1][3] 填a[i-1] -> dp[i][1]
//dp[i-1][3] 填a[i-2] -> dp[i][2]
//dp[i-1][3] 填a[i-3] -> dp[i][3]
//a[i-4]与a[i-1],a[i-2],a[i-3]中的某一个相同
//dp[i-1][3] 填其余 -> dp[i][4]
//
//题目要求求出A在所有合法序列中的出现次数
//转化为A在所有序列中的出现次数(n-m+1)*k^(n-m)
//再减去A在所有不合法序列中的出现次数F
//长x的不合法序列总数很容易求出
//考虑给定的A, 假设A合法, 那么F = 0
//假设A所有元素互不相同
//求出所有长m的互不相同序列在长n的不合法序列中的出现次数
//dp[i][j] = 
//
//

const int N = 2.6e4+10, M = 410;
int n, k, m, a[N];
int f[N][M],g[N][M];
int vis[N],fac[N],ifac[N];
void add(int &a, ll b) {a=(a+b)%P;}

int main() {
	fac[0] = 1;
	REP(i,1,N-1) fac[i]=(ll)fac[i-1]*i%P;
	ifac[N-1]=inv(fac[N-1]);
	PER(i,0,N-2) ifac[i]=(ll)ifac[i+1]*(i+1)%P;
	scanf("%d%d%d", &n, &k, &m);
	REP(i,1,m) scanf("%d",a+i);
	int ma = 0, now = 0;
	REP(i,1,m) {
		while (now<m&&!vis[a[now+1]]) vis[a[++now]]=1;
		ma = max(ma, now-i+1);
		--vis[a[i]];
	}
	int tot = (n-m+1ll)*qpow(k,n-m)%P;
	if (ma==k) return printf("%d\n",tot),0;
	if (ma==m) {
		f[0][0] = 1;
		REP(i,1,n) {
			int s1 = 0, s2 = 0;
			PER(j,1,min(k-1,i)) {
				add(s1,f[i-1][j]),add(s2,g[i-1][j]);
				add(f[i][j]=s1,(ll)(k-j+1)*f[i-1][j-1]);
				add(g[i][j]=s2,(ll)(k-j+1)*g[i-1][j-1]);
				if (j>=m) add(g[i][j],f[i][j]);
			}
		}
		int ans = 0;
		REP(i,1,k-1) (ans += g[n][i])%=P;
		ans = (ll)ans*ifac[k]%P*fac[k-m]%P;
		ans = (tot-ans+P)%P;
		printf("%d\n", ans);
	}
	else {
		int L = 0, R = 0;
		memset(vis,0,sizeof vis);
		while (!vis[a[L+1]]) vis[a[++L]]=1;
		memset(vis,0,sizeof vis);
		while (!vis[a[m-R]]) vis[a[m-R++]]=1;
		f[0][L] = g[0][R] = 1;
		REP(i,1,n) {
			int s1 = 0, s2 = 0;
			PER(j,1,k-1) {
				add(s1,f[i-1][j]),add(s2,g[i-1][j]);
				add(f[i][j]=s1,(ll)(k-j+1)*f[i-1][j-1]);
				add(g[i][j]=s2,(ll)(k-j+1)*g[i-1][j-1]);
			}
		}
		int ans = 0;
		REP(i,0,n-m) {
			int s1 = 0, s2 = 0;
			REP(j,1,k-1) add(s1,f[i][j]),add(s2,g[n-m-i][j]);
			add(ans,(ll)s1*s2);
		}
		ans = (tot-ans+P)%P;
		printf("%d\n", ans);
	}
}








Measured memory_bytes: 82304
s = list(input())
k = int(input())

if s[0] != "1":
    print(int(s[0]))

elif s[0] == "1" and k != 1:
    if len(s) < k:
        for i in s:
            if int(i) != 1:
                print(int(i))
                break

    else:
        for l in range(0, k):
            if int(s[l]) != 1:
                print(int(s[l]))
                break

            if l == k - 1:
                print(1)

elif s[0] == "1" and k == 1:
    print(1)


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

int main(){
  int a;
  cin >> a;
  if(a%2 == 0) cout << setprecision(7) << (float)1/2;
  else cout << setprecision(7) << (float)(a/2+1)/a;
  cout << endl;
  return 0;
}

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

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

  int A = X-(K-1);
  for(int i=0;i<(K-1)*2+1;i++){
  cout << A << " ";
  A+=1;
  }
  
}

Measured memory_bytes: 256
n = gets.chomp.to_i
h = gets.chomp.split.map(&:to_i)

answer = "Yes"

(n - 1).downto(2) do |i|
  h[i - 1] -= 1 if h[i] < h[i - 1]
  if h[i] < h[i - 1]
    answer = "No"
    break
  end
end

puts answer


Measured memory_bytes: 9604
N = int(input())
S = input().strip()
cmax = 0
for i in range(N-1):
    S1 = S[:i+1]
    S2 = S[i+1:]
    hist = {chr(i):0 for i in range(97,123)}
    cnt = 0
    for j in range(i+1):
        a = S1[j]
        if hist[a]==1:continue
        hist[a] = 1
        flag = 0
        for k in range(len(S2)):
            if S2[k]==a:
                flag = 1
                break
        if flag==1:
            cnt += 1
    cmax = max(cmax,cnt)
print(cmax)

Measured memory_bytes: 40304
#include<iostream>
using namespace std;
int A[2*100000+1];
int main() {
    int N,M; cin>>N;
    for (int i=1; i<N; i++) {
        cin>>M;
        A[M-1]++;
    }
    for (int i=0; i<N; i++) {
        cout<<A[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4368
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

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

    vector<bool> b(a.at(n - 1) + 1, true);
    int temp = 0;
    int m;
    for (int i = 0; i < n; i++)
    {
        if (b.at(a.at(i)))
        {
            if (temp == a.at(i))
            {
                b.at(temp) = false;
            }
            temp = a.at(i);
            m = 2;
            while (temp * m <= a.at(n - 1))
            {
                b.at(temp * m) = false;
                m++;
            }
        }
    }
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (b.at(a.at(i)))
        {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3644
N = int(input())
C = [int(input()) for i in range(N)]
MOD = 10**9+7

dp = [0] * N
dp[0] = 1
bak = {C[0]:0}

for i,c in enumerate(C):
    if i==0: continue
    dp[i] = dp[i-1]
    if c in bak and bak[c] < i-1:
        dp[i] += dp[bak[c]]
        dp[i] %= MOD
    bak[c] = i
print(dp[-1])

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
  i64 n;
  cin >> n;
  vector<vector<i64>> G(n);
  vector<i64> deg(n);
  REP(_, n - 1) {
    i64 a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    G[a].push_back(b);
    G[b].push_back(a);
    deg[a] += 1;
    deg[b] += 1;
  }
  vector<i64> c(n);
  cin >> c;
  queue<i64> que;
  REP(i, n) {
    if (deg[i] == 1) {
      que.push(i);
    }
  }
  sort(c.rbegin(), c.rend());
  vector<i64> d(n);
  i64 sum = -c[0];
  while (!que.empty()) {
    i64 v = que.front();
    que.pop();
    sum += d[v] = c.back();
    c.pop_back();
    for (i64 w : G[v]) {
      deg[w] -= 1;
      if (deg[w] == 1 && d[w] == 0) {
        que.push(w);
      }
    }
  }
  cout << sum << endl;
  REP(i, n) {
    cout << d[i] << (i == n - 1 ? "\n" : " ");
  }
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
const int INF = 2147483647;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

string s, t;

bool checker(string s, string t)
{
	int n = t.size();

	for (int i = 0;i < n;i++) {
		if (s[i] != t[i] && s[i] != '?') return false;
	}

	return true;
}

int main()
{
	cin >> s >> t;

	if (s.find(t) != s.npos ) {
		for (int i = 0;i < s.size();i++) {
			if (s[i] == '?') cout << "a";
			else cout << s[i];
		}
		cout << endl;
		return 0;
	}

	int flag = 0;
	for (int i = s.size() - 1;i >= t.size()-1;i--) {
		if (checker(s.substr(i - t.size() + 1, t.size()), t)) {

			int h = 0;
			for (int j = i - t.size() + 1; j <= i; j++) {
				s[j] = t[h];h++;
			}

			flag = 1;
			break;
		}
	}

	if (flag == 0) {
		cout << "UNRESTORABLE" << endl;
	}
	else {
		for (int i = 0;i < s.size();i++) {
			if (s[i] == '?') cout << "a";
			else cout << s[i];
		}
	}

	return 0;
}


Measured memory_bytes: 256