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

#define fi first
#define se second
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 5e5 + 5;
int n,a[MAXN];

int st[MAXN],tp;
LL pre[MAXN],suf[MAXN],sm[MAXN],t[MAXN];
#define X(i) (i)
#define Y(i) (t[i]+sm[i]+(1ll*i*i-i)/2.0)

inline double slope(int x,int y){ // x-y
	return (Y(x)-Y(y))/(X(x)-X(y));
}

inline void dp(){
	FOR(i,1,n) sm[i] = sm[i-1]+a[i];st[tp = 1] = 0;
	FOR(i,1,n){
		while(tp > 1 && slope(st[tp-1],st[tp]) <= i) tp--;
		int j = st[tp];
		// if(i == 2) DEBUG(j),DEBUG(t[j]+(i-j)*(i-j+1)/2-sm[i]+sm[j]);
		t[i] = std::max(t[i-1],t[j]+1ll*(i-j)*(i-j+1)/2-sm[i]+sm[j]);
		while(tp > 1 && slope(st[tp-1],st[tp]) < slope(st[tp],i)) tp--;
		st[++tp] = i;
	}
}

LL f[MAXN],ans[MAXN],tmp[MAXN];

inline void cdq(int l,int r){
	if(l == r){
		f[l] = std::max(f[l],pre[l-1]+suf[r+1]+1-a[l]);
		return;
	}
	int mid = (l + r) >> 1;
	st[tp = 1] = l-1;
	FOR(i,l,mid-1){
		while(tp > 1 && slope(st[tp-1],st[tp]) < slope(st[tp],i)) tp--;
		st[++tp] = i;
	}
	FOR(i,mid,r){
		while(tp > 1 && slope(st[tp-1],st[tp]) <= i) tp--;
		int j = st[tp];
		tmp[i] = t[j]+1ll*(i-j)*(i-j+1)/2-sm[i]+sm[j]+suf[i+1];
	}
	ROF(i,r-1,mid) tmp[i] = std::max(tmp[i+1],tmp[i]);
	FOR(i,mid,r) f[i] = std::max(f[i],tmp[i]);
	cdq(l,mid);cdq(mid+1,r);
}

int main(){
	scanf("%d",&n);
	FOR(i,1,n) scanf("%d",a+i);
	dp();FOR(i,1,n) pre[i] = t[i],t[i] = 0;
	std::reverse(a+1,a+n+1);dp();std::reverse(t+1,t+n+1);std::reverse(a+1,a+n+1);
	FOR(i,1,n) suf[i] = t[i],t[i] = 0,ans[i] = -1e18;

	FOR(i,1,n) t[i] = pre[i],sm[i] = sm[i-1]+a[i],f[i] = -1e18;cdq(1,n);
	FOR(i,1,n) ans[i] = std::max(ans[i],f[i]);

	std::reverse(a+1,a+n+1);std::reverse(pre+1,pre+n+1);std::reverse(suf+1,suf+n+1);
	std::swap(pre,suf);
	FOR(i,1,n) t[i] = pre[i],sm[i] = sm[i-1]+a[i],f[i] = -1e18;cdq(1,n);
	std::reverse(f+1,f+n+1);
	FOR(i,1,n) ans[i] = std::max(ans[i],f[i]);
	std::reverse(a+1,a+n+1);std::reverse(pre+1,pre+n+1);std::reverse(suf+1,suf+n+1);
	std::swap(pre,suf);

	// FOR(i,1,n) DEBUG(ans[i]);

	int q;scanf("%d",&q);
	while(q--){
		int x,y;scanf("%d%d",&x,&y);
		printf("%lld\n",std::max(pre[x-1]+suf[x+1],ans[x]+a[x]-y));
	}
	return 0;
}

Measured memory_bytes: 24560
# -*- coding: utf-8 -*-
# map(int, input().split())

N, D = map(int, input().split())
X = []
Y = []

for i in range(N):
  x,y = map(int, input().split())
  X.append(x)
  Y.append(y)

score = 0
for i in range(N):
  if pow(X[i], 2)+pow(Y[i], 2) <= pow(D, 2):
    score += 1

print(score)

Measured memory_bytes: 96652
check :: String -> Bool
check s = reverse s == s

main = do
   s <- getLine
   let n = length s
   let ss = take ((n-1)`div`2) s
   let sss = drop ((n+3)`div`2-1) s
   if check s && check ss && check sss
      then putStrLn "Yes"
      else putStrLn "No"

Measured memory_bytes: 508
/*
 *
 *  1. sprawdz corner cases
 *  2. sprawdz limity, jesli sie da pozamieniaj wszystkie lokalne zmienne na LL!
 *  3.  MINIMALNE I MAKSYMALNE WEJŚCIE I WYJŚCIE
 *  4. lokalne zmienne, iteracja po tablicach dwuwymiarowych uwazaj
 *  5. SPRAWDZ CZY input jest POSORTOWANY jaki jest niezmiennik
 *
 *
 */
#include <algorithm>
#include <cstdio>
#include <iomanip> // std::setprecision
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>
#include <numeric>
#define FOR(x, y, z) for (int x = (y); x < (z); x++)
#define FORD(x, y, z) for (int x = (y); x >= z; x--)
#define REP(r, n) for (int r = 0; r < (n); r++)
#define MP make_pair
#define ST first
#define ND second
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i, x) for (__typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define ALL(u) (u).begin(), (u).end()
#define RALL(u) (u).rbegin(), (u).rend()
#define PB push_back
#define PF push_front
#define SZ(x) long long((x).size())
#define IS_IN(x, t) (t.find(x) != t.end())
#define BIT(n, i) (((n) >> (i)) & 1)

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) \
    {              \
    }
#endif

#define TYPEMAX(type) std::numeric_limits<type>::max()
#define TYPEMIN(type) std::numeric_limits<type>::min()

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<LL> VI;
typedef pair<LL, LL> PR;

inline LL GCD(LL a, LL b)
{
    LL r;
    while (b) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
};
inline LL LCM(LL a, LL b) { return a / GCD(a, b) * b; };
inline LL fpow(LL n, LL k, LL p)
{
    LL r = 1;
    for (; k; k >>= 1) {
        if (k & 1)
            r = r * n % p;
        n = n * n % p;
    }
    return r;
};
inline LL inv(LL a, LL p) { return fpow(a, p - 2, p); }

[[maybe_unused]] const LL MOD = (LL)1e9 + 7;
[[maybe_unused]] const LL MAXUS = TYPEMAX(LL);
[[maybe_unused]] const LD PI = acos((LD)-1);
[[maybe_unused]] const LD epsilon = 1e-9;

template <typename T>
T input()
{
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e)
{
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

int main()                       
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    LL n = input<LL>();
    LL l = input<LL>();
    vector<string> inp(n);
    REP(i,n) {
      cin >> inp[i];
    }
    sort(inp.begin(), inp.end());
    REP(i,n) cout << inp[i];
    cout << endl;
    return 0;
}


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

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;

    bool ok = true;
    for (size_t i = (a-1); i < (c-1); i++)
    {
        if (s[i] == '#' && s[i+1] == '#') {
            ok = false;
        }
    }
    for (size_t i = (b-1); i < (d-1); i++)
    {
        if (s[i] == '#' && s[i+1] == '#') {
            ok = false;
        }
    }

    if (c > d) {
        bool snuke = false;
        for (size_t i = (b-2); i < (d-1); i++)
        {
            if (s.substr(i, 3) == "...") {
                snuke = true;
            }
        }
        cout << (snuke && ok ? "Yes" : "No") << endl;
    } else {
        cout << (ok ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
int main()
{
	ll N;
	cin >> N;

	vector<ll> P(N);
	priority_queue<pair<int, int>> pq;
	rep(i, N) {
		cin >> P[i];
		pq.push({ P[i],i });
	}

	ll res = 0;
	set<ll> st;
	st.insert(-1); // bannhei
	st.insert(N);  // bannhei
	while (!pq.empty()) {
		ll num, idx;
		tie(num, idx) = pq.top(); pq.pop();

		auto itr_right = st.lower_bound(idx);
		ll right = *itr_right;
		itr_right++;
		ll right_after = itr_right == st.end() ? N : *itr_right;

		auto itr_left = st.lower_bound(idx);
		itr_left--;
		ll left = *itr_left;
		ll left_before = (itr_left == st.begin() ? -1 : *(--itr_left));

		ll right_contain_kind = (right_after - right)*(idx - left);
		ll left_contain_klnd = (left - left_before)*(right - idx);
		ll kind = left_contain_klnd + right_contain_kind;
		ll now_res = num * kind;
		res += now_res;
		st.insert(idx);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 6516
void main() {
	auto N = ri;
	dchar last;
	auto m = redBlackTree!string;
	foreach(i; 0..N) {
		auto S = rs;
		if(i==0) {
			m.insert(S);
			last = S.back;
			continue;
		}
		if(last == S[0]) {
			last = S.back;
		} else {
			writeln("No");
			return;
		}
		auto a = m.insert(S);
		if(a == 0) {
			writeln("No");
			return;
		}
	}
	//m.writeln;
	writeln("Yes");
}

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

import std.stdio;
import std.string;
import std.functional;
import std.conv;
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: 256
#include <bits/stdc++.h>
using namespace std;

int main()
{
  string a, b, c;
  cin >> a >> b >> c;
  int aend = a.size() - 1, bend = b.size() - 1;
  if(a[aend] == b[0] && b[bend] == c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = a*b;

        if (c%2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");
    }
}


Measured memory_bytes: 35620
import sys
input = lambda: sys.stdin.readline().rstrip()
m=2**150-1
n=int(input())
ss=[input()[::-1]for _ in range(n)]
ss.sort(key=len)
d={}
ans=0
for s in ss:
  a=ord(s[-1])-97
  r=1
  h=0
  y=[0]*26
  for t in s[:-1]:
    b=ord(t)-97
    if h in d:
      for i in range(26):y[i]+=d[h][i]
    ans+=y[b]
    y[b]=0
    h=(h*71+b+135)&m
  ans+=y[a]
  if h not in d:d[h]=[0]*26
  d[h][a]+=1
print(ans)

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

using namespace std;

int main(){
	double d, t, s;
	scanf("%lf %lf %lf", &d, &t, &s);
	if(d/s<=t){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<int> p(n);
	rep(i, 0, n - 1)cin >> p[i];
	int cnt = 0;
	rep(i, 0, n - 3)
	{
		int a = p[i + 1] - p[i];
		int b = p[i + 1] - p[i + 2];
		if (a*b < 0)++cnt;
	}
	cout << cnt << endl;
}

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

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int N, M, A, B;
	scanf("%d %d %d %d", &N, &M, &A, &B);
	for(int i = 1; i <= N; i++) {
		for(int j = 1; j <= M; j++)
			if((i <= B && j <= A) || (i > B && j > A))
				putchar('1');
			else putchar('0');
		putchar('\n');
	}
	return 0;
}

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

int n;
string s;

int main(){
	cin>>n>>s;
	
	for(int i=0,x;i<s.size();i++){
		if(s[i]-'A'+n<='Z'-'A'){
		    s[i] = (s[i]-'A'+n)+'A';
		}else {
		    s[i] = 'A'+n-('Z'-s[i])-1;
		}
	}
	cout<<s<<'\n';
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main()
{
	int x, y;
	cin >> x >> y;
	if ((x == 4 || x == 6 || x == 9 || x == 11 )&& (y == 4 || y == 6 || y == 9 || y == 11))
		cout << "Yes";
	else if (x == 2 && y == 2)
		cout << "Yes";
	else if ((x == 3 || x == 1 || x == 12 || x == 5 || x == 7 || x == 8 ||x==10)&&( y == 3 || y == 1 || y == 12 || y == 5 || y == 7 || y == 8||y==10))
		cout << "Yes";
	else
		cout << "No";

}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] bc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (bc[0] == 1) { bc[0] = 14; }
            if (bc[1] == 1) { bc[1] = 14; }
            if (bc[0] > bc[1]) { Console.WriteLine("Alice"); }
            else if (bc[0] < bc[1]) { Console.WriteLine("Bob"); }
            else{Console.WriteLine("Draw"); }
            Console.ReadLine();
        }
    }
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String[] A = new String[N];
		String[] B = new String[N];
		String[] C = new String[N - 1];
		A = br.readLine().split(" ");
		B = br.readLine().split(" ");
		C = br.readLine().split(" ");

		int result = 0;
		int code = 0;
		int save = 0;

		for (int i = 0; i < N; i++) {
			code = Integer.parseInt(A[i]);
			result += Integer.parseInt(B[code - 1]);
			if (code == save) {
				result += Integer.parseInt(C[code - 2]);
			}
			save = code + 1;
		}

		System.out.println(result);

	}

}


Measured memory_bytes: 21204
#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)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } else return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } else return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;

ll sum[56][2]; // pos:[0], neg:[1]

int main() {
	ll N; cin >> N;
	
	ll p[56] = {};
	p[0] = 1;
	FOR(i, 1, 56) p[i] = p[i - 1] * 2;
	
	REP(i, 56) {
		if (i > 0) {
			sum[i][0] = sum[i - 1][0];
			sum[i][1] = sum[i - 1][1];
		}
		
		if (i % 2 == 0) sum[i][0] += p[i];
		else sum[i][1] -= p[i];
	}
	
	string ans = "";
	
	for (int i = 55; i >= 1; i--) {
		if (N > 0) {
			if (sum[i - 1][0] < N && N <= sum[i][0]) {
				N -= p[i];
				ans += "1";
			}
			else ans += "0";
		}
		else {
			if (-sum[i - 1][1] < -N && -N <= -sum[i][1]) {
				N += p[i];
				ans += "1";
			}
			else ans += "0";
		}
	}
	ans += N == 1 ? "1" : "0";
	reverse(ALL(ans));
	
	int lastzero = -1;
	for (int i = ans.size() - 1; i >= 1; i--) {
		if (ans[i] != '0') break;
		lastzero = i;
	}
	if (lastzero != -1) ans.erase(ans.begin() + lastzero, ans.end());
	
	reverse(ALL(ans));
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int a,i;
        char *Name;
        Name="No";
        cin  >> a;
        for (i=1;i<=9;i++){
                if ( a%i==0 && a/i<=9 ){
                        Name="Yes";
                }
        }
        cout << Name;
}

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

int main (){
    int a,b,c,k;

    cin >> a >> b >> c;

    if(a>b){
        k = a;
        a = b;
        b = k;
    }
    if(b>c){
        k = b;
        b = c;
        c = k;
    }
    if(a>b){
        k = a;
        a = b;
        b = k;
    }
        

    cout << a <<" "<< b <<" "<< c << endl;
   
    return 0;
}


Measured memory_bytes: 3088
N, M, K = list(map(int,input().strip().split(' ')))
import itertools
flg = 0
for i,j in itertools.product([k for k in range(N+1)],[k for k in range(M+1)]):
    kuro = M * i + N * j -2 * i * j
    if kuro == K:
        flg = 1
        break

if flg == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n, k;
    cin >> n >> k;
    
    int R, S, P;
    cin >> R >> S >> P;
    
    string t;
    cin >> t;
    
    //rはグー sはチョキ pはパー
    
    map<char, int>mp;
    mp['r'] = P;
    mp['s'] = R;
    mp['p'] = S;
    
    int ans = 0;
    
    for(int i = 0; i < n; i++){
        if(i < k){
            ans += mp[t[i]];
        }
        else{
            if(t[i] == t[i-k]){
                t[i] = 'z';
            }
            else{
                ans += mp[t[i]];
            }
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 512
import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


def li ():
	return list (map (int, sys.stdin.readline ().split ()))


def num ():
	return map (int, sys.stdin.readline ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


def lcm ( x, y ):
	gg = find_gcd (x, y)
	return (x * y // gg)



mm = 1000000007
def solve ():
	t = 1
	for tt in range (t):
		n=nu()
		a=li()
		a.sort()
		mp={}
		for i in a:
			if(i in mp):
				mp[i]=mp.get(i)+1
			else:
				mp[i]=1
		i=0
		j=n-1
		cc=0
		while(i<j):
			if(mp.get(a[i])==1):
				i+=1
				continue
			if(mp.get(a[j])==1):
				j-=1
				continue
			cc+=2
			mp[a[i]]=mp.get(a[i])-1
			mp[a[j]]=mp.get(a[j])-1
			i+=1
			j-=1
		print(n-cc)







if __name__ == "__main__":
	solve ()

Measured memory_bytes: 20220
//????????°???????????°????????????????????\??????????????¢?????´???????????¨??????????§???? P181-182(Google Books?????¬?????\???)?????????.

#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;

int do_cycle(vector<int> &v,int x){
	int s=0,m=1<<30;
	for(auto &e:v)s+=e,m=min(m,e);
	return min(s+(v.size()-2)*m,s+m+(v.size()+1)*x);
}

int main(){
	int N,x=1<<30,r=0;
	scanf("%d",&N);
	vector<int>v(N),b(N),se(N);
	map<int,int>m;
	vector<vector<int> >cycles;
	for(int i=0;i<N;i++)scanf("%d",&v[i]),x=min(x,v[i]),se[i]=v[i];
	sort(se.begin(),se.end());
	int i=0;for(auto &e:se){m[e]=i++;}
	for(int i=0;i<N;i++)if(!b[i]){
		vector<int>cycle;
		int k=i;
		do{
			cycle.push_back(se[k]);
			b[k]=1;
			k=m[v[k]];
		}while(k!=i);
		r+=do_cycle(cycle,x);
	}
	printf("%d\n",r);
}

Measured memory_bytes: 2912
#include <stdio.h>
#include <stdlib.h>
int n, m, ans;
char s[1000][1000];
int dx[4] = { -1, 1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
int judge(int x, int y) {
    if (s[x][y] == '@')return 1;
    if (s[x][y] == '#')return 2;
    if (s[x][y] == '*')return 3;
}
void dfs(int x, int y) {
    int g = judge(x, y);
    s[x][y] = 0;
    for (int i = 0; i < 4; i++) {
        int xx = x + dx[i], yy = y + dy[i];
        if (xx > 0 && xx <= n && yy > 0 && yy <= m &&s[xx][yy] != 0)
        {
            if (judge(xx, yy) == g)dfs(xx, yy);
        }
    }
}
int main() {
 
    while (scanf("%d %d", &n, &m)&&n&&m)
    {
ans = 0;
        for (int i = 1; i <= n; i++)
            scanf("%s", s[i] + 1);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                if (s[i][j] == '@' || s[i][j] == '*' || s[i][j] == '#') {
                    dfs(i, j);
                    ans++;
                }
 
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 3408
/* Coached by rainboy */
#include <stdio.h>

#define N 100000

int oo[1 + (N - 1) * 2], oj[1 + (N - 1) * 2], ow[1 + (N - 1) * 2];

int link(int o, int j, int w) {
	static int _ = 1;

	oo[_] = o, oj[_] = j, ow[_] = w;
	return _++;
}

int ae[N];
long long dd[N];

void dfs(int p, int i, long long d) {
	int o;

	dd[i] = d;
	for (o = ae[i]; o; o = oo[o]) {
		int j = oj[o], w = ow[o];

		if (j != p)
			dfs(i, j, d + w);
	}
}

int main() {
	int n, q, k, h;

	scanf("%d", &n);
	for (h = 0; h < n - 1; h++) {
		int i, j, w;

		scanf("%d%d%d", &i, &j, &w), i--, j--;
		ae[i] = link(ae[i], j, w);
		ae[j] = link(ae[j], i, w);
	}
	scanf("%d%d", &q, &k), k--;
	dfs(-1, k, 0);
	while (q--) {
		int i, j;

		scanf("%d%d", &i, &j), i--, j--;
		printf("%lld\n", dd[i] + dd[j]);
	}
	return 0;
}

Measured memory_bytes: 9856
#include<stdio.h>

main()
{
  int d,x,i;
  long int ans;
  while( scanf("%d",&d)!=EOF){
    ans=0;

    x=d;
    while(x<=600-d){
      ans=ans+d*x*x;
      x=x+d;
    }

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

}

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

int main(){
	long n,m,c;
	long b[20];
	
	cin >>n>>m>>c;
	int counter = 0;
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		int sum = c;
		int tmp;
		for(int j=0;j<m;j++){
			cin >> tmp;
			sum+= (tmp*b[j]);
		}
		counter = (sum > 0) ? counter+1:counter;
	}
	cout << counter <<"\n";
}


Measured memory_bytes: 3592
H, W = map(int, input().split(" "))
m = [list(input().strip()) for _ in range(H)]
mod = 10**9 + 7

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

for h in range(H):
    for w in range(W):
        if h+1 < H and m[h+1][w] == ".":
            dp[h+1][w] += dp[h][w]
            dp[h+1][w] %= mod
        if w+1 < W and m[h][w+1] == ".":
            dp[h][w+1] += dp[h][w]
            dp[h][w+1] %= mod

print(dp[H-1][W-1])

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

int main(){
	string S; cin >> S;

	if(S[5] == '0'){
		if(S[6]-'0' >= 5) cout << "TBD" << endl;
		else cout << "Heisei" << endl;
	}else if(S[5] == '1'){
		cout << "TBD" << endl;
	}

	return 0;
}


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

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'


int main(){
	IoFast;
	string s;
	cin >> s;
	bool b = true;
	for (int i = 0; i < sz(s) - 1; i++) {
		if (s.at(i) != s.at(i + 1)) 
			b = 0;
	}
	if (b) {
		cout << 0 << endl;
		return 0;
	}

	int minn = INT_MAX;
	for (char c = 'a'; c <= 'z'; c++) {
		string t = s;
		for (int l = 0; l <= sz(s) - 1; l++) {
			bool is_all_same = 1;
			for (int i = 0; i < sz(s) - l - 1; i++) {
				if (t.at(i) == c || t.at(i + 1) == c)
					t.at(i) = c;
				else 
					is_all_same = false;
			}

			if (is_all_same) {
				minn = min(minn, l + 1);
				break;
			}
		}
	}

	cout << minn << endl;
}



Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
min=a[0]
ans=1000
for i in range(1,n):
    if min>a[i]:
        min=a[i]
    elif  a[i]>min:
        x=ans//min
        ans-=x*min
        ans+=x*a[i]
        min=a[i]
print(ans)


Measured memory_bytes: 61896
#include <iostream>

namespace ABC178
{

  class C
  {
  public:
    C() = default;
    ~C() = default;

    static constexpr long long TH = 1000000007;

    void Run()
    {
      int N = {};
      std::cin >> N;

      long long sum = 0;
      long long ten = 1;
      long long nine = 1;
      long long eight = 1;

      for(int i = 0; i < N; ++i)
      {
        ten *= 10;
        nine *= 9;
        eight *= 8;

        ten %= TH;
        nine %= TH;
        eight %= TH;
      }

      auto nine_r = nine * 2;
      nine_r %= TH;
      sum = ten + eight - nine_r;
      if (sum < 0)
      {
        sum += TH;
      }
      else
      {
        sum %= TH;
      }

      std::cout << sum << std::endl;
    }
  };
}
int main()
{

  ABC178::C prob;
  prob.Run();

  return 0;
}





Measured memory_bytes: 3140
s=list(input())
n=len(s)
l=[]
i=0
while i<n:
    if i<n-1 and s[i]=='B' and s[i+1]=='C':
        l.append('D')
        i+=2
    else:
        l.append(s[i])
        i+=1
n=len(l)
ans=0
r=[0]*(n+1)
f=0
for i in range(n-1,-1,-1):
    if l[i]=='D':
        f+=1
    elif l[i]=='A':
        ans+=f
    else:
        f=0
print(ans)


Measured memory_bytes: 61808
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int N;
int a[100010], b[100010], c[100010];
int dp[100010][3];

int main () {

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d %d %d", &a[i], &b[i], &c[i]);
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for (int i = 1; i < N; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }

    cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;

    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  if(n==m){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

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

using namespace std;

int main(void)
{
	int a,b; cin>>a>>b;
	if(a == b){
		cout<<"Draw"<<endl;
		return 0;
	}
	else if(a == 1){
		cout<<"Alice"<<endl;
		return 0;
	}
	else if(b == 1){
		cout<<"Bob"<<endl;
		return 0;
	}
	else if(a > b){
		cout<<"Alice"<<endl;
		return 0;
	}
	else{
		cout<<"Bob"<<endl;
		return 0;
	}
	return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, M; cin >> N >> M;
  ll a[N]; rep(i,N) cin >> a[i];
  ll c2[N] = {}; rep(i,N) { while(a[i]%(1<<(c2[i]+1))==0) c2[i]++; }
  bool c2ok = true; rep(i,N) if (c2[i]!=c2[0]) c2ok = false;
  if (!c2ok) { cout << 0 << endl; return 0; }

  ll g = 1;
  rep(i,N) {
    g = lcm(g,a[i]/2);
    if (g>M) break;
  }
  ll result = M/g - M/(g*2);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 1e14
#define N 500001
#define K 4
#define ALPHA 1.1
#define BETA 1.0



int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int d;
    cin >> d;
    vector<int> c(26);
    double average = 0.0;

    for(int i = 0;i < 26;i++)
        cin >> c[i];
    vector<vector<int>> v(d,vector<int>(26,0));
    for(int i = 0;i < d;i++)
    {
        for(int j = 0;j < 26;j++)
        {
            cin >> v[i][j];
            average += v[i][j];
        }
    }
    average /= (d * 26);
    vector<int> last(26,-1);
    for(int i = 0;i < d;i++)
    {
        double mxgain = -inf;
        int ind = -1;

        for(int j = 0;j < 26;j++)
        {
            double gain = pow(v[i][j],BETA) + pow(i - last[j],2) * c[j];
            // cerr << j << " " << gain << endl;
            if(gain > mxgain)
            {
                mxgain = gain;
                ind = j;
            }
        }
        last[ind] = i;
        cout << ind + 1 << endl;
    }

    
    return 0;    
} 



Measured memory_bytes: 3728
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, K = [int(sys.stdin.buffer.readline()) for _ in range(2)]
N = str(N)

DIGIT = len(N)
# d から K 個選ぶ
dp = np.zeros((DIGIT + 1, K + 1, 2), dtype=int)
dp[0, 0, 0] = 1
for d in range(1, DIGIT + 1):
    nd = int(N[d - 1])
    if nd > 0:
        dp[d, :, 1] += dp[d - 1, :, 0]
        dp[d, :, 1] += dp[d - 1, :, 1]
        for k in range(1, K + 1):
            # この d で 1 個使う
            dp[d][k][0] += dp[d - 1][k - 1][0]
            dp[d][k][1] += dp[d - 1][k - 1][0] * (nd - 1)
            dp[d][k][1] += dp[d - 1][k - 1][1] * 9
    else:
        dp[d, :, 0] += dp[d - 1, :, 0]
        dp[d, :, 1] += dp[d - 1, :, 1]
        for k in range(1, K + 1):
            # この d で 1 個使う
            dp[d][k][1] += dp[d - 1][k - 1][1] * 9
print(dp[-1][K].sum())


Measured memory_bytes: 12528
#include<stdio.h>
 
int dp[50];
 
int fib(int n)
{
  if ( n == 0 || n == 1 ) return dp[n] = 1;
  if ( dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
 
int main()
{
  int n, i;
  for( i = 0; i < 50 ; i++)dp[i] = -1;
 
  scanf("%d", &n);
  printf("%d\n",fib(n));
 
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void){

  int a, x, c=0;

  scanf("%d",&a);
 
  for(x=1;x <= a;x++){
    if(x % 3 == 0){
      printf(" %d" ,x);
      continue;
    }
    for(c=x; c; c/=10)
      if (c % 10 == 3){
	printf(" %d",x);
	break;
      }
  }
  printf("\n");
  return 0;
}

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


int main() {
    int y,m,d;
    char slash;
    cin >> y >> slash >> m >> slash >> d;
    if(m <= 4 && d <= 30)cout << "Heisei\n";
    else cout << "TBD\n";

    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int mlb(int x) {
	if (x & 0xffff0000)
		x &= 0xffff0000;

	if (x & 0xff00ff00)
		x &= 0xff00ff00;

	if (x & 0xf0f0f0f0)
		x &= 0xf0f0f0f0;

	if (x & 0xcccccccc)
		x &= 0xcccccccc;

	if (x & 0xaaaaaaaa)
		x &= 0xaaaaaaaa;
	return x;
}
int popc(int x) {
	x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
	x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
	x = (x & 0x0f0f0f0f) + ((x >> 4) & 0x0f0f0f0f);
	x = (x & 0x00ff00ff) + ((x >> 8) & 0x00ff00ff);
	x = (x & 0x0000ffff) + ((x >> 16) & 0x0000ffff);
	return x;
}
int main() {
	int l, n, m;
	scanf("%d", &l);
//	l = (1 << 19) - 1;
	n = 20;
	m = 36;
	for (int i = l; i != 0; m++) {
		int ml = min(mlb(i), 1 << 18);
		i -= ml;
	}
	printf("%d %d\n", n, m);
	for (int i = 3; i <= n; i++) {
		printf("%d %d %d\n", i - 1, i, 0);
		printf("%d %d %d\n", i - 1, i, (1 << (n - i)));
	}
	int off = 0;
	for (int i = l; i != 0;) {
		int ml = min(mlb(i), 1 << 18);
		printf("1 %d %d\n", n - popc(ml - 1), off);
		off += ml;
		i -= ml;
	}
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
//const int inf = pow(2, 62);
const int inf = pow(2, 30);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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 (b<a) { a=b; return 1; } return 0; }




/* main */
int n, k, s;
int dp[15][25][160];

int dfs(int i, int last, int accum){

    if(i == k){
        if(accum == s) return 1;
        else return 0;
    }

    if(accum > s) return 0;

    if(dp[i][last][accum] > -1) return dp[i][last][accum];

    int ret = 0;

    rep(j,last + 1, n + 1){
        ret += dfs(i + 1, j, accum + j);
    }

    return dp[i][last][accum] = ret;

}






signed main(){

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

    while(true){

        cin >> n >> k >> s;

        if(n == 0) return 0;

        memset(dp, -1, sizeof(dp));

        print(dfs(0,0,0));

    }











    

    

    



    
    



    







    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    











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

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

    if(x == 1 || x == 2*n-1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;

        vector<int> ans(2*n);
        ans[n-1] = x-1;
        ans[n]   = x;
        ans[n+1] = x+1;

        int current = 1;
        for(int i=1; i<=2*n-1; i++){
            if(n-1 <= i && i <= n+1) continue;

            if(current == x-1) current += 3;
            ans[i] = current;
            current += 1;
        }
        for(int i=1; i<=2*n-1; i++){
            cout << ans[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using lb=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   int n,k;
           cin>>n>>k;
           vin a(n);
           rep(i,0,n)cin>>a[i];
           map<int,int> cnt;
           rep(i,0,n)cnt[a[i]]++;
           vector<P> b(0);
           for(auto v:cnt){
             b.pb(mp(v.second,v.first));
           }
           sort(all(b));
           reverse(all(b));
           int h=0;
           ll ans=0;
           for(auto v:b){
            h++;
             if(h>k){
               ans+=v.first;
             }
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 17336
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (x % 2 == 0 && x % 5 && x % 3)
        {
            cout << "DENIED" << endl;
            return 0;
        }
    }

    cout << "APPROVED" << endl;
}

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

int main() {
  int N, T;
  std::cin >> N >> T;
  int lT = -1, ans = 0;
  for(int i = 0; i < N; ++i) {
    int t; std::cin >> t;
    int newlT = std::max(lT, t+T);
    if(t > lT) ans += T;
    else ans += newlT - lT;
    lT = newlT;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 

 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 	ll x,n;
 	cin>>x>>n;
 	vector<ll> chk(101,0);
 	ll p;
 	for(int i=0;i<n;i++){
 		cin>>p;
 		chk[p] = 1;
 	}
 	ll lf;
 	ll rh;
 	ll ans;
 	for(int i=0;i<102;i++){
 		lf = x-i;
 		rh = x+i;
 		if(chk[lf]!=1){
 			ans = lf;
 			break;
 		}
 		else if(chk[rh]!=1){
 			ans = rh;
 			break;
 		}

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

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll min_median, max_median;
  if (n % 2 == 1) {
    min_median = a[n / 2];
    max_median = b[n / 2];
  } else {
    min_median = a[n / 2 - 1] + a[n / 2];
    max_median = b[n / 2 - 1] + b[n / 2];
  }
  cout << max_median - min_median + 1 << endl;
  return 0;
}


Measured memory_bytes: 6412
//#include<i_am_noob_orz>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcount((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define LOCAL
#ifdef LOCAL
#define debug(a) cerr<<#a<<" "<<a<<endl;
#else
#define debug(a)
#endif
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int a[200010];
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,m;
	cin>>n>>m;
	F(n)cin>>a[i];
	int l=1,r=1e9;
	while(l<r){
		int mi=((l+r)/2);
		int s=0;
		//cout<<l<<" "<<r<<endl;
		//cout<<mi<<endl;
		F(n)if(a[i]>mi)s+=(ceiling(a[i],mi)-1);
		//cout<<s<<" "<<m<<endl;
		if(s<=m)r=mi;
		else l=mi+1;
	}
	cout<<l<<endl;
return 0;
}


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

int main()
{
	int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
	int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
	int h;
	int w;
	std::string s[60];

	std::cin >> h >> w;
	for(int i=0; i<h; i++) std::cin >> s[i];

	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j] == '.'){
				int cnt = 0;
				for(int k=0; k<8; k++){
					int x = i + dx[k];
					int y = j + dy[k];
					if(x>=0 && x<=h-1 && y>=0 && y<=w-1 && s[x][y]=='#')
						cnt++;
				}
				s[i][j]='0'+cnt;
			}
		}
	}

	for(int i=0; i<h; i++) std::cout << s[i] << std::endl;

	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    S = [s for s in input().strip()]
    q = deque()

    s = S.pop(0)
    q.append(s)
    while len(S) > 0:
        s = S.pop(0)
        q_ = deque()
        while len(q) > 0:
            a = q.popleft()
            q_.append(a + s)
            q_.append(a + '+' + s)

        q = q_

    ans = 0
    for a in q:
        ans += sum([int(i) for i in a.split('+')])

    return ans


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


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

int main(){
	long x;
	scanf("%ld", &x);
	long temp = 100;
	int cnt = 0;
	while(true) {
		temp += temp / 100;
		cnt++;
		if(temp >= x) {
			printf("%d\n", cnt);
			break;
		}
	}
}


Measured memory_bytes: 3756
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c float64
	fmt.Scan(&a, &b, &c)
	s := 0.5 * a * b * math.Sin((c*math.Pi)/float64(180))
	l := a + b + math.Sqrt(math.Pow(a, 2)+math.Pow(b, 2)-2*a*b*math.Cos((c*math.Pi)/float64(180)))
	h := b * math.Sin((c*math.Pi)/float64(180))
	fmt.Println(s, l, h)
}


Measured memory_bytes: 1164
from math import floor as f
S = list(input())
N = len(S)

hantei = True
for c in range(f(N / 2)):
    if S[c] == S[-1 * c - 1]:
        pass
    else:
        hantei = False
        break

for c in range(f((N - 1) / 4)):
    if S[c] == S[-1 * c + -1 * f(N / 2) - 2]:
        pass
    else:
        hantei = False
        break

if hantei:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
function  parse_int(x)
    parse(Int, x)
end
function  MAP()
    map(parse_int, split(readline(), " "))
end
function intinput()
    parse(Int, readline())
end
function solve()
    N = intinput()
    A = MAP()
    Q = intinput()
    numcount = zeros(Int32, 100000)
    for i = 1:N
        numcount[A[i]] += 1
    end
    total = [0 for i = 1:Q + 1]
    total[1] = sum(A)
    for i = 1:Q
        b, c = MAP()
        total[i + 1] = total[i] + c * numcount[b] - b * numcount[b]
        numcount[c] += numcount[b]
        numcount[b] = 0
    end
    for i = 1:Q
        println("$(total[i + 1])")
    end
end
solve()

Measured memory_bytes: 210080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<int char_size, char base>
struct Trie{
    struct Node{
        vector<int> next, accept;
        vector<ll> cnt;
        ll count; //子以下に追加された文字列の数

        Node() : count(0){
            next.assign(char_size, -1);
            cnt.assign(char_size, 0);
        }
    };

    vector<Node> nodes;

    Trie() {nodes.eb();}

    int count() const {return nodes.front().count;}

    int size() const {return sz(nodes);}

    void insert(const string &s, int id = -1){
        int now = 0;
        rep(i, sz(s)){
            int &next = nodes[now].next[s[i]-base];
            if(next == -1){
                next = size(), nodes.eb();
            }
            nodes[now].count++, now = next;
        }
        nodes[now].count++, nodes[now].accept.pb(id == -1? count()-1 : id);
    }

    bool search(const string &s, bool prefix = false){
        int now = 0;
        rep(i, sz(s)){
            now = nodes[now].next[s[i]-base];
            if(now == -1) return false;
        }
        return (prefix)? true : !nodes[now].accept.empty();
    }

    void dfs(int now){
        rep(i, char_size){
            int e = nodes[now].next[i];
            if(e == -1) continue;
            dfs(e);
            rep(j, char_size) if(i != j) nodes[now].cnt[j] += nodes[e].cnt[j];
            nodes[now].cnt[i] += nodes[e].count;
        }
    }

    ll query(const string &s){
        int now = 0;
        rep(i, sz(s)-1) now = nodes[now].next[s[i]-base];
        return nodes[now].cnt[s.back()-base]-1;
    }
};

int main(){
    int N;
    cin >> N;
    string S[N];
    Trie<26, 'a'> trie;
    rep(i, N){
        cin >> S[i];
        reverse(all(S[i]));
        trie.insert(S[i]);
    }
    trie.dfs(0);
    ll ans = 0;
    rep(i, N) ans += trie.query(S[i]);
    cout << ans << endl;
}

Measured memory_bytes: 451292
a,b = map(int, input().split())

num1 = ''
num2 = ''

for i in range(a):
  num1 = num1 + (str(b))

for i in range(b):
  num2 = num2 + (str(a))

list = [num1,num2]

list.sort()
print(list[0])

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

Measured memory_bytes: 128
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
    x,y,z = map(int,input().split())
    graph[x-1].append(y-1)
    graph[y-1].append(x-1)
check = [True]*n
count = 0
for i in range(n):
    if check[i]:
        count += 1
        stack = []
        stack.append(i)
        check[i] = False
        while stack:
            p = stack.pop()
            for j in graph[p]:
                if check[j]:
                    stack.append(j)
                    check[j] = False
    else:
        continue

print(count)

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


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ll n;
   cin>>n;
   queue<ll>q;
   if(n<10){ cout<<n;
   exit(0);
   }
   for(int i=1;i<10;i++)
   {
       q.push(i);

   }
   ll c=9;
   while(!q.empty())
   {
       ll a=q.front();
      // cout<<a<<" ";
       q.pop();
       ll d=a;
       ll x=a%10;

       if(x!=0)
       {
           d=a;
           c++;
           d=d*10+x-1;
           q.push(d);
           if(c==n) {cout<<d<<"\n";
           break;
           }
       }
       d=a;
       c++;
       d=d*10+x;
       q.push(d);
       if(c==n){
        cout<<d<<"\n";
        break;
       }

       if(x!=9)
       {
           d=a;
           c++;
           d=d*10+x+1;
           q.push(d);
           if(c==n){
            cout<<d<<"\n";
            break;
           }
       }
   }
}


Measured memory_bytes: 768