akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e6;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

// dp[i][j][k] := 1個:i個, 2個:j個, 3個:k個の時の期待値
// 遷移
// dp[i][j][k] = 1 +
//               dp[i-1][j][k]    * (i/n) +
//               dp[i+1][j-1][k]  * (j/n) +
//               dp[i][j+1][k-1]  * (k/n) +
//               dp[i][j][k]      * ((n-i-j-k)/n);
// 式変形して
// dp[i][j][k] = (dp[i-1][j][k]   * i +
//                dp[i+1][j-1][k] * j +
//                dp[i][j+1][k-1] * k) / (i+j+k);

int n;
double dp[333][333][333];

double f(int i,int j,int k){
  if(i==0 && j==0 && k==0) return 0.0;
  if(dp[i][j][k]>=0) return dp[i][j][k];

  double res = n;
  if(i>0) res += f(i-1, j, k)   * i;
  if(j>0) res += f(i+1, j-1, k) * j;
  if(k>0) res += f(i, j+1, k-1) * k;
  res /= (double)(i+j+k);  
  return dp[i][j][k] = res;
}

signed main() {
  INIT;
  cin>>n;
  memset(dp,-1.0,sizeof(dp));
  int i=0,j=0,k=0;
  REP(ni,n){
    int t;cin>>t;
    if(t==1) ++i;
    if(t==2) ++j;
    if(t==3) ++k;
  }
  long double ans=f(i, j, k);
  FOUT(10,ans)BR;
  
  return 0;
}


Measured memory_bytes: 288896
def solve():
    N,T = map(int,input().split())
    ans = float('inf')
    for i in range(N):
        c,t = map(int,input().split())
        if t <= T:
            ans = min(ans, c)

    if ans == float('inf'):
        print('TLE')
    else:
        print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include<iostream>
#include<math.h>
using namespace std;

int main(){
	long int N;
	cin>>N;
    long int ma=1,mb=N;
	for(int i=1;i<=sqrt(N);i++){
		if(N%i==0){
			if(i+N/i<ma+mb){
				ma=i;
				mb=N/i;
			}
		}
	}
	cout<<ma+mb-2;
	return 0;
}

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

//#define int ll
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = 5e5 + 228;

int t[N];

void add(int pos, int delta) {
  for (int i = pos + 1; i < N; i += i & -i) {
    t[i] += delta;
  }
}

int query(int r) {
  int res = 0;
  for (; r > 0; r -= r & -r) {
    res += t[r];
  }
  return res;
}

int query(int l, int r) {
  return query(r) - query(l);
}

int n, q, c[N];
int ans[N];
vector<pair<int, int>> have[N];
int last[N];

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    have[r].pb({l, i});
  }
  memset(last, 255, sizeof(last));
  for (int i = 0; i < n; ++i) {
    if (last[c[i]] != -1) {
      add(last[c[i]], -1);
    }
    last[c[i]] = i;
    add(i, 1);
    for (auto p : have[i]) {
      int id = p.Y, l = p.X;
      ans[id] = query(l, i + 1);
    }
  }
  for (int i = 0; i < q; ++i) {
    cout << ans[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 33240
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N; cin >> N;
  vector<int> cs(1e5 + 1);
  auto s = 0LL;
  vector<int> A(N); for (auto &a: A) {cin >> a; ++cs[a]; s += a;}
  int Q; cin >> Q;
  while (Q--)
    {int B, C; cin >> B >> C;
    auto b = cs[B]; cs[B] = 0; cs[C] += b;
    cout << (s += b * (C - B)) << endl;}}

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

short n;
int a[3030];

long long dp[3030][3030][2] = {0};
bitset<3030> seen[2][3030];

long long solve(short start, short end, bool turn) {
    if (start > end)
        return 0;

    if (not seen[turn][start][end]) {
        seen[turn][start][end] = true;
        dp[start][end][turn] = turn ? max(solve(start + 1, end, 0) + a[start], solve(start, end - 1, 0) + a[end])
                                    : min(solve(start + 1, end, 1) - a[start], solve(start, end - 1, 1) - a[end]);
    }

    return dp[start][end][turn];
}

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

    cout << solve(0, n - 1, 1);
}


Measured memory_bytes: 145792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class AFerrisWheel {
public:
        int A,B;
void solve(std::istream& cin, std::ostream& cout) {
    cin >> A >> B;
    if(A > 12)cout << B;
    else if(A < 6)cout << 0;
    else cout << B/2;
}
};


#undef int
int main() {
	AFerrisWheel solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#ひとのを真似しただけ。再挑戦
S = input()
ans = 0

import itertools
ans = 0
for ptn in itertools.product([0, 1], repeat=len(S)-1):
    bgn = 0
    for i in range(len(S) - 1):
        if ptn[i] == 1:
            ans += int(S[bgn:i+1])
            bgn = i + 1
    ans += int(S[bgn: len(S)])

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    int N, K;
    cin >> N >> K;
    vector<bool> cannot_use(10);
    for (int i = 0; i < K; ++i) {
        int D;
        cin >> D;
        cannot_use[D] = true;
    }

    for (int i = N;; ++i) {
        int tmp = i;
        bool isng = false;
        while (tmp) {
            isng |= cannot_use[tmp % 10];
            tmp /= 10;
        }
        if (!isng) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	T := readInt()
	ans := 1000000007
	for i := 0; i < n; i++ {
		c := readInt()
		t := readInt()
		if T < t {
			continue
		}
		if c < ans {
			ans = c
		}
	}
	if ans == 1000000007 {
		println("TLE")
	} else {
		println(ans)
	}
}

// -----------------------------------------------------------------------------


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

using namespace std;



int main(void)
{

    int n, m, x;
    int aMat[12][12];
    int cArr[12];
    cin >> n >> m >> x;

    for (int row = 0; row < n; row++)
    {
        cin >> cArr[row];
        for (int col = 0; col < m; col++)
        {
            cin >> aMat[row][col];
        }
    }

    int all = 1 << n;
    int ans = 1e8;

    for(int bitMsk = 0; bitMsk < all; bitMsk++){
        int cost = 0;
        int skill[12] = {0};
        for(int i = 0; i < n; i++){
            if( (bitMsk >> i) & 1 ){
                cost += cArr[i];
                for(int j = 0; j < m; j++){
                    skill[j] += aMat[i][j];
                }
            }
        }

        bool valid = true;
        for(int j = 0; j < m; j++){
            if(skill[j] < x) valid = false;
        }
        if(valid) ans = min(ans, cost);
    }

    if(ans >= 1e8) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3580
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

def prime_factorize(n):
    divisors = []
    # 27(2 * 2 * 7)の7を出すためにtemp使う
    temp = n
    for i in range(2, int(math.sqrt(n)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                # 素因数を見つけるたびにtempを割っていく
                temp //= i
            divisors.append([i, cnt])
    if temp != 1:
        divisors.append([temp, 1])
    if divisors == []:
        divisors.append([n, 1])

    return divisors

def make_divisors(n):
    divisors = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            divisors.append(i)
            # √nで無い数についてもう一個プラス
            if i != n // i:
                divisors.append(n // i)
    return sorted(divisors)

N = getN()

# 手順としては
# ①　kで出来るだけ割る
# ②　kで引いていく　N = mk + d(d = 1, 2, 3...)とすると,　引いて残る数はm(k - 1) + d
# つまりkで割り切れず、引いても引いても永遠に①に戻ることはない

# N = k ** i * (mk + 1)となるkの数を求める
# i == 0の時
# N - 1の約数の数 - 1(1)
ans = set()
for i in make_divisors(N - 1):
    if i != 1:
        ans.add(i)

# 割れるだけ割る関数
def dividor(x, k):
    if k == 1:
        return 0
    n = x
    while True:
        if n % k == 0:
            n //= k
        else:
            break
    return n

# i >= 1の時
for prim in make_divisors(N):
    if prim == 1:
        continue
    # Nを割れるだけ割る
    alta = dividor(N, prim)
    if alta == 1:
        ans.add(prim)
        continue
    if alta >= prim and alta % prim == 1:
        ans.add(prim)

# Nが素数でない場合はN自身が追加されない
ans.add(N)
print(len(ans))

Measured memory_bytes: 83936
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int k, t;
  cin >> k >> t;

  vector<int> a(t);
  REP(i, t) { cin >> a[i]; }

  int m = 0;
  REP(i, t) { m = max(m, a[i]); }

  cout << max(0, (m - 1) - (k - m)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
   int k;
   string s;
   cin >> k>> s;
   for(int i = 0;i<min(k,(int)s.size());++i)
    printf("%c",s[i]);
   if(k<s.size())
    printf("...");
   printf("\n");

    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int n;
bool p[1001];
int a[1001];
const ll MOD=(ll)1e9+7;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n;
  p[0]=0,p[1]=0;
  for(int i=2;i<=n;i++){
    p[i]=1;
  }
  for(int i=2;i<=n;i++){
    if(p[i]){
      int nowi=2*i;
      while(nowi<=n){
        p[nowi]=0;
        nowi+=i;
      }
    }
  }
  vector<int> v;
  for(int i=0;i<=n;i++){
    if(p[i])v.push_back(i);
  }
  for(int i=2;i<=n;i++){
    int now=i;
    int j=0;
    while(now!=1){
      if(now%v[j]==0){a[v[j]]++;now/=v[j];}
      else j++;
    }
  }
  ll ans=1;
  for(int i=0;i<=n;i++){
    ans=((ans%MOD)*((a[i]+1)%MOD))%MOD;
  }
  cout<<ans<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int X;
    cin >> X;
    int a = X;
    int count = 1;
    while (X % 360 != 0)
    {
        X += a;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(){
int A,B,C;




cin>>A>>B>>C;


if( A>=-100 && A<=100 && B>=-100 && B<=100 && C>=-100 && C<=100){

if(A<=C && B>=C ){
cout<<"Yes";
}
else cout<<"No";
}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){while(1){int n,a=0,b=0,c,d,s;cin>>n;if(n==0)break;for(int i=0;i<n;i++){cin>>c>>d;s=c+d,b+=s;if(c>d)a+=s;if(c==d)a+=c;}cout<<a<<" "<<b-a<<endl;}return 0;}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>


using namespace std;

int main(){

	int H,W;

	cin >> H >> W;

	char a[H+2][W+2];

	for(int w = 0;w <= W+1;w++){
		a[0][w] = '#';
	}

	for(int h = 0;h <= H + 1;h++){
		a[h][0] = '#';
	}

	for(int h = 0;h <= H +1;h++){
		a[h][W+1] = '#';
	}

	for(int w = 0;w <= W + 1;w++){
		a[H+1][w] = '#';
	}

	for(int h = 1;h <= H;h++){
		string str;
		cin >> str;
		for(int w = 1;w <= W;w++){
		   a[h][w] = str[w-1];
		}
	}

	for(int h = 0;h <= H+1;h++){
		for(int w = 0;w <= W + 1;w++){
		   cout << a[h][w];
		}
		cout << endl;
	}

    return 0;

}


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

import sys

input = sys.stdin.readline

def main():
    M = [int(input()) for _ in range(5)]
    t = 0
    print(min([rec(0, i, M[:]) for i in range(len(M))]))

def rec(total, i, M):
    if len(M) == 1:
        total += M[i]
        return total
    else:
        if M[i] % 10 != 0:
            total += int(M[i] / 10) * 10 + 10
        else:
            total += M[i]
        del M[i]
    return min([rec(total, i, M[:]) for i in range(len(M))])

main()


Measured memory_bytes: 3064
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

ll gcd(ll a,ll b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}

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

  ll sx,sy,tx,ty;
  std::cin>>sx>>sy>>tx>>ty;

  ll h=ty-sy,w=tx-sx;

  rep(i,0,h)std::cout<<"U";
  rep(i,0,w)std::cout<<"R";
  rep(i,0,h)std::cout<<"D";
  rep(i,0,w)std::cout<<"L";
  std::cout<<"L";
  rep(i,0,h+1)std::cout<<"U";
  rep(i,0,w+1)std::cout<<"R";
  std::cout<<"DR";
  rep(i,0,h+1)std::cout<<"D";
  rep(i,0,w+1)std::cout<<"L";
  std::cout<<"U\n";

  return 0;
}

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

long long N;
long long d[60];

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		cin >> d[i];
	}

	long long ans = 0;
	for(long long i = 0; i < N; i++){
		for(long long j = i+1; j < N; j++){
			ans += d[i] * d[j];
		}
	}
	cout <<  ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 111111;
vector<int> graph[N];
pair<int, int> bad[N], good[N];
int col[N], cntb[N], cntg[N], cnt[N];
int n, m, k, u, v;

void dfs(int u, int c) {
    if(col[u]) return;
    col[u] = c;
    rall(v, graph[u]) {
        dfs(v, c);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k;
    rep(i, 1, m) {
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
        cntg[u]++;
        cntg[v]++;
        good[i] = {u, v};
    }
    rep(i, 1, k) {
        cin >> u >> v;
        cntb[u]++;
        cntb[v]++;
        bad[i] = {u, v};
    }
    int nc = 0;
    rep(u, 1, n) {
        if(!col[u]) {
            dfs(u, ++nc);
        }
    }
    rep(i, 1, k) {
        int u = bad[i].fi, v = bad[i].se;
        if(col[u] != col[v]) {
            cntb[u]--;
            cntb[v]--;
        }
    }
    rep(u, 1, n) {
        cnt[col[u]]++;
    }
    rep(u, 1, n) {
        int ans = cnt[col[u]] - cntg[u] - cntb[u] - 1;
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 13824
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
if s == "Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else:
    print("Sunny")

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

int main() {
	// your code goes here
	int n;
	string s;
	cin>>n;
	int ac=0,wa=0,tle=0,re=0;
	while(n--){
		cin>>s;
		if(s=="AC") ac++;
		else if(s=="WA") wa++;
		else if(s=="TLE") tle++;
		else re++;
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re;
	return 0;
}

Measured memory_bytes: 3596
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007

def main():

    L = int(input())

    print((L/3)**3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long lli;
lli n;
vector<vector<lli> > g;
lli k;
vector<pair<lli,lli> > r;
vector<bool> vs;
void marge(pair<lli,lli>& a,pair<lli,lli> b){
    a.first = max(a.first,b.first);
    a.second = min(a.second,b.second);
}
pair<lli,lli> dfs(lli x,pair<lli,lli> p,bool isOdd){
    marge(r[x],p);
    vs[x] = true;
    //cout << x << ">" << endl;
    for(lli i = 0;i < g[x].size();i++){
        if(vs[g[x][i]]) continue;
        marge(r[x],dfs(g[x][i],make_pair(r[x].first-1,r[x].second+1),(isOdd+1)%2));
    }
    //cout << x << "<" << r[x].first << " " << r[x].second << endl;
    if(abs(r[x].first) % 2 != isOdd || r[x].first > r[x].second){
        cout << "No" << endl;
        exit(0);
    }
    return make_pair(r[x].first-1,r[x].second+1);
}
int main(int argc, char const *argv[]) {
    cin >> n;
    g = vector<vector<lli> > (n+1);
    for(lli i = 1;i < n;i++){
        lli a,b;
        cin >> a >> b;
        g[a].push_back(b);g[b].push_back(a);
    }
    cin >> k;
    r = vector<pair<lli,lli> > (n+1,make_pair((lli)-10000000,(lli)10000000));
    lli x;
    lli y;
    for(lli i = 0;i < k;i++){
        lli v,p;
        cin >> v >> p;
        r[v] = make_pair(p,p);
        x = v,y = p;
    }
    vs = vector<bool> (n+1);
    dfs(x,make_pair((lli)-10000000,(lli)10000000),y%2);
    vs = vector<bool> (n+1);
    dfs(x,make_pair((lli)-10000000,(lli)10000000),y%2);
    cout << "Yes" << endl;
    for(lli i = 1;i <= n;i++) cout << r[i].second << endl;
    return 0;
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
#define N 809
#define M 650009
using namespace std;

int m,n,lim,tail,d[N][N],h[M][2]; char s[N][N];
int calc(int x){ return (x)?(x-1)/lim+1:0; }
void ext(int x,int y,int z){
	if (x>0 && x<=m && y>0 && y<=n && s[x][y]=='.' && d[x][y]==-1){
		d[x][y]=z;
		h[++tail][0]=x; h[tail][1]=y;
	}
}
int main(){
	scanf("%d%d%d",&m,&n,&lim);
	int i,j,x,y,z,head=0; tail=1;
	memset(d,-1,sizeof(d));
	for (i=1; i<=m; i++){
		scanf("%s",s[i]+1);
		for (j=1; j<=n; j++) if (s[i][j]=='S'){
			s[i][j]='#';
			h[1][0]=i; h[1][1]=j; d[i][j]=0;
		}
	}
	int ans=1000000000;
	while (head<tail){
		x=h[++head][0]; y=h[head][1]; z=d[x][y]+1;
		if (d[x][y]>lim) continue;
		ans=min(ans,calc(min(min(x-1,m-x),min(y-1,n-y))));
		ext(x-1,y,z); ext(x+1,y,z);
		ext(x,y-1,z); ext(x,y+1,z);
	}
	printf("%d\n",ans+1);
	return 0;
}


Measured memory_bytes: 8576
Scanf.scanf "%d %d" (fun n k ->
    let xy = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) in
    let x, y = Array.fold_left (fun (xl, yl) (x, y) -> x :: xl, y :: yl) ([], []) xy in
    let x = Array.of_list x in
    let y = Array.of_list y in
    Array.sort compare x;
    Array.sort compare y;
    let rec loop1 i1 acc =
        let rec loop2 i2 x1 acc =
            let rec loop3 i3 x2 acc =
                let rec loop4 i4 y1 acc =
                    let count y2 =
                        Array.fold_left (fun acc (x, y) -> if x >= x1 && x <= x2 && y >= y1 && y <= y2 then acc + 1 else acc) 0 xy
                    in
                    if i4 >= n then acc else
                        let kk = count y.(i4) in
                        let acc = if kk >= k then min acc ((x2 - x1) * (y.(i4) - y1)) else acc  in
                        loop4 (i4 + 1) y1 acc
                in
                if i3 >= n - 1 then acc else loop3 (i3 + 1) x2 (loop4 (i3 + 1) y.(i3) acc)
            in
            if i2 >= n then acc else loop2 (i2 + 1) x1 (loop3 0 x.(i2) acc)
        in
        if i1 >= n - 1 then acc else loop1 (i1 + 1) (loop2 (i1 + 1) x.(i1) acc)
    in
    loop1 0 max_int |> Printf.printf "%d\n"
)

Measured memory_bytes: 2648
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
using ll = long long int;
//typedef pair<int,int> P;
 
 int main(void){
	 int S,W;
	 cin >> S >> W;
	 if(S <= W){
		 cout << "unsafe" <<endl;
	 }else{
		 cout << "safe" <<endl;
	 }
 }

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main() 
{
    ll n,k;
    cin>>n>>k;
    set<ll> s;
    for(ll i=0;i<k;i++)
    {
        ll d;
        cin>>d;
        for(ll i=0;i<d;i++)
        {
            ll x;
            cin>>x;
            s.insert(x);
        }
    }
    
    ll cnt=0;
    for(ll i=1;i<=n;i++)
    {
        if(s.find(i)==s.end())
        cnt++;
    }
    cout<<cnt;
}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n, k; cin>>n>>k;
    vector<int> cnt(200010, 0);
    for(int i=0; i<n; i++){
        int a; cin>>a;
        cnt[a]++;
    }

    int kinds=0;
    for(int i=1; i<=200000; i++){
        if(cnt[i]>0) kinds++;
    }

    sort(cnt.begin(), cnt.end());

    int num=0, ans=0;
    for(int i=0; i<200010; i++){
        if(cnt[i]>0){
            num++;
            ans+=cnt[i];
        }
        if(num>=(kinds-k)) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n=int(input())
#a,b=map(int,input().split())
hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

mx=max(hl)
count=0
for height in range(1,mx+1):
    i=0
    while i<n:
        if hl[i]>=height:
            count+=1
            while i<n and hl[i]>=height :
                i+=1
        else:
            i+=1

print(count)



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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int32_t main()
{
	FIO;
	int n; cin >> n;
	int sm = 0;
	w(m)
	{
		int x; cin >> x;
		sm += x;
	}

	if (sm > n)
		cout << -1 << '\n';
	else
		cout << n - sm << '\n';
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
const double PI = 3.14159265358979323846;




int main() {
	int N, M;
	cin >> N >> M;
	vector<bool> goodTable = vector<bool>(N + 1, true);
	vector<int> hightTable = vector<int>(N + 1, 0);
	
	for (int i = 1; i < N + 1; i++) {
		int temp;
		cin >> temp;
		hightTable[i] = temp;
	}


	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;


		if (hightTable[A] > hightTable[B]) {
			goodTable[B] = false;
		}
		else if (hightTable[A] < hightTable[B]) {
			goodTable[A] = false;
		}
		else {
			goodTable[B] = false;
			goodTable[A] = false;
		}
	}

	int count = 0;
	for (int i = 1; i < N + 1; i++) {
		if (goodTable[i]) {
			count++;
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int m = 3;
    int a[m][m];
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    for (int t = 0, x; t < n; t++) {
        cin >> x;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                if (a[i][j] == x) {
                    a[i][j] = -1;
                }
            }
        }
    }
    bool ans = false;
    for (int i = 0; i < m; i++) {
        bool ok = true;
        for (int j = 0; j < m; j++) {
            if (a[i][j] != -1) {
                ok = false;
                break;
            }
        }
        if (ok) ans = true;
    }
    for (int j = 0; j < m; j++) {
        bool ok = true;
        for (int i = 0; i < m; i++) {
            if (a[i][j] != -1) {
                ok = false;
                break;
            }
        }
        if (ok) ans = true;
    }
    if (a[0][0] == a[1][1] && a[1][1] == a[2][2] && a[0][0] == -1) ans = true;
    if (a[2][0] == a[1][1] && a[1][1] == a[0][2] && a[1][1] == -1) ans = true;
    cout << (ans ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int N,K,a=1,i;
  cin >> N >> K;
  for(i=0; i<N; i++){
    if(a*2 <= a+K){
      a = a*2;
    }else{
      a = a+K;
    }
  }cout << a << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
rootList = [-1 for i in range(n)]
 
def getRoot(x):
    if rootList[x] < 0:
        rootList[x] = x
    elif rootList[x] != x:
        rootList[x] = getRoot(rootList[x])
    return rootList[x]
 
 
def setSameRoot(x, y):
    x = getRoot(x)
    y = getRoot(y)
    if x != y:
        rootList[x], rootList[y] = min(x, y), min(x, y)
 
for i in range(m):
    s, t = map(int, input().split())
    setSameRoot(s, t)
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    print("yes" if getRoot(s) == getRoot(t) != -1 else "no")

Measured memory_bytes: 7016
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import sys
sys.setrecursionlimit(10**6)
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq

#n,k,x=list(map(int,input().split()))

#c=[list(map(int,input().split())) for _ in range(n)]
#c.sort(key=lambda x:x[0])
#dp=[]
def rec(arr,c,now,cnt,stop=False ,s_val=0):
    if stop and s_val==cnt:
        return now,cnt
    if c[now]:
        return now,cnt
    c[now]=True
    return rec(arr,c,a[now],cnt+1,stop=stop,s_val=s_val)
    

n,k=list(map(int,input().split()))
a=[0]+list(map(int,input().split()))

#n=2*10**5
#a=[i for i in range(2*10**5+1)]


c=[False for _ in range(n+1)]
start,s_to_rep_num=rec(a,c,1,0)
c=[False for _ in range(n+1)]
end,rep_n=rec(a,c,start,0)
val=k
s=1
#print(s_to_rep_num,rep_n)
if s_to_rep_num<k:
    s=start
    val=(k-s_to_rep_num)%rep_n
c=[False for _ in range(n+1)]
ans,cnt=rec(a,c,s,0,stop=True,s_val=val)
print(ans)





Measured memory_bytes: 259100
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=3005,K=998244353,inv2=499122177;
int n,m,a[maxn],f[maxn][maxn];
int Pow(int A,int B)
{
	int res=1;
	while (B)
	{
		if (B&1) res=(LL)res*A%K;
		A=(LL)A*A%K;
		B>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	f[0][0]=Pow(2,n);
	for (int i=1;i<=n;i++)
		for (int j=0;j<=m;j++)
		{
			f[i][j]=f[i-1][j];
			if (a[i]<=j) f[i][j]=(f[i][j]+(LL)f[i-1][j-a[i]]*inv2)%K;
		}
	printf("%d\n",f[n][m]);
	return 0;
}


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

int main(){
    string S[3];
    vector<int> index(3,0);
    for(int i = 0; i < 3; i++) cin >> S[i];
    int who = 0;
    while(1){
        if(index[who] == S[who].size()){
            cout << (char)('A' + who) << endl;
            return 0;
        }

        index[who]++;
        who = S[who][index[who] - 1] - 'a';
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a, b, c;

	scanf("%d%d%d", &a, &b, &c);

	if(a > b)
		a^=b^=a^=b;
	if(b > c)
		b^=c^=b^=c;
	if(a > b)
		a^=b^=a^=b;

	if(a+b == c)
		printf("Yes");
	else
		printf("No");

	return 0;
}


Measured memory_bytes: 128
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    a, b = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    cnt = 0
    for i in range(a, b+1):
        N=[]
        j = i
        while j >= 1:
            N.append(j % 10)
            j = j // 10
 #       print(N)
        if N == list(reversed(N)):
            cnt += 1

    print(cnt)
resolve()

Measured memory_bytes: 41324
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Objects;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		int tens=0;
		int p=0;
		while(true) {
			p=tens*(tens+1)/2;
			if(p>=N) {
				break;
			}
			else {
				tens++;
			}
		}
		if(p==N) {
			for(int i=1; i<=tens; i++) {
				pl(i);
			}
		}
		else {
			for(int i=1; i<=tens; i++) {
				if(p-N!=i) {
					pl(i);
				}
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#include <string>
#include <vector>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
    int n,k;cin >> n >> k;
    string s;cin >> s;
    string t = "";
    bool flag;
    int cnt = 0;
    int Lcnt = 0;
    int Rcnt = 0;
        if(s[0]=='L') {
        flag = true;
        t.push_back('('); 
        Lcnt++;
    }else {
        flag = false;
        t.push_back(')');
        Rcnt++;
    }

    rep(i,n-1){
        if(flag){
            if(s[i+1]=='L') cnt++;
            else {
                t.push_back(')');
                Rcnt++;
                flag = false;
            }
        }else{
            if(s[i+1] == 'R') cnt++;
            else{
                t.push_back('(');
                Lcnt++;
                flag = true;
            }
        }
    }
    if(max(Lcnt,Rcnt) > k) cout << cnt + 2*k << endl;
    else cout << n-1 << endl;

}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1005 , inf=1e17;
ll a[N],b[N],c[N],dist[105][105];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m,ans=0;cin>>n>>m;
    for(ll i=0;i<m;i++)cin>>a[i]>>b[i]>>c[i],a[i]-=1,b[i]-=1;
    for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)dist[i][j]=(i==j?0:inf);
    for(ll i=0;i<m;i++)dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
    for(ll i=0;i<m;i++)dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
    for(ll k=0;k<n;k++)for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    for(ll i=0,chk=0;i<m;i++,chk=0){
        for(ll j=0;j<n;j++)if(dist[j][a[i]]+c[i]==dist[j][b[i]])chk=1;
        ans+=chk;
    }
    cout<<m-ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  map<string, int> S;
  rep(i,n){
    string s;
    cin >> s;
    
    sort(s.begin(), s.end());
    
    if(S.count(s)){
      ans = ans + S[s];
      S[s] = S[s] + 1;
    }
    else{
     S[s] = 1;  
    }
    
  }
 cout << ans;
  
  return 0;
}

Measured memory_bytes: 11272
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    # 桁ごとに1の足される数を数える方針

    # 下準備 Aの中で、d桁目が1であるものの個数
    cnt = [0] * 60
    for i in A:
        for j in range(60):
            if i >> j & 1:
                cnt[j] += 1

    # 繰り上がりのない2進数→10進数に変換
    ans = 0
    for i in range(60):
        # i桁目に1の足される数に2のi乗をかければよい
        ans += cnt[i] * (N - cnt[i]) * pow(2, i, MOD)
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 51864
# coding: utf-8
# Your code here!
import sys

def input():
    return sys.stdin.readline().strip()

N, M = map(int, input().split())
a = set(int(input()) for _ in range(M))
li = [1] + [0 for _ in range(N)]

for i in range(1, N + 1):
    if i in a:
        continue
    else:
        li[i] = li[i - 1] + li[i - 2]
print(li[-1] % 1000000007)

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

#define int long long int
#define pb push_back
#define M 1000000007
#define inf 10000000000
#define ff first
#define ss second
#define deb(x) cout< #x< " "< x< endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<=n;i++)
#define FORR(a,b,c) for(int a= b;a>=c;a--)
#define fa(arrr) for(auto x:arrr)
#define iPair pair<int, pair<int,int>>
#define sz size()
// #define mp make_pair
#define mxm3(a,b,c) max(a, max(b,c))
#define mi3(a,b,c) min(a, min(b,c))
#define mxn 100005
#define PII pair<int,int>
#define all(v) v.begin(), v.end()
#define endl "\n"
#define N 2005
#define C 4
#define nfs ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
// Ordered Set Tree
// typedef tree<PII, null_type, less<PII>,
//         rb_tree_tag,
//         tree_order_statistics_node_update>
//         oset;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

int power(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1) res = (res * x) % M;
        y = y >> 1;
        x = (x * x) % M;
    }
    return res;
}

// int y = 1;

int a[400005], pre[400005], pre2[400005];
// int maxProfit(int *price, int start, int end, int n) {
//     int y = n - (end - start + 1) + 1;
//     if (dp[start][end] != -1) return dp[start][end];
//     if (start > end) {
//         return dp[start][end] = 0;
//     }
//     if (start == end) {
//         return dp[start][end] =  y * price[start];
//     }
//     return dp[start][end] = max(y * price[start] + maxProfit(price, start + 1, end, n), y * price[end] + maxProfit(price, start, end - 1, n));

// }

int h, l, r, n;
// int cnt = 0;
PII arr[N];
int dp[2005][2005];
// int dp;
int go(int l, int r, int i) {
    if (l > r) return 0;
    if(dp[i][l]!=-1) return dp[i][l];
    int c1 = go(l + 1, r, i + 1) + arr[i].ff * abs(arr[i].ss - l);
    int c2 = go(l, r - 1, i + 1) + arr[i].ff * abs((r - arr[i].ss));
    int &cnt = dp[i][l];
    cnt = max(c1, c2);
    return cnt;
}


// (ele + prev)%h >= l
// (ele + prev)%h <= r

// ele , ele-1

void solve() {
    cin >> n;
    // int arr[n + 1];
    // arr[0] = 0;

    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++){
        cin >> arr[i].ff;
        arr[i].ss = i;
    }
    sort(arr, arr+n);
    reverse(arr, arr+n);
    cout << go(0, n-1, 0) << endl;
}



int32_t main()
{


    nfs;
    int t;
    // facto();
    // cin >> t;
    t = 1;
    while (t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 35188
import sys
from collections import deque
from math import floor
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def Main():
    x = I()
    m = 100
    year = 0
    while m<x:
        m = floor(m*1.01)
        year += 1
    print(year)
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 9464
n = int(input())
a, b = map(int, input().split())
p = [int(i) for i in input().split()]
first = [i for i in p if i<=a]
third = [i for i in p if i>=(b+1)]
first_num = len(first)
third_num = len(third)
second_num = len(p) - first_num - third_num
print(min(first_num, second_num, third_num))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
 


int main()
{
	//ifstream cin("input.txt");
	int n, q;
	string s;
	cin>>n>>q;
	cin>>s;
	
	vi cnt(n, 0);
	rep(i, 1, n- 1)
	{
		if(s[i-1] == 'A' && s[i] == 'C')
			cnt[i] = 1 + cnt[i-1];
		else
			cnt[i] = cnt[i-1];
	}

	rep(i, 1,q)
	{
		int l,r;
		cin>>l>>r;
		l--;
		r--;
		cout<<cnt[r] - cnt[l]<<"\n";
	}
	
}

Measured memory_bytes: 4288
console.log([11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,761,811,821,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381,1451,1471].slice(0,require("fs").readFileSync("/dev/stdin", "utf8")).join(" "))

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int answer = 0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    answer += A.at(i)-1;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256