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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

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

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 1005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}
map<string,int> m;
string s;
void solve()
{
	int sz = 7;
	for ( int i = 0; i <= sz; i++)
	{
		//vector<char> v;
		string p = "";
		int num = s[0] -'0';
		p += s[0];
		int k = 1;
		for ( int j = 0; j < 3; j ++)
		{
			if ( i & (1<<j))
			{
				p += '-';
				p += s[k];
				num -= (s[k++] - '0');
			}
			else
				{
					p += '+';
					p += s[k];
					num += (s[k++] -'0');
				}
		}
		//cout << num << endl;
		p += '=';
		p += '7';
		if ( num == 7)
			m[p] = true;

	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	cin >> s;
	solve();
	for ( auto it: m)
	{
		if ( it.se == true)
		{
			cout << it.fi << endl;
			return 0;
		}
	}
	return 0;
}


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

int main(){
	int n, h[11][11];
	while(scanf("%d", &n)){
		if(!n)break;
		for(int i = 0;i < n;i++){
			int num = 0;
			for(int j = 0;j < n;j++){
				scanf("%d", &h[i][j]);
				num += h[i][j];
				printf("%5d", h[i][j]);
			}
			h[i][n] = num;
			printf("%5d\n", num);
		}
		
		for(int i = 0;i <= n;i++){
			int num = 0;
			for(int j = 0;j < n;j++)num += h[j][i];
			printf("%5d", num);
		}
		printf("\n");
	}
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sol() {
  int x;
  cin >> x;
  int a = x / 500;
  x %= 500;
  int b = x / 5;
  x %= 5;
  int ans = a*1000 + b*5;
  cout << ans;
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A_list = list(map(int, input().split()))
A_list.sort()

BC_list = [list(map(int, input().split())) for _ in range(M)]
BC_list = sorted(BC_list, key=lambda x: x[1])

ans = 0
count = 0
i = N-1
m = M-1
while count < N:
    if A_list[i] < BC_list[m][1]:
        for _ in range(BC_list[m][0]):
            ans += BC_list[m][1]
            count += 1
            if count >= N:
                break
        m -= 1
    else:
        ans += A_list[i]
        count += 1
        i -= 1

    if m < 0:
        break

for _ in range(count, N):
    ans += A_list[i]
    i -= 1

print(ans)


Measured memory_bytes: 33732
from collections import deque
s = deque(input())
q = int(input())
f = False
# Falseだと左が先頭
for _ in range(q):
    t = input().split()
    if t[0]=="1":
        f = not f
    elif t[0]=="2":
        t[2]=list(t[2])
        if f:
            t[2]=t[2][::-1]
            if t[1]=="1":
                s.extend(t[2])
            elif t[1]=="2":
                s.extendleft(t[2])
        else:
            if t[1]=="1":
                s.extendleft(t[2])
            elif t[1]=="2":
                s.extend(t[2])
if f:
    print("".join(s)[::-1])
else:
    print("".join(s))

Measured memory_bytes: 8436
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> h(n), a(m), b(m);
	rep(i,n) cin >> h[i];
	rep(i,m){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}


	vector<bool> flag(n,true);
	rep(i,m){
		if(h[a[i]] > h[b[i]]){
			flag[b[i]] = false;
		}else if(h[a[i]] < h[b[i]]){
			flag[a[i]] = false;
		}else{ // a[i] == b[i]
			flag[a[i]] = false;
			flag[b[i]] = false;
		}
	}
	
	int count = 0;
	rep(i,n){
		if(flag[i] == true) count++;
	}
	cout << count;
	

}


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


def main():
    N = int(input())
    A = [[0 for i in range(10)] for j in range(10)]
    for i in range(1, N+1):
        s = str(i)
        A[int(s[0])][int(s[-1])] += 1
    ans = 0
#    [print(a) for a in A]
    for a in range(1, 10):
        for b in range(1, 10):
            ans += A[a][b] * A[b][a]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#define ll long long
using namespace std;



int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s==u){
        a=a-1;
    }
    else{
        b=b-1;
    }
    cout << a << endl;
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    char[] s;

    void solve() {
        s = in.next().toCharArray();
        long res = 0;
        int cntAs = 0;
        for (int i = 0; i < s.length; ) {
            if (s[i] == 'A') {
                cntAs++;
                i++;
            } else {
                if (s[i] == 'C'){
                    cntAs = 0;
                    i++;
                } else {
                    if (i + 1 < s.length && s[i + 1] == 'C') {
                        res += cntAs;
                        i += 2;
                    } else {
                        cntAs = 0;
                        i++;
                    }
                }
            }
        }
        out.println(res);
    }

    void run() {
        try {
            in = new FastScanner(new File("MainC.in"));
            out = new PrintWriter(new File("MainC.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 25704
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;

#define LL long long
#define RG register int
template<typename elemType>
inline void Read(elemType &T){
    elemType X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    T=(w?-X:X);
}

map<int,int> Num;
int Data[200010];
int N;

bool Judge(int x){
    Num.clear();
    for(RG i=2;i<=N;++i){
        if(Data[i]<=Data[i-1]){
            while(!Num.empty()){
                int temp=Num.rbegin()->first;
                if(temp>Data[i]) Num.erase(temp); 
                else break;
            }
            int j=Data[i];
            while(Num[j]+1==x) {Num.erase(j);--j;}
            if(j==0) return false;
            ++Num[j];
        }
    }
    return true;
}

int Solve(){
    int L=2,R=N,Res=-1;
    while(L<=R){
        int mid=(L+R)>>1;
        if(Judge(mid)){Res=mid;R=mid-1;}
        else L=mid+1;
    }
    return Res;
}

int main(){
    Read(N);
    bool flag=true,flagB=true;
    for(RG i=1;i<=N;++i){
        Read(Data[i]);
        if(Data[i]!=1) flag=false;
        if(Data[i]<=Data[i-1]) flagB=false;
    }
    if(flagB){printf("1\n");return 0;}
    if(flag){printf("%d\n",N);return 0;}
    printf("%d\n",Solve());
    return 0;
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(M), Y(M);
    vector<vector<int>> PN(N);
    for (int i = 0; i < M; i++) {
        cin >> P[i] >> Y[i];
        PN[P[i] - 1].push_back(Y[i]);
    }

    for (auto& pn : PN)
        sort(pn.begin(), pn.end());
    for (int i = 0; i < M; i++) {
        auto itr = lower_bound(PN[P[i] - 1].begin(), PN[P[i] - 1].end(), Y[i]);

        printf("%06d%06d\n", P[i], 1 + distance(PN[P[i] - 1].begin(), itr));
    }


    return 0;
}

Measured memory_bytes: 7808
n,m,x = map(int,input().split())

c = []
a = []
for i in range(n):
    t = list(map(int,input().split()))
    c.append(t[0])
    a.append(t[1:])

result = -1
for i in range(1 << n):
    t = [0] * m
    cost = 0
    for j in range(n):
        if(i >> j) & 1 == 0:
            continue
        cost += c[j]
        for k in range(m):
            t[k] += a[j][k]
    if all(X >= x for X in t):
        if result == -1:
            result = cost
        else:
            result = min(result, cost)
            
print(result)            

Measured memory_bytes: 9140
# -*- coding: utf-8 -*-

import sys

N, A, B = map(int, input().split(' '))

if N < 2 and A < B:
    print(0)
    sys.exit()

if B < A:
    print(0)
    sys.exit()

c = B - A

print(B * N - c - (A * N + c) + 1)


Measured memory_bytes: 3316
import sys
import math
import numpy as np
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


inf = float("inf")
mod = 10 ** 9 + 7

a, b, h, m = MI()

hc = 30 * h + 0.5 * m
mc = 6 * m

d = abs(hc - mc)
if d >= 180:
    d = 360 - d


print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(d))))


Measured memory_bytes: 27220
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long ans[90];
    ans[0]=2;ans[1]=1;
    for(int i=2;i<87;i++){
        ans[i]=ans[i-1]+ans[i-2];
    }
    cout<<ans[n]<<endl;
    return 0;
}


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

using namespace std;

const int maxn = 20;

int main(void)
{
	int n, d;
	scanf("%d %d", &n, &d);

	if (n%(2*d+1) == 0) printf("%d\n", n/(2*d+1));
	else printf("%d\n", n/(2*d+1)+1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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

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

  ll cnt = 0;
  REP(i,N-2){
    FOR(j,i+1,N-1){
      FOR(k,j+1,N){
        if(A[k]<A[i]+A[j]&&abs(A[i]-A[j])<A[k]){
          cnt++;
        }else if(A[k]>=A[i]+A[j]){
          break;
        }
      }
    }
  }

  cout << cnt << endl;
}

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

using namespace std;

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

    vector<int> L(N);
    for(int i=0; i<N; i++) cin >> L.at(i);

    sort(L.begin(),L.end(),greater<int>());

    int ans=0;
    for(int j=0;j<K;j++){
        ans = ans + L.at(j);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  ll a, b, c, k; cin >> a >> b >> c >> k;
  ll ans = 0;
  ans += min(a, k);
  k -= min(a, k);
  k -= min(b, k);
  ans -= min(c, k);
  cout << ans << endl;

}
























Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

ll N,a,ans=0;
multiset<ll> st = {0,0};

int main(){
    cin>>N;
    st.insert(N+1);
    st.insert(N+1);
    ll A[N+1];
    rep(i,N){
        cin>>a;
        A[a]=i+1;
    }
    for(int i=N;i>0;i--){
        multiset<ll>::iterator w,x,y,z;
        y=st.upper_bound(A[i]);
        z=next(y);
        x=prev(y);
        w=prev(x);
        // cout<<*w<<" "<<*x<<" "<<*y<<" "<<*z<<endl;
        ans+=i*((*x-*w)*(*y-A[i])+(A[i]-*x)*(*z-*y));
        st.insert(A[i]);
    }
    out(ans);

    
}


Measured memory_bytes: 5760
n = int(input())
a = list(map(int,input().split()))

l = [0] * 9
p = 0
for i in range(0,n):
    q = a[i] // 400
    if q < 8:
        l[q] = 1
    else:
        l[8] = 1
        p = p + 1

s = sum(l[0:8])
m = max(s,l[8])
M = s+p
print(m,M)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef struct{//辺
    int a;//始点終点
    int b;
    int color;//色
}Edge;
typedef struct{//節点
    int num;
    int color;
}Node;
int main(void){
    Edge e[1000010];
    int N; cin >> N;
    vector <vector<int> > map(N+1);//節点に接続している辺
    for(int i=1;i<N;i++){
        cin >> e[i].a >> e[i].b;
        map[e[i].a].push_back(i);
        map[e[i].b].push_back(i);
    }
    e[1].color = 1;
    queue<Node> q;
    q.push((Node){e[1].a,1}), q.push((Node){e[1].b,1});
    int K = 0;
    while(!q.empty()){
        int x = q.front().num; int c = q.front().color; q.pop();
        if(K<map[x].size()) K = map[x].size();
        int clr = 1;
        for(int i=0;i<map[x].size();i++){
            if(e[map[x][i]].color == 0){
                if(c==clr) clr++;
                e[map[x][i]].color = clr++;
                if(e[map[x][i]].a == x)
                    q.push((Node){e[map[x][i]].b,clr-1});
                else
                    q.push((Node){e[map[x][i]].a,clr-1});
            }
        }
    }
    cout << K << endl;
    for(int i=1;i<N;i++) cout << e[i].color << endl;
    
}


Measured memory_bytes: 8832
N,P = map(int,input().split())
S = map(int,input())
S_li = [0]*(N+1)
S_rev = reversed(tuple(S))

tmp = 0
count= 0
from  collections import Counter

if 10%P==0:
    counter = 0
    for i,num in enumerate(S_rev):
        if num%P==0:
            counter += N-i
    print(counter)

else:
    ctr = [0] * P
    ctr[0] = 1
    ret = 0
    t = 0
    c = 1
    for x in S_rev:
        t = (t + c * x) % P
        ret += ctr[t]
        ctr[t] += 1
        c = c * 10 % P
 
    print(ret)


Measured memory_bytes: 54592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll X = in<ll>(),Y = in<ll>();
    int count = 1;
    while(1){
        if(X * 2 <= Y){
            X*=2;
            count++;
        }else{
            break;
        }
    }
    cout << count << "\n";
}

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

int main() {
    int N, M;
    cin >> N >> M;
    if (N == M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
N=int(input())
def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = num**(0.5)

    for serial in range(3, num, 2):
        if serial >= sqrt:
            return input_list
        for s in range(serial ** 2, num, serial):
            input_list[s] = False

list=sieve_of_erastosthenes(max(N+1,6))
ans=1
for i in range(N+1):
    if list[i]:
        tmp=0
        M=N
        for t in range(1,10):
            if M//(i**t)==0:    break
            tmp+=M//(i**t)
        ans*=tmp+1
print(ans%(10**9+7))


Measured memory_bytes: 3064
/*input
5
1 10
3 6
5 2
4 4
2 8
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define YY cout<<"YES\n"
#define NN cout<<"NO\n"
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
pll v[maxn];
int main()
{
	IOS;
	ll n;
	cin>>n;
	REP(i,n) cin>>v[i].F>>v[i].S;
	sort(v,v+n);
	ll ans=n;
	REP(i,n-1){
		ans+=min(abs(v[i].F-v[i+1].F),abs(v[i].S-v[i+1].S))-1;
	}
	ans+=v[0].F-1;
	ans+=v[n-1].S;
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200)
    cout << s << endl;
  else
    cout << "red" << endl;
  return 0;
}

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

int main()
{
    ll n;
    string st;
    cin>>n>>st;

    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        if(st[i]!=st[i-1])
            cnt++;
    }

    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // Tenka1 Programmer Beginner Contest 2019 C - Stones
  // 白→黒、黒→白、何も変えなくても条件を満たす
  // 境目の配列を準備して、右側にある黒、左側にある白をカウントしていく
  // （変えなくてはいけない個数を把握するため）
  // そのあと、境目を左から順に見ていき、最小値を更新する
  int N; cin >> N;
  string S; cin >> S;
  
  vector<int> leftB(N+1, 0); // 境目の配列（左側にある黒）
  vector<int> rightW(N+1, 0); // 境目の配列（右側にある白）
  for(int i = 1; i < N+1; i++){
    if(S[i-1] == '#'){ // 左側にあるのが黒なら
      leftB[i] = leftB[i-1] + 1;
    }else{ // 白なら1を足さない
      leftB[i] = leftB[i-1];
    }
    if(S[N-i] == '.'){ //右側にあるのが白なら
      rightW[N-i] = rightW[N+1-i] + 1;
    }else{
      rightW[N-i] = rightW[N+1-i];
    }
  }
  
  int ans = 1e9;
  REP(i, N+1){  
    ans = min(ans, leftB[i]+rightW[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2196
n = int(input())
s = [input() for _ in range(n)]
s.sort()

a = ""
tt = [[],[]]
for i in s:
    if a != i:
        a = i
        tt[0] += [i]
        tt[1] += [1]
    else:
        tt[1][-1] += 1
t = tt
m = max(t[1])
ans = []
for i in range(len(t[1])):
    if t[1][i] == m:
        ans += [t[0][i]]

for i in range(len(ans)): print(ans[i])

Measured memory_bytes: 91048
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#define YOHAKU 1
#define VA 1000000007
long long fac[1001][1001];
long long ans[1001][1001];
long long prime[1001];





int main(){
long long index = 0, sum = 1;
int N;
prime[0] = 2;

	for(int i = 3; i < 1001; i++){
      
		for(int j = 0; j < index+1; j++){

			if(i % prime[j] == 0)
				break;


			if(j == index){
				prime[j+1] = i;
				index++;
			}

		}

	}


	for(int i = 1; i < 1001; i++){
	 for(int j = 0; prime[j] != 0; j++){
		
		 if(i % prime[j] == 0){
			 fac[i][prime[j]] = fac[i / prime[j]][prime[j]] + 1;
		 }

	 }
	}

	scanf("%d", &N);




	for(int i = 2; i <= N; i++){
      for(int j = 0; prime[j] != 0; j++){
		  ans[i][prime[j]] = (ans[i-1][prime[j]] + fac[i][prime[j]]) % VA;
	  }

	}

	
	for(int i = 0; prime[i] != 0; i++){
		sum = (sum * (ans[N][prime[i]] + 1)) % VA;
		
	}

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


	return 0;
}

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

using namespace std;

typedef long long LL;
const int MAXN=512;
LL dp[MAXN][MAXN],a[MAXN],sum[MAXN];
int n;

int main(){
	cin>>n;
	memset(dp,0x3f,sizeof(dp));
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i]+=a[i]+sum[i-1];
	}
	for(int i=1;i<=n;i++){
		dp[i][i]=0;
	}
	for(int len=2;len<=n;len++){
		for(int l=1;l<=n;l++){
			int r=l+len-1;
			if(r<=n){
				for(int k=l;k<r;k++){
					dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+sum[r]-sum[l-1]);
				}
			}
		}
	}
	cout<<dp[1][n]<<endl;
	return 0;
}


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

int main()
{
	string s;
	string buf;
	cin >> s;
	for (char c : s)
	{
		if (c == 'B')
		{
			if (!buf.empty())buf.pop_back();
		}
		else
		{
			buf.push_back(c);
		}
	}
	cout << buf << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 1010
#define maxp 4010
struct poi
{
	int x, y, r;
}p[maxn];
double a[maxn][maxn], d[maxn];
int last[maxn], next[maxn];
inline double dist(poi a, poi b)
{
	return sqrt((double) (a.x - b.x) * (a.x - b.x) + (double) (a.y - b.y) * (a.y - b.y));
}
int main()
{
//	setfile();
	R int xs = F(), ys = F(), xt = F(), yt = F();
	R int n = F() + 1;
	for (R int i = 2; i <= n; ++i) p[i] = (poi) {F(), F(), F()};
	p[1] = (poi) {xs, ys, 0};
	p[++n] = (poi) {xt, yt, 0};
	for (R int i = 1; i <= n; ++i)
	{
		a[i][i] = 0;
		for (R int j = i + 1; j <= n; ++j)
		{
			a[i][j] = dist(p[i], p[j]) - p[i].r - p[j].r;
			cmax(a[i][j], 0);
			a[j][i] = a[i][j];
		}
	}

	for (R int i = 1; i <= n; ++i) last[i] = i - 1, next[i] = i + 1;
	for (R int i = 1; i <= n; ++i) d[i] = a[1][i];

	for (R int i = 1; i < n; ++i)
	{
		R double minn = 1e18;
		R int node;
		for (R int j = next[1]; j <= n; j = next[j])
			minn > d[j] ? minn = d[j], node = j : 0;
		next[last[node]] = next[node];
		last[next[node]] = last[node];
		for (R int j = next[1]; j <= n; j = next[j])
			cmin(d[j], minn + a[node][j]);
	}
	printf("%.12lf\n", d[n] );
	return 0;
}


Measured memory_bytes: 8192
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    total = a[i] + a[i + 1]
    if total > x:
        a[i] -= max(0, total - x - a[i + 1])
        a[i + 1] = max(0, a[i + 1] - (total - x))
    ans += max(total - x, 0)
print(ans)

Measured memory_bytes: 14540
import Data.List

solver::[Int]->Int
solver ls = let l = length ls in
            case mod l 2 of
              0 -> let b = head (drop ((div l 2)-1) ls) in (sum.(map abs).(map (b-))) ls
              1 -> let b = head (drop (div l 2) ls)     in (sum.(map abs).(map (b-))) ls

preproc::[Int]->[Int]
preproc ls = sort (map (\(x,y)->(x-y)) (zip ls [1..]) )

main::IO()
main=do
  _<-getLine
  d<-getLine
  let dat= map read (words d)::[Int]
  (print.solver.preproc) dat


Measured memory_bytes: 91516
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, k, q;
    cin >> n >> k >> q;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = INF;
    rep(i, n){
        int l = 0, r = 0;
        vector<int> b;
        b.push_back(a[i]);

        while(l < n){
            if(a[l] < a[i]){
                l++;
                r = l;
                continue;
            }
            if(r < n && a[r] >= a[i]){
                r++;
                continue;
            }

            vector<int> c;
            for(int j = l; j < r; j++){
                if(j == i){
                    continue;
                }
                c.push_back(a[j]);
            }
            if((int)c.size() >= k){
                sort(c.begin(), c.end());
                for(int j = 0; j <= (int)c.size()-k; j++){
                    b.push_back(c[j]);
                }
            }
            l = r;
        }
        if(q > (int)b.size()){
            continue;
        }
        sort(b.begin(), b.end());
        int tmp = b[q-1] - b[0];
        if(tmp < ans){
            ans = tmp;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	printf("%lld",n-m+1);
}

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

int main() {
  string S, T;
  cin >> S >> T;
  T = T.substr(0, (int)T.size() - 1);
  if (S == T) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3576
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		try (Stream<String> lines = new BufferedReader(new InputStreamReader(System.in)).lines()) {
			new Main().exec(lines.toArray(String[]::new));
		}
	}

	HashSet[] nodes;

	int[] cntrs;

	void exec(String[] args) {
		String[] nq = args[0].split(" ");
		int n = Integer.parseInt(nq[0]);
		int q = Integer.parseInt(nq[1]);
		nodes = new HashSet[n + 1];
		cntrs = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			nodes[i] = new HashSet();
		}
		for (int i = 1; i < n; i++) {
			String[] pc = args[i].split(" ");
			int p = Integer.parseInt(pc[0]);
			int c = Integer.parseInt(pc[1]);
			nodes[p].add(c);
			nodes[c].add(p);
		}
		for (int i = n; i < n + q; i++) {
			String[] px = args[i].split(" ");
			int p = Integer.parseInt(px[0]);
			int x = Integer.parseInt(px[1]);
			cntrs[p] += x;
		}
		add(0, 1);
		System.out.println(
			IntStream.rangeClosed(1, n)
				.map(i -> cntrs[i])
				.mapToObj(String::valueOf)
				.collect(Collectors.joining(" ")));
	}

	void add(int p, int n) {
		for (Object nc : nodes[n]) {
			int c = (int)nc;
			if (c != p) {
				cntrs[c] += cntrs[n];
				add(n, c);
			}
		}
	}

}


Measured memory_bytes: 203928
#include <algorithm>
#include <array>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define vint vector<int>
const int MAX = 2010000;
long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    ll X, Y;
    cin >> X >> Y;
    if ((2 * X - Y) % 3 != 0 || (2 * Y - X)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans_x = (2 * X - Y)/3;
    ll ans_y = (2 * Y - X)/3;
    COMinit();
    //cout << ans_x << " " << ans_y << endl;
    cout << COM(ans_x + ans_y, max(ans_x, ans_y)) << endl;
    return 0;
}

Measured memory_bytes: 47360
#include <iostream>
#include <vector>
using namespace std;
int main(){
    vector<int> v;
    int n;
    cin>>n;
    int a,b;
    while(n--){
        cin>>a;
        if(a==0){
            cin>>b;
            v.push_back(b);
        }
        else if(a==1){
            cin>>b;
            cout<<v[b]<<endl;
        }
        else{
            v.pop_back();
        }
    }
    return 0;
}


Measured memory_bytes: 3884
#include<iostream>
#include<vector>
#include<cinttypes>
#include<numeric>
#include<iomanip>

using ui32 = std::uint32_t;

using ld = long double;

int main() {

	ui32 n;
	std::cin >> n;



	std::vector<ld> data(n);
	for (auto&e : data)
		std::cin >> e;


	std::vector<std::vector<ld>> tab(n+1, std::vector<ld>(n+1, ld{}));

	tab[0][0] = ld{1};

	//Coin_iを追加で使ってみる
	for (ui32 i{1}; i <= n; ++i) {

		const auto pi = data[i - 1];
		auto& row = tab[i];
		tab[i][0] = tab[i - 1][0] * (1-pi);

		//ci個のコインが表になる確率
		for (ui32 ci{1}; ci <= i; ++ci)
			tab[i][ci] = tab[i-1][ci - 1] * pi + tab[i-1][ci] * (1 - pi);

	}
	
	/*
	for (const auto&e : tab) {
		for (const auto&ee : e)
			std::cout << ee << "\t";
		std::cout << "\n";
	}*/

	const auto required_coins = n / 2 + 1;

	const auto ans = std::accumulate(
		std::begin(tab.back()) + required_coins 
		, std::end(tab.back())
		,ld {}
/*		, [](auto init, auto v) {
			init += v;
			std::cout << init << "\n";
			return init;
		}*/
	);


	std::cout<< std::setprecision(32) << std::fixed;
	std::cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 141056
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 2020;
int n;
bitset<N>A[N],l[N],r[N],lt[N],rt[N],dp[N],dpt[N];
int main() {
	read(n);rep(i,2,n){
		char S[N];scanf("%s",S+1);
		rep(j,1,i-1){
			int x=S[j]=='1';A[i][j]=x;A[j][i]=x^1;
		}
	}
	per(i,n,1)rep(j,i,n){
		if(j==i){l[i][j]=r[i][j]=1;continue;}
		l[j][i]=(A[i]&r[i+1]&l[j]).count();
		r[i][j]=(A[j]&r[i]&l[j-1]).count();
	}
	/*rep(i,1,n){
		rep(j,1,n)printf("%d ",(int)A[i][j]);puts("");
	}
	rep(i,1,n){
		rep(j,1,n)printf("%d ",(int)l[i][j]);puts("");
	}*/
	int res=0;rep(i,1,n)res+=l[n][i]&r[1][i];
	cout<<res;return 0;
}


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


using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;
bool isPrime[MAXN];



ll fastPow(ll x, ll b)
{
    if (b == 0)
        return 1;
    else if (!(b & 1))
    {
        return fastPow(x * x, b / 2);
    }
    else
        return x * fastPow(x * x, (b - 1) / 2);
}

//__builtin_popcount ();
bool isPrim(int n)
{
    if (n == 1 || n == 0)
        return false;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}



int main()
{
    FAST
    string h;
    cin>>h;
    int sz=h.size();
    int arr[sz+1];
    ll ans=0;
    memset(arr,0,sizeof(arr));
    for(int i=0; i<sz; i++)
        if(h[i]=='<')
            arr[i+1]=max(arr[i+1],arr[i]+1);
    for(int i=sz; i>=0; i--)
        if(h[i]=='>')
            arr[i]=max(arr[i],arr[i+1]+1);
    for(int i=0; i<=sz; i++)
        ans+=arr[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2844
#include <stdio.h>
#include <string.h>
int main(){
    int n;
    int taro = 0;
    int hanako = 0;
    char str_t[101];
    char str_h[101];
    int i;
    int judge;
    scanf("%d", &n);
    for(i = 0;i < n; i++){
        scanf("%s %s", str_t, str_h);
        judge = strcmp(str_t, str_h);
        if(judge > 0) taro+=3;
        else if(judge < 0) hanako += 3;
        else {
            taro++;
            hanako++;
        }
    }
    printf("%d %d\n", taro, hanako);
 
    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int n;
void dfs(int l, int r, int mask, int c) {
  if (c == 1) {
    cout << l << " ";
    return;
  }
  int pos = -1;
  for (int i = 0; i < n; i++) {
    if (mask & (1 << i))continue;
    if((l&(1<<i))!=(r&(1<<i))){
      pos=i;
      break;
    }
  }
  int pos2 = -1;
  for(int i=0;i<n;i++){
    if (mask & (1 << i))continue;
    if(i==pos)continue;
    pos2=i;
  }
  dfs(l,l^(1<<pos2),mask|(1<<pos), c-1);
  cout<<(l^(1<<pos2))<<" ";
  dfs(l^((1<<pos2)|(1<<pos)), r, mask|(1<<pos), c-1);
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int l,r;
  cin>>n>>l>>r;
  int cx = 0, cy = 0;
  for(int i=0;i<n;i++){
    if(l&(1<<i))cx++;
    if(r&(1<<i))cy++;
  }
  if((cx&1)!=(cy&1)){
    cout<<"YES"<<endl;
    dfs(l,r,0,n);
    cout<<r<<endl;
  } else cout<<"NO"<<endl;
  return 0;
}

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

int main() {
	int N, K;
	double *p;
	p = new double[200000];
	cin >> N >> K;

	double total = 0;
	for (int i = 0; i < N; ++i) {
		int tmp;
		cin >> tmp;
		p[i] = (double)(1+tmp) / 2;
		if (i < K) total += p[i];
	}

	double maxTotal = total;
	for (int i = K; i < N; ++i) {
		total = total - p[i-K] + p[i];
		if (maxTotal < total) maxTotal = total;
	}

	printf("%10.10lf", maxTotal);

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int h,w,k,cnt,ans;
string s[6],t[6];
int main(void){
    cin>>h>>w>>k;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<(1<<h);i++){
        for(int j=0;j<(1<<w);j++){
            cnt=0;
            for(int ii=0;ii<h;ii++){
                t[ii]=s[ii];
            }
            
            for(int ii=0;ii<h;ii++){
                if(((i>>ii)&1)==1){
                    for(int jj=0;jj<w;jj++){
                        t[ii][jj]='.';
                    }
                }
            }
            
            for(int ii=0;ii<w;ii++){
                if(((j>>ii)&1)==1){
                    for(int jj=0;jj<h;jj++){
                        t[jj][ii]='.';
                    }
                }
            }
            
            for(int ii=0;ii<h;ii++){
                for(int jj=0;jj<w;jj++){
                    if(t[ii][jj]=='#'){
                        cnt++;
                    }
                }
            }
            //cout<<cnt<<endl;
            if(cnt==k)ans++;
            
        }
    }
    cout<<ans<<endl;
}


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

#define mod 1000000007
/*ll ebob(ll a, ll b){
	if(a == 0) return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a,b);
}*/
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	ll res = 1;
	vector<int> vec(n);
	forloop(n){
		cin>>vec[i];
	}
	int arr[n] = {};
	arr[0] = 3;
	for(auto x: vec){
		res = (res * arr[x]) % mod;
		arr[x]--;
		arr[x+1]++;
		
	}
	cout<<res;
	return 0; 
}

Measured memory_bytes: 1024
import sys

input = sys.stdin.readline


def main():
    s = input().strip()
    last = s[0]
    cnt = 1
    i = 1
    length = len(s)
    while i < length:
        if last == s[i]:
            if i == length - 1:
                break
            last = s[i: i + 2]
            i += 2
        else:
            last = s[i]
            i += 1
        cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3500
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
show_flg=True

def naive(b,k):
    a=b*k
    n=len(a)
    p=a[0]
    t=0
    for i in range(n-1):
        if p==a[i+1]:
            t+=1
            p=-1
        else:
            p=a[i+1]
            
    return t

b=StoI()
k=I()

if len(b)*k<10:
    print(naive(b,k))
    exit()

odd=naive(b,3)-naive(b,1)
even=naive(b,4)-naive(b,2)
if k%2==1:
    ans=naive(b,1)+(k//2)*odd
else:
    ans=naive(b,2)+(k//2)*even-even
print(ans)


Measured memory_bytes: 38768
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;
 
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}
 
int main() {
    int a[3] = {1,0,0};
    char c,d;
    map<char, int> m;
    m['A'] = 0;
    m['B'] = 1;
    m['C'] = 2;
    while(scanf("%c,%c\n", &c, &d) + 1) {
        swap(a[m[c]], a[m[d]]);
    }
 
    if(a[0]) cout << "A" << endl;
    else if(a[1]) cout << "B" << endl;
    else cout << "C" << endl;
    return 0;
}

Measured memory_bytes: 1196
from heapq import heappop,heappush,heapify

N, M = map(int, input().split())
A = list(map(int, input().split()))
A_minus = [-a for a in A]

heapify(A_minus)

for _ in range(M):
    heappush(A_minus, -((-heappop(A_minus)) // 2))
ans = -sum(A_minus)
print(int(ans))

Measured memory_bytes: 14184
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    s = gets.chomp

    'a'.upto('z') do |c|
      if s.index(c).nil?
        puts c
        return
      end
    end

    puts "None"
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
long long int v[101], w[101];

int main(){
      int n, W;
      cin>>n>>W;
      long long int sum=0;
      for(int i=0; i<n; i++)
            {cin>>w[i+1]>>v[i+1];sum+=v[i+1];}

      vector<vector<long long int>>dp(n+1, vector<long long int>(sum+1, INT_MAX));

      for(int i=0; i<=sum; i++)dp[0][i]=1e9;
      for(int i=0; i<=n; i++)dp[i][0]=0;
      int ans=0;

      for(int i=1; i<=n; i++)
      {
            for(int v1=1; v1<=sum; v1++){
                  dp[i][v1]=dp[i-1][v1];
                  if(v[i]<=v1)
                  dp[i][v1]=min(dp[i][v1], (dp[i-1][v1-v[i]]+w[i]));
                  //cout<<i<<' '<<v1<<' '<<dp[i][v1]<<'\n';
                  //if(dp[i][v1]<=W)ans=max(ans, v1);
            }
      }
      for(int i=1; i<=sum; i++){
            if(dp[n][i]<=W)
            ans=max(ans, i);
      }
      cout<<ans;
}

Measured memory_bytes: 83124
#include <bits/stdc++.h>
#define MP make_first
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 1005;

int n, m;
char mp[N][N];

struct node{
    int x, y, now;
};

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

bool ok(int x, int y) {
    return x >= 1 && x <= n && y >= 1 && y <= m && mp[x][y] == '.';
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    queue <node> q;
    for(int i = 1; i <= n; i++) {
        cin >> mp[i] + 1;
        for(int j = 1; j <= m; j++) {
            if(mp[i][j] == '#') q.push(node{i, j, 0});
        }
    }
    int ans = 0;
    while(!q.empty()) {
        node cur = q.front(); q.pop();
        int x = cur.x, y = cur.y;
        for(int i = 0; i < 4; i++) {
            int curx = x + dx[i], cury = y + dy[i];
            int now = cur.now;
            ans = now;
            if(ok(curx, cury)) {
                q.push(node{curx, cury, now + 1});
                mp[curx][cury] = '#';
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 13328
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

int main(){

	int a, b, n, ssr, ssc;
	int sl=0, sr=0, su=0, sd=0, tl=0, tr=0, tu=0, td=0;
	int l, r, u, d, x, y, flag=0;
	//vector< vector<int> > board;
	string s, t;

	cin>> a >> b >> n;
	cin>> ssr >> ssc;
	cin>> s;
	cin>> t;

	/*board.resize(a);
	for(int i=0;i<a;i++) board[i].resize(b);

	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			cin>> board[i][j];
		}
	}*/

	l=ssc-1;
	r=b-ssc;
	u=ssr-1;
	d=a-ssr;

	//cout<< l << " " << r << " " << u << " " << d << endl;

	for(int i=0;i<n;i++){
		if(s[i]=='L') sl++;
		if(s[i]=='R') sr++;
		if(s[i]=='U') su++;
		if(s[i]=='D') sd++;

		if(l<sl-tr){
			flag=1;
			//cout<< i << endl;
			break;
		}
		if(r<sr-tl){
			flag=1;
			//cout<< i << endl;
			break;
		}
		if(u<su-td){
			flag=1;
			//cout<< i << endl;
			break;
		}
		if(d<sd-tu){
			flag=1;
			//cout<< i << endl;
			break;
		}

		if(t[i]=='L' && tl+1-sr<=l) tl++;
		if(t[i]=='R' && tr+1-sl<=r) tr++;
		if(t[i]=='U' && tu+1-sd<=u) tu++;
		if(t[i]=='D' && td+1-su<=d) td++;

	}

	if(flag==1){
		cout<< "NO" << endl;
	}else{
		cout<< "YES" << endl;
	}

}

Measured memory_bytes: 776