akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] s = sc.next().split("");
        String ans = "Yes";
        for (int i = 1; i <= s.length; i++) {
          if (i % 2 == 0 && s[i - 1].equals("R")) {
            ans = "No";
            break;
          } else if (i % 2 == 1 && s[i - 1].equals("L")) {
            ans = "No";
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i=0; i<N; i++) cin >> vec[i];
  sort(vec.begin(),vec.end());
  int count = 1;
  int keep = vec[N-1];
  for (int i=0;i<N-1;i++){
    if (vec[N-i-2]<keep){
      keep = vec[N-i-2];
      count += 1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import math
N = int(input())
n_max = int(math.sqrt(N))
a = []
for i in range(1,n_max + 1):
  if N % i == 0:
    a.append(i)
ans = 2 * N
for i in a:
  if (i + (N // i) - 2) < ans:
    ans = i + (N // i) - 2
print(ans)


Measured memory_bytes: 64932
#include<iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

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

	vector<string> strlist;
	string str;

	cin >> str;
	strlist.push_back(str);


	for (int i = 0; i < N - 1; i++)
	{
		cin >> str;
		
		for (int n = 0; n < strlist.size(); n++)
		{
			if (strlist[n] == str)
			{
				cout << "No" << endl;

				return 0;
			}
		}

		if (strlist[strlist.size() - 1][strlist[strlist.size() - 1].size() - 1] != str[0])
		{
			cout << "No" << endl;

			return 0;
		}

		strlist.push_back(str);
	}

	cout << "Yes"<< endl;

	return 0;


}



Measured memory_bytes: 3556
#include <stdio.h>
int main(void) {
    int n, p[100], i, j, c=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&p[i]);
    
    for(i=0;i<n;i++){
        if(p[i]!=i+1){
            for(j=i+1;j<n;j++){
                if(p[j]==i+1){
                    p[j]=p[i];
                    p[i]=i+1;
                    c++;
                }
            }
        }
        if(c==2){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 1644
/**
 *  author: mahfuzz
 *  created: 16.04.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << #x << ':' << x << "\n"
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
  	int n; cin >> n;
  	if(n < 1000)
      cout << "ABC\n";
  	else
      cout << "ABD\n";
  
    return 0;
}



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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> as2(n);
    for(int i = 0; i < n; ++i){
        ll a;
        cin >> a;
        as2.at(i) = 2 * a;
    }
    
    ll sum = 0;
    for(int i = 0; i < n; ++i){
        if(i % 2 == 0){
            sum += as2.at(i);
        }else{
            sum -= as2.at(i);
        }
    }

    vector<ll> bs;
    bs.push_back(sum / 2);
    for(int i = 1; i < n; ++i){
        bs.push_back(as2.at(i - 1) - bs.back());
    }

    for(int i = 0; i < bs.size(); ++i){
        cout << bs.at(i);
        if(i < bs.size() - 1){
            cout << ' ';
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3060
H,W = [int(i) for i in input().split()]
pic = ['0'] * H
pica = ['0'] * (2*H)
for i in range(H):
    pic[i] = list(input())
for i in range(2*H):
    if i !=0:
        pica[i] = pic[(i+1)//2 - 1]
    else:
        continue
for i in range(1,2*H):
    k = pica[i]
    pica[i-1] = k
for i in range(2*H):
    k = ''.join(pica[i])
    print(k)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 

const long long INF = (long long) 1e11+1;
const long long mod = (long long) 100000000 ;
const long long hell = (long long) 1000000007;


ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x*res);
    x=(x*x);    
    y=y/2;
  }
  return res;
}

ll modinv(ll x,ll m){
  return power(x,m-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;

   while(test--)
   solve();
}

void solve(){
   int a,b,c;
   cin>>a>>b>>c;
   swap(a,b);
   swap(a,c);
   cout<<a<<" "<<b<<" "<<c;
}


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/
// gcd of strings
/*
string getgcd(string s1,string s2){
    
    while(true){
        if(s1.length()<s2.length()){
            swap(s1,s2);
            continue;
        }
        if(s2.empty())
        return s1;
        
        if(s1.substr(0,s2.length())!=s2)
        return "";
        
        s1=s1.substr(s2.length());
    }
}
*/
/*
// for user defined DS hashmap and set
 
struct hash_pair{
      size_t operator()(const pair<int,pair<int,int>>& p) const{
          auto hash1=hash<int>()(p.F) ;
          auto hash2=hash<int>()(p.S.F) ;
          auto hash3=hash<int>()(p.S.S) ;
          return (hash1^hash2)^hash3;
      }  
};
struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
*/



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

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if(s < t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


void solve(){
	int n;
	cin >> n;
	long double a[n];
	long double ans = 1;
	int z = 0;
	forn(i,0,n){
		cin >> a[i];
		if(a[i]==0)
			z =1;

	}
	if(z){
		cout << 0 << endl;return;
	}

	forn(i,0,n)
	{
		ans*=a[i];
		if(ans>1e18){
			cout << -1 << endl;return;
		}
	}

	cout << fixed << setprecision(0) << ans << endl;

}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


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

int main() {
  ll N;
  cin >> N;
  vector<double> x(N), y(N);
  vector<int> v(N);
  REP(i,N) {
    cin >> x[i] >> y[i];
    v[i] = i;
  }
  ll k = 1;
  for ( int i=1; i<=N; i++ ) k *= i;

  double total = 0;
  vector< vector<double> > d(N, vector<double>(N) );
  REP(i,N) {
    REP(j,N) {
      d[i][j] = sqrt( (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
    }
  }
  do {
    REP(i,N-1) {
      total += d[v[i]][v[i+1]];
    }
  } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

  cout << fixed << setprecision(10) << (total/k) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

const int INF = 1e9 + 7;
vector<vector<ll>> dp(105, vector<ll>(100005, INF));
//dp[i][j] := 品物をi個まで見終わった後での価値jを作るための最小の重さ

int main(void) {
  ll n, W;
  cin >> n >> W;
  ll w[n + 1], v[n + 1];
  rep (i, n) cin >> w[i + 1] >> v[i + 1];

  for (int i = 0; i <= n; i++) dp[i][0] = 0;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 100005; j++) {
      dp[i][j] = min(dp[i][j], dp[i - 1][j]);
      if (j - v[i] >= 0) {
        dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
      }
    }
  }
  //cout << dp[n][10] << endl;
  int ans = 0;
  for (int i = 1; i <= 100003; i++) {
    if (dp[n][i] == INF) continue;
    if (dp[n][i] > W) continue;
    //cout << i << endl;
    ans = max(ans, i);
  }

  //rep (i, 11) cout << i <<" "<<dp[n][i] << endl;
  //cout << dp[n][100005] << endl;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 83456
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  BS.getLine
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute as
  print ans

compute :: [Int] -> Int
compute as = toBuy 1000 as

toBuy m (a1:a2:as)
  | a1 >= a2 = toBuy m (a2:as)
  | True = let (p,q) = divMod m a1 in toSell q p (a2:as)
toBuy m _ = m

toSell m k (a1:a2:as)
  | a1 <= a2 = toSell m k (a2:as)
  | True = toBuy (m + a1 * k) (a2:as)
toSell m k [a] = m + a * k

-- 少しでも上がるなら全力買い、下がるなら全力売りを繰り返す。下りのところは無視する。


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

using namespace std;

int main()
{
    long long l,r,x,y,Min=INT_MAX,ans;
    cin>>l>>r;

    x=l;
    y=r;
    for(int i=0;i<=2019 && l<r;i++){
        if(l%2019==0 || r%2019==0) {
            cout << 0 <<endl;
            return 0;
        }
        l++,r--;
    }
    for(long long i=x;i<y;i++){
        for(long long j=x+1;j<=y;j++){
            ans=((i%2019)*(j%2019))%2019;
            if(ans<Min) Min=ans;
        }
    }
    cout << Min <<endl;

    return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [Int] -> [Int]
solve n as = eachMax where
    lrsumacc :: UV.Vector Int
    lrsumacc = GV.fromList $ scanl' max 0 as
    rlsumacc :: UV.Vector Int
    rlsumacc = GV.fromList $ reverse $ scanl' max 0 $ reverse as
    eachMax = (\i -> max (lrsumacc GV.! (i - 1)) (rlsumacc GV.! i)) <$> [1..n]

main = do
    n <- readInt
    as <- replicateM n readInt
    forM_ (solve n as) print


Measured memory_bytes: 60540
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static StringBuilder builder = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] a = reader.readLine().split(" ");

		String[] b = Arrays.copyOf(a, a.length);
		bubble(a, n);
		append(a, n);
		builder.append("Stable\n");
		selection(b, n);
		append(b, n);
		builder.append(Arrays.equals(a, b)?"Stable\n":"Not stable\n");
		System.out.print(builder);
	}

	public static void selection(String[] a, int n) {

		for (int i = 0; i < n; i++) {
			int minj = i;
			for (int j = i + 1; j < n; j++) {
				if (toInt(a, j) < toInt(a, minj)) {
					minj = j;
				}

			}
			if (i != minj) {
				String tmp = a[i];
				a[i] = a[minj];
				a[minj] = tmp;
			}
		}
	}

	public static void bubble(String[] a, int n) {
		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (toInt(a, j) < toInt(a, j - 1)) {
					String temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		}
	}

	public static int toInt(String[] a, int j) {
		return a[j].charAt(1);
	}

	public static void append(String[] a, int n) {
		for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		}
		builder.append("\n");
	}
}

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

constexpr size_t get_cost(size_t height_a, size_t height_b) {
  return height_a < height_b ? height_b - height_a : height_a - height_b;
}

std::vector<size_t> fill_jump_costs(const std::vector<size_t> &heights,
                                    const size_t jump_limit) {
  std::vector<size_t> costs;
  costs.reserve(jump_limit);

  for (size_t i = 0u; i < jump_limit && i < heights.size(); ++i) {
    costs.push_back(get_cost(heights[i], heights[0]));
  }

  return costs;
}

void push_back_shift_left(std::vector<size_t> &costs, const size_t cost) {
  for (size_t i = 1u; i < costs.size(); ++i) {
    costs[i - 1] = costs[i];
  }
  costs.back() = cost;
}

size_t cheapest_route_cost(const std::vector<size_t> &heights,
                           const size_t jump_limit) {
  if (heights.size() <= 1u) {
    return 0u;
  }

  if (jump_limit < 1u) {
    throw std::runtime_error("can't jump at all");
  }

  auto costs = fill_jump_costs(heights, jump_limit);

  for (size_t i = jump_limit; i < heights.size(); ++i) {
    const size_t height = heights[i];

    size_t cost = costs[0] + get_cost(height, heights[i - jump_limit]);
    for (size_t j = 1u; j < jump_limit; ++j) {
      cost = std::min(cost,
                      costs[j] + get_cost(height, heights[i + j - jump_limit]));
    }

    push_back_shift_left(costs, cost);
  }

  return costs.back();
}

int main() {
  size_t count{0};
  std::cin >> count;

  size_t jump_limit{0};
  std::cin >> jump_limit;

  std::vector<size_t> heights;
  heights.reserve(count);

  for (size_t i = 0; i < count; ++i) {
    size_t cost{0};
    std::cin >> cost;
    heights.push_back(cost);
  }

  std::cout << cheapest_route_cost(heights, jump_limit) << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>

#include<stdio.h>

using namespace std;

void call(int n){
  int i = 1;
  for(i=1;i<=n;i++)
    {
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    continue;
  }
do{
  if ( x % 10 == 3 ){
    cout << " " << i;
    break;
  }
  x /= 10;
}while(x);
    }

  cout << endl;
}

int main()
{
    int a;
    scanf("%d",&a);
    call(a);
}



Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

string toString(int n)
{
	stringstream ss;
	ss << n;

	return ss.str();
}

int main()
{
	int n, m;
	string str, st;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		cin >> str;
		
		while(n--){
			st = "";
			for(int i = 0; i < str.length(); i++){
				char ch = str[i];
				m = 1;
				if(str[i+1] == ch){
					i++;
					for(; i < str.length() && str[i] == ch; i++){
						m++;
					}
					i--;
				}
				st += toString(m);
				st += ch;
			}
			
			str = st;
		}
		
		cout << str << endl;
	}
	
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    long long a, b;
    cin >> n >> a >> b;
    long long x[n];
    cin >> x[0];
    long long ans = 0;
    for(int i = 1; i < n; i++){
        cin >> x[i];
        ans += min(a*(x[i]-x[i-1]), b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import fractions
A, B, C, D = map(int,input().split())

def lcm(x, y): #最小公倍数
    return (x * y) // fractions.gcd(x, y)

n_C = B//C - (A-1)//C # Cで割り切れる数の数
n_D = B//D - (A-1)//D
CandD = lcm(C,D)
n_CandD = B//CandD - (A-1)//CandD

# CでもDでも割けれない数 = 全体 - CでもDでも割り切れる数
ans = B-A+1 - (n_C + n_D - n_CandD)
print(ans)



Measured memory_bytes: 5048
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
P d[100005];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    cin >> d[i].first >> d[i].second;
  }
  sort(d, d+M);
  int ret = 1;
  int m = N+1;
  for (int i=0; i<M; i++) {
    if (m <= d[i].first) {
      ret++;
      m = N+1;
    }
    m = min(m, d[i].second);
  }
  cout << ret << endl;
}

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

using namespace std;
#define sqr(x) (x)*(x)
#define cube(x) (x)*(x)*(x)
#define fixset(x) fixed << setprecision(x)
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) (a)*(b)/GCD(a,b)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PCI pair<char,int>
#define PIC pair<int,char>
#define PBI pair<bool,int>
#define PIB pair<int,bool>
#define PLL pair<ll,ll>
#define SI set<int>
#define MS multiset
#define MSI multiset<int>
#define PB push_back
#define VI vector<int>
#define VLL vector<ll>
#define VB vector<bool>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1000000000;
const int MOD = 1000000007;
const int N = 200111;

int a[N];
void solve(){
    int n;
    cin >> n;

    cout << n*n*n;


}

int main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int T = 1;
    //cin >> T;

    while (T--){
        solve();
    }

    return 0;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int n,m;
    cin>>n>>m;
    Vi aa(m);
    REP(i,n){
        int k;
        cin>>k;
        REP(j,k){
            int a;
            cin>>a;
            aa[a-1]++;
        }
    }

    int total = 0;
    REP(i,m){
        if(aa[i] == n) total++;
    }

    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
f2::Char -> String
f2 x=take 1 $ tail $ show x

f::Int->String->String
f 0 (x:xs)=f2 x
f n ('1':xs)=f (n-1) xs
f n (x:xs)=f2 x 

main = do
       a<-getLine
       b<-getLine
       let k=read b::Int-- your code goes here
       putStrLn $ (f (k-1) a)

Measured memory_bytes: 508
N = int(input())
t = list(map(int,input().split()))
T = [0]
tot = 0
for i in range(len(t)):
    tot += t[i]
    T.append(tot)
T = list(map(lambda x: x*2,T))
v = list(map(int,input().split()))
v.append(0)
curv = 0
dist = 0
curt = 0
#print(T)
#print(v)

for i in range(N):
    for _ in range(T[i], T[i+1]):
        prev = curv
        ok = 1
        #if (0 < T[j+1]-curt <= curv - v[j+1] for j in range(N)):
            #print(T[1],curt,curv,v[1])
        for j in range(N-i):
            if T[i+j+1]/2.0 - curt > curv - v[i+j+1]:
                continue
            else:
                ok = 0
                break
        if ok == 1:
            if curv < v[i]:
                curv += 0.5
        elif ok == 0:
            curv -= 0.5
        curt += 0.5
        dist +=(prev+curv) / 4.0




print(dist)

Measured memory_bytes: 3188
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    ll res = a[0];
    if(n % 2 == 0){
        for(int i = 1; i < n / 2; i++){
            res += (a[i] * 2LL);
        }
        cout << res << "\n";
    }
    else{
        for(int i = 1; i < n / 2; i++){
            res += (a[i] * 2LL);
        }
        res += (a[n / 2]);
        cout << res << "\n";
    }
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

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

int main() {
	string s1, s2; cin >> s1 >> s2;
	if (s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0])cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as Maybe
import qualified Debug.Trace as Trace

solve :: Int -> String -> String
solve x s
    | ((mod x 2) /= 0) = "No"
    | (take (div x 2) s) == (drop (div x 2) s) = "Yes"
    | otherwise = "No"

main = do
    n <- (fst . Maybe.fromJust . BS.readInt) <$> BS.getLine
    s <- getLine
    let ans = solve n s
    putStrLn ans


Measured memory_bytes: 3800
#include <iostream>
#define ll long long
using namespace std;

ll gcd(ll a, ll b){
    return b == 0 ? a : gcd(b, a % b);
}

int main(void){
    int n;
    ll sol, y;
    cin >> n;
    cin >> sol;
    for(int i = 1; i < n; i++){
        cin >> y;
        sol = sol / gcd(sol, y) * y;
    }
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<pair<int,int> > g[500001];
vector<int> col;
vector<ll> dist;

void dfs(int u){
	for(auto x:g[u]){
		int v = x.X;
		int w = x.Y;
		if(col[v]==-1){
			dist[v] = dist[u] + w;
			col[v] = (dist[v])%2;	
			dfs(v);
		}
	}
}

int main(){
	int n;
	cin>>n;
	col.resize(n+1,-1);
	dist.resize(n+1,0);
	for(int i=0;i<n-1;i++){
		int u,v,w;
		cin>>u>>v>>w;
		g[u].pb({v,w});
		g[v].pb({u,w});
	}
	col[1] = 0;
	dfs(1);
	for(int i=1;i<=n;i++){
		cout<<col[i]<<endl;
	}
}

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

int main() {
    ll n, x;
    cin >> n;
    vector<ll> cnt(100001,0);
    ll res = 0;
    for (ll i=0; i<n; i++) {
        cin >> x;
        res+=x;
        cnt[x]++;
    }
    ll q, b, c;
    cin >> q;
    for (ll i=0; i<q; i++) {
        cin >> b >> c;
        res-=(b*cnt[b]);
        res+=(c*cnt[b]);
        cnt[c]+=cnt[b];
        cnt[b] = 0;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong N,A[200100],mod=1000000007,sum[200100],ans=0;
    cin >> N;
    rep(i,N) cin >> A[i];
    //累積和
    sum[N-1] = A[N-1];
    sum[N-1] %= mod;
    for(int i=N-2;i >= 0;i--){
        sum[i] = sum[i+1] + A[i];
        sum[i] %= mod;
    }
    
    for(int i=0;i<N-1;i++){
        ans += A[i]*sum[i+1];
        ans %= mod;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 6692
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    (n % 1000 == 0) ? cout << 0 << "\n" : cout << 1000 - (n % 1000) << "\n";

    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

bool find(const vvi& a,const vvi& fig)
{
	rep(i,9-fig.size()){
		rep(j,9-fig[0].size()){
			bool ok=true;
			rep(k,fig.size()){
				rep(l,fig[0].size()){
					if(a[i+k][j+l]!=fig[k][l])
						ok=false;
				}
			}
			if(ok)
				return true;
		}
	}
	return false;
}

int main()
{
	vector<vvi> fig(7);
	fig[0]=vvi(2,vi(2));
	fig[0][0][0]=fig[0][0][1]=fig[0][1][0]=fig[0][1][1]=1;
	fig[1]=vvi(4,vi(1));
	fig[1][0][0]=fig[1][1][0]=fig[1][2][0]=fig[1][3][0]=1;
	fig[2]=vvi(1,vi(4));
	fig[2][0][0]=fig[2][0][1]=fig[2][0][2]=fig[2][0][3]=1;
	fig[3]=vvi(3,vi(2));
	fig[3][0][1]=fig[3][1][0]=fig[3][1][1]=fig[3][2][0]=1;
	fig[4]=vvi(2,vi(3));
	fig[4][0][0]=fig[4][0][1]=fig[4][1][1]=fig[4][1][2]=1;
	fig[5]=vvi(3,vi(2));
	fig[5][0][0]=fig[5][1][0]=fig[5][1][1]=fig[5][2][1]=1;
	fig[6]=vvi(2,vi(3));
	fig[6][0][1]=fig[6][0][2]=fig[6][1][0]=fig[6][1][1]=1;
	for(string s;cin>>s;){
		vvi a(8,vi(8));
		rep(i,8)
			a[0][i]=s[i]-'0';
		repi(i,1,8){
			cin>>s;
			rep(j,8)
				a[i][j]=s[j]-'0';
		}
		rep(i,fig.size()){
			if(find(a,fig[i])){
				cout<<char(i+'A')<<endl;
				break;
			}
		}
	}
	
	return 0;
}

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

const int N = 1e3 + 5;
const ll mod = 1e9 + 7;

int r, c;
char s[N][N];
ll dp[N][N];

int wb(int i, int j) {
  return (i >= 1 && i <= r && j >= 1 && j <= c);
}

int main () {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  scanf("%d %d", &r, &c);
  for (int i = 1; i <= r; i++)
    scanf("%s", s[i] + 1);
  dp[1][1] = 1;
  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      if (s[i][j] == '.') {
        if (wb(i-1, j) && s[i-1][j] == '.') {
          dp[i][j] += dp[i-1][j];
          if (dp[i][j] >= mod)
            dp[i][j] -= mod;
        }
        if (wb(i, j-1) && s[i][j-1] == '.') {
          dp[i][j] += dp[i][j-1];
        }
        if (dp[i][j] >= mod)
          dp[i][j] -= mod;
      }
    }
  }
  printf("%lld\n", dp[r][c]);
  return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

struct UnionFind {
    vector<long> par;

    UnionFind(long N) : par(N) {
        for(long i = 0; i < N; i++) par[i] = i;
    }

    long root(long x) {
        if (par[x] == x) return x;
        par[x] = root(par[x]);
        return par[x];
    }

    void unite(long x, long y) {
        long rx = root(x);
        long ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(long x, long y) {
        long rx = root(x);
        long ry = root(y);
        return rx == ry;
    }

    long getMaxSize() {
        map<long, long> m;
        for (long i = 0; i < par.size(); i++) {
            long p = root(i);
            if (m.count(p) == 0) {
                m[p] = 1;
            } else {
                m[p] += 1;
            }
        }
        long cnt = 0;
        for (const auto& item : m) {
            if (item.second > cnt) {
                cnt = item.second;
            }
        }
        return cnt;
    }
    void dump() {
        for (long i = 0; i < par.size(); i++)
            cout << par[i] << endl;
    }
};

int main()
{
    long n, m;
    cin >> n >> m;
    UnionFind uf(n);

    for (long i = 0; i < m; i++) {
        long a, b;
        cin >> a >> b;
        uf.unite(a-1, b-1);
    }

    cout << uf.getMaxSize() << endl;
    return 0;
}

Measured memory_bytes: 17140
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.10 12:50:20
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const ll M = 1000000007;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

ll dp[110][8];
int com[8] = {1, 1, 2, 3, 5, 8, 13, 21}; // i個のあみだ1段で何通り作れるか

int main() {
    ll h, w, k;
    scanf("%lld%lld%lld", &h, &w, &k);

    dp[0][0] = 1LL;
    rep1(i, h) rep(j, w) {
        ll a0 = 0, a1 = 0, a2 = 0;
        if (j != 0) {
            if (w > 3) {
                ll t = j - 1 >= 0 ? com[j - 1] : 1;
                t *= w - j - 1 >= 0 ? com[w - j - 1] : 1;
                a0 = dp[i - 1][j - 1] * t;
            } else {
                a0 = dp[i - 1][j - 1];
            }
        }
        if (j != w - 1) {
            if (w > 3) {
                ll t = j >= 0 ? com[j] : 1;
                t *= w - j - 2 >= 0 ? com[w - j - 2] : 1;
                a1 = dp[i - 1][j + 1] * t;
            } else {
                a1 = dp[i - 1][j + 1];
            }
        }
        if (1) {
            if (w > 2) {
                ll t = j >= 0 ? com[j] : 1;
                t *= w - j - 1 >= 0 ? com[w - j - 1] : 1;
                a2 = dp[i - 1][j] * t;
            } else {
                a2 = dp[i - 1][j];
            }
        }
        // printf("i:%lld j:%lld %lld %lld %lld\n", i, j, a0, a1, a2);
        dp[i][j] = (a0 + a1 + a2) % M;
    }

    // rep(i, h + 1) {
    //     rep(j, w) {
    //         printf("i:%lld j:%lld dp:%lld\n", i, j, dp[i][j]);
    //     }
    //     printf("\n");
    // }

    printf("%lld\n", dp[h][k - 1]);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define inout freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
#define swap(a,b) (a)+=(b);(b)=(a)-(b);(a)-=(b)
#define quicksort(a,n) qsort(a,n,sizeof(a[0]),cmp)
#define inputarr(a,n) for(int i=0;i<n;i++){scanf("%d",&a[i]);}
#define printarr(a,n) for(int i=0;i<n;i++){printf("%d ",a[i]);}puts("");
int cmp(const void *a,const void *b){return *(int *)a - *(int *)b;}

int n, m, k, ans = -1, a[200001], b[200001];

int main() {

	//inout;

	int n;

	scanf("%d", &n);

	if(n % 1000 == 0){
		puts("0");
	}

	else{
		printf("%d", 1000 - (n % 1000));
	}

}

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

int main() {
  int l,r,d;
  int ans = 0;
  cin >> l >> r >> d;
  
  for(int i = l;i<=r;i++){
    if(i % d == 0){
      ans = ans + 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    string s;
    cin>>s;
    ll ans = 0;
    for(int i=0;s[i];++i){
        ans = ans + s[i]-'0';
    }
    if(ans%9==0)cout<<"Yes";
    else cout<<"No";











    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int a, b;
  cin >> a >> b;
  if (a == b) {
    cout << a + b << endl;
  } else if (a > b) {
    cout << a + a - 1 << endl;
  } else {
    cout << b + b - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define SZ(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool inline rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool inline rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n; cin>>n;
int l=1,r=1,ans=0,N=20, p[N][n+1];
memset(p,0,sizeof(p));
for(int i=1;i<=n;++i){
	int t; cin>>t;
	for(int b=0;b<N;++b,t>>=1){
		p[b][i]+=p[b][i-1] + (t&1);
	}
}
for(;l<=n;++l){
	while(r<=n){
		bool ok=true;
		for(int i=0;i<N;++i){
			if(p[i][r]-p[i][l-1]>1) ok=false; 
		}
		if(ok) ++r;
		else break;
	}
	ans+=r-l;
}
cout<<ans<<el; 

return 0;
}


Measured memory_bytes: 31488
H,W = map(int,input().split())
ans = []
for i in range(H):
    a = input()
    if a != "."*W:
        ans.append(a)
H = len(ans)
ans2 = list(map(list,zip(*ans)))
while ["."]*H in ans2:
    ans2.remove(["."]*H)
trueans = list(map(list,zip(*ans2)))
for i in trueans:
    print("".join(i))

Measured memory_bytes: 9248
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lb lower_bound
#define debug(x) cout<<"["<<#x<<": "<<x<<"]"<<endl
#define f(p,n) for(ll i=p;i<n;i++)
ll exp(ll a,ll b,ll m);
ll dp[1001][100000+1];
int main()
{
 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 	/*	
 	#ifndef ONLINE_JUDGE
        freopen("/home/savish/Desktop/2019/io/input.txt", "r", stdin);
        freopen("/home/savish/Desktop/2019/io/output.txt", "w", stdout);
    #endif
        */
    ll n,w;
    cin>>n>>w;
    
    ll va[n+1],wt[n+1];
    f(1,n+1) cin>>wt[i]>>va[i];

    ll me = 1e15;
    f(0,n+1)
    {
    	for(ll j=0;j<=n*1000;j++)
    	{
    		if(i==0 && j>0) dp[i][j] = me;
    		else if(j==0) dp[i][j] = 0;
    		else if(va[i]<=j) dp[i][j] = min(dp[i-1][j],wt[i]+dp[i-1][j-va[i]]);
    		else dp[i][j] = dp[i-1][j];
    	}
    }
    ll ans = 0;

    f(1,n*1000+1) if(dp[n][i]<=w) ans = i;
    cout<<ans<<endl;
    
return 0;
}

ll exp(ll a,ll b,ll m)
{
	if(b==0)
	{
		return 1;
	}
	ll temp =exp(a,b/2,m);
	temp=(temp*temp)%m;
	if(b&1)
	{
		return (temp*(a%m))%m;
	}
	return temp;
}

Measured memory_bytes: 80128
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//77377
public class Main{

	int[] ref = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
	int n;
	String[] w, rep;
	String s;
	Set<String> ans;
	
	void dfs(int i, String r){
		if(i==s.length()){
			ans.add(r+"."); return;
		}
		String sub = s.substring(i);
		for(int j=0;j<n;j++){
			if(!sub.startsWith(rep[j]))continue;
			dfs(i+rep[j].length(), r+" "+w[j]);
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt();
			if(n==0)break;
			w = new String[n]; rep = new String[n];
			for(int i=0;i<n;i++){
				w[i] = sc.next();
				String res = "";
				for(int j=0;j<w[i].length();j++)res+=ref[w[i].charAt(j)-'a'];
				rep[i] = res;
			}
			s = sc.next();
			ans = new HashSet<String>();
			dfs(0, "");
			for(String r:ans)System.out.println(r.substring(1));
			System.out.println("--");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define repeat(i,n) repeat_from(i,0,n)
using namespace std;
struct mobile_t {
    int w; // weight
    double l; // left
    double r; // right
};
const double eps = 0.0001;
double evaluate(vector<int> const & p) {
    stack<mobile_t> stk;
    for (int w : p) {
        if (w == 0) {
            if (stk.size() < 2) return -1;
            mobile_t x = stk.top(); stk.pop();
            mobile_t y = stk.top(); stk.pop();
            mobile_t z;
            z.w = x.w + y.w;
            double dx = y.w /(double) (x.w + y.w);
            double dy = x.w /(double) (x.w + y.w);
            z.l = max(x.l + dx, y.l - dy);
            z.r = max(x.r - dx, y.r + dy);
            stk.push(z);
        } else {
            stk.push((mobile_t){ w, 0.0, 0.0 });
        }
    }
    if (stk.size() != 1) return -1;
    return stk.top().l + stk.top().r;
}
int main() {
    int datasets; cin >> datasets;
    repeat (dataset, datasets) {
        double r; cin >> r;
        int s; cin >> s;
        vector<int> w(s); repeat (i,s) cin >> w[i];
        double result = -1;
        vector<int> p;
        repeat (i,s)   p.push_back(w[i]);
        repeat (i,s-1) p.push_back(0);
        sort(p.begin(), p.end());
        do {
            double it = evaluate(p);
            if (r + eps < it) continue;
            result = max(result, it);
        } while (next_permutation(p.begin(), p.end()));
        if (result == -1) {
            printf("-1\n");
        } else {
            printf("%.16lf\n", result);
        }
    }
    return 0;
}

Measured memory_bytes: 1268
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    ll sum = 0;
    for (auto& a : A) {
        sum += a / N;
    }
    ll ans = 0;
    while (sum > 0) {
        ans += sum;
        for (auto& a : A) {
            a -= (a / N) * N - sum + a / N;
        }
        sum = 0;
        for (auto& a : A) {
            sum += a / N;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C;
  cin >> A >> B >> C;
  bool x=(A==B),y=(B==C),z=(A==C);
  if (x+y+z==1) {cout << "Yes" << endl;} else {cout << "No" << endl;}
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;


#define INF 1e+9


int main(){


	  int N,W; cin >> N >> W;
	  int v[N+1],w[N+1];
	  for(int i=1; i<=N; i++) cin >> v[i] >> w[i];

	  vvi dp(N+1,vi(W+1,-INF));
	  dp[0][0] = 0;
	  for(int i=1; i<=N; i++){
			for(int j=0; j<=W; j++){
				  dp[i][j] = max(dp[i][j], dp[i-1][j]);
				  if(j-w[i] < 0) continue;
				  dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
			}
	  }
	  int ans=0;
	  for(int i=0; i<=W; i++) ans = max(ans,dp[N][i]);
	  cout << ans << endl;
	  

}

Measured memory_bytes: 4964
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N,K = LMIIS()
    P = LMIIS()
    P.sort()
    print(sum(P[:K]))
    
main()

Measured memory_bytes: 67176
a,b,c,x,y=map(int,input().split())
s=0
c*=2
if(x>y):
    s=min((a*x+b*y),((x-y)*a+y*c),c*max(x,y))
else:
    s=min((a*x+b*y),((y-x)*b+x*c),c*max(x,y))
print(s)

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


int main(){
    deque<char> p;
    string s;
    cin >> s;
    int q;
    cin >> q;
    for(unsigned int i = 0; i < s.size(); i++){
        p.push_back(s[i]);
    }
    bool f = false;
    for(int j = 0; j < q; j++){
        int tmp;
        cin >> tmp;
        if(tmp == 1){
            f = !f;
        }
        else{
            int a;
            cin >> a;
            char c;
            cin >> c;
            if(a == 1){
                if(f) p.push_back(c);
                else p.push_front(c);
            }
            else{
                if(f) p.push_front(c);
                else p.push_back(c);
            }
        }
    }
    if(f) reverse(p.begin(), p.end());
    for(auto k = p.begin(); k != p.end(); k++){
        cout << *k;
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 896
#import sys
#input = sys.stdin.readline

import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

t=1
for _ in range(t):
    l,r,d=ml()
    ans=0
    for i in range(l,r+1):
        if(i%d==0):
            ans+=1
    print(ans)        

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    static int in[4001][4001], out[4001][4001];
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
        in[2000-A[i]][2000-B[i]]++;
        out[2000+A[i]][2000+B[i]]++;
    }

    static int64_t dp[4001][4001];
    int64_t ans = 0;
    for(int i=0; i<=4000; i++) for(int j=0; j<=4000; j++){
        dp[i][j] = in[i][j];
        if(i) add(dp[i][j], dp[i-1][j]);
        if(j) add(dp[i][j], dp[i][j-1]);
        add(ans, dp[i][j] * out[i][j]);
    }
    
    create_mod_tables(8000);
    for(int i=0; i<N; i++) add(ans, MOD - comb_mod(2*A[i]+2*B[i], 2*A[i]));
    mul(ans, inv_mod(2));
    cout << ans << endl;
}


Measured memory_bytes: 192512