akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<vector<vector<ll>>> vvvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// struct UnionFind {
//     vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
//
//     UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
//         for(int i = 0; i < N; i++) par[i] = i;
//     }
//
//     int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
//         if (par[x] == x) return x;
//         return par[x] = root(par[x]);
//     }
//
//     void unite(int x, int y) { // xとyの木を併合
//         int rx = root(x); //xの根をrx
//         int ry = root(y); //yの根をry
//         if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
//         par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
//     }
//
//     bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };
//
vint divisor(ll n){ // nの約数
  vint ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i == 0){
      ret.pb(i);
      if(i*i!=n) ret.pb(n/i);
    }
  }
  vsort(ret);
  return ret;
}

ll my_pow(ll x,ll y){
  ll rtn=1;
  rep(i,y) rtn*=x;
  return rtn;
}

ll get_digit_in(ll n, ll i){ // i桁目の数字を得る。
  for(ll j=0;j<i-1;j++){
    n/=10;
  }
  return n%10;
}

ll get_digit(ll n){
  ll rtn=0;
  while(n>0){
    n/=10;
    rtn++;
  }
  return rtn;
}



int main() {
  cout<<fixed<<setprecision(10);


  ll n,k;cin>>n>>k;

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

}




//


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)

	A := make([]int, N-1)
	for i := 0; i < N-1; i++ {
		fmt.Scanf("%d", &A[i])
	}
	counterMap := make(map[int]int)
	for i := 1; i <= N; i++ {
		counterMap[i] = 0
	}
	for i := 0; i < N-1; i++ {
		counterMap[A[i]]++
	}

	for i := 1; i <= N; i++ {
		fmt.Println(counterMap[i])
	}
}


Measured memory_bytes: 16000
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main(void){
    int A, B, C, ans = 0;
    cin >> A >> B >> C;
    
    if(B / A >= C)
        ans = C;
    else
    ans = B / A;
    
    cout << ans <<endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  double total = 0;
  int N, i;

  scanf("%d", &N);

  for(i = 0; i < N; i++){
    double x;
    scanf("%lf", &x);
    char u[3] = {};
    scanf("%s", &u);
    
    if(u[0] == 'J'){
      total += x;
    }
    if(u[0] == 'B'){
      total += x * 380000.0;
    }
  }

  printf("%lf\n", total);

  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

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

const int mod = 998244353;
// const int inf = 1e9L + 5;
int bi[1 << 20];
int spos[1<<20];
int siega[1<<20];
pii x[1 << 20];

int getMax(int p, int q, int pocz, int kon, int ind = 1) {
	// printf("getMax: %d, %d, %d ,%d,%d\n", p,q,pocz,kon,ind);
	if (p == pocz && q == kon) {
		return bi[ind];
	}
	int sr = (pocz + kon) / 2;
	if (q <= sr) return getMax(p,q,pocz,sr,2*ind);
	else if (p > sr) return getMax(p, q, sr + 1, kon, 2*ind + 1);
	return max(getMax(p,sr,pocz,sr, 2*ind), getMax(sr+1,q,sr+1,kon,2*ind + 1));
};

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

	int n;
	cin >> n;
	FOR(i, 1, n) {
		cin >> x[i].st >> x[i].nd;
	}
	sort(x+ 1, x + n + 1);
	spos[n + 1] = 1;
	siega[n + 1] = n + 1;
	spos[n] = 2;
	siega[n] = n + 1;
	int base = 1;
	while (base <= n) {
		base <<= 1;
	}
	auto insert = [&](int ind, int val) {
		// printf("insert: %d, %d\n", ind, val);
		ind = ind + base - 1;
		bi[ind] = val;
		while (ind / 2) {
			ind /=2;
			bi[ind] = max(bi[2*ind], bi[2*ind + 1]);
		}
	};
	insert(n, n + 1);
	// debug() << imie(x);
	// debug() << imie(bi);
	FORD(i, n, 1) {
		if (x[i].st + x[i].nd <= x[i + 1].st) {
			siega[i] = i + 1;
		} else {
			int idx = lower_bound(x + 1, x + n + 1, mp(x[i].st + x[i].nd, -1)) - x;
			// printf("getMax: %d, %d\n", i, idx - 1);
			siega[i] = getMax(i, idx - 1, 1, base); //siega[idx - 1];
		}
		spos[i] = spos[i + 1];
		spos[i] = (spos[siega[i]] + spos[i]) % mod;
		insert(i, siega[i]);
		// printf("i: %d, spos: %d, siega: %d\n", i, spos[i], siega[i]);
	}
	cout << spos[1] << endl;
	return 0;
}

Measured memory_bytes: 7936
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if ((a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12) && (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12))
            System.out.println("Yes");
        else if ((a == 4 || a == 6 || a == 9 || a == 11) && (b == 4 || b == 6 || b == 9 || b == 11))
            System.out.println("Yes");
        else if (a == 2 && b == 2)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


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

int main() {
  string S;cin>>S;int a=0;
  if(S[0]=='R')a++;
  if(S[1]=='R')a++;
  if(S[2]=='R')a++;
  if(S[1]=='S'&&a>0)cout<<1<<endl;
  else cout<<a<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<mint> v(n);
  vector<mint> sum(n+1);
  rep(i, n) cin >> v[i].x;
  rep(i, n) sum[i+1] = sum[i] + v[i];
  mint res = 0;
  rep(i, n-1) res += v[i] * (sum[n]-sum[i+1]);

  cout << res << endl;
}


Measured memory_bytes: 6356
#include<bits/stdc++.h>
#include<map>
#include<set>
using namespace std;
int main () {
  int N;
  cin >> N;
  string S;
  cin >> S;
  string ku = S.substr(0, N);
  string ma = S.substr(N, N);
  map<pair<string, string>, long long>pre;
  set<pair<string, string>>af;
  map<pair<string, string>, long long>aft;
  for (int i_ = 0; i_ < 1 << N; i_ ++) {
    int i = i_;
    string k = "";
    string u = "";
    int si = 0;
    for (int j = 0; j < N; j ++) {
      if (i % 2) k += ku[j];
      else {
        u += ku[j];
        si ++;
      }
      i /= 2;
    }
    string al = "";
    for (int j = si - 1; j >= 0; j --) al += u[j];
    pre[make_pair(k, al)] ++;
  }
  for (int i_ = 0; i_ < 1 << N; i_ ++) {
    int i = i_;
    string k = "";
    string u = "";
    int si = 0;
    for (int j = 0; j < N; j ++) {
      if (i % 2) k += ma[j];
      else {
        u += ma[j];
        si ++;
      }
      i /= 2;
    }
    string al = "";
    for (int j = si - 1; j >= 0; j --) al += u[j];
    aft[make_pair(al, k)] ++;
    af.insert(make_pair(al, k));
  }
  long long ans = 0;
  for (auto x : af) {
    ans += pre[x] * aft[x];
    //cout << x.first << ' ' << x.second << endl;
    //cout << pre[x] << ' ' << aft[x] << endl;
  }
  cout << ans << endl;
}



Measured memory_bytes: 124672
import fractions
import sys
input = sys.stdin.readline


P = 10**9 + 7
N = (10**6)+1
inv_t = [0]+[1]
for i in range(2, N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

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

mod = 10**9+7
lcm = 1
B = [0]*N

for i in range(N):
    lcm = (lcm // fractions.gcd(lcm, A[i])) * A[i]

ans = 0

lcm %= mod
for i in range(N):
    ans += (lcm * inv_t[A[i]]) % mod
    ans %= mod

print(ans)


Measured memory_bytes: 97500
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;


vector<vector<bool>> seen;
vector<int> dx;
vector<int> dy;

void dfs(int u,int v,vector<vector<int>> &c){

    seen[u][v]=true;

    for(int i=0;i<8;i++){
        if(c[u+dx[i]][v+dy[i]]==0)continue;
        if(seen[u+dx[i]][v+dy[i]])continue;
        dfs(u+dx[i],v+dy[i],c);
    }

}

int main(){

    dx={-1,0,1,-1,1,-1,0,1};
    dy={1,1,1,0,0,-1,-1,-1};

    int w=1,h=1;
    cin >> w >> h;
    while(true){
        if(h==0 && w==0)break;
        else{
            vector<vector<int>> c(h+2);
            for(int i=0;i<h+2;i++)c[i].resize(w+2);

            for(int i=0;i<w+2;i++)c[0][i]=0;

            for(int i=1;i<h+1;i++){
                c[i][0]=0;
                for(int j=0;j<w;j++){
                    cin >> c[i][j+1];
                }   
                c[i][w+1]=0;
            }
            for(int i=0;i<w+2;i++)c[h+1][i]=0;
            seen.resize(h+2);
            for(int i=0;i<h+2;i++)seen[i].assign(w+2,false);            

            int e=0;

            for(int i=1;i<h+1;i++){
                for(int j=1;j<w+1;j++){
                    if(seen[i][j]==false && c[i][j]==1){
                        dfs(i,j,c);
                        e++;
                    }
                }
            }
            cout << e << endl;
        }
        cin >> w >> h;
    }
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <math.h>

int main(void){
  double a, b, C, S, L ,h, rad;
  scanf("%lf %lf %lf", &a, &b, &C);

  rad = C * M_PI / 180.0;
  h = b * sin(rad);
  L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(rad));
  S = a * h / 2;

  printf("%lf\n", S);
  printf("%lf\n", L);
  printf("%lf\n", h);
  return 0;
}

Measured memory_bytes: 648
X = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(X[K - 1])

Measured memory_bytes: 3060
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);

    console.log(K === 1 ? 0 : N - K);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21956
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
# define rep(i,n) for(int i=0;i<n;i++)
void solve(){
    lli d,t,s;
    cin>>d>>t>>s;

    lli r= t*s;
    if(r>=d){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }


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

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;
int len[3010][3010];

int main(){
    string s1, s2;
    cin >> s1 >> s2;
    int n = s1.size(), m = s2.size();
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s1[i - 1] == s2[j - 1])
                len[i][j] = len[i - 1][j - 1] + 1;
            else
                len[i][j] = max(len[i - 1][j], len[i][j - 1]); 
        }
    }
    string ans = "";
    while(n > 0 && m > 0){
        if(s1[n - 1] == s2[m - 1]){
            ans += s1[n - 1];
            n--; m--;
        }else{
            if(len[n - 1][m] == len[n][m])
                n--;
            else
                m--;
        }
    }
    reverse(begin(ans), end(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35584
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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




fn solve(w: i64, a: i64, b: i64) -> i64 {
    if a + w < b {
        b - (a+w)
    } else if b + w < a {
        a - (b+w)
    } else {
        0
    }
}


fn main() {
    input! {
        w: i64,
        a: i64,
        b: i64
    }
    println!("{}", solve(w, a, b));
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  vec A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  UNIQUE(A);

  int cont = 1;
  for (int i = 2; i < A.size(); i++) {
    if ((A[i - 2] < A[i - 1] && A[i - 1] > A[i]) ||
        (A[i - 2] > A[i - 1] && A[i - 1] < A[i])) {
      cont++;
      i++;
    }
  }

  cout << cont << endl;
  return 0;
}


Measured memory_bytes: 1024
N = gets.to_i

c = (1 .. N).each_with_object(Array.new(10){Array.new(10, 0)}){|n, a| a[n.to_s[0].to_i][n%10] += 1}
puts [*0 .. 9].repeated_permutation(2).inject(0){|s, (i, j)| s + c[i][j]*c[j][i]}

Measured memory_bytes: 1788
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "c.cpp"

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;

  constexpr double pi = acos(-1);

  h += m/60;
  h = h/12*2*pi;
  m = m/60*2*pi;
  double x = h-m;
  cerr << h/2/pi * 360 << " ";
  cerr << m/2/pi * 360 << " " << el;
  cerr << x << el;
  if (x < 0) {
    x += 2*pi;
  }

  if (x > pi) {
    x = 2*pi-x;
  }

  cerr << x/2/pi * 360 << el;
  cout << sqrt(a*a + b*b - 2*b*a*cos(x)) << el;
}


Measured memory_bytes: 4196
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define mod 1000000007
#define inf 1e18
#define PI 3.14159265358979323846264338327950L
#define w(x) int x; cin>>x; while(x--)
using namespace std;
bool sieve[2000006];
void sieve_make() 
{
	memset(sieve,true,sizeof(sieve));
	sieve[0]=sieve[1]=false;
	for(int i=2;i*i<2000006;i++)
	{
		if(sieve[i])
		{
			for(int j=i*i;j<2000006;j+=i)
				sieve[j]=false;
		}
	}
}

int max(int a,int b)
{
	if(a>b)
		return a;
	return b;
}
int min(int a,int b)
{
	if(a<b)
		return a;
	return b;
}
int modexp(int a,int b,int c)
{
	if(a==0) return 0;
	if(b==0) return 1;

	int ans;
	if(b%2==0)
	{
		int small=modexp(a,b/2,c);
		ans=(small*small)%c;
	}
	else
	{
		int small=modexp(a,b-1,c);
		ans=(a%c);
		ans=(small*ans)%c;
	}
	return (ans+c)%c;
}
bool sign(int x)
{
	if(x>0)
		return true;
	return false;
}
int kadane(int* a,int n)
{
	int loc=a[0],glo=a[0];
	for(int i=1;i<n;i++)
	{
		loc=max(a[i],loc+a[i]);
		glo=max(glo,loc);
	}
	return glo;
}
int prefix[101],dp[401][401];
int help(vector<int>& a,int i,int j)
{
	int s=0;
	for(int k=i;k<=j;k++)
		s+=a[k];
	return s;
}
int solve(vector<int>& a,int i,int j)
{
	if(i==j) return 0;

	int ans=inf;
	if(dp[i][j]!=-1) return dp[i][j];
	for(int k=i;k<j;k++)
	{
		int left=solve(a,i,k);
		int right=solve(a,k+1,j);
		ans=min(ans,left+right+help(a,i,j));
	}
	return dp[i][j]=ans;
}


int32_t main()
{
	ios::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
	
	
	
	
	memset(dp,-1,sizeof dp);
	int n;
	cin>>n;
	vector<int>a(n);
	int s=0;
	for(int i=0;i<n;i++){ cin>>a[i];
	}
	

	prefix[0]=a[0];

	for(int i=1;i<n;i++) prefix[i]=prefix[i-1]+a[i];
	
	cout<<solve(a,0,a.size()-1);
	
}



Measured memory_bytes: 4932
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int dp[2][111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	ll sum[2] = {0,0};
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>dp[i][j];
			if(i==1) sum[i]+=dp[i][j];
		}
	}
	sum[0]=dp[0][0];
	ll ans = 0;
	for(int i=0;i<n;i++)
	{
		ans = max(ans, sum[0] + sum[1]);
		if(i+1<n)
		{
			sum[0]+=dp[0][i+1];
			sum[1]-=dp[1][i];
		}
	}
	cout<<ans<<'\n';
}


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

int main(){
  long n, a, sf = 0, sr = 0;  cin >> n;
  priority_queue<long, vector<long>, greater<long>> pqf;
  for(int i=0; i<n; i++){
    cin >> a;
    sf += a;
    pqf.push(a);
  }
  vector<long> mid(n+1), mf(n+1), mr(n+1);  mf[0] = sf;
  for(int i=0; i<n; i++)  cin >> mid[i];
  priority_queue<long> pqr;
  for(int i=0; i<n; i++){
    cin >> a;
    sr += a;
    pqr.push(a);
  }
  mr[n] = sr;

  for(int i=0; i<n; i++){
    pqf.push(mid[i]);
    sf += mid[i];
    sf -= pqf.top();
    pqf.pop();
    mf[i+1] = sf;
  }
  for(int i=n-1; i>=0; i--){
    pqr.push(mid[i]);
    sr += mid[i];
    sr -= pqr.top();
    pqr.pop();
    mr[i] = sr;
  }
  long ans = -1e18;
  for(int i=0; i<=n; i++)
    ans = max(ans, mf[i]-mr[i]);
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7932
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 1(mod 3)のグループと2(mod 3)のグループを先に決める
N = ir()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

root = 1
rank = [0] * (N+1) # 1-indexed
rank[1] = 1
parent = [0] * (N+1) # 1-indexed
stack = [root]
while stack:
    cur = stack.pop()
    r = rank[cur]
    for next in graph[cur]:
        if next == parent[cur]:
            continue
        parent[next] = cur
        rank[next] = r + 1
        stack.append(next)

counter = [0, 0]
for x in rank[1:]:
    counter[x%2] += 1
num0mod3 = N // 3
num1mod3 = (N+2) // 3
num2mod3 = (N+1) // 3
answer = [0] * (N+1)
if max(counter) >= num1mod3 + num2mod3:
    #この時ここに1mod3、2mod3を全部入れる
    if counter[0] > counter[1]:
        index = 0
    else:
        index = 1
    cur = 1
    used = set()
    for i in range(1, N+1):
        if rank[i] % 2 == index:
            answer[i] = cur
            used.add(cur)
            cur += 1
            if cur % 3 == 0:
                cur += 1
            if cur > N:
                break
    cur = 1
    for j in range(1, N+1):
        while cur in used:
            cur += 1
        if answer[j] == 0:
            answer[j] = cur
            used.add(cur)
else:
    #ここではcounterの多い方にnum1mod3を入れる
    if counter[0] > counter[1]:
        index = 0
    else:
        index = 1
    cur = 1
    used = set()
    for i in range(1, N+1):
        if rank[i] % 2 == index:
            answer[i] = cur
            used.add(cur)
            cur += 3
            if cur > N:
                break
    cur = 2
    for i in range(1, N+1):
        if rank[i] % 2 == 1-index:
            answer[i] = cur
            used.add(cur)
            cur += 3
            if cur > N:
                break
    cur = 1
    for j in range(1, N+1):
        while cur in used:
            cur += 1
        if answer[j] == 0:
            answer[j] = cur
            used.add(cur)

print(*answer[1:])


Measured memory_bytes: 113100
#include<stdio.h>
int main(){
  int a[26] = {0}, ans = 0;
  char s[5];
  scanf("%s", s);
  for(int i = 0; i < 4; ++i){
    a[s[i] - 65]++;
  }
  for(int i = 0; i < 26; ++i){
    
    if(a[i]) ans++;
  }
  if(ans == 2) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

template<class T>
struct Vec2
{
	Vec2(){}
	Vec2(T _x, T _y) : x(_x), y(_y) {}

	Vec2 operator+(const Vec2& rhs) const { return Vec2(x + rhs.x, y + rhs.y); }
	Vec2 operator-(const Vec2& rhs) const { return Vec2(x - rhs.x, y - rhs.y); }
	Vec2 operator*(T s) const { return Vec2(x*s, y*s); }
	T dot(const Vec2& rhs) const { return x*rhs.x + y*rhs.y; }
	T cross(const Vec2& rhs) const { return x*rhs.y - y*rhs.x; }
	double length() const { return sqrt(1.0*x*x + 1.0*y*y); }
	bool operator<(const Vec2& rhs) const
	{
		if (x != rhs.x) return x < rhs.x;
		return y < rhs.y;
	}

	T x;
	T y;
};

int main()
{
	typedef Vec2<double> Vec2;

	int cx, cy, r, q;
	cin >> cx >> cy >> r >> q;
	Vec2 C(cx, cy);
	for (int i = 0; i < q; i++) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		Vec2 A(x1, y1), B(x2, y2);
		A = A - C;
		B = B - C;
		Vec2 D = B - A;
		Vec2 DU = D * (1.0 / D.length());
		Vec2 H = A - DU*(A.dot(DU));
		double h = H.length();


		double l = sqrt(r*r - h*h);
		double pa = (A - H).dot(DU), pb = (B - H).dot(DU);
		Vec2 int1 = (H - DU*l) + C;
		Vec2 int2 = (H + DU*l) + C;
		if (int2 < int1) {
			swap(int1, int2);
		}
		printf("%.10lf %.10lf %.10lf %.10lf\n", int1.x, int1.y, int2.x, int2.y);
	}
	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())
#define ll long long

using namespace std;


#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

const ll inf =998244353;
typedef pair<ll,ll> Pair;


typedef vector<ll> vl;

const ll MAX = 510000;
const ll MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//繰り返し２乗
ll cal(ll x,ll n) {  // (K/x)^N　　
    int p = n;
    x %= inf;
    ll res = 1;
    while (p > 0) {
        if (p & 1) res = (x * res) % inf; //pが奇数ならresはx倍される
        x = x * x % inf; //ここはxを二乗している
        p >>= 1; //pを二で割って、あまり切り捨てか。
    }
    return res;
}



void solve(){
    ll n,m,k;
    cin >> n >>m >>k;
    COMinit();
    ll ans=0;
    rep(j,k+1){
        ll score=m;
        score*=COM(n-1,j);
        score%=MOD;
        score*=cal(m-1,n-1-j);
        score%=MOD;
        ans+=score;
        ans%=MOD;
    }
    kaku(ans);
}

int main(){
    solve();
}

Measured memory_bytes: 15592
#include <stdio.h>
#include <queue>
#include <algorithm>
long long x, ans;
long long n, m;
long long a[100000], b[100000];
long long c[100000];
int main() {
	scanf("%lld%lld", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", a + i, b + i);
		c[i] = a[i] * 100000 + b[i];
	}
	std::sort(c, c + n);
	std::priority_queue<long long>q;
	for (int i = 1; i <= m; i++) {
		while (c[x] / 100000 == i) {
			q.push(c[x] % 100000);
			x++;
		}
		if (!q.empty()) {
			ans += q.top();
				q.pop();
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3704
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

ll cutter[]={1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049};

ll cut(ll hi, ll index){
    return (hi/cutter[index])%3;
}

int main(void){
    ll K;
    cin>>K;
    ll dight=1;
    while(true){
        //cout<<endl<<dight<<endl;
        rep1(i, 9){
            rep(j, pow(3, dight-1)){
                ll thum=i;
                bool ng=false;
                rep(k, dight-1){
                    thum+=(cut(j, dight-2-k)-1);
                    //cout<<cut(j, dight-2-k)-1<<":";
                    if(thum<0) ng=true;
                    if(thum>9) ng=true;
                }
                if(!ng){
                    K--;
                    if(K==0){
                        ll ans=i, last=i;
                        rep(k, dight-1){
                            ans*=10;
                            last+=(cut(j, dight-2-k)-1);
                            ans+=last;
                        }
                        cout<<ans<<endl;
                        return 0;
                    }
                    /*ll ans=i, last=i;
                    rep(k, dight-1){
                        ans*=10;
                        last+=(cut(j, dight-2-k)-1);
                        ans+=last;
                    }*/
                    //cout<<"["<<ans<<"]";
                }
                //cout<<"$"<<i<<sp;
            }
        }
        dight++;
    }
    return 0;
}


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

int f(int h,int m,int s){
	return h*3600+m*60+s;
}

int rf(int sec,int &h,int& m,int &s){
	h=sec/3600;
	sec%=3600;
	m=sec/60;
	sec%=60;
	s=sec;
}

int main(void){
	int e1,e2,e3,s1,s2,s3;
	int h,m,s;
	cin>>s1>>s2>>s3>>e1>>e2>>e3;
	rf(f(e1,e2,e3)-f(s1,s2,s3),h,m,s);
	cout<<h<<" "<<m<<" "<<s<<endl;
	cin>>s1>>s2>>s3>>e1>>e2>>e3;
	rf(f(e1,e2,e3)-f(s1,s2,s3),h,m,s);
	cout<<h<<" "<<m<<" "<<s<<endl;
	cin>>s1>>s2>>s3>>e1>>e2>>e3;
	rf(f(e1,e2,e3)-f(s1,s2,s3),h,m,s);
	cout<<h<<" "<<m<<" "<<s<<endl;
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define A 5e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	string s; cin >> s;
	int L = s.size(), le = 0, ri = 0;
	ll ans = 0;
	vector<int> a(L + 1, -1);
	for (int i = 0; i < L; i++) {
		if (s[i] == '<') {
			for (int j = 0; j <= ri; j++) {
				a[i - j] = max(a[i-j],le + j);
			}
			le++;
			ri = 0;
			if (i == L - 1)a[L] = a[L - 1] + 1;
		}
		else {
			a[i] = le;
			ri++;
			le = 0;
			if (i == L - 1) {
				for (int j = 0; j <= ri; j++) {
					a[L - j] = le + j;
				}
			}
		}


	}
	for (int i = 0; i <= L; i++) {
		//cout << a[i] << " ";
		ans += a[i];
	}
	//cout << endl;
	cout << ans << endl;
}

Measured memory_bytes: 5780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    string s;
    cin >> s;
    int ans = 0;
    if(s.length() % 2 == 0){
        for(int i=0; i<s.length()/2; i++){
            if(s[i] != s[s.length()-1-i]){
                ans += 1;
            }
        }
    }
    else{
        for(int i=0; i<s.length()/2; i++){
            if(s[i] != s[s.length()-1-i]){
                ans += 1;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int p[200005];
	for (i = 0; i < n; i++)
		scanf("%d", &p[i]);
	int a[200005];
	for (i = 0; i <= n + 1; i++)
		a[i] = 0;
	for (i = n - 1; i >= 0; i--)
		a[p[i]] = a[p[i] + 1] + 1;
	int max = 0;
	for (i = 0; i <= n; i++)
		if (max < a[i])
			max = a[i];
	printf("%d\n", n - max);
	return 0;
}

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

int main()
{
    string s1, s2, s3;
    cin >> s1;
    cin >> s2;
    cin >> s3;

    if (s1.at(s1.length()-1) == s2.at(0) && s2.at(s2.length()-1) == s3.at(0) )
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


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

int main(){
	string s,t;

	cin>>s>>t;

	rep(i,s.size()){
		if(s[i]!=t[i]){
			goto ERROR;
		};
	}

	if(s.size()+1==t.size()){
		cout<<"Yes"<<endl;
		return 0;
	}

	ERROR:
	cout<<"No"<<endl;
	return 0;

}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int64 N, T, t[202020];

int main() {
    cin >> N >> T;
    for (int j = 0; j < N; ++j) {
        cin >> t[j];
    }

    int64 acc = 0;
    int64 end = 0;
    for (int j = 0; j < N; ++j) {
        int nend = t[j] + T;
        acc += min(T, nend - end);
        end = nend;
    }
    cout << acc << endl;
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    
    string s;
    cin>>s;
    ll ans=0,ans1=0,countr=0,countw=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            countr++;
        }
        else
        {
            countw++;
        }
    }
 
    for(ll i=0;i<n;i++)
    {
        if(i<countr && s[i]!='R')
        {
            ans++;
        }
        else if(i>=countr && s[i]!='W')
        {
            ans1++;
        }
    }
  
    cout<<(ans1+ans)/2<<endl;
}


Measured memory_bytes: 3724
a,b,c=map(int,input().split())
if a==5:
 if (b==5 and c==7) or(b==7 and c==5):
  print("YES")
 else:
  print("NO")
elif a==7:
 if b==5 and c==5:
  print("YES")
 else:print("NO")
else:
 print("NO")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
using vint = std::vector<int>;
using vvint = std::vector<std::vector<int>>;
using namespace std;
ll mod = 1e9 + 7;


int main() {


	int N; cin >> N;
	int ans = 0;

	rep(i, N) {
		ll a; cin >> a;
		while (a % 2 == 0) {
			a /= 2;
			ans++;
		}
	}

	cout << ans;



	return 0;
}

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

int n, m, k[1123];
int now_card[212], tmp_card[212], cou = 0;

int main(void) {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) { scanf("%d", &k[i]); }

	for (int i = 0; i < 2 * n; ++i) { tmp_card[i] = now_card[i] = i + 1; }
	for (int i = 0; i < m; ++i) {
		if (k[i] == 0) {
			for (int j = 0; j < n * 2; j += 2) {
				tmp_card[j] = now_card[cou];
				tmp_card[j + 1] = now_card[n + cou];
				++cou;
			}
		}
		else {
			for (int j = 0; j < 2 * n; ++j) {
				if (2 * n - k[i] >= j + 1) { tmp_card[j] = now_card[k[i] + j]; }
				else { tmp_card[j] = now_card[j - (2 * n - k[i])]; }
			}
		}
		for (int i = 0; i < 2 * n; ++i) { now_card[i] = tmp_card[i]; }
		cou = 0;
	}

	for (int i = 0; i < 2 * n; ++i) { printf("%d\n", now_card[i]); }
	return 0;
}

Measured memory_bytes: 2756
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, double>pid;
int main()
{
	vector<pid>r;
	for (int i = 1; i <= 999; i++)
	{
		ll s = i / 100 + i / 10 % 10 + i % 10;
		ll now = i;
		for (int j = 0; j <= 15; j++)
		{
			r.push_back(make_pair(now, double(now)/double(s)));
			now = now * 10 + 9;
			s += 9;
		}
	}
	sort(r.begin(), r.end());
	vector<ll>v;
	double now = 1000000000000000000000000.0;
	for (int i = r.size() - 1; i >= 0; i--)
	{
		if (now >= r[i].second && (i == r.size() - 1 || r[i].first < r[i + 1].first))v.push_back(r[i].first), now = r[i].second;
	}
	int k;
	scanf("%d", &k);
	for (int i = 0; i < k; i++)printf("%lld\n", v[v.size() - 1 - i]);
}

Measured memory_bytes: 640
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)

Measured memory_bytes: 16152
program ABC170C
    implicit none
    integer(8)::X,N,ans,i,j,flg,diff
    integer(8),allocatable::P(:)
    read*,X,N
    if(N/=0)then
        allocate(P(N))
        read*,P
        call heapsort(N,P)
        ans=0
        diff=10000
        do i=0,110
            flg=0
            do j=1,N
                if(P(j)==i)then
                    flg=1
                    exit
                end if
            end do
            if(flg==0)then
                if(abs(i-X)<diff)then
                    diff=abs(i-X)
                    ans=i
                end if
            end if
        end do
    else
        ans=X
    end if

    print'(i0)',ans
end program ABC170C
subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
end subroutine heapsort

Measured memory_bytes: 2852
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d,s=1;
int main()
{
	cin>>a>>b;
	while(a)
	{
		a--;
		if(s<=b) s+=s;
		else s+=b;
	}
	cout<<s<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T = double>
using point = complex<T>; // 2D point only

using ll = long long;
using ull = unsigned long long;
using ldob = long double;

template <typename T = int>
using ii = pair<T,T>;
template <typename T = int>
using iii = pair<T,ii<T>>;
template <typename T = int>
using ii_i = pair<ii<T>,T>;
template <typename T = int>
using vi = vector<T>;
template <typename T = int>
using vvi = vector<vi<T>>;
template <typename T = int>
using vii = vector<ii<T>>;
template <typename T = int>
using viii = vector<iii<T>>;
template <typename T = int>
using lim = numeric_limits<T>;

#define re real()
#define im imag()
#define fi first
#define se second
#define all(v) v.begin(), v.end()

// OST
template <typename T>
using ordered_set = __gnu_pbds::tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// from: https://codeforces.com/blog/entry/62393
// struct custom_hash {
// 	static uint64_t splitmix64(uint64_t x) {
// 		// http://xorshift.di.unimi.it/splitmix64.c
// 		x += 0x9e3779b97f4a7c15;
// 		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
// 		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
// 		return x ^ (x >> 31);
// 	}

// 	size_t operator()(uint64_t x) const {
// 		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
// 		return splitmix64(x + FIXED_RANDOM);
// 	}
// };

const int INF = ~(1<<31);
const ll LINF = (1LL << 60);
const long double EPS = 1e-9;
const long double PI = acos(-1);

const int N = 200005;
const int NN = 101;
const int MOD = 998244353;
const int IMAX = 1e9+7;
const ll LMAX = 1e15+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};
const int dx8[8] = {-1,-1,-1,0,0,1,1,1};
const int dy8[8] = {-1,0,1,-1,1,-1,0,1};

ll n, m, k, f[N], F[N];

ll modpow(ll a, ll b, ll m) {
	if (b == 0)
		return 1LL;
	ll c = modpow(a,b/2LL,m);
	(c *= c) %= m;
	return b&1LL ? (a*c)%m : c;
}

void pregen() {
	f[0] = F[0] = 1;
	for (int i = 1; i < N; ++i) {
		(f[i] = 1LL*i*f[i-1]) %= MOD;
		F[i] = modpow(f[i],MOD-2,MOD);
	}
}

ll nCk(ll a, ll b) {
	return f[a]*F[b]%MOD*F[a-b]%MOD;
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0); // cout.tie(0);
	// cout.precision(2); cout << fixed;

	pregen();
	cin >> n >> m >> k;
	ll ans = 0;
	for (int i = 0; i <= k; ++i) {
		(ans += m*nCk(n-1,i)%MOD*modpow(m-1,n-1-i,MOD)%MOD) %= MOD;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6732
import itertools
n = int(input())
l = []
for i in range(n):
    d = int(input())
    for dd in range(d):
        x, y = map(int, input().split())
        l.append([i, x-1, y])

ans = 0
for p in itertools.product([0, 1], repeat=n):
    for ll in l:
        if p[ll[0]] == 1 and p[ll[1]] != ll[2]:
            break
    else:
        ans = max(ans, sum(p))
print(ans)

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

int main(){
    int N, sum=0;
    cin >> N;
    int d[N];
    for(int i=0; i<N; i++) cin >> d[i];
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            sum += d[i]*d[j];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	As := ReadInts(N)
	Fs := ReadInts(N)

	sort.Ints(As)
	sort.Sort(sort.Reverse(sort.IntSlice(Fs)))
	scores := make([]int, N)
	for i := 0; i < N; i++ {
		scores[i] = As[i] * Fs[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(scores)))

	ok := scores[0]
	ng := -1
	for ok-ng > 1 {
		mid := (ok + ng) / 2

		isOK := true
		k := K
		for i := 0; isOK && i < N; i++ {
			if As[i]*Fs[i] > mid {
				k -= As[i] - mid/Fs[i]
			}
			if k < 0 {
				isOK = false
			}
		}

		if isOK {
			ok = mid
		} else {
			ng = mid
		}

	}
	fmt.Println(ok)
}

func ReadInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = ReadInt()
	}
	return ret
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	v, e := strconv.Atoi(Read())
	if e != nil {
		panic(e.Error())
	}
	return v
}


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

int main(){
    
    int i,x,y;
    
    for ( i = 1; i < 3000; i++){
        
        cin >> x >> y;
        
        if ( x ==  0 && y == 0 ) break;
        
        if ( x < y ){ 
        
            
            cout << x << " " << y << endl;
            
        }
        
        if ( x > y ){
            
            
            cout << y << " " << x << endl;
            
        }
        
        if ( x == y){
            
            
            cout << x << " " << y << endl;
            
        }
        
    }
    
    return 0;
}


Measured memory_bytes: 3016
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <char,int> oc; 
    int  r, c ; 
    cin >> r >> c ; 
    for (int i=1;i<=r;i++) {
        string s; cin >> s ; 
        for (int j=0;j<c;j++){
            oc[s[j]]++;
        }
    } 
    vi a(26); 
    for (auto &it: oc){ 
        a[it.ff-'a']=it.ss; 
    } 
    int  four = 0, two = 0, one = 0 ; 
    if (r&1) two = (c/2); 
    if (c&1) two += (r/2); 
    if (r&1 and c&1) one=1; 
    for (int i=1;i<=c/2;i++){
        four += r/2;
    }
    // cout << four << " " << two << " " << one << endl; 
    while (four > 0){
        bool ok=true;
        for (int i=0;i<26 and four>0;i++){
            if (a[i]>=4) {
                a[i]-=4,four--;
                ok=false;
            }
        }
        if (ok) break;
    }
    while (two > 0){
        bool ok=true;
        for (int i=0;i<26 and two>0;i++){
            if (a[i]>=2) {
                a[i] -= 2,two--;
                ok=false;
            }
        }
        if (ok) break;
    }
    while (one > 0){
        bool ok=true;
        for (int i=0;i<26 and one>0;i++){
            if (a[i]>=1) {
                a[i] -= 1,one--;
                ok=false;
            }
        }
        if (ok) break;
    }
    if (four ==0 and two == 0 and one == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


Measured memory_bytes: 3624