akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc136/tasks/abc136_c
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N; cin>>N;    
    vector<ll> hn(N);
    for(auto&& h:hn){
        cin>>h;
    }
    //まま
    bool ans1=true;
    vector<ll> tmp=hn;
    for(ll i=N-1;i>=1;--i){
        if(tmp[i-1]>tmp[i]){
            --tmp[i-1];
            if(tmp[i-1]>tmp[i]){
                ans1=false;
                break; //無理
            }
        }
    }
    //おろす
    bool ans2=true;
    tmp=hn;
    --tmp[N-1];
    for(ll i=N-1;i>=1;--i){
        if(tmp[i-1]>tmp[i]){
            --tmp[i-1];
            if(tmp[i-1]>tmp[i]){
                ans2=false;
                break; //無理
            }
        }
    }
    cout<<((ans1||ans2)?"Yes":"No")<<endl;
    return 0;
}

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

const int MAXV = 300;
const int MAXE = MAXV * MAXV;
const int MAXF = (1<<29);
typedef int F;

struct MaxFlow {
    F cap[MAXE], flow[MAXE];
    int V, E, level[MAXV], edge[MAXV];
    int prev[MAXE], to[MAXE];
    MaxFlow(int n) : E(0), V(n) {
        memset(edge, -1, sizeof(edge));
    }
    void add_edge(int s, int t, F f, F g = 0) {
        flow[E] = 0; cap[E] = f; to[E] = t; prev[E] = edge[s]; edge[s] = E; E++;
        flow[E] = 0; cap[E] = g; to[E] = s; prev[E] = edge[t]; edge[t] = E; E++;
    }
    void make_level(int s) { // make level graph (bfs)
        memset(level, -1, sizeof(level));
        queue<int> q; q.push(s); level[s] = 0;
        while(!q.empty()) {
            int v = q.front(); q.pop();
            for (int e = edge[v]; e != -1; e = prev[e]) {
                if (cap[e] - flow[e] > 0 && level[to[e]] == -1)
                    q.push(to[e]), level[to[e]] = level[v]+1;
            }
        }
    }
    int augment(int s, int t, F f) { // find augment path (dfs)
        if (s == t || f == 0) return f;
        for (int e = edge[s]; e != -1; e = prev[e]) {
            if (level[to[e]] > level[s] && cap[e] - flow[e] > 0) {
                F g = augment(to[e], t, min(f, cap[e] - flow[e]));
                if (g > 0) {
                    flow[e] += g, flow[e^1] -= g;
                    return g;
                }
            }
        }
        return 0;
    }
    int max_flow(int s, int t) {
        int f, ret = 0;
        for (bool cont = true; cont; ) {
            cont = false;
            make_level(s);
            while ((f = augment(s, t, MAXF)) > 0) {
                cont = true;
                ret += f;
            }
        }
        return ret;
    }
};

int main() {
    ios::sync_with_stdio(false);
    int x[MAXE], y[MAXE];
    int N,M,a,b;
    cin>>N>>M;
    MaxFlow mf(N);
    for (int i=0; i<M; ++i) {
        cin>>a>>b; a--, b--;
        mf.add_edge(a, b, 1, 1);
        x[i] = a, y[i] = b;
    }
    cin>>a>>b; a--, b--;
    cout<<mf.max_flow(a, b)<<endl;
    vector<int> rev;
    for (int i=0; i<M; ++i) {
        int e = mf.edge[y[i]];
        while(e != -1) {
            if (mf.to[e] == x[i] && mf.flow[e] > 0) rev.push_back(i);
            e = mf.prev[e];
        }
    }
    cout<<rev.size()<<endl;
    for (int i=0; i<rev.size(); ++i) cout<<rev[i]+1<<endl;
}

Measured memory_bytes: 3284
//  RAKSHIT KADAM

 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 3
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!
 
// NUMERIC DEFINITIONS :
    #define INF 100000000000000005
    #define inf 1000000004
    #define MOD  1000000007
    #define mod 998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500003;
// ll fact[1000005];
//ll modIN[1000005];
//void facto()
//{
//    ll lim =1000005;fact[0]=1;
//    for(ll i=1;i<lim;i++)
//    {
//        fact[i]=(fact[i-1]*i)%MOD;
//    }
//    modIN[n]=modInverse(fact[n],MOD);
//    for(ll i=n-1;i>=1;i--)
//    {
//        modIN[i] = (modIN[i+1]*(i+1))%MOD;
//    }
//}
//ll ncr(ll a,ll b)
//{
//    ll ret = 0;
//    ret = fact[a]*(modIN[b]);
//    ret%=MOD;
//    ret*=modIN[a-b];
//    ret%=MOD;
//    return ret;
//}

void solve()
{
    string s;cin>>s;
    s+='3';
    ll x=0;
    ll ans=0;
    for(auto it:s)
    {
        if(it=='R')
        {
            x++;
        }
        else
        {
            ans=max(ans,x);x=0;
        }
    }
    cout<<ans<<endl;
}
signed main()
{
   Need_for_speed(activated);
  
//    satisfy
//    {
//        solve();
//    }
   
    solve();
    
    return 0;
}
//Concentrate while implementing,,,!!!
 


Measured memory_bytes: 3648
N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#bottomup
memo = [10**10]*(10**5+1)
memo[0] = 0

for weight, value in items:
    for i in reversed(range(len(memo)-value)):
            memo[i+value] = min(memo[i+value],memo[i] + weight)

ans = 0
for i in range(len(memo)):
    if memo[i] != 10**10 and memo[i] <= W:
        ans = i

print(ans)


Measured memory_bytes: 74336
#include <bits/stdc++.h>
#define rep( i, n ) for (long long i = 0; i < ( long long )(n); i++)

using namespace std;
typedef long long ll;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;


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

    int m=n%10;

    if(m==2||m==4||m==5||m==7||m==9) cout<<"hon";
    else if(m==0||m==1||m==6||m==8) cout<<"pon";
    else cout<<"bon";
}



Measured memory_bytes: 3624
#include <iostream>
#include <array>
#include <vector>

using namespace std;
typedef long long ll;

array<array<array<ll, 2501>, 51>, 51> dp;

int main()
{
  int n, a;
  cin >> n >> a;
  vector<int> xs(n);
  for(int i = 0; i  < n; i++) {
    cin >> xs[i];
  }
  dp[0][0][0] = 1;
  for(int i = 1; i <= n; i++) {
    for(int k = 1; k <= i; k++) {
      for(int j = xs[i - 1]; j <= i * 50; j++) {
        dp[i][k][j] += dp[i - 1][k - 1][j-xs[i - 1]];
      }
      for(int j = 0; j <= i * 50; j++) {
        dp[i][k - 1][j] += dp[i - 1][k - 1][j];
      }
    }
  }
  ll count = 0;
  for(int k = 1; k <= n; k++) {
    count += dp[n][k][k * a];
  }
  cout << count << endl;
}

Measured memory_bytes: 49024
import Data.List.Split

main = do line <- getLine
          putStrLn . sleWrap $ line

sleWrap :: String -> String
sleWrap l = let ss = splitOn " " l
                x = read $ ss!!0
                y = read $ ss!!1
            in sle x y

sle :: Int -> Int -> String
sle x y
  | x < y = "a < b"
  | x > y = "a > b"
  | x == y = "a == b"

Measured memory_bytes: 3624
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }


const int maxn = 510;

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


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B, C = MAP()
l = [INT() for i in range(N)]

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))


Measured memory_bytes: 5196
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }

vector<vector<pair<ll, ll> > > V(100005);
vector<bool> A(100005, false);


void sol(ll num, ll parent, ll first) {
	if (A[num]) return;
	A[num] = true;

	rep(i, V[num].size()) {
		sol(V[num][i].first, num, first);
	}
}


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

	ll N, M;

	cin >> N >> M;

	ll X, Y, Z;

	rep(i, M) {
		cin >> X >> Y >> Z;
		V[X].pb(mp(Y, Z));
		V[Y].pb(mp(X, Z));
	}

	ll count = 0;

	rep(i, N) {
		if (A[i+1]) continue;
		count++;

		rep(k, V[i+1].size()) {
			sol(V[i+1][k].first, i+1, i+1);
		}
	}


	cout << count << endl;


	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)

int N, a[100];

int main() {
	cin >> N;
	REP(i, 0, N) cin >> a[i];
	sort(a, a+N, greater<int>());
	int res = 0;
	REP(i, 0, N) res += a[i] * (i & 1 ? -1:1);
	cout << res << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  char S[N][N];
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> S[i][j];
    }
  }
  //Color Test
  bool ColorTest = false;
  int Color[N];
  for (int i = 0; i < N; i++){
    Color[i] = -1;
  }
  Color[0] = 0;
  queue<int> V;
  V.push(0);
  while (!V.empty()){
    int i = V.front();
    for (int j = 0; j < N; j++){
      if (S[i][j]=='1'){
        if (Color[j] == -1){
          Color[j] = 1 - Color[i];
          V.push(j);
        } else if (Color[i] == Color[j]){
          ColorTest = true;
          break;
        }
      }
    }
    V.pop();
    if (ColorTest) break;
  }
  if (ColorTest){
    cout << -1;
  } else {
    int MaxLen = 1;
    for (int i = 0; i < N; i++){
      queue<int> W;
      int group[N];
      for (int j = 0; j < N; j++){
        group[j] = 0;
      }
      W.push(i);
      group[i] = 1;
      while (!W.empty()){
        int j = W.front();
        for (int k = 0; k < N; k++){
          if (S[j][k]=='1' && group[k]==0){
            group[k] = group[j] + 1;
            MaxLen = max(MaxLen,group[k]);
            W.push(k);
          }
        }
        W.pop();
      }
    }
    cout << MaxLen;
  }
}

Measured memory_bytes: 256
// Last Change: 05/19/2019 21:12:35.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

bool CheckYY(int ipt) {
  return 1;
}

bool CheckMM(int ipt) {
  if (0 < ipt and 13 > ipt) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int S, left, right;
  cin >> S;
  left = S / 100;
  right = S % 100;

  bool YYMM, MMYY;
  YYMM = MMYY = false;

  if (CheckYY(left) and CheckMM(right)) {
    YYMM = true;
  }
  if (CheckYY(right) and CheckMM(left)) {
    MMYY = true;
  }

  if (YYMM) {
    if (MMYY) {
      cout << "AMBIGUOUS" << endl;
    } else {
      cout << "YYMM" << endl;
    }
  } else {
    if (MMYY) {
      cout << "MMYY" << endl;
    } else {
      cout << "NA" << endl;
    }
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
def main():
    N = int(input())
    red = sorted([tuple(map(int, input().split())) for _ in range(N)], key = lambda x:(-x[1], x[0]))
    blue = sorted([tuple(map(int, input().split())) for _ in range(N)])

    available = [True] * N

    ans = 0
    for bx, by in blue:
        for i, (rx, ry) in enumerate(red):
            if bx > rx and by > ry and available[i]:
                ans += 1
                available[i] = False
                break
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
int n;
  scanf("%d",&n);
  int v[n],c[n];
  for(int i=0;i<n;i++){
	scanf("%d",&v[i]);
  }
   for(int i=0;i<n;i++){
	scanf("%d",&c[i]);
  }
  int max=0;
  int vsum=0,csum;
  for(int i=0;i<(1<<n);i++){
	for(int j=0;j<n;j++){
	if(i&(1<<j)){vsum+=v[j];
                 csum+=c[j];
                }
    }
    if(vsum-csum>max)max=vsum-csum;
    vsum=0;
    csum=0;
  }
  printf("%d",max);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define lint long long
#define MOD 1000000007


using namespace std;

int n,k;

lint fat[100010];


lint poww(lint b, lint e){
	lint aux = 1;
	for( ;e ;e/=2){
		if(e%2)
			aux *= b;
		aux %= MOD;
		b *= b;
		b %= MOD;
	}

	return aux;
}

lint ncr(lint n, lint r){
    if(r < 0 || n < 0) return 0;
    if(n < r) return 0;
    lint a = fat[n];
    a = (a * poww(fat[r],MOD-2)) % MOD;
    a = (a * poww(fat[n-r],MOD-2)) % MOD;
    return a;
}

int main(){


	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	fat[0] = 1;
	for(int i =1;i<=100008;i++){
		fat[i]=(i*fat[i-1])%MOD;
	}
	
	cin>>n>>k;
	
	lint ans = 0;

	vector<lint> v(n);
	for(int i=0;i<n;i++) cin>>v[i];
	sort(v.begin(), v.end());
	
	for(int i=0;i<n;i++){

		ans += ncr(i,k-1)*v[i];
		ans %= MOD;
		ans -= ncr(n-1-i,k-1)*v[i];
		ans %= MOD;
	}
	
	if(ans<0) ans += MOD;
	cout<<ans<<"\n";


		

	return 0;	
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#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 x, a, b; cin >> x >> a >> b;
  cout << (abs(x-a)<abs(x-b)? 'A' : 'B') << '\n';
  return 0;
}


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

int main()
{
    double r;
    cin >> r;
    cout  << fixed << setprecision(5) << M_PI * r * r << " " << M_PI * r * 2.0 << endl;
    return 0;
}



Measured memory_bytes: 3284
# -*- coding: utf-8 -*-


def main():
    s = input()
    ans = float('inf')

    for i in range(len(s) - 3 + 1):
        candidate = int(s[i:i + 3])
        ans = min(ans, abs(753 - candidate))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#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(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    char op;
    cin>>a>>op>>b;
    if(op=='+')cout<<a+b<<endl;
    else cout<<a-b<<endl;

    return 0;
}


Measured memory_bytes: 3648
from itertools import accumulate
N, K = map(int, input().split())
S = "1" + input() + "1"
arr = []
cnt = 0
flg = 1
for s in S:
    if s == "1" and 1 - flg:
        flg = 1
        arr.append(cnt)
        cnt = 1
    elif s == "0" and flg:
        flg = 0
        arr.append(cnt)
        cnt = 1
    else:
        cnt += 1
arr.append(cnt)
csum = [0] + list(accumulate(arr))
ans = 0
tmp = 0
for i in range(0, len(csum), 2):
    l = i
    r = min(i + 2*K + 1, len(csum) - 1)
    tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)
    ans = max(ans, tmp)
if len(csum) == 2:
    print(csum[1] - 2)
else:
    print(ans)


Measured memory_bytes: 8856
#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(){
    ll a,b,v,w,t;
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;
    ll aa,bb;
    if(a<=b){
    aa=a+v*t;
    bb=b+w*t;
    if(aa>=bb){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    }
    else{
    aa=a-v*t;
    bb=b-w*t;
    if(aa<=bb){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    }
    

    return 0;
}

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

int x,y;
int ti[51][51];
const int dx[]={1,0,-1,0,-1,1,-1,1}, dy[]={0,-1,0,1,-1,1,1,-1};

bool valid(int i,int j)
{
	return(i>=0&&i<y&&j>=0&&j<x);
}

int bfs(int m,int n)
{
	if(ti[m][n]==0)
      return 0;
    queue< pair<int,int> > Q;
	pair<int,int> a,b;
	a.first=m;
	a.second=n;
	Q.push(a);
	while(!Q.empty())
	{
		a=Q.front();
		Q.pop();
		for(int i=0;i<8;i++)
		{
			b.first=a.first+dx[i];
			b.second=a.second+dy[i];
			if(valid(b.first, b.second) && ti[b.first][b.second])
			{
				ti[b.first][b.second]=0;
				Q.push(b);
			}
		}
	}
	return 1;
}

int main()
{
	while(cin >> x >> y)
	{
		if(!x&&!y)
		  break;
		for(int i=0;i<y;i++)
		   for(int j=0;j<x;j++)
		   {
		   	    cin >> ti[i][j];
		   }
        int sum=0;
        for(int i=0;i<y;i++)
		   for(int j=0;j<x;j++)
              if(bfs(i,j))
              {
                  sum++;
              }
        cout << sum << endl;
	}
}


Measured memory_bytes: 3124
n = int(input())
pretree = list(map(int, input().split()))
inotree = list(map(int, input().split()))
def get_postorder(pre, ino):
    if not pre:
        return []
    root = pre[0]
    root_index = ino.index(root)
    result = []
    result.extend(get_postorder(pre[1:root_index + 1], ino[:root_index]))
    result.extend(get_postorder(pre[root_index + 1:], ino[root_index + 1:]))
    result.append(root)
    return result
print(*get_postorder(pretree, inotree))



Measured memory_bytes: 5600
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int main(void)
{
  char s[5];
  int n;
  bool my=0,ym=0;
  scanf("%s",s);
  n=atoi(s);
  if((n/100<13)&&(n/100>0)){
    my=1;
  }
  if((n%100<13)&&(n%100>0)){
    ym=1;
  }
  switch(my&&ym){
    case true: puts("AMBIGUOUS");return 0;
    case false:
    if(my==true){
      puts("MMYY");return 0;
    }else if(ym==true){
      puts("YYMM");return 0;
    }else{
      puts("NA");return 0;  
    }
  }
}


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

 int main() {
   int A,B;
   cin >> A >> B;
   
   if(A % 2 == 0 || B % 2 == 0){
     cout << "No" <<endl;
   }else{
     cout << "Yes" <<endl;
   }
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX = 100;

int main() {
	int H, W;
	char grid[MAX][MAX];

	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> grid[i][j];
		}
	}

	int x = 0;

	for (int i = 0; i < H; i++,x++) {
		bool check = true;
		for (int j = 0; j < W; j++) {
			if (grid[i][j] == '#')check = false;
		}

		for (int j = 0; j < W; j++) {
			grid[x][j] = grid[i][j];
		}

		if (check)x--;
	}

	H = x;
	x = 0;

	for (int i = 0; i < W; i++,x++) {
		bool check = true;
		for (int j = 0; j < H; j++) {
			if (grid[j][i] == '#')check = false;
		}

		for (int j = 0; j < H; j++) {
			grid[j][x] = grid[j][i];
		}
		if (check)x--;
	}

	W = x;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << grid[i][j];
		}
		cout << endl;
	}

	return 0;
}

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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;

    if (a >= b) {
        rep(i, a) cout << b;
        cout << endl;
    }else{
        rep(i, b) cout << a;
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;
 
int n, a, b, c, d;
int mod = 1e9 + 7;
int dp[1010][1010];

typedef long long ll;
ll mod_pow(ll x,ll n){
	if(n==0) return 1;
	ll res=mod_pow(x*x%mod,n/2);
	if(n&1) res=res*x%mod;
	return res;
}
ll fact[200010];
ll factr[200010];
ll inv[200010];
ll get_nCk(ll n,ll k){
    if(k < 0 || k > n || n < 0) return 0;
    return fact[n]*factr[k]%mod*factr[n - k]%mod;
}
 
int f(int p, int s){
    if(dp[p][s] >= 0) return dp[p][s];  
    if(s == 0) return dp[p][s] = 1;        
    // if(p > b || s < 0 || p > s) return 0;
    if(p > b) return 0;
      
    int res = 0;
    int t = 1;
    rep(i, 1, d + 1){
        if(s - p * i < 0) break;
        t = t * get_nCk(s - p * (i - 1), p) % mod * inv[i] % mod;
        if(c <= i && i <= d){
            res += f(p + 1, s - p * i) * t % mod;
        }
    }
    // rep(i, c, d + 1){
    //     if(s - p * i < 0) break;
    // }
    // cout << p << " " << s <<" " <<  res << endl;
    
    res += f(p + 1, s);
    
    return dp[p][s] = res % mod;
}
 
signed main(){
    cin >> n >> a >> b >> c >> d;
    rep(i, 0, 1010){
        rep(j, 0, 1010){
            dp[i][j] = -1;
        }
    }
    fact[0] = 1;
    factr[0] = 1;
    inv[1] = 1;
	for(int i=1;i<1010;i++) fact[i]=fact[i-1]*i%mod;
    for(int i = 1; i < 1010; i++) factr[i] = mod_pow(fact[i], mod - 2);
    for(int i = 2; i < 1010; i++) inv[i] = mod_pow(i, mod - 2);
    cout << f(a, n) << endl;
    // rep(i, a, b + 1){
    //     rep(j, 0, n + 1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
}

Measured memory_bytes: 8320
a,b,c=map(int,input().split())

total1=abs(a-b)+abs(b-c)
total2=abs(a-c)+abs(b-c)
total3=abs(a-b)+abs(a-c)

temp=0

if total1>total2:
	temp=total1
	total1=total2
	total2=temp

if total1>total3:
	temp=total1
	total1=total3
	total3=temp

print(total1)

Measured memory_bytes: 3064
sx, sy, tx, ty = map(int, input().split())
print('U' * (ty - sy) + 'R' * (tx - sx), end='')
print('D' * (ty - sy) + 'L' * (tx - sx), end='')
print('D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L', end='')
print('U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b+c || a+b==c || a+c==b)
    cout<<"Yes"<<'\n';
  else
    cout<<"No"<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n, count = 0, k = 1;
	cin >> n;
	vector<int>h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (int i = 1; i < n; i++) {
		count = 0;
		for (int j = 0; j < i; j++) {
			if (h[i] >= h[j]) {
				//cout << h[j] << endl;
				count++;
			}
			if (count == i) {
				k++;
				count = 0;
			}
		}
	}
	cout << k << endl;

}

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

class E
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = h[0], k = h[1], c = h[2];
		var s = Console.ReadLine();

		var d1 = new int[k];
		for (int j = 0, i = 0; j < k; j++)
		{
			for (; i < n && s[i] == 'x'; i++) ;
			d1[j] = i;
			i += c + 1;
		}

		var d2 = new int[k];
		for (int j = k - 1, i = n - 1; j >= 0; j--)
		{
			for (; i >= 0 && s[i] == 'x'; i--) ;
			d2[j] = i;
			i -= c + 1;
		}

		Console.WriteLine(string.Join("\n", Enumerable.Range(0, k).Where(i => d1[i] == d2[i]).Select(i => d1[i] + 1)));
	}
}


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

int main(){
    int n;
    int k;
    cin >> n >> k;
    double sum=0.0;
    for(int i=1;i<=n;i++){
        int score=i;
        if (i<k){
            int score=i;
            int times=0;
            while(score<k){
                times++;
                score*=2;
            }
            sum+=1.0/n*pow(0.5,times);
        }else{
            sum+=1.0/n;
        }
        
    }
    cout << fixed << setprecision(12);

    cout<<sum<<endl;
    return 0;
}

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

namespace ConsoleApplication51
{
    class Program
    {
        static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] c = { b[0], b[1]};
            while (true)
            {
                Array.Sort(c);
                if (c[1] % c[0] == 0) break;
                int d = c[0];
                c[1] = c[1]-c[0];
                c[0] = d;
            }
            int e = c[0];
            if (a == 3)
            {
                c[0] = e;
                c[1] = b[2];
                while (true)
                {
                    Array.Sort(c);
                    if (c[1] % c[0] == 0) break;
                    int d = c[1];
                    c[1] = c[1] - c[0];
                    c[0] = d;
                }
                e = c[0];
            }
            for(int g=1; g<=e; g++)
            {
                if (e % g == 0) { Console.WriteLine(g); }
            }
        }
    }
}

Measured memory_bytes: 9708
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	ll a, b, x; cin >> a >> b >> x;
	ll A = (a / x) + 1;
	ll B = (b / x) + 1;

	cout << ((a % x == 0) ? B - A + 1 : B - A) << endl;

	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> vec(N);
  for(int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int len = 0;
  for(int i = 0; i < K; i++) {
    len += vec.at(i);
  }
  cout << len << endl;
    
}
    

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


const int MOD=1000000007;
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  int dp[1010][1010]={0};
  for(int i=0;i<h;++i){
    cin >> s[i];
  }
  dp[0][0]=1;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(i+1<h && s[i+1][j]=='.'){
        dp[i+1][j]+=dp[i][j];
        dp[i+1][j]=dp[i+1][j]%MOD;
      }
      if(j+1<w && s[i][j+1]=='.'){
        dp[i][j+1]+=dp[i][j];
        dp[i][j+1]=dp[i][j+1]%MOD;
      }
    }
  }
  cout << dp[h-1][w-1] << endl;
  return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n, c;
	cin >> n >> c;
	VVL cost(c, VL(c));
	rep(i, c) rep(j, c) {
		cin >> cost[i][j];
	}
	VVL cnt(3, VL(c, 0));
	rep(i, n) rep(j, n) {
		int a;
		cin >> a;
		a--;
		cnt[(i + j + 2) % 3][a]++;
	}
	ll ans = UPPER;
	rep(i, c) {
		rep(j, c) {
			if (i == j) continue;
			rep(k, c) {
				if (i == k || j == k) continue;
				ll tmp = 0;
				rep(gru, 3) {
					rep(color, c) {
						ll mul;
						if (gru == 0) mul = cost[color][i];
						if (gru == 1) mul = cost[color][j];
						if (gru == 2) mul = cost[color][k];
						tmp += (cnt[gru][color] * mul);
					}
				}
				chmin(ans, tmp);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define     bolt     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     text     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define     F        first
#define     S        second
#define     pb       push_back
#define     lb       lower_bound
#define     ub       upper_bound
#define     endl     "\n"
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7 ;
const ld pi=3.1415926535897932384626433;
const ll inf = 1e18;
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}

int main ()
{
   bolt;
   ll n;
   cin>>n;
   set< ll> s;
   vector <ll> a(n),pre(n,inf);
   for (ll i=0;i<n;i++)
   {
      cin>>a[i];
      if (!i)
      {
         pre[i]=a[i];
      }
      else
      {
         pre[i]=min(pre[i-1],a[i]);
      }
      s.insert(pre[i]);
   }
   cout<<s.size();
}

Measured memory_bytes: 12800
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val k = sc.nextInt()
    val s = sc.nextInt()
    var ans = 0
    for (x in 0..k) {
        for (y in 0..k) {
            val z = s - (x + y)
            if (z in 0..k) {
                ans++
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 31408
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;


int N;
ll A[5010];
vector<vint> G;
ll dp[5010][2][5010];
ll tmp[2][5010];
ll size[5010];

void dfs(int v,int par){
  size[v]=1;
  dp[v][0][0] = A[v]>0;
  dp[v][1][0] = A[v];
  for(int chi:G[v])if(chi!=par){
    dfs(chi,v);
    fill(tmp[0],tmp[0]+N,0);
    fill(tmp[1],tmp[1]+N,INF);
    for(int k=size[v]-1;k>=0;k--){
      for(int l=size[chi]-1;l>=0;l--){
        if(dp[v][0][k]&&dp[chi][1][l]<0){
          tmp[0][k+l+1]=1;
        }
        if(dp[v][0][k]&&dp[chi][0][l]){
          tmp[0][k+l]=1;
        }
        if(dp[v][1][k]<INF&&dp[chi][0][l]){
          tmp[1][k+l+1]=min(tmp[1][k+l+1],dp[v][1][k]);
        }
        if(dp[v][1][k]<INF&&dp[chi][1][l]<INF){
          tmp[1][k+l]=min(tmp[1][k+l],dp[v][1][k]+dp[chi][1][l]);
        }
      }
    }
    swap(dp[v],tmp);
    size[v]+=size[chi];
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  repeat(i,N){
    cin>>A[i];
  }
  G.resize(N);
  repeat(i,N-1){
    int u,v;cin>>u>>v;
    u--;v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0,-1);
  ll ans;
  for(ans=0;ans<N-1;ans++){
    if(dp[0][0][ans]||dp[0][1][ans]<0){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 392704
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>A>>B;
    cout<<(A+B)%24<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    int a, b;
    cin >> a >> b;

    int n = b - a;

    int h = 0;
    for (int i = 1; i <= n; i++) {
        h += i;
    }

    cout << h - b << endl;

    return 0;
}


Measured memory_bytes: 256
#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 yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
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...);}

vector<long long int> fibo(200001,-1);
long long int fibonatti(long long int n){
    if(fibo[n]!=-1){
        return fibo[n];
    }else if(n==0){
        fibo[0]=1;
        return 1;
    }else if(n==1){
        fibo[1]=1;
        return 1;
    }else if(n>=2){
        fibo[n]=(fibonatti(n-1)+fibonatti(n-2))%MOD;
        return fibo[n];
    }
}
 
int main(){
    ll n,m;
    in(n,m);
    vector<int> vec(m);
    in(vec);
    fibonatti(200000);
    vec.push_back(n+1);
    ll target=0,ans=1,d=0;
    rep(i,m+1){
        if(i==0)target=vec[i]-1;
        else target=vec[i]-vec[i-1]-2;
        if(target==-1){
            ans=0;
            break;
        }
        d=0;
        if(target==0)d=1;
        else if(target==1)d=1;
        else if(target==2)d=2;
        else if(target>=3){
            d=fibo[target];
        }
        ans*=d;
        if(ans>MOD)ans%=(ll)MOD;
    }
    out(ans);
}


Measured memory_bytes: 11700
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	nums := make([]int, n)
	var tmp int
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		nums[i] = tmp
	}
	cnt := 0
L:
	for {
		for i := 0; i < n; i++ {
			if nums[i]%2 == 0 {
				nums[i] /= 2
			} else {
				break L
			}
		}
		cnt++
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
# 優先度付きキューの考え方が必須
import heapq

N, M = map(int, input().split())
# 読み込み時に * -1 を乗算している
A_list = list(map(lambda x: int(x)*(-1), input().split()))
# A_listを優先度付きキューにする
heapq.heapify(A_list)

while M > 0:
    temp_max = heapq.heappop(A_list)
    # //2 で余りは切り捨てのため -1 を 2回 乗算している
    heapq.heappush(A_list, (-1)*((-1*temp_max)//2))
    M -= 1
print(-1*sum(A_list))


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

int MinimumNumIncreasingSubsequences(int arr[], int n) 
{ 
	multiset<int> last; 

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

		multiset<int>::iterator it = last.lower_bound(arr[i]); 

		if (it == last.begin()) 

			last.insert(arr[i]); 

		else { 
			it--; 

			// the largest element smaller than arr[i] is the number 
			// before *it which is it-- 
			last.erase(it); // erase the largest element smaller than arr[i] 
			last.insert(arr[i]); // and replace it with arr[i] 
		} 
	} 
	return last.size(); // our answer is the size of last 
} 

// Driver program 
int main() 
{  int n;
 cin>>n;
 int arr[n];
 for(int i=0;i<n;i++)
   cin>>arr[i];
 cout<< MinimumNumIncreasingSubsequences(arr, n); 
	return 0; 
} 


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;


int main()
{
	long long L, R;
	cin >> L >> R;

	int N = R - L + 1;

	//vector<int> mod_list(N,0);


	int min_mod = 1e9;
	int max_mod = 0;
	int buf;
	for(int ni = 0; ni < N; ni++){
		//mod_list[ni] = (L + ni) % 2019;
		buf = (L + ni) % 2019;
		if (buf < min_mod){
			min_mod = buf;
			if (min_mod == 0) break;
		}
		if (buf > max_mod) {
			max_mod = buf;
		}
	}

	int ans = 1e9;;
	if (min_mod == 0){
		ans = 0;
	}else{
		for (int i = min_mod; i <= max_mod-1; i++) {
			for (int j = i + 1; j <= max_mod; j++) {
				if ((i*j) % 2019 < ans) {
					ans = (i*j) % 2019;
				}
			}
		}		
	}


	printf("%d", ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    string S; cin >> S;
    int N = S.size();
    int K; cin >> K;

    if(N == 1){
        cout << 1;
        return 0;
    }

    vector<mat> dp(N + 1, mat(N + 1, vec(K + 1, 0)));

    REP(i, N){
        REP(j, N){
            if(S[i] == S[N - 1 - j]){
                REP(k, K + 1) dp[i + 1][j + 1][k] = dp[i][j][k] + 1;
            }else{
                REP(k, K) dp[i + 1][j + 1][k + 1] = dp[i][j][k] + 1;
                REP(k, K + 1) dp[i + 1][j + 1][k] = max(dp[i + 1][j + 1][k], max(dp[i + 1][j][k], dp[i][j + 1][k]));
            }
        }
    }

    /*
    REP(i, N + 1){
        REP(j, N + 1){
            cout << i << ", " << j << endl;
            REP(k, K + 1){
                cout << dp[i][j][k] << ",";
            }
            cout << endl;
        }
    }*/

    
    int ans = 0;
    FOR(i, 1, N){
        REP(k, K + 1){
            ans = max(dp[i][N - i][k] * 2, ans);
            ans = max(dp[i][N - i - 1][k] * 2 + 1, ans);
        }
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 216832
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define T3I tuple<int, int, int>
#define STA(a, b) min(a, b), max(a, b)
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

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

    int n;
    cin >> n;
    vector<int> ans(n, -1);
    vector<int> A(n, 0);
    for(int i = 0; i < n; ++i) {
        ++ans[i];
        if(ans[i] > A[i]) {
            ans[i] = -1;
            --i;
            --i;
            if(i < 0) break;
            continue;
        }
        if(i == n-1) {
            for(int j = 0; j < n; ++j) {
                cout << char('a'+ans[j]);
            }
            cout << endl;
            --i;
            continue;
        }
        A[i+1] = max(A[i], ans[i]+1);
    }
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n; i++) cin >> a.at(i);

     int odd = 0 , even = 0;
     for (int i = 0;i < n; i++) {
         if (a.at(i) % 2 == 0) even++;
         else odd++;
     }

     //cout << "odd" << odd << "even" << even << endl;

     bool can = false;

     if (n % 2 != 0) {
         if (odd % 2 == 0 && even % 2 != 0) can = true;
     }
     else {
         if (odd % 2 != 0 && even % 2 != 0);
         else can = true;
     }
     if(can) cout << "YES" << endl;
     else cout << "NO" << endl;
     return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    private int max(int a, int b)
{
        return (a > b)? a : b;
    }

    private int lcs(char[] X, char[] Y, int m, int n){
/*        if (m == n)
            return 0;
        if(X[m-1] == Y[n-1])
            return 1 + lcs(X, Y, m-1, n-1);
        else
            return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));*/


        int L[][] = new int[m + 1][n + 1];
        for(int i = 0; i <= m; i++){
            for(int j = 0; j <= n; j++){
                if(i == 0 || j == 0)
                    L[i][j] = 0;
                else if(X[i - 1] == Y[j - 1]){
                    L[i][j] = L[i - 1][j - 1] + 1;
                } 
                else 
                {
                    L[i][j] = max(L[i - 1][j], L[i][j-1]);
                }
            }
        }
        return L[m][n];
    }

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

        int runLength = scanner.nextInt();

        for(int i = 0; i < runLength; i++)
{
            String inputOne = scanner.next();
            String inputTwo = scanner.next();

            char[] X = inputOne.toCharArray();
            char[] Y = inputTwo.toCharArray();
            int m = inputOne.length();
            int n = inputTwo.length();

            System.out.println(lcs.lcs(X, Y, m, n));
        }

    }
}


Measured memory_bytes: 64464
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <string>
#include <stack>
#include <set>
#define INT long long int
#define MOD 1000000007
#define oo 987654321
using namespace std;
INT n, m;
INT f(INT x)
{
    INT ret = 1, y = x;
    while( 1 ){
        ret*=x;
        ret%=MOD;
        x--;
        if( x == 0 ) break;
    }
    return ret;
}
int main()
{
    cin>>n>>m;
    if( n > m ) swap(n, m);
    if( n == m ) cout<<((f(n)*f(n))%MOD*2)%MOD<<endl;
    else if( m == n+1 ) cout<<(f(n)*f(m))%MOD<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
B - Qualification simulator
https://atcoder.jp/contests/code-festival-2016-qualb/tasks/codefestival_2016_qualB_b

"""
import sys


def solve(N, A, B, S):
    ans = []
    total_qualified = 0
    b_qualified = 0
    for ch in S:
        if ch == 'a':
            if total_qualified < A+B:
                ans.append('Yes')
                total_qualified += 1
            else:
                ans.append('No')
        elif ch == 'b':
            if total_qualified < A+B and b_qualified < B:
                ans.append('Yes')
                total_qualified += 1
                b_qualified += 1
            else:
                ans.append('No')
        else:
            ans.append('No')
    return ans


def main(args):
    N, A, B = map(int, input().split())
    S = input()
    ans = solve(N, A, B, S)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 6352