akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0;

string s,w;

vector<int> z;

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

       cin >> a >> b;
       rrep(i,1,100000){
           if((a*i)%b!=0){
               cout << a*i << endl;
               return 0;
           }
       }
       cout << -1 << endl;
return 0;
}


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

using namespace std;

typedef long long ll;

const ll INF=1e13+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
    ll N,K;
    ll M=INF;
    cin>>N>>K;
    vector<int> H(N);
    rep(i,N)cin>>H[i];
    sort(H.begin(),H.end());
    for(int i=0;i<N-K+1;i++){
        if(M>H[i+K-1]-H[i])M=H[i+K-1]-H[i];
    }
    cout<<M<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 640
/*****************************************************************\
    |     IN THE NAME OF ALLAH, MOST GRACIOUS AND MOST MERCIFUL       |
    |                                                                 |
    |     Author     : Mahabub Rahman                                 |
    |     Email      : mahabubrahman618@gmail.com                     |
    |     University : Comilla University, Bangladesh		          |
    |                  Department of Computer Science & Engineering   |
    \*****************************************************************/


    /*...................................Data_Types............................................*/
    #include<bits/stdc++.h>

    using namespace std;
    #define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
    #define       ll                  long long int
    #define       ull                  unsigned long long int
    #define       veci                 vector<int>
    #define       vecc                 vector<char>
    #define       vecs                 vector<string>
    #define       vecl                 vector<long long int>
    #define       vecp                 vector<  pair<int,int> >
    #define       mapstrint            map< string , int >
    #define       mapstrstr            map< string , string >
    #define       mapint               map< int, int >
    #define       pb                   push_back
    #define       pob                  pop_back
    #define       mp                   make_pair
    #define       F                    first
    #define       S                    second
    ////============ CONSTANT ===============////
    #define mx9   1000000007
    #define mx7   10000007
    #define mx6   1000006
    #define mx5   200005
    #define inf   1<<30                                           //infinity value
    #define eps   1e-9

    #define mod   1000000007
    ////=====================================////

    long double PI = acosl(-1);
    bool compare_int(int a, int b) //This function is use for descending order.
    {
        return (a>b);
    }
    bool compare_string (string a, string b)
    {
        return a.size() < b.size();
    }
    bool compare_pair(const pair<int,int> &a,
                  const pair<int,int> &b)
    {
        if(a.second==b.second) return a.first>b.first;
        else return (a.second > b.second);
    }
    /*ll fact(ll n)
    {
        if(n==0 || n==1) return 1;
        else return n*fact(n-1);
    }*/

    ////======================================////
    /*bool check(int n)
    {
        for(int i=2; i<=sqrt(n); i++)
        {
            if(n%i==0)
            {
                return false;
            }
        }
        return true;
    }*/

    int32_t main()
    {
        //Don't see test case until get 7/8 times wrong submission..!!
        //Try to make Corner, Even, Odd or Prime case..!!
        FastIO;
        int n, x;
        cin >> n;
        cout << setprecision(20) << fixed << 2*PI*n << endl;

    }


Measured memory_bytes: 3808
let words str = Str.split (Str.regexp " ") str |> List.map int_of_string

let bs x (a: int array) =
  let rec loop (i_min,i_max) =
    if i_min > i_max then false
    else
      let mid = (i_min+i_max)/2 in
      if a.(mid) = x then true
      else
        loop (if a.(mid) < x then mid+1,i_max else i_min,mid-1)
  in loop (0,(Array.length a) -1)

let () =
  let _ = read_int () in
  let s = read_line () |> words |> Array.of_list in
  let _ = read_int () in
  let t = read_line () |> words in
  List.fold_left (fun acc x -> if bs x s then acc+1 else acc) 0 t
  |> Printf.printf "%d\n"

Measured memory_bytes: 16260
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vi v(n),ans(n);
	rep(i,n)cin>>v[i],v[i]--;
	rep(i,n){
		rrep(j,n-i){
			if(v[j]==j){
				ans[n-i-1]=j;
				v[j]=-1;
				j=-1;
			}
			if(j==0){
				cout<<-1<<endl;
				return 0;
			}
		}
		int tab=0;
		rep(j,n-i-1){
			if(v[j]<0)tab++;
			v[j]=v[j+tab];
		}
	}
	rep(i,n)cout<<ans[i]+1<<"\n";

}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
ab = []
for i in range(n):
    x,y = [int(j) for j in input().split()]
    ab.append((x, y))

ab.sort()
total = 0
num = 0

for i in range(n):
    if num+ab[i][1] <= m:
        total += ab[i][0]*ab[i][1]
        num += ab[i][1]
    else:
        a = m-num
        total += ab[i][0]*a
        print(total)
        exit()

print(total)

    


Measured memory_bytes: 17004
#include <iostream>
#include <vector>
#include <set>

using namespace std;

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

set<long long> factors(long long n) {
  long long a = 2;
  set<long long> r;
  while (n >= a * a) {
    if (n % a == 0) {
      r.insert(a);
      n /= a;
    } else {
      a++;
    }
  }
  r.insert(n);
  return r;
}

int main() {
  long long A, B;
  cin >> A >> B;
  auto f = factors(gcd(A, B));
  f.insert(1);
  cout << f.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    ll X;
    cin >> X;
    ll x = 100;
    int res = 0;
    while (true) {
        ++res;
        x *= 1.01;
        if (x >= X) {
            cout << res << endl;
            return 0;
        }
    }

    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  for(int N, M; cin >> N >> M && N && M;) {
    int sum[N + 1]; sum[0] = 0;

    int res = 0;
    rep(i, N) {
      int A; cin >> A; A %= M;
      sum[i + 1] = sum[i] + A;
      sum[i + 1] %= M;
      maximize(res, sum[i + 1]);
    }

    set<int> st = {M};

    REP(i, 1, N + 1) {
      maximize(res, sum[i] + M - *st.upper_bound(sum[i]));
      st.insert(sum[i]);
    }

    cout << res << endl;

  }
  
  return 0;
}

Measured memory_bytes: 4408
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main() {
	int K,A,B;
	std::cin >> K;
	std::cin >> A >> B;
	
	double a = double(A) / K;
	double b = double(B) / K;
	double a_res = A % K;
	double b_res = B % K;
	double c = b - a;
	double z = abs(ceil(b) - ceil(a));

	if ((z >=1) | (a_res==0) | (b_res==0)) {
		std::cout << "OK" << std::endl;
	}
	else {
		std::cout << "NG" << std::endl;
	}

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  long long L[87];
  L[0] = 2LL, L[1] = 1LL;
  for (int i=2; i<=n; i++) {
    L[i] = L[i-2] + L[i-1];
  }

  cout << L[n] << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
 
#define MAX_V 1024
using namespace std;
 
void get_map();
void check();
struct edge
{
  int to;
  int weight;
};
 
 
const int INF = INT_MAX/4;
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;
 
int main()
{
  get_map();
  check();
  //for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      //if(i==j)
        {
          if(graph[start][j]<INF/2 && graph[j][j]<0)
        {
          cout << "NEGATIVE CYCLE" <<endl;
          return 0;
        }
        }
    }
    }
   
    for(int i=0;i<vertex;i++)
      {
    if(graph[start][i]>=INF/2)
      {
        cout << "INF" << endl;
      }
    else
      {
    cout << graph[start][i] << endl;
      }
      }
  return 0;
}
 
int fastmin(int a, int b)
{
    int c = a-b;
  return (((c)>>31)&(c))+b;
}
 
void check()
{
  //  int next;
  //int here = start;
  //for(int i=0;i<vertex;i++)
   
  for(int k=0;k<vertex;k++)//v=4
    {
      for(int i=0;i<vertex;i++)
    {
      int gik= graph[i][k];
      for(int j=0;j<vertex;j++)
        {
          //if(graph[i][k] !=INF && graph[k][j]!=INF)
        {
          graph[i][j]= fastmin(graph[i][j], gik+graph[k][j]);
        }
        }
    }
    }
   
}
 
void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
   
  fill(graph[0], graph[vertex], INF);
   
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
      {
    if(i==j)
      {
        graph[i][j]=0;
      }
    /*else
      {
        graph[i][j]=INF;
        }*/
      }
    }
 
  /*for(int i=0;i<vertex;i++)
    {
      dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }
 
  /*  for(int i=0;i<numofedge;i++)
    {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
   }
  */ 
 
  /*  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      cout << graph[i][j] << " ";
    }
      cout << endl;
      }*/
  // dist[start]=0;
   
  /*  cout << vertex << endl;
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      cout << graph[i][j] << " ";
    }  
      cout << endl;    
      }*/
   
 
}

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

int main() {
   int in;
  cin >> in;
  
  int an = in % 10;
  string st;
  if (an == 3){
  st = "bon";
  }else if (an == 0 || an ==1 || an==6||an==8){
   st = "pon";
  }else{
    
    st = "hon";
  }
  
  cout << st << endl;
  
 }

Measured memory_bytes: 3616
x,y,z=gets.split.map &:to_i
a=$<.map &:to_i
a.sort!
c=1
b=[a[0]]
1.upto(x-1) do |i|
    if b[0]+z>=a[i] && b.length+1<=y
      b<< a[i]
    else
      c+=1
      b=[a[i]]
    end
end
p c

Measured memory_bytes: 5624
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
  string s;
  cin >> s;
  int size=s.size();
  int num=0;
  int ans=0;
  for(int i = 0 ; i < size; i++){
    if( s[i]=='g'&& num > 0){
       num-=1;
       ans++;
    }
    else if( s[i]=='p' && num == 0){
       num+=1;
       ans--;
    }
    else if( s[i]=='g' ){
       num++;
    }
    else{
       num--;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<vector<int>>a(2,vector<int>(n));
	for(auto&i:a)for(auto&j:i)cin>>j;
	for(int i=1;i<n;++i)a.at(0).at(i)+=a.at(0).at(i-1);
	for(int i=n-2;i>=0;--i)a.at(1).at(i)+=a.at(1).at(i+1);
	int ans=0;
	for(int i=0;i<n;++i){
		ans=max(ans,a.at(0).at(i)+a.at(1).at(i));
	}
	cout<<ans<<"\n"s;
}

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

long a[300010], s[64][300010][2];
int main()
{
    int n; cin>>n;
    for(int i=0; i<n; ++i) {
        cin>>a[i];
        for(int j=0; j<61; ++j) {
            int k=(a[i]>>j)&1;
            if (k==0) {
                s[j][i+1][0]=s[j][i][0]+1;
                s[j][i+1][1]=s[j][i][1];
            }
            else {
                s[j][i+1][0]=s[j][i][0];
                s[j][i+1][1]=s[j][i][1]+1;
            }
        }
    }

    const long mod=1e9+7;
    long res=0;
    for(int i=0; i<n; ++i) {
        for(int j=0; j<61; ++j) {
            long t=0;
            int x=(a[i]>>j)&1;
            t+=s[j][n][!x]-s[j][i][!x];
            t%=mod;
            (t*=(1L<<j)%mod)%=mod;
            (res+=t)%=mod;
        }
    }
    cout<<res<<endl;
}


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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	int res = h.back() - h.front();
	for (int i = 0; i + K <= N; i++) {
		res = min(res, h[i + K - 1] - h[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define ff first
#define ss second
#define p pair<ll,ll>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define iof  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi acos(-1)
int fx[]={0,0,1,-1,1,1,-1,-1};
int fy[]={1,-1,0,0,-1,1,-1,1};
const int mxn=1e5+7;
const int mod=1e9+7;
inline void normal(ll &a){a=((a%mod)+mod)%mod;}
inline ll modMul(ll a,ll b){normal(a);normal(b);return(a*b)%mod;}
inline ll modAdd(ll a,ll b){normal(a);normal(b);return (a+b)%mod;}
inline ll modSub(ll a,ll b){normal(a);normal(b);a-=b;normal(a);return a;}
inline ll modPow(ll b,ll a)
{
    ll r=1;
    while(a)
    {
        if(a&1)r=modMul(r,b);
        b=modMul(b,b);
        a>>=1;
    }
    return r;
}
int main()
{
    fast;
    ll n;
    cin>>n;
    ll ans=modSub(modAdd(modPow(10,n),modPow(8,n)),modMul(2,modPow(9,n)));
    cout<<ans<<endl;
}



Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define ll long long
#define MAX 200010
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
using namespace std;

int main() {
    cout.precision(10);
    ll n;
    cin>>n;
    vector<ll> a(n),num(MAX,0);
    rep(i,0,n){
        cin>>a[i];
        a[i]--;
        num[a[i]]++;
    }
    
    vector<ll> aa(MAX,0),bb(MAX,0);
    ll sum=0;
    rep(i,0,MAX){
        if(num[i]<2)continue;
        if(num[i]==2){
            aa[i]=1;
            bb[i]=0;
        }
        else{
            aa[i]=(num[i]*(num[i]-1))/2;
            bb[i]=((num[i]-2)*(num[i]-1))/2;
        }
        sum+=aa[i];
    }
    
    rep(i,0,n)cout<<sum-(aa[a[i]]-bb[a[i]])<<endl;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 1000000000

vector<int> adj[200001];
bool vis[200001];

int cnt = 0;

void dfs(int node)
{
	cnt++;
	for (int child : adj[node]) {
		if (!vis[child]) {
			vis[child] = 1;
			dfs(child);
		}
	}
}


void test_case()
{
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			cnt = 0;
			vis[i] = 1;
			dfs(i);
			ans = max(ans, cnt);
		}
	}
	cout << ans;
}


int main()
{
	fastio
	// int t;
	// cin >> t;
	// while (t--)
	test_case();
}


Measured memory_bytes: 20912
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#define ll long long
ll mod=1e9+7;
using namespace std;
map<ll,ll>q;
ll a[100];
ll solve(ll n){
    if (q[n]){
        return q[n];
    }
    if (n==0){
        return q[n]=1;
    }
    if (n==1){
        return q[n]=2;
    }
    if (n%2==0){
        return q[n]=(2*solve(n/2-1)+solve(n/2))%mod;
    }
    if (n%2){
        return q[n]=(solve(n/2-1)+2*solve(n/2))%mod;
    }
}
int main(){
    ll n;
    scanf("%lld",&n);
    solve(n);
    printf("%lld\n",q[n]);
    return 0;
}


Measured memory_bytes: 500
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#define LL long long
#define rint register int
#define MAXN 1000005
using namespace std;

int n, tot, t[MAXN][26], num[MAXN][26], a[MAXN], b[26];
LL ans;
string s[200005];

bool CMP(string x, string y)
{
    return x.length()>y.length();
}

int main()
{
    scanf("%d", &n);
    for(rint i=1; i<=n; ++i) cin>>s[i];
    sort(s+1, s+n+1, CMP);
    for(rint i=1; i<=n; ++i)
    {
        reverse(s[i].begin(), s[i].end());
        int p=0, len=s[i].length();
        a[len]=0;
        for(rint j=len-1; j>=0; --j)
        {
            int ch=s[i][j]-'a';
            a[j]=a[j+1]|(1<<ch);
        }
        for(rint j=0; j<len; ++j)
        {
            int ch=s[i][j]-'a';
            if(j==len-1) ans+=num[p][ch];
            for(rint k=0; k<26; ++k)
                if(a[j]&(1<<k)) num[p][k]++;
            if(!t[p][ch]) t[p][ch]=++tot;
            p=t[p][ch];
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 215724
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c;
  cin>>a>>b>>c;
  long long ok1 = c-(a+b);
  if(c>(a+b) && (4*a*b)<(ok1*ok1)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int num=0,res=0;
    string ans;
    for (int i=0;i<(int)s.length();++i)
        if (num>=i-num) {
            if (s[i]=='p') --res;
            ans+='g';
        } else {
            ++num;
            res+=s[i]=='g';
            ans+='p';
        }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;


constexpr int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
constexpr int N = 0, E = 1, S = 2, W = 3;
string dir = "NESW";
bool connected[55][55][4];

set<PP> pos, tmp;

void move(){
    tmp.clear();
    for(auto &pp : pos){
        int x, y, now, pre;
        x = pp.first.first;
        y = pp.first.second;
        now = pp.second.first;
        pre = pp.second.second;
        int nx = x+dx[now], ny = y+dy[now];
        for(int i=0;i<4;i++){
            if(i==(now+2)%4) continue;
            if(!connected[nx][ny][i]) continue;
            tmp.insert({{nx,ny},{i,now}});
        }
    }
    pos = tmp;
}

int main() {
    int n, x0, y0, T;
    cin >> n >> x0 >> y0 >> T;
    for(int i=0;i<n;i++){
        int xs, ys, xe, ye;
        cin >> xs >> ys >> xe >> ye;
        if(xs == xe){
            if(ys > ye) swap(ys, ye);
            for(int y = ys; y < ye; y++){
                connected[xs][y][N] = true;
                connected[xs][y+1][S] = true;
            }
        }
        else{
            if(xs > xe) swap(xs, xe);
            for(int x = xs; x < xe; x++){
                connected[x][ys][E] = true;
                connected[x+1][ys][W] = true;
            }
        }
    }
    for(int i=0;i<4;i++){
        if(connected[x0][y0][i]){
            pos.insert({{x0,y0},{i,-1}});
        }
    }
    for(int i=0;i<T;i++){
        int d;
        char c;
        cin >> d >> c;
        for(int j=0;j<d;j++){
            move();
        }
        tmp.clear();
        for(auto &pp : pos){
            int now = pp.second.first, pre = pp.second.second;
            if(dir[now] == c || dir[pre] == c){
                tmp.insert(pp);
            }
        }
        pos = tmp;
    }
    set<P> ans;
    for(auto pp : pos){
        int x, y;
        x = pp.first.first;
        y = pp.first.second;
        ans.insert({x,y});
    }
    for(auto p : ans){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}



Measured memory_bytes: 3504
def resolve():
    from collections import defaultdict
    N, M = [int(i) for i in input().split()]
    kaa = [list(map(int, input().split())) for _ in range(N)]
    ans = defaultdict(int)
    for k, *a in kaa:
        for A in a:
            ans[A] += 1
    print(list(ans.values()).count(N))


resolve()


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

string s1 = "dream";
string s2 = "dreamer";
string s3 = "erase";
string s4 = "eraser";

bool calc(string S)
{
  while (1)
  {
    if (S.substr(0, s2.size()) == s2)
    {
      if (S.substr(0, s1.size() + s4.size()) == s1 + s4)
      {
        S.erase(0, s1.size() + s4.size());
      }
      else if (S.substr(0, s1.size() + s3.size()) == s1 + s3)
      {
        S.erase(0, s1.size() + s3.size());
      }
      else
      {
        S.erase(0, s2.size());
      }
    }
    else if (S.substr(0, s1.size()) == s1)
    {
      S.erase(0, s1.size());
    }
    else if (S.substr(0, s4.size()) == s4)
    {
      S.erase(0, s4.size());
    }
    else if (S.substr(0, s3.size()) == s3)
    {
      S.erase(0, s3.size());
    }
    else
    {
      return false;
    }
    if (S.size() == 0)
    {
      return true;
    }
  }
}

int main()
{
  string S, T;
  bool flag = false;
  cin >> S;

  flag = calc(S);
  flag ? cout << "YES" << endl : cout << "NO" << endl;
}


Measured memory_bytes: 3716
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  ll a[51];

  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%lld",a+i);
  }

  bool flag = true;
  ll ans = 0;
  while(flag){
    ll calc = 0;
    ll memo[50];
    
    for(int i=0;i<n;i++){
      memo[i] = a[i]/n;
      calc += a[i]/n;
      a[i] %= n;
    }

    for(int i=0;i<n;i++){
      a[i] += calc - memo[i];
    }

    flag = calc > 0;
    ans += calc;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N,d,x;cin>>N>>d>>x;
    int A[101];
    for(int i=0;i<N;i++) cin>>A[i];
    int res = x+N;
    for(int i=0;i<N;i++){
      res = res + (d-1)/A[i];
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		for (int i = 1; i <= Math.sqrt(x); i++) {
		    if (x % i == 0) {
		        check(x, i);
		        check(x, x / i);
		    }
		}
	}
	
	static void check(int x, int y) {
	    int base = - (y / 2);
	    while (true) {
	        double z = Math.pow(y + base, 5) - Math.pow(base, 5);
	        if (x == z) {
    	        System.out.println((y + base) + " " + base);
    	        System.exit(0);
	        }
	        if (x < z) {
	            return;
	        }
	        base++;
	    }
	}
}


Measured memory_bytes: 38736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,x;
  cin>>a>>b>>x;
  a=(a+x-1)/x;
  b/=x;
  cout<<b-a+1<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = str(input())
rn = s.count("R")
gn = s.count("G")
bn = s.count("B")
 
ct=0
for i in range(n):
  for j in range(i+1,n):
    k = 2*j - i
    if k >= n:
      break
    elif s[i]!=s[j] and s[j]!=s[k]and s[i]!=s[k]:
      ct += 1
 
print(rn*gn*bn-ct)

Measured memory_bytes: 9208
# Your code here!
classmate = []
morning = []
afternoon = []

for i in range(9):
    a,b,c=input().split()
    classmate.append(a)
    morning.append(int(b))
    afternoon.append(int(c))
    
for i in range(9):
    print(classmate[i], morning[i]+afternoon[i],morning[i] * 200 + afternoon[i] * 300)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
long long a [100010];
int main ()
{
    int n,Count=0;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]==0){Count++;}
    }
    if(Count>0){cout<<0<<endl;return 0;}
    long long sum=1;
    for(int i=0; i<n; i++)
    {
        if(a[i]<=1000000000000000000/sum )
        {
// This condition is equivalent to sum*a[i] <=10ˆ18
            sum=sum*a[i];
        }
        else
        {
           cout<<-1<<endl;
            return 0;
        }
    }
   cout<<sum<<endl;
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

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

    int n; cin >> n;
    vi arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i], arr[i]--;

    int res = 0;
    for (int i = 0; i < n; i++){
        if (arr[i] == i) {
            if (i != n-1)
                swap(arr[i], arr[i+1]);
            else
                swap(arr[i], arr[i-1]);
            res++;
        }
    }
    cout << res << endl;
}


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

int main() {
  int n;
  cin>>n;
   vector<string> s(n);
  rep(i,n) cin>>s[i];
   ///////////////////
   int count=1;
  sort(s.begin(),s.end());
  rep(i,n-1){
    if(s[i]==s[i+1]){
      continue;
    }
    else{
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 9548
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ub              upper_bound
#define lb              lower_bound
#define isrt            insert
#define clr             clear
#define rsz             resize
#define ff              first
#define ss              second
#define lli             long long int
#define pb              push_back
#define pf              push_front
#define mkp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<int>
#define mii             map<lli,lli>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define INF             1e9
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define endl            "\n"


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

lli maxm(lli a, lli b)
{
    return (a >= b ? a : b);
}


lli minm(lli a, lli b)
{
    return (a <= b ? a : b);
}

lli power(lli x, lli y, lli p)
{
    lli res = 1;

    x = x % p;
    if (x == 0)
        return 0;

    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;


        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

lli nCrmodp(lli n, lli r, lli p)
{
    if (r == 0)
        return 1;
    if (r == 1)
        return n;


    lli pro = 1, k = n;
    while (k > r)
    {
        pro *= k;
        pro %= p;
        --k;
    }

    k = 2;
    while (k <= (n - r))
    {
        pro *= power(k, (p - 2), p);
        pro %= p;
        ++k;
    }

    return pro;
}


string num_str(lli n, lli k)
{
    string str = "";
    lli x = n;
    while (x != 0)
    {
        string s = to_string(x % k);
        str = s + str;
        x /= k;
    }

    return str;
}


lli first_big(lli n, lli k, lli arr[])
{
    lli l = 0;
    lli r = n - 1;

    lli leftGreater = n;

    while (l <= r) {
        lli m = l + (r - l) / 2;

        if (arr[m] > k) {
            leftGreater = m;
            r = m - 1;
        }

        else
            l = m + 1;
    }

    return leftGreater;
}

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main()
{
    c_p_c();


    int n;
    string str;
    int ans = 1e7;

    cin >> n >> str;


    int cnt = 0, r = 0, w = 0;

    for (int i = 0; i < n; ++i)
    {
        if (str[i] == 'R')
            ++r;
        else
            ++w;
    }

    for (int i = (n - w); i < n; ++i)
        if (str[i] == 'W')
            ++cnt;

    cout << (w - cnt) << endl;
    return 0;
}

Measured memory_bytes: 3672
a, b, c = map(int, input().split())

if a % 2 == 1 and b % 2 == 1 and c % 2 == 1:
  print(0)
elif a == b and b == c:
  print(-1)
else:
  _a, _b, _c = a, b, c
  ai = 0
  while True:
    if _a % 2 == 0:
      _a //= 2
      ai += 1
    else:
      break
  bi = 0
  while True:
    if _b % 2 == 0:
      _b //= 2
      bi += 1
    else:
      break
  ci = 0
  while True:
    if _c % 2 == 0:
      _c //= 2
      ci += 1
    else:
      break
  min2 = min(ai, bi, ci)
  div2 = pow(2, min2)
  a //= div2
  b //= div2
  c //= div2
  if (a + b) % 2 == 0 and (a + c) % 2 == 0 and (c + b) % 2 == 0:
    min2 += 1
  print(min2)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//---------------------------//

int W, H, N;
int x[212345], y[212345], d[212345]; // ??±-0, ???-1
int ord[212345];

int main() {
	cin >> W >> H >> N;
	REP(i, N) {
		char c;
		scanf("%d %d %c", x + i, y + i, &c);
		d[i] = c == 'S';
	}
	
	map<int, vector<pii> > m; // x-y, (x, number)
	REP(i, N) m[x[i] + y[i]].push_back(pii(x[i], i));
	
	vector<vector<pii> > vv; // ????????????????????????
	for (map<int, vector<pii> >::iterator it = m.begin(); it != m.end(); ++it) {
		vv.push_back(it->se);
	}
	
	vector<pii> ans; // (t, number)
	memset(ord, -1, sizeof(ord));
	
	REP(i, vv.size()) {
		vector<pii> &v = vv[i];
		sort(ALL(v));
		
		vector<int> t(v.size());
		REP(j, v.size()) {
			if (d[v[j].se]) t[j] = H + 1 - y[v[j].se];
			else t[j] = W + 1 - x[v[j].se];
		}
		
		bool black = (x[v[0].se] + y[v[0].se]) & 1; // ???????????´?????????????????§??????????????????
		
		queue<int> que[2]; // [y??§?¨??????¶?\?] = ???number
		
		REP(j, v.size()) {
			int num = v[j].se; // ?????¨????????????????????????
			
			if (d[num]) {
				int idx = black ^ (y[num] & 1); // ??????????????????y??§?¨??????¶?\?
				que[idx].push(num);
				ord[j] = que[idx].front();
				que[idx].pop();
			}
			else { // ??±??????
				que[y[num] & 1].push(num);
			}
		}
		
		REP(j, v.size()) {
			if (ord[j] != -1) continue;
			int idx = y[v[j].se] & 1;
			ord[j] = que[idx].front();
			que[idx].pop();
		}
		
		REP(j, v.size()) ans.push_back(pii(t[j], ord[j]));
		REP(j, v.size()) ord[j] = -1;
	}
	
	sort(ALL(ans));
	REP(i, ans.size()) printf("%d\n", ans[i].se + 1);
	
	return 0;
}

Measured memory_bytes: 43400
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
ll l[2010][2010], r[2010][2010], u[2010][2010], d[2010][2010];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) { cin >> S[i]; }

    rep(h, H)
    {
        ll t = 0;
        rep(w, W)
        {
            if (S[h][w] == '.') {
                t++;
            } else {
                t = 0;
            }
            l[h][w] = t;
        }
    }
    rep(h, H)
    {
        ll t = 0;
        for (int w = W - 1; w >= 0; --w) {
            if (S[h][w] == '.') {
                t++;
            } else {
                t = 0;
            }
            r[h][w] = t;
        }
    }
    rep(w, W)
    {
        ll t = 0;
        rep(h, H)
        {
            if (S[h][w] == '.') {
                t++;
            } else {
                t = 0;
            }
            u[h][w] = t;
        }
    }
    rep(w, W)
    {
        ll t = 0;
        for (int h = H - 1; h >= 0; --h) {
            if (S[h][w] == '.') {
                t++;
            } else {
                t = 0;
            }
            d[h][w] = t;
        }
    }
    ll ans = 0;
    rep(h, H)
    {
        rep(w, W)
        {
            if (S[h][w] == '.') {
                ans = max(ans, l[h][w] + r[h][w] + u[h][w] + d[h][w] - 3);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 130688
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N = int(input())
    a = list(map(int,input().split()))
    d = defaultdict(int)
    ans = 1
    d[0] += 3
    MOD = 1000000007
    for num in a:
        ans *= d[num]
        ans %= MOD
        d[num] -= 1
        d[num+1] += 1
    
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20816
#include <cstdio>
#include <algorithm>
#include <cstring>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
ll n,m;
ll minn=0,maxn=0;
int main()
{
	scanf("%lld%lld",&n,&m);
	for (ll i=1;i<m;i++)
	{
		minn=minn+i-1;
		maxn=maxn+n-i+1;
	}
	ll sum=0;
	for (ll i=m;i<n+1;i++)
	{
		minn=minn+i-1;
		maxn=maxn+n-i+1;
		sum=(sum+1+maxn-minn)%mod;
	}
	printf("%lld\n",sum%mod+1);
	return 0;
}

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

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

#define mp make_pair
#define pb(x) push_back(x)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define INF 2123456789
#define IINF 9123456789123456789

void use_cio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}
// template <typename... Args>
// void dbg(Args... args) {
//     ((cout << args << " "), ...);
//     cout << endl;
// }

//--------------------------------------------------//
int main() {
    string s, t;
    cin >> s >> t;
    rep(i, s.size()) {
        if (s == t) {
            cout << "Yes\n";
            return 0;
        }
        s = s.substr(1, s.size() - 1) + s[0];
    }
    cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if (a[0] + a[1] == a[2])
        puts("Yes");
    else
        puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>

int open[10];
int F[105][5][2];
int P[105][15];
int N;
int b;

void dfs(int d){
	if(d==10){
		int i,j,k;
		int flag=0;
		for(i=0;i<10;i++){
			if(open[i]==1){
				flag=1;
				break;
			}
		}
		if(flag==1){
			int m=0;
			for(k=0;k<N;k++){
				int cnt=0;
				for(i=0;i<5;i++){
					for(j=0;j<2;j++){
						if(F[k][i][j]==1&&open[(i*2)+j]==1){cnt++;}
					}
				}
				m+=P[k][cnt];
			}
			if(b<m){b=m;}
		}
		return;
	}

	open[d]=0;
	dfs(d+1);
	open[d]=1;
	dfs(d+1);
	open[d]=0;
}

int main(){

	b=-(1<<30);

	scanf("%d",&N);

	int i,j,k;

	for(i=0;i<N;i++){
		for(j=0;j<5;j++){
			for(k=0;k<2;k++){
				scanf(" %d",&F[i][j][k]);
			}
		}
	}
	for(i=0;i<N;i++){
		for(j=0;j<=10;j++){
		scanf(" %d",&P[i][j]);
		}
	}

	dfs(0);

	printf("%d\n",b);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 1000005 

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

bool isprime(li n)
{
  if (n == 1)
    return false;
  int i = 2;
  while (i*i <= n){
      if (n % i == 0)return false;
      i += 1;
  }
  return true;
}

li lcm(li a,li b)
{
    return ((a*b)/__gcd(a,b));
}

void solve()
{
  li n;
  string s;

  cin>>n;
  cin>>s;

  li b=0,r=0,g=0;

  for(li i=0;i<n;i++)
  {
    if(s[i]=='B')
      b++;
    else if(s[i]=='R')
      r++;
    else if(s[i]=='G')
      g++;
  }

  li total = b*g*r;
  for(li i=0;i<n;i++)
  {
    for(li j=i;j<n;j++)
    {
      li k = 2*j-i;

      if( k<n && s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k])
        total--;
    }
  }

  cout<<total<<endl;
}
int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    solve();
    
    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, K;
  cin >> N >> K;
  vll H(N);
  REP(i, 0, N) {
    ll h;
    cin >> h;
    H[i] = h;
  }
  sort(H.begin(), H.end(), less<>());

  ll ans = kMod;
  REP(i, 0, N - K + 1) {
    ll mi = H[i];
    ll ma = H[i+K-1];
    if (ans > abs(ma - mi)) {
      ans = abs(ma - mi);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import random

n, k = map(int, input().split())
pro = 0

for first_score in range(1, n + 1):
    if first_score >= k:
        pro += 1 / n
    else:
        i = 1
        while True:
            if first_score * (2 ** i) >= k:
                break
            i += 1
        pro += 1 / ((2 ** i) * n) 

print(pro)


Measured memory_bytes: 5092
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int>> edges;
    int sum = n % 2 ? n : n + 1;

    for(int i=1;i<=n;++i)
    {
        for(int j=i+1;j<=n;++j)
        {
            if(i + j != sum)
            {
                edges.push_back(MP(i, j));
            }
        }
    }

    cout << edges.size() << endl;
    for(int i=0;i<edges.size();++i)
    {
        cout << edges[i].first << " " << edges[i].second << endl;
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, A[3010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    int ans = 0;
    rep(i, 0, N) ans += A[i] - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
x = input().split()
A = []
for i in x:
    try:
        A.append(int(i))
    except:
        b = A.pop()
        a = A.pop()
        if i == '+':
            A.append(a + b)
        if i == '-':
            A.append(a - b)
        if i == '*':
            A.append(a * b)
print(A.pop())

Measured memory_bytes: 7696