akhauriyash/Code-Regression huggingface dataset:
N = int(input())
D = list(map(int, input().split()))

"""
愚直に解くと
・時差が0,12以外の人は、D, 24-Dの2パターンの時間になりうる
・なので、2^N全部試す
で、普通にTLE。

例えばある時差Dの人が
（１）一人の場合：時刻Dとする
（２）二人の場合：Dと24-Dで振り分ける
で、最小の時差を減らさない動きができる
一方で
（３）三人以上の場合：Dと24-Dの少なくとも一方が２人以上いることになるから、時差の最小値が0になる

なので、時差Dが一人の時は、Dと24-Dで２通り試して、時差Dが二人の時は両方に入れる、３人以上は問答無用で0になる、みたいにするとよさげ
あるいは最初はDとして、次は24-Dとして～みたいなのを繰り返す。
"""

from collections import Counter
from collections import defaultdict

c = Counter(D)
c[0] += 1

for i in range(13):
    if i == 0 or i == 12:
        if c[i] >= 2:
            print(0)
            exit()
    else:
        if c[i] >= 3:
            print(0)
            exit()

D.sort()

d = defaultdict(int)
d[24] += 1
is_am = True
for t in D:
    if is_am:
        d[t] += 1
        is_am = False
    else:
        d[24 - t] += 1
        is_am = True


ans = min(D)
times = list(d.keys())
times.sort()
for a,b in zip(times, times[1:]):
    ans = min(ans, b-a)

print(ans)

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

int main(){
    int n,q;
    cin >> n;
    int S[n];
    for ( int i = 0;i < n;i++)cin >> S[i];
    cin >> q;
    int T[q];
    for ( int i = 0;i < q;i++)cin >> T[i];
    
    int A[10000];
    int x = 0;
    for ( int i = 0;i < q;i++){
        for ( int j = 0;j < n;j++){
            if(S[j] == T[i]){
                A[x] = S[i];
                x++;
                break;
            }
        }
    }
    cout << x << endl;
    
    
    return 0;
}

Measured memory_bytes: 1196
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1000000007;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  int di[] = {1,-1,0,0};
  int dj[] = {0,0,1,-1};
  int w,h;
  while(cin >> w >> h,w){
    vector<vector<int>> field(w+2,vector<int> (h+2,0));
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    int n; cin >> n;
    REP(i,n){
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if(d==1){
        REP(j,2) REP(k,4) field[x+j][y+k] = c;
      }else{
        REP(j,4) REP(k,2) field[x+j][y+k] = c;
      }
    }
    bool flag = false;
    int color = field[sx][sy];
    queue<pair<int,int>> task;
    task.push(make_pair(sx,sy));
    while(color>0&&!task.empty()){
      pii u = task.front(); task.pop();
      if(u.first==gx && u.second==gy){
        flag = true;
        break;
      }
      REP(i,4){
        int ni = u.first + di[i];
        int nj = u.second + dj[i];
        if(field[ni][nj] == color){
          task.push(make_pair(ni,nj));
          field[ni][nj] = -1;
        }
      }
    }
    cout << (flag? "OK":"NG") << endl;
  }
}


Measured memory_bytes: 3152
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();
    let S = buf_it.next().unwrap().chars();
    let mut set = HashSet::new();

    for s in S{
        set.insert(s);
    }

    let ans = !((set.contains(&'N') ^ set.contains(&'S')) | (set.contains(&'W') ^ set.contains(&'E')));

    println!("{}",if ans {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
N, M = map(int, input().split())
count = [0]*M
ans = 0
for i in range(N):
  food = list(map(int, input().split()))
  for i in range(1,food[0]+1):
    count[food[i]-1] += 1
for i in range(M):
  if count[i] == N:
    ans += 1
print(ans)
  

Measured memory_bytes: 3060
#ifdef __GNUC__ 
#include <bits/stdc++.h>
#endif
using namespace std;

int main () {
  	int n;cin>>n;
  	int l=0;int r=0;vector<uint64_t> a(n);
  	uint64_t state=0,count=0;
  	for(r=0;r<n;++r){
      cin>>a[r];
      while(a[r]&state){
        state^=a[l];l++;
      }
      count+=r-l+1;
      state|=a[r];
    }
  	//for(;l<n;++l){
    //  count+=n-l;
    //}
    std::cout << count<<std::endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>

using namespace std;

int N;
vector< vector< pair<int, int> > >  v;

// int 型を「どのアイテムを選ぶのか」を表す vector<int> 型に変換
// bit: 集合を表す整数
bool judge(int bit){
    for(int i=0; i<N ; ++i){
        // i ga not kind , then no meaning to do the judge.
        if(!(bit & 1 << i)) continue;

        //if i is kind, then check the status
        for(pair<int, int> p: v[i]){
            int x = p.first;
            int y = p.second;
            // if y =1 but i is not kind
            if(y==1 && !(bit & 1<<x)) return false;
            // if y =0 but i is kind
            if(y==0 && (bit & 1<<x)) return false;
        }
    }

    return true;
}


int main(){
    cin >> N;
    v.resize(N);

    //init
    for(int i=0; i<N; ++i){
        int A;
        cin >> A;
        v[i].resize(A);

        for(int j=0; j < A; ++j){
            cin >> v[i][j].first;
            cin >> v[i][j].second;
            --v[i][j].first;
        }
    }

    int mx = 0;
    for(int bit=0; bit<(1<<N); ++bit){
        if(judge(bit)){
            int num_kind = __builtin_popcount(bit);
            mx = max(mx, num_kind);
        }
    }


    cout << mx << endl;
}

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

int gcd(int a, int b){
    int r= a%b;
    while(r>0){
        a=b;
        b=r;
        r=a%b;
    }
    return(b);
}
long long int lcm(int a, int b){
    return( (long long int)a * b / gcd(a,b));
}

int main() {
    int A, B;
    cin >> A >> B;
    cout << lcm(A,B) << endl;
}

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

using namespace std;
using ll = long long;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
const ll LINF = 1e18;

int main()
{
  int N; string S; cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < S.size()-2; ++i) {
    if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <string.h>
#include <stdio.h>

int main(){
    char s[3];
    scanf("%s", s);
    int rday = 0;
    if((s[0] == 'R') && (s[1] == 'R') && (s[2] == 'R')){
        rday = 3;
    }else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')){
        rday = 2;
    }else if((s[0] == 'R' && s[1] == 'S') || (s[1] == 'S' && s[2] == 'R') || (s[0] == 'S' && s[1] == 'R' && s[2] == 'S')){
        rday = 1;
    }else{
        rday = 0;
    }
    printf("%d", rday);

    return 0;
}

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

using namespace std;
const int INF = 1e9;

struct Block {
    bool dir = false; // 0 - L, 1 - R
    int cnt = 0;
};

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    deque<Block> q;
    
    int cnt = 1;
    for (int i = 1; i <= n; ++i) {
        if (i == n || s[i] != s[i - 1]) {
            q.push_back({s[i - 1] == 'R', cnt});
            cnt = 1;
        } else {
            cnt++;
        }
    }
    
    // for (Block &b : q) {
    //     for (int i = 0; i < b.cnt; ++i)
    //         cout << (b.dir ? 'R' : 'L');
    // }
    // cout << '\n';
    
    for (int i = 0; i < k; ++i) {
        if (q.size() == 1) {
            q[0].dir = !q[0].dir;
        } else if (q.size() == 2) {
            q[1].cnt += q[0].cnt;
            q.pop_front();
        } else {
            q[2].cnt += q[0].cnt;
            q[2].cnt += q[1].cnt;
            q.pop_front();
            q.pop_front();
        }
    }
    
    int ans = 0;
    for (Block &b : q) {
        ans += b.cnt - 1;
        // for (int i = 0; i < b.cnt; ++i)
        //     cout << (b.dir ? 'R' : 'L');
    }
    // cout << '\n';
        
    cout << ans;
}

Measured memory_bytes: 1152
import java.util.*;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        final int N=scanner.nextInt();
        final int NN=100001;
        int[] count=new int[NN];
        int[] sample={0,1,2,3,4,5,1,2,3,1};
        for(int i=0;i<sample.length;i++){
            count[i]=sample[i];
        }
        for(int i=sample.length;i<NN;i++){
            int minNum=Integer.MAX_VALUE;
            int j=0;
            while(i>=Math.pow(6,j)){
                if(minNum>count[i-(int)Math.pow(6,j)]){
                    minNum=count[i-(int)Math.pow(6,j)]+1;
                }
                j++;
            }
            j=0;
            while(i>=Math.pow(9,j)){
                if(minNum>count[i-(int)Math.pow(9,j)]){
                    minNum=count[i-(int)Math.pow(9,j)]+1;
                }
                j++;
            }
            count[i]=minNum;
        }
        System.out.println(count[N]);

    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
#define MAXLEN	4*100000000 
using namespace std;

int main(){
    int n,m;	cin >> n >> m;
    vector<pair<int, int> >student(n, pair<int, int>());
    vector<pair<int, int> >check(m, pair<int, int>());
    rep(i, n)	cin >> student[i].first >> student[i].second;
    rep(i, m)	cin >> check[i].first >> check[i].second;
    //solve
    rep(i, n){
	int minlength = MAXLEN;
	int mincheck=0;
	rep(j, m){
	    int length = abs(student[i].first-check[j].first) + abs(student[i].second-check[j].second);
	    if(minlength > length){
		minlength=length;
		mincheck=j;
	    }
	}
	cout << mincheck+1 << endl;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

ll solve(ll k, ll a, ll b, ll x) {
  if (k < 2) {
    return k + x;
  }
  if (b - a < 2) {
    return k + x;
  }
  if (x < a) {
    ll y = a - x;
    return solve(k - y, a, b, x + y);
  }
  ll z = k / 2;
  return solve(k - 2 * z, a, b, x + (b - a) * z);
}

int main() {
  ios::sync_with_stdio(false);
  ll k, a, b;
  cin >> k >> a >> b;
  cout << solve(k, a, b, 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#  --*-coding:utf-8-*--

def f(N, M, A, BC):
    S = {}

    for a in A:
        if a in S:
            S[a] += 1
        else:
            S[a] = 1


    for b, c in BC:
        if c in S:
            S[c] += b
        else:
            S[c] = b
        
    t = N
    x = 0

    for v, w in sorted(S.items(), reverse=True):
        w2 = min(w, t)
        x += v*w2
        t -= w2

        if t == 0:
            break

    return x
        

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = [list(map(int, input().split())) for i in range(M)]

    print(f(N, M, A, BC))


if __name__ == '__main__':
    main()


Measured memory_bytes: 58676
#include <stdio.h>
#include <string.h>
int main(void){
 char a[102],b[102];
 scanf("%s",a);
 scanf("%s",b);
 if(strlen(a)==strlen(b)){
  int i,c=0;
  for(i=0;i<strlen(a);i++){
   if(a[i]>b[i]){
    c++;
    break;
   }else if(a[i]<b[i]){
    c--;
    break;
   }
  }
  printf(c<0?"LESS":c>0?"GREATER":"EQUAL");
 }else{
   printf(strlen(a)<strlen(b)?"LESS":"GREATER");
 }
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <stack>
// #include <unordered_map>
#include <cmath>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
// #define INF 0x7f7f7f7f  //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN                      \
    freopen("in.txt", "r", stdin); \
    freopen("out.txt", "w", stdout);
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m, n) for (int i = m; i < n; i++)
#define PII pair<int, int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back
#define ST(x, y, z) sort(x + y, x + z);
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define rep(i, a, b) for (register int i = a; i <= b; i++)
#define rrep(i, a, b) for (register int i = a; i >= b; i--)
#define PIII pair<int, PII>
#define re read()
#define case  \
    int T;    \
    cin >> T; \
    rep(_, 1, T)
// #define int ll
#define LL long long
#define int ll
inline int read()
{
    char tempt = getchar();
    int x = 0, f = 0;
    while (tempt < '0' || tempt > '9')
        f |= tempt == '-', tempt = getchar();
    while (tempt >= '0' && tempt <= '9')
        x = x * 10 + tempt - '0', tempt = getchar();
    return f ? -x : x;
}

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

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

const int N = 8;
char g[N][N];
signed main()
{
    //STDIN
    int n, m, k;
    cin >> n>>m>>k;
    for (int i = 0; i < n; i++)
    {
        scanf("%s", g[i]);
    }
    int ans = 0;
    // cout << g[0] << endl;
    for (int i = 0; i<= (1<<n)-1; i++)
    {
        for (int j = 0; j <= (1<<m)-1; j++)
        {
            int cnt = 0;
            for (int a = 0; a < n; a++)
            {
                for (int b = 0; b < m; b++)
                {
                    if (g[a][b] == '#' && (((i>>a) & 1) == 0 && (((j>>b)&1)==0)))
                    cnt++;
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
/*
 * atcoder/abc089/b.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int a, b; cin >> a >> b;
  if (a%2==1 and b%2==1) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include<algorithm>
#include <vector>


int main()
{
    int X,A;
    std::cin >> X >> A;
    if(X<A){
        std::cout << 0 << std::endl;
    }else{
        std::cout << 10 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
oks = [True] * (N + 1)
dp = [0] * (N + 1)
dp[0] = 1
mod = 10**9 + 7

for a in A:
    oks[a] = False

for now in range(N + 1):
    next1 = now + 1
    next2 = now + 2
    if N < next1:
        break
    if oks[next1]:
        dp[next1] += dp[now]
        dp[next1] %= mod

    if N < next2:
        break
    if oks[next2]:
        dp[next2] += dp[now]
        dp[next2] %= mod

print(dp[N])


Measured memory_bytes: 14260
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <map>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int maxn=1e4+10;
struct point{
    int u,to,nxt;
}e[maxn],pp[maxn];
int vis[maxn],head[maxn],s,a[2100][2100],tot;
void add(int u,int v){
    e[tot].nxt=head[u];
    e[tot].u=u;
    e[tot].to=v;
    head[u]=tot++;
}
void dfs(int pre,int st,int dis){
    for (int i=head[st];  i;  i=e[i].nxt){
        int to=e[i].to;
        if (to!=pre){
            a[s][to]=a[to][s]=dis;
            dfs(st,to,dis+1);
        }
    }
}
int n,ans=0,k,u,v,w=0;
int main(){
    scanf("%d%d",&n,&k);
    for (int i=1; i<n; i++){
        scanf("%d%d",&u,&v);
        add(u,v);
        add(v,u);
        pp[w].u=u;
        pp[w++].to=v;
    }
    for (int i=1; i<=n; i++){
        s=i;
        dfs(0,i,1);
    }
    if (k%2==0){
        int minn=0x3f3f3f3f;
        for (int i=1; i<=n; i++){
            ans=0;
            for (int j=1; j<=n; j++)
                if (j!=i)
                    if (2*a[j][i]>k)
                        ans++;
            minn=min(ans,minn);
        }
        printf("%d\n",minn);
    }else{
        int minn=0x3f3f3f3f;
        k=k/2;
        for (int i=0; i<w; i++){
            ans=0;
            for (int j=1; j<=n; j++)
                if (a[j][pp[i].u]>k&&a[j][pp[i].to]>k) ans++;
            minn=min(ans,minn);
        }
        printf("%d\n",minn);
    }
    return 0;
}

Measured memory_bytes: 19688
n = gets.to_i
wordlist = []
last =""
n.times do |i|
  word = gets.chomp
  if wordlist.include?(word)
    puts "No"
    exit
  end
  wordlist << word
  if i > 0
    if last != word[0]
      puts "No"
      exit
    end
  end
  last = word[-1]
end
puts "Yes"


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

#define sc second
#define fr first

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int n; string s;
int dp[1000010][2];
int solve(int i,int pre)
{
    if(i == n)return 0;
    int &ret = dp[i][pre];
    if(ret != -1e9)return ret;
    ret = 1e9;
    ret = min(ret , min(solve(i + 1,0) + s[i] , solve(i + 1 , 1) + (pre ? -1 : 1) + 10 - s[i]));
    return ret;
}
int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0) , cout.tie(0);

    for(int i = 0;i <= 1e6;i++)
        for(int j = 0;j < 2;j++)
            dp[i][j] = -1e9;
    cin >> s;
    n = s.size();
    for(int i = 0;i < n;i++)
        s[i] -= '0';
    cout << solve(0,0);

    return 0;
}


Measured memory_bytes: 56092
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
const long long mod = 1e9 + 7;
const long long MAX_P = 200010;
typedef long long ll;
long long qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
long long qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e10;
class combination {
public:
	ll fact[MAX_P]; // n! mod pのテーブル(O(p))
	ll p;
	// factテーブルを初期化する
	combination(ll x) {  // x : 余り(1e9 + 7など)
		p = x;
		fact[0] = 1;
		for (ll i = 1; i < MAX_P; i++) {
			fact[i] = fact[i - 1] * i % p;
		}
	}
	//拡張ユークリッドの互除法
	ll extgcd(ll a, ll b, ll& x, ll& y) {
		ll d = a;
		if (b != 0) {
			d = extgcd(b, a%b, y, x);
			y -= (a / b) * x;
		}
		else {
			x = 1; y = 0;
		}
		return d;
	}
	//mod上の逆元
	ll mod_inverse(ll a, ll m) {
		ll x, y;
		extgcd(a, m, x, y); //extgcdが必要
		return (m + x % m) % m;
	}
	//n! = a p^eとしたときの a mod pを求める O(log_p a)
	ll mod_fact(ll n, ll p, ll& e) {
		e = 0;
		if (n == 0) return 1;

		//pの倍数の部分を計算
		ll res = mod_fact(n / p, p, e);
		e += n / p;

		//(p - 1)!≡-1なので、(p-1)!^(n/p)はn/pの偶奇だけで計算できる
		if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
		return res * fact[n % p] % p;
	}

	//mod p 上の二項係数
	ll mod_comb(ll n, ll k) {
		if (n < 0 || k < 0 || n < k) return 0;
		ll e1, e2, e3;
		ll a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3);
		if (e1 > e2 + e3) return 0;
		return a1 * mod_inverse(a2 * a3 % p, p) % p;
	}
};
int main() {
	ll n, m, k; cin >> n >> m >> k;
	combination c(mod);
	ll lyn, rn;
	lyn = 0; rn = 0;
	for (int i = 1; i < n; i++) {
		lyn += qp(m, 2, mod) * (n - i)*i;
		lyn %= mod;
	}
	for (int i = 1; i < m; i++) {
		rn += qp(n, 2, mod) * (m - i)*i;
		rn %= mod;
	}
	cout << c.mod_comb(n*m - 2, k - 2) * (lyn + rn) % mod << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

int n,p[maxn],pp[maxn];
bool bz[maxn];

int main()
{
    scanf("%d",&n);
    fo(i,1,n) scanf("%d",&p[i]), pp[p[i]]=i;

    int ans=1, cnt=0;
    fo(i,2,n)
    {
        if (pp[i-1]<pp[i]) bz[i]=1;
        if (bz[i]) cnt++; else
        {
            ans=max(ans,cnt+1);
            cnt=0;
        }
    }
    ans=max(ans,cnt+1);

    printf("%d\n",n-ans);
}

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

dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j==k:continue
            dp[i+1][k] = max(dp[i+1][k],dp[i][j]+v[i][k])
            
print(max(dp[N][i] for i in range(3)))

Measured memory_bytes: 50188
N, K, C = [int(_) for _ in input().split()]
S = input()
cand = [i + 1 for i, s in enumerate(S) if s == 'o']
F = [[cand[0]]]
for c in cand[1:]:
    if c - F[-1][0] > C:
        F += [[]]
    F[-1] += [c]
if len(F) > K:
    exit()
B = [[cand[-1]]]
for c in cand[-2::-1]:
    if B[-1][0] - c > C:
        B[-1] = B[-1][::-1]
        B += [[]]
    B[-1] += [c]
B = B[::-1]
B[0] = B[0][::-1]
ans = []
for f, b in zip(F, B):
    if len(f) == 1 or f[1] not in b:
        ans += [f[0]]
print('\n'.join(map(str, ans)))


Measured memory_bytes: 72800
from collections import defaultdict

N, K, L = map(int, input().split())


class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)


uf1 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf1.union(p - 1, q - 1)

uf2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    uf2.union(r - 1, s - 1)


c = defaultdict(int)
for i in range(N):
    c[(uf1.find(i), uf2.find(i))] += 1
for i in range(N):
    print(c[(uf1.find(i), uf2.find(i))])

Measured memory_bytes: 56052
N = int(input())
d = list(map(int, input().split()))

import itertools

D = list(range(1, len(d)+1))
p = itertools.permutations(d, 2)

ans = 0
for v in itertools.permutations(D, 2):
    ans = d[v[0]-1] *d[v[1]-1] + ans

print(int(ans/2))

Measured memory_bytes: 3064
#include <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j;while (1) {scanf("%d %d",&N,&K);if (!N || N==EOF) return 0;ans=-1000000007,j=0;for (i=0,K--;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];for (i=K;i<N;i++) scanf("%d",&RB[i]),j+=RB[i],(ans=(ans>j)?ans:j),j-=RB[i-K]; printf("%d\n",ans);}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define inf 1<<25
using namespace std;

int n,m,r;
int s[201][201],t[201][201],z[1001],dp[1001][201];

void init(){
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j)s[i][j]=0;
      else s[i][j]=inf;
      if(i==j)t[i][j]=0;
      else t[i][j]=inf;
    }
    for(int j=0;j<1001;j++)dp[j][i]=inf;
  }
}

void wf(){
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	s[i][j]=min(s[i][j],s[i][k]+s[k][j]);
	t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
      }
    }
  }
}

int main()
{
  int a,b,d;
  char c;

  while(1){
    cin>>n>>m;
    if(n+m==0)break;
    init();
    for(int i=0;i<m;i++){
      cin>>a>>b>>d>>c;
      a--;b--;
      if(c=='L'){
	t[a][b]=min(d,t[a][b]);
	t[b][a]=min(d,t[b][a]);
      }
      else {
	s[a][b]=min(d,s[a][b]);
	s[b][a]=min(d,s[b][a]);
      }
    }
    cin>>r;
    for(int i=0;i<r;i++){
      cin>>z[i];
      z[i]--;
    }

    wf();
    int ans=inf;
    for(int i=0;i<n;i++)dp[0][i]=s[z[0]][i];
    for(int i=1;i<r;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  dp[i][j]=min(dp[i][j],dp[i-1][k]+t[z[i-1]][k]+s[k][j]+t[z[i]][j]);
	  dp[i][j]=min(dp[i][j],dp[i-1][j]+t[z[i-1]][z[i]]);
	  if(i==r-1)ans=min(ans,dp[i][j]);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  double x = (a + b) / 2.0;
  double r = (a + b) % 2;
  //cout << r << endl;
  cout << x + r / 2.0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod LLONG_MAX
#define mod1 998244353
#define Mmax 1000005
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
bool comp(pair<li,pair<li,li>>a,pair<li,pair<li,li>>b)
{
  if(a.first<b.first)
  return 1;
  else if(a.first>b.first)
  return 0;
  else
  {
    return a.second.first<b.second.first;
  }
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
li modInverse(li n)
{
    return mpow(n, mod-2);
}

li nCrModPFermat(li n, li r,li x,li y,li z)
{
   // Base case
   if (r==0)
      return 1;
    // li fac[n+1];
    // fac[0] = 1;
    // for (int i=1 ; i<=n; i++)
    //     fac[i] = fac[i-1]*i%mod;
    return (x* modInverse(y) % mod *modInverse(z) % mod) % mod;
}
void bfs(vector<li>v[],li visit[],li s,li ans[])
{
  deque<li>q;
  q.push_back(s);
  visit[s]=1;
  while(!q.empty())
  {
    li x=q.front();
    q.pop_front();
    for(auto i=v[x].begin();i!=v[x].end();i++)
    {
      if(!visit[*i])
      {
        q.push_back(*i);
        visit[*i]=1;
      }
    }
  }
}
void buildtree(int*tree,int*arr,int start,int end,int treeNode)
{
  if(start<end)
  {
    int mid=start+(end-start)/2;
    buildtree(tree,arr,start,mid,2*treeNode);
    buildtree(tree,arr,mid+1,end,2*treeNode+1);
    tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
  }
}
void update(int*tree,int*arr,int start,int end,int pos,int val,int treeNode)
{
  if(start==end)
  tree[treeNode]=val;
  else
  {
    int mid=start+(end-start)/2;
    if(pos<=mid)
    update(tree,arr,start,mid,pos,val,2*treeNode);
    else
    update(tree,arr,mid+1,end,pos,val,2*treeNode+1);
    tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
  }
}

void dfs(vector<li>v[],li visit[],li s,li c[],li ans[],map<li,li>*m,li pred[])
{
    visit[s]=1;
     (*m)[c[s]]++;
    for(auto i=v[s].begin();i!=v[s].end();i++)
      {
        if(!visit[*i])
        {pred[*i]=s;
           dfs(v,visit,*i,c,ans,m,pred);
        }
      }
      if((*m)[c[pred[s]]]==1)
    ans[s]=(*m).size()-1;
    else
    ans[s]=(*m).size();
}
vector<li>factor(li n)
{
  vector<li>v;
  if(n%2==0)
  {
    while(n%2==0)
    {n/=2;
    v.push_back(2);
    }
  }
  for(li i=3;i<=sqrt(n);i+=2)
  {
    if(n%i==0)
    {
      while(n%i==0)
      {n/=i;
      v.push_back(i);
      }
    }
  }
  if(n>1)
  v.push_back(n);
  return v;
}
int main()
{
 li t,i,j;
// cin>>t;
// while(t--)
// {
//
//   cout<<endl;
// }
li n,m;
cin>>n>>m;
li a[n];
for(i=0;i<n;i++)
cin>>a[i];
li visit[n]={0};
i=0;
li k=1,p=0;
if(m<=n)
{
  i=0;
  while(m)
  {
    i=a[i]-1;
    m--;
  }
cout<<i+1;
}
else{
while(!visit[i])
{
  visit[i]=k;
  k++;
  i=a[i]-1;
}
k-=visit[i];
m-=(visit[i]-1);
p=i;
if(k==0)
cout<<"1";
else{
li x=m%k;
memset(visit,0,sizeof(visit));
i=0;
while(x)
{
  p=a[p]-1;
  x--;
}
cout<<p+1;
}
}
return 0;
}


Measured memory_bytes: 6852
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // abs()
#include <string.h>         // memset()
#include <stdbool.h>

#define MAX_N 15
#define MAX_S (1 << MAX_N)

const double INF = 1e10;

int n;
int s[MAX_N], l[MAX_N], v[MAX_N];
double dp[MAX_N][MAX_S];
int w[MAX_N][MAX_S];
short prev[MAX_N][MAX_S][2];
int ord[MAX_N];

int
main(int argc, char **argv)
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d%d%d", &s[i], &l[i], &v[i]);

	memset(prev, -1, sizeof(prev));
	int S = 1;
	for (int i = 0; i < n; i++, S <<= 1)
		w[i][S] = v[i];

	int e = 1 << n;
	for (int k = 0; k < e; ++k)
	{
		S = 1;
		for (int i = 0; i < n; ++i, S <<= 1)
		{
			if (k & S)
				continue;

			int t = k | S;
			for (int j = 0; j < n; ++j)
			{
				if (i == j || w[j][k] == 0)
					continue;

				int d = abs(l[i] - l[j]);
				double x = dp[j][k] + d * (10.0 * (7 + 2 * w[j][k]) / 2000.0);
				if (dp[i][t] == 0 || x < dp[i][t])
				{
					dp[i][t] = x;
					w[i][t] = w[j][k] + v[i];
					prev[i][t][0] = j;
					prev[i][t][1] = k;
				}
			}
		}
	}

	double min = INF;
	int u = 0;
	for (int i = 0; i < n; ++i)
	{
		double y = dp[i][e - 1];
		if (y == 0)
			continue;

		if (y < min)
		{
			min = y;
			u = i;
		}
	}

	ord[0] = u;
	int v = e - 1;
	for (int k = 1; k < n; ++k)
	{
		ord[k] = prev[u][v][0];
		v = prev[u][v][1];
		u = ord[k];
	}

	for (int i = n - 1; i >= 0; --i)
		printf("%d%c", s[ord[i]], (i != 0) ? ' ' : '\n');

	return 0;
}

Measured memory_bytes: 8660
#include<stdio.h>
#include<math.h>
int main(){
  int x;
  scanf("%d",&x);
  for (int i=-200;i<200;i++){
    for (int j=-200;j<200;j++) {
      if (pow(i,5)-pow(j,5)==x) {
        printf("%d %d",i,j);
        return 0;
      }
    }
  }
}

Measured memory_bytes: 2508
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()

def main():
    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]

    ans = 10 ** 9

    for bit in range(1 << (H-1)):
        canSolve = True
        ord = defaultdict(int)
        N = 0
        for i in range(H):
            if bit & 1 << i:
                ord[i+1] = ord[i] + 1
                N += 1
            else:
                ord[i+1] = ord[i]
        nums = defaultdict(int)
        for w in range(W):
            one = defaultdict(int)
            overK = False
            for h in range(H):
                one[ord[h]] += int(S[h][w])
                nums[ord[h]] += int(S[h][w])
                if one[ord[h]] > K:
                    canSolve = False
                if nums[ord[h]] > K:
                    overK = True
            if not canSolve:
                break
            if overK:
                N += 1
                nums = one
        if canSolve and ans > N:
            ans = N
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 48856
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;
const ll INF2 = (ll)INF*INF;


int main(){
	ll N, x, ans=INF2;
	ll a[2005], c[2005];
	Fill(c, INF2);

	cin >> N >> x;
	rep(i,N) cin >> a[i];

	rep(k,N){
		rep(i,N) chmin( c[(i+k)%N], a[i] );
		ll sum = x*k;
		rep(i,N) sum += c[i];
		chmin( ans, sum );
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;

public class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();

        if (((s[0] == s[1]) && (s[2] == s[3]) && (s[0] != s[2]))
            || ((s[0] == s[2]) && (s[1] == s[3]) && (s[0] != s[1]))
            || ((s[0] == s[3]) && (s[1] == s[2]) && (s[0] != s[1]))) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

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

#define int long long

const int N = 2e5 + 10;
int n, ar[N], dp[N][5];

int solve(int x, int y) {
	if (!y)
		return x;
	if (y == 1)
		return !(x & 1);
	
	if (!x)
		return 2;
	if (x & 1)
		return 1;
	return 0;
}

int32_t main() {
	for (int i = 0; i < N; i++)
		fill(dp[i], dp[i] + 5, 1e9 + 10);
		
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	
	dp[0][0] = ar[0];
	dp[0][1] = solve(ar[0], 2);
	dp[0][2] = solve(ar[0], 1);
	
	for (int i = 1; i < n; i++) {
		dp[i][0] = dp[i - 1][0] + solve(ar[i], 0);
		dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + solve(ar[i], 2);
		dp[i][2] = min({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) + solve(ar[i], 1);
		dp[i][3] = min({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2], dp[i - 1][3]}) + solve(ar[i], 2);
		dp[i][4] = min({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2], dp[i - 1][3], dp[i - 1][4]}) + solve(ar[i], 0);
	}
	cout << min({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2], dp[n - 1][3], dp[n - 1][4]});
}

Measured memory_bytes: 9600
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int A, B;
	cin >> A >> B;
	cout << A * B << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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


  int count = 0;
  while(true) {
    for(int i = 0; i < n; i++) {
      if(a[i] % 2) {
        cout << count << endl;
        return 0;
      }
      a[i] = a[i] >> 1;
    }
    count++;
  }
  return 0;
}

Measured memory_bytes: 3640
S = input()
ans = [0] * len(S)

goal = 0
r_count = 0
l_count = 0
last_letter = "R"
for i,s in enumerate(S):
    if last_letter == "R" and s == "R":
        r_count += 1
        goal = i
    if last_letter == "L" and s == "L":
        l_count += 1
    if last_letter == "R" and s == "L":
        ans[goal+1] += (r_count//2)
        ans[goal] += (r_count - r_count//2)
        r_count = 0
        l_count = 1
    if last_letter == "L" and s == "R":
        ans[goal] += (l_count//2)
        ans[goal+1] += (l_count - l_count//2)
        l_count = 0
        r_count = 1
        goal = i
    last_letter = s
ans[goal] += (l_count//2)
ans[goal+1] += (l_count - l_count//2)

ans_str = " ".join(list(map(str,ans)))
print(ans_str)

Measured memory_bytes: 49136
#include <stdio.h>
int main(){
    int a,b;
    char *result;
    scanf("%d %d",&a,&b);
    if (a!=1 && b!=1){
        if(b<a){
            result = "Alice";
        }
        else if(a>b){
            result = "Bob";
        }
        else if(a==b){
            result = "Draw";
        }
    }
    else if(a==1){
        if(b==1){
            result = "Draw";
        }
        else{
            result = "Alice";
        }
    }
    else if(b==1){
        if(a==1){
            result = "Draw";
        }
        else{
            result = "Bob";
        }
    }
    printf("%s\n",result);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const long long INF = 1LL << 60;
ll H;
ll DFS(ll i){
    ll ans=0;
    if(i==1){
        ans=1;
    }
    else{
        ans=DFS(i/2)*2+1;
    }
    return ans;
}
int main(){
  cin>>H;
  cout<<DFS(H)<<endl;
}


Measured memory_bytes: 3528
#include <stdio.h>

int main(){
    int a,b,c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a+b >= c) printf("%d\n", b+c);
    else if(a+b < c) printf("%d\n", a+2*b+1);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector
#include <iomanip>

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

double x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

double a, b, c, r, d, x;
a = hypot(x1-x2,y1-y2);
b = hypot(x2-x3,y2-y3);
c = hypot(x3-x1,y3-y1);
r = abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/(a+b+c);
d = max({a,b,c});
x = d/(2+d/r);

cout << fixed << setprecision(15);
cout << x << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int in = sc.nextInt();
        int h = in / 3600;
        int m = (in%3600)/60;
        int s = ((in%3600)%60);

        System.out.printf("%d:%d:%d\n", h, m, s);
        sc.close();
    }
}


Measured memory_bytes: 26284
d, n = map(int,input().split())
cnt = 0
i = 0
if d == 0:
    while cnt < n:
        i += 1
        if i % 100 != 0:
            cnt+= 1
elif d == 1:
    while cnt < n:
        i += 1
        if i % 100 == 0 and i % (100**2) != 0:
            cnt += 1
else:
    while cnt < n:
        i += 1
        if i % (100**2) == 0 and i % (100**3) != 0:
            cnt += 1
print(i)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    ll x[n],x1[n];
    for (i=0;i<n;i++)
    {
        cin>>x[i];
        x1[i]=x[i];
    }
    sort(x1,x1+n);
    ll p1=x1[n/2-1],p2=x1[n/2];
    for (i=0;i<n;i++)
    {
        if (x[i]<p2)
            cout<<p2<<endl;
        else
            cout<<p1<<endl;
    }
}

Measured memory_bytes: 5376
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#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;
typedef long long ll;
typedef pair<int,int> P;
int ceil(int a,int b){// a以上でbの倍数の最小値を出力//
    return (a+b-1)/b*b;
}
int stoii(string s){//stoi関数の代用 文字列を数値として読み取りint型に変換//
    return atoi(s.c_str());
}
int dp[110][110];
int main(){
	int n;
	while(cin>>n&&n){
	// int n;
	// cin>>n;
	//cout<<n<<endl;
		if(n==0) {
		cout<<"okai"<<endl;
		return 0;
		}
		vector<pair<int,char>> v(26);
		rep(i,26){
		v[i].first=0;
		v[i].second='A'+i;
		}
		char a[1500];
		rep(i,n){
			cin>>a[i];
		}
		rep(i,n){
			rep(j,26){
				if(v[j].second==a[i])v[j].first++;
			}
			sort(v.begin(),v.end());
			// rep(i,26){
			// 	cout<<v[i].first<<" "<<v[i].second<<" ";
			// }
			// cout<<endl;
			if(v[25].first > v[24].first+n-i-1){
				cout<<v[25].second<<" "<<i+1<<endl;
				break;
			}
			if(i==n-1){
				cout<<"TIE"<<endl;
				break;
			} 
		}
	}
}	


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define print0(a)           cout<<a<<"\n"
#define print1(a)           cout<<a<<' '
#define print2(a,b)         cout<<a<<" "<<b<<" ";
#define print3(a,b,c)       cout<<a<<" "<<b<<" "<<c<<" ";
#define print4(a,b,c,d)     cout<<a<<" "<<b<<" "<<c<<" "<<d<<" ";
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 1e18;
vector<int> g[N];
int h,w;
/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
int Power(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}
signed main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
       
      int n;
      cin>>n;
      string s;
      cin>>s;
      int ans =0;
      for(int i=0;i<n;i++)
      {
          map<char,int> mp;
          int cnt=0;
          for(int j=i-1;j>=0;j--)
          {
              mp[s[j]]++;
          }
          for(int j=i;j<n;j++)
          {
              if(mp[s[j]])
              {
                  cnt++;
                  mp[s[j]]=0;
              }
          }
          ans = max(ans,cnt);
      }
      cout<<ans<<"\n";


       
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||
*/



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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
char s[N], t[N];
char ani[] = {'S', 'W'};

bool check(int st, int l, int r)
{
	int a = ani[st], b = ani[l], c = ani[r];
	if (a == 'S' && s[1] == 'o' && b != c) return false;
	if (a == 'S' && s[1] == 'x' && b == c) return false;
	if (a == 'W' && s[1] == 'x' && b != c) return false;
	if (a == 'W' && s[1] == 'o' && b == c) return false;
	
	t[1] = a, t[0] = b, t[2] = c;
	for (int i = 2; i <= n; i ++ )
		if (t[i] == 'S')
		{
			if (s[i] == 'o') t[i + 1] = t[i - 1];
			else t[i + 1] = t[i - 1] == 'S' ? 'W' : 'S';
		}
		else
		{
			if (s[i] == 'x') t[i + 1] = t[i - 1];
			else t[i + 1] = t[i - 1] == 'S' ? 'W' : 'S';
		}
	
	return t[0] == t[n] && t[1] == t[n + 1];
}

int main()
{
	scanf("%d%s", &n, s + 1);
	
	for (int i = 0; i < 2; i ++ )
		for (int j = 0; j < 2; j ++ )
			for (int k = 0; k < 2; k ++ )
				if (check(i, j, k))
				{
					t[n + 1] = '\0';
					puts(t + 1);
					return 0;
				}
	
	puts("-1");
    return 0;
}

Measured memory_bytes: 512
def wa(n):
    return int(n*(n+1)/2)

n=int(input())
fizz=int(n/3)
butt=int(n/5)
fizzbutt=int(n/15)
fizz_wa=wa(fizz)*3
butt_wa=wa(butt)*5
fizzbutt_wa=wa(fizzbutt)*15
total=wa(n)
answer=total+fizzbutt_wa-fizz_wa-butt_wa
print(answer)

Measured memory_bytes: 9192
# -*- coding: utf-8 -*-

N = int(input())

X = N
sum1 = 0
# 各桁の和を出す
while N != 0:
    sum1 += N % 10
    N //= 10
    
# 判定する
if X % sum1 == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define ll long long
#define ull  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 110000;
vector < int > g[N];
int mt[N], used[N], a[N], b[N], c[N], d[N];
bool dfs(int v){
    if (used[v]) return false;
    used[v] = 1;
    for (int i = 0; i < g[v].size(); i++){
        int u = g[v][i];
        if (mt[u] == -1 || dfs(mt[u])){
            mt[u] = v;
            return true;
        }
    }
    return false;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= n; i++){
        cin >> c[i] >> d[i];
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            if (a[i] < c[j] && b[i] < d[j]) g[i].pb(j);
        }
    }
    for (int i = 1; i <= n; i++) mt[i] = -1;
    for (int i = 1; i <= n; i++){
        memset(used, 0, sizeof(used));
        dfs(i);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) if (mt[i] != -1) ans++;
    cout << ans;
}


Measured memory_bytes: 3712