akhauriyash/Code-Regression huggingface dataset:
from itertools import count
def max_dist(adj,v):

    q = [v]
    visited = [False]*len(adj)
    visited[v] = True
    last = None
    for d in count():
        if not q:
            return d,last
        nq = []
        last = q[0]
        for v in q:
            for u in adj[v]:
                if not visited[u]:
                    visited[u] = True
                    nq.append(u)
        q = nq


def solve(S):

    N = len(S)

    adj = [[] for _ in range(N)]
    for i,l in enumerate(S):
        for j,f in enumerate(l):
            if f:
                adj[i].append(j)

    stack = [0]
    color = [None]*N
    color[0] = True

    while stack:
        v = stack.pop()
        nc = not color[v]
        for u in adj[v]:
            if color[u] is None:
                color[u] = nc
                stack.append(u)
            elif color[u] != nc:
                return -1

    return max(max_dist(adj,v)[0] for v in range(N))

if __name__ == '__main__':
    N = int(input())
    S = [[c=='1' for c in input()] for _ in range(N)]
    print(solve(S))

Measured memory_bytes: 68656
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC108A
int main(void) {
  int n, k, i, cou=0, tmp;
  scanf("%d", &n);
  if(n%2==0) printf("%d", n*n/4);
  else printf("%d", n/2*(n/2+1));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
const int INF = INT_MAX;
const ll MOD = 998244353;


template <ll mod>
struct ModCombination{
    ll N;
    vector<ll> fact,inv,finv;
    
    ModCombination(ll n):N(n){
        fact.assign(n+1, 1);
        inv.assign(n+1, 1);
        finv.assign(n+1,1);
        for(int i=1;i<n;i++){
            fact[i+1] = fact[i]*(i+1)%mod;
            inv[i+1] = inv[mod%(i+1)]*(mod-mod/(i+1))%mod;
            finv[i+1] = finv[i]*inv[i+1]%mod;
        }
    }
    
    ll Comb(ll n,ll k){
        return (fact[n]*finv[k]%mod)*finv[n-k]%mod;

    }
};

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    ll N,A,B,K;
    cin >> N >> A >> B >> K;
    ModCombination<MOD> C(N);
    ll ans = 0;
    repeat(a, N+1){
        ll bb = K - A*a;
        if(bb<0) break;
        if(bb%B != 0) continue;
        ll b = bb/B;
        if(b > N) continue;
        ll x = C.Comb(N, a)*C.Comb(N, b)%MOD;
        ans = (ans + x)%MOD;
        
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	long long int a, b, c, d;
	cin >> a >> b >> c >> d;

	long long int ans = a * c;
	if(ans < a * d) ans = a * d;
	if(ans < b * c) ans = b * c;
	if(ans < b * d) ans = b * d;

	cout << ans;

	return 0;
}

Measured memory_bytes: 3640
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
s = rs()
n = len(s)
ans = 0
for bit in range(1 << n - 1):
    tmp = 0
    for i in range(n - 1):
        if bit & (1 << i):
            ans += int(s[tmp:i+1])
            tmp = i + 1
    ans += int(s[tmp:n])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
const int MAXN = 200001;
string S[MAXN];

int main(){
    int N;cin >> N;
    rep(i,N)cin >> S[i];
    map<string,int> ma;
    ll ans = 0;
    rep(i,N){
        if(ma[S[i]]>0){
            ma[S[i]]++;
        }
        else {
            ma[S[i]] = 1;
            ans ++;
        }
    }

    cout <<ans << endl;
    



    return 0;
}

Measured memory_bytes: 25436
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u8> = vec![];
    let mut swap_count: u16 = 0;

    for _ in 0..n {
        let number: u8 = read();
        a.push(number);
    }

    for index in 0..n {
        let mut min_j = index;
        for j in index..n {
            if a[j] < a[min_j] {
                min_j = j
            }
        }
        if index != min_j {
            a.swap(index, min_j);
            swap_count += 1;
        }
    }

    for (index, number) in a.iter().enumerate() {
        if index != a.len() - 1 {
            print!("{} ", number);
        } else {
            println!("{}", number);
        }
    }
    println!("{}", swap_count);
}



Measured memory_bytes: 5036
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll N,M,K; cin >> N >> M >> K;
    vector<ll> A(N+1,0),B(M+1,0),a(N),b(M);
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<M;i++) cin >> b[i];
    for(int i=0;i<N;i++) A[i+1] = A[i] + a[i];
    for(int i=0;i<M;i++) B[i+1] = B[i] + b[i];

    ll ans = 0;
    for(ll i=0;i<=N;i++){
        if(K < A[i]) break;
        ll cnt = upper_bound(B.begin(), B.end(), K - A[i]) - B.begin();
        if(A[i] + B[cnt-1] <= K){
            ans = (ll)(max(ans, i+cnt-1));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9520
/*
本宝的程序外人别想看！！

name: [夏宝宝]
run time：[] ms
compilation time: [] ms
output memory: [] MiB
where: []
state: []
*/
#include<bits/stdc++.h>
using namespace std;

inline int read()
{
	int s=0, w=1;

	char ch=getchar();

	while(ch<'0' || ch>'9')
	{
		if(ch='-')
		{
			w=-w;
		}

		ch=getchar();
	}

	while(ch>='0' && ch<='9')
	{
		s=(((s*10ll))+(ch-'0'));

		ch=getchar();
	}

	return s;
}

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	
	cout.sync_with_stdio(false);
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	long long int s;
	
	s=read();
	
	int sum=0;
	
	sum+=(s/500)*1000;
	s%=500;
	sum+=(s/5)*5;
	
	cout<<sum<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/

int main(){FAST;

string s;cin>>s;
ll x = 0;
for(ll i=0;i<s.length();++i){
  x+=s[i]-'0';
  x%=9LL;
}
if(x)cout<<"No";
else cout<<"Yes";
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 3772
/**

       Author : sea_26

    **/


    #pragma GCC optimize("03")
    #include <bits/stdc++.h>

    using namespace std;

    const int M = 1000000007;
    const double PI = acos(-1.0);

    // const double pi = atan2(0, -1);
    // const double PI = 4 * atan(1);
    // const double pi = 2*cos(0.0);

    typedef long long ll;
    typedef long double ld;

    const int iinf = 0x3f3f3f3f;
    const ll linf = 0x3f3f3f3f3f3f3f3f;

    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define ln(x) (int)x.size()

    #define bp(n)  __builtin_popcount(n)
    #define bclz(n) __builtin_clzll(n)
    #define bctz(n) __builtin_ctzll(n)
    #define bip(n) __builtin_parity(n)

    #define vsort(v) sort(v.begin(),v.end())
    #define rvsort(v) sort(v.begin(),v.end(),greater<int>())

    #define rep(n) for(int i=0; i<n; i++)
    #define rrep(n) for(int i=n-1; i>=0; i--)
    #define lrep(p,q) for(int i=p; i<=q; i++)
    #define prep(n) for(int i=1; i*i<=n; i++)
    #define it(a, x)  for(auto &a : x)
    #define yes cout << "YES" << endl
    #define no cout << "NO" << endl

    priority_queue<int> pq;

    #define fs   ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

    template< typename T> inline T lcm(T a, T b){ return (a / gcd(a,b)) * b; }
    template< typename T> inline T MAX(T a, T b){ return a ^ ((a ^ b) & -(a < b)); }
    template< typename T> inline T MIN(T a, T b){ return b ^ ((a ^ b) & -(a < b)); }
    template< typename T> void tpns(T n){ rrep(30){ if(n & (1 << i)) pq.push(1 << i); } }
    template< typename T> void SWAP(T &a, T &b){ a = ((a) ^= (b)),  b = ((b) ^= (a)),  a = ((a) ^= (b)); }
    template< typename T> inline T ABS(T a){ int x = a >> sizeof(int) * CHAR_BIT - 1; return (a + x) ^ x; }
    template< typename T> inline T mod(T a, T b){ return a >= b ? a % b : a; }
    template< typename T> inline T gcd(T a, T b){ while (b) b ^= a ^= b ^= a %= b; return a; }

    ll gcdextd(ll a, ll b, ll& x, ll& y) {
        if (!a) { x = 0; y = 1; return b; }
        ll y1,d;
        d = gcdextd(b % a, a, y, y1);
        x = y1 - (b / a) * y;
        return d;
    }



    double WT() {
    	return double(clock()) / CLOCKS_PER_SEC;
    }

    void ReT(){

    	cout << "\nTime = " << fixed << setprecision(3) << WT()  << " Sec"<< endl;

    exit(0);
    }


    int cnt0,cnt1;
    int main(){

            fs;
            string s;
            cin >> s;
            int ln = s.size();
            rep(ln){
                if(i%2 == s[i] - '0') cnt1++;
                else cnt0++;
            }

        cout <<  min(cnt0, cnt1) << endl;
         //   ReT();

    }


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

int main(){
	char c;
	cin>>c;

	cout<<char(c+1)<<endl;

	return 0;
}


Measured memory_bytes: 764
def judge(t1, t2):
  if t1 < 35.5 and t2 < 71:
    print("AAA")
  elif t1 < 37.5 and t2 < 77:
    print("AA")
  elif t1 < 40 and t2 < 83:
    print("A")
  elif t1 < 43 and t2 < 89:
    print("B")
  elif t1 < 50 and t2 < 105:
    print("C")
  elif t1 < 55 and t2 < 116:
    print("D")
  elif t1 < 70 and t2 < 148:
    print ("E")
  else:
    print("NA")

while True:
  try:
   t1, t2 = map(float, input().split())
   judge(t1, t2)
  except EOFError:
    break


Measured memory_bytes: 5584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		int output = 0;
		for(int i = 0 ; i < 4 ; i++) {
			output += (input.charAt(i) == '+')? 1:-1;
		}
		System.out.println(output);
	}

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N;
    cin >> N;
    vector<int> t(N), x(N), y(N);
    REP(i, N) cin >> t[i] >> x[i] >> y[i];

    auto yes = []() {
        print("Yes");
        exit(0);
    };
    auto no = []() {
        print("No");
        exit(0);
    };

    int X = 0, Y = 0, T = 0;
    REP(i, N) {
        int dist = abs(X - x[i]) + abs(Y - y[i]);
        int can  = (t[i] - T) - dist;
        if (can < 0 || can % 2 == 1) {
            no();
        }
        X = x[i];
        Y = y[i];
        T = t[i];
    }
    yes();

    return 0;
}

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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> x(n),y(n),p(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i]>>y[i]>>p[i];
    }
    vector<ll> pow3(n+1,1);
    for (int i = 0; i < n; i++) {
        pow3[i+1] = pow3[i]*3;
    }

    // iだけ利用するときに、jのコストの最小値
    vector<vector<ll>> tate((1<<n),vector<ll>(n));
    vector<vector<ll>> yoko((1<<n),vector<ll>(n));
    // map<pair<ll,ll>,ll> tate,yoko;
    
    for (ll i = 0; i < (1<<n); i++) {
        for (int j = 0; j < n; j++) {
            tate[i][j] = abs(x[j]);
            yoko[i][j] = abs(y[j]);
            for (int k = 0; k < n; k++) {
                if(i&(1<<k)){
                    tate[i][j] = min(tate[i][j],abs(x[j]-x[k]));
                    yoko[i][j] = min(yoko[i][j],abs(y[j]-y[k]));
                }
            }
        }
    }
    
    vector<ll> ans(n+1,1e15);

    for (ll i = 0; i < pow3[n]; i++) {
        ll cnt = n;
        ll tatei = 0;
        ll yokoi = 0;
        ll nowj = i;
        for (int j = 0; j < n; j++) {
            if(nowj%3==0){
                cnt--;
            }else if(nowj%3==1){
                tatei += (1<<j);
            }else{
                yokoi += (1<<j);
            }
            nowj/= 3;
        }
        ll tmp = 0;
        for (int j = 0; j < n; j++) {
            tmp += min(tate[tatei][j],yoko[yokoi][j])*p[j];
        }
        ans[cnt] = min(ans[cnt], tmp);
    }
    
    for (int i = 0; i <= n; i++) {
        std::cout << ans[i] << std::endl;
    }
}


Measured memory_bytes: 13000
#include <stdio.h>
int r,c,i,j,p;
int main(){
  int A[100][100];
  int S[100][1];
  int s[1][100];
  scanf("%d %d",&r,&c);
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf(" %d",&A[i][j]);
    }
  }
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      S[i][0]+=A[i][j];
    }
  }
  for(i=0;i<c;i++){
    for(j=0;j<r;j++){
      s[0][i]+=A[j][i];
    }
  }
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      printf("%d ",A[i][j]);
    }
    printf("%d\n",S[i][0]);
  }
  for(j=0;j<c;j++){
    printf("%d ",s[0][j]);
  }
  for(i=0;i<r;i++){
    p+=S[i][0];
    }
  printf("%d\n",p);
  return 0;
}

Measured memory_bytes: 2748
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]

segs = sorted([(p - r, p + r) for p, r in a], key=lambda x: x[1])
dp = [1] + [0] * (n - 1)
for i in range(1, n):
    dp[i] = dp[i - 1]
    left, right = -1, i
    while left + 1 < right:
        mid = (left + right) >> 1
        if segs[mid][1] <= segs[i][0]:
            left = mid
        else:
            right = mid
    if left != -1:
        dp[i] = max(dp[i], 1 + dp[left])
print(dp[n - 1])

Measured memory_bytes: 34396
n = int(raw_input())
d = sorted(map(int,raw_input().split(" ")))
m = int(raw_input())
t = sorted(map(int,raw_input().split(" ")))

dic = {}
dic2 = {}

for a in t:
  if a not in dic:
    dic[a]=1
  else:
    dic[a] += 1

for a in d:
  if a not in dic2:
    dic2[a]=1
  else:
    dic2[a] += 1

for a in dic:
  if a not in dic2:
    print "NO"
    exit(0)
  if dic[a] > dic2[a]:
    print "NO"
    exit(0)

print "YES"


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

int main()
{
  int n;
  cin >> n;
  valarray<int64_t> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  const int64_t mod = 1000000007;
  int64_t sum = a.sum() % mod;
  int64_t ans = 0;
  for (int i = 0; i < n; i++) {
    sum -= a[i];
    if (sum < 0) sum += mod;
    ans += a[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
}


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

using ll = long long;
#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;cin >> n >> k;
  vector<ll> a(n);
  REP(i,n)cin >> a[i];

  for(int i = k;i < n;i++){
    cout << ((a[i] > a[i - k]) ? "Yes" : "No") << '\n';
  }
}


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

int main(){
    int n;
    cin >> n;
    vector<string> w(n);
    rep(i, n){
        cin >> w.at(i);
    }
    
    string s = "Yes";
    for(int i = 1; i < n; i++){
        if(!(w.at(i-1).at(w.at(i-1).length()-1)==w.at(i).at(0)))
        s = "No";
        for(int j = 0; j < i; j++){
            if(w.at(i) == w.at(j))
            s = "No";
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const ll INF = 21474836470;
const ll MOD = 1000000007;

using namespace std;

ll d1[300][300] = {};
ll d2[300][300] = {};

int main() {
  int n, m;
  ll l;
  cin >> n >> m >> l;
  REP(i, n) {
    REP(j, n) {
      if (i == j) {
        d1[i][i] = 0;
      } else {
        d1[i][j] = INF;
        d2[i][j] = INF;
      }
    }
  }

  REP(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    d1[a][b] = c;
    d1[b][a] = c;
  }

  REP(k, n) {
    REP(i, n) {
      REP(j, n) { d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]); }
    }
  }

  REP(i, n) {
    REP(j, n) {
      if (i == j) {
        d2[i][j] = 0LL;
      } else if (d1[i][j] <= l) {
        d2[i][j] = 1LL;
      }
    }
  }

  REP(k, n) {
    REP(i, n) {
      REP(j, n) { d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]); }
    }
  }

  // REP(i, n) {
  //   REP(j, n) { cout << d2[i][j] << endl; }
  // }

  int q;
  cin >> q;
  REP(i, q) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    if (d2[s][t] == INF) {
      cout << -1 << endl;
    } else {
      cout << d2[s][t] - 1 << endl;
    }
  }
}


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> a(n), s,t;
    for(int i = 0; i < n; i++) {
        cin >> a.at(i);
        if(a.at(i) < 0) t.push_back(a.at(i));
        else s.push_back(a.at(i));
    }
    
    int S = s.size();
    int T = t.size();
    bool ok = false;
    if(S > 0) {
        if(n == k) ok = (T%2 == 0);
        else ok = true;
    }else {
        ok = (k%2 == 0);
    }
    
    mint ans = 1;
    if(!ok) {
        sort(a.begin(), a.end(), [](int x, int y) {
            return abs(x) < abs(y);
        });
        for(int i = 0; i < k; i++) ans *= a.at(i);
    } else {
        sort(s.begin(),s.end());
        sort(t.rbegin(),t.rend());
        if (k%2 == 1) {
            ans *= s.back();
            s.pop_back();
        }
        vector<ll> p;
        while(s.size() >= 2) {
            ll x = s.back(); s.pop_back();
            x *= s.back(); s.pop_back();
            p.push_back(x);
        }
        while(t.size() >= 2) {
            ll x = t.back(); t.pop_back();
            x *= t.back(); t.pop_back();
            p.push_back(x);
        }
        sort(p.rbegin(), p.rend());
        for(int i = 0; i < k/2; i++) ans *= p.at(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6332
n = int(input())
lim = 10 ** 18
ans = 1
a = input().split(' ')
for i in range(0, n) :
	if int(a[i]) == 0 :
		ans = 0
for i in range(0, n) :
	if int (a[i]) * ans > lim :
		ans = -1
		break
	else :
		ans *= int(a[i])
print(ans)

Measured memory_bytes: 19372
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int f(int n) {
  if(n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}

int main() {
  int s;
  cin >> s;
  vector<int> as;
  as.push_back(s);
  map<int, int> exists;
  exists[s]++;
  while(true) {
    auto na = f(as.back());
    as.push_back(na);
    if(exists[na] != 0) {
      cout << as.size() << endl;
      return 0;
    }
    exists[na]++;
  }
  return 0;
}


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

struct Node {
  int k;
  struct Node *r,*l,*p;
};
typedef struct Node* node;
node root;
node NIL;

void insert(int);
void inorder(node);
void preorder(node);
node find(node,int);

int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n);
  root = NIL;
  
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    if(com[0]=='f'){
      scanf("%d",&x);
      node t=find(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}
void insert(int k){
  node y=NIL;//xの親
  node x=root;
  node z;
  
  z=(node)malloc(sizeof(struct Node));

  z->k = k;
  z->l = NIL;
  z->r = NIL;
 
  while(x != NIL){
    y=x;//親を設定
    if( z->k < x->k )
      x = x->l;//左の子へ
    else x = x->r;//右の子へ
  }
  z->p = y;
  
  if(y==NIL)
    root = z;
  else {
    if( z->k < y->k ){
      y->l = z;
    }
    else
      y->r = z;
  }
}
void inorder(node u){
  if(u==NIL)return;
  inorder(u->l);
  printf(" %d",u->k);
  inorder(u->r);
}
void preorder(node u){
  if(u==NIL)return;
  printf(" %d",u->k);
  preorder(u->l);
  preorder(u->r);
}
node find(node u,int k){
  while(u!=NIL && k!=u->k){
    if( k < u->k ) u=u->l;
    else u=u->r;
  }
  return u;
}



Measured memory_bytes: 20524
<?php
list($o) = strs();
list($e) = strs();
$ans = '';
for ($i = 0; $i < strlen($o); ++$i) {
    $ans .= $o[$i];
    if ($i < strlen($e)) $ans .= $e[$i];
}
echo $ans;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

signed main(){
  lint ans = 0;
  lint N; cin >> N;
  for(lint i = 1; i <= N; i++){
    if(i % 3 != 0 && i % 5 != 0) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
int mx=3234566667;
vi lun;

int dfs(int n){
  if(n>mx) return 0;
  lun.pb(n);
  int p=n%10;
  int i=p+1,j=p-1;
  if(i<10) dfs(n*10+i);
  if(j>=0) dfs(n*10+j);
  dfs(n*10+p);
  return 0;
}

signed main(){
  int k;
  cin>>k;
  FOR(i,1,9){
    dfs(i);
  }
  sort(all(lun));
  // rep(i,20)cout<<lun[i]<<endl;
  cout<<lun[k-1]<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int H,W,A,B;
	cin>>H>>W>>A>>B;

	rep(i,H){
		string s="";
		rep(j,W){
			if(i<B){
				if(j<A) s+='0';
				else s+='1';
			}
			else{
				if(j<A) s+='1';
				else s+='0';
			}
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1280
#include<iostream>
#include<queue>
using namespace std;
int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      queue<int> user;
      for(int i=1;i<=n;i++)
	user.push(i);
      for(;user.size()>1;)
	{
	  for(int i=1;i<m;i++)
	    {
	      user.push(user.front());
	      user.pop();
	    }
	  //      cout<<user.front()<<endl;
	  user.pop();
	}
      cout<<user.front()<<endl;
    }
}

Measured memory_bytes: 1224
import sys
input = sys.stdin.readline


# 処理内容
def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()

    ans = 0
    for i in range(K):
        ans += P[i]
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 62448
X,N = map(int, input().split())
P = list(map(int, input().split()))
sortP = sorted(P)
if N==0:
    print(X)
elif sortP[0]>X:
    print(X)
elif sortP[N-1]<X:
    print(X)
else:
    for n in range(sortP[0]-2,sortP[N-1]+2):
        if n in sortP:
            continue
        if n ==X:
            print(X)
            break
        elif n>X:
            if X-a<=n-X:
                print(a)
                break
            else:
                print(n)
                break
        a = n

Measured memory_bytes: 9212
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define hoise cerr<<"hoise - "<<__LINE__<<"\n";
#define tham getchar();
#define FASTIO ios::sync_with_stdio(false);cin.tie(nullptr);

using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
using vl = vector <ll>;

const int MXN = (int)2e5+6;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int INF = 1e9;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }


template <typename T> using orderedSet = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using orderedSet1 = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*--------------------------------------------------------------------------------------------------------------------------*/




int main(){
	FASTIO
	ll a, b, n;
	cin >> a >> b >> n;
	
	ll x = min (b - 1, n);
	cout << (a * x) / b - a * (x / b) << endl;
	
    return 0;
}

/*

*/


Measured memory_bytes: 3604
#include<stdio.h>
int main(){
int n,i,j,k,l;
int count=0,even=0,odd=0;
int arr[100000];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
if(arr[i]%2==0){
even++;
}
else if(arr[i]%2!=0){
odd++;
}
}
if(odd%2!=0 && n==3){
printf("YES");
}
else if(odd%2!=0 && n!=3){
printf("NO");
}
else if(odd%2==0){
printf("YES");
}

}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int main()
{
	LL n,m;
	while(~scanf("%lld %lld",&n,&m))
	{
		LL ans = min(n/1, m/2);

		n -= ans*1;
		m -= ans*2;
		ans += m/4;
		printf("%lld\n", ans);
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;

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

	char A[50][50], B[50][50];

	for (int y = 0; y < n; y++) {
		for (int x = 0; x < n; x++) {
			cin >> A[y][x];
		}
	}
	for (int y = 0; y < m; y++) {
		for (int x = 0; x < m; x++) {
			cin >> B[y][x];
		}
	}

	bool exists = false;
	for (int ay = 0; ay < n - m + 1; ay++) {
		for (int ax = 0; ax < n - m + 1; ax++) {
			
			bool judge = true;
			for (int by = 0; by < m; by++) {
				for (int bx = 0; bx < m; bx++) {
					if (A[ay + by][ax + bx] != B[by][bx]) judge = false;
				}
			}

			if (judge) exists = true;
		}
	}

	if (exists) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC124B
int main(void) {
  int n, k, i, cou=0, tmp, max=0;
  scanf("%d", &n);
  //int h[n];
  for(i=0; i<n; i++){
    scanf("%d", &tmp);
    if(max<=tmp) cou++, max=tmp;
  }
  printf("%d", cou);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll T[55], P[55];

ll sum(int n,ll x)
{
	if (x == 0)
	{
		return 0;
	}
	if (n == 0)
	{
		return 1;
	}

	ll s = 0;
	x--;
	if (x <= T[n - 1])
	{
		return sum(n - 1, x);
	}
	x -= T[n - 1]+1;
	s += P[n - 1]+1;
	if (x <= T[n - 1])
	{
		return s + sum(n - 1, x);
	}
	return s + P[n - 1];
}

int main()
{
	int N;
	ll X;
	cin >> N >> X;
	
	T[0] = P[0] = 1;
	FOR(i, N + 1, 1)
	{
		T[i] = 2 * T[i - 1] + 3;
		P[i] = 2 * P[i - 1] + 1;
	}

	cout << sum(N, X) << endl;
	return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288

int main(){
    string  s;
    cin>>s;
    bool ok=true;
    rep(i,3){
        if(s[i]==s[i+1]){
            ok=false;
        }
    }
    if(ok)cout<<"Good"<<endl;
    else cout<<"Bad"<<endl;
        
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sz(a) (int)((a).size())
#define fuck() cout<<"--------"<<endl
#define see(x) cout<<#x<<" = "<<x<<endl
#define see2(x,y) cout<<#x<<" = "<<x<<"::"<<#y<<" = "<<y<<endl 
const int mod=1000000007;
typedef pair<int,int> pii;
const int N=1e5+5;
int f(int x){
    return x*(x-1)/2;
}
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    int e,o;
    cin>>e>>o;
    cout<<f(e)+f(o);
}

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

long long N, K;
long long dp[59][59][2509], mod = 1000000007;

int main() {
	cin >> N >> K;
	if (K % 2 == 1) {
		cout << "0" << endl;
		return 0;
	}
	dp[0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k <= N * N; k++) {
				if (dp[i][j][k] == 0) continue;

				long long v0 = j * j, v1 = 2 * j + 1, v2 = 1;
				dp[i + 1][j - 1][k + i * 2] += dp[i][j][k] * v0; dp[i + 1][j - 1][k + i * 2] %= mod;
				dp[i + 1][j + 0][k + i * 1] += dp[i][j][k] * v1; dp[i + 1][j + 0][k + i * 1] %= mod;
				dp[i + 1][j + 1][k + i * 0] += dp[i][j][k] * v2; dp[i + 1][j + 1][k + i * 0] %= mod;
			}
		}
	}
	long long E = N * (N - 1) / 2; E += (K / 2);
	cout << dp[N][0][E] << endl;
	return 0;
}

Measured memory_bytes: 57600
/**********************************************************************
   File abc167_acpp
   Author  harunaya
   Date   2020-05-10(Sun)
   note   
**********************************************************************/

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s, t;
  cin >> s >> t;
  int count = 0;
  for(int i = 0; i < s.size(); ++i) {
    if(s.at(i) == t.at(i)){
      count++;
    }
  }
  //cout << count << endl;
  if(count == s.size()) {
    if (s.size() == t.size() - 1) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
  return 0; 
}

Measured memory_bytes: 3628
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int a, b, c;
  readf (" %d %d %d", &a, &b, &c);
  writeln (a + b >= c ? "Yes" : "No");
}


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

int main(){
  int a[26]={},n,flag=1;
  char s[30];
  scanf("%s",s);
  n=strlen(s);
  for(int i=0;i<n;i++)
    a[s[i]-'a']++;
  for(int i=0;i<26;i++)
    if(a[i]>1)
      flag=0;
  if(flag)
    printf("yes\n");
  else
    printf("no\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, L;
  cin >> N;
  M =0;
for(int i=0;i<8;i++){
  L = N/ std::pow(10,i+1);
  L %= 10;
  M += L;
}
    M += N % 10;
    if(N%M ==0){
      cout << "Yes" << endl;
    }
    else if ( N%M !=0){
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() 
{
	int i, j, H, W;
	while (1) {
    		cin >> H >> W;
		if(H == 0 && W == 0) {
        			break;
		}	
		for (i = 1; i <= H; i++) {
			for (j = 1; j <= W; j++) {
				if(i > 1 && i < H && j < W && j > 1)
                        			cout << ".";
            			else
                     				cout << "#";
            		}
		 	cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
  string S_, T;
  cin >> S_ >> T;
  int ls = S_.length();
  int lt = T.length();
  string S = S_;

  bool found = false;
  for(int i=ls-lt; i>=0; i--){
    bool possible = true;
    for(int j=0; j<lt; j++){
      if(S_[i+j] != '?' && T[j] != S_[i+j]){
        possible = false;
        break;
      }
    }
    if(possible){
      for(int j=0; j<ls; j++){
        if(S[j] == '?'){
          S[j] = 'a';
        }
      }
      for(int j=0; j<lt; j++){
        S[i+j] = T[j];
      }
      found = true;
      break;
    }
  }

  if(found){
    cout << S << endl;
  } else {
    cout << "UNRESTORABLE"<< endl;
  }

  return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> vec(n);
  int cnt1 = 0;
  int cnt2 = 0;
  int cnt3 = 0;
  int cnt4 = 0;
  for (auto &v : vec) {
    cin >> v;
    int tmp = static_cast<int>(v.size());
    for (int i = 0; i < tmp - 1; ++i)
      cnt1 += v.substr(i, 2) == "AB";
    cnt2 += v[0] == 'B';
    cnt3 += v[tmp-1] == 'A';
    cnt4 += v[0] == 'B' && v[tmp-1] == 'A';
  }

  if (cnt2 == cnt4 && cnt3 == cnt4)
    cout << max(cnt4 - 1, 0) + cnt1 << endl;
  else
    cout << min(cnt2, cnt3) + cnt1 << endl;
}




Measured memory_bytes: 3680
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back  
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll    

const int MOD = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) {
    a += MOD;
  }
}

inline int mult(int a, int b) {
  return (a * 1ll * b) % MOD;
}

int b_pow(int a, int b) {
  if (!b) {
    return 1;
  }
  if (b & 1) {
    return mult(a, b_pow(a, b - 1));
  }
  return b_pow(mult(a, a), b >> 1);
}

const int N = (1 << 18);
int prod[N], inv_prod[N], mn[N], mx[N], to[N], sum[N];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
  int h;
  cin >> h;
  prod[0] = inv_prod[0] = 1;
  for (int i = 1; i < (1 << h); i++) {
    prod[i] = mult(prod[i / 2], i);
    inv_prod[i] = mult(inv_prod[i / 2], b_pow(i, MOD - 2));
    //cout << prod[i] << ' ' << inv_prod[i] 
  }
  for (int i = (1 << (h - 1)); i < (1 << h); i++) {
    cin >> to[i];
    //cout << i << ' ' << to[i] << endl;
    to[i] += (1 << (h - 1)) - 1;
    mn[i] = mx[i] = i;
  }
  for (int i = (1 << (h - 1)) - 1; i >= 1; i--) {
    mn[i] = mn[2 * i];
    mx[i] = mx[2 * i + 1];
  }
  int ans = 0;
  for (int lca = 1; lca < (1 << (h - 1)); lca++) {
    for (int i = mn[2 * lca]; i <= mx[2 * lca]; i++) {
      int vl = mult(prod[i], inv_prod[lca]), 
      cur = to[i];
      //cout << vl << '\n';
      while (cur) {
        vl = mult(vl, cur);
        add(sum[cur], vl);
        cur /= 2;
      }
    }
    for (int v = mn[2 * lca + 1]; v <= mx[2 * lca + 1]; v++) {
      int u = to[v], cs = 0, vl = mult(u, mult(prod[v], inv_prod[lca / 2]));
      while (u > 1) {
        int lca2 = u / 2, w = (u ^ 1);
        //cout << lca << ' ' << v << ' ' << u << ' ' << lca2 << ' ' << w << ' ' << sum[w] << '\n';
        vl = mult(vl, lca2);
        add(ans, mult(sum[w], vl));
        u /= 2;
      }
    }
    for (int i = mn[2 * lca]; i <= mx[2 * lca]; i++) {
      int vl = mult(prod[i], inv_prod[lca]);
      int cur = to[i];
      while (cur) {
        vl = mult(vl, cur);
        sub(sum[cur], vl);
        cur /= 2;
      }
    }    
  }

  cout << ans << '\n';
} 

Measured memory_bytes: 9260
n=int(input())
x=list(map(int,input().split()))
result=0
if sum(x)%n==0:
  for i in range(n):
    result+=(x[i]-sum(x)//n)**2
elif sum(x)%n<=n/2:
  for i in range(n):
    result+=(x[i]-sum(x)//n)**2
else:
  for i in range(n):
    result+=(x[i]-sum(x)//n-1)**2
  
print(result)


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

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

    string s; cin >> s;
    vb v(26, false); REP(i, (int)s.length()) v[s[i]-'a'] = true;
    REP(i, 26)
    {
        if(v[i] == false)
        {
            cout << char(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define ni(n) scanf("%d", &n)
#define nl(n) scanf("%I64d", &n)
#define nai(a,n) for (int i = 0; i < (n); i++) ni((a)[i])
#define nal(a,n) for (int i = 0; i < (n); i++) nl((a)[i])
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;

int grundy(int n, int k)
{
    while (n % k != 0)
    {
        int a = n / k + 1;
        n -= max(1, (n % k) / a) * a;
    }
    return n / k;
}

int main()
{
    int n;
    ni(n);
    int cur = 0;
    for (int i = 0; i < n; i++)
    {
        int a, k;
        ni(a), ni(k);
        cur ^= grundy(a, k);
    }
    if (cur == 0) printf("Aoki\n");
    else printf("Takahashi\n");
    return 0;
}


Measured memory_bytes: 256