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


void solve(long long N, long long K, long long S){
    for(auto i=0; i < K; i++){
        cout << S << " ";
    }
    for(auto i=0; i < (N - K); i++){
        cout << (S == 1 ? 2 : S-1) << " ";
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long S;
    scanf("%lld",&S);
    solve(N, K, S);
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, m; cin >> n >> m;
    map<ll, vector<ll>> mp;
    priority_queue<ll, vector<ll>> que;
    rep(i, n) {
        ll a, b; cin >> a >> b;
        if (a > m) continue;
        mp[a].push_back(b);
    }

    ll sum = 0;

    for (int i = 1; i <= m; i++) {
        if (mp.find(i) != mp.end()) {
            for (auto elem : mp[i]) {
                que.push(elem);
            }
        }
        if (que.size()) {
            sum += que.top(); que.pop();
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, k; cin >> n >> k;
	vl a(n); REP(i, n) cin >> a[i];
	vl b(n); b[0] = a[0];
	FOR(i, 1, n) b[i] = a[i] + b[i - 1];

	vl c(n); c[0] = max(0ll, a[0]);
	FOR(i, 1, n) {
		if (a[i] >= 0) {
			c[i] = c[i - 1] + a[i];
		} else {
			c[i] = c[i - 1];
		}
	}

	ll ans = 0;
	REP(i, n - k + 1) {
		ans = max(ans, c[n - 1] - c[i + k - 1] + b[i + k - 1] + (i == 0 ? 0 : c[i - 1] - b[i - 1]));
		ans = max(ans, c[n - 1] - c[i + k - 1] + (i == 0 ? 0 : c[i - 1]));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    data class Spot(val number: String, var isOpen: Boolean = false)

    fun isBingo(spots: List<List<Spot>>): Boolean {
        // 横
        spots.forEach {
            if (it.all { it.isOpen }) {
                return true
            }
        }
        // 縦
        0.until(3).forEach {
            if (spots[0][it].isOpen && spots[1][it].isOpen && spots[2][it].isOpen) {
                return true
            }
        }
        // 斜め
        if (spots[0][0].isOpen && spots[1][1].isOpen && spots[2][2].isOpen) {
            return true
        }
        if (spots[0][2].isOpen && spots[1][1].isOpen && spots[2][0].isOpen) {
            return true
        }

        return false
    }

    val spots = 0.until(3).map {
        readLine()?.split(" ")?.map { Spot(it, false) } ?: return@main
    }
    val n = readLine()?.toInt() ?: return
    val numbers = 0.until(n).map {
        readLine() ?: return@main
    }
    numbers.forEachIndexed { i, number ->
        spots.forEach { line ->
            line.forEach { spot ->
                if (spot.number == number) {
                    spot.isOpen = true
                }
            }
        }
        if (isBingo(spots)) {
            println("Yes")
            return
        }
    }
    println("No")
}


Measured memory_bytes: 38060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;

struct Edge{int to,id;};
vector<int> ans;
vector<vector<Edge>> G;


void dfs(int v, int co=-1, int pre=-1){
    int index = 1;
    rep(i,int(G[v].size())){
        int u = G[v][i].to, ei = G[v][i].id;
        if(u == pre) continue;
        if(index == co) ++index;
        ans[ei] = index; ++index;
        dfs(u,ans[ei],v);
    }
}

int main(){
    int n;
    cin >> n;
    G.resize(n);
    ans.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back((Edge){b,i});
        G[b].push_back((Edge){a,i});
    }    
    dfs(0);
    int colors = 0;
    rep(i,n) colors = max(colors,int(G[i].size()));
    cout << colors << endl;
    rep(i,n-1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 11012
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	/** 白チョコを表す文字 */
	private static final char WHITE = '1';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			int k = scanner.nextInt();
			boolean[][] s = new boolean[h][w];
			IntStream.range(0, h).forEach(i -> {
				char[] cs = scanner.next().toCharArray();
				IntStream.range(0, cs.length).forEach(j -> s[i][j] = (cs[j] == WHITE));
			});
			System.out.println(IntStream.range(0, (1 << h)).map(i -> {
				// 白チョコの数を格納する配列
				int[] counts = new int[Integer.bitCount(i) + 1];
				int result = Integer.bitCount(i);
				for (int j = 0; j < w; j++) {
					int[] now = calcNow(i, h, s, j);
					if (!check(now, k)) {
						return Integer.MAX_VALUE;
					}
					calcSum(counts, now);
					if (!check(counts, k)) {
						counts = now;
						result++;
					}
				}
				return result;
			}).min().getAsInt());
		}
	}

	/**
	 * チョコのj列目の白チョコの個数の配列を計算
	 * 
	 * @param plan チョコを横に分割するプラン
	 * @param h    チョコの高さ
	 * @param s    チョコの配列
	 * @param j    チョコのj列目に対して計算
	 * @return チョコのj列目の白チョコの個数の配列
	 */
	private static int[] calcNow(final int plan, int h, boolean[][] s, int j) {
		int[] result = new int[Integer.bitCount(plan) + 1];
		Arrays.fill(result, 0);
		int index = 0;
		for (int i = 0; i < h; i++) {
			result[index] += (s[i][j]) ? 1 : 0;
			if (0 != ((1 << i) & plan)) {
				index++;
			}
		}
		return result;
	}

	/**
	 * 配列に最大値を超えたものが含まれないかを計算
	 * 
	 * @param array 配列
	 * @param k     チョコの最大値
	 * @return 配列に最大値を超えたものが含まれないか
	 */
	private static boolean check(int[] array, int k) {
		for (int a : array) {
			if (a > k) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 現在のチョコ数配列を合計用チョコ数配列に加算する
	 * 
	 * @param counts 合計用チョコ数配列
	 * @param now    現在のチョコ数配列
	 */
	private static void calcSum(int[] counts, int[] now) {
		for (int i = 0; i < Math.min(counts.length, now.length); i++) {
			counts[i] += now[i];
		}
	}
}


Measured memory_bytes: 47924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;


int main(){
    ll n,m;
    cin >> n >> m;
    map<ll,ll> mp;
    for(ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    bool flag=true;
    for(auto p:mp){
        if(p.second%2==1) flag=false;
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}  


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

#define ll long long
#define ull unsigned long long

using namespace std;

using Graph = vector<vector<int>>;

int main() {
	int N, M;
	cin >> N >> M;

	vector <int> a(M);
	vector <int> b(M);
	for (int ii = 0; ii < M; ++ii){
		cin >> a[ii] >> b[ii];
		a[ii]--;
		b[ii]--;
	}

	int ans = 0;
	for (int ii = 0; ii < M; ++ii){
		//ii番目の辺を除いたグラフを作成
		Graph graph(N);
		for (int jj = 0; jj < M; ++jj){
			if (jj == ii){
				continue;
			}
			graph[a[jj]].push_back(b[jj]);
			graph[b[jj]].push_back(a[jj]);			
		}

		//連結成分の数を求める
		queue<int> q;
		int initIdx = 0;
		q.push(initIdx);	//最初のキューを追加

		vector<int> visit(N, 0);	//visitでその地点を訪れたかどうか管理
		visit[initIdx] = 1;

		while (!q.empty()) {	//キューが空になるまで探索
			int idx = q.front();
			q.pop();
			for (auto adIdx : graph[idx]){
				if (visit[adIdx] == 0){
					q.push(adIdx);
					visit[adIdx] = 1;
				}
			}
		}

		//連結かどうか判別
		for (int ii = 0; ii < N; ++ii){
			if (visit[ii] == 0){
				ans++;
				break;
			}
		}
	}


	cout << ans << "\n";

	return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> correct(N+1, 0);
    vector<int> wrong(N+1, 0);
    int WA_count = 0;
    for (int i=0; i < M; i++) {
        int num;
        string ans;
        cin >> num >> ans;
        if (correct[num] > 0) {
            // 何もしない
        }
        else
        {
            if (ans == "WA")
            {
                wrong[num] += 1;
            }
            else
            {
                correct[num] = 1;
                WA_count += wrong[num];
            }
        }
    }

    int AC_count = 0;
    for (int i =0; i < N+1; i++){
        if (correct[i] > 0) {
            AC_count += 1;
        }
    }

    cout << AC_count << " " << WA_count << endl;

    return 0;
}

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

using namespace std;

int main(){
  int n;
  string s;
  cin >> n;
  cin.ignore();
  cin >> s;
  cin.ignore();
  
  if(n % 2 == 1){
    cout << "No" << endl;
    return 0;
  }

  bool match = true;
  for(int i = 0; i < n / 2; i++){
    if(s[i] != s[n/2 + i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;
void solve()
{
	int a, b, c, x, cnt = 0;
	cin>>a>>b>>c>>x;
	for(int i=0; i<=a; i++)
	{
		for(int j=0; j<=b; j++)
		{
			for(int k=0; k<=c; k++)
			{
				if((500*i + 100*j + 50*k )== x)
					cnt++;
			}
		}
	}
	cout<<cnt<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3592
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long int
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;
#ifndef LOCAL
#define endl '\n'
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
vector<int> v;
int dp[100][76];
int go(int n,int val){
    if(n == 0)
        return val == 1;
    if(dp[n][val]) return dp[n][val] - 1;
    int ans = 0;
    fr(x, 0, v[n - 1]){
        if(val % (x + 1) == 0){
            ans += go(n - 1, val / (x + 1));
        }
    }
    dp[n][val] = ans + 1;
    return ans;
}
bool prime[105];
vector<int> pp;
void solve(){
    int n;
    cin >> n;
    fr(i, 2, n){
        if(!prime[i]){
            for(int j = 2 * i; j <= n; j += i)
                prime[j] = 1;
            pp.pb(i);
        }
    }
    for(int x : pp){
        int val = 0;
        int nn = n;
        while(nn){
            nn /= x;
            val += nn;
        }
        v.pb(val);
    }
    cout << go(v.size(), 75) << endl;
}
signed main()
{
    IO;
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        // freopen("out.txt", "w", stdout);
    #endif
    clock_t clk = clock();
    int t = 1;
    // cin >> t;
    fr(i, 1, t){
        solve();
    }
    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int n;
  cin >> n;
  vpii a(n);
  rep(i,n) {
    int  p,q;
    cin >> p >> q;
    a[i] = make_pair(p,q);
  }
  vi b(n);
  
  rep(i,n) b[i] = i;
  double cnt = 0;
  double sum = 0;
  do{
    cnt++;
    rep(i,n-1){
      sum += sqrt((a[b[i]].first-a[b[i+1]].first)*(a[b[i]].first-a[b[i+1]].first)+(a[b[i]].second-a[b[i+1]].second)*(a[b[i]].second-a[b[i+1]].second));
    }
    
  }while(next_permutation(b.begin(),b.end()));
  double ans = sum/cnt;
  //cout << cnt << " " <<  sum << endl;
  cout << fixed << setprecision(7) << ans << endl;
         
  
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var line = nextLine()

	var cookie = strings.Split(line, " ")
	var cookieA, _ = strconv.Atoi(cookie[0])
	var cookieB, _ = strconv.Atoi(cookie[1])

	if cookieA%3 == 0 || cookieB%3 == 0 || (cookieA+cookieB)%3 == 0 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;

public class Test
{
	public static void Main()
	{
		int N = int.Parse(Console.ReadLine());
		string s = Console.ReadLine();
		int Max = 0;
		HashSet<string> H = new HashSet<string>();
		int count = 0;
		for(int i = 0;i < N;i++){
		    for(int j = 0;j < i;j++){
		        if(!H.Contains(s[j].ToString()) && (s.Skip(i).Take(N-i).ToArray()).Any(a => a == s[j])){
		            H.Add(s[j].ToString());
		            count++;
		        }
		    }
		    if(count > Max)Max = count;
		    count = 0;
		    H.Clear();
		}
		Console.WriteLine(Max);
	}
}


Measured memory_bytes: 15456
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int n;
string s,t,res;
int main() {
	cout << fixed << setprecision(18);
	cin>>n>>s>>t;
    for(int i=0;i<n;i++){
        res.push_back(s[i]);
        res.push_back(t[i]);
    }
	cout<<res;
} 

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var scaner = new Scanner();

        var k = scaner.ReadInt();
        var x = scaner.ReadInt();

        var max = x + k - 1;
        var min = x - k + 1;

        for (var i = min; i <= max; i++)
        {
            if (i > min) Console.Write(" ");
            Console.Write(i);
        }
        Console.WriteLine();
    }
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }

    public string ReadStr()
    {
        return this.Next();
    }

    public char ReadChar()
    {
        return this.Next()[0];
    }

    public int ReadInt()
    {
        return int.Parse(this.Next());
    }

    public long ReadLong()
    {
        return long.Parse(this.Next());
    }

    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }

    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }

    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
}

Measured memory_bytes: 11092
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
ans = [0]
l =[]
values, counts = zip(*cnt.most_common())
for v, c in zip(values, counts):
    if c > 3:
        ans.append(v**2)
        l.append(v)
    elif c > 1:
        l.append(v)
l.sort(reverse=True)
if len(l) > 1:
    ans.append(l[0] * l[1])
print(max(ans))



Measured memory_bytes: 28708
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;

int a[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	copy_n(istream_iterator<int>(cin), n, a);
	int g = 0;
	for (int i = 0; i < n; ++i)
		g = gcd(g, a[i]);
	cout << ((g & 1) ? "first" : "second") << '\n';
	return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll a,b,k;
    cin>>a>>b>>k;
    vector<ll> ans(100);
    ll c=0;
    rep(0,i,100)ans[100]=0;
    rep(0,i,min(a,b)){
        ll x=i+1;
        if(a%x==0 && b%x==0){
            ans[c]=x;
            ++c;
        }
    }
    sort(ans.rbegin(),ans.rend());
    cout<<ans[k-1]<<endl;
}

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


int main(){
	string s;
  cin >> s;
  int r = 0;
  if(s == "SUN"){
   r = 7; 
  }
   if(s == "MON"){
   r = 6; 
  }
    if(s == "TUE"){
   r = 5; 
  }
    if(s == "WED"){
   r = 4; 
  }
    if(s == "THU"){
   r = 3; 
  }
    if(s == "FRI"){
   r = 2; 
  }
      if(s == "SAT"){
   r = 1; 
  }

  cout << r;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int n;
int p[30];
int main(){
  cin>>n;
  rep(i,n) cin>>p[i];
  int cnt=0;
  rep(i,n-2){
    int a[3];
    a[0]=p[i];a[1]=p[i+1];a[2]=p[i+2];
    sort(a,a+3);
    if(a[1]==p[i+1]) cnt++;
  }
  prin(cnt);
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		int m = sc.nextInt();
		String[] t = new String[m];
		for (int i = 0; i < m; i++) {
			t[i] = sc.next();
		}
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int cb = 0;
			int cr = 0;
			for (int j = 0; j < n; j++) {
				if (s[i].equals(s[j]))
					cb++;
			}
			for (int j = 0; j < m; j++) {
				if (s[i].equals(t[j]))
					cr++;
			}
			if (max < cb - cr) {
				max = cb - cr;
			}
		}
		System.out.println(max > 0 ? max : 0);
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x;
    cin >> x >> n;
    vector<int>q(n);
    map<int,int>maps;
    f(i,0,n){
        cin >> q[i]; 
        maps[q[i]] = 1; 
    }
    int ans = INT_MAX,diff = INT_MAX;
    f(i,-200,200){
        if(maps[i] == 0){
            if(abs(i - x) < diff){
                diff = abs(i-x);
                ans = i;
            }
        }
    }
    cout << ans << "\n";
    
    return 0;
}
 

Measured memory_bytes: 3680
using System;
using System.Linq;

namespace Pasta {
	struct NumOfCase {
		const int MOD = 10000;
		public NumOfCase(int _value)
			: this() {
			Value = _value % MOD;
		}
		public int Value { get; private set; }
		public static implicit operator NumOfCase(int i) {
			return new NumOfCase(i);
		}
	}

	[Flags]
	enum Sauce {
		Tomato = 1,
		Cream = 2,
		Basil = 4,
		Any = Tomato | Cream | Basil
	};

	class Menu {
		public NumOfCase Number { get; private set; }
		public NumOfCase NewNumber { private get; set; }
		public readonly Sauce Last1, Last2;
		public Menu(int number, Sauce last1, Sauce last2) {
			Number = number;
			NewNumber = 0;
			Last1 = last1;
			Last2 = last2;
		}
		public void Update() {
			Number = NewNumber;
			NewNumber = 0;
		}
		public bool IsDoubledMenu { get { return Last1 == Last2; } }
	}

	class Program {
		const int NUM_SAUCE = 3;
		static Sauce toSauce(int i) {
			switch (i) {
				case 0: return Sauce.Tomato;
				case 1: return Sauce.Cream;
				case 2: return Sauce.Basil;
				default: return Sauce.Any;
			}
		}
		static bool hasFlag(Sauce s, Sauce flag) { return (s & flag) == flag; }

		static void Main(string[] args) {
			string[] str = Console.ReadLine().Split(' ');
			int N = int.Parse(str[0]);
			int K = int.Parse(str[1]);
			Sauce[] schedule = Enumerable.Repeat<Sauce>(Sauce.Any, N).ToArray();
			for (int k = 0; k < K; k++) {
				str = Console.ReadLine().Split(' ');
				schedule[int.Parse(str[0]) - 1] = toSauce(int.Parse(str[1]) - 1);
			}

			var menulist = (from i in Enumerable.Range(0, NUM_SAUCE * NUM_SAUCE)
							let l1 = toSauce(i / NUM_SAUCE)
							let l2 = toSauce(i % NUM_SAUCE)
							let number = hasFlag(schedule[1],l1) && hasFlag(schedule[0],l2) ? 1 : 0
							select new Menu(number, l1, l2)).ToArray();
			for (int n = 2; n < N; n++) {
				foreach (var menu in menulist) {
					menu.NewNumber = (from old_menu in menulist
									  where old_menu.Last1 == menu.Last2 &&
											!(menu.IsDoubledMenu && old_menu.IsDoubledMenu) &&
											hasFlag(schedule[n], menu.Last1)
									  select old_menu.Number
									 ).Sum(num => num.Value);
				}
				foreach (var menu in menulist) menu.Update();
			}
			NumOfCase answer = menulist.Sum(menu => menu.Number.Value);
			Console.WriteLine(answer.Value);
		}
	}
}

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

using namespace std;

const int md = 1000000007;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline int mul(int a, int b) {
  return (long long) a * b % md;
}

inline int power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int x) {
  return power(x, md - 2);
}

const int N = 1234567;

int fact[N], invfact[N];

inline int C(int n, int k) {
  if (k < 0 || k > n) return 0;
  return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  invfact[N - 1] = inv(fact[N - 1]);
  for (int i = N - 2; i >= 0; i--) {
    invfact[i] = mul(invfact[i + 1], i + 1);
  }
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int ans = 0;
  int rb = 0, rc = 0;
  for (int sum = 0; sum <= b + c; sum++) {
    int coeff = mul(power(3, b + c - sum), fact[a + sum - 1]);
    int what = power(2, sum);
    if (sum > b) {
      add(rb, rb);
      add(rb, C(sum - 1, b));
      add(what, md - rb);
    }
    if (sum > c) {
      add(rc, rc);
      add(rc, C(sum - 1, c));
      add(what, md - rc);
    }
    what = mul(what, invfact[sum]);
    add(ans, mul(coeff, what));
  }
  printf("%d\n", mul(ans, invfact[a - 1]));
  return 0;
}

Measured memory_bytes: 9856
function main()
  
  (N,K) = map(x -> parse(Int,x), split(readline()))
  
  l = map(x -> parse(Int,x), split(readline()))
  
  sort!(l,rev = true)
  ans = 0
  
  for i in 1:K
    
    ans += l[i]
    
  end
  
  println(ans)
  
end

main()

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  
  int M;
  cin >> M;
  vector <string> T(M);
  for(int j=0;j<M;j++){
    cin >> T.at(j);
  }
  
  vector<int> C(M*(N+1));
  
   for (int i = 0; i < N; i++) {
      int count =0;
      for(int k=0;k<N;k++){
       if(S.at(i)==S.at(k)){
         count++;
       }
      }
      for(int j=0;j<M;j++){
        if(S.at(i)==T.at(j)){
          count--;
        }
      }
      C.at(i)= count;
    }
  
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());

  
  cout << C.at(0) << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);


int main(){
  int N; ll Z, W;
  cin >> N >> Z >> W;

  ll A[N];
  for (int i = 0; i < N; i++) cin >> A[i];

  if (N == 1){
    cout << abs(A[0] - W) << endl;
    return 0;
  }

  ll ans = max(abs(A[N - 1] - A[N - 2]), abs(A[N - 1] - W));
  cout << ans << endl;

  return 0;
}


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

ac_set = set()
wa_cnt = {}
for i in range(M):
    p, s = input().split()
    if s == 'WA' :
        wa_cnt.setdefault(p, 0)
        if p not in ac_set:
            wa_cnt[p] += 1
    else :
        ac_set.add(p)
        
wa_sum = 0
for k, v in wa_cnt.items():
    if k in ac_set:
        wa_sum += v
print(len(ac_set),wa_sum)


Measured memory_bytes: 14052
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <memory>
#include <cstdlib>
#include <vector>
using namespace std;

int n;
int a[150];
void print();
int main(){
    //freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>a[i];
    }
    print();
    for (int i=1; i<n; i++) {
        int key=a[i];
        int j=i-1;
        while (key<a[j]&&j>=0){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=key;
        print();
    }
    return 0;
}
void print()
{
    for (int i=0; i<n; i++) {
        if (i>0) {
            cout<<' ';
        }
        cout<<a[i];
    }
    cout<<endl;
}

Measured memory_bytes: 3084
import java.util.Scanner;

public class Main
{
	private static int[] P2 = new int[1000 + 1];
	private static int[] P3 = new int[100 + 1];
	
	public static void main(String[] args)
	{
		for (int y = 1; y <= 1000; y++) P2[y] = y * y;
		for (int z = 1; z <= 100; z++) P3[z] = z * z * z;
		
		Scanner sc = new Scanner(System.in);
		for(;;)
		{
			int E=sc.nextInt();
			if (E==0) break;
			
			int m = 1<<20;
			for (int z = 100; z >= 0; z--)
			{
				int z3 = P3[z];
				for (int y = 1000; y >= 0; y--)
				{
					int y2 = P2[y];
					int x = (E - y2 - z3);
					if (x >= 0) m = Math.min(m, x + y + z);
				}
			}
			System.out.println(m);
		}
	}
}

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

int main(){
  long d;
  cin >> d;
  long n = 26, csum = 0, ccost = 0;
  vector<long> c(n),last(n);
  rep(i,n){
    cin >> c[i];
    csum += c[i];
    last[i] = 0;
  }
  vector<vector<long>> s(d,vector<long>(n));
  rep(i,d)rep(j,n)cin >> s[i][j];
  vector<vector<long>> cand;
  vector<long> score;
  random_device rd{};
  vector<long> yotei(d);
  vector<long> tmp(d);
  long final_ans = 0, final_index;

  rep(jj,20){

    long ans = 0;
    rep(i,n)last[i] = 0;
    rep(i,d)yotei[i] = rd()%n;
    rep(i,d){
      ccost += csum;
      ccost -= c[yotei[i]]*(i+1 - last[yotei[i]]);
      ans -= ccost;
      last[yotei[i]] = i+1;
      ans += s[i][yotei[i]];
    }
    int ii = 0;
    while(ii < 100000){
      long new_day = rd()%d, new_con;
      while(1){
        new_con = rd()%n;
        if(yotei[new_day] != new_con)break;
      }
      long pre_con = yotei[new_day];
      yotei[new_day] = new_con;
      long tmpans = 0;
      ccost = 0;
      rep(i,n)last[i] = 0;
      rep(i,d){
        tmp[i] = yotei[i];
        ccost += csum;
        ccost -= c[yotei[i]]*(i+1 - last[yotei[i]]);
        tmpans -= ccost;
        last[yotei[i]] = i+1;
        tmpans += s[i][yotei[i]];
      }
      if(tmpans < ans)yotei[new_day] = pre_con;
      else{
        ans = tmpans;
        cand.push_back(tmp);
      }
      ii++;
    }
    if(final_ans < ans){
      final_ans = ans;
      final_index = int(cand.size()-1);
    }
  }
  rep(i,d)cout << cand[final_index][i]+1 << endl;
  return 0;
}

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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

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

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
	long long d, t, s;
	cin >> d >> t >> s;

	if (t * s >= d) {
		cout << "Yes" << nl;
	}
	else {
		cout << "No" << nl;
	}
}

int main()
{


	FIO;

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    k--;
    cin >> s;
    if(s[k] == 'A'){
        s[k] = 'a';
    }else if(s[k] == 'B'){
        s[k] = 'b';
    }else{
        s[k] = 'c';
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
#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 LL long long
#define MOD 998244353
#define FACT_MAX 1000000

int n,k;
LL mod = MOD;

LL fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0;
    if(k==n || k==0) return 1;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};

int main(){
  cin>>n>>k;
  LL ret=0;
  Combinatrics c;
  REP(i,k+1){
    if(i < k - i || i < n)continue;
    if(i==k-i){
      if(2*i-n+2>k)
	ret+=c.nck(k-1,i);
      else
	ret+=c.nck(k-1,i)-c.nck(k-1,k-2*i+n-2);
    }else
      ret+=(2*i-k>=n)?c.nck(k,i):c.nck(k,i)-c.nck(k,2*i-n+1);
    //cerr<<i<<" "<<ret<<endl;
    ret%=mod;
  }
  cout<<(ret+mod)%mod<<endl;
  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define do(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i < (k); i ++)
#define dec(i, j, k) for(int i = j; i >= (k); i --)
#define mfil(x, k) memset(x, k, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y, true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y, true) : false; }
struct __init { __init()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cout.precision(16); cout << fixed;
    srand(time(0) ^ ul(new char));
} } static __init__;
/* default code ends here */

const int maxn = 1e5 + 10;
int n;
int a[maxn];

void solve1()
{
    int ans = 0;
    do(i, 2, n)
        ans += a[i];
    ans -= a[1];
    cout << ans << '\n';
    int cur = a[1];
    do(i, 2, n - 1)
    {
        cout << cur << ' ' << a[i] << '\n';
        cur -= a[i];
    }
    cout << a[n] << ' ' << cur << '\n';
}

void solve2()
{
    reverse(a + 1, a + n + 1);
    int ans = 0;
    do(i, 2, n)
        ans -= a[i];
    ans += a[1];
    cout << ans << '\n';
    int cur = a[1];
    do(i, 2, n)
    {
        cout << cur << ' ' << a[i] << '\n';
        cur -= a[i];
    }
}

void solve3()
{
    int pos = 1;
    while(a[pos] < 0)
        pos ++;
    int ans = 0;
    do(i, 1, n)
        ans += abs(a[i]);
    cout << ans << '\n';
    int cur = a[1];
    do(i, pos, n - 1)
    {
        cout << cur << ' ' << a[i] << '\n';
        cur -= a[i];
    }
    cout << a[n] << ' ' << cur << '\n';
    cur = a[n] - cur;
    do(i, 2, pos - 1)
    {
        cout << cur << ' ' << a[i] << '\n';
        cur -= a[i];
    }
}

int main()
{
    cin >> n;
    do(i, 1, n)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    if(a[1] >= 0)
        solve1();
    else if(a[n] < 0)
        solve2();
    else solve3();
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()



using namespace std;





int main() {
  ll K,N; cin>>K>>N;
  vector <ll> A;
  REP(i,N){
    ll a; cin>>a;
    A.push_back(a);
  }

  ll ans = K;
  ll ma  = -1;

  REP(i,N){
    ll dist = 0;
   if(i != N-1) dist = A[i+1] - A[i];
   else dist = A[0] + (K - A[i]);
    ma = max(ma,dist);
  }

  ans -=ma;

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 2420
#!/usr/bin/env python3


def judge(d, t, s):
    return t * s >= d


def main():
    d, t, s = (int(z) for z in input().split())
    if judge(d, t, s):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

int main()
{
    int n, m;
    cin >> n >> m;
    int x[100002], b[100002]{0};
    for(int i = 0; i < n; i++){
        cin >> x[i];
        b[x[i]]++;
    }
    int s[100002]{0}, r[100002]{0};
    for(int i = 1; i <= 100000; i++){
        s[i % m] += b[i];
        r[i % m] += b[i] / 2;
    }
    int ans = s[0] / 2;
    for(int i = 1; i <= (m - 1) / 2; i++){
        if(s[i] > s[m - i]) ans += s[m - i] + min(r[i], (s[i] - s[m - i]) / 2);
        else ans += s[i] + min(r[m - i], (s[m - i] - s[i]) / 2);
    }
    if(m % 2 == 0) ans += s[m / 2] / 2;
    cout << ans << endl;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), ans(n);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    a[i]--;
    ans[a[i]]++;
  }
  for (auto &v : ans) {
    cout << v << endl;
  }

  return 0;
}

Measured memory_bytes: 4832
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        String ans="";
  		int c=0;
		String s="abcdefghijklmnopqrstuvwxyz";
  		String[] a=s.split("");
       
  
  		while(n>0){
         long b1=n/(long)Math.pow(26,c);
         long b2=b1%26;
            if(b2==0){
            b2=26;
            }
         ans=a[(int)b2-1]+ans;
         n=n-(long)Math.pow(26,c)*b2;
         c++;
           
        }
		

    	System.out.println(ans);
    }
}

Measured memory_bytes: 39736
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define eb emplace_back
#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int m, k;
	cin >> m >> k;
	if ((1 << m) - 1 < k || (m == 1 && k == 1)) {
		cout << -1;
		return;
	}
	if (!k) {
		for (int i = 0; i < (1 << m); i++) cout << i << " " << i << " ";
		return;
	}
	for (int i = 0; i < (1 << m); i++) if (i != k) cout << i << " ";
	cout << k << " ";
	for(int i = (1 << m) - 1;i>=0;i--) if (i != k) cout << i << " ";
	cout << k;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

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

typedef long long int64;
const int MAX = 3e5 + 5;
int n, m;
int64 tree[4 * MAX], lazy[4 * MAX], dp[MAX];
vector <pair <int, int> > s[MAX];

void prop(int x, int st, int nd) {
	tree[x] += lazy[x];

	if(st != nd) {
		lazy[2 * x] += lazy[x];
		lazy[2 * x + 1] += lazy[x];
	}

	lazy[x] = 0;
}

void upd(int x, int st, int nd, int a, int b, int64 v) {
	prop(x, st, nd);

	if(st > b || nd < a)
		return;

	if(st >= a && nd <= b) {
		lazy[x] = v;
		prop(x, st, nd);
		return;
	}

	int mid = (st + nd) >> 1;

	upd(2 * x, st, mid, a, b, v);
	upd(2 * x + 1, mid + 1, nd, a, b, v);

	tree[x] = min(tree[2 * x], tree[2 * x + 1]);
}

int64 query(int x, int st, int nd, int a, int b) {
	prop(x, st, nd);

	if(st > b || nd < a)
		return LLONG_MAX;

	if(st >= a && nd <= b)
		return tree[x];

	int mid = (st + nd) >> 1;

	return min(query(2 * x, st, mid, a, b), query(2 * x + 1, mid + 1, nd, a, b));
}

int main() {
	scanf("%d%d", &n, &m);

	int64 sum = 0;
	for(int i = 1; i <= m; i++) {
		int l, r, c;
		scanf("%d%d%d", &l, &r, &c);
		s[l].push_back({r, c});
		sum += c;
	}

	for(int i = n; i > 0; i--) {
		upd(1, 1, n, i, i, dp[i + 2]);

		for(auto o : s[i])
			upd(1, 1, n, o.first, n, o.second);

		dp[i] = min(dp[i + 1], query(1, 1, n, i, n));
	}

	printf("%lld\n", sum - dp[1]);
	return 0;
}

Measured memory_bytes: 27008
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

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

int main()
{
    string S;
	cin >> S;
	ll len=S.size();
	ll mod=1000000007;
	vector < vector <ll> > dp(len+2, vector<ll>(4, 0));
	dp[len+1][3]=1;
	for(int now=len; now>=1; now--){
		for(int i=0; i<4; i++){
			dp[now][i]=dp[now+1][i]%mod;
		}
		if(S[now-1]=='A'){
			dp[now][0]=(dp[now+1][0]+dp[now+1][1])%mod;
		}else if(S[now-1]=='B'){
			dp[now][1]=(dp[now+1][1]+dp[now+1][2])%mod;
		}else if(S[now-1]=='C'){
			dp[now][2]=(dp[now+1][2]+dp[now+1][3])%mod;
		}else{
			dp[now][0]=(dp[now+1][0]*3+dp[now+1][1])%mod;
			dp[now][1]=(dp[now+1][1]*3+dp[now+1][2])%mod;
			dp[now][2]=(dp[now+1][2]*3+dp[now+1][3])%mod;
			dp[now][3]=dp[now+1][3]*3%mod;
		}
	}
    cout << dp[1][0]%mod << endl;

    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    string S;
    cin>>N>>S;
    int counter=0;
    rep(i,N) if(S[i]=='E') counter++;
    int ans=counter;
    rep(i,N) {
        if(S[i]=='E') counter--;
        if(i>=1) {
            if(S[i-1]=='W') counter++;
        }
        ans=min(ans,counter);
    }
    cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int tiles[51][51];
int w,h;

void dfs(int x,int y){
    tiles[x][y]=0;

    for(int dx=-1;dx<=1;dx++){
      for(int dy=-1;dy<=1;dy++){
        int nx=x+dx,ny=y+dy;

        if(0<=nx && nx<w && 0<=ny && ny<h &&
          tiles[nx][ny] == 1) dfs(nx,ny);
        }
    }
}

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

  while(true){
    for(int i=0;i<51;i++){
      for(int j=0;j<51;j++){
        tiles[i][j]=0;
      }
    }
    int ans=0;
    cin >> w >> h;
    if(w==0) break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> tiles[j][i];
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(tiles[j][i]==1){
           dfs(j,i);
           ans++;
         }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3196
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 100050;
int N;
long long A[MAX_N];

bool solve() {
    if (N == 1) {
        return true;
    }

    long long one_proc_num = 0;
    long long total = 0;
    long long min = A[1];

    for (int i = 1; i <= N; i++) {
        total += A[i];
        one_proc_num += i;
        min = std::min(min, A[i]);
    }

    if (total % one_proc_num != 0) {
        return false;
    }

    long long NP = total / one_proc_num;

    if (min < NP) {
        return false;
    }

    long long tmp_proc_num = 0;
    for (int i = 1; i <= N; i++) {
        long long tmp = A[i] + NP;
        int next = i == N ? 1 : i + 1;
        if (tmp < A[next]) {
            return false;
        } else if ((tmp - A[next]) % N != 0) {
            return false;
        } else {
            tmp_proc_num += (tmp - A[next]) / N;
        }
    }
    return tmp_proc_num == NP;
}

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }

    if (solve()) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1024
import java.math.BigInteger
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.nextLong()
    for (a in -1000L..1000L) {
        for (b in -1000L..1000L) {
            if (a * a * a * a * a - b * b * b * b * b == x) {
                println("$a $b")
                return
            }
        }
    }
}

Measured memory_bytes: 36404
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  long M,D;
  in(M,D);
  long ans=0;
  up(i,1,M){
    up(j,1,D){
      long d1=j%10,d2=j/10;
      if(d1>=2&&d2>=2&&i==d1*d2)ans++;
    }
  }
  out(ans);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,m;
  cin >>n>>m;
  int a[60],b[60];
  for(int i=0;i<m;i++){
    cin >>a[i]>>b[i];
  }
  for(int i=1;i<=n;i++){
    int count=0;
    for(int j=0;j<m;j++){
    if(i==a[j]||i==b[j]) count++;
  }
   cout<<count <<endl;
  }
}


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

using namespace std;

int main() {
	int n, ans = 0, f, s = 1e6;
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		f = s;
		cin >> s;
		ans += min(f, s);
	}
	ans += s;
	cout << ans;

}

Measured memory_bytes: 256