akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

int main() {
    init_io();
    ll N;
    cin >> N;
    V<ll> B(N);
    for(ll &e : B) {
        cin >> e;
    }
    V<ll> ans;
    for(ll i = 0; i < N; i++) {
        ll idx = -1;
        for(ll j = B.size() - 1; j >= 0; j--) {
            if(j + 1 == B[j]) {
                idx = j;
                break;
            }
        }
        if(idx == -1) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(B[idx]);
        auto ite = B.begin() + idx;
        B.erase(ite);
    }
    reverse(ALL(ans));
    for(ll e : ans) cout << e << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 8
int row[N]={},col[N]={},dpos[2*N-1]={},dneg[2*N-1]={};
int board[N][N];
void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(board[i][j]==1&&row[i]!=j)return;
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
void putQueen(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==1||dpos[i+j]==1||dneg[i-j+N-1]==1)continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=1;
    putQueen(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=0;
  }
}

int main(){
  int k,r,c,i,j;
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      board[i][j]=0;
    }
  }
  
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    board[r][c]=1;
  }
  putQueen(0);
  return 0;
}

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

int main() {
  int a, b, x, ar, ea;
  int cou = 0, cou_max = 0;
  string str;
  cin >> a;

  long long sum = 0, mi = 1000000000000007;
  long long arr[a];
  for (int i = 0; i < a; i++) {
    cin >> arr[i];
    arr[i] = arr[i] - i - 1;
  }
  sort(arr, arr + a);

  if (a % 2 == 1) {
    for (int j = arr[(a - 1) / 2]; j < arr[(a) / 2] + 100; j++) {
      for (int i = 0; i < a; i++) {
        sum += abs(arr[i] - j);
      }
      if (sum < mi) {
        mi = sum;
      }
      sum = 0;
    }
  } else {
    b = arr[(a) / 2];
    for (int j = arr[(a - 1) / 2]; j < arr[(a + 1) / 2] + 10; j++) {
      for (int i = 0; i < a; i++) {
        sum += abs(arr[i] - j);
      }
      if (sum < mi) {
        mi = sum;
      }
      sum = 0;
    }
  }

  cout << mi << endl;
  return 0;
}


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

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

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

  	unsigned long long int pre[n];
  	pre[n-1]=a[n-1];
  	for(int i=n-2;i>0;i--)
  	{
  			pre[i]=(pre[i+1]%1000000007+a[i]%1000000007)%1000000007;
  			
  	}
  	int sum=0;
  	for(int i=0;i<n-1;i++)
  	{
  		//cout<<pre[i+1]<<" ";
  		sum=(sum%1000000007+((a[i])*(pre[i+1]))%1000000007)%1000000007;
  		//cout<<sum<<endl;
  	}
  	cout<<sum<<endl;

}

Measured memory_bytes: 5992
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,ans;
long long x[100005];
int main(){
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++){
    	cin>>x[i]; 
	}
    for(int i=1;i<n;i++){
    	ans+=min(a*(x[i+1]-x[i]),b);
	}
    cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


void solve(){
    int x, y, a, b, c, j = 0, k = 0;
    cin>>x>>y>>a>>b>>c;
    vl v1(a), v2(b), v3(c), ans;
    f(i,a)cin>>v1[i];
    f(i,b)cin>>v2[i];
    f(i,c)cin>>v3[i];
    sort(all(v1));
    reverse(all(v1));
    sort(all(v3));
    reverse(all(v3));
    sort(all(v2));
    reverse(all(v2));
    f(i,x)ans.pb(v1[i]);
    f(i,y)ans.pb(v2[i]);
    sort(all(ans));
    while(j < c && k < ans.size() && v3[j] > ans[k])ans[k++] = v3[j++];
    k = 0;
    f(i,ans.size())k += ans[i];
    cout<<k; 
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

void transpose(vector<vector<char>> &b)
{
    if (b.size() == 0)
        return;

    vector<vector<char>> trans_vec(b[0].size(), vector<char>());

    for (int i = 0; i < b.size(); i++)
    {
        for (int j = 0; j < b[i].size(); j++)
        {
            trans_vec[j].push_back(b[i][j]);
        }
    }

    b = trans_vec; // <--- reassign here
}

int main()
{

    int a, b;
    cin >> a >> b;

    if (a == b)
    {
        rep(i, a)
        {
            cout << b;
        }
        cout << endl;
    }
    else if (a > b)
    {
        rep(i, a)
        {
            cout << b;
        }
        cout << endl;
    }
    else
    {
        rep(i, b)
        {
            cout << a;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const int MAX_V = 1e5 + 1;
vector<vector<int>> G(MAX_V);

vector<int> bfs(int s) {
    vector<int> d(MAX_V, -1);
    queue<int> que;
    d[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto to : G[v]) {
            if (d[to] != -1) continue;
            d[to] = d[v] + 1;
            que.push(to);
        }
    }

    return d;
}
int main()
{
    int N;
    cin >> N;

    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> df = bfs(0);
    vector<int> ds = bfs(N - 1);

    int f = 0, s = 0;
    rep(i, N) {
        if (df[i] <= ds[i]) f++;
        else s++;
    }

    if (f > s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return 0;
}

Measured memory_bytes: 9552
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        ll count = n/i;
        ans = ans + ((count+1)*count*i)/2LL;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll ans = 0;
    ll n, d;

    cin >> n >> d;
    
    vector<ll> *x = new vector<ll>[n];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            int d;
            cin >> d;
            x[i].push_back (d);
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ll sq = 0;
            for (int k = 0; k < d; k++) {
                sq += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            if (sq == (ll)sqrt(sq) * (ll)sqrt(sq)) ans++;
        }
    }
    cout << ans << endl;

    
}

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

int main()
{
    int n;
    cin >> n;
    int a[300005];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        if(a[i] % 2 == 0 && (a[i] % 3 != 0 && a[i] % 5 != 0)){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
m,d=map(int,input().split())
c=0
for i in range(1,m+1):
	for j in range(1,d+1):
		if j>=10:
			d10=int(str(j)[0])
			d1=int(str(j)[1])
			if d10>1 and d1>1:
				if i==d10*d1:
					#print(i,j)
					c+=1
print(c)

Measured memory_bytes: 9176
require 'prime'

e107 = 1000000007

n = gets.to_i

if n==1
    p 1
    exit
end

q ={}

2.upto(n){|i|
    Prime::prime_division(i).each{|pair|
        q[pair[0]] = 0 if !q[pair[0]]
        q[pair[0]] += pair[1]
    }
}

result = 1
q.each{|e|
    result = (result*(e[1] + 1))%1000000007
}

p result

Measured memory_bytes: 2172
n = gets.to_i
s = Array.new(n) { gets.chomp }

min, max = [s.count { |e| e[-1] == 'A' && e[0] != 'B' }, s.count { |e| e[-1] != 'A' && e[0] == 'B' }].minmax
both = s.count { |e| e[-1] == 'A' && e[0] == 'B' }
count = max == 0 ? [both - 1, 0].max : min + both

s.each do |e|
  idx = -2
  count += 1 while (idx = e.index('AB', idx + 2))
end

puts count

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

int main(){
  int64_t N; cin >> N;
  if(N%2==1){
    cout << 0 << endl;
    return 0;
  }
  int64_t ans=0;
  int64_t now=5;
  for(int i=1;i<=25;i++){
    ans+=(N/now)/2;
    now*=5;
  }
  cout << ans << endl;
}
    
    

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

int main(){
  string S;
  cin >> S;
  
  size_t size = S.length();
  int a = size;
  
  int count = 0; 
  for(int i=0; i<a; i++){
    if(S[i] == '0'){
      count++;
    }
  }
  int ans = 2*min(count, a-count);
  
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int a, b;
	cin >> a >> b;
	if(a * b % 2 == 1) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a, b, c, n;
    
    while(scanf("%d %d", &a, &b) != EOF){
        c=a+b;
        n=0;
        do{
            n++;
            c /= 10;
        }while(c);
        
        printf("%d\n", n);
    }
    return 0;
}
    


Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll>P;
vector<P>vec;

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    vec.push_back(P(a,b));
  }
  sort(vec.begin(),vec.end());
  ll sum=0,ans=0;
  for(int i=0;i<n;i++){
    //cout<<sum<<' '<<ans<<endl;
    if(sum+vec[i].second>=m){
      ans+=(m-sum)*vec[i].first;
      cout<<ans<<endl;
      return(0);
    }
    sum+=vec[i].second;
    ans+=vec[i].first*vec[i].second;
  }
  return(0);
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1LL << 30
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " = " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) cout << x[i][j] << " "; printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define F first
#define S second
#define mp make_pair
 
typedef long long int ll;
typedef pair < int, int > ii;
typedef pair < int, ii > iii;


int main()
{
	
	int n; cin >> n;
	int t, x, y, px = 0, py = 0, pt = 0;
	
	rep(i, 0, n){
		scanf("%d %d %d", &t, &x, &y);
		int dist = abs(px-x)+abs(y-py);
		if(dist > t-pt || dist%2!=(t-pt)%2){
			puts("No");
			return 0;
		}
		pt = t;
		px = x;
		py = y;
	}
	
	puts("Yes");
	
	
	
	return 0;	
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

int main(){
    lint N;
    cin >> N;
    lint *A,*B;
    A=new lint[N];
    B=new lint[N];
    for(lint i=0;i<N;i++) cin >> A[i];
    for(lint i=0;i<N;i++) cin >> B[i];

    lint ra=0,rb=0;
    for(lint i=0;i<N;i++){
        if(A[i]<B[i]) ra+=(B[i]-A[i])/2;
        else rb+=(A[i]-B[i]);
    }
    if(ra>=rb) cout << "Yes" << endl;
    else cout << "No" << endl;

    delete[]A,B;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

#define int ll

bool check(string a) {
	int n = a.size();
	if(n%2) return false;

	for(int i=0;i<n/2;i++) if(a[i]!=a[i+n/2]) return false;
	return true;
}

signed main() {
	fast;

	int n;
	cin>>n;
	string s;
	cin>>s;
	if(check(s)) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
// D - Equal Cut

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

ll A[200000];
ll cum_A[200001];

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

	for (int i=0; i<N; i++) {
		cin >> A[i];
		cum_A[i+1] = cum_A[i] + A[i];
	}

	ll ans = INF;

	ll P, Q, R, S;
	ll max_sub;
	ll min_sub;
	for (int m=2; m<=N-1; m++) {
		int l = upper_bound(cum_A, cum_A+m, cum_A[m] / 2) - cum_A;
		int r = upper_bound(cum_A+m, cum_A+N, cum_A[m] + (cum_A[N] - cum_A[m]) / 2) - cum_A;

		P = cum_A[l];
		Q = cum_A[m] - cum_A[l];
		R = cum_A[r] - cum_A[m];
		S = cum_A[N] - cum_A[r];
		max_sub = max(P, max(Q, max(R, S)));
		min_sub = min(P, min(Q, min(R, S)));
		ans = min(ans, max_sub - min_sub);

		P = cum_A[l-1];
		Q = cum_A[m] - cum_A[l-1];
		R = cum_A[r] - cum_A[m];
		S = cum_A[N] - cum_A[r];
		max_sub = max(P, max(Q, max(R, S)));
		min_sub = min(P, min(Q, min(R, S)));
		ans = min(ans, max_sub - min_sub);

		P = cum_A[l];
		Q = cum_A[m] - cum_A[l];
		R = cum_A[r-1] - cum_A[m];
		S = cum_A[N] - cum_A[r-1];
		max_sub = max(P, max(Q, max(R, S)));
		min_sub = min(P, min(Q, min(R, S)));
		ans = min(ans, max_sub - min_sub);

		P = cum_A[l-1];
		Q = cum_A[m] - cum_A[l-1];
		R = cum_A[r-1] - cum_A[m];
		S = cum_A[N] - cum_A[r-1];
		max_sub = max(P, max(Q, max(R, S)));
		min_sub = min(P, min(Q, min(R, S)));
		ans = min(ans, max_sub - min_sub);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6660
def ii2ss(n):
    ss = []
    for i in range(n):
        ss.append(input())
    return ss

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

import math
def main(ss):
    N, A, B, C, D, E = ss2nn(ss)
    m = min(A, B, C, D, E)
    return math.ceil(N / m) + 4

ss = ii2ss(6)
print(main(ss))

Measured memory_bytes: 3064
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()

	switch {
	case a+b == 15:
		fmt.Println("+")
	case a*b == 15:
		fmt.Println("*")
	default:
		fmt.Println("x")
	}
}


Measured memory_bytes: 640
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;

int main() {

	long res = 0;
	long N, K; cin >> N >> K;
	vector<long> h(N); for (int i = 0; i < N; i++) cin >> h[i];

	for (long e : h) if (e >= K) res++;
	
	cout << res << endl;
}

Measured memory_bytes: 1024
#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<double,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int m;cin >> m;
    vector<LL> d(m),c(m);
    LL ans = 0;
    vector<LL> k(10,0);
    for (int i = 0; i < m; i++) {
        cin >> d[i] >> c[i];
        k[d[i]] += c[i];
    }
    while(true){
        bool f = false;
        for (int i = 0; i < 10; i++) {
            if(k[i]>1) f = true;
        }
        if(!f){
            while(true){
                int sum = 0;
                for (int i = 0; i < 10; i++) {
                    sum += k[i];
                }
                if(sum==1) break;
                int p =-1;
                for (int i = 0; i < 10; i++) {
                    if(k[i]){
                        if(p==-1){
                            p = i;
                        }
                        else{
                            k[i]--;
                            k[p]--;
                            if(i+p>=10){
                                ans+=2;
                            }
                            else{
                                ans++;
                            }
                            k[(i+p)/10 + (i+p)%10]++;
                            p = -1;
                        }
                    }
                }
            }
            cout << ans << endl;
            return 0;
        }
        for (int i = 0; i < 10; i++) {
            LL t = k[i] / 2;
            if(i >= 5) ans += 2 * t;
            else ans += t;
            k[(i + i) / 10 + (i + i)%10] += t;
            k[i] -= 2 * t;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
def getNumber(string):
    i=0
    while(string[i]!=" "):
        i+=1
    return string[0:i],string[i+1:]
raw = str(input())
a,raw= getNumber(raw)
b,raw= getNumber(raw)
a = int(a)
b = int(b)
c = int(raw)

if(a+b>c):
    print(b+c)
elif(a+b<c):
    print(a+b+1+b)
elif(a+b==c):
    print(c+b)

Measured memory_bytes: 3064
#include<iostream>
    using namespace std;
    int arr[100000+50];
    int main(){
      int n; cin>>n;
      long long cnt=0;
      for(int i=0;i<n;i++) cin>>arr[i];
      for(int i=0;i<n-1;i++){
       	 if(arr[i]%2!=0 && arr[i+1]>0){
         cnt+=arr[i]/2+1; arr[i+1]--;
         }
        else {
          cnt+=arr[i]/2;
        }
      }
      
      cout<<cnt+arr[n-1]/2;
      return 0;
    }


Measured memory_bytes: 768
import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=A+B;
        if((A%3==0)||(B%3==0)||(C%3==0)){
            System.out.println("Possible");
        }else{
            System.out.println("Impossible");
        }


}
        
        
    }


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while(sc.hasNextLine())
            sb.append(sc.nextLine());
        if (sb.toString().equals("ARC")) {
            System.out.println("ABC");
            return;
        }
        if (sb.toString().equals("ABC")) {
            System.out.println("ARC");
            return;
        }
    }
}


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

int main()
{
    int n, i, a, x = 0;
    cin >> n;
    for(i = 1; i <= n; i++)
    {
        cin >> a;
        if(a != i)
            x++;
    }

    cout << (x <= 2? "YES" : "NO");

}


Measured memory_bytes: 3600
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[][] A = new long[N][N];
		long[][] a = new long[N][N];
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				long temp = sc.nextLong();
				A[i][j] = temp;
				a[i][j] = temp;
			}
		}
		sc.close();
		for(int k=0; k<N; k++) {
			for(int i=0; i<N; i++) {
				for(int j=0; j<N; j++) {
					if(i != j && A[i][k] + A[k][j] < A[i][j]) {
						System.out.println(-1);
						return;
					}
				}
			}
		}
		long ans = 0;
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				boolean flag = true;
				for(int k=0; k<N; k++) {
					if(i!=j && k!=i && k!=j && a[i][j] == a[i][k]+a[k][j]) {
						flag = false;
						break;
					}
				}
				if(flag) {
					ans += a[i][j];
				}
			}
		}
		System.out.println(ans/2);
	}

}


Measured memory_bytes: 58128
s = input()
t = input()

#dp[i+1][j+1]:Sのi文字目までとTのj文字目まででのLCSの長さ

dp = [[0 for j in range(len(t)+1)] for i in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])


#復元
res = ""
i = len(s)
j = len(t)

while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        res = s[i-1] + res
        i -= 1
        j -= 1

print(res)

Measured memory_bytes: 120156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define reverse(s) reverse(s.begin(),s.end())

int main(){
    string t = "abcdefghijklmnopqrstuvwxyz";
    map<char,int> a;
    rep(i,26){
        a[t[i]];
    }

    string s;   cin >> s;
    rep(i,s.size()){
        a[s[i]]++;
    }

    rep(i,26){
        if(a[t[i]]==0){
            cout << t[i] << endl;
            return 0;
        }
    }

    cout << "None" << endl;

    return 0;
}

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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  char s;
  cin >> s;
  if (97 <= s && s <= 122) {
    cout << 'a' << endl;
  } else {
    cout << 'A' << endl;
  }
}

Measured memory_bytes: 3552
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>

int		main(void)
{
	int		a, b;
	int		d, r;
	double	f;

	scanf("%d",&a);
	scanf("%d",&b);

	d = a/b;
	r = a%b;
	f = (double)a/b;

	printf("%d %d %f",d, r, f);

	return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
 
int main(void) {
	int time, hour, minute, second;
	scanf("%d", &time);
	hour=time/3600;
	minute=(time-hour*3600)/60;
	second=time-hour*3600-minute*60;
	printf("%d:%d:%d\n", hour, minute, second);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//FILE *fi = freopen("1.txt", "r", stdin);
//FILE *fo = freopen("1", "w", stdout);
//FILE *fi = freopen("P.inp", "r", stdin);
//FILE *fo = freopen("P.out", "w", stdout);
int k;
string s;
const long long Mod = 1e9 + 7;
long long g[2000001];
long long power(long long n, int x)
{
    if (x == 0)
        return 1;
    if (x % 2 == 0)
        return power(n * n % Mod, x / 2);
    else
    {
        return n * power(n * n % Mod, x / 2) % Mod;
    }
}
long long combi(int n, int k)
{
    return g[n] * power(g[k], Mod - 2) % Mod * power(g[n - k], Mod - 2) % Mod;
}
int main()
{
    //------------------------------
    // Faster
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //-------------------------------
    g[0] = 1;
    for (int i = 1; i <= 2e6; i++)
    {
        g[i] = g[i - 1] * 1LL * i % Mod;
    }
    cin >> k >> s;
    long long ans = 0;
    int n = s.size();
    for (int i = 0; i <= k; i++)
    {
        ans = (ans + (power(26, i) * combi(n + k - i - 1, n - 1) % Mod) * power(25, k - i) % Mod) % Mod;
        ans %= Mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 19880
#include <stdio.h>
int main(void)
{
int al[30] = {0};
char b[2000]= {0};
int i,j,n;
i=0;
while( scanf("%c",&b[i]) != EOF) {
if (b[i] >= 'A' && 'Z' >= b[i] ) {
n = b[i] - 'A';
al[n] += 1;
} else if(b[i] >=  'a' && b[i] <= 'z' ) {
n = b[i] - 'a';
al[n] += 1;
}
i=i+1;
}
for(j=97; j<=122; j++) {
n = j - 'a';
printf("%c : %d\n",j,al[n]);
}
return 0;
}



Measured memory_bytes: 2100
#include <stdio.h>
int main(){
    int a,b,c;
  
    scanf("%d %d %d",&a,&b,&c);
    if(a==b && b!=c){
        printf("Yes");
    }else if(c==b && b!=a){
        printf("Yes");
    }else if(c==a && b!=a){
        printf("Yes");
    }else{
        printf("No");
    }
    
    return 0;
}


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

int main(void)
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] + N > 'Z') {
            S[i] = S[i] - (26 - N);
        }
        else {
            S[i] += N;
        }
    }
    cout << S << endl;
}

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

string chk_bingo(int N1,int N2,int N3,map<int,int> B){
  string res = "No";
  
//  cout << N1 << " " << N2 << " " << N3 << "B " << B[N1] << " " << B[N2]  << " " << B[N3]  << endl;
  
  if(B[N1] > 0 && B[N2] > 0 && B[N3] > 0){
    res = "Yes";
  }
  else{
    res = "No"; 
  }

  return res; 
}

int main() {
  vector <int> A(9);
  
  for(int i =0;i<9;i++){
    cin >> A.at(i);
  }
  
  string res = "No";
  int N;
  
  cin >> N;
  
  
  map<int, int> B;
  
  int tmp;
  for(int i =0;i<N;i++){
    cin >> tmp;
    B[tmp] = 1;
  }

  //row1
  if(res == "No"){
    res = chk_bingo(A.at(0),A.at(1),A.at(2),B);
  }  
  //row2
  if(res == "No"){
    res = chk_bingo(A.at(3),A.at(4),A.at(5),B);
  }
  //row3
  if(res == "No"){
    res = chk_bingo(A.at(6),A.at(7),A.at(8),B);
  }

  //co1
  if(res == "No"){
    res = chk_bingo(A.at(0),A.at(3),A.at(6),B);
  }
  //co2
  if(res == "No"){
    res = chk_bingo(A.at(1),A.at(4),A.at(7),B);
  }  
  //co3
  if(res == "No"){
    res = chk_bingo(A.at(2),A.at(5),A.at(8),B);
  }

  //x1
  if(res == "No"){
    res = chk_bingo(A.at(0),A.at(4),A.at(8),B);
  }
  //x2
  if(res == "No"){
    res = chk_bingo(A.at(2),A.at(4),A.at(6),B);
  }    
  
  
  cout << res << endl;
}







Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define sz size()
using namespace std;
typedef pair<int,int> pii;

struct Node{
  int id,left,right;
  Node(int a,int b,int c):id(a),left(b),right(c){}
};

vector<pii> sim;
vector<int> shape_id;
vector< set<int> > shapes;
map<pii,int> shape_hash;

int construct(const string &s, int &p, vector<Node> &tree){
  if(s[p] == 'x'){
    tree.pb( Node(tree.sz, -1, -1) );
    p++;
  }else if(s[p] == '('){
    p++;
    int lid = construct(s, p, tree);
    p++;
    int rid = construct(s, p, tree);
    tree.pb( Node(tree.sz, lid, rid) );
    p++;
  }
  return tree.sz-1;
}

void cal_sim(int v, const vector<Node> &tree){
  shapes[v].clear();

  if(tree[v].left<0){
    shape_id[v] = 0;
    shapes[v].insert(0);

    sim[v] = pii(0,1);
  }else{
    int l = tree[v].left, r = tree[v].right;
    cal_sim(l,tree); cal_sim(r,tree);
    for(int x : shapes[l])shapes[v].insert(x);
    for(int x : shapes[r])shapes[v].insert(x);

    pii new_shape = pii(shape_id[l], shape_id[r]);
    if(new_shape.first > new_shape.second)swap(new_shape.first, new_shape.second);
    int new_id;
    if(shape_hash.find(new_shape)!=shape_hash.end())new_id = shape_hash[new_shape];
    else{
      new_id = shape_hash.sz + 1;
      shape_hash[new_shape] = new_id;
    }
    shape_id[v] = new_id;
    shapes[v].insert(new_id);

    int cnt = 0;
    for(int x : shapes[l]){
      if(shapes[r].find(x) != shapes[r].end())cnt++;
    }
    sim[v] = pii(cnt,shapes[v].sz-1);
  }
}

//-1: a<b, 0:a==b, 1: a>b
map<pii,int> memo;
int cmp_node(int a, int b, const vector<Node> &tree){
  if(memo[pii(a,b)])return memo[pii(a,b)];
  int res = 0;

  int dif = sim[a].first*sim[b].second - sim[b].first*sim[a].second;
  if(dif!=0){
    if(dif<0)res = 1;
    else res = -1;
  }else if(tree[a].left<0 && tree[b].left<0){
    res = 0;
  }else{
    int al = tree[a].left, ar = tree[a].right;
    if(cmp_node(al,ar,tree)<0)swap(al,ar);
    int bl = tree[b].left, br = tree[b].right;
    if(cmp_node(bl,br,tree)<0)swap(bl,br);
    
    res = cmp_node(al,bl,tree);
    if(res == 0)res = cmp_node(ar,br,tree);
  }
  return memo[pii(a,b)] = res;
}

void transform(int v, vector<Node> &tree, bool is_lc){
  if(tree[v].left<0)return;
  if(is_lc && (cmp_node(tree[v].left, tree[v].right, tree) < 0)){
    swap(tree[v].left, tree[v].right);
  }
  if(!is_lc && (cmp_node(tree[v].left, tree[v].right, tree) > 0)){
    swap(tree[v].left, tree[v].right);
  }
  transform(tree[v].left, tree, true);
  transform(tree[v].right, tree, false);
}

string encode(int v, const vector<Node> &tree){
  if(tree[v].left<0)return "x";
  return "(" + encode(tree[v].left,tree) +  " " +  encode(tree[v].right,tree) + ")";
}

int main(){
  string s;
  while(getline(cin,s)){
    if(s == "0")break;
    vector<Node> tree;
    int p = 0;
    construct(s,p,tree);

    sim.resize(tree.sz);
    shape_id.resize(tree.sz); shapes.resize(tree.sz);
    shape_hash.clear();
    cal_sim(tree.sz-1,tree);

    memo.clear();
    transform(tree.sz-1,tree,true);

    cout << encode(tree.sz-1,tree) << endl;
  }
}

Measured memory_bytes: 1344
#include<stdio.h>

int main()
{
    char X[2];  scanf("%s", X);
    char Y[2];  scanf("%s", Y);

    if((X[0] - Y[0]) > 0){
        puts(">");
    }
    else{
        if((X[0] - Y[0]) < 0){
            puts("<");
        }
        else{
            puts("=");
        }
    }
  
    return 0;
}

Measured memory_bytes: 128
sentences = $stdin.readlines

alphabets = {"a" => 0, "b" => 0, "c" => 0, "d" => 0, "e" => 0, "f" => 0,
             "g" => 0, "h" => 0, "i" => 0, "j" => 0, "k" => 0, "l" => 0,
             "m" => 0, "n" => 0, "o" => 0, "p" => 0, "q" => 0, "r" => 0,
             "s" => 0, "t" => 0, "u" => 0, "v" => 0, "w" => 0, "x" => 0,
             "y" => 0, "z" => 0}

sentences.each do |sentence|
   sentence.each_char do |char|
      if /[a-z]/i =~ char
         alphabets["#{char.downcase}"] += 1
      end
   end
end

alphabets.each do |key, val|
   puts "#{key} : #{val}"
end

Measured memory_bytes: 8744
import math

A,B,H,M=map(int, input().split())

kakudo_min=M/60*360
kakudo_hour=H/12*360+M/720*360
kakudo=0

if abs(kakudo_min-kakudo_hour)<180:
	kakudo=abs(kakudo_min-kakudo_hour)
	cosAB=math.cos(math.radians(kakudo))
	print((A**2+B**2-2*A*B*cosAB)**0.5)
	
elif abs(kakudo_min-kakudo_hour)>180:
	kakudo=360-abs(kakudo_min-kakudo_hour)
	cosAB=math.cos(math.radians(kakudo))
	print((A**2+B**2-2*A*B*cosAB)**0.5)
	
else:
	print(A+B)
	

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

#define MAX 101010
#define EPS 1e-6
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using namespace std; 

using ll = long long;
using ii = pair<int,int>;

ll dp[MAX];

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

  int n; cin >> n;
  vector<ll> v(n);
  for (auto &i : v) cin >> i;

  mset(dp, inf);
  dp[0] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i; j <= i + 2; ++j)
      if (j < n)
        dp[j] = min(dp[j], dp[i] + abs(v[i] - v[j]));

  cout << dp[n-1] << ende;
  return 0;
}


Measured memory_bytes: 1792
/*
   وَعَلَى اللَّهِ فَلْيَتَوَكَّلِ الْمُؤْمِنُونَ
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
   //  freopen("in.txt", "r", stdin) ;
   ios :: sync_with_stdio(0) ;
   cin.tie(0) ;
   cout.tie(0) ;

   int a, b ;
   cin >> a >> b ;
   if(a > 10) return cout << b, 0 ;
   cout << 100 * (10 - a) + b ;


}




Measured memory_bytes: 256
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


def main():
    N, K = lmi()
    A = lmi()
    c = [-1] * N
    current = 0
    d = dict()
    d[0] = 0
    c[0] = 0
    count = 0
    loop_start = -1
    for count in range(1,2 * N+2):
        _next = A[current] - 1
        c[_next] = count
        d[count] = _next
        current = _next
    for i in reversed(range(N)):
        if d[i] == d[N]:
            loop_size = N- i
            break
    if K <= 2*N:
        print(d[K] + 1)
    else:
        print(d[(K - N) % loop_size + N] + 1)
    # print(loop_size,loop_start)
    # print(c, d, loop_size, loop_start, loop_size)
    # print(d[K % loop_size] + 1)


if __name__ == '__main__':
    main()


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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    vll a(n);
    rep(i, n) {
        cin >> a[i];
    }

    long long ans = 0;

    rep(i, 60) {
        long long x = 0, y = 0;

        rep(j, n) {
            if ((a[j] >> i) & 1)
                x++;
            else
                y++;
        }

        long long t = (1LL << i) % mod;
        t = t * x % mod;
        t = t * y % mod;
        ans += t;
        ans %= mod;
    }

    cout << ans << endl;
}

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

int main()
{
  int n;
  cin>>n;
  
  string s,t,m;
  cin>>s>>t;
  
  for(int i=0;i<s.size();i++)
  {
    m = m + s[i] + t[i];
  }
  
  cout<<m<<endl;
}

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

int main(){
    int n,d,x;
    int a[100];
    int chocolate = 0;
    cin >> n >> d >> x;
    for(int i=0; i!=n; i++){
        cin >> a[i];
        if(a[i] == 1){
            chocolate = chocolate + d;
        }else{
            chocolate = chocolate + d / a[i] + 1;
            if(d % a[i] == 0){
                chocolate -= 1;
            }
        }
        
    }
    cout << chocolate + x << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  int x, y, n, k, sum;

  scanf("%d%d%d%d", &n, &k, &x, &y);

  if (n - k <= 0)
    sum = n * x;
  else
    sum = k * x + (n - k) * y;

  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 128
mod=10**9+7
n, k=map(int, input().split())
a=list(map(int, input().split()))
jibun=0
for i in range(n-1):
    for j in range(i+1, n):
        if a[i]>a[j]:
            jibun=(jibun+1)%mod

saki=0
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            saki=(saki+1)%mod

ans=jibun*k+saki*k*(k-1)//2
print(ans%mod)


Measured memory_bytes: 41836
until (n = gets.to_i).zero?
  arr = [[0] * (n + 1)] * (n + 1)
  
  # row
  n.times do |i|
    arr[i] = gets.split.map(&:to_i) << 0
    
    n.times do |j|
      arr[i][n] += arr[i][j]
    end
  end
  
  # column
  (n + 1).times do |i|
    (n + 1).times do |j|
      arr[n][i] += arr[j][i] unless j == n
    end
    
    puts "%5d" * (n + 1) % arr[i]
  end
end

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const ll mod = 1e9+7;
const ll nax = 1e5+7;
const ll INF = 1e18;

ll n,k,dp[nax][3],a[nax][3];

int main(){
//	freopen("input.inp","r",stdin);
//	freopen("output.out","w",stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin>>n;
	for (ll i=0;i<n;++i) for (ll j=0;j<3;++j) cin>>a[i][j];

	for (ll i=0;i<n;++i){
		dp[i+1][0] = max(dp[i][1],dp[i][2]) + a[i][0];
		dp[i+1][1] = max(dp[i][0],dp[i][2]) + a[i][1];
		dp[i+1][2] = max(dp[i][0],dp[i][1]) + a[i][2];
		
	}
	
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<"\n";
}

Measured memory_bytes: 8304
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	string s,t;
  	cin >> s >> t;
  	bool flag=false;
  	for(int i=s.size()-t.size();i>=0;i--){
      	flag=true;
    	for(int j=0;j<t.size();j++){
        	if(s[i+j]!=t[j] && s[i+j]!='?') flag=false; 
        }
      	if(flag){
        	for(int j=0;j<t.size();j++){
        		s[i+j]=t[j]; 
        	}
          	break;
        }
    }
  	if(flag){
    	  	for(int j=0;j<s.size();j++){
            	if(s[j]=='?') s[j]='a';
            }
          	cout << s << endl;
    }else{
    	cout << "UNRESTORABLE" << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
int main() {
	ll n, m;
	scanf("%lld%lld", &n, &m);
	if (m < n * 2) printf("%lld\n", m / 2);
	else printf("%lld\n", (m - n * 2) / 4 + n);
	return 0;
}

Measured memory_bytes: 128
package main

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

type scn struct { s *bufio.Scanner }

func (s scn) word() string {
	s.s.Scan()
	return s.s.Text()
}

func (s scn) int() int {
	i, _ := strconv.Atoi(s.word())
	return i
}

func main() {
	s := scn{bufio.NewScanner(os.Stdin)}
	s.s.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)

	n := s.int()

	a := make([]int, n)
	for i := range a {
		a[i] = s.int()
	}

	c := make([]int, 10001)
	for _, e := range a {
		c[e]++
	}

	for i := 1; i < len(c); i++ {
		c[i] += c[i-1]
	}

	b := make([]int, n)
	for _, e := range a {
		b[c[e]-1] = e
		c[e]--
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Fprint(w, " ")
		}
		fmt.Fprint(w, b[i])
	}
	fmt.Fprintln(w)
	w.Flush()
}



Measured memory_bytes: 41868
N=int(input())
P=list(map(int,input().split()))

flag=0

for i in range(0,N-1):
    if i+1!=P[i]:
        for j in range(i+1,N):
            if j+1!=P[j]:
                if j!=N-1:
                    for k in range(j+1,N):
                        if k+1!=P[k]:
                            flag=1
                        break
if flag==0:
    print('YES')
else:
    print('NO')


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

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;

const int mxN = 5e3+5;
const int MOD = 1e9+7;
int N, P[mxN];
vector<int> al[mxN];
bool vis[mxN];
int dp[mxN][mxN];

int comp = 0, cyc = 0, sz[mxN], fac[mxN], po[mxN];
void dfs(int u, bool f) {
    vis[u] = 1;
    sz[comp] += f;
    for (int v : al[u]) if (!vis[v]) dfs(v,f);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    FOR(i,1,N){
        cin >> P[i];
        if (P[i] != -1) {
            al[i].push_back(P[i]);
            al[P[i]].push_back(i);
        }
    }

    FOR(i,1,N) if (P[i] == -1) ++comp, dfs(i,1);
    FOR(i,1,N) if (!vis[i]) ++cyc, dfs(i,0);

    dp[0][0] = 1;
    FOR(i,1,comp){
        dp[i][0] = 1;
        FOR(x,1,comp){
            dp[i][x] = dp[i-1][x];
            dp[i][x] = (dp[i][x] + (ll) dp[i-1][x-1] * sz[i] % MOD) % MOD;
        }
    }

    fac[0] = 1, po[0] = 1;
    FOR(i,1,comp){
        fac[i] = (ll) fac[i-1] * i % MOD;
        po[i] = (ll) po[i-1] * (N-1) % MOD;
    }
    int tot = (ll) po[comp] * (N-cyc) % MOD, sub = 0;
    FOR(i,1,comp){
        sub += (ll) (sz[i]-1) * po[comp-1] % MOD;
        sub %= MOD;
    }
    FOR(i,2,comp){
        sub += (ll) dp[comp][i] * fac[i-1] % MOD * po[comp-i] % MOD;
        sub %= MOD;
    }
    cout << (tot - sub + MOD) % MOD << '\n';
}



Measured memory_bytes: 101476
import java.io.InputStream;
import java.util.Scanner;
import java.util.stream.*;

public class Main {
  public static void main(String[] args){
    System.out.println(new Main().excute(System.in)); 
  }
  public String excute(InputStream f) {
    Scanner scan = new Scanner(f);
    String[] s =  scan.next().split("");

    return "" + IntStream.range(0, s.length/2)
                .filter(i -> !(s[i].equals(s[s.length-i-1])))
                .count();
  }
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;
const long double PI = acos(-1) ;
int arr[MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	long double r ;
	cin>>r ;
	long double ans = 2.00 * PI * r ;
	return cout<<fixed<<setprecision(10)<<ans<<"\n" , 0 ;
}		

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

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

typedef long long ll;

using namespace std;

//-------------------------↓↓↓↓↓↓------------------------

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

      int N, a, cou = 0;
      cin >> N;
      rep(i,N){
        cin >> a;
        if(a % 2 == 1)cou++;
      }
      if(cou % 2 == 0)cout << "YES" << "\n";
      else cout << "NO" << "\n";
     

       
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define MOD 1000000007
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define LLINF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main(void){
  string s;
  ll k;
  cin>>s>>k;
  int one=-1;
  for(int i=0;i<s.length();i++){
    if(s[i]!='1'){
      one=i;
      break;
    }
    if(i==s.length()-1)one=s.length();
  }
  if(k<=one)cout<<'1'<<endl;
  else cout<<s[one]<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
d = sorted(list(map(int, input().split())) + [0])

ans, cnt = [], 1
for num in d:
    ans.append(((num - 12) * cnt + 12) % 24)
    cnt *= -1

ans = sorted(ans + [i + 24 for i in ans])
s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))
print(s)


Measured memory_bytes: 61992
n = int(input())
a = list(map(int,input().split()))
ans = [0]*n
mini = a[0]
for i in range(1,n):
    if a[i] - mini >= 0:
        mini = a[i]
    else:
        ans[i] = mini - a[i]
        mini

print(sum(ans))

Measured memory_bytes: 32328
#include <stdio.h>
#include <stdlib.h>
#define N 10000
#define NIL -1
typedef struct node{
  int parent;
  int right;
  int left;
}Node;

Node T[N];
int n,D[N],H[N];

void preorder(int);
void inorder(int);
void postorder(int);


int main(){
  int i,v,l,r,root=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    T[i].parent = NIL;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l!=NIL) T[l].parent = v;
    if(r!=NIL) T[r].parent = v;
  }
  for(i=0;i<n;i++){
    if(T[i].parent == NIL){
      root=i;
    }
  }

  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");

  return 0;
}


void preorder(int u){
  if(u==NIL){
    return;
  }
  printf(" %d",u);
  preorder(T[u].left);
  preorder(T[u].right);
}

void inorder(int u){
  if(u==NIL){
    return;
  }
  inorder(T[u].left);
  printf(" %d",u);
  inorder(T[u].right);
}

void postorder(int u){
  if(u==NIL){
    return;
  }
  postorder(T[u].left);
  postorder(T[u].right);
  printf(" %d",u);
}




Measured memory_bytes: 2100
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int num = Integer.parseInt(sc.next());
        int[] s = new int[num];
        for(int i=0; i<num; i++){
            s[i] = Integer.parseInt(sc.next());
        }
        
        int q = Integer.parseInt(sc.next());
        int count=0, wanted=0;
        for(int i=0; i<q; i++){
            wanted = Integer.parseInt(sc.next());
            if(binarySearch(s, wanted)>=0) count++;
        }
        System.out.println(count);
    }
    public static int binarySearch(int[] dt, int target){
        int left=0, right=dt.length-1;
        int mid=-1;
        
        while(left<=right){
            mid = (right+left)/2;
            if(dt[mid] == target){
                return mid;
            }
            if(dt[mid] < target){
                left=mid+1;
            }else{
                right=mid-1;
            }
        }
        return -1;
    }
}


Measured memory_bytes: 69876