akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    vector<ll> Humburger(51),Patty(51);
    Humburger[0]=1;
    Patty[0]=1;
    for(int i=1;i<=50;i++){
        Humburger[i]=2*Humburger[i-1]+3;
        Patty[i]=2*Patty[i-1]+1;
    }
    LL(n,x);
    ll ans=0;
    for(int i=n;i>=0;i--){
        if(x==Humburger[i]){
            ans+=Patty[i];
            break;
        }else if(x>Humburger[i-1]+2){
            ans+=Patty[i-1]+1;
            x-=Humburger[i-1]+2;
        }else if(x==Humburger[i-1]+2){
            ans+=Patty[i-1]+1;
            break;
        }else if(x>1){
            x--;
        }else if(x==1){
            if(i==0)ans++;
            break;
        }
    }
    out(ans);
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }

int main(){
    int g=0, p=0;
    string s; cin >> s;
    for(int i=0; i<s.size(); ++i){
        if(s[i] == 'g') g++;
        else p++;
    }

    cout << (g-p)/2 << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main (void) {
    int N;
    // vector<int> l, r;
    cin >> N;
    int num = 0;
    for ( int i = 0; i < N; i++ ) {
        int tmp_l, tmp_r;
        cin >> tmp_l >> tmp_r;
        num += tmp_r - tmp_l + 1;
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
total_t = 1; total_a = 1;
for t, a in ratio:
    q = max((total_t + t - 1) // t, (total_a + a - 1) // a)
    total_t = t*q
    total_a = a*q
ans = total_t + total_a
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

#define ld  long double
#define ll  long long int
#define ull unsigned long long int
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define endl "\n"

const int    INF = 1e11;
const double EPS = 1e-11;

//切り上げ整数除算
int divRoundUp(const int& a, const int& b) { return (a + b - 1) / b; }
//四捨五入
int roundOff(const double& a) { return (int)(a + 0.5); }
// r の(誤差付きの)符号に従って, -1, 0, 1 を返す.
int sgn(const ld& r) { return (r > EPS) - (r < -EPS); }
// a, b の(誤差付きの)大小比較の結果に従って, -1, 0, 1 を返す.
int sgn(const ld& a, const ld& b) { return sgn(a - b); }

using namespace std;

inline void Main() {
	int n; cin >> n;
	map<string, vector<pair<int, int>>> dic;
	REP(i, n) {
		string s;
		int p; cin >> s >> p;
		dic[s].push_back(make_pair(i + 1, p));
	}
	for (auto& d : dic) {
		sort(ALL(d.second), [](const pair<int, int>& a, const pair<int, int>& b) {return a.second > b.second; });
	}

	for (auto& d : dic) {
		for (auto& t : d.second) {
			cout << t.first << endl;
		}
	}
}

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

	Main();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;

	int kotae = N * 2;

	for (int i = N; i >= 1; i--) {
		int OK = 1;
		rep(j, i) {
			if (S[j + (N - i)] != T[j]) OK = 0;
		}
		if (OK) {
			kotae = 2 * N - i;
			break;
		}
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int dy[2][9] = {{-2,-1,-1,0,0,0,1,1,2},{-2,-1,-1,0,0,0,1,1,2}};
int dx[2][9] = {{1,1,2,1,2,3,1,2,1},{-1,-2,-1,-3,-2,-1,-2,-1,-1}};
int w,h;
char s[61][31];
int dis[61][31][2];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> w >> h, w) {
    MINF(dis);
    using P = tuple<int,int,int,int>;
    priority_queue<P,vector<P>,greater<P>> que;
    vector<pii> gs;
    REP(i,h) REP(j,w) {
      cin >> s[i][j];
      if (s[i][j] == 'S') {
        que.emplace(0,i,j,0);
        que.emplace(0,i,j,1);
        dis[i][j][0] = dis[i][j][1] = 0;
      } else if (s[i][j] == 'T') {
        s[i][j] = '0';
        gs.emplace_back(i,j);
      }
    }
    while (!que.empty()) {
      int dd,y,x,t;
      tie(dd,y,x,t) = que.top(); que.pop();
      if (dis[y][x][t] < dd) continue;
      for (int i = 0; i < 9; i++) {
        int ny = y+dy[t][i];
        int nx = x+dx[t][i];
        if (IN(ny,0,h-1) && IN(nx,0,w-1) && s[ny][nx] != 'X') {
          int cost = (s[ny][nx]-'0');
          if (CHMIN(dis[ny][nx][t^1],dis[y][x][t]+cost)) {
            que.emplace(dis[ny][nx][t^1],ny,nx,t^1);
          }
        }
      }
    }
    int ans = INF;
    for (pii g : gs) REP(i,2) CHMIN(ans,dis[g.first][g.second][i]);
    cout << (ans == INF ? -1 : ans) << endl;
  }

  return 0;
}


Measured memory_bytes: 3228
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int getOrderNum(vi vec){
  vi svec = vec;
  sort(svec.begin(), svec.end());
  int cnt = 0;
  do {
    cnt++;
    if (svec == vec) break;
  } while( next_permutation(svec.begin(), svec.end()));
  return cnt;
}


int main() {
  int n;
  cin >> n;
  vi p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  int a = getOrderNum(p);
  int b = getOrderNum(q);
  cout << abs(a - b) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

M = int(input())
Dsum = 0
digit = 0

for _ in range(M):
    d, c = map(int, input().split())
    Dsum += d * c
    digit += c

ans = digit - 1
div, mod = divmod(Dsum, 9)
if mod:
    ans += div
else:
    ans += div - 1

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = "";
		int[] cnt = new int[26];

		while(sc.hasNext()) {
			str = sc.nextLine();
			str = str.toLowerCase();
			char[] c = str.toCharArray();

			for(int i = 0; i < c.length; i++) {
				if('a' <= c[i] && c[i] <= 'z') {
					cnt[c[i] - 'a']++;
				}
			}
		}

		for(int i = 0; i < 26; i++) {
			System.out.println(((char)(i + 'a')) + " : " + cnt[i]);
		}
	}
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    int i, j;
    for (i = 0; i <= x; i++) {
        j = x - i;
        if (i * 2 + j * 4 == y) {
            cout << "Yes" << endl;
            break;
        }
    }
    if (i == x + 1) {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する

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

    vector<int> v;
    REP(i, 0, n) {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());

    int ret = 0;
//    int cnt = 1;
    int i = 0;

    while(i < n){
        int begin = i;
        int en = begin;
        while(v[begin] == v[en]){
            en++;
            if(en >= n){
                break;
            }
        }
        int dif = en - begin;
        if(dif % 2 == 1){
            ret++;
        }
        i = en;

    }


    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 892
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).ok();

    let mut v : Vec<_> = input.split_whitespace().map(|v| v.parse::<i32>().unwrap()).collect();
    v.sort();
    println!("{} {} {}", v[0], v[1], v[2]);
}



Measured memory_bytes: 5036
import sys
buf = sys.stdin.buffer


class UnionFind:
    def __init__(self, num_of_node):
        self.roots = [-1] * num_of_node
        self.ranks = [1] * num_of_node
        self.groups = num_of_node

    def get_root(self, node):
        root = self.roots[node]
        if root == -1:
            return node

        else:
            root = self.get_root(root)
            self.roots[node] = root
            return root

    def is_same_group(self, node1, node2):
        return self.get_root(node1) == self.get_root(node2)

    def unite(self, node1, node2):
        self.groups -= 1
        root1, root2 = self.get_root(node1), self.get_root(node2)
        rank1, rank2 = self.ranks[root1], self.ranks[root2]
        if rank1 < rank2:
            root1, root2 = root2, root1

        self.roots[root2] = root1
        self.ranks[root2] += self.ranks[root1]


def main():
    n = int(buf.readline())
    XY = map(int, buf.read().split())
    Xs = []
    Ys = []
    for i, (x, y) in enumerate(zip(XY, XY)):
        Xs.append((x-1, i))
        Ys.append((y-1, i))

    Xs.sort()
    Ys.sort()

    edges = []
    for i, ((x, node), (nx, new_node)) in enumerate(zip(Xs[:-1], Xs[1:])):
        edges.append((nx-x, node, new_node))

    for i, ((y, node), (ny, new_node)) in enumerate(zip(Ys[:-1], Ys[1:])):
        edges.append((ny-y, node, new_node))

    edges.sort(reverse=True)

    ans = 0
    uf = UnionFind(n)
    while uf.groups != 1:
        d, node1, node2 = edges.pop()
        if uf.is_same_group(node1, node2):
            continue
        uf.unite(node1, node2)
        ans += d

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 55492
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

#include<vector>
using namespace std;
int a[233333];
int b[233333];
long long ans;
vector<int> v;
int sum;
int main(){
	int n;
	cin>>n;
	sum=n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	bool flag=true;
	for(int i=0;i<n;i++){
		ans+=a[i]-b[i];
		if(a[i]>=b[i]){
			v.push_back(a[i]-b[i]);
		}
		else{
			flag=false;
		}
	}
	if(flag){
		puts("0");
		return 0;
	}
	sort(v.begin(),v.end());
	if(ans>=0){
		for(int i=0;i<v.size();i++){
			if(ans>=v[i]){
				ans-=v[i];
				sum--;
			}
		}
		cout<<sum<<endl;
	}
	else{
		puts("-1");
	}
	return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
const int mod = 1000000007;

template<class T> struct prime {
    using NP = pair<T,int>;
    T n;
    prime(T n):n(n) {
        assert(n > 0);
    }
    vector<NP> factorization() {
        if(n == 1) return {};
        T nn = n;
        vector<NP> ret;
        T i = 2;
        while (i*i <= n) {
            if(nn%i == 0) {
                nn /= i;
                if(!ret.empty() && ret[ret.size()-1].first == i) ret[ret.size()-1].second++;
                else ret.emplace_back(i,1);
            } else i++;
        }
        if(nn != 1) ret.emplace_back(nn,1);
        return ret;
    }
    bool isprime() {
        auto v = factorization();
        return v.size() == 1 && v[0].second == 1;
    }
    // count number of divisors
    int divisor() {
        int ret = 1;
        vector<NP> fl = factorization(n);
        for(auto p : fl) {
            ret *= p.second+1;
        }
        return ret;
    };
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    vb isp(100010);
    rep2(i,1,100010) isp[i] = prime<int>(i).isprime();
    vi sum(100010,0);
    rep2(i,1,100010) {
        sum[i] = sum[i-1];
        if(i%2 == 0) continue;
        if(isp[i] && isp[(i+1)/2]) sum[i]++;
    }
    int q;
    cin >> q;
    rep(_,q) {
        int l,r;
        cin >> l >> r;
        cout << sum[r]-sum[l-1] << endl;
    }
}


Measured memory_bytes: 1024
use std::fmt::Debug;
use std::io::{self, Read};
use std::str;
use std::str::FromStr;

fn main() {
    let mut sc = StdinScanner::new();
    if solve(sc.next()) {
        println!("yes");
    } else {
        println!("no");
    }
}


fn solve(s: String) -> bool {
    let mut counter = [false; 256];
    for &c in s.as_bytes() {
        if counter[c as usize] {
            return false;
        } else {
            counter[c as usize] = true;
        }
    }
    true
}


struct StdinScanner {
    buf: Vec<u8>,
}

impl StdinScanner {
    fn new() -> Self {
        StdinScanner { buf: Vec::with_capacity(256) }
    }

    fn next<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let stdin = io::stdin();
        let mut stdin = stdin.lock().bytes();
        let mut c = stdin.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = stdin.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = stdin.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }
}


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

string target;
unsigned long n;

string sa[4] = {"dream", "dreamer", "erase", "eraser"};

void f(unsigned long len, string ts) {
    //cout << len << ": " << ts << endl;
    if (len == target.length()) {
        if (target == ts) {
            cout << "YES\n";
            exit(0);
            return ;
        }
        return;
    }
    if (len > target.length())
        return;
    
    
    f(len+sa[0].length(), ts+sa[0]);
    f(len+sa[1].length(), ts+sa[1]);
    f(len+sa[2].length(), ts+sa[2]);
    f(len+sa[3].length(), ts+sa[3]);
}

bool search(string s, int index) {
    int length = s.size();
    
    if (s != target.substr(index, length))
        return false;
    
    if (length + index == target.size())
        return true;
    return (search("dream", index+length) || search("erase", index+length) ||search("eraser", index+length) || search("dreamer", index+length));
   
}


int main()
{
    cin >> target;
    //n = target.length();
    //f(0, "");
    //cout << "NO\n";
    
    if ( search("dream", 0) || search("erase", 0) || search("eraser", 0) || search("dreamer", 0) ) {
        cout << "YES" << endl;
        
    }
    else
        cout << "NO" << endl;
    
    
    return 0;
}


Measured memory_bytes: 4608
#include <string.h>
#include <iostream>

using namespace std;

int main()
{
	const int MAX_NO  = 100;
	const int MAX_NOS = 9;
	const int MAX_SUM = 1000;

	int n[51], s[51], c = 0;long long dp[MAX_NOS + 1][MAX_NO + 1][MAX_SUM + 1];

	long long SUM = 0;

	memset(dp, 0, sizeof(dp));

	for (int i = 0; i <= MAX_NO; i++)
	{
		dp[1][i][i] = 1;
	}

	for (int N = 2; N <= MAX_NOS; N++)
	{
		for (int i = 1; i <= MAX_NO; i++)
		{
			for (int j = 1; j <= MAX_SUM; j++)
			{
				if (j - i >= 0)
				{
					for (int k = 0; k < i; k++)
					{
						dp[N][i][j] += dp[N - 1][k][j - i];
					}
				}
			}
		}
	}

	while (true)
	{
		cin >> n[c] >> s[c];

		if (n[c] == 0 && s[c] == 0) { goto Exit; }

		c++;
	}

Exit:;

	for (int p = 0; p < c; p++)
	{
		SUM = 0;

		for (int i = 0; i <= MAX_NO; i++)
		{
			SUM += dp[n[p]][i][s[p]];
		}

		cout << SUM << endl;
	}

	return 0;
}

Measured memory_bytes: 9064
N, Y = map(int, input().split())

ans = [-1, -1, -1]
findit = False
sen = 0
for man in range(N + 1):
    if findit == True:
        break
    for gosen in range(N + 1):
        if findit == True:
            break
        sen = N - man - gosen
        if (man * 10000) + (gosen * 5000) + (sen * 1000) == Y and 0 <= sen:
            ans = [man, gosen, sen]
            findit = True

str_ans = map(str, ans)
print(" ".join(str_ans))

Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

int n, ls;
char ar[N];
stack<char> s;

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> ar + 1;
	n = strlen(ar + 1);
	for(int i = 1; i <= n; i++) {
		if(s.size() && s.top() == 'S' && ar[i] == 'T')
			s.pop();
		else
			s.push(ar[i]);
	}
	cout << s.size();
}

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

using namespace std;

int main(){
    string s;
    cin>>s;
    int freq[2] = {0,0};
    for(int i=0; i<s.length(); i++){
        if(s[i] == 'A'){
            freq[0]++;
        }
        else{
            freq[1]++;
        }
    }
    if(freq[0] > 0 && freq[1] > 0){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m, a, b; cin >> n >> m >> a >> b;
    string l = string(a, '0') + string(m - a, '1');
    string o = string(a, '1') + string(m - a, '0');
    for(int i = 0; i < b; i++) cout << l << "\n";
    for(int i = b; i < n; i++) cout << o << "\n";
}

Measured memory_bytes: 1280
import java.util.Scanner;

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

		boolean[] spade = new boolean[13];
		boolean[] dia = new boolean[13];
		boolean[] club = new boolean[13];
		boolean[] heart = new boolean[13];

		int n = scanner.nextInt();

		for (int i = 0; i < n; i++) {
			String markChar = scanner.next();
			int number = scanner.nextInt();

			
			if (markChar.equals("S")) {
				spade[number - 1] = true;
			}
			if (markChar.equals("H")) {
				heart[number - 1] = true;
			}
			if (markChar.equals("C")) {
				club[number - 1] = true;
			}

			if (markChar.equals("D")) {
				dia[number - 1] = true;
			}
		}

		for (int i = 0; i < spade.length; i++) {
			if (!spade[i]) {
				System.out.println("S " + (i + 1));
			}
		}
		for (int i = 0; i < heart.length; i++) {
			if (!heart[i]) {
				System.out.println("H " + (i + 1));
			}
		}
		for (int i = 0; i < club.length; i++) {
			if (!club[i]) {
				System.out.println("C " + (i + 1));
			}
		}
		for (int i = 0; i < dia.length; i++) {
			if (!dia[i]) {
				System.out.println("D " + (i + 1));
			}
		}
		
	}
}

Measured memory_bytes: 26224
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;

int main(){
int x,h;
double ans,height;

while(cin>>x>>h){
    if(x==0&&h==0){
        break;
    }
    height=sqrt(x*x*0.5*0.5+h*h);
    ans=(double)(x*x+4*(x*height*0.5));

    printf("%.6f\n",ans);
}
    return 0;
}


Measured memory_bytes: 3184
import math
from collections import deque

N = int(input())

a = []
b = []
for i in range(N):
    i1, i2 = map(int, input().split())
    g = math.gcd(i1,i2)
    if g == 0:
        a.append(i1)
        b.append(i2)
        continue
    x = i1 // g
    y = i2 // g
    if x < 0:
        x = - x
        y = - y 
    a.append(x)
    b.append(y)

P = {}
for i in range(N):
    if b[i] < 0:
        tmp = b[i]
        b[i] = a[i]
        a[i] = - tmp
        sgn = 1
    elif a[i] == 0 and b[i] != 0:
        a[i] = b[i]
        b[i] = 0
        sgn = 1
    else :
        sgn = 0

    if (a[i],b[i]) in P:
        P[(a[i],b[i])][sgn]=P[(a[i],b[i])][sgn] + 1
    elif sgn == 0 :
        P[(a[i],b[i])]=[1,0]
    else :
        P[(a[i],b[i])]=[0,1]


MOD = 1000000007
a1 = 1 
ans0=0
for k in P:
    if k == (0,0):
        ans0 = P[k][0]
    else:
        a1 = a1*(pow(2,P[k][0],MOD)+pow(2,P[k][1],MOD) - 1) % MOD

if ans0 != 0:
    ans = ans0 + a1 -1
else:
    ans = a1 -1
print(ans%MOD)



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

using namespace std;

typedef long long ll;

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

    int a, b;
    cin >> a >> b;
    int result;

    if (a > b) {
        result += a;
        a--;
    } else {
        result += b;
        b--;
    }
    if (a > b) {
        result += a;
        a--;
    } else {
        result += b;
        b--;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

const MOD: i64 = 1000000007;

fn solve(n: i64, k: i64) -> i64 {
    let mut x: i64 = 0;
    let mut y: i64 = 0;
    for i in 1..k {
        x = x + (n - i + 1);
        x = x % MOD;
        y = y + i - 1;
        y = y % MOD;
    }
    let mut s: i64 = 0;
    for m in k..=(n+1) {
        x = x + (n - m + 1);
        x = x % MOD;
        y = y + m - 1;
        y = y % MOD;
        s = (s + x - y + 1 + MOD) % MOD;
    }
    s
}

fn main() {
    input! {
        n: i64,
        k: i64,
    }
    let r = solve(n, k);
    println!("{}", r);
}


Measured memory_bytes: 2176
#!/usr/bin/env python

N = input()

n = int(N)

list1 = list(range(n))

for i in range(n) :
	list1[i] = list1[i] + 1

#print(list1)

list2 = []

list2 = input().split()  

list2 = [int(n) for n in list2]

#print(list2)

judge = 0

for i in range(n) : 
	if list1[i] != list2[i] :
		judge = judge + 1

if judge <= 2 :
	print('YES')

else :
	print('NO') 






Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
public class Main{
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
	public static void main(String[] args) {
		FastReader in  = new FastReader();
		String s = in.next();
		int max = 0;
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) == 'R'){
				int count = 0;
				for(int j = i; j < s.length() && s.charAt(j) == 'R'; j++){
					count++;
					i = j;
				}
				max = Math.max(max,count);
			}
		}
		System.out.println(max);

	}
}

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

int main(){
  int inp=0;
  cin>>inp;
  if(inp%10==3)cout<<"bon";
  else if(inp%10==0)cout<<"pon";
  else if(inp%10==1)cout<<"pon";
  else if(inp%10==6)cout<<"pon";
  else if(inp%10==8)cout<<"pon";
  else cout<<"hon";
  return 0;
  
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int mod = 1000000007;

int main() {
	int n;
	string s1, s2;
	cin >> n >> s1 >> s2;

	vector<long long> dp(n, 0);
	dp[0] = 1;

	if (s1[0] == s2[0]) {
		dp[0] = 3;
	} else {
		dp[0] = 3 * 2;
	}

	for (int i = 1; i < n; i++) {
		if (s1[i] == s1[i-1]) {
			dp[i] = dp[i-1];
		} else if (s1[i] == s2[i]) {
			if (s1[i-1] == s2[i-1]) {
				dp[i] = dp[i-1] * 2 % mod;
			} else {
				dp[i] = dp[i-1];
			}
		} else if (s1[i-1] == s2[i-1]) {
			dp[i] = dp[i-1] * 2 % mod;
		} else {
			dp[i] = dp[i-1] * 3 % mod;
		}
	}
	cout << dp.back() << endl;
	return 0;
}


Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

#define amen ;
#define vec vector
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef double d;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;
typedef unsigned int ui;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    double x, y;
    cin >> x >> y;
    cout.precision(3);
    cout<< fixed;
    cout << x / y;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
 
 
using namespace std;
 
int main()
{
	string s, ans;
	int n;
	//int count=0;
 
	cin >> s;
	n = s.size();
		
	for (int i = 0; i < n; i+=2) 
	{
 
		ans += s.at(i);
 
	}
 
	cout << ans << endl;
 
 
	return 0;
 
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

long long fast_pow(long long a, long long b)
{
	long long ret = 1;
	for (; b; b >>= 1) {
		if (b & 1) ret *= a;
		a *= a;
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	long long N, P, ans = 1;
	cin >> N >> P;
	if (N == 1) {
		cout << P << '\n';
		return 0;
	}
	for (int i = 2; i <= 1000000; i++) {
		int cnt = 0;
		while (P%i == 0) {
			P /= i;
			cnt++;
		}
		ans *= fast_pow(i, cnt / N);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
import sys
n=int(input())
array=list(map(int, input().split()))

if not (0<=min(array) and max(array)<n):
    print(0)
    sys.exit()

if n%2==0:
    if (n**2)/2 != sum(array):
        print(0)
        sys.exit()
else:
    if (n**2-1)/2 != sum(array):
        print(0)
        sys.exit()

sub_list=list(set(array))

if n%2==0:
    if int(n/2)==len(sub_list):
        print((2 ** int(n / 2))%(10**9 + 7))
    else:
        print(0)
else:
    if int(n/2)==len(sub_list)-1:
        print((2 ** int(n / 2)) % (10 ** 9 + 7))
    else:
        print(0)

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    vector<ll> a;
    ll temp;temp=0;
    ll s;s=0;
    REP(i,N){
        cin>>temp;
        s+=temp;
        a.pb(temp);
    }
    ll sunuk;sunuk=0;
    ll ans;ans=INF;
    if(N==2){
        ans=abs(a[1]-a[0]);
        print(ans);
        return 0;
    }
    REP(i,N-1){
        sunuk+=a[i];
        ans=min(ans,abs(s-2*sunuk));
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int N=305;
ll sum;
int a[N][N],p[N][N];
int n;
int main() {
//	freopen("1.in","r",stdin);
	cin>>n;
	F(i,1,n) F(j,1,n) cin>>a[i][j],sum+=a[i][j];
	F(k,1,n) F(i,1,n) F(j,1,n) 
		if(a[i][k]+a[k][j]<a[i][j]){
			cout<<-1;return 0;
		}
	F(k,1,n) F(i,1,n) F(j,1,n) 
		if(a[i][k]+a[k][j]==a[i][j]&&i!=k&&k!=j&&i!=j)
			p[i][j]=1;
	F(i,1,n) F(j,1,n)
		if(p[i][j]) sum-=a[i][j];
	cout<<sum/2;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)

{

  int a,b,d,r;

  double f;

  scanf("%d %d",&a,&b);

  d=a/b;

  r=a%b;

  f=(double)a/(double)b;

 printf("%d %d %lf",d,r,f);

  return 0;

}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int now = 0;
    vector<int> ans;
    while (now < n) {
        for (int i = min(m, n-now); i >= 1; --i) {
            if (s[now+i] == '0') {
                ans.push_back(i);
                now += i;
                break;
            }
            if (i == 1) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    rep(i, ans.size()) printf("%d%c", ans[i], i==n-1?'\n':' ');
}

Measured memory_bytes: 1096
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		boolean[] tri = new boolean[1000001];
		for (int i = 1; i * (i + 1) / 2 <= 100000; i++) {
			int a = i * (i + 1) / 2;
			tri[a] = true;
		}
		loop: while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int sum = 0;
			List<Integer> list = new LinkedList<Integer>();
			for (int i = 0; i < n; i++) {
				int a = scanner.nextInt();
				list.add(a);
				sum += a;
			}
			if (tri[sum]) {
				int res = 0;
				while (res <= 10000) {
					if (slove(list)) {
						System.out.println(res);
						continue loop;
					}
					int size = list.size();
					for (ListIterator<Integer> it = list.listIterator(); it
							.hasNext();) {
						int a = it.next();
						if (a == 1)
							it.remove();
						else
							it.set(a - 1);

					}
					list.add(size);

					res++;
				}
			}
			System.out.println(-1);
		}
	}

	private boolean slove(List<Integer> list) {
		for (int i = 0; i < list.size(); i++)
			if (i + 1 != list.get(i))
				return false;
		return true;
	}
}

Measured memory_bytes: 56668
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using Graph = vector<vector<int>>;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K, ans = 0;
  cin >> K;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        int tmp = gcd(i, j);
        ans += gcd(tmp, k);
      }
    }
  }
  cout << ans << endl;
}

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

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

#define pb push_back
#define in ,
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  rep(i, 0, 7) {
    int a, b;
    cin >> a >> b;
    cout << a - b << endl;
  }
}

Measured memory_bytes: 3144
s = input()
t = input()

ans = False
for i in range(len(s)):
    rotated_s = ""
    if i == 0:
        rotated_s = s[i:-1] + s[-1]
    else:
        rotated_s = s[i:-1]+ s[-1] + s[0:i]
    
    if rotated_s == t:
        ans = True

if ans is True:
    print("Yes")
else:
    print("No")




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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  map<ll,ll> m;
  rep(i,n){
    ll k;
    cin >> k;
    if(k >= 3200) k = 3200;
    m[k / 400]++;
  }
  ll a,b;
  a = m.size();
  if(m.count(8)){
    a--;
  }
  if(a <= 0) a = 1;
  b = m.size();
  if(m.count(8)){
    b--;
    b += m[8];
    /* b = min(b,7LL); */
  }
  cout << a << ' ' << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int N, K, D[10] = {0};

  cin >> N >> K;
  for(int i = 0; i < K; i++){
    int x;
    cin >> x;
    D[x] = 1;
  }

  int ans = N;
  bool  flag = true;

  while(flag){
    string str = to_string(ans);
    for(int j = 0; j < str.size(); j++){

      if(D[str[j] - '0'] == 1){
        flag = true;
        break;
      }else{
        flag = false;
      }
    }
    ans++;
  }
  ans--;

  cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
N, M = gets.chomp.split.map(&:to_i)
dir = Array.new(N).map{Array.new()}
M.times do 
	line = gets.chomp.split.map(&:to_i)
	dir[line[0]-1].push [line[1]-1,line[2]]
	dir[line[1]-1].push [line[0]-1,line[2]*-1]
end
S = Array.new(N)
node = []
N.times do |n|
	if S[n] == nil
		S[n] = 0
		node.push [n, 0]
		while !node.empty?
			cur = node.shift
			dir[cur[0]].delete_if do |d|
				false
				if !S[d[0]]
					S[d[0]] = cur[1]+d[1]
				else
					if S[d[0]] != cur[1]+d[1]
						print "No\n"
						exit
					end
				end
				node.push [d[0], cur[1]+d[1]]
				true
			end
		end
	end
end
print "Yes\n"

Measured memory_bytes: 54908
#include <iostream>

using namespace std;

int main() {

	int a, b, c, d;

	scanf("%d %d %d %d", &a, &b, &c, &d);

	int n = 0;

	if (c < b && d > a) {
		n = (b < d ? b : d) - (c > a ? c : a);
	}

	printf("%d", n);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  int a[210000];
  cin >> N;
  rep(i,N) cin >> a[i];

  sort(a,a+N);

  int prev=0;
  rep(i,N){
    if(prev==a[i]) {
      cout << "NO" << endl;
      return 0;
    }
    prev = a[i];
  }

  cout << "YES" << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1000000
 
 
int n,M[100][100],color[100],d[100],p[100];
 
//プリム法
int prim(){
  int i,u;

  //初期化
  for( i = 0; i < 100; i++ ){ 
    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;   
  }
  
  d[0] = 0;
  
  
  while(1){
    u = -1;
    int mincost = INFTY;
     
    for( i = 0; i < n; i++ ){
      if( color[i] != BLACK && d[i] < mincost ){
    mincost = d[i];
    u = i;
      }
    }
    
    if( u == -1 ) break;
 
    color[u] = BLACK;
 
    //最小全域木の更新
    for( int v = 0; v < n; v++ ){
      if( color[v] != BLACK && M[u][v] != INFTY ){
    if( M[u][v] < d[v] ){
      d[v] = M[u][v];
      p[v] = u;
      color[v] = GRAY;
    }
      }
    }
  }
  //最小全域木の辺の重みの総和をもとめる
  int sum = 0;
  for( i = 0; i < n; i++ ){
    if( p[i] != -1 ) sum+= M[i][p[i]];
  }
  return sum;
}
 
int main(){
  //入力
  cin >> n;
  for( int i = 0; i < n; i++ ){
    for( int j = 0; j < n; j++ ){
      cin >> M[i][j];
      if( M[i][j] == -1 ) M[i][j] = INFTY;
    }
  }
 
  cout << prim() << endl;
 
  return 0;
}

Measured memory_bytes: 1200
package main

import (
	"fmt"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	workDays := 0
	var a int
	for i := 0; i < M; i++ {
		fmt.Scan(&a)
		workDays += a
	}
	if N-workDays >= 0 {
		fmt.Println(N - workDays)
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 2372
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define s second
#define int long long
#define pb push_back
#define pencho ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N 3000
#define mod 1000000007

long double dp[N][N], p[N];


long double solveDp(int x, int y) {
       if (y < x)       return 0;
       if (x < 0 || y < 0)  return 0;
       if ((int)dp[x][y] != -1)      return dp[x][y];
       dp[x][y] = p[y] * solveDp(x - 1, y - 1) + (1.0 - p[y]) * solveDp(x, y - 1);
       return dp[x][y];
}


void solve() {
       pencho
       int n;     cin >> n;
       for (int i = 1; i <= n; i++)       cin >> p[i];
       for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i][j] = -1;
       dp[0][0] = 1;

       long double s = 0;
       for (int i = n; i > n / 2; i--)          s += solveDp(i, n);
       cout << fixed << setprecision(10) << s;
}


signed main()
{
#ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("o.txt", "w", stdout);
#endif

       solve();
}

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

int main() {
  int a;
  int b;
  int c;
  int d;
  
  cin >> a >> b >> c >> d;
  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<P> c;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        c.emplace_back(a, b);
    }
    sort(c.begin(), c.end());

    vector<P> ans;
    int cc = 0;
    rep(i, m){
        if(i == 0){
            ans.push_back(c[i]);
            cc++;
            continue;
        }

        if(ans[cc-1].second > c[i].first){
            ans[cc-1].first = max(ans[cc-1].first, c[i].first);
            ans[cc-1].second = min(ans[cc-1].second, c[i].second);
            continue;
        }
        ans.push_back(c[i]);
        cc++;
    }
    cout << cc << endl;

    return 0;
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[21][1<<21];
ll p=1000000007;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n][n];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    for(ll i=0;i<n;i++)
    {
        if(a[0][i]==1)
        {
            dp[0][1<<i]=1;
        }
    }
    for(ll i=1;i<n;i++)
    {
        vector<ll>v;
        ll i1=i+1;
        for(ll j=0;j<(n-i1);j++)
        {
            v.push_back(0);
        }
        for(ll j=0;j<i1;j++)
        {
            v.push_back(1);
        }
        do{
            ll sum=0;
            for(ll j=0;j<n;j++)
            {
                sum=sum+(v[j])*(1<<j);
            }
            //cout<<sum<<endl;
            for(ll j=0;j<n;j++)
            {
                if(a[i][j]==1)
                {
                    dp[i][sum]=(dp[i][sum]+dp[i-1][sum^(1<<j)])%p;
                }
            }
        }while(next_permutation(v.begin(),v.end()));
        //cout<<endl;
    }
    cout<<dp[n-1][(1<<n)-1];
	return 0;
}

Measured memory_bytes: 307456
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if ((a == b) && (a != c))
    {
        printf("Yes\n");
    }
    else if ((a == c) && (a != b))
    {
        printf("Yes\n");
    }
    else if ((c == b) && (a != c))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $a,$b,$c);
$arr = [$a,$b,$c];
$z = 0;
foreach($arr as $ar)
switch($ar){
    case(5):
      	$z += 1;
    	break;
    case(7):
      	$z += 10;
    	break;
  default:
      	break;
}
if($z == 12){
  	echo "YES";
}else{
  	echo "NO";
}
?>


Measured memory_bytes: 3828