akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<char, int>P;

int main() {
	int a, b, c;
	int cnt1 = 0, cnt2 = 0;
	while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
		if (a*a + b*b == c*c)cnt1++;
		if (a == b)cnt2++;
	}
	cout << cnt1 << endl << cnt2 << endl;
	return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	string s;
	cin>>s;
	cout<<s.substr(0,3);	
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
# DSL_3_B: The Smallest Window II


class Window:
    def __init__(self, k):
        self.k = k
        self.data = [0] * k
        self.zeros = set(range(k))

    def add(self, i):
        if self.data[i-1] == 0:
            self.zeros.remove(i-1)
        self.data[i-1] += 1

    def remove(self, i):
        if self.data[i-1] == 1:
            self.zeros.add(i-1)
        self.data[i-1] -= 1

    def removable(self, i):
        return self.data[i-1] > 1

    def open(self):
        return len(self.zeros) == 0


def run():
    n, k = [int(x) for x in input().split()]
    li = [int(x) for x in input().split()]
    w = Window(k)
    i = 0
    min_ = n+1
    for j, v in enumerate(li):
        if v <= k:
            w.add(v)
            while True:
                if li[i] > k:
                    pass
                elif w.removable(li[i]):
                    w.remove(li[i])
                else:
                    break
                i += 1
            if w.open():
                if min_ > j - i + 1:
                    min_ = j - i + 1

    if min_ > n:
        print(0)
    else:
        print(min_)


if __name__ == '__main__':
    run()



Measured memory_bytes: 20268
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;
 
int main() {
  string S;
  cin>>S;
  int ans=0;
  if(S=="SUN") ans=7;
  else if(S=="MON") ans=6;
  else if(S=="TUE") ans=5;
  else if(S=="WED") ans=4;
  else if(S=="THU") ans=3;
  else if(S=="FRI") ans=2;
  else ans=1; 
  cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
import itertools
from operator import itemgetter

D,G = map(int,input().split())
pc = []

for i in range(D):
    p,c = list(map(int,input().split())) 
    tmp = (i+1) * 100 * p + c #合計得点
    pc.append([p,c,tmp])

A = [0,1]
mintimes = 10000

for i in itertools.product(A,repeat=D):
    score = 0
    times = 0
    lest = []
    
    for j,v in enumerate(i):
        if v != 0:
            score += pc[j][2]
            times += pc[j][0]
        else:
            lest.append(j)
    
    if score >= G:
        #更新する
        mintimes = min(times,mintimes)
    else:
        objective = G - score

        part = []
        for k in lest: 
            part.append([pc[k][0],100*(k+1)])
        
        part2 = sorted(part,key=itemgetter(1),reverse = True)

        for m in part2:
            if objective > (m[0]-1) * m[1]:
                objective -= (m[0]-1) * m[1]
                times += (m[0]-1)
            else:
                tmp3 = objective // m[1]
                if objective % m[1] != 0:
                    tmp3 += 1
                times += tmp3
                mintimes = min(mintimes,times)
                break

print(mintimes)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

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

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

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


int main() {
	ll i, j;
	ll L, R;
	cin >> L >> R;
	ll mod = 2019;
	if (R - L >= mod) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = mod;
	for (i = L; i <= R; i++) {
		for (j = i + 1; j <= R; j++) {
			chmin(ans, (i * j) % mod);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  string S; cin >> S;
  
  int ans = 1;
  map<char,int> map;

  rep(i, N) {
    map[S[i]]++;
  }
  
  for(auto p : map) {
    ans *= p.second+1;
    ans %= 1000000007;
  }
  
  cout << ans-1 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include <iomanip>
#include <cmath>
const double PI = 3.14159265358979323846;
using namespace std;
int main()
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    h=30*h+m/2;
    m=6*m;
    double angle=abs(h-m);
    double radians = angle * PI / 180.0000000000000000000;
    double ans=sqrt(a*a +b*b -2*a*b*cos(radians));
    cout<<std::fixed;

    cout<<std::setprecision(20)<<ans<<endl;
    //cout<<angle<<endl;
    //cout<<h<<" "<<m<<endl;
}


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

int main(){
  ll n,a,b;
  cin >>n >>a >>b;
  ll ans = n/(a+b)*a;
  ll rem = n%(a+b);
  ans += min(rem,a);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
// ~maqsat~
/*
*/

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e10 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
    fre("");
    ACCELERATE;

    int r;
    cin >> r;
    cout << r * r;

    return 0;
}
/*
 
*/


Measured memory_bytes: 256
"""
https://abc096.contest.atcoder.jp/tasks/abc096_b
"""
[a,b,c]=[int(i) for i in input().split()]
k=int(input())
d=max(a,b,c)*(2**k)
if max(a,b,c)==a:
    print(b+c+d)
elif max(a,b,c)==b:
    print(a+c+d)
else:
    print(a+b+d)


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

using namespace std;

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



int main(){

  int n;
  cin >> n;
  vector<complex<double> > p(n);
  rep(i,n){
    double x,y;
    cin >> x >> y;
    p[i] = complex<double>(x,y);
  }
  if(n%2!=0){
    cout << "NA" << endl;
    return 0;
  }
  complex<double> c,cb;
  cb = (p[0]+p[n/2])/2.0;
  for(int i=1;i<n/2;i++){
    c = (p[i]+p[i+n/2])/2.0;
    if(c.real()!=cb.real()||c.imag()!=cb.imag()){
      cout << "NA" << endl;
      return 0;
    }
  }
  cout << setprecision(9) << cb.real() << " " << cb.imag() << endl;


  return 0;
}



Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int i;
    for(i = 1;i < s.length();i++) {
        if(s[i] == s[i-1]) {
            cout << "Bad" << '\n';
            return 0;
        }
    }
    cout<< "Good" << '\n';
}

Measured memory_bytes: 256
#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>;

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

    set<char> cset_odd,cset_even;
    rep(i,S.length()){
        if(i%2 == 1){
            cset_even.insert(S[i]);
        }
        else{
            cset_odd.insert(S[i]);
        }
    }

    if(cset_even.find('R')==cset_even.end() && cset_odd.find('L')==cset_odd.end()){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
// 提出時に消す
// package app;

import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

// 提出時にMainに変更する
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();
        long a[] = LongStream.range(0, n).map(e -> sc.nextLong()).toArray();

        long total = 0;
        long height = a[0];

        for (int i = 1; i < n; i++) {
            if (height > a[i]) {
                total += height - a[i];
            } else {
                height = a[i];
            }
        }

        System.out.println(total);

        sc.close();
    }
}

Measured memory_bytes: 63924
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <cstdio>

using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

int main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    long long int s = 0;
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    vector<pair<int, int> > bc;
    for(int i = 0; i < m; i++) {
        int b, c;
        scanf("%d", &b);
        scanf("%d", &c);
        bc.push_back(make_pair(b, c));
    }
    sort(bc.begin(), bc.end(), cmp);

    int max_b = 0;
    int max_c = 0;
    for(int i = 0; i < n; i++) {
//        cerr << "max_b: " << max_b << " max_c: " << max_c << endl;
        if(!bc.empty()){
            if(max_b <= 0) {
                max_b = bc.back().first;
                max_c = bc.back().second;
                bc.pop_back();
            }
        }else{
            if(max_b <= 0) {
                max_c = 0;
            }
        }

        if(a[i] > max_c) {
            s += a[i];
            cerr << a[i] << endl;
        } else {
            s += max_c;
            cerr << max_c << endl;
            max_b--;
        }
    }

    cout << s << endl;

    return 0;
}


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

int main(int argc, const char * argv[]) {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if (W-r>=x && r<=x && H-r>=y && r<=y) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3108
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var k = int.Parse(Console.ReadLine());
        for (int i = 0; i < k; i++)
        {
            if (abc[0] >= abc[1]) abc[1] *= 2;
            else abc[2] *= 2;
        }

        Console.WriteLine(abc[0] < abc[1] && abc[1] < abc[2] ? "Yes" : "No");
    }
}


Measured memory_bytes: 28220
#include<iostream>
using namespace std;
int main(){
  string s, t;
  cin>>s;
  cin>>t;
  int i=0;
  if(t.length() == s.length()+1){
    for(i=0;i<s.length();i++){
      if(s[i]!=t[i]) break;
    }
    if(i!=s.length()){
      cout<<"No"<<endl;
    }
    else{
		cout<<"Yes"<<endl;
    }
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

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

int main(){
  int K, A, B;
  cin >> K >> A >>B;
  for(int i = A; i <= B; i++){
    if(i % K == 0){
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
   vector<pair<string,pll> >s;
    lli n;
    cin>>n;
    for(lli i=0;i<n;i++){
    	string st;
    	lli a;
    	cin>>st;
    	cin>>a;
    	s.pb(mp(st,mp(-a,i)));
    }
    sort(s.begin(),s.end());
    for(lli i=0;i<n;i++)cout<<s[i].se.se+1<<endl;
    return 0;
}




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

int main() {
    int n;
    cin >> n;
    int array[n];
    for (int i = 0; i < n; i++) {
        cin >> array[i];
    }   
    sort(array, array+n);
    for (int i = 0; i < n; i++) {
        if (array[i] == array[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

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


class SegmentTrees:
    def __init__(self, target, no_effect):
        target_size = len(target)
        leaves_size = 1
        while leaves_size < target_size:
            leaves_size *= 2
        self.tree_size = leaves_size * 2 - 1
        self.tree = [no_effect] * self.tree_size
        self.no_effect = no_effect
        self.initialize_tree(target, no_effect)

    @classmethod
    def initialize_func(cls, value):
        return 1 << (ord(value) - ord('a'))

    @classmethod
    def merge_func(cls, a, b):
        return a | b

    def merge_child_data(self, node):
        child1 = node * 2 + 1
        child2 = node * 2 + 2
        merged = self.merge_func(self.tree[child1], self.tree[child2])
        return merged

    def initialize_tree(self, target: list, no_effect=0):
        initial_leaf = self.tree_size // 2
        leaves = range(initial_leaf, initial_leaf+len(target))
        for value, leaf in zip(target, leaves):
            self.tree[leaf] = self.initialize_func(value)

        for parent in range(initial_leaf-1, -1, -1):
            self.tree[parent] = self.merge_child_data(parent)

    def update(self, new_value, index):
        leaf = self.tree_size//2 + index
        new_data = self.initialize_func(new_value)
        if self.tree[leaf] == new_data:
            return
        self.tree[leaf] = new_data

        parent = (leaf-1) // 2
        while parent >= 0:
            new_data = self.merge_child_data(parent)
            if self.tree[parent] == new_data:
                break
            self.tree[parent] = new_data
            parent = (parent-1) // 2

    def resolve_query(self, _from, to):
        def is_in_query(left, right):
            if _from <= left and right <= to:
                return 1
            elif to < left or right < _from:
                return 0
            else:
                return -1

        node = 0
        left, right = 0, self.tree_size//2
        todo = [[node, left, right]]

        result = self.no_effect
        while todo:
            node, left, right = todo.pop()
            if is_in_query(left, right) == 1:
                data = self.tree[node]
                result = self.merge_func(result, data)

            elif is_in_query(left, right) == 0:
                continue

            else:
                child1 = node * 2 + 1
                child2 = node * 2 + 2
                center = (left+right)//2
                todo.append([child1, left, center])
                todo.append([child2, center+1, right])

        return bin(result).count('1')


n = int(input())
S = input().replace('\n', '')
seg_tree = SegmentTrees(target=S, no_effect=0)

Q = int(input())
for _ in range(Q):
    query = input().split()
    if query[0] == '1':
        index, new = int(query[1])-1, query[2]
        seg_tree.update(new, index)

    elif query[0] == '2':
        _from, to = int(query[1])-1, int(query[2])-1
        print(seg_tree.resolve_query(_from, to))


Measured memory_bytes: 76324
def read():
    N, K = map(int, input().split())
    return N, K

def solve(N, K, MOD=10**9+7):
    s = list(range(N+2))
    for i in range(1, N+2):
        s[i] = s[i-1] + i
        s[i] %= MOD

    ans = 0
    for k in range(N+1, K-1, -1):
        # [a, b]
        b = s[N+1] - s[N+1-k]
        b %= MOD
        a = s[k] - s[0]
        a %= MOD
        ans += (b - a + 1)
        ans %= MOD
    return ans


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 16664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
 
ll a[maxn],pre[maxn],mark[maxn];
 
int main(){
	boost;
	
	int n;
	cin>>n;
 
	rep(i,1,n)cin>>a[i];
 
	sort(a+1,a+1+n);
	rep(i,1,n)pre[i]=pre[i-1]+a[i];
 
	mark[n]=1;
	for(int i=n-1;i>0;i--){
		if(pre[i]*2>=a[i+1]&&mark[i+1]==1)mark[i]=1;
	}
	int cnt=0;
	rep(i,1,n)cnt+=mark[i]==1;
	cout<<cnt;
 
	return 0;
}

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

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

    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int ans = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(i * 500 + j * 100 + k * 50 == x){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input()); b = []
for j in range(N):
    b.append(int(input()))
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            A[i][j] = 0

col1 = A[0][0]+A[1][0]+A[2][0]
col2 = A[0][1]+A[1][1]+A[2][1]
col3 = A[0][2]+A[1][2]+A[2][2]
dig1 = A[0][0]+A[1][1]+A[2][2]
dig2 = A[2][0]+A[1][1]+A[0][2]
if sum(A[0])==0 or sum(A[1])==0 or sum(A[2])==0 or col1==0 or col2==0 or col3==0 or dig1==0 or dig2==0:
    print('Yes')
else:
    print('No')

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

const int mn=1e6+6;
int n,cnt;
char a[mn];

int main()
{
    scanf("%d",&n);
    scanf("%s",a+1);
    int l=1,r=n;
    while(r>l) {
        while(a[l]=='R') l++;
        while(a[r]=='W') r--;
        if(l>=r) break;
        cnt++;l++,r--;
    }
    cout<<cnt;
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct KMP{
	string pat;
	vi fail;
	KMP(const string& p):pat(p),fail(p.size()+1){
		fail[0]=-1;
		for(int i=0,j=-1;i<pat.size();){
			while(j>=0 && pat[i]!=pat[j])
				j=fail[j];
			i++,j++;
			fail[i]=j;
		}
	}
	int Match(const string& text){
		for(int i=0,j=0;i<text.size();){
			while(j>=0 && text[i]!=pat[j])
				j=fail[j];
			i++,j++;
			if(j==pat.size())
				return i-j;
		}
		return -1;
	}
	vi MatchAll(const string& text){
		vi res;
		for(int i=0,j=0;i<text.size();){
			while(j>=0 && text[i]!=pat[j])
				j=fail[j];
			i++,j++;
			if(j==pat.size()){
				res.push_back(i-j);
				j=fail[j];
			}
		}
		return res;
	}
};

typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		vs ps(n);
		rep(i,n) cin>>ps[i];
		string t;
		rep(i,m){
			string x; cin>>x;
			t+=x;
		}
		vvi ms(n);
		rep(i,n) ms[i]=KMP(ps[i]).MatchAll(t);
		
		m=t.size();
		vvvb dp(1<<n,vvb(n,vb(m+1)));
		rep(i,n) rep(j,ms[i].size()) dp[1<<i][i][ms[i][j]+ps[i].size()]=1;
		rep(i,1<<n) rep(j,n) if(i>>j&1) rep(k,n) if(!(i>>k&1)){
			rep(l,ms[k].size()) if(dp[i][j][ms[k][l]])
				dp[i|1<<k][k][ms[k][l]+ps[k].size()]=1;
		}
		
		vi res(m+1);
		rep(i,n) rep(j,m+1) res[j]|=dp.back()[i][j];
		cout<<accumulate(all(res),0)<<endl;
	}
}

Measured memory_bytes: 34356
N = int(input())
S1 = list(input())
S2 = list(input())
ans=1
prev=0
ue = ""
for i in range(N):
  if S1[i]==S2[i]:
    if prev == 0:
      ans*=3
    elif prev == 1:
      ans*=2
    else:
      ans*=1
    prev = 1
  else:
    if ue == S1[i]:
      continue
    else:
      if prev == 0:
        ans*=6
      elif prev == 1:
        ans*=2
      else:
        ans*=3
      ue=S1[i]
      prev=2
print(ans%1000000007)

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

using namespace std;



int main() {
    int n;
    cin >> n;
    if (n % 1000 == 0) {
        cout << "0\n";
    } else {
        cout << 1000 - (n % 1000) << endl;
    }
    return 0;
}


Measured memory_bytes: 3560
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	string s;
	cin >> s;
	if (s == "ABC") {
		cout << "ARC";
	}
	else {
		cout << "ABC";
	}
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define db double
#define ldb long double
#define uint unsigned
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef map<int,int> mii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int inline nextin(){
	int t;
	if(scanf("%d",&t)!=1)exit(0);
	return t;
}
int inline in(){
	int x=0,c;
	for(;(uint)((c=getchar())-'0')>=10;){
		if(c=='-')return -in();
		if(!~c)throw ~0;
	}
	do{
		x=(x<<3)+(x<<1)+(c-'0');
	}while((uint)((c=getchar())-'0')<10);
	return x;
}
int zz[100005];
int main(){
    cin.sync_with_stdio(false);cin.tie(0);
	int n;
	string dat;
	cin>>n>>dat;
	for(int i=0;i<2;i++)for(int j=0;j<2;j++){
		zz[0]=i;zz[1]=j;
		for(int k=1;k<n-1;k++){
			zz[k+1]=zz[k]^zz[k-1]^(dat[k]=='x');
		}
		if((dat[0]=='x')==(zz[0]^zz[1]^zz[n-1])&&(dat[n-1]=='x')==(zz[0]^zz[n-1]^zz[n-2])){
			for(int k=0;k<n;k++)cout<<(zz[k]?'W':'S');
			cout<<endl;
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std ;
int main(){
    int N,X;
    cin >> N >> X;
    int L[N];
    for(int i=0;i<N;i++)cin >> L[i];
    int NP=0;
    int count =1;
    for(int i=0;i<N;i++){
        NP+=L[i];
        if(NP<=X)count++;
        else break;
    }
    cout << count << endl;
}

Measured memory_bytes: 3592
def attack(player,enemy):
    enemy[0] -= player[1]
    if(enemy[0] <= 0):
        return 1
    else:
        return -1

def resolve():
    data = [int(i) for i in input().split()]

    takahasi = [data[0],data[1]]
    aoki = [data[2],data[3]]
    
    while(True):
        flag = attack(takahasi,aoki)
        if(flag == 1):
            print("Yes")
            break
        flag = attack(aoki,takahasi)
        if(flag == 1):
            print("No")
            break
resolve()

Measured memory_bytes: 9144
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int s = max(a + b, a - b);
	s = max(s, a * b);
	cout << s << endl;
}


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

int main() {
  LL N,M,A,B=0;
  cin>>N>>M;
   for(int i=0; i<M; i++){
     cin>>A;
     B=B+A;
     if(N<B){
       cout<<-1<<endl;
       break;
     }
   }
   if(N>=B){
     cout<<N-B<<endl;
   }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	ll n, k; scanf("%lld%lld", &n, &k);
	if(n > k) n = n % k;
	printf("%lld\n", min(n, k-n));
}


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

int N,M,K;
ll A[100010],dp[100010][310] = {{0}},D[100010] = {0};

int main(){
	cin >> N >> M >> K;
	for(int i=1;i<=N;i++){
		cin >> A[i];
		dp[i][1] = A[i];
	}
	int s = 0,t = 0;
	for(ll j=2;j<=K;j++){
		for(int i=1;i<N;i++){
			while(s<t && dp[D[t-1]][j-1]<=dp[i][j-1]) t--;
			D[t] = i;
			t++;
			if(j-1<=i){
				int m = D[s];
				dp[i+1][j] = dp[m][j-1] + j*A[i+1];
				if(i>=M && D[s]==i-M+1) s++;
			}
		}
		for(int i=0;i<=N;i++) D[i] = 0;
		s = 0; t = 0;
	}
	ll ans = 0;
/*	for(int j=1;j<=K;j++){
		for(int i=1;i<=N;i++){
			cout << dp[i][j] << (i!=N? " ":"\n");
		}
	}
*/	for(int i=K;i<=N;i++) ans = max(ans,dp[i][K]);
	cout << ans << endl;
}

Measured memory_bytes: 243968
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  
  int x = 1;
  for(int i = 0; i < n; i++){
  	if(x < k){
      x *= 2;
    }else{
      x += k * (n-i);
      break;
    }
  }
  cout << x;

  
 
}

Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

r = inp[0]
p r*r

Measured memory_bytes: 1788
//R<3S
#include <bits/stdc++.h>
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define int long long
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);}
#define inset(data,n) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);}
#define ll long long

#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>
#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


using namespace std;

void solve()
  {
	int n;
	cin>>n;
	int a[n+1];
	rep(i,n)cin>>a[i+1];int cnt=0;
	mii m1,m2;
	repA(i,1,n)
	{
		m1[i+a[i]]++;
		m2[i-a[i]]++;
		
	}
	int sum=0;
	repA(i,1,n)
	{
		sum+=m2[i+a[i]];
	}
	cout<<sum<<endl;
	// trav(m)if(i.se-1)cout<<i.fi<<" "<<i.se<<endl;
	
	

  }



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


   return 0;
}


Measured memory_bytes: 39460
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 998244353;

vector<int> graph[2001];
int d;
vector<bool> used(2001);
vector<bool> used2(2001);
vector<P> edge;

void dfs(int i, int di) {
  if (di > d) return;
  used.at(i) = true;
  for(auto e: graph[i]) {
    if (used[e]) continue;
    dfs(e, di+1);
  }
}

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

  int n, k; cin >> n >> k;
  d = k/2;

  rep(i, n-1) {
    int a, b; cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
    edge.push_back(P(a,b));
  }

  if (k%2 == 0) {
    int ma = 0;
    for(int i=1; i<=n; i++) {
      for(int j=1; j<=n; j++) {
        used[j] = false;
      }
      dfs(i, 0);
      int cnt = 0;
      for(int j=1; j<=n; j++) {
        if (used[j]) cnt++;
      }
      ma = max(ma, cnt);
    }
    cout << n - ma << endl;
  } else {
    int ma = 0;
    for(int i=0; i<n-1; i++) {
      for(int j=1; j<=n; j++) {
        used[j] = false;
      }
      int a = edge[i].first;
      int b = edge[i].second;
      dfs(a, 0);
      for(int j=1; j<=n; j++) {
        used2[j] = used[j];
        used[j] = false;
      }
      dfs(b, 0);
      int cnt = 0;
      for(int j=1; j<=n; j++) {
        if (used[j] || used2[j]) cnt++;
      }
      ma = max(ma, cnt);
    }
    cout << n - ma << endl;
  }



}

Measured memory_bytes: 384
I=lambda:map(int,input().split())
R,G,B,N=I()
r=0
for i in range(N//R+1):
    for j in range(N//G+1):
        if N-i*R-j*G>=0 and (N-i*R-j*G)%B==0:
            r+=1
print(r)

Measured memory_bytes: 40940
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void){
	int K,S;
	scanf("%d %d",&K,&S);
	int c,d;
	int ans;
	ans = 0;
	for(c=0;c<=K;c++){
		for(d=0;d<=K;d++){
			if(c+d<=S && c+d>=S-K){
				ans = ans+1;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}
	

Measured memory_bytes: 256
# F
from collections import deque
 
TT_list = []
# input
N, L = map(int, input().split())
T = 0.0
vt_now = 0.0
v_now = 0
que = deque()

for i in range(N):
    ti, v = map(int, input().split())
    t = float(ti)
    v_now += v
    vt_now += v*t
    # add
    if v == L:
        que.append([t, v])
    else:
        while v < L and len(que) > 0:
            t_, v_ = que[-1]
            if t_ <= t:
                que.append([t, v])
                break
            elif v + v_ >= L:
                v_ = v + v_ - L
                t = ((L - v) * t_ + v * t) / L
                v = L
                que = deque([[t, v]])
                v_now = L
                vt_now = t*L
                # break
            else:
                t = (t*v + t_*v_) / (v + v_)
                v = v + v_
                que.pop()
    # minus
    while v_now > L:
        if que[0][1] <= v_now - L:
            v_now -= que[0][1]
            vt_now -= que[0][1]*que[0][0]
            que.popleft()
        else:
            que[0][1] -= v_now - L
            vt_now -= (v_now - L)*que[0][0]
            v_now = L
            
    TT_list.append(vt_now / L)

for i in range(N):
    print(TT_list[i])


Measured memory_bytes: 123096
import math
a,b,h,m=map(float,input().split())
pi=math.pi
th=((h+(m/60))*(2*pi))/12
tm=((2*pi)*m)/60
diff=abs(th-tm)
val=a*a+b*b-2*a*b*math.cos(diff)
print(math.sqrt(val))



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

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

  if (a + b < c + d) {
    cout << "Right" << endl;
  } else if(a + b > c + d) {
    cout << "Left" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<memory.h>
using namespace std;
unsigned long long val[5005] = {};
int main()
{
	int a,b,c,d,flag=0;
	cin >> a >> b >> c>>d;
	if (abs(a - c) <= d||(abs(b-a)<=d&&abs(c-b)<=d))flag = 1;
	if (flag)cout << "Yes";
	else cout << "No";

	system("pause");
	return 0;
}

Measured memory_bytes: 504
from collections import deque

H,W=list(map(int,input().split()))
ans=-1

s=['#'*(W+2)]
s+=['#'+input()+'#' for _ in range(H)]
s+=['#'*(W+2)]

deq=deque([(1,1,0)])
move=[(1,0),(0,1),(-1,0),(0,-1)]
dist=[[-1 for _ in range(W+2)] for _ in range(H+2) ]
while len(deq) !=0:
    x=deq.pop()
    if x[:-1]==(H,W):
        ans=x[-1]
        break
    for m in move:
        i=x[0]+m[0]
        j=x[1]+m[1]
        d=x[2]
        if s[i][j]=='.' and dist[i][j]==-1:
            deq.appendleft((i,j,d+1))
            dist[i][j]=d+1

if ans==-1:
    print(-1)
else:
    sum_=0
    for t in s:
        sum_+=t.count('#')
    b=sum_-(W+2)*2-H*2
    ans=H*W-b-ans-1
    print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<vector>
//#include<unordered_map> 
#include<map>
using namespace std ;
typedef long long ll ;

int main(){
    ll a , b ;
   cin >> a >> b ;
   for (ll i = 0; i < b ; i++)
   {
       ll temp ; 
       cin >>temp ;
        a-=temp ;
   }
   if (a< 0)
   {
       cout << -1 << endl ;
       return  0 ;
   }
   
   cout << a << endl  ;
   
    return 0 ;
}

Measured memory_bytes: 3652
A,B,C,K = list(map(int,input().split()))
if A >= K:
  print(1*K)
elif A < K and A + B >= K:
  print(1 * A + (K-A) * 0)
elif A<K and A+B<K and A+B+C>=K:
  print(1*A + B * 0 + (K-A-B) * -1)

Measured memory_bytes: 9180
#include "bits/stdc++.h"
typedef long long ll;
const ll mod = 1e9 + 7;
#define vl vector<ll,ll>
#define vp vector<pair<ll,ll>>
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define For(i,a,b) for(ll i=(a);i<(b);i++)
#define all(x) (x).begin(),(x).end()
#define rsort(x) sort((x).rbegin(),(x).rend())
#define debug(x) cerr<<#x<<":"<<x<<endl
using namespace std;
string s, t;
signed main() {
	ll n[3];
	cin >>n[0]>>n[1]>>n[2];
	sort(n, n + 3);
	cout << n[0]+n[1] << endl;
}

Measured memory_bytes: 256
def main():
    n=int(input())
    s=list(input())
    rgb=[[0]*3 for _ in range(n)]
    rgb[0][0],rgb[0][1],rgb[0][2]=s.count('R'),s.count('G'),s.count('B')
    ans=0

    def num(x):
        if x=='R':
            return 0
        elif x=='G':
            return 1
        else:
            return 2
    for i in range(n-1):
        rgb[i+1][0],rgb[i+1][1],rgb[i+1][2]=rgb[i][0],rgb[i][1],rgb[i][2]
        rgb[i+1][num(s[i])]-=1

    for i in range(n-2):
        for j in range(i+1,n-1):
            if s[i]==s[j]:
                continue
            else:
                ans+=rgb[j+1][3-num(s[i])-num(s[j])]
                if 2*j-i<=n-1:
                    if s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                        ans-=1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 70444
fun main(args: Array<String>) {
    val (x, n) = readLine()!!.split(' ').map { it.toInt() }
    if (n == 0) {
        print(x)
        return
    }

    val p = readLine()!!.split(' ').map { it.toInt() }.toSet()

    var itr: Int = 0;
    var ans = 1000
    while (true) {
        if (!p.contains(x + itr)) {
            ans = x + itr
        }
        if (!p.contains(x - itr)) {
            ans = x - itr
        }

        if (ans != 1000) break

        itr++
    }

    println(ans)
}

Measured memory_bytes: 36752
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 100005;
 
int X,Y,Z;
int n;
struct P {
    ll x,y,z;
    bool operator<(const P&a)const {
        return x+a.y>y+a.x;
    }
} p[maxn];
 
struct cmp1 {
    bool operator()(const int x,const int y)const {
        return p[x].x+p[y].z>p[y].x+p[x].z;
    }
};
struct cmp2 {
    bool operator()(const int x,const int y) const{
        return p[x].y+p[y].z<p[x].z+p[y].y;
    }
};
 
bool in_silver[maxn];
int main() {
  // freopen("in.cpp","r",stdin);
    cin>>X>>Y>>Z;
    n=X+Y+Z;
    for(int i=0; i<n; i++)scanf("%lld%lld%lld",&p[i].x,&p[i].y,&p[i].z);
    sort(p,p+n);
    ll ret=0;
    priority_queue<int,vector<int>,cmp1>left_gold;
    priority_queue<int,vector<int>,cmp2>right_bronze;
    for(int i=0; i<X; i++) {
        ret+=p[i].x;
        left_gold.push(i);
    }
    for(int i=n-1; i>=X; i--) {
        ret+=p[i].z;
        right_bronze.push(i);
        if(right_bronze.size()>Z) {
            int tt=right_bronze.top();
            right_bronze.pop();
            ret-=p[tt].z;
            ret+=p[tt].y;
            in_silver[tt]=true;
        }
    }
    ll cur=ret;
    for(int i=X; i<X+Z; i++) {
        ll tmp=cur;
        tmp+=p[i].x;
        left_gold.push(i);
        int tt=left_gold.top();
        left_gold.pop();
        tmp-=p[tt].x;
        tmp+=p[tt].z;
        if(in_silver[i]) {
            tmp-=p[i].y;
            while(!right_bronze.empty()) {
                int tt=right_bronze.top();
                if(tt<=i) {
                    right_bronze.pop();
                } else {
                    right_bronze.pop();
                    in_silver[tt]=true;
                    tmp-=p[tt].z;
                    tmp+=p[tt].y;
                    break;
                }
            }
        } else {
            tmp-=p[i].z;
        }
        ret=max(ret,tmp);
        cur=tmp;
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 3196
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt(), S = cin.getStr();
    let W = new Array(N + 1).fill(0);
    for (let n = 0; n < N; n++)
        W[n + 1] = W[n] + (S.charAt(n) == '#' ? 1 : 0);
    let ans = Number.MAX_SAFE_INTEGER;
    for (let n = 0; n <= N; n++)
        ans = Math.min(ans, W[n] + N - n - (W[N] - W[n]));
    console.log(ans);
}
class Inputer{constructor(t){this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
	int a,b,i,j,k,ans=0;
	cin >> a >> b;
	
	for(i=0;i<=a;i++){
		for(j=0;j<=a;j++){
			if(b-i-j>=0 && b-i-j<=a) ans++;
			}
		}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
from collections import deque
 
def main():
    H,W=map(int,input().split())
    S=[]
    for i in range(H):
        s=input()
        S.append(s)
 
    G=[]
    for i in range(H):
        for j in range(W):
            tmp=[]
            if S[i][j]=="#":
                G.append(tmp)
                continue
            if i-1>=0:
                if S[i-1][j]==".":
                    tmp.append((i-1)*W+j)
            if i+1<=H-1:
                if S[i+1][j]==".":
                    tmp.append((i+1)*W+j)
            if j-1>=0:
                if S[i][j-1]==".":
                    tmp.append(i*W+j-1)
            if j+1<=W-1:
                if S[i][j+1]==".":
                    tmp.append(i*W+j+1)
            G.append(tmp)
 
    res=0
 
    for start in range(H*W):
        dist = 0
        v = [-1 for _ in range(H * W)]
        que=deque([])
        que.append(start)
        v[start]=dist
        while len(que)>0:
            next_index=que.popleft()
            next=G[next_index]
            for i in next:
                if v[i]==-1:
                    que.append(i)
                    v[i]=v[next_index]+1
 
        if max(v)>=res:
            res=max(v)
 
    print(res)
 
 
if __name__=="__main__":
    main()
 
 

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

int main() {
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		double s=0;
		string p;
		cin >> p;		
		s = ((p[0] - '0') * 10 + (p[1] - '0')) * 30 - ((p[3] - '0') * 10 + (p[4] - '0'))*5.5;
		if (s < 0)s = s - s * 2;
		if (s > 360 - s)s = 360 - s;
			if (s < 30)cout << "alert" << endl;
			else if (s < 90)cout << "warning" << endl;
			else cout << "safe" << endl;
	}
}

Measured memory_bytes: 3196
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, M;
  cin>>N>>M;
  vector<vector<pair<ll, ll> > > edge(N);
  ll L, R, D;
  for(ll i=0;i<M;++i) {
    cin>>L>>R>>D;
    L--;
    R--;
    edge[L].push_back(mp(R, D));
    edge[R].push_back(mp(L, -D));
  }
  map<ll ,ll> amap, bmap;
  queue<pair<ll, ll> > que;
  pair<ll, ll> state;
  ll node, dist;
  bool can = true;
  for(int i=0;i<N;++i) {
    if(bmap[i]!=0) continue;
    que.push(mp(i, 0));
    bmap[i] = 1;
    while(!que.empty()) {
      state = que.front();que.pop();
      node = state.fi;
      dist = state.se;
      for(int j=0;j<edge[node].size();++j) {
        if(bmap[edge[node][j].fi]==0) {
          amap[edge[node][j].fi] = dist + edge[node][j].se;
          bmap[edge[node][j].fi] = 1;
          que.push(mp(edge[node][j].fi, dist+edge[node][j].se));
        }
        else {
          if(dist+edge[node][j].se!=amap[edge[node][j].fi]) {
            can = false;
          }
        }
      }
    }
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 28852
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int D; cin >> D;
  if (D==22){ cout << "Christmas Eve Eve Eve" << endl;}
  if (D==23){ cout << "Christmas Eve Eve" << endl;}
  if (D==24){ cout << "Christmas Eve" << endl;}
  if (D==25){ cout << "Christmas" << endl;}
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 3 5

output:
30
"""

import sys
from functools import reduce


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


def lcm(a, b):
    return a * b // gcd(a, b)


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = tuple(map(int, _input[1].split()))
    print(solve(n_list))

Measured memory_bytes: 8304
from bisect import bisect_right
s = input()
t = input()
n = len(s)

position = [[] for i in range(26)]
for i, ss in enumerate(s):
    pos = ord(ss)-ord("a")
    position[pos].append(i)

for tt in set(t):
    if not position[ord(tt)-ord("a")]:
        print(-1)
        exit(0)

count = 0
idx = -1
for tt in t:
    t_i = ord(tt)-ord("a")
    pos = bisect_right(position[t_i], idx)
    if pos == len(position[t_i]):
        idx = position[t_i][0]
        count += 1
    else:
        idx = position[t_i][pos]

print(count*n+idx+1)


Measured memory_bytes: 80404
#include <iostream>
using namespace std;
int main()
{
    int a, b, temp , i;
    for(i=1; i<=3000 ; i++)
    {
        cin >> a >> b;
    
        if (a==0 && b==0 )
            break;
   
        if(a > b)
        { 
            temp = a;
            a = b;
            b = temp;
       
    
        }
        cout << a << " " << b << endl;
    }
}
    


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

int main() {
	int a,b=0;
	cin >> a;
	vector<int>s(a);
	for (int i = 0; i <a; i++) {
		cin >> s[i];
		if (s[i] % 2 == 1)b++;
	}
	if (b % 2 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 640