akhauriyash/Code-Regression huggingface dataset:
N = int(input())
X = list(map(int, input().split()))

ans = 10000000000
for i in range(min(X), max(X) + 1):
    tmp_ans = 0
    for j in range(N):
        tmp_ans += (X[j] - i) ** 2 
    ans = min(ans, tmp_ans)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define maxn 10010
typedef long long ll;
typedef long double ld;
const int MINI INT_MIN;
const ll MINL LLONG_MIN;
int k;
double a,b,l;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>k;
    cin>>a>>b;
    l=ceil(a/k);
    if (l*k>=a && l*k<=b) cout <<"OK"<< endl;
    else cout <<"NG"<< endl;
}


Measured memory_bytes: 3756
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<utility>
#include<vector>
using namespace std;

int n;
map<string, int> m;
vector<pair<int, string>> v;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        char s[11];
        scanf("%s", s);
        string str = s;
        m[str] += 1;
    }
    for (auto &i : m) v.emplace_back(i.second, i.first);
    sort(v.begin(), v.end());
    for (auto &i : v) {
        if (i.first < v.back().first) continue;
        cout << i.second << endl; 
    }
    return 0;
}


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

int main() {
    int a,b,cnt;
    cin>>a>>b;
    cnt=a+b;
    if(a%3==0 || b%3==0 || cnt%3==0) {
        cout<<"Possible"<<endl;
    }
    else cout<<"Impossible"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1, 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N;
    cin >> N;
    vector<vector<ll>> a(N, vector<ll>(3));
    REP(i, N) REP(j, 3) cin >> a[i][j];
    vector<vector<ll>> dp(N + 1, vector<ll>(3));
    REP(i, N) {
        REP(x, 3) {
            REP(y, 3) {
                if (x == y)
                    continue;
                chmax(dp[i + 1][x], dp[i][y] + a[i][x]);
            }
        }
    }
    print(max({dp[N][0], dp[N][1], dp[N][2]}));

    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define P 1000000007

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	
	ll n, q;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	cin >> q;
	vector<ll> b(q), c(q);
	for(int i = 0; i < q; i++) {
		cin >> b[i] >> c[i];
	}
	
	vector<ll> cnt(200001, 0);
	for(int i = 0; i < n; i++) cnt[a[i]]++;
	
	ll sum = 0;
	for(int i = 0; i < n; i++) sum += a[i]; 
	
	for(int i = 0; i < q; i++) {
		sum -= b[i] * cnt[b[i]];
		sum += c[i] * cnt[b[i]];
		cnt[c[i]] += cnt[b[i]];
		cnt[b[i]] = 0;
		
		cout << sum << endl;
	}
	
	return 0;
}

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

int main(){
    int a , b , c;
    cin >> a >> b >> c;
    if(a==b && a==c) {cout << '1' << endl; return 0;}
    if(a==b || a==c || b==c) cout << '2' << endl;
    else cout << '3' << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
using namespace std;
int main() {
	string s,p;
	cin >> s >> p;
	int n = s.size();
	int m = p.size();
	int cosuu = 0;
	rip(i, n) {
		int count = 0;
		rip(j, m) {
			if (s[(i + j) % n] == p[j]) {
				count++;
			}
		}
		if (count == m)cosuu++;
	}
	if (cosuu >= 1)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0056
{
    public class Program

    {
        public static void Main(string[] args)
        {

            bool[] primes = new bool[50001]; 
            for (int i = 1 ; i < primes.Length ; i++) primes[i] = IsPrime(i);
       
            while (true)
            {
                int n = RInt();
                if (n == 0) return;

                int cnt = 0;
                for (int i = 1 ; i <= n/2 ; i++) if (primes[i] && primes[n - i]) cnt++;
                Console.WriteLine(cnt);
            }
        }

        /// <summary>
        ///素数判定
        /// </summary>
        public static bool IsPrime(long number)
        {
            long boundary = (long)Math.Floor(Math.Sqrt(number));

            if (number == 1) return false;
            if (number == 2) return true;

            for (long i = 2 ; i <= boundary ; ++i)
            {
                if (number % i == 0) return false;
            }
            return true;
        }


        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 13844
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
//////////////

void solve() {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	int ans = 1;
	X -= Y + 2 * Z;
	while (X >= Y + Z) {
		X -= Y + Z;
		ans++;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
  public static ArrayList[] edge;
  public static long[] point;
  public static boolean[] visit;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    point = new long[n];
    edge = new ArrayList[n];
    int[] c = new int[n];
    for(int i = 0; i < n - 1; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      if(c[a] == 0) {
        c[a] = 1;
        edge[a] = new ArrayList<Integer>();
      }
      if(c[b] == 0) {
        c[b] = 1;
        edge[b] = new ArrayList<Integer>();
      }      
      edge[a].add(b);
      edge[b].add(a);
    }
    
    for(int i = 0; i < q; i++) {
      int p = sc.nextInt() - 1;
      long x = sc.nextLong();
      point[p] += x;
    } 
 
    dfs(0, -1);
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < n; i++) {
      sb.append(point[i] + " ");
    }
    System.out.println(sb);
  }
 
  public static void dfs(int v, int p) {
    ArrayList<Integer> list = edge[v];
    long x = point[v];
    for(int i = 0; i < list.size(); i++) {
      int t = list.get(i);
 
      if(t != p) {
        point[t] += x;
        dfs(t, v);
      }
    }
  }
}

Measured memory_bytes: 227304
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    ll ans = (n) / (a + b) * a;
    n -= n/(a+b)*(a+b);
    ans += min(n,a); 

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


Measured memory_bytes: 256
#include <cstdio>

const int Max = 100005;
int n,m,k;
int fa[Max],Size[Max],Du[Max];

int getfa(int x){
	if(fa[x] == x) return x;
	return fa[x] = getfa(fa[x]);
}

void Union(int x,int y){
	int Fx = getfa(x);
	int Fy = getfa(y);
	if(Fx == Fy) return;
	fa[Fx] = Fy;
	Size[Fy] += Size[Fx];
}

int main(){
	scanf("%d %d %d",&n,&m,&k);
	for(int i = 1; i <= n; i++){
		fa[i] = i;
		Size[i] = 1;
	}
	for(int i = 1; i <= m; i++){
		int x,y;
		scanf("%d %d",&x,&y);
		Du[x]++;
		Du[y]++;
		Union(x,y);
	}
	for(int i = 1; i <= k; i++){
		int x,y;
		scanf("%d %d",&x,&y);
		if( getfa(x) == getfa(y) ) Du[x]++,Du[y]++;
	}
	for(int i = 1; i <= n; i++){
		int Out = Size[getfa(i)] - 1 - Du[i];
		printf("%d ",Out);
	}
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, ans=0;
  cin >> n;
  
  for(int i=1; i<=n; i++){
    if(i%3==0){
    }
    else if(i%5==0){
    }
    else{
      ans += i;
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

int main()
{
    char a;
    cin >> a;

    char ans;
    if (a - 'a' < 0)
    {
        ans = 'A';
    }
    else
    {
        ans = 'a';
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define rep(i,n) for(int i =0;i < (n); i++)

int main() {
    string S;
    cin >> S;
    for(int i =0;i < S.size(); i = i+  2) {
        if(i + 1 > S.size()) {
            cout << "No" << endl;
            return 0;
        }
        if(S[i] == 'h' && S[i+1] == 'i') {
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#define MIN(A,B) ((A<B)?A:B)
using namespace std;

long long n,a[200010];
long long tot,ans=10000000000000000;

long long check(long long x){
	long long re=0;
	for(int i=1;i<=n;i++)
		re+=abs(a[i]-x);
	return re;
}

int main(){
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]-=i;
		tot+=a[i];
	}
	long long l,r,lmid,rmid;
	for(l=-2000000000,r=2000000000,lmid=l+(r-l)/3,rmid=l+(2*(r-l))/3;r-l>=3;lmid=l+(r-l)/3,rmid=l+(2*(r-l))/3){
		if(check(lmid)>check(rmid))
			l=lmid+1;
		else{
			if(check(lmid)==check(rmid)){
				l=lmid,r=rmid;
			}
			else
				r=rmid-1;
		}
	}
	cout<<MIN(MIN(check(l),check(l+1)),MIN(check(r),check(r-1)));
}

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

double grow[100][100];
double dp[100][100];

int main(void){
	int n,m;
	while( cin >> n >> m,n|m){
		for(int y=0;y<n;y++)
			for(int x=0;x<m;x++)
				dp[x][y]=0;
		for(int y=0;y<n;y++)
			for(int x=0;x<n;x++)
				cin >> grow[x][y];
		for(int i=0;i<n;i++)
			dp[0][i]=1.0;
		for(int i=1;i<m;i++)
			for(int j=0;j<n;j++)
				for(int k=0;k<n;k++)
				dp[i][j]=max(dp[i][j],dp[i-1][k]*grow[k][j]);
		double MAX=0;
		for(int i=0;i<n;i++)
			MAX=max(MAX,dp[m-1][i]);
		cout.precision(2);
		cout << fixed <<MAX << endl;
	}
	return 0;
}

Measured memory_bytes: 1444
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

ll fact(ll n);

int main() {
	int n,a,val;
	cin >> n;
	map<int, int> mp;

	rep(i, n) {
		cin >> a;
		mp[a]++;
	}

	int ans = 0;
	for (auto i = mp.begin(); i != mp.end(); i++) {
		a = i->first;
		val = i->second;
		if (val < a) {
			ans += val;
		} else {
			ans += abs(a-val);
		}
	}
	cout << ans << endl;
	return 0;
}





Measured memory_bytes: 4736
s=input()
k=int(input())
ans=''
for i in range(len(s)-1):
  if s[i]=='a':
    ans+='a'
  else:
    if k>=123-ord(s[i]):
      k-=(123-ord(s[i]))
      ans+='a'
    else:
      ans+=s[i]
ans+=chr((ord(s[-1])-97+k)%26+97)
print(ans)

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

using namespace std;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
#define INF (int)1e9
#define MOD 1000000007
#define PI 3.1415926535897932384626
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
int a[mxN];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    string s;
    cin >> s;
    sort(s.begin(), s.end());
    s[0] == s[2] ? cout << "No" : cout << "Yes";

    return 0;
}

Measured memory_bytes: 3616
S = input()
N = len(S)

if len(set(S)) == 1:
    print(N)
    exit()

ans = N//2
l = r = N//2
if N%2 == 0: l -= 1

inside = None
while l >= 0:
    if not inside:
        if N%2:
            if S[l] == 1:
                print(N//2 + 1)
                exit()
        else:
            if S[l] != S[r]:
                print(N//2)
                exit()
        inside = S[l]
        continue
    if S[l] != inside or S[r] != inside:
        break
    inside = S[l]
    l -= 1
    r += 1
    ans += 1
print(ans)

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) cout << c << "\n";
  else if (a == c) cout << b << "\n";
  else if (b == c) cout << a << "\n";

  return 0;
}

Measured memory_bytes: 256
//
// Created by miyoshi on 2019/05/23.
//

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;


int main() {
    int n, k, score;
    cin >> n;
    cin >> k;
    long double count[n+1];
    long double result = 0;

    for (int dice=1; dice <= n; dice++) {
        count[dice] = 0;
        score = dice;
        while (score < k) {
            score = score * 2;
            count[dice]+=1.0;
        }
    }

    for (int dice=1; dice <=n; dice++) {
        result += std::pow(2.0,  -1 * count[dice]) / n;
    }
    cout << setprecision(13) << result << endl;
    return 0;
}

Measured memory_bytes: 1792
P = 52
alph = (?A..?Z).to_a + (?a..?z).to_a
code = Hash[*alph.zip((0..alph.size-1).to_a.reverse).flatten]

n = gets.to_i
a = $<.map {|l| l.chomp.split("")}
edges = {}
(1..n).each do |i|
    edges[[0, i]] = 0
    (1..n).each do |j|
        edges[[i, n+j]] = P ** 52 - P ** code[a[i-1][j-1]]
    end
    edges[[n+i, 2*n+1]] = 0
end

n.times do
    dist = [Float::INFINITY] * (2*n+2)
    dist[0] = 0
    prev_node = [nil] * (2*n+2)
    (2*n+1).times do
        change = false
        edges.each do |(i, j), len|
            d = dist[i] + len
            if d < dist[j]
                change = true
                dist[j] = d
                prev_node[j] = i
            end
        end
        break unless change
    end
    path = [2*n+1]
    path << prev_node[path[-1]] while prev_node[path[-1]]
    path.each_cons(2) do |i, j|
        c = edges[[j, i]]
        edges.delete([j, i])
        edges[[i, j]] = -c
    end
end

puts edges.keys.select {|i, j| i > j && j != 0 && i != 2*n+1}.map {|j, i| a[i-1][j-n-1]}.sort.join

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

int main(){
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int x[N] = {0};
    int B[N];
    for (int i = 0; i < N; i++)
    {
        B[i] = A[i];
    }
    sort(B,B+N);
    int j = B[0];
    x[0] = j;
    for (int i = 1; i < N; i++)
    {
        x[i] = A[i-1] - x[i-1];
    }
    if(A[N-1]-x[N-1] == x[0]){
        for (int i = 0; i < N; i++)
        {
            cout << 2 * x[i];
            if(i!=N-1) cout << " ";
            else cout << endl;
        }
    }
    else{
        x[0] = (B[0] + A[N-1]-x[N-1])/2;
        for (int i = 1; i < N; i++)
        {
            x[i] = A[i-1] - x[i-1];
        }
        for (int i = 0; i < N; i++)
        {
            cout << 2 * x[i];
            if(i!=N-1) cout << " ";
            else cout << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m;
struct cards
{
    int from,to;
    cards(int f,int t)
    {
        from=f,to=t;
    }
};
deque<cards> all;
deque<cards> split(int k)
{
    deque<cards> sub;
    if(k==0)return sub;
    for(;;)
    {
        cards t=all.front();
        all.pop_front();
        k -= t.to-t.from+1;
        if(k==0)
        {
            sub.pb(t);
            break;
        }
        if(k<0)
        {
            all.push_front(cards(t.to+k+1,t.to));
            t.to+=k;
            sub.pb(t);
            break;
        }
        sub.pb(t);
    }
    return sub;
}
void print(deque<cards> mount)
{
	for(int i=0;i<mount.size();i++)
	{
		cout << mount[i].from << ' ' << mount[i].to << endl;
	}
	cout << endl;
	return;
}
void shuffle(int x,int y)
{
    deque<cards> a=split(x);
    deque<cards> b=split(y);
    for(int i=a.size()-1;i>=0;i--)all.push_front(a[i]);
    for(int i=b.size()-1;i>=0;i--)all.push_front(b[i]);
}
int main()
{
    while(1)
    {
        cin >> n >> m;
        if(n==0&&m==0)break;
        all.clear();
        all.pb(cards(1,n));
        for(int i=0;i<m;i++)
        {
            int p,c;
            cin >> p >> c;
            shuffle(p-1,c);
            //print(all);
        }
        cout << n-all[0].from+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    divisors.append(n)
    return divisors

def check(N,K):
    try:
        if N == K:
            return True
        if N % K ==1:
            return True
        if N<K:
            return False
        
        if N % K ==0:
            return check(N//K,K)
        else:
            return False
    except:
        return False

def resolve():
    N = int(input())
    ys= set(make_divisors(N))
    ys2= set([i for i in make_divisors(N-1) if check(N,i)])

    x =set([i for i in ys if check(N,i)])

    print(len(x | ys2))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

int sum[100009];

signed main(){
  int n,k,m;
  cin>>n>>k>>m;
  r(i,m){
    int x;
    cin>>x;
    sum[x-1]++;
  }
  r(i,n){
    if(sum[i]+k-m<=0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll t,n,u,i,j,k,q;
	string s;
	cin>>s;
	n=s.length();
	ll a[n+1]={0};
	ll sum=0;
	for(i=0;i<n;i++)
	{
	    if(s[i]=='R')
	    sum++;
	    else
	    {
	        a[i]+=sum/2;
	        a[i-1]+=(sum+1)/2;
	        sum=0;
	    }
	}
	sum=0;
	for(i=n-1;i>=0;i--)
	{
	    if(s[i]=='L')
	    sum++;
	    else
	    {
	        a[i]+=sum/2;
	        a[i+1]+=(sum+1)/2;
	        sum=0;
	    }
	}
	for(i=0;i<n;i++)
	cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
int main(){
    long long n;
    cin>>n;
    vector<pair<long long,long long>> a;
    rep(i,n){
        string s;
        cin>>s;
        long long lef=0;
        long long worst=s.size();
        rep(j,s.size()){
            if(s.at(j)=='(') lef++;
            else{
                lef--;
                worst=min(worst,lef);
            }
        }
        pair<long long,long long> date(worst,lef);
        a.push_back(date);
    }
    sort(a.begin(),a.end());
    long long cou=0;
    long long y=0;
    while(int(a.size())-2-y>=0){
        if(a.at(int(a.size())-1-y).second>=0 && cou+a.at(int(a.size())-1-y).first>=0){
            cou+=a.at(int(a.size())-1-y).second;
            a.erase(a.begin()+int(a.size())-1-y);
            y=0;
        }
        else y++;
    }
    rep(i,a.size()){
        a.at(i).first-=a.at(i).second;
        a.at(i).second*=-1;
    }
    sort(a.begin(),a.end());
    rep(i,a.size()){
        a.at(i).first-=a.at(i).second;
        a.at(i).second*=-1;
    }
    long long x=0;
    bool ans=true;
    rep(i,a.size()){
        if(cou+a.at(i).first<0){
            ans=false;
            break;
        }
        else cou+=a.at(i).second;
    }
    if(cou==0 && ans) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 19680
#pragma GCC optimize(2)
#include <cstdio>
#include <cstring>
using namespace std;

char a[110],s[110];
int la,l;

int main()
{
	scanf("%s",a+1);
	la=strlen(a+1);
	for(int i=1;i<=la;i++) {
		if(a[i]=='B') {
			if(l>0) --l;
		}
		else s[++l]=a[i];
	}
	for(int i=1;i<=l;i++) printf("%c",s[i]);
	return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))

int main(){
    FAST
    ll n; cin >> n;
    string alpha = "zabcdefghijklmnopqrstuvwxy";
    string ans = "";
    while(n > 0){
        int a = n%26;
        ans += alpha[a];
        if(a == 0)n--;
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3568
open Batteries

let read_two () = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))

let read_three () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> (a, b, c))

let read_four () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c d -> (a, b, c, d))

let read_list () =
  read_line () |> String.split_on_char ' '
  |> List.map (fun s -> int_of_string s)

(* a**x *)
let pow a x =
  let rec aux acc = function 0 -> acc | n -> aux (acc * a) (n - 1) in
  aux 1 x

let _ = read_line ()

let rec f (a, b) at = function
  | [] -> (a, b)
  | n :: rest ->
      if at then f (n + a, b) (not at) rest else f (a, n + b) (not at) rest

let () =
  let ls = read_list () |> List.fast_sort (fun x y -> -compare x y) in
  let a, b = f (0, 0) true ls in
  print_int (a - b);
  print_newline ()


Measured memory_bytes: 1152
s=list(input())
m=0
if s[0]=="0":
    for i in range(1,len(s),2):
        if s[i]=="0":
            m+=1
    for i in range(2,len(s),2):
        if s[i]=="1":
            m+=1
if s[0]=="1":
    for i in range(1,len(s),2):
        if s[i]=="1":
            m+=1
    for i in range(2,len(s),2):
        if s[i]=="0":
            m+=1
print(m)


Measured memory_bytes: 3956
#include<iostream>
using namespace std;
 
int gcd(int x, int y){
  // x >= y のときgcd(x,y)とgcd(y,yをxで割った余りが)等しいことをもちいた
  if ( y == 0 ) return x;
  else return gcd(y,x%y);
}
 
int main(){
  int x,y;
  cin >> x >> y;
  int result = gcd(x,y);
 
  cout << result << endl;
   
  return 0;
}

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

using namespace std;

using ll = long long;

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

    int n, m;
    cin >> n >> m;
    pair<ll, ll> d[n];

    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        d[i] = make_pair(a, b);
    }

    sort(d, d + n);
    ll res = 0;
    for (auto e: d) {
        if (e.second < m) {
            m -= e.second;
            res += e.first * e.second;
        } else {
            res += e.first * m;
            break;
        }
    }

    cout << res << '\n';
    
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
int main()
{
	char c;
	scanf("%c",&c);
	switch(c)
	{
		case 'A':
			printf("T");
			break;
		case 'G':
			printf("C");
			break;
		case 'C':
			printf("G");
			break;
		case 'T':
			printf("A");
			break; 
	}
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123456
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e3 + 10;

//initialization here
//
int l[201];
//
//initialization finish


// your function is here
//

//
// your function finished



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int n; cin >> n;
	

	rep(i, 2 * n) cin >> l[i];

	sort(l, l + 2*n);

	int ans = 0;
	for (int i = 0; i < 2 * n; i += 2) ans += l[i];

	Print(ans);

	//
	// your code finished


	return 0;
}

Measured memory_bytes: 256
def min2(x,y):
    return x if x < y else y

N, M = map(int, input().split())

large = 1<<20
dp = [large]*(1<<N + 1)
dp[0] = 0
data = []
for i in range(M):
    a, b = map(int, input().split())
    bit = 0
    for c in map(int, input().split()):
        c -= 1
        bit = bit|1<<c
    data.append((a, bit))
for i, x in enumerate(data):
    a, bit = x
    for p in range(1<<N):
        dp[p|bit] = min2(dp[p] + a, dp[p|bit])
print(dp[(1<<N)-1] if dp[(1<<N)-1] != large else -1)

Measured memory_bytes: 77284
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SYOU(x) fixed<<setprecision(x) //小数点桁数を指定する
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    INT(N);
    VEC(int,a,N);
    ll ans = 0LL;
    sort(a.begin(),a.end(),greater<int>());
    for(int i = 0; i < N - 1; ++i) {
        ans += a[(i+1)/2];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4012
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
const ll mod = 998244353;
ll dp[200005];
ll sumdp[200005];

int main(){
  int n,k;
  cin >> n >> k;
  vector<pair<int,int>> to(k);
  rep(i,k){
    int x,y;
    cin >> x >> y;
    to[i] = {x,y};
  }
  sumdp[1] = 1LL;
  dp[1] = 1LL;
  for (int i = 1; i <= n;i++){
    for (auto q :to){
      int left = max(0,i-q.second-1);
      int right = max(0,i-q.first);
      ll diff = sumdp[right]-sumdp[left];
      //printf(" i = %d (l,r) = (%d,%d)\n",i,q.first,q.second);
      //cout << "diff is " << diff << endl;
      if (diff < 0) diff+=mod;
      dp[i] += diff;
      dp[i]%= mod;
    }
    //rep(j,6){
    //  cout << dp[j] << " ";
    //}
    //cout << endl;
    sumdp[i] = sumdp[i-1] + dp[i];
    sumdp[i] %= mod;
    //rep(j,6){
      //cout << sumdp[j] << " ";
    //}
    //cout << endl;
  }
  cout << dp[n] << endl;

  return 0;
}

Measured memory_bytes: 6712
module Main where

import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import           Data.Array.IO
import qualified Data.Vector            as V
import           Text.Printf

main :: IO ()
main = do
  n <- getLine
  s <- getLine
  k <- readLn
  let key = s !! (k - 1)
  putStrLn $ map (\ x -> (\a b -> if a == b then a else '*') x key) s


Measured memory_bytes: 508
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    string s;cin>>s;
    while(s.size()>=2){
        int n=s.size();
        if(s[n-1]=='i'&&s[n-2]=='h'){
            REP(j,2) s.pop_back();
        }
        else break;
    }
    if(s.empty()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

typedef long long ll;

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

    ll x,ans;
    cin >> x;
    for(ll i=0;i<=x;i++){
        if(i*(i+1)/2>=x){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
i,counter = 0,0
divCheck = False
while True:
    i = 0
    for i in range(0,N):
        if A[i] % 2 == 0:
            A[i] /= 2
        else:
            divCheck = True
    if divCheck:
        break
    counter += 1
print(counter)

Measured memory_bytes: 3060
A = int(input()) #500
B = int(input()) #100
C = int(input()) #50
X = int(input()) #target

N = (A + 1) * (B + 1) * (C + 1)
Total = [0 for i in range(N)]
l = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            Total[l] = 500*i + 100*j + 50*k
            l += 1

print(Total.count(X))


Measured memory_bytes: 8276
#include<cstdio>
#include<cctype>
#include<cstring>
const int maxn=1010,mod=1000000007;
int n,m;
long long k;
char s[maxn][maxn];
int p,q,r;
bool ta,tb;
struct Matrix {
	int a[2][2];
	void cls() {
		memset(a,0,sizeof a);
	}
}c;
Matrix operator * (const Matrix &a,const Matrix &b) {
	c.cls();
	for(register int i=0;i<2;++i)for(register int k=0;k<2;++k)for(register int j=0;a.a[i][k]&&j<2;++j)
	b.a[k][j]?c.a[i][j]=(c.a[i][j]+1ll*a.a[i][k]*b.a[k][j])%mod:0;
	return c;
}
Matrix f,x;
int pw(register int x,register long long y) {
	register int s=1;
	for(;y;y>>=1,x=1ll*x*x%mod)y&1?s=1ll*s*x%mod:0;
	return s;
}
void pw(register long long y) {
	for(;y;y>>=1,x=x*x)if(y&1)f=f*x;
}
int main() {
	scanf("%d%d%lld",&n,&m,&k);
	for(register int i=0;i<n;++i)scanf("%s",s[i]);
	if(!k) return puts("1"),0;
	--k;
	for(register int i=0;i<n;++i)for(register int j=0;j<m;++j)p+=s[i][j]=='#';
	for(register int i=0;i<n;++i)if(s[i][0]=='#'&&s[i][m-1]=='#') ta=1,++q;
	for(register int i=0;i<m;++i)if(s[0][i]=='#'&&s[n-1][i]=='#') tb=1,++q;
	if(ta&&tb) return puts("1"),0;
	if(!ta&&!tb) return printf("%d\n",pw(p,k)),0;
	f.a[0][0]=f.a[1][1]=1;
	if(ta) for(register int i=0;i<n;++i)for(register int j=1;j<m;++j)r+=s[i][j]=='#'&&s[i][j-1]=='#';
	else for(register int i=1;i<n;++i)for(register int j=0;j<m;++j)r+=s[i][j]=='#'&&s[i-1][j]=='#';
	x.a[0][0]=p,x.a[0][1]=r,x.a[1][1]=q;
	pw(k);
	printf("%d\n",(f.a[0][0]-f.a[0][1]+mod)%mod);
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int n; cin >> n;
    if(n == 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3616
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	int k; cin>>k;
	int t,ans=0;
	while(n--){
		cin>>t;
		if(t>=k) ans++;
	}
	cout<<ans<<"\n";
	return 0;
}





























Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define ll  long long int
    #define N 100000
    #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
    #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
    #define po pop_back
    #define pb push_back
    #define lb lower_bound
    #define fi first
    #define se second
    #define debug(x) cout << #x << " = " << x << endl
    #define ub upper_bound
    #define ibs ios_base::sync_with_stdio(false)
    #define cti cin.tie(0)
    #define all(x) x.begin(),x.end()
    #define PI 3.14159265
    #define cot cout.tie(0)
    using namespace std;
      /**
        * @author :: Sawlani
        *
        */
        int main()
        {
          //  freopen("input.txt","r",stdin);

            ll n;
            cin >> n;

            ll a,b,c;
            ll dp[n+1][4]={0};
            f(i,1,n) {
            cin >> a >> b >> c;

            dp[i][1]=a+max(dp[i-1][2],dp[i-1][3]);
            dp[i][2]=b+max(dp[i-1][1],dp[i-1][3]);
            dp[i][3]=c+max(dp[i-1][1],dp[i-1][2]);

            }

            cout << max({dp[n][1],dp[n][2],dp[n][3]});

        }


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int c;
	c=a+b;
	if(c%2==1)cout<<(c+1)/2<<endl;
	else cout<<c/2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include <string>
#define loop(i,n) for(int i=0;i<(int)n;i++)

using namespace std;
int d[10];

bool check(int x){

int a=1;

while(x>0){

    if(d[x%10]){
        a=0;
    }
    x=x/10;
}

if(a)
    return true;
else
    return false;

}


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


for(int i=1;i<=k;i++){
    int x;
    cin>>x;

    d[x]=1;

}

for(int i=n;;i++){

    if(check(i)){

       cout<<i;
       break;
       }
}


}




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

int main(){
  int N;
  cin >> N;
  vector<int> W;
  for(int i = 0;i < N;i++){
    int w;
    cin >> w;
    W.push_back(w);
  }

  vector<int> answers;

  for(int i = 0;i < N;i++){
    int sum1 = 0;
    int sum2 = 0;
    for(int j = 0;j < N;j++){
      if(j <= i)sum1 += W[j];
      else sum2 += W[j];
    }

    if(sum1 > sum2)answers.push_back(sum1 - sum2);
    else answers.push_back(sum2 - sum1);
  }

  cout << *min_element(answers.begin(),answers.end()) << endl;

  return 0;
}


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

int main()
{
// #ifndef ON
//     freopen("input.txt","r",stdin);
// #endif
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0 ;i<n;i++)
        cin>>arr[i];
    int arr1[n];
    int sum = 0;
    for(int i = 0 ;i<n;i++)
    {
        cin>>arr1[i];
        sum+=arr1[i];
    }
    int value = n -1 ;
    int arr2[value];
    for(int i = 0 ;i<value;i++)
        cin>>arr2[i];
    int tmp = 0 ;
    for(int i=0;i<n;i++)
    {
        if(i!=0 && arr[i]==arr[i-1]+1)
            sum+=arr2[arr[i-1]-1];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
string S, T = {}; 
cin >> S; 
for(int i = 0; i < S.size(); i++){
if(S.at(i) != 'B'){
T = T + S.at(i); 
}
else if(T.size() > 0){
T = T.substr(0, T.size()-1); 
}
}
cout << T << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;

	cin >> n;

	for (int i = 0; i < n; i++) cin >> R[i];

	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    string t="";
    std::deque<string> words{"maerd","remaerd","esare","resare"};
    std::deque<string> deq{t};
    while (deq.size()!=0) {
        string tmp=deq.front();
        deq.pop_front();
        if (tmp.size()<100000) {
            for (int i=0;i<4;i++) {
                if (tmp+words[i]==s) {
                    cout<<"YES"<<endl;
                    return 0;
                } else if (tmp+words[i]==s.substr(0,(tmp+words[i]).size())) {
                    deq.emplace_back(tmp+words[i]);
                }
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 1208
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=1000000007;
const ll INF=1<<27;
int main(){
    int n;cin>>n;
    int h[n];
    rep(i,n)cin>>h[i];
    int ans=0;
    ans+=h[0];
    for(int i=1;i<n;i++){
        if(h[i-1]<h[i]){
         ans+=h[i]-h[i-1];
        }
    }
cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
 
int main() {
 
    //input
    int n;
    cin>>n;
    vector<int>vec;

    int j;
    for(int i=0;i<n;i++) {
        cin>>j;
        vec.push_back(j);
    }
    //sort(vec.begin(),vec.end());

  	//solve
    //number of odd elements
    int odd_count = 0;

    for(auto el:vec){
        if((el % 2) !=0){
            odd_count++;
        }
    }
    //  mod 2 of it
    if(odd_count % 2 == 0){
        cout<<"YES";
    }else{
        cout<<"NO";
    }

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	
	int n;
	cin >> n;
	set<int> s;
	rep(i, n){
		int a;
		cin >> a;
		if(s.count(a)){
			s.erase(a);
		}else{
			s.insert(a);
		}
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k)
    {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k)
    {
        return (-data[find(k)]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind Friend(N);
    vvint block(N), fr(N);
    int a, b, c, d;
    for (int i = 0; i < M; i++)
    {
        cin >> a >> b;
        a--;
        b--;
        Friend.unite(a, b);
        fr[a].push_back(b);
        fr[b].push_back(a);
    }
    for (int i = 0; i < K; i++)
    {
        cin >> c >> d;
        c--;
        d--;
        block[c].push_back(d);
        block[d].push_back(c);
    }
    for (int i = 0; i < N; i++)
    {
        int ans = Friend.size(i) - 1 - fr[i].size();
        for (auto &&j : block[i])
        {
            if (Friend.same(i, j))
            {
                ans--;
            }
        }
        cout << ans << " ";
    }

    return 0;
}

Measured memory_bytes: 12280
def main():
    n = int(input())
    ttn = [[-1] * n for _ in range(n)]  # Testimonies.
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = [int(z) for z in input().split()]
            x -= 1
            ttn[i][x] = y  # i says that x is honest guy or not.
    ans = set()
    # for else で頑張ったが，フラグを作ったほうがずっと分かりやすいだろう。
    for i in range(2 ** n):
        tmp = [i >> j & 1 for j in range(n)]  # Bit-shift.
        for k, tm in enumerate(tmp):
            if tm:
                for l, tt in enumerate(ttn[k]):
                    if tt == -1:
                        continue
                    if tt != tmp[l]:
                        break
                else:
                    continue
                break
        else:
            ans.add(bin(i).count('1'))
    return max(ans)


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


Measured memory_bytes: 3064