akhauriyash/Code-Regression huggingface dataset:
def check_block(comb, H):
    block = 0
    pre = (comb & 1) > 0
    mapping = {0: 0}
    cut_num = 0
    for i in range(1, H):
        cur = ((1 << i) & comb) > 0
        if pre != cur:
            block += 1
            pre = cur
            cut_num += 1
        mapping[i] = block
    return mapping, cut_num

H, W, K = map(int, input().split())
graph = [input() for ele in range(H)]
#
ans = 1319203291031903
for comb in range(1<<(H-1)):
    mapping, cut_num = check_block(comb, H)
    pre = [0] * (cut_num + 1)
    gg = False
    # preprocess 
    for j in range(H):
        pre[mapping[j]] += (graph[j][0] == '1')
    for ele in pre:
        if ele > K:
            gg = True
            break
    if gg: continue

    for i in range(1, W):
        cum = pre[:]
        for j in range(H):
            cum[mapping[j]] += (graph[j][i] == '1')
        for ii in range(len(cum)):
            if cum[ii] - pre[ii] > K or cut_num > ans:
                gg = True
                break
            if cum[ii] > K:
                cut_num += 1
                for idx in range(len(cum)):
                    cum[idx] -= pre[idx]
                break
        pre = cum
        if gg: break

    if not gg:
        ans = min(ans, cut_num)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int A[100000];

int main()
{
    int N;
    cin >> N;
    
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    
    std::sort(A, A + N);
    
    int ans = 0;
    int index = 0;
    while (index != N)
    {
        auto num = A[index];
        auto count = 1;
        for (int i = index + 1; i < N; i++)
        {
            if (A[i] == num)
            {
                count++;
            }
            else
            {
                break;
            }
        }
        if (count % 2 == 1)
        {
            ans++;
        }
        index += count;
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s[45000],n,m;
void f(ll N){
    for(ll i=44999;i>0;i--){
        if(N-s[i]<=0)continue;
        if((N-s[i])%i==0){
            cout<<(N-s[i])/i<<" "<<i<<endl;
            return ;
        }
    }
}
int main(void){
    for(ll i=1LL;i<45000;i++)s[i]=i+s[i-1]-1;
    while(1){
        cin>>n;
        if(n==0)return 0;
        f(n);
    }
}



Measured memory_bytes: 3436
w = input()


hist = dict()
for char in w:
  if not char in hist.keys():
    hist[char] = 1
  else:
    hist[char] += 1

answer = True
for value in hist.values():
  if value % 2 == 1:
    answer = False

if answer:
  print ('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let n: usize = read();
    let mut cnt = 0;
    let mut ans = "No";
    for _ in 0..n {
        let d: Vec<u8> = read_vec();
        if d[0] == d[1] { cnt += 1; }
        else { cnt = 0; }
        if cnt >= 3 { ans = "Yes"; }
    }
    println!("{}", ans);
}


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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 double PI = acos(-1);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double x;
    if (abs(60.0*h - 11.0*m) < 360) x = abs(60.0*h - 11.0*m);
    else x = 720.0 - abs(60.0*h - 11.0*m);

    //cout << x << endl;

    if (x == 0) {
        cout << abs(a-b) << endl;
        return 0;
    }
    x = x * 2.0 * PI / 720.0; 
    cout << setprecision(12) << sqrt(a*a + b*b - 2.0*a*b*cos(x)) << endl;

    return 0;
}



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

int main()
{
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for(auto& pj:p) cin >> pj;
    for(auto& qj:q) cin >> qj;
    for(auto& rj:r) cin >> rj;

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    priority_queue<ll, vector<ll>, greater<ll>> pq;
    ll sum = 0;
    rep(i,x) { pq.push(p[i]); sum += p[i]; }
    rep(i,y) { pq.push(q[i]); sum += q[i]; }
    rep(i,c) {
        pq.push(r[i]);
        int t = pq.top();
        pq.pop();
        if(t >= r[i]) break;
        sum += r[i] - t;
    }

    cout << sum << endl;
    return 0;
}

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




int main(){
  unsigned int A, B;
  cin >> A;
  cin >> B;

  vector<int> answers{1, 2, 3};

  answers.erase(remove(answers.begin(), answers.end(), A), answers.end());
  answers.erase(remove(answers.begin(), answers.end(), B), answers.end());

  cout << answers[0] << endl;
}


Measured memory_bytes: 888
#include <cstdio>
using namespace std;
bool memo[100005];
int main(){
    memo[0]=true;
    for (int x=100;x<=105;x++){
        for (int y=x;y<100005;y++){
            memo[y]|=memo[y-x];
        }
    }
    
    int n;
    scanf("%d",&n);
    printf("%d\n",memo[n]);
}


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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    auto f = [](char c)->bool{
        return c == 'A' || c == 'C' || c == 'G' || c == 'T';
    };
    int ans = 0;
    for(int i = 0; i < n; i++){
        int j = i;
        while(j < n && f(s[j])) j++;
        ans = max(ans, j-i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int n;
int check(int n)
{
	int cnt=0;
	for(;n;n/=10)++cnt;
	return cnt&1;
}
int main()
{
	n=read();
	int ans=0;
	for(int i=1;i<=n;i++)
		ans+=check(i);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int k, x;
  cin >> k >> x;
  rep3(i, max(x - k + 1, -1000000), min(x + k - 1, 1000000) + 1) cout << i << " "; cout << endl;
}


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

typedef long long ll;

int N, M;
int k[10], s[10][10];
int p[10];
int ans = 0;

bool judge(vector<bool> v1) {
    bool res = true;
    rep(i, M) {
        int tmp = 0;
        rep(j, k[i]) {
            if (v1[s[i][j] - 1]) tmp++;
        }

        if (p[i] != tmp % 2) {
            res = false;
            break;
        }
    }
    return res;
}

void dfs(int i, vector<bool> v1) {
    if (i >= N) {
        if (judge(v1)) ans++;
        // cout << endl;
        // rep(j, N) {
        //     cout << v1[j] << " ";
        // }
        // cout << endl;
        // cout << endl;
        return;
    }

    vector<bool> v2(v1.size());
    copy(v1.begin(), v1.end(), v2.begin());

    v1.push_back(true);
    v2.push_back(false);
    dfs(i + 1, v1);
    dfs(i + 1, v2);
}

int main() {
    cin >> N >> M;
    rep(i, M) {
        cin >> k[i];
        rep(j, k[i]) {
            cin >> s[i][j];
        }
    }

    rep(i, M) {
        cin >> p[i];
    }

    vector<bool> b;
    dfs(0, b);

    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	a1 := getNextInt(scanner)
	a2 := getNextInt(scanner)
	a3 := getNextInt(scanner)
	a := a1 + a2 + a3
	if a <= 21 {
		fmt.Fprintln(writer, "win")
	} else {
		fmt.Fprintln(writer, "bust")

	}
	writer.Flush()
}


Measured memory_bytes: 640
import Data.Char
main = do
  getLine
  foldr (\x y -> min y $ sol x)  10000 . map read . words  <$> getLine >>= print

sol :: Int -> Int
sol 0 = 0
sol x
  | x `mod` 2 == 0 = 1 + sol (x `div` 2)
  | otherwise = 0




Measured memory_bytes: 1020
n,m=gets.split.map(&:to_i)
cities=m.times.map{|i|gets.split.map(&:to_i)<<i}
prefectures=Hash.new(0)
ans=Array.new(m)
cities.sort_by{|p,y,i|y}.each{|p,y,i|
  prefectures[p]+=1
  ans[i]="%06d%06d"%[p,prefectures[p]]
}
puts ans

Measured memory_bytes: 24532
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main()
{
llong n,m;
cin>>n>>m;
pair<llong,llong> drink[100100];
for(int i=0;i<n; i++)
{
 llong a,b;
 cin>>a>>b;
 drink[i].first=a;
 drink[i].second=b;
}
sort(drink,drink+n);
llong cost=0;
int cnt=0;

while(1)
{
    if(drink[cnt].second<m)
    {
        cost+=drink[cnt].first*drink[cnt].second;
        m-=drink[cnt].second;
    }
    else
        {
        cost+=drink[cnt].first*m;
        break;
        }
    cnt++;
}
cout<<cost<<endl;
}

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

void solve()
{
    int n;cin>>n;
    cout << !(int(n)) << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    auto t1 = high_resolution_clock::now();
    ll test = 1;
    // cin >> test;
    for (ll i = 0; i < test; i++)
    {
        // cout << "Case #" << (i + 1) << ": ";
        solve();
    }
    auto t2 = high_resolution_clock::now();
    auto duration = duration_cast<milliseconds>(t2 - t1).count();
    // cout << duration << endl;
    return 0;
}

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

using namespace std;

int rr[4] = {0, 0, 1, -1};
int cc[4] = {1, -1, 0, 0};

#define mp make_pair
#define pii pair<int, int> 

int
main(void){
	int h, w, k; cin >> h >> w >> k;
	int x1, y1, x2, y2; cin>> x1 >> y1 >> x2 >> y2;
	--x1; --x2; --y1; --y2;
	vector<string> grid(h);
	for(int i = 0; i < h; i++) cin >> grid[i];
	
	vector<vector<bool> > used(h, vector<bool> (w, false));
	vector<vector<int> > dist(h, vector<int> (w, INT_MAX));
	queue<pii> q;
	q.push(mp(x1, y1));
	dist[x1][y1] = 0;
	while(!q.empty()){
		pii cur = q.front();
		q.pop();
		int r = cur.first;
		int c = cur.second;
		int d = dist[r][c] + 1;
		for(int i = 0; i < 4; i++){
			int row = r, col = c;
			for(int j = 0; j < k; j++){
				row += rr[i]; col += cc[i];
				if(row < 0 || row >= h || col < 0 || col >= w || grid[row][col] == '@') break;
				if(dist[row][col] == INT_MAX){
					q.push(mp(row, col));
					dist[row][col] = d;
				}
				else if(dist[row][col] < d) break;
			}
		} 
	
	}
	if(dist[x2][y2] == INT_MAX) cout << -1;
	else cout << dist[x2][y2];
}

Measured memory_bytes: 12424
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
    	int N, p[1001]{};
        cin >> N;
		for (int i = 2; i <= N; ++i) {
		int I = i;
		for (int j = 2, n = sqrt(I) + 1; I != 1 && j != n; ++j) {
		while (I % j == 0) {
        I /= j;
        ++p[j];
      }
    }
    if (I != 1) ++p[I];
  }
 
  cout << accumulate(begin(p), end(p), 1ll, [&](ll a, ll x) 
  {
    return a * (x + 1) % MOD;
  }) << endl;
		return 0;  
}  


Measured memory_bytes: 3608
#include <iostream>

using namespace std;

string s;

long long dfs(int n,long long nw,long long tmp){
  long long ans = nw + tmp * 10 + (s[n] - '0');
  if(s.size()-1 == n){
    return ans;
  }
  return (long long)dfs(n + 1, ans, 0) + dfs(n + 1, nw, ans - nw); 
}

int main()
{
  cin >> s;
  cout << (long long)dfs(0 ,0 ,0) << endl;
}

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

int main(){
  string S,T;
  cin >> S >> T;
  int cnt=0;
  for (int i=0; i<S.size(); i++){
    if (S.at(i) != T.at(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e18;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  string s;
  cin >> s;
  string t = s;
  s.erase(4);
  t=t.substr(4);
  cout << s << " " << t << endl;
}


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


int main() {
  int x, y, z, a;
  int i = 1;
  
  cin >> x >> y;

  while(!(x==0 && y==0)){
    if(x<y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
		cin >> x >> y;
  }
}



Measured memory_bytes: 3076
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int x,n;
int arr[105];
map<int,bool>ada;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>x>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        ada[arr[i]]=true;
    }
    int l=x,r=x;
    while(true){
        if(ada.count(l)==false){
            cout<<l<<endl;
            return 0;
        }
        else if(ada.count(r)==false){
            cout<<r<<endl;
            return 0;
        }
        else {
            l--;r++;
        }
    }

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

template<ll mod>
class Fp {
public:
	ll val;

private:
	inline void calc_mod(ll& v) {
		if (v >= mod)v -= mod;
	}
public:
	Fp() {}
	Fp(ll v) :val(v%mod) {
		if (val < 0)val += mod;
	}

	Fp operator+=(const Fp &in) {
		val += in.val;
		calc_mod(val);
		return *this;
	}

	Fp operator+(const Fp &in) const {
		return Fp(*this) += in;
	}

	Fp &operator-=(const Fp &in) {
		val -= in.val;
		calc_mod(val);
		if (val < 0)val += mod;
		return *this;
	}

	Fp operator-(const Fp &in) const {
		return Fp(*this) -= in;
	}

	Fp& operator*=(const Fp& in) {
		val = val * in.val % mod;
		return *this;
	}

	Fp operator*(const Fp &in) const {
		return Fp(*this) *= in;
	}

	Fp& operator/=(const Fp& in) {
		*this *= modpow(in, mod - 2);
		return *this;
	}

	Fp operator/(const Fp& in) const {
		return Fp(*this) /= in;
	}

	bool operator==(const Fp&in)const {
		return val == in.val;
	}

	bool operator!=(const Fp&in)const {
		return val != in.val;
	}

	friend Fp modpow(const Fp& in, ll n) {
		if (n == 0)return 1;
		if (n & 1) {
			return in * modpow(in*in, n / 2);
		}
		else {
			return modpow(in*in, n / 2);
		}
	}
};
using modll = Fp<mod>;

class Factorial {
public:
	vector<modll> fact, finv;
	Factorial(ll n) :fact(n, modll(1)), finv(n, modll(1)) {
		for (int i = 2; i < n; i++) {
			modll tmp(i);
			fact[i] = fact[i - 1] * tmp;
			finv[i] = finv[i - 1] / tmp;
		}
	}

	modll com(const ll& n, const ll& k) {
		if (n < k || n < 0 || k < 0)return modll(0);
		return fact[n] * finv[k] * finv[n - k];
	}
};


int main() {
	cin >> S;
	vector<modll> ans(100001),dp(100001);
	dp[0] = modll(1);
	if (S[S.size()-1] == '1')
		ans[0] = modll(3);
	else ans[0] = modll(1);
	for (int i = 1; i < S.size(); i++) {
		dp[i] = dp[i - 1] * modll(3);
	}
	for (int i = 1; i<S.size() ; i++) {
		if (S[S.size()-i-1] == '1') {
			ans[i] = dp[i] + ans[i - 1] * modll(2);
		}
		else {
			ans[i] = ans[i - 1];
		}
	}
	cout << ans[S.size()-1].val << endl;
}


Measured memory_bytes: 2048
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll X,Y;
ll mny[206];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll ans=0;
	cin>>X>>Y;
	REP(i,3)mny[i+1]=100000*(3-i);
	ans+=mny[X]+mny[Y];
	if(X==1&&Y==1){
		ans+=400000;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
H,W,K = map(int, input().split())
S = [[int(i) for i in list(input())] for _ in range(H)]

accum_col = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if i == 0:
            accum_col[i][j] = S[i][j]
        else:
            accum_col[i][j] = accum_col[i-1][j] + S[i][j]

def cnt_white(x, a, b):
    if a == 0:
        return accum_col[b-1][x]
    else:
        return accum_col[b-1][x] - accum_col[a-1][x]

ans = H*W
for bit in range(1 << (H-1)):
    # 横に直線で割るが、その線の真下のindex
    horizs = [0]
    cnt_split = bin(bit).count("1")
    for i in range(H-1):
        if bit & (1 << i):
            """
            i=0でbitに1が立っていると、y=0と1の間を横一直線に割るので、次のブロックの始まりはy=1から。
            みたいな意味でi+1
            """
            horizs.append(i+1)
    
    horizs.append(H)
    # horizsの要素間がブロックなので-1
    # これまでの各ブロックの累積のホワイトチョコの個数
    prev = [0] * (len(horizs) - 1)
    for x in range(W):
        # 横位置でxの列の各ブロックのホワイトチョコの個数
        curr_col = [cnt_white(x, a, b) for a,b in zip(horizs, horizs[1:])]
        # 各ブロックの個数
        prev_curr = [curr_col[i] + prev[i] for i in range(len(horizs)-1)]
        if max(curr_col) > K:
            # 一行だけみてもKを超えるブロックがあるので、十分大きい値を足してアウトにする
            cnt_split += H*W
            break
        if max(prev_curr) > K:
            # ホワイトチョコが最も多いブロックでKを超えていれば、手前の列までで割る
            prev = curr_col
            cnt_split += 1
        else:
            # いずれもK以下であればそのままブロックを広げる
            prev = prev_curr
    
    ans = min(ans, cnt_split)

print(ans)


Measured memory_bytes: 47452
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define mod 1000000007
#define MOD 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

const int N = 100005;
ll cnt[N];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    FASTIO;
    int n, k;
    cin>>n>>k;
    ll res = 0;
    for(int i = k; i > 0; i--)
    {
        cnt[i] = modPow(k/i, n);
        for(int j = i + i; j < N; j+=i)
            cnt[i] = modSub(cnt[i], cnt[j]);
        res = modAdd(res,modMul(cnt[i], i));
    }
    cout<<res<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pa pair<int,int>
#define pb push_back
#define ms(x,y) memset(x,y,sizeof(x))
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mod 998244353
#define N 210
using namespace std;
inline ll read() {
	ll x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int n,bin[N];
struct hhh {
	int x,y;
}p[N];
int main() {
	n=read(),bin[0]=1;
	for (int i=1; i<=n; i++) p[i].x=read(),p[i].y=read(),bin[i]=bin[i-1]*2%mod;
	int ans=bin[n]-n-1;
	for (int i=1; i<n; i++) 
		for (int j=i+1; j<=n; j++) {
			int cnt=0;
			for (int k=j+1; k<=n; k++) if ((p[i].y-p[k].y)*(p[j].x-p[k].x)==(p[j].y-p[k].y)*(p[i].x-p[k].x)) cnt++;
//			cout << cnt << endl;
			(ans-=bin[cnt])%=mod;
		}
	ans=(ans+mod)%mod;
	cout << ans << endl;
}

Measured memory_bytes: 256
D, N = map(int, input().split())

if D == 0:
    l = [i for i in range(1, 200) if i % 100 != 0]
elif D == 1:
    l = [i for i in range(100, 20000, 100) if i % 10000 != 0]
else:
    l = [i for i in range(10000, 2000000, 10000) if i % 1000000 != 0]
print(l[N - 1])


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

int main()
{ 
  int a, b, c, d ;
  cin >> a >> b >> c >> d ;
  vector<int> e = {1, 4, 7, 9} ;
  vector<int> f = {a, b, c, d} ;
  sort(f.begin(), f.end()) ;

  if(e == f)
  {
    cout << "YES" << endl ;
  }
  else
  {
    cout << "NO" << endl ;
  }
  
}


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

int main(){
  int64_t N,A,B;
  cin >> N >> A >> B;
  int64_t a,x;
  a=N/(A+B);
  x=a*A;
  if(N%(A+B)>A){
    x+=A;
  }else{
    x+=N%(A+B);
  }
  cout << x << endl;
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int N;
	cin >> N;
	vector<int> V(N), C(N);
	rep(i, N) cin >> V[i];
	rep(i, N) cin >> C[i];
	int sum=0;
	rep(i, N) if (V[i] - C[i] > 0) sum += V[i] - C[i];
	cout << sum << endl;




	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define inf 200000
int max(int a,int b){
  return (a<b?b:a);
}
int min(int a,int b){
  return (a<b?a:b);
}

int main(){
int n;
int minv;
int maxv;
scanf("%d¥n",&n);
int r[inf];
for(int j;j<n;j++){
  scanf("%d\n",&r[j]);
}
maxv= -2e9;
minv = r[0];
for (int i = 1;i< n;i++) {
  maxv=max(r[i]-minv,maxv);
  minv=min(r[i],minv);

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



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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define list_input(x, n) x[n]; rep(i,n){ cin >> x[i];}
#define ll long long

int main(){
  int N, count = 0;
  cin >> N;
  ll M = 5555;
  int arr[M+1];
  for(int i = 0; i < M; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(M); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < M; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for(int i = 2; i < M; i++){
    if (count >= N) {
      cout << '\n';
      break;
    }
		if(arr[i]){
      string st = to_string(i);
      if (st[st.size()-1] == '1') {
        cout << to_string(i) << " ";
        count += 1;
      }
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;


int main() {

	ios::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);

	ll n, m;	cin >> n >> m;
	ll sum = 0, cnt = 0;

	vector <ll> v(n);

	rep(i, n) {
		cin >> v[i];
		sum += v[i];
	}

	m = 4 * m;
	sum = (sum + m - 1) / m;

	m = m / 4;

	rep (i, n) {
		if (v[i] >= sum)
			cnt++;
	}

	if (cnt >= m)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):

    n = len(S)
    p = S[0:(n-1)//2]
    q = S[(n+1)//2:]
    # print(p,q)
    if p==q:
        print(YES)
    else:
        print(NO)    

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<unordered_set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
const ll mod=1e9+7;

/*
wa
*/

ll n,m,dp[310][310][310],ans=0;//(r,g,b)を最後に塗った場所
vector<mp> v[310];

int main(void){
	rep(i,310)rep(j,310)rep(k,310)dp[i][j][k]=0;
	cin>>n>>m;
	rep(i,m){
		ll l,r,x;
		cin>>l>>r>>x;
		v[r].push_back(make_pair(l,x));
	}
	dp[1][0][0]=3;
	reg(i,1,n){//実はr,g,bは等価なので，r>g>bとして纏められる
		reg(j,0,i-1){
			reg(k,0,max(0,j-1)){
				// if()continue;
				bool ok=true;
				rep(t,v[i].size()){
					ll l=v[i][t].first,x=v[i][t].second,cnt=0;
					if(i>=l)cnt++;
					if(j>=l)cnt++;
					if(k>=l)cnt++;
					if(cnt!=x){
						ok=false;
						break;
					}
				}
				if(!ok)continue;
				if(i==n){
					ans=(ans+dp[i][j][k])%mod;
				}else{
					dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%mod;
					dp[i+1][i][k]=(dp[i+1][i][k]+dp[i][j][k])%mod;
					dp[i+1][i][j]=(dp[i+1][i][j]+dp[i][j][k])%mod;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 232960
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int X,t;
	cin>>X>>t;

	cout<<(X > t ? (X-t) : 0)<<endl;
	return 0;
}


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

using namespace std;

#define ll long long

int N;
string W[105];
set<string> ST;

void solve(){
    bool flag = true;
    if(ST.size() != N)
        flag = false;
    else{
        for(int i = 0; i < N-1; i++)
            if(W[i].back() != W[i+1].front()) flag = false;
    }
    if(flag)          
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(){
    cin >> N;

    for(int i = 0; i < N; i++){
        cin >> W[i];
        ST.insert(W[i]);
    }

    solve();
}


Measured memory_bytes: 256
from sys import stdin
#from collections import deque
#from math import ceil


def ii(): return int(stdin.readline())


def fi(): return float(stdin.readline())


def mi(): return map(int, stdin.readline().split())


def fmi(): return map(float, stdin.readline().split())


def li(): return list(mi())


def lsi():
    x=list(stdin.readline())
    x.pop()
    return x


def si(): return stdin.readline()


def sieve(x):
    a=[True]*(x+1)
    sq=floor(sqrt(x))
    for i in range(3, sq+1, 2):
        if a[i]:
            for j in range(i*i, x+1, i):
                a[j]=False
    if x>1:
        p=[2]
    else:
        p=[]
    for i in range(3, x+1, 2):
        if a[i]:
            p.append(i)
    return p
#vowel={'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y'}
#pow=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808]
############# CODE STARTS HERE #############
n, m=mi()
a=li()
a.sort(reverse=True)
m=min(n, m)
print(sum(a[m:]))

Measured memory_bytes: 25756
n, m = gets.split.map(&:to_i)
a = Array.new(n){[]}
m.times do
    x, y = gets.split.map(&:to_i)
    a[x - 1] << y - 1
    a[y - 1] << x - 1
end
c = Array.new(n){0}
que = []
que << 0
while que.size > 0
  e = que.shift
  a[e].each do |i|
    next if c[i] > 0
    c[i] = e + 1
    que << i
  end
end
puts "Yes", c[1..-1]

Measured memory_bytes: 32748
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c, s, e) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1l)
const int M = 1000000007;
const int N = 3e5 + 5;
const long long INF = 1e18 + 37;

#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif


void solve(){
    int n;
    cin >> n;
    map<string , int > mp;
    for(int i=0; i<n ;i++){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

}


signed main() {
    FAST
    int tc = 1;
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}

Measured memory_bytes: 3664
r=Array.new
cheese=Array.new
50.times{
r=Array.new
cheese=Array.new
	cheese = gets.chomp.split(" ").map{|i| i.to_i}
	cheese.sort!
	min=cheese[0]**2 +cheese[1]**2
	
	if cheese[0]==0 && cheese[1] == 0 && cheese[2] ==0
		break
	end
	n = gets.chomp.to_i
	n.times{
	r << gets.to_i
	



	
	}
	r.each{|i|
		if (i*2)**2 > min
			puts "OK"
		else
			puts "NA"
		end
	}
}

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

using namespace std; 

#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fp(i,a,b,p) for(int i=a;i<b;i+=p)
#define SZ(x) (int)x.size()

typedef  vector<string> vs;
typedef  vector<int> vi;
typedef  vector<long long> vl;	


int main(){
	
	
	int n , k; 

	
	cin >> n >> k;
	
		
	vi v(n);
	
	f(i,0,n){
		cin >> v[i];
	}
	
	int ans = 0;
	
	while(1){
		n-=k;
		ans++;
		if(n<=0) break;
		n++; 
	}
	
	cout << ans << endl;
	

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int res=0;
bool judge(int i,int a,int b){
  int buf=i;
  int sum=0;
  bool flag=true;
  while(buf>0){
    sum+=buf%10;
    buf/=10;
  }
  flag=sum>=a&&sum<=b;
  if(flag){
    res+=i;
  }
  return flag;
}
signed main(){
  int n;cin>>n;
  int a,b;cin>>a>>b;
  //int res=0;
  rep1(i,n){
    if(judge(i,a,b)){
      //res++;
    }
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Text.Printf

main = do
  line <- readline
  let aa = Point { x = line !! 0, y = line !! 1}
  let bb = Point { x = line !! 2, y = line !! 3}
  let l = Line aa bb
  q <- readLn
  input <- replicateM q getLine
  let xs = fmap (fmap (read :: String -> Double) . words) input
  let result = fmap (\e -> (x $ res l (e !! 0) (e !! 1), y $ res l (e !! 0) (e !! 1))) xs
  mapM_  (\r -> (printf "%.8f %.8f\n" (fst r) (snd r))) result
    where res l x1 y1 = l `reflect` Point{x=x1,y=y1}

readline :: (Read a) => IO [a]
readline = fmap (fmap read . words) getLine


eps :: (Floating a) => a
eps = 1e-7

add :: (Ord a, Floating a) => a -> a -> a
add a b
  | abs (a + b) < eps * (abs a + abs b ) = 0.0
  | otherwise = a + b

data Point a = Point { x :: a, y :: a } deriving (Eq)
data Line a = Line {a :: Point a, b :: Point a}

(^+) :: (Ord a, Floating a) => Point a -> Point a -> Point a
a ^+ b =  Point (add (x a) (x b)) (add (y a) (y b))

(^-) :: (Ord a, Floating a) => Point a -> Point a -> Point a
a ^- b = Point (add (x a) (-(x b))) (add (y a) (-(y b)))

(^*) :: (Floating a) => Point a -> a -> Point a
a ^* d = Point (x a * d) (y a * d)

dot :: (Floating a) => Point a -> Point a -> a
a `dot` b = x a * x b + y a * y b

project :: (Ord a, Floating a) => Line a -> Point a -> Point a
l `project` p = a l ^+ (base ^* t)
  where base = b l ^- a l
        t = ((p ^- a l) `dot` base) / (base `dot` base)

reflect :: (Ord a, Floating a) => Line a -> Point a -> Point a
l `reflect` p = p ^+ (((l `project` p) ^- p) ^* 2.0)

Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,x;
  cin >> n >> x;
  vi b(n),l(n),u(n);
  REP(i,n) cin >> b[i] >> l[i] >> u[i];
  int d0 = 0;
  REP(i,n) d0 += b[i]*l[i];
  V<pii> f(n);
  REP(i,n) f[i].fi = (x-b[i])*u[i]+b[i]*l[i], f[i].se = i;//pairのfirstには各数列の総和、secondにはindexを入れておく。
  sort(rALL(f));//降順ソート
  int le = -1,ri = n*x;
  //(le,ri]で二分探索
  while(le+1<ri){// lower_bound
    int m = (le+ri)/2;
    int k = m;
    int q = k/x;
    int sum = 0;
    REP(i,q) sum += f[i].fi;
    int mx = sum;
    int r = k - q*x;
    RREP(i,n){
      int a = l[f[i].se]*min(b[f[i].se],r)+u[f[i].se]*max(0LL,r-b[f[i].se]);
      if(i<q) sum += f[i+1].fi - f[i].fi;
      maxs(mx,sum+a);
    }
    if(mx<d0) le = m;
    else ri = m;
  }
  cout << ri << endl;
}


Measured memory_bytes: 4224
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a;
    scanf("%d",&a);
    int t=0,i;
    long int b[20000000],k=0;
    for(i=0;i<a;i++){
        scanf("%ld",&b[i]);
        if(t<b[i]) t=b[i];
        else k+=t-b[i];
    }
    printf("%ld",k);
    return 0;
}



Measured memory_bytes: 3700
N = int(input())
L = list(map(int,input().split()))

count =0


for i in range(0, N-1):
    for n in range(0,N-1):
        if(L[n]>L[n+1]):
            tmp = L[n]
            L[n] = L[n+1]
            L[n+1] = tmp            

for i in range(0,N):
    for n in range(0,N):
        for l in range(0,N):
            if i < n and n<l:
                if L[i] != L[n]:
                    if L[n] != L[l]:
                        if L[i] != L[l]:
                            if L[i]+L[n]> L[l]:
                                count +=1

print(count)



Measured memory_bytes: 9132
using System;
namespace q1
{
  class q2
  {
    static void Main()
    {
      string[] x = Console.ReadLine().Split();
      int a = int.Parse(x[0]);
      int b = int.Parse(x[1]);
      if (a * 2 <= b && b <= a * 4 && b % 2 == 0)
      {
        Console.WriteLine("Yes");
      }
      else
      {
        Console.WriteLine("No");
      }
    }
  }
}


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

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)
#define input_c(x) scanf("%c", &x);

#define BS 1001

int main(int argc, char const *argv[]) {
    char S[BS];
    input_s(S);
    switch(S[0]) {
        case 'S':
            printf("Cloudy");
            break;
        case 'C':
            printf("Rainy");
            break;
        case 'R':
            printf("Sunny");
            break;
        default:
            break;
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define mod 998244353
#define DEBUG 1
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define range 200010
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#define endl '\n'
#endif

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
	cerr << *it << " = " << a <<" ";
	err(++it, args...);
}


int main(){

	//freopen("test.txt","r",stdin);
	ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int a,b;cin>>a>>b;
	cout<<max(a+b,max(a*b,a-b))<<endl;;

	
	
    return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int N, A;
	cin >> N >> A;
	OUT(N*N - A);
}

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

vector<vector<int>> r;
int n, k;

int sum(int y, int x, int Y, int X) {
  return (r[Y][X] - r[Y][x] - r[y][X] + r[y][x]);
}

int query(int y, int x) {
  return sum(0, 0, y, x) + sum(y, x, y + k, x + k) + sum(y + k, x + k, 2 * k, 2 * k) + sum(0, x + k, y, 2 * k) +
         sum(y + k, 0, 2 * k, x);
}

int main() {
  cin >> n >> k;
  r.assign(2 * k + 1, vector<int>(2 * k + 1, 0));
  for (int i = 0; i < n; ++i) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    if (c == 'W') x += k;
    x %= 2 * k;
    y %= 2 * k;
    r[y + 1][x + 1]++;
  }

  for (int i = 0; i < r.size(); ++i) {
    for (int j = 1; j < r.size(); ++j) {
      r[i][j] += r[i][j - 1];
    }
  }
  for (int j = 0; j < r.size(); ++j) {
    for (int i = 1; i < r.size(); ++i) {
      r[i][j] += r[i - 1][j];
    }
  }

  int ans = 0;
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      ans = max({ans, query(i, j), n - query(i, j)});
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 16000
def ok(_to: int, _from: int, S: str)->bool:
    '''_to から _from へ行けるかどうかを判定する
    '''
    for i in range(_to, _from+1):
        if i < _from and S[i] == '#' and S[i+1] == '#':
            return False
    return True


def kenken_race(N: int, A: int, B: int, C: int, D: int, S: str)->bool:
    if not ok(A, C, S) or not ok(B, D, S):
        return False

    if C < D:
        # ふぬけくんの方が右にいることは保障されている。
        # この時、ふぬけくんのゴールがすぬけくんのそれより右なら
        # 先にふぬけくんをゴールさせてしまえばいい。
        return True

    # ふぬけくんのゴールの方が左にある場合はどこかですぬけくんが追い抜かないといけない
    # そのスペースがあるかを確認する。
    # 具体的にはふぬけくんのスタートからゴールまでの間に '.' が 3 つ以上連続する点があれば良い。
    for i in range(B, D+1):
        if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
            return True
    return False


if __name__ == "__main__":
    N, A, B, C, D = map(int, input().split())
    S = input()

    yes = kenken_race(N, A-1, B-1, C-1, D-1, S)
    print('Yes' if yes else 'No')


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

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

  if(a <= 5)
  {
    r = 0;
  }
    if(a <= 12 && a>=6)
  {
    r = b/2;
  }
      if(a > 12)
  {
    r = b;
  }
  
  cout << r;
}

Measured memory_bytes: 256