akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    let mut inv = vec![vec![]; n];
    for _ in 0..m {
        let s = sc.read::<usize>() - 1;
        let t = sc.read::<usize>() - 1;
        graph[s].push(t);
        inv[t].push(s);
    }

    let p = calc(&graph);
    let mut ans = p[0];
    for i in 0..n {
        if graph[i].len() == 1 {
            continue;
        }
        if let Some(&next) = graph[i]
            .iter()
            .max_by(|&&next_a, &&next_b| p[next_a].partial_cmp(&p[next_b]).unwrap())
        {
            let mut new_graph = vec![vec![]; n];
            for from in 0..n {
                for &to in graph[from].iter() {
                    if (from, to) == (i, next) {
                        continue;
                    }
                    new_graph[from].push(to);
                }
            }

            let p = calc(&new_graph)[0];
            if ans > p {
                ans = p;
            }
        }
    }

    println!("{}", ans);
}

fn calc(graph: &Vec<Vec<usize>>) -> Vec<f64> {
    let n = graph.len();
    let mut p = vec![0.0; n];
    for i in (0..n).rev() {
        let edges = graph[i].len() as f64;
        for &next in graph[i].iter() {
            p[i] += (p[next] + 1.0) / edges;
        }
    }
    p
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10492
console.log(function(args){
  const [[Q],...tmp] = args.trim().split('\n').map( r=>r.split(' ').map(v=>v|0) );
  const MAX = 1e5;
  const a = Array(MAX).fill(true);
  const s = Array(MAX+2).fill(0);
  a[0] = false; s[2] = 1;
  for ( let i = 1; i < MAX; i++ ) {
    if ( a[i] ) {
      const n = 2*i+1;
      if ( ~i&1 && a[i/2] ) s[i+1] += 1;
      for ( let j = i+n; j < MAX; j=j+n ) a[j] = false;
    }
    s[i+2] += s[i+1];
  }
  const x = [];
  for ( let i = 0; i < Q; i++ ) {
    const l = ( tmp[i][0] - 1 ) / 2;
    const r = ( tmp[i][1] - 1 ) / 2 + 1;
    x.push( s[r] - s[l] );
  }
  return x.join('\n');
}(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 74868
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;

int main(){
  /*処理系*/
  int X, A, B;
  int ans = 0;
  cin >> X;
  cin >> A;
  cin >> B;
  ans = X;
  ans -= A;
  while(ans >= 0){
    ans -= B;
  }
  ans += B;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import heapq
N,M=map(int,input().split())
R=[]
G=[[] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    G[a].append((b,c))
    G[b].append((a,c))
    R.append((a,b,c))
Q=[[0]*N for i in range(N)]
INF=10**9
for i in range(N):
    stack=[]
    g=[INF for i in range(N)]
    g[i]=0
    n=1
    for b,c in G[i]:
        heapq.heappush(stack,(g[i]+c,i,b))
    used=[[0]*N for i in range(N)]
    while(stack):
        if n==N:
            break
        c,a,b=heapq.heappop(stack)
        g[b]=min(g[b],c)
        used[a][b]=1
        used[b][a]=1
        for j in G[b]:
            if used[b][j[0]] or g[j[0]]!=INF:
                continue
            heapq.heappush(stack,(g[b]+j[1],b,j[0]))
    for j in range(i+1,N):
        Q[i][j]=g[j]
ans=0
for a,b,c in R:
    if b<a:
        a,b=b,a
    if Q[a][b]<c:
        ans+=1
print(ans)


Measured memory_bytes: 3824
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

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

struct point{ double x, y; };

point sub(const point& a, const point& b){
  point ret;
  ret.x = a.x - b.x;
  ret.y = a.y - b.y;
  return ret;
}

int solve(point a, point b, point c, point p){
  point ab = sub(b, a), bp = sub(p, b);
  point bc = sub(c, b), cp = sub(p, c);
  point ca = sub(a, c), ap = sub(p, a);

  double c1 = ab.x * bp.y - ab.y * bp.x;
  double c2 = bc.x * cp.y - bc.y * cp.x;
  double c3 = ca.x * ap.y - ca.y * ap.x;

  if((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0)) return 1;
  return 0;
}

int main(){
  double x1, x2, x3, xp, y1, y2, y3, yp;
  while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)){
    point a, b, c, P;
    a.x = y1; a.y = x1;
    b.x = y2; b.y = x2;
    c.x = y3; c.y = x3;
    P.x = yp; P.y = xp;

    if(solve(a, b, c, P)) puts("YES");
    else puts("NO");
  }
  return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		long sum = 0;
		int[] nums = new int[a];
		
		for(int i = 0; i < a; i++){
			nums[i] = sc.nextInt();
			sum += nums[i];
		}
		
		int max = nums[0];
		int min = nums[0];
		for (int n : nums) {
			max = Math.max(max,n);
			min = Math.min(min, n);
		}
		
		System.out.println(min + " " + max + " " + sum);
	}

}

Measured memory_bytes: 31748
fun main(args: Array<String>) {
    val (A,B,K) = readLongList()
    val a = A-K
    val b = A+B-K
    println(when {
        a >= 0 -> "$a $B"
        b >= 0 -> "0 $b"
        else   -> "0 0"
    })
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun Int.pow(n: Int) = Math.pow(this.toDouble(), n.toDouble())

Measured memory_bytes: 38000
package main

import "fmt"

func main() {
	var (
		n    int
		s, t string
	)
	fmt.Scan(&n, &s, &t)

	for i := 0; i < n; i++ {
		fmt.Print(string(s[i]))
		fmt.Print(string(t[i]))
	}
	fmt.Println()
}


Measured memory_bytes: 512
N, Q = map(int, input().split())
ruisekiwa = [0]
lists = []
cnt = 0
S = str(input())
for t in range(1, N):
    if S[t - 1] == "A" and S[t] == "C":
        cnt += 1
    ruisekiwa.append(cnt)
ruisekiwa.append(cnt)
for i in range(Q):
    l, r = map(int, input().split())
    ans = ruisekiwa[r - 1] - ruisekiwa[l - 1]
    lists.append(ans)
for m in range(len(lists)):
    print(lists[m])


Measured memory_bytes: 59208
#include <bits/stdc++.h>
using namespace std;
 
string A;
 
int main() {
  cin >> A;
  for(int i = 0; i < A.size(); i++) {
    if(A[i] == '7') {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  int N, x; cin >> N >> x;
  vector<int> a(N);
  rep(i, N) {
    cin >> a[i];
  }
  sort(all(a));
  int ans = 0;
  rep(i, N) {
    x -= a[i];
    if (i != N-1 && x > 0) {
      ans++;
    }
    else if (x == 0) {
      ans++;
    }
    else {
      break;
    }
  }
  cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++) cin >> a.at(i);
    int s;
    for(int i=0;i<n;i++){
        s=a.at(i);
        b.at(s-1)=i;
    }
    for(int i=0;i<n;i++){
        cout << b.at(i)+1;
        cout << " ";
    }
    cout << endl;
    }


Measured memory_bytes: 1536
// clang-format off
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using G = vector<vector<ll>>;
#define G(i, j) i, vector<ll>(j)
#define Gv(i, j, k) i, vector<ll>(j, k)
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl
#define END(ans) ANS(ans); return
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long X, long long N, std::vector<long long> p) {
  ll a, s = INF;
  rep(i, 102) {
    if (find(all(p), i) != p.end())
      continue;
    ll d = abs(X - i);
    if (d < s) {
      a = i;
      s = d;
    }
  }
  ANS(a);
}

// clang-format off
int main() {
  long long X;
  scanf("%lld",&X);
  long long N;
  scanf("%lld",&N);
  std::vector<long long> p(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&p[i]);
  }
  solve(X, N, std::move(p));
  return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
bool kaibun(string s){

    for (int i = 0; i < s.size()/2; i++)
        if (s[i] != s[s.size()-i-1]) return false;
    return true;
}
int main(){
    string s; cin >> s;
    if (kaibun(s) && kaibun(s.substr(0, (s.size()-1)/2)) && kaibun(s.substr((s.size()+3)/2 - 1, s.size()-(s.size()+3)/2+1)))
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
}

Measured memory_bytes: 256
from itertools import accumulate
import bisect

n,m,K = map(int, input().split())
a = [0] + list(accumulate(list(map(int, input().split()))))
b = list(accumulate(list(map(int, input().split()))))
ans = 0
for k,v in enumerate(a):
    if v > K:
        break
    tmp = k + bisect.bisect_right(b,K-v)
    if tmp > ans:
        ans = tmp
print(ans)

Measured memory_bytes: 126724
#include<iostream>
#include<math.h>

using namespace std;

int main(void)
{
	double input;
	while(cin>>input)
	{
		for(int i=0;;i++)
		{
			double t=sqrt((5*i-5)/4.9);
			if(9.8*t>input)
			{
				cout<<i<<endl;
				break;
			}
		}
	}
}

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

int main() {
  int x[5], result;
  for(int i=0;i<5;i++) {
	cin >> x[i];
    if (x[i] == 0) {
      result = i;
    }
  }
  result++;
  cout << result << endl;
  return 0;
}




Measured memory_bytes: 3516
#include <iostream>
#define endl '\n'

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string str1, str2; cin >> str1 >> str2;
    sort(str1.begin(), str1.end());
    sort(str2.begin(), str2.end(), greater<char>());
    if(str1 < str2)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int gi() { 
	int res = 0, w = 1; 
	char ch = getchar(); 
	while (ch != '-' && !isdigit(ch)) ch = getchar(); 
	if (ch == '-') w = -1, ch = getchar(); 
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); 
	return res * w; 
} 
const int MAX_N = 3e5 + 5; 
int N, a[MAX_N]; 

int main () { 
#ifndef ONLINE_JUDGE 
    freopen("cpp.in", "r", stdin); 
#endif 
	N = gi(); 
	for (int i = 1; i <= 3 * N; i++) a[i] = gi(); 
	sort(&a[1], &a[3 * N + 1], greater<int>()); 
	long long ans = 0; 
	for (int i = 1; i <= N; i++) ans += a[i << 1];
	printf("%lld\n", ans); 
    return 0; 
} 

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

string c = "zabcdefghijklmnopqrstuvwxy";

int main(){
    LL n;cin >> n;
    string ans = "";
    while(n){
        ans += c[n % 26];
        n = (n - 1) / 26;
    }
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
n = int(input())
h = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for _ in range(n):
    b, f, r, v = [int(e) for e in input().split()]
    h[b-1][f-1][r-1] += v
for i, b in enumerate(h):
    if i != 0:
        print('#'*20)
    for f in b:
        print(' ', end='')
        print(*f)

Measured memory_bytes: 7696
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;
typedef std::pair<int, int> P;
struct edge { int to;double cost; };
#define VMAX 1010
int N;
double C[VMAX][VMAX];
double d[VMAX];
bool F[VMAX];
int X[VMAX], Y[VMAX], R[VMAX];
ll ans;

void Dijkstra(int s) {
	std::fill(F, F + N + 2, false);
	//std::fill(d, d + N + 2, INF);
	d[s] = 0;
	while (true) {
		int v = -1;
		REP(i, N+2) {
			if (!F[i] && (v == -1 || d[i]<d[v]))v = i;
		}
		if (v == -1)break;
		F[v] = true;
		REP(i, N+2) {
			d[i] = std::min(d[i], d[v] + C[v][i]);
		}
	}
}

int main() {
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy >> N;
	X[N] = sx, Y[N] = sy, X[N + 1] = gx, Y[N + 1] = gy;
	R[N] = R[N + 1] = 0;
	REP(i, 1002)REP(j, 1002)C[i][j] = INF;
	REP(i, N) {
		cin >> X[i] >> Y[i] >> R[i];
	}
	REP(i, N + 2){REP(j, N + 2) {
		if (i == j) { continue; }
		double temp =
			sqrt(ll(X[i] - X[j])*ll(X[i] - X[j]) + ll(Y[i] - Y[j])*ll(Y[i] - Y[j]));
        if(temp<=R[i]+R[j]){C[i][j]=0;}
	    else C[i][j] = temp- R[i] - R[j];
		/*DEB(X[i])DEB(X[j])DEB(Y[i])DEB(Y[j])*/DEB(C[i][j])
	}END}
    std::fill(d, d + N + 2, INF);
	Dijkstra(N);
    //Dijkstra(N);
	printf("%.10lf\n", d[N + 1]);
	return 0;
}


Measured memory_bytes: 8192
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define P(p) cout << (p) << endl;
#define PP(p) cout << (p) << " ";
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
// int dy[8]={1,1,1,0,-1,-1,-1,0};
// int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int n, m, q;
int a[51], b[51], c[51], d[51];
int ans = 0;

// dfs(index,vi,r,func) vi からr個の配列
vector<int> res(150);  // res
vector<int> v;    //元はソート済
void f(vi indexes) {
    int tmp = 0;
    rep(i,q){
        if((indexes[b[i]] - indexes[a[i]] )== c[i]){
            tmp += d[i];
        }
    }
    ans = max(ans,tmp);
}
void dfs(int i, vector<int> res, int r) {
    if (i == (r)) {
        f(res);
    } else {
        for (int j = 0; j < v.size(); j++) {
            if (i > 0 && res[i-1] > v[j]) {
              //  cout << *res.end() << endl;
                continue;
            }
            res[i] = v[j];
            dfs(i + 1, res, r);
        }
    }
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    rep(i, m) { 
        v.push_back(i + 1);
    }

    dfs(0, res, n);
    cout << ans << endl;
    return 0;
}


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

int main() {
    //
    long long num;
    long long tmp, tmp2;
    long long cnt1 = 0;
    long long cnt2 = 0;
    string kekka = "";
    vector<int> vec2;

    vector<string> vec(27);
    vec = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
           "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    cin >> num;

    while (true) {
        //
        tmp = (num - 1) / 26;
        tmp2 = (num - 1) % 26;

        vec2.push_back(tmp2);

        if (tmp == 0) break;
        // kekka += vec.at(tmp % 26);
        num = tmp;
        cnt1++;
    }

    // kekka += vec.at(tmp2);
    for (int i = vec2.size() - 1; i >= 0; i--) {
        //
        kekka += vec.at(vec2.at(i));
    }
    cout << kekka;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
	int n;
	scanf("%d",&n);
	int i;
	for(i=0; i<n; i++) scanf("%d",&a[i]);
	int m;
	scanf("%d",&m);
	while(m--)
	{
		int x;
		scanf("%d",&x);
		printf("%d\n",lower_bound(a, a+n, x) - a);
	}
	return 0;
}


Measured memory_bytes: 3620
// ------------------------------------
// Date:2018/ 3/ 7
// Problem:ABC 076 DubioutsDocument2 c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

static const int MOD = 1000000007;

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

  string s, t, tmp;
  cin >> s >> t;

  bool ok = false;
  bool flag;
  int cnt = 0;
  REP(si, s.size() - t.size() + 1) {
    flag = true;
    REP(ti, t.size()) {
      if (not(s[si + ti] == t[ti] or s[si + ti] == '?')) flag = false;
    }
    if (flag) {
      cnt = si;
      ok = true;
    }
  }
  REP(ti, t.size()) {
    s[ti + cnt] = t[ti];
  }
  REP(si, s.size()) {
    if (s[si] == '?') {
      s[si] = 'a';
    }
  }

  string ans;
  if (!ok) {
    ans = "UNRESTORABLE";
  } else {
    ans = s;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
def main():
    _ = input()
    ts = list(map(int, input().split()))
    t = sum(ts)
    m = int(input())
    for _ in range(m):
        p, x = map(int, input().split())
        p -= 1
        print(t - ts[p] + x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
using namespace std;
int n, c, v[555555], mem[555555];
void solve(int l, int r) {
	if(r - l == 1) return; c += r - l;
	solve(l, (l + r) / 2);
	solve((l + r) / 2, r);
	merge(v + l, v + (l + r) / 2, v + (l + r) / 2, v + r, mem);
	for(int i = l; i < r; i++) v[i] = mem[i - l];
}
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &v[i]);
	solve(0, n);
	for(int i = 0; i < n; i++) {
		if(i) putchar(' ');
		printf("%d", v[i]);
	}
	printf("\n%d\n", c);
}

Measured memory_bytes: 7040
// D - Partition

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int N, M;
	cin >> N >> M;

	if (N == 1) {
		cout << M << endl;
		return 0;
	}

	int ans = 1;

	for (int i=1; i*i<=M; i++) {
		if (M % i == 0) {
			int j = M / i;
			 if (M / i >= N) ans = max(ans, i);
			 if (M / j >= N) ans = max(ans, j);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3576
#include<vector>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll w[100],v[100];
const ll INF=1e18;

ll ks(ll n,ll W){
  ll p=0;
  for(int i=0;i<n;i++) p+=v[i];
  vector<ll> dp(p+1,INF);
  dp[0]=0;
  for(int i=0;i<n;i++)
     for(int j=p;j>=v[i];j--)
     	 dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
  ll answer=0;
  for(ll i=0;i<=p;i++)
    if(dp[i]<=W)
       answer=max(answer,i);
  return answer;
}


int main(){
  ll n,W;
  cin>>n>>W;
  for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
  cout<<ks(n,W)<<endl;
 return 0; 
}


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

int main(){
    int N;
    cin >> N;
    int a[3] = {};
    for(int i = 0; i < N; ++i){
        int p;
        cin >> p;
        if(p % 4 == 0){
            a[2]++;
        }else if(p % 2 == 0){
            a[1]++;
        }else{
            a[0]++;
        }
    }

    if(a[2] + 1 <= a[0]){
        if(a[2] + 1 == a[0] && a[2] + a[0] == N){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }else{
        cout << "Yes\n";
    }
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c; 
    if(b/a > c){
        cout << c;
    }
    else{
        cout << b/a;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=15;
int r[N],p[N],c[N],a[N][N];
int n,m,ans;
void go(int k)
{
    if(k==n)
    {
        bool can=true;
        for(int i=0;i<m;i++)
        {
            int cnt=0;
            for(int j=0;j<r[i];j++)
                if(c[a[i][j]]==1)
                    cnt++;
            if(cnt%2!=p[i])
                can=false;
        }
        if(can)
            ans++;
        return;
    }
    c[k]=0;
    go(k+1);
    c[k]=1;
    go(k+1);
    return;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>r[i];
        for(int j=0;j<r[i];j++)
        {
            cin>>a[i][j];
            a[i][j]--;
        }
    }
    for(int i=0;i<m;i++)
        cin>>p[i];
    go(0);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())

arr = map(int,raw_input().split())

arr.sort()

i = n-1

lines = []

while i > 0 and len(lines) < 2:
	if arr[i] == arr[i-1]:
		lines.append(arr[i])
		i -= 2
		next

	else :
		i -= 1

if len(lines) == 2:
	print lines[0] * lines[1]

else :
	print 0

Measured memory_bytes: 11320
#include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace std;
    using namespace __gnu_pbds; 
    #define lli long long int
    #define fr(i,a,b) for(lli i=a;i<b;i++)
    #define bfr(i,a,b) for(lli i=a;i>=b;i--)
    #define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
    #define tc int t;cin>>t;while(t--)
    #define mod 1000000007LL
    #define mod2 998244353LL
    #define all(vec) vec.begin(),vec.end()  
    #define ld long double
    #define pb push_back

    #define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 



    int main()
    {
                           
             

                        
              fio

              lli n,sum=0;
              cin>>n;
              fr(i,1,n+1)
              if(i%3==0 || i%5==0);
              else sum+=i;
              cout<<sum;
              
return 0;}

Measured memory_bytes: 3648
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(16);

    int t, x;
    cin >> t >> x;


    long double res = t;
    res /= x;

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll=long long;
using db=double;
///***************************************************** CONSTANTS ******************************************************///

int const N=1e6+3;
ll MOD=1e9+7,fact[N];
const long long inf=(long long)1e18;
const long double PI=3.14159265358979;

///************************************************ CONTAINER DEFINITIONS ***********************************************///

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///************************************************ SHORT FORM KEYWORDS *************************************************///

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define I insert
#define lb lower_bound
#define ub upper_bound
#define endl '\n'

///************************************************ SHORT FORM FUNCTIONS ************************************************///

#define loop(a,b) for(ll i=a;i<b;i++)
#define loopr(a,b) for(ll i=a-1;i>=b;i--)
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define stll(x) stoll(x, nullptr, 10);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define all(a) a.begin(),a.end()
#define mxa(a,N) *max_element(a,a+N)
#define mna(a,N) *min_element(a,a+N)
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


///************************************************ SOLUTION STARTS HERE ************************************************///
///======================================================================================================================///

void solve(){
   ll n;
   cin>>n;
   string s="abcdefghijklmnopqrstuvwxyz";
   string ss="";
   while(n!=0){
    n--;
    ss+=s[n%26];
    n/=26;
   }
   rev(ss);
   cout<<ss<<endl;
}
int main()
{
    io();
    int T=1;//cin>>T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll I,O,T,J,L,S,Z;
  cin >> I >> O >> T >> J >> L >> S >> Z;
  ll ans = 0;
  // O
  ans += O;
  // I,J,L
  vector<ll> a(3);
  a[0] = I; a[1] = J; a[2] = L;
  ll odd = 0;
  REP(i,3) odd += (a[i]%2==1);
  if(odd==3){
    ans += 3;
    REP(i,3) ans += 2*(a[i]/2);
  }else if(odd==1 || odd == 0){
    REP(i,3) ans += 2*(a[i]/2);
  }else{
    bool f = true;
    REP(i,3) if(a[i]==0) f = false;
    if(f) ans += 3;
    REP(i,3) {
      if(a[i]%2==1) ans += 2*(a[i]/2);
      else ans += 2*max(a[i]/2 - 1,0LL);
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int solve()
{
    long long n, s;
    cin >> n >> s;

    if (s == n)
    {
        cout << n + 1 << endl;
        return 0;
    }
    if (s > n)
    {
        cout << -1 << endl;
        return 0;
    }

    long long b;
    for (b = 2; b * b <= n; ++b)
    {
        long long sum = 0;
        long long value = n;
        while (value != 0)
        {
            sum += value % b;
            value /= b;
        }
        if (sum == s)
        {
            cout << b << endl;
            return 0;
        }
    }


    for (long long div = n / b; div > 0; --div)
    {
        long long current = n / div;
        long long next = n / (div + 1);
        long long max = n - (next + 1) * div;
        long long mod = n % current;
        if (s != mod && s <= (max + div) && (s - mod) % div == 0)
        {
            cout << current - (s - mod) / div + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

int main()
{
    solve();
    system("pause");
    return 0;
}

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

int calc_digit_sum(string &num_str)
{
  int sum = 0;
  for (char c : num_str)
  {
    sum += c - '0';
  }
  return sum;
}

int main()
{
  while (true)
  {
    string num_str;
    cin >> num_str;
    if (num_str == "0"s)
    {
      break;
    }
    cout << calc_digit_sum(num_str) << endl;
  }
}


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

int n;
vector<int> l;
int ans;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    for(int i = 2; i < n; i++){
        for(int j = 1; j < i; j++){
            int k = lower_bound(l.begin(),l.end(),l[i]-l[j] + 1) - l.begin();
            if(k >= j) continue;
            ans += j - k;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;

  string s;
  cin >> s;

  vector<int>check(26,1);

  long ans = 1;
  for(int j=0;j<N;j++){
    check[s[j] - 'a']++;
  }

  for(int i=0;i<26;i++){
    ans *= check[i];
    ans %= 1000000007;
  }

  cout << ans - 1 << endl;

  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int H = scanner.nextInt();
        int A = scanner.nextInt();

        if (H % A == 0) {
            System.out.println(H / A);
        } else {
            System.out.println(H / A + 1);
        }
    }
}


Measured memory_bytes: 35604
//Only the Creator has given me strength!🖤
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<cstring>

typedef long long ll;



using namespace std;
void fastio() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
    fastio();
    int s;
    ll g=0;
    string a;
    cin>>s>>a;
    ll c[90]={0},k,l;
    for(int i=0; i<s; i++) {
        c[a[i]]++;
        for(int j=0; j<s; j++) {
            k=2*j+i;
            l=j+i;
            if(k>=s) break;
            if(a[i]!=a[l] && a[i]!=a[k] && a[l]!=a[k])
                g++;
        }
    }
    ll ans=c['R']*c['G']*c['B']-g;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();
		int ans = (L*2+N-1)*N/2;
		int min = Integer.MAX_VALUE;
		int pick = 0;
		for(int i = 0; i < N; i++) {
			if(Math.abs(L+i) < min) {
				min = Math.abs(L+i);
				pick = L+i;
			}
		}
		System.out.println(ans-pick);
	}

}

Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    int count = 0;
    rep(i,S.length()) {
        if (S[i]==T[i]) {
            count++;
        }
    }
    if (S.length() == count)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3580
x, n, *p = map(int, open(0).read().split())
ans1 = x
while ans1 in p:
    ans1 += 1
ans2 = x
while ans2 in p:
    ans2 -= 1

if abs(ans2-x) < abs(ans1-x):
    print(ans2)
elif abs(ans2-x) > abs(ans1 - x):
    print(ans1)
else:
    print(min(ans1,ans2))

Measured memory_bytes: 9216
def n_based(n:int, base:int) -> str:
    if n == 0:
        return "0"
    
    ans = ""
    res = n
    
    while abs(res) > 0:
        q = res%base
        if q>=0:
            ans = str(q) + ans
            res //= base
        else:
            q += abs(base)
            ans = str(q) + ans
            res //= base
            res += 1
        
    return ans

N = int(input())
print(n_based(N, -2))

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N; cin >> N;
	LL ans = 0, ansi = 1;
	FOR(i, 1, N + 1) {
		LL cnt = 0;
		LL b = i;
		while (b % 2 == 0) {
			b /= 2;
			cnt++;
		}
		if (ans < cnt) {
			ans = cnt;
			ansi = i;
		}
	}


	cout << ansi << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int n;
ll dp[110][4][4][4];
int main()
{
    scanf("%d",&n);
    dp[0][3][3][3]=1;
    for(int i=0;i<=n;i++){
        for(int c1=0;c1<4;c1++){
            for(int c2=0;c2<4;c2++){
                for(int c3=0;c3<4;c3++){
                    if(dp[i][c1][c2][c3]==0) continue;
                    for(int a=0;a<4;a++){
                        if(a==1&&c1==2&&c2==0) continue;
                        if(a==1&&c1==0&&c2==2) continue;
                        if(a==2&&c1==1&&c2==0) continue;
                        if(a==1&&c1==2&&c3==0) continue;
                        if(a==1&&c2==2&&c3==0) continue;
                        dp[i+1][a][c1][c2]+=dp[i][c1][c2][c3];
                        dp[i+1][a][c1][c2]%=mod;
                    }
                }
            }
        }
    }
    ll ans=0;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                ans+=dp[n][i][j][k];
                ans%=mod;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef std::vector<ll> lls;

void cinv(lls& llVec, ll n) {
	ll val;
	llVec.reserve((size_t)(n));
	for (ll i = 0; i < n; i++) {
		cin >> val;
		llVec.push_back(val);
	}
}


int main()
{
	ll N;
	cin >> N;
	lls H;
	cinv(H, N);

	ll minH = H[N - 1];
	for (ll i=N-2; i>=0; i--){
		if (H[i] >= minH + 2) {
			cout << "No" << '\n';
			return 0;
		}
		minH = std::min(minH, H[i]);
	}

	cout << "Yes" << '\n';

	return 0;
}



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

int main()
{
  string s;
  cin >> s;
  string S = s;
  reverse(s.begin(), s.end());
  if (s == S)
  {
  	string mae, usiro, maecheck, usirocheck;
  	int check1 = (s.size() - 1) / 2;
  	int check2 = (s.size() + 3) / 2;
  	for (int i = 0; i < check1; i++)
  	{
   		mae += s[i];
    	maecheck += s[i];
  	}
  	for (int i = check2 - 1; i < s.size(); i++)
  	{
    	usiro += s[i];
    	usirocheck += s[i];
  	}
  	reverse(mae.begin(), mae.end());
  	reverse(usiro.begin(), usiro.end());
  
  	//cout << usiro  << ";"<< usirocheck << endl;
  	if(mae == maecheck && usiro == usirocheck)
  	{
    	cout << "Yes" << endl;
  	}
  	else
  	{
    	cout << "No" << endl;
  	}
  }
  else
  {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
def congruence(x, y): #=(a, b) such that ax+by=gcd(x,y)
  if x < y:
    (a, b) = congruence(y, x)
    return (b, a)
  z = x % y
  if z == 0:
    return (0, 1)
  (c, d) = congruence(y, z)
  return (d, (c - int(x / y) * d) % 1000000007)

inverse_sum = {1: 1}
for i in range(2, 100001):
  inverse_sum[i] = (inverse_sum[i - 1] + congruence(1000000007, i)[1]) % 1000000007

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

N_factorial = 1
for i in range(1, N + 1):
  N_factorial = (N_factorial * i) % 1000000007

ans = 0
for i in range(N):
  ans = (ans + (inverse_sum[i + 1] + inverse_sum[N - i] - 1) * A[i] * N_factorial) % 1000000007

print(ans)

Measured memory_bytes: 27540
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 100000007;
const int INF = 1 << 29;
const double EPS = 1e-9;


int main() {

	cin.tie(0);

	int a[5], k;
	FOR(i,0,5) cin >> a[i];
	cin >> k;

	FOR(i, 0, 5)FOR(j, 0, 5) {
		if (a[i] - a[j] > k) {
			cout << ":(";
			return 0;
		}
	}
	cout << "Yay!";
	return 0;
}

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

int toi(char a){
    return a - '0';
}

int main(){
    int n; cin >> n;
    int k; cin >> k;
    vector<int> flag(10, 0);
    for(int i = 0; i < k; i++){
        int a; cin >> a;
        flag[a] = 1;
    }
    int ans = 100000;
    for(int i = 100000; i >= n; i--){
        string s = to_string(i);
        int f = 0;
        for(int l = 0; l < s.size(); l++){
            if(flag[toi(s[l])] == 1){
                f = 1;
                break;
            }
        }
        if(f == 1){continue;}
        else{
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printans(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var a, b, c int
	fmt.Fscan(read, &a, &b, &c)
	printans(a+b+c >= 22, "bust", "win")
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int dp[1001][1001];
char arr[1001][1001];
int flag[1001][1001];
int h,w;
int m=1e9+7;
signed  main()
{
    cin>>h>>w;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin>>arr[i][j];
            if(arr[i][j]=='#')
            {
            flag[i][j]=-1;
            dp[i][j]=0;
            }

        }

    }

    for(int i=1;i<=h;i++)
    {
        if (arr[i][1]=='#')
        {
        for(int j=i;j<=h;j++)
            {
                flag[j][1]=-1;
                dp[j][1]=0;
            }
        }
    }
    
    for(int i=1;i<=w;i++)
    {
        if(arr[1][i]=='#')
        {
            for(int j=i;j<=w;j++)
            {
                flag[1][j]=-1;
                dp[1][j]=0;
            }
        }

    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {

            if(i==1||j==1)
            {
              if(flag[i][j]==0)
              dp[i][j]=1;
              else dp[i][j]=0;

            }

            else if(flag[i][j]!=-1)
            {
                dp[i][j]=(dp[i-1][j]%m+dp[i][j-1]%m)%m;
                
            }
            else if(flag[i][j]==-1)
            dp[i][j]=0;
            
        
        
        
        }
    }
 /*   for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cout<<dp[i][j];
        }
        cout<<"\n";    
        }
        */
        cout<<dp[h][w];
}

Measured memory_bytes: 16896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static final int INF = (int) 1e9;
    static int n, m, k;
    static char[][] bar;
    static int c, group[];

    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        bar = new char[n][];
        for (int i = 0; i < n; i++)
            bar[i] = sc.next().toCharArray();
        group = new int[n];
        int ans = INF;
        for (int mask = 0; mask < 1 << (n - 1); mask++) {
            c = Integer.bitCount(mask) + 1;
            int g = 0;
            for (int i = 0; i < n - 1; i++) {
                group[i] = g;
                if ((mask & 1 << i) != 0) g++;
            }
            group[n - 1] = g;
            ans = Math.min(ans, c - 1 + solve());
        }
        out.println(ans);
        out.flush();
        out.close();
    }

    static int solve() {
        int cuts = 0;
        int[] cnt = new int[c], extra = new int[c];
        for (int j = 0; j < m; j++) {
            boolean needcut = false;
            for (int i = 0; i < n; i++)
                if (bar[i][j] == '1') {
                    extra[group[i]]++;
                    if (extra[group[i]] > k) return INF;
                    if (cnt[group[i]] + extra[group[i]] > k) needcut = true;
                }
            if (needcut) cuts++;
            for (int i = 0; i < c; i++) {
                if (needcut) cnt[i] = 0;
                cnt[i] += extra[i];
                extra[i] = 0;
            }
        }
        return cuts;
    }


    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        boolean ready() throws IOException {
            return br.ready();
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        int nextChar() throws IOException {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

    }
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
int n,m;
int ax[55],ay[55],bx[55],by[55];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++)
		scanf("%d%d",&ax[i],&ay[i]);
	for(int j=1; j<=m; j++)
		scanf("%d%d",&bx[j],&by[j]);
	for(int i=1; i<=n; i++){
		int bes = 1000000000, id = -1;
		for(int j=1; j<=m; j++){
			int now = labs(bx[j]-ax[i]) + labs(by[j]-ay[i]);
			if(now < bes){
				bes = now;
				id = j;
			}
		}
		printf("%d\n",id);
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())

x = [0] * N
y = [0] * N
h = [0] * N

for i in range(N):
    xyh = list(map(int, input().split()))
    x[i] = xyh[0]
    y[i] = xyh[1]
    h[i] = xyh[2]
    if xyh[2] != 0:
        Cx = xyh[0]
        Cy = xyh[1]
        CH = xyh[2]

for i in range(101):
    for j in range(101):
        flag = True
        H = CH + abs(i - Cx) + abs(j - Cy)
        for k in range(N):
            if h[k] != max(H - abs(i - x[k]) - abs(j - y[k]), 0):
                flag = False
                break
        if flag:
            print(i, j, H)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  VI h(n);
  rep(i,n) cin >> h[i];
  
  bool flag=true;
  
  rep(i,n-1){
    int x = (n-1)-i;
    if(h[x-1] > h[x]) h[x-1]--;
    if(h[x-1] > h[x]){
      flag = false;
      break;
    }
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
   
  return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, K, L = list(map(int, input().split()))
uf_road = UnionFind(N)
uf_train = UnionFind(N)

for i in range(K):
    node1, node2 = map(int, input().split())
    uf_road.union(node1 - 1, node2 - 1)

for i in range(L):
    node1, node2 = map(int, input().split())
    uf_train.union(node1 - 1, node2 - 1)

# 全メンバ列挙は遅い
# ans = [len(set(uf_road.members(i)) & set(uf_train.members(i))) for i in range(N)]
d = defaultdict(int)
for i in range(N):
    d[uf_road.find(i), uf_train.find(i)] += 1
print(*(d[uf_road.find(i), uf_train.find(i)] for i in range(N)))


Measured memory_bytes: 105180