akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

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


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

struct Graph {
    Graph(ll n)
    {
        edge.resize(n);
    }
    void addEdge(ll from, ll to)
    {
        edge[from].push_back(to);
    }
    vector<vector<ll>> edge;
};

ll N;
pair<ll, ll> dfs(const Graph& g, ll s, const vector<bool>& cycle, vector<ll>& value)
{
    multiset<ll> st;
    for (const ll p : g.edge[s]) {
        if (cycle[p]) {
            continue;
        }
        const ll child = dfs(g, p, cycle, value).first;
        st.insert(child);
    }
    ll first = -1;
    ll second = -1;
    for (ll i = 0; i <= 2 * N; i++) {
        if (st.find(i) == st.end()) {
            if (first == -1) {
                first = i;
            } else if (second == -1) {
                second = i;
                break;
            }
        }
    }
    value[s] = first;
    assert(first >= 0 and second > first);
    return make_pair(first, second);
}

int main()
{
    cin >> N;
    Graph g(N);
    Graph rev(N);

    for (ll i = 0; i < N; i++) {
        ll from;
        cin >> from;
        from--;
        g.addEdge(from, i);
        rev.addEdge(i, from);
    }

    ll pos = 0;
    for (ll i = 0; i < 2 * N; i++) {
        pos = rev.edge[pos][0];
    }
    vector<bool> cycle(N, false);
    vector<ll> comp;
    for (ll i = 0; i < 2 * N; i++) {
        if (cycle[pos]) {
            break;
        }
        comp.push_back(pos);
        cycle[pos] = true;
        pos = rev.edge[pos][0];
    }
    const ll size = comp.size();

    for (ll i = 1; i < size; i++) {
        assert(rev.edge[comp[i - 1]][0] == comp[i]);
    }
    assert(rev.edge[comp[size - 1]][0] == comp[0]);

    vector<ll> value(N, 0);
    const auto pi = dfs(g, comp[0], cycle, value);

    for (ll d = 0; d < 2; d++) {
        ll prev = (d == 0) ? pi.first : pi.second;
        const ll start = prev;
        for (ll i = 1; i <= size; i++) {
            const ll ind = (i == size) ? 0 : i;
            const ll p = comp[ind];
            const auto q = dfs(g, p, cycle, value);
            prev = (q.first == prev) ? q.second : q.first;
            value[comp[ind]] = prev;
        }
        if (start == value[comp[0]]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}


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

if N%2 == 0:
  B = list(range(N-1,0,-2))+list(range(1,N,2))
else:
  B = list(range(N-1,0,-2))+list(range(0,N,2))

if Counter(A) != Counter(B):
  print(0)
else:
  mod = 10**9+7
  print(2**(N//2)%mod)

Measured memory_bytes: 20704
N = int(input())
ans = n_BA = n_A = n_B = n_others = 0
for i in range(N):
    s = input()
    ans += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        n_BA += 1
    elif s[0] == 'B':
        n_B += 1
    elif s[-1] == 'A':
        n_A += 1
    else:
        n_others += 1

if n_BA >= 1:
    ans += n_BA - 1
    if n_A >= 1:
        n_A -= 1
        ans += 1
    if n_B >= 1:
        n_B -= 1
        ans += 1
ans += min(n_A, n_B)
print(ans)


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

int main() {
vector<int> vec(5);
int A = 10;
int ans = 0;

for (int i = 0; i < 5; i++) {
  cin >> vec.at(i);
  if (vec.at(i) % 10 != 0) {
    A = min(A, vec.at(i) % 10);
    ans += vec.at(i) / 10 * 10 + 10;
  }
  else ans += vec.at(i);
}

if (A == 10) cout << ans << endl;
else cout << ans - (10 - A) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] vec = new int[n];
        for (int i = 0; i < n; i++) {
            vec[i] = sc.nextInt();
        }
        int ans = 0;
        Arrays.sort(vec);
        for (int i = 2; i < n; i++) {
            int l = 0, r = i - 1;
            while(l < r) {
                if (vec[l] + vec[r] > vec[i]) {
                    ans += (r - l);
                    --r;
                } else {
                    ++l;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 28484
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		int n=sc.nextInt();
		int m=sc.nextInt();
		int k=sc.nextInt();
		int [] a=new int [k];
		for(int i=0;i<k;i++)
			a[i]=sc.nextInt();
		int p=0;
		int [][] ans=new int [n][m];
		boolean e=true;
		for(int i=0;i<n;i++){
			if(e){
				for(int j=0;j<m;j++){
					ans[i][j]=p+1;
					a[p]--;
					if(a[p]==0)
						p++;
				}
			}else{
				for(int j=m-1;j>=0;j--){
					ans[i][j]=p+1;
					a[p]--;
					if(a[p]==0)
						p++;
				}
			}
			e=!e;
		}
		
		
		for(int i=0;i<n;i++){
			boolean f=true;
			for(int j : ans[i]){
				if(!f)
					pw.print(" ");
				pw.print(j);
				f=false;
			}
			pw.println();
		}
		pw.flush();
		pw.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}

Measured memory_bytes: 22100
# -*- coding: utf-8 -*-
#ABC136C
import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
minhoge=hoge[n-1]
for i in range(1,n):
	t=n-1-i
	if(hoge[t]>minhoge+1):
		print("No")
		sys.exit()
	elif(hoge[t]<minhoge):
		minhoge=hoge[t]
	if(t==0):
		print("Yes")
		sys.exit()
print("Yes")





Measured memory_bytes: 14908
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n,x;
	cin >> n >> x;
	ll p[100],b[100],pb[100];
	p[0]=1;b[0]=0;pb[0]=1;
	for(int i=1;i<=n;i++){
		p[i]=p[i-1]*2+1;
		b[i]=b[i-1]*2+2;
		pb[i]=p[i]+b[i];
	}
	ll sum=0,ans=0,cnt=n;
	while(sum!=x){
		if(sum+pb[cnt]<=x){
			sum+=pb[cnt];
			ans+=p[cnt];
			if(sum+1<=x){
				sum++;
				ans++;
			}
		}else{
			cnt--;
			sum++;
		}
	}

	cout << ans << endl;


}

Measured memory_bytes: 256
N = int(input())
nodes = {}
for _ in range(N-1):
    l, r, d = map(int, input().split())
    if nodes.get(str(l)) is None:
        nodes[str(l)] = {'to': [], 'color': -1}
    if nodes.get(str(r)) is None:
        nodes[str(r)] = {'to': [], 'color': -1}

    nodes[str(l)]['to'].append((str(r), d))
    nodes[str(r)]['to'].append((str(l), d))

q = [('1', 0)]
while q:
    node, color = q.pop()

    nodes[node]['color'] = color
    for n, d in nodes[node]['to']:
        if nodes[n]['color'] != -1:
            continue

        if d % 2 == 0:
            q.append((n, color))
        else:
            q.append((n, (color+1) % 2))


for i in range(1, N+1):
    print(nodes[str(i)]['color'])


Measured memory_bytes: 123864
// Try Exawizards 2019
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let ans = get()
    	.as_bytes()
        .iter()
        .filter(|&ch| *ch == b'R')
        .collect::<Vec<_>>()
        .len();
        
	if ans + ans > n {
    	println!("Yes");
    } else {
    	println!("No");
    }
}

Measured memory_bytes: 4352
R, G, B, N = map(int, input().split())

ans = 0
for r in range((N + R - 1) // R + 1):
    for g in range((N + G - 1) // G + 1):
        if (N - r * R - g * G) % B > 0: continue
        b = (N - r * R - g * G) // B
        if 0 <= r and 0 <= g and 0 <= b:
            ans += 1

print(ans)

Measured memory_bytes: 41036
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] ab = new int[n][2];
        int sum = 0;
        PriorityQueue<Integer> candidate = new PriorityQueue<Integer>(Collections.reverseOrder());

        for (int i = 0; i < n; i++) {
            ab[i][0] = scanner.nextInt();
            ab[i][1] = scanner.nextInt();
        }

        Arrays.sort(ab, Comparator.comparingInt(a -> a[0]));

        int j = 0;
        for (int i = 1; i <= m; i++) {
            while (j< n && ab[j][0] == i) {
                candidate.add(ab[j][1]);
                j++;
            }

            if (!candidate.isEmpty()) {
                sum += candidate.poll();
            }
        }
        System.out.println(sum);

    }

}



Measured memory_bytes: 92964
for _ in range(input()):
	s = raw_input()
	cur = 0
	for __ in range(input()):
		cmd = raw_input()
		if   cmd == "forward char":
			cur = min(len(s),cur+1)
			
		elif cmd == "forward word":
			while cur < len(s) and s[cur] == " ": cur+=1
			while cur < len(s) and s[cur] != " ": cur+=1
				
		elif cmd == "backward char":
			cur = max(0,cur-1)
			
		elif cmd == "backward word":
			while cur > 0 and s[cur-1] == " ": cur-=1
			while cur > 0 and s[cur-1] != " ": cur-=1
			
		elif cmd == "delete char":
			s = s[:cur] + s[cur+1:]
			
		elif cmd == "delete word":
			if s[cur:].count(" ") == len(s[cur:]): continue
			while cur < len(s) and s[cur] == " ": s = s[:cur] + s[cur+1:]
			while cur < len(s) and s[cur] != " ": s = s[:cur] + s[cur+1:]
			
		elif cmd[:6] == "insert":
			s = s[:cur] + cmd[8:-1] + s[cur:]
			cur += len(cmd[8:-1])

	print s[:cur] + "^" + s[cur:]

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int mod = 1e9+7;
const int maxn = 200005;
int f[maxn];
int invf[maxn];
int fa[maxn];
int fb[maxn];
int fab[maxn];
int invfab[maxn];
int inv100_C;

int N,A,B,C;

int mult(int a,int b){
    LL res = a;
    res *= b;
    res%=mod;
    return (int)res;
}

int add(int a,int b){
    LL ans = a;
    ans += b;
    ans %= mod;
    return (int)ans;
}

int fpow(int a,int p){
    if(p == 0) return 1;
    int ans = fpow(a,p/2);
    ans = mult(ans,ans);
    if(p&1) ans = mult(ans,a);
    return ans;
}

int com(int a,int b){
    if(a < b) return 0;
    if(b == 0) return 1;
    return mult(invf[a-b],mult(f[a],invf[b]));
}

void init(){
    inv100_C = fpow(100-C,mod-2);
    f[0] = 1;fa[0] = 1;fb[0] = 1;fab[0] = 1;

    _for(i,1,maxn){
        f[i] = mult(f[i-1],i);
        fa[i] = mult(fa[i-1],A);
        fb[i] = mult(fb[i-1],B);
        fab[i] = mult(fab[i-1],A+B);
    }

    invf[maxn-1] = fpow(f[maxn-1],mod-2);
    invfab[maxn-1] = fpow(fab[maxn-1],mod-2);

    for(int i = maxn-2;i >= 0;i--){
        invf[i] = mult(invf[i+1],i+1);
        invfab[i] = mult(invfab[i+1],A+B);
    }
}

int main()
{
    cin >> N >> A >> B >> C;
    init();
    LL ans = 0;
    _for(i,0,N){
        int cb = com(N+i-1,i);
        int temp = mult(cb,invfab[N+i]);

        int ab = add(mult(fa[N],fb[i]),mult(fb[N],fa[i]));
        ab = mult(ab,N+i);

        temp = mult(temp,ab);
        ans = add(ans,temp);
    }
   // cout << ans << endl;
    ans = mult(ans,100);
    //cout << com(6,3) << endl;
    ans = mult(ans,inv100_C);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
k,x=(int(x) for x in input().split())

syou=x-k+1
dai=x+k
if syou>=-1000000:
    if dai<=1000000:
        llist=list(range(syou,dai,1))
    else:
        llist=list(range(syou,1000000,1))
else:
    if dai<=1000000:
        llist=list(range(-1000000,dai,1))
    else:
        llist=list(range(-100000,1000000,1))
for n in range(len(llist)):
    llist[n]=str(llist[n])
print(' '.join(llist))


Measured memory_bytes: 3064
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B, C, D;
    scan(A, B, C, D);
    // writefln("%d %d %d %d", A, B, C, D);
    writeln((min(B, D) - max(A, C)).max(0));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long N, M, Q, ans = 0;
vector<vector<long>> datax(50, vector<long>(4));
void dfs(long co, vector<long> bin){
  long sub = 0;
  if(co < N){
    for(int i = bin[co - 1]; i <= M; i++){
      bin[co] = i;
      dfs(co + 1, bin);
    }
  } else if(co == N){
    for(int i = 0; i < Q; i++){
      if(bin.at(datax.at(i).at(1) - 1) - bin.at(datax.at(i).at(0) - 1) == datax.at(i).at(2)){
        sub += datax.at(i).at(3);
      }
    }
    ans = max(ans, sub);
  }
}
int main () {
  cin >> N >> M >> Q;
  for(int i = 0; i < Q; i++){
    for(int j = 0; j < 4; j++){
      cin >> datax.at(i).at(j);
    }
  }
  vector<long> bin(10);
  for(int i = 1; i <= M; i++){
    bin[0] = i;
    dfs(1, bin);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>

int main(void)
{
  int stack[10];
  int num = 0;
  int buf;
  int i;

  while (scanf("%d", &buf) != EOF) {
    if (buf != 0) {
      stack[num] = buf;
      num++;
    } else {
      num--;
      printf("%d\n", stack[num]);
    }
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define MAX_W 1000

int main()
{
    int H, W, A, B; cin >> H >> W >> A >> B;
    char ans[MAX_W + 10];
    ans[W] = '\0';
    int row, cmn;
    for (row = 0; row < B; ++row){
        for (cmn = 0; cmn < A; ++cmn)
            ans[cmn] = '0';
        for (cmn = A; cmn < W; ++cmn)
            ans[cmn] = '1';
        puts(ans);
    }
    for (int row = B; row < H; ++row){
        for (cmn = 0; cmn < A; ++cmn)
            ans[cmn] = '1';
        for (cmn = A; cmn < W; ++cmn)
            ans[cmn] = '0';
        puts(ans);
    }

    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
#define MAXN 1010

vi V[MAXN];
int W[MAXN];
int p[MAXN];
int N,a;
int A[MAXN];
int B[MAXN];

void dfs(int x){
	if (SZ(V[x]) == 0){
		A[x] = W[x];
		B[x] = 0;
		return;
	}
  vpi VV;
	for (auto v:V[x])dfs(v);
	for (auto v:V[x])VV.pb(A[v],B[v]);
	int minv=0;
	int tot=0;
	for (auto i:VV){
		minv += min(i.f,i.s);
		tot+=i.f+i.s;
	}
	if (minv > W[x]){
		cout<<"IMPOSSIBLE";exit(0);
	}
	int mem[5010];
	int tar = W[x]-minv;
	memset(mem,0,sizeof(mem));
	mem[0]=1;
	for(auto i:VV){
		int val = max(i.f,i.s)-min(i.f,i.s);
		for (int j=tar;j>=val;--j)if(mem[j-val])mem[j]=1;
	}
	while (!mem[tar])--tar;
	A[x]=W[x];
	B[x]=tot-(tar+minv);
}

int main(){
	cin>>N;
	for (int i=2;i<=N;++i){
		cin>>a;
		V[a].pb(i);
		p[i]=a;
	}
	for (int i=1;i<=N;++i)cin>>W[i];
	dfs(1);
	// for(int i=1;i<=N;++i)cout<<A[i]<<' '<<B[i]<<'\n';
	cout<<"POSSIBLE";	
}

Measured memory_bytes: 8704
package main

import (
  "fmt"
  "sort"
)

func main() {
  // n % 2 == 0: Alice, i % 2 == 1, Bob i % 2 == 0
  // n % 2 == 1: Alice, i % 2 == 0, Bob i % 2 == 1

  n := 0
  fmt.Scan(&n)

  cards := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&cards[i])
  }
  a := 1 - (n % 2)
  alice := 0
  bob := 0
  sort.Sort(sort.IntSlice(cards))
  for i, x := range cards {
    if i % 2 == a {
      alice += x
    } else {
      bob += x
    }
  }
  fmt.Println(alice - bob)
}


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

int main(void){
  int n;
  string str;
  cin >> n >> str;
  long long temp = 1;
  vector<int> arr(26,1);
  for(int i = 0; i < n; i++){
    arr[str[i] - 'a']++;
  }
  for(int i = 0; i < 26; i++){
    temp *= arr[i];
    temp %= 1000000007;
  }
  temp--;
  cout << temp << endl;
  return 0;
}

Measured memory_bytes: 512
N = gets.chomp.to_i
A = []
N.times do |i|
  A << gets.chomp.to_i
end

q = []
A.each do |a|
  if q.empty?
    q << a
  elsif q[-1] < a
    q[-1] = a
  else
    i = q.bsearch_index { |v| v >= a }
    if i.zero?
      q.insert(0, a)
    else
      q[i-1] = a
    end
  end
end
puts q.size


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using it=std::int64_t;

int main(){
    it n;
    cin>>n;
    std::vector<it> h(n);
    for(it i=0;i<n;i++){
        cin>>h[i];
    }

    it high=0,count=0;
    for(it i=0;i<n;i++){
        if(high<=h[i]){
            count++;
            high=h[i];
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map do |x|
  x.to_i
end

counter = 0
s=[]
y = []

until (a.include?(0) == true) or (s.include?(1) == true) do
  a.map do |num|
    y << num/2
    s << num%2
  end
  a.replace(y)
  y.clear
  counter = counter + 1
end

puts (counter - 1)


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

const int INF=1<<30;

int N,M,X;
int A[12][12];
int C[12];

signed main() {
  cin >> N >> M >> X;
  for(int i=0; i<N; i++) {
    cin >> C[i];
    for(int j=0; j<M; j++) cin >> A[i][j];
  }

  int ans = INF;
  for (int bit = 0; bit < (1<<N); ++bit) {
    int cost = 0;
    vector<int> R(M, 0);
    for (int i = 0; i < N; ++i) {
      if (bit & (1<<i)) {
        cost += C[i];
        for(int j=0; j<M; j++) R[j] += A[i][j]; 
      }
    }
    for(int j=0; j<M; j++) if(R[j] < X) cost = INF;
    ans = min(cost, ans);
  }
  if(ans == INF) ans = -1;
  cout << ans << endl;

}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) FILE* aasckmasl=freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

ll sum(ll x) {
	ll ans = 0;
	while (x) {
		ans += x % 10;
		x /= 10;
	}
	return ans;
}

int main() {
//    fin("t.in");
    sync;
    ll n, st[111];
    vector <ll> a;
    cin >> n;
    st[0] = 1;
    F(i, 1, 17) {
    	st[i] = st[i - 1] * 10;
    }
    F(i, 0, 17) {
    	F(j, 1, 10) {
    		a.pb(st[i] * j - 1);
    	}
    }
    sort(all(a));

    DF(i, sz(a) - 1, 0) {
    	if (a[i] <= n) {
    		cout << sum(a[i]) << endl;
    		exit(0);
    	}
    }

    return 0;
}

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


int main(){
	int n; cin >> n;
	int d[100000];
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d, d + n);

	int a = d[n / 2] - d[n / 2 - 1];

	cout << a << endl;

	return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。

    def root(self, A):
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる

        return True

    def is_in_same(self, A, B):
        return self.root(A) == self.root(B)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc126/tasks/abc126_e

N, M = read_ints()
X, Y, Z = read_col(M)

uf = UnionFind(N)
for x, y in zip(X, Y):
    uf.unite(x - 1, y - 1)

# 親が何種類あるかカウント
cnt = Counter([])
for i in range(N):
    cnt[uf.root(i)] += 1
print(len(cnt))


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

int main()
{ 
  string s ;
  cin >> s ;
  int answer = count(s.begin(), s.end(), 'o') ;
  
  if(15 - s.size() + answer >= 8)
  {
    cout << "YES" << endl ;
  }
  else
  {
    cout << "NO" << endl ;
  }
  
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcorder71a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int x = int.Parse(input[0]);
            int a = int.Parse(input[1]);
            int b = int.Parse(input[2]);

            int result1 = System.Math.Abs(x - a);
            int result2 = System.Math.Abs(x - b);

            if (result1 > result2)
            {
                Console.WriteLine("B");
            }
            else
            {
                Console.WriteLine("A");
            }
        }
    }
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    rep(i,0,n){
        cin>>a.at(i)>>b.at(i);
    }
    sort(all(a));
    sort(all(b),greater<int>());
    int mi;
    int ma;

    if(n%2==1){
        cout<<b.at(n/2)-a.at(n/2)+1<<endl;
        return 0;
    }
    else{
        mi=a.at(n/2)+a.at(n/2-1);
        ma=b.at(n/2)+b.at(n/2-1);
        cout<<ma-(mi-1)<<endl;
    }
return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
    int a,b,c,t,sum=0;
    cin>>a>>b>>c;
    if(a>b)
    {
        t=a;
        a=b;
        b=t;
    }
    if(b>c)
    {
        t=b;
        b=c;
        c=t;
    }
    if(a>b)
    {
        t=a;
        a=b;
        b=t;
    }
    t=(c-b)/2;
    sum+=t;
    if((c-b)%2)
    {
        a++;
        sum++;
    }
    t=(c-a)/2;
    sum+=t;
    if((c-a)%2)
    sum+=2;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char a = 'A';
        while (sc.hasNext()) {
            char[] list = sc.nextLine().toCharArray();
            char p1 = list[0];
            char p2 = list[2];
            if (p1 == a || p2 == a) {
                if (p1 == a) {
                    a = p2;
                } else {
                    a = p1;
                }
            }
        }
        System.out.println(a);
    }
}


Measured memory_bytes: 26112
#include<iostream>
#include<stdio.h>
using namespace std;

#define MAX 100005
#define NIL -1

class Node{
    public:
    int p,l,r,d;
};

Node T[MAX];
int n;

void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << T[u].d << ", ";

    if(T[u].p == NIL) cout << "root, ";
    else if(T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    int i,c;
    for(i = 0, c = T[u].l;c != NIL;i++, c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u,int p){
    T[u].d = p;
    if(T[u].r != NIL) rec(T[u].r,p);
    if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(int argc, char const *argv[])
{
    int v,d,l,r,c;
    cin >> n;

    for(int i = 0;i < n;i++) T[i].p = T[i].l = T[i].r = T[i].d = NIL;

    for(int i = 0;i < n;i++){
        scanf("%d%d",&v,&d);
        //cin >> v >> d;

        for(int j = 0;j < d;j++){
            scanf("%d",&c);
            //cin >> c;
            if(j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }

    for(int i = 0;i < n;i++){
        if(T[i].p == NIL) r = i;
    }

    rec(r,0);

    for(int i = 0;i < n;i++) print(i);

    return 0;
}



Measured memory_bytes: 7832
#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 pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 3000 + 5;
int dp[2][N][N];
int a[N];
int n;
int x = 0, y = 0;

int dynamic(int turn, int left, int right, int moves)
{
    if (moves >= n)
        return 0;
    if (dp[turn][left][right] != -1)
        return dp[turn][left][right];
    int ans = 0;
    if (turn == 0)
    {
        ans += max(dynamic(1, left + 1, right, moves + 1) + a[left], dynamic(1, left, right - 1, moves + 1) + a[right]);
    }
    if (turn == 1)
    {
        ans += min(dynamic(0, left + 1, right, moves + 1) - a[left], dynamic(0, left, right - 1, moves + 1) - a[right]);
    }
    //int ans = x - y;
    dp[turn][left][right] = ans;
    return ans;
}

void solve()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    mem1(dp);
    cout << dynamic(0, 0, n - 1, 0);
}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 141568
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin>>a>>b;
    int m=max(a,b);
    if(a==b) cout<<2*a<<endl;
    else cout<<m+(m-1)<<endl;
}

Measured memory_bytes: 256
S = input()

cnt1 = 0
cnt2 = 0

nc = '0'
for c in S :
    if c != nc :
        cnt1 += 1
    
    if nc == '0' :
        nc = '1'
    else :
        nc = '0'
        
nc = '1'
for c in S :
    if c != nc :
        cnt2 += 1
    
    if nc == '0' :
        nc = '1'
    else :
        nc = '0'
        
print(min(cnt1, cnt2))

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main(){
  int n[25000] = {0};
  int cnt_in = 0;
  int a[50000] = {0};
  float ave[50000] = {0};
  int bias = 0;

  for(;;){
    cin >> n[cnt_in];
    if(n[cnt_in] == 0){
      break;
    }
    
    long long sum = 0;

    for(int i = 0; i < n[cnt_in]; i++){
      cin >> a[bias + i];
      sum += a[bias+i];
    }
    ave[cnt_in] = sum / (float)n[cnt_in];
    bias += n[cnt_in];
    cnt_in++;
  }
  
  bias = 0;
  for(int i = 0; i < cnt_in; i++){
    int ans = 0;
    for(int j = 0; j < n[i]; j++){
      if(ave[i] >= a[bias+j]){
	ans++;
      }
    }
    cout << ans << endl;
    bias += n[i];
  }

  return 0;
}



Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
	}

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

	cout << (a[n / 2] - a[n / 2 - 1]) << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll n;
    cin>>n;
    ll res;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0) res=i;
    }
    ll mx=max(res,n/res),cnt=0;
    while(mx>0){
        mx/=10;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

procedure Solve is
   A : Integer;
   B : Integer;
   C : Integer;
begin
   Get (A);
   Get (B);
   Get (C);
   if A = B then
      if B = C then
         Put_Line ("Yes");
      else
         Put_Line ("No");
      end if;
   else
      Put_Line ("No");
   end if;
end Solve;

Measured memory_bytes: 3632
# ARC072C - Sequence (ABC059C)
def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    # start with positive number
    cur, cnt_1 = 0, 0
    for i, j in enumerate(lst):
        new = cur + j
        if i % 2 == 0 and new <= 0:
            cnt_1 += abs(new) + 1
            cur = 1
        elif i % 2 == 1 and new >= 0:
            cnt_1 += abs(new) + 1
            cur = -1
        else:
            cur = new

    # start with negative number
    cur, cnt_2 = 0, 0
    for i, j in enumerate(lst):
        new = cur + j
        if i % 2 == 0 and new >= 0:
            cnt_2 += abs(new) + 1
            cur = -1
        elif i % 2 == 1 and new <= 0:
            cnt_2 += abs(new) + 1
            cur = 1
        else:
            cur = new
    print(min(cnt_1, cnt_2))


if __name__ == "__main__":
    main()

Measured memory_bytes: 14648
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}



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

int main() {
  long double a, b, c;
  cin >> a >> b >> c;
  if(c-a-b-2*(pow(a*b, 0.5))>0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
bool vis[2000222];int n;
int main()
{
	n=read();
	for(int i=1;i<=n/5+10;++i)vis[i*5]=1;
	for(int i=1;i<=n/3+10;++i)vis[i*3]=1;
	LL asd=0;
	for(int i=1;i<=n;++i)
	{
		if(!vis[i])asd+=i;
	}
	printf("%lld\n",asd);
}

Measured memory_bytes: 4644
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define NL << endl
using namespace std;
using ll = long long;
const int INFINT = 1 << 30;
const ll INFLL = 1LL << 60;
const int MOD = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}

int main() {

	int n;

	int ans = 0;

	cin >> n;

	FOR(i, 1, n + 1) {
		int cnt = 0;
		if (i % 2 == 0) continue;
		FOR(j, 1, i + 1) {
			if (i % j == 0)
				cnt++;
		}
		if (cnt == 8) 
			ans++;
	}

	cout << ans NL;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

bool isprime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    for(int i = 31; i <= 55555; i += 30) {
        if(isprime(i)) {
            if(i != 31) cout << " ";
            cout << i;
            n--;
        }
        if(!n) break;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                          
using namespace std;
string s;
int a,b;
int main(){
    cin>>s;
    if(s[0]=='A') a++;
    else b++;
    if(s[1]=='A') a++;
    else b++;
    if(s[2]=='A') a++;
    else b++;
    if(a==1||b==1) cout<<"Yes";
    else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int ans=0;
	string s;
	getline(cin,s);
	for(int i=1;i<s.size();i++){
		if(s[i-1]!=s[i]){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	buy := "No"
	for i := 0; i <= n/4; i++ {
		for j := 0; j <= n/7; j++ {
			if 4*i+7*j == n {
				buy = "Yes"
			}
		}
	}

	fmt.Println(buy)
}


Measured memory_bytes: 512
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, X): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = (0..(N + 1)).map(|i|
        (i, (0..(N - i + 1)).find(|j| 10000 * i + 5000 * j + 1000 * (N - i - j) == X))
    ).find(|&(_, j)| j != None)
    .map(|(i, j)| (i, j.unwrap()))
    .map_or(vec![-1, -1, -1], |(i, j)| vec![i, j, N - i - j])
    .iter()
    .map(std::string::ToString::to_string)
    .collect::<Vec<_>>()
    .join(" ");

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


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    string S;
    cin >> S;
    int N = S.size();
    int res = N;
    REP(i, N-1){
        if(S[i]!=S[i+1]){
            int tmp = max(i+1, N-i-1);
            res = min(res, tmp);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

int main(){
  long long H, W;
  scanf("%lld", &H);
  scanf("%lld", &W);
  if (H==1 || W==1){
    printf("1\n");
  } else if (H%2==1 && W%2==1){
    printf("%lld\n",(H*W+1)/2);
  } else {
    printf("%lld\n",(H*W)/2);
  }
  return 0;
}


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

int main(){
    string S,T,ans,tmp;
    bool flag = false;
    cin>>S>>T;

    for(int i=0; i<S.size(); i++){
        if(S[i] == '?' || S[i] == T[0]){
            int cnt = 0;
            int ind = 0;
            tmp = S;

            for(int j=i; j<S.size(); j++){
                if(ind >= T.size()) break;
                if(S[j] == '?' || S[j] == T[ind]){
                    tmp[j] = T[ind];
                    cnt++;
                }
                else break;
                ind++;
            }

            if(cnt == T.size()){
                ans = tmp;
                flag = true;
            }
        }
    }

    if(flag){
        for(int i=0; i<S.size(); i++){
            if(ans[i] == '?') ans[i] = 'a';
        }
    }

    else ans = "UNRESTORABLE";

    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input!{
        x: u64,
    }
    let mut ans = 1;
    for i in 1..x {
        for j in 2..x as u32 {
            if i.pow(j) > ans && i.pow(j) <= x {
                ans = i.pow(j)
            }
        }
    }

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


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    int a,b,k;
    cin>>k>>a>>b;
    bool flag=false;
    int i=1;
    while(k*i<=b){
        if(i*k>=a) flag=true;
        i+=1;
    }
    if(flag) cout<<"OK";
    else cout<<"NG";
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int n;
  cin >> n;
  map<int, int> a;
  rep(i, n - 1) {
    int s;
    cin >> s;
    a[s - 1]++;
  }
  rep(i, n) { cout << a[i] << endl; }
}


Measured memory_bytes: 13016
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	char C = getcha();
	int A = C - '0';
	while ((C = getcha()) >= '0') A = A * 10 + C - '0';
	return A;
}

const int dm = 1 << 16;
char dn[dm], * di = dn;

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


	int N = getint(), K = getint(), Q = getint();

	int P[100001];
	rep1(i, N) {
		P[i] = K - Q;
	}
	rep(i, Q) {
		P[getint()]++;
	}
	rep1(i, N) {
		if (P[i] > 0) {
			*di++ = 'Y';
			*di++ = 'e';
			*di++ = 's';
			*di++ = '\n';
		}
		else {
			*di++ = 'N';
			*di++ = 'o';
			*di++ = '\n';
		}
		if (i % 16000 == 0) {
			fwrite(dn, 1, di - dn, stdout);
			di = dn;
		}
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(long long a, long long b, long long x){
    ll countA;
    if (a == 0) countA = -1;
    else countA = (a - 1) / x;
    ll countB = b / x;
    print(countB - countA);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long x;
    scanf("%lld",&x);
    solve(a, b, x);
    return 0;
}


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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  multiset<int> S;
  for (int i = 0; i < N; i++) {
    auto it = S.lower_bound(A[i]);
    if (it != S.begin()) {
      S.erase(prev(it));
    }
    S.insert(A[i]);
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	char fi[n][n];
	char fi2[n][n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> fi[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				fi2[j][k]=fi[(j+i)%n][k];
			}
		}
		bool ok=true;
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				if(fi2[j][k]!=fi2[k][j])ok=false;
			}
		}
		if(ok)ans+=n;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline

N = int(readline())
A = list(map(int, readline().split()))
A.sort(reverse=True)

if A[-1] == 0:
    print(0)
    exit()

for i, x in enumerate(A):
    if i == 0:
        result = x
        continue

    result = result * x

    if result > 10**18:
        print(-1)
        exit()

else:
    print(result)


Measured memory_bytes: 20180
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define el '\n'
#define oo 4294967296

const int N = 1e5;
int n, t;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	//freopen("test.inp", "r", stdin);
	//freopen("test.out", "w", stdout);
	string s;
	cin >> s;
	rep(i, s.length()) s[i] = 'x';
	cout << s;
}


Measured memory_bytes: 256