akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort()
ctr = defaultdict(int)
for i in range(N - 1):
    for j in range(i + 1, N):
        p = X[i][0] - X[j][0]
        q = X[i][1] - X[j][1]
        ctr[(p, q)] += 1
        ctr[(-p, -q)] += 1

if N == 1:
    print(1)
else:
    print(N - max(ctr.values()))


Measured memory_bytes: 70688
fun main(args: Array<String>) {
    val (n, m, c) = readLine()!!.split(' ').map { it.toInt() }
    val b = readLine()!!.split(' ').map { it.toInt() }

    val ans = (0 until n).filter {
        val a = readLine()!!.split(' ').map { it.toInt() }
        (0 until m).map { i ->
            a[i] * b[i]
        }.sum() + c > 0
    }.count()

    println(ans)
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  
  vector<int> D(100);
  for (int i = 0; i < n; i++) {
    D.at(A.at(i) - 1)++;
  }
  
  int mochi = 0;
  for (int i = 0; i < 100; i++) {
    if (D.at(i) > 0) {
      mochi++;
    }
  }
  cout << mochi << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int n,k;
  cin>>n>>k;
  vi cnt(n);
  rep(i,k){
    int d;
    cin>>d;
    rep(j,d){
      int a;
      cin>>a;
      cnt[a-1]++;
    }
  }
  int ans=0;
  rep(i,n){
    if(cnt[i]==0) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int INF = 999999999;

int N, M; 
struct edge { int to, cost; };
using ve = vector<edge>;

vector<ve> G(100010, ve());
vi dist(100010, INF);
vi ans(100010, -1);

void dijkstra(int s){
    // first:最短距離 second:頂点番号
    priority_queue<pii, vector<pii>, greater<pii>> q;
    dist[s] = 0;
    q.push(pii(0, s));

    while (!q.empty()){
        int cur_d = q.top().first;
        int cur_v = q.top().second;
        //cout << cur_v << endl;
        q.pop();

        if (cur_d > dist[cur_v]) continue;

        for (int i = 0; i < G[cur_v].size(); i++){
            edge e = G[cur_v][i];
            if (dist[cur_v] + e.cost < dist[e.to]){
                dist[e.to] = dist[cur_v] + e.cost;
                ans[e.to] = cur_v+1;
                q.push(pii(dist[e.to], e.to));
            }
        }
    }
}


int main(){
    cin >> N >> M;
    rep(i,M){
        int A, B; cin >> A >> B; A--; B--;
        G[A].push_back(edge{B,1});
        G[B].push_back(edge{A,1});
    }

    dijkstra(0);

    cout << "Yes" << endl;
    rep1(i,N-1) cout << ans[i] << endl;
}


Measured memory_bytes: 13624
# https://atcoder.jp/contests/abc137/tasks/abc137_e
import sys
from collections import deque

read = sys.stdin.read
INF = 1 << 60


def main():
    N, M, P, *ABC = map(int, read().split())

    G = [[] for _ in range(N)]
    G_rev = [[] for _ in range(N)]
    edge = []
    for a, b, c in zip(*[iter(ABC)] * 3):
        a -= 1
        b -= 1
        c = P - c
        G[a].append(b)
        G_rev[b].append(a)
        edge.append((a, b, c))

    # Only consider nodes that can be reached from 1 and can reach N.
    reachable_1 = [False] * N
    reachable_N = [False] * N

    reachable_1[0] = True
    reachable_N[N - 1] = True

    queue = deque([0])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if not reachable_1[nv]:
                reachable_1[nv] = True
                queue.append(nv)

    queue = deque([N - 1])
    while queue:
        v = queue.popleft()
        for nv in G_rev[v]:
            if not reachable_N[nv]:
                reachable_N[nv] = True
                queue.append(nv)

    ok = [reachable_1[i] and reachable_N[i] for i in range(N)]

    dist = [INF] * N
    dist[0] = 0

    for i in range(N):
        for a, b, c in edge:
            if not ok[a] or not ok[b]:
                continue
            if dist[b] > dist[a] + c:
                if i < N - 1:
                    dist[b] = dist[a] + c
                else:
                    print(-1)
                    return

    score = -dist[N - 1]
    print(max(score, 0))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 11300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int MOD = 1000000007;
int main() {
	int n;
	cin >> n;
	string s[50];
	int a[50][26];
	int res[26];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < 26; j++) {
			a[i][j] = 0;
			res[j] = 100000;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < s[i].size(); j++) {
			a[i][(int)(s[i][j] - 'a')]++;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) {
			res[j] = min(res[j], a[i][j]);
		}
	}
	string sol = "";

	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < res[i]; j++) {
			sol += (char)('a' + i);
		}
	}
	

	cout << sol << endl;
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>
#include <set>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

using namespace std;

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> v(m + 1, 0);
    vector<vector<int>> c(n, vector<int>(m + 1, 0));
    for (int i = 0; i < n; i++)
    {
        cin >> c[i][0];
        for (int j = 1; j <= m; j++)
        {
            cin >> c[i][j];
        }
    }

    long long ans = LONG_INF;
    for (int i = 0; i < (1 << n); i++)
    {
        vector<int> v(m + 1, 0);
        long long sum = 0;

        for (int r = 0; r < n; r++)
        {
            if (((i >> r) & 1) == 1)
            {
                sum += c[r][0];
                for (int j = 1; j <= m; j++)
                {
                    v[j] += c[r][j];
                }
            }
        }

        bool f = true;
        //cout << i << " " << sum;
        for (int j = 1; j <= m; j++)
        {
            if (v[j] < x)
            {
                f = false;
                break;
            }
        }
        //cout << endl;

        if (f)
        {
            ans = min(ans, sum);
        }
    }

    if (ans == LONG_INF)
    {
        ans = -1;
    }

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

Measured memory_bytes: 3640
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < M; i++) {
			sum += sc.nextInt();
		}
		System.out.println(Math.max(N - sum, -1));
	}
}

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

#define INF 1e8

int N;
int R[10000];
double x[10000];
int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &R[i]);
		x[i] = 0;
	}
	x[0] = R[0];
	double max = x[0] * 2;
	for(int i = 1; i < N; i++){
		double ans = R[i];
		for(int j = 0; j < i; j++){
			double r = R[i] + R[j];
			double dr = R[i] - R[j];
			ans = fmax(ans, sqrt(r * r - dr * dr) + x[j]);
		}
		x[i] = ans;
		max = fmax(max, x[i] + R[i]);
	}
	printf("%lf\n", max);
}
	

Measured memory_bytes: 2832
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
int n,a,b,c,d;
bool jiao(LL a,LL b,LL c,LL d){
	return max(a,c)<=min(b,d);
}
int main(){
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);n--;
	if(a>b)swap(a,b);
	b-=a;
	LL sa,sb,sc,sd;
	for(int i=0,j=n;i<=n;i++,j--){
		sb=(LL)i*d,sa=(LL)i*c;
		sd=(LL)j*d+b,sc=(LL)j*c+b;
		if(jiao(sa,sb,sc,sd)){puts("YES");return 0;}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
/*     If they say
    Who cares if one more light goes out?
    In a sky of a million stars
    It flickers, flickers
    Who cares when someone's time runs out?
    If a moment is all we are
    We're quicker, quicker
    Who cares if one more light goes out?
    Well I do
*/

#include<bits/stdc++.h>
using namespace std;

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()

#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);

ll MOD = 1e9+7;

ll add(ll a, ll b){a+=b; a%=MOD;if(a<0) a+=MOD;return a;}
//doesn't work for neg numbers

ll mult(ll a, ll b){if(a>MOD) a%=MOD;if(b>MOD) b%=MOD;ll ans=(a*b)%MOD;if(ans<0) ans+=MOD;return ans;}
//doesn't work for neg numbers

ll pw(ull a, ull b){ll r=1;while(b){if(b&1) r=mult(r,a);a=mult(a,a);b>>=1;}return r;}
//doesn't work for neg numbers

ll sod(ll n){
    ll dp[n+1];
    ll a=0, ans=0;
    memset(dp,0,sizeof(dp));
    for(ll i=1;i<=n;i++){
      for(ll j=1;j*i<=n;j++){
        dp[i*j]++;
      }
    }
    for(ll i=1;i<=n;i++){
      a=i*dp[i];
      ans+=a;
    }
    return ans;
}

void solve(){
	ll n;
	cin>>n;
	cout<<sod(n);
}

int main(){
    fast_io;
    ll t, k=0;
    t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


Measured memory_bytes: 81768
from itertools import combinations_with_replacement as CwR

N,M,Q = map(int,input().split())

A = list(CwR(range(1,M+1),N))
lis = list()
for i in range(Q):
    a,b,c,d = map(int,input().split())
    a,b = a-1,b-1
    lis.append([a,b,c,d])

ans = 0
for A_ in A:
    tmp = 0
    for a,b,c,d in lis:
        if A_[b] - A_[a] == c:
            tmp += d
    ans = max(ans,tmp)

print(ans)


Measured memory_bytes: 21528
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define cerr cout
#define F first
#define S second
#define fori(i,a,b) for (i = a; i < b; ++i)
#define ford(i,a,b) for(i = a; i>=b;--i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int(x.size())
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <bool> vb;
typedef vector < char> vc;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fill(a, x) memset(a, x, sizeof(a))
#define INF 1000000000
#define MOD 1000000007
#define SMOD 998244353
#define endl "\n"
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
const ll N = 100043;
ll fact[N];
ll add(ll x, ll y)
{
	x += y;
	while(x >= MOD) x -= MOD;
	while(x < 0) x += MOD;
	return x;
}
ll mul(ll x, ll y)
{
	return (x * 1ll * y) % MOD;
}
ll mulmod(ll a, ll b)
{
    ll res = 0;
    a = a % MOD;
    while (b>0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
        a = (a * 2) % MOD;
        b /= 2;
    }
    return res % MOD; 
}
ll binpow(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}
ll inv(ll x)
{
	return binpow(x, MOD - 2);
}
ll divide(ll x, ll y)
{
	return mul(x, inv(y));
}
void precalc()
{
	fact[0] = 1;
	ll i;
	fori(i, 1, N)
		fact[i] = mul(i, fact[i - 1]);
}
ll C(ll n, ll k)
{
	if(k > n)
	    return 0;
	return divide(fact[n], mul(fact[n - k], fact[k]));
}

void solve()
{
    ll n, x, t;
    cin >> n >> x >> t;
    ll ans = ((n+x-1)/x) * t;
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin >> t;
    for(int i=1; i<=t; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  String[]s=sc.next().split("",0);
  int min=0;
  for(int i=1;i<n;i++){
  	if(s[i].equals("E"))min++;
  }
  int now=min;
	for(int i=0;i<n-1;i++){
      int m=now;
    	if(s[i].equals("W"))m++;
      	if(s[i+1].equals("E"))m--;
     	now=m;
       min=Math.min(m,min);
    }
  System.out.println(min);


}

}


Measured memory_bytes: 54340
#![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 l: Vec<i64> = read_vec();
    let mut cnt = 0;
    for i in 0..n {
        for j in i + 1..n {
            for k in j + 1..n {
                let mut t = vec![l[i], l[j], l[k]];
                t.sort();
                if t[0] != t[1] && t[1] != t[2] && t[0] + t[1] > t[2] { cnt += 1; }
            }
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 2184
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

template <typename T>
std::vector<int> sort_indexes(const std::vector<T> &v) {
  std::vector<int> idx(v.size());
  std::iota(idx.begin(), idx.end(), 0);
  std::sort(idx.begin(), idx.end(), [&v](int i1, int i2) {return v[i1] > v[i2];});
  return idx;
}


signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	auto idx = sort_indexes<int>(a);
	// dp[i][j] j=#greater in l
	// dp[i][j] = dp[i-1][j-1]+i*a[i]-(j-1)*a[i], dp[i-1][j]+(n-i-1-(i-j))*a[i]
	std::vector<std::vector<int> > dp(n+1,std::vector<int>(n+1,-INF));
	dp[0][0]=0;
	rep(x,n) {
		int i=idx[x];
		rep(j,n) {
			// dp[x+1][j] = std::max(dp[x][j-1]+i*a[i]-(j-1)*a[i], dp[x][j]+(n-i-1-(x-j))*a[i]);
			dp[x+1][j] = std::max(dp[x+1][j],dp[x][j]+(n-i-1-(x-j))*a[i]);
			dp[x+1][j+1] = std::max(dp[x+1][j+1], dp[x][j]+i*a[i]-j*a[i]);
		}
	}
	int max=0;
	rep(i,n+1) max=std::max(max,dp[n][i]);
	print(max);
	return 0;
}


Measured memory_bytes: 34676
//tenka1_2018_c.cpp
//Sat Oct 27 20:32:23 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll left = a[0];
	ll right = a[0];
	ll ans = 0;
	int flag = 1; //1なら大きい方から足す。
	ll larger = n-1;
	ll smaller = 1;
	while (larger>=smaller){
		if (flag == 1){
			ll temp = a[larger]-left;
			ans = ans + temp;
			left = a[larger];
			larger--;
			temp = a[larger]-right;
			ans = ans + temp;
			right = a[larger];
			larger--;
			flag = 0;
		}else {
			ll temp = left - a[smaller];
			ans = ans + temp;
			left = a[smaller];
			smaller++;
			temp = right - a[smaller];
			ans = ans + temp;
			right = a[smaller];
			smaller++;
			flag = 1;
		}
	}
	if (larger == smaller){
		ll temp = 0;
		if (a[larger] > left){
			temp = a[larger] - left;
		}else {
			temp = left - a[larger];
		}
		ans = ans + temp;
	}

	left = a[n-1];
	right = a[n-1];
	ll ans2 = 0;
	flag = 0; //1なら大きい方から足す。
	larger = n-2;
	smaller = 0;
	while (larger>=smaller){
		if (flag == 1){
			ll temp = a[larger]-left;
			ans2 = ans2 + temp;
			left = a[larger];
			larger--;
			temp = a[larger]-right;
			ans2 = ans2 + temp;
			right = a[larger];
			larger--;
			flag = 0;
		}else {
			ll temp = left - a[smaller];
			ans2 = ans2 + temp;
			left = a[smaller];
			smaller++;
			temp = right - a[smaller];
			ans2 = ans2 + temp;
			right = a[smaller];
			smaller++;
			flag = 1;
		}
	}
	if (larger == smaller){
		ll temp = 0;
		if (a[larger] > left){
			temp = a[larger] - left;
		}else {
			temp = left - a[larger];
		}
		ans2 = ans2 + temp;
	}

	if (ans > ans2){
		cout << ans << endl;
	}else{
		cout << ans2 << endl;
	}
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
long long a[100005];
int main()
{
	long long n,i,Max=-9999,ans=-9999,x;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		a[x]++;
		Max=max(Max,x);
	}
	for(i=0;i<=Max;i++)
	{
		ans=max(ans,a[i]+a[i-1]+a[i+1]);
	}
	cout<<ans;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main() {
	int ans=1000;
	string s;
	cin >> s;
	for(int i = 0; i < s.length()-2; ++i) {
		int val = 0;
		val = abs(stoi(s.substr(i, 3)) - 753);
		ans = min(ans, val);
	}
	cout<<ans<<endl;
}

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

int cnt[26];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    string S[110];
    rep(i, H) cin >> S[i];
    rep(i, H) {
        rep(j, W) {
            cnt[S[i][j] - 'a']++;
        }
    }
    int cnt1 = 0, cnt2 = 0, cnt4 = 0;
    rep(i, 26) {
        int tmp = cnt[i] / 4;
        cnt4 += tmp;
        cnt[i] -= tmp * 4;
        tmp = cnt[i] / 2;
        cnt2 += tmp;
        cnt[i] -= tmp * 2;
        cnt1 += cnt[i];
        cnt[i] = 0;
    }
    //cout << cnt1 << " " << cnt2 << " " << cnt4 << endl;
    int need1 = 0, need2 = 0, need4 = 0;
    if(H % 2 && W % 2) need1++;
    if(H % 2) need2 += W / 2;
    if(W % 2) need2 += H / 2;
    need4 += (H/2) * (W/2);
    //cout << need1 << " " << need2 << " " << need4 << " " << need1 + need2 * 2 + need4 * 4 << " " << H * W << endl;
    if(need4 < cnt4) {
        cnt4 -= need4;
        need4 = 0;
        cnt2 += cnt4 * 2;
        cnt4 = 0;
    }
    if(need2 < cnt2) {
        cnt2 -= need2;
        need2 = 0;
        cnt1 += cnt2 * 2;
        cnt2 = 0;
    }
    //cout << need1 << " " << need2 << " " << need4 << " " << need1 + need2 * 2 + need4 * 4 << " " << H * W << endl;
    if(need1 == cnt1 && need2 == cnt2 && need4 == cnt4) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int a, b;
int ans;

bool f(int n){
	int v[5] = {};
	for(int i=0; i<5; ++i){
		v[i] = n % 10;
		n /= 10;
	}
	return v[0] == v[4] && v[1] == v[3];
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> a >> b;
	for(int i=a; i<=b; ++i){
		if(f(i)) ++ans;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
def zeros(h,*w): return [[0] * w[0]  for _ in range(h)] if w else [[0] * h  for _ in range(h)]

n = int(input())
h = [ list(map(int, input().split())) for _ in range(n) ]

dp = zeros(n+1,3)

for i in range(n):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + h[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + h[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + h[i][2]

ans = max( dp[n] )

print(ans)

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int N, K;
    cin >> N >> K;

    string S;
    cin >> S;

    int happy=0;
    rep(i, N)
    {
        if(S[i]=='L')
        {
            if(i!=0&&S[i-1]=='L')
            {
                happy++;
            }
        }

        if(S[i]=='R')
        {
            if(i!=N-1&&S[i+1]=='R')
            {
                happy++;
            }
        }
    }

  
    happy+=2*K;
  
    
    if(happy>N-1)
    {
        cout << N-1 << endl;
    }
    else
    {
        cout << happy << endl;
    }
    
    

 

 

 

    return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  int B[20];
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int tmp = C;
    int a;
    for (int j = 0; j < M; j++) {
      cin >> a;
      tmp += a * B[j];
    }
    if (tmp > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int N, M, x, y; 
	cin >> N >> M;
	int cities[N] = {0};
	REP(i, 0, M){
		cin >> x >> y;
		++cities[x-1];
		++cities[y-1];
	}
	REP(i,0, N) cout << cities[i] << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, M;
    cin >> N >> M;

    vector<vector<int>> AB(1e5 + 1);

    rep(i, N) {
        int A, B;
        cin >> A >> B;
        AB[A].push_back(B);
    }

    priority_queue<int> pque;

    int ans = 0;
    repd(i, 1, M + 1) {
        rep(j, AB[i].size()) {
            pque.push(AB[i][j]);
        }
        if (!pque.empty()) {
            int p = pque.top();
            pque.pop();
            ans += p;
        }
    }

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

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

class Program
{
    static void Main(string[] args)
    {
    	var sc = new Scanner();
    	int n = sc.NextInt();
    	var s = new HashSet<int>();
    	for (int i = 0; i < n; i++)
    	{
    		int x = sc.NextInt();
    		if (s.Contains(x)) s.Remove(x);
    		else s.Add(x);
    	}
    	Console.WriteLine(s.Count);
    }
    
    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }
        
    public long NextLong()
    {
    	CheckNext();
    	return long.Parse(buf[index++]);
    }
    
    public double NextDouble()
    {
    	CheckNext();
    	return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}

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

int main(){
    int N; cin >> N; int A[100100];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A,A+N);
    int k =A[N-1];
    A[N-1]=0;
    int md=k/2;
    int mid=(k+1)/2;
    int a= *upper_bound(A,A+N-1,md);
    int b= *(upper_bound(A,A+N-1,md)-1);
    if( abs(a-mid) <= abs(b-md) ){
        cout << k << " " << a << endl;
    }
    else{
        cout << k << " " << b << endl;
    }
}

Measured memory_bytes: 640
n = int(input())
s = []
for _ in range(n):
    s.append(input())
set_s = set(s)
dict_s = {}
for si in set_s:
    dict_s[si] = 0
for si in s:
    dict_s[si] += 1
sorted_ds = sorted(dict_s.items(), key=lambda x: x[1], reverse=True)
f = True
for str_, c in sorted_ds:
    if f:
        list_ = [str_]
        p = c
        f = False
    else:
        if c == p:
            list_.append(str_)
list_ = sorted(list_)
for si in list_:
    print(si)


Measured memory_bytes: 57740
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int x,y;
  cin >> x >> y;
  long ans = 0;
  if(x <= 3) ans += 100000*(4-x);
  if(y <= 3) ans += 100000*(4-y);
  if(x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<set>
#include<algorithm>
#define L long long
#include<string.h>
#include <math.h>
#define mis 999
using namespace std;
typedef long long ll;
int a[100002];
int main()
{
     string s;
     cin>>s;
     int mins=mis;
     int len=s.length();
     for(int i=2;i<len;i++)
     {
          int ss=(s[i-2]-'0')*100+(s[i-1]-'0')*10+s[i]-'0';
          if(abs(ss-753)<mins)
          {
              mins=abs(ss-753);
          }
     }
     cout<<mins<<endl;
    return 0;
}


Measured memory_bytes: 256
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var xList = new Array(N);
  var yList = new Array(N);
  input.shift();
  for(var i = 0; i < N; i++){
    var tmp = myconv(input[i],4);
    xList[i] = tmp[0];
    yList[i] = tmp[1];
  }
  var sum = 0;
  for(var i = 0; i < N-1; i++){
    for(var j = i+1; j < N; j++){
      var x = Math.abs(xList[i] - xList[j]);
      var y = Math.abs(yList[i] - yList[j]);
      //myout("i:" + i + ",j:" + j + ",x" + x+",y:"+y);
      sum += Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
    }
  }
  //myout(xList);
  //myout(yList);
  sum *= 2;
  var fact = 1;
  for(var i = 1; i <= N; i++){
    fact *= i;
  }
  //myout(sum / fact);
  myout(sum / N);
}

Main(myin());


Measured memory_bytes: 23476
import sys
input=sys.stdin.readline

def main():
  def dp(i):
    for a,b in AB:
      T=C[i-a if i>a else 0]+b
      C[i]=T if T<C[i] else C[i]

  H,N=map(int,input().split())
  AB=[list(map(int,input().split())) for _ in range(N)]
  C=[0]+[10**8]*H

  for i in range(1,H+1):
    dp(i)

  print(C[H])

if __name__=='__main__':
	main()


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long s = Long.parseLong(br.readLine());

		long x1 = 0;
		long y1 = 0;
		long x2 = 1000000000L;
		long x3 = 1;
		long y3 = (s + x2 - 1) / x2;
		long y2 = (x2 * y3 - s);

		System.out.println(x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + y3);
	}
}


Measured memory_bytes: 37796
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
long long n, h[1000005], F[1000005];
int k;
int main()
{
    //freopen("FROG2.INP", "r", stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> h[i];
    F[1] = 0;
    for (int i = 2; i <= n; i++)
    {
        F[i] = 1e9;
        for (int j = max(1, i - k); j <= i - 1; j++) F[i] = min(F[i], F[j] + abs(h[i] - h[j]));
    }
    cout << F[n];
    return 0;
}


Measured memory_bytes: 5152
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>

using namespace std;

int main(){

	int a,b;
  	cin >> a >>b;
  
  	int d,r;
  	double f;
  	d = a/b;
  	r = a%b;
  	f = (double)a/b;
  
  	cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
  
    return 0;
}


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

using namespace std;

constexpr int MOD = 1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  string prev_row, cur_row;
  cin >> prev_row;
  vector<int> prev_dp(w), cur_dp(w);
  int idx=0;
  while (idx<w && prev_row[idx] == '.')
    prev_dp[idx++] = 1;
  for (int i=1; i<h; ++i) {
    cin >> cur_row;
    cur_dp.assign(w, 0);
    for (int j=0; j<w; ++j) {
      if (cur_row[j] == '.') {
        if (i-1 >= 0)
          cur_dp[j] = (cur_dp[j] + prev_dp[j]) % MOD;
        if (j-1 >= 0)
          cur_dp[j] = (cur_dp[j] + cur_dp[j-1]) % MOD;
      }
    }
    prev_row = cur_row;
    prev_dp = cur_dp;
  } 
  cout << cur_dp[w-1] << '\n';
  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

ll n;
ll dp[MAXN];
ll h[MAXN];

int main()
{
    fast_io;
    cin >> n;
    for (int i = 1; i <= n;i++){
        cin >> h[i];
        dp[i] = INF;
    }
    dp[1] = 0;
    for (int i = 1;i <= n;i++){
        dp[i + 1] = min(dp[i + 1],dp[i] + abs(h[i] - h[i + 1]));
        dp[i + 2] = min(dp[i + 2],dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[n] << endl;
}


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

int const N=1e5+5, M=1e9+7, OO = 0x3f3f3f3f;

int n,k;
int arr[N];

int mem[N];
int solve(int i)
{
    if(i==n-1)
        return 0;
    if(mem[i]!=-1)
        return mem[i];
    int ret=OO;
    for(int j=1; j<=k && i+j<=n-1; j++)
        ret=min(ret,solve(i+j)+abs(arr[i]-arr[i+j]));
    return mem[i]=ret;
}


int main()
{
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);
    scanf("%d %d",&n,&k);
    for(int i=0; i<n; i++)
        scanf("%d",arr+i);
    memset(mem, -1, sizeof mem);
    printf("%d\n",solve(0));

    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
	
	LL n,a,b;
	cin>>n>>a>>b;
	if(a>b) swap(a,b);
	if((b-a)%2) cout<<min(a+(b-a)/2,n-b+(b-a)/2+1)<<'\n';
	else cout<<(b-a)/2<<'\n';
	
	return 0;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x)      x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? (a=b,1) : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? (a=b,1) : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);

    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;

    return 0;
}



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

#define INF 100000000

int limit,n,m,x;
int sec_e[100],sec_s[100];
int e[100],s[100];

int memo[1001][100][101];

int tansaku(int nowmoney,int nowpos,int nowwaku) {
	int result;
	int nowresult;
	if(nowpos>=m || nowmoney<=0)return nowwaku<=0?0:-INF;
	if(memo[nowmoney][nowpos][nowwaku]!=0)return memo[nowmoney][nowpos][nowwaku]-1;

	result=tansaku(nowmoney,nowpos+1,nowwaku);
	if(nowmoney>=e[nowpos]) {
		nowresult=tansaku(nowmoney-e[nowpos],nowpos+1,nowwaku>0?nowwaku-1:nowwaku);
		nowresult+=s[nowpos];
		if(nowresult>result)result=nowresult;
	}

	memo[nowmoney][nowpos][nowwaku]=result+1;
	return result;
}

int main(void) {
	while(scanf("%d%d%d%d",&limit,&n,&m,&x)==4 && (limit|n|m|x)!=0) {
		int i,j;
		int maxscore;
		memset(memo,0,sizeof(memo));
		for(i=0;i<n;i++)scanf("%*s%d%d",&sec_e[i],&sec_s[i]);
		for(i=0;i<m;i++)scanf("%*s%d%d",&e[i],&s[i]);
		maxscore=0;
		for(i=0;i<n;i++) {
			for(j=i+1;j<=n;j++) {
				int nowscore,nowmoney;
				nowscore=sec_s[i];
				nowmoney=limit-sec_e[i];
				if(j<n) {
					nowscore+=sec_s[j];
					nowmoney-=sec_e[j];
				}
				if(nowmoney<0)continue;
				nowscore+=tansaku(nowmoney,0,x);
				if(nowscore>maxscore)maxscore=nowscore;
			}
		}
		printf("%d\n",maxscore);
	}
	return 0;
}

Measured memory_bytes: 40108
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

	int H,W;
	cin >> H >> W;
	string S;

	for (int i = 0; i < H; i++) {
		cin>>S;
		cout<<S<<endl;
		cout<<S<<endl;
	}


	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("");
	//文字列から10進数に変換するときはparseIntを使います
  	var count = 0;
  	if (input.length !== 1) {
      for (var i=0; i<input.length; i++) {
        if (i === input.length - 1) break;
        if (input[i] === input[i + 1]) {
          count++;
          input[i + 1] = (input[i] === "0") ? "1" : "0";
        }
      }
    }
	
  	//出力
	console.log(count);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	if(m == n) cout << "Yes";
	else cout << "No";

	return 0;
}



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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
 int main() {
	 int N, D;
	 cin >> N >> D;
	 int W = 2 * D + 1;
	 cout << (N + W - 1) / W << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = n*a;
        System.out.println(ans > b ? b:ans);
    }
}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>>  var(n, vector<int>(m, 0))
#define vecb2(var, n, m)   vector<vector<bool>> var(n, vector<bool>(m, false))
#define vecll2(var, n, m)  vector<vector<ll>>   var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  string t;
  rep(i,n){
    if(i!=n-1){
      if(s[i]=='B' && s[i+1]=='C'){
        t.pb('o');
        i++;
      } else {
        t.pb(s[i]);
      }
    } else {
      t.pb(s[i]);
    }
  }

  int m = t.size();
  vecll num(m);
  int tmp=0;
  rep(i,m){
    if(t[m-1-i]=='o') tmp++;
    else if(t[m-1-i]=='B' || t[m-1-i]=='C') tmp=0;
    num[m-1-i] = tmp;
  }

  ll ans=0;
  rep(i,m){
    if(t[i]=='A') ans+=num[i];
  }

  prt(ans);
}


Measured memory_bytes: 5360
x = int(input())

d = 1
while d * d <= x:
	if (x % d) == 0:
		for b in range(-200, 200):
			a = b + d
			if a**4 + a**3 * b + a**2 * b**2 + a * b**3 + b**4 == x // d:
				print(a, b)
				exit(0)
	d += 1


Measured memory_bytes: 65176
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

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

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	while (N) {
		vector<string>s(N);
		for (int i = 0; i < N; i++)cin >> s[i];
		if (N <= 20) {
			int loop = pow(2, N);
			ans = 0;
			for (int i = 0; i < loop; i++) {
				int num = 0;
				int box = i;
				int fig = 0;
				vector<int>used(M,0);
				while (box) {
					if (box % 2) {
						num++;
						for (int j = 0; j < M; j++) {
							if (s[fig][j] == '1') {
								used[j]++;
							}
						}
					}
					fig++;
					box /= 2;
				}
				bool flag = true;
				for (int j = 0; j < M; j++) {
					if (used[j] % 2)flag = false;
				}
				if (flag) {
					ans = max((int)ans, num);
				}
			}
			cout << ans << endl;
		}
		else if (N <= 40) {
			int loop_f = pow(2, N / 2);
			int loop_s = pow(2, N - N / 2);
			vector<int>used_f((int)pow(2, M), 0);
			vector<int>used_s((int)pow(2, M), 0);
			vector<int>bi(N);
			for (int i = 0; i < N; i++) {
				for (auto j : s[i]) {
					bi[i] *= 2;
					if (j == '1')bi[i]++;
				}
			}
			ans = 0;
			for (int i = 0; i < loop_f; i++) {
				int num = 0;
				int box = i;
				int fig = 0;
				int bag = 0;
				while (box) {
					if (box % 2) {
						num++;
						bag ^= bi[fig];
					}
					fig++;
					box /= 2;
				}
				used_f[bag] = max(used_f[bag], num);
			}
			for (int i = 0; i < loop_s; i++) {
				int num = 0;
				int box = i;
				int fig = N / 2;
				int bag = 0;
				while (box) {
					if (box % 2) {
						num++;
						bag ^= bi[fig];
					}
					fig++;
					box /= 2;
				}
				used_s[bag] = max(used_s[bag], num);
			}
			ans = used_f[0] + used_s[0];
			for (int i = 1; i < (int)pow(2, M); i++) {
				if(used_f[i]&&used_s[i])
				ans = max((int)ans, used_f[i] + used_s[i]);
			}
			cout << ans << endl;
		}
		else {
			int loop = pow(2, M);
			vector<vector<int>>dp(N, vector<int>(loop, 0));
			vector<int>num(N, 0);
			for (int i = 0; i < N; i++) {
				for (auto j : s[i]) {
					num[i] *= 2;
					if (j == '1')num[i]++;
				}
			}
			dp[0][num[0]]++;
			for (int i = 1; i < N; i++) {
				dp[i][num[i]] = max(dp[i - 1][0] + 1, dp[i - 1][num[i]]);
				for (int j = 1; j < loop; j++) {
					if (dp[i - 1][j]) {
						dp[i][j^num[i]] = max(dp[i - 1][j] + 1, dp[i - 1][j^num[i]]);
					}
					else {
						dp[i][j^num[i]] = dp[i - 1][j^num[i]];
					}
				}
			}
			cout << dp[N - 1][0] << endl;
		}
		cin >> N >> M;
	}
	return 0;
}

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
  
  	if(a==b && b==c){
      cout << 1 <<endl;
    }
    else if(a!=b && b!=c && a !=c ){
	  cout << 3 <<endl;
    }
    else{
      cout << 2 <<endl;
	}
}


Measured memory_bytes: 3564
# D問題とほぼ同じだが計算量が問題になる．
# 前回と違い重さの制約が，W<10^9なので，重さのノードを作ってしまうと，計算量がどう仕様もなくなる
# なので，価値に対してノードを作ってあげて，最小の重さを計算するようにする

N, W_max = map(int, input().split())

W = []
V = []

for i in range(N):
    w,v = map(int,input().split())
    W.append(w)
    V.append(v)
# dp[v][i] := 商品iまで選択して，価値がv以下となった場合について，最小の重さ
import math
import numpy as np
dp = np.ones((10**3*(N+10))) * np.inf
dp[0] = 0
for v,w in zip(V,W):
    np.minimum(dp[:-v]+w, dp[v:],out=dp[v:])
print(np.where(dp<=W_max)[0][-1])



Measured memory_bytes: 14168
import sys

input=sys.stdin.readline

N,M,Q=map(int,input().split())
S=[]
for i in range(N):
    S.append(input())

blue=[[0 for j in range(M+1)] for i in range(N+1)]
for i in range(1,N+1):
    for j in range(1,M+1):
        blue[i][j]+=blue[i][j-1]+int(S[i-1][j-1])

for j in range(1,M+1):
    for i in range(1,N+1):
        blue[i][j]+=blue[i-1][j]

yoko=[[0 for j in range(M+1)] for i in range(N+1)]
for i in range(1,N+1):
    for j in range(2,M+1):
        yoko[i][j]+=int(S[i-1][j-1])*int(S[i-1][j-2])+yoko[i][j-1]

for j in range(M+1):
    for i in range(1,N+1):
        yoko[i][j]+=yoko[i-1][j]

tate=[[0 for i in range(M+1)] for j in range(N+1)]
for j in range(1,M+1):
    for i in range(2,N+1):
        tate[i][j]+=tate[i-1][j]+int(S[i-2][j-1])*int(S[i-1][j-1])

for i in range(N+1):
    for j in range(1,M+1):
        tate[i][j]+=tate[i][j-1]

for _ in range(Q):
    x1,y1,x2,y2=map(int,input().split())
    res=(blue[x2][y2]-blue[x1-1][y2])-(blue[x2][y1-1]-blue[x1-1][y1-1])
    res-=(tate[x2][y2]-tate[x2][y1-1])-(tate[x1][y2]-tate[x1][y1-1])
    res-=(yoko[x2][y2]-yoko[x1-1][y2])-(yoko[x2][y1]-yoko[x1-1][y1])
    print(res)

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

int main(){
    long long N;
    string s;
    long long ans = 100000000000000000;
    cin >> N;
    cin >> s;
    string a,b;

    string S = "!" + s;

    long long black[N + 1];
    for(int i = 0; i <= N; i++){
        a = S.substr(i,1);
        if(a == "#"){
            black[i] = black[i - 1] + 1;
        }else{
            if(i == 0){
                black[i] = 0;
            }else{
                black[i] = black[i - 1];
            } 
        }
    }

    long long max = black[N]; 

    long long white[N + 1];
    for(int j = 0; j <= N; ++j){
        b = S.substr(j,1);
        if(b == "."){
            white[j] = white[j - 1] - 1;
        }else{
            if(j == 0){
                white[j] = N - max;
            }else{
                white[j] = white[j - 1];
            } 
        }
    }

    for(int i = 0; i <= N; i++){
        //cout << black[i] << " " << white[i] << endl;
        ans = min(ans,black[i]+white[i]);
    } 

    cout << ans << endl;

}

Measured memory_bytes: 3972
//#include <cstdio>
#include <iostream>
//#include <algorithm>
using namespace std;

int N, H[10];

void solve()
{
  int big=0, small=0;
  bool flag = true;
  for (int i = 0; i < 10; i++)
  {
    if (H[i] > big) big = H[i];
    else if (H[i] > small) small = H[i];
    else
    {
      flag = false;
      break;
    }
  }
  if (flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

int main()
{
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 10; j++) cin >> H[j];
    solve();
  }
  return 0;
}

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

using namespace std;
int main() {
    int n, m; cin >> n >> m;
    string* a = new string [n];
    string* b = new string [m];
    for(int i = 0; i < n; ++i) { cin >> a[i]; }
    for(int i = 0; i < m; ++i) { cin >> b[i]; }
    bool found;
    for(int top = 0; top < n-m+1; ++top)
    {
        for(int lef = 0; lef < n-m+1; ++lef)
        {
            found = true;
            for(int bt = 0; bt < m; ++bt)
            {
                for(int bl = 0; bl < m; ++bl)
                {
                    if (b[bt][bl] != a[top+bt][lef+bl]) {found = false; goto nf;}
                }
            }
            nf:
            if (found) goto ff;
        }
    }
    ff:
    cout << (found ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256