akhauriyash/Code-Regression huggingface dataset:
import numpy as np
N= int(input())
H = list(map(int, input().split()))
dp = np.zeros(N, dtype = int)


for i in range(N - 1):
    if i == 0:
        dp[i + 1] = abs(H[0] - H[1])
    else:
        dp[i + 1] = min(dp[i] + abs(H[i] - H[i + 1]),
                        dp[i - 1] + abs(H[i - 1] - H[i + 1]))

#print(dp)
print(dp[N - 1])


Measured memory_bytes: 22840
/**
 *    author: kalyan       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;
 
void solve(){
    string str;
    cin >> str;
    if(str[str.size()-1] == 's') cout<<str+"es";
    else cout << str+"s";
    
}
 
int main(){
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t;
    t = 1;
    // cin >> t;
    while(t--){
    	solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#define MAX 1000
using namespace std;

int top, s[MAX];

bool isEmpty() {
    if (top == 0) return true;
    else return false;
}

bool isFull() {
    if (top >= MAX-1) return true;
    else return false;
}

void push(int x) {
    if (!isFull()) {
        s[++top] = x;
    }
}

int pop() {
    if(!isEmpty()) {
        top--;
        return s[top+1];
    }
}

int main() {
    int a, b, i;
    char str[MAX];
    top = 0;
    // getline(cin, str);
    while (scanf("%s", str) != EOF) {
        if (str[0] == '+') {
            a = pop();
            b = pop();
            push(a + b);
        } else if (str[0] == '-') {
            a = pop();
            b = pop();
            push(b - a);
        } else if (str[0] == '*') {
            a = pop();
            b = pop();
            push(a * b);
        } else {
            push(atoi(str));
        }
    }
    cout << pop() << endl;
    return 0;
}


Measured memory_bytes: 3152
from collections import Counter
I=lambda:[int(i) for i in input().split()]
n,m=I()
a=0
s=[0]
for i in I():
  a=(a+i)%m
  s+=[a]
x=0
for i,j in Counter(s).most_common():
  x+=j*(j-1)//2
print(x)

Measured memory_bytes: 15560
if __name__ == '__main__':
    n,k,q= map(int, input().split())
    a = [0]*n
    for i in range(q):
        b = int(input()) -1
        a[b] = a[b] +1
    for i in a:
        point = k - q + i
        if point > 0:
            print('Yes')
        else:
            print('No')



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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    while (true)
    {
        for (int i = 0; i < n; i++)
        {
            if (a[i] % 2 != 0)
            {
                cout << ans << endl;
                return 0;
            }
        }
        for(int i = 0; i < n; i++){
            a[i] /= 2;
        }
        ans++;
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(){
    double deg,a,b,C,c,d;
    double rad,S,L,h;
    double pi=acos(-1);
    cin>>a>>b>>C;
    rad=(pi*C)/180;
    S=a*b*sin(rad)/2;
    d=a*a+b*b-2*a*b*cos(rad);
    c=sqrt(d);
    L=a+b+c;
    h=2*S/a;
    printf("%.8lf\n",S);
    printf("%.8lf\n",L);
    printf("%.8lf\n",h);
    return 0;
}


Measured memory_bytes: 3372
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
char a[69][69],b[69][69];
signed main(){
	ic(n) ic(m)
	rep(0,i,n)rep(0,j,n)cin>>a[i][j];
	rep(0,i,m)rep(0,j,m)cin>>b[i][j];
	int sum=0;
	rep(0,i,n-m+1){
		rep(0,j,n-m+1){
			sum=0;
			rep(0,k,m){
				rep(0,l,m){
					if(a[k+i][l+j]==b[k][l])sum++;
				}
			}
			if(sum==m*m){
				c("Yes")
				return 0;
			}
		}
	}
	c("No")
}	


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A), greater<>());

  map<int, int> m;
  REP(i, N) m[A[i]]++;

  int now = 2;
  while(now <= A[0]) now *= 2;

  int ans = 0;
  REP(i, N){
    while(now > A[i]*2) now /= 2;
    int cnt = min(m[A[i]], m[now-A[i]]);
    if(A[i]+A[i] == now) cnt /= 2;
    m[A[i]] -= cnt;
    m[now-A[i]] -= cnt;
    ans += cnt;
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll> g(n);
  vector<ll> a(n);
  for(ll i=0;i<n;i++) cin>>a[i];
  for(ll i=0;i<m;i++){
    ll x,y;
    cin>>x>>y;
    g[x-1]=max(g[x-1],a[y-1]);
    g[y-1]=max(g[y-1],a[x-1]);
  }
  
  ll ans=0;
  for(ll i=0;i<n;i++){
  	if(g[i]<a[i]) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4812
#include <stdio.h>


int main(void){
  int i,j,k,n,s;
  char ca[201],can[201];

  while(1){
    scanf("%s\n%d", ca, &n);
    if(!strcmp(ca, "-")) break;
   
    for(i=0;i<n;i++){
      scanf("%d", &s);
      for(j=s;ca[j]!='\0';j++)
        can[j-s] = ca[j];
      for(k=0;k<s;k++)
        can[j-s+k] = ca[k];
     
      for(j=0;ca[j]!='\0';j++)
        ca[j] = can[j];
    }

    printf("%s\n", ca);
  }

  return 0;
}



Measured memory_bytes: 2036
#include<iostream>

using namespace std;

int brick_break(int n, int a[]) {
  int ans = 0;
  int peek = 1;
  for(int i=0;i<n;i++) {
    if(a[i] != peek) {
      ans++;
      continue;
    }
    peek++;
  }
  if (peek == 1) {
    return -1;
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  cout << brick_break(n, a);
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int n,k,x,y,i;
	long long m=0;
	scanf("%d%d%d%d",&n,&k,&x,&y);
	if(k>n)k=n;
	for(i=0;i<k;i++)
	{
		m+=x;
	}
	if(n>k)
	{
		
		for(i=0;i<n-k;i++)
		{
			m+=y;
		}
	}
	printf("%d",m);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=25005,M=405,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,K,m,a[N],h[M],fir,las,ans;
int f[N][M],sf[N],g[N][M],sg[N];
void check(int &x,int y){if ((x+=y)>=p) x-=p;}
void solve(int f[][M]){
	for (int i=1;i<=n;i++){
		int s=0;
		for (int j=K-1;j;j--){
			check(s,f[i-1][j]);
			f[i][j]=(s+(ll)f[i-1][j-1]*(K-j+1))%p;
		}
	}
}
void solve2(){
	for (int i=1;i<=n;i++){
		int s=0,sg=0;
		for (int j=K-1;j;j--){
			check(s,f[i-1][j]);check(sg,g[i-1][j]);
			f[i][j]=(s+(ll)f[i-1][j-1]*(K-j+1))%p;
			g[i][j]=(sg+(ll)g[i-1][j-1]*(K-j+1))%p;
			if (j>=m) check(g[i][j],f[i][j]);
		}
	}
}
int main(){
	n=read();K=read();m=read();
	int fl=1;
	for (int i=1;i<=m;i++){
		a[i]=read();
		if (h[a[i]]){
			if (!fir) fir=i;
			las=max(las,h[a[i]]);
		}
		if (las+K==i) {fl=0;break;}
		h[a[i]]=i;
	}
	ans=(ll)qpow(K,n-m)*(n-m+1)%p;
	if (fl){
		if (fir){
			f[0][fir-1]=1;
			solve(f);
			for (int i=0;i<=n;i++)
			for (int j=0;j<K;j++)
			check(sf[i],f[i][j]);
			g[0][m-las]=1;
			solve(g);
			for (int i=0;i<=n;i++)
			for (int j=0;j<K;j++)
			check(sg[i],g[i][j]);
			for (int i=0;i<=n-m;i++)
			check(ans,p-(ll)sf[i]*sg[n-m-i]%p);
		}
		else{
			f[0][0]=1;
			solve2();
			int s=0,t=1;
			for (int i=0;i<K;i++) check(s,g[n][i]);
			for (int i=(K-m+1);i<=K;i++) t=(ll)t*i%p;
			check(ans,p-(ll)s*qpow(t,p-2)%p);
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif


#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1)
#define ld long double
#define prime 1000000007

using namespace std;

#define INF 1000000000

ll f(ll n){
	ll res  = 0;
	for(int i = 0; i < n; ++i){
		if(n & (1 << i)){
			res = i;
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	ll n, k;
	cin >> n >> k;
	vl vet1(n);
	for(int i = 0; i < n; ++i){
		cin >> vet1[i];
	}
	vl vet2(62);
	for(int i = 0; i < n; ++i){
		for(ll j = 0, l = 1; j < 60; ++j, l <<= 1){
			vet2[j] += ((vet1[i]&l) != 0);
		}
	}
	ll pres = 0, state = 0, uBit = f(k);
	for(ll i = 60, j = 1LL << 60; i >= 0; --i, j >>= 1){
		if(vet2[i]*2 < n && (pres | j) <= k){
			pres |= j;
		}
	}
	W(pres, endl)
	ll res = 0;
	for(int i = 0; i < n; ++i){
		res += (vet1[i] ^ pres);
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1024
import bisect
import math
n, c, k = list(map(int, input().split()))
t = [0] * n
for i in range(n):
    t[i] = int(input())
t.sort()
bus_count = 0
pre_index = 0
index = 0
while index < n:
    #indexを乗せるバスが発車する時間
    leave = t[index] + k
    count = 0
    bus_count += 1
    while index < n and count < c and leave >= t[index]:
        count += 1
        index += 1
print(bus_count)

Measured memory_bytes: 45272
import sys
import collections as cc
input = sys.stdin.readline
I=lambda:list(map(int,input().split()))
n,w=I()
val=[]
wt=[]
for i in range(n):
	x,y=I()
	wt.append(x)
	val.append(y)
dp=[[0]*(w+1) for i in range(n+1)]
for i in range(1,n+1):
	for j in range(1,w+1):
		if wt[i-1]<=j:
			dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j])
		else:
			dp[i][j]=dp[i-1][j]
print(dp[n][w])


Measured memory_bytes: 119916
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//(AGCも含めてはならない??

//隣接する2文字を入れ替えて AGCとなるパターン
//AGC, ACG, GAC, A?GC, AG?C  
//0: 何でも, 1: A, 2: G, 3: C, 4:T
//AGC (123)
//ACG (132)
//GAC (312)
//A?GC (1023)
//AG?C (1203)

//3文字前までのdp

//多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    auto dp = make_vec<ll>(n+1,5,5,5);
    dp[0][0][0][0] = 1;

    //dp[i][3文字前][2文字前][1文字前]
    //dp[i+1][2文字前][1文字前][今回の]
    
    for(int s = 0; s < n; ++s){
        for(int i = 0; i < 5; ++i){
            for(int j = 0; j < 5; ++j){
                for(int k = 0; k < 5; ++k){
                    for(int l = 1; l < 5; ++l){
                        if(i == 1 && j == 2 && l == 3)continue;
                        if(i == 1 && k == 2 && l == 3)continue;
                        if(j == 1 && k == 2 && l == 3)continue;
                        if(j == 2 && k == 1 && l == 3)continue;
                        if(j == 1 && k == 3 && l == 2)continue;
                        dp[s+1][j][k][l] += dp[s][i][j][k];
                        dp[s+1][j][k][l] %= MOD;
                    }
                }
            }
        }
    }

    //nのやつ足す
    ll res = 0;
    for(int i = 1; i < 5; ++i){
        for(int j = 1; j < 5; ++j){
            for(int k = 1; k < 5; ++k){
                res += dp[n][i][j][k];
                res %= MOD;
            }
        }
    }


    cout << res << endl;



    return 0;    
}



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

int main(){
  int n,r,p,c,a[50];
  while(1){
    cin>>n>>r;
    if(n==0 && r==0)break;

    for(int i=n;i>0;i--){
      a[n-i]=i;
    }
    for(int i=0;i<r;i++){
    cin>>p>>c;
    rotate(a,a+p-1,a+p+c-1);
    }
    
  cout<<a[0]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3160
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 310000
#define MAX_V 900010
#define vec vector<int>
using namespace std;

ll a[N],b[N],n;
bool check(int k){
    ll int m=1<<(k+1);
    ll int A[N];
    ll int B[N];
    rep(i,n)A[i]=a[i]%m;
    rep(i,n)B[i]=b[i]%m;
    sort(A,A+n);
    int res=0;
    rep(i,n){
        res+=(lower_bound(A,A+n,m-B[i])-lower_bound(A,A+n,m/2-B[i]));
        res+=lower_bound(A,A+n,2*m-B[i])-lower_bound(A,A+n,m*3/2-B[i]);
        res%=2;
    }
    return res;
}
main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll int r=1;
    ll int ans=0;
    rep(i,31){
        ans+=check(i)*r;
        r<<=1;
    }
    cout<<ans;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,res=0;
  scanf("%d%d%d",&A,&B,&C);
  res=min(B,C);
  B-=res;
  C-=res;
  res*=2;
  if(C && A) res+=min(A,C);
  if(A<C) ++res;
  printf("%d\n",res+B);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef unsigned long long ull;
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;
const ll MAX=9223372036854775807;

ll a[maxn], siz[maxn];

void slove() {
	ll n;
	ll temp = 1e18, ans=1;
	//cout << tmp << '\n';
	int flag = 1;
	cin >> n;
	rep(i,0,n) {
		cin >> a[i];
		if (a[i]==0) flag=0;
	}
	if (!flag) {cout << "0\n"; return;}

	rep(i,0,n) {
		if (a[i] > MAX/ans || a[i]*ans > temp) {flag=0; break;}
		ans*=a[i];
	}
	if (!flag) cout << "-1\n";
	else cout << ans << '\n';
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
	//int t; cin >> t; while(t--)
	slove();

	return 0;
}

Measured memory_bytes: 4428
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

void solve(string s, int p) {
    int n = s.size();
    ll ans = 0;
    rep (i, n) {
        int x = s[i] - '0';
        if (x % p == 0) {
            ans += (i + 1);
        }
    }
    cout << ans << endl;
}

signed main() {
    fio();   
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    if (p == 2 or p == 5) {
        solve(s, p);
        return 0;
    }
    ll mul = 1;
    ll add = 0;
    vl sum(p);
    ll ans = 0;
    rrep (i, n) {
        add += mul * (s[i] - '0') % p;
        add %= p;
        if (add == 0) ans++;
        ans += sum[add];
        sum[add]++;
        (mul *= 10) %= p;
    }
    cout << ans << endl;

}

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

using namespace std;

int main(int argc, char *argv[]) {
    string S, T, U;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    cin >> U;
    if (U == S) {
        A--;
    } else if (U == T) {
        B--;
    }
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int A[100001];
int B[100001];
int C[100001];
int diffs[100001]; // index => diff
vector<P> diffIndexes; // 昇順 (diff, index)
ll sumA = 0;
ll sumB = 0;

int main() {
    int N;
    cin >> N;
    rep(i, N) {
        ll ai;
        cin >> ai;
        A[i] = ai;
        C[i] = ai;
        sumA += ai;
    }
    rep(i, N) {
        ll bi;
        cin >> bi;
        B[i] = bi;
        sumB += bi;
        ll diff = A[i] - B[i]; // diff Bを基準にしたときのA
        diffs[i] = diff;
        diffIndexes.pb(make_pair(diff, i));
    }

    if (sumA < sumB) {
        cout << -1 << endl;
        return 0;
    }

    // ソート
    sort(all(diffIndexes));

    int plusIndex = diffIndexes.size() - 1;
    int minusIndex = 0;
    //DEBUG(plusIndex);
    //DEBUG(minusIndex);
    //rep (i, N) {
    //    DEBUG(diffIndexes[i]._1);
    //    DEBUG(diffIndexes[i]._2);
    //}
    //DEBUG("----------");

    while (diffs[diffIndexes[minusIndex]._2] < 0) { // minusIndexの場所のdiffが0以上で終了
        int currentMinIndex = diffIndexes[minusIndex]._2;
        int currentMaxIndex = diffIndexes[plusIndex]._2;
        int restLack = B[currentMinIndex] - C[currentMinIndex] ;
        int restExtra = C[currentMaxIndex] - B[currentMaxIndex];
        //DEBUG(plusIndex);
        //DEBUG(minusIndex);
        //DEBUG(currentMinIndex);
        //DEBUG(currentMaxIndex);
        //DEBUG(restLack);
        //DEBUG(restExtra);
        //DEBUG("----------");

        if (restLack > restExtra) {
            C[currentMinIndex] += restExtra;
            C[currentMaxIndex] -= restExtra;
            plusIndex--;
        } else if (restExtra > restLack) {
            C[currentMinIndex] += restLack;
            C[currentMaxIndex] -= restLack;
            minusIndex++;
        } else if (restLack == restExtra) {
            C[currentMinIndex] += restLack;
            C[currentMaxIndex] -= restExtra;
            plusIndex--;
            minusIndex++;
        }
    }

    int result = 0;
    rep (i, N) {
        if (A[i] != C[i]) result++;
    }
    cout << result << endl;
}

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

int main(void){
  int n,k;
  string str;
  cin >> n >> k;
  cin >> str;
  str[k - 1] -= ('A' - 'a');
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1001001001;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll memo[100000];
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/

int main(){
    char A,B;
    cin >> A >> B;
    if(A == 'H' && B == 'H' ||( A == 'D' && B == 'D'))cout << "H" << endl;
    else cout << "D" << endl;
}

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

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for ( ll i = 2; i <= n; ++i ) {
            if ( f[i] ) continue;
            primes.push_back(i);
            f[i] = i;
            for ( ll j = i * i; j <= n; j += i ) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) {return f[x] == x;}
    vector<int> factorList(int x) {
        vector<int> res;
        while(x != -1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<pair<int, int>> factor(int x) {
        vector<int> fl = factorList(x);
        if ( fl.size() == 0 ) return {};
        vector<pair<int, int>> res(1, make_pair(fl[0], 0));
        for ( int p : fl ) {
            if ( res.back().first == p ) {
                res.back().second++;
            }
            else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

ll pow ( ll a, ll n ) {
    ll ans = 1;
    while(1) {
        if ( n == 0 ) break;
        if ( n&1 ) ans = ans * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ans;
}

ll inv ( ll a ) {
    return pow(a, mod-2);
}

int main(){
    Sieve sieve(1e6);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    map<int, int> mp;
    rep(i, n) {
        auto f = sieve.factor(a[i]);
        for ( auto p : f) {
            mp[p.first] = max(mp[p.first], p.second);
        }
    }

    ll lcm = 1;
    for ( auto p : mp ) {
        rep(i, p.second) {
            lcm = lcm * p.first % mod;
        }
    }

    ll ans = 0;
    rep(i, n) {
        ll b = lcm * inv(a[i]) % mod;
        ans = ( ans + b ) % mod;
    }
    cout << -ans << endl;
    return 0;
}


Measured memory_bytes: 4984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v[100005],w[100005];
ll dp[100001][101];
ll recur(ll wt,ll i)
{
	if(dp[wt][i]!=-1)
		return dp[wt][i];
	if(i==0)
		return 0;
	if(wt==0)
		return 0;
	ll maxi=-1;
	if(wt-w[i]>=0)
	{
		maxi=v[i]+recur(wt-w[i],i-1);
	}
	maxi=max(maxi,recur(wt,i-1));
	dp[wt][i]=maxi;
	//cout<<wt<<" "<<i<<" "<<maxi<<endl;
	return maxi;
}
int main()
{
	for(ll i=0;i<100001;i++)
	{
		for(ll j=0;j<101;j++)
		{
			dp[i][j]=-1;
		}
	}
	ll n,wt;
	cin>>n>>wt;
	for(ll i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
	}
	cout<<recur(wt,n);	
}


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

if c < b:
    tmp = c
    c = b
    b = tmp
else:
    pass

if b < a:
    mtp = b
    b = a
    a = mtp
else:
    pass

if c < b:
    tmp = c
    c = b
    b = tmp
else:
    pass

print(a, b, c)


Measured memory_bytes: 5596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int A = Integer.parseInt(arr[1]) - 1;
        int B = Integer.parseInt(arr[2]) - 1;
        int C = Integer.parseInt(arr[3]) - 1;
        int D = Integer.parseInt(arr[4]) - 1;
        String S = br.readLine();
        String ans = "Yes";
        String reg1 = "#{2}";
        String reg2 = "\\.{3}";
        Pattern p1 = Pattern.compile(reg1);
        Pattern p2 = Pattern.compile(reg2);

        if (C < D) {
            String routeA = S.substring(A + 1, C);
            String routeB = S.substring(B + 1, D);
            Matcher ma = p1.matcher(routeA);
            Matcher mb = p1.matcher(routeB);
            if (ma.find() || mb.find()) {
                ans = "No";
            } 
        } else {
            int pStart = 0;
            int pEnd = D + 2;
            if (B - A == 1) {
                pStart = A;
            } else {
                pStart = B - 1;
            }
            String routeA = S.substring(A + 1, C);
            String routeB = S.substring(B + 1, D);
            String routeAPrime = S.substring(pStart, pEnd);
            Matcher ma = p1.matcher(routeA);
            Matcher mb = p1.matcher(routeB);
            Matcher maPrime = p2.matcher(routeAPrime);
            if (ma.find() || mb.find() || !maPrime.find() ) {
                ans = "No";
            } 
         }

        out.println(ans);
        out.close();
    }
}


Measured memory_bytes: 25656
N, M, Q = map(int, raw_input().split())
L = []
R = []
for i in range(M):
	_l, _r = map(int, raw_input().split())
	L.append(_l)
	R.append(_r)

p = []
q = []
for i in range(Q):
	_p, _q = map(int, raw_input().split())
	p.append(_p)
	q.append(_q)


start_end_mat = [[0] * (N + 1) for i in range(N + 1)]

for i in range(M):
	start_end_mat[L[i]][R[i]] += 1

for i in range(1, N + 1):
	for j in range(1, N + 1):
		start_end_mat[i][j] += start_end_mat[i-1][j]
		start_end_mat[i][j] += start_end_mat[i][j-1]
		start_end_mat[i][j] -= start_end_mat[i-1][j-1]

for i in range(Q):
	res = start_end_mat[N][q[i]]
	res -= start_end_mat[p[i] - 1][q[i]]
	print(res)



Measured memory_bytes: 26128
//url:https://atcoder.jp/contests/abc054/tasks/abc054_c
//problem name:C - One-stroke Path

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

void print_vec(vector<int> vec) {
    cout << "{";
    for(auto s: vec) cout << s << " ";
    cout << "}" << endl;
}

int main() {
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N,vector<int>());
    vector<int> num(N);

    for(int i = 0; i < N; i++) num.at(i) = i; 

    rep(i,M) {
        int a,b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
        G.at(b-1).push_back(a-1);
    }

    int ans = 0;

    do {
        if(num.at(0) != 0) break;
        //print_vec(num);
        bool ok = true;
        for(int i = 0; i < N-1;i++) {
            vector<int> g = G.at(num[i]);
            if(count(g.begin(),g.end(),num[i+1]) == 0) ok = false;
        }
        if(ok) ans++;
    } while(next_permutation(num.begin(),num.end()));

    cout << ans << endl;


}


Measured memory_bytes: 3640
//In the Name of ̲A̲l̲l̲a̲h̲
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define sz size()
#define ull unsigned long long
#define ll long long
#define err(x) cout << #x << " " << x << endl

using namespace std;

ll n, m, t, a[10101], ans[111][111];
vector < ll > c;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> t;
	for (int i = 0; i < t; i++)
    {
        cin >> a[i];
        for (int j = 0; j < a[i]; j++)
        {
            c.pb(i+1);
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; i+=2)
    {
        for (int j = 0; j < m; j++)
        {
            ans[i][j] = c[cnt];
            cnt++;
        }
        if (i+1 < n)
            for (int j = m-1; j >= 0; j--)
            {
                ans[i+1][j] = c[cnt];
                cnt++;
            }
    }
    for (int i = 0; i < n; i ++)
    {
        for (int j = 0; j < m; j++)
        {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}




Measured memory_bytes: 640
"""B."""

import sys

input = sys.stdin.readline  # noqa: A001

S = input()[:-1]
T = input()[:-1]

S_L = len(S)
T_L = len(T)
ans = T_L

for i in range(S_L - T_L + 1):
    S_2 = S[i:i + T_L]
    match = 0
    for v1, v2 in zip(S_2, T):
        match += bool(v1 != v2)
    ans = min(ans, match)

print(ans)

exit(0)

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

using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define all(n) n.begin(),n.end()



signed main(){
	int n;
	cin>>n;
	int ans=0;
	lp(i,n-1){
		ans+=i+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=1e6+5;
const ll M=16;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
int main()
{
    ld n;
    cin>>n;
    ld sum=0;
    for(ll i=0;i<n;i++)
    {
        ld a;
        cin>>a;
        sum+=(1/a);
    }
    sum=(1/sum);
    cout<<fixed<<setprecision(9)<<sum<<endl;
}

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

#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
vector<int>lk[N];
int sg[N];

void dfs(int x,int fr)
{
	for(auto y:lk[x])
	if(y!=fr)
	{
		dfs(y,x);
		sg[x]^=sg[y]+1;
	}
}

int main()
{
	//freopen("1.in","r",stdin);
	int n;
	cin>>n;
	rep(i,1,n-1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		lk[x].push_back(y);
		lk[y].push_back(x);
	}
	dfs(1,0);
	puts(sg[1]?"Alice":"Bob");
}

Measured memory_bytes: 12416
//2019.11.09  参考元:new18さんのコード
//https://atcoder.jp/contests/nikkei2019-qual/submissions/6771098

import java.util.*;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        //N頂点
		int n=sc.nextInt();
        //m本の有向辺を追加
		int m=sc.nextInt();
        //有向辺をいくつ受けているかをカウントする配列
		int[] dg=new int[n];
		ArrayList<Integer>[] list=new ArrayList[n];
		for(int i=0; i<n; i++){
        	//リストの中にリストを作成（2次元）
            //なお、データ型は省略し<>となっている
			list[i]=new ArrayList<>();
		}
		for(int i=0; i<n+m-1; i++){
			int a =sc.nextInt()-1;
			int b =sc.nextInt()-1;
            
			dg[b]++;
            //最終的には
            //dg[0] = 0
            //dg[1] = 1
            //dg[2] = 2 となっている
			list[a].add(b);
            //list[a]は頂点番号aからどこへ向かってるかを格納する配列
            //今回は、
            //list[0] = 1, 2
            //list[1] = 2
            //list[2] = NULL
		}
		int root=0;
		for(int i=0; i<n; i++){
			if(dg[i]==0){
				root=i;
				break;
			}
		}
        
		int[] ans=new int[n];
      	//ちょっとした注意点：
        //newで宣言した時点で、配列の各要素は全て0が格納されている。
        //よって現段階では ans[0] = ans[1] = ans[2] = 0
        
        //双方向結合リストの作成
		LinkedList<Integer> que=new LinkedList<>();
        //リストの一番最初に根を持ってくる
		que.add(root);
      	//この時点でque = [0]
        
        //全ての頂点を調べ上げるまで無限ループ
		while(!que.isEmpty()){
        
        //.poll()はキューの先頭を取得し、削除するメソッド
			int g=que.poll();
            
            //最初にgに入るのは根となる頂点
            //今回はg=0(頂点1)からスタート
            
            //[[拡張for文]]　for (データ型 変数名: コレクション)
            //iにlist[g]の値を代入する
			for(int i:list[g]){
              // 1週目：g = 0
              // i はlist[0]から1を獲得。dg[1]は1 → 0
              // dg[1] = 0となるため、if文に入りans[1] = 0+1 = 1
              // queにiが追加され、que = [1]
              // 2週目：
              // i はlist[0]から2を取得。dg[2]は2 → 1
              // dg[2] = 1 なので、if文には入らない。
              //
              // ここで、list[0]の要素であるi=1,2のチェックが終了したため、for文から出る
              
              //queは空ではないため、再びwhile文を回す。
              //que.pollより、 g = 1
              //1週目：g = 1
              //iはlist[1]から2を取得。dg[2]は1 → 0
              //dg[2] = 0となるため、if文に入りans[2] = 1+1 = 2
              //queにiが追加され、que = [2]
              //
              //ここで、list[1]の要素であるi=2のチェックが終了したため、for文から出る
              
              //queは空ではないため、再びwhile文を回す。
              //que.pollより、 g = 2
              //list[2]はNULLのため、for文内の処理は無視されてforループを出る
              //queが空なので、while文も出る
				dg[i]--;
				if(dg[i]==0){
					ans[i]=g+1;
					que.add(i);
				}
                
			}
		}
		for(int i=0; i<n; i++){
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 106760
n = int(input())
s = list(map(int, input().split()))
count = 0
dic = {}
cl = []
sm = 0
for i in range(n):
  sm+=s[i]
  if sm not in dic.keys():
    dic.update({sm:1})
  else:
    dic[sm]+=1

        
for x in dic.keys():
  t = dic[x]
  if x==0:
    count+=dic[x]
  count+=int(t*(t-1)/2)

print(count)

Measured memory_bytes: 38644
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a == 5 && b == 7 && c == 5){
			System.out.println("YES");
		}
		else if(a == 5 && b == 5 && c == 7){
			System.out.println("YES");
		}
		else if(a == 7 && b == 5 && c == 5){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 8788
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A[100007],B[10007],C,D,E,F,K,G,H,L,M,N,P,Q,R,W,X,Y,Z;
string S,T;
ll dp[1007][10007];

int main(){
  cin >> M >> N;
  rep(i,N){
    cin >> X >> S;
    if(A[X]<=0){
      if(S[0]=='A'){
        C-=A[X];
        D++;
        A[X]=1;
      }
      else{
        A[X]--;
      }
    }
  }
  cout << D << " " << C <<  endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    int w, h, n;
    int m[105][105] = {0};
    cin >> w >> h >> n;
    rep(i,n){
        int x, y, a;
        cin >> x >> y >> a;
        switch (a) {
            case 1:
                rep(i,h) rep(j,x) m[i][j] = 1;
                break;
            case 2:
                rep(i,h) range(j,x,w) m[i][j] = 1;
                break;
            case 3:
                rep(i,y) rep(j,w) m[i][j] = 1;
                break;
            case 4:
                range(i,y,w) rep(j,w) m[i][j] = 1;
                break;
        }
        //show(n) rep(i,h){ rep(j,w){ cout << m[i][j]; } cout << endl; }
    }
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(m[i][j] == 0) ans++;
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N, K; cin >> N >> K;
    cout << (N + K - 1) / K - N / K << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
const int N = 1005;
int n, X[N], Y[N], len[50];
char ans[50];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int Abs(int x) {return x >= 0 ? x : - x;}
signed main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i ++) X[i] = read(), Y[i] = read();
	int tmp = Abs(X[1] + Y[1]) & 1;
	for(int i = 1; i <= n; i ++) if((Abs(X[i] + Y[i]) & 1) != tmp) {puts("-1"); return 0;}
	printf("%lld\n", 32 - tmp); int N = 1; len[1] = 1;
	if(tmp) for(int i = 1; i <= 30; i ++) len[++ N] = (1 << i);
	else for(int i = 0; i <= 30; i ++) len[++ N] = (1 << i);
	for(int i = 1; i <= 32 - tmp; i ++) printf("%lld ", len[i]); puts("");
	for(int i = 1; i <= n; i ++)
	{
		int nx = 0, ny = 0;
		for(int j = N; j >= 1; j --)
		{
			int x = X[i] - nx, y = Y[i] - ny;
			if(Abs(x) > Abs(y))
			{
				if(x > 0) nx += len[j], ans[j] = 'R';
				else nx -= len[j], ans[j] = 'L';
			}
			else
			{
				if(y > 0) ny += len[j], ans[j] = 'U';
				else ny -= len[j], ans[j] = 'D';
			}
		}
		printf("%s\n", ans + 1);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		str = br.readLine().split(" ");
		int k = Integer.parseInt(str[0]);
		int[] c = new int[k];
		int[] d = new int[k];
		for(int i = 0; i < k; i++){
			int b = Integer.parseInt(str[i + 1]);
			int pow2 = 1;
			for(int j = 0; j < b; j++) pow2 *= 2;
			c[i] = pow2;
			d[i] = b;
		}
		for(int i = 0; i < (1 << k); i++){
			int sum = 0;
			ArrayList<Integer> a = new ArrayList<Integer>();
			for(int j = 0; j < k; j++){
				if((i & (1 << j)) != 0){
					sum += c[j];
					a.add(d[j]);
				}
			}
			pw.print(sum + ":");
			if(i > 0) pw.print(" ");
			for(int j = 0; j < a.size(); j++){
				pw.print(a.get(j));
				if(j != a.size() - 1) pw.print(" ");
			}
			pw.print("\n");
		}
		pw.close();
	}
}



Measured memory_bytes: 62464
package main

import (
        "bufio"
        "fmt"
        "os"
)

func solution(n, t int, ts []int) int {
        var sum int = 0
        for i := 1; i < n; i++ {
                d := ts[i] - ts[i-1]
                if d >= t {
                        sum += t
                } else {
                        sum += d
                }
        }
        return sum + t
}

func main() {
        r := bufio.NewReader(os.Stdin)
        var n, t int
        fmt.Fscan(r, &n, &t)
        ts := make([]int, n)
        for i := range ts {
                fmt.Fscan(r, &ts[i])
        }
        fmt.Println(solution(n, t, ts))
}

Measured memory_bytes: 5928
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(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: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x; cin >> n >> x;
    vector<int> L(n + 1);
    for(int i = 1; i <= n; i++) cin >> L[i];
    vector<int> D;
    D.push_back(0);
    for(int i = 1; i <= n; i++)
    {
        D.push_back(D.back() + L[i]);
    }
    int ans = 0;
    for(int i = 0; i < D.size(); i++)
    {
        if(D[i] > x) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import re
import numpy as np

np.seterr(over='raise')

N, M = [int(item) for item in re.split(r"\s", input())]

AB = []
for _ in range(N):
    AB.append([int(item) for item in re.split(r"\s", input())])

AB = np.array(AB)
A = AB[:, 0]
B = AB[:, 1]


sorted_B = B[np.argsort(A)]
sorted_A = np.sort(A)


cumB = np.cumsum(sorted_B)
index = np.argmax(cumB > M)

if N > 1 and index > 0:
    total = np.sum(sorted_A[:index] * sorted_B[:index])
    total = total + (M - cumB[index - 1]) * sorted_A[index]
else:
    total = M * sorted_A[0]

print(total)


Measured memory_bytes: 31668
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[4],maxn;
int main()
{
	cin>>a[1]>>a[2]>>a[3];
	for (int i=1;i<=3;i++)
	    if (maxn<a[i])
			maxn=a[i];
	cout<<a[1]+a[2]+a[3]+9*maxn<<endl;
//	system("pause");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)




int main(){
    int n; cin>>n;
    vector<ll> x(n), y(n);
    rep(i,n) cin>>x[i]>>y[i];
    vector<ll> p(n);
    rep(i,n){
        p[i]=y[i]-x[i];
    }
    sort(etob(p));
    ll ans=p[0]-p[n-1];
    rep(i,n){
        p[i]=x[i]+y[i];
    }
    sort(etob(p));
    ans=max(ans, p[0]-p[n-1]);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main(){
  string st;
  int n,m,sum,k,kk;
  while(1){
    cin>>n;
    if(n==0)break;
    cin>>m;
    cin>>st;
    sum=0;
    k=1;
    kk=0;

    for(int i=0;i<st.size();i++){

      if(k==1&&st[i]=='O'&&st[i+1]=='I'){
	kk++;
	i++;
      }
      
      else if(st[i]=='I'){
	k=1;
	kk=0;
      }
      else if(st[i]=='O'){
	k=0;
	kk=0;
      }

      if(kk>=n)sum++;
      
    }
    cout<<sum<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3884