akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

/* main */
int main() {

    string S, op, rep_s;
    cin >> S;
    int n; cin >> n;
    int head, tail;

    while (n--) {
        cin >> op >> head >> tail;
        if (op == "replace") {
            cin >> rep_s;
            S.replace(head, tail - head + 1, rep_s);
        }
        else if (op == "reverse") {
            string rev_S = S.substr(head, tail - head + 1);
            reverse(rev_S.begin(), rev_S.end());
            S.replace(head, tail - head + 1, rev_S);
        }
        else {
            cout << S.substr(head, tail - head + 1) << '\n';
        }
    }

}




Measured memory_bytes: 3224
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: u8 = iter.next().unwrap().parse().unwrap();
    let mut numbers: Vec<u32> = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();

    let mut attempted_times = 0;
    while numbers.iter().all(|item| item % 2 == 0) {
        numbers = numbers.iter().map(|item| item / 2).collect();
        attempted_times += 1;
    }
    println!("{}", attempted_times);
}

Measured memory_bytes: 4352
function Main(input){
var a = input.split("\n")[0];
a = parseInt(a,10);
var s = input.split("\n")[1];

if (a >= 3200){
    console.log(s);
}
else {
    console.log("red");
}
}





Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
N = int(input())

R = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]

B.sort(key=lambda x: x[0])
R.sort(key=lambda x: x[0])

res = 0
for b in B:

    targets = []
    for i in range(len(R)):
        r = R[i]
        if r[0] < b[0] and r[1] < b[1]:
            targets.append(r)
        if r[0] >= b[0]:
            break

    if len(targets) == 0:
        continue
    targets.sort(key=lambda x: x[1], reverse=True)
    R.remove(targets[0])
    res += 1
print(res)

Measured memory_bytes: 3192
# coding:utf-8


def main():
    # N = int(input())
    N, X = map(int, input().split())
    L = list(map(int, input().split()))

    ans = 0
    d = 0
    i = 0
    # for i in range(len(L)):
    #     ans += 1
    #     if d > X:
    #         break
    #     d += L[i]

    while d <= X and i <= N:
        if i < N:
            d += L[i]
        ans += 1
        i += 1
        # print(ans, d, i)

    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

int main() {
  ll a, b, c;
  scanf("%lld %lld %lld", &a, &b, &c);

  bool k = false;
  if (a == b && a != c) {
    k = true;
  }
  if (a == c && a != b) {
    k = true;
  }
  if (b == c && a != c) {
    k = true;
  }

  if (k) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vector<int> F[MAX];
vector<int> B[MAX];
int N, M, K;

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

    UnionFind uf = UnionFind(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        F[a].push_back(b);
        F[b].push_back(a);

        uf.unionSet(a, b);
    }

    rep(i, K) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        B[c].push_back(d);
        B[d].push_back(c);
    }

    rep(i, N) {
        int ans = uf.size(i) - 1;
        for (auto &j : F[i]) {
            if (uf.findSet(i, j)) ans--;
        }
        for (auto &j : B[i]) {
            if (uf.findSet(i, j)) ans--;
        }
        cout << ans << " ";
    }
}

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

using namespace std;

int main() {
  int N;
  int ans = 0;
  
  cin >> N;
  
  for (int i = 1; i <= N; i++) {
    int divisor = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) {
        divisor++;
      }
    }
    
    if (i % 2 == 1 && divisor == 8) {
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}



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

#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define pb push_back
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std ;
typedef long long ll ;
const int mx=100000+5 ;
int a[mx] ;
int b[mx] ;
int c[mx] ;
int f[mx][4] ;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n ;
	cin >> n ;
	for(int i =1 ; i<= n ; i++){
		cin >> a[i] >> b[i] >> c[i] ;
	}
	f[1][1] = a[1] ;
	f[1][2] = b[1] ;
	f[1][3] = c[1] ;
	for(int i =2 ; i<= n ;i++){
		f[i][1] = a[i]+max(f[i-1][2] , f[i-1][3]) ;
		f[i][2] = b[i]+max(f[i-1][1] , f[i-1][3]) ;
		f[i][3] = c[i]+max(f[i-1][1] , f[i-1][2]) ;
	}
	cout << max(f[n][1] , max(f[n][2],f[n][3])) ;
	return 0 ;
}


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

typedef long long ll;
const int maxn = 1e5 + 5;

int main(int argc, const char* argv[]) {
    ll x, y, a, b, c, p[maxn], q[maxn], r[maxn * 3], ans = 0;
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; i++) scanf("%lld", &p[i]);
    for (int i = 0; i < b; i++) scanf("%lld", &q[i]);
    for (int i = 0; i < c; i++) scanf("%lld", &r[i]);

    sort(p, p + a, greater<ll>());
    sort(q, q + b, greater<ll>());

    for (int i = 0; i < x; i++) r[c + i] = p[i];
    for (int i = 0; i < y; i++) r[c + x + i] = q[i];

    sort(r, r + c + x + y, greater<ll>());

    for (int i = 0; i < x + y; i++) ans += r[i];

    cout << ans << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int>d(N);
  for(int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int count = 1, same = 0;
  for(int i = 0; i < N - 1; i++){
    if(d.at(i) <= d.at(i + 1)) count++;
    if(d.at(i) == d.at(i + 1)) same++;
  }
  cout << count - same << endl;
}


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

using namespace std;

int n, a[1000005], b[1000005], sum;

int main () {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for(int i = 0; i < n; i++) {
        if(a[i] > b[i]) {
            sum+=a[i];
            sum-=b[i];
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>
#include <cassert>

using ll = long long;
using ull = unsigned long long;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN;
constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX;


int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		ll tmp;
		cin >> tmp;
		if (i % 2 == 1 && tmp % 2 == 1) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	//ll n, m;
	ll a;
	string s;
	ll ans = 0;
	//double ans = 0;
	
	cin >> a >> s;

	ll c = s[0] - '0';
	ll d = s[2] - '0';
	ll e = s[3] - '0';

	ll t1 = (a * d) % 10;
	ll t2 = (a * e) % 100;
	ll t3 = (t1 * 10 + t2) / 100;
	
	ans = a * c + a * d / 10 + a * e / 100 + t3;

	cout << ans << "\n";
}

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

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 3644
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    mut b:usize,
    mut c:[usize;a],
    }
    c.sort();
    let mut d=0;
    for i in 0..a{
        if b>=c[i]{
            b-=c[i];
            d+=1;
        }
    }
    println!("{}",if d==a&&b!=0{a-1}else{d})
}

Measured memory_bytes: 2140
#include <stdio.h>

int main() {
  int kyu[8] = {8, 7, 6, 5, 4, 3, 2, 1};
  int X;
  
  scanf("%d\n", &X);
  printf("%d\n", kyu[X / 200 - 2]);
  
  return 0;
}

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

int main(){
  long A,B;
  cin >> A >> B;
  long C=A,D=B;

  do{
    if(A<B){
      A += C;
    }
    else if(A>B){
      B += D;
    }
  }while(A!=B);
  cout << A << endl;
}

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

#define lcm(a,b) (a / gcd(a,b) * b)

ll gcd(ll a,ll b){ return b ? gcd(b,a%b) : a; }
ll d[10],v[10],t[10];
int n;

int main(){
	while(cin >> n , n){
		ll g = 1;
		for(int i = 0 ; i < n ; i++){
			cin >> d[i] >> v[i];
			ll C = gcd(d[i],v[i]);
			d[i] /= C;
			v[i] /= C;
			
		}
		ll D = d[0];
		for(int i = 1 ; i < n ; i++)
			D = lcm(D,d[i]);
		for(int i = 0 ; i < n ; i++)
			t[i] = (D / d[i]) * v[i];
		ll A = t[0];
		for(int i = 1 ; i < n ; i++)
			A = gcd(A,t[i]);
			
		for(int i = 0 ; i < n ; i++)
			cout << t[i] / A << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	string o, e;
	cin >> o >> e;
	for(int i = 0; i < o.size() + e.size(); ++i){
		if(i % 2 == 0) cout << o[i/2];
		else cout << e[i/2];
	}
}


Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list("x" * K + input())

win = {"r":P,"s":R,"p":S}

ans = 0
for i in range(K, len(T)):
  if T[i] == T[i - K]:
    T[i] = "x"
  else:
    ans += win[T[i]]

print(ans)

Measured memory_bytes: 10440
/*
 
*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <deque>
 
#define ll long long
#define cint const int
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
 
using namespace std;
 
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, long long> pil;
typedef pair <int, string> pis;
typedef pair <int, char> pic;
typedef pair <long long, int> pli;
typedef pair <long long, string> pls;
typedef pair <long long, char> plc;
typedef pair <string, int> psi;
typedef pair <string, long long> psl;
typedef pair <string, char> psc;
typedef pair <char, int> pci;
typedef pair <char, long long> pcl;
typedef pair <char, string> pcs;
 
int n, m;
 
int main () {
	cin >> n >> m;
	if (n >= 10) {
	    cout << m;
	    return 0;
	}
	cout << m + (100 * (10 - n));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if(A+B>=C){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;  
}

Measured memory_bytes: 3520
#include<stdio.h>

int n, A[50];

int solve(int i, int m){
   if(m==0) return 1;
   if(i>= n) return 0;
   int res = solve(i+1,m) || solve(i+1, m-A[i]);
   return res;
}

int main(){
   int q, M, i;

   scanf("%d", &n);
   for( i=0; i<n; i++) scanf("%d", &A[i]);
   scanf("%d", &q);
   for( i=0; i<q; i++){
      scanf("%d", &M);
      if( solve(0, M)) printf("yes\n");
      else printf("no\n");
   }

   return 0;
}
 



Measured memory_bytes: 2048
#include <iostream>

int main() {
    int data[3000][2];
    int length;
    for (int i=0;i<3000;++i) {
        int x, y;
        std::cin >> x >> y;
        if (x == 0 && y == 0) {
            length = i;
            break;
        }
        else {
            if (x < y) {
                data[i][0] = x;
                data[i][1] = y;
            } else {
                data[i][0] = y;
                data[i][1] = x;
            }
        }
    }
    for (int i=0;i<length;++i)
        std::cout << data[i][0] << " " << data[i][1] << std::endl;
    return 0;
}


Measured memory_bytes: 3104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		if(a < 30){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
		
		
	}
}

Measured memory_bytes: 35712
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	int N; cin >> N;
	vector<long long> A(N + 1), B(N);
	for (int i = 0; i <= N; i++)cin >> A[i];
	for (int i = 0; i < N; i++)cin >> B[i];
	long long ans = 0;

	for (int i = 0; i < N; i++) {
		if (B[i] > A[i]) {
			ans += A[i]; B[i] -= A[i];
		}
		else {
			ans += B[i]; B[i] = 0;
		}
		if (A[i + 1] >= B[i]) {
			ans += B[i]; A[i + 1] -= B[i];
		}
		else {
			ans += A[i + 1]; A[i + 1] = 0;
		}
	}
	cout << ans << endl;

}





Measured memory_bytes: 1792
N,K = map(int,input().split())
b = K
r = N-K
mod = 10**9+7
# rのしきりr+1にi個いれる→(r+1)Ci
# bはしきりb-1にi-1個入れる→(b-1)C(i-1)

ans = (r+1)
print(ans)
for i in range(2,K+1):
    ans *= (r+1)-(i-1)
    ans *= (b-1)-(i-2)
    ans *= pow(i,mod-2,mod)
    ans *= pow(i-1,mod-2,mod)
    ans %= mod
    print(ans)

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

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  std::int_fast64_t a, b;
  std::cin >> a >> b;
  std::cout << tools::ceil<std::int_fast64_t>(a + b, 2) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Pb push_back
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 7, Mod = 1e9 + 7;
inline int Mop ( int na ) { return na >= Mod ? na - Mod : na; }

inline int R()
{
    int rt = 0; char ch = getchar(); bool isn = false;
    for ( ; ch < '0' || ch > '9'; ch = getchar() ) isn = ch == '-' ? true : isn;
    for ( ; ch >= '0' && ch <= '9'; ch = getchar() ) rt = rt * 10 + ch - '0';
    return isn ? -rt : rt;
}

inline ll Pow ( ll bs, int t )
{
	ll rt = 1;
	for ( ; t; t >>= 1, bs = bs * bs % Mod )
		if ( t & 1 )
			rt = rt * bs % Mod;
	return rt;
}

ll c[MAXN][MAXN], dp[MAXN][MAXN];
ll g[MAXN][MAXN];
ll Get ( int x, int y )
{
	if ( x == y )
		return 1;
	if ( g[x][y] != -1 )
		return g[x][y];
	return g[x][y] = Get ( x - y, y ) * c[x - 1][y - 1] % Mod;
}

int main()
{
	int n = R(), a = R(), b = R(), cl = R(), d = R();
	memset ( g, -1, sizeof g );
	for ( int i = 0; i <= n; ++i )
		c[i][0] = 1;
	for ( int i = 1; i <= n; ++i )
		for ( int j = 1; j <= i; ++j )
			c[i][j] = Mop ( c[i - 1][j - 1] + c[i - 1][j] );
	dp[a - 1][0] = 1;
	for ( int i = a; i <= b; ++i )
		for ( int j = 0; j <= n; ++j )
		{
			dp[i][j] = dp[i - 1][j];
			for ( int k = cl; k <= d; ++k )
			{
				if ( j - k * i < 0 )
					break;
				dp[i][j] = Mop ( dp[i][j] + dp[i - 1][j - k * i] * c[j][k * i] % Mod * Get ( i * k, i ) % Mod );
			}
		}
	printf ( "%lld\n", dp[b][n] );
	return 0;
}

Measured memory_bytes: 23936
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

const int MAX_V = 205;
int d[MAX_V][MAX_V];
int V;

void warshall(){
    rep(k,V){
        rep(i,V){
            rep(j,V){
                d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
            }
        }
    }
}

int main(){
    rep(i,MAX_V){
        rep(j,MAX_V){
            d[i][j] = 1e9;
        }
    }

    int n,m,r,tmpr;
    cin >> n >> m >> r;
    V = n;
    vector<int> R(r,0);
    rep(i,r){ 
        cin >> tmpr;
        R[i] = tmpr-1;
    }
    int a,b,c;
    rep(i,m){
        cin >> a >> b >> c;
        a--;b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    warshall();

    int ans = 1e9;
    int tmp = 0;
    vector<int> vec;
    for(int i = 0; i < r; i++) vec.push_back(i);
    do{
        rep(j,r-1){
            tmp += d[ R[vec[j]] ][ R[vec[j+1]] ];
        }
        if(ans > tmp) ans = tmp;
        tmp = 0; 
        
    }while(next_permutation(vec.begin(),vec.end()));

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

typedef long long ll;

const int N=3005;
int n,P,phi_p,F[N][N],C[N][N],ans;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }

int phi(int x){
	int res=1;
	for(int i=2;i*i<=x;++i){
		if(i%x==0){
			x/=i,res*=(i-1);
			while(x%i==0)x/=i,res*=i;
		}
	}
	if(x>1)res*=x-1;
	return res;
}

int pwr(int a,int k,int p=P){
	int res=1;
	for(;k;k>>=1,a=1ll*a*a%p){
		if(k&1)res=1ll*res*a%p;
	}
	return res;
}

int ways(int i){
	int res=0,arbi=pwr(2,pwr(2,n-i,phi_p)),x=pwr(2,n-i),w=1;
	rep(j,0,i){
		res=add(res,mul(F[i][j],mul(w,arbi)));
		w=mul(w,x);
	}
	return res;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	cin>>n>>P; 
	phi_p=phi(P); 
	C[0][0]=1;
	rep(i,1,n){
		C[i][0]=1;
		rep(j,1,i)C[i][j]=add(C[i-1][j-1],C[i-1][j]);
	}
	F[0][0]=1;
	rep(i,1,n){
		F[i][0]=1;
		rep(j,1,i){
			F[i][j]=add(mul(F[i-1][j],j+1),F[i-1][j-1]);
		}
	}
	rep(i,0,n){
		int w=mul(C[n][i],ways(i)); 
		if(i%2==0)ans=add(ans,w);
		else ans=sub(ans,w); 
	}
	printf("%d\n",ans); 
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    int num;
    cin >> num;
    if ((i + 1) % 2 == 1 && num % 2 == 1)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <stdio.h>

int main(void)
{int N,A,M,B,C,x,i,a,b,l,r,g,m,tmp;
	char c1[4];
	char c2[4];
	char c3[4];
	scanf("%s",c1);
	scanf("%s",c2);
	scanf("%s",c3);
	putchar(c1[0]);
	putchar(c2[1]);
	putchar(c3[2]);
	

	return 0;
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, tmpv=-1, tmpi=-1, flag=0;
vector<ll> A;
vector<pair<ll,ll>> ans;

signed main(){
    cin >> N;
    cout << 2*N-2 << endl;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        if(tmpv<abs(a)) {
            tmpv = abs(a);
            tmpi = i;
            if(a>=0) flag=0;
            else flag=1;
        }
        A.push_back(a);
    }
    //cout << tmpv << endl;
    for(int i=0;i<N;i++) {
        if(i!=tmpi) {
            cout << tmpi+1 << " " << i+1 << endl;
        }
    }
    for(int i=0;i<N-1;i++) {
        if(flag==0) {
            cout << i+1 << " " << i+2 << endl;
        }
        else {
            cout << N-i << " " << N-i-1 << endl;
        }
    }

    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> a(n);
    cin >> a;
    lli sum = accumulate(a.begin(), a.end(), 0LL);
    lli curr = 0;
    lli mn = 1LL << 60;
    for (int i = 0; i < n - 1; ++i) {
      curr += a[i];
      setmin(mn, abs(curr - (sum - curr)));
    }
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

ans = 1
prev = A[0]
state = 0
for i in range(1, N):
    if state == 0:
        if A[i] > prev:
            state = 1
        elif A[i] < prev:
            state = -1

    elif state == 1:
        if A[i] < prev:
            ans += 1
            state = 0

    else:
        if A[i] > prev:
            ans += 1
            state = 0

    prev = A[i]

print(ans)


Measured memory_bytes: 14636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void check (char *s, int n, int *a) {
    a[0] = 0;
    for (int i=1; i<n; i++) {
        if ((s[i] == 'C') && (s[i-1] == 'A')) {
            a[i] = a[i-1] + 1;
        }
        else {
            a[i] = a[i-1];
        }
    }
}

int main() {
    int n = 0, q = 0;
    scanf("%d %d\n", &n, &q);
    char s[n+2];
    fgets(s, n+2, stdin);
    int a[n];
    for (int i=0; i<n; i++) {
        a[i] = 0;
    }
    check(s, n, a);
    int l = 0, r = 0;
    for (int i=0; i<q; i++) {
        scanf("%d %d", &l, &r);
        printf("%d\n", a[r-1] - a[l-1]);
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    int t=100,ans=0;
    int x; cin>>x;
    int x1=0.01*t;
    while(1){
        t+=x1;
        // cout<<t<<"\n";
        ans++;
        if(t>=x){
            break;
        }
        x1=0.01*t;
        // cout<<x1<<"\n";
    }
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <limits.h>
 
#define MAX 2000000000
#define nMax 100000
 
typedef struct{
  int x;
  char c;
}card;
 
card M[nMax];
 
void mergeSort(int left, int right, card K[]){
  if((left + 1) < right){
    int mid = (left + right) / 2;
    mergeSort(left, mid, K);
    mergeSort(mid, right, K);
    merge(left, mid, right, K);
  }
}

void merge(int left, int mid, int right, card K[]){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  card L[nMax+1], R[nMax+1];
 
  for(i = 0; i < n1; i++){
    L[i] = K[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = K[mid+i];
  }
  L[n1].x = MAX;
  R[n2].x = MAX;
 
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    if(L[i].x <= R[j].x)
      K[k]=L[i++];
    else
      K[k]=R[j++];
  }
}

int Partition(int e, int s){
  card tmp;
  int i, j, x;
  x = M[s].x;
  i = e - 1;
 
  for(j = e; j < s; j++){
    if (M[j].x <= x){
      i++;
      tmp = M[i];
      M[i] = M[j];
      M[j] = tmp;
    } 
  }
  tmp = M[i + 1];
  M[i + 1] = M[s];
  M[s] = tmp;
  return (i + 1);
}
   
void Quicksort(int e, int s){
  int w;
  if(e < s){
     w = Partition(e, s);
     Quicksort(e, w-1);
     Quicksort(w+1, s);
  }
}
 
int main(){
  int i, p, n;
  char c;
  card N[nMax];
 
  scanf("%d%c", &n, &c);
 
  for(i = 0; i < n; i++){
    scanf("%c%d%c", &N[i].c, &N[i].x, &c);
    M[i] = N[i];
  }
 
  p = 0;
  mergeSort(0, n, N);
  Quicksort(0, n-1);
 
  for(i = 0; i < n; i++){
    if(N[i].c != M[i].c){
      printf("Not stable\n");
      break;
    }
    if(i == (n - 1))
      printf("Stable\n");
  }
   
  for(i = 0; i < n; i++){
    printf("%c %d\n", M[i].c, M[i].x);
    }
   
  return 0;
}

Measured memory_bytes: 2952
import Control.Applicative
import Data.Maybe
import qualified Data.Sequence as S
import Data.Sequence (Seq, fromList, (<|), (|>), viewl, viewr, ViewL(..), ViewR(..))
 
main = getLine >>= print . fromMaybe (-1) . solve . fromList
 
solve :: Seq Char -> Maybe Int
solve q
  | S.length q <= 1 = Just 0
  | l == r    = solve ms
  | l == 'x'  = succ <$> solve (q |> 'x')
  | r == 'x'  = succ <$> solve ('x' <| q)
  | otherwise = Nothing
  where
    (l :< rs) = viewl q
    (ms :> r) = viewr rs

Measured memory_bytes: 7548
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

int main() {
	ll n, k; cin >> n >> k;
	ll ans = 0;
	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}
	repe(b, k + 1, n) {
		ans += n / b * (b - k) + max((ll)0, ((n % b) - k + 1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(long long N, std::vector<long long> A){
    LL maxv=-1, smaxv=-1;
    rep(i, N){
        if(A[i] <= maxv && A[i] > smaxv){
            smaxv = A[i];
        }else if(A[i] > maxv){
            smaxv = maxv;
            maxv = A[i];
        }
    }
    rep(i, N){
        if(maxv != smaxv && A[i]==maxv){
            cout << smaxv << endl;
        }else{
            cout << maxv << endl;
        }
    }
}

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


Measured memory_bytes: 3200
#include<stdio.h>
int main(void){
    int n;
    int m;
    scanf("%d%d",&n,&m);
    int b[m];
    int A[n][m];
    int i,j;
    int c = 0;
    int d;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++){
        c = 0;
        for(j=0;j<m;j++){
            d = A[i][j]*b[j];
            c = c+d;
        }printf("%d\n",c);
    }
    return 0;
}

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

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

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

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(h[i] >= k){
            ans++;
        }
    }

    cout << ans << endl;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
// #define MULTIPLE_TEST_CASE
void solution() {
  int n, k;
  cin >> n >> k;
  int v[n];
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v, v + n);
  int ans = 0;
  for (int i = 0; i < k; i++) ans += v[i];
  cout << ans << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int N,M; cin >> N >> M;
    vector<int> A(M);
    REP(i,M) cin >> A[i];

    ll res = accumulate(A.begin(), A.end(), 0LL);

    (res<=N)?cout << N-res << endl : cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
char s[200200];
const int INF = 1e9;
const int A = 26;
vi p[A];
vvi g;
int mp[200200];
int n;
int dp[200200];
char res[200200];
int ds(int u) {
	if(u >= n) {return 1;}
	if(dp[u] != -1) {return dp[u];}
	int ma = INF;
	for(int i=0;i<A;i++) {
		ma = min(ma,1+ds(g[u][i]));
	}
	return dp[u] = ma;
}
int main() {
	scanf("%s ",s);
	n = strlen(s);
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++) {
		int t = s[i]-'a';
		mp[i] = t;
		p[t].push_back(i);
	}
	for(int i=0;i<A;i++) {
		mp[i+n] = i;
		p[i].push_back(n+i);
	}
	g.assign(n+A,vi(A,-1));
	int pt[A];
	memset(pt,0,sizeof(pt));
	for(int i=0;i<n;i++) {
		pt[mp[i]]++;
		for(int j=0;j<A;j++) {
			g[i][j] = p[j][pt[j]];
		}
	}
	int sz = INF;
	int mi = -1;
	for(int i=0;i<A;i++) {
		if(ds(p[i][0]) < sz) {
			mi = i;
		}
		sz = min(sz,ds(p[i][0]));
	}
	res[0] = 'a'+mi;
	int st = p[mi][0];
	for(int i=1;i<sz;i++) {
		for(int j=0;j<A;j++) {
			int u = g[st][j];
			if(ds(u) == sz-i) {
				res[i] = 'a'+j;
				st = u;break;
			}
		}
	}
	res[sz] = '\0';
	printf("%s\n",res);
}


Measured memory_bytes: 29824
#include <iostream>
using namespace std;
int main(void){
   long long int n,a[10001] = {0},max,min,sum=0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    max = a[0];
    min = a[0];
    for(long long int i=0; i<n; i++){
        if(a[i] > max){
            max = a[i];
        }
        if(a[i] < min){
            min = a[i];
        }        
    } 
    for(long long int i=0;i<n;i++){
	sum = sum + a[i];
}
    cout << min << " " << max << " " << sum;
    
    cout << endl;
     
}


Measured memory_bytes: 3188
N=gets.to_i
array=gets.chomp.split(" ").map(&:to_i)

b_array=Array.new(N,0)
N.downto(1) do |i|
    sum = 0
    target = i*2
    while target <= N do
        sum = (sum + b_array[target-1])%2
        target += i
    end
    if sum != array[i-1]
        b_array[i-1]=1
    end
end

m = 0
rets = []
b_array.each_with_index do |b,index|
    if b != 0
        m += 1
        rets.push(index+1)
    end
end
puts m
puts rets.join(" ") if m > 0


Measured memory_bytes: 33176
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    auto x = lread();
    if (x < 1200)
    {
        writeln("ABC");
        return;
    }
    writeln("ARC");
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


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

public class Main {

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        int[] nm = in.readLineAsIntArray();
        final int N = nm[0];
        final int M = nm[1];
        int[] A = in.readLineAsIntArray();
        Operation[] ops = new Operation[M];
        Arrays.sort(A);

        for (int i = 0; i < M; i++) {
            int[] bc = in.readLineAsIntArray();
            ops[i] = new Operation(bc[0], bc[1]);
        }
        Arrays.sort(ops, (x, y) -> (y.C == x.C) ? y.B - x.B : y.C - x.C);

        int[] rep = new int[N];
        int k = 0;
        for (int i = 0; i < ops.length; i++) {
            if (k >= N) {
                k = N;
                break;
            }
            Arrays.fill(rep, k, Math.min(N, k + ops[i].B), ops[i].C);
            k += ops[i].B;
        }
        long sum = 0L;

        for (int i = 0; i < N; i++) {
            if (i < k) {
                sum += Math.max(rep[i], A[i]);
            }else{
                sum += A[i];
            }
        }
        System.out.println(sum);
    }

    static class Operation {
        int B;
        int C;

        public Operation(int b, int c) {
            B = b;
            C = c;
        }

    }

    static class CustomReader extends BufferedReader {

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

    }
}

Measured memory_bytes: 51448
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> x(N), y(N);
    for(int i  =0; i < N; i++) cin >> x[i] >> y[i];
    vector<long long> z1(N), z2(N), z3(N), z4(N);
    for(int i = 0; i < N; i++){
        z1[i] = x[i] + y[i];
        z2[i] = -x[i] + y[i];
        z3[i] = x[i] - y[i];
        z4[i] = -x[i] - y[i];
    }
    sort(z1.begin(), z1.end());
    sort(z2.begin(), z2.end());
    sort(z3.begin(), z3.end());
    sort(z4.begin(), z4.end());
    long long t1 = z1[N - 1] - z1[0], t2 = z2[N - 1] - z2[0], t3 = z3[N  -1] - z3[0], t4 = z4[N  -1] - z4[0];
    cout << max(t1, max(t2, max(t3, t4))) << endl;
}

Measured memory_bytes: 12740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807
struct edge
{
  ll to;
  double cost;
  edge() {}
  edge(ll to, double cost) : to(to), cost(cost){};
};
vector<double> dijkstra(ll s, vector<vector<edge>> &g)
{
  //pair.first=距離,pair.second=点
  priority_queue<pair<double, ll>, vector<pair<double, ll>>, greater<pair<double, ll>>> q;
  vector<double> dist(g.size(), INF);
  dist[s] = 0;
  q.push({0, s});

  while (!q.empty())
  {
    pair<double, ll> p = q.top();
    q.pop();
    ll v = p.second;
    if (dist[v] < p.first)
      continue;
    rep(i, g[v].size())
    {
      edge e = g[v][i];
      if (dist[e.to] > dist[v] + e.cost)
      {
        dist[e.to] = dist[v] + e.cost;
        q.push({dist[e.to], e.to});
      }
    }
  }
  return dist;
}
int main()
{
ll xs , ys , xt , yt ;
cin >> xs >> ys >> xt >> yt ;
ll n ;
cin >> n ;
vector<vector<ll>> v(n+2, vector<ll>(3,0) );
v[0][0]=xs;
v[0][1]=ys;
v[n+1][0]=xt;
v[n+1][1]=yt;
rep(i, n)
{
  ll a, b, c;
  cin >> a >> b >> c;
  v[i+1][0]=a;
  v[i+1][1]=b;
  v[i+1][2]=c;
}
vector<vector<edge>> g(n+2);
for (ll i = 0; i < n+1; i++)
{
  for (ll j = i; j < n+2; j++)
  {
    double di=sqrt((v[i][0]-v[j][0])*(v[i][0]-v[j][0])+(v[i][1]-v[j][1])*(v[i][1]-v[j][1]))-v[i][2]-v[j][2];
    if(di<0)di=0;
    g[i].emplace_back(j,di);
    g[j].emplace_back(i,di);
  }
}

vector<double> ans = dijkstra(0, g);
cout<<fixed<<setprecision(12)<<ans[n+1]<<endl;
return 0;
}

Measured memory_bytes: 22532
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int r = sc.nextInt();
        int s = sc.nextInt();
        int p = sc.nextInt();
        String t = sc.next();
        Map<Character, Integer> map = new HashMap<>();
        map.put('r', p);
        map.put('s', r);
        map.put('p', s);
        int ans = 0;
        boolean[] win = new boolean[n];
        for (int i = 0; i < n; i++) {
            char ci = t.charAt(i);
            if (i >= k && win[i - k] && ci == t.charAt(i - k)) {
                continue;
            }
            win[i] = true;
            ans += map.get(ci);
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 28004
c11,c12,c13=map(int, input().split())
c21,c22,c23=map(int, input().split())
c31,c32,c33=map(int, input().split())

ans="No"
for a1 in range(c11+1):
    
    b1=c11-a1
    b2=c12-a1
    b3=c13-a1
    a2=c21-b1
    a3=c31-b1

    if c22==a2+b2 and c23==a2+b3 and c32==a3+b2 and c33==a3+b3:
        ans="Yes"
        break

print(ans)
    

Measured memory_bytes: 9196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(ll (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

ll p(ll a,ll n) {
    if (n <= 0)return 1;
    return a * p(a - 1, n - 1) % mod;
}
ll kaijo(ll a) {
    if (a <= 0)return 1;
    return a * kaijo(a - 1) % mod;
}

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

    int n;
    cin >> n;
    vector<ll> a(n);
    FOR(i, 0, n)cin >> a[i];

    vector<ll> ans(n);
    FOR(i, 0, n) {
        if (i % 2)ans[0] -= a[i];
        else ans[0] += a[i];
    }
    FOR(i, 1, n)ans[i] = 2 * a[i - 1] - ans[i - 1];

    cout << ans[0];
    FOR(j, 1, n)cout << " " << ans[j];
    cout << "\n";
}

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

int main(void)
{
    int n;
    cin >> n;
    set<int> arr;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        arr.insert(x);
    }
    if(n == arr.size())
        cout << "YES\n";
    else
        cout << "NO\n";
    
    return 0;
}

Measured memory_bytes: 9600
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
    I LOVE CLARICE STARLING

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥


    EXPLAINATION BELOW->
    Brute force Complete Search + Backtracking
    Read Editorial
    https://cp-algorithms.com/combinatorics/stars_and_bars.html
    https://www.youtube.com/watch?v=qvqPZkPURCo
    https://codeforces.com/blog/entry/76792?#comment-614251
    

*/
//C-Many Requirements
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
ll ans;
vector<int>a,b,c,d;
int n,m,q;
void recursion(vector<int> A)
{
    int i;
   if(sz(A)==n+1)
   {
       ll score=0;
       fo(i,0,q)
       {
           if(A[b[i]]-A[a[i]]==c[i])score+=d[i];
       }
       ans=max(ans,score);
   }
   else
   {
       int last_entered=A.back();
       fo(i,last_entered,m+1)
       {
           A.pb(i);
           recursion(A);
           A.pop_back();
       }
   }
 
}
void solve()
{
   cin>>n>>m>>q;
   int i;
   a=b=c=d=vector<int>(q,0);
   fo(i,0,q)
   cin>>a[i]>>b[i]>>c[i]>>d[i];
   
   recursion(vector<int>(1,1));
   cout<<ans<<"\n";
   
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/
/*   EXPLAINATION BELOW->
     The bank pays an annual interest rate of 1 % compounded annually. 
     P+=(P*1)/100;
*/
/*void solve()
{
   ll X,P=100;cin>>X;
   int cnt=0;
   while(P<X)
   {
       P+=(P/100);
       cnt++;
   }
   cout<<cnt<<"\n";
}*/

Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=300+10;
int n,m,modd;
int c[maxn][maxn],f[maxn][maxn],g[maxn][maxn];

inline void file() {
	freopen("AGC024E.in","r",stdin);
	freopen("AGC024E.out","w",stdout);
}

int main() {
//	file();
	scanf("%d%d%d",&n,&m,&modd);
	c[0][0]=1;
	For (i,1,n) {
		c[i][0]=1;
		For (j,1,n) c[i][j]=(c[i-1][j]+c[i-1][j-1])%modd;
	}
	For (i,0,m) f[1][i]=1,g[1][i]=i+1;
	For (i,2,n+1)
		For (j,0,m) {
			For (k,1,i-1) {
				(f[i][j]+=1ll*c[i-2][k-1]*f[i-k][j]%modd*(g[k][m]-g[k][j])%modd)%=modd;
				if (j) g[i][j]=(g[i][j-1]+f[i][j])%modd;
			}
		}
	printf("%d",(f[n+1][0]+modd)%modd);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define N 100010
int a[N], b[N], n, k;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        b[i] = a[i];
    }
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; i++)
        if ((lower_bound(b + 1, b + n + 1, a[i]) - b - i) & 1) k++;
    printf("%d\n", (k >> 1));
    return 0;
}

Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
res=10**15
for isplus in (True,False):
  cur=0
  ans=0
  for i in range(N):
    cur+=A[i]
    if isplus:
      if cur<=0:
        ans+=abs(cur-1)
        cur=1
      isplus=False
    else:
      if cur>=0:
        ans+=abs(cur-(-1))
        cur=-1
      isplus=True
  if res>ans:
    res=ans

print(res)

Measured memory_bytes: 14332
#include<stdio.h>

int main(void){
  int a[100] = {}, max, size, result = 0;
  int i;
  scanf("%d", &max);

  for(i = 0; i < max; i++){
    scanf("%d", &size);
    a[size - 1] = 1;
  }
  for(i = 0; i < 100; i++){
    result += a[i];
  }

  printf("%d\n", result);
  return 0;
}

Measured memory_bytes: 128