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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrepn(i, n) for (int i = ((int)(n)); i > 0; --i)
#define SZ(x) ((int)(x).size())
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long K, std::vector<long long> A) {
    rep(i, min(K, 100LL)) {
        vector<ll> im(N + 1);
        rep(i, N) {
            im[max(i - A[i], 0LL)]++;
            im[min(i + A[i] + 1, N)]--;
        }
        A[0] = im[0];
        repn(i, N - 1) { A[i] = A[i - 1] + im[i]; }
    }
    rep(i, N - 1) { cout << A[i] << " "; }
    cout << A[N - 1] << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


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


int main() {
    const ll MOD = 1e+9 + 7;
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> S(N + 1, 0);
    rep(i, N) {
        S[i + 1] += S[i] + A[i];
        S[i + 1] %= MOD;
    }

    ll ans = 0;
    rep(i, N) {
        ans += S[i] * A[i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6424
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long A, B, N;
    cin >> A >> B >> N;

    if (B - 1 > N)
        cout << floor(A * N / B) - A * floor(N / B) << endl;
    else
        cout << floor(A * (B - 1) / B) - A * floor((B - 1) / B) << endl;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


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

    if(M == 1 and K == 0){
        cout << "0 0 1 1";
    }else if(K >= 1<<M or (M == 1 and K == 1)){
        cout << -1;
    } else{
        cout << K << " ";
        REP(i, 1<<M){
            if(i != K) cout << i << " ";
        }
        cout << K << " ";
        for(int i = (1<<M)-1; i >= 0; --i){
            if(i != K) cout << i << " ";
        }
    } 
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1792
if __name__ == '__main__':
    A, B, K = map(int, input().split())

    answer = 1
    cnt = 0
    for i in range(min(A, B), 1, -1):
        if A % i == 0 and B % i == 0:
            cnt += 1
        if cnt == K:
            answer = i
            break

    print(answer)

Measured memory_bytes: 3060
#include <cstdio>
constexpr int MOD = 1e9+7;
int K, M, N;

constexpr int fpm(int base, int index) {
    if (!index) return 1;
    int nb = 1LL * base * base % MOD;
    int ni = index >> 1;
    return (index & 1) ? 1LL * base * fpm(nb, ni) % MOD : fpm(nb, ni);
}
constexpr int inv2 = fpm(2, MOD-2);

int ncr(int r) {
    // (N x M - 2) choose (K - 2)
    int n = (1LL * N * M % MOD + MOD - 2) % MOD;
    int c = 1;
    for (int i = 1; i <= r; ++i) {
        c = 1LL * c * (n - (i - 1)) % MOD * fpm(i, MOD-2) % MOD;
    }
    return c;
}

int sum(int n) { return 1LL * n * (n + 1) % MOD * inv2 % MOD; }

int main() {
    scanf(" %d%d%d", &N, &M, &K);
    int ret = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            int b = N-i;
            ret = (1LL * sum(M-j-1) * b % MOD + ret) % MOD; // Forwards (>= i)
            ret = (1LL * sum(j) * (b-1) % MOD + ret) % MOD; // Backwards (> i)
            ret = (1LL * sum(b - 1) * M % MOD + ret) % MOD; // Downwards (all)
        }
    }
    ret = 1LL * ret * ncr(K-2) % MOD;
    printf("%d\n", ret);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
typedef long long int ll;


int main() {
	int a, b;
	cin >> a >> b;
	cout << a - (b < a ? 1 : 0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class fibonacci{
    
    static int[] memo = new int[45];
    
    int fib(int n){
	if(n == 0 || n == 1) return 1;
	if(memo[n] != -1) return memo[n];
	return memo[n] = fib(n - 2) + fib(n - 1);
    }
}

public class Main{
    public static void main(String[] args){

	fibonacci f = new fibonacci();

	for(int i = 0; i < 45; i++){
	    f.memo[i] = -1;
	}

	int n = new Scanner(System.in).nextInt();

	System.out.println(f.fib(n));

    }
}



Measured memory_bytes: 26084
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static System.Array;

class MainClass : Scanner
{
    static void Main()
    {
        int N = RInt();
        var csf = new int[N][];
        for (int i = 0; i < N-1; i++)
        {
            csf[i] = RInts();
        }

        for (int i = 0; i < N; i++)
        {
            long time = 0;
            for (int j = i; j < N-1; j++)
            {
                if (time <= csf[j][1])
                {
                    time = csf[j][1] + csf[j][0];
                }
                else if (time % csf[j][2] == 0)
                {
                    time += csf[j][0];
                }
                else
                {
                    time += (csf[j][2]- time%csf[j][2]) + csf[j][0];
                }
            }
            WriteLine(time);
        }
    }
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

Measured memory_bytes: 27688
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let mut n: i64 = read();
    let mut ans: String = "".to_string();

    if n == 0 {
        ans = "0".to_string();
    }
    else {
        let mut base: i64 = 2;
        while n != 0 {
            if n % base == 0 {
                ans = format!("{}{}", "0".to_string(), ans);
            } else {
                ans = format!("{}{}", "1".to_string(), ans);
                n -= base / 2;
            }

            base *= -2;
        }
    }

    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll N;
  cin >> N;
  vector<ll> X(N);
  for(int i = 0;i < N;i++)cin >> X[i];

  vector<ll> sorted(N);
  for(int i = 0;i < N;i++)sorted[i] = X[i];


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

  //基本的には,sorted[N/2-1]もしくはsorted[N/2]を出力すればよい.

  for(int i = 0;i < N;i++){
    auto itr = lower_bound(sorted.begin(),sorted.end(),X[i]);
    ll pos = itr - sorted.begin();

    if(pos >= N/2)cout << sorted[N/2-1] << endl;
    else cout << sorted[N/2] << endl;
  }
}


Measured memory_bytes: 5376
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*N
    for i in range(N-1):
        a = A[i] - 1
        B[a] += 1
    for b in B:
        print(b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int INF=1e9;


int main()
{
    fast
    int n,K; cin>>n>>K;
    int a[n]; for(int i=0;i<n;i++) cin>>a[i];
    vector<bool> dp(K+1,false);
    for(int x=0;x<=K;x++)
    {
        for(int k=0;k<n;k++)
        {
            if(x+a[k]<=K)
            {
                if(!dp[x]) dp[x+a[k]]=true;
            }             
        }
    }
    if(dp[K]) cout<<"First"; else cout<<"Second";


	return 0;
}


Measured memory_bytes: 3680
#![allow(unused)]

// ///////
// Math //
// ///////

// for i in 0 to n-1
//   sum( floor( (a * i + b) / m ) )
fn floor_sum(n: i64, m: i64, mut a: i64, mut b: i64) -> i64 {
    let mut ans = 0;
    if a >= m {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if b >= m {
        ans += n * (b / m);
        b %= m;
    }
    let y_max = (a * n + b) / m;
    let x_max = y_max * m - b;
    if y_max == 0 {
        return ans;
    }
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - (x_max % a)) % a);
    return ans;
}

fn main() {
    use proconio::*;
    input! {
    t: usize
    }
    for i in 0..t {
        input! {
        n:i64,
        m:i64,
        a:i64,
        b:i64,
        }
        println!("{}", floor_sum(n, m, a, b));
    }
}


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

class LowestCommonAncestor {
  ll N, D;
  vector<ll> depth;
  vector<vector<ll>> parent, E;

public:
  LowestCommonAncestor(ll N, ll D = 24): N(N), D(D) {
    depth.resize(N);
    parent.resize(D, vector<ll>(N));
    E.resize(N);
  }

  void add_edge(ll u, ll v) {
    E[u].push_back(v);
    E[v].push_back(u);
  }

  void init(ll root) {
    dfs(root, -1, 0);
    REP(i, 0, D - 1) REP(j, 0, N) {
      if (parent[i][j] == -1) parent[i + 1][j] = -1;
      else parent[i + 1][j] = parent[i][parent[i][j]];
    }
  }

  ll query(ll u, ll v) {
    if (depth[u] > depth[v]) swap(u, v);
    REP(i, 0, D) {
      if ((depth[v] - depth[u]) & 1LL << i) {
        v = parent[i][v];
      }
    }
    if (u == v) return u;
    for (ll i = D - 1; i >= 0; i--) {
      if (parent[i][u] != parent[i][v]) {
        u = parent[i][u];
        v = parent[i][v];
      }
    }
    return parent[0][u];
  }

  ll dist(ll u, ll v) {
    return depth[u] + depth[v] - depth[query(u, v)] * 2;
  }

private:
  void dfs(ll v, ll p, ll d) {
    parent[0][v] = p;
    depth[v] = d;
    REP(i, 0, E[v].size()) {
      if (E[v][i] != p) {
        dfs(E[v][i], v, d + 1);
      }
    }
  }
};

/* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp */
int main(void) {
  ll N;
  cin >> N;
  LowestCommonAncestor lca(N);
  REP(i, 0, N) {
    ll k;
    cin >> k;
    REP(j, 0, k) {
      ll v;
      cin >> v;
      lca.add_edge(i, v);
    }
  }
  lca.init(0);

  ll Q;
  cin >> Q;
  REP(i, 0, Q) {
    ll U, V;
    cin >> U >> V;
    cout << lca.query(U, V) << endl;
  }
}


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

using namespace std;

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

  int q, h, s, d;
  int64_t n;
  cin >> q >> h >> s >> d >> n;

  q *= 4;
  h *= 2;
  int one = min(min(q, h), s);
  int64_t ans = n * one;
  ans = min(ans, (n / 2) * d + (n - (n / 2) * 2) * one);
  // cerr << n * one << '\n';
  // cerr << (n / 2) * d + (n - (n / 2) * 2) * one << '\n';

  cout << ans << '\n';

  return 0;
}


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

using namespace std;

bool check(int n)
{
     for(int i=1;i<=9;i++)
    {
        if(n%i==0)
        {
            if((n/i)>=1 && (n/i)<=9){ return true; break; }
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    if(check(n))
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class40
    {
        static void Main()
        {
            var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = nk[0], K = nk[1];
            int ans = 1;
            long t = K;
            while (t<=N)
            {
                t *= K;
                ans++;
            }
            Console.WriteLine(ans);
        }
    }
}


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

 int main() {
  int N;
  cin >> N;
  vector<string> w(N);
  string res = "Yes";
  for (int i = 0; i < N; i++) {
    cin >> w[i];
    for ( int j = 0; j < i; j++) {
      if (w[i] == w[j]) {
        res = "No";
        break;
      }
    }
  }

  for (int i = 0; i < N-1; i++) {
    if(w[i].back() != w[i+1].front()){
      res = "No";
      break;
    }

    }

   cout << res << '\n';
 }


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

#define repd(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}
int count(int n){
	if(n%2==0){
		return count(n/2)+1;
	}else{
		return 0;
	}
}

int main(){
	//source
	int n;
	cin >> n;
	int a[n];
	int ans=0;
	rep(i,n){
		int temp;
		cin >> temp;
		ans+=count(temp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
def DFS(list,s,t):
    if s==t:
        print("YES")
        sys.exit()
    if not t in s:
        return

    for i in list:
        DFS(list,s,t+i)

list=["maerd","remaerd","esare","resare"]
s=input()
s=s[::-1]
t=""
c_index=0
while True:
    moto=c_index
    for i in list:
        index=0
        temp=c_index
        while index<len(i) and temp<len(s) and i[index]==s[temp]:
            index+=1
            temp+=1
        if index==len(i):
            c_index=temp
            break
    if c_index==len(s):
        print("YES")
        sys.exit()
    if c_index==moto:
        print("NO")
        sys.exit()

Measured memory_bytes: 3316
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	s := r.nextString()

	m := []string{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}

	i := 0
	for i = range m {
		if m[i] == s {
			break
		}
	}

	fmt.Fprintln(stdout, 7-i)
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
vector<ii> a[N];
bool visit[N];
int d[N];

void SPFA(int n) {
  fill(d, d + n, 0);
  fill(visit, visit + n, false);
  stack<int> Q;
  for (int i = 0; i < n; ++i) {
    Q.push(i);
    visit[i] = true;
  }
  while (!Q.empty()) {
    int u = Q.top();
    Q.pop();
    visit[u] = false;
    for (auto& it : a[u]) {
      int v = it.first, cost = it.second;
      if (d[v] < d[u] + cost) {
        d[v] = d[u] + cost;
        // trace(u, v, d[u], d[v]);
        if (!visit[v]) {
          visit[v] = true;
          Q.push(v);
        }
      }
    }
  }
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i) {
    a[i - 1].push_back({i, 0});
    a[i].push_back({i - 1, -1});
  }
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    if (x > y) swap(x, y);
    a[x].push_back({y, 1});
  }
  SPFA(n);
  // for (int i = 0; i < n; ++i) {
  //   trace(i, d[i]);
  // }
  printf("%d\n", d[n - 1]);
  return 0;
}


Measured memory_bytes: 10572
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 1000000007
#define pii pair<int, int>
#define PI 2*acos(0.0)


int main()
{
    io;
    long double a, b;
    cin>>a>>b;
    ll ans = a*b;
    cout<< ans;
    return 0;
}



Measured memory_bytes: 3748
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int swap = 0;
        for (int i = 0; i < n-1; i++) {
            int minj = i;
            for (int j = i+1; j < n; j++) {
                if (a[j] < a[minj])
                    minj = j;
            }
            if (minj != i) {
                int tmp = a[i];
                a[i] = a[minj];
                a[minj] = tmp;
                swap++;
            }
        }
        for (int i = 0; i < n; i++) {
            // System.out.print(a[i]+" "); // AOJ doesn't allow extra blanks.
            if (i > 0)
                System.out.print(' ');
            System.out.print(a[i]);
        }
        System.out.println("");
        System.out.println(swap);
    }
}


Measured memory_bytes: 26412
/**
    AUTHOR:Jun_SH
    TIME:2019/6/16
    PROBLEM:ABC130_a
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<(a<b?"0":"10")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<long long> a(1, 1), p(1, 1);

long long f(int N, long long X){
//    printf("N=%d, X=%d\n", N, X);
//    printf("a=%d, p=%d\n", a[N-1], p[N-1]);
    if(N==0){
//        printf("N=0\n");
        return 1;
    }
    else if(X==1){
//        printf("X=1\n");
        return 0;
    }
    else if(1<X && X<a[N-1]+2){
//        printf("X<a+2\n", X,);
        return f(N-1, X-1);
    }
    else if(X==a[N-1]+2){
//        printf("X=a+2\n");
        return p[N-1]+1;
    }
    else if(a[N-1]+2<X && X<2*a[N-1]+3){
//        printf("X<2a+3\n");
        return p[N-1]+1+f(N-1, X-a[N-1]-2);
    }
    else if(X==2*a[N-1]+3){
//        printf("X=2a+3\n");
        return 2*p[N-1]+1;
    }
}

int main(void){
    int N, i;
  	long long X;
    scanf("%d %lld", &N, &X);
    for(i=0; i<N-1; i++){
        a.push_back(2*a[i]+3);
//        printf("a[%d]=%d, ", i+1, a[i+1]);
        p.push_back(2*p[i]+1);
//        printf("p[%d]=%d\n", i+1, p[i+1]);
    }
    printf("%lld", f(N, X));
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>

#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int n;
    scanf("%d", &n);
    ll ans = 0;
    int i;
    for (i = 1; i < n; i++) {
        ll tmp = n / i;
        if (tmp && n%i==0) tmp--;
        ans += tmp;
    }
    printf("%lld\n", ans);

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 1736
from sys import setrecursionlimit
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush
from time import time
setrecursionlimit(10**9)
mod=10**9+7
inf=10**18

n=int(input())
zorocnt=0
maxcnt=0
for i in range(n):
    d1,d2=[int(x) for x in input().split()]
    if d1==d2:
        zorocnt+=1
    else:
        zorocnt=0
    maxcnt=max(maxcnt,zorocnt)

print('Yes' if maxcnt>=3 else 'No')

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

int main(){
  int N;cin>>N;
  int M[N+10];
  int ma=0;
  int sec=0;
  int A[N+10];for(int i=0;i<N;i++){
    cin>>A[i];
    if(ma<A[i]){
      sec=ma;
      ma=A[i];
  }else if(sec<A[i]){
    sec=A[i];
  }
}
int cnt=0;
for(int i=0;i<N;i++){
  if(A[i]==ma){
    cnt++;
  }
}
for(int i=0;i<N;i++){
  if(A[i]==ma&&cnt==1){
    cout<<sec<<endl;
  }else{
    cout<<ma<<endl;
  }
}
  
}

Measured memory_bytes: 2432
#include <cstdio>
#include <vector>
#include <algorithm>
#include "memory.h"
#include <string>
#include <set>

using namespace std;

int main() {
	char buf[1000];
	scanf("%s", buf);
	string s(buf);
	int gans = 1000;
	for(char ch = 'a'; ch <= 'z'; ch++) {
		int ans = 0;
		int last = -1;
		for(int i = 0; i < s.size(); i++) if (s[i] == ch) {
			ans = max(ans, i - last - 1);
			last = i;
		}
		ans = max(ans, (int)s.size() - last - 1);
		gans = min(ans, gans);
	}
	printf("%d\n", gans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
main(){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)
        cin>>c[i][j];
    }
    int s=0;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)
        s+=c[i][j];
    }
    s=s/3;
    int flag=1;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            int t=c[i][0]+c[i][1]+c[i][2]
            +c[0][j]+c[1][j]+c[2][j]-s;
            if(t!=c[i][j]*3) flag=0;
        }
    }
    if(flag)cout<<"Yes";
    else cout<<"No";
    return 0;
 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define max(a,b) (a>b)?a:b
int main(void){
	int N,W,i,j;
	int *v,*w,*dp;
	scanf("%d%d",&N,&W);
	v=calloc(N,sizeof(int));
	w=calloc(N,sizeof(int));
	dp=calloc(W+1,sizeof(int));
		for(i=0;i<N;i++){scanf("%d%d",&v[i],&w[i]);}
	for(i=0;i<N;i++){
		for(j=W;j>=w[i];j--){
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	printf("%d\n",dp[W]);
	free(v);free(w);free(dp);
	return 0;
}

Measured memory_bytes: 648
n = int(input())
a_list = sorted(list(map(int, input().split())), reverse = True)
alice = 0
bob = 0

for i in range(0, n, 2):
    alice += a_list[i]
for i in range(1, n, 2):
    bob += a_list[i]
print(alice - bob)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

//const ll mod = 1000000007;
const ll INF = 1e9;
int N, M;
string S;

void solve() {
    //cout.precision(10);
    cin >> N >> M >> S;
    vector<int> dist(N + 1, INF);
    vector<int> MostLeft(N + 1, INF);
    dist[N] = 0;
    MostLeft[0] = N;
    int Next = N-1;
    int Left = N;
    int timer = 0;
    while(true) {
        timer++;
        int newLeft = Left;
        while(Next >= Left - M && Next >= 0) {
            if(S[Next] == '0') {
                dist[Next] = timer;
                newLeft = Next;
            }
            Next--;
        }
        if(newLeft == Left) {
            cout << -1 << endl;
            return;
        }
        Left = newLeft;
        MostLeft[timer] = Left;
        if(Next < 0) break;
    }
    timer = dist[0];
    for(int i = 0; i <= N; i++) {
        cerr << dist[i] << endl;
    }
    vector<int> ans;
    int now = 0;
    while(timer >= 1) {
        timer--;
        ans.push_back(MostLeft[timer] - now);
        now = MostLeft[timer];
    }
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i];
        if(i + 1 != ans.size()) cout << " ";
    }
    cout << endl;
    return;
}

int main() {
    solve();
    return 0;
}


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

using namespace std;

int main()
{
  vector<int> a(3); cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  cout << (a[0] == a[1] and a[0] == 5 and a[2] == 7 ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define repp(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define popcnt __builtin_popcount
#define all(v) v.begin(),v.end()
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?GCD(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/GCD(a,b);}

int main(){
    double w,h,x,y; cin >> w >> h >> x >> y;
    printf("%.9f\n", w*h/2);
    if(x == w/2 && y == h/2) cout << 1 << endl;
    else cout << 0 << endl;
    
    return 0;
}


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

bool check(int n, string s) {
    if (s.length() != n) {
        return false;
    }
    string t = s.substr(0, n / 2);
    if (t + t != s) {
        return false;
    }
    return true;
}
int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    if (check(n, s)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define inf 2147483647
#define MOD 1000000007
using namespace std;
typedef pair<int,int> pii;
int n;
long long arr[202020],ans;
long long g(long long p)
{
	if(p==0) return 1;
	if(p==1) return 2;
	long long ret=g(p/2);
	if(p%2) return ((ret*ret)%MOD*2)%MOD;
	return (ret*ret)%MOD;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",arr+i);
	} if(n==1) 
	{
		printf("%lld",(arr[0]*2)%MOD); 
		return 0;
	}
	sort(arr,arr+n); long long m=(long long)n-2;
	long long t=g(m); long long start=(t*(m+3))%MOD;
	for(int i=0;i<n;i++)
	{
		ans=(ans+(start*arr[i])%MOD)%MOD;
		start=(start+MOD-t)%MOD;
	} ans*=g(m+2); ans%=MOD;
	printf("%lld",ans);
}

Measured memory_bytes: 1792
#include<algorithm>
#include<bitset>
#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<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && a != c) {
		cout << "Yes" << endl;
	}
	else if (c == b && a != c) {
		cout << "Yes" << endl;
	}
	else if (a == c && a != b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	solve();

}

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

using namespace std;

int main(){
    double a,b,x,y;
    cin >> a >> b >> x >> y;
    
    double diffx = x-a;
    double diffy = y-b;
    
    cout << fixed << setprecision(6) << sqrt((diffx * diffx) + (diffy * diffy)) << endl;
    
}


Measured memory_bytes: 3288
n = int(input())
list = [input() for i in range(n)]
ac,wa,tle,re = 0,0,0,0
for j in list:
  if j == "AC":
    ac += 1
  if j == "WA":
    wa += 1
  if j == "TLE":
    tle += 1
  if j == "RE":
    re += 1
    
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 15980
// CODEFESTIVAL 2016 B

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;

  int b_count = 0;
  int total_count = 0;
  for(int i = 0; i < n; i++) {
    if (s[i] == 'a') {
      if ((a + b) > total_count) {
        cout << "Yes" << endl;
        total_count = total_count + 1;
      } else {
        cout << "No" << endl;
      }
    } else if (s[i] == 'b') {
      b_count += 1;
      if ((a + b) > total_count && b_count <= b) {
        cout << "Yes" << endl;
        total_count = total_count + 1;
      } else {
        cout << "No" << endl;
      }
    } else {
      cout << "No" << endl;
    }

  }
  return 0;
}


Measured memory_bytes: 896
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N=200005;
vector<int>vis(N);
vector<vector<int>>adj(N);
void dfs(int v){vis[v]=1;for(auto i:adj[v]){if(!vis[i]){dfs(i);}}return;}
bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}
int root(int a[],int i){while(a[i]!=i){a[i]=a[a[i]];i=a[i];}return i;}
void unionn(int a[],int i,int j){int root_i=root(a,i);int root_j=root(a,j);a[root_i]=root_j;return;}
void fun()
{
    #ifndef ONLINE_JUDGE
    freopen("infile.txt", "r", stdin);
    freopen("oufile.txt", "w", stdout);
    #endif
}

int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
}
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
// Returns factorial of n 

signed main()
{
    flash;
    //fun();
    int t=1;
    //cin>>t;
    while(t--)
    {
    	double l;
    	cin>>l;
    	l=l/3;
    	l=l*l*l;
    	cout<<setprecision(20)<<l;
    }
    return 0;
}

Measured memory_bytes: 6528
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int x[] = new int[N];
    for(int i=0;i<N;i++){
      x[i]=sc.nextInt();
    }
    int answer =0;
    for(int i=0;i<N;i++){
      answer = answer + 2*Math.min(Math.abs(x[i]-K),x[i]);
    }
    System.out.println(answer);
  }
  

  
}


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

int main()
{
  int a, b;
  cin >> a >> b;
  vector<string> s(2, "");
  for (int i = 0; i < b; i++)
    s.at(0) += to_string(a);
  for (int i = 0; i < a; i++)
    s.at(1) += to_string(b);

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

  cout << s.at(0) << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

bool canXOR(ll a, ll b){
    if(a+b == (a^b)){
        return true;
    }else{
        return false;
    }
}

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

    // input
    int N;
    cin >> N;
    
    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    // F[i] = iからどこまで右に行けるか
    vector<ll> F(N);

    ll state = 0;
    ll head = 0; // どこまで行けるか
    // i 現在地
    FOR(i, 0, N){
        // 行けるところまで進む
        while(canXOR(state, A[head]) && head < N){
            state ^= A[head];
            head++;
        }
        F[i] = head - 1;

        // もう進めない
        if(F[i] == i){
            state = 0;
        }
        // 終了前, iの分を削除
        else{
            state -= A[i];
        }
    }

    ll answer = 0;
    FOR(i, 0, N){
        ll diff = F[i] - i + 1;
        answer += diff;
    }
    p(answer);
    
    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    long long m,k;
    cin>>m>>k;
    if(pow(2LL,m)-1<k){
        cout<<-1<<endl;
        return 0;
    }
    if(m==1 && k==1){
        cout<<-1<<endl;
        return 0;
    }
    if(k!=0){
        cout<<0<<" "<<k<<" "<<0<<" ";
        for(int i=pow(2LL,m)-1;i>=1;i--){
            if(i!=k) cout<<i<<" ";
        }
        cout<<k<<" ";
        for(int i=1;i<=pow(2LL,m)-1;i++){
            if(i!=k)cout<<i<<" ";
        }
        cout<<endl;
    }
    if(k==0){
        for(int i=0;i<=pow(2LL,m)-1;i++){
            cout<<i<<" "<<i<<" ";
        }
        cout<<endl;
    }

    
}

Measured memory_bytes: 1792
n, k = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(n)]

td.sort(key=lambda x: x[1], reverse=True)

types = set()
can_remove = []
d_sm = 0

for t, d in td[:k]:
	d_sm += d
	if t in types:
		can_remove.append(d)
	else:
		types.add(t)

type_cnt = len(types)

ans = d_sm + type_cnt ** 2

left = td[k:][::-1]

while can_remove and left:
	t, d = left.pop()
	if t not in types:
		types.add(t)
		d_rmv = can_remove.pop()
		d_sm += d - d_rmv
		type_cnt += 1
		ans = max(ans, d_sm + type_cnt ** 2)

print(ans)


Measured memory_bytes: 30800
#include<iostream>
using namespace std;
int main(void)
{
  int i,j,k,n,t[100001],x[100001],y[100001],z[100001];
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>t[i+1]>>x[i+1]>>y[i+1];
  }
  t[0]=0;
  x[0]=0;
  y[0]=0;
           
  for(i=0;i<=n;i++)
  {
    z[i]=x[i]+y[i];
  
  }
  for(i=0;i<n;i++)
  { j=abs(z[i+1]-z[i]);
    k=t[i+1]-t[i];
    if(k%2!=j%2||j>k)
    {cout<<"No"<<endl;return 0;}
  }
 cout<<"Yes"<<endl;return 0;
}

Measured memory_bytes: 5136
def abc098_d():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 0
    rt = 0
    total = 0
    for lf in range(n):
        while rt < n:
            if total ^ A[rt] == total + A[rt]:
                total += A[rt]
                rt += 1
            else:
                break
        ans += rt - lf
        if lf == rt: rt += 1
        else: total -= A[lf]
    print(ans)

if __name__ == '__main__':
    abc098_d()

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

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

  long n1 = N + 1;
  long n2 = K - 1;

  long ans = 0;
  ans += (N+1)*n1*(n1+1)/2 - n1*(n1+1)*(2*n1+1)/6 + n1;
  ans -= (N+1)*n2*(n2+1)/2 - n2*(n2+1)*(2*n2+1)/6 + n2;
  cout << ans % 1000000007 << std::endl;

  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
int n,a,la=-1,i;
long long ans=-1;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%d",&a);
		if(a>la+1)return puts("-1"),0;
		ans+=a==la+1?1:a;la=a;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#写経
#https://atcoder.jp/contests/aising2020/submissions/15195468
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

def resolve():
    T = int(input())
    for _ in range(T):
        N = int(input())
        ans = 0
        camels0 = [[] for _ in range (N)]
        camels1 = [[] for _ in range (N)]
        for _ in range(N):
            K,L,R = map(int, input().split())
            if L>R:
                camels0[K-1].append(L-R)
            elif L<R and K<N:
                camels1[N-K-1].append(R-L)
            ans += min(L,R)
        
        H = []
        for i in range(N):
            for j in camels0[i]:
                heappush(H,j)
            while len(H) > i+1:
                heappop(H)
        ans += sum(H)
        H = []
        for i in range(N):
            for j in camels1[i]:
                heappush(H,j)
            while len(H) > i+1:
                heappop(H)
        ans += sum(H)
        print(ans)
resolve()

Measured memory_bytes: 47444
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second
 
/*
//functions from gfg
 
long long int power(long long int x,long long int y,long long  int p)
{
    long long int res = 1;     // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            {//d=(long double)x/p;
            res = (res*x) % p;
            }
 
        // y must be even now
        y = y>>1; // y = y/2
        x=(x*x)%p;
        
    }
    return res%p;
}
 
long long int gcd(long long int a,long long int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
 
long long int binomialCoeff(long long int n, ll k) 
{ 
    ll res = 1; 
  
    // Since C(n, k) = C(n, n-k) 
    if (k > n - k) 
        k = n - k; 
  
    // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1] 
    for (ll i = 0; i < k; ++i) 
    { 
        res *= (n - i); 
        res /= (i + 1); 
    } 
  
    return res; 
} 
 

void sieve(int n, vector<ll> &primes) 
{ 
    vector<int> prime(n,1);
    ll p;
    for ( p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == 1) 
        { 
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 0; 
        } 
    } 
  
    for(p=2;p<=n;p++)
    {
        if(prime[p])
        primes.pb(p);
    }
   
} 


void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
    vis[src]=1;
    for(ll i=0;i<adj[src].size();i++)
    {
        if(vis[adj[src][i]]==0)
        dfs(adj,adj[src][i],vis)
    }
}
 
*/

int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    
    
	ll n,i,j,p,k,m,t,ans=0;
    cin>>n>>t;
    ll dp[3005][3005];
    memset(dp, 0, sizeof(dp)); 
    vector<ll> a(n),b(n);
    vector<pair<ll,ll> > val(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        val[i].F=a[i];
        val[i].S=b[i];
    }
    sort(val.begin(),val.end());
    for(i=0;i<n;i++)
    {
        a[i]=val[i].F;
        b[i]=val[i].S;
    }
    for(i=0;i<t;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i+a[j]<t)
            {
                dp[j+1][i+a[j]] = max(dp[j][i]+b[j],dp[j+1][i+a[j]]);
            }
            
            dp[j+1][i] = max(dp[j][i],dp[j+1][i]);
            
        }
    }
    for(i=0;i<n;i++)
    {
        ans=max(ans,dp[i][t-1]+b[i]);
    }
    cout<<ans<<endl;
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    
	return 0;
}

Measured memory_bytes: 74236
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define foreach(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<int64, int64> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}

const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(a);
    cill(b);
    cill(k);
    LL ans = 0;
    rREP(i, 1, 101){
        if(a % i == 0 && b % i == 0)
            ans++;
        if(ans == k){
            co(i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256