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

vector<int> mkper(vector<int> p, int n){
  vector<int> perm(n);
  for (int i=0;i<n;i++){
    perm[i] = i;
  }
  vector<int> nex(n);
  int peak = n;
  for (int i=0;i<n;i++){
    nex[i] = perm[p[i]];
    for (int j=p[i];j<peak-1;j++){
      perm[j] = perm[j+1];
    }
    peak -= 1;
  }
  return nex;
}
int main(){
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r(R);
  for (int i=0;i<R;i++){
    cin >> r[i];
    r[i] -= 1;
  }
  vector<vector<long long>> d(N, vector<long long>(N, 100000000000));
  int A, B, C;
  for (int i=0;i<M;i++){
    cin >> A >> B >> C;
    d[A-1][B-1] = C;
    d[B-1][A-1] = C;
  }
  for (int k=0;k<N;k++){
    for (int i=0;i<N;i++){
      for (int j=0;j<N;j++){
        if (d[i][j] > d[i][k] + d[k][j]){
          d[i][j] = d[i][k] + d[k][j];
        }
      }
    }
  }
  vector<int> L(R);
  vector<int> LL(R);
  long long m = 100000000000000, tmp = 0, fact = 1, tmp2;
  for (int i=0;i<R;i++){
    fact *= i + 1;
  }
  for (int i=0;i<fact;i++){
    tmp2 = i;
    for (int j=0;j<R;j++){
      LL[R-j-1] = tmp2 % (j+1);
      tmp2 /= j + 1;
    }
    L = mkper(LL, R);
    tmp = 0;
    for (int j=0;j<R-1;j++){
      tmp += d[r[L[j]]][r[L[j+1]]];
    }
    if (m > tmp){
      m = tmp;
    }
  }
  cout << m << endl;
  return 0;
}

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

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            var n = Console.ReadLine().ToLong();
            var ais = new List<long>();
            for (int i = 0; i < n; i++)
            {
                ais.Add(Console.ReadLine().ToLong());
            }

            var max = ais.Max();
            if (ais.Count(x => x == max) == 1)
            {
                var dist = ais.Distinct().OrderBy(x => x).ToArray();
                var next = dist[dist.Length - 2];
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine(ais[i] == max ? next : max);
                }
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine(max);
                }
            }
        }
    }

    public static partial class Program
    {
        //テンプレここから
        private static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb);
        public static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb);
        public static long ToLong(this double ddd) => (long) ddd;
        public static long ToLong(this string str) => long.Parse(str);
        public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        public static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong();
        public static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        public static long Sign(this long iii) => Math.Sign(iii);
        public static bool IsEven(this long iii) => iii % 2 == 0;
        public static readonly int[] Dx = {0, -1, 0, 1};
        public static readonly int[] Dy = {-1, 0, 1, 0};
        public const int MOD = 1000000007;
        public const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string alphabet = "abcdefghijklmnopqrstuvwxyz";
        public static long ToLong(this char ccc) => ccc.ToString().ToLong();
        public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

        public static string JoinToStr(this IEnumerable<long> array, string sep = "")
            => array.Select(xxx => xxx.ToString()).Join(sep);

        //テンプレここまで
    }
}

Measured memory_bytes: 33372
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define fl(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rfl(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        forloop(n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define section(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));

const long long INF64 = 1e18;





void solve()
 { 
   int n;
   cin>>n;
   vec<pair<int,pair<int,int> > >v;
      fl(i,0,n-1)
         {
         	int x,y,z;
         	cin>>x>>y>>z;
         	v.pb({x,{y,z}});


         }
        int dp[n][3];
        memset(dp,-1,sizeof(dp));
        dp[0][0]=v[0].F;
        dp[0][1]=v[0].S.F;
        dp[0][2]=v[0].S.S;
        for(int i=1;i<n;i++)
        	  {
                  dp[i][0]=max(dp[i-1][1]+v[i].F,dp[i-1][2]+v[i].F);
                  dp[i][1]=max(dp[i-1][0]+v[i].S.F,dp[i-1][2]+v[i].S.F);
                  dp[i][2]=max(dp[i-1][0]+v[i].S.S,dp[i-1][1]+v[i].S.S);






        	  }
cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

 }



  








 



signed main()
{fast
	int t;
   //cin>>t;
	t=1;

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












Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, s = 1; cin >> n;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(a == s) s++;
    }
    s--;
    if(s) cout << n - s;
    else cout << -1;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int d = in.nextInt();
		int n = in.nextInt();
		if (n == 100)
			n = 101;
		for (int i = 0; i < d; i++)
			n *= 100;
		System.out.println(n);
		in.close();
	}
}

Measured memory_bytes: 21844
import java.io.*;
import java.util.*;

public class Main {
  private static boolean solve(char[] ss, char[] ts) {
    Arrays.sort(ss);
    String s = new String(ss);
    
    Arrays.sort(ts);
    StringBuffer sb = new StringBuffer();
    for (int i = ts.length - 1; i >= 0; i--) {
      sb.append(ts[i]);
    }
    String t = sb.toString();
    return s.compareTo(t) < 0;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    char[] ss = reader.nextCharArray();
    char[] ts = reader.nextCharArray();
    out.println(solve(ss, ts) ? "Yes" : "No");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 23252
#ALDS1_7-B Binary Trees
class Node:
    def __init__(self, nid):
        self.nid = nid
        self.parent = None
        self.sibling = None
        self.degree = self.funcDeg
        self.depth = self.funcDep
        self.height = self.funcH
        self.type = self.funcT
        self.left = None
        self.right = None
        
    def funcDeg(self):
        deg = 0
        if self.left:
            deg+=1
        if self.right:
            deg+=1
        return deg
        
    def funcDep(self):
        if self.parent:
            parentD = self.parent.depth()
        else:
            parentD = -1
        return parentD + 1
    
    def funcH(self):
        if self.left:
            leftH = self.left.height()
        else:
            leftH = -1
        if self.right:
            rightH = self.right.height()
        else:
            rightH = -1
        return max(leftH,rightH) + 1
        
    def funcT(self):
        if not self.parent:
            return "root"
        elif self.left or self.right:
            return "internal node"
        else:
            return "leaf"
        
    def dump(self):
        txt = "node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"
        print (txt.format(self.nid, -1 if not self.parent else self.parent.nid, -1 if not self.sibling else self.sibling.nid, self.degree(), self.depth(), self.height(), self.type()))
        
n = int(input())
D = {}
for i in range(n):
    D[i] = Node(i)
for i in range(n):
    nid, left, right = [int(i) for i in input().split()]
    if not left == -1 and not right == -1:
        D[right].sibling = D[left]
        D[left].sibling = D[right]
        
    if not left == -1:
        D[nid].left = D[left]
        D[left].parent = D[nid]
            
    if not right == -1:
        D[nid].right = D[right]
        D[right].parent = D[nid]
        
for i in range(n):
    D[i].dump()


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

string s;
int n;
bool c = true;

void solve(int h, int o)
{
  if (s[h - 1] != s[o - 1])
  {
    cout << "No" << endl;
    exit(0);
  }
  for (int i = h - 1; i < (o - 1) / 2; i++)
  {
    if (s[i] != s[(o - i) - 1])
    {
      cout << "No" << endl;
      exit(0);
    }
  }
}

int main()
{
  cin >> s;
  n = s.length();
  solve(1, n);
  solve(1, (n - 1) / 2);
  solve((n + 3) / 2, n);
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<pii, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N, Q;
    cin >> N >> Q;
    dsu d(N);
    for (int i = 0; i < Q; ++i) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0)
            d.merge(u, v);
        else
            cout << d.same(u, v) << '\n';
    }

    return 0;
}


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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        a: usize,
        b: usize
    }
    if a * b % 2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>

using namespace std;

double PI = 3.14159265358;

int main()
{
    double a,b,h,m;
    cin >> a >> b >> h >> m;

    double mp = PI*m/30;
    double hp = PI/12/30*(h*60+m);

    double diff = abs(mp-hp);
    if (diff > PI) {diff = 2*PI-diff;}

    double ans = sqrt(a*a + b*b - 2*a*b*cos(diff));
    printf("%.15f\n", ans);
    return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define N 305
#define db double
#define ll long long
int A,B,dist[12][12],f[N][N],d;
int cal(int a,int b)
{
	int res=0;
	for(int i=1;i<=A;i++)
		for(int j=1;j<=B;j++) res=max(res,dist[i][j]-i*a-j*b);
	return res;
}
int main()
{
	scanf("%d%d",&A,&B);
	for(int i=1;i<=A;i++)
		for(int j=1;j<=B;j++) scanf("%d",&dist[i][j]);
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++) f[i][j]=cal(i,j);
	for(int i=1;i<=A;i++)
		for(int j=1;j<=B;j++)
		{
			d=1e9;
			for(int i2=0;i2<=100;i2++)
				for(int j2=0;j2<=100;j2++)
					d=min(d,f[i2][j2]+i*i2+j*j2);
			if(d^dist[i][j]) {puts("Impossible");return 0;}
		}
	puts("Possible\n202 10401");
	for(int i=1;i<=100;i++) printf("%d %d X\n",i,i+1);
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)//if(f[i][j])
			printf("%d %d %d\n",i+1,j+102,f[i][j]);
	for(int i=1;i<=100;i++) printf("%d %d Y\n",102+i,101+i);
	puts("1 102");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; ++i) cin >> d[i];

  int sum = 0;
  for (int i = 0; i < N; ++i)
  {
    for (int j = i+1; j < N; ++j)
    {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
}


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

int partition(vector<int> &a, int p, int r) {
  int x = a[r - 1];
  int i = p;
  for (int j = p; j < r - 1; ++j) {
    if (a[j] <= x) {
      int t = a[i];
      a[i] = a[j];
      a[j] = t;
      ++i;
    }
  }
  int t = a[i];
  a[i] = a[r - 1];
  a[r - 1] = t;
  return i;
}

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

  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    a.push_back(t);
  }

  int q = partition(a, 0, n);
  for (int i = 0; i < n; ++i) {
    if (i) {
      cout << " ";
    }
    if (i == q) {
      cout << "[" << a[i] << "]";
    } else {
      cout << a[i];
    }
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3316
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = []

for i in range(n):
    count = 0
    for j in range(i,n):
        count += a[j]
        l.append(count)
l.sort(reverse=True)

le = 0
ri = 0

count = [0]*45
for i in range(44,-1,-1):
    x = 1<<i
    while ri < len(l) and l[ri] >= x:
        ri += 1
    
    for j in range(le,ri):
        for t in range(45):
            if l[j] >> t & 1:
                count[t] += 1
    
    if count[i] >= k:
        m = i
        break
    else:
        le = ri
    
check = []
for i in range(ri):
    if l[i] >> m & 1:
        check.append(l[i]%x)

ans = x
for i in range(m-1,-1,-1):
    count = 0
    for j in check:
        if j >> i & 1:
            count += 1
    if count >= k:
        x = 1<<i
        ans += x
        checkn = []
        for c in check:
            if c >> i & 1:
                checkn.append(c%x)
        check = checkn
print(ans)

Measured memory_bytes: 112688
#include <stdio.h>
#include <vector>
 
using namespace std;
 
struct Node{
    Node(){
        brother = parent = -1;
        height = depth = num_of_children = 0;
    }
    int parent,brother,depth,num_of_children,height;
    vector<int> children;
};
 
void calcDepth(Node nodes[],int root_id){
    for(int i = 0;i < nodes[root_id].num_of_children;i++){
        nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth+1;
        calcDepth(nodes,nodes[root_id].children[i]);
    }
}
 
void calcHeight(Node nodes[],int height,int parent){
    nodes[parent].height = max(nodes[parent].height,height+1);
    if(nodes[parent].parent != -1) calcHeight(nodes,height+1,nodes[parent].parent);
}
 
int main(){
    int n,id,left_id,right_id,root_id;
    scanf("%d",&n);
    Node nodes[n];
 
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&id,&left_id,&right_id);
        if(left_id != -1){
            nodes[id].children.push_back(left_id);
            nodes[id].num_of_children++;
            nodes[left_id].parent = id;
        }
        if(right_id != -1){
            nodes[id].children.push_back(right_id);
            nodes[id].num_of_children++;
            nodes[right_id].parent = id;
        }
        if(left_id != -1 && right_id != -1){
            nodes[left_id].brother = right_id;
            nodes[right_id].brother = left_id;
        }
    }
 
    for(root_id = 0; root_id < n; root_id++){
        if(nodes[root_id].parent == -1) break;
    }
 
    if(n > 1){
        calcDepth(nodes,root_id);
 
        for(int i = 0; i < n; i++){
            if(nodes[i].num_of_children == 0) calcHeight(nodes,0,nodes[i].parent);
        }
    }
 
    for(int i = 0; i < n; i++){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,"
                ,i,nodes[i].parent,nodes[i].brother,nodes[i].num_of_children,nodes[i].depth,nodes[i].height);
        if(nodes[i].parent == -1){
            printf(" root\n");
        }else if(nodes[i].num_of_children == 0){
            printf(" leaf\n");
        }else{
            printf(" internal node\n");
        }
 
    }
}


Measured memory_bytes: 2796
#include <stdio.h>


int main(){

  int n, m, i, s[1010], d[1010], g, cnt;

  while(1){
    scanf("%d %d",&n, &m);
    if(n==0 && m==0) break;

    for(i=1;i<=n;i++){
      scanf("%d", &s[i]);
    }
    for(i=1;i<=m;i++){
      scanf("%d", &d[i]);
    }

    g=1;
    cnt=0;
    for(i=1;i<=n;i++){
      g += d[i];
      g += s[g];
      cnt++;
      if(g>=n){
	printf("%d\n", cnt);
	break;
      }
    }

    
  }

  
  return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int dp[10001];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, n;
    cin >> h >> n;
    memset(dp, 127, sizeof(dp));
    dp[0] = 0;
    for (int i=0; i<n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j=1; j<=h; j++)
            dp[j] = min(dp[j], dp[max(j - a, 0)] + b);
    }
    cout << dp[h] << "\n";

    return 0;
}


Measured memory_bytes: 3672
#include <iostream>

int main() {
  int A, B, C, D;
  std::cin >> A >> B >> C >> D;

  if (A + B == C + D) {
    std::cout << "Balanced" << std::endl;
  } else if (A + B > C + D) {
    std::cout << "Left" << std::endl;
  } else {
    std::cout << "Right" << std::endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
bool echeck(ll a) { return a % 2 == 0 ? 1 : 0; }
ll comb(ll n, ll m){
  ll tmp = 1;
  for(int i = n; i >= n - m + 1; i--){
    tmp *= i;
  }
  ll temp = 1;
  for(int i = 1; i <= m; i++){
    temp *= i;
  }
  return tmp / temp;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  int ans = 0;
  rep(i,n-1)if(v[i] < v[i+1])ans++;
  cout << ans << endl;
  return 0;
} 


Measured memory_bytes: 3108
n, m = map(int, input().split())
a = list()
for i in range(n) :   #1行ずつn行まで読み込みlistに格納
 a.append(list(map(int, input().split())))
b = list()
for j in range(m) :
 b.append(int(input()))
 
for i in range(n) :
 s = 0
 for j in range(m) :
   s += a[i][j] * b[j]
 print(s)


Measured memory_bytes: 5980
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int T = Int32.Parse(args[2]);

		Console.WriteLine((T/A) * B);
	}
}





Measured memory_bytes: 11092
#include <cstdio>
int n;
int a[200005];
int box[200005];
int ans[200005];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	for (int i = n; i >= 1; i--) {
		int sum = 0;
		for (int j = i; j <= n; j += i) {
			sum += box[j];
		}
		if (sum % 2 != a[i]) {
			int upper = n / i * i;
			int flag = 0;
			for (int j = upper; j >= 1; j -= i) {
				if (box[i] == 0) {
					box[i] = 1;
					flag = 1;
					break;
				}
			}
			if (!flag) {
				printf("-1\n");
				return 0;
			}
		}
	}
	
	int m = 0;
	
	for (int i = 1; i <= n; i++) {
		if (box[i]) {
			ans[m++] = i;
		}
	}
	printf("%d\n", m);
	for (int i = 0; i < m; i++) {
		printf("%d ", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n,a,c=0;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        if (a%2==1) {c+=1;}
    }
    cout << (c%2==1 ? "NO" : "YES") << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        HashSet<int> canMake = new HashSet<int>();
        for (int i = 0; i < 1 << n; i++)
        {
            int sum = 0;
            for (int j = 0; j < n; j++)
            {
                if ((i >> j & 1) == 1) sum += a[j];
            }
            canMake.Add(sum);
        }
        var q = int.Parse(Console.ReadLine());
        var m = Console.ReadLine().Split().Select(int.Parse).ToArray();

        Console.WriteLine(string.Join("\n", m.Select(x => canMake.Contains(x) ? "yes" : "no")));
    }
}


Measured memory_bytes: 18560
#include <stdio.h>

void right_triangle (int x, int y, int z)
{
    if(x * x == y * y + z * z || y * y == z * z + x * x || z * z == x * x + y * y){
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        right_triangle(x, y, z);
    }
    return 0;
}

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

int main(){
  int N,M,i;
  int L[111111],R[111111];
  cin >> N >> M;
  for(i=0;i<=M-1;i++)
    cin >> L[i] >> R[i];
  int lmax = L[0];
  int rmin = R[0];
  for(i=0;i<=M-1;i++)
    if(lmax < L[i]) lmax = L[i];
  for(i=0;i<=M-1;i++)
    if(rmin > R[i]) rmin = R[i];
  if(rmin < lmax) cout << 0;
  if(rmin >= lmax) cout << rmin - lmax + 1;
}

Measured memory_bytes: 1024
N = int(input())
H = list(map(int, input().split()))

ans = 0
temp = 0
prev = 0
for i in range(N):
    if H[i] <= prev:
        temp += 1
    else:
        ans = max(ans, temp)
        temp = 0
    prev = H[i]
ans = max(ans, temp)
print(ans)


Measured memory_bytes: 63984
N=int(input())
A=[int(x) for x in input().split()]

a4=0
a1=0
for i in range(N):
  if A[i]%4==0:
    a4+=1
  elif A[i]%2==1:
    a1+=1

if (a1+a4)==N:
  if a4+1>=a1:
    print("Yes")
  else:
    print("No")
else:
  if a4>=a1:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

vector<string> s;
vector<string> t;

int calc(string now) {
    int len = now.size();

    if (now[0] == '*') {
        reverse(now.begin(), now.end());
        now.pop_back();
        auto down = lower_bound(t.begin(), t.end(), now);
        now.push_back('{');
        auto up = upper_bound(t.begin(), t.end(), now);
        return up - down;
    } else if (now[len - 1] == '*') {
        now.pop_back();
        auto down = lower_bound(s.begin(), s.end(), now);
        now.push_back('{');
        auto up = upper_bound(s.begin(), s.end(), now);
        return up - down;
    } else {
        return upper_bound(s.begin(), s.end(), now) - lower_bound(s.begin(), s.end(), now);
    }
}

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

    for (int i = 0; i < n; i++) {
        string now;
        cin >> now;
        s.push_back(now);
        reverse(now.begin(), now.end());
        t.push_back(now);
    }
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    for (int i = 0; i < m; i++) {
        string now;
        cin >> now;

        int que = -1;
        for (int j = 0; j < now.size(); j++)
            if (now[j] == '?')que = j;

        if (que >= 0) {
            int ret = 0;
            for (int i = 'a'; i <= 'z'; i++) {
                now[que] = i;
                ret += calc(now);
            }
            cout << ret << endl;
        } else {
            cout << calc(now) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 11792
n=gets.to_i
hash={}
n.times do
    s=gets.chomp
    if hash[s].nil?
        hash[s]=1
    else
        hash[s]+=1
    end
end

m=gets.to_i
m.times do
    s=gets.chomp
    hash[s]-=1 unless hash[s].nil?
end

p [hash.values.max,0].max

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

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in); 
    int[] heights = new int[10];
    for(int i=0;i<10;i++) {
      int height = sc.nextInt();
      heights[i] = height;
    }
    Arrays.sort(heights);
    System.out.println(heights[9]);
    System.out.println(heights[8]);
    System.out.println(heights[7]);
  }
}

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

int main()
{
	bool ans[4]={0};
	int a,b;
	cin>>a>>b;
	ans[a]=1;
	ans[b]=1;
	for(int i=1;i<=3;i++)
		if(ans[i]==0)
			cout<<i<<"\n";

}

Measured memory_bytes: 256
#include <vector>

std::vector<int> strongly_connected_components(const std::vector<std::vector<int>> &adj) {
    int n = adj.size();
    std::vector<int> vs;
    {
        std::vector<bool> visited(n);
        static auto dfs = [&](auto &&self, int cur) -> void {
            if (visited[cur]) { return; }
            visited[cur] = true;
            for (int i = 0; i < adj[cur].size(); i++) { self(self, adj[cur][i]); }
            vs.push_back(cur);
        };
        for (int i = 0; i < n; i++) { dfs(dfs, i); }
    }
    std::vector<int> ret(n);
    {
        std::vector<bool> visited(n);
        std::vector<std::vector<int>> radj(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < adj[i].size(); j++) { radj[adj[i][j]].push_back(i); }
        }
        int k = 0;
        static auto dfs = [&](auto &&self, int cur) -> void {
            visited[cur] = true;
            ret[cur] = k;
            for (int i = 0; i < radj[cur].size(); i++) {
                if (!visited[radj[cur][i]]) { self(self, radj[cur][i]); }
            }
        };
        for (int i = n - 1; i >= 0; i--) { if (!visited[vs[i]]) { dfs(dfs, vs[i]), k++; }}
    }
    return ret;
}

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

int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> adj(V);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        adj[s].push_back(t);
    }
    vector<int> cmp = strongly_connected_components(adj);
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int u, v;
        cin >> u >> v;
        cout << (cmp[u] == cmp[v]) << endl;
    }
}


Measured memory_bytes: 4128
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
v=lnii()
v.sort()

ans=v[0]
for i in range(1,n):
  ans=(ans+v[i])/2

print(ans)

Measured memory_bytes: 9084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int mod = 1000000007;

int main(){
    int N;
    cin >> N;
    long long res = 1;
    for (int i = 1; i <= N; ++i) {
        res = (res * i) % mod;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split(' '))
H = list(map(int, input().split(' ')))

Best = 0
Bestabs = abs(A - (T-H[0]*0.006))
for i in range(N):
    Ti = T - H[i]*0.006
    if Bestabs > abs(A-Ti):
        Best = i
        Bestabs = abs(A-Ti)

print(str(Best+1))

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	if(N%2==0){
		printf("%d\n",N*(N-1)/2-N/2);
		for(int i=1;i<=N;++i){
			for(int j=i+1;j<=N;++j){
				if(i+j!=N+1){
					printf("%d %d\n",i,j);
				}
			}
		}
	}else{
		printf("%d\n",N*(N-1)/2-N/2);
		for(int i=1;i<=N;++i){
			for(int j=i+1;j<=N;++j){
				if(i+j!=N){
					printf("%d %d\n",i,j);
				}
			}
		}
	}
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Integer[] point = new Integer[n];
		for (int i = 0; i < n; i++) {
			point[i] = scan.nextInt();
		}
		
		Arrays.sort(point, Collections.reverseOrder());
		
		int sum = 0;
		for (int i = 0; i + 1 < point.length; i += 2) {
			sum += point[i] - point[i + 1];
		}
		if (point.length % 2 == 1) {
			sum+= point[point.length - 1];
		}
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 21588
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        }

        // answer
        System.out.println(count);
    }
}

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            // var ab = new SortedList<long,long>();
            var ab = new List<KeyValuePair<long,long>>();
            for (int i = 0; i < nm[0]; i++)
            {
                var input =  Console.ReadLine().Split().Select(long.Parse).ToArray();
                ab.Add(new KeyValuePair<long,long>(input[0],input[1]));
            }
            ab = ab.OrderBy(x => x.Key).ToList();
            
            int index = 0;
            long sum = 0;
            long count = 0;


            while(index <nm[0])
            {
                if(nm[1] - count >=ab[index].Value)
                {
                    sum += (ab[index].Key)*(ab[index].Value);
                    count+=ab[index].Value;
                }
                else
                {
                    sum += (nm[1]-count) * ab[index].Key;
                    break;
                }
                index++;
            }

            Console.WriteLine(sum);

        }
    }
}


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

int main()
{
    int n;
    cin >> n;
    long long ans = 1;
    long double check = 1;
    for (int i = 0; i < n; i++)
    {
        long long a;
        cin >> a;
        check *= a;
        ans *= a;
    }
    if (check > 1e18)
        cout << -1 << endl;
    else
        cout << ans << endl;
}

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

int main(){
	int ans,a,b,c,d,n;

	while(cin>>n){
	ans = 0;
		for(a = 0;a <= 9;a++){
			for(b = 0;b <= 9;b++){
				for(c = 0;c <= 9;c++){
					for(d = 0;d <= 9;d++){
						if(a+b+c+d==n)
						ans++;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

vector< vector<int> > nexts;
vector< int > depth;
// メモ化再帰
// depth[i] = iノードからの最大深さ
// next[fi][ti] = fiの隣接リスト

// depth[u] を返す
// max(depth[forearch(next[u])]+1)を返す
int sdepth( int u ){
    if( depth[u] != -1 ) return depth[u];
    depth[u] = 0;
    for( int i : nexts[u] ){
        depth[u] = max( depth[u] , 1+sdepth(i) );
    }
    return depth[u];
}

int main() {

    int N,M;
    int a,b;
    Scd2(N,M);
    depth.assign(N+1,-1);
    nexts.resize(N+1);
    Rep(i,M){
        Scd2(a,b);
        nexts[a].push_back(b);
    }



    int ans = 0;
    Rep(i,N+1){
        ans = max( ans, sdepth(i) );
    }
    Rep(i,N+1){
        ans = max( ans, sdepth(i) );
    }
    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 8192
from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin,stdout
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math
import math
import time
from queue import Queue
# PradeepGhosh_2017076

def seive(n):
	l=[True]
	l=l*(n+1)
	for i in range(2,int(sqrt(n))+1):
		if(l[i]==True):
			val=i*i
			while(val<len(l)):
				l[val]=False
				val+=i
	prime=[]
	for i in range(2,len(l)):
		if(l[i]==True):
			prime.append(i)
	return prime

def dp(l,i,n,val,ans):
	if(i>=n or val<0):
		return 1000000
	elif(val==0):
		return 0
	else:
		if(ans[i]==1000000):
			ans[i]=min(min(1+dp(l,i+1,n,val-l[i],ans),1+dp(l,i,n,val-l[i],ans)),dp(l,i+1,n,val,ans))
		return ans[i]
from queue import Queue
def factors(n):
	l=[]
	for i in range(1,int(sqrt(n))+1):
		if(n%i==0):
			if(n//i==i):
				l.append(i)
			else:
				l.append(i)
				l.append(n//i)
	return l
def check1(s,v,x):
	while(True):
		if(v not in s):
			return v
		else:
			v-=1
def check2(s,v,x):
	while(True):
		if(v not in s):
			return v
		else:
			v+=1

def up(n):
	j=n-1
	while(j>0):
		if(n%j==0):
			break
		j-=1
	return j		
def fac(n):
	c=1
	i=1
	while(i<=n):
		c*=i
		i+=1
	return c
def check_happy(n):
	ss=set()
	print(n)
	while(n!=1):
		val=n
		s=0
		print(val)
		while(val!=0):
			s+=(val%10)**2
			val=val//10
		print(val)
		print("hi")
		if(val in ss):
			return False
		else:
			n=val
			ss.add(n)
	return True
if __name__ == '__main__':
	t=int(input())
	ac=0
	wa=0
	tle=0
	re=0
	for i in range(t):
		s=str(input())
		if(s=="AC"):
			ac+=1
		elif(s=="WA"):
			wa+=1
		elif(s=="TLE"):
			tle+=1
		elif(s=="RE"):
			re+=1
	s1="AC"+" x "+str(ac)
	s2="WA"+" x "+str(wa)
	s3="TLE"+" x "+str(tle)
	s4="RE"+" x "+str(re)
	print(s1)
	print(s2)
	print(s3)
	print(s4)

Measured memory_bytes: 10724
#include<bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,w;
    cin>>n>>w;
    long long int weight[n+1],value[n+1];
    for(long long int i=1;i<=n;i++)
    cin>>weight[i]>>value[i];
    long long int ans[n+1][w+1];
    for(long long int i=0;i<=n;i++)
    ans[i][0]=0;
    for(long long int i=0;i<=w;i++)
    ans[0][i]=0;
    for(long long int i=1;i<=n;i++)
    {
        for(long long int j=1;j<=w;j++)
        {
            if((j-weight[i])>=0)
            {
                long long int fake=j-weight[i];
                ans[i][j]=max(ans[i-1][j],ans[i-1][fake]+value[i]);
            }
            else
            ans[i][j]=ans[i-1][j];
        }
    }
    cout<<ans[n][w]<<endl;
    //return 1;
}

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

constexpr int hax = 500;

int h, w;
int tab[hax][hax];

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

    cin >> h >> w;

    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
        {
            char c; cin >> c;
            if (c == '#')
                tab[i][j] = 3;
        }

    for (int i = 0; i < h; ++i)
        tab[i][0] += 1, tab[i][w - 1] += 2;

    for (int i = 0; i < h; ++i)
        for (int j = 1; j < w - 1; ++j)
            tab[i][j] |= (i & 1? 2 : 1);

    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (tab[i][j] & 1)
                cout << '#';
            else
                cout << '.';
        }
        cout << '\n';
    }


    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (tab[i][j] & 2)
                cout << '#';
            else
                cout << '.';
        }
        cout << '\n';
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl t(n);
    ll sum = 0;
    rep(i, n) {
        cin >> t[i];
        sum += t[i];
    }

    ll m;
    cin >> m;

    vl p(m), x(m);
    rep(i, m) {
        cin >> p[i] >> x[i];
        p[i]--;
    }

    rep(i, m) {
        out(sum - t[p[i]] + x[i]);
    }

    re0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
s=input()
x,y=0,0
for i in range(n):
    if s[i]=='a':
        if x+y<a+b:
            x+=1
            print("Yes")
        else:
            print("No")
    elif s[i]=='b':
        if x+y<a+b and y<b:
            y+=1
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 53208
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define print(a) cout<<(a)<<endl;
#define to_ll(b) stoll(b)
#define MOD 1000000007

int main(){
	ll N,K;cin>>N>>K;
	ll ans=0;
	vector<char> vec(K);
	rep(i,0,K){
		char a; cin>>a;
		vec[i]=a;
	}
	while(true){
		string n=to_string(N);
		bool x=true;
		rep(i,0,n.size()){
			rep(j,0,K){
				if(n.at(i)==vec[j]){
					x=false;
					//print(x)
					break;
				}
			}
		}
		
		if(x==false){
			N++;
		}
		else{
			ans=N;
			break;
		}

	}
	//if(ans!=0) break;
	print(ans)
	return 0;
}

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

class STRING : public string {
public:
  STRING() {}
  STRING(const string& rstr) { assign(rstr); }
  STRING& MakeUpper() {
    for (int iPos = 0; iPos < size(); iPos++) {
      at(iPos) = toupper(at(iPos));
    }
    return *this;
  }
  STRING& MakeLower() {
    for (int iPos = 0; iPos < size(); iPos++) {
      at(iPos) = tolower(at(iPos));
    }
    return *this;
  }
};

int main(void)
{
  int i,k,m;
  STRING w,s[1001];

  cin >> w;
  w = w.MakeUpper();

  k = 0;
  do{
    k = k + 1; 
    cin >> s[k];
  }while(s[k] != "END_OF_TEXT");

  m = 0;
  for(i = 1; i <= k; i++){
    if(s[i].MakeUpper() == w)
      m = m + 1;
  }

  cout << m << endl;

  return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,k,ans=0;
  cin >>n>>k;
  vector<int>vec(n);
  rep(i,n){
    int l;
    cin>>l;
    vec.at(i)=l;
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  rep(j,k){
    ans+=vec.at(j);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define sec second
#define pii pair<int, int>
int n, m, k, x, y, sum, ans;
char s[200005];
int main () {
	scanf("%s", s);
	n=strlen(s);
	ans=n;
	stack<int>st;
	for (int i=0; i<n; i++) {
		if (s[i]=='S') {
			st.push(1);
		} else {
			if (!st.empty()) {
				st.pop();
				ans-=2;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;
    int come[120000] = {0};
    come[0]++;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        come[a]++;
        come[b + 1]--;
    }
    for (int i = 1; i < 120000; i++)
        come[i] += come[i - 1];
    int res = 1;
    for (int i = 2; i < 120000; i++)
    {
        if (i <= come[i])
            res = i;
    }
    cout << res - 1 << endl;
}


Measured memory_bytes: 3672
#include<stdio.h>
#include<ctype.h>
#include<vector>
#include<map>
typedef std::map<int,int>M;
typedef M::iterator I;
typedef std::pair<int,int>P;
std::vector<P>v;
int x[10];
int F(char*&p,int n)
{
	if(isdigit(*p))
		return -*p+'0';
	v.push_back(P(0,0));
	int s=v.size();
	v[n].first=F(++p,s);
	s=v.size();
	v[n].second=F(p+=2,s);
	++p;
	return n;
}
M G(int i)
{
	M m;
	if(i<0)m[x[-i]]=1;
	else
	{
		M a(G(v[i].first)),b(G(v[i].second));
		for(I p=a.begin();p!=a.end();++p)for(I q=b.begin();q!=b.end();++q)
		{
			int a=p->first,b=q->first,c=p->second*q->second;
			m[a&b]+=c;
			m[a|b]+=c;
			m[a^b]+=c;
		}
	}
	return m;
}
int main()
{
	int n,i,j,t;
	char*p,s[512];
	v.reserve(64);
	while(fgets(s,512,stdin),*s-'E')
	{
		v.clear();
		scanf("%d",&n);
		for(i=1;i<=n;++i)for(x[i]=j=0;j<4;++j)scanf("%d",&t),x[i]=x[i]*2+t;
		t=F(p=s,0);
		printf("%d\n",t?x[-t]==15:G(0)[15]);
		fgets(s,512,stdin);
	}
	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline

'''

'''

x, n = map(int, input().split())
p = set(map(int, input().split()))

l, r = x,x 

if not(x in p):
    print(x)
else:
    while True:
        if not(l in p):
            print(l)
            break
        elif not(r in p):
            print(r)
            break

        l -= 1
        r += 1
    








Measured memory_bytes: 61860