akhauriyash/Code-Regression huggingface dataset:
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(input())
s=input().strip()

memo={}
def getans(a,b,c):
    while a and c and a[0]==c[-1]:
        a=a[1:]
        c=c[:-1]
    if a and c: return 0
    if b=="":
        if a=="" and c=="": return 1
        else: return 0
    key=a+"/"+b+"/"+c
    if key in memo: return memo[key]
    # select first letter
    ans=0
    for i in range(1,len(b)):
        if b[0]==b[i]:
            ans+=getans(a,b[1:i],b[i+1:]+c)
    # don't select first letter
    ans+=getans(a+b[0],b[1:],c)
    memo[key]=ans
    #print(key,ans)
    return ans

print(getans("",s,"")*2)

#print(len(memo))


Measured memory_bytes: 62684
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a[3][3];
  for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>a[i][j];
  int n;cin>>n;
  int b[n];for(int i=0;i<n;i++)cin>>b[i];
  int ans[3][3]={};
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(b[i]==a[j][k])a[j][k]=1;
      }
    }
  }
 /* for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }*/
  for(int i=0;i<3;i++){
    int ans=0;
    for(int j=0;j<3;j++){
      ans+=a[i][j];
    }
    if(ans==3){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  for(int i=0;i<3;i++){
    int ans=0;
    for(int j=0;j<3;j++){
      ans+=a[j][i];
    }
    if(ans==3){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  if(a[0][0]==1&a[1][1]==1&a[2][2]==1){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(a[0][2]==1&a[1][1]==1&a[2][0]==1){
    cout<<"Yes"<<endl;
    return 0;
  }  
  cout<<"No"<<endl;
}

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

int main(void) {
    int a, b;
    cin >> a >> b;
    if (a > 0) cout << "Positive" << endl;
    else if (b < 0) cout << ((b - a) % 2 ? "Positive" : "Negative") << endl; 
    else if (a <= 0 && 0 <= b) cout << "Zero" << endl;
}


Measured memory_bytes: 256
#python3
import numpy as np
n,d=map(int, input().split())
pos=[[int(i) for i in input().split()] for _ in range(n)]

def dist(a, b):
  sum=0;
  for i in range(d):
    sum+=(a[i]-b[i])**2
  return np.sqrt(sum) 

def isInt(d):
  if d-np.floor(d) == 0:
    return True
  else:
    return False

cnt=0
for i in range(n):
  for j in range(i+1, n):
    distance = dist(pos[i], pos[j])
    if isInt(distance):
      cnt+=1

print(cnt)

    

Measured memory_bytes: 12444
h, w = map(int, input().split())
graph = []
for i in range(h):
    row = []
    for j in input():
        row.append(j)
    graph.append(row)

dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1,  1, -1, 0, 1]

for row in range(h):
    for col in range(w):
        if graph[row][col] == '#':
            print("#", end='')
            continue

        # 爆弾カウント
        bomb = 0
        for i in range(8):
            row_sur = row + dx[i]
            col_sur = col + dy[i]
            if row_sur < 0 or h <= row_sur or col_sur < 0 or w <= col_sur:
                continue
            if graph[row_sur][col_sur] == "#":
                bomb += 1
        print(bomb, end='')
    print()


Measured memory_bytes: 3444
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    vector<pair<int, int> > p;
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        p.pb(mp(y, x));
    }
    sort(all(p));
    ll ans = 0;
    for(int i = 0; i < p.size(); i++){
        ans+=p[i].second;
        if(ans <= p[i].first){
            continue;
        }
        else{
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 2548
#include<stdio.h>
int main(){
    
    int a,b;
    scanf("%d %d", &a , &b);
    if(a < b) printf("a < b\n" );
    else if(a > b) printf("a > b\n");
    else if(a == b) printf("a == b\n" );
    
    return 0;
}


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

int main() {
  int a,b,c,d,e,f,g,h,i,j=0;
  cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
  if(a-d==b-e&&b-e==c-f) {
    if(d-g==e-h&&e-h==f-i) {
      cout << "Yes" << endl;
      j++;
    }
  }
  if(j==0) {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2E5+2;

struct FenwickTree{
    vector<int> F;
    void init(int n){
      F.assign(n+1, 0);
        
    }
    void update(int p, int val){
        for(int i=p; i< F.size(); i+= i&(-i)) F[i]+= val;
    }
    int get(int p){
        if(p==0) return 0;
        return F[p]+ get(p-(p&(-p)));
    }
};


int n;
string S;
vector<int> pos[26];
vector<int> id(MAXN, 0);
FenwickTree fen;
long long ret = 0;

bool check(){
    int cnt = 0;
    for(int i=0; i< 26; ++i) cnt+= (int)(pos[i].size()%2);
    return (cnt <= 1);
}

void pairing(){
		vector<pair<int,int> >P;
    for(int i=0; i< 26; ++i){
        int half = (int)(pos[i].size()+1)/2;
        for(int j=0; j< half; ++j){
					int o =(int)pos[i].size()-j-1;
					if(o==j) id[(n+1)/2] = pos[i][j];
        	else P.push_back({pos[i][j], pos[i][o]});
				}
            
    }
    sort(P.begin(), P.end());
    int cur = 1;
    for(int i=0; i< P.size(); ++i){
			id[cur] = P[i].first;
			id[n+1-cur] = P[i].second;
			++cur;
		}
}

signed main()
{
    cin >>  S;
    n = S.length();
    for(int i=0; i< n; ++i){
        pos[S[i]-'a'].push_back(i+1);
    }
    if(!check()){
        cout << -1;
        return 0;
    }
    pairing();
    //according to the first element
    fen.init(n);
    for(int i=n; i>= 1; --i){
			ret += 1LL*fen.get(id[i]);
			fen.update(id[i], 1);
		}
		cout << ret;
}

Measured memory_bytes: 3832
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  
  color[u] = GRAY;
  d[u] = ++tt;
  
  for(v = 0; v < n; v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;

  for(u = 0; u < n; u++) color[u] = WHITE;
  tt = 0;

  for(u = 0; u < n; u++){
    if(color[u] == WHITE) dfs_visit(u);
  }

  for(u = 0; u < n; u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u, v, k, i, j;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++) M[i][j] = 0;
  }
  
  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <set>
using ll = long long;
using namespace std;

int main()
{
    int d;
    cin >> d;
    if (d == 25)
        cout << "Christmas" << endl;
    if (d == 24)
        cout << "Christmas Eve" << endl;
    if (d == 23)
        cout << "Christmas Eve Eve" << endl;
    if (d == 22)
        cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 256
// D - Xor Sum 4
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,e) for(ll i=0;i<(e);++i)
#define MOD 1000000007
ll in(){ll x;scanf("%lld",&x);return x;}

ll O[60];

int main(){
	ll j, a, ans=0, N; cin>>N;
	rp(i,N){ for(j=0,a=in(); a; a>>=1) O[j++]+=a&1; }
	rp(i,60) ans = (ans + (O[i]*(N-O[i]) % MOD) * ((1LL<<i) % MOD)) % MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def get_primes(n):
  lst = []
  for x in xrange(2, n+1):
    is_prime = True
    for i in xrange(len(lst)):
      if x % lst[i] == 0:
        is_prime = False
        break
    if is_prime:
      lst.append(x)
  return lst

primes = get_primes(1000)
n = int(raw_input())
a = map(int, raw_input().split())
mul_list = {}
for i in xrange(n):
  ai = a[i]
  for j in xrange(len(primes)):
    counter = 0
    while True:
      if ai % primes[j] == 0:
        ai = ai / primes[j]
        counter += 1
      else:
        break
    if counter > 0:
      if primes[j] in mul_list:
        mul_list[primes[j]] = max(mul_list[primes[j]], counter)
      else:
        mul_list[primes[j]] = counter

ans = 1
for k,v in mul_list.items():
  ans *= k ** v
print ans

Measured memory_bytes: 6504
h,w=map(int,input().split())
list=[]
for i in range(h):
    a=input()
    if "#" in a:
        list.append(a)
h=len(list)
d=[0]*w
for i in range(h):
    for j in range(w):
        if list[i][j]=="#":
            d[j]=1
for i in range(h):
    ans=""
    for j in range(w):
        ans+=list[i][j]*d[j]
    print(ans)

Measured memory_bytes: 9176
use proconio::input;
use proconio::marker::Usize1;
use std::cmp;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        c: usize,
        costs: [[usize; c]; c],
        grid: [[Usize1; n]; n],
    }

    // group iには何色が何個あるか
    let mut data = vec![HashMap::new(); 3];
    for i in 0..n {
        for j in 0..n {
            let index = ((i + 1) + (j + 1)) % 3;
            let entry = data[index].entry(grid[i][j]).or_insert(0);
            *entry += 1;
        }
    }

    let mut min = std::usize::MAX;
    // group 1 -> color i
    // group 2 -> color j
    // group 3 -> color k
    for i in 0..c {
        for j in 0..c {
            for k in 0..c {
                if i == j || j == k || k == i {
                    continue;
                }
                let mut tmp = 0;
                for (key, value) in &data[0] {
                    tmp += costs[*key][i] * value;
                }
                for (key, value) in &data[1] {
                    tmp += costs[*key][j] * value;
                }
                for (key, value) in &data[2] {
                    tmp += costs[*key][k] * value;
                }
                min = cmp::min(min, tmp);
            }
        }
    }
    println!("{}", min);
}


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

#define MAX_N 100

const int inf = 1<<25;

int n;
int A[MAX_N][MAX_N];
int used[MAX_N];
int mincost[MAX_N];

int main() {
  int i, j;
  scanf("%d", &n);
  memset(A, -1, sizeof(A));
  for(i = 0; i < n; i++) {
    int u, k;
    scanf("%d %d", &u, &k);
    for(j = 0; j < k; j++) {
      int v, c;
      scanf("%d %d", &v, &c);
      A[u][v] = c;
    }
  }

  for(i = 0; i < n; i++) {
    used[i] = 0;
    mincost[i] = inf;
  }
  mincost[0] = 0;
  while(1) {
    int v, u = -1;
    for(v = 0; v < n; v++) {
      if(used[v]) continue;
      if(u == -1 || mincost[v] < mincost[u]) u = v;
    }
    if(u == -1) break;
    used[u] = 1;
    for(v = 0; v < n; v++) {
      if(used[v]) continue;
      if(~A[u][v] && mincost[u]+A[u][v] < mincost[v]) {
	mincost[v] = mincost[u]+A[u][v];
      }
    }
  }
  for(i = 0; i < n; i++) {
    printf("%d %d\n", i, mincost[i]);
  }
  return 0;
}

Measured memory_bytes: 648
#include <stdio.h>
int linearsearch(int*,int,int);
#define N 10000

int main()
{
  int i,s,array[N],t,m,sum=0;

  scanf("%d",&s);
  for(i=0;i<s;i++)
    {
      scanf("%d",&array[i]);
    }
  scanf("%d",&t);
  for(i=0;i<t;i++)
    {
      scanf("%d",&m);
      if(linearsearch(array,s,m)) sum++;
    }
  printf("%d\n",sum);
  return 0;
}

int linearsearch(int A[],int x, int key)
{
  int i;
  i=0;
  A[x]=key;
  while(A[i]!=key)
    {
      i++;
      if(i==x) return 0;
    }
  return 1;
}

Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
signed main(){
	int n,a=0,b;
  cin>>n;
  b = n;
  while(n>0){
    a += n % 10;
    n = n / 10;
  }
  if(b%a==0){
    cout<<"Yes\n";
  }else{
    cout<<"No\n";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> A(N, vector<ll>(M));
    rep(i,N){
        rep(j,M){
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    ll ans = N;
    vector<ll> memo(M,1);
    rep(j,M){
        //cout << "Memo ";
        //PR(memo,M);
        vector<ll> note(M,0);
        rep(i,N){
            rep(k,M){
                if(memo[A[i][k]] == 0) continue;
                note[A[i][k]]++;
                break;
            }
        }
        //PR(note,M);
        ll Mat = 0;
        ll id = -1;
        rep(i,M){
            if(memo[i] == 0) continue;
            if(Mat < note[i]){
                Mat = note[i];
                id = i;
            }
        }
        //cout << "Mat:" << Mat << endl;
        if(id != -1){
            cmin(ans, Mat);
            memo[id] = 0;
        }
    }
    cout << ans << endl;
}

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

int N;
int C[500];
int S[500];
int F[500];

void solve() {
  for (int i = 0; i < N - 1; i++) {
    int time = 0;
    for (int j = i; j < N - 1; j++) {
      if (time < S[j]) {
        time = S[j] + C[j];
      } else {
        if (time % F[j]) {
          time = (time / F[j] + 1) * F[j];
        }
        time += C[j];
      }
    }
    cout << time << endl;
  }
  cout << 0 << endl;
}

int main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }

  solve();
  return 0;
}


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

int main(int argc, char *argv[])
{
  int n, one, ten, hand, thou;
  cin >> n;
  one = n%10;
  n/=10;
  ten = n%10;
  n/=10;
  hand = n%10;
  n/=10;
  thou = n%10;
  if((one == ten && ten == hand)||(ten == hand && hand == thou)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int n;
            while((n = scn.nextInt()) > 0) {
                ArrayList<Island> islands = new ArrayList<>();
                while(n-- > 0) {
                    islands.add(new Island(scn.nextInt(), scn.nextInt()));
                }
                Collections.sort(islands);
 
                boolean fail = false;
                int weight = 0;
                for(Island island : islands) {
                    weight += island.getTreasure();
                    if(weight > island.getDurability()) {
                        fail = true;
                        break;
                    }
                }
 
                System.out.println(fail ? "No" : "Yes");
            }
        }
    }
}
 
class Island implements Comparable<Island> {
    private int treasure;
    private int durability;
 
    public Island(int treasure, int durability) {
        this.treasure   = treasure;
        this.durability = durability;
    }
 
    public int getTreasure() {
        return treasure;
    }
 
    public int getDurability() {
        return durability;
    }
 
    public int compareTo(Island another) {
        return this.durability > another.durability ? 1 : -1;
    }
}

Measured memory_bytes: 31840
#include<bits/stdc++.h>
using namespace std;
const int N(111111);
int modulo(1e9 + 7);
int a[N], stmp[N], zc[N], cnt[N], deg[N], rela[N], f[N];
bool vst[N], incyc[N];
int getr(int x) {
	int p(x);
	while(p != rela[p]) 
		p = rela[p];
	int p1(p); p = x;
	while(p != rela[p]) {
		int p2(rela[p]);
		rela[p] = p1;
		p = p2;	
	}
	return p1;
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i(1); i <= n; i++) {
		scanf("%d", &a[i]);
		deg[a[i]]++;
		if(deg[a[i]] >= 3) {
			printf("0\n");
			return 0;
		}
	}
	int t(0);
	vector<vector<int> > cyc;
	fill(vst + 1, vst + 1 + n, false);
	for(int i(1); i <= n; i++) {
		if(!vst[i]) {
			int x(i);
			++t;
			while(!vst[x]) {
				stmp[x] = t;
				vst[x] = true;
				x = a[x];
			}
			if(stmp[x] == t) {
				int y(x);
				vector<int> vec;
				do {
					vec.push_back(y);
					incyc[y] = true;
					y = a[y];
				} while(y != x);
				cyc.push_back(vec);
			}
		}
	}
	for(int i(1); i <= n; i++) 
		if(!incyc[i] && deg[i] >= 2) {
			printf("0\n");
			return 0;
		}
	for(int i(1); i <= n; i++) 
		rela[i] = i;
	for(int i(1); i <= n; i++) {
		if(!incyc[i]) {
			rela[getr(i)] = getr(a[i]);
		}
	}
	for(int i(1); i <= n; i++)
		if(!incyc[i])
			cnt[getr(i)]++;
	int ans(1);
	for(int i(0); i < (int)cyc.size(); i++) {
		int len(cyc[i].size());
		int cz(0);
		for(int j(0); j < len; j++) {
			if(cnt[getr(cyc[i][j])]) {
				int c(0);
				for(int k((j - 1 + len) % len); k != j && cnt[getr(cyc[i][k])] == 0; k = (k - 1 + len) % len) {
					c++;
				}
				if(c + 1 == cnt[getr(cyc[i][j])]) {
				}else if(c + 1 > cnt[getr(cyc[i][j])]) {
					ans = (ans * 2 % modulo);
				}else {
					ans = 0;
				}
			}else {
				cz++;
			}
		}
		if(cz == len) {
			zc[len]++;
		}
	}
	for(int i(1); i <= n; i++) {
		if(zc[i]) {
			//cout << i << '!' << zc[i] << endl;
			f[1] = 1 + (i % 2 == 1 && i > 1);
			f[0] = 1;
			for(int j(2); j <= zc[i]; j++) {
				f[j] = ((1 + (i % 2 == 1 && i > 1)) * f[j - 1] + (j - 1ll) * i * f[j - 2]) % modulo;
			}
			ans = (long long)ans * f[zc[i]] % modulo;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 7856
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] == 0:
  print(0)
  exit()
ans = 1
for i in range(0, N):
  ans *= A[i]
  if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)

Measured memory_bytes: 21704
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        String[] arr = sc.nextLine().split(" ");
        sc.close();

        boolean isOk = true;

        for (int i = 0; i < N; i++) {
            int val = Integer.parseInt(arr[i]);
            if (val % 2 == 0) {
                if (val % 3 == 0 || val % 5 == 0) {
                    continue;
                } else {
                    isOk = false;
                    break;
                }
            } else {
                continue;
            }
        }

        if (isOk) {
            System.out.println("APPROVED");
        } else {
            System.out.println("DENIED");
        }

    }

}


Measured memory_bytes: 23252
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	string S,T;
	cin>>S>>T;
	set<string> tes;
	int sz=S.size();
	int tz=T.size();
	for(int i=0;i<sz;i++){
		string U=S;
		bool flag=0;
		for(int j=0;j<tz;j++){
			if(U[i+j]==T[j] || U[i+j]=='?'){
				U[i+j]=T[j];
			}
			else{
				flag=1;
				break;
			}
		}
		if(!flag){
			for(int i=0;i<sz;i++){
				if(U[i]=='?'){
					U[i]='a';
				}
			}
			tes.insert(U);
		}
	}
	if(tes.size()==0){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	vector<string> v;
	for(string W:tes)
		v.pb(W);
	cout<<v[0]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}

const int N = (int)1e6 + 7;
ll rev[N];
ll a[N];
ll b[N];
int n;
ll ans = 0;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	rev[1] = 1;
	for (ll x = 2; x < N; x++)
		rev[x] = sub(0, mult(rev[MOD % x], MOD / x));

	for (int i = 1; i < N; i++)
		b[i] = rev[i];
	for (int i = 1; i < N; i++)
		for (int j = 2 * i; j < N; j += i)
			b[j] = sub(b[j], b[i]);

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		ll x;
		scanf("%lld", &x);
		ans = sub(ans, x);
		a[x] = add(a[x], x);
	}

	for (int i = 1; i < N; i++)
		for (int j = 2 * i; j < N; j += i)
			a[i] = add(a[i], a[j]);

	for (int i = 1; i < N; i++) {
		ans = add(ans, mult(mult(a[i], a[i]), b[i]));
	}
	if (ans & 1) ans += MOD;
	ans /= 2;
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 23680
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;

	rep(i, 0, 1 << 3)
	{
		string ans;
		ans+= S[0];
		int res = S[0] - '0';
		rep(j, 0, 3)
		{
			if ((i >> j) & 1)
			{
				res += S[j + 1] - '0';
				ans += '+';
				ans += S[j + 1];
			}
			else
			{
				res -= S[j + 1] - '0';
				ans += '-';
				ans += S[j + 1];
			}
		}
		if (res == 7)
		{
			ans += "=7";
			cout << ans << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
function main(input) {
  const inputs =input.split('\n')
  const [N, K] = inputs[0].split(' ').map(Number)

  if (N === 1) {
    console.log(1)
  } else {
    console.log(
      Math.ceil(Math.log(N) / Math.log(K))
    )
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 30556
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)


int main() {
  int a,b;
  cin >> a>>b;
  
  vector<string> p(a);
  rep(i,a) {
  cin >> p[i];
  }
  
  vector<bool> yo(a,false);
  vector<bool> ta(b,false);

  rep(i,a) {
    rep(j,b) {
      if(p[i][j]=='#') {
        yo[i]=true;
        ta[j]=true;
      }
    }
  }
  
  int memo;
  for(int i=b-1; i>=0; i--) {
    if(ta[i]) {
    memo = i;
    break;
    }
  }
  
  rep(i,a) {
    rep(j,b) {
      if(yo[i] && ta[j]) {
      cout << p[i][j];
        if(j==memo) cout<<endl;
      }
    }
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const int N = 1e5 + 5;
const ll mo = 1e10 +7;
const int M = 100+50;
const ll mod = 998244353;
struct node{
	int n;
	int x;
};
bool cmp(node a,node b){
	return a.x<b.x;
}
int main(){
	node p[10];
	for(int i=0;i<5;i++){
		cin>>p[i].n;
		if(p[i].n%10!=0)
			p[i].x=(p[i].n/10)*10+10-p[i].n;
		else
			p[i].x=0;
//		cout<<p[i].x<<endl;
	}
	sort(p,p+5,cmp);
	int ans=0;
	for(int i=0;i<5;i++){
		ans+=p[i].n+p[i].x;
	}
	ans-=p[4].x;
	cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}

void solve(){
	int n;
	cin>>n;
	if(n>=30){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc=1;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	// cin>>tc;
    while(tc--)solve();
}


Measured memory_bytes: 3652
G=60486
M=2**61-1
(N,),A,B=$<.map{|l|l.split.map &:to_i}
C,D=[A,B].map{|z|(z*3).each_cons(2).map{|x,y|x^y}}
e,f=[C,D].map{|z|b=0;z[0,N].map{|x|b=(b*G+x)%M};b}
q=(1-G**N)%M
N.times{|i|
puts "#{i} #{A[i]^B[0]}" if e==f
e=(e*G+C[i]*q)%M
}


Measured memory_bytes: 66052
n=int(input())
a=[int(i) for i in input().split()]
m=max(a)
l=[0]*(m+1)
c=[0]*(m+1)
for i in a:
  l[i]+=1
for i in set(a):
  c[i]=l[i]*(l[i]-1)/2
s=sum(c)
for i in range(n):
  print(int(s-c[a[i]]+(l[a[i]]-1)*(l[a[i]]-2)/2))

Measured memory_bytes: 25768
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t, r;
    cin >> s >> t >> r;
    cout << s[0] << t[0] << r[0] << endl;
    return 0;
}



Measured memory_bytes: 256
a, b = input().split()
a = int(a)
b = int(b)
for i in range(1000):
    if (i * (i + 1) / 2 - a == (i + 2) * (i + 1) / 2 - b):
        print(int(i * (i + 1) / 2 - a))
        exit(0)

Measured memory_bytes: 2940
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

#define DEBUG(x) cerr << #x << ": " << x << endl

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

const llong INF = 1e18 + 123;

int N;
llong K;
vector<llong> A;

bool trace;
llong count(llong p) {
   llong sum = 0;
   vector<llong> neg;
   REP(i, N) {
      int a = A[i];
      int cnt = 0;
      if (a > 0) {
         llong target;
         if (p >= 0)
            target = p/a;
         else
            target = (p-(a-1))/a;
         cnt = upper_bound(A.begin(), A.begin()+i, target) - A.begin();
      }
      else if (a < 0) {
         neg.push_back(-a);
      }
      else {
         if (p >= 0)
            cnt = i;
      }
      if (trace)
         cerr << "i:" << i << "  A[i]:" << a << "  cnt:" << cnt << endl;
      sum += cnt;
   }

   reverse(neg.begin(), neg.end());
   REP(i, SZ(neg)) {
      int a = neg[i];
      int cnt = upper_bound(neg.begin(), neg.begin()+i, p / a) - neg.begin();
      if (trace)
         cerr << "i:" << i << "  NEG[i]:" << -a << "  cnt:" << cnt << endl;
      sum += cnt;
   }

   return sum;
}

llong solve() {
   sort(A.begin(), A.end());

   llong lo = -INF, hi = INF;
   llong res = -INF - 10;
   while (lo <= hi) {
      llong mid = lo + (hi - lo)/2;
      llong sum = count(mid);
   // cerr << "lo:" << lo << "  hi:" << hi << "  mid:" << mid 
   //      << "  sum:" << sum << endl;
      if (sum >= K) {
         res = mid;
         hi = mid-1;
      }
      else {
         lo = mid+1;
      }
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> N >> K;

   cerr << -7/3 << endl;

   A.assign(N, 0);
   REP(i, N)
      cin >> A[i];
/*
   trace = true;
   sort(A.begin(), A.end());
   cerr << count(-7) << endl;
   return 0;
*/

   llong res = solve();
   cout << res << '\n';


   return 0;
}


Measured memory_bytes: 5252
dict = {}
dict['A'] = 'X'
dict['B'] = 'Y'
dict['C'] = 'Z'
dict['D'] = 'A'
dict['E'] = 'B'
dict['F'] = 'C'
dict['G'] = 'D'
dict['H'] = 'E'
dict['I'] = 'F'
dict['J'] = 'G'
dict['K'] = 'H'
dict['L'] = 'I'
dict['M'] = 'J'
dict['N'] = 'K'
dict['O'] = 'L'
dict['P'] = 'M'
dict['Q'] = 'N'
dict['R'] = 'O'
dict['S'] = 'P'
dict['T'] = 'Q'
dict['U'] = 'R'
dict['V'] = 'S'
dict['W'] = 'T'
dict['X'] = 'U'
dict['Y'] = 'V'
dict['Z'] = 'W'

for s in input().strip():
	print(dict[s], end='')
print()


Measured memory_bytes: 5716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int[] a = new int[M];
		int[] b = new int[M];
		for(int i = 0;i < M;i++) {
			a[i] = Integer.parseInt(sc.next());
			b[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		int[] cnt = new int[N];
		for(int i =0;i < N;i++){
			for(int j = 0;j < M;j++) {
				if(a[j] == i+1) {
					cnt[i]++;
				}
				if(b[j] == i+1) {
					cnt[i]++;
				}
			}
		}
		for(int i : cnt) {
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 23252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		double x1, y1, x2, y2;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] coor = in.readLine().split(" ");
		x1 = Double.parseDouble(coor[0]);
		y1 = Double.parseDouble(coor[1]);
		x2 = Double.parseDouble(coor[2]);
		y2 = Double.parseDouble(coor[3]);
		System.out.println(Math.sqrt(Math.pow(x2 - x1, 2)
				+ Math.pow(y2 - y1, 2)));
	}
}

Measured memory_bytes: 17088
#include <iostream>

using namespace std;

int val[10002];

int main()
{
	int h,w,n; 

	cin>>h>>w;

	cin>>n;

	for(int i=1;i<=n;i++) cin>>val[i];

	int ans[101][101];	

	int k=1;

	for(int i=0;i<h;i++)
	{
		if(i%2==0)
		{
			for(int j=0;j<w;j++)
			{
				while(val[k]==0) k++;

				ans[i][j]=k;

				val[k]--;	
			}	
		}

		else
		{
			for(int j=w-1;j>=0;j--)
			{
				while(val[k]==0) k++;

				ans[i][j]=k;

				val[k]--;
			}
		}
	}	

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cout<<ans[i][j]<<" ";
		}

		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 384
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			while (true)
			{
				string s = Console.ReadLine();
				string[] sar = s.Split(' ');
				int m = int.Parse(sar[0]);
				int f = int.Parse(sar[1]);
				int r = int.Parse(sar[2]);
				if ((m == -1 && f == -1) && r == -1) { break; }
				if (m == -1 || f == -1) { Console.WriteLine("F"); }
				else
				{
					if (m + f >= 80) { Console.WriteLine("A"); }
					else
					{
						if (m + f >= 65) { Console.WriteLine("B"); }
						else
						{
							if (m + f >= 50) { Console.WriteLine("C"); }
							else
							{
								if (m + f >= 30)
								{
									if (r >= 50) { Console.WriteLine("C"); }
									else { Console.WriteLine("D"); }
								}
								else { Console.WriteLine("F"); }
							}
						}
					}
				}
			}
		}
	}
}

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

using namespace std;

int main(){
	string S, T;
	cin >> S >> T;
	vector<char> smemo, tmemo;
	smemo.push_back(S[0]);
	tmemo.push_back(T[0]);
	for(int i=1; i<S.size(); i++){
		int flag = 1;
		for(int j=0; j<smemo.size(); j++){
			if(smemo[j] == S[i]){
				flag = 0;
				if(T[i] != tmemo[j]){
					cout << "No" << endl;
					return 0;
				}
			}
		}
		if(flag){
			smemo.push_back(S[i]);
			tmemo.push_back(T[i]);
		}
	}
	for(int i=0; i<tmemo.size(); i++){
		for(int j=i+1; j<tmemo.size(); j++){
			if(tmemo[i] == tmemo[j]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

ll inf=1e18;
const int mod=1e9+7;
const int M=1003;
int a[M];
vector<int>vec;
int pre[M];
int sz;
 main()

{
    fast
    int n,k;
    cin>>n>>k;
    int tmp=0;
    vector<int>s;
    f(i,1,n)
    {
        cin>>a[i];
        tmp+=a[i];
        pre[i]=tmp;
    }
    f(i,1,n)
    {
        f(j,i,n)
        {
            int x=pre[j]-pre[i-1];
            vec.pb(x);
        }
    }
    sz=vec.size();
    bitset<42>yo[sz+1];
    f(i,0,sz-1)
    {
        s.pb(i);
        yo[i]=vec[i];
    }
    int ses=0;
    rf(j,40,0)
    {
        vector<int>nw;
        int cnt=0;
        for(auto x:s)
        {
            if(yo[x][j])cnt++,nw.pb(x);
        }
       // cout<<cnt<<"#"<<j<<endl;
        if(cnt>=k)
        {
             s=nw;
             ses+=(1LL<<j);
        }
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 16364
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int a,b,c;
     cin>>a>>b;
     if(b<10) c=10*a+b;
     if(b>9 && b<100) c=100*a+b;
     if(b==100) c=1000*a+b;
     if(int(sqrt(c))*int(sqrt(c))==c) cout<<"Yes";
     else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int dx[] ={ 0,1,0,-1};
const int dy[] ={-1,0,1, 0};

int main(){
  int n;
  while(cin >> n , n){
    long double dp[16][5][5] = {{{0.0}}};
    char map[5][5];
    rep(i,5)rep(j,5)map[i][j] = 'X';
    rep(i,3)rep(j,3)map[i+1][j+1] = ' ';
    int sx, sy, gx, gy, bx, by;
    char s,t,b;
    cin >> s >> t >> b ;
    sy = (s-'A')/3 +1 , sx = (s-'A')%3 +1;
    gy = (t-'A')/3 +1 , gx = (t-'A')%3 +1;
    by = (b-'A')/3 +1 , bx = (b-'A')%3 +1;
    
    map[by][bx] = 'X';
    dp[n][sy][sx] = 1.0;
    
    while(n){
      for(int y=1;y<=3;y++){
	for(int x=1;x<=3;x++){
	  rep(i,4){
	    int tx = x+dx[i], ty = y+dy[i] ;
	    if(map[ty][tx] == 'X')ty = y , tx = x;
	    dp[n-1][ty][tx] += dp[n][y][x] / 4.0;
	  }
	}
      }
      n--;
    }
    printf("%.8Lf\n",dp[0][gy][gx]);
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];  
  int c = 0;
  for(int i = 1; i <= p.size() - 2; ++i) {
      if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) ++c;
    }

  cout << c << endl;
  return 0;
}

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

int main(){
  char x, y;
  int x16, y16;
  cin >> x >> y;
  
  if(x=='A'){
    x16 = 10;
  }
  else if(x=='B'){
    x16 = 11;
  }
  else if(x=='C'){
    x16 = 12;
  }
  else if(x=='D'){
    x16 = 13;
  }
  else if(x=='E'){
    x16 = 14;
  }
  else{
    x16 = 15;
  }
  
  if(y=='A'){
    y16 = 10;
  }
  else if(y=='B'){
    y16 = 11;
  }
  else if(y=='C'){
    y16 = 12;
  }
  else if(y=='D'){
    y16 = 13;
  }
  else if(y=='E'){
    y16 = 14;
  }
  else{
    y16 = 15;
  }
  
  if(x16>y16){
    cout << ">";
  }
  else if(x16<y16){
    cout << "<";
  }
  else{
    cout << "=";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
 
using namespace std;
 
struct Node{
  int key;
  Node *parent,*left,*right;
};
Node *root,*NIL;
 
Node* find(int k){
  Node* x=root;
  while(x!=NIL&&k!=x->key){
    if(k<x->key) x=x->left;
    else x=x->right;
  }
  return x;
}
 
Node* getMinimum(Node* x){
  while(x->left!=NIL) x=x->left;
  return x;
}
 
Node* getSuccessor(Node* x){
  if(x->right!=NIL) return getMinimum(x->right);
  else{
    Node* y=x->parent;
    while(y!=NIL&&x==y->right){
      x=y;
      y=y->parent;
    }
    return y;
  }
}
 
void deleteNode(Node* z){
  Node *y,*x;
  if(z->left==NIL||z->right==NIL){
    y=z;
  }else{
    y=getSuccessor(z);
  }
  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }else if(y==(y->parent)->left){
    (y->parent)->left=x;
  }else{
    (y->parent)->right=x;
  }
  if(y!=z) z->key=y->key;
}
 
void insert(int k){
  Node* y=NIL;
  Node* x=root;
  Node* z;
  z=(Node*)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL) root=z;
  else{
    if(y==NIL){
      root=z;
    }else{
      if(z->key<y->key) y->left=z;
      else y->right=z;
    }
  }
}
 
void inorder(Node* u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
 
void preorder(Node* u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
 
int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    string com;
    cin >> com;
    if(com=="print"){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
    else if(com=="insert"){
      int z;
      cin >> z;
      insert(z);
    }
    else if(com=="find"){
      int z;
      cin >> z;
      Node* t=find(z);
      if(t==NIL) cout << "no\n";
      else cout << "yes\n";
    }
    else if(com=="delete"){
      int z;
      cin >> z;
      Node* t=find(z);
      deleteNode(t);
    }
  }
}


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

using namespace std;

bool isHarshad(int num) {
  string s = to_string(num);
  int total = 0;
  for (int i = 0; i < s.length(); i++) {
    total += s[i] - '0';
  }
  return num % total == 0;
}
int main() {
  int n;
  cin >> n;
  cout << (isHarshad(n) ? "Yes" : "No") << endl;
  return 0;
}

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

namespace Test
{
    class ForStudy
    {
        public static void Main(string[] args)
        {
            int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int r = nums[0];
            int c = nums[1];
            var matrix = new List<int[]>();
            for (int i = 0; i < r; i++)
            {
                matrix.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToArray());
            }
            for (int i = 0; i < r; i++)
            {
                Console.Write(String.Join(" ", matrix[i]));
                Console.WriteLine(" {0}", SumR(matrix[i]));
            }
            int[] sumArray = new int[c];
            for (int i = 0; i < c; i++)
            {
                sumArray[i] = Sumc(matrix, i);
            }
            Console.WriteLine("{0} {1}", String.Join(" ", sumArray), SumR(sumArray));
        }
        public static int SumR(int[] array)
        {
            int sum = 0;
            foreach (int i in array)
            {
                sum += i;
            }
            return sum;
        }
        public static int Sumc(List<int[]> list, int c)
        {
            int sum = 0;
            foreach (int[] array in list)
            {
                sum += array[c];
            }
            return sum;
        }
    }
}




Measured memory_bytes: 18460
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n, m, b[100010];
    long long int a[100010], c[100010], ans = 0;
    vector<pair<long long int, long long int>> v;
    int cnt = 0;

    cin >> n >> m;

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

    sort(a, a+n);

    for (int i = 0; i < m; i++) {
        cin >> b[i] >> c[i];
        v.push_back(make_pair(c[i], b[i]));
    }

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    for (int i = 0; i < n; i++) {
        if (v[cnt].second == 0 && cnt < v.size()) {
            cnt++;
        }
        if (v[cnt].first > a[i] && v[cnt].second != 0) {
            ans += v[cnt].first;
            v[cnt].second--;
        }
        else {
            ans += a[i];
        }
    }

    cout << ans << endl;
}



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

typedef string::const_iterator iter;

string expr(iter& p);
string term(iter& p);
string factor(iter& p);

// flag == false -> min
// flag == true -> max

string expr(iter& p) {
  string res = term(p);
  while(*p != '$' && *p != ']') {
    res += term(p);
  }
  return res;
}

string term(iter& p) {
  if(*p == '[') {
    ++p; // skip '['
    string s = expr(p);
    reverse(s.begin(), s.end());
    ++p; // skip ']'
    return s;
  }
  return factor(p);
}

string factor(iter& p) {
  int inc = 0;
  while(*p == '+' || *p == '-') {
    if(*p == '+') inc++;
    if(*p == '-') inc--;
    ++p;
  }
  char c = *p;
  ++p;
  if(c == '?') {
    string res;
    res.push_back('A');
    return res;
  }
  while(inc < 0) inc += 26;
  string res;
  res.push_back((c - 'A' + inc) % 26 + 'A');
  return res;
}

int main() {
  // add $
  while(true) {
    string s; cin >> s;
    if(s == ".") break;
    s.push_back('$');
    iter p = s.begin();
    cout << expr(p) << endl;
  }
}

Measured memory_bytes: 1196
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")



#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <memory>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <unordered_map>
#include <iomanip>
#include <ctime>
#include <sstream>  
#include <deque>
#include <unordered_set>
#include <stack>
#include <functional>
#include <memory.h>
#include <bitset>
#include <numeric>

using namespace std;

#define int long long

signed main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    if (c > a + b + 1) {
        c = a + b + 1;
    }
    cout << c + b << endl;
}

Measured memory_bytes: 256