akhauriyash/Code-Regression huggingface dataset:
import numpy as np

n,k = map(int, input().split())
lstA = np.array(sorted(list(map(int, input().split()))))
lstF = np.array(sorted(list(map(int, input().split())), reverse=True))
s = lstA.sum()

left = -1
right = 10**12

while True:
    center = (left+right)//2
    if s-np.minimum(lstA, center//lstF).sum() <=k:
        right = center
    else:
        left = center
    if right <= left+1:
        print(right)
        exit()


Measured memory_bytes: 37272
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
//const ll MOD = 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

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

    int n;
    cin >> n;
    string s[100010];
    rep(i, n) cin >> s[i];
    rep(i, n) sort(all(s[i]));
    set<string> for_search;
    multiset<string> cnt;

    rep(i, n) {
        for_search.insert(s[i]);
        cnt.insert(s[i]);
    }
    ll ans = 0;

    for (auto si : for_search) {
        ll c = cnt.count(si);
        ans += c * (c - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 24448
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn=100000;

int main(){
   
    int n;
    ll mod=INF;
    ll ans=0;
    string s1,s2;
    vector<ll> v;
   
    cin >> n;
    cin >> s1;
    cin >> s2;
    
    int ite=0;
    while(ite<s1.size()){
        if(s1[ite]==s2[ite]){
            v.push_back(1);
            ite+=1;
        }else{
            v.push_back(2);
            ite+=2;
        }
    }
    
    
    rep(i,v.size()){
        if(i==0){
            if(v[i]==1){
                ans=3;
            }else{
                ans=6;
            }
        }else{
            if(v[i-1]==1){
                if(v[i]==1){
                    ans=(ans*2)%mod;
                }else{
                    ans=(ans*2)%mod;
                }
            }else{
                if(v[i]==1){
                    ans=(ans*1)%mod;
                }else{
                    ans=(ans*3)%mod;
                }
            }
        }
    }

    cout << ans<<endl;
    
    return 0;
}


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

int main(){
 ll A, B;
 cin >> A >> B;
 string S;
 cin >> S;
 ll count = 0;
 if (S.length() == A+B+1) {
     for(int i = 0; i < S.length(); i++){
         if(S[i] == '-')count++;
     }
     if(count==1 && S[A] == '-'){
         cout << "Yes" << endl;
         return 0;
     }
 }
 cout << "No" << endl;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,m,l;
  int i,j,k;
  scanf("%d %d %d",&n,&m,&l);

  int A[n][m],B[m][l];
  long int C[n][l];
  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      scanf("%d",&A[i][j]);
    }
  }

  for(i=0; i<m; i++){
    for(j=0; j<l; j++){
      scanf("%d",&B[i][j]);
    }
  }

  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      C[i][j]=0;
    }
  }

  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      for(k=0; k<m; k++){
	C[i][j]+=A[i][k]*B[k][j];
      }
    }
  }

  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      if(j!=l-1)
	printf("%ld ",C[i][j]);
      else
	printf("%ld",C[i][j]);
    }
    puts("");
  }
  return 0;
  
}
	  



Measured memory_bytes: 2144
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

const int SIZE = 2 * (100000 + 10);
ll dp[SIZE][3];

int janken(char c) {
  if(c == 'r') return 0;
  if(c == 's') return 1;
  return 2;
}

int main() {
  int N, K; cin>>N>>K;
  vector<ll> P(3);
  REP(i,3) cin>>P[i];
  string T; cin>>T;
  for(int s = K; s < K + K; s++) { 
    for(int i = s; i < N + K; i += K) {
      const int o = janken(T[i-K]);
      for(int m = 0; m <= 2; m++) {
	ll point = 0;
	if((m+1)% 3 == o) {
	  point = P[m];
	}
	//	cout << i << m << o << point << endl;
	for(int n = 0; n <= 2; n++) {
	  if(m==n) continue;
	  chmax(dp[i][m], dp[i-K][n] + point);
	}
	
      }
    }
  }
  ll ans = 0;
  for(int i = N; i < N + K; i++) {
    //    cout << i;
    ll tmp = 0;
    REP(j,3) {
      chmax(tmp, dp[i][j]);
      //      cout <<  " " << dp[i][j];
    }
    ans += tmp;
    //    cout << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K == 1:
    print(0)
else:
    S, LUT, ans = [0], {0: 1}, 0
    for a in A:
        S.append(S[-1] + a)
    for i in range(1, N + 1):
        p = (S[i] - i) % K
        ans += LUT.get(p, 0)
        LUT[p] = LUT.get(p, 0) + 1
        if i - K + 1 >= 0:
            LUT[(S[i - K + 1] - i + K - 1) % K] -= 1
    print(ans)


Measured memory_bytes: 112456
class PriorityQueue
  attr_accessor :data

  def initialize(arr=[])
    @data = arr
  end

  def push(e)
    @data.push(e)

    current_index = @data.size-1
    parent_index = parent(current_index)

    while current_index > 0 && @data[parent_index] > @data[current_index]
      @data[current_index] = @data[parent_index]
      @data[parent_index] = e
      current_index = parent_index
      parent_index = parent(current_index)
    end
  end

  def pop
    ret = @data.first
    last = @data.last
    current_index = 0

    while have_child?(current_index)
      li = left_child_index(current_index)
      ri = right_child_index(current_index)

      ni = li
      ni = ri if ri < @data.size && @data[ri] < @data[li]

      break if @data[ni] >= last

      @data[current_index] = @data[ni]
      current_index = ni
    end
    @data[current_index] = last
    @data.pop

    ret
  end

  def size
    @data.length
  end

  def parent(index)
    (index-1)/2
  end

  def left_child_index(index)
    2*index+1
  end

  def right_child_index(index)
    2*index+2
  end

  def have_child?(index)
    left_child_index(index) < @data.size
  end
end

class BigPQ < PriorityQueue
  def push(e)
    @data.push(e)

    current_index = @data.size-1
    parent_index = parent(current_index)

    while current_index > 0 && @data[parent_index] < @data[current_index]
      @data[current_index] = @data[parent_index]
      @data[parent_index] = e
      current_index = parent_index
      parent_index = parent(current_index)
    end
  end

  def pop
    ret = @data.first
    last = @data.last
    current_index = 0

    while have_child?(current_index)
      li = left_child_index(current_index)
      ri = right_child_index(current_index)

      ni = li
      ni = ri if ri < @data.size && @data[ri] > @data[li]

      break if @data[ni] <= last

      @data[current_index] = @data[ni]
      current_index = ni
    end
    @data[current_index] = last
    @data.pop

    ret
  end
end


n=gets.strip.to_i
aa = gets.strip.split.map(&:to_i)

bpq = BigPQ.new
pq = PriorityQueue.new

n.times do |i|
  pq.push(aa[i])
  bpq.push(aa[3*n-1-i])
end

left_score = pq.data.inject(:+)
left_scores = [left_score]

right_score = bpq.data.inject(:+)
right_scores = [right_score]

n.times do |i|
  c = aa[n+i]
  if c >= pq.data.first
    pq.push(c)
    left_score -= pq.pop
    left_score += c
  end
  left_scores.push(left_score)

  c = aa[2*n-1-i]
  if c <= bpq.data.first
    bpq.push(c)
    right_score -= bpq.pop
    right_score += c
  end
  right_scores.unshift(right_score)
end

result = left_scores.zip(right_scores).map {|l, r| l-r }.max

#p left_scores
#p right_scores
p result




Measured memory_bytes: 34824
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;
 
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }
 
    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int n = in.nextInt();
 
            if (k % 2 == 0) {
                out.print(k / 2);
                for (int i = 0; i < n - 1; i++) {
                    out.print(" " + k);
                }
                out.println();
                return;
            }
 
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add((k + 1) / 2);
            }
            for (int i = 0; i < n / 2; i++) {
                if (list.get(list.size() - 1) == 1) {
                    list.remove(list.size() - 1);
                } else {
                    list.set(list.size() - 1, list.get(list.size() - 1) - 1);
                    while (list.size() < n) list.add(k);
                }
            }
            for (int i = 0; i < list.size(); i++) {
                if (i > 0) out.print(" ");
                out.print(list.get(i));
            }
            out.println();
        }
 
    }
 
    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;
 
        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(nextString());
        }
 
        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }
 
    }
}

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

int main() {
  int N;
  cin >> N;
  
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    os << "["; 
    for (int i = 0; i < v.size(); ++i) { 
        cout << v[i]; 
        if (i != v.size() - 1) 
            os << ", "; 
    } 
    os << "]"; 
    return os; 
} 
template <typename T> 
ostream& operator<<(ostream& os, const set<T>& v) 
{ 
    os << "["; 
    for (auto it : v) { 
        os << it; 
        if (it != *v.rbegin()) 
            os << ", "; 
    } 
    os << "]"; 
    return os; 
} 
  template <typename T, typename S> 
ostream& operator<<(ostream& os, const map<T, S>& v) 
{ 
    for (auto it : v)  
        cout << it.first << " : " 
           << it.second << "\n"; 
      
    return os; 
} 
template <typename T, typename S> 
ostream& operator<<(ostream& os, const pair<T, S>& v) 
{ 
    os << "("; 
    cout << v.first << ", " 
       << v.second << ")"; 
    return os; 
} 
  
// D

void solve(){
int n;
cin>>n;
vector<int> ans(n);
int a;
cin>>a;
ans[0] = a;
FOR(i,1,n) {
    cin>>ans[i];
    a^=ans[i];
} 
FOR(i,0,n) cout<<(ans[i]^a)<<" ";
}
int32_t main()
{
IOS
int t=1;
// cin>>t;
while(t--) {
    solve();
}

return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int main() {
    int64 N, A, B; cin >> N >> A >> B;
    if (A > B) {
        cout << 0 << endl;
        exit(0);
    }
    if (N <= 2) {
        if (A == B) cout << 1 << endl;
        else cout << 0 << endl;
        exit(0);
    }

    int64 s = A * (N - 2);
    int64 e = B * (N - 2);

    cout << e - s + 1 << endl;
}


Measured memory_bytes: 256
var
	n,a,m,p,i,s:Longint;
begin
	readln(n);
	m:=1000000000;
	for i:=1 to n do begin
		read(a);
		if a<m then m:=a;
		if p<a-m then begin
			p:=a-m;
			s:=0;
		end;
		if p=a-m then inc(s);
	end;
	writeln(s);
end.


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace Curtain
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string slimeString = Console.ReadLine();

            var slimes = new List<char>();

            for (int i = 0; i < slimeString.Length; i++)
            {
                slimes.Add(slimeString[i]);
            }

            for (int i = 0; i < slimes.Count; i++)
            {
                if (i + 1 < slimes.Count && slimes[i] == slimes[i + 1])
                {
                    N = N - 1;
                }
            }

            Console.WriteLine(N);
        }
    }
}


Measured memory_bytes: 13228
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int A[100000 + 1], q, n, key;
    int sum = 0;

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

    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> key;
        if (*lower_bound(A, A + n, key) == key) {
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3404
import queue


def bfs(u):
    state = ['new']*n
    distance = [0]*n
    q = queue.Queue()
    
    state[u] = 'visited'
    distance[u] = 0
    q.put(u)
    
    while not q.empty():
        u = q.get()
        for v in Adj[u]:
            if state[v[0]] == 'new':
                state[v[0]] = 'visited'
                distance[v[0]] = distance[u]+v[1]
                q.put(v[0])
    
    return distance
    


n = int(input())

Adj = [[] for _ in range(n)]
for i in range(n-1):
    s,t,w = map(int,input().split())
    Adj[s].append([t,w])
    Adj[t].append([s,w])

distance = bfs(0)
max_index = 0
max_d = 0
for i in range(n):
    if max_d<distance[i]:
        max_index = i
        max_d = distance[i]
print(max(bfs(max_index)))


Measured memory_bytes: 50668
#include <stdio.h>

int main(void){
	
	int n,r,num_min;
	int fin_max = -1000000000;
	
	scanf("%d", &n);
	scanf("%d", &num_min);
	for(int i = 0; i < n-1; i++){
		scanf("%d", &r);
		if( r-num_min > fin_max ) fin_max = r-num_min;
		if( r < num_min ) num_min = r;
	}
	printf("%d\n", fin_max);
	
}


Measured memory_bytes: 2100
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int MIN(int A,int B){
    return A<B?A:B;
}

int MAX(int A,int B){
    return A>B?A:B;
}

int main(void){
    int n,sum=0;
    scanf("%d",&n);
    int w[n];
    for (int i=0; i<n; i++){
        scanf("%d",&w[i]);
        sum+=w[i];
    }
    int ans=1e9,sum2=0;
    for (int i=0; i<n-1; i++){
        sum2+=w[i];
        ans=MIN(abs((sum-sum2)-sum2),ans);
    }
    printf("%d\n",ans);
    return 0 ;
}

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

int main()
{
	string s;
	ll ac(0),wa(0),tle(0),re(0),n;
	cin>>n;
	while(n--)
	{
		cin>>s;
		if(s=="AC")
		{
			ac++;
		} else if(s=="WA")
		{
			wa++;
		} else if(s=="TLE")
		{
			tle++;
		} else if(s=="RE")
		{
			re++;
		}
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define debug2(a, b) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<endl
#define debug3(a, b, c) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<endl
#define debug4(a, b, c, d) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<" | "<<#d<<" = "<<d<<endl
#define debug5(a, b, c, d, e) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<" | "<<#d<<" = "<<d<<" | "<<#e<<" = "<<e<<endl
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 1000 + 5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
int convert[26];
int convert2[26];
int main() {
	string s, t;
	cin>>s>>t;
	for(int i=0; i<26; ++i) {
		convert2[i] = convert[i] = -1;
	}
	for(int i=0; i<s.size(); ++i) {
		if((convert[s[i]-'a']!=-1 && convert[s[i]-'a']!=t[i]-'a')||(convert2[t[i]-'a']!=-1 && convert2[t[i]-'a']!=s[i]-'a')) {
			// debug3(i, s[i], t[i]);
			printf("No\n");
			return 0;
		} else {
			convert[s[i]-'a'] = t[i]-'a';
			convert2[t[i]-'a'] = s[i]-'a';
		}
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 776
function Main(input) {
	
    input = input.split("\n");
	
    const i = String(input[0]).trim();

    if( i === '0' ){
        console.log('1');
    } else if(i === '1') {
        console.log('0');
    }
}

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

Measured memory_bytes: 29664
#include <iostream>
using namespace std;
int main(void){
    int d,g,p[10],c[10],z=1000;
    cin>>d>>g;
    for(int i=0;i<d;i++){
        cin>>p[i]>>c[i];
    }
    for(int i=0;i<(1<<d);i++){
        int n=0,m=0,l[1000],k=0;
        for(int j=0;j<d;j++){
            if((1&i>>j)==1){
                n+=p[j];
                m+=p[j]*(j+1)*100+c[j];
            }else{
                for(int h=0;h<p[j];h++){
                    l[k]=(j+1)*100;
                    k++;
                }
            }
        }
        while(m<g){
            k--;
            m+=l[k];
            n++;
        }
        z=min(z,n);
    }
    cout<<z<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
string S;
int main(){
	cin>>S;
	bool ans=false;
	REP(i,(int)S.size()-1){
		if(S.substr(i,2)=="AC"){
			ans=true;
		}
	}
	cout<<(ans ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
/*
 * @Author: RBQRBQ
 * @Date: 2020-04-10 22:42:18
 * @LastEditors: RBQRBQ
 * @LastEditTime: 2020-04-12 23:54:47
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> pii;
namespace IO{
    template<typename T>inline void read(T &x){
        x=0;ll f=1;char ch=getchar();
        while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
        while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
        x=x*f;
    }
}
using namespace IO;
ll N;
long double L;
const int maxn=5000;
long double T[maxn];

#define pi 3.14159265358979323846
int main()
{
    cin>>N>>L;
    for(int i=1;i<=N;i++)
    cin>>T[i];
    long double rx=0.0,ry=0.0;
    for(int i=1;i<=N;i++)
    for(int j=i+1;j<=N;j++)
    {
        rx+=(N-2*j+2*i)*cos((long double)2*pi*(T[j]+T[i])/(long double )(2.0*L));
        ry+=(N-2*j+2*i)*sin((long double)2*pi*(T[j]+T[i])/(long double)(2.0*L));
    }
    cout<<fixed<<setprecision(13)<<(long double)(6*rx)/(long double)((N)*(N-1)*(N-2))<<" "<<(long double)(6*ry)/(long double)((N)*(N-1)*(N-2));
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>


int main()
{
  int i,n,score1 = 0,score2 = 0;
  char n1[100],n2[100];

  scanf("%d",&n);

  for(i = 0; i < n; i++)
  {
    scanf("%s %s",n1,n2);
    if(strcmp(n1,n2) > 0)
    {
      score1 += 3;
    }
    else if(strcmp(n1,n2) == 0) 
    {
      score1++;
      score2++;
    }
    else if(strcmp(n1,n2) < 0)
    {
      score2 += 3;
    }
  }
  printf("%d %d\n",score1,score2);

  return 0;
}

Measured memory_bytes: 604
//ll _(){
//    ll n;
//    cin >> n;
//    vvl grid(2,vl(n));
//    cin >> grid;
//    vvl ans = grid;
//    rep(i,0,1)
//        rep(j,0,n-1){
//            if(i == 0){
//                if(j)
//                    grid[i][j] += grid[i][j-1];
//            }else if(j == 0){
//                if(i)
//                    grid[i][j] += grid[i-1][j];
//            }
//            else{
//                grid[i][j] += max(grid[i-1][j],grid[i][j-1]);
//            }
//
//        }
//    return grid[1][n-1];
//}
//
//
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
ll _(){
    ll n;
    cin >> n;
    vvl grid(2,vl(n));
    cin >> grid;
    vvl ans = grid;
    rep(i,0,1)
        rep(j,0,n-1){
            if(i == 0){
                if(j)
                    grid[i][j] += grid[i][j-1];
            }else if(j == 0){
                if(i)
                    grid[i][j] += grid[i-1][j];
            }
            else{
                grid[i][j] += max(grid[i-1][j],grid[i][j-1]);
            }
        }
    return grid[1][n-1];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[][] g;
	static boolean[] dead;
	static int N;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			g = new int[N][N];
			dead = new boolean[N];
			int M = sc.nextInt();
			Sink[] sk = new Sink[N];
			for (int i = 0; i < N; ++i) {
				sk[i] = new Sink(sc.nextInt(), i);
			}
			Arrays.sort(sk);
			for (int i = 0; i < M; ++i) {
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				int c = sc.nextInt();
				g[a][b] = g[b][a] = c;
			}
			if (!connect(N)) {
				System.out.println(0);
				continue;
			}
			int pos = 0;
			while (pos < N) {
				int pp = pos;
				int t = sk[pos].t;
				while (pos < N && sk[pos].t == t) {
					dead[sk[pos].i] = true;
					++pos;
				}
				if (!connect(N - pos)) {
					for (int i = pp; i < pos; ++i) {
						dead[sk[i].i] = false;
					}
					pos = pp;
					break;
				}
			}
			ArrayList<Integer> from = new ArrayList<Integer>();
			ArrayList<Integer> to = new ArrayList<Integer>();
			for (int i = 0; i < N; ++i) {
				if (!dead[i]) to.add(i);
			}
			from.add(to.get(to.size() - 1));
			to.remove(to.size() - 1);
			int ans = mst(from, to);
			from.addAll(to);
			while (pos > 0) {
				to.clear();
				int t = sk[pos - 1].t;
				while (pos > 0 && sk[pos - 1].t == t) {
					dead[sk[pos - 1].i] = false;
					to.add(sk[pos - 1].i);
					--pos;
				}
				ans += mst(from, to);
				from.addAll(to);
			}
			System.out.println(ans);
		}
	}

	static boolean connect(int rest) {
		int st = 0;
		for (int i = 0; i < N; ++i) {
			if (!dead[i]) {
				st = i;
				break;
			}
		}
		boolean[] used = new boolean[N];
		ArrayList<Integer> pos = new ArrayList<Integer>();
		pos.add(st);
		int c = 0;
		while (c != pos.size()) {
			int cur = pos.get(c);
			++c;
			used[cur] = true;
			for (int i = 0; i < N; ++i) {
				if (dead[i] || used[i]) continue;
				if (g[cur][i] == 0) continue;
				pos.add(i);
				used[i] = true;
			}
		}
		return c == rest;
	}

	static int mst(ArrayList<Integer> from, ArrayList<Integer> to) {
		boolean[] used = new boolean[N];
		PriorityQueue<Long> q = new PriorityQueue<Long>();
		for (int v : from) {
			q.add((long) v);
		}
		int sum = 0;
		while (!q.isEmpty()) {
			long cur = q.poll();
			int ci = (int) cur;
			int cc = (int) (cur >> 32);
			if (used[ci]) continue;
			sum += cc;
			used[ci] = true;
			for (int v : to) {
				if (used[v]) continue;
				if (g[ci][v] == 0) continue;
				q.add((((long) g[ci][v]) << 32) + v);
			}
		}
		return sum;
	}

	static class Sink implements Comparable<Sink> {
		int t, i;

		public Sink(int t, int i) {
			this.t = t;
			this.i = i;
		}

		public int compareTo(Sink o) {
			return this.t - o.t;
		}
	}

}

Measured memory_bytes: 172104
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <set>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[100005];

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	
	llint ans = 0;
	for(int i = 1; i < n-1; i++){
		llint sum = 0;
		if(i >= n-1-i) continue;
		for(int j = i; j <= n-1; j+=i){
			if((n-1-j)%i == 0 && j >= (n-1-j)) break;
			if((n-1-j)<=i) break;
			sum += a[j] + a[n-1-j];
			ans = max(ans, sum);
			//cout << i << " " << j << " " << ans << endl;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(void) {
	int a, b, c, x, ans = 0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i < (a+1); i++) {
		for (int j = 0; j < (b+1); j++) {
			for (int k = 0; k < (c+1); k++) {
				if ((500 * i + 100 * j + 50 * k) == x) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define outl(x) cout << (x) << '\n'
using namespace std;
typedef long long ll;

constexpr int MX = 101010;
constexpr int MOD = (int)1e9 + 7;

int f[MX], finv[MX];

inline ll sqr(ll n)
{
    return n * n;
}

inline int modPow(int n, int p)
{
    if (p <= 0) return 1;
    ll ret = sqr(modPow(n, p/2)) % MOD;
    if (p & 1) (ret *= n) %= MOD;
    return ret;
}

void preCalc()
{
    f[0] = finv[0] = 1;
    for (ll i = 1; i < MX; ++i) {
        f[i] = i * f[i-1]  % MOD;
        finv[i] = modPow(f[i], MOD-2);
    }
    return;
}

inline int combi(int n, int k)
{
    if (k < 0 || n < k) return 0;
    return 1LL * f[n] * finv[k] % MOD * finv[n-k] % MOD;
}

int main()
{
    int N, l, r;
    int pos[MX];

    preCalc();
    memset(pos, -1, sizeof(pos));

    cin.tie(nullptr); ios::sync_with_stdio(false);

    cin >> N;
    ++N;
    rep(i, N) {
        int a; cin >> a;
        if (~pos[a]) l = pos[a], r = i;
        else pos[a] = i;
    }

    for (int i =1; i <= N; ++i) {
        outl( (combi(N, i) - combi(N-1-r+l, i-1) + MOD) % MOD );
    }
}


Measured memory_bytes: 2432
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;
template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
ll mod_pow(ll a, ll n, T mod) {
    mod = (ll)mod;
    ll res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

void dfs(const int start, vector<int> &dist, vector<vector<int>> &tree) {
    deque<pair<int, int>> s;
    s.push_back({start, 0});
    bool visited[tree.size()] = {};
    while (!s.empty()) {
        pair<int, int> p = s.back();
        s.pop_back();
        visited[p.first] = true;
        dist[p.first] = p.second;
        for (auto &node : tree[p.first]) {
            if (!visited[node]) {
                s.push_back({node, p.second + 1});
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> dist_f(N, 0), dist_s(N, 0);
    vector<vector<int>> tree(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(0, dist_f, tree);
    dfs(N - 1, dist_s, tree);
    int cnt = 0;
    rep(i, N) {
        if (dist_f[i] > dist_s[i]) cnt++;
    }
    if (cnt >= N - cnt)
        cout << "Snuke" << endl;
    else
        cout << "Fennec" << endl;

    return 0;
}

Measured memory_bytes: 8576
open Scanf
open Printf

let id a = a
let pair a b = a, b
let triplet a b c = a, b, c

let rec scan_list = function
  | 1 -> scanf "%d" (fun k -> [k])
  | n -> scanf "%d " (fun k -> k :: scan_list (n-1))

let f s w = let rec g k = if k < String.length s
              then begin
                printf "%c" (String.get s k);
                g (k+w)
              end
              else printf "\n"
  in g 0

let () = scanf "%s\n%d\n" f

Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A, B;
  cin >> N;
  cin >> A >> B;

  ll ans = 0;
  if (B == 0 && A == 0) {
    ans = 0;
  } else if (A == 0) {
    ans = 0;
  } else if (B == 0) {
    ans = N;
  } else {
    ans = N / (A + B) * A + min((N % (A + B)), A);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x)		(x).begin(),(x).end()

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

//-------------------------------------------
int n,s;
int ans=0;

void dfs(int nnum,int cnt,int sum){
    //cout << "nnum:" << nnum << "\tcnt:" << cnt << "\tsum;" << sum << "\t lastadded:"<<nnum-1 << "\tans:" << ans << endl;
    if(cnt==n){
        if(sum==s){
            ans++;
        }
        return;
    }
    if(nnum<=9){
        dfs(nnum+1,cnt+1,sum+nnum);
        dfs(nnum+1,cnt,sum);
    }
    return;
}

int main(){
    while(1){
        ans = 0;
        cin >> n >> s;
        if(n==0&&s==0) break;
        dfs(0,0,0);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			list.add(number);
		}
		
		int counter = 0;
		boolean listHasOdd = false;
		while(!listHasOdd) {
			for(int i = 0; i < list.size()-1; i++) {
				if(!(list.get(i) % 2 == 0)) {
					System.out.println(counter);
					listHasOdd = true;
					return;
				}
				int devidedNumber = list.get(i) / 2;
				list.set(i, devidedNumber);
			}
			counter++;
			
		}

		}

		
	}




Measured memory_bytes: 21716
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc161
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            int n = nm[0];
            int m = nm[1];
            int ans = (n *( n - 1) / 2)+   (m * (m - 1) / 2);
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 100001
int MOD=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

void solve()
{
    int n; cin>>n;
    vector<int> adj[n+1]; int x;
    for(int i=2;i<=n;i++)
    {
        cin>>x;
        adj[x].pb(i);
    }
    for(int i=1;i<=n;i++)
    cout<<adj[i].size()<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test;test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
inline int read() {
	int f=1,sum=0;
	char x=getchar();
	for(;(x<'0'||x>'9');x=getchar()) if(x=='-') f=-1;
	for(;x>='0'&&x<='9';x=getchar()) sum=sum*10+x-'0';
	return f*sum;
}

ll A,B,C,D;

inline ll gcd(ll x,ll y) {return y?gcd(y,x%y):x;}

int main() {
	//freopen("a.in","r",stdin);
	int Test_=read();
	while (Test_--) {
		cin>>A>>B>>C>>D;
		if(A<B||D<B) puts("No");
		else if(C>=B-1) puts("Yes");
		else {
			ll d=gcd(D%B,B)%B;
			if(!d) {
				if(A%B>=C+1) puts("No");
				else puts("Yes");			
			}
			else {
				if(A%B>=C+1) puts("No");
				else {
					ll c=C-A%B;
					c=c/d+1;
					if((c*d%B+A%B)%B>=C+1) puts("No");
					else puts("Yes");
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

struct pair{
  int p;
  int y;
  int num;
};

int compare_y(const void *x, const void *y) {
  return ((struct pair *)x)->y - ((struct pair *)y)->y;
}

int compare_num(const void *x, const void *y) {
  return ((struct pair *)x)->num - ((struct pair *)y)->num;
}

int main() {
  int N,M;
  scanf("%d %d",&N,&M);
  struct pair PY[M];
  int check[N];
  for (int i = 0; i < N; i++) {
    check[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    scanf("%d %d",&PY[i].p,&PY[i].y);
    PY[i].num = i;
  }
  qsort(PY,M,sizeof(struct pair),compare_y);

  for (int i = 0; i < M; i++) {
    int pref = PY[i].p-1;
    int city = check[pref];
    PY[i].y = city+1;
    check[pref] += 1;
  }

  qsort(PY,M,sizeof(struct pair),compare_num);

  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n",PY[i].p,PY[i].y);
  }
  return 0;
}


Measured memory_bytes: 4204
S = list(input())
T = list(input())
NS,NT = len(S),len(T)
outs = []
if NS>=NT:
    for i in range(NS-NT+1):
        flag = 0
        for j in range(NT):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                flag = 1
                break
        if flag==0:
            out = ["a"]*NS
            for j in range(NT):
                out[i+j]=T[j]
            for j in range(NS):
                if S[j]!="?":
                    out[j]=S[j]
            outs.append("".join(out))

if len(outs) == 0:
    print("UNRESTORABLE")
else:
    print(outs[-1])

Measured memory_bytes: 62672
#include <iostream>
#include <vector>
using namespace std;
int n,a,b;
vector<int> v[100001];
int F[100001],S[100001];

void dfs(int *D,int node,int num){
    D[node]=num;
    for(int i=0;i<v[node].size();i++){
        if(D[v[node][i]]==-1)dfs(D,v[node][i],num+1);
    }
}

int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1;i<=n;i++)F[i]=-1,S[i]=-1;
    dfs(F,1,0);
    dfs(S,n,0);
    int f=0,s=0;
    for(int i=1;i<=n;i++){
        if(F[i]>S[i])s++;
        else f++;
    }
    cout<<(f>s?"Fennec":"Snuke");
}


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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int a,b;
int main() {
    cin >> a >> b;
    int sum = 0;
    sum += max (a,b);
    int p = max(a,b);
    p--;
    sum += max(p,min(a,b));
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

vector<int> dp(10, -1);
int h, w, c[10][10];
int dfs(int i, vector<int> p = vector<int>())
{
    if (dp[i] >= 0)
    {
        return dp[i];
    }
    int closest = c[i][1];
    p.emplace_back(i);
    rep(k, 10)
    {
        if (find(p.begin(), p.end(), k) != p.end())
            continue;
        closest = min(closest, dfs(k, p) + c[i][k]);
    }
    if (p.size() == 1)
        dp[i] = closest;
    return closest;
}

int main()
{
    cin >> h >> w;
    rep(i, 10) rep(j, 10) cin >> c[i][j];
    vector<vector<int>> a(h, vector<int>(w));
    rep(i, h) rep(j, w)
    {
        cin >> a[i][j];
        a[i][j] = a[i][j] == -1 ? 1 : a[i][j];
    }

    dp[1] = 0;
    rep(i, 10)
    {
        dp[i] = dfs(i, vector<int>());
    }

    int ans = 0;
    rep(y, h) rep(x, w)
    {
        ans += dp[a[y][x]];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
import itertools

N,C=[int(i) for i in input().split()]
D=[[int(i) for i in input().split()] for _ in range(C)]
c=[[int(i)-1 for i in input().split()] for _ in range(N)]

costXY = [[0]*C for _ in range(3)]



for X in range(3):
    for Y in range(C):
        costXY[X][Y] = sum([D[c[i][j]][Y] for i,j in itertools.product(range(N), repeat=2) if (i+j)%3==X])

#print(costXY)    

ans = 1<<31
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i==j or j==k or k==i:
                continue
            p=costXY[0][i] + costXY[1][j] + costXY[2][k]
#            print(p)
            ans = min(ans,p)
print(ans)
            
            
            
            
            


Measured memory_bytes: 120000
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

using namespace std;

const int N = 3005, MOD = 1e9 + 7;

int n;
string s;

int dp[N][N], S[N][N];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>s;
    s = "##" + s;
    dp[1][1] = 1;
    S[1][1] = 1;
    for (int i = 2; i <= n; i++)
        for (int j = 1; j <= i; j++){
            if (s[i] == '<')
                dp[i][j] = S[i - 1][j - 1];
            else
                dp[i][j] = (S[i - 1][i - 1] - S[i - 1][j - 1] + MOD) % MOD;
            S[i][j] = (S[i][j - 1] + dp[i][j]) % MOD;
        }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans = (ans + dp[n][i]) % MOD;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 69504
while True:
    (H, W) = [int(i) for i in input().split()]

    if H == W == 0:
        break

    for i in range(H):
        for r in range(W):
            if (i + r) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
            #print('#', end='') if (i + r) % 2 == 0 else print('.', end='')
        print()
    print()

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

int n, m;
char a[60][60], b[60][60];

int main(){
  cin >> n >> m;
  rep(i, n){
    cin >> a[i];
  }
  rep(i, m){
    cin >> b[i];
  }
  
  string res = "No";
  rep(i, n - m + 1){
    rep(j, n - m + 1){
      bool flag = true;
      for(int k = 0; k < m; k++){
        for(int l = 0; l < m; l++){
          if(a[i + k][j + l] != b[k][l]){
            flag = false;
          }
        }
      }
      if(flag){
        cerr << i << " "<<j <<endl;
        res = "Yes";
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
def step(n, x, y, theta):
    x += n*math.sin(theta)
    y += n*math.cos(theta)
    return x, y
    
n, m = 100, 100
x, y, theta = 0.0, 0.0, 0.0
while n != 0 and m != 0:
    n, m = map(int, raw_input().split(","))
    m = (m * math.pi)/180
    x, y = step(n, x, y, theta)
    theta = (m + theta)
print int(x)
print int(y)

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

long long patty[55];
long long bun[55];

long long burger(long long n,long long k);
int main(){
  long long n,k;
  cin>>n>>k;
  patty[0]=1;
  bun[0]=0;
  for(long long i=1;i<=n;i++){
    patty[i]=patty[i-1]*2+1;
    bun[i]=bun[i-1]*2+2;
  }
  
  cout<<burger(n,k)<<endl;
  return(0);
}

long long burger(long long n,long long k){
  if(k==0){
    return(0);
  }
  if(n==0){
    return(1);
  }
  
  if(k <= (patty[n]+bun[n])/2){
    return(burger(n-1,k-1));
  }else if(k > (patty[n]+bun[n])/2+1){
    return(patty[n-1] + 1 + burger(n-1,k-((patty[n]+bun[n])/2+1)));
  }
  return(patty[n-1] + 1);
}


Measured memory_bytes: 256