akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read(){ll x=0,f=1;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;return x*f;}
inline void write(ll x){if(x>9)write(x/10);putchar('0'+x%10);}
inline void writeln(ll x){write(x);puts("");}
const int N=55;
string s, t;  
set<string> S;  
int n,m;
int main()
{
	cin >> s;
	cin >> t;
    int lens = s.size();  
    int lent = t.size();  
    for(int i = 0; i < lens; i++){  
        if(s[i] == '?' || s[i] == t[0]){  
            string tmp = s;  
            for(int j = 0; j < i; j++) if(tmp[j] == '?') tmp[j] ='a';  
            bool can = false;  
            for(int j = 0; j < lent; j++){  
                if(tmp[i+j]!= '?' && tmp[i+j] != t[j]) break;  
                tmp[i+j] = t[j];  
                if(j == lent - 1) can = true;  
            }  
            if(can){  
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';  
                S.insert(tmp);  
            }  
        }  
    }  
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;  
    else cout << *S.begin() << endl;  
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int ll;
const ll maxn=(3*1e3)+5;
const int N = 1e5;
int main()
{
    string s;
    cin>>s;
    ll l=s.length();
    if(s[l-1]=='s')
        cout<<s<<"es"<<"\n";
    else
        cout<<s<<"s"<<"\n";
    cerr<<"\nTime elapsed:"<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>

using namespace std;

void brain(string s, int size){
	int ans[size] = {};
	int a = 1, b = 0;
	char last = 'R';
	
	for(int i = 1; i < size; i++){		
		if(s[i] == last){
			if(a == b) a++;
			else b++;
			
			if(i == size - 1){
				ans[i - (a + b - 1)] += a;
				ans[i - (a + b)] += b;
			}
		}else{
			if(last == 'R'){
				ans[i - 1] += a;
				ans[i] += b;
				
				if(i == size - 1) ans[i]++;
			}else{
				ans[i - (a + b)] += a;
				ans[i - (a + b + 1)] += b;
			}
			a = 1;
			b = 0;
			last = s[i];
		}
		//cout << last << " " << a << " " << b << endl;
	}
	
	for(int i = 0; i < size - 1; i++) cout << ans[i] << " ";
	cout << ans[size - 1] << endl;
}

int main(){
	string s;
	int size;
	
	cin >> s;
	size = s.length();
	
	brain(s, size);
	
	return 0;
}

Measured memory_bytes: 1024
def s_in():
    return input()

def n_in():
    return int(input())

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

class SegmentTree():
    def __init__(self, n, init_val, segfunc, unifunc):
        self.n = n
        self.size = 2**(n-1).bit_length()
        self.segfunc = segfunc
        self.unifunc = unifunc

        self.seg = [unifunc() for _ in range(2*self.size)]

        for i in range(self.n):
            self.seg[i+self.size-1] = init_val[i]

        for i in range(self.size-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])


    def update(self, k, x):
        k += self.size-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])

    def query(self, p, q): # [p, q)
        if q <= p:
            return self.unifunc()
        p += self.size-1
        q += self.size-2
        res = self.unifunc()

        while q-p > 1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res

n = n_in()
S = s_in()
Q = n_in()


dic={i:j for i,j in zip('abcdefghijklmnopqrstuvwxyz',[2**i for i in range(26)])}

T = SegmentTree(n,
    [dic[s] for s in S],
    lambda x,y: x|y,
    lambda: 0
    )

for _ in range(Q):
    n, i, j = input().split()
    if int(n) == 1:
        T.update(int(i)-1, dic[j])
    else:
        print(bin(T.query(int(i)-1, int(j))).count('1'))


Measured memory_bytes: 32160
#include<stdio.h>
#define N_MAX 120

int main()
{
  int N[N_MAX][N_MAX];
  int n;
  int v,vi, k;
  int i, j;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d%d", &k, &v);
    for(j=0; j<v; j++){
      scanf("%d", &vi);
      N[k][vi]=1;
    }
  }

  for(i=1; i<=n; i++){
    for(j=1; j<=n; j++){
      printf("%d", N[i][j]);
      if(j!=n) printf(" ");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 652
#include <iostream>
    using namespace std;
    int main()
    {
      int a, b, c, d, e;
      cin>> a>> b;
      c=2*a-1;
      d=2*b-1;
      e=a+b;
      if (c>=d && c>=e){
        cout<<c;
      }else if (d>=c && d>=e){
        cout<<d;
      }else if (e>=d && e>=c){
        cout<<e;
      }
    }

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    ll ans = 0;
    ll a;
    cin >> a;
    FOR(i, 1, a + 1) if(i % 3 && i % 5) ans += i;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
result = -(10 ** 7) * 100

for i in range(1, 1024):
    array = []
    num = i
    for _ in range(10):
        array.append(num%2)
        num //= 2

    point = 0
    for j in range(N):
        counter = 0
        for k in range(10):
            if array[k] == 1 and F[j][k] == 1:
                counter += 1

        point += P[j][counter]

    result = max(result, point)

print(result)


Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K;
int X, Y; char C;

int cnt[4005][4005];
int sum[4005][4005];

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    cin >> X >> Y >> C;
    if (C == 'W') Y += K;
    X %= 2 * K; Y %= 2 * K;
    X++; Y++;

    cnt[X][Y]++;
    cnt[X + 2 * K][Y]++;
    cnt[X][Y + 2 * K]++;
    cnt[X + 2 * K][Y + 2 * K]++;
  }

  for (int i = 1; i <= 4 * K; i++){
    for (int j = 1; j <= 4 * K; j++){
      sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
      sum[i][j] += cnt[i][j];
    }
  }

  int ans = 0;
  for (int i = 1; i <= 2 * K; i++){
    for (int j = 1; j <= 2 * K; j++){
      int now = sum[i+K][j+K] - sum[i][j+K] - sum[i+K][j] + sum[i][j];
      now += sum[i+2*K][j+2*K] - sum[i+K][j+2*K] - sum[i+2*K][j+K] + sum[i+K][j+K];
      ans = max(ans, now);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 128728
object Main {
  def main(args: Array[String]): Unit = {
    val jewelry_nums   = io.StdIn.readInt
    val jewelry_values = io.StdIn.readLine.split(" ").map{_.toInt}
    var jewelry_costs  = io.StdIn.readLine.split(" ").map{_.toInt}
    var max_profits    = 0

    (0 until jewelry_nums).foreach { i =>
      val profit = jewelry_values(i) - jewelry_costs(i)
      if(profit > 0) {
        max_profits += profit
      }
    }
    println(max_profits)

  }
}

Measured memory_bytes: 25420
import numpy as np
import sys
N, D, A = map(int, input().split())
L = 2 * D
I = np.array(sys.stdin.read().split(), np.int64)
X = I[::2]
H = I[1::2]
sort_ind = np.argsort(X)
X = X[sort_ind]
H = H[sort_ind]
S = np.zeros(N+1, np.int64)
ind = np.searchsorted(X,X+L+1,side = 'left')

atack = 0
ans = 0
for i in range(N):
	atack += S[i]
	H[i] -= atack
	if H[i] > 0:
		atack_cnt = -(-H[i]//A)
		ans += atack_cnt
		tmp = atack_cnt * A
		S[i+1] += tmp
		S[ind[i]] -= tmp

print(ans)

Measured memory_bytes: 62260
N = int(input())
A = [int(i) for i in input().split()]
A_count = [0] * (max(A)+1)

for i in A:
    A_count[i] += 1

max_count = 0
if len(A_count) < 4:
    print(sum(A_count))
else:
    for X in range(1, len(A_count)-1):
        count = A_count[X-1] + A_count[X] + A_count[X+1]
        if count > max_count:
            max_count = count
    print(max_count)

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

int main(){
	int n,x; cin >> n >> x;
	vector<int> m(n);
	int r=1e9;
	int ans=0;
	for(int i=0;i<n;i++){
		cin >> m[i];
		x-=m[i];
		ans++;
		r=min(r,m[i]);
	}
	while(x>=r){
		x-=r;
		ans++;
	}
	cout << ans << endl;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] a = new int[n];
        for(int i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int max = a[n-1];
        int half = (max+1)/2;
        int dist = Integer.MAX_VALUE;
        int pair = 0;
        for(int i = 0; i < n; i++) {
        	if( Math.abs(half-a[i]) < dist) {
        		dist = Math.abs(half-a[i]);
        		pair = a[i];
        	}
        }
        System.out.println(max+" "+pair);
    }
}

Measured memory_bytes: 50308
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int c[24];

void rot(char r){
  int t;
  if(r=='U'){
    t = c[4]; c[4] = c[8]; c[8] = c[12]; c[12] = c[16]; c[16] = t;
    t = c[5]; c[5] = c[9]; c[9] = c[13]; c[13] = c[17]; c[17] = t;
    t = c[0]; c[0] = c[2]; c[2] = c[3]; c[3] = c[1]; c[1] = t; 
  }
  else if(r=='F'){
    t = c[2]; c[2] = c[7]; c[7] = c[21]; c[21] = c[12]; c[12] = t;
    t = c[3]; c[3] = c[5]; c[5] = c[20]; c[20] = c[14]; c[14] = t;
    t = c[8]; c[8] = c[10]; c[10] = c[11]; c[11] = c[9]; c[9] = t;
  }
  else if(r=='R'){
    t = c[1]; c[1] = c[9]; c[9] = c[21]; c[21] = c[18]; c[18] = t;
    t = c[3]; c[3] = c[11]; c[11] = c[23]; c[23] = c[16]; c[16] = t;
    t = c[12]; c[12] = c[14]; c[14] = c[15]; c[15] = c[13]; c[13] = t;
  }
  else if(r=='D'){
    t = c[6]; c[6] = c[18]; c[18] = c[14]; c[14] = c[10]; c[10] = t;
    t = c[7]; c[7] = c[19]; c[19] = c[15]; c[15] = c[11]; c[11] = t;
    t = c[20]; c[20] = c[22]; c[22] = c[23]; c[23] = c[21]; c[21] = t;
  }
  else if(r=='B'){
    t = c[0]; c[0] = c[13]; c[13] = c[23]; c[23] = c[6]; c[6] = t;
    t = c[1]; c[1] = c[15]; c[15] = c[22]; c[22] = c[4]; c[4] = t;
    t = c[16]; c[16] = c[18]; c[18] = c[19]; c[19] = c[17]; c[17] = t;
  }
  else{
    t = c[0]; c[0] = c[19]; c[19] = c[20]; c[20] = c[8]; c[8] = t;
    t = c[2]; c[2] = c[17]; c[17] = c[22]; c[22] = c[10]; c[10] = t;
    t = c[4]; c[4] = c[6]; c[6] = c[7]; c[7] = c[5]; c[5] = t;
  }
}

char trans(int x){
  int a = x/4;
  if(a==0)return 'r';
  if(a==1)return 'g';
  if(a==2)return 'y';
  if(a==3)return 'b';
  if(a==4)return 'w';
  return 'o';
}

int main(){
  rep(i,24)c[i] = i;
  string s;
  cin >> s;

  rep(i,s.size())rot(s[i]);

  cout << ".."; rep(i,2)cout << trans(c[i]); cout << "....\n"; 
  cout << ".."; rep(i,2)cout << trans(c[i+2]); cout << "....\n";
  rep(i,2){
    rep(j,8)cout << trans(c[(j&1)+(j/2)*4+i*2+4]);
    cout << endl;
  }
  cout << ".."; rep(i,2)cout << trans(c[i+20]); cout << "....\n"; 
  cout << ".."; rep(i,2)cout << trans(c[i+22]); cout << "....\n";
}

Measured memory_bytes: 1184
N,M = map(int,input().split())

slink = {}
glink = {}

for i in range(M):

    a,b = map(int,input().split())

    if a == 1:
        slink[b] = 1
    elif b == 1:
        slink[a] = 1
    elif a == N:
        glink[b] = 1
    elif b == N:
        glink[a] = 1

ans = "IMPOSSIBLE"
for i in slink:

    if i in glink:
        ans = "POSSIBLE"
        break

print (ans)


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

int main() {
  int n;
  cin >> n;
  int mi = 1e9+1;
  int res = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (mi > b) {
      res = a + b;
      mi = b;
    }
  }
  cout << res << endl;
  return 0;
}

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

using namespace std;

typedef long long signed int ll;

#define MAXN 501

ll n,m,q,t[MAXN][MAXN],s[MAXN][MAXN];//t[l][r]

int main() {
	cin >> n >> m >> q;
	for(int i = 0;i < m;i++) {
		int l,r;
		cin >> l >> r;
		t[l][r]++;
	}
	for(int i = 1;i <= n;i++) {
		for(int j = 1;j <=n;j++) {
			s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + t[i][j];
		}
	}
	for(int i = 0;i < q;i++) {
		int p,q;
		cin >> p >> q;
		cout << s[q][q] + s[p-1][p-1] - s[p-1][q] - s[q][p-1] << endl;
	}
}


Measured memory_bytes: 4864
#include<iostream>
#include<vector>
#define DIM 200005
using namespace std;
int n, m, i, p, u, x, y, j, nod, vecin;
vector<int> v[DIM];
int d0[DIM], d1[DIM], c[DIM], viz[DIM];
char s[DIM];
int main(){
    cin>> n >> m;
    cin>> s + 1;
    for(i = 1; i <= m; i++){
        cin>> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(i = 1; i <= n; i++){
        for(j = 0; j < v[i].size(); j++){
            if(s[ v[i][j] ] == 'A'){
                d0[i]++;
            }
            else{
                d1[i]++;
            }
        }
    }
    p = 1;
    for(i = 1; i <= n; i++){
        if(d1[i] == 0 || d0[i] == 0){
            c[++u] = i;
            viz[i] = 1;
        }
    }
    while(p <= u){
        nod = c[p];
        for(i = 0; i < v[nod].size(); i++){
            vecin = v[nod][i];
            if(s[nod] == 'A'){
                d0[vecin]--;
            }
            else{
                d1[vecin]--;
            }
            if(d0[vecin] == 0 || d1[vecin] == 0){
                if(viz[vecin] == 0){
                    viz[vecin] = 1;
                    c[++u] = vecin;
                }
            }
        }
        p++;
    }
    if(u == n){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        x: usize,
        a: [usize; n],
    }
    let mut a = a;
    a.sort();
    let mut x = x;
    let mut ans = 0;
    for ai in a {
        if x < ai {
            break;
        }
        x -= ai;
        ans += 1;
    }
    if ans == n && x > 0 {
        ans -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import           Control.Monad.Primitive     (PrimMonad, PrimState)
import qualified Data.ByteString.Builder     as BSB
import qualified Data.ByteString.Char8       as BS
import           Data.Char                   (isSpace)
import           Data.Foldable               (foldlM)
import           Data.List                   (unfoldr)
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           System.IO                   (stdout)

-- Union Find
newUnionFindTree :: PrimMonad m => Int -> m (UM.MVector (PrimState m) Int)
newUnionFindTree n = U.thaw $ U.enumFromN 0 n

getRoot :: PrimMonad m => UM.MVector (PrimState m) Int -> Int -> m Int
getRoot !v = go
  where
    go !i = do
      j <- UM.read v i
      if i == j then
        return i
      else do
        k <- go j
        UM.write v i k
        return k
{-# INLINE getRoot #-}

unify :: PrimMonad m => UM.MVector (PrimState m) Int -> Int -> Int -> m ()
unify !v !i !j = do
  i' <- getRoot v i
  j' <- getRoot v j
  unless (i' == j') $ do
    let !k = min i' j'
    UM.write v i' k
    UM.write v j' k
{-# INLINE unify #-}

main = do
  [n,q] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  uf <- newUnionFindTree n
  queries <- U.replicateM q $ do
    [t,u,v] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (t,u,v)
  bb <- U.foldM (\bb (t,u,v) ->
                   if t == 0 then
                     unify uf u v >> return bb
                   else do
                     i <- getRoot uf u
                     j <- getRoot uf v
                     return $ bb <> if i == j then BSB.string8 "1\n" else BSB.string8 "0\n"
                ) mempty queries
  BSB.hPutBuilder stdout bb


Measured memory_bytes: 21472
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
#define MAX 1000000
bool sosu[MAX+1]={1,1,0};
int main(){
  for(int i=4;i<=MAX;i+=2)sosu[i]=true;
  for(int i=3;i<=MAX;i+=2){
    if(sosu[i])continue;
    for(int j=i*3;j<MAX;j+=i*2)sosu[j]=true;
  }
  int n,m;
  while(cin>>n>>m,n||m){
    bool dp[MAX+1]={false};
    vector<int>in(n);
    rep(i,n){cin>>in[i];dp[in[i]]=true;}
    rep(i,n)rep(j,m+1){
      if(dp[j]&&j+in[i]<=MAX)dp[j+in[i]]=true;
    }
    int maxi=0;
    int i=0;
    for(i=m;i>=0;i--)if(!sosu[i]&&dp[i])break;
    if(i!=-1)cout<<i<<endl;
    else cout<<"NA"<<endl;
  }
}

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

int main(void) {
  string S, T;
  cin >> S >> T;
  string ans = "Yes";
  for (int i = 0; i < S.length(); i++) {
    if (T[i] != S[i]) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

struct Node {
    int key;
    Node *next, *prev;
};
Node *nil;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while(1) {
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}
Node *listSearch(int key) {
    Node *t = nil->next;
    while(t != nil && t->key != key) {
        t = t->next;
    }
    return t;
}

void deleteNode(Node *t) {
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();

    for(int  i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if(com[0] == 'i') {
            insert(key);
            np++;
            size++;
        }else if(com[0] == 'd') {
            if(strlen(com) > 6) {
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            }else {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }
    printList();
    return 0;
}

Measured memory_bytes: 33828
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


# A
def A():
    r = I()
    print(r * r)
    return


# B
def B():
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    A()
    return


# Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 38384
#include<stdio.h>
#define N 2000
int n,S[N];

int solve(int m,int key){
   if( m >= n)
    return 0;
  if( S[m] == key)
    return 1;
  if( solve(m+1, key))
    return 1;
  if( solve(m+1, key-S[m]))
    return 1;
}


    

int main(){
  int m,i,key,a;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);
  
  scanf("%d", &m);
  for(i = 0; i < m; i++){
    scanf("%d", &key);
    a = solve(0,key);
    if( a == 1)
      printf("yes\n");
    else
      printf("no\n");
  }

  return 0;
}




Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
string s[3];
int main()
{
    s[0]="Sunny";s[1]="Cloudy";s[2]="Rainy";
    string ss;cin>>ss;
    int ans;
    for(int i=0;i<3;i++)
        if(ss==s[i]) ans=i;
    ans=(ans+1)%3;
    cout<<s[ans];
}


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

int main() {
	int h,n;cin>>h>>n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	vector<vector<int>> v(n,vector<int>(h+1,1<<30));
	for(int i=0;i<n;i++){
		v[i][0]=0;
		for(int j=0;j<=h;j++){
			if(i)v[i][j]=min(v[i-1][j],v[i][j]);
			if(j+a[i]<=h){
				v[i][j+a[i]]=min(v[i][j+a[i]],v[i][j]+b[i]);
			}else{
				v[i][h]=min(v[i][h],v[i][j]+b[i]);
			}
//			cout<<v[i][j]<<' ';
		}
//		cout<<endl;
	}

	cout<<v[n-1][h]<<endl;

	return 0;
}


Measured memory_bytes: 39424
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=4;
int a[maxn][4];
int main()
{
    while (scanf("%d%d%d",&a[1][1],&a[1][2],&a[1][3])!=EOF) {
        for(int i=2;i<=3;i++)
            for(int j=1;j<=3;j++)scanf("%d",&a[i][j]);
        bool flag=true;
        for(int i=2;i<=3;i++)
            for(int j=2;j<=3;j++)
                if((a[j-1][i]-a[j-1][i-1])!=(a[j][i]-a[j][i-1])||(a[i-1][j]-a[i-1][j-1])!=(a[i][j]-a[i][j-1])){
                    flag=false;break;
                }
        if(flag)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())

result = 0
if (a + b) > c * 2:
    m = min(x, y)
    result += (m * c * 2)
    if (a if x > y else b) > c * 2:
        result += (max(x, y) - m) * c * 2
    else:
        result += ((x - m) * a if x > y else (y - m) * b)
else:
    result += a * x + b * y

print(result)


Measured memory_bytes: 3060
/*
    author: Salam_35
    problem name:
*/

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

#define ll          long long int
#define pb          push_back
#define sc(n)       scanf("%d",&n)
#define Max         100005
#define scan(n)     scanf("%lld",&n)
#define pi          acos(-1.0)
#define _fastio     ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x)      x.begin(),x.end()
#define pii         pair<int,int>
#define uniq(v)	    v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define load(arr,n) for(int i=0 ; i<n ; i++) cin>>arr[i] ;
#define load1(arr,n) for(int i=1 ; i<=n ; i++) cin>>arr[i] ;
#define INF	        1LL<<30
#define pll         pair<ll,ll>
ll dp[150][100050];
ll arr[Max];
ll n,w,s;
ll price[10005];
ll knapsack(int i, int w)
{
    if(i==(n+1) )
        return 0;
    if(dp[i][w]!=-1)
        return dp[i][w];
    if(w+arr[i]<=s)
        return dp[i][w] = max(knapsack(i+1,w), price[i]+knapsack(i+1,w+arr[i]));
    else
        return dp[i][w]=knapsack(i+1,w);
}

int main()
{
    memset(dp,-1,sizeof dp);
    cin >> n >> s;
    for(int i=0;i<n;i++)
        cin >> arr[i] >> price[i];
    cout<< knapsack(0,0)<<endl;
}


Measured memory_bytes: 117504
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;

bool isPrime(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) return false;
	}
	return true;
}

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

	vector<ll> ps;
	for(int i = 2; i <= 100000; i++) {
		if(isPrime(i)) ps.push_back(i);
	}

	ll m, a, b;
	while(cin >> m >> a >> b, m) {
		ll mx = -1, mp = -1, mq = -1;
		for(int i = 0; i < ps.size(); i++) {
			for(int j = i; j < ps.size(); j++) {
				ll p = ps[i], q = ps[j];
				if(p * q <= m && a * q <= b * p) {
					if(mx < p * q) {
						mx = p * q;
						mp = p;
						mq = q;
					}
				}
				else break;
			}
		}
		cout << mp << " " << mq << endl;
	}
}

Measured memory_bytes: 3152
while True:
    s, t = input().split()
    if s == "0" and t == "0":
        break
    
    S = [int(x) for x in list(s)]
    T = [int(x) for x in list(t)]
    
    hit = 0
    blow = 0
    for i in range(len(T)):
        if T[i] in S:
            blow += 1
        if T[i] == S[i]:
            blow -= 1
            hit  += 1
    
    print(hit, blow)
        
        
        


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define int long long
void run();
signed main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13); run(); return 0; }
mt19937 rng(random_device{}());

void run() {
   int n;
   cin >> n;
    int k;
    cin >> k;
 int d = 0;
    while (n) {
n /= k;
++d;
 }
    cout << d;
}


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

fn main() {
    let (N, M): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    let (a, b, c) = {
        let (mut a, mut b, mut c) = (vec![], vec![], vec![]);
        for _ in 0..M {
            let (x, y): (i64, usize) = {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                let mut iter = line.split_whitespace();
                (
                    iter.next().unwrap().parse().unwrap(),
                    iter.next().unwrap().parse().unwrap(),
                )
            };
            let z: Vec<usize> = {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                line.split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect()
            };
            a.push(x);
            b.push(y);
            c.push(z);
        }
        (a, b, c)
    };

    const INF: i64 = 1e15 as i64;
    let P = 1 << N;
    let mut dp = vec![INF; P];
    dp[0] = 0;
    for k in 0..M {
        let s = c[k].iter().map(|&x| 1 << (x - 1)).sum::<usize>();
        for i in 0..P {
            dp[i | s] = std::cmp::min(dp[i | s], dp[i] + a[k]);
        }
    }
    let ans = if dp[P - 1] < INF { dp[P - 1] } else { -1 };

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


Measured memory_bytes: 4352
#include<iostream>
#include<cstring>
#include<cmath>
#include<fstream>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  int dp[100001];
  dp[0]=0;
  int pow6,pow9,t1,t2,log6,log9;
  memset(dp,0,sizeof(dp));
  for(int i=1;i<6;i++)
  {
    dp[i] = i;
  }
  dp[6]=1;
  dp[7]=2;
  dp[8]=3;
  for(int i=9;i<=n;i++)
  {
    t1=0,t2=0;
    log6 = float(log(i)/log(6));
    log9 = float(log(i)/log(9));
    pow6 = pow(6,log6);
    pow9 = pow(9,log9);
    t1 = 1 + dp[i-pow6];
    t2 = 1 + dp[i-pow9];
    dp[i] = min(t1,t2);
  }
  //cout<<t1<<t2;
  cout<<dp[n]<<endl;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

  int n;
  cin>>n;
  n==1 ? cout<<0<<endl:cout<<1<<endl;
    return 0;
}



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

int main() {
  int N, W;
  cin >> N >> W;
  vector<long> DP(W + 1);
  for (int w, v; cin >> w >> v;) {
    vector<long> tmp = DP;
    for (int i = w; i < W + 1; i++) {
      tmp.at(i) = max(tmp.at(i), DP.at(i - w) + v);
    }
    DP = tmp;
  }
  cout << DP.at(W) << "\n";
}

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

int main() {
    int h, w; scanf("%d%d%d", &h, &w);
    vector <string> lines(h);
    vector <int> cols(h, 0), rows(w, 0);
    for(int i=0;i<h;i++)cin >> lines[i];
    for(int col=0;col<h;col++){
        for(int row=0;row<w;row++){
            if(lines[col][row]=='#'){cols[col]=1;rows[row]=1;}        
            }
    }
    for(int col=0;col<h;col++){
        if(cols[col]==1){
            for(int row=0;row<w;row++){
                if(rows[row]==1)printf("%c", lines[col][row]);
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main() {
    string s,t;
    cin>>s>>t;
    int n=s.size();
    bool ok=true;
    rep(i,n){
        if(s[i]!=t[i]) ok=false;
    }

    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3592
import java.util.*;
import java.lang.*;

class Main {
	static int[] segTree;
	static int n;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int _n = scanner.nextInt();
		int q = scanner.nextInt();

		initSegTree(_n);

		for(int i = 0; i < q; i++) {
			int type = scanner.nextInt();
			int x = scanner.nextInt();
			int y = scanner.nextInt();

			if(type == 0) {
				// update(i,x): Change a[i] to x
				update(x, y);	
			} else if(type == 1) {
				// find(s,t): Find minimum in range [s,t]
				int result = find(x, y);
				System.out.println(result);
			}
		}
	}


	static void initSegTree(int _n) {
		n = 1;
		while(n < _n)
			n *= 2;

		segTree = new int[2*n-1];
		Arrays.fill(segTree, Integer.MAX_VALUE);
	}	

	static void update(int i, int x) {
		// Convert to index of segTree
		int k = i + n - 1;
		segTree[k] = x;
		while(k > 0) {
			// Update ancestors of k
			k = (k-1)/2;
			segTree[k] = Math.min(segTree[k*2+1], segTree[k*2+2]);
		}
	}

	static int find(int s, int t) {
		return query(s, t+1, 0, 0, n);
	}

	/* Find minimum element in the range [s,t)
	/* s : start of desired range
	/* t : end of desired range
	/* k : index of segTree
	/* l : left
	/* r : right 
	*/
	static int query(int s, int t, int k, int l, int r) {
		if (r <= s || t <= l) // [s,t] and [l,r] not intersect
			return Integer.MAX_VALUE;

		if (s <= l && r <= t) // [l,r] totally inside [s,t]
			return segTree[k];

		// [s,t] and [l,r] intersect
		int vleft = query(s, t, k*2+1, l, (l+r)/2);
		int vright = query(s, t, k*2+2, (l+r)/2, r);
		return Math.min(vleft, vright);
	}
}



Measured memory_bytes: 104564
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if((h == 0)&&(w == 0)){
                break;
            }
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w;j++){
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n) cin >> w[i];

    int ans = INT32_MAX;
    for (int i = 1; i < n; ++i)
    {
        int s1 = 0, s2 = 0;
        for (int j = 0; j < n; ++j)
        {
            if (j <= i)
                s1 += w[j];
            else
                s2 += w[j];
        }
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main(){
    fast();

/* you get what you work for not what you wish for */
    inps(a, b);
    ll x = __gcd(a, b);
    set <ll> s;
    for(ll i=1; i*i<=x; i++){
        if((x%i)==0){
            s.ins(i);
            s.ins(x/i);
        }
    }
    vector <bool> sieve(1000005, 0);
    set <ll> p;
    p.ins(1);
    for(ll i=2; i<=1000000; i++){
        if(!sieve[i]){
            p.ins(i);
            for(ll j=i*i; j<=1000000; j+=i){
                sieve[j]=1;
            }
        }
    }
    p.ins(x);
    for(ll i=2; i*i<=x; i++){
        if((x%i)==0){
            p.er(x);
        }
    }
    ll cnt = 0;
    for(auto i:s){
        if(i>1000000){
            cnt++;
            for(ll j=2; j*j<=i; j++){
                if((i%j)==0){
                    cnt--;
                    break;
                }
            }
        }
        else{
            if(!sieve[i]){
                cnt++;
            }
        }
    }
    out(cnt);
}

Measured memory_bytes: 4352
import sys

class UnionFind:
    def __init__(self, n):
        self.root = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)  # The number of nodes under the target node.
        self.weight = [0] * (n+1)  # Distance from the root

    def find(self, x):
        if self.root[x] == x:
            return x
        else:
            y = self.find(self.root[x])
            self.weight[x] += self.weight[self.root[x]]
            self.root[x] = y
            return self.root[x]

    def unite(self, x, y, w=0):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.root[rx] = ry
            self.size[ry] += self.size[rx]
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.root[ry] = rx
            self.size[rx] += self.size[ry]
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def diff(self, x, y):
        return self.weight[y] - self.weight[x]


def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    UF = UnionFind(N)

    for _ in range(M):
        l, r, d = map(int, input().split())
        l -= 1
        r -= 1

        if not UF.is_same(l, r):
            UF.unite(l, r, d)

        elif UF.is_same(l, r) and UF.diff(r, l) != d:
            return 'No'

        else:
            continue

    return 'Yes'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 12376
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int n = Integer.parseInt(line);
		line = br.readLine();
		String[] sp = line.split(" ");
		int[] a = new int[n];
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sp[i]);
			min = Math.min(a[i] , min);
			max = Math.max(a[i] , max);
		}
		int minCost = Integer.MAX_VALUE;
		for (int i = min; i <= max; i++) {
			int cost = 0;
			for (int j = 0; j < n; j++) {
				cost += Math.pow(a[j] - i, 2);
			}
			minCost = Math.min(cost, minCost);
		}
		System.out.println(minCost);
	}

}


Measured memory_bytes: 8272
#include<stdio.h>

int main(){
	int a,b,c,d,f;
	bool e=false;
	scanf("%d",&a);
	scanf("%d",&b);
	for(int i=1;a>=i;i++){
		scanf("%d",&c);
		scanf("%d",&d);
		if(d<=b){
			e=true;
		if(i==1||f>=c){
			f=c;
		}
		}
	}
		if(e==false){
			printf("TLE");
		}
		else{
			printf("%d",f);
		}
}

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N, L;
	
	cin >> N >> L;
	
	string S[N];
	
	for(int i=0; i<N; i++)
		cin >> S[i];
	
	sort(S, S+N);
	
	for(int i=0; i<N; i++)
		cout << S[i];
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

void solve(long long N, long long K, std::vector<long long> D){
    for(int i=N; i<=1000000; i++){
        string num = to_string(i);
        bool err=false;
        REP(j, num.size()){
            // debug(num);
            REP(k, K){
                if((int)num[j]-(int)'0'==(int)D[k]){
                    err=true;
                    break;
                }
            }
            if(err)break;
        }
        if(!err){
            cout<<num<<endl;
            return;
        }

    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> D(K);
    for(int i = 0 ; i < K ; i++){
        scanf("%lld",&D[i]);
    }
    solve(N, K, std::move(D));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
#define Q 50000
 
void search(int[],int);

int count=0;
int n,q;

int main(void){
  
  int S[N];
  int T[Q];
  int i;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  
  scanf("%d",&q);
  
  for(i=0;i<q;i++){
    scanf("%d",&T[i]); 
    search(S,T[i]);
  }
  
  printf("%d\n",count);
  
  return 0;
}

void search(int S[],int key){
  
  int flag = 0;
  int mid;
  int left = 0;
  int right = n;


  while(left <= right){
    mid = (left+right)/2;

    if(S[mid] == key){
      flag = 1;
      break;
    }
    
    else if(S[mid] < key)
      left = mid +1;
    
    else if(S[mid] > key)
      right = mid -1;
  }

  if(flag ==1)
    count++;
  
}

Measured memory_bytes: 1184
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 2000;

int main(void){
    ll N, Y;
    ll a, b, c;
    ll answer[3];
    rep(i, 3) answer[i] = -1;

    cin >> N >> Y;

    rep(a, N + 1){
        rep(b, N - a + 1){
            if (Y - 1000 * N == 9000 * a + 4000 * b){
                answer[0] = a;
                answer[1] = b;
                answer[2] = N - a - b;
            }
        }
    }

    rep(i, 3) cout << answer[i] << " ";
    cout << "" << endl;

    return 0;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())

dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1

B = [format(i, 'b').zfill(W - 1) for i in range(2 ** (W - 1)) if '11' not in format(i, 'b')]

for h in range(H):
  for w in range(W):
    for b in B:
      if w > 0 and b[w - 1] == '1':
      	dp[h + 1][w - 1] += dp[h][w]
      elif w < W - 1 and b[w] == '1':
        dp[h + 1][w + 1] += dp[h][w]
      else:
        dp[h + 1][w] += dp[h][w]

print(dp[H][K - 1] % (10**9 + 7))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int64_t n;
    cin>>n;
    int64_t Sum=0;
    for(int i=1;i<=n;i++){
        if(i%3>0&&i%5>0){
            Sum+=i;
        }
    }
    cout<<Sum<<endl;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan =new Scanner(System.in);
		int n=scan.nextInt();
		int[] num=new int[n+1];
		for(int i=1;i<=n;i++){
			num[i]=scan.nextInt();
		}
		for(int i=n/2;i>0;i--){
			maxHeap(num,i);
		}
		for(int i=1;i<=n;i++){
			System.out.print(" "+num[i]);
		}
		System.out.println();
	}

	private static void maxHeap(int[] num, int i) {
		// TODO Auto-generated method stub
		int l=2*i;
		int r=2*i+1;
		int H=num.length-1;
		int largest=-1;
		if(l<=H&&num[l]>num[i]){
			largest=l;
		}else {
			largest=i;
		}
		if(r<=H&&num[r]>num[largest])
			largest=r;
		
		if(largest!=i){
			swap(num,largest,i);
			maxHeap(num, largest);
		}
	}

	private static void swap(int[] num, int j, int i) {
		// TODO Auto-generated method stub
		int tmp=num[i];
		num[i]=num[j];
		num[j]=tmp;
	}

}



Measured memory_bytes: 168040
ans=[]
N=int(input())
def saiki(A):
    eigo="abcdefghijklmnopqrstuvwxyz"
    if len(A)==N:
        B="".join(A)
        ans.append(B)
        return
    for i in range(len(set(A))+1):
        A.append(eigo[i%26])
        saiki(A)
        A.pop()
saiki([])
ans.sort()
for i in ans:
    print(*i,sep="")

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

int main()
{
    string s;
    cin>>s;
    long long flag=0;
    for(int i=0; i<s.size(); i++)
    {
		long long a=0;
		for(int j=0; j<s.size(); j++)
		{
			if(s[i]==s[j])
			{
				a++;
			}
		}
		if(a%2==0)
		{
			flag=1;
		}
		else 
		{
			flag=0;
			break;
		}
	}
	
	
	if(flag==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] grid = new char[H][W];
		for (int i=0; i<H; i++) {
			char[] t = sc.next().toCharArray();
			grid[i] = t;
		}
		for (int i=-1; i<=H; i++) {
			StringBuffer sb = new StringBuffer();
			for (int j=-1; j<=W; j++) {
				if (i==-1) sb.append("#");
				else if (j==-1) sb.append("#");
				else if (i==H) sb.append("#");
				else if (j==W) sb.append("#");
				else sb.append(grid[i][j]);
			}
			System.out.println(sb.toString());
		}
	}
}


Measured memory_bytes: 21972