akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<iostream>
#include<algorithm> // sort,reverse,min,lower_bound
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int n,k; cin >>n >>k;
  vector<int> h(n);
  for(int& x:h) cin >>x;
  sort(h.begin(),h.end());
  reverse(h.begin(),h.end());
  li ans=0;
  repa(i,k,n){
    ans+=h.at(i);
  }
  cout << ans;
}

/// confirm df==0 ///


Measured memory_bytes: 1024
def inpl(): return list(map(int, input().split()))
N, K = inpl()
x = inpl()
candidates = []
for i in range(N-K+1):#mini return
    if x[i]*x[i+K-1]<0:#またぐ
        if abs(x[i])<abs(x[i+K-1]):#mini return
            candidates.append(abs(x[i])+abs(x[i+K-1]-x[i]))
        else:#maxi return
            candidates.append(abs(x[i+K-1])+abs(x[i+K-1]-x[i]))
    
    else:#またがない
        candidates.append(max(abs(x[i]),abs(x[i+K-1])))
        

print(min(candidates))

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
const int N = 1e5 + 5;
 
int n, m, k;
int x11, y11, x2, y2;
int dx[4]={-1, +1, 0, 0};
int dy[4]={0, 0, +1, -1};
vector<vector<char> > a;
vector<vector<int> > vis, ways, dist;
 
void bfs(int x, int y)
{
	queue<pair<int, int> > q;
	q.push({x, y});
	vis[x][y] = 1;
	dist[x][y] = 0;
	while(!q.empty())
	{
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		for(int dir=0;dir<4;dir++)
		{
			for(int len = 1; len <= k; len++)
			{
				int nx=x+dx[dir] * len;
				int ny=y+dy[dir] * len;
				if(nx<1 || ny<1 || nx>n || ny>m)
					break;
				if(vis[nx][ny] && dist[x][y] + 1 > dist[nx][ny])
					break;
				if(a[nx][ny] == '@')
					break;
				if(vis[nx][ny])
					continue;
				dist[nx][ny]=dist[x][y]+1;
				vis[nx][ny]=1;
				q.push({nx, ny});
			}
		}
	}
}
 
int32_t main()
{
	IOS;
	cin >> n >> m >> k;
	cin >> x11 >> y11 >> x2 >> y2;
	a = vector<vector<char> > (n + 1, vector<char> (m + 1));
	vis = ways = dist = vector<vector<int> > (n + 1, vector<int> (m + 1, 0));
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	bfs(x11, y11);
	if(!vis[x2][y2])
		cout << -1;
	else
		cout << dist[x2][y2];
	return 0;
}


Measured memory_bytes: 32432
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
int a[3];
int main(){
    for(int i = 0;i < 3;i++){
        cin >> a[i];
    }
    sort(a,a+3);
    cout << a[0]*a[1]/2 << endl;
    return 0;
}

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

ll gcd(ll x, ll y){
    ll r = x%y;
    if(r==0) return y;
    return gcd(y, r);
}


int main(){
    ll n, x, m;    cin >> n >> x;
    vector<ll> v(n);
    for(int i=0; i<n; i++){
        cin >> m;
        v.at(i) = abs(x-m);
    }
    sort(v.begin(), v.end());
    ll ans=v.at(0);
    
    for(int i=1; i<n; i++)
        ans = gcd(ans, v.at(i));
    
    
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

int merge(vector<int> &vec, int left, int mid, int right)
{
    int n1 = mid - left,
        n2 = right - mid;
    vector<int> L(n1 + 1), R(n2 + 1);
    repi(i, n1, 0)
    {
        L[i] = vec.at(left + i);
    }
    repi(i, n2, 0)
    {
        R[i] = vec.at(mid + i);
    }
    L[n1] = INF;
    R[n2] = INF;
    int i = 0, j = 0;
    repi(k, right, left)
    {
        if (L.at(i) <= R.at(j))
        {
            vec.at(k) = L.at(i);
            i++;
        }
        else
        {
            vec.at(k) = R.at(j);
            j++;
        }
    }
    return right - left;
}
int mergeSort(vector<int> &vec, int left, int right)
{
    int sum = 0;
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        sum += mergeSort(vec, left, mid);
        sum += mergeSort(vec, mid, right);
        sum += merge(vec, left, mid, right);
    }
    return sum;
}
int main()
{
    int n;
    cin >> n;
    vector<int> s(n);
    repi(i, n, 0)
    {
        cin >> s[i];
    }
    int cnt = mergeSort(s, 0, n);
    repi(i, n, 0)
    {
        cout << s.at(i) << ((i + 1) % n ? " " : "\n");
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 6776
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	a, b, c, d := io.NextInt(), io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(Max(a*c, a*d, b*c, b*d))
}

// Max returns max value of inputs
func Max(a ...int) (max int) {
	for i, ai := range a {
		if i == 0 || ai > max {
			max = ai
		}
	}
	return max
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1776
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int h, w, k;
vector<string> grid;
vector<vector<int>> result;

int main()
{
    cin >> h >> w >> k;
    grid.resize(h);

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

    result.resize(h, vector<int>(w, 0));

    int li = 0, lj = 0;
    int m = 1;
    int s = 0;
    rep(i, h)
    {
        rep(j, w)
        {
            if (grid[i][j] == '#') {
                s++;
            }

            if (s >= 2) {
                for (int x = li; x <= i; x++) {
                    for (int y = lj; y < j; y++) {
                        result[x][y] = m;
                    }
                }
                m++;
                s--;

                lj = j;
            }
        }

        if (s > 0) {
            for (int x = li; x <= i; x++) {
                for (int y = lj; y < w; y++) {
                    result[x][y] = m;
                }
            }
            m++;
            s--;

            li = i + 1;
            lj = 0;
        }
    }

    for (int x = li; x < h; x++) {
        for (int y = lj; y < w; y++) {
            result[x][y] = result[x - 1][y];
        }
    }

    rep(i, h)
    {
        rep(j, w)
        {
            cout << result[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  if (S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  if (S == "Rainy") {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
import math
NOTCOM = "not coprime"
SETWISE = "setwise coprime"
PAIRWISE = "pairwise coprime"
MAX_A = 10 ** 6 + 5

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = [0] * MAX_A
    for a in A:
        c[a] += 1
    pairwse = True
    for i in range(2, MAX_A):
        cnt = 0
        for j in range(i, MAX_A, i):
            cnt += c[j]
        if cnt > 1: pairwse = False
    if pairwse:
        return PAIRWISE
    
    allgcd = A[0]
    for a in A:
        allgcd = math.gcd(allgcd, a)
    if allgcd == 1: return SETWISE
    return NOTCOM

print(main())


Measured memory_bytes: 189256
#include <stdio.h>

#define MAX 30

int N;
int M;
int K[MAX];
int A[MAX][MAX];

void input(void) {
    int i, j;
    scanf("%d%d", &N, &M);
    for (i=0;i<N;i++) {
        scanf("%d", &K[i]);
        for (j=0; j<K[i]; j++){
            scanf("%d", &A[i][j]);
        }
    }
}

int process(void){
    int i, j, k;
    int sum, count;

    sum = 0;
    for (i=1; i<=M; i++){
        count = 0;
        for (j=0; j<N; j++) {
            for (k=0; k<K[j]; k++) {
                if (A[j][k]==i) {
                    count++;
                }
            }
        }
        if (count==N) {
            sum++;
        }
    }
    return sum;
}



int main(void) {
    input();
    printf("%d", process());
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  char s[11];
  scanf("%s",s);

  int len = strlen(s);

  int ans = 10000;
  for(int i = 0; i < len-2 ; ++i){
    int tmp = abs(753 - ((s[i] - '0') *100 + (s[i+1] - '0' ) * 10 + (s[i+2] - '0')));
    ans = min(ans, tmp);
  }

  printf("%d",ans);

  return 0;
}


Measured memory_bytes: 1700
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

a, b, c, d, e = map(int, input().split())

if a==0:
    print(1)
elif b==0:
    print(2)
elif c==0:
    print(3)
elif d==0:
    print(4)
else:
    print(5)

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

int tax(int n, int r){
    return n * (100+r) / 100;
}

int main(){
    int x, y, s;
    while(cin >> x >> y >> s, x+y+s){
        int ans = 0;
        for(int i = 1; i <= s-1; i++){
            for(int j = 1; j <= s-1; j++){
                if(tax(i,x) + tax(j,x) == s){
                    ans = max(ans, tax(i,y)+tax(j,y));
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n; cin>>n;
  vector<pii> a(n);
  rep(i,n){
    int x; cin>>x;
    a[i]={x,i+1};
  }
  sort(a.begin(),a.end());
  rep(i,n) cout<<a[i].second<<" ";
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e15;
vector<vector<ll> > dp;
vector<ll> a,sum;
ll solve(ll l,ll r){//[l,r)
    if(dp[l][r] != 0 ) return dp[l][r];
    if( l+1 == r ) return dp[l][r] = 0;
    ll res = inf;
    for(int i=l+1;i<r;i++) res = min( res , solve(l,i)+solve(i,r) );
    return dp[l][r] = res + sum[r] -sum[l];
}
int main(){
    int n;
    cin>>n;
    dp = vector<vector<ll> > (n+1,vector<ll>(n+1,0) );
    a=vector<ll>(n,0);
    for(int i=0;i<n;i++)cin>>a[i];
    sum = vector<ll>(n+1,0);
    for(int i=1;i<=n;i++)sum[i] = sum[i-1] + a[i-1];
    //for(int i=0;i<=n;i++)cout<<sum[i]<<endl;
    cout<<solve(0,n)<<endl;

    return 0;
}


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

using namespace std;

#define int long long

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

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }
template <typename T> T fact(T n) { return (n == 0 ? 1 : n * fact(n - 1)); }
template <typename T> T modpow(T a, T e, T m) { return (e == (T)0 ? 1 : ((a % m) * modpow((a % m), e - 1, m)) % m); }

constexpr int MOD = 1e9 + 7;

signed main(void) {
  int k, x;
  cin >> k >> x;
  if (500 * k >= x) {
    cout << "Yes" << endl;

  } else
    cout << "No" << endl;
}


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

int main(){
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> xc(n), yc(m);
  for(int i = 0; i < n; ++i) cin >> xc.at(i);
  for(int i = 0; i < m; ++i) cin >> yc.at(i);
  
  sort(xc.begin(), xc.end());
  sort(yc.begin(), yc.end());
  int s = max(x, xc.at(n-1));
  int t = min(y, yc.at(0));
  
  if(s >= t) cout << "War" << endl;
  else cout << "No War" << endl;
}

Measured memory_bytes: 384
/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=0;i<n;i++){      cin>>a[i];}
#define output(a,i,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}

using namespace std;
int64_t R=1;
void solution(){
    int64_t n;
    cin>>n;
    int64_t k=(n+1)/2,sum=0,cnt=0;
    for(int i=1;i<=n;i++){
        if(n%i==0){
            sum+=(n/i)-1;
        }
        else{
            if(i>n/2) sum++;
            else{
                sum+=n/i;
            }
        }
    }
    cout<<sum<<endl;
}
int main()
{
   // cin>>R;
    FOR(i,R){solution();}
    return 0;
}


Measured memory_bytes: 3632
import itertools
x = int(input())

if x >= 2600:
    print(1)
    exit()

cnt = 0
for i in range(0, 25):
    for v in itertools.combinations_with_replacement([100, 101, 102, 103, 104, 105], i):
        if sum(v) == x:
            print(1)
            exit()
print(0)

Measured memory_bytes: 9112
using System;

namespace abc150
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b,c;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = 500 * a;
            if (c >= b)
                Console.WriteLine("Yes");
            if (c < b)
                Console.WriteLine("No");



        }
    }
}


Measured memory_bytes: 11092
a = "a".getbyte(0)
counter = Array.new(26, 0)

eof = false

until eof do
	str = STDIN.gets
	break if str == nil
	str.chomp!
	0.upto(str.length-1) {|i|
		if str[i] =~ /[A-Z]/ then
			str[i] = str[i].downcase
		end
	
		counter[(str[i].getbyte(0) - a)] += 1 if str[i] =~ /[a-z]/
	}
end

0.upto(25) {|i|
	char = String.new()
	char << a + i
	print char, " : ", counter[i], "\n"
}


Measured memory_bytes: 7040
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

#define P (1'000'000'007)

signed main() {
    int n, k;
    cin >> n >> k;

    vi va;

    rep(i, n) {
        capi(a);
        va.push_back(a % k);
    }

    vi dp(n, 0);

    dp[0] = va[0];
    rep(i, n - 1) {
        dp[i + 1] = (dp[i] + va[i + 1]) % k;
    }

    int ans = 0;
    map<int, int> m;
    m.emplace(0, 1);

    vi vh(n, 0);

    rep(i, n) {
        int x = (dp[i] - (i + 1)) % k;
        if (x < 0) x += k;
        vh[i] = x;
        if (i - k == -1) --m[0];
        if (i - k >= 0) {
            --m[vh[i - k]];
        }
        if (auto it = m.find(x); it != m.end()) {
            ans += m[x];
            ++m[x];
        } else {
            m.emplace(x, 1);
        }
    }

    cout << ans;

    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

bool check(const vector<string>& W, const int& N) {
  int len = W[0].size();
  char c = W[0][len-1];
  srep(i, 1, N) {
    if (c != W[i][0]) {
      return false;
    }
    len = W[i].size();
    c = W[i][len-1];
  }
  vector<string> W_cp = W;
  std::sort(W_cp.begin(), W_cp.end());
  srep(i, 1, N) {
    if (W_cp[i-1] == W_cp[i]) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int N;
  cin >> N;
  vector<string> W(N);
  rep(i, N) cin >> W[i];
  if (check(W, N)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 256
N = int(input())
nums = list(map(int, input().split(' ')))
def gcd(a, b):
   return b if a % b == 0 else gcd(b, a % b)
def lcm(a, b):
   return a * b // gcd(a, b)
lcms = nums[0]
for i in range(1, len(nums)):
    lcms = lcm(lcms, nums[i])

ans = 0
for i in range(len(nums)):
    ans += ((lcms-1) % nums[i])
print(ans)


Measured memory_bytes: 3316
#include <stdio.h>

int main(void)
{
  	int a, b, c;
  
  	scanf("%d %d", &a, &b);
  
  	if(a-b*2<0){
      	c = 0;
    }
  
  	else{
      	c = a-b*2;
    }
  
  	printf("%d", c);
  
  	return 0;
}

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

vector<string> lis;
int s;

void make(string a, vector<int> flag){
    if(a.size() == s){
        lis.push_back(a);
        return;
    }
    for(int i = 1; i <= s; i++){
        if(flag[i] == 0){
            flag[i] = 1;
            make(a + to_string(i), flag);
            flag[i] = 0;
        }
    }
}
int main(){
    cin >> s;
    vector<int> flag(s+1, 0);
    string a = "";
    make(a, flag);
    sort(lis.begin(), lis.end());
    string mid, p = "", q = "";
    for(int i = 0; i < s; i++){
        cin >> mid;
        p = p + mid;
    }
    for(int i = 0; i < s; i++){
        cin >> mid;
        q = q + mid;
    }
    int aa, bb;
    for(int i = 0; i < lis.size(); i++){
        if(lis[i] == p){
            aa = i;
        }
        if(lis[i] == q){
            bb = i;
        }
    }
    cout << abs(aa - bb) << endl;
}

Measured memory_bytes: 2424
#include<iostream>
#include <unordered_set>

using namespace std;

bool IsKaibun(int n)
{
    string s = to_string(n);
    int i = 0;
    int j = s.size() - 1;
    while (i != j)
    {
        if (s[i] != s[j]) return false;
        ++i;
        --j;
    }
    return true;
}

int main()
{

    int A, B;
    cin >> A >> B;

    int result = 0;
    for (int n = A; n <= B; ++n)
    {
        if (IsKaibun(n)) ++result;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    ll a1=min(2*q,h),a2;
    a1=min(2*a1,s);
    a2=min(2*a1,d);
    if(n%2==0) cout<<(n/2)*a2<<endl;
    else cout<<(n/2)*a2+a1<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
C = 0
for i in range(N-1):
  if li_a[i] == li_a[i+1] - 1:
    C += li_c[li_a[i]-1]
B = sum(li_b)
print(B+C)

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

using namespace std;

int main()
{
    int h, w;
    char c[110][110];

    cin >> h >> w;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> c[i][j];
        }
    }

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cout << c[i][j];
        }
        cout << endl;
        for (int j = 0; j < w; j++){
            cout << c[i][j];
        }
        cout << endl;
    }
    return 0;
}

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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_NM = 100000, MOD = 1e9 + 7;
int n, m;
ll x[MAX_NM+20], y[MAX_NM+20];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> x[i];
  for (int i = 1; i <= m; ++i) cin >> y[i];

  ll xans = 0;
  for (ll i = 1; i <= n-1; ++i) {
    xans += i*(n-i)%MOD*(x[i+1]-x[i])%MOD;
    xans %= MOD;
  }
  ll yans = 0;
  for (ll i = 1; i <= m-1; ++i) {
    yans += i*(m-i)%MOD*(y[i+1]-y[i])%MOD;
    yans %= MOD;
  }

  ll ans = xans*yans%MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int k;
	cin >> k;
	string s;
	cin >> s;
	if (s.size() <= k)
	{
		cout << s << endl;
	}
	else
	{
		rep(i, k)
		{
			cout << s[i];
		}
		cout << "..." << endl;
	}

	return 0;
}

Measured memory_bytes: 3652
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  long long X, Y;
  cin >> X >> Y;

  if (abs(X - Y) <= 1) {
    cout << "Brown";
  } else {
    cout << "Alice";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,sum=0,i,j;
  cin >> a >> b;
  vector<int>vec;
  while(a--)
  {
      cin >> c;
      vec.push_back(c);
      sum+=c;


  }
 int p=ceil((float)sum/((float)b*4));

int m=0;
  for(i=0;i<vec.size();i++)
  {
      if(vec[i]>=p)
      {
          m++;
      }
 }
  if(m>=b)
  {
      cout << "Yes" << endl;
  }
  else
  {
      cout << "No" << endl;
  }

}




Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  1e6+5;
const ll   mod   =  1e9;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, k;

void solve(){
	int ans = 0;
	cin >> k;
	ll i = 1, j = 7%k;
	while(1){
		if(j == 0){
			deb1(i)
			return;
		}
		i++;
		j = (j*10+7)%k;
		if(i == 50000000){
			deb1(-1)
			return;
		}
	}
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll ans = 1;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] != s[i - 1])ans++;
    }
    ll iu = 1;
    ans = max(iu, ans - k * 2);
    cout << n - ans << endl;
}

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

int main(){
  int N,K,Q,i,j=0;
  cin >> N >> K >> Q;
  vector<int> P(N,K-Q);
  vector<int> Ans(Q);
  for(i=0;i<Q;i++)
    cin >> Ans.at(i);

  for(i=0;i<Q;i++)
    P.at(Ans.at(i)-1)++;
  
  for(i=0;i<N;i++){
    if(P.at(i) <= 0)
      cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;    
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll ans=0;
    rep(i,n-1){
        for(ll j=i+1;j<n;j++){
            chmax(ans,abs(a[i]-a[j]));
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3640
n, m = map(int, input().split())
list_AB = [ list(map(int,input().split(" "))) for i in range(n)]

list_AB.sort()
ans = 0
for i in range(n):
    l = list_AB[i]
    if l[1] > m:
       ans += l[0]*m
       break
    else:
        ans += l[0]*l[1]
        m -= l[1]

print(ans)


Measured memory_bytes: 27812
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int s=scan.nextInt();
            if(s<3){
                out.println(0);
            }else {
                long mod=(long)(1e9)+7;
                long[] dp = new long[s + 1];
                dp[0] = 1;
                for(int i=3;i<=s;i++){
                    for(int j=3;j<=i;j++){
                        dp[i]=(dp[i]+dp[i-j])%mod;
                    }
                }
                out.println(dp[s]);
            }
        }
        out.flush();
        out.close();
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


Measured memory_bytes: 33124
N = gets.chomp.to_i
list = []
row = 1
N.times do
    s, p = gets.chomp.split(" ")
    list.push([s, p.to_i, row])
    row += 1
end
list = list.sort_by  {|list| [list[0] , -list[1]]}

list.each do | data |
    puts data[2]
end


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int sum = 0;
		for (int i = 0; i < s.length(); i++) {
			sum = (sum + s.charAt(i) - '0') % 9;
		}
		System.out.println(sum == 0 ? "Yes" : "No");
		in.close();
	}
}


Measured memory_bytes: 40468
MOD=1000000007

def combination(n,m):
    if m==0:
        return 1
    else:
        return combination(n-1,m-1)*n//m

def pow_mod(a, b, p):
    if b == 0:
        return 1
    elif b%2 == 0:
        d = pow_mod(a, b//2, p)
        return (d**2)%p
    else:
        return (a*pow_mod(a,b-1,p))%p    
    
def factorial_mod(n,p):
    tmp = 1
    for i in range(1,n+1):
        tmp *= i
        tmp %= p
    return tmp


      
x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
elif x*2<y:
  print(0)
elif y*2<x:
  print(0)
else:
  a=(x+y)//3
  x-=a
  y-=a
  #x+yCx
  if x>y:
    a=x
    x=y
    y=a
  W=x+1
  H=y+1
  ans = factorial_mod(W-1 + H-1, MOD)
  ans *= pow_mod(factorial_mod(H-1,MOD), MOD-2, MOD)
  ans %= MOD
  ans *= pow_mod(factorial_mod(W-1,MOD), MOD-2, MOD)
  ans %= MOD

 
  print(ans)
  
 

Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll k;
int a[200005];
vector<int> vec;
bool used[200005];

int main(void){
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i]--;
	}
	vec.push_back(0);
	used[0]=true;
	int cur=a[0];
	while(!used[cur]){
		vec.push_back(cur);
		used[cur]=true;
		cur=a[cur];
	}
	int po=0;
	for(int i=0;i<vec.size();i++){
		if(vec[i]==cur){
			po=i;
			break;
		}
	}
	if(k<po){
		printf("%d\n",vec[k]+1);
	}else{
		k-=po;
		int len=vec.size()-po;
		printf("%d\n",vec[(ll)k%(ll)len+po]+1);
	}
	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
bool ask(int a, int b) {
	printf("? %d %d\n", a, b);
	fflush(stdout);
	char ch;
	scanf(" %c", &ch);
	return ch == 'Y';
}
int main() {
	int A, B;
	scanf("%d%d", &A, &B);
	if (A <= B) {
		printf("Impossible\n");
		fflush(stdout);
		return 0;
	}
	int n = A + B;
	int cnt = 0, cur;
	for (int i = 0; i < n; ++i) {
		if (cnt <= 0) {
			cnt = 0;
			cur = i;
		}
		if (ask(i, cur)) {
			++cnt;
		} else {
			--cnt;
		}
	}
	assert(cnt > 0);
	string ans;
	for (int i = 0; i < n; ++i) {
		ans += ask(cur, i) ? '1' : '0';
	}
	printf("! %s\n", ans.c_str());
	fflush(stdout);
}


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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }

  int cnt = 0;
  for(const auto itr: mp){
    if(itr.second > 1) cnt += itr.second-1;
  }
  
  int d = (int)ceil(cnt * 1. / 2);

  cout << n - 2*d << endl;

  return 0;
}


Measured memory_bytes: 5376
/**
 * Author: Deb Natkh Maxim (debnatkh@gmail.com)
 */

#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
typedef pair<int, int> pii; 

const int MAXN = 1e5;
int arr[MAXN];

signed main() {
 	string s, t;
 	cin >> s >> t;
 	int cnt = 0;
 	for (int i = 0; i < 3; i++) {
 		cnt += s[i] == t[i];
 	}
 	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
H, W = gets.chomp.split(" ").map(&:to_i)
if H % 3 == 0 || W % 3 == 0 then
  puts 0
  exit
end

ret = H * W
short, long = [H, W].minmax

long.times do |i|
  a = (i + 1) * short
  
  b = (short / 2) * (long - (i + 1))
  c = (short - short / 2) * (long - (i + 1))
  if a > 0 && b > 0 && c > 0 then
    ret = [([a, b, c].max - [a, b, c].min), ret].min 
  end

  b = ((long - i) / 2) * short
  c = (long - (i + 1) - ((long - i) / 2)) * short
  if b > 0 && c > 0 then
    ret = [([a, b, c].max - [a, b, c].min), ret].min 
  end

end

short, long = long, short
long.times do |i|
  a = (i + 1) * short

  b = (short / 2) * (long - (i + 1))
  c = (short - short / 2) * (long - (i + 1))
  if b > 0 && c > 0 then
    ret = [([a, b, c].max - [a, b, c].min), ret].min 
  end

  b = ((long - i) / 2) * short
  c = (long - (i + 1) - ((long - i) / 2)) * short
  if a > 0 && b > 0 && c > 0 then
    ret = [([a, b, c].max - [a, b, c].min), ret].min 
  end

end
puts ret

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

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

    double p = 0.0;
    if(n % 2 == 0) {
        p = 0.5;
    } else {
        p = (double)(n+1) / (double)(2*n);
    }
    cout << p << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[26] = {};
    string s;
    for (int i = 0; i < 26; i++) a[i] = 328;
    cin >> n;
    while (n--) {
        int b[26] = {};
        cin >> s;
        for (int i = 0; i < s.length(); i++) b[s[i] - 'a']++;
        for (int i = 0; i < 26; i++) a[i] = min(a[i], b[i]);
    }
    for (int i = 0; i < 26; i++) for (int j = 0; j < a[i]; j++) cout << (char)(i + 'a');
}


Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, M);
    IN(ll, X);
    vi C(N);
    vvi A(N, vi(M));
    REP(i, N)
    {
        cin >> C[i];
        REP(j, M)
        {
            cin >> A[i][j];
        }
    }
    ll ans = INF;
    REP(p, 1 << N)
    {
        vi y(M);
        ll cost = 0;
        REP(i, N)
        {
            if ((p >> i) & 1)
            {
                cost += C[i];
                REP(j, M)
                {
                    y[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        REP(i, M)
        {
            ok &= y[i] >= X;
        }
        if (ok)
        {
            CH(min, ans, cost);
        }
    }
    if (ans == INF)
    {
        ans = -1;
    }
    OUT(ans);
}


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

int main()
{
  int A, B, ans;
  cin >> A >> B;
  if (B % A == 0)
    ans = A + B;
  else
    ans = B - A;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
S = input()

len_s = len(S)
if len_s == 1:
  print(0)
else:
  temp = len_s//2

  a = '10' * (temp)
  b = '01' * (temp)

  if len_s%2 != 0:
    a = a + '1'
    b = b + '0'

  cnt_a = 0
  cnt_b = 0
  for i in range(len_s):
    if a[i] != S[i]:
      cnt_a += 1
    if b[i] != S[i]:
      cnt_b += 1
  print(min(cnt_a, cnt_b))

Measured memory_bytes: 41072
#include <iostream>
using namespace std;
using ll = long long;

int main() {
  ll l,r; 
  cin >>l>>r;
  if (r-l > 3000){
    cout << 0 << endl;
    return 0;
  }
  else {
    ll res = 2018;
    for (ll i = l; i < r; ++i){
      for (ll j = i+1; j <= r; ++j){
        res = min(res, (i * j) % 2019);
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 256
def p_h():
    h, w = map(int, input().split())
    dp = []
    for _ in range(h):
        dp.append(list(map(int, input().replace(".", "0 ").replace("#", "-1 ").split())))
    dp[0][0] = 1
    mod = 10**9 + 7

    for i in range(h):
        for j in range(w):
            if j < w - 1 and dp[i][j + 1] != -1 and dp[i][j] != -1:
                dp[i][j + 1] += dp[i][j]
                dp[i][j + 1] %= mod
            if i < h - 1 and dp[i + 1][j] != -1 and dp[i][j] != -1:
                dp[i + 1][j] += dp[i][j]
                dp[i + 1][j] %= mod

    print(dp[-1][-1])


if __name__ == '__main__':
    p_h()


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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    rep(i, H) cin >> S[i];
    int ans = 1001001001;
    rep(bit, 1 << (H - 1)) {
        vector<int> g(H);
        int nowg = 0;
        rep(i, H) {
            g[i] = nowg;
            if (bit >> i & 1) ++nowg;
        }
        ++nowg;
        vector<vector<int>> c(nowg, vector<int>(W, 0));
        rep(i, H) rep(j, W) c[g[i]][j] += S[i][j] - '0';
        vector<int> now(nowg, 0);
        int tmpans = nowg-1;
        rep(w, W) {
            bool flag = true;
            rep(g, nowg) {
                now[g] += c[g][w];
                if (now[g] > K) {
                    flag = false;
                    ++tmpans;
                    now = vector<int>(nowg, 0);
                    break;
                }
            }
            if (!flag) {
                rep(g, nowg) {
                    now[g] += c[g][w];
                    if (now[g] > K) {
                        tmpans = 1001001001;
                        break;
                    }
                }
            }
			if(tmpans == 1001001001) break;
        }
        ans = min(ans,tmpans);
    }
	cout << ans << endl;
}

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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

int main() {
    int v = 0;
    cin >> v;
    char c;
    while(cin >> c, c != '=') {
        int b; cin >> b;
        if(c == '+') {
            v += b;
        } else if(c == '-') {
            v -= b;
        } else if(c == '/') {
            v /= b;
        } else {
            v *= b;
        }
    }
    cout << v << endl;
}


Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
#define maxn 25
#define maxA 55
const int inf = 0x3f3f3f3f;
int n,cst[maxn],a[maxn],b[maxn],f[(1 << 18) + 5][maxA];
int main(){
  memset(f,0x3f,sizeof(f));
  n = getint();
  for(int i = 0;i < n;i++) a[i] = getint();
  for(int i = 0;i < n;i++) b[i] = getint();
  f[0][0] = 0;
  for(int S = 0;S < (1 << n);S++){
    cst[0] = 0;
    for(int i = 1;i < n;i++)
      cst[i] = cst[i - 1] + ((S & (1 << (i - 1))) == 0);
    int nxt = __builtin_popcount(S);
    for(int st = 0;st <= 50;st++){
      if(f[S][st] == inf) continue;
      for(int j = 0;j < n;j++){
        if(S & (1 << j)) continue;
        int val = (abs(nxt - j) & 1) ? b[j] : a[j];
        if(st <= val){
          f[S | (1 << j)][val] = min(f[S | (1 << j)][val],f[S][st] + cst[j]);
        }
      }
    }
  }
  int ans = inf;
  for(int i = 1;i <= 50;i++) ans = min(ans,f[(1 << n) - 1][i]);
  putint(ans == inf ? -1 : ans,'\n');
  bufo.flush();
  return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t x,k,d; cin>>x>>k>>d; x=abs(x);
	int64_t mn=x/d;
	if(mn>k){
		cout<<x-k*d;
	}
	else{
		if((mn+k)%2)cout<<abs(x-d*(mn+1));
		else cout<<abs(x-d*mn);
	}
	cout<<"\n"s;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;
ll K;
ll m;

void dfs(ll x){
  if(abs(K-x)>x){
    m=x;
    return ;
  }

  dfs(abs(K-x));
}

int  main(){
  ll N;cin >> N >> K;
  dfs(N%K);

  cout << m << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, t; cin >> n >> t;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> b(n,0);
    int MIN = a[0];
    map<int, int> ma;
    rep(i,n){
        if(a[i] < MIN) MIN = a[i];
        ma[a[i] - MIN]++;
    }
    int ans = ma.rbegin()->second;//max key
    cout << ans << endl;
}

Measured memory_bytes: 5760