akhauriyash/Code-Regression huggingface dataset:
// IN the name of GOD

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 1e9 + 7, N = 1e5 + 10;

void solve () {
    int n;
    cin >> n;
    vector <int> v(n), w(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i] >> w[i];
    }
    int limit = min (512, n);
    vector<vector<int>> dp(limit, vector<int>(N));
    for (int j = 0; j < N; ++j) {
        dp[0][j] = (j >= w[0] ? v[0] : 0);
    }
    for (int i = 1; i < limit; ++i) {
        int p = (i - 1)/2;
        for (int j = 0; j < N; j++) {
            dp[i][j] = dp[p][j];
            if (j >= w[i]) {
                dp[i][j] = max(dp[i][j], dp[p][j - w[i]] + v[i]);

            }
        }
    }

    int tt;
    cin >> tt;
    while (tt--) {
        int ver, L;
        cin >> ver >> L;
        --ver;
        vector <int> ids;
        while (ver >= limit) {
            ids.push_back(ver);
            ver = (ver - 1)/2;
        }
        int sz = (int)ids.size();
        int ans = 0;
        for (int t = 0; t < (1 << sz); t++) {
            int sv = 0;
            int sw = 0;
            for (int i = 0; i < sz; ++i) {
                if (t & (1 << i)) {
                    sv += v[ids[i]];
                    sw += w[ids[i]];
                }
            }
            if (sw <= L) {
                ans = max(ans, dp[ver][L - sw] + sv);
            }
        }
        cout << ans << "\n";
    }
}
int main () {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
        // scanf("%d", &tt);
    while (tt--)
        solve();
 
}


// 5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu 
// bandit12


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

using namespace std;

#define mem(a,b) memset(a, b, sizeof(a))
#define FOR(i,j,k) for(int i = j; i <= k; i++)
typedef long long LL;
const int MAX = 200005;
const int M = (1e9) + 7;

LL ara[MAX], uni[MAX], n, p, col[MAX];
LL dp[MAX];

int main()
{
    ios::sync_with_stdio(false);
    ///freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);

    cin >> n;
    FOR(i,0,n-1) cin >> uni[i];

    p = 1;
    FOR(i,0,n-1) if(!i || ara[p - 1] != uni[i]) ara[p++] = uni[i];
    n = p;

    dp[0] = 1;
    FOR(i,1,n)
    {
        dp[i] = dp[i - 1] + col[ ara[i] ];
        col[ ara[i] ] += dp[i - 1];

        dp[i] %= M; col[ ara[i] ] %= M;
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 6528
#include <iostream>

using namespace std;

int main(){
	int N;
	while(cin >> N){
		long long ca = 0, cb = 0;
		cin >> ca >> cb;
		for(int i=1;i<N;i++){
			long long a, b;
			cin >> a >> b;
			long long sa = (ca+a-1)/a;
			long long sb = (cb+b-1)/b;
			long long s = max(sa, sb);
			ca = a * s;
			cb = b * s;
		}
		cout << ca+cb << endl;
	}
}



Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll INF=2e18;

ll N,M,K,C;
ll a,b,c,d;
string s;
int main(){
    cin>>N>>s;
    int ans=0;
    for(int i=0;i<s.length();i++){
        map<char,int> mp;
        for(auto c:s.substr(0,i)){
            mp[c]++;
        }
        for(auto c:s.substr(i,s.length())){
            if(mp[c]>=1){
                mp[c]=-1;
            }
        }
        int cnt=0;
        for(auto o:mp){
            if(o.second==-1)cnt++;
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
(** val add : int -> int -> int **)

let rec add = ( + )

(** val sub : int -> int -> int **)

let rec sub = ( - )

module Nat =
 struct
  (** val div2 : int -> int **)

  let rec div2 = (fun x -> x / 2)
 end

(** val lower_bound_aux : (int -> bool) -> int -> int -> int **)

let rec lower_bound_aux p_dec x x0 =
  (fun fO fS n -> if n = 0 then fO () else fS (n-1))
    (fun _ ->
    x)
    (fun n0 ->
    if p_dec (add x (Nat.div2 (succ n0)))
    then lower_bound_aux p_dec x (Nat.div2 (succ n0))
    else lower_bound_aux p_dec (add (succ (Nat.div2 (succ n0))) x)
           (sub (succ n0) (succ (Nat.div2 (succ n0)))))
    x0

(** val lower_bound : (int -> bool) -> int -> int -> int **)

let lower_bound p_dec alpha beta =
  lower_bound_aux p_dec alpha (sub beta alpha)

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.sort compare as_;
  Printf.printf "%d\n" (n - 
  lower_bound (fun i ->
    Array.fold_left (fun (j, (acc, b)) a ->
      (j + 1,
        if i = j then (acc, b)
        else (acc + a, b && a <= 2 * acc))
      ) (0, (as_.(i), true)) as_
    |> snd
    |> snd) 0 n)

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

#define PI 3.141592653589793238462643383279
int main(){
	double a,b,h,m;
	cin >> a >> b >> h >> m;
	double angleh, anglem;
	anglem = m*6.0;
	angleh = h*30.0 + m/2.0;
	double diff = abs(anglem-angleh);
	if(diff == 0) {printf("%.15g",abs(a-b)); return 0;}
	if (diff == 180.0) {printf("%.15g",a+b); return 0;}
	if(diff > 180.0) diff = 360.0-diff;
	double result = sqrt(a*a+b*b-2*a*b*cos(diff*PI/180.0));
	printf("%.15g",result);
	
}


Measured memory_bytes: 4160
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func solve(n int, s []byte) int {
	mMax := n / 2
	mMin := 0
	for true {
		//if mMax == 0 {
		//	return 0
		//}
		if mMax == mMin {
			return mMax
		}
		m := (mMax + mMin + 1) / 2
		i := 0
		for ; ; i++ {
			s1 := s[i : i+m]
			s2 := s[i+m:]
			if len(s2) < m {
				mMax = m - 1
				break
			}
			if bytes.Contains(s2, s1) {
				mMin = m
				break
			}
		}
	}
	return 0
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := nextInt()
	s := nextStringAsBytes(n)
	res := solve(int(n), s)
	fmt.Fprintln(out, res)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


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

int main()
{
	int N; 
    cin>>N;
	set<string> s{"a"};
	while(--N)
    {
		set<string>t; swap(s,t);
		for(auto pre:t)
        {
			set<char> types{'a'}; 
            for(auto c:pre) 
            	types.insert(c+1);
			for(auto c:types) 
            	s.insert(pre + c);
		}
	}
	for(auto x:s) cout<< x <<endl;
}

Measured memory_bytes: 16512
#include<stdio.h>
#include<string.h>
int main(){
	int r=0,a[4],b[2],i,s=100,nf;
	scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1]);
	for(i=0;i<4;i++){
		if(s>=a[i]){
			s=a[i];
			nf=i;
		}
	}
	for(i=0;i<4;i++){
		if(i!=nf){
			r+=a[i];
		}
	}
	if(b[0]>b[1]){
		r+=b[0];
	}else{
		r+=b[1];
	}

	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 2696
while True:
    try:
        
        a = map(int,raw_input().split(' '))
        s = a[0] + a[1]
        c = 0
        while s > 0:
            s = s / 10
            c = c + 1
            if s <= 0:
                print c
                break
                
    except (EOFError):
        break

Measured memory_bytes: 4204
object Main extends App {
  val n = readLine.toInt
  
  var list = scala.collection.mutable.Seq[Long](2,1)
  
  for (i <- 1 to n - 1) {
    val a = list.reverse.head + list.dropRight(1).reverse.head
    list = list :+ a
  }
  
  println(list.reverse.head)
}

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

int main() {
  int n, x, m[101];
  cin >> n >> x;
  
  int s = 0;
  int M = 712489;
  
  for(int i = 0; i < n; i++) {
    cin >> m[i];
    s += m[i];
    if(m[i] < M) M = m[i];
  }
  
  cout << n + (x - s) / M << endl;
}  

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _136B
{
    class Program
    {
        static void Main(string[] args)
        {
            string strN = Console.ReadLine();
            int n = int.Parse(strN);

            double ans = 0;
            int keta = strN.Length;
            int a = 1;

            for (; a <= keta; a+=2)
            {
                if (Math.Pow(10, a) <= n)
                {
                    ans += (Math.Pow(10, a) - 1) - (Math.Pow(10, a - 1)) + 1;
                }
            }

            if (keta % 2 == 1)
            {
                ans += n - (Math.Pow(10, a - 3)) + 1;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector> 
#include <algorithm>
#include <map>
using namespace std;
 
// ref: http://drken1215.hatenablog.com/entry/2018/09/23/232100
int main() {
  string S, T;
  cin >> S >> T;
  bool ok = true;
  map<char,char> s_map, t_map;
  for (int i = 0; i < S.size(); i++) {
    char s = S[i], t = T[i];
    // map.count()は見つかった要素の数を返す。この場合、一つでも見つかった場合trueになる
    if (s_map.count(s)) if (s_map[s] != t) ok = false;
    if (t_map.count(t)) if (t_map[t] != s) ok = false;
    s_map[s] = t; t_map[t] = s;
  }
  if (ok) puts("Yes");
  else puts("No");
}

/**
 * 嘘解法
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  string S,T; cin>>S>>T;
  // int型のvectorを要素数26, 値0で初期化
  vector<int> c1(26,0), c2(26,0);
  for(int i = 0; i<S.length(); i++ ) c1[S[i]-'a']++;
  for(int i = 0; i<T.length(); i++ ) c2[T[i]-'a']++;
  sort(c1.begin(), c1.end());
  sort(c2.begin(), c2.end());
  if( c1 == c2 ) cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}
*/

Measured memory_bytes: 776
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;


const int maxn = 400 + 3;

long long dp[maxn][maxn], f[maxn][maxn];
const long long inf = 1e+18;

void solve()
{
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		cin >> dp[i][i];
		f[i][i] = 0;
	}

	for (int l = 2; l <= n; l++)
	{
		for (int i = 0; i + l - 1 < n; i++)
		{
			int j = i + l - 1;
			f[i][j] = inf;
			for (int k = i; k <= j - 1; k++)
			{
				if (f[i][j] >= f[i][k] + f[k + 1][j] + dp[i][k] + dp[k + 1][j])
				{
					f[i][j] = f[i][k] + f[k + 1][j] + dp[i][k] + dp[k + 1][j];
					dp[i][j] = dp[i][k] + dp[k + 1][j];
				}
			}

			//cout << i << " " << j << " " << dp[i][j] << "\n";
		}
	}

	cout << f[0][n - 1];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll A,B,M;cin>>A>>B>>M;
	vl a(A),b(B);
	rep(i,A){
		cin>>a[i];
	}
	rep(i,B){
		cin>>b[i];
	}
	vl x(M),y(M),c(M);
    ll ans=100000000;
	rep(i,M){
		cin>>x[i]>>y[i]>>c[i];
		ans=min(ans,(ll)a[x[i]-1]+b[y[i]-1]-c[i]);
	}
	sort(all(a));sort(all(b));
	ans=min((ll)a[0]+b[0],ans);
	cout<<ans<<endl;
}


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

void main_()
{
    ll N;
    vector<ll> as;
    cin >> N;
    copy_n(istream_iterator<ll>(cin), N, back_inserter(as));

    bitset<100007> pushed;
    int button = 1;
    int ans = 0;
    while (button != 2 && !pushed.test(button)) {
        pushed.set(button);
        button = as[button - 1];
        ans++;
    }
    cout << (pushed.test(button) ? -1 : ans) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main()
{
    int a[4];
    ci >> a[0] >> a[1] >> a[2] >> a[3];
    sort(a, a + 4);

    if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
	co << "YES" << en;
    else
	co << "NO" << en;
  
    return 0;
}


Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  string s;
  cin >> s;
  if (s == "SSS") {
    cout << 0 << endl;
  } 
  if (s == "SSR") {
    cout << 1 << endl;
  }
  if (s == "SRR") {
    cout << 2 << endl;
  }
  if (s == "RRR") {
    cout << 3 << endl;
  }
  if (s == "SRS") {
    cout << 1  << endl;
  }
  if (s == "RSS") {
    cout << 1 << endl;
  }
  if (s == "RRS") {
    cout << 2 << endl;
  }
  if (s == "RSR") {
    cout << 1 << endl;
  }
}


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

using namespace std;

int main(){
    int N;
    vector<int> A;
    int a;
    cin >> N;
    vector<int> memo;
    
    for(int i=0; i<100000; i++){
        memo.push_back(0);
    }

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


    int ans = 0;
    for(int i=0; i<=99997; i++){
        int cnt = memo[i] + memo[i+1] + memo[i+2];
        ans = max(ans, cnt);
    }

    cout << ans << endl;
}


Measured memory_bytes: 892
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

class Bellman_Ford final{
private:
    using size_type=std::vector<long long>::size_type;
    static inline constexpr auto inf=std::numeric_limits<long long>::max();
    static inline constexpr auto minf=std::numeric_limits<long long>::min();
    std::vector<std::tuple<size_type,size_type,long long>>edge;
    std::vector<long long>dist;
public:
    Bellman_Ford(size_type node_cnt):dist(node_cnt)
    {
    }
    void add_edge(size_type from,size_type to,long long cost)
    {
        edge.emplace_back(from,to,cost);
    }
    void update(size_type start=0)
    {
        std::fill(dist.begin(),dist.end(),inf);
        dist[start]=0;
        bool is_updated=false;
        for(size_type i=0;i<dist.size();++i){
            for(auto[from,to,cost]:edge){
                if(dist[from]!=inf&&dist[to]>dist[from]+cost){
                    dist[to]=dist[from]+cost;
                    is_updated=true;
                }
            }
            if(!is_updated)break;
        }
        if(is_updated){
            for(auto[from,to,cost]:edge){
                if(dist[from]==minf||(dist[from]!=inf&&dist[to]>dist[from]+cost)){
                    dist[to]=minf;
                }
            }
        }
    }
    long long get_dist(size_type node)
    {
        return dist[node];
    }
    bool is_unreacheable(size_type node)
    {
        return dist[node]==inf;
    }
    bool is_in_negative_loop(size_type node)
    {
        return dist[node]==minf;
    }
};
int main()
{
    ll n=in(),m=in();
    Bellman_Ford bf(n);
    for(ll i=0;i<m;++i){
        ll a=in(),b=in(),c=in();
        bf.add_edge(a-1,b-1,-c);
    }
    bf.update();
    cout<<(bf.is_in_negative_loop(n-1)?"inf":to_string(-bf.get_dist(n-1)))<<endl;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int ans=0;
	ll n;
	cin>>n;
	ll x=7;
	ll c=1;
	ll cc=1e7;
	while(cc--)
	{
		if(x%n==0)
		{
			cout<<c<<endl;
			return 0;
		}
		c++;
		x%=n;
		x=x*10+7;
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 3620
//package cf;
import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.LongAdder;

public class Main {
    static int p=1000000007;
    public static void main(String[] args) throws Exception {
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc = new FastReader();
        // long k = sc.nextLong();
        int n = sc.nextInt();
        int k= sc.nextInt();
        StringBuilder sb = new StringBuilder();
        int ar[]=new int[n];
        int s=0,tot=0;
        for(int i=0;i<n;i++)
        {
            ar[i]=sc.nextInt();
        }
        Arrays.sort(ar);
        int dp[] = new int[k+1];
       // Arrays.fill(dp,-1);
        //dp[0]=0;
        for(int i=1;i<=k;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i-ar[j]>=0&&dp[i-ar[j]]==0)
                {
                    dp[i]=1;
                    break;
                }
            }
        }
        System.out.println(dp[k]==1?"First":"Second");
//Arrays.fill(dp,-1);
        //System.out.println(dp(ar,n,k,dp));


    }
    public static int dp(int ar[],int n,int k,int dp[]) {
      //  System.out.println(k+" ");
        if(k<=0)
            return 0;
        if(dp[k]!=-1)
            return dp[k];

         for(int i=0;i<n;i++)
        {
            if(k-ar[i]<0)
                break;
            int ans=dp(ar,n,k-ar[i],dp);
            if(ans==0)
            {
             // System.out.println(k+" "+ar[i]);
                dp[k]=1;
                return dp[k]=1;
            }
        }
        dp[k]=0;
        return dp[k];
    }




    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }


}


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

int judge(string a, string b)
{
    int la = a.length();
    int lb = b.length();
    int l  = (la < lb)? la : lb;

    for (int i = 0; i < l; ++i) {
        if (a[i] > b[i])
            return 3;
         else if (a[i] < b[i])
             return 0;
    }

    if (la > lb)
        return 3;
    else if (la < lb)
        return 0;
    else
        return 1;
}

int main(void)
{
    int n, p1 = 0, p2 = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string a, b;
        cin >> a >> b;
        int tmp1, tmp2;
        tmp1 = judge(a, b);
        tmp2 = judge(b, a);

        p1 += tmp1;
        p2 += tmp2;
    }

    cout << p1 << " " << p2 << endl;

    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define ll long long
#define MOD 2019
#define N 200123

using namespace std;

string s;
ll ans, f[3000], curr, last, v[N], pot;

int main() {
    ios_base::sync_with_stdio(0);

    cin >> s;

    int n = s.size();

    pot = 1;
    for(int i = n - 1; i >= 0; --i) {
        v[i] = ((s[i] - '0') * pot) % MOD;
        pot = (pot * 10) % MOD;
    }

    f[0] = 1;
    for(int i=0; i < n; ++i) {
        curr = (last + v[i]) % MOD;
        ans += f[curr];
        f[curr]++;
        last = curr;
    }
    //cout << endl;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 5328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x=min(x, y)
#define chmax(x,y) x=max(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = (1<<21);
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main(){
	int n, c;
    cin >> n >> c;
  	vector<vector<int>> D(c, vector<int>(c));
    rep(i, c)rep(j, c) cin >> D[i][j];
    vector<map<int, int>> C(3);
    rep(i, n)rep(j, n){
        int tmp;
        cin >> tmp;
        tmp--;
        int index = (i+j)%3;
        C[index][tmp]++;
    }
    vector<vector<ll>> cost(3, vector<ll>(c, 0));
    rep(i, 3)rep(j, c)
    {
        for(auto itr = C[i].begin(); itr!=C[i].end(); itr++){
            int key = itr->first, value = itr->second;
            cost[i][j] += D[key][j] * value;
        }
    }
    ll ans = INF;
    rep(i, c)rep(j, c)rep(k, c){
        if(i!=j and i!=k and j!=k){
            chmin(ans, cost[0][i] + cost[1][j] + cost[2][k]);
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    long long x = 0;

    long N;
    scanf("%ld", &N);

    for (int i = 0; i <= N; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            x += i;
        }
    }
    printf("%lld\n", x);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

int main() {
    const int INF = 2e9;
    int N, M;
    cin >> N >> M;
    vector<int> dp = vector<int>(1 << N, INF);
    dp[0] = 0;
    for(int i = 0; i < M; i++) {
        int A, B, C = 0;
        cin >> A >> B;
        for(int j = 0; j < B; j++) {
            int tmp;
            cin >> tmp;
            C |= 1 << (tmp - 1);
        }
        for(int b = 0; b < (1 << N); b++) {
            dp[b | C] = min(dp[b | C], dp[b] + A);
        }
    }
    int ans = dp[(1 << N) - 1];
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        s: Chars,
    }
    let ans = if s[2] == s[3] && s[4] == s[5] {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    char c[19]; REPI(i, 19) cin >> c[i];
    REPI(i, 19)
        cout << (c[i] != ',' ? c[i] : ' ');
}


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

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,odd=0;
    cin >> n;
    rep(i,n){
        int a;
        cin >> a;
        if(a%2==1)odd++;
    }
    if(odd%2){
        cout << "NO" << endl;
    }else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

// practice for deque

int main() {
  int n;
  cin >> n;
  deque<int> b;
  rep(i,n) {
    int a;
    cin >> a;
    if(i%2==0) b.push_back(a);
    else b.push_front(a);
  }
  if(n%2==1) reverse(b.begin(),b.end());
  rep(i,b.size()-1) cout << b[i] << " ";
  cout << b[b.size()-1] << endl;
  return 0;
}

Measured memory_bytes: 2944
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
n,m = map(int,input().split())
s=list(input())
t=list(input())
l=lcm(n,m)
g=gcd(n,m)
for i in range(g):
    if s[i*(n//g)]!=t[i*(m//g)]:
        l=-1
        break
print(l)


Measured memory_bytes: 52336
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll a,b;
	cin>>a>>b;
	if(a*b<=0){cout<<"Zero"<<endl; return 0;}
	if(a>0){cout<<"Positive"<<endl; return 0;}
	if(!((b-a+1)%2))cout<<"Positive"<<endl;
	else cout<<"Negative"<<endl;

	// if(0<a && a<=b){cout<<"Positive"<<endl; return 0;}
	// if(b<0){
	// 	if((b-a+1)%2){cout<<"Negative"<<endl;}
	// 	else {cout<<"Positive"<<endl;}
	// 	return 0;
	// }
	// cout<<"Zero"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    int A1 = 0;
    int B1 = 0;
    int C1 = 0;
    int D1 = 0;
    int A2 = 0;
    int B2 = 0;
    int C2 = 0;
    int D2 = 0;
    int enter;
    unsigned long long min = 1000000000000;
    int min_x;
    int min_y;
    int i, j;
    cin >> n;
    vector<int> ent;
    vector<int> a;
    vector<int> b;
    for(i = 0; i < n; i++) {
        cin >> enter;
        ent.push_back(enter);
    }
    sort(ent.begin(), ent.end(), greater<int>());
    for(i = 0; i < n; i++) {
        a.push_back(ent[i]);
        b.push_back(ent[i]);
    }
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            if(a[i] - a[j] > 0) {
                if(a[i] - a[j] < min) {
                    min = a[i] - a[j];
                    min_x = i;
                    min_y = j;
                }
            }
        }
    }

    C1 = a[min_x];
    D1 = a[min_y];

    a.erase(a.begin() + min_x);

    a.erase(a.begin() + min_y - 1);

    A1 = a[0];
    B1 = a[1];

    A2 = b[0];
    B2 = b[1];

    b.erase(b.begin());
    b.erase(b.begin());

    min = 1000000000000;
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            if(b[i] - b[j] > 0) {
                if(b[i] - b[j] < min) {
                    min = b[i] - b[j];
                    min_x = i;
                    min_y = j;
                }
            }
        }
    }
    C2 = b[min_x];
    D2 = b[min_y];

    if((A1 + B1) / (C1 - D1) > (A2 + B2) / (C2 - D2)) {
        printf("%16f\n", (double)(A1 + B1) / (C1 - D1));
    } else {
        printf("%16f\n", (double)(A2 + B2) / (C2 - D2));
    }

    return 0;
}


Measured memory_bytes: 3288
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort.push(0)
ans = 0
for i in 0..n-2
  a[i] += a[i-1]
  if a[i]*2 < a[i+1]
    ans = i+1
  end
end
puts n-ans

Measured memory_bytes: 11256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,d;
    cin>>n>>d;
    int c=0;
    for(ll i=0; i<n; i++)
    {
        ll x,y;
        cin>>x>>y;
        if((x*x+y*y)<=d*d)
        {
            c++;
        }
    }
    cout<<c<<endl;
}


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

const int N = 310;

double dp[N][N][N];
int n, cnt[4];

double solve(int a, int b, int c) {
    if (a+b+c == 0) return 0.0;
    double k = (double)n/(a+b+c);
    double &r = dp[a][b][c];
    double res = 0;

    if (r > -0.5) return dp[a][b][c];
    if (a) {
        res += (solve(a-1, b, c) + k)*a/(a+b+c);
    }
    if (b) {
        res += (solve(a+1, b-1, c) + k)*b/(a+b+c);
    } 
    if (c) {
        res += (solve(a, b+1, c-1) + k)*c/(a+b+c);
    }
    return dp[a][b][c] = res;
}

int main() {
    cin >> n;
    fore(i,0,N)fore(j,0,N)fore(k,0,N)dp[i][j][k] = -1.0;
    
    fore(i,0,n) {
        int aux;
        cin >> aux;
        cnt[aux]++;
    }

    int a, b, c;
    a=cnt[1], b=cnt[2], c=cnt[3];
    printf("%.12f\n", solve(a, b, c));
}

Measured memory_bytes: 233088
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n, y;
  cin >> n >> y;
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n - i; j++){
      if(i * 10000 + j * 5000 + (n - i - j) * 1000 == y){
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N,K;
  cin>>N>>K;
  vector<double> data(N);
  for (int i = 0; i < N; i++)
  {
    cin>>data[i];
  }

  for (int i = 0; i < N; i++)
  {
    data[i] = (data[i]+1)/2;
  }
  vector<double> SUM(N+1,0);
  for (int i = 0; i < N; i++)
  {
    SUM[i+1] += SUM[i] + data[i];
  }
  double ANS = 0;
  for (int i = 0; i < N - K + 1; i++)
  {
    ANS = max(ANS,SUM[K + i] - SUM[i]);
  }
  
  cout<<ANS<<endl;
  

  
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>
#include <string.h>
#define N 100000
 
 
typedef struct
{
  int time;
  char name[10];
}P;
 
int head,tail,n;
int  min(int,int);
void enqueue(Pro);
P dequeue(void);
 
P Q[N];
 
int main()
{
  int q,i,c,e=0;
  P z;
 
  scanf("%d%d",&n,&q);
  
  for(i=1;i<=n;i++)
    {
      scanf("%s%d" ,Q[i].name,&Q[i].time);
    }
  
  head = 1;
  tail = n+1;
  while(head!=tail)
    {
      z = dequeue();
      c = min(q,z.time);
      z.time -= c;
      e += c;
      if(z.time > 0)
	{
	  enqueue(z);
	}
      else printf("%s %d\n",z.name,e);
    }
  return 0;
}
 
void enqueue(P x)
{
  Q[tail] = x;
  tail = (tail + 1)% N;
}

P dequeue()
{
  P x;  
  x = Q[head];
  head = (head + 1) % N;
    
  return x;  
}
 
int min(int v, int w)
{
  return v < w ? v:w;
}

Measured memory_bytes: 2160
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
-- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace
import           Text.Printf


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons
getInt = readLn :: IO Int
getInt2Tuple = (\vec -> (vec VU.! 0, vec VU.! 1)) <$> getIntVector
getInt3Tuple = (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) <$> getIntVector


-- s = sum [1..n-1]
-- s = sum [1..n-1]
-- 2s = (n-1)*n

main = do
  n <- getInt
  print $ solve n

solve n = (n-1)*n `div` 2


Measured memory_bytes: 508
import numpy as np
n=int(input())
b=list(map(int,input().split()))

ans=0
for i in range(n):
    if i==0:
        ans+=b[i]
    elif i==n-1:
        ans+=b[i-1]
    else:
        ans+=np.min((b[i],b[i-1]))

print(ans)

Measured memory_bytes: 12484
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Measured memory_bytes: 40664
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, K;
    cin >> N >> K;
    vector<ll> P(N), C(N);
    rep(i, N) {
        cin >> P[i];
        P[i]--;
    }
    rep(i, N) cin >> C[i];
    
    ll ans = -(1LL << 62);
    rep(i, N) { // iから始まる
        ll len = 0;
        ll sum = 0;
        ll vv = i;
        while(1) {
            vv = P[vv];
            sum += C[vv];
            len++;
            if(vv == i) break;
        }
        ll tmp = 0;
        ll llen = 0;
        ll v = i;
        while(1) {
            v = P[v];
            llen++;
            tmp += C[v];
            if(llen > K) break;
            ll loops = (K - llen) / len;
            ans = max(ans, tmp);
            ans = max(ans, tmp + sum * loops);
            
            if(v == i) break;
        }
        
    }
    output(ans);
    return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



string s;
void solve(){
	cin >> s;
	int n = s.size();
	
	int ans[101010] = {0};
	int l = 0, r = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R'){
			if(i % 2) r++;
			else l++;
		}
		else{
			if(i % 2){
				ans[i] += r;
				ans[i-1] += l;
			}
			else{
				ans[i] += l;
				ans[i-1] += r;
			}
			l = 0; r = 0;
		}
	}
	
	for(int i = 0; i < n; i++){
		if(s[n-i-1] == 'L'){
			if(i % 2) l++;
			else r++;
		}
		else{
			if(i % 2){
				ans[n-i-1] += l;
				ans[n-i] += r;
			}
			else{
				ans[n-i-1] += r;
				ans[n-i] += l;
			}
			l = 0; r = 0;
		}
	}
	
	for(int i = 0; i < n; i++){
		cout << ans[i];
		if(i != n-1) cout << " ";
	}
	cout << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 1104
import collections

n = int(input())
s_list = []
for _ in range(n):
    s_list.append(input())
s_data = list(collections.Counter(s_list).most_common())
s_count = int(s_data[0][1])
s_index = 0
for s in s_data:
    if int(s[1]) == s_count:
        s_index += 1
    else:
        break
output = []
for i in range(s_index):
    output.append(s_data[i][0])
output.sort()
for s in output:
    print(s)


Measured memory_bytes: 45036
#include <iostream>

using namespace std;
using ll = long long;

ll modpow(ll a, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	ll m, n;
	cin >> m >> n;
	cout << modpow(m, n, 1000000007) << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  int number;
  cin >> number;
  switch (number%10) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    cout << "hon" << endl;
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    cout << "pon" << endl;
    break;
  default:
    cout << "bon" << endl;
    break;
  }
  return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    string search[4] = {"maerd", "remaerd", "esare", "resare"};
    int d = 0, k;
    for (int i = 0; i < s.length();)
    {
        for (int j = 0; j < 4; j++)
        {
            k = 0;
            if (s.substr(i, search[j].length()) == search[j])
            {
                i += search[j].length();
                k++;
                break;
            }
        }
        if (k == 0)
        {
            d++;
            break;
        }
    }
    if (d == 0) cout << "YES";
    else cout << "NO";
}

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

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

    cin >> a >> b >> c >> d;

    while(a > 0 || c > 0){
        c-=b;
        if(c <= 0){
            cout <<"Yes"<<endl;
            break;
        }
        a-=d;
        if(a<=0){
            cout << "No" << endl;
            break;
        }
    }
    
    
}

Measured memory_bytes: 3640
n, y = map(int, input().split())
a = -1 #10000
b = -1 #5000
c = -1 #1000
for i in range(n + 1):
    if n + 1 - i > 0:
        for j in range(n + 1 - i):
            k = n - i - j
            if 10000 * i + 5000 * j + 1000 * k == y:
                a = i
                b = j
                c = k
                break
    else:
        if 10000 * (n + 1) == y:
            a = n + 1
            b = n + 1 - i
            c = n + 1 - i
            break
        else:
            continue
print('{} {} {}'.format(a, b, c))

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

using namespace std;

int Max(const string &data){
  string buf(data);
  sort(buf.begin(),buf.end());
  int maxval=0;
  for(int i=0;i<buf.size();i++){
    buf[i]-='0';
    maxval+=buf[i]*pow(10,i);
  }
  return maxval;
}

int Min(const string &data){
  string buf(data);
  sort(buf.begin(),buf.end(),greater<char>());
  int minval=0;
  for(int i=0;i<buf.size();i++){
    buf[i]-='0';
    minval+=buf[i]*pow(10,i);
  }
  return minval;
}

int main(){
  string strdata;
  int n;
  cin>>n;
  vector<int> diff(n);
  for(int i=0;i<n;i++){
    cin>>strdata;
    diff[i]=Max(strdata)-Min(strdata);
  }
  for(int i=0;i<n;i++){
    cout<<diff[i]<<endl;
  }

}

Measured memory_bytes: 1268
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    long long N;
    cin >> N;

    vector<long long> C(N - 1), S(N - 1), F(N - 1);
    for (int i = 0; i < N - 1; i++)cin >> C[i] >> S[i] >> F[i];

    for (int i = 0; i < N; i++) {
        long long time = 0;
        for (int j = i; j < N - 1; j++) {
            long long t = time - S[j];
            if (t < 0) t = S[j];
            else {
                t = S[j] + ((time - S[j]) / F[j]) * F[j] + ((time - S[j]) % F[j] > 0 ? 1 : 0) * F[j];
            }
            time = t + C[j];
        }
        cout << time << endl;
    }

}















































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

using namespace std;

int main() {

    int n,m;

    cin >> n >> m;
    if(m == 1) return cout << "0\n",0;
    int cur = n;
    int ans = 1;
    while(cur < m) {
        cur--;
        cur+= n;
        ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int x;
  vector<int> v;
  for(int i=0;i<n;i++)
  {
    cin>>x;
    v.push_back(x);
  }
  int dp[n];
  dp[0]=0;
  for(int i=1;i<n;i++)
  {
    int minval=INT_MAX;
    for(int j=i-1;((j>=0)&&(j>=i-k));j--)
    {
      minval=min(minval,abs(v[i]-v[j])+dp[j]);
    }
    dp[i]=minval;
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1144
#include <stdio.h>
#include <stdlib.h>

int main()
{int a,b,c,d,e,i;
 while(~scanf("%d%d%d%d",&a,&b,&c,&d))
 {i=0;e=0;
  if(a>b)
  while(i<a)
  {while(i<b)
   {e+=c;
    i++;
   }
   e+=d;
   i++;
  }
  if(a<=b)
  e=c*a;
  printf("%d\n",e);
 }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main (void) {
	int n, i, j, swaps = 0, tmp;
	int* data;
	scanf("%d", &n);
	data = (int*)malloc(sizeof(int) * n);
	for (i = 0; i < n; i++) {
		scanf("%d", data + i);
	}
	for (i = 0; i < n; i++) {
		for (j = n - 1; j > i; j--) {
			if (data[j] < data[j-1] ) {
				tmp = data[j-1];
				data[j-1] = data[j];
				data[j] = tmp;
				swaps++;
			}
		} 
	}
	for (i = 0; i < n; i++) {
		printf("%d", *(data + i));
		if (i < n - 1) printf(" ");
		else printf("\n");
	}
	printf("%d\n", swaps);
	free(data);
	return 0;
}


Measured memory_bytes: 1988
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <functional>
#include <tuple>

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define fst first
#define scd second

using pii=pair<int,int>;
using vpii=vector<pii>;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

struct edge{
};

signed main()
{
    int K, S; cin >> K >> S;

    int cnt = 0;

    rep(X, K + 1) rep(Y, K + 1) {
        int Z = S - X - Y;
        if (Z < 0 || Z > K) continue;

        cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
# ABC062B - Picture Frame
h, w = list(map(int, input().rstrip().split()))
lst = [input().rstrip() for _ in range(h)]
ans = ["#" * (w + 2)]

for i in range(h):
    ans.append("#" + lst[i] + "#")
ans.append("#" * (w + 2))

for i in ans:
    print(i)

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

ll dp[101010], H[101010];

int main(){
  int N; cin>>N;
  rep(i,N) cin>>H[i];
  fill(dp,dp+101010,1e15);
  dp[0]=0;
  rep(i,N){
    dp[i+1]=min(dp[i+1],dp[i]+abs(H[i]-H[i+1]) );
    dp[i+2]=min(dp[i+2],dp[i]+abs(H[i]-H[i+2]) );
  }
  cout<<dp[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 1792