akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
int main(void)
{
  int n, b;
  vector<int> v;

  while(cin >> n, n){
    v.clear();
    for(int i = 0;i < n; i++){
      cin >> b;
      v.push_back(b);
    }
    int ans;
    for(ans = 0;ans <= 10000; ans++){
      bool f = true;
      for(int i = 0;i < v.size(); i++)
	if(v[i] != i + 1) f = false;
      if(f) break;
      v.push_back(v.size());
      for(int i = 0;i < v.size() - 1; i++)
	if(--v[i] == 0) v.erase(v.begin() + i--);
    }
    if(ans >= 10000) cout << -1 << endl;
    else cout << ans << endl;
  }
}


Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int w, h, n; cin >> w >> h >> n;
    vector<pair<P,int>> query;
    P c1 = make_pair(0,0);
    P c2 = make_pair(w,h);
    rep(i,n){
        int x, y, a; cin >> x >> y >> a;
        if(a == 1){
            if(c1.first < x) c1.first = x;
        }else if(a == 2){
            if(c2.first > x) c2.first = x;
        }else if(a == 3){
            if(c1.second < y) c1.second = y;
        }else{
            if(c2.second > y) c2.second = y;
        }
    }
    int ans = max(c2.first - c1.first, 0) * max(c2.second - c1.second, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
// ~maqsat~

// #pragma GCC target ("avx2")
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)
#define ever ;;

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e6 + 345;
const ll MOD = 998244353;
const ll INF = 1e15 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

main() {
	fre("");
	ACCELERATE;

	ll n, a, b;
	cin >> n >> a >> b;
	
	if ((b - a) % 2 == 0) cout << (b - a) / 2;
	else cout << min(a - 1, n - b) + 1 + (b - a - 1)/ 2;

	return 0;
}
/*
 
*/


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

int main() {
  int N, M;
  cin >> N >> M;
  int A[50], B[50], C[50], D[50];
  for (int i=0;i<N;++i) {
    cin >> A[i] >> B[i];
  }
  for (int j=0;j<M;++j) {
    cin >> C[j] >> D[j];
  }
  for (int i=0;i<N;++i) {
    int res1=abs(A[i]-C[0])+abs(B[i]-D[0]), checkpoint=1;
    for (int j=0;j<M;++j) {
      int res2=abs(A[i]-C[j])+abs(B[i]-D[j]);
      if (res1>res2) {
        res1=res2;
        checkpoint=j+1;
      }
    }
    cout << checkpoint << endl;
  }
  return 0;
}       

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;

  long ans = 0;
  bool before = false;

  rep (i, N) {
    long x;
    cin >> x;

    if (before and x > 0) {
      x--;
      ans++;
    }

    ans += x / 2;
    x %= 2;

    before = x == 1;
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<int>> c(10, vector<int>(10, 0));
    rep1(i, n) {
        int tmp = i;
        while (tmp >=10) tmp/=10;
        c[tmp][i%10]++;
    }
    int ans = 0;
    rep1(i, 9) rep1(j, 9) ans += c[i][j] * c[j][i];
    cout << ans << endl;
    return 0; 
}

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


using namespace std;



const int MAXN = 500 * 1000 + 23, INF = 1000 * 1000 * 1000 + 23;












int n, k, p[MAXN], fen[MAXN], inv[MAXN], od[MAXN], seg[MAXN << 2], ml[MAXN << 2];

inline void upd(int p) { for (p++; p <= MAXN; p += (p & -p)) fen[p]++; }
inline int pget(int p) {
	int ret = 0;
	for (; p; p -= (p & -p)) ret += fen[p];
	return ret;
}
inline int fget(int l, int r) { return pget(min(r, n)) - pget(max(l, 0)); }

void add(int l, int r, int val, int v = 1, int st = 0, int ed = n) {
	if (l >= ed || st >= r) return;
	if (l <= st && ed <= r) {
		seg[v] += val;
		ml[v] += val;
		return;
	}
	int mid = ((st + ed) >> 1);
	add(l, r, val, v << 1, st, mid), add(l, r, val, (v << 1) | 1, mid, ed);
	seg[v] = min(seg[v << 1], seg[(v << 1) | 1]) + ml[v];
}
int get(int v = 1, int st = 0, int ed = n) {
	if (ed - st == 1) return st;
	int mid = ((st + ed) >> 1);
	if (seg[(v << 1) | 1] <= seg[v << 1]) return get((v << 1) | 1, mid, ed);
	else return get(v << 1, st, mid);
}




int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		inv[--p[i]] = i;
	}
	for (int i = n - 1; ~i; i--) {
		od[inv[i]] = fget(inv[i] - k + 1, inv[i] + k);
		upd(inv[i]);
	}
	for (int i = 0; i < n; i++) add(i, i + 1, od[i]);
	for (int i = n - 1; ~i; i--) {
		int x = get();
		p[x] = i;
		add(x, x + 1, INF);
		add(max(x - k + 1, 0), min(n, x + k), -1);
	}
	for (int i = 0; i < n; i++) cout << p[i] + 1 << '\n';
	return 0;
}

Measured memory_bytes: 24960
#include <iostream>
#include <vector>
#include <ios>
using namespace std;
struct Node
{
    Node(int k) : depth(0) { vChildId.resize(k, -1); }
    int depth;
    vector<int> vChildId;
};
 
void SetNodeDepthRecursive(Node* n, vector<Node*>& vNode)
{
    int s = n->vChildId.size();
    if (0 == s) return;
    for (int i = 0; i < s; ++i){
        Node* cn = vNode[n->vChildId[i]];
        cn->depth = n->depth + 1;
        SetNodeDepthRecursive(cn, vNode);
    }
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int nu, id, k, c;
    cin >> nu;
    vector<int> vParentId(nu, -1);
    vector<Node*> vNode(nu, (Node*)0);
    while (nu--){
        cin >> id >> k;
        vNode[id] = new Node(k);
        for (int j = 0; j < k; ++j){
            cin >> c;
            vNode[id]->vChildId[j] = c;
            vParentId[c] = id;
        }
    }
    vector<Node*> vRoot;
    for (int i = 0; i < vNode.size(); ++i){
        if (vParentId[i] == -1)
            vRoot.push_back(vNode[i]);
    }
    for (int i = 0; i < vRoot.size(); ++i)
        SetNodeDepthRecursive(vRoot[i], vNode);
 
    Node* n;
    int pid;
    for (int i = 0; i < vNode.size(); ++i){
        n = vNode[i];
        pid = vParentId[i];
        cout << "node " << i << ": parent = " << pid << ", depth = " << n->depth << ", ";
        if (pid == -1){
            cout << "root, [";
            if (n->vChildId.size() == 0)
                cout << "]\n";
        }
        else if (n->vChildId.size() == 0) cout << "leaf, []\n";
        else cout << "internal node, [";
        if (n->vChildId.size() != 0){
            int cs = n->vChildId.size();
            for (int j = 0; j < cs; ++j){
                cout << n->vChildId[j];
                if (j < cs - 1)
                    cout << ", ";
            }
            cout << "]\n";
        }
    }
 
    return 0;
}

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

int solve(string str){
    char x[9], y[9];
    x[8] = y[8] = 0;
    string rev;
    for(int i = 0;i < 8;i++)x[i] = str[i];
    sort(x, x + 8);
    for(int i = 0;i < 8;i++)y[i] = x[7 - i];
    int a, b;
    sscanf(x, "%d", &a);
    sscanf(y, "%d", &b);
    return abs(a- b);
}

int main(){
    int n;
    string str;
    cin >> n;
    for(int i = 0;i < n;i++){
	cin >> str;
	cout << solve(str) << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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;
    }
}

int main(void)
{
    string s, t, u;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), std::greater<char>());
    if (s < t)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;
const ll MAX_N = 100000 * 2 + 10;
int main(){
	ll N; cin >> N;
	vl cs;
	FOR(i, 0, N) {
		ll tmp; cin >> tmp;
		if (sz(cs) == 0 || tmp != cs.back()) {
			cs.pb(tmp);
		}
	}

	vl dp(sz(cs)), last(MAX_N);
	dp[0] = 1;

	FOR(i, 0, sz(cs)) {
		if (i != 0) dp[i] = (dp[i-1] + last[cs[i]]) % MOD;
		last[cs[i]] = dp[i];
	}

	cout << dp.back() << endl;

	return 0;
} //cin.tie(0) bei schnellem Wechseln



Measured memory_bytes: 5104
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>

using namespace std;
using ld = long double;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for (ll i=1; i<=n; i++) {
        ll m = n/i;
        ans += i*m*(m+1)/2;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


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

  int n;
  string s;
  cin>>n;
  cin>>s;
  int l=0,r=0;
  bool b[210000]={};
  rep(i,s.size()){
    if(s[i]=='B'&&(r-l)%2==0||s[i]=='W'&&(r-l)%2){
      r++;
      b[i]=true;
    }else{
      l++;
    }
  }

  if(r!=l){
    cout<<0<<endl;
    return 0;
  }

  /*
  rep(i,s.size()){
    if(b[i]) cout<<'R';
    else cout<<'L';
  }
  cout<<endl;
  */

  int ans=1;
  l=0;
  rrep(i,s.size()-1){
    if(b[i]){
      ans*=l;
      ans%=M;
      l--;
    }else{
      l++;
    }
  }

  FOR(i,2,r+1){
    ans*=i;
    ans%=M;
  }


  cout<<ans<<endl;


}

Measured memory_bytes: 788
while True:
    min = 1000
    max = 0
    sum = 0
    
    n=int(input())
    if n ==0:
        break
    for i in range(n):
        s=int(input())
        if s < min:
            min = s
        if s > max:
            max = s
        sum += s
    print((sum - min - max)//(n - 2))



Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N; int ans = 999999999;
    rep(i,N+1){
        int cnt=0;
        int t=i;
        while(t>0){
            cnt+=t%6;
            t/=6;
        }
        t=N-i;
        while(t>0){
            cnt+=t%9;
            t/=9;
        }
        ans=min(ans,cnt);
    }
    cout << ans << endl;

    return 0;
}


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

import sys


def main():
    input = sys.stdin.readline
    N, R = map(int, input().split())
    if N >= 10:
        rate = R
    else:
        rate = R + 100 * (10 - N)
    print(rate)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n; char s[MAXN+1];

char ret[MAXN+1];

char calc(char kind,char ans,char other) {
	char same=other,diff=other=='S'?'W':'S';
	if(kind=='S') return ans=='o'?same:diff; else return ans=='o'?diff:same;
}

void run() {
	scanf("%d%s",&n,s);
	REP(a,2) REP(b,2) {
		ret[0]=a==0?'S':'W';
		ret[1]=b==0?'S':'W';
		FOR(i,2,n) ret[i]=calc(ret[i-1],s[i-1],ret[i-2]);
		ret[n]='\0';
		bool ok=calc(ret[n-1],s[n-1],ret[n-2])==ret[0]&&calc(ret[0],s[0],ret[n-1])==ret[1];
		//printf("%d %d -> %s (%c,%c)\n",a,b,ret,calc(ret[n-1],s[n-1],ret[n-2]),calc(ret[0],s[0],ret[n-1]));
		if(ok) { printf("%s\n",ret); return; }
	}
	printf("-1\n");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 512
# coding: utf-8
import os
import time
import re
import math

def main():
    s=input().replace("BC","D")
    max=0
    acount=0
    for a in range(len(s)):
        if s[a]=='D':
            max+=acount
        elif s[a]=='A':
            acount+=1
        else:
            acount=0
    print(max)



start=time.time();
main()
#print(time.time()*1000-start*1000)

Measured memory_bytes: 3752
import sys
input = sys.stdin.buffer.readline

N, M = map(int,input().split())
town = [[] for _ in range(N)]
ans = [0] * M

for i in range(M):
    a, b = map(int,input().split())
    town[a-1].append((b,i))

for i in range(N):
    town[i].sort()
    for k in range(len(town[i])):
        index = town[i][k][1]
        t = town[i][k][0]
        ans[index] = str(i+1).zfill(6) + str(k+1).zfill(6)

for i in ans:
    print(i)


Measured memory_bytes: 71856
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

K=int(input())
ans=0
for a in range(1,K+1):
    for b in range(1, K + 1):
        for c in range(1,K+1):
            ans+=gcd(a,b,c)
print(ans)

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

#define int            long long int
#define float          long double
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define inf            1e18
#define set_pre(x,y)   fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
using namespace std;
int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
string buidSequence(string &s,string &t,vector<vector<int>>&dp)
{
    int n=s.length();
    int m=t.length();
    string ans;
    while(n!=0 && m!=0)
    {
        if(s[n-1]==t[m-1])
        {
            ans+=s[n-1];
            n--;
            m--;
        }
        else if(dp[n][m]==dp[n-1][m])
        {
            n--;
        } else if(dp[n][m]==dp[n][m-1])
        {
            m--;
        }
    }
    return ans;
}
int32_t main()
{
    string s;
    string t;
    cin>>s>>t;
    int n,m;
    n=s.length();
    m=t.length();
    vector<vector<int>>dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int cost=1;
            if(s[i-1]!=t[j-1])
                cost=0;
            dp[i][j]=max(max(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]+cost);
        }
    }
    string ans=buidSequence(s,t,dp);
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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 ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

//----------------ここからだよ-------------------

int main(){
    int N,M; cin>>N>>M;
    vector<pair<int,int>> sc(M);
    rep(i,M) cin>>sc[i].first>>sc[i].second;
    string n;
    bool can=true;
    rep(i,N) n.push_back('0');
    sort(sc.begin(),sc.end());
    rep(i,M){
        if(N!=1&& sc[i].first==1 && sc[i].second==0){
            can=false;
            break;
        }
        if(i<M-1 && sc[i].first==sc[i+1].first && sc[i].second!=sc[i+1].second){
            can = false;
            break;
        }
        char num = '0'+sc[i].second;
        n[(sc[i].first) -1]= num;
    }
    if(N!=1 && n[0]=='0') n[0]='1';
    if(can){
        cout<<n<<endl;
    }else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 256
def In(): return map(int, raw_input().split())
def D(a,b): return ((a[0]-b[0])**2+(a[1]-b[1])**2)**.5
def f(P,O): return P[0]-O[0], P[1]-O[1]
def dot(a,b): return a[0]*b[0]+a[1]*b[1]
def cross(a,b): return a[0]*b[1]-a[1]*b[0]

def ab2c(a,b,c):
  if dot(f(c,a),f(b,a))<0: return D(a,c)
  if dot(f(c,b),f(a,b))<0: return D(b,c)
  return abs(cross(f(b,a),f(c,a)))/D(b,a)

def isIn(P,O,P1,P2):
  a11,a21 = f(P1,O)
  a12,a22 = f(P2,O)
  x0,y0 = f(P,O)
  det = 1.0*a11*a22-a12*a21
  x = (a22*x0-a12*y0)/det
  y = (-a21*x0+a11*y0)/det
  return 0<=x<=1 and 0<=y<=1 and 0<=x+y<=1

def check(P4,r,P1,P2,P3):
  if max([D(P4,P1),D(P4,P2),D(P4,P3)])<=r: return 2
  h1 = ab2c(P1,P2,P4)
  h2 = ab2c(P2,P3,P4)
  h3 = ab2c(P3,P1,P4)
  if isIn(P4,P1,P2,P3):
    if min([h1,h2,h3])>=r: return 1
  elif min([h1,h2,h3])>r: return 0
  return 3

while 1:
  P1 = In()
  if P1[0]== P1[1]==0: break
  P2 = In()
  P3 = In()
  P4 = In()
  r = int(raw_input())
  print 'dabc'[check(P4,r,P1,P2,P3)]

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


int main()
{
	int a, b;
	cin >> a >> b;
	if(a == b){
		cout << "a == b" << endl;
	}
	else {
		if (a < b) {
			cout << "a < b" << endl;
		}
		else {
			cout << "a > b" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define ll long long int
#include <iostream>
using namespace std;

int main() {
    ll a[3][3];
  for(ll i=0;i<3;i++){
  for(ll j=0;j<3;j++)
  {cin>>a[i][j];}
  }
  ll n;cin>>n;
  while(n--)
  {
  ll x;cin>>x;
     for(ll i=0;i<3;i++){
  for(ll j=0;j<3;j++)
  {if(a[i][j]==x) {a[i][j]=0;break;}}
  }
  }
  ll x=0;
  for(ll i=0;i<3;i++){ll h=1;
  for(ll j=0;j<3;j++){
  if(a[i][j]!=0) {h=0;break;}}
   if(h==1) {x=1;break;}                   
  }
  for(ll i=0;i<3;i++){ll h1=1;
  for(ll j=0;j<3;j++){
  if(a[j][i]!=0) {h1=0;break;}}
   if(h1==1) {x=1;break;}                   
  }
  if(a[0][0]==a[1][1]&&((a[1][1]==a[2][2])&&(a[2][2]==a[0][0]))) x=1;
    if(a[0][2]==a[1][1]&&((a[1][1]==a[2][0])&&(a[2][0]==a[0][2]))) x=1;
    if(x==1) cout<<"Yes";else cout<<"No";
  return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
	string T;
	cin >> T;
	int t = T.size();
	string ans;
	REP(i,t){
		if(T[i]=='?') ans.push_back('D');
		else ans.push_back(T[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3864
cnt = int(input())
numbers = list(map(int, input().split(' ')))


def selectionsort(A, N):
    '''
    :param A: N個の要素を含む０オリジンの配列
    :param N: Aの要素数
    :return:
    '''
    swap_cnt = 0

    for i in range(0, N):
        minj = i
        for j in range(i+1, N):
            if A[j] < A[minj]:
                minj = j

        if minj != i:
            A[i], A[minj] = A[minj], A[i]
            swap_cnt += 1

    return ' '.join(map(str, A)), swap_cnt

numbers, swap_cnt = selectionsort(numbers, cnt)
print(numbers)
print(swap_cnt)



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

int main(){
   string s,t;
   bool flag = true;
   cin >> s >> t;
   if(s.size()+1 != t.size()) flag = false;
   if(s.compare(t.substr(0,s.size())) != 0) flag = false;
   if(flag) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;  
}

Measured memory_bytes: 3628
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *NOIP 2019 RP++                                           *
 ***********************************************************/
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) ((x>y)?x:y)
#define Min(x,y) ((x<y)?x:y)
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (int)(1<<30)
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register ll a=b;a<=c;a++)
#define FORD(a,b,c) for (register ll a=b;a>=c;a--)
using namespace std;
inline ll read(){
    ll x=0,f=1;char c;
    for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());return x*f;
}

template<typename T>
inline void write(T a){
    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}

inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//
ll x2,x3,y2,y3;
signed main(){
    #ifdef _WIN32
        freopen("0.in","r",stdin);
//        freopen("0.out","w",stdout);
        long double be=clock();
    #endif
    ll s=read(),sq=sqrt(s),p;
    if(1ll*sq*sq==s){
    	x2=y3=0,x3=y2=sq;
	}else{
		++sq;
		p=1ll*sq*sq-s;
		x3=1;
		if(1ll*sq*(sq-1)-s>=0){
			y2=1ll*sq*(sq-1)-s;
			x2=sq;y3=sq-1;
		}else{
			y2=p;x2=y3=sq;
		}
	}
	writeln(0,0,x2,y2,x3,y3);
    #ifdef _WIN32
    	writeln((Abs(1ll*x2*y3-1ll*x3*y2)==s));
    	if((Abs(1ll*x2*y3-1ll*x3*y2)==s)&&0<=x2&&x2<=1000000000&&0<=y2&&y2<=1000000000&&0<=x3&&x3<=1000000000&&0<=y3&&y3<=1000000000)puts("Accepted");else puts("Wrong_Answer");
        long double en=clock();
        printf("Time: %.0Lfms",en-be);
        fclose(stdin);fclose(stdout);
    #endif
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 2000000
 
int h, a[MAX+1];
 
void maxHeapify(int);
 
int main(){
  int i;
 
  scanf("%d", &h);
  for(i = 1;i <= h;i++){
    scanf("%d", &a[i]);
  }
  for(i = h/2;i >= 1;i--){
    maxHeapify(i);
  }
  for(i = 1;i <= h;i++){
    printf(" %d", a[i]);
  }
  printf("\n");
  return 0;
}
 
void maxHeapify(int i){
  int l, r, largest, b;
 
  l = 2 * i;
  r = 2 * i + 1;
  if(l <= h && a[l] > a[i]){
    largest = l;
  }
  else largest = i;
  if(r <= h && a[r] > a[largest]){
    largest = r;
  }
  if(largest != i){
    b = a[i];
    a[i] = a[largest];
    a[largest] = b;
    maxHeapify(largest);
  }
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    string s; cin >> s;
    set<char> se;
    for (int i = 0; i < 3; ++i) {
        se.insert(s[i]);
    }
    string ans = "No";
    if(se.size()==2) ans = "Yes";
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <tuple>

using namespace std;

int main() {
  int n,k;
  int ans = 0;
  string s;
  cin >> n >> k;
  cin >> s;

  int start,i,cnt;
  start = i = cnt = 0;
  while(i<n) {
    char c = s[i];
    while(i<n && c==s[i]) i++;  
    cnt++;
    if (i<n && cnt < 2*k+1) continue;
    else ans += (i-start)-1;
    start = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        if(1 <= n && n <= 9) {
        	System.out.println(n);
        } else if(10 <= n && n <= 99) {
        	System.out.println(9);
        } else if(100 <= n && n <= 999) {
        	System.out.println(9 + n - 99);
        } else if(1000 <= n && n <= 9999) {
        	System.out.println(909);
        } else if(10000 <= n && n <= 99999) {
        	System.out.println(909 + n - 9999);
        } else {
        	System.out.println(90909);
        }
        
        
        sc.close();
    }
}


Measured memory_bytes: 23892
#include<iostream>
using namespace std;
typedef long long ll;
ll n;
int main()
{
	cin>>n;
	ll a[n+1],maxv=-1e18,minv=(1<<30)-1;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
		maxv=max(maxv,a[i]);
		minv=min(minv,a[i]);
	}
	cout<<maxv-minv;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ans = 0
for i in range(n+1):
    if i%3 == 0 and i%5 == 0:
        ans += 0
    elif i%3 == 0:
        ans += 0
    elif i%5 ==0:
        ans += 0
    else:
        ans += i

print(ans)

Measured memory_bytes: 65808
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    int n;
    cin>>n;
    if(n<10){
    cout<<n<<'\n';
    }else if(n>=10 && n<100){
    cout<<9<<'\n';
    }else if(n>=100 && n<1000){
    cout<<n-90<<'\n';
    }else if(n>=1000 && n<10000){
    cout<<909<<'\n';
    }else if(n>=10000 && n<100000){
    cout<<n-9090<<'\n';
    }else if(n==100000){
    cout<<90909<<'\n';
    }
    }

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main() {
  int n, a[105], count[1005], flag, temp_cnt, ans;
  cin >> n;
  for (int i = 1; i <= n; i++){
      cin >> a[i];
  }
  for (int i = 1; i <= n; i++){
      count[i]=0;
  }  
  
  flag=0;
  for (int i = 2; i <= n; i++){
    if(flag==0){
      if(a[i]==a[i-1]) flag=1;
      temp_cnt=2;
      //printf("a");
    }
    else{
      if(a[i]==a[i-1]){
	//printf("b");
	temp_cnt++;
      }
      else{
	count[temp_cnt]++;
	flag=0;
	//printf("c");
      }
    }
  }
  if(flag==1) count[temp_cnt]++;
 
  ans=0;
  for (int i = 1; i <= n; i++){
      ans += count[i]*(i/2);
  }
 
  cout << ans << endl;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int row = in.nextInt();
        int col = in.nextInt();
        String [] original = new String[row];
        for(int i = 0; i < row; i++){
            original[i] = in.next();
        }
        //System.out.println("first fase finished");
        List<Integer> delete_row = new ArrayList<>();
        int new_row = row;
        for (int i = 0; i < row; i++){
            boolean delete = true;
            for(int j = 0; j < col; j++){
                if(original[i].charAt(j) == '#'){
                    delete = false;
                    break;
                }
            }
            if (delete){
                delete_row.add(i);
                new_row--;
            }
        }
        //System.out.println(new_row);
        List<Integer> delete_col = new ArrayList<>();
        int new_col = col;
        for (int i = 0; i < col; i++){
            boolean delete = true;
            for (int j = 0; j < row; j++){
                if(original[j].charAt(i) == '#'){
                    delete = false;
                    break;
                }
            }
            if (delete){
                delete_col.add(i);
                new_col--;
            }
        }
        for (int i = 0; i < row; i++){
            String ans = "";
            if (delete_row.contains(i))continue;
            for (int j = 0; j < col; j++){
                if (delete_col.contains(j))continue;
                ans += original[i].charAt(j);
            }
            System.out.println(ans);
        }
    }
    
}

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

void dfs(vector<int> graph[], int visited[], int v, int &total){
	visited[v] = 1;
	total++;
	for(auto x: graph[v]){
		if(visited[x] == 0)
			dfs(graph, visited, x, total);
	}
}

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

	int n, m, i, j, u, v;
	cin >> n >> m;

	vector<int> graph[n];
	for(i=0; i<m; i++){
		cin >> u >> v;
		u--; v--;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}

	vector<int> connectedSizes;
	int visited[n] = {0}, ind = 0;
	while(ind != n){
		if(visited[ind] == 1){
			ind++;
			continue;
		}
		int total = 0;
		dfs(graph, visited, ind, total);
		connectedSizes.push_back(total);
		ind++;
	}

	sort(connectedSizes.begin(), connectedSizes.end());
	// for(auto x: connectedSizes)
	// 	cout << x << " ";
	// cout << "\n";

	int sub = 0, ans = 0;
	for(i=0; i<connectedSizes.size(); i++){
		connectedSizes[i] -= sub;
		ans += connectedSizes[i];
		sub += connectedSizes[i];
	}
	cout << ans << "\n";
}

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

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

  if (D == 25) cout<<"Christmas"<<endl;
  if (D == 24) cout<<"Christmas Eve"<<endl;
  if (D == 23) cout<<"Christmas Eve Eve"<<endl;
  if (D == 22) cout<<"Christmas Eve Eve Eve"<<endl;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	int q1, b, c1, c2, q2;
	while (cin >> q1, q1) {
		cin >> b >> c1 >> c2 >> q2;
		
		int ans1 = 0, ans2 = 0;
		for (int i = 1; i <= q2; i++) {
			int nc = b - i * c1;
			int cnt = nc / c2;
			
			if (nc < 0 || i + cnt < q1) continue;
			
			ans1 = i;
			ans2 = cnt;
		}
		
		if (ans1 == 0) puts("NA");
		else printf("%d %d\n", ans1, ans2);
		 
	}
	return 0;
}

Measured memory_bytes: 3016
#include<stdio.h>
#include<stdlib.h>

int main(){

  int i,H,*key;

  scanf("%d",&H);
  key=(int *)malloc(sizeof(int)*H);
  for(i=0;i<H;i++)scanf("%d",&key[i]);

  for(i=0;i<H;i++){
    printf("node %d: ",i+1);
    printf("key = %d, ",key[i]);
    if(i!=0)printf("parent key = %d, ",key[(i+1)/2-1]);
    if(2*(i+1)<=H)printf("left key = %d, ",key[2*(i+1)-1]);
    if(2*(i+1)+1<=H)printf("right key = %d, ",key[2*(i+1)]);
    printf("\n");
  }

  free(key);

  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  int dekiru = 0;
  for (int i = 1; i <= n; i += 2) ++dekiru;
  cout << (dekiru >= k ? "YES" : "NO") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int H,k,i;
  int A[250];

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=H;i++){
    k = A[i];
    printf("node %d: key = %d, ",i,k);
    if(i/2 >= 1){
      printf("parent key = %d, ",A[i/2]);
    }
    if(i*2 <= H){
      printf("left key = %d, ",A[i*2]);
    }
    if((i*2+1) <= H){
      printf("right key = %d, ",A[i*2+1]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
package main

import(
	"fmt"
)

func main() {
	var a , b int
fmt.Scan(&a)
fmt.Scan(&b)
d := a / b
r := a % b
f := float64(a) / float64(b)
fmt.Printf("%d\n", d)
fmt.Printf("%d\n", r)
fmt.Printf("%f\n", f)
}


Measured memory_bytes: 1172
n=int(input())
a=list(map(int,input().split(" ")))
ans=0
for x in range(n):
  for y in range(x+1,n):
    for z in range(y+1,n):
      if a[x]+a[y]>a[z] and a[y]+a[z]>a[x] and a[z]+a[x]>a[y] and a[x]!=a[y] and a[y]!=a[z] and a[x]!=a[z]:
        ans=ans+1
print(ans)


Measured memory_bytes: 73864
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; 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;
  }
}

// 二項係数計算
long long 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;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  int firstr = n;
  rep(i,0,n){
    if(s[i] == 'R'){
      firstr=i;
      break;
    }
  }
  int count = 0;
  rep(i,firstr,n){
    if(s[i] == 'L'){
      rep(j,i,n){
        if(s[j] == 'L'){
          s[j] = 'R';
        }else{
          count++;
          break;
        }
      }
    }
    if(count == k)break;
  }
  if(count < k){
    rep(i,0,firstr)s[i] = 'R';
  }
  int res = 0;
  s = 'X' + s + 'X';
  rep(i,1,n+1){
    if(s[i] == 'L'){
      if(s[i] == s[i-1])res++;
    }else{
      if(s[i] == s[i+1])res++;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 512
import Data.List
f3::[Int]->Bool
f3 (a:b:c:[])
   |a==b && b==c=True
   |otherwise   =False

f2 ::[Int]->Bool
f2 (a:b:c:[])
     |a<=(-2) || b<=(-2) || c<=(-2)=False
     |otherwise           =True

f :: [Int]->[[Int]]
f (a:b:c:[]) =nub $ map sort $ ((a-2):(b-2):c:[]):((a-2):b:(c-2):[]):(a:(b-2):(c-2):[]):((a-1):b:c:[]):(a:(b-1):c:[]):(a:b:(c-1):[]):[]

f4 :: [[Int]] -> [[[Int]]]
f4 []=[]
f4 (x:xs)=(f x):f4 xs

f5 :: Int->[[Int]]->Int
f5 n xs
   |null (filter f3 xs)=f5 (n+1) (nub ( filter f2 (concat (f4 xs))))
   |otherwise=n

main = do
       x<-getLine
       let ys=[sort $ map read (words x)::[Int]]
       putStrLn $ show $ f5 0 ys

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli h,w;
mat s;

int main(){
  cin >> h >> w;
  s = mat(h+2,vll(w+2,0));
  for(lli i = 1;i <= h;i++){
    string c;
    cin >> c;
    for(lli j = 1;j <= w;j++){
      s[i][j] = (c[j-1] == '#');
    }
  }
  // cout << h << " " << w << endl;
  for(lli i = 1;i <= h;i++){
    for(lli j = 1;j <= w;j++){
      // cout << s[i][j];
      if(s[i][j]){
        if(s[i+1][j] == 0 && s[i-1][j] == 0 && s[i][j+1] == 0 && s[i][j-1] == 0){
          cout << "No" << endl;
          return 0;
        }
      }
    }
    // cout << endl;
  }
  cout << "Yes" << endl;
  return 0;

}


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

  #define pb push_back
  #define mp make_pair
  #define ll long long int
  #define mod 1000000007
  #define w(t) int t;	cin>>t while(t--)
  #define vi vector<int>
  #define vll vector<ll>
  #define pi pair<int,int>
  #define pll pair<ll,ll>
  #define fastIO ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
  #define loop(i, k, n) for(ll i=k; i<n; i+=1)
  #define loop2(i, k, n) for(ll i=k; i>=n; i--)

  void take_fileIO(){
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    return;
  }

  void solve(){
    ll n,k; cin>>n>>k;
    vll heights(n);

    loop(i, 0, n)
      cin>>heights[i];

    vll dp(n+1, 0);

    loop(i, 1, n){
      dp[i] = LLONG_MAX;
      for(ll j=i-1; j>=0 && j>=(i-k); j--){
        ll only_option = dp[j] + abs(heights[j]-heights[i]);  //jump from some j to i

        dp[i] = min(dp[i], only_option);
      }
    }
    
    cout<<dp[n-1]<<endl;
    return;
  }

  int main(){

    fastIO;
    // take_fileIO();
    
    solve();

    return 0;
  }

Measured memory_bytes: 1920
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    S=input()
    n=len(S)
    dp=[0]*4
    dp[0]=1
    for s in S:
        ndp=dp[:] if(s!='?') else [3*d%MOD for d in dp]
        if(s=='A' or s=='?'):
            ndp[1]+=dp[0]
            ndp[1]%=MOD
        if(s=='B' or s=='?'):
            ndp[2]+=dp[1]
            ndp[2]%=MOD
        if(s=='C' or s=='?'):
            ndp[3]+=dp[2]
            ndp[3]%=MOD
        dp=ndp
    print(dp[3])
resolve()

Measured memory_bytes: 42220
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
H = list(map(int, input().split()))
ans, prev = 0, 0
for i in reversed(range(N - 1)):
    if H[i] >= H[i + 1]:
        ans = max(ans, prev + 1)
        prev += 1
    else:
        prev = 0
print(ans)


Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
bool mem[500][500];
bool lis[500];
int n,m,kazu;
int main(){
    while(1){
        kazu=0;
        fill(lis,lis+500,0);
        for(int i=0;i<500;i++){
            for(int j=0;j<500;j++){
                mem[i][j]=0;
            }
        }
        cin>>n;
        cin>>m;
        if(n+m==0)break;
        int a,b;
        for(int i=0;i<m;i++){
            cin>>a>>b;
            mem[a-1][b-1]=1;
            mem[b-1][a-1]=1;
        }
        for(int i=0;i<n;i++){
            if(mem[0][i]==1){
                lis[i]=1;
                for(int j=0;j<n;j++){
                    if(mem[i][j]==1){
                        lis[j]=1;
                    }
                }
            }
        }
        lis[0]=0;
        for(int i=0;i<n;i++){
            if(lis[i]==1){kazu++;}
        }
        cout<<kazu<<endl;
    }
}

Measured memory_bytes: 3352
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int a[50];
int b[50];
int c[50];

int memo[51][9][9][51];
int n;

int solve(int now, int l2, int l1, int m) {
  if (now == n)  return 0;
  if (memo[now][l2][l1][m] >= 0) return memo[now][l2][l1][m];
  int res = -INF;
  for (int i=0; i<=min(8,m); ++i) {
    int n2 = i;
    int n1 = l2;
    int t = solve(now+1,n2,n1,m-i);
    res = max(res, c[now] + t);
    int tt;
    int use = min(8, n2);
    if (n1||n2) {
      tt = use*a[now] + min(8-use, n1)*b[now];
      res = max(res, tt + t);
      use = min(8, n1);
      tt = use*b[now] + min(8-use, n2)*a[now];
      res = max(res, tt + t);
    }
    if (n1) {
      res = max(res, min(8,n1)*b[now] + t);
      res = max(res, b[now] + t);
    }
    if (n2) {
      res = max(res, min(8,n2)*a[now] + t);
      res = max(res, a[now] + t);
    }
  }
  //cout << now << " " << l2 << " " << l1 << " " << m << " " << res << endl;
  return memo[now][l2][l1][m] = res;
}

int main() {
  int m;
  while(cin>>n>>m) {
    memset(memo,-1,sizeof(memo));
    REP(i,n) {
      cin >> a[i] >> b[i] >> c[i];
    }
    cout << solve(0,0,0,m) << endl;
  }
}

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

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

  bool dislike[10]={0};
  int d;
  for(int i=0;i<K;i++){
    cin>>d;
    dislike[d]=1;
  }

  for(int i=N;i<100000;i++){
    int tmp=i;
    bool flag=true;
    while(tmp>0){
      if(dislike[tmp%10]){
        flag=false;
        break;
      }
      tmp=tmp/10;
    }
    if(flag){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256