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

const int MOD = (int)1e9+7;

int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);
 
  vector<int> k(50);
  int cnt=0;
  while(K>0){
    if(K%2==1)  k.at(cnt)++;
    K/=2;
    cnt++;
  }
  cnt--;
  
  vector<int> bitA(50);
  for(int i=0;i<N;i++){
    long long x=A.at(i);
    int count=0;
    while(x>0){
      if(x%2==1)  bitA.at(count)++;
      x/=2;
      count++;
    }
  }
 
  long long ans=0;
  for(int j=cnt;j>=-1;j--){
    vector<int> y(50);
    if(j>0 && k.at(j)==0)  continue;
    for(int s=0;s<50;s++){
      if(j==s) y.at(s)=0;
      else if(j<s)  y.at(s)=k.at(s);
      else if(j>s)  y.at(s)=-1;
    }
 
    long long ansx=0;
    long long count2=1;
    for(int i=0;i<50;i++){
      long long mx;
      if(y.at(i)==0) mx=bitA.at(i);
      else if(y.at(i)==1) mx=N-bitA.at(i);
      else if(y.at(i)==-1)  mx=max(bitA.at(i),N-bitA.at(i));
      ansx+=count2*mx;
      count2*=2;
    }
    ans=max(ans,ansx);
  }
 
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
    #include <cstdint>
    using namespace std;
     
    int main(){
      uint64_t Ns, Nc;
      cin >> Ns >> Nc;
      cout << (Nc <= 2*Ns ? (Nc / 2) : (Ns + (Nc - 2 * Ns) / 4)) << endl;
      return 0;
    }

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
int main(void){
  int i;
  char a[256];
  scanf("%s", a);
  for(i = strlen(a) - 1; i >= 0; i--){
    printf("%c",a[i]);
  }
  printf("\n");
  return 0;
}

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

vector<vector<pair<int, int> > > edge;//edge[i][j] firstがiからj番目のノード、secondがその重み
vector<int> d(100005,INF);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x;
	cin >> x;
	cout << 48 - x << endl;
}

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

using namespace std;

string s;
int K;

int canBeA(char c)
{
  if (K >= (('z' + 1) - (c + 0)) && c != 'a') {
    return ('z' + 1) - (c + 0);
  }
  return 0;
}

int main()
{
  cin >> s >> K;
  // a => 97, z => 122
  int lastIndex = s.size() - 1;
  for (int i = 0; i <= lastIndex; i++)
  {
    if (canBeA(s[i]) > 0) {
      K -= canBeA(s[i]);
      s[i] = 'a';
    }
  }
  s[lastIndex] = 'a' + (s[lastIndex] - 'a' + K) % 26;
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define sf1(x)      scanf("%d",&x)
#define pf3(x,y,z)  printf("%d\n%d\n%d\n",x,y,z)
#define FOR(i,x)    for(int i=0;i<x;i++)
using namespace std;
int main()
{
    int a[15];
    FOR(i,10)   sf1(a[i]);
    sort(a,a+10);
    pf3(a[9],a[8],a[7]);

    return 0;
}

Measured memory_bytes: 3264
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Measured memory_bytes: 19476
import math
a, b, h, m = map(int, input().split())

x1 = a * math.cos(math.pi * (60 * h + m)/60/6)
x2 = b * math.cos(math.pi * m/30)
y1 = a * math.sin(math.pi * (60 * h + m)/60/6)
y2 = b * math.sin(math.pi * m/30)

d2 = (x1 - x2) ** 2 + (y1 - y2) ** 2
print(d2 ** .5)


Measured memory_bytes: 62420
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]    

cnt = [0] * N

S = []
for i in range(N):
  t = A[i][cnt[i]] - 1
  if i == A[t][cnt[t]] - 1:
    if cnt[i] != N - 2:
      S.append(i)

ans = 1
L = [True] * N
while S:
  ans += 1
  for i in S:
    cnt[i] += 1
    L[i] = True
  T = []
  for i in S:
    if L[i]:
      t = A[i][cnt[i]] - 1
      if i == A[t][cnt[t]] - 1:
        if cnt[i] != N - 2:
          L[i] = False
          T.append(i)
        if L[t]:
          L[t] = False
          if cnt[t] != N - 2:
            T.append(t)
  S = T

for i in range(N):
  if cnt[i] != N - 2:
    print(-1)
    break
else:
  print(ans)


Measured memory_bytes: 54620
/*input
14282668646
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	string s;
	cin>>s;
	map<ll,ll> mp;
	ll k=0;
	mp[0]=1;
	ll ans=0;
	reverse(s.begin(),s.end());
	rep(i,0,s.length()){
		k+=(s[i]-'0')*power(10,i,2019);
		k%=2019;
		ans+=mp[k];
		++mp[k];
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 3776
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    int n, m;
    cin >> n >> m;
    vector<P> p(m);

    rep(i, m) {
        cin >> p[i].first >> p[i].second;
    }
    
    rep(x, 1000) {
        int keta = 1;
        int nx = x/10;
        vector<int> d(1, x%10);
        while (nx) {
            keta++;
            d.push_back(nx%10);
            nx /= 10;
        }
        if (keta != n) {
            continue;
        }
        bool ok = true;
        reverse(d.begin(), d.end());
        rep(i, m) {
            if (d[p[i].first-1] != p[i].second) {
                ok = false;
            }
        }
        if (ok) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3


def main():
    s = input()
    s1 = s[:2]
    s2 = s[2:]
    if 1 <= int(s1) <= 12:
        if 1 <= int(s2) <= 12:
            print('AMBIGUOUS')
        else:
            print('MMYY')
    else:
        if 1 <= int(s2) <= 12:
            print('YYMM')
        else:
            print('NA')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
int main(){
    int N,min = 31;
    cin >> N;
    REP(i,N){
        int A;
        cin >> A;
        int c = 0;
        while(c < min && ((~A >> c) & 1)) c++;
        min = c;
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
import math
import itertools

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

X = [[0]*(D+1)]*(N+1)

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

def distance(x, y):
    dis = 0
    for d in range(D):
        dis += abs(x[d] - y[d]) ** 2
    
    return math.sqrt(dis).is_integer()
    
distance(X[1], X[2])

count = 0

for c in itertools.combinations(list(range(N)), 2):
    if distance(X[c[0]], X[c[1]]):
        count += 1
        
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i,j;
  for(i=0;i<s.size();i++){
    int count=0;
    for(j=0;j<s.size();j++){
      if(s.at(i)==s.at(j)){
        count++;
      }
    }
    if(count%2==1){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
      

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

signed main(){
  ll n,x,ans=0;cin>>n>>x;

  vector<ll> v(n,0);
  for(int i=0;i < n;i++)
  {
    cin>>v[i];
  }

  for(int i=1;i < n;i++)
  {
    if(v[i-1]+v[i]>x){
      ans+=v[i-1]+v[i]-x;
      v[i]=max(x-v[i-1],0ll);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 1024
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int M = int.Parse(input[1]);
    int X = int.Parse(input[2]);
    input = Console.ReadLine().Split(' ');
    int[] arr = new int[M];
    for (int i = 0; i < M; i++) {
      arr[i] = int.Parse(input[i]);
    }
    
    int incCost = 0;
    for (int i = (X + 1); i < N; i++) {
      if (0 <= Array.IndexOf(arr, i)) {
        incCost++;
      }
    }
    int decCost = 0;
    for (int i = (X - 1); 0 < i; i--) {
      if (0 <= Array.IndexOf(arr, i)) {
        decCost++;
      }
    }
    Console.WriteLine(Math.Min(incCost, decCost));      
  }
}

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

int main() {
    int N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i], a[i] *= 2;

    long long off = 0;
    for (int i = 0; i < N; ++i) off = a[i] - off;
    long long x = off / 2;

    long long cur = x;
    for (int i = 0; i < N; ++i) {
        cout << cur << " ";
        cur = a[i] - cur;
    }
    cout << endl;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  vector<double> v(n);cin >> v;
  int idx = 0;
  double mind = 1001001001;
  double sum = 0;
  for(int i = 0; i < n; ++i)sum += v[i];
  double ave = sum / n;
  for(int i = 0; i < n; ++i){
    if(ChangeMin(mind, abs(ave - v[i])))idx = i;
  }
  cout << idx << endl;
  return 0;
}


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int>votes(N);
  for(int i=0;i<N;i++)
  {cin>>votes.at(i);}
  int sum=0;
  for(int i=0;i<N;i++)
  {sum+=votes.at(i);}
   sort(votes.begin(), votes.end()); // {1, 2, 2, 5}
    reverse(votes.begin(), votes.end()); // {5, 2, 2, 1}
  int min=votes.at(M-1);
  int border;
  if(sum%(4*M)==0){border=sum/(4*M);}
  else{border=(sum/(4*M))+1;}
  if(min<border){cout<<"No"<<endl;}
  else{cout<<"Yes"<<endl;}
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll N; cin>>N;
	map<ll,ll> cnt;
	ll ans = 0;
	rep(i,N){
		ll t; cin>>t;
		cnt[t] ++;
		ans += t;
	}
	ll Q; cin>>Q;
	vector<pair<ll, ll>> query(Q);
	rep(i,Q)cin>>query[i].first>>query[i].second;
	rep(i,Q){
		ll kazu = cnt[query[i].first];
		cnt[query[i].first] = 0;
		cnt[query[i].second] += kazu;
		ans += (query[i].second-query[i].first)*kazu;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 10512
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, M; cin >> N >> M;
	pair<int, int> A[M];
	for (int i = 0; i < M; i++) {
		cin >> A[i].second >> A[i].first;
	}
    sort(A,A+M);
	int a, b;
	a = A[0].second;
	b = A[0].first;
	int cur = b, ans = 0;
	ans++;
	for (int i = 1; i < M; i++) {
		if (A[i].second >= cur) {
          ans++;
		cur = A[i].first;
        }
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#17D8101028I tou koutetsu  2019/10/10
#ID:tanghaozhe 
#python
from collections import deque
n,q= map(int,input().split(" "))
data=deque([])
for i in range(n):
    name,time=input().split()
    time=int(time)
    cur = [name,time]
    data.append(cur)
    
t=0
while len(data)>0:
    cur=data.popleft()
    spend=min(cur[1],q)
    cur[1]-=spend
    t+=spend
    if(cur[1]==0):
        print(cur[0],t)
    else:
        data.append(cur)


#150 80 200 350 20


Measured memory_bytes: 13276
n = int(input())
s = input()

w = [0]*(n+1)
e = [0]*(n+1)

for i in range(n):
    if s[i] == "W":
        w[i+1] = w[i]+1
    else:
        w[i+1] = w[i]

for i in range(n-1, -1, -1):
    if s[i] == "E":
        e[i] = e[i+1]+1
    else:
        e[i] = e[i+1]

w.append(w[-1])
e.insert(0, e[0])

ans = n
for i in range(1, n+1):
    ans = min(ans, w[i-1]+e[i+1])

print(ans)


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

const int Maxn = 105;

int n, k;
bool mark[Maxn];

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 0; i < k; i++) {
        int d; scanf("%d", &d);
        while (d--) {
            int a; scanf("%d", &a);
            mark[a] = true;
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++)
        if (!mark[i]) res++;
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 3816
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(2);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI=3.141592653589793;

void solve()
{
	int a=1,b=1;
	int n;
	cin >>n;
	while(n--)
	{
		int x,y;
		cin >> x >> y;
		int m1= (a+x-1)/x;
		int m2= (b+y-1)/y;
		int m= max(m1,m2);
		a = x*m;
		b = y*m;
		//cout << a << " " << b << nl;
	}
	cout << a+b << nl;
}

int32_t main()
{
	FastIO;
	Fast_D;
	int T;
	T=1;
	while(T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3584
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


a,b,c = map(int, input().split())
ans = min(a*b*(c%2), a*(b%2)*c, (a%2*b*c))
print(ans)

Measured memory_bytes: 61752
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++)	cin >> a[i];
	sort(a.begin(),a.end());
	cout << a[n-1]-a[0] << endl;
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  int h, w, n;
  cin >> h >> w >> n;
  VI a(n);
  REP(i, 0, n) {
    cin >> a[i];
  }
  VI dat(h * w);
  int pos = 0;
  REP(i, 0, n) {
    REP(j, 0, a[i]) {
      dat[pos] = i + 1;
      pos += 1;
    }
  }
  vector<VI> res(h, VI(w, -1));
  pos = 0;
  REP(i, 0, h) {
    int dir = i % 2 ? -1 : 1;
    int start = i % 2 ? w - 1: 0;
    int end = i % 2 ? -1 : w;
    for (int j = start; j != end; j += dir) {
      res[i][j] = dat[pos];
      pos += 1;
    }
  }
  REP(i, 0, h) {
    REP(j, 0, w) {
      cout << res[i][j] << (j == w - 1 ? "\n" : " ");
    }
  }
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i = 0; i < A.size(); i++) cin >> A.at(i);
  
  sort(A.begin(), A.end());
  
  bool judge = true;
  
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1)) judge = false;
  }
  
  if (judge) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  string S, T;
  cin >> S >> T;
  int n;
  n = S.size();
  int count = 0;
  while (count <= n) {
    string Sn;
    Sn += S[n-1];
    for (int i = 0; i < n-1; i++) {
      Sn += S[i];
    }
    if (Sn == T) {
      cout << "Yes" << endl;
      return 0;
    }
    S = Sn;
    count++;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
/*
 * Created by Dipta Das on 14-01-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define endl "\n"
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

vector<int> s[1000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n, k = 2;
    cin >> n;
    while(1) {
        if (k*(k-1) / 2 >= n) break;
        ++k;
    }
    if (k*(k-1)/2 > n) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl << k << endl;
    int x = 1;
    
    for (int i = 0; i < k; ++i) {
        for (int j = i + 1; j < k; ++j) {
            s[i].push_back(x);
            s[j].push_back(x);
            ++x;
        }
    }

    for (int i = 0; i < k; ++i) {
        cout << s[i].size();
        for (int j = 0; j < s[i].size(); ++j) {
            cout << " " << s[i][j];
        }
        cout << endl;
    }
    


    return 0;
}



Measured memory_bytes: 2304
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

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


using namespace std;


int main()
{
    int n;
    cin >> n;
    string p;
    cin >> p;
    
    int a = 0;
    for (int i = 0; i <= n - 3; i++) {
        string t = p.substr(i, 3);
        if (t == "ABC")a++;
    }
    cout << a << endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long buff1=x+a;
		long buff2=x+b;
		long buff3=a+b;

		if(buff1<buff2 && buff1<buff3) {
			System.out.println(buff1);
		}else if(buff2<buff1&&buff2<buff3) {
			System.out.println(buff2);
		}else {
			System.out.println(buff3);
		}

	}
}




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

typedef long long ll;

const ll mod = 10007;
const int inf = 101234567;

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

    vector<vector<int>> x(N+1);
    vector<pair<int, int>> city(M);

    for (int i = 0; i < M; i++) {
        ll P, Y;
        cin >> P >> Y;
        x[P].push_back(Y);
        city[i] = {P, Y};
    }
    
    for (int i = 1; i <= N; i++) {
        sort(x[i].begin(), x[i].end());
    }

    for (int i = 0; i < M; i++) {
        printf("%06d%06d\n", city[i].first, lower_bound(x[city[i].first].begin(), x[city[i].first].end(), city[i].second)-x[city[i].first].begin()+1);
    }
}


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

void fnLinkedListSet(list<int> &a_rltiNumber)
{
  list<int>::iterator itlti;
  list<int>::iterator itltEND = a_rltiNumber.end();
  string sCommand;
  int iMaxCommand, iNumber;

  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin >> iMaxCommand;
  for (int i = 0; i < iMaxCommand; i++)
  {
    cin >> sCommand;
    if (sCommand == "insert")
    {
      cin >> iNumber;
      a_rltiNumber.push_front(iNumber);
    }
    else if (sCommand == "deleteFirst")
      a_rltiNumber.pop_front();
    else if (sCommand == "deleteLast")
      a_rltiNumber.pop_back();
    else if (sCommand == "delete")
    {
      cin >> iNumber;
      for (itlti = a_rltiNumber.begin(); itlti != itltEND; ++itlti)
        if (*itlti == iNumber)
        {
          a_rltiNumber.erase(itlti);
          break;
        }
    }
  }
}

void fnLinkedListGet(const list<int> &a_cnrltiNumber)
{
  list<int>::const_iterator itlti;
  list<int>::const_iterator itltEND = a_cnrltiNumber.end();

  for (itlti = a_cnrltiNumber.begin(); itlti != itltEND; ++itlti)
  {
    if (itlti != a_cnrltiNumber.begin()) cout << " ";
    cout << *itlti;
  }
  cout << endl;
}

int main()
{
  list<int> ltiNumber;
  fnLinkedListSet(ltiNumber);
  fnLinkedListGet(ltiNumber);

  return 0;
}

Measured memory_bytes: 32476
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	int a, b;
	char c;
	std::cin >> a >> c >> b;
	std::cout << ((c == '+') ? a + b : a - b) << std::endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a * b, a - b));
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
 
 
class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None
 
 
def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top
 
 
def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)
 
 
def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)
 
 
n = int(stdin.readline())
 
top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()

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


int main() {
  
  int N;
  while (cin >> N && N) {
    
    struct point {
      int x, y;
    } block[200];
    
    
    block[0].x = 0;
    block[0].y = 0;
    
    const int dx[4]={-1,0,1,0};
    const int dy[4]={0,-1,0,1};
    
    for(int bn = 1; bn < N; bn++){
      int num, d;
      
      cin >> num >> d;

      block[bn].x = block[num].x + dx[d];
      block[bn].y = block[num].y + dy[d];
    }
    
    int r = 0, l = 0, t = 0, b = 0;
    
    for (int i = 0; i < N; i++) {
      if (r < block[i].x)
        r = block[i].x;
      if (l > block[i].x)
        l = block[i].x;
      if (t < block[i].y)
        t = block[i].y;
      if (b > block[i].y)
        b = block[i].y;
    }
    cout << r - l + 1 << " ";
    cout << t - b + 1 << endl;
  }
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int n;
    cin >> n;
    int minv = INF,maxv = -10;
    int miv = 0,mav = 0;
    int a,b;
    rep(i,n){
        cin >> a >> b;
        if(minv > a){ 
            minv = a;
            miv = b;
        }
        if(maxv < a){ 
            maxv = a;
            mav = b;
        }
    }   
    cout << maxv + mav << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

int main()
{
    ll k, n;
    cin >> k >> n;
    vector<ll> A(n);
    vector<ll> B(n);
    ll sum = 0;
    for (ll i = 0; i < n; i++)
    {
        cin >> A[i];
        if(i!=0)
        {
            B[i] = A[i] - A[i - 1];
            sum += B[i];
        }
    }
    B[0] = A[0]+k - A[n - 1];
    sum += B[0];
    auto itr = max_element(B.begin(), B.end());
    sum -= *itr;
    cout << sum << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	int h[100];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int island;
	bool flag;
	int ans = 0;
	while (1) {
		flag = false;
		island = 0;
		if (h[0] != 0) {
			island++;
		}
		for (int i = 1; i < n; i++) {
			if (h[i - 1] == 0 && h[i] != 0) {
				island++;
			}
		}
		if (island == 0 && h[n-1] != 0) {
			island++;
		}
		ans += island;
		for (int i = 0; i < n; i++) {
			if (h[i] > 0) {
				h[i]--;
			}
			if (h[i] != 0) {
				flag = true;
			}
		}
		if (flag == false) {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
  vector<int> vec;
  int i, j, k, x, sum, counter = 0;
  while(cin>>x) {
  	vec.push_back(x); 
  }
  sum = vec.back();
  vec.pop_back();
  for(i = 0; i <= vec[0]; i++) {
    for(j = 0; j <= vec[1]; j++) {
      for(k = 0; k <= vec[2]; k++) {
        x = 500 * i + 100 * j + 50 * k;
		if (sum == x)  {
          counter++;
        }
      }  
    }  
  }
  
  printf("%d", counter);
  return 0;
}

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

int main() {
    char s[2];
    cin >> s[0] >> s[1];
    if(s[0] > s[1])
        cout << ">" << endl;
    else if(s[0] == s[1])
        cout << "=" << endl;
    else
        cout << "<" << endl;
}

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

int main(void){
  int n;
  ll k;
  cin >> n >> k;
  if(k == 1){
    puts("0");
    return 0;
  }
  ll res = 0LL;
  vector<ll> lv = vector<ll>(n+1);
  map<ll,ll> lvmap;
  ll acc = 0LL;
  lv[0] = 0;
  lvmap[0] = 1;
  for(int i = 1;i <= n;++i){
    ll a;
    cin >> a;
    acc = (acc + a) % k;
    lv[i] = ((acc - i) % k + k) % k;
    res += lvmap[lv[i]];
    lvmap[lv[i]]++;
    if(i >= k-1){
      lvmap[lv[i-k+1]]--;
    }
  }
  cout << res << endl;
  return 0;
}


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

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

	int h, m, s;

	h = S / (60 * 60);
	S %= 60 * 60;
	m = S / 60;
	S %= 60;
	s = S % 60;

	cout << h << ':' << m << ':' << s << endl;

	return 0;
}


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

const ll INF = 1e18;


int main(){
  int a,b;
  cin >> a >> b;
  
  if (a>b) cout << "safe" << endl;
  else cout << "unsafe" << endl;
}

Measured memory_bytes: 3624
fun main() {
    val builder = StringBuilder()

    val input = readInputLine().split(" ").map { it.toInt() }

    for (i in 0 until 5) {
        if (input[i] == 0) {
            builder.appendln(i + 1)
            break
        }
    }

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

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

int main()
{
        string s, t;
        cin >> s >> t;
        sort(all(s));
        sort(all(t));
        reverse(all(t));
        if (s < t)
                cout << "Yes" << endl;
        else
                cout << "No" << endl;

        return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
tmp = 0
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            tmp = i * 500 + j * 100 + k * 50
            if tmp == x:
                ans += 1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>

int main()
{
  int x, y;
  scanf("%d%d", &x, &y);
  if (x == 1 && y == 1)
  {
    puts("1000000");
  }
  else
  {
    int ans = 0;
    if (x <= 3)
    {
      ans += (4 - x) * 100000;
    }
    if (y <= 3)
    {
      ans += (4 - y) * 100000;
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a[100], n,sum=0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		for (int j = n-1; j > i; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]); sum++;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1)cout << " ";
	}
	cout <<endl<< sum << endl;
}

Measured memory_bytes: 3080
import sys
sys.setrecursionlimit(500000)

def main():
    N, M = map(int, input().split())
    E = [[] for _ in range(N+1)]
    for u, v, s in zip(*[iter(map(int, sys.stdin.read().split()))]*3):
        E[u].append((v, s))
        E[v].append((u, s))

    V = [[None] * (N+1), [None] * (N+1)]

    def dfs(v=1, sign=1, val=0):
        V[sign][v] = val
        sign = 1 - sign
        for u, s in E[v]:
            if V[sign][u] is None:
                dfs(u, sign, s-val)
            else:
                if V[sign][u] != s-val:
                    print(0)
                    exit()

    dfs()

    mi, ma = 1, float("inf")
    for m, p in zip(V[0][1:], V[1][1:]):
        if m is not None and p is not None:
            mp = m - p
            if mp % 2 == 0:
                a = mp // 2
                mi = max(mi, a)
                ma = min(ma, a)
            else:
                ma = -1
        if p is not None:
            mi = max(mi, 1-p)
        if m is not None:
            ma = min(ma, m-1)

    ans = max(0, ma-mi+1)

    # if ans == 1:
    #     A = [-1] * (N+1)
    #     def check(v=1, val=ma):
    #         A[v] = val
    #         for u, s in E[v]:
    #             if A[u] == -1:
    #                 check(u, s - val)
    #             else:
    #                 if A[u] != s - val:
    #                     print(0)
    #                     exit()
    #
    #     check()
        #print(A)
    print(ans)

main()


Measured memory_bytes: 221464
#include<bits/stdc++.h>
#include <iostream>
//#include <boost/math/common_factor.hpp>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

#define all(x) x.begin(), x.end()
#define reg(i,x) for(ll i=0;i<x;i++)
#define regi(i,a,x) for(ll i=a;i<x;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
//const ll INF = 1e18;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
int dx[]={-1,0,0,1};
int dy[]={0,-1,1,0};
int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return (a*b)/gcd(a,b);
}
ll MAXN=10e9;
int m,n;
vi l(100);
int leader(int v)
{
    if(l[v]!=v) l[v]=leader(l[v]);
    return l[v];
}
int unite(int v1,int v2)
{
    v1=leader(v1);
    v2=leader(v2);
    l[v1]=v2;
}
int main()
{
    // clock_t start, end;
    // start = clock();
    ios_base::sync_with_stdio(0); //cant use scanf, printf
    cin.tie(0);cout.tie(0); // no longer auto flush cout before each cin, remove for interactive
    int d,t,s;
    cin>>d>>t>>s;
    ll ans=s*t;
    if(ans>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    // end = clock();
    // double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
    // watch(time_taken);
}


Measured memory_bytes: 3688
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
for i in range(N):
  n = bin(A[i])
  for j in range(len(n)-1, 1, -1):
    bit[len(n)-j-1] += int(n[j])
ans = 0
POW = 1
for j in range(60):
  ans = (ans +bit[j]*(N-bit[j])*POW)%MOD
  POW = (POW * 2)%MOD
print(ans%MOD)

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int x,y;
	std::cin >> x >> y;
	int count = 0;
	while(x<=y) {
		count++;
		x*=2;
	}
	print(count);
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    /*int cnt=0;
    int t;cin>>t;
    while(t--){




        cout<<"Case #"<<++cnt<<": "<<ans<<endl;
    }*/

    int n;cin>>n;
    string s,t;cin>>s>>t;
    for(int len=n;len>=0;len--){
        string ss=s.substr(n-len,len);
        string tt=t.substr(0,len);
        if(ss==tt){
            cout<<2*n-len<<endl;
            return 0;
        }
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

















































Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int x;
	int y;
	
	scanf("%d %d", &x, &y);
	if (x==1 && y==2){
		printf ("3");
	}
	if (x==2 && y==3){
		printf ("1");
	}
	if (x==3 && y==1){
		printf("2");
	}
	if (x==3 && y==2){
		printf("1");
	}	
	if (x==2 && y==1){
		printf("3");
	}
	if (x==1 && y==3){
		printf("2");
	}
	
	
	return 0;
}

Measured memory_bytes: 3000
#include<stdio.h>
int main()
{    int a,b,c;
       while(scanf("%d %d %d",&a,&b,&c)==3){
               if(a<c && b>c){
                    printf("Yes\n");
               }
             else if(a==b && b==c){
                    printf("Yes\n");
                }
             else{
                       printf("No\n");
              }
          }
           return 0;
    }

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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

int main() {
  cout << setprecision(18);
  double R;

  cin >> R;
  cout << R * 6.28318530717958623200 << endl;
}

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

int main () {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;

  if (b >= a){
    if (a + v * t >= b + w * t) cout << "YES";
    else cout << "NO";
  }
  else{
    if (a - v * t <= b - w * t) cout << "YES";
    else cout << "NO";
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, m, a[100005], sum[100005], ans;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) sum[i+1] += sum[i] + a[i];
    map<ll, ll> res;
    erep(i, 0, n) res[sum[i] % m]++;
    for (auto itr = res.begin(); itr != res.end(); ++itr) {
      ll p = itr->second;
      ans += p * (p - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
  int d, g;
  cin >> d >> g;
  g /= 100;
  vector<int> p(d), c(d), s(d), u(d);
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
    s[i] = (i + 1) * p[i] + c[i];
    u[i] = s[i] - (i + 1) - c[i];
  }
  int ans = 10000;
  for (int x = 0; x < (1 << d); x++) {
    int uncomp = -1;
    int sum = 0;
    int temp = 0;
    for (int i = 0; i < d; i++) {
      if (x & (1 << i))  {
        sum += s[i];
        temp += p[i];
      } else {
        uncomp = i;
      }
    }
    if (sum >= g) {
      ans = min(ans, temp);
    } else if (sum + u[uncomp] >= g) {
      ans = min(ans, temp + (g - sum - 1) / (uncomp + 1) + 1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, m = gets.chomp.split(' ').map(&:to_i)
ss = m.times.map { gets.chomp.split(' ').drop(1) }
ps = gets.chomp.split(' ')

cnt = 0
(0...2**n).each do |ptn|
    switches = (0...n).map { |i| (ptn / 2 ** i) % 2 }
    on = true
    ss.zip(ps).each do |nums, ons|
        on_cnt = nums.map { |n| switches[n.to_i - 1] }.reduce(:+)
        if on_cnt % 2 != ons.to_i
            on = false
            break
        end
    end
    next if !on
    cnt = cnt + 1
end

puts cnt


Measured memory_bytes: 1916
import java.util.Scanner;							
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] stock = new int[100];
		int input, ST, output;
		
		while(sc.hasNext()){
			input = sc.nextInt();
			if(input == 0){
				ST = seach(stock);
				output = stock[ST -1];
				System.out.println(output);
				stock[ST-1] = 0;
			}else{
				ST = seach(stock);
				stock[ST] = input;
			}
		}
	}
	
	static int seach(int[] stock){
		int k = 0;
		for(int i = 0; i < stock.length; i++){
			if(stock[i] == 0){
				k = i;
				return k;
			}
		}
		return k;
	}
}

Measured memory_bytes: 26204
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int[] a = new int[3];
            int[] b = new int[3];
            for (int j = 0; j < a.length; j++) {
                a[j] = scanner.nextInt();
            }
            for (int j = 0; j < b.length; j++) {
                b[j] = scanner.nextInt();
            }
            int x = a[0] * 3600 + a[1] * 60 + a[2];
            int y = b[0] * 3600 + b[1] * 60 + b[2];
            int t = y - x;
            int h = t / 3600;
            int m = t % 3600 / 60;
            int s = t % 3600 % 60;
            System.out.println(h + " " + m + " " + s);
        }
    }
}


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

#define fo(i,s,t) for(int i =s; i<=t;++i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
const int maxn = 500050;

long long f[maxn][2];
int n, a, b, c, d;

int main()
{
	cin >> n >> a >> b >> c >> d;
	f[1][0] = c; f[1][1] = d;
	fo(i,2,n) f[i][0] = f[i-1][0]+c, f[i][1] = f[i-1][1]+d;
	fo(i,0,n-1) if(f[i][0]-f[n-i-1][1]<=b-a&&f[i][1]-f[n-i-1][0]>=b-a) {puts("YES"); return 0;}
	puts("NO");	
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

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();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

long long m = 1e9+7, mod = 1e9+7;
//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

/* //約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}*/


int main() {
  int N;ll ans=0;
  scanf("%d",&N);
  vector<Vi> v(10,Vi (10,0));
  REP(i,N) {
    string str(to_string(i+1));
    int f = str[0] - '0';
    int l = str[str.length()-1] - '0';
    // printf("%d %d\n",f,l);
    v[f][l]++;
  }
  REP(i,10) {
    FOR(j,0,10) {
      ans += v[i][j]*v[j][i];
    }
  }
  printf("%d",ans);
}

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

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

  int n, m;
  cin >> n >> m;
  priority_queue<pair<ll, int>> q;
  rep(i, n) { 
    pair<ll, int> p;
    cin >> p.first;
    p.second = 1;
    q.push(p);
  }
  rep(i, m) {
    pair<ll, int> p;
    cin >> p.second >> p.first;
    q.push(p);
  }
  ll ans = 0;
  int i = 0;
  while (i < n) {
    auto p = q.top(); q.pop();
    int num = min(n-i, p.second);
    ans += p.first * num;
    i += num;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6384
#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)
const int MOD=1e9+7;

int main() {
    string s;
    cin >> s;
    int n=s.size();
    ll ans=0,acnt=0;    
    rep(i,n-2) {
        if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') {
            ans+=acnt+1;
            s[i+2]='A';
            ++i;
        }
        else if (s[i]=='A') ++acnt;
        else acnt=0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640