akhauriyash/Code-Regression huggingface dataset:
use std::cmp::min;
use std::io::stdin;

fn main() {
    const W: usize = 101;
    const H: usize = 101;
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut t = s.split_whitespace().map(|e| e.parse().unwrap());
    let h: usize = t.next().unwrap();
    let w: usize = t.next().unwrap();
    let mut v = vec![vec![0; W]; H];
    for i in 0..h {
        let mut s = String::new();
        stdin().read_line(&mut s).ok();
        let mut t = s.chars();
        for j in 0..w {
            let n = t.next().unwrap();
            v[i][j] = if n == '#' { 1 } else { 0 };
        }
    }

    println!("{}", solve(&mut v, h, w));
}
fn solve(v: &mut Vec<Vec<usize>>, height: usize, width: usize) -> i32 {
    let mut dp = vec![vec![0; 101]; 101];
    let mut black = false;
    let mut t = 0;
    for i in 0..width {
        dp[0][i] = if v[0][i] == 1 && !black {
            black = true;
            t += 1;
            t
        } else if v[0][i] == 1 {
            t
        } else {
            black = false;
            t
        };
    }

    black = false;
    t = 0;

    for i in 0..height {
        dp[i][0] = if v[i][0] == 1 && !black {
            black = true;
            t += 1;
            t
        } else if v[i][0] == 1 {
            t
        } else {
            black = false;
            t
        };
    }

    for i in 1..height {
        for j in 1..width {
            let t1 = dp[i - 1][j]
                + if v[i - 1][j] == 0 && v[i][j] == 1 {
                    1
                } else {
                    0
                };
            let t2 = dp[i][j - 1]
                + if v[i][j - 1] == 0 && v[i][j] == 1 {
                    1
                } else {
                    0
                };
            dp[i][j] = min(t1, t2);
        }
    }

    dp[height - 1][width - 1]
}


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

int main(){
  int n;
  cin >> n;
  vector<double> a(n),b(n-1);
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  double r = a.at(n-1);
  for(int i = 0;i < n-1;i++){
    b.at(i) = a.at(i);
    a.at(i) = abs(a.at(i) - r/2);
  }
  double x = 1000000007;
  int r2;
  for(int i = 0;i < n-1;i++){
    if(x >= a.at(i)){
      r2 = i;
      x = a.at(i);
    }
  }
  int t = r,s = b.at(r2);
  cout << t << " " << s << endl;
}

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

namespace ABC146A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            int day = 0;

            switch (S)
            {
                case "SUN":
                    day = 7;
                    break;
                case "MON":
                    day = 6;
                    break;
                case "TUE":
                    day = 5;
                    break;
                case "WED":
                    day = 4;
                    break;
                case "THU":
                    day = 3;
                    break;
                case "FRI":
                    day = 2;
                    break;
                case "SAT":
                    day = 1;
                    break;
            }

            Console.WriteLine(day);
            Console.ReadLine();
        }
    }
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      ans += vec.at(i);
    }
    else {
      ans -= vec.at(i);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> H(N);
	for (auto& x : H) cin >> x;
	vector<vector<int>> G(N);
	for (int i = 0; i < M; ++ i) {
		int u, v;
		cin >> u >> v;
		-- u; -- v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int res = 0;
	for (int i = 0; i < N; ++ i) {
		for (int j : G[i]) {
			if (H[i] <= H[j]) goto next;
		}
		++ res;
		next:;
	}
	cout << res << endl;
}


Measured memory_bytes: 8748
#include <iostream>
#define MAX 100001

using namespace std;

int par[MAX],rank[MAX],n,m;

void init(void){
  for(int i = 0 ; i < MAX ; i++){
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x,int y){
  x = find(x); y = find(y);
  if(x == y) return;
  
  if(rank[x] < rank[y]){
    par[x] = y;
  } else {
    par[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}

int main(void){
  int com,x,y;
  init();
  cin >> n >> m;
  for(int i = 0 ; i < m ; i++){
    cin >> com >> x >> y;
    if(com){
      same(x,y);
      if(par[x] == par[y]) cout << '1' << endl;
      else cout << '0' << endl;
    }
    else unite(x,y);
  }
  return 0;
}

Measured memory_bytes: 1932
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n;cin >> n;
    vl v(n+1),w(n+1);
    ll k=log2(n)+1;
    ll mid=k/2;
    repl(i,1,n+1){
        cin >> v[i] >> w[i];
    }
    vvl g((1<<mid),vl(100010,0));
    repl(i,1,(1<<mid)){
        rep(j,100010){
            if(j+w[i]<=100000)chmax(g[i][j+w[i]],g[i/2][j]+v[i]);
            chmax(g[i][j],g[i/2][j]);
        }
    }
    ll q;cin >> q;
    while(q--){
        ll s,l;cin >> s >> l;
        if(s<(1<<mid)){
            cout << g[s][l] <<endl;
            continue;
        }
        ll res=0;
        vpl use;
        while(s>=(1<<mid)){
            use.pb({w[s],v[s]});
            s/=2;
        }
        ll t=use.size();
        vl tv,tw;
        rep(bit,1<<t){
            ll a=0,b=0;
            rep(i,t){
                if(bit&(1<<i)){
                    a+=use[i].fi;
                    b+=use[i].se;
                }
            }
            tw.pb(a);tv.pb(b);
        }
        rep(i,tw.size()){
            if(tw[i]>l)continue;
            chmax(res,tv[i]+g[s][l-tw[i]]);
        }
        cout << res <<endl;
    }
}

Measured memory_bytes: 409748
# -*- coding: utf-8 -*-
from heapq import heappush, heapreplace
from itertools import count, product, combinations
from functools import partial, reduce
from math import floor, ceil, sqrt
from collections import defaultdict, deque

def Primes_fnct():
    def b_search(L,t):
        #増大列LについてL[:+1]の要素すべてがt以下であるような最大のi<len(L)を返す。
        search_range = [-1, len(L)]
        update_range = lambda mid: search_range.__setitem__(t<L[mid], mid)
        for _ in [0]*search_range[1].bit_length():
            update_range(sum(search_range)//2)
        return search_range[0]
    
    P = [2,]
    Pappend = P.append
    Q = deque([])
    Qappend = Q.append
    Qpopleft = Q.popleft
    hq = [] 
    integer = count(3,2)
    current_i = 1
    valid_range = 1
    def Primes(*, max_int=None):
        nonlocal valid_range, current_i
        if max_int is None:
            return P[:]

        if  max_int - current_i <= 1:
            return P[:b_search(P,max_int)+1]

        for i in integer:
            if i >= valid_range:
                if Q:
                    q = Qpopleft()
                    heappush(hq, (q**2,q))
                valid_range = Q[0]**2 if Q else i**2

            m,r = hq[0] if hq else (0,0)
            if i != m:
                Pappend(i)
                Qappend(i)

            while m == i:
                heapreplace(hq, (m+2*r, r))
                m,r = hq[0]

            current_i = i
            if max_int - current_i <=1:
                break 
        return P[:]
    return Primes

def factorization(m, Primes=None):
    F = defaultdict(int)
    if m < 2:
        return F

    while not m&1:
        F[2] += 1
        m >>= 1

    if Primes is None:
        Primes = Primes_fnct()

    Primes = deque(Primes(max_int=ceil(sqrt(m))+1))
    Primespopleft = Primes.popleft

    while m > 1 and Primes:
        p = Primespopleft()
        while not m%p:
            m //= p
            F[p] += 1

    if m > 1:
        F[m] += 1
    return F

def solve():
    N = int(input())
    res = 0
    flag = 1
    for d in range(3,10):
        if not flag:
            break
        for i in product('357', repeat=d):
            if set(i) == {'3','5','7'}:
                if int(''.join(i)) <= N:
                    res += 1
                else:
                    flag = 0
                    break
    return res



if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3828
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int l,r,d,ans=0;
            cin>>l>>r>>d;
            for(int i=d;i<=r;i=i+d)
                if(i>=l)
                    ++ans;
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}
map<ll,ll> prime_factor(ll x){
    map<ll,ll> m;
    ll sq=(ll)sqrt(x) + 1;
    vector<ll> v_prime=vectorprime(sq);
    
    ll tmp=x;
    rep(i,sz(v_prime)){
        ll count=0;
        while(tmp % v_prime[i] == 0){
            tmp /= v_prime[i];
            count++;
        }
        if(count != 0) m[v_prime[i]]=count;
        if(tmp==1) break;
    }
    
    if(tmp != 1) m[tmp]=1;
    return m;
}

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    vector<ll> A(N);
    bool c=false;
    rep(i,N){
        cin>>A[i];
        if(A[i]%2==1) c=true;
    }
    
    if(c) cout<<"first";
    else cout<<"second";
}



Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
int n, c[200010], dp[200010];
int main() {
	scanf("%d", &n);
	vector<int> V;
	for(int i=1; i<=n; i++) {
		scanf("%d", c+i);
		V.push_back(c[i]);
	}
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());
	for(int i=1; i<=n; i++)
		c[i] = lower_bound(V.begin(), V.end(), c[i]) - V.begin() + 1;
	const int MOD = 1e9 + 7;
	int ans = 1;
	for(int i=1; i<=n; i++) {
		if(c[i] != c[i-1]) {
			int old = ans;
			ans = (ans + dp[c[i]]) % MOD;
			dp[c[i]] = (dp[c[i]] + old) % MOD;
		}
		//printf("i:%d ,ans:%d\n", i, ans);
	}
	printf("%d", ans);
	return 0;
}

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

int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    int c = 0;
    for(int i = a; i <= b; i++) {
        int p = i % 10, q = i / 10000 % 10;
        int r = i / 10 % 10, s = i / 1000 % 10;
        if(p == q && r == s)
            c++;
    }

    printf("%d\n", c);
}

Measured memory_bytes: 1704
from heapq import heappush, heappop, heapify
def prim(n, graph):
    used = [False] * n
    hq = [(w, v) for v, w in graph[0]]
    heapify(hq)
    used[0] = True
    res = 0
    while hq:
        w, v = heappop(hq)
        if used[v]:
            continue
        used[v] = True
        res += w
        for cv, cw in graph[v]:
            if used[cv]:
                continue
            heappush(hq, (cw, cv))
    return res

V, E = map(int, input().split())
graph = [[] for _ in range(V)]
for _ in range(E):
    s, t, w = map(int, input().split())
    graph[s].append((t, w))
    graph[t].append((s, w))
print(prim(V, graph))


Measured memory_bytes: 37264
#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;
const int MAXN = 4100;

int N;
int loc[2][MAXN];
int dp[MAXN][MAXN];
int nintersect[2][MAXN][MAXN];

int main()
{
    cin >> N;
    for (int i = 0; i < 2 * N; i++)
    {
        char c;
        int x;
        cin >> c >> x;
        x--;
        if (c == 'B')
            loc[0][x] = i;
        else
            loc[1][x] = i;
    }

    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < N; j++)
        {
            int cloc = loc[i][j];
            int res = 0;
            nintersect[i][j][N] = res;
            for (int k = N - 1; k >= 0; k--)
            {
                if (cloc > loc[1-i][k])
                    res++;
                nintersect[i][j][k] = res;
            }
        }
    }

    for (int i = 0; i <= N; i++)
        for (int j = 0; j <= N; j++)
            dp[i][j] = MAXN * MAXN;
    dp[0][0] = 0;

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N; j++)
        {
            if (i < N)
            {
                dp[i+1][j] = min (dp[i+1][j], dp[i][j] + nintersect[0][i][j]);
            }
            if (j < N)
            {
                dp[i][j+1] = min (dp[i][j+1], dp[i][j] + nintersect[1][j][i]);
            }
        }
    }

    int ans = dp[N][N];
    for (int i = 0; i < N; i++)
        for (int j = i + 1; j < N; j++)
        {
            if (loc[0][i] > loc[0][j])
                ans++;
            if (loc[1][i] > loc[1][j])
                ans++;
        }
    cout << ans << "\n";
}

Measured memory_bytes: 98048
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <array>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <random>
#include <chrono>
#include <fstream>

#define PI 3.14159265359
#define mt make_tuple
#define mp make_pair
#define pii pair <int, int>
#define pll pair <long long, long long>
#define all(x) (x).begin(), (x).end()

//mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

const int MOD = 1000000007;

int main()
{
	int N;
	cin >> N;
	vector < pair <long long, long long> > points(N + 1, mp(0, 0));
	long long answer = 0;
	long long mn = (1LL << 60);
	long long mx = -(1LL << 60);
	for (int i = 1; i <= N; ++i)
	{
		cin >> points[i].first >> points[i].second;
		mn = min(mn, points[i].first + points[i].second);
		mx = max(mx, points[i].first + points[i].second);
	}
	answer = max(answer, mx - mn);
	mn = (1LL << 60);
	mx = -(1LL << 60);
	for (int i = 1; i <= N; ++i)
	{
		mn = min(mn, points[i].first - points[i].second);
		mx = max(mx, points[i].first - points[i].second);
	}
	answer = max(answer, mx - mn);
	cout << answer << "\n";
	return 0;
}


Measured memory_bytes: 5992
#include<iostream>

using namespace std;

int ans[30];

// 残りn個をans[m]から入れる
void solve(int n, int m){
  if(n == 0) {
    //プリント
    for(int i = 0; i< m-1; i++){
      cout << ans[i] <<" ";
    }
    cout <<ans[m-1] << endl;
  }
  
  else {
    for(int i = n; i>0 ;i--){
      if(m>0 && i > ans[m-1]) continue;
      
      ans[m] = i;
      solve(n-i,m+1);
    }
  }
}

int main(){
  int n;
  while(cin >> n && n){
  solve(n,0);
  }
  return 0;
}
  

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

using namespace std;
typedef long long ll;

const int N = int(1e8) + 7;

void init(){

}

void solve(){
    int A[55];
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    if(is_sorted(A, A+n)){
        printf("YES\n");
        return;
    }
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            swap(A[i], A[j]);
            if(is_sorted(A, A+n)){
                printf("YES\n");
                return;
            }
            swap(A[i], A[j]);
        }
    }
    printf("NO\n");
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}



Measured memory_bytes: 256
A,B,C,D,E,F = map(int,input().split())
p = -1
a = [0,0]

for i in range(0,F+1,A*100):
    for j in range(0,F+1-i,B*100):
        for k in range(0,int(E*(i+j)/100)+1,C):
            for l in range(0,int(E*(i+j)/100)+1-k,D):
                if i+j+k+l > F:
                    continue
                if i+j > 0 and p < (k+l) / (i+j+k+l):
                    p = (k+l) / (i+j+k+l)
                    a = [i+j+k+l,k+l]
print(a[0],a[1])

Measured memory_bytes: 3064
K=int(input())
from math import gcd
s=0
G=[[0 for i in range(K)] for i in range(K)]
for i in range(0,K):
    for j in range(0,K):
        G[i][j]=gcd(i+1,j+1)
for a in range(0, K):
    for b in range(0,K):
        for c in range(0,K):
            s+=G[G[b][c]-1][a]
print(s)

Measured memory_bytes: 9420
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    static FastIO io = new FastIO("in.txt");

    public static void main(String[] args) throws Exception {
        long X, K, D;
        X = io.nextLong(); K = io.nextLong(); D = io.nextLong();
        X = Math.abs(X);
        long ans = X % D;

        long n = X / D;
        if(n < K){
            if((K - n) % 2 == 0) {
                ans = X % D;
            }else{
                ans = D - (X % D);
            }
        }else{
            ans = X - K * D;
        }

        io.println(ans);
        io.flush();
    }

    static class FastIO {
        static StringBuilder sb = new StringBuilder();
        static BufferedReader br;
        static StringTokenizer st;
        static PrintStream ps = new PrintStream(System.out);

        public FastIO(String fname) {
            try {
                File input = new File(fname);
                if (input.exists()) {
                    System.setIn(new FileInputStream(fname));
                }
            }catch (Exception e){
                e.printStackTrace();
            }

            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        void flush(){
            System.out.print(sb.toString());
            sb.setLength(0);
        }

        void print(Object o){
            sb.append(o);
        }

        void println(Object o){
            sb.append(o);
            sb.append('\n');
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(vector<A> v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

constexpr int MOD = 1000000007;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  vector<long long> a(2);
  cin >> n >> a[0] >> a[1];
  long long ans;
  ans = powmod(2, n, MOD) - 1;
  ans %= MOD;
  debug(ans);
  for (const auto& c : a) {
    long long num = 1, den = 1;
    for (int i = 0; i < c; i++) {
      num *= n - i;
      num %= MOD;
      den *= (i + 1);
      den %= MOD;
    }
    debug(num, den);
    long long den_inv = powmod(den, MOD - 2, MOD);
    debug(den_inv);
    long long elim = num * den_inv % MOD;
    ans -= elim;
    ans %= MOD;
  }
  ans %= MOD;
  cout << (ans < 0 ? MOD + ans : ans) << '\n';
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>

using namespace std;
#define int long long

signed main()
{
	string X;
	cin >> X;

	int i, j, k, ans = 0, s = 0, t = 0;
	for (i = 0; X[i]; i++){
		if (X[i] == 'S')s++;
		if (X[i] == 'T'){
			t++;
			if (s > 0){
				t--;
				s--;
			}
		}
	}

	cout << t + s << endl;

	return 0;
}

Measured memory_bytes: 640
N = int(input())
H = list(map(int, input().split()))

dp = [None] * N
dp[0] = 0
dp[1] = abs(H[1]-H[0])

for n in range(2, N):
    dp[n] = min(dp[n-2]+abs(H[n]-H[n-2]),
                dp[n-1]+abs(H[n]-H[n-1]))

print(dp[N-1])


Measured memory_bytes: 13980
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import Data.Ix
import Data.Ord (Down(Down))
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

modN = 1000000007

pow :: Num a => a -> Int -> a
pow base 0 = 1
pow base 1 = base
pow base time
    | odd time = let
        a = pow base (div time 2)
        in
        a * a * base
    | otherwise = let
        a = pow base (div time 2)
        in
        a * a

inv :: ModNum -> ModNum
inv a = pow a $ modN - 2

newtype ModNum = ModNum {getInt :: Int} deriving (Show, Eq, Ord)
instance Num ModNum where
    (+) (ModNum a) (ModNum b) = ModNum $ mod (a + b) modN
    (-) (ModNum a) (ModNum b)
            | a < b = (ModNum $ a + modN) - ModNum b
            | otherwise = ModNum $ mod (a - b) modN
    (*) (ModNum a) (ModNum b) = ModNum $ mod (a * b) modN
    abs (ModNum a)
            | a < 0 = abs . ModNum $ a + modN
            | otherwise = ModNum a
    signum (ModNum a) = ModNum $ signum a
    fromInteger i = abs . ModNum . fromIntegral $ mod i (fromIntegral modN)

mDiv :: ModNum -> ModNum -> ModNum
mDiv a b = a * inv b

solve :: [(Int, Int)] -> Int -> Int
solve ((a, b):xs) k
      | k <= b = a
      | otherwise = solve xs (k - b)


main :: IO ()
main = do
  (n, k) <- readTuple2
  ab <- sortOn fst <$> replicateM n readTuple2
  print $ solve ab k


Measured memory_bytes: 56700
#include <bits/stdc++.h>
using namespace std;
int n, a[22], b[22];

int main() {
    cin>>n;
    int sum = 0;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++) {
        cin>>b[i];
        if(a[i] > b[i]) sum += (a[i] - b[i]);
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=[]
for i in range(n-k+1):
    temp=abs(0-x[i])+abs(x[i]-x[k+i-1])
    ans.append(temp)
    temp_2=abs(x[n-1-i])+abs(x[n-1-i]-x[n-i-k])
    ans.append(temp_2)
print(min(ans))


Measured memory_bytes: 14384
K, N = map(int, input().split())
A = [int(n) for n in input().split()]
distances = []
for i in range(N):
    if i == 0:
        distances.append(A[0] + (K - A[N - 1]))
    else:
        distances.append(A[i] - A[i - 1])
distances.sort()
distances.pop(N - 1)
print(sum(distances))


Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
const double EPS = 1e-8;

double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

double area(vector<P> v){
  double sum = 0.0;
  int n = v.size();
  for(int i=0;i<n;i++) sum += (real(v[i]) - real(v[(i+1)%n])) * (imag(v[i]) + imag(v[(i+1)%n]));
  return fabs(sum) / 2;
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

vector<P> convex_cut(vector<P> G, L l){
  vector<P> ans;
  for(int i=0;i<G.size();i++){
    P A = G[i];
    P B = G[(i+1)%G.size()];
    if(ccw(l.first, l.second, A) != -1) ans.push_back(A);
    if(ccw(l.first, l.second, A) * ccw(l.first, l.second, B) < 0)
      ans.push_back(crossPoint(L(A,B), l));
  }
  return ans;
}

int n,m;
vector<P> mp;
double calc(int idx,vector<P>g){
  for(int i=0;i<m;i++){
    if(i==idx)continue;
    P t=mp[idx]-mp[i];
    P a=P(abs(t)/2,1)*t/abs(t)+mp[i];
    P b=P(abs(t)/2,-1)*t/abs(t)+mp[i];
    g=convex_cut(g,L(a,b));
  }
  return area(g);
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    vector<P> pl(n);
    mp.resize(m);
    for(int i=0,x,y;i<n;i++)cin>>x>>y,pl[i]=P(x,y);
    for(int i=0,x,y;i<m;i++)cin>>x>>y,mp[i]=P(x,y);
    for(int i=0;i<m;i++)printf("%.10f\n",calc(i,pl));
  }
  return 0;

}

Measured memory_bytes: 3268
from statistics import median
n = int(input())
nums = list(map(int,input().split()))
bs = nums[:]
tmp =0

for i in range(n):
  bs[i] -= i+1

med = median(bs)

for i in range(n):
  tmp += abs(nums[i]-(med+(i+1)))

print(int(tmp))

Measured memory_bytes: 27244
def inputTable(a):
	lit=[]
	for aa in range(a):
		lit.append(list(map(int,input().split())))
	return lit

def kouten(dai):
	x=dai[0]
	dai[0]=dai[1]
	dai[1]=dai[5]
	dai[5]=dai[4]
	dai[4]=x
	return(dai)
def sokuten(dai):
	x=dai[0]
	dai[0]=dai[2]
	dai[2]=dai[5]
	dai[5]=dai[3]
	dai[3]=x
	return(dai)

def tokei(dai):
	dai1 = dai[1]
	dai[1] = dai[2]
	dai[2] = dai[4]
	dai[4] = dai[3]
	dai[3] = dai1
	return(dai)

def check(dai,daini):
	for j in range(4):
		if daini[0] == dai[0] and daini[1] == dai[1] and daini[2] == dai[2] and daini[3] == dai[3] and daini[4] == dai[4] and daini[5] == dai[5]:
			print('No')
			return True
		tokei(dai)
	return False

def checkup(a,b):
	for unuse in range(3):
		if not check(a,b):
			kouten(a)
		else:
			return True
		if not check(a,b):
			sokuten(a)
			if unuse==2 :
				if	not check(a,b) :
					return	False  
		else:
			return True

n=int(input())
daise=inputTable(n)
k=0
R=0
for cc in range(n):
	if k==1:
		break
	for dd in range(cc+1,n):
		if k==1:
			break
		if   checkup(daise[cc],daise[dd]):
			k=1
			break
		
if k==R:
	print('Yes')


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;

int main(){
    string s;   cin >> s;
    int n = s.size()-1;
    while(0<n){
        string nt=s.substr(0, n/2);
        string ns=s.substr(n/2, n/2);
        n -= 1;
        if(nt!=ns) continue;
        cout << 2*nt.size() << endl; return 0;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(long)N;i++)
const long LINF=0x7fffffffffffffff;
long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void AscRadix32(int A[],const int sz,const int minus)
{
  int temp[200001];
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>8*k&255]++;
    rep(i,255)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>8*k&255]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>8*k&255]++;
    rep(i,255)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>8*k&255]]=temp[sz-1-i];
  }
  rep(i,minus)temp[i]=A[sz-minus+i];
  rep(i,sz-minus)temp[minus+i]=A[i];
  rep(i,sz)A[i]=temp[i];
}
int main(void)
{
  int A[200000],N=IN(),i=0,m=0,p=0,z=0,temp;
  long K=IN(),low=-LINF/2,mid,high=LINF/2,count;
  rep(i,N){A[i]=IN();if(A[i]<0)m++;else if(A[i]>0)p++;else z++;}
  AscRadix32(A,N,m);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;else temp=0;
  if(K<=1l*m*p)high=1l;else low=-1l;
  while(high-low>1)
  {
    mid=(low+high)/2,count=0;
    if(!mid)count=1l*m*p;
    else if(mid>0)
    {
      count=1l*m*p+1l*z*(m+p)+1l*z*(z-1)/2;temp=N-1;i=m+z;
      while(i<N)
      {
        while(1l*A[temp]*A[i]>=mid){temp--;}
        if(temp>i)count+=temp-i++;else break;
      }
      temp=0;i=m-1;
      while(i>=0)
      {
        while(1l*A[temp]*A[i]>=mid){temp++;}
        if(temp<i)count+=i-temp,i--;else break;
      }
    }
    else
    {
      temp=m-1;i=N-1;
      while(i>=m+z)
      {
        while(temp>=0&&1l*A[temp]*A[i]>=mid){temp--;}
        if(temp>=0){count+=temp+1;}i--;
      }
    }
    if(count<K)low=mid;else high=mid;
  }
  return printf("%ld\n",low),0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<int, int, int> tp;
///-------------------------

int main()
{
    Phuong_; /// <3333
    int a,b;
    cin >> a >> b;
    cout << (a*b);
    return 0;
}


Measured memory_bytes: 3656
#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 INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n, m, tot;
    cin >> n >> m;
    vector<ll> a(m, 0);
    tot = n;
    REP(i, m){
        cin >> a[i];
        tot -= a[i];
    }
    if (tot < 0) cout << "-1" << endl;
    else cout << tot << endl;
    return 0;
}


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

const int MAX_N = 1e5;
int N;
int H[MAX_N];

void solve() {
    int ans = 0;
    int s = 0;

    for(int i = 0; i < N-1; i++) {
        if (H[i] >= H[i+1]) s++;
        else {
            s = 0;
        }
        ans = max(s, ans);
    }

    cout << ans << endl;
    return ;
}

int main() {
    cin >> N;
    for(int i = 0; i < N; i++) {
        scanf("%d", &H[i]);
    }

    solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
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
   string str;
   cin>>str;
   int n=str.length();
   multiset<char> s;
   for(int i=0;i<n;i++)
   {
        s.insert(str[i]);
   }
   for(auto x:s)
   {
    if(s.count(x)%2!=0)
    {
        cout<<"No";
        return 0;
    }
     }
   cout<<"Yes";
   
    return 0;
}








Measured memory_bytes: 3652
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner((System.in));

        //System.out.print("4桁の整数を入力してください\n4桁の整数:");
        int ABCD = stdIn.nextInt();

        int A = ABCD / 1000;
        int B = (ABCD - A * 1000) / 100;
        int C = (ABCD - A * 1000 - B * 100) / 10;
        int D = ABCD - (A * 1000 + B * 100 + C * 10);

        if ((A + B + C + D) ==7){
            System.out.print(A + "+" + B + "+" + C + "+" + D  + "=7");
        }
        else if((A + B + C - D)== 7){
            System.out.print(A + "+" + B + "+" + C + "-" + D + "=7");
        }
        else if((A + B - C + D)== 7){
            System.out.print(A + "+" + B + "-" + C + "+" + D + "=7");
        }
        else if((A - B + C + D)== 7){
            System.out.print(A + "-" + B + "+" + C + "+" + D + "=7");
        }
        else if((A + B - C - D)== 7){
            System.out.print(A + "+" + B + "-" + C + "-" + D + "=7");
        }
        else if((A - B - C - D)== 7){
            System.out.print(A + "-" + B + "-" + C + "+" + D + "=7");
        }
        else if((A - B + C - D)== 7){
            System.out.print(A + "-" + B + "+" + C + "-" + D + "=7");
        }
        else System.out.print(A + "-" + B + "-" + C + "+" + D + "=7");
    }
}


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

int main()
{
    int n;
    cin >> n;
    if (n < 1200)
    {
        cout << "ABC" << endl;
    }
    else if (n < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        bs: [usize; n - 1],
    }
    let mut a_s = vec![0; n];
    a_s[0] = bs[0];
    for i in 1..n {
        a_s[i] = bs[i - 1];
        if bs[i - 1] < std::cmp::max(a_s[i - 1], a_s[i]) {
            if bs[i - 1] < a_s[i - 1] && bs[i - 1] < a_s[i] {
                a_s[i - 1] = bs[i - 1];
                a_s[i] = bs[i - 1];
            } else if bs[i - 1] < a_s[i] {
                a_s[i] = bs[i - 1];
            } else if bs[i - 1] < a_s[i - 1] {
                a_s[i - 1] = bs[i - 1];
            }
        }
    }
    let ans = a_s.iter().fold(0, |sum, item| sum + item);
    println!("{}", ans);
}


Measured memory_bytes: 4352
n, m = map(int, input().split())
abc = []

INF = 10 ** 20

for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    c *= -1
    abc.append([a, b, c])

dist = [INF for _ in range(n)]
dist[0] = 0

for i in range(n - 1):
    for a, b, c in abc:
        if dist[a] == INF:
            continue
        elif dist[b] > dist[a] + c:
            dist[b] = dist[a] + c

ans = dist[n - 1]

check = [-1 for _ in range(n)]

for i in range(n - 1):
    for a, b, c in abc:
        if dist[a] == INF:
            continue
        elif dist[b] > dist[a] + c:
            dist[b] = dist[a] + c
            check[b] = 0

if check[n-1] == 0:
    print('inf')
else:
    print(-ans)




Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int H, W, K; cin >> H >> W >> K;
    vector<vector<int>> grids(H, vector<int>(W, 0));
    for (int r = 0; r < H; ++r)
    {
        int sum = 0;
        string row; cin >> row;
        for (int c = 0; c < W; ++c)
        {
            grids[r][c] = row[c] - '0';
        }
    }
    int ans = 10000;
    for (int bit = 0; bit < (1 << H); ++bit)
    {
        vector<vector<int>> whiteNums;
        vector<int> whiteNum = grids[0];
        int tmpAns = 0;
        for (int r = 1; r < H; ++r)
        {
            if (bit & (1 << r))
            {
                whiteNums.push_back(whiteNum);
                whiteNum = grids[r];
                ++tmpAns;
            }
            else
            {
                for (int c = 0; c < W; ++c)
                {
                    whiteNum[c] += grids[r][c];
                }
            }
        }
        whiteNums.push_back(whiteNum);
        int n = whiteNums.size();
        bool NG = false;
        for (int i = 0; i < n; ++i)
        {
            for (int c = 0; c < W; ++c)
            {
                if (whiteNums[i][c] > K)
                {
                    NG = true;
                    break;
                }
            }
        }
        if (NG) continue;
        vector<int> sums(n, 0);
        for (int c = 0; c < W; ++c)
        {
            bool shouldCut = false;
            for (int i = 0; i < n; ++i)
            {
                sums[i] += whiteNums[i][c];
                if (sums[i] > K)
                {
                    shouldCut = true;
                    break;
                }
            }
            if (shouldCut)
            {
                ++tmpAns;
                for (int i = 0; i < n; ++i)
                {
                    sums[i] = whiteNums[i][c];
                }
            }
        }
        ans = min(ans, tmpAns);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	r <- readInt
	b <- readInt
	print $ b + ( b - r )


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

int main(){
    int a, b;
    cin >> a >> b;
    if(a>=13){
        cout << b << endl;
    }else if(a>=6 && a<=12){
        cout << (b/2) << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)1e5 + 5;
const int mod = (int)1e9 + 7;

int n, p;
int a[60];

ll dp[60][2];

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    cin >> n >> p;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] %= 2;
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int prev = 0; prev < 2; prev++) {
            dp[i][prev] += dp[i - 1][prev];
            dp[i][(prev + a[i]) % 2] += dp[i - 1][prev];
        }
    }
    cout << dp[n][p] << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]
D={}
x=0
for a in A:
	try:
		D[a]=D[a]+((D[a]*2)**0.5//1)+1
	except:
		D[a]=0

y=sum(D.values())
for i in range(len(A)):
	x=0
	z=((D[A[i]]*2)**0.5)//1
	x=y-z
	print(int(x))


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

int main() {
    long long int N;
    cin >> N;
    int sq_N = sqrt(N);
    int a = 1;
    for (int i = 2; i <= sq_N; i++) {
        if (N % i == 0) {
            a = i;
        }
    }
    long long int b = N / a;
    long long int ans = a + b - 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
main(){
    int n;
    scanf("%lld",&n);
    int a[n+2];
    int p[n+2]; p[0] = 0, p[n+1] = n+1;
    for (int i =1 ; i <= n; i++) {
        scanf("%lld",&a[i]);
        p[a[i]] = i;
    }
    int l[n+2]; l[0] = 0;
    int r[n+2]; r[n+1] = n+1;
    int ll[n+2]; ll[0] = 0;
    int rr[n+2]; rr[n+1] = n+1;
    set<int> s; s.insert(0);
    for (int j = n; j >= 1; j--){
        int i = p[j];
        set<int>::iterator k = s.lower_bound(i);
        if (k != s.begin()){
            k = prev(k);
            l[i] = *k;
        }
        else l[i] = 0;
        if (k != s.begin()){
            k = prev(k);
            ll[i] = *k;
        }
        else ll[i] = 0;
        s.insert(i);
    }
    s.clear(); s.insert(n+1);
    for (int j = n; j >= 1; j--){
        int i = p[j];
        set<int>::iterator k = s.lower_bound(i);
        if (k != s.end()){
            r[i] = *k;
        }
        else r[i] = n+1;
        k = next(k);
        if (k != s.end()){
            rr[i] = *k;
        }
        else rr[i] = n+1;
        s.insert(i);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        int l1 = l[i] - ll[i];
        int l2 = i - l[i];
        int r1 = r[i] - i;
        int r2 = rr[i] - r[i];
        ans += a[i]*(l1*r1 + l2*r2);
    }
    printf("%lld",ans);
}


Measured memory_bytes: 9600