akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main(){
	string a;
	cin >> a ;
	if (a[0] == a[1]){
		cout << "Bad" << endl;
	}
	else if (a[1] == a[2]){
		cout << "Bad" << endl;
	}
	else if (a[2] == a[3]){
		cout << "Bad" << endl;
	}
	else{
		cout << "Good" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    ll a[N], b[N];
    ll A = 0, B = 0;
    rep(i, N) cin >> a[i], A += a[i];
    rep(i, N) cin >> b[i], B += b[i];
    ll n = B-A, cnt = 0;
    rep(i, N){
        if(a[i] > b[i]) cnt += (a[i]-b[i]);
        elif(a[i]%2 != b[i]%2) cnt++;
    }
    if(cnt <= n) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<map>
#include<cstdio>
#include<algorithm>
#define INF 10000000
using namespace std;
bool used[101];
int cost[101][101];
int mincost[101];
int n,m;
int prim(){
  for(int i=0;i<n;i++){
    mincost[i]=INF;
    used[i]=false;
  }
  mincost[0]=0;
  int res=0;
  while(true){
    int v=-1;
    for(int u=0;u<n;u++){
      if(!used[u] && (v==-1 || mincost[u]<mincost[v])) v=u;
    }
    if(v==-1) break;
    used[v]=true;
    res+=mincost[v];
    for(int u=0;u<n;u++){
      mincost[u]=min(mincost[u],cost[v][u]);
    }
  }
  return res;
}
main(){
  int a,b,k;
  while(1){  
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cost[i][j]=INF;
      }
    }
    cin>>m;
    for(int i=0;i<m;i++){
      scanf("%d,%d,%d",&a,&b,&k);
      cost[a][b]=k/100-1;
      cost[b][a]=k/100-1;
    }
    cout<<prim()<<endl;
  }
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
int n, k, x=1;
int main (){
	cin >> n>> k;
	for(int i=1;i<=n;i++){
		if(x+k<=2*x) x=x+k;
		else if(x+k>2*x) x=x*2;
	}
	cout << x;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

template <typename T>
class segmenttree
{
private:
    int n;

public:
    using F = function<T(T, T)>;

    T dif;
    F f;
    vector<T> st;

    segmenttree(int size, T init, F f) : f(f)
    {
        n = 1;

        while (n < size)
        {
            n *= 2;
        }

        st.assign(2 * n - 1, init);
    }

    void set(int i, T x)
    {
        st[i + n - 1] = x;
    }

    void build()
    {
        for (int i = n - 2; i >= 0; i--)
        {
            st[i] = f(st[i * 2 + 1], st[i * 2 + 2]);
        }
    }

    void update(int i, T x)
    {
        i += n - 1;
        st[i] = x;

        while (i > 0)
        {
            i = (i - 1) / 2;
            st[i] = f(st[2 * i + 1], st[2 * i + 2]);
        }
    }

    T query(int a, int b)
    {
        return query_(a, b, 0, 0, n);
    }

    T query_(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
        {
            return dif;
        }

        if (a <= l && r <= b)
        {
            return st[k];
        }
        else
        {
            T x = query_(a, b, 2 * k + 1, l, (l + r) / 2);
            T y = query_(a, b, 2 * k + 2, (l + r) / 2, r);

            return f(x, y);
        }
    }
};

int main(void)
{
    int n, q;
    string s;
    int i, j;
    vector<int> ans;

    cin >> n >> s >> q;

    segmenttree<bitset<26>> seg(n, 0, [](bitset<26> a, bitset<26> b) { return a | b; });
    seg.dif = 0;

    rep(i, 0, n)
    {
        bitset<26> bit = 1 << (s[i] - 'a');
        seg.set(i, bit);
    }

    seg.build();

    rep(i, 0, q)
    {
        int x;

        cin >> x;

        if (x == 1)
        {
            int iq;
            char c;
            bitset<26> bit;

            cin >> iq >> c;
            iq--;

            s[iq] = c;
            bit = 1 << (s[iq] - 'a');

            seg.update(iq, bit);
        }
        else
        {
            int l, r;
            int an = 0;

            cin >> l >> r;
            l--;

            bitset<26> bit = seg.query(l, r);

            an = bit.count();

            ans.push_back(an);
        }
    }

    for (auto &z : ans)
    {
        cout << z << endl;
    }
}

Measured memory_bytes: 9220
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  string S;
  while (cin >> N >> S) {
    int needLeft = 0, left = 0;
    for (char c : S) {
      if (c == '(') {
        ++left;
      } else {
        if (left == 0) {
          ++needLeft;
        } else {
          --left;
        }
      }
    }
    int needRight = left;
    string res = string(needLeft, '(') + S + string(needRight, ')');
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//42
#include<iostream>
#include<utility>
#include<cctype>
#include<cstdio>
#include<climits>
#include<cstdlib>

using namespace std;

char s[101];
bool f;
int i;
typedef pair<int,int> pii;

void co(pii a){
  f|=a.first<-10000||10000<a.first||a.second<-10000||10000<a.second;
}

pii pp();
pii pm();
pii pn();

pii pn(){
  if(s[i]=='i'){
    i++;
    return make_pair(0,1);
  }else if(isdigit(s[i])){
    int d,n;
    long dd;
    char *p;
    dd=strtol(s+i,&p,10);
    f|=dd<-10000||10000<dd;
    i+=p-(s+i);
    d=dd;
    /*    if(1){
      d=0;
      while(isdigit(s[i])){
	d=(d*10+s[i]-'0');
	i++;
      }
    }else{
      sscanf(s+i,"%d%n",&d,&n);
      //      i+=n;
      f|=d==INT_MAX;
      while(isdigit(s[i])){
	i++;
      }
      }*/
    pii r=pii(d,0);
    co(r);
    return r;
  }else if(s[i]=='('){
    i++;
    pii r=pp();
    i++;
    return r;
  }else{
    return pii();
  }
}

pii pm(){
  pii a=pn();
  while(s[i]=='*'){
    i++;
    pii b=pn();
    pii c=pii(a.first*b.first-a.second*b.second,a.first*b.second+a.second*b.first);
    a=c;
    co(a);
  }
  return a;
}

pii pp(){
  pii a=pm();
  while(s[i]=='+'||s[i]=='-'){
    char o=s[i];
    i++;
    pii b=pm();
    a.first+=b.first*((o=='+')?1:-1);
    a.second+=b.second*((o=='+')?1:-1);
    co(a);
  }
  return a;
}

int main(){
  while(cin.getline(s,100)){
    f=false;
    i=0;
    pii r=pp();
    if(f){
      cout<<"overflow"<<endl;
    }else{
      if(r.first==0&&r.second==0){
	cout<<0<<endl;
      }else{
	if(r.first){
	  cout<<r.first;
	}
	if(r.second){
	  if(r.first&&r.second>0){
	    cout<<'+';
	  }
	  cout<<r.second<<'i';
	}
	cout<<endl;
      }
    }
  }
  return 0;
}

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

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

Measured memory_bytes: 256
#include <iostream>

int main (void)
{
	// variables for main process
	char buf;
	int  year, month, day;


	// STEP.01
	// read out the target date
	std::cin >> year >> buf >> month >> buf >> day;

	// STEP.02
	// judge the month
	// output the result
	if( month <= 4 ) { std::cout << "Heisei" << std::endl; }
	else             { std::cout << "TBD"    << std::endl; }

	// STEP.END
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    ll N, H; cin >> N >> H;
    vel a(N), b(N); rep(i,N) cin >> a[i] >> b[i];

    ll ma = maxel(a); sort(rall(b));

    int cnt = 0;
    rep(i,N) {
        if(b[i] > ma) { H -= b[i]; cnt++; }
        if(H <= 0) {cout << cnt << endl; return 0;}
    }
    cnt += (H + ma - 1) / ma;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.List;

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

    static void solve(Scanner sc) {
        String n = sc.next();
        char[] ns = n.toCharArray();
        int sum = 0;
        for (char c : ns) {
            sum += c - '0';
        }
        System.out.println(Integer.parseInt(n) % sum == 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {

    int N, H;
    cin >> N >> H;

    vector<int> throw_dmg;
    int max_at = 0, at_throw = 0;
    int at, th;
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &at ,&th);
        if (at > max_at) {
            max_at = at;
            throw_dmg.push_back(at_throw);
            at_throw = th;
        }
        else if (at == max_at) {
            if (at_throw > th) {
                throw_dmg.push_back(at_throw);
                at_throw = th;
            }
            else {
                throw_dmg.push_back(th);
            }
        }
        else {
            throw_dmg.push_back(th);
        }
    }

    sort(throw_dmg.begin(), throw_dmg.end(), greater<int>());
    /*
    cout << max_at << ' ' << at_throw << '\n';
    for (int i = 0; i < N; i++) {
        cout << throw_dmg[i] << '\n';
    }
    */

    long long ans = 0;
    for (int i = 0; i < throw_dmg.size(); i++) {
        if (throw_dmg[i] > max_at) {
            H -= throw_dmg[i];
            ans++;
        }
        else break;
        if (H <= 0) {
            break;
        }
    }

    if (H <= 0) {
        cout << ans << '\n';
        return 0;
    }
    
    H -= at_throw;
    ans++;
    if (H <= 0) {
        cout << ans << '\n';
        return 0;
    }
    
    ans += (H + (max_at - 1)) / max_at;
    cout << ans << '\n';


}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s,k;
    cin>>s>>k;
    int c=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]!=k[i])c++;
    }
    cout<<c<<endl;

}


Measured memory_bytes: 3832
#include<iostream>
#include<iomanip>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const int INF = 1e9;


int N, B[99];

int main() {
    cin >> N;
    for (int i = 0; i < N-1; i++) cin >> B[i];
    int res = 0;
    res += B[0];
    for (int i = 1; i < N-1; i++) {
        res += min(B[i-1], B[i]);
    }    
    res += B[N-2];
    cout << res << endl;
}


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

int main()
{
  string s;
  
  while(getline(cin, s)) {
    if(s == "END OF INPUT") break;

    int count = 0;
    vector<int> num;
    for (int i = 0; i < s.size(); i++) {
      if(s[i]==' ') {
	num.push_back(count);
	count = 0;
      }
      else count++;
    }
    num.push_back(count);

    for (int i = 0; i < num.size(); i++) {
      cout << num[i];
    }
    cout << endl;
  }
    
  return 0;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if(u == s) --a;
  if(u == t) --b;
  cout << a << ' ' << b << '\n';
}

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

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

const long long MOD = 1000000007;

int main(){
  int n,m,a,b;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ans(n,true);
  rep(i,n) cin >> h.at(i);
  rep(i,m){
      cin >> a >> b;
      a--;b--;
      if(h.at(a)>=h.at(b)) ans.at(b)=false;
      if(h.at(b)>=h.at(a)) ans.at(a)=false;
  }
  int c=0;
  rep(i,n){
      if(ans.at(i)) c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 3788
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll a;
  long double b;
  cin >> a >> b;
  long double c = a * b;
  cout << (ll)c << endl;
  return 0;
}

Measured memory_bytes: 3728
#include <cstdio>

using namespace std;

int dic[244140625];

int ctoi(char c) {
    switch (c) {
        case 'A':return 1;
        case 'C':return 2;
        case 'G':return 3;
        case 'T':return 4;
        default:return 0;
    }
}

int hash(char s[]) {
    int res = 0;
    for (int i = 0; s[i] != '\0'; ++i) {
        res *= 5;
        res += ctoi(s[i]);
    }
    return res;
}

void insert(char s[]) {
    dic[hash(s)]++;
}

bool find(char s[]) {
    return dic[hash(s)];
}

int main() {
    int n;
    char inst[8], str[16];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%s %s", inst, str);
        if (inst[0] == 'i') insert(str);
        else printf("%s\n", (find(str) ? "yes" : "no"));
    }
    return 0;
}



Measured memory_bytes: 19536
'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => Number(v))
  // const ans = (input[0] - input[1]) % input[2]

  // 500, 100, 50
  const A = input[0]
  const B = input[1]
  const C = input[2]
  const X = input[3]

  let count = 0
  for (let ai = 0; ai <= A; ai++) {
    for (let bi = 0; bi <= B; bi++) {
      for (let ci = 0; ci <= C; ci++) {
        if (ai * 500 + bi * 100 + ci * 50 === X) count++
      }
    }
  } 

  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include<iostream>
#include<cstdio>
#include<cstring>
/*
int main()
{
    int r;
    scanf("%d",&r);
    if(r < 1200)
        printf("ABC");
    else if(r>=1200 && r<2800)
        printf("ARC");
    else if(r >= 2800)
        printf("AGC");
    return 0;
}*/
int main()
{
    char s[20];
    scanf("%s",s);
    bool flag = true;
    int len = strlen(s);
    if(s[0] != 'A')
        flag = false;
    if(s[1]=='C' || s[len-1]=='C')
        flag = false;
    int tot = 0;
    for(int i = 2;i < len-1;i ++)
    {
        if(s[i] == 'C')
            tot ++;
    }
    for(int i = 1;i <= len-1;i ++)
    {
        if(!(s[i]>='a'&&s[i]<='z') && s[i]!='C')
            flag = false;
    }
    if(tot != 1)
        flag = false;
    printf("%s\n",flag ? "AC" : "WA");
    return 0;
}

Measured memory_bytes: 256
import math

n = int(input())
if n == 1:
    print(1)
    exit(0)
dp = [0] * (n+1)
mod = 10**9+7

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):

        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

prime = sieve_of_erastosthenes(1000)
prime = [i for i, t in enumerate(prime) if t]

for i in range(2, n+1):
    v = i
    while v < n+1:
        dp[i] += 1
        v += i

dp2 = [0] * (n+1)
for p in prime:
    v = p
    k = 1
    while v < n+1:
        dp2[p] += dp[v]
        v *= p
        k += 1

ans = 1
for i in range(n+1):
    ans = (ans * (dp2[i]+1)) % mod
print(ans)
        

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

int bs_upper_bound(int a[], int n, int x) {
    int l = 0;
    int h = n; // Not n - 1
    while (l < h) {
        int mid =  l + (h - l) / 2;
        if (x >= a[mid]) {
            l = mid + 1;
        } else {
            h = mid;
        }
    }
    return l;
}

int bs_lower_bound(int a[], int n, int x) {
    int l = 0;
    int h = n; // Not n - 1
    while (l < h) {
        int mid =  l + (h - l) / 2;
        if (x <= a[mid]) {
            h = mid;
        } else {
            l = mid + 1;
        }
    }
    return l;
}

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

int n;
vector<int> g[100001];
ll mod=1e9+7;
ll dp[100001][2];

ll dfs(int x,int f,int p){
    if(dp[x][f]!=0)
        return dp[x][f];
    dp[x][f]=1;
    for(int i=0;i<g[x].size();i++){
        if(g[x][i]!=p){
            if(f==0)
                dp[x][0]=(dp[x][0]*((dfs(g[x][i],1,x)+dfs(g[x][i],0,x))%mod))%mod;
            if(f==1)
                dp[x][1]=(dp[x][1]*dfs(g[x][i],0,x))%mod;
        }
    }
    return dp[x][f];
}

int main()
{
    IOS;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i=0;i<n;i++){
        dp[i][0]=0;
        dp[i][1]=0;
    }
    ll x=dfs(0,0,-1);
    ll y=dfs(0,1,-1);
    cout<<(x+y)%mod;
}


Measured memory_bytes: 21712
s = input()
n = len(s)

ans = 0
dp1 = [0]*(n+1)
dp0 = [0]*(n+1)

dp1[0] = 1

for i in range(n):
  k = int(s[i])
  if k < 5:
    dp0[i+1] = dp0[i] + k
  elif k > 5:
    dp0[i+1] = dp1[i] + 10-k
  else:
    if i == 0:
      dp0[i+1] = dp0[i] + k
    elif int(s[i-1]) < 5:
      dp0[i+1] = dp0[i] + k
    else:
      dp0[i+1] = dp1[i] + 10-k
  k += 1
  if k == 10:
    dp1[i+1] = dp1[i]
  elif k < 5:
    dp1[i+1] = dp0[i] + k
  elif k > 5:
    dp1[i+1] = dp1[i] + 10-k
  else:
    if i == 0:
      dp1[i+1] = dp0[i] + k
    elif int(s[i-1]) < 5:
      dp1[i+1] = dp0[i] + k
    else:
      dp1[i+1] = dp1[i] + 10-k

print(dp0[n])

Measured memory_bytes: 83308
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+7;
int n;
int a[maxn];
int f[2][maxn][20];
int Log[maxn];
int pos[maxn]; 
inline int ask(int opt,int l,int r)
{
	int k=Log[r-l+1];
	return min(f[opt][l][k],f[opt][r-(1<<k)+1][k]);
}
inline pair<int,int> calc(int l,int r)
{
	int x,y;
	x=ask(l&1,l,r);
	y=ask((l-1)&1,pos[x]+1,r);
	return make_pair(-x,-y);
}
priority_queue<pair<pair<int,int>,pair<int,int > > > q;
int main()
{
  //freopen(".in","r",stdin);
  //freopen(".out","w",stdout);
  scanf("%d",&n);
  for(int i=1;i<=n;i++) 
  {
  	scanf("%d",&a[i]);
  	f[i&1][i][0]=a[i];
  	f[(i-1)&1][i][0]=1e9+7;
  	pos[a[i]]=i;
  }
  Log[1]=0;
  for(int i=2;i<=maxn-7;i++)
    Log[i]=Log[i>>1]+1;
  for(int k=0;k<=1;k++)//奇or偶
    for(int j=1;j<=19;j++)
	  for(int i=1;i+(1<<j)-1<=n;i++)
	    f[k][i][j]=min(f[k][i][j-1],f[k][i+(1<<(j-1))][j-1]);
  q.push({{calc(1,n)},{1,n}}); 
  while(q.size())
  {
  	pair<pair<int,int>,pair<int,int> > tmp=q.top(); 
	q.pop(); 
  	int x=tmp.first.first,y=tmp.first.second; 
  	printf("%d %d ",-x,-y);
  	x=pos[-x];
	y=pos[-y];
  	int l=tmp.second.first,r=tmp.second.second; 
  	if(l+1<x) 
	  q.push({{calc(l,x-1)},{l,x-1}});
  	if(x+1<y-1) 
	  q.push({{calc(x+1,y-1)},{x+1,y-1}});
  	if(y+1<r) 
	  q.push({{calc(y+1,r)},{y+1,r}});
  }
  return 0;
}

Measured memory_bytes: 35828
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

int main()
{
    ll N, D, sum = 0;
    ll X, Y;
    cin >> N >> D;
    for(ll i = 0;i < N;i++)
    {
        cin >> X >> Y;
        if(D*D >= X*X + Y*Y)
        {
            sum++;
        }
    }

    cout << sum << endl;

    return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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

int a[200001];


int main(void) {
	int n;
	long long int p, q;
	bool flag = false;
	long long int count = 0;
	char s[301][301];

	cin >> n;
	FOR(i, 0, n-1) {
		cin >> s[i];
	}

	FOR(u, 0, n - 1) {
		flag = true;
		FOR(i, 0, n - 1) {
			FOR(t, 0, n - 1) {
				if (i == t) {
					continue;
				}
				if (i + u > n - 1) {
					p = (i + u) - (n - 1) - 1;
				}
				else {
					p = i + u;
				}
				if (t + u > n - 1) {
					q = (t + u) - (n - 1) - 1;
				}
				else {
					q = t + u;
				}
				//cout << u << " " << p << " " << q << endl;
				if (s[i][q] != s[t][p]) {
					flag = false;
					//cout << u << " " << p << " " << q <<" "<<"out"<< endl;
					break;
				}
			}
			if (flag == false) {
				break;
			}
		}
		if (flag) {
			count++;
		}
	}
	
	cout << count*n << endl;


	return 0;
}



Measured memory_bytes: 384
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

A, B = MAP()
C = []

for i in range(50):
    C.append(["#"] * 100)
for i in range(50):
    C.append(["."] * 100)

h = 0
w = 0
for i in range(A-1):
    C[h][w] = "."
    w += 2
    if w >= 100:
        # 端まで行ったら最初っから
        w = 0
        # 一行開けて下に書く
        h += 2

# 下から．二次元でもできる．
h = -1
w = 0

for i in range(B-1):
    C[h][w] = "#"
    w += 2
    if w >= 100:
        # 端まで行ったら最初っから
        w = 0
        # 一行開けて下に書く
        h -= 2

print(100, 100)
for i in range(100):
    print(*C[i], sep="")

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

const int MN=105;
const int MK=1e5+5;
int a[MN];
int dp[MK];
int n,k; 
int getdp(int x)
{
	//if(x<=2) cout<<x<<endl;
	if(x<a[0]) return 0;
	int &ans=dp[x];
	if(ans!=-1) return ans;
	ans=0;
	for(int i=0;i<n&&a[i]<=x;i++)
	{
		if(getdp(x-a[i])==0)
		{
			ans=1;
			return ans;
		}
	}
	return ans;
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	memset(dp,-1,sizeof(dp));
	printf("%s\n",getdp(k)?"First":"Second");
	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
int R,C,s[10000][10],f[10],N,i,j,n,m;void rec(int k){if(k<R){f[k]=0;rec(k+1);f[k]=1;rec(k+1);}else for(n=i=0;i<C;i++,n+=m>R-m?m:R-m,N=N>n?N:n)for(m=j=0;j<R;j++)m+=s[i][j]^f[j];}main(){for(;std::cin>>R>>C,R|C;rec(0),printf("%d\n",N))for(j=R;j-->0;)for(i=C;i-->0;)std::cin>>s[i][j];}

Measured memory_bytes: 1256
@memo = {}

def count(n)
  return @memo[n] if @memo[n]
  result = case n
           when 1 then 1
           when 2 then 2
           when 3 then 4
           else
             count(n - 1) + count(n - 2) + count(n - 3)
           end
  @memo[n] = result
end

until (n = $<.gets.to_i).zero?
  days = Rational(count(n), 10).ceil
  puts Rational(days, 365).ceil
end



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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: i32,
        s: chars
    }
    let change = |c: char, num: i32| -> char {
        let aint = 'A' as i32;
        let alphanum = 26;
        ((((c as i32) - aint + num) % alphanum) + aint) as u8 as char
    };
    for i in s {
        print!("{}", change(i, n));
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<cmath>
#include<iomanip>

using namespace std;

int main()
{
  long double a,b,h,m;
  cin>>a>>b>>h>>m;
  
  long double d1=h*30+m/2;
  long double d2=m*6;
  
  long double result=a*a+b*b-2*a*b*cos((d1-d2)*3.14159265358979/180);
  
  result=(long double)sqrt(result);
  
  cout<<fixed<<setprecision(10)<<result;
  
  return 0;
}

Measured memory_bytes: 4152
s=input()
t=input()
n=len(s)
s=sorted(s)
t=sorted(t)
Lists={}
nums=[]
Listt={}
numt=[]

for i in range(n):
    Lists.setdefault(s[i], 0)
    Listt.setdefault(t[i], 0)
    Lists[s[i]]+=1
    Listt[t[i]]+=1
    
for j in Lists.values():
    nums.append(j)
    
for j in Listt.values():
    numt.append(j)
#print(nums)
#print(numt)
#nums=sorted(Lists.values)
#numt=sorted(Listt.values)

if (sorted(nums)==sorted(numt)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7580
#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 PLL pair<ll, ll>
#define T3I tuple<int, int, int>
#define x first
#define y second
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);

    ll N, A, B;
    cin >> N >> A >> B;
    ll r = N%(A+B);
    ll ans = N/(A+B)*A;
    ans += min(A, r);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define inf 1000000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
using namespace std;


signed main()
{
	fastio(0);
	int n;
	cin>>n;
	int a[n];
	loop(i,0,n) cin>>a[i];
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[0]-a[1]);
	loop(i,2,n)
		dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
	cout<<dp[n-1]<<endl;	
 	return 0;		
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(){
  int n,a,b;
  scanf("%4d",&n);
  a=n/100;
  b=n%100;
  if (a>0 && a<13){
    if (b>0 && b<13) printf("AMBIGUOUS\n");
    else printf("MMYY\n");
  }
  else {
    if (b>0 && b<13) printf("YYMM\n");
    else printf("NA\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B,C,D;
  string a,b,c;
  cin >>A>>B;
  if(A+B>9)Out("error");
  else Out(A+B);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,i,j,c,d,an=0,k,mod;
    mod=1000000007;
    cin>>n;
    ll ar[n+2];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    for(i=0;i<62;i++)
    {
        k=(1LL<<i);
        c=0;
        d=0;
        for(j=0;j<n;j++)
        {
            if((ar[j] & k)==0)
                c++;
            else
                d++;
        }
        an=an+((k%mod)*((c*d)%mod))%mod;
        an=an%mod;
    }
     cout<<an<<endl;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <ll> A(N);
	vector <ll> absA(N);
	int sign = 0;
	ll ans = 0;
	for (int ii = 0; ii < N; ++ii){
		cin >> A[ii];
		absA[ii] = abs(A[ii]);
		ans += absA[ii];
		if (A[ii] < 0){
			sign ^= 1;
		}
	}

	if (sign){
		sort(absA.begin(), absA.end());
		ans = ans - 2 * absA[0];
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4752
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
DP = [0]
for i in range(N-1):
    act = float("inf")
    for k in range(K):
        if i-k < 0 : break
        act = min(DP[-1-k] + abs(h[i-k]-h[i+1]) , act)
    DP += [act]
 
print(DP[-1])


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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n; cin >> n;
    vi a(n); rep(i,n) cin >> a[i];
    vi sorted_a = a;
    sort(all(sorted_a));
    int maxim = sorted_a[n-1];
    int maxim2 = sorted_a[n-2];
    if(maxim == maxim2){
        rep(i,n) cout << maxim << '\n';
    }
    else {
        rep(i,n){
            if(a[i] == maxim) cout << maxim2 << '\n';
            else cout << maxim << '\n';
        }
    }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void cout_join(I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)cout<<d;cout<<*i;}cout<<endl;}

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

  int n; cin >> n;
  vector<double> a(n);
  REP(i,n) cin >> a[i];

  double avr = accumulate(ALL(a),0.0f);
  avr /= n;

  REP(i,n) a[i] = abs(a[i]-avr);

  cout << min_element(ALL(a)) - a.begin() << endl;
  
  return 0;
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a, b) << " ";
  if(a+b<=n) cout << 0 << endl;
  else cout << a+b-n << endl;
  return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int K=stdIn.nextInt();
		long ans=K;
		if(N!=0)
			ans*=Math.pow(K-1,N-1);
		System.out.println(ans);
	}
}


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

int uni(string s){
	set<char>st(s.begin(),s.end());
	return (int)st.size();
}

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

	string s;
	cin>>s;

	if(s[2] == s[3] and s[4] == s[5] ) {
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    
    vector<int>a;
    for(int i=0;i<s.length();i++){
        a.pb(s[i]-'0');
    }
    ll sum=0;
    ll now=a[0];
    ll ss=s.length()-1;
    for(int bit=0;bit<(1<<ss);bit++){
        for(int i=0;i<ss;i++)
        {
            if(bit&(1<<i)){
                //cout<<now<<endl;
                sum+=now;
                now=a[i+1];
            }
            else
                now=now*10+a[i+1];
        }
        //cout<<now<<endl;
        sum+=now;
        now=a[0];
    }
    cout<<sum<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i) << ", ";
  }
  cout << "]" << endl;
}

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

  if (a < b && b < c)
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }
}



Measured memory_bytes: 3096
#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 Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#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;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>S;
    N = S.size();
    vector<string> d = {"dream", "erase"};
    //cout<<d[0].substr(3, 4)<<endl;
    int id = 0;
    while(id != N){
        string st = S.substr(id, 5);
        if(st == d[0]){
            id += 5;
            if(S.substr(id, 3) == "era") continue;
            if(S.substr(id, 2) == "er") id += 2;
        }else if(st == d[1]){
            id += 5;
            if(id < N){
                if(S[id] == 'r') ++id;
            }
        }else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final char[] chs = sc.next().toCharArray();
			
			int[] counts = new int[10];
			for(int i = chs.length - 1; i >= 0; i--) {
				counts[chs[i] - '0']++;
			}
			
			HashSet<String> answer = new HashSet<String>();
			
			boolean[] i_pat = new boolean[10];
			boolean[][] j_pat = new boolean[10][10];
			
			for(int i = 0; i < N; i++) {
				final int c1 = chs[i] - '0';
				counts[c1]--;
				
				if(i_pat[c1]) { continue; }
				int[] backup = counts.clone();
				
				for(int j = i + 1; j < N; j++) {
					final int c2 = chs[j] - '0';
					counts[c2]--;
					
					if(j_pat[c1][c2]) { continue; }
					
					for(int val = 0; val < 10; val++) {
						if(counts[val] <= 0) { continue; }
						
						answer.add(c1 + "" + c2 + "" + val);
					}
					
					j_pat[c1][c2] = true;
				}
				
				i_pat[c1] = true;
				counts = backup;
			}
			
			System.out.println(answer.size());
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 23508
// Aizu Vol-2 0296: A Fat Wallet
// 2017.8.6

#include <stdio.h>

int u[6] = { 1, 5, 10, 50, 100, 500 };

int main()
{
	int i, s, n;
	for (i = s = 0; i < 6; i++) {
		scanf("%d", &n);
		s += u[i] * n;
	}
	puts(s >= 1000 ? "1" : "0");
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>  // This will work only for g++ compiler. 
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forab(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define pb push_back
#define fi first
#define se second
#define __builtin_popcount(x) ones(x)
#define __builtin_popcountl(x) onesl(x)
#define __builtin_popcountll(x) onesll(x)// to be used with algorithms that processes a container Eg: find(all(c
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
// int ans=0;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    int t;
    cin>>t;
    int k;
    cin>>k;
    int arr[t];
    int i=0;
    while(i<t){
      cin>>arr[i];
      i++;
    }
    if(t==1){cout<<0<<endl; return 0;}
    if(t==2){
      cout<<abs(arr[0]-arr[1])<<endl;
      return 0;
    }
    vector<long> cost(t,INT_MAX);
    cost[0]=0;
    cost[1]=abs(arr[0]-arr[1]);
    for(i=2;i<t;i++){
      for(int j=i-1;j>=0 && i-j<=k;j--){
        cost[i]=min(cost[j]+abs(arr[i]-arr[j]),cost[i]);
      }
    }
    cout<<cost[t-1]<<endl;
    return 0;
}


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

ans = 0
while True:
    
    l,r = -1,-1

    for i in range(N):
        if H[i] != 0:
            l = i
            break

    if l == -1:
        break

    for i in range(l,N):
        if H[i] == 0:
            r = i-1
            break

        if i == N-1: r = N-1


    tmp =  min(H[l:r+1])
    for i in range(l,r+1):
        H[i] -= tmp
    ans += tmp

print(ans)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n, m, c int
	fmt.Scan(&n, &m, &c)
	bs := make([]int, m)
	for i := range bs {
		fmt.Scan(&bs[i])
	}
	res := 0
	sum := 0
	for l := 0; l < n; l++ {
		for i := range bs {
			ia := make([]int, m)
			fmt.Scan(&ia[i])
			sum += bs[i] * ia[i]
		}
		if sum+c > 0 {
			res++
		}
		sum = 0
	}
	fmt.Println(res)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	string s;
	cin >> s;
	for(int i = 0;i < s.length(); i++){
		if(i % 2 == 0){
			if(s[i] == 'L'){
				cout << "No\n";
				return 0;
			}
		}
		else{
			if(s[i] == 'R'){
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
}


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


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    ll A,B,K;
    cin>>A>>B>>K;
    if(K>A){
        K -= A;
        A=0;

        if(K>B){
            K-=B;
            B=0;
        }
        else{
            B-=K;
        }
    }
    else{
        A-=K;
    }

    cout<<A<<" "<<B;
    return 0;
}

Measured memory_bytes: 256
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  int n, k, i, h, cou=0;
  scanf("%d %d", &n, &k);
  for(i=0; i < n; i++){
    scanf(" %d", &h);
    if(h >= k) cou++;
  }
  printf("%d", cou);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,c=0;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<n;i++)
  {
    if((a[i]==b[i]) && (a[i+1]==b[i+1]) &&(a[i+2]==b[i+2]))
    {
      c=1;
    }
  }
  if(c==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3632