akhauriyash/Code-Regression huggingface dataset:
/*input
30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k; cin >> n >> k;
    ll r, s, p; cin >> r >> s >> p;
    ll ans = 0;
    map<char, char> win;
    win['r'] = 'p';
    win['s'] = 'r';
    win['p'] = 's';
    string t; cin >> t;
    string res = "";
    for(int i = 0; i < n; i++)
    {
    	res += win[t[i]];
    	if(i >= k && res[i] == res[i - k]) res[i] = '?';
    	if(res[i] == 'r') ans += r;
    	else if(res[i] == 's') ans += s;
    	else if(res[i] == 'p') ans += p;
    }
    cout << ans;

    return 0;
}

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

int main(){
  string str;
  cin >> str;
  int n = str.length();
  string newStr = "";
  rep(i, n){
    if(str[i] == 'A'){
      newStr += 'A';
    }else if(str[i] == 'B'){
      if(i != n-1 && str[i+1] == 'C'){
        newStr += 'D';
        i++;
      }else{
        newStr += 'B';
      }
    }else{
      newStr += 'C';
    }
  }
  int a = 0;
  ll cnt = 0;
  rep(i, newStr.length()){
    if(newStr[i] == 'A') a++;
    else if(newStr[i] == 'D') cnt += a;
    else a = 0;
  }
  cout << cnt << endl;
  return 0;
}
  
  

Measured memory_bytes: 776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a<b) {
			if(b<c) {
				System.out.printf("%d %d %d\n",a,b,c);
			}else if(a<c) {
				System.out.printf("%d %d %d\n",a,c,b);				
			}else {
				System.out.printf("%d %d %d\n",c,a,b);
				
			}
		}else if(b>c) {
			System.out.printf("%d %d %d\n",c,b,a);
		}else if(a<c) {
			System.out.printf("%d %d %d\n",b,a,c);
		}else {
			System.out.printf("%d %d %d\n",b,c,a);
		}
		sc.close();

	}
}


Measured memory_bytes: 26300
#include <iostream>
using namespace std;
int main(){
  int n,r, p,c;
  string pile, buf, next;
  while(cin>>n>>r&&(n||r)){
    pile=" ";
    for( int i=n;i>0;i-- )
      pile = pile + (char)i;
    while(r--){
      cin>>p>>c;

      next = " " + pile.substr(p,c);
      if( p != 1)
	next += pile.substr(1, p-1);
      if( c != (int)pile.length() )
	next += pile.substr(p+c);

      pile = next;
    }
    cout << (int)pile[1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
 
 
 
struct node{
  int lc;
  int rc;
  int key;
  void init(int a){
    lc=rc=-1;
    key=a;
  }
};
 
#define bstN 600000
struct bst{
 
  int size;
  node t[bstN];
 
  void init(){
    size=0;
  }
   
  void insert(int v){
    int i=0;
    while(i<size){
      int& child=(v<t[i].key?t[i].lc:t[i].rc);
      if(child==-1)child=size;
      i=child; 
    }
    t[size++].init(v);
  }
 
  void preord(int pos){
    if(pos==-1||pos==size)return;
    preord(t[pos].lc);
    printf(" %d",t[pos].key);
    preord(t[pos].rc);
  }
   
  void inord(int pos){
    if(pos==-1||pos==size)return;
    printf(" %d",t[pos].key);
    inord(t[pos].lc);
    inord(t[pos].rc);
  }
};
 
 
bst T;
 
int main(){
  T.init();
  int n,a;
  char str[100];
  scanf("%d",&n);
   
  while(n--){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&a);
      T.insert(a);
    }else{
      T.preord(0);
      printf("\n");
      T.inord(0);
      printf("\n");
    }
  }
 
  return 0;
}


Measured memory_bytes: 9020
#include<stdio.h>
int main(){
    int S;
    int h;
    int m;
    int s;
    
    scanf("%d",&S);
    h = S / 3600;
    S = S % 3600;
    m = S / 60;
    s = S % 60;
    
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2084
list_a = []
list_b = []

for x in range(4):
    list_a.append(int(input()))
list_a.sort(reverse = True)

for x in range(2):
    list_b.append(int(input()))
list_b.sort(reverse = True)

print(sum(list_a[0:3]) + list_b[0])



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define maxn 200005
#define INF 0x3f3f3f3f
#define mod 1000000007
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
using namespace std;

void slove()
{
	string a, b;
	cin >> a >> b;
	if (a.size() == b.size()) {cout << "No"; return;}
	rep(i, 0, a.size()) {
		if (a[i] != b[i]) {
			cout << "No";return;
		}
	}
	cout << "Yes";
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
	slove();

	return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
int main (void){
	int n, i, j, maxv, minv, a[200000];

	scanf("%d", &n);
	
	for(i=0; i<n; i++)
		scanf("%d", &a[i]);
	
	maxv = a[1]-a[0];
	minv = a[0];
	
	for(j=1; j<n; j++){
		if(maxv < a[j]-minv) maxv = a[j]-minv;
		if(minv > a[j]) minv = a[j];
	}
	
	printf("%d\n", maxv);
	
	return 0;
}

Measured memory_bytes: 1376
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define ANS_DC(x)			cout <<  x << endl
#define VEC_TYPE			int	
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
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; }
template<typename T>inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T>inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


int main()
{
	int n, m;
	cin >> n >> m;
	int ans = 0;

	int l = 0;
	int r = n;
	for (int i = 0; i < m; ++i)
	{
		int compL, compR;
		cin >> compL >> compR;
		chmax(l, compL);
		chmin(r, compR);
	}

	if (l <= r)
		ans = r - l + 1;
	ANS_DC(ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define cBits(x) __builtin_popcount(x)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) a/gcd(a,b)*b
#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 MAX3(a,b,c) max(a,max(b,c))
#define MIN3(a,b,c) min(a,min(b,c))
#define eachTest int t; cin >> t; while(t--) solve();

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;

const int MOD=1000000007;

void solve() {
	;
}

int main() {

	fastio;
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

	// eachTest

	ll n, w;
	cin >> n >> w;
	vector <ll> vals(n + 1);
	vector <ll> wts(n + 1);
	FOR(i,1,n+1) {
		cin >> wts[i] >> vals[i];
	}
	ll table[n+1][w+1];
	FOR(i,0,n+1) {
		table[i][0] = 0;
	}
	FOR(i,0,w+1) {
		table[0][i] = 0;
	}
	FOR(i,1,n+1) {
		FOR(j,1,w+1) {
			if (wts[i] > j) {
				table[i][j] = table[i-1][j];
				continue;
			}
			table[i][j] = max(table[i-1][j], vals[i] + table[i-1][j-wts[i]]);
		}
	}
	// FOR(i,1,n+1) {
	// 	FOR(j,1,w+1) {
	// 		cout << table[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }
	cout << table[n][w] << "\n";

	return 0;
}


Measured memory_bytes: 79232
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void sort(int a[]) {
		int n = a.length;
		if (n == 0) {
			return;
		}
		for (int i = 1; i < n; i++) {
			int j = i;
			int ca = a[i];
			do {
				int nj = (j - 1) >> 1;
				int na = a[nj];
				if (ca <= na) {
					break;
				}
				a[j] = na;
				j = nj;
			} while (j != 0);
			a[j] = ca;
		}
		int ca = a[0];
		for (int i = n - 1; i > 0; i--) {
			int j = 0;
			while ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {
				j <<= 1;
				j += (a[j + 2] > a[j + 1]) ? 2 : 1;
			}
			if ((j << 1) + 2 == i) {
				j = (j << 1) + 1;
			}
			int na = a[i];
			a[i] = ca;
			ca = na;
			while (j != 0 && a[j] < ca) {
				j = (j - 1) >> 1;
			}
			while (j != 0) {
				na = a[j];
				a[j] = ca;
				ca = na;
				j = (j - 1) >> 1;
			}
		}
		a[0] = ca;
	}

	static void solve() throws Exception {
		int n = scanInt();
		int x = scanInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanInt();
		}
		sort(a);
		for (int i = 0; i < n; i++) {
			if (a[i] > x) {
				out.print(i);
				return;
			}
			x -= a[i];
		}
		out.print(x == 0 ? n : n - 1);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 21204
#include <stdio.h>

int main()
{
    int a;
    scanf("%d",&a);
    int arr[a],arr1[a],x=1;;
    for(int i=0;i<a;i++)
    {
        scanf("%d",&arr[i]);
    }
    arr1[0]=0;
    int p=arr[0];
    long long int count=0;
    for(int i=1;i<a;i++)
    {
        if(arr[i]>=p)
        {
            arr1[x]=i;
            p=arr[i];
            x++;
        }
    }
    arr1[x]=a;
    for(int i=0;i<x;i++)
    {
        if((arr1[i+1]-arr1[i])>1)
        {
            for(int j=arr1[i]+1;j<arr1[i+1];j++)
            {
                count=count+arr[arr1[i]]-arr[j];
            }
        }
    }
    printf("%lld",count);
    
    return 0;
}

Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {
  int n; cin >> n;
  int now = 100000;
  for (int i = 0; i < n; i++) {
    now *= 1.05;
    if (now % 1000 != 0)
      now = (now / 1000 + 1) * 1000;
  }
  cout << now << endl;
}



Measured memory_bytes: 3000
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<pair<int, int>> v(N);
  REP(i, N){
    int x, l;
    cin >> x >> l;
    v[i].first = x-l;
    v[i].second = x+l;
  }
  sort(ALL(v), [](pair<int, int> const & l, pair<int, int> const & r){
      return l.second < r.second;
      });

  int ans = 0;
  int past = -INF;
  REP(i, N){
    if(past <= v[i].first){
      ans++;
      past = v[i].second;
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main()
{
    vector<int> A(3);
    int K;
    cin >> A[0] >> A[1] >> A[2] >> K;
    sort(A.begin(), A.end());
    rep(i, K)
    {
        A[2] *= 2;
    }
    cout << A[0] + A[1] + A[2] << endl;
}


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

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

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

int main(){
    int p=0,g=0;
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='p') p++;
        if(s[i]=='g') g++;
    }
    int ap=n/2,ag=n-n/2; //cout<<ap<<' '<<ag<<endl;
    cout<<ap-p<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

    if (abs(a - c) <= d)
    {
        cout << "Yes" << endl;
    }
    else if (abs(a - b) <= d && abs(b - c) <= d)
    {
        cout << "Yes" << endl;
    }
    else 
    {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
ls = [int(input()) for i in range(5)]

na = []
for n in ls:
  if n%10 == 0:
  	na.append(n//10)
nb = []
rb = []
for n in ls:
  if n%10 != 0:
    nb.append(n//10 + 1)
    rb.append(n%10)
#print(na,nb)

if len(rb) == 0:
  print(sum(na)*10 + sum(nb)*10)
else:
  minr = max(min(rb), 0)
  print(sum(na)*10 + sum(nb)*10 -10 + minr)

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

long long suusiki(string s) {}

int main() {
  string s;
  cin >> s;
  long long ans = 0;
  // ans = suusiki(s);
  for (int bit = 0; bit < (1 << (s.size() - 1)); bit++) {
    long long tmp = s.at(0) - '0';
    for (int i = 0; i < s.size() - 1; i++) {
      if (bit & (1 << i)) {
        ans += tmp;
        tmp = s.at(i + 1) - '0';
      } else {
        tmp *= 10;
        tmp += s.at(i + 1) - '0';
      }
    }
    ans += tmp;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n,i,j;
	cin>>n;
	int a[9];
	a[0]=111;
	for (i=1;i<9;i++)
	a[i]=a[i-1]+111;
	for (i=1;i<9;i++)
	{
		if (n>=a[i-1]&&n<a[i])
		{
			if (n==a[i-1])
			cout<<a[i-1];
			else
			cout<<a[i];
		}
	}
	if (n==999)
	cout<<999;
	else if (n>=100&&n<111)
	cout<<111;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>


int main()
{
  std::string str;
  std::cin >> str;

  std::sort(str.begin(), str.end());
  if( str[0] == str[1] && str[2] == str[3] && str[1] != str[2] )
  {
    std::cout << "Yes"; return 0;
  }

  std::cout << "No";
}


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

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

const int MAXN=200000;

int n;
int p[MAXN];

int pos[MAXN];
int cnt[MAXN];

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&p[i]),--p[i];

	REP(i,n) pos[p[i]]=i;
	for(int i=n-1;i>=0;--i) { cnt[i]=1; if(i+1<n&&pos[i+1]>pos[i]) cnt[i]+=cnt[i+1]; }
	//printf("cnt:"); REP(i,n) printf(" %d",cnt[i]); puts("");

	int ret=n; REP(i,n) ret=min(ret,n-cnt[i]); printf("%d\n",ret);
}

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


Measured memory_bytes: 2560
import queue
import sys
from collections import defaultdict

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        # S = [list(map(int, list(input().rstrip())))for _ in range(N)]

        edges = defaultdict(set)
        for i in range(N):
            for j, flag in enumerate(list(input().rstrip())):
                if int(flag):
                    edges[i + 1].add(j + 1)

        ans = -1
        for i in range(N):
            q = queue.Queue()
            colors = defaultdict(int)
            q.put((i + 1, 0))
            colors[i+1] = -1
            is_bipartite_graph = True
            distance = 0
            while not q.empty():
                node = q.get()

                edge = edges[node[0]]

                # 2部グラフ判定
                for to in edge:
                    if colors[to] == 0:
                        colors[to] = -1 * colors[node[0]]
                        q.put((to, node[1] + 1))
                        distance = max(distance, node[1] + 1)
                    elif colors[to] == colors[node[0]]:
                        is_bipartite_graph = False
                        break
                if not is_bipartite_graph:
                    break

            if is_bipartite_graph:
                ans = max(ans, distance + 1)

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 50660
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int k, x; cin >> k >> x;
    cout << (500*k >= x ? "Yes" : "No") << endl;

return 0;
}

Measured memory_bytes: 3576
#[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" ) } ; }
#[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 ! 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 ) * } } ; }

fn main() {
    input! {
        n: usize,
        s_: String,
    }
    let s: Vec<i32> = s_.chars().map(|c| c.to_digit(10).unwrap() as i32).collect::<Vec<i32>>();

    let mut ret = 0;
    for i in 0..1000 {
        let mut ii = i;
        let mut v = vec![];
        for _ in 0..3 {
            v.push(ii % 10);
            ii /= 10;
        }

        let mut pos = 0;
        for j in 0..n {
            if s[j] == v[pos] {
                pos += 1;
            }
            if pos == 3 {
                break;
            }
        }
        if pos == 3 {
            ret += 1;
        }
    }

    println!("{}", ret);
}


Measured memory_bytes: 2276
#!/usr/bin/env python3
# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????

# input & calc
n = int(input())
max_diff = -20**9
minv = 20**9
for i in range(n):
    r = int(input())
    max_diff = max(max_diff, r - minv)
    minv = min(minv, r)

# output
print(max_diff)

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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 1e6 + 5;
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen(".INP", "r")){
                freopen(".INP", "r", stdin);
                freopen(".OUT", "w", stdout);
        }
        string s;
        cin >> s;
        if (s[2] == s[3] && s[4] == s[5]) cout << "Yes";
        else cout << "No";
}


Measured memory_bytes: 256
from collections import defaultdict as ddict
def cal_interval(Num):
	interval = ddict(int)
	dp = [0 for i in range(Num)]
	for i in range(Num):
		tmp = int(raw_input())
		for j in range(i+1):
			dp[j] += tmp
			interval[dp[j]] += 1
	return interval
while 1:
	N, M = map(int,raw_input().split(" "))
	if (N, M) == (0,0):
		break
	Lon = cal_interval(N)
	Lat = cal_interval(M)
	count = 0
	for k,v in Lon.iteritems():
		count += v * Lat[k]
	print count

Measured memory_bytes: 81816
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var sampleText = Console.ReadLine();
        switch(sampleText[sampleText.Length-1])
        {
            case '2':
            case '4':
            case '5':
            case '7':
            case '9':
                Console.WriteLine("hon");
                break;
            case '0':
            case '1':
            case '6':
            case '8':
                Console.WriteLine("pon");
                break;
            case '3':
                Console.WriteLine("bon");
                 break;
                
        }
    }
  
}

Measured memory_bytes: 25704
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;

ll fac[510000], finv[510000], inv[510000];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(){
  ll N,K;
  cin>>N>>K;
  vector <ll> a(N);
  for(ll i = 0;i<N;i++){
    cin>>a[i];
  }
  COMinit();
  sort(a.begin(),a.end());
  
  ll ans1 = 0;
  ll ans2 = 0;
  for(ll i = K-1;i<N;i++){
    ans1 += COM((i),(K-1))*a[i];
    ans1 = ans1%MOD;
  }
  
  for(ll i = 0;i<N-K+1;i++){
    ans2 += COM((N-i-1),(K-1))*a[i];
    ans2 = ans2%MOD;
  }
  if(ans1>=ans2){
    cout << (ans1-ans2)%MOD << endl;
  }
  else{
    cout << ans1-ans2+MOD << endl;
  }
  return 0;
}


Measured memory_bytes: 12928
#include<stdio.h>

bool exhaustiveSearch(int i, int n, int m, int A[]) {
  if (A[i] == m) return true;
  if (i >= n - 1) return false;
  return exhaustiveSearch(i + 1, n, m, A) || exhaustiveSearch(i + 1, n, m - A[i], A);
}

int main() {
  int i, n, A[20], q, m;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &m);
    if (exhaustiveSearch(0, n, m, A)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}



Measured memory_bytes: 2612
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,q;cin>>n>>k>>q;
    int a;
    vector<int> ac(n);
    for(int i=0;i<q;i++){
        cin>>a;
        ac[a-1]++;
    }
    for(int i=0;i<n;i++){
        if(q-ac[i]<k){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
}

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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}
ll N,M;
ll dp[100001];
vector<vector<ll>> G;

void chmax(ll &a,const ll &b){
    if(a<b) a=b;
}
void chmin(ll &a,const ll &b){
    if(a>b) a=b;
}

ll rec(ll v){
    if(dp[v]!=-1) return dp[v];

    ll res = 0;
    for(auto nv:G[v]){
        chmax(res,rec(nv)+1);
    }
    return dp[v]=res;
}


int main()
{


    cin >> N >> M;
    G.assign(N+1,vector<ll>());

    ll a,b;

    rep(i,M){
        cin >> a >> b;
        G[a].push_back(b);
    }


    rep(i,N+1) dp[i] = -1;

    ll ans=0;

    for(ll v=1;v<=N;v++){
        chmax(ans,rec(v));
    }

    cout << ans << endl;

    return 0;


}

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MAX_V 100000

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	int w, a, b;
	cin >> w >> a >> b;
	if (a < b) {
		cout << max(0, b - (a + w)) << endl;
	} else {
		cout << max(0, a - (b + w)) << endl;
	}
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;


void solve(long long N, std::vector<long long> A){
    long long result = 0;
    REP(i, N-1) { 
        if(A[i+1] > A[i]) {
            continue;
        } else  {
            result += A[i] - A[i+1];
            A[i+1] += A[i] - A[i+1];
        }
    }
    cout << result << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4840
# coding: utf-8
S = input()
cnt = {}
flg = True
for s in S:
  if s not in cnt:
    cnt[s] = 1
  else:
    cnt[s] += 1
for i in cnt.values():
  if i % 2 != 0:
    flg = False
print('Yes' if flg else 'No')


Measured memory_bytes: 2940
#include <cstdio>

using namespace std;

int n;
long long a[100043];
long long s[100043];

int main() {
  scanf("%d", &n);
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    ++s[a[i]]; res += a[i];
  }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int b, c;
    scanf("%d%d", &b, &c);
    res = res - s[b] * b + s[b] * c;
    s[c] += s[b];
    s[b] = 0;
    printf("%lld\n", res);
  }
  return 0;
}

Measured memory_bytes: 3236
from collections import defaultdict
N, M = map(int, input().split())
section = [list(map(int, input().split())) for i in range(N)]

# 区間の大きさごとに分類
D = defaultdict(list)
for sec in section:
    D[sec[1] - sec[0] + 1].append(sec)


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


BIT = BinaryIndexedTree(M)
certainly = 0  # 確実に通るもの

for d in range(1, M + 1):
    for l, r in D[d - 1]:
        certainly += 1
        BIT.add(l, 1)
        BIT.add(r + 1, -1)

    ans = N - certainly
    for i in range(d, M + 1, d):
        ans += BIT.sum(i)
    print(ans)


Measured memory_bytes: 131416
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int N, M, l=0, r=100000;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i=0; i<M; i++) {
    cin >> L[i] >> R[i];
    l=max(l,L[i]);
    r=min(r,R[i]);
  }
  cout << max((r-l+1),0) << endl;
}

Measured memory_bytes: 4032
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double a = w * h / 2;
  if (w/2 == x && h/2 == y) {
    printf("%.10f %d", a, 1);
    // cout << a << " " << 1 << endl;
  }else{
    printf("%.10f %d", a, 0);
    // cout << a << " " << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext())
        {
          int x = in.nextInt();
          int y = in.nextInt();
          int z = in.nextInt();
          int max = 0;
          int min =0;
          if(x==y && y==z)
              max=x;
          if(x==y)
          {
              if(y>z)
                  max=y;
              else
                  max=z;
          }
          if(x>y){
              if(x>z) {
                  max = x;
                  min=z;
              }
              else if(y>z) {
                  max = y;
                  min =z;
              }
              else {
                  max = z;
                  min =y;
              }
          }
          else
          {
              if(y>x)
              {
                  if(y>z) {
                      max = y;
                      min = x;
                  }
                  else {
                      max = z;
                      min=x;
                  }
              }
          }

          String s = Integer.toString(y);
          String t = Integer.toString(z);
          String q = Integer.toString(x);
          if(max==y) {
              String v = s+z;
              System.out.println(Integer.valueOf(v)+x);
          }
          else if(max==z) {
              String r = t+y;
              System.out.println(Integer.valueOf(r)+x);
          }
          else if(max==x){
              String f = q+y;
              System.out.println(Integer.valueOf(f)+z);
          }

        }
    }
}


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

#define ll long long
#define d long double

#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%Lf",&n)
#define pri(n) printf("%d ",(int)n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%Lf ",n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define dprin(n) printf("%Lf\n",n)

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define bitcount(n) __builtin_popcount(n)
#define tc   int tt; scf(tt); while(tt--)
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264

const ll M =1e9+7;
const int N = 1e6+7;



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

    int a[n],b[n];

    rep(i,0,n)
    cin>>a[i]>>b[i];

    int count=0,flag=0;

    rep(i,0,n-2)
    {
        if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])
       { flag=1;break;  }
    }
    if(flag)
    cout<<"Yes";
    else
    {
        cout<<"No";
    }
    
return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int N, ans;
int h[100];
/*int min(){
  	int M=101;
	for(int i=0; i<N; i++){
     	if(h[i]<M){
        	M=h[i];  
        }
    }
  	return M;
}*/
int sum(){
  	int s=0;
	for(int i=0; i<N; i++){
    	s+=h[i]; 
    }
	return s;
}

int main(){
	cin >> N;
  	for(int i=0; i<N; i++){
    	cin >> h[i];  
    }
	while(sum()){
      	int start=-1;
  		for(int i=0; i<N; i++){
    		if(h[i]>0){
        	 	start=i;
             	break;
       	 	}
    	}
      	if(start!=-1){
      		for(int i=start; i<N; i++){
         		if(h[i]>0&&i!=N-1){
            		h[i]-=1; 
            	}
              	else if(h[i]>0&&i==N-1){
                 	h[i]-=1;
                  	ans+=1;
                }
          		else{
              		ans+=1;
            		break; 
            	}
        	}
        }
    }
  	cout << ans << endl;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		char[][] map = new char[100][99];
		for(int i=0; i<100; i++) {
			Arrays.fill(map[i], '.');
		}
		fillA(map, a);
		if(a==1) {
			fillB(map, b+1);	
		} else {
			fillB(map, b);
		}
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(100 + " " + 99);
		for(int i=0; i<100; i++) {
			for(int j=0; j<99; j++) {
				pw.print(map[i][j]);
			}
			pw.println();
		}
		pw.close();
	}
	
	static void fillA(char[][] map, int a) {
		for(int i=0; i<100; i+=3) {
			for(int j=0; j<99; j+=3) {
				if(a-1>0) {
					fillBlock(map, i, j);
					a--;
				} else if(a-1==0) {
					return;
				} else {
					assert false;
				}
			}
		}
	}
	
	static void fillBlock(char[][] map, int i, int j) {
		for(int ii=i; ii<i+3; ii++) {
			for(int jj=j; jj<j+3; jj++) {
				map[ii][jj] = '#';
			}
		}
		map[i+1][j+1]='.';
	}
	
	static void fillB(char[][] map, int b) {
		for(int i=99; i>=50; i-=2) {
			for(int j=0; j<99; j+=2) {
				if(b-1>0) {
					if(j%2==0) {
						map[i][j] = '#';
						b--;
					}
				} else if(b-1==0) {
					return;
				} else {
					assert false;
				}
			}
		}
	}

	static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public MyScanner(InputStream s)
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    int count = 0;
    int max = 0;

    rep(i, N){
        cin >> H[i];
    }

    rep(i, N){
        if (H[i] >= max){
            max = H[i];
            count++;
        }
    }

    cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,a; cin >> n >> a;
    if(n%500 <= a) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;

int a, b[16][17];
unordered_map<int, int>memo;
int saiki(int c) {
	if (c == 0)return 0;
	else if (memo[c] != 0) return memo[c];
	else {
		int S = 1 << 29;
		for (int d = 0, e = 1; d < a; d++, e <<= 1) {
			if (c&e) {
				c -= e;
				S = min(S, saiki(c) + b[d][0]);
				for (int f = 0,g=1; f <= a; f++,g<<=1) {
					if (c&g) {
						S = min(S, saiki(c) + b[d][f+1]);
					}
				}
				c += e;
			}
		}
		 memo[c] = S;
		 return S;
	}
}
int main() {
	while (cin >> a, a) {
		for (int c = 0; c < a; c++) {
			for (int d = 0; d <= a; d++) {
				scanf("%d", &b[c][d]);
			}
		}
		memo.clear();
		cout << saiki((1 << a) - 1) << endl;
	}
}

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

int main() {
    int k;
    cin >> k;
    long dp[k + 1][5];
    fill(dp[0], dp[0] + 5, 0);
    for (int i = 0; i < k; i++) {
        long a;
        cin >> a;
        long min1 = dp[i][min_element(dp[i], dp[i] + 2) - dp[i]];
        long min2 = dp[i][min_element(dp[i], dp[i] + 3) - dp[i]];
        long min3 = dp[i][min_element(dp[i], dp[i] + 4) - dp[i]];
        long min4 = dp[i][min_element(dp[i], dp[i] + 5) - dp[i]];
        if (a == 0) {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = min1 + 2;
            dp[i + 1][2] = min2 + 1;
            dp[i + 1][3] = min3 + 2;
            dp[i + 1][4] = min4;
        } else if (a & 1l) {
            dp[i + 1][0] = dp[i][0] + a;
            dp[i + 1][1] = min1 + 1;
            dp[i + 1][2] = min2;
            dp[i + 1][3] = min3 + 1;
            dp[i + 1][4] = min4 + a;
        } else {
            dp[i + 1][0] = dp[i][0] + a;
            dp[i + 1][1] = min1;
            dp[i + 1][2] = min2 + 1;
            dp[i + 1][3] = min3;
            dp[i + 1][4] = min4 + a;
        }
    }
    cout << dp[k][min_element(dp[k], dp[k] + 5) - dp[k]] << endl;

    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";}
using namespace std;
using ll = long long;

int dp[105][10005], v[105], w[105];
// dp[i][j]...品物i個まで見たときの重さがj以下となるときの価値の最大値。

int main(void) {
    int N, W;
    cin >> N >> W;
    rep (i, N) cin >> v[i + 1] >> w[i + 1];

    for (int j = 1; j <= W; j++) {
        for (int i = 1; i <= N; i++) {
            if (j - w[i] >= 0) {
                dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
            }
            else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    
    cout << dp[N][W] << endl;
    return 0;
}


Measured memory_bytes: 7004
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;

	if (a > b)
		cout << "a > b" << endl;
	else if (a < b)
		cout << "a < b" << endl;
	else
		cout << "a == b" << endl;
	return 0;
}


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

typedef long long Int;

Int* tree;
void update(int node, Int val) {
	while (node < tree[0]) 
		tree[node] = max(tree[node], val),
		node += node & -node;
}

Int get(int node) {
	Int res = 0;
	while (node) 
		res = max(res, tree[node]),
		node &= node - 1;
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> h(n);
	vector<Int> a(n);
	for (auto&x : h) cin >> x;
	for (auto&x : a) cin >> x;
	tree = new Int[n + 1];
	tree[0] = n + 1;
	for (int i = 1; i <= n; i++) tree[i] = 0;
	
	Int answer = 0;
	for (int i = 0; i < n; i++) {
		Int f_i = get(h[i]) + a[i];
		answer = max(answer, f_i);
		update(h[i], f_i);
	} 
	cout << answer;
}

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

int main(void) {
    int n,k,r=0;
    int x[100];
    int tmp;

    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> x[i];
    }
    for(int i=0; i<n; i++){
        tmp = min(x[i], k-x[i]);
        r += tmp;
    }

    cout << r*2 << endl;
    
    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S=in<string>();
	ll K = in<ll>();
	int num = 1;
	for(ll i=0,ei=min(S.size(),(size_t)K);i<ei;i++){
		if(S[i]-'0'>1){
			num = (S[i]-'0');
			break;
		}
	}
	
	cout << num << endl;
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

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

    int ans = 0;

    int n, k;
    cin >> n >> k;
    if (n == 0) {
        cout << 1;
        return 0;
    }

    while (n > 0) {
        ans++;
        n /= k;
    }

    cout << ans;








    return 0;
}


Measured memory_bytes: 256
N = int(input())
a, b, ab, ret = 0, 0, 0, 0
for i in range(N):
    s = input()
    l = len(s) - 1
    if s[0] == "B" and s[l] == "A":
        ab += 1
    if s[0] == "B":
        b += 1
    if s[l] == "A":
        a += 1
    ret += s.count("AB")
if a == b and a == ab and a > 0:
    a -= 1
ab = min(a,b)
print(ret + ab)

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

inline bool ok(string& s) {
    li n = sz(s);
    if (s[0] == '0') {
        return false;
    }
    if (s[n - 1] == '1') {
        return false;
    }
    rep(i, (n - 1) / 2) {
        if (s[i] != s[n - 2 - i]) {
            return false;
        }
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    li n = sz(s);
    if (!ok(s)) {
        puts("-1");
        return 0;
    }
    if (n == 2) {
        puts("1 2");
        return 0;
    }

    li head = 1;
    repp(i, 1, n) {
        cout << head << " " << i + 1 << endl;
        if (s[i - 1] == '1') {
            head = i + 1;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define  ren(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) ren(i,0,(n))
#define  all(a) begin(a),end(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
 
int main()
{
    int a;
    cin>>a;
    if(a<1200) cout<<"ABC\n";
    else cout<<"ARC\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,a;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i) {
		scanf("%d",&a);
		n-=a;
	}
	if(n<0) printf("-1");
	else printf("%d",n);
	return 0;
}

Measured memory_bytes: 3828