akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp make_pair
#define pb push_back
#define mes(a,b) memset(a,b,sizeof(a))
#define mes0(a) memset(a,0,sizeof(a))
#define lson l,mid,pos<<1
#define rson mid+1,r,pos<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define sss(a) a::iterator
#define all(a) a.begin(),a.end()

using namespace std;

typedef double DB;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<long long ,int> pli;
typedef pair<int,long long > pil;
typedef pair<string,int> psi;
typedef pair<long long ,long long > pll;

const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const int maxn = 100000+10;
const int mod = 1e9+7;
map<int,int> mpp;
vector <int> s;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int T;
    int a;
    scanf("%d",&T);
    for (int cas=1;cas<=T;cas++){
        scanf("%d",&a);
        mpp[a]++;
        if (mpp[a]%2==0)s.push_back(a);
    }
    sort (all(s));
    if (s.size()>=2){
        int a1=s.back();
        s.pop_back();
        int a2=s.back();
        printf("%lld\n",1LL*a1*a2);
    }else puts("0");
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        cout<<s[i];
        if(i==3)
            cout<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
"""
全探索１　O(n^3)
while 1:
    a = []
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for i in range(n)]
    max = 0
    for i in range(n):
        for j in range(i, n):
            sum = 0
            for k in range(i, j+1):
                sum += a[k]
            if max < sum:
                max = sum
    print(max)
"""
while 1:
    a = []
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for i in range(n)]
    max = -111111111111111
    for i in range(n):
        sum = 0
        for j in range(i, n):
            sum += a[j]
            if sum > max:
                max = sum

    print(max)



Measured memory_bytes: 5648
from collections import defaultdict
if __name__ == "__main__":
    dic = defaultdict(int)
    N = int(input())
    for i in range(N):
        S = input()
        if S[0] in "M A R C H":
            dic[S[0]] += 1
    res = []
    if len(dic) < 3:
        print(0)
        exit(0)
    value = 1
    for key in dic:
        val = dic[key]
        res.append(val)
        value *= val
    if len(dic) == 3:
        print(value)
        exit(0)
    result = 0
    if len(dic) == 4:
        for i in res:
            result += value // i
    if len(dic) == 5:
        for i in range(len(res)):
            for j in range(i + 1, len(res)):
                result += value // (res[i] * res[j])
    print(result)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#include<functional>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 11234567890123456789
using namespace std;

struct NODE{
	ll dist;
	ll number;
	bool done;
	vl edges_to;
	vl edges_cost;
	bool operator<= (const NODE &temp) const { return this->dist >= temp.dist; }
	bool operator>= (const NODE &temp) const { return this->dist <= temp.dist; }
	bool operator< (const NODE &temp) const { return this->dist > temp.dist; }
	bool operator> (const NODE& temp) const { return this->dist < temp.dist; }
};

void dijkstra(vector<NODE> &nodes, ll start){
	priority_queue<NODE> q;
	vb contains_flag(nodes.size(),false);
	nodes[start].dist = 0;
	q.push(nodes[start]);
	contains_flag[start] = true;
	while (!q.empty()){
		NODE temp_v = q.top();
		q.pop();
		contains_flag[temp_v.number] = false;
		//cout << "temp_v.number="<<temp_v.number << endl;
		temp_v.done = true;
		rep(i, temp_v.edges_to.size()){
			ll to = temp_v.edges_to[i];
			ll cost = temp_v.edges_cost[i] + temp_v.dist;
			if (nodes[to].dist < 0 || cost < nodes[to].dist){
				nodes[to].dist = cost;
				if (!contains_flag[to]){
					q.push(nodes[to]);
					//cout << "push_" << to << endl;
					contains_flag[to] = true;
				}
			}
		}
	}
}

int main(){
	ll n; cin >> n;
	vector<NODE> nodes(n);
	nodes[0].dist = -1;
	nodes[0].done = false;
	nodes[0].number = 0;
	rep(i, n-1){
		ll a, b, c;
		cin >> a >> b >> c;
		nodes[a-1].edges_to.push_back(b-1);
		nodes[a-1].edges_cost.push_back(c);
		nodes[b - 1].edges_to.push_back(a - 1);
		nodes[b - 1].edges_cost.push_back(c);
		nodes[i + 1].number = i + 1;
		nodes[i + 1].dist = -1;
		nodes[i + 1].done = false;
	}
	/*
	rep(i, n){
		cout << i << "番目" << endl;
		cout << "number=" << nodes[i].number << endl;
		cout << "next_edges_size=" << nodes[i].edges_to.size() << endl;;
		for (ll j : nodes[i].edges_to) cout << " " << j;
		cout << endl;
		for (ll cost : nodes[i].edges_cost) cout << " " << cost;
		cout << endl;
	}
	*/
	ll q, k; cin >> q >> k;
	k--;
	dijkstra(nodes, k);
	rep(i, q){
		ll x, y; cin >> x >> y;
		x--; y--;
		//cout << x << " to " << k << " =" << dijkstra(nodes, x, k) << endl;
		//cout << k << " to " << y << " =" << dijkstra(nodes, k, y) << endl;
		//cout << "ans=" << ans << endl;
		cout << nodes[x].dist+nodes[y].dist << endl;
	}
	return 0;
}

Measured memory_bytes: 31932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false);
	ll x, y;
	ll ans;
	cin>>x>>y;
	if(x%y==0){
		cout<<"-1";
	}
	else{
		cout<<x;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <cmath>
using namespace std;
using ll = long long;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)


int h,w;
int pat[51][51];
bool map[51][51];

void rec(int i,int j){//i:y,j:x
    
    if(i < 0 || j < 0 || i > h || j > w) return ;
    if(!map[i][j]) return ;

    if(i > 0){
        if(map[i-1][j]){
            if(pat[i-1][j] > pat[i][j]+1){
                pat[i-1][j] = min(pat[i-1][j],pat[i][j]+1);
                rec(i-1,j);
            }
        }
    }
    if(i < h-1 && map[i+1][j]){
        if(pat[i+1][j] > pat[i][j]+1){
            pat[i+1][j] = min(pat[i+1][j],pat[i][j]+1);
            rec(i+1,j);
        }
    }
    if(j > 0){
        if(map[i][j-1]){
            if(pat[i][j-1] > pat[i][j]+1){
                pat[i][j-1] = min(pat[i][j-1],pat[i][j]+1);
                rec(i,j-1);
            }
        }
    }
    if(j < w-1 && map[i][j+1]){
        if(pat[i][j+1] > pat[i][j]+1){
            pat[i][j+1] = min(pat[i][j+1],pat[i][j]+1);
            rec(i,j+1);
        }
    }
}

int main(){
    const int INF = 1e4;
    cin >> h >> w;
    vector<string> lines;
    lines.resize(h);
    
    int b_cnt=0;
    rep(i,51){
        rep(j,51){
            pat[i][j] = INF;//y,x
            map[i][j] = true;
        }
    }


    rep(i,h){
        cin >> lines[i];
    }

    rep(i,h){
        rep(j,w){
            if(lines[i][j] == '#'){ 
                b_cnt++;
                map[i][j] = false;
            }
        }
    }

    pat[0][0] = 1;
    rec(0,0);
    
    int ans = 0;
    if(pat[h-1][w-1] == INF)ans = -1;
    else{
        ans = w*h - b_cnt - pat[h-1][w-1];
    } 
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
//File Name: arc074_A.cpp
  //Created Time: 2017年06月13日 星期二 14时56分12秒
                                   
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int INF = 0x3f3f3f3f;
int cal(int h,int w){
	if(h % 2 == 0) return h / 2;
	else{
		int x = ((LL)w * h - w - h + 2 * h - 2) / (2 * h - 1);
		return (LL)h * x - (LL)(w - x) * (h - 1) / 2;
	}
}
int main(){
	int h,w,ans;
	cin >> h >> w;
	if(h % 3 == 0 || w % 3 == 0)
		ans = 0;
	else{
		ans = min(h,w);
		ans = min(ans,cal(h,w));
		ans = min(ans,cal(w,h));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split(" ")))
i=0
a=0
b=0

while len(l)!=0:
    if i%2==0:
        a+=max(l)
        l.remove(max(l))
    else:
        b+=max(l)
        l.remove(max(l))
    i+=1
print(a-b)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint d,n;std::cin>>d>>n;
    if(n==100)n++;
    while(d--)n*=100;
    std::cout<<n<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 10007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int a = 0;
    for(int i = 0; i < 4; i++) {
        if(s[i] == '2') {
            a++;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
h,w,k=map(int,input().split())
def split(word): 
    return [char for char in word]  
      
m=[]
for i in range(h):
  m.append(input())
t=[0]*(h-1)
ans=w-1+h-1
for i in range(2**(h-1)):
  failflag=0
  s=split("{0:b}".format(i))
  s.reverse()
  for j in range(h-1-len(s)):
    s.append('0')
  s.reverse()
  a=[]
  a.append([])
  for j in range(w):
    a[0].append(int(m[0][j]))
  for j in range(1,h):
    if s[j-1]=='0':
      for l in range(w):
        a[-1][l]+=int(m[j][l])
    else:
      a.append([])
      for l in range(w):
        a[-1].append(int(m[j][l]))
  n=len(a)
  tmp=0
  p=[0]*n
  flag=0
  for j in range(w):
    for l in range(n):
      if a[l][j]>k:
        failflag=1
      if p[l]+a[l][j]>k:
        flag=1
        break
    if flag==1:
      tmp+=1
      flag=0
      for t in range(n):
        p[t]=0
    for l in range(n):
      p[l]+=a[l][j]
  if failflag==0 and n-1+tmp<ans:
    ans=n-1+tmp
print(ans)

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

int main(){
    int n,m;cin>>n>>m;
    int lmax=0, rmin=n;
    int l,r;
    rep(i,m){
        cin >> l >> r;
        lmax = max(lmax, l);
        rmin = min(rmin, r);
    }
    
    cout << max(rmin-lmax+1, 0) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=20000+10;
const int inf=1e9;
int p[N];
long long a[N],b[N],ans1[N],ans2[N];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++) scanf("%d",&p[i]);
        long long cc=(inf-1)/2+1;
        a[1]=1;b[1]=cc;
        for(int i=2;i<=n;i++)
        {
            a[i]=a[i-1]+2;
            b[i]=b[i-1]-1;
        }
        for(int i=1;i<=n;i++)
        {
            ans1[p[i]]=a[i];
            ans2[p[i]]=b[i];
        }
        long long sum,tmp;
        sum=ans1[1]+ans2[1];
        ans1[1]=1;ans2[1]=sum-1;
        for(int i=2;i<=n;i++)
        {
            sum=ans1[i]+ans2[i];
            tmp=ans1[i-1]+1;
            while(tmp<sum)
            {
                if(sum-tmp==1&&i==n) break;
                if(sum-tmp<ans2[i-1]) break;
                tmp++;
            }
            ans1[i]=tmp;
            ans2[i]=sum-tmp;
        }
        for(int i=1;i<=n;i++)
        {
            if(i-1) printf(" ");
            printf("%lld",ans1[i]);
        }
        printf("\n");
        for(int i=1;i<=n;i++)
        {
            if(i-1) printf(" ");
            printf("%lld",ans2[i]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <limits.h>

int min = INT_MAX;
int x;

void Solve(int cx,int t);
int main(int argc, char const *argv[])
{

	int cx = 0;
	scanf("%d",&x);
	min = x;
	//Solve(0,0);
	//printf("%d\n",min );
	int i;
	for(i=0;i<=x;i++){
		if((i*(i+1))/2 >= x){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}
/*void Solve(int cx,int t){
	if(t > min){
		return;
	}
	else if(cx == x){
		if(t < min){
			min = t;
		}
		return;
	}
	else{
		Solve(cx,t+1);
		Solve(cx+(t+1),t+1);
		// Solve(cx-(t+1),t+1);
	}
}*/

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = s[i] + A[i]
	}
	sum := s[N]
	d := sum
	for i := 1; i <= N-1; i++ {
		d = Min(d, Abs(sum-2*s[i]))
	}
	fmt.Println(d)
}

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 7604
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator, fractions
from bisect import *

N, x = map(int, input().split())
X = [int(x) for x in input().split()]

def f():
    X.sort()
    L = len(X)
    if L == 1:
        return abs(X[0] - x)
    
    i = bisect_left(X, x)
    
    d = [t - u for t,u in zip(X[1:], X[:-1])]
    s = None
    if i == 0:
        s = set(d)
        s.add(x[0] - x)
    elif i == len(X):
        s = set(d)
        s.add(x - X[-1])
    else:
        s = set(d[:i - 1])
        s.update(d[i+1:])
        s.update({x - X[i-1], X[i] - x})
    return reduce(fractions.gcd, s)

print(f())

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

int main(){

    string s; cin >> s;
    int m = (int)s.size();
    int n; cin >> n;

    int ans = 0;
    for(int i = 0; i < n; i++){
        string t; cin >> t;
        t = t + t + t;

        for(int j = 0; j < (int)t.size(); j++){

            bool ok = true;
            for(int k = 0; k < m; k++){
                if(s[k] != t[j + k]){
                    ok = false;
                    break;
                }
            }

            if(ok){
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3240
import java.util.Scanner;
   
public class Main{
    public void solve(){
        Scanner sc=new Scanner(System.in);
           
        int n=sc.nextInt();
           
        for(int i=0;i<n;i++){
            int x=sc.nextInt();
            int y=sc.nextInt();
            int b=sc.nextInt();
            int p=sc.nextInt();
               
            int kin=x*b+y*p;
               
            if(b>=5 && p>=2){
                kin = (x*b + y*p)*4/5;
            }else{
                if(b<5){
                b=5;
                }
                if(p<2){
                p=2;
                }
                int wari = (x*b + y*p)*4/5;
                   
                if(kin>wari){
                    kin = wari;
                }
            }
            System.out.println(kin);
        }
    }
       
    public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
}
}

Measured memory_bytes: 23292
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    vector<char> a{s[0]};
    int ans = 0;
    for(int i = 1; i < s.size(); i++){
        if(a.back() == s[i]){
            if(s[i] == '0'){ 
                s[i] = '1';
            }else {
                s[i] = '0';
            }
            ans += 1;
            a.push_back(s[i]);
        } else{
            a.push_back(s[i]);
        }
    }
    cout << ans;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll f[MX];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    f[0] = 1;
    FOR(i,1,MX) f[i] = (f[i-1]*i*1LL)%MOD;

    int N, M; cin >> N >> M;

    if (abs(N-M) > 1) {
        cout << "0\n";
    } else if (abs(N-M) == 1) {
        cout << (f[N]*f[M]*1LL)%MOD;
    } else {
        cout << (((f[N]*f[M]*1LL)%MOD)*2LL)%MOD << "\n";
    }

}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		long mod=1000000007L;
		int n=sc.nextInt();
		boolean g=false;
		if(n%2==0){n++;g=true;}
		int a[]=new int[n];
		for (int i = 0; i < n; i++) {
			if(g&&i==n-1){a[n-1]=0;break;}
			a[i]=sc.nextInt();
		}
		if(g){
			for (int i = 0; i < n-1; i++) {
				a[i]++;
			}
		}
		
			int b[]=new int[n/2+1];
			for (int i = 0; i < n; i++) {
				if(a[i]%2==1){System.out.println(0);return;}
				b[a[i]/2]++;
			}
			boolean ok=true;
			for (int i = 0; i < b.length; i++) {
				if(i==0&&b[i]!=1)ok=false;
				else if(i!=0&&b[i]!=2)ok=false;
			}
			if(ok){
				long ans=1;
				for (int i = 0; i < n/2; i++) {
					ans=(ans*2)%mod;
				}
				System.out.println(ans);
			}
			else System.out.println(0);
			
			
			
		
		}
		
	}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int gcd(int a,int b){
    int r=a%b; 
    while(r!=0){ 
      a=b; 
      b=r; 
      r=a%b; 
    }
    return b;
}
int main(){
  int n;cin>>n;
  int ans=0;
  for(int i=1;i<=n;i+=2){
    int cnt=0;
    for(int j=1;j<=i;j++){
      if(gcd(i,j)==j)cnt++;
    }
    if(cnt==8)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
s=list(input())

former=int("".join(s[0:2]))
latter=int("".join(s[2:4]))

if (0 < former <13) :
  if 0<latter<13:
    print("AMBIGUOUS")
  else:
    print("MMYY")
elif (0 < latter <13) :
  print("YYMM")
else:
  print("NA")



Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll h,w;
    cin>>h>>w;
    ll ans = 0;
    ll add = (w+1)/2;
    ll b; 
    if(h==1||w==1){cout<<1<<endl;return 0;}
    if(w%2==0)b = add;
    else b = add-1;
    ans = (h/2)*(add+b) + h%2 *add;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def checker(i,s):
  if s[i] > s[i+1] and s[i+1] > s[i+2]:
    return True
  elif s[i] < s[i+1] and s[i+1] < s[i+2]:
    return True
  return False

n = int(input())
s = [int(i) for i in input().split()]
res = 0

for i in range(n-2):
  if checker(i,s):
    res += 1
print(res)
  
  

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(num,init,name) vector<int> name((num),(init));
#define op(i) cout<<(i)<<endl;

int main(){
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(&a[0],&a[3]);
    int ans=(a[2]-a[1]);
    if((a[1]-a[0])%2){
        ans+=(a[1]-a[0])/2+2;
    }else ans+=(a[1]-a[0])/2;
    op(ans);
    return 0;

}

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

ll n,m,a[100009],sum;

ll f(ll x){
    ll num=0,y=n-1;
    rep(i,n){
        while(y>=0&&a[i]+a[y]>=x){
            sum+=a[y]*(n-i);
            y--;
        }
        sum+=(n-y-1)*a[i];
        num+=n-y-1;
    }
    return num;
}

int main(){
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    ll l=0,r=1e18,mid;
    while(l+1<r){
        mid=(l+r)/2;
        if(f(mid)<=m)r=mid;
        else l=mid;
    }
    sum=0ll;
    cout<<l*(m-f(mid))+sum<<endl;
    //assert(m-f(r)==0ll);
    //cout<<m-f(r)<<" "<<l<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
	char a, b, c, d;
	cin >> a >> b >> c >> d;
	if(a==b||b==c|c==d) cout << "Bad" << endl;
	else cout << "Good" << endl;
	return 0;
}


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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int a = in.nextInt() - 1;
        int b = in.nextInt() - 1;
        System.out.println((b + a - 1) / a);


	}
}
	

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  long long n, a, b, x, y;
  cin >> n>>a>>b;
 
  x = n /(a+b);
  y = n-x*(a+b);
  
  if(y>=a) y = a;
  
  else y  = y;
    
  cout<<x*a+y<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        int s = Integer.parseInt(sc.next());
        int cnt=0;
        for(int x=0;x<=k;x++){
            for(int y=0;y<=k;y++){
                int z = s-(x+y);
                if(z>=0 && z<=k){cnt++;}
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    int a[n],colours[8]={0},monster=0,ans=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]<400){
            colours[0]=1;
        }else if(a[i]<800){
            colours[1]=1;
        }else if(a[i]<1200){
            colours[2]=1;
        }else if(a[i]<1600){
            colours[3]=1;
        }else if(a[i]<2000){
            colours[4]=1;
        }else if(a[i]<2400){
            colours[5]=1;
        }else if(a[i]<2800){
            colours[6]=1;   
        }else if(a[i]<3200){
            colours[7]=1;
        }else{
            monster++;
        }
        }
        for(int i=0;i<8;i++)ans+=colours[i];
        printf("%d %d",ans>0?ans:1,ans+monster);
    return 0;
}


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

int main()
{
  int x, y, z, bills, total;
  cin >> bills >> total;
  bool found = false;
  for (int x = 0; x <= bills; ++x)
  {
    for (int y = 0; y <= bills - x; ++y)
    {
      if (total == (10000 * x) + (5000 * y) + 1000 * (bills - x - y))
      {
        cout << x << " " << y << " " << bills - x - y << endl;
        found = true;
        break;
      }
    }
    if (found) break;
  }
  if (!found) cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
for i in range(len(s)-1):
	if s[i]==s[i+1]:
		print(i+1,i+2)
		exit()
for i in range(len(s)-2):
	if s[i]==s[i+2]:
		print(i+1,i+3)
		exit()
print(-1,-1)

Measured memory_bytes: 3188
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#include<cstdio>

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if ((A + B) > (C + D)) {
		cout << "Left" << endl;
	}
	else if ((A + B) < (C + D)) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long ll;
const int N = 1e6+9, M = 1e2+9, OO = 0x3f3f3f3f,MOD = 1e9 + 7;
ll prexor[N],csum[N];
int main()
{
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;++i)
  {
    int x;
    scanf("%d",&x);
    prexor[i]=prexor[i-1]^x;
    csum[i]=csum[i-1]+x;
  }
  int r=1;
  ll ans=0;
  for(int l=1;l<=n;++l)
  {
    
    while(r<=n && (csum[r]-csum[l-1] == (prexor[r]^prexor[l-1]))) r++;
    ans+=(r-l);
  }
  printf("%lld\n",ans);
  #ifdef _LOCAL_DEFINE  
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}



Measured memory_bytes: 5888
import java.util.Scanner;
import java.util.Arrays;

public class Main{ public static void main(String...args){
        Scanner sc = new Scanner(System.in); int K = sc.nextInt(); int N = sc.nextInt();
        int[] A = new int[N]; int[] B = new int[N];
        for(int i=0;i <N;i++) A[i]=sc.nextInt();
        Arrays.sort(A);
        for(int i=0;i<N-1;i++) B[i]=A[i+1]-A[i];
        B[N-1] = A[0]+K-A[N-1];
        int maximum = B[0];
        for(int i=0;i<B.length;i++){ if(maximum<B[i]) maximum = B[i];}
        int sol = K-maximum;
        System.out.print(sol);
    }
}

Measured memory_bytes: 85128
#include "algorithm"
#include "iomanip"
#include "iostream"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

int main() {
	V<ll> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll k;
	cin >> k;
	cout << a[k-1] << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
  string s;
  cin>>s;
  int wins = 0;
  for (int i = 0; i < s.size(); i++) if (s[i] == 'o') wins++;
  if (wins + 15 - s.size() >= 8) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = []
ten = 0

for i in range(N):
    s = int(input())
    if s % 10 == 0:
        ten += 1
    S.append(s)

S.sort()
ans = sum(S)

if ten == N:
    ans = 0
    print(ans)
    exit()

if ans % 10 == 0:
    for i in range(N):
        if S[i] % 10 != 0:
            ans -= S[i]
            break


print(ans)


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

const int maxn = 100000 + 5;
int N;
int mem[maxn];

bool solve()
{
	int cnt = 0;
	for(int i = 0; i < N; i++)
	{
		if(i > 0 && mem[i] >= mem[i-1]) cnt++;
		if(i > 0 && mem[i] > mem[i-1])
		{
			mem[i] -= 1;
		}
	}
	if(cnt == N-1) return true;
	else return false;
}

int main()
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> mem[i];
	if(solve()) printf("Yes\n");
	else printf("No\n"); 
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N;cin>>N;
    int ans=1;
    for(int i=1;i<=N;i++){
        ans*=i;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
"""
問題文
    N段の階段があります。高橋君は現在、上り口(0段目)にいます。 高橋君は一歩で1段か2段上ることができます。
    ただし、a1,a2,a3,....aM段目の床は壊れており、その段に足を踏み入れることは危険です。
    壊れている床を踏まないようにしながら、最上段(N段目)にたどりつくまでの移動方法は何通りあるでしょうか？ 
    総数を1,000,000,007で割った余りを求めてください。

制約
    1≦N≦10^5
    0≦M≦N−1
    1≦a1<a2< ... <aM≦N−1
"""
#入力の受け取り
N, M = map(int, input().split())
hoal = [int(input()) for i in range(M)]

#listの初期化
dp = list()
dp = [0]*N

    
dp_check = list()
dp_check = [0]*N

for i in range(M):
    dp_check[hoal[i]-1]=1
    if dp_check[hoal[i]-1]==1 and dp_check[hoal[i]-2]==1:
        print("0")
        exit()

if N==1:
    if M==1:
        dp[0]=0
    else:
        dp[0]=1
    print(dp[N-1])
else:
    if dp_check[0]==1:
        dp[0]=0
        dp[1]=1
    elif dp_check[1]==1:
        dp[0]=1
        dp[1]=0
    else:
        dp[0] = 1
        dp[1] = 2
    #実際に求める
    #dp[i]<-i段までの移動方法の和
    for i in range(N):
        if i>1 and dp_check[i]==0:
            dp[i]=dp[i-1]+dp[i-2]

        dp[i]=dp[i]%1000000007

    print(dp[N-1])
    

Measured memory_bytes: 8616
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define EPS (1e-20)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 1000010

int used[MAX];

signed main(){
	cout<<fixed<<setprecision(7);
	
	int s, a;
	
	cin>>s;
	
	a = s;
	
	for(int i = 1;; i++){
		used[a] = true;
		if(a%2){
			a = a*3 + 1;
		} else {
			a /= 2;
		}
		if(used[a]){
			cout<<i+1<<endl;
			return 0;
		}
		// cout<<i<<" "<<a<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main()  {
	var n int
	fmt.Scan(&n)
	a := make(pairs, n)
	for i := range a {
		fmt.Scan(&a[i].val)
		a[i].idx = i
	}
	sort.Sort(a)

	for i := range a {
		for j:=n-1;j>=0;j-- {
			if (i != a[j].idx) {
				fmt.Println(a[j].val)
				break
			}
		}
	}
}

type pair struct {
	idx int
	val int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}

func (p pairs) Less(i, j int) bool {
	return p[j].val > p[i].val
}

func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}




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

int main(){
  int n, m;
  cin >> n >> m;
  int v[n];
  int w[n];
  for(int i = 0; i < n; i++){
    scanf("%d %d", &v[i], &w[i]);
  }
  int dp[110][10010];
  memset(dp, 0, sizeof(dp));
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= 10000; j++){
      if(j < w[i]){
        dp[i + 1][j] = dp[i][j];
      }else{
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }
  cout << dp[n][m] << endl;
}

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

int main()
{
    int W, H, N;
    cin >> W >> H >> N;

    int x_min = 0, x_max = W, y_min = 0, y_max = H;
    int x, y, a;
    for (int i = 0; i < N; i++)
    {
        cin >> x >> y >> a;

        if (a == 1)
        {
            x_min = max(x, x_min);
        }
        else if(a == 2)
        {
            x_max = min(x, x_max);
        }
        else if (a==3)
        {
            y_min = max(y, y_min);
        }
        else
        {
            y_max = min(y, y_max);
        }
    }

    if ((x_max - x_min >= 0) && (y_max - y_min) >= 0)
        cout << (x_max - x_min) * (y_max - y_min) << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n,k,len,ans=0;
    cin >> n >> k;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector<int>b(a);
    b.erase(unique(b.begin(),b.end()),b.end());
    len=b.size()-k;
    for(int i=0;i<b.size();i++){
        b[i]=upper_bound(a.begin(),a.end(),b[i])-lower_bound(a.begin(),a.end(),b[i]);
    }
    sort(b.begin(),b.end());
    for(int i=0;i<len;i++){
        ans+=b[i];
    }
    cout << ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
int main()
{
    ll n,p,q=0,r,i,s=0,u,v,b;
    cin>>n;
    ll a[n],c[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
   for(i=0;i<n;i++)
   {
       c[i]=a[i]-(i+1);
   }
   sort(c,c+n);
   b=c[(n-1)/2];
   if(n%2==0)
   {
       b=c[(n-1)/2]+c[(n+1)/2];
       b=b/2;
   }
    for(i=0;i<n;i++)
    {
        s=s+abs(a[i]-(b+i+1));
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  string s; cin >> s;
  int ans = 0;
  for(int i = 0; i < s.length(); i++){
    int j;
    for(j = i; j < s.length(); j++){
      if(s[j] == 'A' || s[j] == 'T' || s[j] == 'C' || s[j] == 'G');
      else break;
    }
    ans = max(j - i, ans);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    const ll MOD = 1e9 + 7;
    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    sort(A.begin(), A.end());

    bool ok = true;
    if (N%2==1) {
        if (A[0] != 0) ok = false;
        for(int i=1; i<N; i+=2) {
            if (A[i]%2==0 && A[i]!=A[i + 1]) ok = false;
        }
    } else {
        for(int i=0; i<N; i+=2) {
            if (A[i]%2==1 && A[i]!=A[i + 1]) ok = false;
        }
    }
    if (!ok) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    if (N%2==1) {
        for(int i=1; i<N; i+=2) {
            ans *= 2;
            ans %= MOD;
        }
    } else {
        for(int i=0; i<N; i+=2) {
            ans *= 2;
            ans %= MOD;
        }
    }

    cout <<  ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,c;
    cin >> n >> c;
    int d[33][33];
    int C[505][505];
    for (int i = 0; i < c; i++)
    {
        for (int j = 0; j < c;j++){
            cin >> d[i][j];
        }
    }
    for (int i = 0; i < 505;i++){
        for (int j = 0; j < 505;j++){
            C[i][j] = 0;
        }
    }
    int cost[3][35];
    //cost[i][j]:mod3でiの集合について、それを色jに変えた時のコスト
    for (int i = 0; i < 3;i++){
        for (int j = 0; j < 35;j++){
            cost[i][j] = 0;
        }
    }
    for (int i = 0; i < n;i++){
        for (int j = 0; j < n;j++){
            int x;
            cin>>x;
            x--;
            for (int k = 0; k < c; k++){
                cost[(i + j) % 3][k] += d[x][k];
            }
        }
    }
    int res = inf;
    for(int i=0;i<c;i++){
        for (int j = 0; j < c;j++){
            for (int k = 0; k < c;k++){
                if(i==j||j==k||k==i)
                    continue;
                res = min(res, cost[0][i] + cost[1][j] + cost[2][k]);
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main{

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=sc.nextInt(),a[]=new int [n];
		int sum=0;
		for(int i=0;i<n;i++)
			sum+=a[i]=sc.nextInt();
		Arrays.sort(a);
		int x=sum-a[n-1];
		out.println(a[n-1]<x?"Yes":"No");
		out.close();

	}
	
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 24660
class abc_158:
    
    def __init__(self):
        pass
    
    def A(self):
        S=input()
        if "BA" in S or "AB" in S:print("Yes")
        else:print("No")
    
    def B(self):
        NAB=list(map(int,input().split()))
        tail = NAB[0]%(NAB[1]+NAB[2]) if NAB[0]%(NAB[1]+NAB[2])<NAB[1] else NAB[1]
        ans=((NAB[0]/(NAB[1]+NAB[2]))*NAB[1])+tail
        print(int(ans))
            
    def C(self):
        AB=list(map(int,input().split()))
        ans=-1
        
        #A<B<100
        for i in range(1,101):
            if AB[0]==int(i*0.08) and AB[1]==int(i*0.1):
                ans=i
                break
            else:continue
        print(ans)
            
    def D(self):
        pass
        
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_158()
    obj.A()

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

int main() {
  int n, minv, maxv;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    v.push_back(k);
  }
  minv = v[0];
  maxv = v[1] - v[0];
  for (int i = 1; i < v.size(); i++) {
    maxv = max(maxv, v[i] - minv);
    minv = min(minv, v[i]);
  }
  cout << maxv << endl;

  return 0;
}



Measured memory_bytes: 3856
def fun(N,V):
    cnt = 0

    for i in range(5):
        cnt += V // (5-i)
        V = V % (5-i)
        if V == 0:
            break

    if cnt<=N and V==0:
        flag = False
        print(1)
    else:
        flag = True
    
    return flag

def main():
    X = int(input())

    flag = True
    N = X//100
    V = X-N*100

    while flag:
        if N >= V/5:
            flag = fun(N,V)
            N -= 1
            V += 100
        else:
            flag = False
            print(0)

if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>
using ll = long long;
using namespace std;


int main() {
    int N;
    int sum = 0;
    cin >> N;

    vector<int> A(N, 0);
    vector<int> B(N-1, 0);

    for(int i = 0; i < N-1; i++){
        cin >> B[i];
    }

    for(int i = 0; i < N; i++){
        if(i == 0){
            A[0] = B[0];
        }else if(i == N-1){
            A[N-1] = B[N-2];
        }else{
            A[i] = min(B[i], B[i-1]);
        }
    }

    for(int i = 0; i < N; i++){
        sum += A[i];
    }
    cout << sum << endl;

    return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = x[0];
            int M = x[1];
            int[] arr = new int[M * 2];

            int[] y = new int[2];

            for (int i = 0; i < M; i++)
            {
                y = Console.ReadLine().Split().Select(int.Parse).ToArray();
                arr[2 * i] = y[0];
                arr[2 * i + 1] = y[1];
            }

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(arr.Count(w=> w == i+1));
            }
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
//    String s=sc.next();
    int x=sc.nextInt();
    int a=sc.nextInt();
    int b=sc.nextInt();
    System.out.println(x-a-(x-a)/b*b);
  }
}

Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>

#include <vector>

#include <algorithm>
#include <numeric>

using namespace std;

#define repeat(n) for(int _ = 1; _ <= n; _++)

int n;
long long k;
int a[45];

long long f(int i, bool flag)
{
	static long long memo[45][2];
	
	if(i == -1)
		return 0;
	
	if(memo[i][flag])
		return memo[i][flag];
	
	if(flag && (k & (1ll<<i)) == 0)
		return memo[i][flag] = (1ll<<i) * a[i] + f(i-1, true);
	else
		return memo[i][flag] = max((1ll<<i) * a[i] + f(i-1, false), (1ll<<i) * (n - a[i]) + f(i-1, flag));
}

int main()
{
	ios::sync_with_stdio(false);
#ifdef CAI_WEI_HAN
	freopen("test.in", "r", stdin);
#endif
	
	cin >> n >> k;
	
	for(int i = 1; i <= n; i++) {
		long long x;
		cin >> x;
		
		for(int j = 0; j <= 40; j++)
			if(x & (1ll<<j))
				a[j]++;
	}
	
	cout << f(40, true);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int L, D;
	static char[][] str = new char[3][];
	static int[][] count;

	public static void main(String[] args) {
		while (true) {
			L = sc.nextInt();
			D = sc.nextInt();
			if (L == 0) break;
			for (int i = 0; i < 3; ++i) {
				str[i] = sc.next().toCharArray();
			}
			String ans = solve();
			System.out.println(ans == null ? "-1" : ans);
		}
	}

	static String solve() {
		count = new int[L + 1][5];
		char[] ret = new char[L];
		for (int i = 0; i < L; ++i) {
			if (str[0][i] == str[1][i] && str[0][i] == str[2][i]) {
				count[i][4]++;
			} else if (str[1][i] == str[2][i]) {
				count[i][0]++;
			} else if (str[0][i] == str[2][i]) {
				count[i][1]++;
			} else if (str[0][i] == str[1][i]) {
				count[i][2]++;
			} else {
				count[i][3]++;
			}
		}
		for (int i = L - 2; i >= 0; --i) {
			for (int j = 0; j < 5; ++j) {
				count[i][j] += count[i + 1][j];
			}
		}
		int[] rem = { D, D, D };
		for (int i = 0; i < L; ++i) {
			char[] cand = { 'A', str[0][i], str[1][i], str[2][i] };
			Arrays.sort(cand);
			boolean ok = false;
			for (char ch : cand) {
				for (int j = 0; j < 3; ++j) {
					if (str[j][i] != ch) rem[j]--;
				}
				if (ok(rem, i + 1)) {
					ok = true;
					ret[i] = ch;
					break;
				}
				for (int j = 0; j < 3; ++j) {
					if (str[j][i] != ch) rem[j]++;
				}
			}
			if (!ok) return null;
		}
		return String.valueOf(ret);
	}

	static boolean ok(int[] rem, int pos) {
		int[] num = new int[3];
		for (int i = 0; i < 3; ++i) {
			if (rem[i] < 0) return false;
			if (rem[i] < count[pos][i]) {
				num[i] += rem[i];
				for (int j = 0; j < 3; ++j) {
					if (j != i) num[j] += count[pos][i] - rem[i];
				}
			} else {
				num[i] += count[pos][i];
			}
		}
		for (int i = 0; i < 3; ++i) {
			if (num[i] > rem[i]) return false;
			num[i] = rem[i] - num[i];
		}
		Arrays.sort(num);
		int use = num[1] - num[0];
		num[1] -= use;
		num[2] -= use;
		if (num[0] + num[1] < num[2]) {
			use += num[0] + num[1];
		} else {
			use += (num[0] + num[1] + num[2]) / 2;
		}
		return count[pos][3] <= use;
	}

}

Measured memory_bytes: 102644
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	long long int x;
	cin >> x;
	unordered_map<long long int, int> um;
	for (long long int i = 0; i <= 1000; i++) {
		um[i * i * i * i * i] = i;
		um[-i * i * i * i * i] = -i;
	}
	for (auto p : um) {
		long long int n = p.first;
		if (um.find(n - x) != um.end()) {
			cout << p.second << " " << um[n - x] << endl;
			return 0;
		}
		if (um.find(n + x) != um.end()) {
			cout << um[n + x] << " " << p.second << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3704