akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def check(num):
    res = 0
    for a,b,c,d in abcd:
        if num[b-1] - num[a-1] == c:
            res += d
    return res

def dfs(x, y, z, res):
    if y == n:
        res = max(res, check(x))
        return res
    for i in range(z, m+1):
        res = max(res, dfs(x + [i], y+1, i, res))
    return res

n, m, q = LI()
abcd = [LI() for _ in range(q)]
ans = dfs([1], 0, 1, 0)
print(ans)
        

    

Measured memory_bytes: 74144
H,W = map(int,input().split())
A = [list(input()) for i in range(H)]
S = [[0]*W for i in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w]=="#":
            S[h][w] = H*W
for h in range(H):
    a = 0
    for w in range(W):
        S[h][w] = max(a,S[h][w])
        a = max(a,S[h][w])-1
    for w in range(W)[::-1]:
        S[h][w] = max(a,S[h][w])
        a = max(a,S[h][w])-1
for w in range(W):
    a = 0
    for h in range(H):
        S[h][w] = max(a,S[h][w])
        a = max(a,S[h][w])-1
    for h in range(H)[::-1]:
        S[h][w] = max(a,S[h][w])
        a = max(a,S[h][w])-1
ans = H*W
for h in range(H):
    for w in range(W):
        ans = min(ans,S[h][w])
print(H*W-ans)

Measured memory_bytes: 93660
import java.util.Scanner;

import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

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

        Scanner in = new Scanner(System.in);

        String input = in.nextLine();

        int cnt = Integer.parseInt(input);

        while(cnt != 0){
            double sum = 0.0;
            input = in.nextLine();
            String [] param_line = input.split(" ", 0);
            int [] points = new int[param_line.length];
            for(int i=0; i<points.length; i++){
                points[i] = Integer.parseInt(param_line[i]);
                sum += points[i];
            }

            double avg = sum/points.length;
            double tmp = 0;
            for(int i=0; i<points.length; i++)
                tmp += pow(points[i]-avg,2);

            double bunsan = tmp/points.length;
            double hyohen = sqrt(bunsan);

            System.out.printf("%.8f\n",hyohen);

            input = in.nextLine();
            cnt = Integer.parseInt(input);
        }
    }
}

Measured memory_bytes: 28132
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sa,sb = [0],[0]
ans = 0
for i in range(n):
    sa.append(sa[i]+a[i])
for i in range(m):
    sb.append(sb[i]+b[i])


for i in range(n+1):
    sai = sa[i]
    x = k-sai
    if x>=0:
        ans = max(ans,bisect.bisect_right(sb,x)-1+i)
print(ans)

Measured memory_bytes: 47556
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		m: usize,
		ab: [[usize; 2]; m],
	}

	let mut v: Vec<Vec<usize>> = vec![vec![]; n];
	for i in 0..m {
		v[ab[i][0]-1].push(ab[i][1]-1);
		v[ab[i][1]-1].push(ab[i][0]-1);
	}

	for i in 0..v[0].len() {
		for j in 0..v[v[0][i]].len() {
			if v[v[0][i]][j] == n-1 {
				println!("POSSIBLE");
				return;
			}
		}
	}
	println!("IMPOSSIBLE ");
}



Measured memory_bytes: 27616
M = 10**9 + 7
s = int(input()) - 3

f = [1]  +  [None] * s
for i in range(1, s + 1):
  f[i] = f[i - 1] * i % M

r = 0
for k in range(s // 3 + 1):
  r += f[s] * pow(f[k], M - 2, M) * pow(f[s - k], M - 2, M)
  s -= 2

print(r % M)


Measured memory_bytes: 9132
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll x,y,z;
cin>>x>>y>>z;
swap(x,y);
swap(x,z);
cout<<x<<" "<<y<<" "<<z<<endl;
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b, c;
	char op;
	scanf("%d %c %d", &a, &op, &b);
	while (op != '?')
	{
		if (op == '+')
		{
			c = a + b;
		}
		if (op == '-')

		{
			c = a - b;
		}
		if (op == '*')
		{
			c = a*b;
		}
		if (op == '/')
		{
			c = a / b;
		}
		printf("%d\n", c);
		scanf("%d %c %d", &a, &op, &b);
	}

	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int n;
int c[100010];


int main() {
    cin>>n;
    ll ret=1;
    c[0]=3;
    rep(i,n){
        int x;
        cin>>x;
        ret=ret*c[x]%MOD;
        c[x]--;
        c[x+1]++;
    }
    cout<<ret<<endl;
}

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

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

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

    if (k >= n) {
        cout << 0 << endl;
        return 0;
    }

    long long output = 0;
    sort(h.begin(), h.end());
    for (int i = 0; i < n - k; i++)
    {
        output += h[i];
    }
    cout << output << endl;
}

Measured memory_bytes: 1024
package main

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

type Entry struct {
	value int
	count int
	even  bool
}

// AtCoder は Go 1.6 なので sort.Slice が使えない...
type Entries []*Entry

func (e Entries) Len() int {
	return len(e)
}
func (e Entries) Less(i, j int) bool {
	a := e[i]
	b := e[j]
	if a.count != b.count {
		return a.count > b.count
	}
	return a.value > b.value
}
func (e Entries) Swap(i, j int) {
	e[i], e[j] = e[j], e[i]
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)

	evens := make(map[int]*Entry, 0)
	odds := make(map[int]*Entry, 0)
	var mp map[int]*Entry
	for i := 0; i < n; i++ {
		v := scanInt(sc)

		if i%2 == 0 {
			mp = evens
		} else {
			mp = odds
		}

		if mp[v] == nil {
			mp[v] = &Entry{value: v, count: 1, even: i%2 == 0}
		} else {
			mp[v].count += 1
		}
	}

	entries := make([]*Entry, 0, len(evens)+len(odds))
	for _, e := range evens {
		entries = append(entries, e)
	}
	for _, e := range odds {
		entries = append(entries, e)
	}

	sort.Sort(Entries(entries))

	// for _, e := range entries {
	// 	fmt.Println(*e)
	// }

	top := entries[0]
	oppCount := 0
	for _, et := range entries {
		if et.even != top.even && et.value != top.value {
			oppCount = et.count
			break
		}
	}

	fmt.Println(n - top.count - oppCount)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    string ss,tt;cin>>ss>>tt;
    ll ans=1;
    if(ss[0]==tt[0])ans=3;
    else ans=6;
    for(int i=1;i<ss.size();i++){
        if(ss[i]==tt[i]){
            if(ss[i-1]==tt[i-1])ans*=2;
        }
        else{
            if(ss[i-1]==ss[i])continue;
            if(ss[i-1]==tt[i-1])ans*=2;
            else ans*=3;
        }
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
C11, C12, C13 = map(int, input().split());
C21, C22, C23 = map(int, input().split());
C31, C32, C33 = map(int, input().split());

# a1 = 0と仮定して他を調整する
b1 = C11;
b2 = C12;
b3 = C13;

a2 = C21 - b1;
a3 = C31 - b1;

if (C22 == a2 + b2 and
    C23 == a2 + b3 and
    C32 == a3 + b2 and
    C33 == a3 + b3):
  print("Yes");
else:
  print("No");

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

using namespace std;

void solve()
{
	string str;
	while(getline(cin, str))
	{
		string s;
		bool flag = false;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == ' ' || str[i] == ',' || str[i] == '.')
			{
				if(3 <= s.size() && s.size() <= 6)
				{
					if(flag)
					{
						cout << " " << s;
					}
					else
					{
						cout << s;
						flag = true;
					}
				}
				s = "";
			}
			else
			{
				s += str[i];
			}
		}
		cout << endl;
	}
}

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

Measured memory_bytes: 1172
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = int(input())
s = input()
t = input()
cnt = 0
ans = 0
for i in range(len(s)):
    if s[i] == t[cnt]:
        cnt += 1
    elif s[i] != t[cnt] and s[i] == t[0]:
        ans = max(ans,cnt)
        cnt = 1
    else:
        ans = max(ans,cnt)
        cnt = 0
print(n + n - cnt)


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

#define int long long

using namespace std;

struct node {
  int i, j;
  node *left, *right;
  int val, lazy;
};

vector<int> a;

node* build(int i, int j) {
  if (i == j) {
    return new node{i, j, nullptr, nullptr, a[i], 0};
  } 
  node *left = build(i, (i + j) / 2);
  node *right = build((i + j) / 2 + 1, j);
  return new node{i, j, left, right, left->val + right->val, 0};
}

void propagate(node* cur) {
  if (cur->lazy != 0) {
    cur->val += (cur->j - cur->i + 1) * cur->lazy;
    if (cur->left != nullptr) {
      cur->left->lazy += cur->lazy;
      cur->right->lazy += cur->lazy;
    }
    cur->lazy = 0;
  }
}

int query(node *cur, int i, int j) {
  propagate(cur);
  if (cur->i > j || cur->j < i) {
    return 0;
  }
  if (cur->i >= i && cur->j <= j) {
    return cur->val;
  }
  return query(cur->left, i, j) + query(cur->right, i, j);
}

void update(node* cur, int i, int j, int newVal) {
  //cout << i << ' ' << j  << endl;
  //cout << cur->i << ' ' << cur->j << endl;
  propagate(cur);
  if (cur->i > j || cur->j < i) {
    return;
  }
  if (cur->i >= i && cur->j <= j) {
    cur->lazy += newVal;
    propagate(cur);
    return;
  }
  update(cur->left, i, j, newVal);
  update(cur->right, i, j, newVal);
  cur->val = cur->left->val + cur->right->val;
  return;
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  //cout << n << q << endl;
  a = vector<int>(n, 0);
  node *root = build(0, n - 1);
  //cout << root->val << endl;
  while (q--) {
    int c;
    int s, t, x;
    cin >> c >> s >> t;
    //cout << s << t << endl;
    if (c == 0) {
      cin >> x;
      update(root, s - 1, t - 1, x);
    } else {
      cout << query(root, s - 1, t - 1) << '\n';
    }
  }
  return 0;
}



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

int main(){
  char s[19];
  for(int i=0; i<19; i++){
    cin >> s[i];
    if(s[i]==','){
      cout << " ";
    }
    else{
      cout << s[i];
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Cube cube = new Cube(br);
		char[] act = br.readLine().toCharArray();
		
		for(int i = 0; i < act.length; i++){
			switch(act[i]){
			case 'S':	
				cube.south();
				break;
			case 'N':
				cube.north();
				break;
			case 'E':
				cube.east();
				break;
			case 'W':
				cube.west();
				break;
			}
		}
		System.out.println(cube.top);
	}
}


class Cube {
	String[] num;
	String top;
	String center;
	String back;
	String bottom;
	String right;
	String left;
	String temp;
	
	Cube(BufferedReader br) throws IOException {
		num = br.readLine().split(" ");
		this.top = num[0];
		this.center = num[1];
		this.right = num[2];
		this.left = num[3];
		this.back = num[4];
		this.bottom = num[5];	
	}
	void south() {
		temp = this.top;
		this.top = this.back;
		this.back = this.bottom;
		this.bottom = this.center;
		this.center = temp;	
	}
	void north() {
		temp = this.top;
		this.top = this.center;
		this.center = this.bottom;
		this.bottom = this.back;
		this.back = temp;	
	}
	void east() {
		temp = this.top;
		this.top = this.left;
		this.left = this.bottom;
		this.bottom = this.right;
		this.right = temp;	
	}
	void west() {
		temp = this.top;
		this.top = this.right;
		this.right = this.bottom;
		this.bottom = this.left;
		this.left = temp;
		}
}

Measured memory_bytes: 24312
def a():
  a = list(map(int,input().split()))

  max1 = max(a[0], a[1])
  min1 = min(a[0], a[1])
  max2 = max(a[2], a[3])
  min2 = min(a[2], a[3])
  result = [max1 * max2, max1 * min2, min1 * max2, min1 * min2]

  return max(result)

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

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

// ############################################################################################

#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for (register int i = (a); i < (int)(n); ++i)
#define FORE(i, a, n) for (i = (a); i < (int)(n); ++i)
#define Size(n) ((int)(n).size())
#define all(n) (n).begin(), (n).end()

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair

#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>

#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>

#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)

#define mod 1000000007
#define inf 1e18

#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// ############################################################################################

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2) res = (res * base) % mod;
        base = (base * base) % mod;
        exp /= 2;
    }
    return res % mod;
}

void a_k_s() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
}

int main() {
    a_k_s();

    ll n, w, wt, val;
    cin >> n >> w;

    vector<pll> v;
    v.pb({0, 0});

    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));

    FOR(i, 0, n) {
        cin >> wt >> val;
        v.pb({wt, val});
    }

    FOR(i, 1, n + 1) {
        FOR(wt, 1, w + 1) {
            dp[i][wt] = dp[i - 1][wt];
            if (v[i].ff <= wt) {
                dp[i][wt] = max(dp[i][wt], dp[i - 1][wt - v[i].ff] + v[i].ss);
            }
        }
    }

    cout << dp[n][w] << endl;

    return 0;
}

Measured memory_bytes: 83056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        const long MOD = 1000000007;
        var sc = new Scanner();
        int n = sc.nextInt();
        var v = new int[n];
        for (int i = 0; i < n; i++)
        {
            v[i] = sc.nextInt();
        }

        Array.Sort(v);
        double ans = v[0];
        for (int i = 1; i < n; i++)
        {
            ans = (ans + v[i]) / 2.0;
        }
        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11220
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back
#define FILE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);

using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 100001;
const int mod = 1000000007;

vector<int> adj[MAXN];

ll dp[MAXN][2]; // dp[i][j] = no. of ways to paint subtree rooted at  node i  if parent of i is colored j

ll dfs(int x, int p, int parentColor){
    if(dp[x][parentColor] != -1)return dp[x][parentColor];
    ll ret1 = 1, ret2 = 1-parentColor;
    for(int c : adj[x]){
        if(c != p){
                ret1 = (ret1 * dfs(c, x, 0))%mod;
        }
    }

    if(!parentColor){
        for(int c : adj[x]){
            if(c != p){
                    ret2 = (ret2 * dfs(c, x, 1))%mod;
            }
        }
    }

    return dp[x][parentColor] = (ret1 + ret2)%mod;
}

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

    fro(i,1,n)dp[i][0] = dp[i][1] = -1;

    fro(i,2,n){
        int x, y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    cout<< dfs(1, 0, 0) << endl;

}


Measured memory_bytes: 15616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, c[101][3], p[200][4];

int main(){
  scanf("%d", &N);
  rep(i, N) rep(j, 3){ scanf("%d", &p[i][j]); c[p[i][j]][j]++; }

  rep(i, N) rep(j, 3) if(c[p[i][j]][j] == 1) p[i][3] += p[i][j];
  
  rep(i, N) printf("%d\n", p[i][3]);
  return 0;
}

Measured memory_bytes: 1192
# https://atcoder.jp/contests/abc138/tasks/abc138_c

class PriorityQueue
  def initialize(values = [])
    @data = []
    values.each{|value| add(value)}
  end

  def add(value)
    @data.push(value)
    bottom_up
  end

  def peek
    @data[0]
  end

  def poll
    if size == 0
      nil
    elsif size == 1
      @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop # 末尾を先頭へ
      top_down # Queueを再構築
      min
    end
  end

  def size
    @data.size
  end

  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end


  def bottom_up
    idx = size - 1
    while has_parent?(idx)
      parent_idx = parent_idx(idx)
      if @data[parent_idx] > @data[idx]
        swap(parent_idx, idx)
        idx = parent_idx
      else
        return
      end
    end
  end

  def top_down
    idx = 0
    while has_child?(idx)
      a = left_child_idx(idx)
      b = right_child_idx(idx)
      if @data[b].nil?
        c = a
      else
        c = @data[a] <= @data[b] ? a : b
      end
      if @data[idx] > @data[c]
        swap(idx, c)
        idx = c
      else
        return
      end
    end
  end

  def parent_idx(idx)
    (idx - (idx.even? ? 2 : 1)) / 2
  end

  def left_child_idx(idx)
    (idx * 2) + 1
  end

  def right_child_idx(idx)
    (idx * 2) + 2
  end

  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end

  def has_parent?(idx)
    idx > 0
  end
end


N = gets.to_i
vs = gets.split.map(&:to_i)

queue = PriorityQueue.new(vs)

while queue.size > 1
  ave = (queue.poll + queue.poll) / 2.0
  queue.add(ave)
end

puts queue.poll


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

void dfs(int cur, vector<vector<pair<int, int>>> *edge, vector<int> *color){
  for (int i = 0; i < (*edge)[cur].size(); i++){
    if ((*color)[(*edge)[cur][i].first] == -1){
      if ((*edge)[cur][i].second % 2 == 1)
        (*color)[(*edge)[cur][i].first] = 1 - (*color)[cur];
      else
        (*color)[(*edge)[cur][i].first] = (*color)[cur];
      dfs((*edge)[cur][i].first, edge, color);
    }
  }
}


int main(void){
  int n;

  cin >> n;
  vector<vector<pair<int, int>>> edge(n, vector<pair<int, int>>(0));


  int a, b, c;
  for (int i = 0; i < n - 1; i++){
    cin >> a >> b >> c;
    edge[a-1].push_back(pair<int,int>(b-1, c));
    edge[b-1].push_back(pair<int,int>(a-1, c));
  }


  vector<int> color(n, -1);

  color[0] = 0;
  dfs(0, &edge, &color);


  for (int i = 0; i < n; i++){
    cout << color[i] << endl;
  }

  return 0;
}


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

int main()
{
	int n; std::cin >> n;
	int* A = new int[n];
	for (int i=0; i<n; i++) std::cin >> A[i];
	
	int q; std::cin >> q;
	
	for (int i=0; i<q; i++) {
		int b, e;
		std::cin >> b >> e;
		std::reverse(A + b, A + e);
	}
	
	std::cout << A[0];
	for (int i=1; i<n; i++) std::cout << " " << A[i];
	std::cout << std::endl;
	
	delete[] A;
	
	return 0;
}



Measured memory_bytes: 3104
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000
typedef long long i64;

int n;
int d[MAXN], c[MAXN];
vector<pair<int,int>> g[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	memset(d, 0, sizeof(d));
	for (int i=0; i<n-1; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		x--, y--;
		d[x]++, d[y]++;
		g[x].push_back({y,i});
		g[y].push_back({x,i});
	}
	return 1;
}

void init() {
}

void dfs(int v, int f) {
	int i = 1;
	for (auto x: g[v]) {
		int u = x.first, e = x.second;
		if (e==f) continue;
		if (f>=0 && i==c[f]) i++;
		c[e] = i++;
		dfs(u, e);
	}
}

int solve() {
	int k = 0;
	for (int i=0; i<n; i++)
		if (d[i] > d[k]) k = i;
	dfs(0, -1);
	return d[k];
}

void output(int ans) {
	printf("%d\n", ans);
	for (int i=0; i<n-1; i++) printf("%d\n", c[i]);
}

void cleanup() {
	for (int i=0; i<n; i++) g[i].clear();
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}




Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
int n,k;
double s;
double fb(int x,int y)
{
    int s=y;
    while(s<x)
        s*=2;
    s=s/y;
    return 1.0/s;
}
int main()
{
    cin>>n>>k;
    double x=0;
    for(int i=1;i<=n;i++)
    {
        x+=fb(k,i);
    }
    s=x/n;
    printf("%.17lf",s);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
#include<stack>
#include<fstream>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
ll k,n,p[200010],rui[200010];
int main(){
	cin>>n>>k;
	rui[0]=0;
	rep(i,n){
		cin>>p[i];
		p[i]++;
		rui[i+1]=rui[i]+p[i];
	}
	ll ans=0;
	for(int i=0;i+k-1<n;i++){
		chmax(ans,rui[i+k]-rui[i]);
	}
	cout<<fixed<<setprecision(9)<<(double)ans/(double)2<<endl;
}


Measured memory_bytes: 3328
#include <iostream>

size_t next_quasi753(size_t n) {
  if (n < 357) return 357;

  size_t r = n % 10;

  bool carry = false;

  if (r == 7) {
    carry = true;
    r = 3;
  } else if (r == 5) {
    r = 7;
  } else {
    r = 5;
  }

  size_t digit = 10;
  n /= 10;

  for (; n > 0; n /= 10) {
    auto d = n % 10;
    if (carry) {
      if (d == 7) {
        d = 3;
      } else if (d == 5) {
        carry = false;
        d = 7;
      } else {
        carry = false;
        d = 5;
      }
    }

    r += d * digit;
    digit *= 10;
  }

  if (carry)
    return 3*digit+r;
  else
    return r;
}

bool is_753(size_t n) {
  bool has_7 = false;
  bool has_5 = false;
  bool has_3 = false;

  for (; n > 0; n /= 10) {
    switch (n % 10) {
    case 7:
      has_7 = true;
      break;
    case 5:
      has_5 = true;
      break;
    case 3:
      has_3 = true;
      break;
    default:
      return false;
    }
  }

  return has_7 & has_5 & has_3;
}

int main() {
  size_t N;

  std::cin >> N;

  size_t n = 0;
  size_t ans = 0;

  while (N >= (n = next_quasi753(n))) {
    // std::cerr << n << std::endl;
    if (is_753(n)) ans++;
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int count = 0;
	int counter = 0;
	int a[10000][3];
	while (1){
		for (int i = 0; i < 3; i++){
			cin >> a[count][i];
		}
		if (a[count][0] == -1 && a[count][1] == -1 && a[count][2] == -1){
			break;
		}
		count += 1;
	}
	while (1){
		if (a[counter][0] == -1 || a[counter][1] == -1){
			cout << "F" << endl;
		}
		else if (a[counter][0] + a[counter][1] >= 80){
			cout << "A" << endl;
		}
		else if (a[counter][0] + a[counter][1] >= 65){
			cout << "B" << endl;
		}
		else if (a[counter][0] + a[counter][1] >= 50){
			cout << "C" << endl;
		}
		else if (a[counter][0] + a[counter][1] >= 30){
			if (a[counter][2] >= 50){
				cout << "C" << endl;
			}
			else{
				cout << "D" << endl;
			}
		}
		else{
			cout << "F" << endl;
		}
		counter += 1;
		if (counter == count){
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i, N) cin >> A.at(i);
    rep(i, N) cin >> B.at(i);
    rep(i, N) cin >> C.at(i);
    sort(all(A));
    sort(all(C));

    ll ans = 0;
    rep(i, N){
        int b = B.at(i);
        ll an = lower_bound(all(A), b) - A.begin();
        ll cn = C.end() - upper_bound(all(C), b);
        ans += an * cn;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,n) for ( int i = (a); i < (n); ++i)
#define REP(i,n) for( int i = 0; i < (n); ++i )
#define ALL(obj) (obj).begin(), (obj).end()

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

    queue<double> q;
    double sum = 0.0;
    double max = 0.0;

    REP(i,K) {
        q.push(0.0);
    }

    REP(i,N) {
        double v;
        cin >> v;
        double e = (v+1.0)/2.0;

        sum -= q.front();
        //cout << (sum + e) << endl;
        q.pop();
        sum += e;
        q.push(e);

        if( max < sum ) {
            max = sum;
        }
    }
    cout << fixed << max << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s,sv,v,vs,f=1,i=0;
  cin>>s>>sv>>v>>vs;
  while(f)
  {
    if(i%2==0)
    {
      v=v-sv;
      if(v<1)
      {
        cout<<"Yes";
    	exit(0);
      }
    } 
    else
    {
      s=s-vs;
      if(s<1)
      {
        cout<<"No";
        exit(0);
      } 
    }
    i++;
  }
}  

Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  
  ll d = c - a - b;
  string result = (d > 0 && d * d > 4 * a * b)? "Yes" : "No";
  cout << result;
  return 0;
}

Measured memory_bytes: 3624
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut aa: [usize; n],
        mut bb: [usize; n],
        mut cc: [usize; n],
    }

    aa.sort();
    bb.sort();
    cc.sort();

    let mut a_index = 0;
    let mut c_index = 0;
    let mut counts = vec![];
    for &b in bb.iter() {
        for &a in aa.iter().skip(a_index) {
            if a >= b {
                break;
            }
            a_index += 1;
        }
        for &c in cc.iter().skip(c_index) {
            if b < c {
                break;
            }
            c_index += 1;
        }
        let a_count = std::cmp::min(aa.len(), a_index);
        let c_count = cc.len() - c_index;
        let count = a_count * c_count;
        counts.push(count);
    }

    let ans = counts.into_iter().sum::<usize>();
    println!("{}", ans);
}


Measured memory_bytes: 8688
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return


ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////

int main(){

    int a,b,c;
    cin >> a >> b >> c;

    swap(a,b);
    swap(a,c);

    PS(a);PS(b);PS(c);
    return  0;
}


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

int main(){
  int n, d, p[10][10];
  double check;
  int count=0;
  cin >> n >> d;
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
    	cin >> p[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      check =0;
      for(int k=0;k<d;k++){
        check += pow((p[i][k]-p[j][k]),2);
      }
      check = sqrt(check);
      if(floor(check)==ceil(check)){
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
long long int max(long long int a,long long int b)
{
    return a>b?a:b;
}
long long int Knapsack(long long int wt[],long long int v[],long long int W,int n)
{
    long int i,w;
    long long int k[n+1][W+1];
    for(i=0;i<=n;i++)
    {
        for(w=0;w<=W;w++)
        {
            if(i==0||w==0)
              k[i][w]=0;
            else if(wt[i-1]<=w)
            k[i][w]=max(v[i-1]+k[i-1][w-wt[i-1]],k[i-1][w]);
            else
            k[i][w]=k[i-1][w];
        }
    }
    return k[n][W];
}
int main()
{
    int n,i;
    long long int W,wt[100000],v[100000];
    scanf("%d%lld",&n,&W);
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&wt[i],&v[i]);
    }
    long long int r=Knapsack(wt,v,W,n);
    printf("%lld ",r);
}


Measured memory_bytes: 79104
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]  # parent. if par[x]==x: x is root.
        self.rank = [0 for i in range(n)]  # depth of tree

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if(x == y):
            return

        if(self.rank[x] < self.rank[y]):
            self.par[x] = y
        else:
            self.par[y] = x
            if(self.rank[x] == self.rank[y]):
                self.rank[x] += 1

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

    def is_root(self, x):
        return self.par[x] == x

    def roots(self):
        return [i for i in range(self.n) if self.is_root(i)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def groups(self):
        return {r: self.members(r) for r in self.roots()}


def main():
    N, M = map(int, input().split())
    p = list(map(int, input().split()))
    p = list(map(lambda x: x - 1, p))

    UF = UnionFind(N)
    for i in range(M):
        x, y = map(int, input().split())
        UF.unite(x - 1, y - 1)

    ans = 0
    for i in range(N):
        if UF.same(i, p[i]):
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13940
use strict;
use warnings;
use utf8;

use feature qw(say);
use Data::Dumper;

my $n = <STDIN>;
chomp $n;

my $as = <STDIN>;
chomp $as;
my $num_list = [split / /, $as];
my $sum = 0;

my $current = $num_list->[0];
my $next_index = 1;

while (1) {
    my $next = $num_list->[$next_index];
    last unless defined($next);
    if ($next < $current) {
        my $extra = $current - $next;
        $sum += $extra;
    } else {
        $current = $next;
    }
    $next_index++;
}

say $sum;

Measured memory_bytes: 39440
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

bool dp[100010];

int main(){
  int n,k; cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,k+1)rep(j,n){
    if(i-a[j]>=0) dp[i]|=!dp[i-a[j]];
  }
  if(dp[k]) cout << "First" << endl;
  else cout << "Second" << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000000;
ll INF=1e18;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}


void solve()
{    
     ll n,k;
     cin>>n>>k;
     ll i;
     vector<ll> v(n);
     for(i=0;i<n;i++)
          cin>>v[i];
     ld sum =0;
     ld epsilon = 0.000001;
     ld curmax=0.0;
     for(i=0;i<k;i++)
          sum+=v[i];
     curmax = (sum+k)/2;
     for(i=k;i<n;i++)
     {
          sum+=v[i]-v[i-k];
          ld cd = (sum+k)/2;
          if(cd>curmax+epsilon)
          {
               curmax=cd;
          }
     }
     cout<<setprecision(12)<<curmax;
}
     
     
     
    

     
     


int main()
{
    ios;
    ll t;
     // cin>>t;
     t=1;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 4664
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int l, r, d;
  cin >> l >> r >> d;
  kek(r / d - (l - 1) / d);
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,mx=0,bi,tp=0;
  int x[100001];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
    mx=max(mx,x[i]);
  }
  bi=mx/2;
  for(int i=0;i<n;i++){
    if(abs(bi-tp)>abs(bi-x[i]))tp=x[i];
  }
  cout<<mx<<" "<< tp<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for (int i = 0; i < t; i++)

int main()
{
    int N, H, W, A[1010], B[1010];
    cin >> N >> H >> W;
    REP(i, N) cin >> A[i] >> B[i];

    int ans = 0;
    REP(i, N)
        if (H <= A[i] && W <= B[i])
            ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	int s=0;
	cin>>a>>b>>c>>d;
	if(a>=b)
	s+=b;
	else
	s+=a;
	if(c>=d)
	s+=d;
	else
	s+=c;
        cout<<s;
	return 0;
}

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


int main(){
	string a,b,c;
	cin >> a >> b >> c;
	if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
		cout << "YES" << endl;

	}
	else{
		cout << "NO" << endl;
	}

	}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string S;
    cin >> S;
    if(S.size() == 2) {
        printf("%s\n", S.c_str());
    } else {
        reverse(S.begin(), S.end());
        printf("%s\n", S.c_str());
    }
    return 0;
}


Measured memory_bytes: 256
/* Author darklight13 -_- 
   IIT Patna 
*/
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
using namespace std;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " is " << (x) << endl
#define dbg(x)     cout << x << ' '
#define here cout << " Hey baitch!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld PI = 3.1415926535898;
int n,dp[3000][3000];
vi a;
int play(int l, int r) {
	if(dp[l][r] != -1)	return dp[l][r];
	if(l > r)	return 0;
	if(l==r) {
		dp[l][r] = a[l];
		return a[l];
	}
	int res = max(a[l]-play(l+1,r),a[r]-play(l,r-1));
	dp[l][r] = res;
	return res;
}
int32_t main()
{
	SYNC
	cin >> n;
	memset(dp,-1,sizeof dp);
	a.resize(n);
	for(int &x : a)	cin >> x;
	cout << play(0,n-1);
    return 0;
}

Measured memory_bytes: 70784
N = int(input())
A = list(map(int,(input().split())))
S = A #調べたいリスト

result={}
for i in range (0,len(S)):
    item = S[i]
    if item in result:
        result[item] = result[item]+1
    else:
        result[item] = 1

a = [k for k, v in result.items()]

h = []
for i in a:
    h.append(result[i]-1)

h.sort(reverse=True)

n = len(h)
for i in range(n):
    if h[i] >= 1:
        if h[i]%2 == 1:
            h[i] = 1
        else:
            h[i] = 0

if sum(h) % 2 == 0:
    print(n)
else:
    print(n-1)

Measured memory_bytes: 63208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a, b; 
    while(cin >> a >> b) {
        if(a == 0 and b == 0) return 0;
        if(a > b) swap(a,b);
        cout << a << " " << b << endl;
    }

    
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include<queue>

using namespace std;
int G[9][9];


int main() {
	int N, M;
	int ans = 0;
	cin >> N >> M;
	int A[50], B[50];

	

	for (int i = 0; i < M; i ++) {
		cin >> A[i] >> B[i];
		G[A[i]][B[i]] = 1;
		G[B[i]][A[i]] = 1;
	}

	vector<int> v(N);
	
	for (int i = 0; i < N; i++) {
		v[i] = i + 1;
	}

	do {
		if (v[0] == 1) {
			int flag = 1;
			for (int i = 0; i < N - 1; i++) {
				if (G[v[i]][v[i + 1]] == 0)flag = 0;
			}
			if (flag == 1)ans++;
		}


		
	} while (next_permutation(v.begin(), v.end()));


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast_I_O ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod = 1e9+7 , INF = 1e9 ,  mx = 100005 ;
main()
{
    fast_I_O;
    int i,j,n,m,x=0,y,sum=0,p=0,l,k;
    string s;
    cin>>s;
    for(i=0;i<3;i++)
    {
        if(s[i]=='R')
        ++p , x=max(x,p);
        else p=0;
    }
    cout<<x;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int m;
    in>>m;
    ll D,C,d=0,s=0;
    fr(i,m) in>>D>>C,d+=D*C,s+=C;
    cout<<(d-1)/9+s-1<<endl;
}

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

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

int main() {
    ll w,h,x,y;
    cin >> w >> h >> x >> y;
    double ans = (double) (h*w) / 2;
    int b = 0;
    if (w%2 == 0 && h%2 == 0 && w/2 == x && h/2 == y) b++;
    cout << ans << " " << b << endl;
    return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
int f(int x)
{
	int a[10],len=0,i,j;
	while(x>0){
		a[len++]=x%10;
		x=x/10;
	} 
	int y=1;
	for(i=0,j=len-1;i<j;i++,j--){
		if(a[i]==a[j]) y=1;
		else {
			y=0; break;
		}	
	}
	return y;
	

}
int main()
{
	int x,y,k,i;
	scanf("%d%d",&x,&y);
	int ans=0;
	for(i=x;i<=y;i++){
		k=f(i);
		if(k==1){
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import fractions

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

left = [0] * (N + 1)
right = [0] * (N + 1)

for i in range(N):
    left[i + 1] = fractions.gcd(A[i], left[i])

for i in reversed(range(N)):
    right[i] = fractions.gcd(A[i], right[i + 1])

max_gcd = 1

for i in range(N):

    l = left[i]
    r = right[i + 1]

    gcd_num = fractions.gcd(l, r)

    max_gcd = max(max_gcd, gcd_num)

print(max_gcd)


Measured memory_bytes: 89580
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x, t;
		
		x = sc.nextInt();
		
		sc.close();
		
		t = (int)Math.ceil((-3.0 + Math.sqrt(9.0 - 8.0 * (1.0 - (double)x))) / 2.0); 
		System.out.println(t + 1);
	}

}


Measured memory_bytes: 22868