akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (ll i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<bool>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll H,W,M,max_t=0,max_y=0;	cin>>H>>W>>M;
	vector<pair<ll, ll>> P;
	vector<ll> T(H,0), Y(W,0);
	FOR(i,0,M){
		ll a,b; cin>>a>>b;
		a--; b--;
		T.at(a)++;
		Y.at(b)++;
		max_t = max(max_t, T.at(a));
		max_y = max(max_y, Y.at(b));
		P.push_back(make_pair(a, b));
	}

	sort(range(P));
	//cout<<max_t<<"/"<<max_y<<endl;

	vector<ll> T_0,Y_0;
	FOR(i,0,H){
		if(T.at(i)==max_t) T_0.push_back(i);
	}

	FOR(i,0,W){
		if(Y.at(i)==max_y) Y_0.push_back(i);
	}

	FOR(i,0,T_0.size()){
		FOR(j,0,Y_0.size()){
			if(binary_search(range(P),make_pair(T_0.at(i), Y_0.at(j)))==false){
				cout<<max_t+max_y<<endl;
				return 0;
			} 
		}
	}

	cout<<max_t+max_y-1<<endl;

    return 0;
}



Measured memory_bytes: 21500
=begin
N = gets.to_i               # 単一整数
a = gets.split.map(&:to_i)  # スペースで区切られた複数の整数
a = N.times.map{gets.to_i}  # 縦に並んだ複数の整数。たまにある
s = gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
=end
N = gets.to_i              # 文字列。chompを付けないと改行文字がついてくる
S = gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'


a = A.split('')
b = S.split('')

str = ''
b.size.times do |n|
	aa = a.find_index(b[n])
	if aa + N >= 26
		b[n] = a[aa+N-26]
	else
		b[n] = a[aa+N]
	end
	# puts b[n]
	str += b[n]
end

puts str

Measured memory_bytes: 23944
import numpy as np
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = np.array(ab) * [-1, 1] + [m, 0]

at = [[] for _ in range(m)]
for a, b in ab:
    if a >= 0:
        at[a].append(b)

ans = 0
now = []
for value in at[::-1][:m]:
    for v in value:
        heapq.heappush(now, -v)
    if now:
        ans += heapq.heappop(now)
print(-ans)



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

#define se second
#define fi first
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

vector<ii> vec;

int main(){
    int n, h;
    scanf("%d %d", &n, &h);
    for (int i = 0; i < n; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        vec.pb(mp(a, 0));
        vec.pb(mp(b, 1));
    }

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

    int ans = 0;
    for (int i = (int)vec.size()-1; i >= 0; i--){
        if (vec[i].se){
            ans++;
            h -= vec[i].fi;
        }
        else{
            ans += h/vec[i].fi;
            if (h%vec[i].fi) ans++;
            h = 0;
        }
        if (h <= 0) break;
    }

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


Measured memory_bytes: 2420
#include <iostream>
#define MAX 70
#define rep(i,p) for(int i=0;i<p;i++)
#define pb push_back
using namespace std;
int w,h,ans,yoko,tate;
int hoge;
bool c[MAX][MAX];
bool visit[MAX][MAX];
// ?§???? {?????????????????????????????????????????????????????????}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,1,-1};

bool dfs (int x, int y) {
  if(!c[x][y]) return false;
  visit[x][y] = true;
  rep(i,8) {
    yoko = x+dx[i];
    tate = y+dy[i];
    if ( c[yoko][tate] and !visit[yoko][tate] ) dfs(yoko,tate);
  }
  return true;
}
int main(){
  while (1) {
    cin >> w >> h;
    if (w == 0 and h == 0) break;
    rep(i,MAX) rep(j,MAX) c[i][j] = false;
    rep(i,MAX) rep(j,MAX) visit[i][j] = false;
    ans = 0;
    // ?????? 0 false
    // ?????? 1 true
    // ??§?¨? [1,w]x[1,h]????????´??????(false)
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++) {
        cin >> hoge;
        if (hoge == 1) c[i][j] = true;
      }
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++)
        if (!visit[i][j])
          // dfs ????????¢?´¢???????????\???????????¨??????false?????????
          if (dfs(i,j)) ans++;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  vector<int> LB(N + 1);
  rep(i, N) {
    LB[i + 1] = LB[i] + (S[i] == '#');
  }

  vector<int> RW(N + 1);
  repr(i, N, 1) {
    RW[i - 1] = RW[i] + (S[i - 1] == '.');
  }


  int ans = INF;
  rep(i, N + 1) {
    int temp = LB[i] + RW[i];
    chmin(ans, temp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3732
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author P.Alizadeh
 */

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

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll,ll>     pll;

#define all(x)          x.begin(),x.end()
#define Sort(x)         sort(all(x))
#define trace(x)        cerr << #x << " = " << x << endl;
#define X               first
#define Y               second
#define sep             " "
#define endl            "\n"
#define fastio          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define ld_io           cout << setprecision(10) << fixed;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll md) {
    if (!b)
        return 1;
    if (b & 1)
        return a * pw(a * a % md, b / 2, md) % md;
    return pw(a * a % md, b / 2, md) % md;
}

const ll MAXN = 3e3 + 10,
         INF  = 8e18,
         MOD  = 1e9 + 7;
//const ld PI   = acos(-1);

ll dp[MAXN][MAXN];
string s, t;
vector<char> ans;

int main()
{
    fastio;
    //ld_io;

    cin >> s >> t;
    ll n = s.size(), m = t.size();

    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            dp[i][j] = max({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]+(s[i-1]==t[j-1])});
        }
    }

    ll i = n, j = m;
    while (i && j) {
        if (s[i-1] == t[j-1]) {
            ans.push_back(s[i-1]);
            i--; j--;
            continue;
        }
        if (dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }

    reverse(all(ans));
    for (auto c : ans)
        cout << c;
    cout << endl;

    return 0;
}



Measured memory_bytes: 70784
#include<stdio.h>
int n,v[51],c[51],i,ans;
int main(void){
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&v[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&c[i]);
    }
    for(i=0;i<n;i++){
        if(v[i]-c[i] >= 1){
        ans += v[i]-c[i];
        }
    }
    printf("%d",ans);

}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String a = scanner.next();
        String b = scanner.next();
        int addedNum = Integer.parseInt(a + b);
        for (int i = 0; i < 316; i++) {
            if (addedNum == i * i) {
                System.out.print("Yes");
                return;
            }
        }
        System.out.print("No");
    }
}


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

int main(){
    int a,b,c;

    cin >> a >> b;
    c = a*b;
    
    /*if(c%2 == 0) cout << "Even" << endl;
    else if (c%2 != 0) cout << "Odd" << endl;
*/
    cout << (c % 2 == 0 ? "Even" : "Odd") << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=100100;
char s[N],p[10][10];
int f[N],len[10];
int main()
{
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,j,k,n;
    scanf("%s",s+1);n=strlen(s+1);
    p[1][1]=p[2][1]='d',p[1][2]=p[2][2]='r',p[1][3]=p[2][3]='e',
    p[1][4]=p[2][4]='a',p[1][5]=p[2][5]='m',p[2][7]=p[4][6]='r';
    p[3][1]=p[4][1]='e',p[3][2]=p[4][2]='r',p[3][3]=p[4][3]='a',
    p[3][4]=p[4][4]='s',p[3][5]=p[4][5]='e';p[2][6]='e';
    len[1]=len[3]=5,len[2]=7,len[4]=6;
    memset(f,0,sizeof(f));
    for (i=0,f[0]=1;i<n;i++)
    {
        if (!f[i]) continue;
        for (j=1;j<=4;j++)
        {
            if (i+len[j]>n) continue;
            for (k=1;k<=len[j];k++) if (s[i+k]!=p[j][k]) break;
            if (k>len[j]) f[i+len[j]]=1;
        }
    }
    if (f[n]) puts("YES"); else puts("NO");
    
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

std::vector<int> to[200005];
std::vector<int> ans;

void dfs(int v, int p=-1){
    for(int u : to[v]){
        if(u==p) continue;
        ans[u] += ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q; std::cin >> n >> q;

    rep(i,n-1){
        int a, b; std::cin >> a >> b; a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    ans.resize(n);
    rep(i,q){
        int p, x; std::cin >> p >> x; p--;
        ans[p] += x;
    }

    dfs(0);

    rep(i,n){
        std::cout << ans[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 24292
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>

#define N_size 100000000000

using namespace std;

int main(){
    int N,M;
    cin >> N;

    vector<long long> D(N);

    for(int i = 0;i < N;i++){
        cin >> D.at(i);
    }

    cin >> M;

    vector<long long> T(M);

    for(int i = 0;i < M;i++)
        cin >> T.at(i);

    map<int ,int> mpa,mpb;

    for(int i = 0;i < N;i++)
        mpa[D.at(i)]++;
    for(int i = 0;i < M;i++)
        mpb[T.at(i)]++;

    for(int i = 0;i < M;i++){
        int x = T.at(i);
        if(mpb[x] > mpa[x]){
            cout << "NO"  << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;

}


Measured memory_bytes: 22144
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long


 
int main(){
    
    ll n,m;
    ll ans=0;
    
    cin>>n>>m;
    if(n<m/2){
        ans+=n;
        m-=n*2;
        ans+=m/4;
    }
    else{
        ans+=m/2;
    }
    cout<<ans<<endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
ll ncr(ll x, ll y) {
	ll ans = 1;
	for (ll i = 1; i <= y; ++i) {
		ans *= (x - y + i);
		ans /= i;
	}

	return ans;
}
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}
int main()
{
    fio;
    int t;
    cin>>t;
   if(t==0)
    cout<<"1\n";
   else if(t==1)
    cout<<"0\n";
    return 0;
}


Measured memory_bytes: 3596
def multiples_of(num)
  if num % 4 == 0
    4
  elsif num % 4 != 0 && num % 2 == 0
    2
  else
    1
  end
end

def upper_than_num(num, memo)
  (num..4).find { |i| memo[i] > 0 }
end

n = gets.to_i
nums = gets.split.map(&:to_i)
memo = Hash.new(0)
nums.each do |num|
  memo[multiples_of(num)] += 1
end
array = [4]
ans = "Yes"
n.times do |i|
  upper_than =
    if array.last == 1
      4
    elsif array.last == 2
      2
    else
      1
    end
  if selected_num = upper_than_num(upper_than, memo)
    memo[selected_num] -= 1
    array << selected_num
  else
    ans = "No"
    break
  end
end
puts ans


Measured memory_bytes: 11916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  if (SZ(s) <= k) {
    cout << s << "\n";
    return 0;
  }
  s = s.substr(0, k);
  cout << s << "..."
       << "\n";
}

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

ll n;

const ll MOD = 998244353;

struct robo {
	ll x, d;
	vector<int> child;
};
vector<robo> v;

ll dfs( int node ){
	const robo &r = v[node];
	
	ll result = 1;
	for ( size_t i = 0; i < r.child.size(); i++ ){
		//cout << node << "->" << r.child[i] << endl;
		result = result * dfs(r.child[i]) % MOD;
	}
	
	// 組み合わせ = 全ての子ノードの組み合わせ + このノードを起動して全ての子を起動
	//cout << node << ":" << result+1 << endl;
	return  (result+1) % MOD;
}

int main(){
	cin >> n;
	
	v.resize(n+1);
	for ( int i = 0; i < n; i++ ){
		cin >> v[i].x >> v[i].d;
	}
	v[n].x = -2000000000LL;
	v[n].d =  4000000000LL; // root
	
	sort(v.begin(),v.end(),[](const robo &l, const robo &r){return l.x < r.x;});
	
	
	// 起動の順番は結果に影響を与えない
	// ロボットの関係をツリーにする。 Aを起動したときにBが起動するなら、AはBの祖先
	stack<int> s;
	s.push(0);
	for ( int i = 1; i < n+1; i++ ){
		const robo &ri = v[i];
		while ( v[s.top()].x + v[s.top()].d <= ri.x )
			s.pop();
		v[s.top()].child.push_back(i);
		s.push(i);
	}
	
	ll result = dfs(0) - 1; // rootを起動 の1を引く
	
	cout << result << endl;
	
	return 0;
}



Measured memory_bytes: 27472
r, g, b, n = gets.chomp.split(" ").map(&:to_i);
ans = 0
for i in 0..n/r do
	for j in 0..(n-i*r)/g do
		if (n - i*r - j*g)%b == 0
			ans += 1
		end
	end
end
puts ans

Measured memory_bytes: 14308
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 2e6 + 1e5;

ll DP[22][MAXN];
int hashe[MAXN];
int A[22][22];
int n;

ll rek(int pos, ll now) {
	//cout << pos << ' ' << now << '\n';
	if (pos == n) return 1;
	ll &ret = DP[pos][now];
	if (ret != -1) return ret;
	ret = 0;
	ll sek = ~now;
	//cout << pos << ' ' << now << ' ' << sek << ' ' << ~0 << '\n';
	while(sek != 0) {
		ll tmp = sek & (-sek);
		//cout << sek << ' ' << tmp << ' ' << hashe[tmp] << ' ' << A[pos][hashe[tmp]] << "EA\n";
		if (tmp > 2100000) break;
		if (A[pos][hashe[tmp]] == 1) {
			//cout << pos
			ret = (ret + rek(pos + 1, now | tmp)) % MOD;
		}
		sek -= tmp;
	}
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	REP(i, n) REP(j, n) cin >> A[i][j];
	int i = 0, j = 1;
	while (j < 3000000) {
		//cout << i << ' ' << j << '\n';
		hashe[j] = i++;
		j *= 2;
	}
	memset(DP, -1, sizeof DP);
	cout << rek(0, 0) << '\n';
}

Measured memory_bytes: 365312
# coding: utf-8
# Your code here!
N=int(input())

def keta(num):
    count=0
    while num:
        num=num//10
        count+=1
    return count

ans=10*10
for i in range(1,int(N**0.5//1)+1):
    if N%i==0:
        a=i
        b=N//i
        ans=min(ans,max(keta(a),keta(b)))

print(ans)
    

Measured memory_bytes: 3188
#include <stdio.h>

int p = 0, q[2000000];

int max_num(int x, int y){
    if(q[x]>q[y])   return x;
    else    return y;
}

insert(int k){
    int i, j, temp;
    p++;
    q[p] = k;
    i = p;
    while(q[i]>q[i/2] && i>1){
        temp = q[i];
        q[i] = q[i/2];
        q[i/2] = temp;
        i = i/2;
    }
}

int extract(){
    int i, temp, max, a;
    a = q[1];
    q[1] = q[p];
    p--;
    i = 1;
    while(i*2<=p){
        if(i*2+1<=p)    max = max_num(i*2, i*2+1);
        else    max =i*2;
        if(max_num(max, i)==max){
            temp = q[max];
            q[max] = q[i];
            q[i] = temp;
            i = max;
        }
        else break;
    }
    return a;
}

int main(){
    int i, j, k;
    char cmd[10];
    while(1){
        scanf("%s",cmd);
        if(cmd[0]=='i'){
            scanf("%d",&k);
            insert(k);
        }
        if(cmd[0]=='e' && cmd[1]=='x')  printf("%d\n",extract());
        if(cmd[0]=='e' && cmd[1]=='n')  break;
    }
    return 0;
}


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long c;
  int mas[11][11];
  while(cin>>c){
    memset(mas,0,sizeof(mas));
    //cout<<c<<endl;
    for(int i=0;i<10;i++){
      mas[0][i] = c % 10;
      c /= 10;
    }
    
    for(int i=1;i<10;i++){
      for(int j=0;j<10;j++){
	mas[i][j] = (mas[i-1][j] + mas[i-1][j+1]) % 10;
	//cout<<mas[i][j]<<" ";
      }
      //cout<<endl;
    }
    
    cout<<mas[9][0]<<endl;
  }
}

Measured memory_bytes: 1160
#include<cstdio>
void swap(int &x,int &y) {int t=x;x=y;y=t;}
int main()
{
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	int k;scanf("%d",&k);
	if(a<b) swap(a,b);if(a<c) swap(a,c);
	printf("%d\n",b+c+a*(1<<k));
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int a,b,c;cin>>a>>b>>c;
    int ary[3][3];
    int z=3*c;
    ary[0][0]=a;
    ary[0][1]=b;
    ary[0][2]=3*c-a-b;
    ary[1][0]=z-2*a-b+c;
    ary[1][1]=c;
    ary[1][2]=z-ary[1][0]-ary[1][1];
    ary[2][0]=a+b-c;
    ary[2][1]=z-b-c;
    ary[2][2]=z-ary[2][0]-ary[2][1];
    rep(i,3){
        rep(j,3){
            if(j)cout<<" ";
            cout<<ary[i][j];
        }
        cout<<endl;
    }
}


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

double dtor(double deg){
	return deg*M_PI/180.0;
}

int main() {
	double a,b,c,d;
	double r = 6378.1;
	
	while(cin>>a>>b>>c>>d,(int)(a+1)|(int)(b+1)|(int)(c+1)|(int)(d+1)){
		double distance = r*acos(sin(dtor(a))*sin(dtor(c))+cos(dtor(a))*cos(dtor(c))*cos(dtor(b-d)));
		
		cout<<round(distance)<<endl;
		
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  int H, W, h, w;
  cin >> H >> W;
  cin >> h >> w;

  cout << (H*W) - (h*W + w*(H-h)) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
vector<double> V; int N, K, ans=0;
bool check(double X){
  int L=K, i=0;
  while(i<N){
  if(V[i]<=X){ return true; }
  L-=(ceil(V[i]/X)-1);
  if(L<0){ return false; }
  i++;
  }
  return true;
}

int main(){
cin >> N >> K; double v;
REP(i, N){ cin >> v; V.push_back(v); }
sort(V.begin(), V.end()); reverse(V.begin(), V.end());
double L=0, R=1e9, M=(L+R)/2; bool F=false;
while(R-L>1){
M=(L+R)/2;
F=check(M);
if(F){ R=ceil(M); }else{ L=floor(M); }
}
cout << (long)R << "\n";
}


Measured memory_bytes: 5408
n,m = map(int,input().split())
h = tuple(map(int,input().split()))
ab = []
for i in range(m):
  ab.append(tuple(map(int,input().split())))

g = [1 for _ in range(n)]
for a,b in ab:
  a -= 1
  b -= 1
  if h[a] < h[b]:
    g[a] = 0
  elif h[a] > h[b]:
    g[b] = 0
  else:
    g[a] = 0
    g[b] = 0
print(sum(g))

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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int x,y,a,b,c;
signed main(){
  cin>>x>>y>>a>>b>>c;
  vector<P> apple(a+b+c);
  rep(i,a){
    cin>>apple[i].first;
    apple[i].second=1;
  }
  rep(i,b){
    cin>>apple[i+a].first;
    apple[i+a].second=2;
  }
  rep(i,c){
    cin>>apple[i+a+b].first;
    apple[i+a+b].second=3;
  }
  sort(apple.begin(),apple.end());
  reverse(ALL(apple));
  int res=0;
  vector<int> color(4,0);
  rep(i,a+b+c){
    if(color[1]+color[2]+color[3]==x+y){
      break;
    }
    if(apple[i].second==1&&color[1]==x){
      continue;
    }
    if(apple[i].second==2&&color[2]==y){
      continue;
    }
    res+=apple[i].first;
    color[apple[i].second]++;
    //cout<<apple[i].second<<endl;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;

//자동 정렬은 ctrl k f
//주석은 ctrl k c
//주석 해제는 ctrl k u
// int gcd(int a, int b){
// 	while(b!=0){
// 		int r= a%b;
// 		a=b;
// 		b=r;
// 	}
// 	return a;
// }
// int lcm(int a, int b){
// 	return a*b/gcd(a,b);
// }
int arr[200001];
int save[200001];

int getParent(int x) {
	if (arr[x] == x) {
		return x;
	}
	else {
		return arr[x] = getParent(arr[x]);
	}

}

void find(int x, int y) {
	//int x_p = arr[x];
	int x_p = getParent(x);
	//int y_p = arr[y];
	int y_p = getParent(y);

	if (x_p != y_p) {
		if (x_p < y_p) {
			arr[y_p] = x_p;
		}
		else {
			arr[x_p] = y_p;
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		arr[i] = i;
	}

	
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		find(x, y);

	}
	
	for (int i = 1; i <= n; i++) {
		arr[i] = getParent(arr[i]);
		//cout << arr[i] << ' ';
	}

	for (int i = 1; i <= n; i++) {
		save[arr[i]]++;
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, save[i]);
	}
	cout << ans<<'\n';
	return 0;
}



Measured memory_bytes: 5112
N = int(input())
h_array = list(map(int, input().split()))

c_array = [0] * N
c_array[0] = 0
c_array[1] = abs(h_array[0] - h_array[1])

for i in range(2, N):
    c_array[i] = min(c_array[i - 1] + abs(h_array[i - 1] - h_array[i]),
                     c_array[i - 2] + abs(h_array[i - 2] - h_array[i]))

print(c_array[-1])


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;


const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct Bitree {
	typedef ll btT;
	vector<btT> bv;
	Bitree(int n) : bv(n + 3) {}
	btT sum(int i) {
		btT res=0; for(i++; i>0; i -= i & -i) res += bv[i]; return res;
	}
	btT sum(int a, int b) {return sum(b) - (a? sum(a-1): 0);}
	void add(int i, btT x){for(i++; i<(int)bv.size(); i += i & -i) bv[i] += x; }
};

bool f(int s, const VI& a){
	int n=sz(a),  cur = n +10;
	Bitree bt(2*cur);
	
	ll sm=0;
	bt.add(cur, 1);
	rep(i, n){
		cur += a[i]>=s? 1: -1;
		sm += bt.sum(0,cur);
		bt.add(cur, 1);
	}
	//dbg(s,sm, (ll)n*(n+1)/2);
	return sm * 4 >= (ll)n*(n+1);
}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<int> a(n);
	rep(i,n) cin >>a[i];
	
	auto b = a;
	sort(all(b));
	
	f(b[0], a);
	
	ll hi=n, lw=0;
	while(hi - lw > 1){
		ll md= (hi + lw) >> 1;
		( f(b[md], a)? lw: hi )  = md;
	}

	cout << b[lw] <<"\n";
	return 0;
}


Measured memory_bytes: 2664
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int ans=1;
  cin >> N;
  //int x=1;
  for(int i=0; i<N; i++){
    int a;
  	cin >> a;
    if(i+1>=a&&a==ans){
      ans++;
    }
  }
  if(ans==1)ans=-1;
  else ans=N-ans+1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
 
int main(int argc, char const* argv[])
{
    int m,n;
    int a[100][100];
    int b[100];
    int c[100] = {0,0,0};
 
    std::cin >> n >> m ;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            std::cin >> a[i][j] ;
        }
    }
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            c[i] += a[i][j] * b[j];
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << c[i] << std::endl;
    }
 
}

Measured memory_bytes: 1200
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        int m,f,r;
        Scanner s = new Scanner(System.in);
        while(true){
            m = s.nextInt();
            f = s.nextInt();
            r = s.nextInt();
            if(m==-1&&f==-1&&r==-1)break;
            if(m==-1||f==-1)System.out.println("F");
            else if(m+f>=80)System.out.println("A");
            else if(m+f>=65)System.out.println("B");
            else if(m+f>=50)System.out.println("C");
            else if(m+f>=30){
                if(r>=50)System.out.println("C");
                else System.out.println("D");
            }
            else System.out.println("F");
 
 
        }
    }
}


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

void solver() {
  int n;
  cin >> n;

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    ans += i;
  }

  cout << ans << "\n";
}

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


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int abs(int x){
  return (x>0)?x:(-x);
}

int main(void){
  int N;
  cin >> N ;

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

  int all = abs(A[0]);
  for(int i = 0 ; i < N ; i++){
    all += abs(A[i + 1] - A[i]);
  }

  cout << all - abs(0 - A[0]) - abs(A[1] - A[0]) + abs(A[1] - 0) << endl;

  for(int skip = 1 ; skip < N ; skip++){
    cout << all - abs(A[skip - 1] - A[skip]) - abs(A[skip + 1] - A[skip]) + abs(A[skip - 1] - A[skip + 1]) << endl;
  }

  return 0;
}

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

int main() {
  string n;
  cin >> n;
  int max_sum = 0;
  rep(i, n.size() + 1) {
    int now_sum = 0;
    rep(j, n.size()) {
      if (j < i) now_sum += n[j] - '0';
      else if (j == i) now_sum += n[j] - '0' - 1;
      else now_sum += 9;
    }
    max_sum = max(max_sum, now_sum);
  }
  cout << max_sum << endl;
  return 0;
}

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

using namespace std;

int main(void)
{
	double tate,yoko,takasa;
	int L; cin>>L;
	tate = (double)L / 3.0;
	yoko = (double)L / 3.0;
	takasa = (double)L - tate - yoko;
	
	double ans = tate*yoko*takasa;
	
	printf("%lf\n",ans);
	return 0;
}



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n, k;
    cin >> n >> k;
    vector<int32> v(n);
    REP(i,n)cin >> v[i];
    int32 ans = 0;
    for(int32 i = 1; i <= min(n,k); ++i){
        for(int32 left = 0; left <= i; ++left){
            vector<int32> jewelries;
            int32 valueSum = 0;
            REP(j,left){
                jewelries.pb(v[j]);
                valueSum += v[j];
            }
            REP(j,i - left){
                jewelries.pb(v[n-j-1]);
                valueSum += v[n-j-1];
            }
            sort(ALL(jewelries));
            REP(j,k-i){
                if(jewelries[j] < 0){
                    valueSum -= jewelries[j];
                }else{
                    break;
                }
            }
            ans = max(ans, valueSum);
        }
    }
    ANS(ans);
    return 0;
}

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

#define ll long long
#define ull unsigned long long

#define vi vector < int >
#define vll vector < ll >
#define vs vector < string >

#define pii pair < int, int >
#define pll pair < ll, ll >

#define pb push_back

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

int main()
{
    fast;

    char ch;

    cin >> ch;

    if(ch >= 'A' && ch <= 'Z') cout << 'A' << endl;
    else cout << 'a' << endl;

    return 0;
}



Measured memory_bytes: 3652
#include "bits/stdc++.h"
#define rep(i,N) for (int (i) = 0; (i) < (N); (i)++)

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	
	std::set<int> s;
	rep(i, 3) {
		int tmp; std::cin >> tmp;
		s.insert(tmp);
	}

	std::cout << s.size();

	return 0;
}

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

int N;
vector<int> a(9);

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int temp; scanf("%d", &temp);
        int rate = temp/400;
        if (rate>7) a[8]++;
        else a[rate]++;
    }
    int mini = 0, maxi = 0;
    for (int i = 0; i < 8; i++) {
        if (a[i]) mini++, maxi++;
    }
    if (!mini && a[8]) mini = 1, maxi = a[8];
    else maxi += a[8];
    cout << mini << " " << maxi << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int a[5];
  for (int i = 0; i < 5; ++i)
    cin >> a[i];
  int nmin = 200;
  int itr = 0;
  for (int i = 0; i < 5; ++i)
  {
    if (nmin > (a[i] % 10) && (a[i] % 10) != 0)
    {
      itr = i;
      nmin = a[i] % 10;
    }
  }
  int sum = 0;
  for (int i = 0; i < 5; ++i)
  {
    if (i == itr)
      sum += a[i];
    else
      sum += ((a[i] - 1) / 10 + 1) * 10;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 384
moji = input()
def isEvenStr(moji):
	length = len(moji)
	if length % 2 == 1:
		return None
	else:
		firsthalf = moji[0:int(length/2)]
		latterhalf = moji[int(length/2):int(length)]
		return firsthalf == latterhalf

for i in range(len(moji)-1,0,-1):
	trimmed = moji[0:i]
	isEven = isEvenStr(trimmed)
	if isEven:
		print(i)
		break


Measured memory_bytes: 3060
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		int c = int.Parse(input[2]);
                if ((a == 5 || a == 7) && (b == 5 || b == 7) && (c == 5 || c == 7) && a + b + c == 17)
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");
	}
}


Measured memory_bytes: 2648
gets
ds = gets.split.map(&:to_i).each_with_object(Hash.new(0)) do |c, h|
  h[c] += 1
end

gets
ts = gets.split.map(&:to_i).each_with_object(Hash.new(0)) do |t, h|
  h[t] += 1
end

ans = "YES"

ts.keys.each do |t|
  if ts[t] > ds[t]
    ans = "NO"
    break
  end
  ts.delete(t)
  ds.delete(t)
end

puts ans


Measured memory_bytes: 56552
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int n = s.length();
		int[] sn = new int[n];
		int[] tn = new int[n];
		int cnt = 1;
		sn[0] = 0;
		tn[0] = 0;
		for(int i=1; i<n; i++){
			for(int j=1; j<i; j++){
				if(s.charAt(i)==s.charAt(j)){
					sn[i] = sn[j];
					break;
				}
				else sn[i] = cnt++;
			}
		}
		cnt = 1;
		for(int i=1; i<n; i++){
			for(int j=1; j<i; j++){
				if(t.charAt(i)==t.charAt(j)){
					tn[i] = tn[j];
					break;
				}
				else tn[i] = cnt++;
			}
		}
		boolean bl = false;
		for(int i=0; i<n; i++){
			if(sn[i]!=tn[i]){
				bl = true;
				break;
			}
		}
		System.out.println(bl==false ? "Yes" : "No");
	}
}

Measured memory_bytes: 30008
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n, ii1, a;
    scanf("%d", &n);
    for(ii1=0; ii1<3; ii1++){
        a = n%10;
        if( a == 7){
          printf("%s\n", "Yes");
          return 0;
        }
        n /= 10;
    }

    printf("%s\n", "No");
    return 0;
}


Measured memory_bytes: 1612
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll A, B, C;
	cin >> A >> B >> C;
  	string ans="NO";
	for(ll i=1; i<=B; i++){
      if(A*i%B==C)
        ans="YES";
    }
  cout<<ans<<endl;
}







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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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


vector<int>a(n);
for(int i = 0; i < n; i++){ 
    cin >> a[i];
}
sort(all(a));
int max_a = a[n - 1];
int ad = a[0]; 
REP(i,n - 1) if (abs(a[i] - max_a / 2) <= abs(ad - max_a / 2)) ad = a[i]; 
cout << max_a << " " << ad << endl;
}

Measured memory_bytes: 640
n,k=map(int,input().split())
xyc_=[list(input().split()) for _ in range(n)]
xyc=[]
for x,y,c in xyc_:
  x=int(x)%(2*k)
  y=int(y)%(2*k)
  if x>=k and y>=k:
    x%=k
    y%=k
  elif x>=k:
    x%=k
    c='W' if c=='B' else 'B'
  elif y>=k:
    y%=k
    c='W' if c=='B' else 'B'
  xyc.append([x,y,c])

wmap=[[0]*k for _ in range(k)]
bmap=[[0]*k for _ in range(k)]
for x,y,c in xyc:
  if c=='B':
    bmap[x][y]+=1
  else:
    wmap[x][y]+=1
for i in range(k):
  for j in range(k-1):
    bmap[i][j+1]+=bmap[i][j]
    wmap[i][j+1]+=wmap[i][j]
for i in range(k):
  for j in range(k-1):
    bmap[j+1][i]+=bmap[j][i]
    wmap[j+1][i]+=wmap[j][i]
#print(xyc)
#for b in bmap:
#  print(b)
#for w in wmap:
#  print(w)

def func(x,y):
  bret,wret=0,0
  bret=bmap[-1][-1]
  wret=wmap[-1][-1]
  if x==0 and y==0:
    pass
  elif x==0:
    bret-=bmap[-1][y-1]
    wret-=wmap[-1][y-1]
  elif y==0:
    bret-=bmap[x-1][-1]
    wret-=wmap[x-1][-1]
  else:
    bret-=bmap[-1][y-1]
    wret-=wmap[-1][y-1]
    bret-=bmap[x-1][-1]
    wret-=wmap[x-1][-1]
    bret+=2*bmap[x-1][y-1]
    wret+=2*wmap[x-1][y-1]
  return max(wmap[-1][-1]-wret+bret,bmap[-1][-1]-bret+wret)
ans=0
for i in range(k):
  for j in range(k):
    ans=max(ans,func(i,j))
print(ans)


Measured memory_bytes: 130896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k,n,m,c,l,ans,f1,f2;
    vector<pair<int,int> >v;
    string s;
    cin>>n>>m;
    cin>>s;
    for(i=0;i<n; i++){
        if(s[i]=='0'){ f1=i;j=i;j++;
        while(j<n){if(s[j]=='1') break;
            j++;i++;
        }
        f2=j-1;
        v.push_back(make_pair(f1,f2));
        }
    }
    l=v.size();// cout<<"l "<<l<<endl;
    if(l==0||l<=m){cout<<n<<endl;return 0;}
    ans=v[m].first;
    v.push_back(make_pair(-1,-1));v.push_back(make_pair(n,n));l+=2;
    sort(v.begin(),v.end());
    for(i=2;i<l-m;i++){
        k=v[i+m].first-v[i-1].second-1;
        ans=max(ans,k);
    }
    cout<<ans<<endl;

    //for(i=0;i<v.size();i++) cout<<v[i]<<" ";
}


Measured memory_bytes: 1020
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    string s; cin >> s;
    string rmv = "";
    vl lv; ll cnt = 0;
    REP(i, s.size()){
        ll now = s[i] == 'x' ? 0 : 1;
        if(now == 0){
            cnt++;
        }
        else{
            rmv += s[i];
            lv.pb(cnt); cnt = 0;
        }
    }
    lv.pb(cnt);
    string rmvr = rmv;
    reverse(rmvr.begin(), rmvr.end());
    if(rmvr != rmv){
        cout << -1 << endl; return 0;
    }
    
    cnt = 0; vl rv;
    reverse(s.begin(), s.end());
    REP(i, s.size()){
        ll now = s[i] == 'x' ? 0 : 1;
        if(now == 0){
            cnt++;
        }
        else{
            rv.pb(cnt); cnt = 0;
        }
    }
    rv.pb(cnt);
    
    ll ans = 0;
    REP(i, lv.size()){
        ans += abs(lv[i] - rv[i]);
    }
    cout << ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 2932
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

vector<vector<ll> > WarshallFloyd(vector<vector<P> >& adj) {
	int n=(int)adj.size();
	vector<vector<vector<ll> > > dp(n+1, vector<vector<ll> >(n, vector<ll>(n, INF*INF)));
	for(int i=0; i<n; ++i) dp[0][i][i]=0;
	for(int i=0; i<n; ++i) {
		for(int j=0; j<adj[i].size(); ++j) {
			dp[0][i][adj[i][j].first]=adj[i][j].second;
		}
	}

	for(int i=1; i<n+1; ++i) {
		for(int j=0; j<n; ++j) {
			for(int k=0; k<n; ++k) {
				dp[i][j][k]=min(dp[i-1][j][k], dp[i-1][j][i-1]+dp[i-1][i-1][k]);
			}
		}
	}
	return dp[n];
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w;
	cin>>h>>w;
	vector<vector<P>> c(10,vector<P>(10,P(0,1)));
	REP(i,10) REP(j,10) {
		c[i][j].first=j;
	}
	REP(i,10) REP(j,10) cin>>c[i][j].second;
	vector<vector<ll>> a(h,vector<ll>(w));
	REP(i,h) REP(j,w) cin>>a[i][j];
	vector<vector<ll>> mini=WarshallFloyd(c);
	ll ret=0;
	REP(i,h) {
		REP(j,w) {
			if(a[i][j]==-1) continue;
			ret+=mini[a[i][j]][1];
		}
	}
	cout<<ret<<endl;
}


Measured memory_bytes: 640
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    P = list(sorted([int(input()) for _ in range(N)], reverse=True))
    print(sum(P) - P[0] + P[0] // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3944
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

if N >= M:
    print("0")
    exit()

# print(X)
diffs = []
for i in range(len(X)-1):
    diffs.append(X[i+1] - X[i])

diffs.sort(reverse=True)

print(sum(diffs[N-1:]))



Measured memory_bytes: 13968
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    print(n//3)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;


int A, B, Q;
ll s, t, x;
vector<ll>S, T;

int main() {
	cin >> A >> B >> Q;
	while (A--) {
		cin >> s;
		S.push_back(s);
	}
	while (B--) {
		cin >> t;
		T.push_back(t);
	}
	S.push_back(-llmax/20);
	S.push_back(llmax/20);
	T.push_back(-llmax/20);
	T.push_back(llmax/20);
	sort(S.begin(), S.end());
	S.erase(unique(S.begin(), S.end()), S.end());
	sort(T.begin(), T.end());
	T.erase(unique(T.begin(), T.end()), T.end());
	while (Q--) {
		cin >> x;
		auto sr = lower_bound(S.begin(), S.end(), x);
		auto tr = lower_bound(T.begin(), T.end(), x);
		auto sl = sr;
		auto tl = tr;
		--sl;
		--tl;
		cout << min({ max(*sr,*tr) - x,x - min(*sl,*tl),*sr - *tl + min(*sr - x,x - *tl),*tr - *sl + min(*tr - x,x - *sl) }) << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A, B, P, c1 = 0, c2 = 0, c3 = 0;

  std::cin >> N >> A >> B;

  for (int i = 0; i < N; i ++) {
    std::cin >> P;

    if (P <= A) {
      c1 ++;
    }
    else if (P <= B) {
      c2 ++;
    }
    else {
      c3 ++;
    }
  }

  std::cout << std::min({c1, c2, c3}) << std::endl;

  return 0;
}


Measured memory_bytes: 256