akhauriyash/Code-Regression huggingface dataset:
///dp solution
#include<bits/stdc++.h>
using namespace std;
const int N=100007;
long long dp[N][3];
int main(){
  int n,A[N],B[N],C[N];
  cin>>n;
  for(int i=0;i<n;++i)
    cin>>A[i]>>B[i]>>C[i];
  dp[0][0]=A[0],dp[0][1]=B[0],dp[0][2]=C[0];
  for(int i=1;i<n;++i){
    dp[i][0]=A[i]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=B[i]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=C[i]+max(dp[i-1][0],dp[i-1][1]);
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


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

using namespace std;
typedef long long int ll;


int main()
{
   string s;
   cin>>s;
   int ans=0,count=0;
   if(s[0]=='R')
   {
       count += 1;
   }
   if(s[1] == 'R')
   {
       count += 1;
       ans = max(ans,count);
   }
   else
   {
       ans = count;
       count =0;
   }
   if(s[2] == 'R')
   {
       count += 1;
       ans =max(ans,count);
   }
   cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3576
from collections import deque
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
table = [[] for i in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  table[a].append(b)
  table[b].append(a)
task = [0]*N
count = [0]*N
visited = [-1]*N
visited[0] = 1
for i in range(Q):
  p,x = map(int,input().split())
  p -= 1
  task[p] += x
H = deque()
H.append(0)
while H:
  y = H.popleft()
  count[y] += task[y]
  for ny in table[y]:
    if visited[ny] == -1:
      visited[ny] = 1
      H.append(ny)
      count[ny] = count[y]
print(" ".join(map(str,count)))
    


Measured memory_bytes: 74576
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <tuple>
# include <functional>
# include <utility>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;

int main() {
	int n;
	std::cin >> n;
	int ans = -INF, min = INF;
	int a;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		ans = std::max(ans, a - min);
		min = std::min(a, min);
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
#include <iterator>     // std::back_inserter
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
const ll inf = 1e18+1;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
//小文字=大文字+32
int main() {
	
	int n;
	cin >> n;
	vector<vector<int>>a(n, vector<int>(3));
	vector<int>dp(3);
	vector<int>tmp(3);
	rep(i, n) {
		rep(j, 3) {
			cin >> a[i][j];
		}
	}
	dp[0] = a[0][0];
	dp[1] = a[0][1];
	dp[2] = a[0][2];
	tmp = dp;
		//copy(dp.begin(), dp.end(), back_inserter(tmp));
	for (int i = 1; i < n; i++) {
		dp[0] = max(a[i][0] + tmp[1], a[i][0] + tmp[2]);
		dp[1] = max(a[i][1] + tmp[0], a[i][1] + tmp[2]);
		dp[2] = max(a[i][2] + tmp[1], a[i][2] + tmp[0]);
		tmp = dp;
		//copy(dp.begin(), dp.end(), back_inserter(tmp));
	}
	cout << max({ dp[0], dp[1], dp[2] }) << endl;

}


Measured memory_bytes: 8768
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 100000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

// Input number
func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

func main() {
	K := scanIntNum()
	var ans int

	// 1 -> *3
	for i := 1; i <= K-2; i++ {
		for j := i + 1; j <= K-1; j++ {
			for k := j + 1; k <= K; k++ {
				ans += gcd(i, j, k) * 6
			}
		}
	}
	// 2 -> *3
	for i := 1; i <= K-1; i++ {
		for j := i + 1; j <= K; j++ {
			ans += gcd(i, i, j) * 3
			ans += gcd(i, j, j) * 3
		}
	}

	// 3 -> *1
	for i := 1; i <= K; i++ {
		ans += gcd(i, i, i)
	}

	fmt.Println(ans)
}

func gcd(a, b, c int) int {
	min := a

	if b < min {
		min = b
	}
	if c < min {
		min = c
	}

	for i := min; i > 0; i-- {
		if (a%i == 0) && (b%i == 0) && (c%i == 0) {
			return i
		}
	}
	return 1
}


Measured memory_bytes: 1840
#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<functional>


using namespace std;

typedef long long ll;
ll d;
int n,m;
vector<ll> s;

ll labs(ll a){
	if(a<0)return -a;
	return a;
}


int main(void){
	while(1){
		scanf("%lld",&d);
		if(d==0)break;
		scanf("%d%d",&n,&m);
		s.clear();
		s.push_back(-1);
		s.push_back(0);
		s.push_back(d);
		for(int i=0;i<n-1;i++){
			ll a;
			scanf("%lld",&a);
			s.push_back(a);
		}
		sort(s.begin(),s.end());
		ll res=0;
		for(int i=0;i<m;i++){
			ll a;
			scanf("%lld",&a);
			int k=lower_bound(s.begin(),s.end(),a)-s.begin();
			if(s[k]==a)continue;
			res+=min(labs(a-s[k]),labs(a-s[k-1]));
		}
		printf("%lld\n",res);
	}
	return 0;
}

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

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

    vector<long long> C(N+1);
    for (int i=1; i<=N; i++)
        for (int j=i; j<=N; j+=i)
            C[j]++;
    long long ans = 0;
    for (int K=1; K<=N; K++)
        ans += K*C[K];
    cout<<ans<<endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	
	if(a > c) swap(a,c);
	if(b > d) swap(b,d);

	if(a==c or b==d){
		cout << 0 << endl;
		return 0;
	}

	int dy=d-b,dx=c-a;
	const int g=__gcd(dx,dy);
	dx/=g,dy/=g;

	cout << 1LL*g*(dx+dy-1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,i,j;
	scanf("%d %d",&a,&b);
	while(a!=0 || b!=0){
		for(i=1;i<=a;i++){
			for(j=1;j<=b;j++){
				if(i==1 || j==1 || i==a || j==b){
					printf("#");
				}
				else{
					printf(".");
				}		
			}
				printf("\n");
		}
			printf("\n");
			scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 1000
a,b,c,x,y=map(int, input().split( ))
#超過してよい
#x,y<=10000
ans=10**15

for i in range(0,max(x,y)+7):
    tmp = 2*i*c
    tmp+=max(0,(x-i)*a)
    tmp+=max(0,(y-i)*b)
    ans=min(ans, tmp)
print(ans)



Measured memory_bytes: 40048
#include <iostream>
#include <cstdio>

using namespace std;

class list
{
  struct node
  {
    int val;
    node* prev;
    node* next;
    node(int n) : val(n), prev(NULL), next(NULL) {}
    node(int n, node* prev_p, node* next_p) : val(n), prev(prev_p), next(next_p) {}
  };

  node* nil;
  node* cur;

public:
  list()
  {
    nil = new node(0);
    nil->prev = nil;
    nil->next = nil;
    cur = nil;
  }
  ~list() { clear(); }

  void insert(int val);
  void move(int d);
  void erase();
  void dump();
  void clear();
private:
  void moveForward(int d);
  void moveBackword(int d);
};

void list::insert(int val)
{
  // 新しいオブジェクトを作成する
  // 新しいオブジェクトのprevをcurのprevにする
  // 新しいオブジェクトのnextをcurにする
  node* newobj = new node(val, cur->prev, cur);

  // curのprevのnextを新しいオブジェクトにする
  cur->prev->next = newobj;

  // curのprevを新しいオブジェクトにする
  cur->prev = newobj;

  // curを新しいオブジェクトにする
  cur = newobj;
}

void list::move(int d)
{
  if (d == 0) return;
  if (d > 0) moveForward(d);
  else moveBackword(d * (-1));
}

void list::erase()
{
  if (cur == nil) return;
  // curのnexeのprevをcurのprevにする
  cur->next->prev = cur->prev;
  // curのprevのnextをcurのnextにする
  cur->prev->next = cur->next;

  node* p = cur;
  cur = cur->next;

  delete p;
}

void list::moveForward(int d)
{
  while (d > 0 && cur != nil)
  {
    cur = cur->next;
    --d;
  }
}

void list::moveBackword(int d)
{
  while (d > 0)
  {
    cur = cur->prev;
    --d;
  }
}

void list::dump()
{
  node* p = nil->next;
  while (p != nil)
  {
    printf("%d\n", p->val);
    p = p->next;
  }
}

void list::clear()
{
  node* p = nil->next;
  node* tmp;
  while (p != nil)
  {
    tmp = p;
    p = p->next;
    delete tmp;
  }
  delete nil;
}


int main()
{
  int q, i, c, n;
  list arylist;

  scanf("%d", &q);

  for (i = 0; i < q; i++)
  {
    scanf("%d", &c);
    switch (c)
    {
    case 0:
      scanf("%d", &n);
      arylist.insert(n);
      break;
    case 1:
      scanf("%d", &n);
      arylist.move(n);
      break;
    case 2:
      arylist.erase();
      break;
    }
  }

  arylist.dump();

  return 0;
}


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

class C
{
	static void Main()
	{
		var n = long.Parse(Console.ReadLine());
		Console.WriteLine(Divisors(n).Select(x => x + n / x - 2).Min());
	}

	static long[] Divisors(long v)
	{
		var d = new List<long>();
		for (long i = 1, rv = (long)Math.Sqrt(v); i <= rv; i++)
			if (v % i == 0) d.Add(i);
		return d.ToArray();
	}
}


Measured memory_bytes: 13396
X, Y = map(int, input().split())
ans = 0
if X == 3:
    ans += 100000
elif X == 2:
    ans += 200000
elif X == 1:
    ans += 300000

if Y == 3:
    ans += 100000
elif Y == 2:
    ans += 200000
elif Y == 1:
    ans += 300000

if X == 1 and Y == 1:
    ans += 400000

print(ans)


Measured memory_bytes: 38384
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let v: Vec<usize> = line.unwrap()
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect();
        if v == [0, 0] {
            return;
        }
        let top_bottom = "#".repeat(v[1]);
        let blank = format!("#{}#\n", ".".repeat(v[1] - 2));
        println!("{}\n{}{}\n", top_bottom, blank.repeat(v[0] - 2), top_bottom);
    }
}



Measured memory_bytes: 5064
module Main where

import Numeric
import Data.Functor

main :: IO ()
main = do
  { [a,b] <- getInts
  ; let (q,r) = divMod a b
  ; let s = fromIntegral a / fromIntegral b
  ; putStrLn . unwords $ [show q, show r, showFFloat Nothing s ""]
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

done :: IO ()
done = return ()

Measured memory_bytes: 4032
#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define CEIL_DIV(a, b) (((a)-1) / (b) + 1)

int main() {
    int N;
    scanf("%d", &N);

    long long int curT = 1, curA = 1;
    while (N--) {
        int inT, inA;
        scanf("%d%d", &inT, &inA);
        long long int gcd = MAX(CEIL_DIV(curT, inT), CEIL_DIV(curA, inA));
        curT = inT * gcd;
        curA = inA * gcd;
    }
    printf("%lld", curT + curA);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const ll mod = 998244353;

int main() 
{
    int n, k;
    cin >> n >> k;
    if(n % 2 == 1){
        int l = 1, r = n;
        while(k -- ){
            cout << l << ' ' << r << '\n';
            l++;
            r--;
        }
    }
    else{
        int b = k / 2, a = k - b;
        int l = 1, r = (n + 1) / 2;
        while(a--){
            cout << l << ' ' << r << '\n';
            l++;
            r--;
        }
        l = (n + 1) / 2 + 1, r = n - 1;
        while(b--){
            cout << l << ' ' << r << '\n';
            l++, r--;
        }
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k;
    cin >> n >> k;
    double ans=0;
    for(int i=1;i<=n;i++){
        double p=1.0/n; 
        int dice = i;
        while(dice<=k-1){
            dice = dice*2;
            p/=2.0;
        }
        ans += p;
    }
    cout << setprecision(13) << ans << endl;
    
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          l = Math.max(l, lc);
          r = Math.min(r, rc);
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 44644
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}
ll mod=1e9+7;
ll fib[100005]={0};
int main()
{
    fio;
    fib[0]=1;
    fib[1]=1;
    repA(i,2,100005)
    fib[i]=(fib[i-1]+fib[i-2])%mod;
    ll n,m;
    cin>>n>>m;
    ll a[m];
    rep(i,m)
    cin>>a[i];
    sort(a,a+m);
    if(m==0)
    {
        cout<<fib[n]%mod;
        return 0;
    }
    repA(i,1,m-1)
    {
        if(a[i]-a[i-1]==1)
        {
            cout<<0;
            return 0;
        }
    }
    ll diff[m+1];
    diff[0]=a[0]-1;
    repA(i,1,m-1)
    {
        diff[i]=a[i]-a[i-1]-2;
    }
    diff[m]=n+1-a[m-1]-2;
    ll ans=1;
    rep(i,m+1)
    {
        ans=(ans*fib[diff[i]])%mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n;
vector<vi> e, g;
bool v[200000];

void rec(int c, int p){
	v[c] = 1;
	int cnt = 0;
	for(int i : g[c]) if(i != p){
		cnt++;
		rec(i, c);
	}
	if(g[c].size() > 2){
		cout << -1 << endl;
		exit(0);
	}
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n;
	if(n < 4){
		for(int i = 1; i <= n; i++) cout << i << (i==n?"\n":" ");
		return 0;
	}
	
	e.resize(n);
	g.resize(n);
	rep(i, n - 1){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	rep(i, n) if(e[i].size() > 1) for(int j : e[i]) if(e[j].size() > 1) g[i].pb(j);
	rep(i, n) if(e[i].size() > 1){
		rec(i, i);
		break;
	}
	rep(i, n) if(e[i].size() > 1 && !v[i]){
		cout << -1 << endl;
		return 0;
	}
	
	//rep(i, n) dbg(i, g[i]);
	vi seq;
	
	rep(i, n) if(e[i].size() > 1 && g[i].size() <= 1){
		int c = i, p = i;
		for(; ;){
			bool f = 0;
			seq.pb(e[c].size());
			for(int j : g[c]) if(j != p){
				f = 1; p = c; c = j;
				break;
			}
			if(!f) break;
		}
		break;
	}
	
	vi ans;
	rep(it, 2){
		vi tmp(1, 1);
		int cur = 1;
		rep(i, seq.size()){
			int x = max(0, seq[i] - 2);
			cur++;
			rep(j, x) tmp.pb(cur + 1 + j);
			tmp.pb(cur);
			cur += x;
		}
		tmp.pb(++cur);
		//assert(cur == n);
		if(ans.empty() || ans > tmp) ans = tmp;
		
		
		//dbg(seq, tmp);
		
		reverse(all(seq));
	}
	rep(i, ans.size()) cout << ans[i] << (i==ans.size()-1?"\n":" ");
	return 0;
}

Measured memory_bytes: 15348
#include<stdio.h>


int main(){
	double high=0.0,low=1e100;
	double yama;
	while(~scanf("%lf",&yama)){
		if(yama>high){
			high = yama ;
		}
		else if(low>yama){
			low = yama ;
		}
	}

	printf("%.1lf\n",high-low);
	return 0;
}

Measured memory_bytes: 648
n = int(input())
lst = list(map(int, input().split()))

sort = sorted(lst)
medi1 = sort[n//2-1]
medi2 = sort[n//2]
    
for i in range(n):
  if lst[i] <= medi1:
    print(medi2)
  else:
    print(medi1)
  

Measured memory_bytes: 104700
#include <stdio.h>

int main(void)
{
    int i, j;
    int h[10];
    int t;

    for (i = 0; i < 10; i++) {
        scanf("%d", &h[i]);
    }

    for (i = 0; i < 9; i++) {
        for (j = 9; j >= i; j--) {
            if (h[j] < h[j + 1]) {
                t = h[j];
                h[j] = h[j + 1];
                h[j + 1] = t;
            }
        }
    }

    for (i = 0; i < 3; i++) {
        printf("%d\n", h[i]);
    }

    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(){

  int n,sum,i;

  while(1){

    scanf("%d",&n);
    if(n == 0) break;
    if(n == 1){

      printf("deficient number\n");
      continue;

    }

    sum=1;

    for(i = 2; i*i <= n; i++){

      if(n%i == 0){

        sum += i+n/i;
        if(i == n/i) sum -= i;

      }

      if(sum > n) break;

    }

    if(sum == n) printf("perfect number\n");
    if(sum < n) printf("deficient number\n");
    if(sum > n) printf("abundant number\n");

  }

  return 0;

}

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

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	if (a >= 1 && a <= 9 && b >= 1 && b <= 9) printf("%d", a * b);
	else puts("-1");
	return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>
#include <sstream>
using namespace std;

vector<string> split(const string& s, char delim) {
	vector<string> elems;
	stringstream ss(s);
	string item;
	while (getline(ss, item, delim)) {
		if (!item.empty()) {
			elems.push_back(item);
		}
	}
	return elems;
}

int main() {

	int n, k;
	cin >> n >> k;
	vector<int> p;
	for (int i = 0; i < n; i++)
	{
		int temp;
		cin >> temp;
		p.push_back(temp);
	}

	std::sort(p.begin(), p.end());

	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += p[i];
	}

	cout << sum << endl;

	return 0;
}

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

int main() {
    int N;
    cin>>N;
    vector<int> C(4,0);
    for (int i = 0; i < N; i++){
        string S;
        cin>>S;
        if(S=="AC")C[0]++;
        else if(S=="WA")C[1]++;
        else if(S=="TLE")C[2]++;
        else C[3]++;
    }
    cout<<"AC x "<<C[0]<<endl;
    cout<<"WA x "<<C[1]<<endl;
    cout<<"TLE x "<<C[2]<<endl;
    cout<<"RE x "<<C[3]<<endl;
}

Measured memory_bytes: 3632
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(c - (a - b), 0ll) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
using namespace std;
string str, str2;
int main() {
	int N,tmp;
	vector<int> A;
	vector<int> B;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> tmp;
		A.push_back(tmp);
		B.push_back(0);
	}
	for (int i = 0;i < N;i++) {
		B[A[i] - 1] = i;
	}
	for (int i = 0;i < N;i++) {
		cout << B[i] + 1 << " ";
	}

	return 0;
}


Measured memory_bytes: 1780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var raw = ReadLine().Split().Select(int.Parse).ToArray();
            var A = raw[0];
            var B = raw[1];
            var C = raw[2];

            var ans = B / A;
            WriteLine(ans > C ? C : ans);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


int main(){
    int N;
    cin>>N;
    int a[100004];
    REP(i,N){
        cin>>a[i];
        a[i]--;
    }
    int cnt=0;
    REP(i,N){
        if(a[a[i]]==i)cnt++;
    }
    cout<<cnt/2<<endl;
    return 0;
}

Measured memory_bytes: 640
use std::collections::VecDeque;
fn main() {
    input! {
        n: usize,
        m: usize,
        lrd: [(usize, usize, i64); m]
    }

    let INF = 1e15 as i64;
    let mut edges = vec![vec![]; n];
    for &(l, r, d) in lrd.iter() {
        let r = r - 1;
        let l = l - 1;
        edges[r].push((l, d));
        edges[l].push((r, -d));
    }

    let mut dists = vec![INF; n];
    for i in 0..n {
        if dists[i] != INF {
            continue;
        }
        let mut stack: VecDeque<usize> = VecDeque::new();
        dists[i] = 0;
        stack.push_front(i);
        while let Some(current) = stack.pop_front() {
            for &(nc, d) in &edges[current] {
                let dist = dists[current] + d;
                if dists[nc] == INF {
                    dists[nc] = dist;
                    stack.push_front(nc);
                } else {
                    if dists[nc] != dist {
                        println!("No");
                        return;
                    }
                }
            }
        }
    }

    println!("Yes");
}

fn dfs(v: usize, edges: &Vec<Vec<usize>>, visited: &mut Vec<bool>) -> bool {
    visited[v] = true;
    for &edge in &edges[v] {
        if visited[edge] {
            return false;
        }
        if !dfs(edge, &edges, visited) {
            return false;
        }
    }
    return true;
}

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

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

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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


Measured memory_bytes: 23480
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

    if(a<=2*b) cout<<0<<endl;
    else cout<<a-2*b<<endl;    

}



Measured memory_bytes: 256
from collections import deque
n,m=map(int,input().split())
edges=[[] for _ in range(n)]
visited=[-1 for _ in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)
def dfs(edges,visited):
  stack=deque([0])
  visited[0]=0
  while stack:
    x=stack.pop()
    for newx in edges[x]:
      if visited[newx]==visited[x]:
        return False,sum(visited)
      elif visited[newx]==-1:
        visited[newx]=(visited[x]+1)%2
        stack.append(newx)
  return True,sum(visited)
ok,b=dfs(edges,visited)
if ok:
  print(b*(n-b)-m)
else:
  print(n*(n-1)//2-m)

Measured memory_bytes: 22396
n = gets.to_i
h = gets.chomp.split.map(&:to_i)

(n - 2).downto(0) do |i|
  if h[i] > h[i + 1]
    if h[i] == h[i + 1] + 1
      h[i] -= 1
    else
      puts 'No'
      exit
    end
  end
end

puts h == h.sort ? 'Yes' : 'No'

Measured memory_bytes: 11256
#include<iostream>
using namespace std;
main()
{
	long n,m,A=1,B=1,a,t;cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>t>>a;
		m=max(A/t+!!(A%t),B/a+!!(B%a));
		A=t*m,B=a*m;
	}
	cout<<A+B<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int N;
ll X[2000000];

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

	vector<pair<ll, int> > vec;
	for(int i=0; i<N; i++){
		vec.push_back(make_pair(X[i], i));
	}
	sort(vec.begin(), vec.end());

	vector<pair<int, int> > vec2;
	for(int i=0; i<N; i++){
		vec2.push_back(make_pair(vec[i].second, i));
	}
	sort(vec2.begin(), vec2.end());

	for(int i=0; i<N; i++){
		int j=vec2[i].second;
		if(j<N/2){
			cout << vec[N/2].first << endl;
		}
		else{
			cout << vec[N/2-1].first << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 11116
function main(input) {
    var args = input.trim().split("\n");
    var N = Number(args[0]);
    var Hs = args[1].split(" ").map(v => Number(v));

    for (var i = 0; N > i; i++) {
        if (i === 0) {
            Hs[i] = Hs[i] > 0 ? Hs[i] - 1 : Hs[i]
            continue;
        }

        if (Hs[i - 1] < Hs[i]) {
            Hs[i] = Hs[i] > 0 ? Hs[i] - 1 : Hs[i]
        } else if (Hs[i - 1] === Hs[i]) {
            continue;
        } else {
            console.log("No");
            return;
        }
    }

    console.log("Yes");
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17816
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    int cnt = 0;
    int k = i;
    while(k%2 == 0){
      cnt++;
      k /= 2;
    }
    ans = max(cnt, ans);
  }
  cout << pow(2, ans) << endl;
  return 0;
}

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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    return iterator.next().unwrap()
        .chars()
        .filter(|c| *c == '1')
        .count()
        .to_string();
}


Measured memory_bytes: 2096
#include <stdio.h>
 
using namespace std;
 
void outPut(int Array[],char mark){
    for(int i = 1; i <= 13; i++){
        if(Array[i] == 0) printf("%c %d\n",mark,i);
    }
}
 
int main(){
    char mark[2];
    int n,S[14],H[14],C[14],D[14],tmp;
    for(int i = 0; i < 14; i++) S[i] = H[i] = C[i] = D[i] = 0;
    scanf("%d",&n);
 
    for(int i = 0; i < n; i++){
        scanf("%s %d",mark,&tmp);
        switch(mark[0]){
        case 'S':
            S[tmp] = 1;
            break;
        case 'H':
            H[tmp] = 1;
            break;
        case 'C':
            C[tmp] = 1;
            break;
        case 'D':
            D[tmp] = 1;
            break;
        }
    }
    outPut(S,'S');
    outPut(H,'H');
    outPut(C,'C');
    outPut(D,'D');
}


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

int main() {
 int S, h, m, ss;
 cin >> S;
 h = S / 3600;
 m = (S - (3600 * h)) / 60;
 ss = S - ((3600 * h) + (60 * m));

 cout << h << ":" << m << ":" << ss << endl;

 return 0;
 
}


Measured memory_bytes: 3100
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 200100;

    void solve(){
        string a, b;
        cin >> a >> b;
        ll cnt = 0;
        rep(i, 3) a[i]==b[i] ? cnt++:0;
        cout << cnt << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
     /*
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
      #endif
     */
      //te
      solve();
      return 0;
    } 


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

public class Main {	
	
	private static void solve(){
		//Implement solution here.
		String S = next();
		String T = next();
		if(T.indexOf(S, 0) == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25420
#include<stdio.h>

int main(void)
{
  int  n, m;
  int  t, i, l;
  long int  p;

  scanf("%d %d", &n, &m);

  if(n > m){ t=n;  n=m;  m=t;}
  if(m - n > 1){  l = 0; }
  else if( n == m){ l = 2; }
  else { l = m; }

  p = 1;
  for( i = 1; i <= n; i++){
    p *= i;
    p %= 1000000007;
    p *= i;
    p %= 1000000007;
  }
  p *= l;
  p %= 1000000007;

  printf("%ld\n", p);

  return 0;
}

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

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

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

typedef long long ll;

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    if (x < 0)
        x = -x;
    ll ls = x / d;
    ll ls2 = k - ls;
    ll lsx = x - ls * d;
    if (ls2 <= 0)
    {
        cout << x - k * d;
    }
    else
    {
        if (ls2 % 2)
            lsx -= d;
        cout << abs(lsx) << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Char
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

readIntTriplet :: BS.ByteString -> (Int, Int, Int)
readIntTriplet s = let Just (a, s') = BS.readInt s
                       Just (b, s'') = BS.readInt $ BS.dropWhile isSpace s'
                       Just (c, _) = BS.readInt $ BS.dropWhile isSpace s''
                   in (a, b, c)

main = do
  n <- readLn
  let loop 0 !a !b !c = return (a,b,c)
      loop i !a !b !c = do
        (a',b',c') <- readIntTriplet <$> BS.getLine
        -- a,b,c <= 10^4
        loop (i - 1) (max b c + a') (max a c + b') (max a b + c')
  (a,b,c) <- loop n 0 0 0
  print (max a (max b c))


Measured memory_bytes: 1020
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define next(a) ( ((a)+1)%SIZE )
#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000
#define SIZE 100000

typedef struct queue
{
	int front;
	int rear;
	int data[200];
}queue;

void init(queue* p)
{
	p->front = 0;
	p->rear = 0;
}

void enqueue(queue *p,int x)
{
	if (next(p->rear) == p->front)
		printf("OVERFLOW!\n");
	p->data[p->rear] = x;
	p->rear = next(p->rear);
}

int dequeue(queue *p)
{
	int x;

	if (p->front == p->rear)
		printf("NO DADA\n");

	x = p->data[p->front];
	p->front = next(p->front);

	return x;
}

int empty(queue *p)
{
	return p->front == p->rear;
}

void print(char* str, int a, int b)
{
	int i;

	for (i = a; i <= b; i++)
		printf("%c", str[i]);
	printf("\n");
}

void reverse(char* str, int a, int b)
{
	int i,j=0;
	char t;

	for (i = a; i <= (a + b) / 2; i++)
	{
		t = str[i];
		str[i] = str[b - j];
		str[b - j] = t;
		j++;
	}
}

void replace(char* str, int a, int b, char* temp)
{
	int i, j=0;

	for (i = a; i <= b; i++)
	{
		str[i] = temp[j];
		j++;
	}
}

double rad(int C)
{
	return M_PI * C / 180;
}

double distance(int* a, int* b, int n, int p)
{
	double sum = 0.0;

	int i, j;

	int max = 0;

	for (i = 0; i < n; i++)
	{
		sum += pow(ABS(a[i] - b[i]), p);

		if (ABS(a[i] - b[i]) > max)
			max = ABS(a[i] - b[i]);
	}

	if (p == INF)
		return max;

	return pow(sum, (double)1 / p);
}

typedef struct Dice
{
	int num[6];
}Dice;

void ROT(Dice* p,char R)
{
	int num2[6];
	int i;

	for (i = 0; i < 6; i++)
		num2[i] = p->num[i];

	if (R == 'E')
	{
		p->num[0] = num2[3];
		p->num[1] = num2[1];
		p->num[2] = num2[0];
		p->num[3] = num2[5];
		p->num[4] = num2[4];
		p->num[5] = num2[2];
	}

	if (R == 'S')
	{
		p->num[0] = num2[4];
		p->num[1] = num2[0];
		p->num[2] = num2[2];
		p->num[3] = num2[3];
		p->num[4] = num2[5];
		p->num[5] = num2[1];
	}

	if (R == 'W')
	{
		p->num[0] = num2[2];
		p->num[1] = num2[1];
		p->num[2] = num2[5];
		p->num[3] = num2[0];
		p->num[4] = num2[4];
		p->num[5] = num2[3];
	}

	if (R == 'N')
	{
		p->num[0] = num2[1];
		p->num[1] = num2[5];
		p->num[2] = num2[2];
		p->num[3] = num2[3];
		p->num[4] = num2[0];
		p->num[5] = num2[4];
	}
}

int main()
{
	Dice dice;
	int n;
	char str[150];
	int i, j;
	int u, d;
	int temp;

	for (i = 0; i < 6; i++)
		scanf("%d", &dice.num[i]);

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d%d", &u, &d);
		
		while (1)
		{
			temp = rand() % 4;
			if (temp == 0)
				ROT(&dice, 'E');
			else if (temp == 1)
				ROT(&dice, 'S');
			else if (temp == 2)
				ROT(&dice, 'W');
			else if (temp == 3)
				ROT(&dice, 'N');

			if (dice.num[0] == u && dice.num[1] == d)
			{
				printf("%d\n", dice.num[2]);
				break;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 2028
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30;
vector<long long int> baum;
long long int n, ans, minma = INF;
long long int Baum = 0, Baum3 = 0;

void cut(long long int f) {
	long long int s = f + Baum3, t = s + Baum3;
	long long int p;
	long long int sp[3] = {}, tp[3] = {};
	p = lower_bound(baum.begin(), baum.end(), s) - baum.begin();
	if (s == baum[p]) {
		sp[0] = baum[p + 1];
		sp[1] = baum[p - 1];
		sp[2] = baum[p];
	}
	else {
		sp[0] = baum[p];
		sp[1] = baum[p - 1];
		sp[2] = INF;
	}
	p = lower_bound(baum.begin(), baum.end(), t) - baum.begin();
	if (t == baum[p]) {
		tp[0] = baum[p + 1];
		tp[1] = baum[p - 1];
		tp[2] = baum[p];
	}
	else {
		tp[0] = baum[p];
		tp[1] = baum[p - 1];
		tp[2] = INF;
	}
	for (int i = 0; i <= 2; i++) {
		if (sp[i] == INF) break;
		minma = sp[i] - f;
		for (int j = 0; j <= 2;j ++){
			if (tp[j] == INF) break;
			minma = min( minma, min( tp[j] - sp[i], Baum - tp[j] + f ));
			ans = max(ans, minma);
			minma = sp[i]-f;
		}
	}
}

int main() {
	cin >> n;
	baum.push_back(0);
	for (int i = 0; i < n; i++) {
		int in;
		cin >> in;
		Baum += in;
		baum.push_back(in);
	}
	baum.push_back(baum[1]);
	Baum3 = Baum / 3;

	for (int i = 2; i <= n+1; i++) {
		baum[i] += baum[i - 1];
	}
	for (int i = 0; i < n + 1; i++) {
		if (baum[i] > Baum3) break;
		cut(baum[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2076
import math
from itertools import permutations


class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def distance_to(self, p):
        dx = p.x - self.x
        dy = p.y - self.y
        return math.sqrt(dx * dx + dy * dy)


def route_distance(ps):
    if len(ps) < 2:
        return 0
    else:
        return ps[0].distance_to(ps[1]) + route_distance(ps[1:])


def main():
    N = int(input())
    ps = []
    for _ in range(N):
        x, y = map(int, input().split())
        ps.append(Point(x, y))

    sum_routes = sum(route_distance(ps) for ps in permutations(ps, N))
    print(sum_routes / math.factorial(N))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
//#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

#define INF 10000;


bool check[100][100][2] = { false };
int cost[100][100][2];
int move[] = { 1, -1 };

class Node{
public:
	int x;
	int y;
	int lr;//0 -> left, 1 -> right
	int num;

	Node(){ x = 0; y = 0; lr = 0; num = 0; }
	Node(int x, int y, int lr, int num) : x(x), y(y), lr(lr), num(num){}

};

bool operator< (const Node &n1, const Node &n2){
	return n1.num < n2.num;
}

bool operator> (const Node &n1, const Node &n2){
	return n1.num > n2.num;
}

int main(void){

	int w, h;
	while (cin >> w >> h, w, h){
		char map[100][100];
		int result = -1;

		for (int i = 0; i < 100; i++){
			for (int j = 0; j < 100; j++){
				cost[j][i][1] = cost[j][i][0] = INF;
			}
		}

		for (int i = 0; i < 100; i++){
			for (int j = 0; j < 100; j++){
				check[j][i][1] = check[j][i][0] = false;
			}
		}

		for (int j = h - 1; j >= 0; j--){
			for (int i = 0; i < w; i++){
				cin >> map[j][i];
				if (map[j][i] == 'X') check[j][i][1] = check[j][i][0] = true;
			}
		}

		priority_queue<Node, vector<Node>, greater<vector<Node>::value_type> > que;

		for (int i = 0; i < w; i++){
			if (map[0][i] == 'S'){
				que.push(Node(i, 0, 0, 0));
				que.push(Node(i, 0, 1, 0));
			}
		}

		bool flag = false;
		while (!que.empty()){
			Node buff = que.top();
			que.pop();

			if (check[buff.y][buff.x][buff.lr]) continue;
			check[buff.y][buff.x][buff.lr] = true;
			cost[buff.y][buff.x][buff.lr] = min(cost[buff.y][buff.x][buff.lr], buff.num);

			for (int i = 1; i <= 3; i++){
				for (int j = 3 - i; abs(j) + i <= 3; j--){
					if (flag) break;
					int nextx = buff.x + move[buff.lr] * i;
					int nexty = buff.y + j;
					if (nextx < 0 || w <= nextx || nexty < 0 || h <= nexty || map[nexty][nextx] == 'S' || map[nexty][nextx] == 'X') continue;
					if (map[nexty][nextx] == 'T'){
						result = buff.num;
						flag = true;
						break;
					}
					que.push(Node(nextx, nexty, (buff.lr + 1) % 2, buff.num + (map[nexty][nextx] - '0')));
				}
			}


		}
		/*
		for (int j = h - 1; j >= 0; j--){
			for (int i = 0; i < w; i++){
				cout << map[j][i] << "\t";
			}
			cout << endl;
		}
		for (int j = h - 1; j >= 0; j--){
			for (int i = 0; i < w; i++){
				cout << min(cost[j][i][0], cost[j][i][1]) << "\t";
			}
			cout << endl;
		}
		*/
		if (!flag) cout << -1 << endl;
		else cout << result << endl;

	}

	return 0;
}

Measured memory_bytes: 1408
import collections
n = int(input())
a = list(map(int, input().split()))

c = collections.Counter(a)
k = list(c.keys())
v = list(c.values())

if n % 3 == 0:
  if len(v) == 3:
    if v[0] == v[1] == v[2] and k[0] ^ k[1] == k[2]:
      print("Yes")
    else:
      print("No")
  elif len(v) == 2:
    if (k[0] == 0 and v[0] * 2 == v[1]) or (k[1] == 0 and v[1] * 2 == v[0]):
      print("Yes")
    else:
      print("No")
  elif len(v) == 1:
    if k[0] == 0:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
elif len(v) == 1:
  if k[0] == 0:
    print("Yes")
  else:
    print("No")
else:
  print("No")


Measured memory_bytes: 14468
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int d,t,s;
  cin >> d >> t >> s;
  if(t*s >= d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;    
  }

  return 0;
}


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

const ll MOD = 1000000007;
int n;
char s[2][100];

int main()
{
    cin >> n;
    cin >> s[0] >> s[1];
    
    int p = (s[0][0] == s[1][0]);
    ll res = 3;
    rep(i, n)
    {
        if(s[0][i] == s[1][i])
        {
            if(p == 0)
            {
                res *= 2LL;
                res %= MOD;
            }
            p = 0;
        }
        else
        {
            if(p == 0)
            {
                res *= 2LL;
                res %= MOD;
            }
            else
            {
                res *= 3LL;
                res %= MOD;
            }
            p = 1;
            i++;
        }
        
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256