akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > xy(n);
    rep(i, n) {
        int a;
        cin >> a;
        xy[i].resize(a);
        rep(j, a) {
            cin >> xy[i][j].first >> xy[i][j].second;
        }
    }

    int cc=0;
    rep(b, 1<<n) {
        bitset<15> bits(b);
        int M;
        rep(i, n) {
            if(!bits.test(i)){
                continue;
            }
            rep(j, xy[i].size()) {
                if(bits.test(xy[i][j].first-1) != xy[i][j].second) {
                    goto OUT;
                }
            }
        }
        M = bits.count();
        cc = max(cc, M);

        OUT:;
    }

    cout << cc << '\n';
}

Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define int ll
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    int ar[5001],ar2[5001],visited[5001];
    vector<int> v;
    ll sum;

    void dfs(int i)
    {
        visited[i]=1;
        v.pb(i);
        sum=sum+ar2[i];
        if(visited[ar[i]]==0)
        {
            dfs(ar[i]);
        }
    }

    void func2()
    {
        vector<int> v2=v;
        for(auto it:v2)
            v.pb(it);
    }

    ll func(int x,int n)
    {
        ll i,ans=-1e10,j,sum=0;
        for(i=0;i<n;++i)
        {
            sum=0;
            for(j=i;j-i+1<=x;++j)
            {
                sum=sum+ar2[v[j]];
                // cout<<i<<" "<<j<<" "<<sum<<endl;
                ans=max(ans,sum);
            }
        }
        return ans;
    }

    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,k,i,j;
            cin>>n>>k;
            ll ans=-1e10,z;
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
            }
            for(i=1;i<=n;++i)
            {
                cin>>ar2[i];
                ans=max(ans,ar2[i]);
            }
            
            for(i=1;i<=n;++i)
            {
                if(visited[i]==0)
                {
                    sum=0;
                    v.clear();
                    dfs(i);
                    func2();
                    // for(auto it:v)
                    //     cout<<it<<"...";
                    // cout<<endl;
                    // cout<<sum<<endl;
                    if(sum>0)
                    {
                        z=sum*(k/(v.size()/2));
                        ans=max(ans,z+func(k%(v.size()/2),v.size()/2));
                        // cout<<func(1,n)<<".."<<endl;
                        if(k/(v.size()/2)>0)
                        {
                            ans=max(ans,z-sum+func(v.size()/2,v.size()/2));
                        }
                    }
                    else
                    {
                        ans=max(ans,func(min(k,(int)v.size()/2),v.size()/2));
                    }
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

// (x, y) の最大公約数を返す関数
LL GCD(LL x, LL y) {
    return y ? GCD(y, x%y) : x;
}

VPLL prime_factorize(LL n) {
    VPLL res;
    for (LL p=2; p*p<=n; p++) {
        if (n%p!=0) continue;
        int num = 0;
        while (n%p==0) {num++; n/=p;}
        res.push_back(make_pair(p,num));
    }
    if (n!=1) res.push_back(make_pair(n,1));
    return res;
}

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

    LL a, b;
    cin >> a >> b;
    long long G = GCD(a,b);
    auto pf = prime_factorize(G);

    cout << pf.size()+1 << endl;    

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

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

    int ans = -1;
    for (int i = 1; i <= 3; i++) {
        if (i != a && b != i) {
            ans = i;
        } 
    }
    cout << ans << endl;
    
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define PI 3.14159265358979323846264338327950L
typedef unsigned long long uint64;
using namespace std;
int main(){
 char b;
 cin >> b;
 if(islower(b)){
   cout << 'a' << endl;
 }else{
   cout << 'A' << endl;
 }
return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}

bool isprime(long long x){
  long long i;
  if(x==1){return false;}
  if(x==2){return true;}
  if(x%2==0){return false;}
  for(i=3;i*i<=x;i+=2){
    if(x%i==0){return false;}
  }
  return true;
}

long long calcmod(long long x,long long m){
  if(x>=0){return x%m;}
  return (m-((-x)%m))%m;
}

long long n,a[16384];

bool judge(long long p){
  if(p==1 || p==0){return false;}
  //printf("try:%lld\n",p);
  if(calcmod(a[0],p)!=0){return false;}
  if(!isprime(p)){return false;}
  long long i,b[16384],t=-1;
  for(i=0;i<=n;i++){
    b[i]=calcmod(a[i],p);
    if(b[i]!=0){t=i;}
  }
  if(t==-1){return true;}
  if(p>t){return false;}
  for(i=n;i>=p;i--){
    b[i-(p-1)]+=b[i];
    b[i-(p-1)]%=p;
  }
  for(i=p-1;i>=0;i--){
    if((b[i]%p)!=0){return false;}
  }
  return true;
}

int main(){
  long long i,g;
  long long res[16384],rp=0,t;
  scanf("%lld",&n);
  for(i=n;i>=0;i--){scanf("%lld",&a[i]);}
  g=llzt(0,a[n]);
  for(i=n-1;i>=0;i--){
    g=llgcd(g,llzt(0,a[i]));
  }
  for(i=2;i*i<=g;i++){
    if((g%i)!=0){continue;}
    if(isprime(i)){res[rp]=i;rp++;}
    while((g%i)==0){g/=i;}
  }
  if(isprime(g)){res[rp]=g;rp++;}
  for(i=2;i<=n;i++){
    if(judge(i)){res[rp]=i;rp++;}
  }
  qsort(res,rp,sizeof(long long),llsortfncsj);
  res[rp]=-1;
  for(i=0;i<rp;i++){
    if(res[i]==res[i+1]){continue;}
    printf("%lld\n",res[i]);
  }
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> a(N);
   for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    a.at(A.at(i)-1) = i+1;
  } 
  for (int i = 0; i < N; i++)
  cout << a.at(i) <<" ";
}

Measured memory_bytes: 1536
a,b,c,d=gets.split.map &:to_i
e=a<c ? 0:1
f=b<d ? 0:1
h=[?R,?L]
g=[?U,?D]
m=(c-a).abs
l=(d-b).abs

print g[f]*l
print h[e]*m
print g[1-f]*l
print h[1-e]*m
print h[1-e]
print g[f]*(l+1)
print h[e]*(m+1)
print g[1-f]
print h[e]
print g[1-f]*(l+1)
print h[1-e]*(m+1)
print g[f]

Measured memory_bytes: 1788
def main():
    [N, M] = [int(i) for i in input().split()]
    edge = [[10**100] * N for _ in range(N)]

    E = []

    for i in range(M):
        E.append([int(i) for i in input().split()])

    dist = [-1*10**100 for i in range(N)]
    dist[0] = 0

    flag = False

    for i in range(N):
        for [a, b, c] in E:
            newLen = dist[a-1] + c
            if newLen > dist[b-1]:
                dist[b-1] = newLen
        if i == N-1 and dist[N-1] > predist:
            flag = True
        predist = dist[N-1]

    if flag:
        print('inf')
    else:
        print(dist[N-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 54248
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int K,S;
	cin>>K>>S;
	int X=0,Y=0,Z=0;
	int aw=0;
	
	for (X=0;X<=K;X++){
		for (Y=0;Y<=K;Y++){
			Z=S-X-Y;
			if (Z>=0 &&Z<=K){
				aw++;
			}
		}
	}
	cout<<aw<<endl;
	return 0;
}

Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


int main(void) {
   ll A,B,K;
   cin>>A>>B>>K;
   if (K>=0) {
      ll now = min(A,K);
      K-= now;
      A -= now;
   }
   if (K>=0) {
      ll now = min(B,K);
      K -= now;
      B -= now;
   }
   cout<<A<<" "<<B<<endl;







   return 0;
}

Measured memory_bytes: 256
d = int(input())
n = int(input())

for _ in range(n):
    a,b = map(int, input().split())
    if a > d/2:
        a = d-a+1
    if b > d/2:
        b = d-b+1
    c = min(a,b) % 3
    if c == 0:
        c = 3
    print(c)


Measured memory_bytes: 5616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main() {
    string S;
    cin >> S;
    // cout << S.substr(0, 2) << endl;
    int ans = 753;
    for (int i = 0; i < S.length()-2; i++) {
        int x = stoi(S.substr(i, 3));
        int diff = abs(x - 753);
        if (diff < ans) {
            ans = diff;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	cout << n / gcd(n, 360) * 360 / n << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll S, W; cin >> S >> W;
    if (W >= S){cout << "unsafe" << endl;} else {cout << "safe" << endl;}
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

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




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    for(int i=min(a,b);i<=max(a,b);i++){
        if(abs(a - i) == abs(b - i)){
            print(i);
            return 0;
        }
    }
    print("IMPOSSIBLE");

}


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

using namespace std;

void funcC(char *s,int length){
	char *tmp;
	tmp = new char[length];

	for(int i=0;i<length-1;i++){
		tmp[i] = s[i+1];
	}
	tmp[length-1] = s[0];

	for(int i=0;i<length;i++){
		s[i] = tmp[i];
	}
}


void funcJ(char *s,int length){
	char *tmp;
	tmp = new char[length];

	for(int i=1;i<length;i++){
		tmp[i] = s[i-1];
	}
	tmp[0] = s[length-1];

	for(int i=0;i<length;i++){
		s[i] = tmp[i];
	}
}

void funcE(char *s,int length){
	char *tmp1,*tmp2;
	int num=0;

	if(length%2==0){
		num = length/2;
	}
	else num =length/2 +1;

	tmp1 = new char[length];
	tmp2 = new char[length];

	for(int i=0;i<length/2;i++){
		tmp1[i] = s[i];
		tmp2[i] = s[num+i];
	}

	for(int i=0;i<length/2;i++){
		s[i] = tmp2[i];
	}

	for(int i=num;i<length;i++){
		s[i] = tmp1[i-num];
	}

}

void funcA(char *s,int length){
	char *tmp;
	tmp = new char[length];

	for(int i=0;i<length;i++){
		tmp[i] = s[length-1-i];
	}

	for(int i=0;i<length;i++){
		s[i]   = tmp[i];
	}
}

void funcM(char *s,int length){
	
	for(int i=0;i<length;i++){
		if(s[i] >='0' &&s[i]<='8'){
			s[i]++;
		}
		else if(s[i]=='9'){
			s[i]='0';
		}
	}
}

void funcP(char *s,int length){
	for(int i=0;i<length;i++){
		if(s[i] >='1' &&s[i]<='9'){
			s[i]--;
		}
		else if(s[i]=='0'){
			s[i]='9';
		}
	}
}


int main(){

	int num;

	cin>>num;

	for(int k=0;k<num;k++){
		string data;

		string str;
		cin>>data;
		cin>>str;

		char tmp[30];
		for(int i=0;i<str.size();i++){
			tmp[i] = str.at(i);
		}
		tmp[str.size()] = '\0';

		for(int i=data.size()-1;i>=0;i--){

			if(data.at(i)=='A'){
				funcA(tmp,str.size());
			}
			else if(data.at(i)=='J')funcJ(tmp,str.size());
			else if(data.at(i)=='M')funcM(tmp,str.size());
			else if(data.at(i)=='P')funcP(tmp,str.size());
			else if(data.at(i)=='C')funcC(tmp,str.size());
			else if(data.at(i)=='E')funcE(tmp,str.size());
		}

		cout<<tmp<<endl;

	}





	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;cin>>N>>K;
  int D=0;
  for(int i=0; i<N; i++){
    int x;cin>>x;
    D+=min(abs(x),abs(x-K));
  }
  cout<<D*2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

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

typedef pair<int, int> pii;
int n, m, w, u, v, c, id;
map<pii, int> mmap;
vector<pii> a[N];
deque<int> q;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m; id = n;
    for(int i = 0; i < m; ++i) {
        cin >> u >> v >> c;
        int& idu = mmap[mp(u, c)];
        int& idv = mmap[mp(v, c)];
        if(idu == 0) idu = ++id;
        if(idv == 0) idv = ++id;
        a[idu].pb(idv, 0), a[idv].pb(idu, 0);
        a[u].pb(idu, 1), a[idu].pb(u, 0);
        a[v].pb(idv, 1), a[idv].pb(v, 0);
    }
    vector<int> dis(id + 1, mod);
    dis[1] = 0; q.push_back(1);
    while(q.size()) {
       u = q.front(); q.pop_front();
       for(pii p: a[u]) {
          w = p.se, v = p.fi;
          if(dis[v] > dis[u] + w) {
            dis[v] = dis[u] + w;
            if(!w) q.push_front(v);
            else q.push_back(v);
          }
       }
    }
    if(dis[n] == mod) cout << -1;
    else cout << dis[n];
}


Measured memory_bytes: 57600
#include <bits/stdc++.h>
using namespace std;
    
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a;i<=b;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair < int, int> 
#define pal pair < ll, ll> 
#define vi vector <int> 
#define vl vector < ll > 
#define vpai vector < pii > 

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 3005;

void fill(char mat[10][10],char temp[10][10]){
    rep(i,7) rep(j,7) temp[i][j]=mat[i][j];
}

void solve() {
    int n,m,k;
    cin>>n>>m>>k;
    char mat[10][10],temp[10][10];
    int b=0;
    rep(i,n) rep(j,m) {
        cin>>mat[i][j];
        if(mat[i][j]=='#')
        b++;
    }
    int row=(1<<n)-1;
    int col=(1<<m)-1;
    ll count=0,tmp=b;
    for(int i=0;i<=row;i++){
        for(int j=0;j<=col;j++){
            fill(mat,temp);
            tmp=b;
            for(int k=0;k<n;k++){
                if(i&(1<<k)){
                    for(int l=0;l<m;l++) {
                        if(temp[k][l]=='#') tmp--,temp[k][l]='.';

                    }
                }
            }
            for(int k=0;k<m;k++){
                if(j&(1<<k)){
                    for(int l=0;l<n;l++) {
                        if(temp[l][k]=='#') tmp--,temp[l][k]='.';

                    }
                }
            }
            if(tmp==k) count++;
        }
    }

    cout<<count<<endl;

}

int main() {
    IOS;

    int t = 1;
    // cin >> t;
    while (t--) {
       solve();
    }

  return 0;
}

Measured memory_bytes: 3676
from bisect import insort_left

N = int(input())
v = list(map(int, input().split()))


v = sorted(v)

ans = 0

while len(v) > 1:
    v0 = v.pop(0)
    v1 = v.pop(0)

    insort_left(v, (v0+v1)/2)

print(v[0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;

int X[105];
int main()
{
  int n;
  cin >> n;
  rep(i, n) cin >> X[i];
  int ans = 1e9;
  for (int p = 1; p <= 100; p++)
  {
    int sum = 0;
    rep(i, n)
    {
      sum += pow((p - X[i]), 2);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                          
using namespace std;
long long n,m,ans;
int main() {
    cin>>n>>m;
    ans=abs(n*m-n*2-(m-2)*2);
    cout<<ans;
	return 0;
}
//68871358
//76140264
//25446011
//200841159

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

string S;

bool is_ACGT(string S)
{
  REP(i,0,S.length()) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      continue;
    } else {
      return false;
    }
  }
  return true;
}

int main()
{
  cin >> S;

  int res = 0;
  REP(i,0,S.length()) {
    REP(j,i,S.length()) {
      // i to j in S
      if (is_ACGT(S.substr(i, j+1-i))) {
        chmax(res, j+1-i);
      }
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    static long[] a;
    static long[] p;
    
    public static void main(String[] args) throws Exception {
    
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long X = sc.nextLong();
        
        a = new long[N+1];
        a[0] = 1L;
        p = new long[N+1];
        p[0] = 1L;
        
        for(int i = 1; i <= N; i++){
            a[i] = a[i-1] * 2 + 3;
            p[i] = p[i-1] * 2 + 1;
        }
        
        System.out.println( f(N, X) );
    }
    
    static long f(int N, long X){
        
        if( N == 0 ){
            return 1;
        }
        
        if( X == 1 ){
            return 0;
        }
        
        if( 1 < X && X <= a[N-1] + 1 ){
            return f(N-1, X-1);    
        }
        
        if( X == a[N-1] + 2 ){
            return p[N-1] + 1;
        }
        
        if( a[N-1] + 2 < X && X <= 2 * a[N-1] + 2 ){
            return p[N-1] + 1 + f(N-1, X-a[N-1]-2);
        }
        
        // X == a[N]
        return p[N];
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
    int a, b;

	cin >> a >> b;
	if ((a * b) % 2 == 0) {
		cout << "Even\n";
	} else {
		cout << "Odd\n";
	}						

	return 0;
}


Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    Q, H, S, D = map(int, input().split())
    N = int(input())
    Double = [Q * 8, H * 4, S * 2, D]
    Single = [Q * 4, H * 2, S]
    if N % 2 == 0: print(min(Double) * N // 2)
    else: print(min(Double) * (N - 1) // 2 + min(Single))

    return 0

if __name__ == "__main__":
    solve()

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back

int a[100001];

int main(void){
  int n,l;
  cin >> n >> l;
  rep(i,n){
    cin >> a[i];
  }
  int ind = -1;
  rep(i,n-1){
    if(a[i] + a[i+1] >= l){
      ind = i;
    }
  }
  if(ind == -1){
    cout << "Impossible" << endl;
    return 0;
  }
  stack<int> s;
  s.push(ind);
  for(int i = ind-1; i >= 0; --i){
    s.push(i);
  }
  for(int i = ind+1; i<n-1; ++i){
    s.push(i);
  }
  cout << "Possible" << endl;
  while(!s.empty()){
    cout << s.top()+1 << endl;
    s.pop();
  }

  return 0;
}



Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

typedef pair<int, int> pii;

const int maxn = 2005;
const int maxk = 10005;
string s[maxn];
bitset<maxk> can[maxn];
pii pos[2][1000051];

int chch[1000];

int TM = 0;
inline bool tl() {
    if (++TM == 10000) {
        TM = 0;
        if (clock() > CLOCKS_PER_SEC * 4.6)
            return true;
    }
    return false;
}

int main() {
    #ifdef LOCAL
    assert(freopen("f.in", "r", stdin));
    #else
    #endif
    cin.tie(0);
    cin.sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    forn (i, n) {
        cin >> s[i];
        for (auto c: s[i])
            ++chch[c];
    }

    int cch = 0;
    for (char c = 'z'; c >= 'a'; --c) {
        cch += (chch[c] > 0);
    }
    if (cch == 1) {
        for (char c = 'a'; c <= 'z'; ++c)
            if (chch[c] > 0) {
                cout << string(k, c) << '\n';
            }
        return 0;
    }

    can[n][0] = 1;
    for (int i = n; i > 0; --i)
        can[i - 1] = can[i] | (can[i] << s[i - 1].length());
    string ans;
    int q = 0, cnt = 0;
    forn (i, n)
        if (can[i + 1][k - sz(s[i])])
            pos[q][cnt++] = {i, 0};
    forn (i, k) {
        char minCh = 'z';
        cnt = min(cnt, 10000);
        forn (ii, cnt) {
            int sid = pos[q][ii].first;
            int spos = pos[q][ii].second;
            minCh = min(minCh, s[sid][spos]);
        }
        ans.push_back(minCh);
        int ncnt = 0;
        int minSt = inf;
        forn (ii, cnt) {
            int sid = pos[q][ii].first;
            int spos = pos[q][ii].second;
            if (s[sid][spos] != minCh)
                continue;
            if (spos + 1 == sz(s[sid]))
                minSt = min(minSt, sid + 1);
            else
                pos[q ^ 1][ncnt++] = {sid, spos + 1};
        }
        for (int j = minSt; j < n; ++j)
            if (k - i - 1 - sz(s[j]) >= 0 && can[j + 1][k - i - 1 - sz(s[j])])
                pos[q ^ 1][ncnt++] = {j, 0};
        q ^= 1;
        cnt = ncnt;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3840
def exam(L, R):
    min = 2019
    if L-R > 2019:
        return 0
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            modval = i*j % 2019
            if modval < min:
                min = modval
                if min == 0:
                    return 0
    return min


L, R = map(int, input().split())
print(exam(L, R))


Measured memory_bytes: 2940
#include<stdio.h>

void swap(int *a, int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	
	if(a > b){
		swap(&a, &b);
	}
	if(a > c){
		swap(&a, &c);
	}
	if(b > c){
		swap(&b, &c);
	}
	
	
	printf("%d %d %d\n", a, b, c);
	
	return 0;
}

Measured memory_bytes: 596
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

manzoku = sum(b)

for i in range(n-1):
  if a[i+1] - a[i] == 1:
      cno = a[i]  - 1
      manzoku = manzoku + c[cno]

print(manzoku)

Measured memory_bytes: 3064
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

ll W, H, x, y;

void solve()
{
    double r = H * W;
    double s = 0.;
    ll x2 = W - x, y2 = H - y;
    if(x == x2 || y == y2){
        cout << fixed << setprecision(10) << r/2 << " " << (x==x2 && y == y2 ? 1 : 0) << endl;
    }else{
        double a = (double)(H-y - y) / (W-x - x);
        double above = H-y + a*x;
        double below = y - a*x;
        double s = (above + below) * W * 0.5;
        cout << fixed << setprecision(10) << s << " ";
        cout << 0 << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> W >> H >> x >> y;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

int main()
{
    int h, r;

    cin >> h >> r;

    if (r + h == 0) {
        cout << 0 << endl;
    }
    else if (h + r > 0) {
        cout << 1 << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3108
n = int(input())
h = list(map(int,input().split()))
mh = h[0]
for i in range(1,n):
    if h[i] - h[i-1] > 0:
        h[i] -= 1
    if h[i-1] - h[i] > 0:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b){
    return *(int *)a-*(int *)b;
}
int main(){
    int N;
    int d[100000];
    scanf("%d",&N);
    int i;
    for(i=0;i<N;i++){
        scanf("%d",&d[i]);
    }
    qsort(d,N,sizeof(int),comp);
    if(d[N/2-1]<d[N/2]){
        printf("%d",d[N/2]-d[N/2-1]);
        return 0;
    }
    printf("0");
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N;
    cin >> N;
    yesno(N >= 30);
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
using namespace std;

void solve(){
	int n;
	cin>>n;
	string s[n];
	int ans=0;
	int st=0,en=0;
	int both=0;
	rep(i,n){
		cin>>s[i];
		int nn=s[i].length();
		rep(j,nn-1){
			if(s[i][j]=='A'&&s[i][j+1]=='B')ans++;
		}
		if(s[i][0]=='B'&&s[i][nn-1]=='A')both++;
		else if(s[i][0]=='B')st++;
		else if(s[i][nn-1]=='A')en++;
	}
	if(both>0){ans+=both-1;both=1;}
	else both=0;
	int x=max(st,en);
	if(x){
		st+=both;
		en+=both;
		ans+=min(st,en);
	}
	cout<<ans;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
 template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  long long n,ans=1,p,x;
  cin>>n>>p;
  x=p;
  long long num[1000010]={};
  if(n==1)
    cout<<p<<endl;
  else{
    for(long long i=2;pow(i,n)<=x;i++){
      while(p%i==0){
        p/=i;
        num[i]++;
      }
      if(p==1)
        break;
    }
  for(long long i=0;pow(i,n)<=x;i++){
    if(num[i]>=n)
      for(int j=0;j<num[i]/n;j++){
      ans*=i;
      }
  }
  cout<<ans<<endl;
  }
}


Measured memory_bytes: 8064
#include <stdio.h>

int main(void)
{
	int a, b, c, d, n;
	int i, i2, i3, i4, i5;
	int ans;
	
	while (scanf("%d", &n) != EOF){
		ans = 0;
		if (37 <= n){
		}
		else {
			for (i2 = 0; i2 <= 9; i2++){
				for (i3 = 0; i3 <= 9; i3++){
					for (i4 = 0; i4 <= 9; i4++){
						for (i5 = 0; i5 <= 9; i5++){
							if ((i2 + i3 + i4 + i5) == n){
								ans++;
							}
						}
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S,T = "";
    cin >> S;
    ll s = S.size();
    vector<string> vec;
    rep(i,s - 1){
        if(S[i] == 'B' && S[i + 1] == 'C'){
            T += 'D';
            i++;
        }
        else if(S[i] == 'A')T += S[i];
        else{
            if(T != ""){
                vec.push_back(T);
                T = "";
            }
        }
    }
    if(S[s - 1] == 'A')T += S[s - 1];
    if(T != "")vec.push_back(T);
    //rep(i,vec.size())cout << vec[i] << "\n";
    //cout << T << endl;
    ll ans = 0;
    ll sz = vec.size();
    rep(i,sz){
        ll siz = vec[i].size();
        vector<ll> D(siz);
        rep(j,siz){
            if(vec[i][j] == 'D')D[j]++;
        }
        for(ll j = siz - 1;j > 0;j--){
            D[j - 1] += D[j];
        }
        rep(j,siz){
            if(vec[i][j] == 'A'){
                ans += D[j];
            }
        }
        //vecout(D);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5520
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#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 _GLIBCXX_DEBUG

void printv(vector<int> v) {
  for (int i : v)
    cout << i << " ";
  cout << endl;
}


int main() {
  string x, y;
  cin >> x >> y;
  vector<vector<int>> L(1010, vector<int>(1010, 0));
  for (int i = 0; i < 1010; i++) {
    L[0][i] = i;
    L[i][0] = i;
  }
  int lx = x.size(), ly = y.size();
  for (int i = 1; i <= lx; i++) {
    for (int j = 1; j <= ly; j++) {
      if (x[i - 1] == y[j - 1]) {
        L[i][j] = L[i - 1][j - 1];
      } else
        L[i][j] = min(L[i - 1][j - 1], min(L[i - 1][j], L[i][j - 1])) + 1;
    }
  }
  cout << L[lx][ly] << endl;
}



Measured memory_bytes: 6920
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<P> u,d;
    rep(i,n) {
        string s;
        cin >> s;
        int b=0,h=0;
        rep(j,s.size()) {
            if (s[j]=='(') ++h;
            else --h;
            b=min(b,h);
        }
        if (h>=0) u.push_back(make_pair(b,h));
        else d.push_back(make_pair(b-h,-h));
    }
    sort(u.begin(),u.end(),greater<>());
    sort(d.begin(),d.end(),greater<>());
    int now1=0,now2=0;
    bool flag=1;
    rep(i,u.size()) {
        if (now1+u[i].first<0) flag=0;
        now1+=u[i].second;
    }
    rep(i,d.size()) {
        if (now2+d[i].first<0) flag=0;
        now2+=d[i].second;
    }
    if (flag && now1==now2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 11248
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,k=MI()
    aa=LI()
    aa.sort()
    ans=sum(aa[:k])
    print(ans)

main()

Measured memory_bytes: 9248
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1)<<endl;

  return 0;
}


Measured memory_bytes: 256
import Control.Monad.State
import Data.List.Split
data BH = Hist { a :: Int,
                 b :: Int,
                 ab :: Int,
                 o :: Int}

main = do
    groups <- fmap (map (last.splitOn ",").lines) getContents
    let hist = execState ( foldl1 (>>) $ fmap add groups) (Hist 0 0 0 0)
    print $ a hist
    print $ b hist
    print $ ab hist
    print $ o hist

add :: String -> State BH ()
add g 
  | g == "A" = get >>= \bh -> put $ bh { a = a bh + 1}
  | g == "B" = get >>= \bh -> put $ bh { b = b bh + 1}
  | g == "AB" = get >>= \bh -> put $ bh { ab = ab bh + 1}
  | g == "O" = get >>= \bh -> put $ bh { o = o bh + 1}

Measured memory_bytes: 3488
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
 
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
 
        int i = 1;
        while (true) {
            int n = Integer.parseInt(br.readLine());
            if (n == 0) {
                break;
            }
            sb.append("Case ").append(i).append(": ").append(n).append("\n");
            i++;
        }
        System.out.print(sb);
    }
 
}

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

long long n;

string solve();

int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}

string solve() {
  string res;
  while (n) {
    --n;
    res += 'a' + (n % 26);
    n /= 26;
  }
  reverse(res.begin(), res.end());
  return res;
}

Measured memory_bytes: 3636
N, K = map(int, input().split())
MOD = 1000000007
ans = 0
dp = [0] * (K + 1)
for i in range(K, 0, -1):
    div = K // i
    amount = (pow(div, N, MOD)) % MOD
    for j in range(2, div + 1, 1):
        amount = (amount - dp[j * i] + MOD) % MOD
    dp[i] = amount
    ans = (ans + amount * i) % MOD
print(ans)


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

#define rep(i, n) for (int i = 1; i <= (n); i++)

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

  int sum = 0;
  rep(a, K)rep(b, K)rep(c, K) sum += gcd(a, gcd(b, c));
  cout << sum << endl;
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{

    class Program
    {

        const int Mod = 1000000007;

        static void Main()
        {

            var num = int.Parse(Console.ReadLine());
            var result = Enumerable.Repeat(0, num).ToList();

            Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList().ForEach(x => result[x - 1]++);

            result.ForEach(x => Console.WriteLine(x));
            
        }


    }
}


Measured memory_bytes: 43884
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))


count = 0
for i in range(n):
    count += min(a[i],b[i])
    if a[i] < b[i]:
        if  a[i+1] <= (b[i] - a[i]):
            count += a[i+1]
            a[i+1] = 0
        else:
            count += (b[i] - a[i])
            a[i+1] = a[i+1] - (b[i] - a[i])

print(count)

Measured memory_bytes: 24180
#include<stdio.h>

int main()
{
	float a,b,c,d,e,f;
	float x,y;
	
	while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f)>0)
	{
		y=(c*d-a*f)/(b*d-a*e);
		x=(c-(b*y))/a;

		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int l[q], r[q];
    rep(i, 0, q) {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }

    int sum[n] = {};
    for (int i = 0; i <= n - 2; i++) {
        string sub = s.substr(i, 2);
        if (sub == "AC") {
            sum[i + 1] = sum[i] + 1;
        } else {
            sum[i + 1] = sum[i];
        }
    }

    rep(i, 0, q) {
        cout << sum[r[i]] - sum[l[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    num_list = i_list()

    num_list.sort(reverse=True)

    print(num_list[0]*10+num_list[1]+num_list[2])

if __name__ == '__main__':
    main()


Measured memory_bytes: 58860
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <utility>
using namespace std;

using ll = long long;

ll cul(ll n){
  return n*(n-1)/2;
}

int main(){
  ll n; cin >> n;
  ll a[n+1], b[n+1];

  map<ll, ll> mp;
  b[0] = 0;
  mp[0]++;
  for(int i=1; i<=n; i++){
    cin >> a[i];
    b[i] = b[i-1] + a[i];
    mp[b[i]]++;
  }

  ll ans=0;
  for(auto i = mp.begin(); i!=mp.end(); i++){
    ans += cul(i->second);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15872
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws  Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        int a = Integer.parseInt(input.readLine());

        System.out.println((n*n) - a);

    }
}


Measured memory_bytes: 21204
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)));
#define Mx(a , b) ((a) > (b) ? (a) : (b))
#define Mn(a , b) ((a) < (b) ? (a) : (b))

const double EPS = 1e-10;
const int INF = 2147483647;

LL N , X;

LL gcd(LL a , LL b){
	return b != 0 ? gcd(b , a % b) : a;
}

int main(){
	scanf("%lld%lld" , &N , &X);
	printf("%lld\n" , 3 * (N - gcd(N , X)));
	return 0;
}


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

ll gcd(ll a, ll b){
    if(a%b==0){return b;}
    else{return gcd(b, a%b);}
}

ll lcm(ll a, ll b){
    return a*b / gcd(a, b);
}

int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll nc, nd, ncd;
    nc = b/c - a/c;
    if(a%c==0){nc += 1;}
    nd = b/d - a/d;
    if(a%d==0){nd += 1;}
    ll cd = lcm(c, d);
    ncd = b/cd - a/cd; 
    if(a%cd==0){ncd += 1;}
    ll res = (b-a+1)-(nc+nd-ncd);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3604