akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll MOD = ll(1e9 + 7);
const int MAX_N = int(1e5) + 5;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)

ll power(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

ll N, a[MAX_N]{}, c[MAX_N]{}, q[MAX_N];

int main() {
    string s;
    cin >> s;
    N = s.size();
    REP(i, N) {
        if (s[i] == 'A') a[i + 1]++;
        a[i + 1] += a[i];
        if (s[N - i - 1] == 'C') c[i + 1]++;
        c[i + 1] += c[i];
        if (s[i] == '?') q[i + 1]++;
        q[i + 1] += q[i];
    }
    ll ans = 0;
    FOR(i, 1, N-1) {
        if (s[i] == 'B' || s[i] == '?') {
            ll k = s[i]=='?';
            ans += (a[i])*(c[N-i])%MOD*power(3,q[N]-k)%MOD;
            ans %= MOD;
            ans += (q[i])*(c[N-i])%MOD*power(3,q[N]-1-k)%MOD;
            ans %= MOD;
            ans += (a[i])*(q[N]-q[i+1])%MOD*power(3,q[N]-1-k)%MOD;
            ans %= MOD;
            ans += (q[i])*(q[N]-q[i+1])%MOD*power(3,q[N]-2-k)%MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>

int main(void) {
	int a,b,c,s;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		s=a;
		a=b;
		b=s;
	}if(b>c){
		s=b;
		b=c;
		c=s;
	}if(a>b){
		s=a;
		a=b;
		b=s;
	}
	printf("%d %d %d\n",a,b,c);
	return 0; 
}


Measured memory_bytes: 2056
#include <cstdio>
#include <algorithm>

using namespace std;

struct war
{
    int a;
    int b;
};

bool cmp(const war& left, const war& right) {
    return left.b < right.b;
}

int main () {
    int N,M,a,b,sum=0,bridge=-1,i;
    scanf("%d %d",&N,&M);
    war wars[M];
    for (i=0; i<M; i++) {
        scanf("%d %d",&a,&b);
        wars[i] = war{a,b};
    }
    sort(wars,wars+M,cmp);
    for (i=0; i<M; i++) {
        if (wars[i].a > bridge) {
            bridge = wars[i].b-1;
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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


int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    vector<int> A(3);
    int K;

    cin >> A[0] >> A[1] >> A[2] >> K;
    sort(A.begin(), A.end());

    int pow2K = 1;
    for(int i = 0; i < K; i++){
        pow2K *= 2;
    }

    cout << A[0] + A[1] + A[2] * pow2K << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;

 
int main() {


  long long a;
  long double b;
  cin >> a >> b;
  int c = round(b*100);
  long long d = a*c;
  cout << d/100 << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a;
  int c = 0;
  for(int i = 0; i< N; i++){
    int b;
    cin >> b;
    a.push_back(b);
    if(a[i] == a[i - 1] && i > 0){
      a[i] = -1;
      c++;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 384
#include <iomanip>
#include <iostream>

#define ll long long

using namespace std;

const int N = 2e5 + 10;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    double l;
    cin >> l;
    double k = l / 3.0;
    k = k * k * k;
    cout << setprecision(10) << k;
    return 0;
}


Measured memory_bytes: 256
void main() {
	auto ip = readAs!(int[]), N = ip[0], M = ip[1];
	auto cnt = new ulong[](N);
	foreach(i; 0..M) {
		auto ip2 = readAs!(int[]), a = ip2[0], b = ip2[1];
		a--; b--;
		cnt[a]++; cnt[b]++;
	}
	if(cnt.all!(v => v % 2 == 0)) writeln("YES");
	else writeln("NO");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 1e9 + 7;
long long n, m, v[N], w[N], dp[N];
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> w[i] >> v[i];
    for (int i = 1; i <= n; ++i)
        for (int j = m; j >= w[i]; --j)
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
    cout << dp[m];
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    ASC(A);
    cout << A[A.size()-1] - A[0] << "\n";
}


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

using namespace std;

int A,B,Q;
typedef long long ll;
const ll MAX_id2 = 100000000000;
const int MAX_id = 100000000;
ll s[MAX_id],t[MAX_id],x[MAX_id];

ll solve(int i){
  ll* p=lower_bound(s,s+A,x[i]);
  ll* q=lower_bound(t,t+B,x[i]);
  ll a1,a2,b1,b2;
  if(s[A-1]>x[i]&&s[0]<x[i]){
  a1 = s[p-s]-x[i];
 
  a2 = x[i]-s[p-s-1];

  }else if(s[A-1]<=x[i]){
    a1 = MAX_id2;
    a2 = x[i]-s[A-1];
    }else{
      a1 = s[0]-x[i];
      a2 = MAX_id2;
    }
  if(t[B-1]>x[i]&&t[0]<x[i]){
  b1 = t[q-t]-x[i];
 
  b2 = x[i]-t[q-t-1];
 
  }else if(t[B-1]<=x[i]){
    b1=MAX_id2;
    b2=x[i]-t[B-1];
  }else{
    b1=t[0]-x[i];
    b2=MAX_id2;
  }
 
  ll ss = max(a1,b1);
  ll ss2 = max(a2,b2);
  ll ss3 = a1+b2+min(a1,b2);
  ll ss4 = a2+b1+min(a2,b1);
 
  return min(min(min(ss,ss2),ss3),ss4);

}

int main(){
  cin >> A >> B >> Q;
  for (int i=0;i<A;i++){
    cin >> s[i];
  }
  for (int i=0;i<B;i++){
    cin >> t[i];
  }
  for (int i=0;i<Q;i++){
    cin >> x[i];
  }
  for (int i=0;i<Q;i++){
    cout << solve(i) << endl;
  }

}


Measured memory_bytes: 8192
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, dp[4][N];
	cin >> n;
	for (int i=1; i<=3; i++) {
        dp[i][0] = 0;
	}
	for (int i=1; i<=n; i++)
    {
        int x1, x2, x3;
        cin >> x1 >> x2 >> x3;
        dp[1][i] = max(dp[2][i-1], dp[3][i-1]) + x1;
        dp[2][i] = max(dp[1][i-1], dp[3][i-1]) + x2;
        dp[3][i] = max(dp[2][i-1], dp[1][i-1]) + x3;
    }
    cout << max (max(dp[1][n], dp[2][n]), dp[3][n]);
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(){
  int D, T, S;
 
  scanf("%d %d %d", &D, &T, &S);
  
  if(D <= S * T){
  	printf("Yes\n");
  }
  
  else{
  	printf("No\n");
  }
  
  return 0;
  
}

Measured memory_bytes: 1648
#include <iostream>
#include <cstdio>
#include <algorithm>
#define F first
#define S second
#define N 200005
using namespace std;

int n, s;
pair<int, int> a[N];
int main()
{
	int i, j;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%d %d", &a[i].S, &a[i].F);
	}
	sort(a, a + n);
	for (i = 0; i < n; i++) {
		if (s + a[i].S > a[i].F) break;
		s +=a[i].S;
	}
	if (i == n) cout << "Yes";
	else cout << "No";
    return 0;
}


Measured memory_bytes: 1792
from collections import Counter as C
N = int(input())
A = sorted(list(C([int(a) for a in input().split()]).values()))
X = [0] * 303030
for a in A:
    X[a] += 1

s = 0
c = 0
B = [0] * 303030
for i in range(300030)[::-1]:
    s += c
    B[i] += s
    c += X[i]

def chk(k, a):
    if N - B[a] >= k * a: return 1
    return 0

for i in range(1, N+1):
    l, r = 0, N + 1
    while r-l > 1:
        m = (l+r) // 2
        if chk(i, m):
            l = m
        else:
            r = m
    print(l)

Measured memory_bytes: 120476
package main

import (
	// "bufio"
	"fmt"
	// "os"
)

func main() {

	//答えの変数
	cnt := 0

	var s, t string

	// スキャナーの生成
	// scanner := bufio.NewScanner(os.Stdin)

	fmt.Scan(&s, &t)
	// // Sの取得
	// scanner.Scan()
	// s = scanner.Text()

	// // Tの取得
	// scanner.Scan()
	// t = scanner.Text()

	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			cnt++
		}
	}
	fmt.Println(cnt)
}


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

int n;
int a[2010];
long long b, c;
long long k;
long long ans = 0;

int mod = 1000000007;

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

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            b = 0;
            c = 0;
            if (a[i] > a[j]) {
                if (i > j) b++;
                if (i < j) c++;
            }
            ans += (k*(k - 1)*(c + b))/2 + k*c;
            ans %= mod;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
	run();
	int n;
	cin >> n;
	set<string> st;
	while (n--) {
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << sz(st) << endl;
}


Measured memory_bytes: 19248
#include<bits/stdc++.h>
using namespace std;
int main()
{
      ios_base::sync_with_stdio(false);
      long long int n,k,a,c,m,i,j=0,p,q;
      cin>>n;
      long long int ara[n]={};
      for(i=0;i<n-1;i++){
            cin>>a;
            ara[a-1]++;
      }
      for(i=0;i<n;i++){
            cout<<ara[i]<<endl;
      }
      return 0;
}

Measured memory_bytes: 5208
import itertools
n,c = map(int,input().split())
D = []
for i in range(c):
    L = list(map(int,input().split()))
    D.append(L)
G = []
for i in range(n):
    P = list(map(int,input().split()))
    G.append(P)
mod3_0 = [0]*c
mod3_1 = [0]*c
mod3_2 = [0]*c
for i in range(n):
    for j in range(n):
        if (i+j+2)%3 == 0:
            mod3_0[G[i][j]-1] += 1
        elif (i+j+2)%3 == 1:
            mod3_1[G[i][j]-1] += 1
        else:
            mod3_2[G[i][j]-1] += 1
t = []
for i in range(c):
    t.append(i)
T = list(itertools.permutations(t,3))
ans = float('inf')
for i in range(len(T)):
    cur = 0
    for j in range(c):
        cur +=  mod3_0[j]*(D[j][T[i][0]])
    for k in range(c):
        cur +=  mod3_1[k]*(D[k][T[i][1]])
    for l in range(c):
        cur +=  mod3_2[l]*(D[l][T[i][2]])
    if ans >= cur:
        ans = cur
print(ans)

Measured memory_bytes: 47068
#include <iostream>
#include <complex>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>

using namespace std;

template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}

typedef complex<double> P;
#define X real()
#define Y imag()

double dot(P a, P b){
    return (a * conj(b)).X;
}

double cross(P a, P b){
    return (a * conj(b)).Y;
}

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    string r = new char[3]{toupper(s1.at(0)) , toupper(s2.at(0)) , toupper(s3.at(0))};
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
n,d = [int(i) for i in input().split()]
a=[]
ctr=0
for i in range(n):
  c= [int(i) for i in input().split()]
  a.append(c)
#print(a)
for i in range(n-1):
  for j in range(i+1,n):
    ans=0
    for k in range(d):
     # print(i,j,d)
      ans+=pow(a[i][k]-a[j][k],2)
    ans = pow(ans,0.5)
    if(ans - int(ans) < 0.000001):ctr+=1
print(ctr)
      

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int fin(vector<int> &f,int v){
  if(f.at(v)==f.size())
    return v;
  f.at(v)=fin(f,f.at(v));
  return f.at(v);
}
void uni(vector<int> &f,vector<int> &h,int x,int y){
  if(h.at(x)>h.at(y)){
    uni(f,h,y,x);
    return;
  }
  if(x==y)
    return;
  f.at(x)=y;
  h.at(y)=max(h.at(x)+1,h.at(y));
  return;
}
int main(){
  int n,q;
  cin>>n>>q;
  vector<int> f(n,n);
  vector<int> h(n,0);
  for(int _=0;_<q;_++){
    int t,u,v;
    cin>>t>>u>>v;
    int x=fin(f,u);
    int y=fin(f,v);
    if(t==0)
      uni(f,h,x,y);
    if(t==1)
      cout<<(x==y)<<endl;
  }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if(abs(x-a) < abs(x-b))
    cout << "A" << endl;
  else
    cout << "B" << endl;
}

Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline
from operator import itemgetter

def readlines(n):
    for _ in range(n):
        b, c = map(int, input().split())
        yield b, c

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    change = []
    for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):
        change += [c] * b
        if len(change) > N:
            break

    A += change
    A.sort()
    answer = sum(A[-N:])
    print(answer)

main()

Measured memory_bytes: 23672
a = ord('a')
z = ord('z')
S = input()

ans = 'WA'
if S[0] == 'A':
    if S[2:-1].count('C') == 1:
        for i, c in enumerate(S):
            if i == 0 or c == 'C':
                continue
            else:
                if a <= ord(c) <= z:
                    continue
                else:
                    break
        else:
            ans = 'AC'

print(ans)


Measured memory_bytes: 38820
#!/usr/bin/env python3
n = int(input())
s = input()
s = [int(i) for i in s]
c = 0
for i in range(10):
    for j in range(10):
        if i in s:
            t = s[s.index(i) + 1:]
            if j in t:
                c += len(set(t[t.index(j) + 1:]))
print(c)


Measured memory_bytes: 9864
#include<stdio.h>
#include<algorithm>
#include<stack>
#include<time.h>
#include<deque>
using namespace std;
long long c[32];
long long d[32];
int pow3[17];
pair<long long,long long>e[14444444];
pair<long long,long long>f[14444444];
int main(){
	int a;
	long long b;
	scanf("%d%lld",&a,&b);
	for(int i=0;i<a;i++)scanf("%lld%lld",c+i,d+i);
	int L=a/2;
	int R=a-L;
	pow3[0]=1;
	srand(time(NULL));
	for(int i=1;i<17;i++)pow3[i]=pow3[i-1]*3;
	for(int i=0;i<pow3[L];i++){
		for(int j=0;j<L;j++){
			int t=i%pow3[j+1]/pow3[j];
			if(t==1){e[i].first+=c[j];e[i].second+=d[j];}
			if(t==2){e[i].first-=c[j];e[i].second-=d[j];}
		}
	}
	std::sort(e,e+pow3[L]);
	long long ret=-999999999999999999LL;
	for(int i=0;i<pow3[R];i++){
		long long h=0;
		long long w=0;
		for(int j=0;j<R;j++){
			int t=i%pow3[j+1]/pow3[j];
			if(t==1){h+=c[L+j];w+=d[L+j];}
			if(t==2){h-=c[L+j];w-=d[L+j];}
		}
		f[i]=make_pair(-h,w);
	}
	std::sort(f,f+pow3[R]);
	for(int i=0;i<pow3[R];i++)f[i].first=-f[i].first;
	deque<long long>Q;
	int right=0;
	int left=0;
	for(int i=0;i<pow3[R];i++){
		while(right<pow3[L]&&e[right].first<=b-f[i].first){
			while(Q.size()&&e[right].second>=e[Q.back()].second){
				Q.pop_back();
			}
			Q.push_back(right);
			right++;
		}
		while(Q.size()&&left<pow3[L]&&e[left].first<-b-f[i].first){
			if(Q.front()==left)Q.pop_front();
			left++;
		}
		if(Q.size())ret=max(ret,e[Q.front()].second+f[i].second);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 452440
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
 
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
using namespace std;

string s;

int main() {
	cin >> s;
	int f = 0;
	for(int i = 0; i < s.length(); i++){
	    if(f == 0){
	        if(s[i] == 'C') f = 1;
	    }
	    else{
	        if(s[i] == 'F'){
	            f = 2;
	            break;
	        }
	    }
	}
	if(f == 2)  cout << "Yes\n";
	else{
	    cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int[][] m = new int[a[0]][a[1]];
        for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        print2DArray(m);
    }

    private static void print2DArray(int[][] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        }
        int allsum = 0;
        for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        }
        sb.append(" ").append(allsum);
        System.out.println(sb);
    }
}

Measured memory_bytes: 40348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans=0;
    for(int i=0; i<1000; i++){
        vector<int>c ={i/100, (i/10)%10, i%10};
        int f=0;
        
        rep(j,n){
            if(s[j] == '0'+c[f])f++;
            if(f ==3) break;
        }
        if(f ==3) ans++;
    }
    cout << ans << endl;
    return 0;
}
    

Measured memory_bytes: 256
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), n=N;
		double K = sc.nextDouble(), t=0;
		Map<Double, Double> m = new HashMap<Double, Double>();
		Queue<Double> minQueue = new PriorityQueue<Double>();
		while (n-->0) {
			double b = sc.nextDouble(), c = sc.nextDouble();
			if (!m.containsKey(b)) minQueue.add(b);
			m.put(b,m.get(b)==null ? c : m.get(b)+c);
		}
		while (!minQueue.isEmpty()) {
			double k = minQueue.poll();
			if (t==K||t+m.get(k)>=K) {
				System.out.println((int)k); System.exit(0);				
			}
			t+=m.get(k);
		}
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}


Measured memory_bytes: 70980
#pragma once
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

string S;
char now;
int result=0;


int main(){

	cin >> S;
	char now =S[0];

	for(int i=1;i<S.size();i++){
		if(S[i]!=now){
			result++;
			now=S[i];
		}
	}

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

return 0;
}



Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

struct attack{
public:
  int damage;
  bool lose;
};

bool operator<(const attack& left, const attack& right){
  return left.damage < right.damage;
}

int main(){
  long n,h;
  cin >> n >> h;
  vector<attack> v;
  for(int i = 0; i < n; i++){
    int ai, bi;
    cin >> ai >> bi;
    attack a;
    a.damage = ai;
    a.lose = false;
    v.push_back(a);
    a.damage = bi;
    a.lose = true;
    v.push_back(a);
  }
  sort(v.begin(),v.end());
  long hp = h;
  long ans = 0;
  while(h>0){
    attack a = v.back();
    h -= a.damage;
    ans++;
    if(a.lose == true){
      v.pop_back();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
a, b, c, d = list(map(int, list(input())))

ops = {'+', '-'}

for op1 in ops:
    if op1 == '+': ab = a+b
    else: ab = a-b
    
    for op2 in ops:
        if op2 == '+': abc = ab+c
        else: abc = ab-c
        
        for op3 in ops:
            if op3 == '+': abcd = abc+d
            else: abcd = abc-d

            if abcd == 7:
                a, b, c, d = map(str, [a, b, c, d])
                print(a+op1+b+op2+c+op3+d+'=7')
                exit()

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>
#include<map>

#define foreach(it, c) for(__typeof__((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;

typedef unsigned int uint;
typedef pair<int, uint> P;

uint encode(vector<int> vec){
    uint res=0;
    for (int i=0;i<vec.size();i++)
        res=(res<<4)+vec[i];
 
    return res;
}
 
vector<int> decode(uint a){
    vector<int> res;
    for (;a>0;a>>=4)res.push_back(a & 15);
	reverse(res.begin(),res.end());
	
    return res;
}
 
struct edge{uint to, cost; };
 
int V;
int c[10][10],ans;
map<uint,int>d;
 
void dijkstra(uint s){
  priority_queue<P, vector<P>, greater<P> >que;
  d[s] = 0;
  que.push(P(0, s));
 
  while(!que.empty()){
 
    P p = que.top();
    que.pop();
    uint v = p.second;
    if(d[v] < p.first)continue;

    vector<int>tmp=decode(v);
  
    for(int i=0;i<V;i++){
      for(int j=i+1;j<V;j++){
			edge e;
			e.cost=c[tmp[i]][tmp[j]];
			swap(tmp[i],tmp[j]);
			e.to=encode(tmp);
 
      	if(!d.count(e.to) || d[e.to] > d[v]+e.cost){
      		d[e.to] = d[v]+e.cost;
      		que.push(P(d[e.to], e.to));
    	}
    	swap(tmp[i],tmp[j]);
      }
    }
  }
}
 
 
int main(void){
 
  cin >> V;
 
  for(int i=1;i<=V;i++){
    for(int j=1;j<=V;j++){
      cin >> c[i][j];
    } 
  }
	
  vector<int>v;
  for(int i=1;i<=V;i++)v.push_back(i);
 
  uint s=encode(v);
 
  dijkstra(s);
 
  ans=0;
  foreach(i,d)ans=max(ans,i->second);
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 3416
n, k = map(int,input().split())
a = list(map(int,input().split()))


def d(x):
    l = []
    for i in range(1, int(x**0.5)+1):
        if x%i==0:
            l.append(i)
            if i != x//i:
                l.append(x//i)
    l.sort(reverse=True)
    return l

s = d(sum(a))
for i in s:
    x = [0 for k in range(n)]
    for j in range(len(a)):
        x[j] = a[j] % i
    x.sort()
    l = [0 for k in range(n+1)]
    r = [0 for k in range(n+1)]
    for j in range(n+1):
        if j == 0:
            l[0] = 0
            r[n-0] = 0
        else:
            l[j] = l[j-1] + x[j-1]
            r[n-j] = r[n-j+1] + (i-x[n-j])
    ans = 1
    for j in range(n+1):
        if l[j] == r[j] and l[j] <= k:
            ans = i
            print(ans)
            exit()


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

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

const long long mod = 1e9 + 7;

vector<int> vx = {1, -1, 0, 0};
vector<int> vy = {0, 0, 1, -1};


int main() {
    

    
    ll h, w;
    
    cin >> h >> w;
    
    vector<string> s(h);
    for (int i = 0; i < h; ++i)
    {
        cin >> s[i];
    }
    
    ll maxv = 0;
    
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            ll tmp = 0;
            P startpos = make_pair(i, j);
            queue<pair<P, ll>> q;
            vector<vector<ll>> tmpv(h, vector<ll>(w, mod));
            if (s[i][j] != '#')
            {
                q.push(make_pair(startpos, 0));
                tmpv[i][j] = 0;
            }
            while (q.size() > 0)
            {
                P curpos = q.front().first;
                ll curv = q.front().second;
                q.pop();
                for (int k = 0; k < 4; ++k)
                {
                    ll nextx = curpos.second + vx[k];
                    ll nexty = curpos.first + vy[k];
                    if (nexty < h && nexty >= 0 && nextx < w && nextx >= 0 && s[nexty][nextx] != '#' && tmpv[nexty][nextx] == mod)
                    {
                        tmpv[nexty][nextx] = curv + 1;
                        q.push(make_pair(P(nexty, nextx), curv + 1));
                    }
                }
            }
            
            for (int k = 0; k < h; ++k)
            {
                for (int l = 0; l < w; ++l)
                {
                    if (tmpv[k][l] != mod)
                    {
                        maxv = max(maxv, tmpv[k][l]);
                    }
                }
            }
        }
    }
    
    cout << maxv << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    long long int ans=0;
    string s;
    cin>>s;
    //文字列変換
    queue<int> q;
    char last;
    int cnt=0;
    for(int i=0;i<s.size();i++){
        if(i==0){last=s[0];cnt=1;}
        else{
            if(s[i]==last){cnt++;}
            else{
                q.push(cnt);
                cnt=1;
            }
            last=s[i];
        }
    }
    q.push(cnt);
    long long int n=0;
    long long int n2=0;
    if(s[0]=='>'){
        n=q.front();
        q.pop();
        ans=ans+n*(n+1)/2;
    }
    while(!q.empty()){
        n=q.front();
        q.pop();
        if(q.empty()){
            ans=ans+n*(n+1)/2;
        }
        else{
            n2=q.front();
            q.pop();
            if(n<n2){
                ans=ans+n*(n-1)/2+n2*(n2+1)/2;
            }
            else{
                ans=ans+n*(n+1)/2+n2*(n2-1)/2;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main (){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <array>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define uinf 0x3f3f3f3f3f3f3f3f
#define CLEAR(a) a = decltype(a)()
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define pii pair<int ,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define pi 2*acos(0.0)
#define INFILE() freopen("in.txt","r",stdin)
#define OUTFILE() freopen("out.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FIN std::ifstream cin("D:\input.txt")
const int MOD = 1e9 + 7;

// x^n % mod
// O(log n)
template<typename T>
T mod_pow(T x, T n, T mod) {
	T res = 1;
	while (n > 0) {
		if (n & 1) res = res * x & mod;
		x = x*x %mod;
		n >>= 1;
	}
	return res;
}

// fact(n)%MOD, invFact(n)%MOD, inv(n)%MOD, nCk
// Constructor O(N)
// other O(1)
template<typename T, int MOD>
class Choose {
public:
	vector<T> fact, inv, invFact;

	Choose(T N):fact(N), inv(N), invFact(N){
		inv[1] = 1;
		FOR(i, 2, inv.size()) inv[i] = MOD - (MOD / i) * inv[MOD%i] % MOD;
		fact[0] = invFact[0] = 1;
		FOR(i, 1, fact.size()) {
			fact[i] = fact[i - 1] * i % MOD;
			invFact[i] = (invFact[i - 1] * inv[i]) % MOD;
		}
	}

	//Get nCk
	T operator () (T n, T k) const {
		if (not ((T)0 <= k and k <= n)) return 0;
		return (((fact[n] * invFact[k]) % MOD)*invFact[n - k]) % MOD;
	}
};

ll f(ll x , ll y, const Choose<ll, MOD>& c) {
	return c(x + y, x);
}

signed int main(void) {
	ll H, W, A, B; cin >> H >> W >> A >> B;
	Choose<ll, MOD> c(H + W);

	ll ans = 0;
	FOR(i, B, W + 1) {
		ans += f(H - A - 1, i, c) * f(A - 1, W - 1 - i, c);
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4992
<?php
  $inputs = array_map(
    function($v) {return (int)$v;},
    explode(' ', trim(fgets(STDIN)))
  );

  $a = $inputs[0];
  $b = $inputs[1];
  $m = $inputs[2];

  $freezerList = array_map(function($v) {return (int)$v;}, explode(' ', trim(fgets(STDIN))));
  $microWaveList = array_map(function($v) {return (int)$v;}, explode(' ', trim(fgets(STDIN))));

  $ans = min($freezerList) + min($microWaveList);
  for($i = 0; $i < $m; $i += 1) {
    $coupon = array_map(function($v) {return (int)$v;}, explode(' ', trim(fgets(STDIN))));
    $currentCost = $freezerList[$coupon[0] - 1] + $microWaveList[$coupon[1] - 1] - $coupon[2];
    $ans = min($ans, $currentCost);
  }

  printf("%s\n", $ans);
?>

Measured memory_bytes: 20976
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
                int a,b;
        a=sc.nextInt();
        b=sc.nextInt();
        System.out.println(a*b+" "+(a+b)*2);
        
        
        
        
        
    }
    
    
}


Measured memory_bytes: 25984
#include<iostream>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<math.h>
using namespace std;

class UnionFind{
    vector<int> p;
    vector<int> s;
    public:
        UnionFind( int size ) : p( size, -1 ), s( size, 1 ) {}

    int root( int i )
    {
        if( p[i] == -1 ) return i;
        else return p[i] = root( p[i] );
    }

    bool connect( int a, int b )
    {
        auto root_a = root(a);
        auto root_b = root(b);

        if( root_a == root_b ) return false;

        /* if( size[root_a] > size[root_a] ) */

        p[root_a] = root_b;
        return true;
    }
};

struct Link{
    int a,b;
    int cost;
};

vector<Link> links;

int main()
{
    // get a integer
    int N;
    cin >> N;

    vector<tuple<int,int,int>> a;

    for (auto&& i = 0; i < N; ++i ) {
        int x, y;
        cin >> x >> y;
        a.push_back( tuple<int,int,int>( i, x, y ) );
    }

    sort( &a[0], &a[N], [](auto l, auto r) {
            return std::get<1>(l) < std::get<1>(r);
            } );

    for (auto&& i = 0; i < N-1; ++i ) {
        links.push_back( { get<0>(a[i]), get<0>(a[i+1]), ( get<1>(a[i+1]) - get<1>(a[i]) ) } );
    }

    sort( &a[0], &a[N], [](auto l, auto r) {
            return std::get<2>(l) < std::get<2>(r);
            } );

    for (auto&& i = 0; i < N-1; ++i ) {
        links.push_back( { get<0>(a[i]), get<0>(a[i+1]), ( get<2>(a[i+1]) - get<2>(a[i]) ) } );
    }

    sort( links.begin(), links.end(), [](auto l, auto r) {
            return l.cost < r.cost;
            } );

    /* for (auto itr = links.begin(); itr != links.end(); itr++) { */
    /*     /1* cout << (*itr).a <<"," << (*itr).b << "  " << (*itr).cost << endl; *1/ */
    /* } */

    UnionFind f( N );
    int count = 0;
    int cost = 0;
    for (auto itr = links.begin(); count < N - 1; itr++) {
        if( f.connect( (*itr).a, (*itr).b ) )
        {
            cost += (*itr).cost;
            count++;
        }
        if( itr == links.end() )
            break;
    }

    /* for (auto&& i = 0; i < N; ++i ) { */
    /*     cout << get<0>(a[i]) << "," << get<1>(a[i]) << endl; */
    /* } */

    /* int sum = 0; */
    /* for (auto&& i = 0; i < N-1; ++i ) { */
    /*     int m = min( ( get<0>(a[i+1]) - get<0>(a[i]) ), abs( get<1>(a[i+1]) - get<1>(a[i]) ) ); */
    /*     /1* cout << m << endl; *1/ */
    /*     sum += m; */
    /* } */
    cout << cost << endl;
}



Measured memory_bytes: 6132
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
//		a = insertionSort(a,n);
//		a = selectionSort(a,n);
		a = bubbleSort(a,n);

		in.close();

	}
	int[] bubbleSort(int[] c, int n){
		int count = 0;
		for(int i = 0; i < n-1; i++){
			for(int j = n-1; j >= i+1; j--){
				if(c[j]  < c[j-1]){
					int tmp = c[j];
					c[j] = c[j-1];
					c[j-1] = tmp;
					count++;
				}
			}
		}
		printArray(c);
		System.out.println(count);
		return c;
	}
	int[] insertionSort(int[]a, int n){
		for(int i = 1; i < n; i++){
			printArray(a);
			int v = a[i];
			int j = i - 1;
			while(j >= 0 && a[j] > v){
				a[j+1] = a[j];
				j--;
			}
			a[j+1] = v;
		}
		return a;
	}
	int[] selectionSort(int[] a, int n){
		int count = 0;
		for(int i = 0; i < n; i++){
//			printArray(a);
			int minj = i;
			for(int j = i; j < n;j++){
				if(a[j] < a[minj]) minj = j;
			}
			if(minj != i){
				int tmp = a[i];
				a[i] = a[minj];
				a[minj] = tmp;
				count++;
			}
		}
		printArray(a);
		System.out.println(count);
		return a;
	}
	void printArray(int[] a){
		System.out.print(a[0]);
		for(int i= 1; i < a.length; i++){
			System.out.print(" " + a[i]);
		}
		System.out.println();
	}

}

Measured memory_bytes: 26348
from collections import deque
N, Q = map(int, input().split())
tree = [[] for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  tree[a-1] += [b-1]
  tree[b-1] += [a-1]

ans = [0 for i in range(N)]
for i in range(Q):
  x, p = map(int, input().split())
  ans[x-1] += p
que = deque()
for a in tree[0]:
  que.append([0,a])
used = [1] + [0]*(N-1)
while que:
  u, v = que.pop()
  if used[v] == 0:
    used[v] = 1
    ans[v] += ans[u]
    for a in tree[v]:
      que.append([v,a])

    
print(*ans)

Measured memory_bytes: 66384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


const long double pai=3.14159265358979323;

int main(){
    long double a,b,h,m;
    cin>>a>>b>>h>>m;
    long double dif=h/12+m/720-m/60, ans;
    if(dif<0) dif=-dif;
    dif=min(dif,1-dif);
    ans=a*a+b*b-2*a*b*cos(dif*pai*2);
    ans=sqrt(ans);
    cout<<ketasuu(15)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4136
#include <stdio.h>
#include <string.h>
#include <math.h>

long func(long x, long max){
    if (max < 0){
        return 0;
    }else{
        return max/x+1;
    }
}

int main()
{
    long a,b,x;
    long ans;

  scanf("%ld %ld %ld", &a, &b, &x);

  ans = func(x, b) - func(x, a-1);

  printf("%ld\n", ans);
  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
int k,counter=0;
int main() {
  cin >> k;
  queue<ll> lunlun;
  REP(i,9)lunlun.push((ll)(i+1));
  while(!(k-1==counter)){
    counter++;
    ll x = lunlun.front();
    if(0 != x%10) lunlun.push(x*10+(x%10)-1);
    lunlun.push(x*10+(x%10));
    if(9 != x%10) lunlun.push(x*10+(x%10)+1);
    lunlun.pop();
  }
  cout << lunlun.front() << endl;
  return 0;
}


Measured memory_bytes: 5112
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
#define MAX 100000

static const int N =100;
static const int INFTY =(1<<21);
int n,M[N][N];
int d[N];

void bfs(int s){
  queue<int> q;
  q.push(s);
  for(int i=0;i<n;i++) d[i]=INFTY;
  d[s]=0;
  int u;
  while(!q.empty()){
    u=q.front();
    q.pop();
    for(int v=0;v<n;v++){
      if(d[v]!=INFTY)continue;
      if(M[u][v]==1){
        d[v]=d[u]+1;
        q.push(v);
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << i+1 << " " << ((d[i]==INFTY)? (-1):d[i])<< endl;
  }
}

int main(){
  int u,k,v;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) M[i][j]=0;
  }

  for(int i=0;i<n;i++){
    cin >>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);
  return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
//#define int ll
#define ld double
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 5e5 + 6, MOD = 998244353;

int t[4 * N];
string s;

void build (int v, int l, int r) {
    if (l == r) {
        t[v] = 1 << (s[l] - 'a');
        return;
    }
    int m = l + r >> 1;
    build(2 * v + 1, l, m);
    build(2 * v + 2, m + 1, r);
    t[v] = t[2 * v + 1] | t[2 * v + 2];
}

void change(int v, int l, int r, int pos, int val) {
    if (l == pos && r == pos) {
        t[v] = 1 << val;
        return;
    }
    int m = l + r >> 1;
    if (m >= pos)
        change(2 * v + 1, l, m, pos, val);
    else
        change(2 * v + 2, m + 1, r, pos, val);
    t[v] = t[2 * v + 1] | t[2 * v + 2];
}

int ask(int v, int l, int r, int L, int R) {
    if (l > R || r < L)
        return 0;
    if (l >= L && r <= R) 
        return t[v];
    int m = l + r >> 1;
    return ask(2 * v + 1, l, m, L, R) | ask(2 * v + 2, m + 1, r, L, R);
}

void solve() {
    int n, q;
    cin >> n >> s >> q;
    build(0, 0, n - 1);
    loop(i, q) {
        int e;
        cin >> e;
        if (e == 1) {
            int pos; char c;
            cin >> pos >> c;
            change(0, 0, n - 1, pos - 1, c - 'a');
        }
        else {
            int l, r;
            cin >> l >> r;
            int x = ask(0, 0, n - 1, l - 1, r - 1);
            int ans = 0;
            loop(i, 26)
                ans += bool(x & (1 << i));
            cout << ans << "\n";
        }
    }
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 7068
X, N = map(int, input().split())
p = list(map(int, input().split()))

if N == 0:
    print(X)

elif X not in p:
    print(X)
    
else:
    for i in range(110):
        if (X-(i+1)) in p and (X+i+1) in p:
            continue
    
        else:
            if(X-(i+1)) not in p:
                print(X-(i+1))
                break
    
            elif (X+i+1) not in p:
                print(X+i+1)
                break

Measured memory_bytes: 9068
#include <iostream>
#include <vector>
#include <limits>

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a.at(i);
    }
    ll ans = numeric_limits<ll>::max();
    for(ll b = -100; b <= 100; ++b){
        ll tmp = 0;
        REP(i, n){
            tmp += (a.at(i) - b) * (a.at(i) - b);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
N,M=gets.split.map(&:to_i)
G=Array.new(N+1){[]}
M.times do
  a,b=gets.split.map(&:to_i)
  G[a]<<b
  G[b]<<a
end

post=[]
q=[[0,1]]
until q.empty?
  pre,cur=q.shift
  next if post[cur]
  post[cur]=pre
  G[cur].each do |nex|
    q<<[cur,nex] unless post[nex]
  end
end

puts :Yes
puts post[2..-1]


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

bool inside(int a, int b, int alim, int blim) {
	return 0 <= a && a < alim && 0 <= b && b < blim;
}

int main() {
	int h, w;
	cin >> h >> w;
	string s[h];
	for (auto &i : s) {
		cin >> i;
	}
	string ans[h];
	for (auto &i : ans) {
		i = string(w, '#');
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;
			int count = 0;
			for (int k = -1; k <= 1; k++) {
				for (int l = -1; l <= 1; l++) {
					if (k == 0 && l == 0) continue;
					if (!inside(i + k, j + l, h, w)) continue;
					if (s[i + k][j + l] == '#') count++;
				}
			}
			ans[i][j] = count + '0';
		}
	}
	for (int i = 0; i < h; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

struct Card {
	char mark;
	int number, order;
};

int partition(Card[], int, int);
void quicksort(Card[], int, int);
void swap(Card*, Card*);
bool check(Card[], int);

int main()
{
	Card *cards;
	int n;
	bool flag = 1;
	scanf("%d", &n);
	cards = new Card[n];
	for (int i = 0; i < n; i++)
	{
		scanf(" %c %d", &cards[i].mark, &cards[i].number);
		cards[i].order = i;
	}

	quicksort(cards, 0, n - 1);
	
	if (check(cards, n))
		printf("Stable\n");
	else
		printf("Not stable\n");
	for (int i = 0; i < n; i++)
		printf("%c %d\n", cards[i].mark, cards[i].number);
	delete[] cards;

	return 0;
}

void swap(Card *a, Card *b)
{
	Card tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
	return;
}

int partition(Card cards[], int left, int right)
{
	int i, x;
	x = cards[right].number;
	i = left;
	for (int j = left; j < right; j++)
		if (cards[j].number <= x)
		{
			swap(cards + i, cards + j);
			i++;
		}
	swap(cards + i, cards + right);

	return i;
}

void quicksort(Card cards[], int left, int right)
{
	if (left < right)
	{
		int q;
		q = partition(cards, left, right);
		quicksort(cards, left, q - 1);
		quicksort(cards, q + 1, right);
	}
	return;
}

bool check(Card cards[], int n)
{
	for (int i = 0; i < n - 1; i++)
		if (cards[i].number == cards[i + 1].number && cards[i].order > cards[i + 1].order)
			return false;
	return true;
}


Measured memory_bytes: 3424
#include<bits/stdc++.h>
#define int long long 
#define MOD 1000000007
using namespace std;

int32_t main()
{
  int n;cin>>n;
  string a,b;
  cin>>a>>b;

  int i=0;
  while (i<n){
    cout<<a[i]<<b[i];
    i++;
  }
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
h = na()
d = [[] for i in range(n)]

for i in range(m):
    a,b = na()
    a,b = a-1,b-1
    d[a].append(b)
    d[b].append(a)

ans = 0

for i in range(n):
    for j in d[i]:
        if h[j] >= h[i]:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 29368
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int k;
    cin >> k;
    int res = 1;
    vector<int> v1(1, 1), v2;
    vector<int> visited(k, 0);
    visited[1] = 1;

    while (v1.size() > 0) {
        v2 = v1;
        for (auto node : v1) {
            node = node * 10 % k;
            while (visited[node] == 0) {
                visited[node] = 1;
                v2.push_back(node);
                node = node * 10 % k;
            }
        }
        for (auto node : v2) {
            if (node == 0) {
                cout << res << endl;
                return 0;
            }
            node = (node + 1) % k;
            if (visited[node] == 0) {
                visited[node] = 1;
                v1.push_back(node);
            }
        }
        res++;
    }
    cout << res << endl;
}




Measured memory_bytes: 4584
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Og")
#pragma GCC push_options
#pragma GCC pop_options

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k, n;
    cin >> k >> n;
    int a = 500 * k;
    if (a >= n)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class T> inline std::istream& operator >> (std::istream& is, std::vector<T>& v) { for (T& x : v) { is >> x; }return is; }
	template<class T> inline std::ostream& operator << (std::ostream& os, const std::vector<T>& v) {
		for (auto itr = v.begin(); itr != v.end();) { os << (*itr) << ((++itr != v.end()) ? " " : ""); }
		return os;
	}
	template<class V, typename T>inline void fill(V& v, const T& val) { v = val; }
	template<class V, typename T>inline void fill(std::vector<V>& v, const T& val) { for (V& x : v) { fill(x, val); } }
	template<class V, typename H>inline void resize(std::vector<V>& v, const H h) { v.resize(h); }
	template<class V, typename H, typename... T>inline void resize(std::vector<V>& v, const H& h, const T& ... t) { v.resize(h); for (auto& x : v) { resize(x, t...); } }
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }

	vector<int> demical(ll n, int k, int l = -1) {
		vector<int> rtn;
		if (l < 0) {
			while (n > 0) {
				rtn.push_back(n % k);
				n /= k;
			}
		} else {
			rtn.resize(l);
			REP(i, l) {
				rtn[i] = n % k;
				n /= k;
			}
		}
		return rtn;
	}

	void solve() {
		IOS;
		ll n, m, x;
		cin >> n >> m >> x;
		vector<ll> c(n);
		vector<vector<ll>> a(n,vector<ll>(m));
		REP(i, n) {
			cin >> c[i];
			REP(j, m) {
				cin >> a[i][j];
			}
		}
		ll t = 1 << n;
		ll res = LLONG_MAX;
		REP(i, t) {
			auto d = demical(i, 2, n);
			vector<ll> cnt(m, 0);
			REP(j, n) {
				if (d[j]) {
					REP(k, m) {
						cnt[k] += a[j][k];
					}
				}
			}
			bool flag = true;
			REP(j, m) {
				if (cnt[j] < x) {
					flag = false;
				}
			}
			if (flag) {
				ll tmp = 0;
				REP(j, n) {
					if (d[j]) {
						tmp += c[j];
					}
				}
				chmin(res, tmp);
			}
		}
		if (res == LLONG_MAX) {
			put(-1);
		} else {
			put(res);
		}
	}
} // namespace idaten


int main() {
	idaten::solve();
	return 0;
}


Measured memory_bytes: 3664