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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<string> s;


	cin >> N;
	s.resize(N);
	for (int i = 0; i < N; i++)
		cin >> s[i];

	llong sum = 0, a = 0, b = 0, ab = 0;
	for (auto &t : s) {
		if (t[0] == 'B' && t[t.size()-1] == 'A') {
			ab++;
		} else if (t[0] == 'B') {
			b++;
		} else if (t[t.size()-1] == 'A') {
			a++;
		}

		for (int i = 0; i < (int)t.size()-1; i++) {
			if (t[i] == 'A' && t[i+1] == 'B') {
				sum++;
			}
		}
	}

	cerr << ab << " " << b << " " << a << " " << sum << endl;

	if (ab > 0) {
		sum += ab-1;
		if (a > 0) {
			sum++;
			a--;
		}
		if (b > 0) {
			sum++;
			b--;
		}
	}
	sum += min(a,b);

	cout << sum << endl;

	return 0;
}

/*

冒頭がBである
冒頭がBであり文末がAである
文末がAである

＋文字列内のABの数

*/

Measured memory_bytes: 768
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val as = List.fill(n)(sc.nextInt()+1)
  val b = Array.fill(100002)(0)
  for (a <- as) {
    b(a-1) += 1
    b(a) += 1
    b(a+1) += 1
  }
  println(b.max)
}


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

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

    int count1=0;
    int count2=0;
    int count3=0;

    while(N>=100){
        count1++;
        N = N - 100;
    }
 
    while(N>=10){
        count2++;
        N = N - 10;
    }

    
    while(N>=1){
        count3++;
        N = N - 1;
    }

    if(count1==7||count2==7||count3==7){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, q;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  map<ll, ll> mp;
  ll sum = 0;

  REP(i, n) {
    ll a;
    cin >> a;
    mp[a]++;
    sum += a;
  }

  cin >> q;
  REP(i, q) {
    ll x, y;
    cin >> x >> y;

    ll t = mp[x];
    mp[x] = 0;
    sum -= x * t;
    sum += y * t;
    mp[y] += t;

    cout << sum << endl;
  }
}


Measured memory_bytes: 9560
sx,sy,tx,ty = map(int,input().split())

ans = ''

# 1周目
ans += 'D'
for _ in range(tx-sx+1):
    ans += 'R'
for _ in range(ty-sy+1):
    ans += 'U'
for _ in range(tx-sx+1):
    ans += 'L'
for _ in range(ty-sy):
    ans += 'D'

# 2周目
for _ in range(tx-sx):
    ans += 'R'
for _ in range(ty-sy+1):
    ans += 'U'
for _ in range(tx-sx+1):
    ans += 'L'
for _ in range(ty-sy+1):
    ans += 'D'
ans += 'R'

print(ans)


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

int main(){
    long long A,B,K;
    cin >> A;
    cin >> B;
    cin >> K;
    /*for(int i = 0; i<K; i++){
        if(A>0){
            A--;
        }else if(B>0){
            B--;
        }else{
            break;
        }
    }*/
    if(A<=K){
        B -= K - A;
        A = 0;
        if(B < 0) B = 0;
    }else{
        A -= K;
    }
    cout << A << " " << B << endl;
    return 0;
}

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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> p(n, k - q);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    p[a - 1]++;
  }
  for (auto e : p) cout << (e > 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int>height(n,0);
	for(int i=0;i<n;i++)
	{
		cin >> height[i];
	}
	vector<int>dp(n,1e9+5);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j : {i + 1, i + 2})
		{if(j<n)
			dp[j] = min(dp[j], dp[i] + abs(height[i] - height[j]));
		}
	}
	cout << dp[n - 1] << "\n";

}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[argc])
{
  int N;
  ull odd = 1;

  scanf("%d", &N);

  FOR(i, N) {
    int A;
    scanf("%d", &A);
    if (A % 2 == 0) odd *= 2;
  }

  printf("%llu\n", (ull)pow(3, N) - odd);
  
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
    string N; cin >> N;
    if((N.at(0) == N.at(1) && N.at(1) == N.at(2)) ||( N.at(1) == N.at(2) && N.at(2) == N.at(3))){
        cout << "Yes" << endl;

    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n1 = int(input())

t3 = 0
na4 = []
na4.append(n1)
i2 = 1
r1 = 0
while True:
    if na4[i2 - 1] % 2 == 0:
        t3 = na4[i2 - 1] // 2 
    else:
        t3 = (3 *  na4[i2 - 1] ) + 1
    for i5 in range(len(na4)):
        if na4[i5] == t3:
            r1 = len(na4) + 1
    i2 += 1
    na4.append(t3)
    if r1 != 0:
        break

print(r1)

Measured memory_bytes: 3064
N = gets.to_i
A, B = N.times.map{gets.split.map(&:to_i)}.transpose

order = N.times.sort_by{|i| A[i] + B[i]}.reverse

ans = 0
N.times do |i|
    if i%2 == 0
        ans += A[order[i]]
    else
        ans -= B[order[i]]
    end
end
puts ans

Measured memory_bytes: 14404
// ref. https://img.atcoder.jp/agc043/editorial.pdf
// ref. https://atcoder.jp/contests/agc043/submissions/11047912

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <time.h>       /* time */

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<ll> a(n);
  vector<ll> e(n); // the odd or even of a. 0 or 1.
  bool has1 = false;
  rep(i, n) {
    a[i] = (s[i] - '0') - 1; // 0,1,2
    if (a[i] == 1) { has1 = true; }
    e[i] = a[i] % 2;
  }
  // Here, calculate the answer
  {
    int ans = 0;
    rep(i, n) {
      // We want to known the contribution of (n-1)C(i) using Lucas's theorem.
      // The bit representatio of n-1 must have all bits in i. (n-1)C(i) mod 2 == 1 if ((n-1)&i) == i, else 0.
      if (((n-1)&i) != i) { continue; }
      ans ^= e[i];
    }
    if (ans == 1) { // odd case
      cout << ans << endl;
      return 0;
    }
  }

  // Here, ans is 0 or 2
  if (has1) { // 1 is in a, so ans is not 2.
    cout << 0 << endl;
    return 0;
  }

  // Here, ans is 0 or 2. a includes only 0 or 2. divide whole a by 2 and calculate same value.
  rep(i, n) {
    // 0 => 0, 2 => 1
    a[i] /= 2;
  }
  // Here, calculate the answer
  {
    int ans = 0;
    rep(i, n) {
      // We want to known the contribution of (n-1)C(i) using Lucas's theorem.
      // The bit representatio of n-1 must have all bits in i. (n-1)C(i) mod 2 == 1 if ((n-1)&i) == i, else 0.
      if (((n-1)&i) != i) { continue; }
      ans ^= a[i];
    }
    cout << ans*2 << endl;
  }
}


Measured memory_bytes: 17052
#include <bits/stdc++.h>
using namespace std;
long long ans = 1E15;
int main(){
  long long n,cnt=0,med=0;
  bool d=0;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[i] -= (i+1);
  }
  sort(a,a+n);
  if(n%2==0){
     med = (a[n/2]+a[(n-1)/2])/2;
     d = 1;
  } 
  else med = a[n/2];
  for(int j=0;j<=1;j++){
    long long sum=0;
    if(j==1&&!d) break;
    for(int i=0;i<n;i++) sum += abs(a[i]-(med+j));
    ans = min(ans,sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

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


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

    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll v[] = {a*c, a*d, b*c, b*d};
    cout << *max_element(v, v+4) << endl;

    return 0;
}


Measured memory_bytes: 3652
#![allow(non_snake_case)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        a: i32,
        b: i32,
    );
    let wa = a + b;
    if wa % 2 == 0 {
        let k = wa / 2;
        println!("{}", k);
    } else {
        println!("IMPOSSIBLE");
    }
}


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

typedef long long ll;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> h(N);
    rep(i, N) {
        cin >> h[i];
    }
    ll hi = 1e9, lo = 0;
    while (lo + 1 < hi) {
        ll mi = (hi + lo) / 2;
        //cout << lo << " " << mi << " " << hi << " ";
        ll s = 0;
        rep(i, N) {
            s += max(0LL, (h[i] - mi * B + A - B - 1) / (A - B));
        }
        //cout << s << "\n";
        if (s > mi) lo = mi;
        else hi = mi;
    }
    cout << hi << "\n";
}

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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    cout << setprecision(16) << fixed;

    string s, t;
    cin >> s >> t;

    vector<vector<ll>> dp(s.size()+1, vector<ll>(t.size()+1));
    for(ll i=1; i<=s.size(); i++)
        for(ll j=1; j<=t.size(); j++)
            dp[i][j] = max({
                    dp[i-1][j-1] + (s[i-1] == t[j-1]),
                    dp[i-1][j],
                    dp[i][j-1],
                    });

    string r;
    ll i = s.size(), j = t.size();
    while(i && j) {
        if(dp[i][j] == dp[i-1][j]) i--;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else r += s[i-1], i--, j--;
    }
    reverse(r.begin(), r.end());

    cout << r << endl;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

const int N = 7;
char a[N][N];
int n,m,k;
bool vis[1000][1000];
int go(int p,int q){
  if(p>=(1ll<<n)|| q>=(1ll<<m)|| vis[p][q])
    return 0;
  int ans = 0;
  int cnt = 0;
  vis[p][q] = 1;
  for(int i=0;i<n;i++){
    if((p&(1ll<<i))==0){
      for(int j=0;j<m;j++)
        if((q&(1ll<<j))==0&&a[i][j]=='#')
          cnt++;
    }
  }
  if(cnt == k)
    ans = 1;

  ans += go(p+1,q) + go(p,q+1) + go(p+1,q+1);
  return ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        cin>>a[i][j];
    
    cout<<go(0,0);
    return 0;
}


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

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

	vector<int> ret(n, -1);
	int retVal = 0;
	for (int i = 0; i < m; ++i) {
		int s, c;
		cin >> s >> c;

		if ((ret[s - 1] == -1) || (ret[s - 1] == c)) {
			ret[s - 1] = c;
		}
		else {
			retVal = -1;
		}
	}

	vector<int> bai(3);
	bai[0] = 1;
	bai[1] = 10;
	bai[2] = 100;

	if (retVal != -1)
	{
		for (int i = 0; i < n; ++i) {
			if (i == 0 && 1 < n) 
			{
				if (ret[0] == -1) {
					retVal += bai[n - i - 1];
				}
				else if (ret[0] == 0) {
					retVal = -1;
					break;
				}
				else {
					retVal += ret[0] * bai[n - i - 1];
				}
				continue;
			}

			if (ret[i] == -1) {
				// スルー
			}
			else {
				retVal += ret[i] * bai[n - i - 1];
			}
		}
	}

	cout << retVal << endl;

	return 0;
}

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

using namespace std;


int32_t main() {

    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

    int a,b,c;
    cin>>a>>b>>c;
    int l= a-b;
    cout<<max(0,c-l)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

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

    int n,c;
    cin >> n >> c;

    vector<vector<int>> vec(c,vector<int>(200002,0));

    for(int i = 0; i < n; i++){
        int s,t,r;
        cin >> s >> t >> r;
        for(int j = s*2-1; j < t*2; j++){
            vec[r-1][j] = 1;
        }
    }

    int result = 0;

    for(int i = 0; i < 200002; i++){
        int count = 0;
        for(int j = 0; j < c; j++){
            if(vec[j][i] == 1){
                count++;
            }
        }
        if(count > result){
            result = count;
        }
    }

    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 24576
MOD = 1000000007
H, W = (int(x) for x in input().split())
grid = []
for row in range(H):
  grid.append(input())
# Number of paths to get to end grid[i][j]
dp = [[0 for i in range(W)] for i in range(H)]
# dp[H-1][W-1] == '#' ? 1 : return 0
if grid[H-1][W-1] == '#':
  print(0)
else:
  dp[H-1][W-1] = 1

for i in range(W-2, -1, -1):
  if grid[H-1][i] == '#':
    dp[H-1][i] = 0
    continue
  dp[H-1][i] = dp[H-1][i+1]
for i in range(H-2, -1, -1):
  if grid[i][W-1] == '#':
    dp[i][W-1] = 0
    continue
  dp[i][W-1] = (dp[i+1][W-1]) % MOD

for i in range(H-2, -1, -1):
  for j in range(W-2, -1, -1):
    if grid[i][j] == '#':
      dp[i][j] = 0
    else:
      dp[i][j] = (dp[i+1][j] + dp[i][j+1]) % MOD
print(dp[0][0])

Measured memory_bytes: 83404
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<array>

using namespace std;
int main()
{int H,W; cin >> H >> W;
 string board[60];
 for(int i = 0 ; i < H; i++)
 {cin >> board[i];}
 //2次元配列board入力完了
 int idx[] = {1,1,0,-1,-1,-1,0,1};
 int idy[] = {0,1,1,1,0,-1,-1,-1};
 for(int i = 0; i  < H ; i++){//1
  for(int j = 0; j  < W ; j++){//2
     if(board[i][j] == '.'){//3
                            int cnt = 0;
     for(int k = 0; k  < 8 ; k++){//4
                                   int x = i + idx[k];
                                   int y = j + idy[k];
      
      if(x >= 0 && x < H && y >= 0 && y <  W && board[x][y] == '#')
         {cnt++;}
         }//4
      board[i][j] = '0' + cnt;}}}//3//2//1
   for(int i = 0; i < H; i++)
   {cout << board[i] <<endl;}
    return 0;}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
	
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n;
	char s, t, b;
	while (cin >> n, n)
	{
		cin >> s >> t >> b;
		s -= 'A';
		t -= 'A';
		b -= 'A';

		int sx = s % 3, sy = s / 3;
		int tx = t % 3, ty = t / 3;
		int bx = b % 3, by = b / 3;

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

		double dp[20][3][3];
		memset(dp, 0, sizeof(dp));
		dp[0][sy][sx] = 1;
		rep (i, n)
		{
			rep (y, 3)
			{
				rep (x, 3)
				{
					rep (j, 4)
					{
						int nx = x + dx[j], ny = y + dy[j];
						if (0 <= nx && nx < 3 && 0 <= ny && ny < 3
							&& !(nx == bx && ny == by))
							dp[i + 1][ny][nx] += dp[i][y][x] / 4;
						else
							dp[i + 1][y][x] += dp[i][y][x] / 4;
					}
				}
			}
		}

		printf("%.8f\n", dp[n][ty][tx]);
	}
}

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

const ll INF = 1e18;

struct edge {
    int from;
    int to;
    int cost;
};

bool BellmanFord(vector<edge> &es, vector<ll> &dist, int V, int s) {
    dist.resize(V, INF);
    dist.at(s) = 0;
    for (int i = 0; i < V; ++i) {
        for (auto &e : es) {
            if (dist.at(e.from) == INF) continue;
            dist.at(e.to) = min(dist.at(e.to), dist.at(e.from) + e.cost);
        }
    }
    for (auto &e : es) {
        if (dist.at(e.from) == INF) continue;
        if (dist.at(e.to) > dist.at(e.from) + e.cost) return false;
    }
    return true;
}

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

    int V, E, r;
    cin >> V >> E >> r;
    vector<edge> es;
    for (int i = 0; i < E; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        es.push_back(edge{s, t, d});
    }
    vector<ll> dist;
    if (BellmanFord(es, dist, V, r)) {
        for (auto &x : dist) {
            if (x == INF) {
                cout << "INF" << endl;
            } else {
                cout << x << endl;
            }
        }
    } else {
        cout << "NEGATIVE CYCLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define X first
#define Y second
#define INF 1000 * 1000 * 1000
#define PB push_back
const int MAX = 505;
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;

string s;
int n , q;
pair<char , char> p[200005];
int nah(int pos)
{
	for(int i = 0; i < q; i++)
	{
		if(p[i].X == s[pos])
			pos = pos + (p[i].Y == 'L' ?  -1 : 1);
		if(pos == -1)
			return -1;
		if(pos == n)
			return 1;
	}
	return 0;
}
int main()
{
	//init();
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n >> q >> s;
	for(int i = 0; i < q; i++)
	{
		cin >> p[i].X >> p[i].Y;
	}
	int l = -1;
	
	int r = n;
	for(int i = 17; i >= 0; i--)
	{
		if(l + (1 << i) < n && nah(l + (1 << i)) == -1)
		{
			l += (1 << i);
		}
		if(r - (1 << i) >= 0 && nah(r - (1 << i)) == 1)
		{
			r -= (1 << i);
		}
		
	}
	cout << r - l - 1 << endl;
    return 0;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<62)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,pair<auto,auto> p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,tuple<auto,auto,auto> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,pair<auto,auto> &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


bool in(Int x,Int y, Int X,Int Y,Int a,Int b){
  return x <= a && a <= X && y <= b && b <= Y;  
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n, K;
  cin>>n>>K;
  vector<P> A(n);
  cin>>A;

  Int ans = INF;
  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      for(Int k=0;k<n;k++)
	for(Int l=0;l<n;l++){
	  Int x = A[i].first;
	  Int y = A[j].second;
	  Int X = A[k].first;
	  Int Y = A[l].second;
	  Int area = (X - x) * (Y - y);
	  if(x >= X || y >= Y) continue;
	  
	  Int cnt = 0;
	  for(Int m=0;m<n;m++)
	    cnt += in(x, y, X, Y, A[m].first, A[m].second);
	  if(cnt >= K) Min(ans, area);
	}
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
nl = input().split(" ")
n = int(nl[0])
l = int(nl[1])

sum = 0

for i in range(1,n+1):
  sum = sum + l+i-1

x = 0
ans = 0
for i in range(1,n+1):
  x = sum - (l+i-1)
#  print("x:{}  ans:{} sum:{}".format(x,ans,sum))
  if abs(sum-x) < abs(sum-ans):
    ans = x
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
struct Edge{int to,cost;};
struct Node{
    int v,d;
    bool operator<(const Node&right)const{return d<right.d;}
    bool operator>(const Node&right)const{return d>right.d;}
};
int n,m,l,r,c,d[100009];
vector<Edge> e[100009];

signed main(){
    cin>>n>>m;
    for(int i=1;i<n;i++){
        e[i+1].push_back({i,0});
        d[i+1]=1e18;
    }
    rep(i,m){
        cin>>l>>r>>c;
        e[l].push_back({r,c});
    }
    priority_queue<Node,vector<Node>,greater<Node>> que;
    que.push({1,0});
    while(!que.empty()){
        Node V=que.top();
        que.pop();
        if(d[V.v]<V.d)continue;
        rep(i,e[V.v].size()){
            if(d[e[V.v][i].to]>V.d+e[V.v][i].cost){
                d[e[V.v][i].to]=V.d+e[V.v][i].cost;
                que.push({e[V.v][i].to,d[e[V.v][i].to]});
            }
        }
    }
    cout<<(d[n]<1e18?d[n]:-1)<<endl;
}

Measured memory_bytes: 10104
class Dice
  def initialize(i1, i2, i3, i4, i5, i6)
    @nums = [i1, i2, i3, i4, i5, i6]
  end
  def get_top
    @nums[0]
  end
  def move_n
    move(1, 5, 2, 3, 0, 4)
  end
  def move_s
    move(4, 0, 2, 3, 5, 1)
  end
  def move_w
    move(2, 1, 5, 0, 4, 3)
  end
  def move_e
    move(3, 1, 0, 5, 4, 2)
  end
  private
  def move(i1, i2, i3, i4, i5, i6)
    @nums[0], @nums[1], @nums[2], @nums[3], @nums[4], @nums[5] =
      @nums[i1], @nums[i2], @nums[i3], @nums[i4], @nums[i5], @nums[i6]
  end
end

nums = STDIN.gets.chomp.split(' ').map(&:to_i)
dice = Dice.new(*nums)

commands = STDIN.gets.chomp.split('')
commands.each do |c|
  case c
  when 'N' then dice.move_n
  when 'S' then dice.move_s
  when 'W' then dice.move_w
  when 'E' then dice.move_e
  end
end

puts dice.get_top

Measured memory_bytes: 8700
n,m = map(int,input().split())
ml = [list(map(int,input().split())) for i in range(m)]
l_l = []
r_l = []
for i in range(m):
    l_l.append(ml[i][0])
    r_l.append(ml[i][1])
if min(r_l) < max(l_l):
    print(0)
elif n<max(l_l):
    print(0)
elif max(l_l)<=n<=min(r_l):
    print(n-max(l_l)+1)
else:
    print(min(r_l)-max(l_l)+1)

Measured memory_bytes: 29092
#include<iostream>

#include<cstdio>

#include<cmath>

#include<cstring>

#include<algorithm>

#define maxn 1005

 

using namespace std;

int vis[maxn];

 long double dis[maxn][maxn];

 long double d[maxn];

const long double inf=1e18;

int n;

 

struct point

{

    int x,y,r;

}p[maxn];

  long double getdis(int i,int j)

{

 long double ans=(long double)sqrt((long double)(p[j].x-p[i].x)*(p[j].x-p[i].x)+(long double)(p[j].y-p[i].y)*(p[j].y-p[i].y))-(long double)p[i].r-(long double)p[j].r;

if(ans>(long double)0)

    return ans;

else

    return (long double)0;

}

void dij(int s)

{

    memset(vis,0,sizeof(vis));

    for(int i=0;i<maxn;i++)

        d[i]=(i==s)?(long double)0:inf;

        for(int i=0;i<=n+1;i++)

        {

            int x;

          long minn=inf;

            for(int y=0;y<=n+1;y++)

                if(!vis[y]&&minn>=d[y])

                minn=d[x=y];

            vis[x]=1;

            for(int y=0;y<=n+1;y++)

              d[y]=min(d[y],d[x]+dis[x][y]);

        }

}

int main()

{

    int x1,y1,x2,y2;

    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

    scanf("%d",&n);

    p[0].x=x1;

    p[0].y=y1;

    p[0].r=0;

    p[n+1].x=x2;

    p[n+1].y=y2;

    p[n+1].r=0;

    for(int i=1;i<=n;i++)

        scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].r);

        for(int i=0;i<=n;i++)

            for(int j=i+1;j<=n+1;j++)

            dis[i][j]=dis[j][i]=getdis(i,j);

        dij(0);

        printf("%.9Lf\n",d[n+1]);

 

}


Measured memory_bytes: 19584
import sys
input = sys.stdin.readline
ModNum = 10**9+7

def main():
    N = int(input())
    S = input()

    direction = [0] * (2*N)

    line = 0
    for i in range(2*N):
        if S[i]=="B" and line%2==0:
            direction[i] = 1
            line += 1
        elif S[i]=="B" and line%2==1:
            direction[i] = -1
            line -= 1
        elif S[i]=="W" and line%2==0:
            direction[i] = -1
            line -= 1
            if line < 0:
                print(0)
                break
        elif S[i]=="W" and line%2==1:
            direction[i] = 1
            line += 1
    else:
        if line>0:
            print(0)
        else:
            ans = 1
            Sum = 0           
            for i in range(2*N):  
                if direction[i]==1:
                    Sum += 1
                else:
                    ans *= Sum
                    ans %= ModNum
                    Sum -= 1
            for i in range(1,N+1):
                ans *= i
                ans %= ModNum
            print(ans)




if __name__ == "__main__":
    main()


Measured memory_bytes: 42096
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"	
	typedef long long LL;
	#define ld long double
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define INFINITE 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)	
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i]; 
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	#define precision(a) cout<<fixed<<setprecision(a);
	#define INF (1e18+5)
	#define inf (1e9+5)
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
	// 8-directions
	//int dx[]={1,1,1,0,0,-1,-1,-1};
	//int dy[]={-1,0,1,-1,1,-1,0,1};
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	int begtime = clock();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n;
		cin>>n;
		cout<<(n==0?1:0)<<endl;	
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		#ifndef ONLINE_JUDGE
    		cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    		#endif
		return 0;
	}

	
	
	
	

Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();
        char tiles[] = S.toCharArray();
        int cnt = 0;
        if(tiles.length==1) {
        	System.out.println(0); 
        }
        else {
        	for(int i=1; i<tiles.length; i++) {
        		if(tiles[i-1]!=tiles[i]) {
        			//何もしない
        		}else {
        			cnt++;
        			if(tiles[i] == '0') {
        				tiles[i] = '1';
        			}else {
        				tiles[i] = '0';
        			}
        		}
        	}
        	System.out.println(cnt); 
        }           
    }
}

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

using namespace std;

int main() {
  int a[10];
  for (int i = 0; i < 10; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + 10);
  reverse(a, a + 10);
  for (int i = 0; i < 3; i++) {
    printf("%d\n", a[i]);
  }
  return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll res = 0;
vector<ll> A(13);
ll p = 0;
ll q, ans;
struct item {
	ll a, b, c, d;
} st[55];

void dfs(int i, int j) {
	A[i] = j;
	if (i == n) {
		ll sum = 0;
		for (int i = 1; i <= q; ++i) {
			if (A[st[i].b] - A[st[i].a] == st[i].c)
				sum += st[i].d;
		}
		chmax(res, sum);
		return;
	}
	for (int k = j; k <= m; ++k)
		dfs(i + 1, k);
}
int main() {
	cin >> n;
	vector<ll> a(n);
	ll sum;
	rep(i, n) {
		cin >> a[i];
	}
	sum = a[0] ^ a[1];
	for (ll i = 2; i < n - 1; i++) {
		sum ^= a[i];
	}
	if (a[n - 1] == sum) {
		cout<<"Yes"<<endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N);
    int M = 1e6;
    vec<int> cnt(M+1);
    for(int i=0;i<N;i++){
        cin >> A[i];
        cnt[A[i]]++;
    }
    int g = accumulate(A.begin(),A.end(),0,[](int a,int b){return gcd(a,b);});
    bool pairwise = true;
    for(int i=2;i<=M;i++){
        int c = 0;
        for(int j=i;j<=M;j+=i) c += cnt[j];
        pairwise &= c<2;
    }
    if(pairwise){
        cout << "pairwise coprime\n";
    }else if(g==1){
        cout << "setwise coprime\n";
    }else{
        cout << "not coprime\n";
    }
}

Measured memory_bytes: 11108
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] h = new long[n];
    for(int i = 0;i < n;i++)h[i]=sc.nextLong();
    long[] sum = new long[n];
    sum[0]=0;
    sum[1]=Math.abs(h[0]-h[1]);
    for(int i = 2;i <= n-1;i++)
      sum[i]=Math.min(sum[i-1]+Math.abs(h[i]-h[i-1]),sum[i-2]+Math.abs(h[i]-h[i-2]));
    System.out.println(sum[n-1]);
  }
}

Measured memory_bytes: 58824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];

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

    int ans = N;
    vector<bool> existed(1000005);
    for (int i = 0; i < N; ++i) {
        int num = A[i];
        if (i < N && A[i] == A[i + 1]) {
            ans--;
            existed[num] = true;
            continue;
        }

        bool flag = false;
        for (int j = 1; j * j <= num; ++j) {
            if (num % j == 0) {
                if (existed[j] || existed[num / j]) {
                    flag = true;
                    break;
                }
            }
        }

        if (flag)
            ans--;
        existed[num] = true;
    }

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


Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    int ans = 0;
    int count = 0;
    int key = 0;
    for(int i = 0 ; i < n; i++){
        if(key != a[i]){
            if(count % 2 == 1){
                ans++;
            }
            key = a[i];
            count = 1;
            if(n-1 == i){
                if(count % 2 == 1){
                    ans++;
                }
            }
        }else{
            count++;
            if(i == n-1){
                if(count % 2 == 1){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int N; 
	cin >> N;
	
	double ans = 1.0- (double)(N/2)/(double)(N);
	std::cout<<std::fixed<<std::setprecision(10);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>M>>R;
    mat dist(N,vec(N,INF));
    vec r(R);
    rep(i,R) {
        cin>>r[i];
        --r[i];
    }
    rep(i,M){
        cin>>A>>B>>C;
        --A; --B;
        dist[A][B] = dist[B][A] = C;
    }
    rep(k,N){
        rep(i,N){
            rep(j,N){
                if(dist[i][k] + dist[k][j] < dist[i][j]){
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }
    vec per(R);
    rep(i,R) per[i] = i;
    ll ans = INF;
    do{
        ll temp = 0;
        reps(i,1,R) temp += dist[r[per[i-1]]][r[per[i]]];
        ans = min(ans, temp);
    }while(next_permutation(per.begin(), per.end()));
    cout<<ans<<endl;
}

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

int compare(const void* a, const void* b)
{
	const int* x = (int*) a;
	const int* y = (int*) b;
	if (*x > *y)
		return 1;
	else if (*x < *y)
		return -1;
	return 0;
}

int main() {
	// your code goes here
	int n,k;
	long h[200001];
	long long sum = 0;
	
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	if(k>=n){
		cout<<0;
		return 0;
	}
	qsort(h,n,sizeof(long),compare);
	for(int i=0;i<n-k;i++){
		sum = sum + h[i];
	}
	cout<<sum;
	return 0;
}

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

using namespace std;

int main(){
    long long int N,M,ans=0;
    cin >> N >> M;
    ans += min(N,M/2);
    if(N<M/2){
        M -= N*2;
        ans += M/4;
    }else{
    }
    cout << ans;
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x,y;
	cin>>x>>y;
	int X=abs(x),Y=abs(y);
	if(X==Y)
		cout<<1<<endl;
	else{
		int ans=0;
		if((X>Y&&x>=0)||(X<Y&&x<0))
			x*=-1,ans++;
		x+=abs(X-Y);
		ans+=abs(X-Y);
		if(x!=y)
			cout<<ans+1<<endl;
		else
			cout<<ans<<endl;
	}
}


Measured memory_bytes: 256
n, m = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(m)]
city = {}
city = {i:0 for i in range(1, n+1)}
for point in points:
  city[point[0]] += 1
  city[point[1]] += 1
for i in city.values():
  print(i)

Measured memory_bytes: 3060
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: i18n
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int n = s.size();
  printf("%c%d%c\n", s[0], n - 2, s[n - 1]);
  return 0;
}


Measured memory_bytes: 256
### constant

MOD = 10007

### main

loop do
  n = gets.to_i
  break if n == 0

  nbrs = n.times.map{[]}
  edges = n.times.map{{}}

  for i in (0...n)
    j0, f0, j1, f1 = gets.split.map(&:to_i)
    nbrs[i] = [j0, j1]
    
    if nbrs[j0].include?(i)
      edges[i][j0] = edges[j0][i] = f0
    end

    if nbrs[j1].include?(i)
      edges[i][j1] = edges[j1][i] = f1
    end
  end
  #p edges

  used = n.times.map{false}
  count = 1

  for ri in (0...n)
    next if used[ri]

    prj = ri
    rj = nbrs[ri][0]
    used[ri] = used[rj] = true

    max_f = edges[ri][rj]
    max_n = 1

    loop do
      rj1 = (prj == nbrs[rj][0]) ? nbrs[rj][1] : nbrs[rj][0]
      f = edges[rj][rj1]

      if max_f < f
        max_f = f
        max_n = 1
      elsif max_f == f
        max_n += 1
      end

      break if rj1 == ri

      prj = rj
      rj = rj1
      used[rj] = true
    end

    count = (count * max_n) % MOD
  end

  puts count
end

Measured memory_bytes: 13956
#include<stdio.h> 
#include<iostream> 
#include<string.h>
#include<cstring>
#include<string>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#define cuttime ios::sync_with_stdio(false)
#define swap(x, y) x ^= y, y ^= x, x^= y
#define INF 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define scan1(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define scan3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scanll1(x) scanf("%lld",&x)
#define scanll2(x,y) scanf("%lld%lld",&x,&y)
#define scanll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define lowbit(x) (x&(-x))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+20;
const int MAX=10000007;
inline int read() {
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}

inline void out(int x) {   
	if(x>9) out(x/10);   
	putchar(x%10+'0'); 
} 
int n;
int vis[N*10];
int main(){
	int n;
	cin>>n;
	ll sum=0;
	rep(i,1,n){
		if(i%3==0&&i%5==0){
			vis[i]=1;
		}
		else if(i%3==0){
			vis[i]=1;
		}
		else if(i%5==0){
			vis[i]=1;
		}
		
	}
	rep(i,1,n){
		if(!vis[i])sum+=i;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 7476
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<tuple>

using namespace std;
const long long MOD = (long long)1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> c(2 * n);
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        c[i] = {x, 0};
    }
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        c[i + n] = {x, 1};
    }
    sort(begin(c), end(c));
    long long ans = 1;
    queue<int> a, b;
    for(int i = 0; i < 2 * n; i++){
        int x, y;
        tie(x, y) = c[i];
        if(y == 0){
            if(b.empty()){
                a.push(x);
            }else{
                ans *= b.size();
                ans %= MOD;
                b.pop();
            }
        }else{
           if(a.empty()){
                b.push(x);
            }else{
                ans *= a.size();
                ans %= MOD;
                a.pop();
            }     
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String
    }

    let mut s = s;

    while s.len() > 0 {
        if s.ends_with("dream") {
            s = s[..s.len() - 5].to_string();
        } else if s.ends_with("dreamer") {
            s = s[..s.len() - 7].to_string();
        } else if s.ends_with("erase") {
            s = s[..s.len() - 5].to_string();
        } else if s.ends_with("eraser") {
            s = s[..s.len() - 6].to_string();
        } else {
            break;
        }
    }

    if s.len() == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352