akhauriyash/Code-Regression huggingface dataset:
from collections import deque
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
a.sort()
a=deque(a)
ans=0

big=a.pop()
small=a.popleft()
ans+=big-small
#print(ans,a,big,small)
pre_big=big
pre_small=small
checked_a=deque([small,big])
while(len(a)>1):
    big=a.pop()
    small=a.popleft()
    ans+=pre_big-small
    ans+=big-pre_small
#    print(ans,a,big,small,pre_big,pre_small)
    pre_big=big
    pre_small=small

if(len(a)==1):
    last_a=a.pop()
    ans+=max(pre_big-last_a,last_a-pre_small)

print(ans)



Measured memory_bytes: 8120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	vector<int> a;
	int k;cin>>k;
	for(int i=0;i<4;i++){
		a.push_back(k%10);
		k/=10;
	}
	for(int i=0;i<3;i++){
		if(a.at(i)==a.at(i+1)){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;

namespace ABC125 {
  class ProblemD {
    static void Main(string[] args) {
      int n = Input.num;
      long[] a = Input.numLs;

      int cnt = 0;
      long sum = 0, min = 0;
      for (int i = 0; i < n; i++) {
        if (a[i] < 0) {
          cnt++;
          a[i] *= -1;
        }
      }
      
      if (cnt % 2 == 0) { // even
        for (int i = 0; i < n; i++) {
          sum += a[i];
        }
      } else {  // odd
        min = Min(a);
        for (int i = 0; i < n; i++) {
          if (a[i] != min) {
            sum += a[i];
          } else {
            sum -= a[i];
          }
        }
      }
      System.Console.WriteLine(sum);
    }
    public static long Min(long[] array) {
      long ret = array[array.Length - 1];
      for (int i = 0; i < array.Length - 1; i++) {
        if (ret > array[i]) {
          ret = array[i];
        }
      }
      return ret;
    }
  }
  public class Input {
    public static string str => System.Console.ReadLine();
    public static string[] strs => str.Split(' ');
    public static char[] charArr => str.ToCharArray();
    public static int num => int.Parse(str);
    public static int[] nums => Array.ConvertAll(strs, int.Parse);
    public static long numL => long.Parse(str);
    public static long[] numLs => Array.ConvertAll(strs, long.Parse);
  }
}

Measured memory_bytes: 27484
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define REP(var, num) for(int var = 0; var < num; var++)

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

    int res = 0;
    REP(i, n+1) {
        int x = i;
        int sum = 0;
        do {
            sum += x % 10;
            x /= 10;
        } while(x > 0);

        if (a <= sum && sum <= b) {
            res += i;
        }
    }

    cout << res << endl;
    return 0;
}

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

const int N = 2e5 + 1;

int a[N], b[N], c[N];
int lb[N], rb[N];

int main () {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
		scanf("%d", a + i);
	for (int i = 1; i <= n; i ++)
		scanf("%d", b + i);

	for (int i = 1; i <= n; i ++)
		rb[a[i]] = i;
	for (int i = n; i >= 1; i --)
		lb[b[i]] = i;

	int sh = 0;
	for (int i = 1; i <= n; i ++) if (lb[i] && rb[i])
		sh = max(sh, rb[i] - lb[i] + 1);

	for (int i = 1; i <= n; i ++)
		c[(i + sh > n) ? (i + sh - n) : (i + sh)] = b[i];

	int ok = 1;
	for (int i = 1; i <= n; i ++) if (a[i] == c[i])
		ok = 0;

	if (ok) {
		puts("Yes");
		for (int i = 1; i <= n; i ++)
			printf("%d%c", c[i], "\n "[i != n]);
	} else {
		puts("No");
	}
}


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

const int N = 2e5 + 5;
typedef long long ll;

int a[N], dp[N];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dp[a[i]] = dp[a[i] - 1] + 1;
	}
	int ans = n + 1;
	for (int i = 0; i < n; i++) {
		ans = min(ans, n - dp[a[i]]);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int x, y, z; cin >> x >> y >> z;
    rep(i, x + 1) { //人数
        if (i * y + (i - 1) * z > x - 2 * z) { out(i - 1); break; }
    }
}




Measured memory_bytes: 256
def make_divisors(n):
    lower, upper = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n//i)
        i += 1
    return lower + upper[::-1]

cnt = 0
for i in range(1, int(input())+1, 2):
    if len(make_divisors(i)) == 8:
        cnt += 1
print(cnt)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, y,z, swap;
  cin >> x >> y >> z;

  swap = x;
  x = y;
  y = swap;

  swap = x;
  x = z;
  z = swap;

  cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
char*p,x[1<<17],b[1001],*q;
A(){for(;p>x&&p[-1]-10;)p--;}
E(){for(;*p>10;)p++;}
F(){if(*p)p++;}
B(){if(p>x)p--;}
main(c){
	for(p=x;p<x+13||strcmp(p-13,"\nEND_OF_TEXT\n");p++)
		*p=getchar();
	p[-13]=0;
	for(p=x;~scanf("%s",&c);)
		c-'a'?
		c-'e'?
		c-'p'?
		c-'n'?
		c-'f'?
		c-'b'?
		c-'d'?
		c-'k'?
		c-'y'?
		puts(x)
		:(memmove(p+strlen(b),p,strlen(p)+1),memcpy(p,b,strlen(b)),p+=strlen(b))
		:(q=p,*p-10?E():p++,b[p-q]=!memcpy(b,q,p-q),p=memmove(q,p,strlen(p)+1))
		:*p&&memmove(p,p+1,strlen(p))
		:B()
		:F()
		:A(F(E()))
		:A(B(A()))
		:E()
		:A();
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main() {
    ll n;
    cin >> n;

    ll div = floor(sqrt(n));

    while (div >= 2) {
        if (floor((double) n / div) == ceil((double) n / div)) {
            MSG((n / div - 1) + (div - 1))
            exit(0);
        }
        div--;
    }
    MSG((n / div - 1) + (div - 1))
}


Measured memory_bytes: 256
N,x = gets.to_i,gets
c,x = x.scan(?1).count, x.to_i(2)
R = [1,-1].map { m = c+_1; x%m if m>1 }
D = R.map { _1 ? 1 : 0 }
M = {0=>1}
X = (0...N).map {|n|
  b = x[n]
  d,r,m = D[b],R[b],c+1-b-b
  D[0] -= c+1  if c < D[0]<<=1
  D[1] -= c-1  if c-1 <= D[1]<<=1
  if m < 2
    m - 2
  elsif b > 0
    (0 > r-=d) ? r+m : r
  else
    (c < r+=d) ? r-m : r
  end
}.reverse!
I = [*0...N].sort_by! {X[_1]}
S = []
I.each {|i|
  next  if 1 > x=X[i]
  until c=M[x]
    S << x
    b,c = x+x,0
    c+=b[0] while 0 < (b>>=1)
    x %= c
  end
  M[x] = c+=1  while x=S.pop
}
X.each {|x| p x<0 ? x+2 : M[x]}

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

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


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

int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    
    
	ll n,i,j,p,k,m,ans=0;
    
    string s;
    cin>>s;
    n=s.length()+1;
    vector<ll> bef(n,0),lar(n,0);
    for(i=0;i<n-1;i++)
    {
        if(s[i]=='<')
        {
            bef[i+1]=bef[i]+1;
        }
    }
    for(i=n-2;i>=0;i--)
    {
        if(s[i]=='>')
        {
            lar[i] = lar[i+1]+1;
        }
    }
    for(i=0;i<n;i++)
    {
        ans+=max(lar[i],bef[i]);
    }
    cout<<ans<<endl;
    
    
    
    
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    
	return 0;
}

Measured memory_bytes: 11604
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

x, y = map(int, input().split())
mod = 10**9 + 7
if (x + y) % 3 != 0:
    print(0)
    exit()
n = (2*y - x)//3
m = (2*x - y)//3

print(cmb(n+m, n, p))


Measured memory_bytes: 128584
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll n;
    cin >> n;
    string s = "";
    while(n > 0){
        s += char((n-1)%26 + 'a');
        n = (n-1)/26;
    }
    reverse(s.begin(),s.end());
    cout << s << endl;
    return 0;
}

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

int main(void){
    int n,q;
    cin >> n >> q;

    priority_queue<int> pq[n];

    for(int i=0; i<q; i++){
        int cmd;
        cin >> cmd;

        if(cmd==0){
            int t,x;
            cin >> t >> x;
            pq[t].push(x);
        }
        else if(cmd==1){
            int t;
            cin >> t;
            if(!pq[t].empty()){
                cout << pq[t].top() << "\n";
            }
        }
        else if(cmd==2){
            int t;
            cin >> t;
            if(!pq[t].empty()){
                pq[t].pop();
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4164
#include <stdio.h>

int main( void )
{
  int a, b, c;
  scanf( "%d %d %d", &a, &b, &c );
  if ( a < b && a < c ) {
    printf( "%d", a );
    if ( b < c ) {
      printf( " %d %d\n", b, c );
    }
    else {
      printf( " %d %d\n", c, b );
    }
  }
  else if ( b < a && b < c ) {
    printf( "%d", b );
    if ( a < c ) {
      printf( " %d %d\n", a, c );
    }
    else {
      printf( " %d %d\n", c, a );
    }
  }
  else {
    printf( "%d", c );
    if ( a < b ) {
      printf( " %d %d\n", a, b );
    }
    else {
      printf( " %d %d\n", b, a );
    }
  }
  return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<vector<int>> Graph;

int main() {

	int n;
	cin >> n;
	vector<int>a(n + 1);
	rep(i, n)
		cin >> a[i];
	a[n] = 1000000001;

	int ans = 0;
	int now = 0;
	rep(i, n) {
		if (a[i] >= a[i + 1])
			now++;
		else {
			ans = max(now, ans);
			now = 0;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    double S = W * H / 2.0;
    cout << S << ' ';
    if (W / 2 == x and H / 2 == y) {
        cout << 1 << endl;
        return 0;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	nextReader = newScanner()
	h, n := nextInt(), nextInt()
	as := nextInts(n)
	for _, a := range as {
		h -= a
	}
	if h <= 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


Measured memory_bytes: 1920
import collections

def solve(S, Q, queries):
    S = collections.deque(S)
    is_reversed = False
    for q in queries:
        if q[0] == "1":
            is_reversed = not is_reversed
        else:
            _, f, c = tuple(q.split(" "))

            if is_reversed:
                f = "2" if f == "1" else "1"

            if f == "1":
                S.appendleft(c)
            else:
                S.append(c)

    if is_reversed:
        S = reversed(S)

    return "".join(S)

if __name__ == "__main__":
    S = input()
    Q = int(input())
    queries = []
    for _ in range(Q):
        queries.append(input())

    print(solve(S, Q, queries))


Measured memory_bytes: 21204
// AUTHOR - RUTVIK KOTHARI
// DAIICT , GANDHINAGAR

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

#define ll long long int
#define ull unsigned long long
#define pll pair<ll,ll>
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define INFL LLONG_MAX
#define pb push_back
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll N = 1e5 + 5;
const ll M = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll m1 = 1e9 + 7;
const ll m2 = 1e9 + 9;
const ll p1 = 402653189;
const ll p2 = 1610612741;
const int LN = 32;

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

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

ll pw[LN],fact[N],invfact[N];

void pre()
{
    fact[0]=1;
    for(int i=0;i<LN;i++)pw[i]=power(2,i);
    for(int i=1;i<N;i++)fact[i]=(i*fact[i-1])%mod;
    for(int i=0;i<N;i++)invfact[i]=powermodm(fact[i],mod-2,mod);
}

ll ans[N];

int main()
{
    FIO;
    //pre();

    ll i,j;
    
    string s;
    cin>>s;
    
    
    for(i=0;i<s.length()-1;i++)
    {
        if(s[i]=='R' && s[i+1]=='L')
        {
            for(j=i;j>=0;j--)
            {
                if(s[j]=='L')break;
                
                if((i-j)%2)
                    ans[i+1]++;
                else
                    ans[i]++;
            }
            
            for(j=i+1;j<s.length();j++)
            {
                if(s[j]=='R')break;
                
                if((j-i-1)%2)
                    ans[i]++;
                else
                    ans[i+1]++;
            }
        }
    }
    
    for(i=0;i<s.length();i++)
        cout<<ans[i]<<" ";
    
    return 0;
}

Measured memory_bytes: 1488
N=int(input())
P=list(map(float,input().strip().split(' ')))
dp=[[0]*(N+1) for i in range(N)]
for i in range(N):
    for j in range(0,i+2):
        if i==0:
            dp[0][0]=1-P[0]
            dp[0][1]=P[0]
        else:
            if j>0:
                dp[i][j]=dp[i-1][j-1]*P[i]+dp[i-1][j]*(1-P[i])
            else:
                dp[i][j]=dp[i-1][j]*(1-P[i])
print(sum(dp[-1][(N+1)//2:]))

Measured memory_bytes: 266248
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let k = get!(usize);
    println!("50");
    let mut vec = vec![49;50];
    vec[0] = 0;
    if k%50 == 0 {
        for i in 0..50 {
            print!("{} ", vec[i]+k/50);
        }
        println!("");
        return;
    }
    print!("{} ", vec[0]+50+k/50-k%50+1);
    for i in 1..k%50 {
        print!("{} ", vec[i]+50+k/50-k%50);
    }
    for i in k%50..50 {
        print!("{} ", vec[i]+k/50-k%50);
    }
    println!("");
}


Measured memory_bytes: 8572
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

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

    return false;
}

int n,m,s,g1,g2;
int d[102][102];
void solve() {
    s--;
    g1--;
    g2--;
    rep(i,102) rep(j,102) d[i][j]=INF;
    rep(i,102) d[i][i]=0;
    rep(i,m) {
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        d[a][b]=c;
    }
    rep(k,n) rep(i,n) rep(j,n) {
        chmin(d[i][j],d[i][k]+d[k][j]);
    }
    int ans=INF;
    rep(v,n) {
        int t=d[s][v];
        t+=d[v][g1]+d[v][g2];
        chmin(ans,t);
    }
    cout<<ans<<endl;
}
int main() {
    while(cin>>n>>m>>s>>g1>>g2) {
        if(!n) break;
        solve();
    }
    return 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

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

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define INF 		2000000007
#define MINF		-2000000007
#define MAX 		100005

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

int K;
ll dp[MAX];
vector<vector<pair<int,int>>> tree(MAX);

void dfs(int s,int p,ll suml){
	for(auto itr : tree[s]){
		if(itr.first == p)continue;
		dp[itr.first] = suml + itr.second;
		dfs(itr.first,s,suml + itr.second);
	}
}

// agc070
int main(){
	int N;cin>>N;
	REP(i,N-1){
		int a,b,c;
		cin >> a >> b >> c;
		tree[a-1].push_back(make_pair(b-1,c));
		tree[b-1].push_back(make_pair(a-1,c));
	}
	int Q;
	cin>>Q>>K;

	dfs(K-1,K-1,0);

	REP(i,Q){
		int x,y;cin>>x>>y;
		cout << (dp[x-1]+dp[y-1]) << endl;
	}

	//REP(i,N)cout << dp[i] << " ";
	//cout << endl;


	return 0;
}




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

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

    int A, B;
    cin >> A >> B;
    int ans = 0;
    for (int N = A; N <= B; ++N) {
        string s = to_string(N);
        string t = s;
        reverse(t.begin(), t.end());
        ans += s == t;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100003;
ll i,n,m,a,b;
vector<vi> adj(N);
ll in[N],out[N];
void dfs1(ll v,ll par)
{
    in[v] = 1;
    for(auto it: adj[v]) if(it != par){
        dfs1(it,v);
        in[v] = (in[v] * (1 + in[it]) % m) % m;
    }
}
void dfs2(ll v,ll par)
{
    ll sz = adj[v].size();
    vi pre(sz), suf(sz);
    for(ll i = 0;i < sz;i += 1){
        auto it = adj[v][i];
        if(it == par){
            if(i) pre[i] = pre[i - 1];
            else
                pre[i] = 1;
        }
        else{
            if(i) pre[i] = (pre[i - 1] * (1 + in[it])) % m;
            else
                pre[i] = (1 + in[it]) % m;
        }
    }
    
    for(ll i = sz - 1;i >= 0;i -= 1){
        auto it = adj[v][i];
        if(it == par){
            if(i < sz - 1) suf[i] = suf[i + 1];
            else
                suf[i] = 1;
        }
        else{
            if(i < sz - 1) suf[i] = (suf[i + 1] * (1 + in[it])) % m;
            else
                suf[i] = (1 + in[it]) % m;
        }
    }
    
    ll Pre, Suf;
    for(ll i = 0;i < sz;i += 1){
        auto it = adj[v][i];
        if(it == par) continue;
        Pre = Suf = 1;
        if(i) Pre = pre[i - 1];
        if(i < sz - 1)
            Suf = suf[i + 1];
        out[it] = (((out[v] * Pre) % m * Suf) % m + 1) % m;
        dfs2(it,v);
    }
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,1,n){
        cin>>a>>b;
        adj[a].pb(b); adj[b].pb(a);
    }
    dfs1(1,1);
    out[1] = 1;
    dfs2(1,1);
    rep(i,1,n + 1) cout<<(in[i] * out[i]) % m<<endl;
    return 0;
}

Measured memory_bytes: 23168
#include<iostream>
#define re register
using namespace std;
int da[100005];
int ans[100005];
long long add;
int main(){
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> da[i];
		add += da[i];
	}
	ans[N] = add;
	for(int i = 1;i<=N-2;i+=2){
		ans[N] -= (da[i] << 1);
	}
	for(int i = N-1;i>=1;i--){
		ans[i] = (da[i] - ((ans[i+1])>>1))<<1;
	}
	for(int i = 1;i<=N;i++){
		cout << ans[i] <<' ';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(), v.end()
using namespace std;
typedef pair<int,int> PII;

int P[100]; //union_find

int root(int i){
    if(P[i] == i) return i;
    else return P[i] = root(P[i]);
}

bool same(int x, int y){
    return root(P[x]) == root(P[y]);
}

void unite(int x, int y){
    P[root(x)] = root(y);
}

int main(){
    int n;
    cin >> n;
    int g[n][n];
    vector<pair<int,PII> > V;
    REP(i,n){
        REP(j,n){
            cin >> g[i][j];
            if(i<j && g[i][j] >= 0) V.pb(mp(g[i][j],mp(i,j)));
        }
    }
    sort(all(V));
    REP(i,n){
        P[i] = i;
    }
    int wsum = 0, count = 0;
    REP(i,n*n){
        int x = V[i].snd.fst;
        int y = V[i].snd.snd;
        if(same(x,y)) continue;
        unite(x,y);
        wsum += V[i].fst;
        count++;
        if(count == n-1) break;
    }

    cout <<wsum<<endl;

    return 0;
}

Measured memory_bytes: 1328
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=' ';
	ll f=1,x=0;
	while(!isdigit(ch)){ch=getchar();if(ch=='-')f*=-1;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return f*x;
}
struct pizza
{
	ll x;
	ll v;
}e[100010];
bool cmp(pizza d1,pizza d2){return d1.x<d2.x;}
ll a[100010],b[100010],c[100010],d[100010],maxa[100010],maxb[100010],maxc[100010],maxd[100010];
int main()
{
	ll n=qr,C=qr;
	for(int i=1;i<=n;i++)in(e[i].x),in(e[i].v);
	sort(e+1,e+1+n,cmp);
	e[n+1].x=C;
	for(int i=1;i<=n;i++)a[i]=a[i-1]+e[i].v-2*(e[i].x-e[i-1].x),b[i]=b[i-1]+e[i].v-(e[i].x-e[i-1].x);
	for(int i=n;i>=1;i--)c[i]=c[i+1]+e[i].v-2*(e[i+1].x-e[i].x),d[i]=d[i+1]+e[i].v-(e[i+1].x-e[i].x);
//	for(int i=1;i<=n;i++)cout<<b[i]<<" ";cout<<endl;
//	for(int i=1;i<=n;i++)cout<<d[i]<<" ";cout<<endl;
	maxa[0]=maxb[0]=maxc[n+1]=maxd[n+1]=-C-1;
	for(int i=1;i<=n;i++)maxa[i]=max(maxa[i-1],a[i]),maxb[i]=max(maxb[i-1],b[i]);
	for(int i=n;i>=1;i--)maxc[i]=max(maxc[i+1],c[i]),maxd[i]=max(maxd[i+1],d[i]);
//	for(int i=1;i<=n;i++)cout<<maxb[i]<<" ";cout<<endl;
//	for(int i=1;i<=n;i++)cout<<maxd[i]<<" ";cout<<endl;
	ll ans=-C-1;
	for(int i=0;i<=n;i++)
	{
		ans=max(ans,maxb[i]),ans=max(ans,maxd[i]);
		ans=max(ans,maxa[i]+maxd[i+1]),ans=max(ans,maxb[i]+maxc[i+1]);
	}
	cout<<max(ans,0LL);
	return 0;
}

Measured memory_bytes: 8064
def soinsu(n):
    insu = []
    tmp = n
    if n == 1:
        insu.append([1,0])
        return insu
    for i in range(2,int(n**0.5)+1):
        cnt = 0
        if tmp % i == 0:
            while(tmp % i == 0):
                tmp //= i
                cnt += 1
            insu.append([i,cnt])
    if tmp != 1:
        insu.append([tmp,1])
    if len(insu) == 0:
        insu.append([n,1])
    return insu

n = int(input())
a = [0]*(int(n**0.5)+1)
cnt=1
for i in range(1,len(a)):
    for j in range(cnt,cnt+i+1):
        if j < len(a):
            a[j] = i
            cnt += 1
        else:
            break
sum = 0
insu = soinsu(n)

for i in range(len(insu)):
    sum += a[insu[i][1]]
print(sum)

Measured memory_bytes: 81848
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;

    cout << (char)(s1.at(0)-32) << (char)(s2.at(0)-32) << (char)(s3.at(0)-32) << endl;

}




Measured memory_bytes: 3548
#include <iostream>
#include <string>

using namespace std;


void displayAnswer(const string& str) {
	for(auto ite = str.rbegin(); ite != str.rend(); ++ite)
		cout << *ite;
	cout << endl;
}


void doAllProcess() {
	string buffer;

	getline(cin, buffer);

	displayAnswer(buffer);
}


int main() {
	doAllProcess();

	return 0;
}


Measured memory_bytes: 3176
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long cyaku = 0;
        long dyaku = 0;

        long max = b - a + 1;

        cyaku = (b / c) - ((a-1) / c);


        dyaku = (b / d) - ((a-1) / d);


        long yakusum = cyaku + dyaku;

        long lcm = lcm(c, d);
        yakusum -= (b / lcm) - ((a-1) / lcm);

        System.out.println(max - yakusum);
    }

    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (c/b);
    }
}

Measured memory_bytes: 23892
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var s = Console.ReadLine();

        var dp = new int[s.Length + 1][];
        for (int i = 0; i < dp.Length; ++i)
            dp[i] = new int[13];

        dp[0][0] = 1;

        for (int i = 0; i < s.Length; ++i)
        {
            var prev = dp[i];
            var now = dp[i + 1];

            if (s[i] == '?')
            {
                for (int j = 0; j < 10; ++j)
                {
                    for (int k = 0; k < prev.Length; ++k)
                    {
                        var t = (10 * k + j) % 13;
                        now[t] += prev[k];
                        now[t] %= MOD_N;
                    }
                }
            }
            else
            {
                var c = s[i] - '0';
                for (int j = 0; j < prev.Length; ++j)
                {
                    now[(10 * j + c) % 13] = prev[j];
                }
            }
        }

        Console.WriteLine(dp[dp.Length - 1][5]);
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 29272
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  string s;
  cin >> s;
  int num[3] = {};
  rep(i, s.size())
    num[s[i]-'a']++;
  sort(num, num+3);
  if (num[2]-num[0] <= 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

int main(void){
    int n;
    cin>>n;
    int d[n];
    for(int i=0; i<n; i++){
        cin>>d[i];
    }
    sort(d,d+n);
    cout<<d[n/2]-d[n/2-1]<<endl;
    return 0;
}

Measured memory_bytes: 3964
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long

int out6(ll x){
  int tmp =100000;
  while(tmp>0){
    cout << x/tmp;
    x=x%tmp;
    tmp/=10;
  }
  return 0;
}

int main(){
    ll N,M;
    cin >> N >> M;
    ll i;
    vector< pair<ll,ll> > cities1;
    vector< pair<ll,ll> > cities2;
    ll a,b;
    for(i=0;i<M;i++){
      cin >> a >>b;
      cities1.push_back(make_pair(b,a));
      cities2.push_back(make_pair(b,i));
    }
    sort(cities1.begin(),cities1.end());
    sort(cities2.begin(),cities2.end());
    ll cnt[N];
    for(i=0;i<N;i++){
      cnt[i]=0;
    }
    vector< pair<ll,ll> > citynumbers1;
    vector< pair<ll,ll> > citynumbers2;
    for(i=0;i<M;i++){
      cnt[cities1[i].second-1]++;
      citynumbers1.push_back(make_pair(cities2[i].second,cnt[cities1[i].second-1]));
      citynumbers2.push_back(make_pair(cities2[i].second,cities1[i].second));
    }
    sort(citynumbers1.begin(),citynumbers1.end());
    sort(citynumbers2.begin(),citynumbers2.end());
    for(i=0;i<M;i++){
      out6(citynumbers2[i].second);
      out6(citynumbers1[i].second);
      cout << endl;
    }
    return 0;
}


Measured memory_bytes: 10340
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    set<string> d;
    string q, s;
    REP(i, n) {
        cin >> q >> s;
        if (q == "insert") {
            d.emplace(s);
        } else {
            if (d.count(s)) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
}



Measured memory_bytes: 29760
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 int N;
  cin >>N;
  if(N<10) {
    cout <<N<< endl;
  }
  else if((N<100) &&(N>=10)) {
    cout <<9<< endl;
  }
else if ((N<1000) &&(N>=100)) {
cout <<9+(N-100)+1<< endl;
}
  else if ((N<10000) &&(N>=1000)){
cout << 9+900<< endl;
  }
  else if ((N<100000) &&(N>=10000)) {
cout <<909+(N-10000)+1<< endl;
  }
  else if(N==100000) {
cout <<90909<< endl;
  }
}


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

inline int read() {
	int ret, cc;
	while (!isdigit(cc = getchar()));
	ret = cc - 48;
	while ( isdigit(cc = getchar()))
		ret = cc - 48 + ret * 10;
	return ret;
}

const int MAXN = 100010;

std::vector<int> G[MAXN];

int dp[MAXN][20];
int A[MAXN];
int B[MAXN];
int C[MAXN];
int n, m, q;

void Dfs(int u, int d, int t) {
	if (d < 0) return;
	if (dp[u][d] >= t) return;
	dp[u][d] = t;
	for (auto v : G[u]) Dfs(v, d - 1, t);
}

int main() {
	n = read(), m = read();
	for (int i = 1, x, y; i <= m; ++i) {
		x = read(), y = read();
		G[x].push_back(y), G[y].push_back(x);
	}
	q = read();
	for (int i = 1; i <= q; ++i) 
		A[i] = read(), B[i] = read(), C[i] = read();
	for (int i = q; i >= 1; --i) Dfs(A[i], B[i], i);
	for (int i = 1; i <= n; ++i) {
		int x = 0;
		for (int j = 0; j <= 10; ++j) 
			x = std::max(x, dp[i][j]);
		printf("%d\n", C[x]);
	}
}


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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<pair<int,int>> vpi;

const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
    int n;cin>>n;
    int a[n];
    FOR(i,0,n) cin>>a[i];
    ll s=0;
    FOR(i,1,n){
        if(a[i]<a[i-1]){
            s += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout<<s<<"\n";
    
}





int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t=1;
    //cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": "; 
        solve();
    }
    
	return 0;
	
	
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  int P=(N+1)/2;
  double ans=P*1.0/N;
  printf("%.10lf\n",ans);
  }


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    int k;
    int a,b;
    cin >> k>> a>> b;
    bool ok =0;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            ok=1;
        }
    }
    if(ok){
        cout<<"OK"<<endl;
    }else{
        cout<<"NG"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3604
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')[0].split(' ')
x = inp.shift() * 1
y = inp.shift() * 1
if (x == 2 || y == 2) {
    ans = 'No'
} else if (
    (x == 4 || x == 6 || x == 9 || x == 11)
    &&
    (y == 4 || y == 6 || y == 9 || y == 11)
) {
    ans = 'Yes'
} else if (
    (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12)
    &&
    (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)
) {
    ans = 'Yes'
} else {
    ans = 'No'
}
console.log(ans)

Measured memory_bytes: 7372
#include <iostream>
using namespace std;
int main(){
    int N,a,b,c,d,i,j;
    cin>>N;
    int S[N+1];
    int rank[N+1];
    for(i=1;i<=N;i++){
        S[i]=0;
        rank[i]=1;
    }
    for(i=0;i<N*(N-1)/2;i++){
        cin>>a>>b>>c>>d;
        if(c==d){
            S[a]+=1;
            S[b]+=1;
        }else if(c>d){
            S[a]+=3;
        }else if(c<d){
            S[b]+=3;
        }
    }
    for(i=1;i<=N;i++){
     for(j=1;j<=N;j++){
         if(S[i]<S[j])rank[i]++;
     }
    }
    for(i=1;i<=N;i++)cout<<rank[i]<<endl;
   return 0; 
}

Measured memory_bytes: 3084
import math
N = int(input())
ans = []
ctr = 0

# "5で割って余りが1になる数" を5個足せば、5で割れる（5の倍数になる）
# 5の倍数のうち、5だけは素数である
# 素数は2以上であるから、5個足すと必ず5より大きい数になる

def is_prime(n):
	if n == 2: return True
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0: return False
	return True

for i in range(6, 55555 + 1, 5): # mod5で余りが1になる数を探す
	if is_prime(i):
		ans.append(i)
		ctr += 1
	if ctr == N: break
	
print(*ans)

Measured memory_bytes: 38896
n,m=map(int,input().split())
l=[1]
k=m//n
if n==1:
  print(m)
  exit()
for i in range(2,int(m**0.5)+1):
  if m%i==0:
    if i<=k:
      l.append(i)
    if (m//i)<=k:
      l.append(m//i)
print(max(l))


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    public static int ans;
    public static int[] NT;
    public static int[] t;
    static void Main(string[] args)
    {
        NT = Console.ReadLine().Split().Select(int.Parse).ToArray();
        t = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 0; i < NT[0]-1; i++)
        {
            if ((t[i + 1] - t[i]) >= NT[1]) { ans += NT[1]; }
            else { ans += t[i + 1] - t[i]; }
        }
        ans += NT[1];
        Console.WriteLine(ans.ToString());
    }
}

Measured memory_bytes: 28768
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]

ans = 0

for i in range(N-1):
  x1,y1 = xy[i]
  for j in range(i+1,N):
    x2,y2 = xy[j]
    p = x2-x1
    q = y2-y1
    cost = 0
    for x,y in xy:
      if [x-p,y-q] in xy:
        cost += 1
    ans = max(ans,cost)
    
print(N-ans)

Measured memory_bytes: 9152
import itertools

s = input()
l = len(s)
N = int(s)

ans = 0
for i in range(3, l+1):
    for t in itertools.product("357", repeat = i):   
        if '3' in t and '5' in t and '7' in t and int(''.join(t)) <= N:
            ans += 1

print(ans)


Measured memory_bytes: 3060
def main():

    N = int(input())
    a = list(map(int, input().split()))

    if 1 not in a: return -1
    ans = 0
    p = 1
    for i in range(N):
        if a[i] != p:
            ans += 1
        else:
            p += 1
    return ans


if __name__ == '__main__':
    print(main())


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

#define endl '\n'
#define rep(i,n)       for(int i=0; i<n; i++)
#define clr(arr)       memset(arr, 0, sizeof arr)
#define all(x)         x.begin(), x.end()
const int MOD = 1e9 + 7;

#ifdef SMIT
template<class F, class S> ostream& operator<<(ostream &out, const pair<F, S> &p)
{
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out)
{
	out << '{';
	for (auto i = x.begin(); i != x.end(); i++)
		out << *i << (i == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dmp() {}
template<class T, class... Args> void dmp(T &&x, Args... args)
{
	cerr << x << ";  "; dmp(args...);
}
struct Nl {~Nl() {cerr << '\n';}};
#define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dmp(x), Nl(), cerr << ""
#else
#define debug(...) {}
#endif
// Yes you CAN


string s;
int cnt, ans;
void solve()
{
// #define TEST
	cnt = ans = 0;
	cin >> s;
	for (auto i : s)
	{
		if (i == 'R')
			cnt++;
		else
		{
			ans = max(ans, cnt);
			cnt = 0;

		}
	}
	ans = max(ans, cnt);
	cout << ans << endl;
}

int32_t main()
{
#ifdef SMIT
	// freopen("/home/smit/Desktop/in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int t = 1;
#ifdef TEST
	cin >> t;
#endif
	while (t--)
		solve();
}

Measured memory_bytes: 3604
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	if (n != 1 && a <= b) cout << b * (n - 1) + a - a * (n - 1) - b + 1;
  	else if (n == 1 && a == b) cout << 1;
  	else cout << 0;
	return 0;
}


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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

string S;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main(void){
	cin>>S;

	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());

	bool can = true;
	for (int i = 0; i < S.size();) {
		bool can2 = false;
		for (int j = 0; j < 4; j++) {
			string d = divide[j];
			if (S.substr(i, d.size()) == d) {
				can2 = true;
				i += d.size();
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}

	if (can) cout<< "YES" <<endl;
	else cout<< "NO" <<endl;

	return 0;
}

Measured memory_bytes: 512