akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main{

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int a = fs.nextInt();
        System.out.println(a + a*a + a*a*a);
    }

    static void sort(int[] a){
        ArrayList<Integer>l = new ArrayList<>();
        for(int i: a)
            l.add(i);
        Collections.sort(l);
        for(int i = 0; i < a.length; i++)
            a[i] = l.get(i);
    }

    static class FastScanner{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        String next(){
            while(!st.hasMoreTokens())
                try{
                    st = new StringTokenizer(br.readLine());
                } catch(IOException e){
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt(){
            return Integer.parseInt(next());
        }
        int[] readArray(int n){
            int[] a = new int[n];
            for(int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }
        long nextLong(){
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 32716
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}
 
 int min_cost(int arr[], int n , int k){
 	int dp[n+1]={0};
 	// base case

 	dp[1]=0;
 	for(int i=2;i<=n;i++){
 		dp[i]=INT_MAX;
 		for(int j=k;j>=1;j--){
 			if(i>j){
 				int subprob = abs(arr[i]-arr[i-j]) + dp[i-j];

 				dp[i]=min(dp[i], subprob );
 			}

 		}
 	}
 	return dp[n];

 }
int32_t main()
{
	//paawan9s
	FIO;
		int n, k; cin>>n>>k;
		mk(arr, n+1, int );
		for(int i=1;i<=n;i++)
			cin>>arr[i];
		cout<< min_cost(arr, n, k);
		// for(int i=1;i<=n;i++) cout<< arr[i];

	
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
As = list(map(int, input().split()))
q = int(input())
Ts = list(map(int, input().split()))

from bisect import bisect_left
ans = 0
As += [10**9]
for T in Ts:
    ind = bisect_left(As,T)
    if As[ind] == T:
        ans += 1
print(ans)


Measured memory_bytes: 16712
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;


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

    long long x;
    long long y;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            x = i;
            y = n / i;
        }
    }

    long long ans = x + y - 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> P;
struct pos {
  int row;
  int column;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main(void) {
  int N, M;
  vector<P> dp;
  cin >> N >> M;
  rep(i, M) {
    int left, right;
    cin >> left >> right;
    dp.push_back(P(right, left));
  }

  Sort(dp);

  int count = 0;
  int before = 0;
  rep(i, M) {
    P p = dp[i];
    if (count == 0 || before <= p.second) {
      count++;
      before = p.first;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll solve()
{
    int n, d;

    cin >> n >> d;

    int diameter = 2 * d + 1;
    int insp = n / diameter;

    if (n % diameter == 0)
        cout << insp << endl;
    else
        cout << insp + 1 << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s1;
    string s2;
    bool b = true;
    cin >> s1 >> s2;
    for(int i = 0;i < s1.size(); i++) {
        if(s1.at(i) != s2.at(i)) b = false;
    }
    if(s2.size() - s1.size() != 1) b = false;
    if(b) cout << "Yes";
    else cout << "No";
}

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

int main(){
  string s,l,r; int q;
  cin>>s>>q;
  bool sw = true;
  for(int i=0; i<q; i++){
    int t; cin>>t;
    if(t==1) {
      if(sw) sw = false; 
      else sw = true;
    }
    else {
      int f; char c;
      cin>>f>>c;
      if(sw){
        if(f==1) l += c;
        else r += c;
      }
      else { 
      	if(f==1) r += c;
      	else l += c;
      }
    }
  }
  reverse(l.begin(),l.end());
  s = l+s+r;
  if(!sw) reverse(s.begin(),s.end());
  cout<<s;
}

Measured memory_bytes: 1348
#include <stdio.h>

int main(void)
{
    int N, i;
    int A[100002];//i番目の街はA[i]体のモンスターに襲われている
    int B[100002];//i番目の勇者はiまたはi+1番目の街を襲っているモンスターを合計B[i]体倒せる
    long long sum=0;

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

    for(i=0; i<N; i++){
        //i街の討伐
        if(B[i] < A[i]){
            A[i]-=B[i];
            sum+=B[i];
            B[i]=0; 
        } else {
            B[i]-=A[i];
            sum+=A[i];
            A[i]=0;
        }

        //i+1街の討伐
        if(B[i] < A[i+1]){
            A[i+1]-=B[i];
            sum+=B[i];
            B[i]=0;
        } else {
            B[i]-=A[i+1];
            sum+=A[i+1];
            A[i+1]=0;
        }
    }

    printf("%lld\n",sum);

    return 0;
}

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

ll dp[1000000];
int main() {
	ll n; scanf("%lld", &n);
	dp[0] = n;
	ll sum = n - 1;
	for (int i = 1; i < n; i++) {
		dp[i] = ((n - 1)*(n - 1) + dp[i - 1] + sum) % MOD;
		sum = (sum + (i - 2 >= 0 ? dp[i - 2] : 1) + MOD - (i - n > 0 ? dp[i - n - 1] : 1)) % MOD;
	}
	printf("%lld\n", dp[n - 1]);
}

Measured memory_bytes: 8064
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, C, D, S):

    C = (C[0]-1, C[1]-1)
    D = (D[0]-1, D[1]-1)
    q = deque()
    q.append((0, C))
    memo = {}
    T = 10**6
    while q:
        c, (x, y) = q.popleft()
        if (x*T + y) in memo:
            continue
        memo[x*T + y] = c
        for nx, ny in [(x, y-1), (x, y+1), (x-1, y), (x+1, y)]:
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                q.appendleft((c, (nx, ny)))

        for nx in range(x-2, x+3):
            for ny in range(y-2, y+3):
                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                    q.append((c+1, (nx, ny)))

    return -1 if (D[0]*T + D[1]) not in memo else memo[D[0]*T + D[1]]


def main():
    H, W = read_int_n()
    C = read_int_n()
    D = read_int_n()
    S = [read_str() for _ in range(H)]
    print(slv(H, W, C, D, S))


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
int main() {
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int l=0,r=1;
    int tk=s[0]=='1'?0:1;
    int ts= 1;
int ms=ts;
    while(r<n){
        if(s[r-1]=='1'&&s[r]=='0')++tk;
        if(tk>k){
            while(l<r&&(s[l]!='0'||s[l+1]!='1')){
                ++l;
                --ts;
            }
            ++l;--ts;
            --tk;
        }
        ++ts;
        ++r;
        ms=max(ms,ts);
//cout<<ts<<" "<<tk<<endl;
    }
    cout<<ms<<endl;

    return 0;
}


Measured memory_bytes: 512
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))

C=[0]
for i in range(len(A)):
    C.append(C[i]+A[i])

mod=[]
for i in range(len(C)):
    mod.append(C[i]%M)

mod.sort()

n=1
t=0
for i in range(1,len(mod)):
    if i < len(mod)-1:
        if mod[i-1]==mod[i]:
            n+=1
        elif n>=2:
            t+=int(n*(n-1)/2)
            n=1
        else:
            pass
    else:
        if n>=2:
            if mod[i-1]==mod[i]:
                n+=1
            else:
                pass
            t+=int(n*(n-1)/2)
        else:
            if mod[i-1]==mod[i]:
                t+=1
            else:
                pass

print(t)

Measured memory_bytes: 16024
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * 2];
int N,head[MAXN],sumE,K,val[MAXN],c[MAXN],dp[MAXN],mv[MAXN];
bool vis[MAXN];
bool flag = 0;
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void dfs(int u,int fa) {
    mv[u] = 1e9;
    if(vis[u]) {
	if(val[u] > c[u] || ((c[u] - val[u]) & 1)) {flag = 1;}
	else dp[u] = (c[u] - val[u]) / 2;
	mv[u] = dp[u];
    }
    
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    c[v] = c[u] + 1;
	    dfs(v,u);
	    mv[u] = min(mv[u],mv[v]);
	}
    }
}
bool dfs2(int u,int fa,int d) {
    c[u] -= d * 2;
    if(vis[u] && c[u] != val[u]) return false;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    int t = d;
	    if(mv[v] - d > 0) ++t;
	    if(!dfs2(v,u,t)) return false;
	}
    }
    return true;
}

void Solve() {
    read(N);
    int a,b;
    for(int i = 1 ; i < N ; ++i) {
	read(a);read(b);
	add(a,b);add(b,a);
    }
    read(K);
    int v,p;
    for(int i = 1 ; i <= K ; ++i) {
	read(v);read(p);
	vis[v] = 1;val[v] = p;
    }
    int rt;
    for(int i = 1 ; i <= N ; ++i) {
	if(vis[i]) {rt = i;break;}
    }
    c[rt] = val[rt];
    dfs(rt,0);
    if(flag) {puts("No");return;}
    if(!dfs2(rt,0,0)) {puts("No");return;}
    puts("Yes");
    for(int i = 1 ; i <= N ; ++i) {out(c[i]);enter;}
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 9216
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define MAX_A 1'000'001
int N;
vector<int> A, C(MAX_A, 0);

string solve(){
	for(int a:A) C[a]++;
	bool pairwise = true;
	rp(i, 2, MAX_A){
		int c = 0;
		for(int j=i; j<MAX_A; j+=i) c += C[j];
		if(c > 1) pairwise = false;
	}
	if(pairwise) return "pairwise";
	int g = 0;
	for(int a:A) g = gcd(g, a);
	if(g == 1) return "setwise";
	return "not";
}

int main(){
	cin>>N;
	A.resize(N); rp(i, 0, N) cin>>A[i];
	cout<< solve() <<" coprime\n";
}


Measured memory_bytes: 11184
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
    IOS;
    int n;
    cin>>n;
    int ans=(n/500)*1000;
    n%=500;
    ans+=(n/5)*5;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
typedef struct E{
  int to,cost;
}edge;
vector<vector<edge> >E(100010);
int n,m;
bool used[100010]={};
ll human[100010]={};
bool flag=true;
void dfs(int now,int dis){
  for(int i=0;i<E[now].size();i++){
    if(!used[E[now][i].to]){
      used[E[now][i].to]=true;
      human[E[now][i].to]=dis+E[now][i].cost;
      dfs(E[now][i].to,dis+E[now][i].cost);
    }else{
      if(abs(human[now]-human[E[now][i].to])!=abs(E[now][i].cost)){
	flag=false;

      }
    }
  }
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int l,r,d;cin>>l>>r>>d;
    edge e;
    e.to=r;e.cost=d;
    E[l].pb(e);
    e.to=l;e.cost=-d;
    E[r].pb(e);
  }
  for(int i=1;i<=n;i++){
    if(used[i]==false)
      dfs(i,0);
  }
  if(flag)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 12416
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
#define FALSE 0
#define TRUE 1

int dp[64][2];
int A[100010];
int N, K;
int calc(int bit, int smaller) {
    //cout << bit << " " << smaller << endl;
    if(bit < 0) return 0;
    if(dp[bit][smaller] != -1) return dp[bit][smaller];
    int ret1 = 0, ret2 = 0;
    rep(i, N) {
        int c1 = A[i] & (1LL << bit);
        int c2 = K & (1LL << bit);
        ret1 += c1 ^ c2;
    }
    rep(i, N) {
        int c1 = A[i] & (1LL << bit);
        int c2 = 0;
        if(!(K & (1LL << bit))) c2 = (1LL << bit);
        ret2 += c1 ^ c2;
    }
    if(smaller) 
        return dp[bit][smaller] = calc(bit - 1, TRUE) + max(ret1, ret2);
    if(K & (1LL << bit))
        return dp[bit][smaller] = max(calc(bit - 1, FALSE) + ret1, calc(bit - 1, TRUE) + ret2);
    return dp[bit][smaller] = calc(bit - 1, FALSE) + ret1;
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> K;
    
    rep(i, N) cin >> A[i];
    rep(i, 64) rep(j, 2) dp[i][j] = -1;
    cout << calc(60, FALSE) << endl;

    return 0;
}


Measured memory_bytes: 4356
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;

static int MOD = 1e9 + 7;

class ECommonSubsequence {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m;
        in >> n >> m;
        vector<int> u(n), v(m);
        forn(i, n)in >> u[i];
        forn(i, m)in >> v[i];

        vector<vector<int> > dp(n + 1, vector<int>(m + 1, 0));

        forn(i, n + 1)dp[i][0] = 1;
        forn(i, m + 1)dp[0][i] = 1;

        fore(i, 1, n)fore(j, 1, m) {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
                if (u[i - 1] != v[j - 1])
                    dp[i][j] = (0LL + dp[i][j] - dp[i - 1][j - 1] + MOD) % MOD;
            }

        out << dp[n][m] << endl;
    }
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ECommonSubsequence solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << a;
  int ans = a - '0';
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int x = ans;
        x += pow(-1, i) * (b - '0');
        x += pow(-1, j) * (c - '0');
        x += pow(-1, k) * (d - '0');
        if (x == 7) {
          string s;
          s += i ? '-' : '+';
          s += b;
          s += j ? '-' : '+';
          s += c;
          s += k ? '-' : '+';
          s += d;
          cout << s << "=7" << endl;
          return 0;
        }
      }
    }
  }
}

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

const int MOD = 1000000007;
#define p(var)  std::cout<<var<<std::endl
#define pp(var) std::cout<<#var" = "<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for (int i = 0; i <  (n); i++)
#define repeq(i, n) for (int i = 1; i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a;}
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b;}

/*-----8<-----8<-----*/

int main(){
    string X;
    cin >> X;
    int a[2][X.length()];

    int odd_0=0;
    int even_0=0;
    int odd_1=0;
    int even_1=0;

    rep(i,X.length()){
        if(i%2==0){
            if(X[i]=='0')even_0++;
            else even_1++;
        }else{
            if(X[i]=='0')odd_0++;
            else odd_1++;
        }
    }

    //int hanbun=X.length%2==0 ? X.length()/2 : (X.length()+1)/2;
    //最初を０
    int tmp0=even_1+odd_0;

    //
    int tmp1=even_0+odd_1;

    int aaa=tmp0<tmp1?tmp0:tmp1;
    p(aaa);

    return 0;
    
}






Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b;
    for(int i=0;i<n;i++)
    {
        cin>>a.at(i);
    }
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        {
            b.insert(b.begin(),a.at(i));
        }
        else
        {
            b.push_back(a.at(i));
        }
    }
    if(b.size()>1 && b.size()%2==0)
    {
        reverse(b.begin(),b.end());
    }
    for(int i=0;i<n;i++)
    {
        if(i)
        {
            cout<<" ";
        }
        cout<<b.at(i);
    }
}


Measured memory_bytes: 5108
import java.util.Scanner;
public class Main {
    
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int c = 1;
			while(sc.hasNext()) {
				int W = sc.nextInt();
				if(W == 0) break;
				int N = sc.nextInt();
				int[] v = new int[N+1];
				int[] w = new int[N+1];
				for(int i=1; i<=N; i++) {
					String[] s = sc.next().split(",");
					v[i] = Integer.parseInt(s[0]);
					w[i] = Integer.parseInt(s[1]);
				}
				int[][] dp = new int[N+1][W+1];
				int maxV = Integer.MIN_VALUE;
				int minW = Integer.MAX_VALUE;
				for(int i=1; i<=N; i++) {
					for(int j=1; j<=W; j++) {
						if(j-w[i] >= 0) {
							dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
							if(maxV < dp[i][j]) {
								maxV = dp[i][j];
								minW = j;
							}
							else if(maxV == dp[i][j]) {
								minW = Math.min(minW, j);
							}
						}
						else dp[i][j] = dp[i-1][j];
					}
				}
				System.out.println("Case " + c++ + ":\n" + maxV + "\n" + minW);
			}
		}
	}
}


Measured memory_bytes: 40656
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

ll const MAX = 2e7 + 5;
ll fct[MAX];
void init() {
	fct[0] = 1;
	REP(i, 1, MAX - 1) {
		fct[i] = mod_m(fct[i - 1], i);
	}
}


int main() {
	init();
	ll h, w, k;
	cin >> h >> w >> k;
	ll a = h + w;
	ll x, y, z;
	x = mod_m(mod_inv(2), mod_m(k + 1, k));
	y = k;
	z = 0;
	REP(i, 1, k) {
		z = mod_p(z, mod_m(i, i - 1));
	}
	z = mod_m(z, mod_m(h, w));
	z = mod_m(z, mod_m(mod_inv(a), mod_inv(a - 1)));
	ll ans = mod_m(mod_m((x + y + z), fct[a]), mod_inv(fct[a - k]));
	cout << ans << endl;
}

Measured memory_bytes: 156544
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N, T;
    cin >> N >> T;
    vl c(N), t(N);
    rep(i, N){
        cin >> c[i] >> t[i];
    }
    ll time = 0;
    ll mini = 10e9;
    rep(i, N){
        if(t[i] <= T){
            if(mini > c[i]){
                mini = c[i];
            }
        }
    }
    if(mini != 10e9){
        cout << mini;
    }else{
        cout << "TLE";
    }
}

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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  int n;
  int h[105];
  int temp[105];
  int ans;
  int d;

  while(1){  
    scanf("%d",&n);
    if(n==0) break;
    
    for(int i=0;i<=n;i++){
      scanf("%d",&h[i]);
    }
    
    ans=0;
    for(int i=0;i<=n&&ans==0;i++){
      int cnt=0;
      for(int j=0;j<=n;j++){
	if(i!=j){
	  temp[cnt]=h[j];
	  cnt++;
	}
      }
    
      ans=0;
      d=temp[1]-temp[0];
      for(int j=2;j<n;j++){
	if(temp[j]-temp[j-1]!=d){
	  break;
	}
	if(j==n-1) ans=h[i];
      }
    }

    printf("%d\n",ans);
  }
  
  return (0);
}



Measured memory_bytes: 3212
class UFTree():
  def __init__(self,n):
    self.N = n
    self.parents = [-1]*n
    
  def root(self,n):
    if self.parents[n]<0: return n
    else:
      self.parents[n] = self.root(self.parents[n])
      return self.parents[n]
      
  def unite(self,x,y):
    rx,ry = self.root(x), self.root(y)
    if rx==ry: return
    if rx>ry: rx,ry = ry,rx
    self.parents[rx] += self.parents[ry]
    self.parents[ry] = rx
      
  def size(self,x):
    return -self.parents[self.root(x)]
  
N,M = map(int,input().split())
uft = UFTree(N)
for i in range(M):
  A,B = map(int,input().split())
  uft.unite(A-1,B-1)
print(max([uft.size(i) for i in range(N)]))

Measured memory_bytes: 18432
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;

class Program
{
    //Hashtable ht = new Hashtable();
    static List<int> A = new List<int>();
    static decimal result;
    static int N,K;
    //StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく



    static void Main()
    {
        //Modular mo = new Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）
        //Node no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        // delegate int CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名を入れる。
        //PriorityQueue pr = new PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
        Read1();
        Read2(N);
      int count=0;
      for(int i=0;i<N-1;i++){if(A[i]==A[i+1]){result++;}else{count++;}}
      //K*2かLR(RL)の個数count、小さい方を足す。
      if(count>K*2){result+=K*2;}else{result+=count;}
        Console.WriteLine(result.ToString());
    }


    static void Read1()
    {
        string[] tmp = Console.ReadLine().Split(' ');
        N = int.Parse(tmp[0]);
      K=int.Parse(tmp[1]);
    }

    static void Read2(int kosuu)
    {
        string tmp = Console.ReadLine();
      for(int i=0;i<N;i++){if(tmp[i]=='R'){A.Add(1);}else{A.Add(-1);}}
    }

}

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

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) cout << mat[i][j] << " "; cout << endl; }

using namespace std;

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


int main(){

	int n; cin >> n;
	int p[n+1];
	rep(i, 1, n+1) cin >> p[i];
	
	int q = 0;
	rep(i, 1, n+1){
		if(p[i]!=i){
			if(p[p[i]]==i){
				q++;
				swap(p[i], p[p[i]]);
			}
			else{
				q = 10;
			}
		}
	}
	
	
	if(q<=1){
		puts("YES");
	}else{
		puts("NO");
	}
	
	return 0;
}

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

int main(void) {
  int A, B;
  scanf("%d %d", &A, &B);
  if ((A+B)%2==1) {
    printf("IMPOSSIBLE\n");
  } else {
    printf("%d\n", (A+B)/2);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001

int n,m,r;

// char X[100][100];
// int dp[1000000001];
bool used[8];
int ans;

int main(void){
    cin >> n >> m >> r;
    int R[r];
    
    REP(i,0,r) {
        cin >> R[i];
    }
    
    int d[n+1][n+1];
    REP(i,1,n+1) REP(j,1,n+1) {
        if (i == j) d[i][j] = 0;
        else d[i][j] = INF;
    }

    
    REP(i,0,m) {
        int a,b,c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }
    

    
    REP(k,1,n+1) REP(i,1,n+1) REP(j,1,n+1) {
        if (d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j];
    }


    vector<int> v;
    REP(i, 0, r) v.push_back(R[i]);
    sort(v.begin(), v.end());
    int ans = INF;
    do {
        int sm = 0;
        REP(i, 0, r -1) sm += d[v[i]][v[i + 1]];
        ans = min(ans, sm);
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
    
    // int ans = INF;
    // do {
    //     int res = 0;
    //     REP(i,0,r-1) {
    //         res += d[target[i]][target[i+1]];
    //     }
    //     ans = min(ans,res);
    // } while(next_permutation(target, target + r));

    
    // cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>



int main(void){
	long long q,h,s,d,n;
	scanf("%lld %lld %lld %lld",&q,&h,&s,&d);//q:0.25 h:0.5 s:1 d:2
	scanf("%lld",&n);
	
	long long min=q*4;//1L買うならどうすれば安いか
	if(min>h*2) min=h*2;
	if(min>s) min=s;
	
	long long sum=0;
	
	if(min*2<=d){
		sum=min*n;
	}
	else{
		sum=d*(n/2)+min*(n%2);
	}
	
	printf("%lld",sum);
	
	return 0;
} 

Measured memory_bytes: 128
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,w = get_nums_l()
ppp = list(map(lambda s: tuple(map(int,s.strip().split())), sys.stdin.readlines()))

# dp[i] = 価値iを得られる最小の重さ
dp = [9999999999999999999] * (n*1000+1)
dp[0] = 0

for p in ppp:
    we = p[0]
    va = p[1]
    for i in reversed(range(len(dp))):
        if i+va >= len(dp):
            continue
        ne = i+va
        dp[ne] = min(dp[ne], dp[i]+we)

# log(dp)

for i,we in reversed(list(enumerate(dp))):
    if we <= w:
        print(i)
        exit()


Measured memory_bytes: 91228
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            :oyhhhhhhyo:    
#define next         .sdNNNmNNNNNNNmds. 
#define y0          -hNNNNy`yNNNNNN`/Nh-
#define y1          mNNNNNd+dNNNNNN+sNNm
#define yn          mNNNNNNNNy--:smNNNms
#define tm          .+oooooosyysooooo+- 
#define read               :yhy/        
#define rank              :mNmo         
#define index              ... 
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 111111;
int a[N], b[N];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    n++;
    rep(i, 1, n) {
        cin >> a[i];
    }
    rep(i, 1, n - 1) {
        cin >> b[i];
    }
    int ans = 0;
    rep(i, 1, n - 1) {
        int x = min(a[i], b[i]);
        a[i] -= x;
        b[i] -= x;
        ans += x;
        x = min(a[i + 1], b[i]);
        a[i + 1] -= x;
        b[i] -= x;
        ans += x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mp make_pair
#define ll long long
using namespace std;

int main() {
  
   int n;
   cin>>n;
   int a[n];
   int count[100005]={0};
    for(int i=0;i<n;i++) {
        cin>>a[i];
        count[a[i]]++;
    }  
    int count_pre[100005]={0};
    int count_front[100005]={0};
    for(int i=1;i<=100000;i++){
        count_pre[i]=count[i-1]+count_pre[i-1];
    }
    for(int i=100000;i>=1;i--){
        count_front[i]=count[i]+count_front[i+1];
    }
    int c=0;
    for(int i=1;i<=100000;i++){
        int x=count_front[i]-count_pre[i];
        if(x==0) {
            c++;
        }
    }
    cout<<c;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int N, A, B;
  cin >> N >> A >> B;
  cout << min(A * N, B) << endl;
  }

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

def get(x):
    y = x % 10
    if y == 0:
        return 10
    else:
        return y

A = get(a)
B = get(b)
C = get(c)
D = get(d)
E = get(e)


x = min([A, B, C, D, E]) % 10

if x == 0:
    print(10 * ((-(-a // 10) + -(-b // 10) + -(-c // 10) + -(-d // 10) + -(-e // 10))) + x)
else:
    print(10 * ((-(-a // 10) + -(-b // 10) + -(-c // 10) + -(-d // 10) + -(-e // 10))) + x - 10)    

Measured memory_bytes: 3064
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     SPEED       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());




int main()
{
	SPEED;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>m;
		// n=s.length();
		vector<pair<ll,ll> > a;
		rep(i,m)
		{
			cin>>k>>j;
			a.pb({k,j});
		}
		sort(all(a));
		ll l=a[0].ff,r=a[0].ss;
		repe(i,1,m)
		{
			if(a[i].ff>r)
			{
				cout<<"0";
				return 0;
			}
			l=max(l,a[i].ff);
			r=min(r,a[i].ss);
		}
		// debug3(l,r,i);
		cout<<r-l+1;
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 2420
import std.stdio, std.string, std.array, std.algorithm, std.conv;

void main() {
  for(int n, q; readf("%d %d\n", &n, &q);) {
    int[] arr = readln.chomp.split(" ").map!(to!int).array;
    int limit = arr.reduce!(max) + 1;
    int[] table = new int[](limit);
    foreach(i; arr) table[i] = i;
    for(int i = 1; i < limit; i++) {
      table[i] = max(table[i], table[i - 1]);
    }
    for(int i = 0; i < q; i++) {
      int query, ans = 0;
      readf("%d\n", &query);

      for(int j = query; j < limit; j += query) {
        ans = max(ans, table[j - 1] % query);
      }
      ans = max(ans, table[limit - 1] % query);
      writeln(ans);
    }
  }
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1001001001;

const int mod = 1000000007;

int main() {

    ll l, r;
    cin >> l >> r;

    r = min(r, l + (2 * 2019));

    int ans = 2018;

    for (ll i = l; i <= r; i++) {
        for (ll j = i + 1; j <= r; j++) {
            int x = i * j % 2019;
            ans = min(ans, x);
        }
    }

    cout << ans << endl;

}



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

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  rep(i, A+1) rep(j, B+1) rep(k, C+1) {
    if (500*i+100*j+50*k == X)
      ++ans;
  }
  out(ans);
  return 0;
}


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

int main(void) {
    long long int x,a,b;
    cin>>x>>a>>b;
    if(b-a>=x+1) cout<<"dangerous"<<endl;
    else if(b-a<=x) {
        if(b-a<=0) cout<<"delicious"<<endl;
        else cout<<"safe"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>      // std::setprecision
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

int main() {
  int N;

  cin >> N;
  
  vector<int> H(N);
  for(auto& i : H)cin >> i;
  
  int r = 0, rm = 0;
  
  for (auto i = N - 2; i >= 0; i--) {
    if (H[i] < H[i+1])
      r = 0;
    else
      r++;
    rm = max(r, rm);
  }

  cout << rm << endl;

  return 0;
}


Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, s, k, ans, sum, last,a[200001];
struct Edge { LL to, cost; }; 
string str,ss;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n >> m;
	ans = 1;
	if (abs(n - m) > 1) {
		cout << 0 << endl;
	}
	else {
		for (LL i = 1; i <= n;i++) {
			ans *= i;
			ans %= MOD;
		}
		for (LL i = 1; i <= m; i++) {
			ans *= i;
			ans %= MOD;
		}
		if (n == m)ans *= 2;
		ans %= MOD;
		cout << ans << endl;
	}
	return 0;
}


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

int main(){
  string input ;

  cin >> input;

  deque<char> words;
  for(int i = 0 ; i < input.size(); i++){
    if(input[i] == 'B'){
      if( !words.empty() ) words.pop_back();
    }else{
      words.push_back(input[i]);
    }
  }

  while(!words.empty()){
    cout <<  words.front() ;
    words.pop_front();
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int dat[3]; FOR(i,3) scanf("%d", dat+i);
    sort(dat, dat+3);
    puts(dat[0] + dat[1] == dat[2] ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, n;
  cin >> h >> n;
  vi a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  int dp[h + 1];
  rep(i, h + 1) dp[i] = 1e9;
  dp[0] = 0;
  rep(i, n) rep(j, h) {
    int nj = min(h, j + a[i]);
    dp[nj] = min(dp[nj], dp[j] + b[i]);
  }
  cout << dp[h] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>
#include<cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, P;
    cin >> N >> P;

    ll ans = 1;
    for (ll i = 2; i * i <= P; i++) {
        if (P % i == 0) {
            ll sub = 0;
            while (P % i == 0) {
                sub++;
                P /= i;
            }
            ans *= pow(i, sub / N);
        }
    }

    ans *= pow(P, 1 / N);

    cout << ans << endl;
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;
template <typename Int, Int MOD, int N>
struct comb_util {
	std::array<Int, N + 1> fc, ifc;

	comb_util() {
		fc[0] = 1;
		for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
		ifc[N] = inv(fc[N]);
		for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
	}

	Int fact(Int n) { return fc[n]; }

	Int inv_fact(Int n) { return ifc[n]; }

	Int inv(Int n) { return pow(n, MOD - 2); }

	Int pow(Int n, Int a) {
		Int res = 1, exp = n;
		for (; a; a /= 2) {
			if (a & 1) res = res * exp % MOD;
			exp = exp * exp % MOD;
		}
		return res;
	}

	Int perm(Int n, Int r) {
		if (r < 0 || n < r)
			return 0;
		else
			return fc[n] * ifc[n - r] % MOD;
	}

	Int binom(Int n, Int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
	}

	Int homo(Int n, Int r) {
		if (n < 0 || r < 0) return 0;
		return r == 0 ? 1 : binom(n + r - 1, r);
	}
};

using comb = comb_util<long long, 1000000007, 3000000>;
comb cb;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S;
	cin >> S;
	int M = S.size();
	int res = 0;
	N = N + M;
	for (int i = M; i <= N; i++) {
		int ans = cb.binom(i - 1, M - 1);
		ans = (ans * cb.pow(25, i - M)) % MOD;
		ans = (ans * cb.pow(26, N - i)) % MOD;
		res = (res + ans) % MOD;
	}

	cout << res << endl;
}

Measured memory_bytes: 51136
# マップでカウントしておく
# 頭文字の組み合わせそれぞれに対して頭文字それぞれの数を掛ける
# なので組み合わせさえ出せれば解ける
# （なんかしらんけど1TLE出した（原因不明）ので一部書き直した）

n = gets.chomp.to_i
@table = {"M"=>0, "A"=>0, "R"=>0, "C"=>0, "H"=>0}

n.times do
  name = gets.chomp
  if @table.has_key?(name[0])
    @table[name[0]]+=1
  end
end

@march = []

def perm(i, current_arr, source_arr, limit, length)
  return  if length < limit
  if current_arr.size == limit
    @march << current_arr
  else
    i.upto(length) do |j|
      next if i==j
      perm(j, current_arr.clone<<source_arr[j-1], source_arr, limit, length)
    end
  end
end

perm(0, [], ["M", "A", "R", "C", "H"], 3, 5)

ans = 0
@march.each do |march|
  a, b, c = march
  ans += @table[a]*@table[b]*@table[c]
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
	
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
	
#define MOD 1000000007
#define mini 18446744073709551615
#define ff first
#define ss second
#define pb push_back
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--)
	{
		int n,c=0,f=0;
		cin>>n;
		int d,e;
		for(int i=0;i<n;i++)
		{
			cin>>d>>e;
			if(d==e)
				c++;
			else
				c=0;
			if(c==3)
				f=1; 
		}
		if(f)
			cout<<"Yes";
		else
			cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3688