akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll k=0,s=0,n,min=100000000000,ans=0,max=0;
    string s1,s2,s3;
    cin >> s1;
    
    rep(i,s1.size()){
        if(s1[i]=='A'){
            for(int j=i;j<s1.size();j++){
                ans++;
                if(s1[j]=='Z'){
                    if(max<ans)
                        max = ans;
                }
            }
            break;
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    string ans = "";
    rep(i, s.size()){
        if(s[i] == 'B'){
            if(ans.size()) ans.pop_back();
        }
        else ans.pb(s[i]);
    }
    cout << ans;
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string S;
    int K;
    cin >> S >> K;
    int N = S.size();
    int dp[N][N][K+1];
    rep(i, K+1){
        rep(j, 2*i+1){
            rep(k, N-j){
                dp[k][k+j][i] = j+1;
            }
        }
        rep2(j, 2*i+1, N-1){
            rep(k, N-j){
                if(S[k] == S[k+j]){
                    if(j == 1 && i == 0) dp[k][k+j][i] = 2;
                    else dp[k][k+j][i] = dp[k+1][k+j-1][i]+2;
                }
                else{
                    dp[k][k+j][i] = max(dp[k+1][k+j][i], dp[k][k+j-1][i]);
                    if(i > 0){
                        dp[k][k+j][i] = max(dp[k][k+j][i], dp[k+1][k+j-1][i-1]+2);
                    }
                }
            }
        }
    }
    cout << dp[0][N-1][K] << endl;
}

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

def check_prime(num):
	for i in range(2, int(pow(num, 0.5)) + 1):
		if num%i == 0:
			return False
	return True

def main():
	N, P = map(int, input().split())

	if N == 1:
		print(P)
		return

	if check_prime(P):
		print(1)
		return
	
	MAX_PRIME = int(pow(P, 0.5))
	primes = []
	is_prime = [True] * (MAX_PRIME+1)
	for i in range(2, MAX_PRIME+1):
		if is_prime[i]:
			primes.append(i)
			for j in range(2*i, MAX_PRIME+1, i):
				is_prime[j] = False
	# print(primes)

	so = []
	for p in primes:
		count = 0
		while P%p == 0:
			count += 1
			P //= p
		if count > 0:
			so.append((p, count))
	if P != 1:
		so.append((P, 1))
	# print(so)

	ans = 1
	for (p, count) in so:
		ans *= pow(p, count//N)
	print(ans)
	

if __name__ == "__main__":
	main()

Measured memory_bytes: 13988
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
typedef long long ll;
ll d[515151];
ll now[515151];
ll lb[515151];
int main()
{
	int num;
	ll gen;
	scanf("%d%lld", &num, &gen);
	for (int i = 0; i < num; i++)scanf("%lld", &d[i]);
	now[0] = gen;
	for (int i = 0; i < num; i++)now[i + 1] = min(now[i], abs(now[i] - d[i]));
	lb[num] = 1;
	for (int i = num - 1; i >= 0; i--)
	{
		if (lb[i + 1] * 2 <= d[i])lb[i] = lb[i + 1];
		else lb[i] = lb[i + 1] + d[i];
	}
	int query;
	scanf("%d", &query);
	for (int i = 0; i < query; i++)
	{
		int z;
		scanf("%d", &z);
		z--;
		if (lb[z + 1] <= now[z])printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 13824
#include<stdio.h>
  
int main(void)
{
    char num;
    int sum[128]={0,};
    int count=0,i,large=65,small=97,n=26;
    while(scanf("%c", &num) != EOF){
        sum[(int)num]++;
    }
    for(i=0;i<n;i++){
        printf("%c : %d\n",small+i,sum[i+large]+sum[i+small]);
    }
    return 0;   
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
#include<tuple>
using namespace std;
#define ll long long
int main(){
  int n, m;
  ll a[100000], b[100001] = {}, ans = 0;
  map<ll, ll> d;
  cin >> n >> m;
  d[0]++;
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i+1] = (a[i] + b[i]) % m; 
    d[b[i+1]]++;
  }
  for(map<ll, ll>::iterator iter = d.begin();iter !=d.end();iter++){
    ans += (iter->second * (iter->second -1)) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll N,x;
	ll a[101];
	ll ninzu=0;
	scan(N);scan(x);
	rep(i,N){
		scan(a[i]);
	}
	ll xnow=x;
	sort(a,a+N);
	rep(i,N){
		if(xnow<a[i]) break;
		if(xnow>=a[i]&&i!=N-1){
			xnow-=a[i];
			ninzu++;
		}
		else if(xnow==a[i]&&i==N-1){
			xnow-=a[i];
			ninzu++;
		}
	}
	prin(ninzu);
	return 0;
}


Measured memory_bytes: 256
<?php
    $in = trim(fgets(STDIN));
    $temp = str_split($in);
    $count = count($temp);
    $work = array();
    $flag = 1;
    for($i=0;$i<$count;$i++){
        if(isset($work[ord($temp[$i])])){
            $work[ord($temp[$i])]++;
        } else {
            $work[ord($temp[$i])] = 1;
        }
    }

    foreach($work as $val){
        if($val % 2 != 0){
            $flag = 0;
        }
    }

    if($flag){
        echo "Yes";
    } else {
        echo "No";
    }
?>  

Measured memory_bytes: 3576
#include<iostream>
#include<string>
using namespace std;
int main(){
int x;
string N,y;
cin >> N;
x=N.size()-1;
y=N[x];
if(y=="2"||y=="4"||y=="5"||y=="7"||y=="9"){cout <<"hon" << endl;}
else if(y=="3"){cout <<"bon"<<endl;}else if(y=="0"||y=="1"||y=="6"||y=="8"){cout << "pon" <<endl;}

return 0;
}



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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int query_value(vector<int>& A) {
    int n = A.size();
    int val = 0;
    for (int i = 0; i < n; i++) {
        val = (val + 9) / 10 * 10;
        val += A[i];
    }
    return val;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n = 5;
    int min_val = 1e9;
    vector<int> A;
    A.resize(n);
    for (int i = 0; i < n; i++)
        cin >> A[i];
    sort(A.begin(), A.end());
    do {
        int val = query_value(A);
        min_val = min(min_val, val);
    } while (next_permutation(A.begin(), A.end()));
    cout << min_val << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

double xs, ys, xt, yt;
int N;
double x[1000], y[1000], r[1000];

double dist(double xa, double ya, double xb, double yb){
    return sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
}

double cost[1000];
priority_queue<pair<double, int>> pq;

const double EPS = 1e-7;

signed main(){
    cin >> xs >> ys >> xt >> yt;
    cin >> N;
    rep(i, N) cin >> x[i] >> y[i] >> r[i];

    rep(i, N){
        cost[i] = max(0.0, dist(xs, ys, x[i], y[i])-r[i]);
        pq.push({ -cost[i],i });
    }

    while(!pq.empty()){
        int i = pq.top().second;
        pq.pop();
        rep(j, N){
            if(i == j) continue;
            if(cost[j] > max(cost[i], cost[i]+dist(x[i], y[i], x[j], y[j])-r[i]-r[j])+EPS){
                cost[j] = max(cost[i], cost[i]+dist(x[i], y[i], x[j], y[j])-r[i]-r[j]);
                pq.push({ -cost[j],j });
            }
        }
    }

    double ans = dist(xs, ys, xt, yt);
    rep(i, N){
        ans = min(ans, max(cost[i], cost[i]+dist(xt, yt, x[i], y[i])-r[i]));
    }
    cout << fixed << setprecision(16) << ans << endl;
}

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

def read():
    N, K = map(int, input().strip().split())
    V = list(map(int, input().strip().split()))
    return N, K, V


def solve(N, K, V):
    ans = 0
    for k in range(min(K, N) + 1):
        for l in range(0, k+1):
            s = sorted(V[:l] + V[N-k+l:])
            v = sum(s)
            ans = max(ans, v)
            if k < K:
                # 最大(min(K-k, k))回、キューに戻すことが可能
                # 負の数は戻せるだけ戻せばよい
                for m in range(min(K-k, k)):
                    if s[m] < 0:
                        v -= s[m]
                ans = max(ans, v)

    return ans


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000
#define MOD 1000000009

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<iostream> //c++
#include<algorithm>
/*
int main(){
	int a=0;
	char A[5];
	for (int i = 0; i < 5; i++) {
		scanf("%c\n", &A[i]);
	}
	
	for(int i = 0; i < 5; i++) {
		if (A[i] =='A' &&A[i + 1]=='C') {
			a = 1;
		
		}
	}
	if (a == 1) {
		printf("Yes");

	}
	else {
		printf("No");
	}
}*/

using namespace std;
/*int main() {
	int g;
	int  N,Num=0;
	vector<int>a;
	cin >> N;
	for (int i = 0; i < N;i++) {

		cin >> g;

		a.push_back(g);
	

	}
	int t,p=0;
	while (true) {
		t=a[p] ;
		a[p] = -1;
		p = t;
		if (p == -1) {
			Num = -1;
			break;
		}
			Num++;
			if (p == 2) {
				break;
			}
			p = p - 1;
	}
	cout << Num;
	



int main() {
	
		long long N, g;
	vector<int>a;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> g;
		a.push_back(g);
	}
	sort(a.begin(), a.end());
	long long Num1 = 0, Num2 = 0, Num;
	for (int i = 0; i < N; i++)
	{
		if (a[i] == a[i + 1] && a[i] >= Num1 && i != N - 1) {
			Num2 = Num1;
			Num1 = a[i];
			i++;
		}
	}
	Num = Num1 * Num2;
	cout << Num;
	return 0;
}
	

int main(){vector<int>S;
	int count=0;
	int g;

		cin >> g;
		S.push_back((g %100000)/10000);
		S.push_back((g %10000)/1000);
		S.push_back((g %1000)/100);
		S.push_back((g %100)/10);
		S.push_back((g %10)/1);
		S.push_back((g %1000000)/100000);
		
		
		for (int i = 0; i < 6; i++) {
			if (S[i] == 1) {

				count++;
			}
		}



	cout << count;






*/

int main(){
int num=0;

string s[100];
string t[100];

	int N, M;
	cin >> N;
	
	
	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin>>t[i];
	}
	
	int max=0;
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {

			if (s[k] == s[i]) {

				num++;
			}
		}
		for (int i = 0; i < M; i++) {
			
				if (s[k] == t[i]) {
				
				num--;
			}
		}
		
		if (max < num){
			max = num;
		}
		num = 0;
	}
	cout << max;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)























int main(){
    int Q;
    scanf("%d", &Q);
    
    priority_queue<ll> que1;
    priority_queue<ll, vector<ll>, greater<ll>> que2;
    
    ll sum1 = 0, sum2 = 0, bb = 0;
    
    for(int i = 0; i < Q; i++){
        int q;
        scanf("%d", &q);
        if(q == 1){
            ll a, b;
            scanf("%lld %lld", &a, &b);
            bb += b;
            
            if(que1.empty()){
                que1.push(a);
                continue;
            }
            if(que2.empty()){
                que1.push(a);
                que2.push(que1.top());
                que1.pop();
                sum2 += que2.top() - que1.top();
                continue;
            }
            
            ll t1 = que1.top(), t2 = que2.top();
            if(a < t2){
                if(t1 < a){
                    sum1 += (a - t1) * que1.size();
                    sum2 -= (a - t1) * que2.size();
                    que1.push(a);
                }
                else{
                    sum1 += t1 - a;
                    que1.push(a);
                }
                
                if(que1.size() > que2.size() + 1){
                    ll t3 = que1.top(); que1.pop();
                    ll t4 = que1.top();
                    sum1 -= (t3 - t4) * que1.size();
                    que2.push(t3);
                    sum2 += (t3 - t4) * que2.size();
                }
            }
            else{
                sum2 += a - t1;
                que2.push(a);
                if(que1.size() < que2.size()){
                    sum2 -= (t2 - t1) * que2.size();
                    sum1 += (t2 - t1) * que1.size();
                    que1.push(t2);
                    que2.pop();
                }
            }
        }
        else{
            printf("%lld %lld\n", que1.top(), sum1 + sum2 + bb);
        }
    }
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;
  cin>>n;
  vector<int> s(n);
  for(int i=0;i<n;++i){
    cin>>s[i];
    sum+=s[i];
  }
  sort(s.begin(),s.end());
  for(int i=0;i<n;++i){
    if(sum%10!=0) break;
    if(s[i]%10!=0) sum-=s[i];
  }
  if(sum%10==0) cout<<0<<endl;
  else cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
s = list(map(lambda x:ord(x)-97,input()))
t = list(map(lambda x:ord(x)-97,input()))

ret = "Yes"
transform_mapping = [[0] * 26 for _ in range(26)]

for si,ti in zip(s,t):
    transform_mapping[si][ti] = 1
for i in transform_mapping:
    if sum(i) >= 2:
        ret = "No"
for i in zip(*transform_mapping):
    if sum(i) >= 2:
        ret = "No"
print(ret)


Measured memory_bytes: 6664
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


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

  int a,b,c,d;
  cin>>a>>b>>c>>d;

  cout<<a*b-(c*b)-(d*a)+c*d<<endl;


}

Measured memory_bytes: 256
import numpy as np
H,W = map(int,input().split())
h,w = map(int,input().split())
matrix = np.ones((H,W))
h_num = np.random.choice(H,h,replace=False)
w_num = np.random.choice(W,w,replace=False)

for _ in h_num:
  matrix[_,:] = 0
for _ in w_num:
  matrix[:,_] = 0

print(int(np.sum(matrix)))


Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int inf = 1e9;

int h, w, c;
int cnt;
int ans;

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

bool inside(int x, int y) {
    return 0 <= x && x < h && 0 <= y && y < w;
}

void change(VV &b, int oc, int nc, int i, int j) {
    if (nc == oc) return;
    if (!inside(i, j)) return;
    if (b[i][j] != oc) return;
    b[i][j] = nc;
    cnt++;
    rep(k, 4) {
        change(b, oc, nc, i + dx[k], j + dy[k]);
    }
}


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

    while (cin >> h >> w >> c, h) {
        VV a(h, V(w));
        rep(i, h) rep(j, w) cin >> a[i][j];

        int ans = -1;

        rep(s, pow(6, 4)) {
            VV b = a;
            int perm = s;
            rep(step, 4) {
                change(b, b[0][0], (perm % 6) + 1, 0, 0);
                perm /= 6;
            }
            change(b, b[0][0], c, 0, 0);

            cnt = 0;
            change(b, b[0][0], 10, 0, 0);
            ans = max(ans, cnt);
        }

        cout << ans << endl;
    }
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int mi = 1000000, ma = -10000000;
  int a[m];
  ll b[m - 1];
  b[0] = 0;
  rep(i, m) {
    cin >> a[i];
    mi = min(mi, a[i]);
    ma = max(ma, a[i]);
  }
  ll sum = abs(ma - mi);
  //cout << sum << endl;
  sort(a, a + m);
  rep(i, m - 1){
    b[i] = a[i + 1] - a[i];
    //cout << b[i] << endl;
  }
  sort(b, b + m - 1, greater<>());
  if(n >= m) cout << 0 << endl;
  else{
    rep(i, n - 1){
      sum -= b[i];
    }
    cout << sum << endl;
  }
  
  
        

  return 0;
}

Measured memory_bytes: 4760
import java.util.Scanner;
import java.util.ArrayList;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<Integer> list=new ArrayList<>();
		int[] set={0,2,5,5,4,5,6,3,7,6};
		int[] a=new int[m];
		String[] dp=new String[n+1];
		dp[0]="";
		for(int i = 0; i<m; i++){
			a[i]= sc.nextInt();
		}
		for(int i = 0; i<=n; i++){
			for(int j = 0; j<m; j++){
				if(i>=set[a[j]] && dp[i-set[a[j]]]!=null){
					if(check(dp[i-set[a[j]]]+a[j],dp[i])){
						dp[i]=dp[i-set[a[j]]]+a[j];
					}
				}
			}
		}
		System.out.println(dp[n]);
	}
	static boolean check(String a,String b){
		if(b==null || a.length()>b.length()){
			return true;
		}
		if(a.length()<b.length()){
			return false;
		}
		return a.compareTo(b)>0;
	}
}

Measured memory_bytes: 376780
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>

using namespace std;

class Fibonacci
{
public:
  array<int,45> f;
  int fib( int n );
  int init();
};

int Fibonacci::init()
{
  for ( auto& i : f )
    i = -1;

  f[0] = 1;
  f[1] = 1;

  return 0;
}

int Fibonacci::fib( int n )
{
  if ( f[n] > 0 )
    return f[n];

  int ret = fib( n - 1 ) + fib( n - 2 );
  f[n] = ret;

  return ret;
}

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

  Fibonacci f;

  f.init();
  cout << f.fib( n ) << endl;

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int w,h;
    cin>>w>>h;
    long long mod=1e9+7;
    char arr[w][h];
    long long dp[w][h];
    for(int i=0;i<w;i++)
    {
        for(int j=0;j<h;j++)
        {
            cin>>arr[i][j];
            dp[i][j]=0;
        }
    }
    dp[0][0]=0;
    dp[0][1]=1;
    dp[1][0]=1;
    for(int i=0;i<w;i++)
    {
        for(int j=0;j<h;j++)
        {
            if(arr[i][j]=='#')
                continue;
            if(i-1>=0&&arr[i-1][j]!='#')
            dp[i][j]+=dp[i-1][j];
               if(j-1>=0&&arr[i][j-1]!='#')
                dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[w-1][h-1];
   return 0;
}


Measured memory_bytes: 9088
import itertools
import bisect
N = int(input())
A = [int(_) for _ in input().split()]
C = list(itertools.accumulate([0] + A))
i = bisect.bisect(C, C[-1] // 2)
#2*(C[i]-x)=C[-1]-x
x = 2 * C[i] - C[-1]
#2*(C[i-1]+y)=C[-1]+y
y = C[-1] - 2 * C[i - 1]
print(min(x, y))


Measured memory_bytes: 25896
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

ll wait(ll now, ll s, ll f) {
  if (now <= s) return s - now;
  return (now + f - 1) / f * f - now;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> C(N - 1), S(N - 1), F(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }
  for (int i = 0; i < N; i++) {
    ll now = 0;
    for (int j = i; j < N - 1; j++) {
      now += wait(now, S[j], F[j]);
      now += C[j];
    }
    cout << now << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// Code by ajcxsu
// Geometry template

#include<bits/stdc++.h>
#define EPS (1e-9)
using namespace std;

struct Point {
    double x,y;
    Point(double x=0,double y=0):x(x), y(y) {}

    Point operator +(Point p) { return Point(x+p.x,y+p.y); }
    Point operator -(Point p) { return Point(x-p.x,y-p.y); } // 加减
    Point operator *(double a) { return Point(x*a,y*a); }
    Point operator /(double a) { return Point(x/a,y/a); } // 数乘

    double norm() { return x*x+y*y; } // 范数
    double abs() { return sqrt(norm()); } // 大小

    bool operator < (const Point &p) { return x!=p.x?x<p.x:y<p.y; }
    bool operator == (const Point &p) { return fabs(p.x-x) < EPS && fabs(p.y-y) < EPS; }
} ;
typedef Point Vector;

double dot(const Point &a, const Point &b) {
    return a.x*b.x+a.y*b.y;
} // 内积
double cross(const Point &a, const Point &b) {
    return a.x*b.y-a.y*b.x;
} // 外积
bool equals(double a, double b) { return fabs(a-b)<EPS; } // 误差相等

struct Line {
    Point p1,p2;
} ;
typedef Line Seg;

/* 1 正交 2 平行 0 其他 */
int PO(Vector a, Vector b) {
    if(equals(dot(a,b), 0)) return 1;
    else if(equals(cross(a,b), 0)) return 2;
    else return 0;
}
int PO(Line a, Line b) { // 正交、平行判定
    return PO(a.p2-a.p1, b.p2-b.p1);
}

istream& operator >>(istream &in, Vector &a) {
    in>>a.x>>a.y;
    return in;
}
istream& operator >>(istream &in, Line &a) {
    in>>a.p1>>a.p2;
    return in;
} // 输入重载

Point project(Point a, Seg b) {
    Vector base=b.p2-b.p1;
    Vector hypo=a-b.p1;
    return b.p1+base*(dot(base, hypo)/ base.norm());
} // 投影

Point ref(Point a, Seg b) {
    Vector base=project(a,b)-a;
    return a+base*2;
} // 映像

int ccw(Vector a, Vector b) {
    if(cross(a,b)>EPS) return 1; // Counter clockwise
    else if(cross(a,b)<-EPS) return -1; // Clockwise
    else if(dot(a,b)<-EPS) return 2; // Online back
    else if(a.norm()<b.norm()) return -2; // Online front
    else return 0; // On segement
}

ostream& operator <<(ostream &out, Vector a) {
    out<<a.x<<' '<<a.y;
    return out;
} // 输出重载

int main() {
    cout.setf(ios::fixed);
    cout<<setprecision(10); // 设置输出精度

    Point p0,p1;
    cin>>p0>>p1;
    int q,ans;
    cin>>q;
    Vector a=p1-p0;
    while(q--) {
        Point p2;
        cin>>p2;
        ans=ccw(a,p2-p0);
        if(ans==1) cout<<"COUNTER_CLOCKWISE"<<endl;
        else if(ans==-1) cout<<"CLOCKWISE"<<endl;
        else if(ans==2) cout<<"ONLINE_BACK"<<endl;
        else if(ans==-2) cout<<"ONLINE_FRONT"<<endl;
        else cout<<"ON_SEGMENT"<<endl;
    }
    return 0;
}



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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> B = A;
  sort(B.begin(), B.end());
  int a = B[(N - 1) / 2], b = B[N / 2];
  for (int i = 0; i < N; i++) {
    if (A[i] <= a) {
      cout << b << endl;
    } else if (A[i] >= b) {
      cout << a << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3840
def mht(a,b):
	return abs(a[0]-b[0])+abs(a[1]-b[1])
n,m=map(int,input().split())
p=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]
for i in p:
	a=[10**9,0]
	for j in range(m):
		if mht(i,c[j])<a[0]:
			a=[mht(i,c[j]),j+1]
	print(a[1])

Measured memory_bytes: 70908
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
struct Team{
  int id,m,tm;
  Team():id(0),m(0),tm(0){}
  Team(int i):id(i),m(0),tm(0){}
};

bool operator < (const Team& a, const Team& b){
  return a.m>b.m || (a.m==b.m && a.tm < b.tm) || (a.m==b.m && a.tm==b.tm && a.id > b.id);
}

int mistake[60][20];

int main(){
  int m,t,p,r;
  while(cin>>m>>t>>p>>r,m||t||p||r){
    memset(mistake,0,sizeof(mistake));
    Team tem[60];
    for(int i=0;i<t;++i) tem[i]=Team(i+1);
    while(r--){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      b--;
      if(!d){
	tem[b].m++;
	tem[b].tm+=a+mistake[b][c]*20;
      }
      else
	mistake[b][c]++;
    }
    sort(tem,tem+t);
    for(int i=0;i+1<t;++i){
      cout<<tem[i].id;
      if(tem[i].m==tem[i+1].m && tem[i].tm==tem[i+1].tm) cout << "=";
      else cout << ",";
    }
    cout << tem[t-1].id << endl;
  }
  return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

char x[] = {'#','#','.','.'};
char y[] = {'#','.','#','.'};
char buf[125];

int main(){
  int n;
  scanf("%d",&n);
  string a,b;
  bool go = true;
  REP(i,n){
    bool flag = false;
    if(go){
      REP(j,4){
        string c,d;
        c=a+x[j];
        d=b+y[j];
        printf("%s\n%s\n",c.c_str(),d.c_str());
        fflush(stdout);
        scanf("%s",buf);
        if(buf[0]=='e')return 0;
        if(buf[0]=='T'){
          a=c;
          b=d;
          flag=true;
          break;
        }
      }
    }else{
      REP(j,4){
        string c,d;
        c=x[j]+a;
        d=y[j]+b;
        printf("%s\n%s\n",c.c_str(),d.c_str());
        fflush(stdout);
        scanf("%s",buf);
        if(buf[0]=='e')return 0;
        if(buf[0]=='T'){
          a=c;
          b=d;
          flag=true;
          break;
        }
      }
    }
    if(!flag){
      go=false;
      --i;
    }
  }
  return 0;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e,k;
  bool ok;
  
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a <= k)
  {
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  
  }
  
  
  return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if (N * A > B) {
    cout << B << endl;
  } else if (N * A < B) {
    cout << N * A << endl;
  } else {
    cout << B << endl;
  }  
}

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

char map[8][9];

void rotate(){
	char bM[8][9];
	memcpy(bM,map,72);
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			map[i][j]=bM[7-j][i];
		}
	}
}

void showmap(){
	for(int i=0;i<8;i++){
		printf("%s\n",map[i]);
	}
}
int main(void){
	for(int j=0;j<=7;j++){
		cin >> map[j];
	}
	printf("90\n");
	rotate();
	showmap();
	printf("180\n");
	rotate();
	showmap();
	printf("270\n");
	rotate();
	showmap();
    return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	//定義関数から参照できる変数定義はこの辺
	static int S;
	static int Ary[]=new int[1000001];
	static int ans=0;

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		S = sc.nextInt();
		Ary[1] = S;
		loop1:for(int i=1;i<=1000000;i++){
			if (Ary[i]%2==0) {
				Ary[i+1] = Ary[i]/2;
				for(int j=1;j<=i;j++){
					if (Ary[j]==Ary[i+1]) {
					 	ans=i+1;
					 	break loop1;
					} 
				}
			}
			else{
				Ary[i+1] = Ary[i]*3+1;
					for(int j=1;j<=i;j++){
					if (Ary[j]==Ary[i+1]) {
					 	ans=i+1;
					 	break loop1;
					} 
				}
			}
		}
		System.out.println(ans);
    }
}

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

struct Edge {
	int to, id;
	Edge(int to, int id) :to(to), id(id) {}
};

vector<Edge> esets[55];

vector<int> es;
int dfs(int st, int to, int prev = -1) {
	if (st == to) return true;
	for(Edge e : esets[st]) {
		if (prev == e.to) continue;
		if ( dfs(e.to, to, st) == true) {
			es.push_back(e.id);
			return true;
		}
	}
	return false;
}


int main(void) {
	int n,m;
	cin >> n;
	rep(i, n-1) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		esets[a].emplace_back(b, i);
		esets[b].emplace_back(a, i);
	}
	
	cin >> m;
	vector<ll> combination(m);	// 各条件を白線が有効な場合にbitを立てている
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		es.clear();	// es = vector<int>()
		--a;
		--b;
		dfs(a, b);
		for(int id : es) {
			combination[i] |= 1ll<<id;
		}
	}
	
	ll answer = 0;
	int counter;
	rep(i, 1<<m) {
		ll mask = 0;
		rep(j,m) {
			if (((i>>j)&1)==1) mask |= combination[j];
		}
		int counter = __builtin_popcountll(mask);
		ll now = 1ll << (n-1-counter);
		if (__builtin_popcountll(i)%2==0) answer += now;
		else answer -= now;
		
	}
	
	cout << answer << endl;
	
	return 0;
	
}


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

int main() {
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);      freopen("outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);

   int n;
   cin >> n;
   string s;
   cin >> s;
   int l = 0, r = n - 1, ans = 0, red = 0, wht = 0;
   for (auto i : s) {
      red += (i == 'R');
      wht += (i == 'W');
   }
   while (l < r) {
      if (s[l] == 'W') {
         while (s[r] != 'R' && l < r)
            r--;
         if (l >= r)
            break;
         r--;
         ans++;
      }
      l++;
   }
   cout << min({wht, red, ans}) << '\n';

   return 0;
}

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

using namespace std;

#define pb            push_back
#define mp            make_pair
#define po            pop_back
#define fi            first
#define se            second
#define mxn           200001
#define ll            long long int
#define ldb           long double
#define fr(i,a,b,k)   for(ll i=a ; i<b ; i+=k)
#define frr(i,a,b,k)  for(ll i=a ; i>b ; i-=k)
#define all(v)        v.begin(),v.end()
#define endl          "\n"
#define deg(x)        cout<<endl<<#x<<" = "<<(x)<<endl;
#define casep(x)      cout<<"Case #"<<(x)<<": ";
#define fast          ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

typedef pair<ll,ll> pp;
typedef vector<ll> vi;
typedef vector<pp> vpp;
typedef vector<vi> vvi;

const int inf = 1e9+7;

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b){ return __gcd(a,b);}
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}

void solve(ll test){

    ll n;
    cin >> n;
    ll a[n+1];
    ll cnt = 0;
    fr(i,1,n+1,1){
        cin >> a[i];
        if(i&1 && a[i]&1)cnt++;
    }

    cout << cnt;

}

int main(){

    fast;
    int t=1;
    // cin >> t;
    for(int i=1 ; i<=t ; i++){
        solve(i);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
#define REP(i, n) for(int (i)=0; (i)<(int)(n); (i)++)

int main(){
    string s;
    cin >> s;
    int ans = 0;
    REP(i, 6){
        if(s[i]=='1') ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  double r,menseki,enshu;
  cin >> r;
  enshu=3.141592653589*2*r;
  menseki=3.141592653589*r*r;
  printf("%f %f\n",menseki,enshu);
  return 0;
}

Measured memory_bytes: 1232
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var N = cin.ReadInt;
            var W = cin.ReadInt;
            var dp = new int[W + 1];   //weight to value
            dp[0] = 0;
            for(int i = 0; i < N; i++) {
                var item = cin.ReadIntArray(2);
                var v = item[0];
                var w = item[1];
                for(int j = 0; j + w <= W; j++) {
                    dp[j + w] = Max(dp[j + w], dp[j] + v);
                }
            }
            Console.WriteLine(dp.Last());
        }
    }

    static class ExtendClass {
        public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }

}



Measured memory_bytes: 18708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  ll N,A,B;
  cin >> N >> A >> B;
  ll T = A + B;
  if(A == 0){
    cout << 0 << endl;
    return 0;
  }
  ll ans = A * ll(N/T);
  ll r = N % T;
  ans += min(A,r);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <vector>
#include <unordered_map>
using namespace std;


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

  vector<int> spf(N+1, 0);
  for (long long i = 0; i <= N; i++) spf[i] = i;
  for (long long i = 2; i <= N; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j <= N; j += i) {
        if (spf[j] == j) spf[j] = i;
      }
    }
  }

  long long ans = 0;
  long long numDivisors, x;
  unordered_map<int, int> mp;
  for (int i = 1; i <= N; i++) {
    x = i;
    numDivisors = 1;
    while (x != 1) {
      mp[spf[x]]++;
      x /= spf[x];
    }
    for (auto& p : mp) numDivisors *= (p.second+1);
    mp.clear();

    ans += i * numDivisors;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 42324
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read() {
	int x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
const int N = 1010;
int a, b, c, d, ans, i, v[N];
int main() {
	a = read(); b = read(); c = read(); d = read();
	for (i = a + 1; i <= b; i++) v[i] = 1;
	for (i = c + 1; i <= d; i++) if (v[i]) ans++;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3604
s = input()
if len(s) % 2 == 0:
    s_1 = s[:len(s) // 2]
    s_2 = s[len(s) // 2:][::-1]
else:
    s_1 = s[:len(s) // 2 + 1]
    s_2 = s[len(s) // 2:][::-1]
ans = 0
for i in range(len(s_1)):
    if s_1[i] != s_2[i]:
        ans += 1
print(ans)

Measured memory_bytes: 9068
import java.io.*;
import java.util.Arrays;
import java.util.HashSet;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		HashSet<String> list = new HashSet<String>();

		for ( int i = 0; i<n ; i++ ) {
			String[] str = (br.readLine()).split(" ");
			if (str[0].equals("insert")) {
				list.add(str[1]);
			}else if(str[0].equals("find")){
				if (list.contains(str[1])) {
					System.out.println("yes");
				}else{
					System.out.println("no");

				}
			}else{
				System.out.println("Error");
			}
		}

	}
}

Measured memory_bytes: 189796
import math

def comb_count(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = (int(S[i]) * tmp + current)
    mod = current % 2019
    # ans += mods[mod]
    mods[mod] += 1
    tmp = tmp * 10 % 2019

for mod in mods:
    if mod > 1:
        # print(mod)
        ans += comb_count(mod, 2)

print(ans)


Measured memory_bytes: 9484
c[100],i;main(A,a,C,n,x,r,s){scanf("%d%d%d%d",&n,&A,&a,&C);for(i=0;i<n;i++)scanf("%d",c+i);qsort(c,n,4,"\x8b\6+\7\xc3");for(r=C/A,x=i=0;i<n;i++){x+=c[i];s=(C+x)/(A+a*(i+1));if(s<r)break;r=s;}i=!printf("%d\n",r);}

Measured memory_bytes: 600
#include <stdio.h>

int main(){
    int a[28],i,j,x[30];
    for (i=0;i<28;i++) {
        scanf("%d",&a[i]);
    }
    for (i=1;i<=30;i++) {
        x[i]=0;
        for (j=0;j<28;j++) {
            if (a[j]==i) {x[i]=1;}
        }
    }
    for (i=1;i<=30;i++) {
        if (x[i]==0) {
            printf("%d\n",i);
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n);
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	ll s=0;
	for(ll i=0;i<k;i++)
	{
		s+=a[i];
	}
	cout<<s<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1;
	//cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;scanf("%lld",&n);
    ll ans=1e17;
    for(ll i=1;i*i<=n;i++)if(n%i==0)
    {
        ll t1=i,t2=n/i;
        ll dis=t1-1+t2-1;
        ans=min(dis,ans);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i++)
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
string keyence="keyence";
int main(){
    ll a,b,c,ans;
    cin>>a>>b>>c;
    ll mi=max(a,max(b,c));
    if(a==mi)ans=b*c/2;
    if(b==mi)ans=a*c/2;
    if(c==mi)ans=a*b/2;
    cout<<ans<<endl;
}

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

long long INF = 1000000000000000;

template<typename Type>
vector<Type> Dijkstra(vector<vector<pair<long long, Type> > > Graph, long long Start) {
	using PT = pair<Type, long long>;
	const Type Inf = INF;
	long long Size = Graph.size();
	vector<Type> Dist;
	Dist.assign(Size, Inf);
	priority_queue<PT, vector<PT>, greater<PT> > PQ;

	Dist[Start] = 0;
	PQ.emplace(PT(Dist[Start], Start));
	while (!PQ.empty()) {
		PT p = PQ.top();
		PQ.pop();
		Type D = p.first;
		long long E = p.second;
		if (Dist[E] < D) continue;
		for (pair<long long, Type> Next : Graph[E]) {
			Type ND = Next.second;
			long long NE = Next.first;
			if (Dist[NE] > Dist[E] + ND) {
				Dist[NE] = Dist[E] + ND;
				PQ.emplace(PT(Dist[NE], NE));
			}
		}
	}
	return Dist;
}

int main() {
	long long N, M;
	vector<vector<pair<long long, long long> > > V;
	cin >> N >> M;
	V.resize(N);
	for (int i = 0; i < M; i++) {
		long long L, R, C;
		cin >> L >> R >> C;
		L--, R--;
		V[L].push_back({ R, C });
	}
	for (int i = 0; i < N - 1; i++) {
		V[i + 1].push_back({ i, 0 });
	}
	vector<long long> Dist = Dijkstra(V, 0);
	cout << (Dist[N - 1] == INF ? -1 : Dist[N - 1]) << endl;
}

Measured memory_bytes: 15996
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1000000000000
#define M 1000000007
typedef long long ll;

vector<ll> a;

int main()
{
  ll n, tempA, ans = 0, sum = 0;
  cin >> n;

  REP(i, n)
  {
    cin >> tempA;
    a.push_back(tempA);
  }

  REP(i, n - 1)
  {
    sum += a[i];
    sum %= M;
    ans += (a[i + 1] * sum);
    ans %= M;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5288