akhauriyash/Code-Regression huggingface dataset:
#include <list>
#include <string>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  std::list<int> lst;
  //??\???
  int count;
  cin >> count;
  string cmd;
  int num;
  for (int i = 0; i < count; i++) {
    cin >> cmd;
    if(cmd == "insert"){
      cin >> num;
      lst.push_front(num);
    }else if (cmd == "delete"){
      cin >> num;
      for(auto itr = lst.begin(); itr != lst.end(); ++itr){
        if (*itr == num){
          lst.erase(itr);
          break;
        }
      }
    }else if (cmd == "deleteFirst"){
      lst.pop_front();
    }else if (cmd == "deleteLast"){
      lst.pop_back();
    }
  }
  //??????
  bool isfirst = true;
  for(auto itr = lst.begin(); itr != lst.end(); ++itr){
    if(isfirst){
      isfirst = false;
    }else{
      cout << ' ';
    }
    cout << *itr;
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 34396
#include <cstdio>
using namespace std;

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

	int half;
	if(n%2 ==0){
		half = n/2;
	}else{
		half = n/2+1;
	}
	double rate = (double)half/n;
	printf("%.10lf",rate);
	return 0;
}

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

using i64 = int64_t;
//
// O(N)で二項係数(mod)を求める
//
// ref: http://drken1215.hatenablog.com/entry/2018/06/08/210000
struct Comb {
    std::vector<i64> fact;     // a!
    std::vector<i64> factinv;  // (a!)^-1
    std::vector<i64> inv;
    const i64 mod;
    Comb(int maximum, i64 modulo) : mod(modulo) {
        fact.assign(maximum, 0);
        factinv.assign(maximum, 0);
        inv.assign(maximum, 0);
        // テーブルを作る前処理
        fact[0] = factinv[0] = 1;
        fact[1] = factinv[1] = 1;
        inv[1] = 1;
        for (i64 i = 2; i < maximum; ++i) {
            fact[i] = fact[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            factinv[i] = factinv[i - 1] * inv[i] % mod;
        }
    }
    i64 comb(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fact[n] * (factinv[k] * factinv[n - k] % mod) % mod;
    }
};

using namespace std;

int main() {
    i64 x, y;
    cin >> x >> y;
    i64 s, t;
    bool flag = false;
    for (i64 a = 0; a < x + 1; ++a) {
        if (a % 2 == 0 && (x - a) * 2 + a / 2 == y) {
            s = a / 2;
            t = x - a;
            flag = true;
        }
    }
    if (!flag) {
        cout << 0 << endl;
        return 0;
    }
    i64 n = s + t;
    i64 k = s;
    Comb c(1'000'100, 1'000'000'007);
    cout << c.comb(n, k) << endl;

    return 0;
}

Measured memory_bytes: 23680
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] arrA = sc.next().toCharArray();
		char[] arrB = sc.next().toCharArray();
		char[] arrC = sc.next().toCharArray();
		int count = 0;
		for (int i = 0; i < n; i++) {
		    if(arrA[i] == arrB[i]) {
		        if (arrB[i] != arrC[i]) {
		            count++;
		        }
		    } else if (arrA[i] == arrC[i] || arrB[i] == arrC[i]) {
		        count++;
		    } else {
		        count += 2;
		    }
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
N=int(input())
A=list(map(int,input().strip().split()))

#降った雨の総量
rain=sum(A)
#山Nに降った雨の量
r_N=rain
for  n in range(1,N):
    if n%2==1:
        r_N-=2*A[n-1]

ans=[]
tmp=r_N
for n in range(N):
    tmp=A[n-1]*2-tmp
    ans.append(tmp)

print(" ".join(list(map(str,ans))))

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

int solve(long long int n){
int ans = 0;
while(n){
ans++;
n >>= 1;
}
return ans;
}

int main(void){
int n,m; cin >> n >> m;
for(int i = 0; i < n; i++){
if(i != 0) cout <<" ";
if(i <= n / 2) cout <<0;
else cout <<m;
}
cout <<endl;
return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back

using namespace std;

//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*const lli mod=1000000007;

lli gcd(lli a,lli b)
{
    if(a==0)
        return b;
    return (b%a,a);
}

lli binpow(lli x,lli y,lli m)
{
    if (y==0)
        return 1;
    lli p=binpow(x,y/2,m)%m;
    p=(p*p)%m;
    if(y%2)
        return (x*p)%m;
    else
        return p;
}

lli modi(lli a,lli m)
{
    return binpow(a,m-2,m);
}*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        lli d,s,t;
        cin>>d>>t>>s;
        if(d<=t*s)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 3648
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    }
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt), * )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(s:chars, t:chars,);
    let mut ans = 0;
    for i in 0..3 {
        if s[i] == t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	dd=[0]*n
	for x in range(1,n):
		if x*x > n:
			break
		for y in range(1, n):
			if x*x + x*y + y*y >n:
				break
			for z in range(1, n):
				if x*x + y*y + z*z + x*y + y*z + z*x > n:
					break
				dd[x*x + y*y + z*z + x*y + y*z + z*x -1] += 1
		
	for v in dd:
		print(v)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 68444
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* UnionFind */

struct UnionFind{
  vector<int> data, tree_size;
  UnionFind(int s):data(s,-1),tree_size(s,1) {}
  
  int root(int x){
    if(data[x]==-1) return x;
    return data[x]=root(data[x]);
  }
  
  bool set(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y) return false;
    data[y]=x;
    tree_size[x] += tree_size[y];
    tree_size[y] = 0;
    return true;
  }
  
  bool check(int x,int y){
    x=root(x);
    y=root(y);
    return x==y;
  }
  
  int size(int x){
    return tree_size[root(x)];
  }
  
};

int main(){
  int n, m;
  int a[SIZE], b[SIZE];
  vector<pair<pair<int,int> ,int> > vec;
  vector<int> g[SIZE];
  pair<ll,ll> dp[SIZE];
  
  scanf("%d%d", &n, &m);
  
  for(int i=0;i<n;i++){
    scanf("%d%d", a+i, b+i);
    vec.push_back({{a[i]-b[i], -b[i]}, i});
  }

  sort(vec.begin(), vec.end());

  for(int i=0;i<m;i++){
    int u, v;
    scanf("%d%d", &u,&v);
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  UnionFind uf(n);

  bool used[SIZE] = {};
  
  for(int i=0;i<n;i++){
    int p = vec[i].second;
    vector<int> uni;
    
    for(int j=0;j<g[p].size();j++){
      if (used[g[p][j]])
        uni.push_back(uf.root(g[p][j]));
    }
    used[p] = true;

    sort(uni.begin(), uni.end());
    uni.erase(unique(uni.begin(), uni.end()), uni.end());
    
    ll sum = 0;

    for(int j=0;j<uni.size();j++){
      sum += dp[uni[j]].second;
    }
    sum += b[p];

    pair<ll,ll> calc = {LLINF, LLINF};
    
    for(int j=0;j<uni.size();j++){
      int q = uni[j];
      ll nowcost = dp[q].first;

      nowcost += b[p];
      nowcost = max(nowcost, (ll)a[p]);
      nowcost += sum - (dp[q].second + b[p]);

      calc = min(calc, make_pair(nowcost, sum));
    }

    calc = min(calc, make_pair(max(a[p], b[p]) + (sum - b[p]), sum));
    
    for(int j=0;j<uni.size();j++){
      uf.set(p, uni[j]);
      //assert(p == uf.root(uni[j]));
    }

    dp[uf.root(p)] = calc;
    //assert(p == uf.root(p));

    //debug(uf.root(p));
    //debug(calc.first);
  }
  
  printf("%lld\n", dp[uf.root(0)].first);
  
  return 0;
}



Measured memory_bytes: 10740
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second

#define pb push_back
#define es erase
#define in insert

#define pii pair<ll, ll>
#define ll long long
#define lb long double

#define ios                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define m_p(i, j) make_pair(i, j)
#define mem(a, x) memset(a, x, sizeof(a))
#define fcout(i) cout << setprecision(i) << fixed
#define endl "\n"

int a[123456];
int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < k; i++)
        ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

void rot(ll &vx, ll &vy){
    ll tx = -vy;
    ll ty = vx;
    vx = tx;
    vy = ty;
}

int main(){
    
    ll x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    ll vx = x2 - x1;
    ll vy = y2 - y1;
    rot(vx, vy);
    ll x3 = x2 + vx, y3 = y2 + vy;
    rot(vx, vy);
    ll x4 = x3 + vx, y4 = y3 + vy;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp
flag = 0
arr = []

t.length.times do |i|
  arr.push(t[i])
end

t.length.times do |i|
  join_str = arr.join
  if s == join_str
    flag = 1
  end
  last = arr.pop
  arr.unshift(last)
end

if flag == 0
  puts 'No'
else
  puts 'Yes'
end

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

/* include file*/
#include <functional>
#include <vector>
using namespace std;

template <class Monoid>
struct Segment
{
    using Func = function<Monoid(Monoid,Monoid )>;

    vector<Monoid> node;
    Monoid ide;
    int n = 1;

    Func bin_f;
    Func update_f;

    Segment(const vector<Monoid> &init, Monoid ide_, Func f_,Func u_f) : bin_f(f_),ide(ide_),update_f(u_f)
    {
        int sz = init.size();
        while (n < sz)
            n *= 2;
        node.assign(n * 2 - 1, ide);
        for (int i = 0; i < sz; i++)
            node[i + n - 1] = init[i];
        for (int i = n - 2; i >= 0; i--)
            node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }

    void update(int i, Monoid x)
    {
        i += n - 1;
        node[i] = update_f(node[i],x);
        while (i)
        {
            i = (i - 1) / 2;
            node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }

    Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
            r = n;
        if (a <= l && r <= b)
            return node[k];
        if (r <= a || b <= l)
            return ide;

        Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
        Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
        return bin_f(lm, rm);
    }
};

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1

i64 n;
vector<i64> x;

int main(){
    cin >> n;
    x.assign(n + 1,0);
    for(int i = 1;i <= n;i++) cin >> x[i];

    Segment<i64> seg(vector<i64>(n + 1,0),0,[](i64 a , i64 b){
        return max(a,b);
    },[](i64 node,i64 a){
        return a;
    });

    for(int i = 1;i <= n;i++){
        seg.update(x[i],x[i] + seg.get_inter(1,x[i]));
    }

    cout << (n + 1) * n / 2 - seg.get_inter(0,n + 1) << endl;;

}


Measured memory_bytes: 6540
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

#define PI 3.14159265358979323846264338327950L

// 絶対値を求める
double Abs(const double a) {
    return a > 0 ? a : -a;
}
// 二つの値の最小値を求める関数
Int Min(const Int a, const Int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}
// 二つの値の最小値を求める関数
double Min(const double a, const double b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    Int a, b, h, m;
    cin >> a >> b >> h >> m;
    Int minutes = 60 * h + m;
    double a_angle = 0.5 * (double)minutes;
    double b_angle = (double)((6 * minutes) % 360);
    double angle = Abs(a_angle - b_angle);
    angle = (double)Min(angle, 360.0f - angle) * PI / 180.0f;
    double c = sqrt((double)(a * a + b * b)  - (double)(2 * a * b) * cosl(angle));
    cout << fixed << setprecision(20) << c << endl;
    return 0;
}



Measured memory_bytes: 4088
#include<bits/stdc++.h>
using namespace std;
#define y1 y114514
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define M 1000000007
#define all(a) a.begin(), a.end()
typedef long long ll;

int n;
int a[50], b[50];
vector<ll> f[51][51];

void dfs(int s, int cur, int t, ll co){
	if(t > 0){
		if(cur) dfs(s, cur % t, cur % t, co | 1LL << t);
		dfs(s, cur, t - 1, co);
	}else f[s][cur].pb(co);
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", a + i);
	for(int i = 0; i < n; ++i) scanf("%d", b + i);
	f[0][0].pb(0);
	for(int i = 1; i <= 50; ++i)
		dfs(i, i, i, 0);
	
	for(int i = 0; i < n; ++i)
		if(f[a[i]][b[i]].size() == 0){
			puts("-1");
			return 0;
		}
	
	ll now = 0;
	for(int k = 49; k >= 1; --k){
		bool flag = 1;
		for(int i = 0; i < n && flag; ++i){
			bool tmp = 0;
			for(ll v : f[a[i]][b[i]])
				if(~v >> k & 1) { tmp = 1; break; }
			flag &= tmp;
		}
		if(!flag) now |= 1LL << k;
		else{
			for(int i = 0; i < n; ++i){
				vector<ll> g;
				for(ll v : f[a[i]][b[i]])
					if(~v >> k & 1) g.pb(v);
				f[a[i]][b[i]] = g;
			}
		}
	}
	printf("%lld\n", now);
	
	
#ifndef ONLINE_JUDGE
	system("pause");
#endif
	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
long long n;
long long k;
int main() {
	cin >> n;
	if(n%2==1) cout << 0LL << endl;
	else {
		k=1LL;
		long long ans = 0;
		k=1LL;
		for(int i=1; i<=100; i++) {
			k *= 5;
			if(k>5e17) break;
			ans += n/(k*2);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
function main(n){var e=n[0],o="keyence",s=0,i=0,t=0;if(e!==o){for(var r=0;r<e.length;r++){if(e[r]!==o[s]||s===o.length){i=r;break}s++}e=e.split("").reverse().join(""),o=o.split("").reverse().join(""),s=0;for(r=0;r<e.length;r++){if(e[r]!==o[s]||s===o.length){t=r;break}s++}i+t>=o.length?console.log("YES"):console.log("NO")}else console.log("YES")}var input="";process.stdin.resume(),process.stdin.setEncoding("utf8"),process.stdin.on("data",function(n){input+=n}),process.stdin.on("end",function(){main(input=input.split("\n"))});

Measured memory_bytes: 7628
#include <stack>
#include <stdio.h>
using namespace std;

stack<int> stk;
bool ans[4444];

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

	if (a <= b)
	{
		printf("Impossible\n");
		return 0;
	}

	int n = a + b;

	for (int i = 0; i < n; i++)
	{
		if (stk.empty()) stk.push(i);
		else
		{
			printf("? %d %d\n", stk.top(), i);
			fflush(stdout);
			char res;
			scanf(" %c", &res);

			if (res == 'N')
			{
				stk.pop();
			}
			else
			{
				stk.push(i);
			}
		}
	}

	int h = stk.top();
	ans[h] = true;

	for (int i = 0; i < n; i++)
	{
		if (i == h) continue;
		printf("? %d %d\n", h, i);
		fflush(stdout);

		char ch;
		scanf(" %c", &ch);
		ans[i] = (ch == 'Y');
	}

	printf("! ");
	for (int i = 0; i < n; i++) printf("%d", ans[i]);
	printf("\n");
}


Measured memory_bytes: 724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    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 { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=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 { mint res(*this); return res/=a; }
};

int main(){
  int n,k;
  cin >> n >> k;
  vector<pair<ll,int>> a(n); 
  mint sum = 1;
  bool flag = false;
  rep(i,n){
    cin >> a[i].F;
    sum *= a[i].F;
    if(a[i].F>=0){
      a[i].S = 0;
      flag = true;
    } else {
      a[i].F *= -1;
      a[i].S = 1;
    }
  }
  if(k==n){
    cout << sum.x << ln; return 0;
  }
  if(k%2 && !flag){
    sort(a.begin(),a.end());
    mint ans = 1;
    rep(i,k){
      ans *= (-1)*a[i].F;
    }
    cout << ans.x << ln; return 0;
  }

  sort(a.rbegin(),a.rend());
  mint ans = 1;
  int cnt = 0;
  rep(i,k){
    ans *= a[i].F;
    cnt += a[i].S;
  }

  if(cnt%2==0 || ans.x==0){
    cout << ans.x << ln; return 0;
  }
  ll A=inf,B=inf,C=inf,D=inf;
  REP(i,k,n){ if(a[i].S==0){ C = a[i].F; break; } }
  REP(i,k,n){ if(a[i].S==1){ D = a[i].F; break; } }
  for(int i=k-1; i>=0; i--){ if(a[i].S==0){ B = a[i].F; break; } }
  for(int i=k-1; i>=0; i--){ if(a[i].S==1){ A = a[i].F; break; } }
  if(C==inf){
    ans *= D;
    ans /= B;
  }else if((B==inf || D== inf)){
    ans *= C;
    ans /= A;
  } else {
    if(C*B >= A*D ){
      ans *= C;
      ans /= A;
    }else{
      ans *= D;
      ans /= B;
    }
  }
  cout << ans.x << ln;
  return 0;
}

Measured memory_bytes: 6364
A,B,C,D = list(map(int,input().split()))
def gcd(a,b):
    r = divmod(a,b)[1]
    if r == 0:
        return int(b)
    else:
        return gcd(b,r)
l = (C*D) // gcd(C,D) 
print((B - A + 1) - ( (B//C - (A-1)//C ) + (B//D - (A-1)//D ) - (B//l - (A-1)//l ) ))

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const double PI = acos(-1);
const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

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

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

    int R = 0, G = 0, B = 0;
    REP(i, N) {
        if (S[i] == 'R') ++R;
        if (S[i] == 'G') ++G;
        if (S[i] == 'B') ++B;
    }

    ll ans = (ll)R*(ll)G*(ll)B;
    REP (i, N) {
        FOR (j, i, N) {
            int k = 2 * j - i;
            if (k < N) {
                if (S[i] == S[j]) continue;
                if (S[j] == S[k]) continue;
                if (S[i] == S[k]) continue;
                ans--;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define MP make_pair
#define ull unsigned long long int
#define F first
#define S second
#define put insert
#define pb push_back
#define rsortV(arr) sort(arr.begin(),arr.end(),greater<int>())
#define sortV(arr) sort(arr.begin(),arr.end())
#define sortA(arr,n) sort(arr,arr+n)
#define rsortA(arr,n) sort(arr,arr+n,greater<int>())
#define arrInput(arr,n) for(int i=0;i<n;i++) cin>>arr[i];
#define rev(arr) reverse(arr.begin(), arr.end())
#define all(x) (x).begin(), (x).end()
ll MOD = 1e9+7;
int main() {
    fastio
    // int t;
    // cin>>t;
    // while(t--) {
    int n,x,y;
    cin>>n;
    string s = "";
    while(n--) {
        cin>>x>>y;
        s += to_string(x==y);
    }
    cout<<(s.find("111")!=s.npos?"Yes":"No");
    // }
    return 0;
}


Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

int main() {
        int a, b;
        cin >> a >> b;
        cout << max(a - b, 0) << endl;
        return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace std;
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define pii pair<int, int>
#define debug(a) cout << #a": " << a << endl;
#define eularMod(a, b) a < b ? a : a % b + b
#define X first
#define Y second
#define lc rt << 1
#define rc rt << 1 | 1
inline int lowbit(int x){ return x & -x; }
typedef long long LL;
typedef unsigned long long ULL;
const int N = 3000 + 10;
const int M = 1e7 + 10;
const int mod = (int) 1000000007;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double eps = 1e-6;

LL v[N];

int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
//    freopen("out.txt","w",stdout);
#endif
    LL x, y;

    scanf("%lld%lld", &x, &y);

    int res = 0;
    int sum = 0;

    LL nowx = x;
    LL nowy = y;

    for (; nowx <= nowy; nowx <<= 1)
        sum++;

    res = sum;
    sum = 0;
    nowx = x;
    nowy = y;

    for (; nowx <= nowy; nowy >>= 1)
        sum++;

    printf("%d\n", max(res, sum));

    return 0;
}


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

namespace C
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var n = line[0];
			var k = line[1];

			var an = Console.ReadLine().Split().Select(int.Parse).ToArray();
			var dict = new Dictionary<int, int>(n);
			foreach (var a in an)
			{
				if (dict.ContainsKey(a)) { dict[a]++; }
				else { dict.Add(a, 1); }
			}

			var numList = new List<int>(n);
			foreach (var d in dict) { numList.Add(d.Value); }

			numList.Sort();

			var result = 0;
			for (var i = 0; i < numList.Count - k; i++) { result += numList[i]; }

			Console.WriteLine(result);
		}
	}
}

Measured memory_bytes: 36816
#include <stdio.h>
#include <algorithm>
using ll = long long;
using ull = unsigned long long;
int main() {
	int n, m;
	ll x[100000], y[100000];
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%lld", x + i);
	for (int i = 0; i < m; i++)
		scanf("%lld", y + i);
	ll sxline = 0, syline = 0;
	for (int i = 0; i < n; i++) {
		sxline -= x[i] * (n - 1 - i);
		sxline += x[i] * i;
	}
	for (int i = 0; i < m; i++) {
		syline -= y[i] * (m - 1 - i);
		syline += y[i] * i;
	}
	sxline %= 1000000007ll;
	syline %= 1000000007ll;
	ll area = (sxline * syline) % 1000000007ll;
	printf("%lld\n", area);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    cin >> s;
    int cnt = 0, ans = s.size();
    rep(i, s.size()){
        if(s[i] == 'S')cnt++;
        else{
            if(cnt > 0){
                cnt--;
                ans-=2;
            }
        }
    }
    cout << ans << endl;
}   

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  ll D;
  cin>>D;
  ll ans=0;
  for(ll i=0;i<N;i++) {
ll X,Y;
    cin>>X>>Y;
    if(D*D>=X*X+Y*Y) {
ans++;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
n=int(input())
List = []
for _ in range(n):
  x = int(input())
  List.append(x)
List = sorted(List)
Total = sum(List)

if Total % 10 ==0:
  for item in List:
    if item %10 !=0:
      Total -= item
      break
if Total % 10 == 0:
  Total = 0
print(Total)

Measured memory_bytes: 3060
N = int(input())
S = input()

res = 10**9

cta = 0
ctb = 0
a = [0]*N
b = [0]*N

for i in range(N):
    if S[i] == ".":
        cta += 1
    else:
        ctb += 1
    a[i] = cta
    b[i] = ctb
for i in range(N):
    res = min(res, b[i] + (a[-1] - a[i]))
res = min(res, a[-1], b[-1])
print(res)

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

typedef long long int ll;
typedef pair<int,int> pii;
const int mod = 1e9+7;

const double pi = acos(-1);

int main(){
    double r;
    cin>>r;
    double res = 2*r*pi;
    printf("%.20f\n",res);

	return 0;
}


Measured memory_bytes: 3788
#include "bits/stdc++.h"
using namespace std;

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

	if (n % 2 != 0) {
		cout << 0 << endl;
		return 0;
	}

	int64_t ten = 10;
	int64_t ans = 0;
	while (n >= ten) {
		ans += n / ten;
		ten *= 5;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=[0]*n

for i in range(n,0,-1):
    m=n//i
    total=0
    for j in range(1,m+1):
        if j==1:
            total+=a[i-1]
        else:
            total+=b[i*j-1]
    b[i-1]=total%2
ans=sum(b)
print(ans)
if ans != 0:
    l=[]
    for i in range(n):
        if b[i]==1:
            l.append(i+1)
    print(*l)

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

int main(void){
	double n, a, b, c;
	int i;
	
	scanf("%lf", &n);
	
	while (n--){
		scanf("%lf %lf %lf", &a, &b, &c);
		
		a = pow(a, 2.0);
		b = pow(b, 2.0);
		c = pow(c, 2.0);
		
		if (a > b && a > c){
			if (b+c == a) printf("YES\n");
			else printf("NO\n");
		}
		else if (b > a && b > c){
			if (a+c == b) printf("YES\n");
			else printf("NO\n");
		}
		else if (c > a && c > b){
			if (a+b == c) printf("YES\n");
			else printf("NO\n");
		}
		else printf("NO\n");
	}
	
	return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

int n, m, k;
void solve(){
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];

    vector<ll> p1(n), p2(m);
    p1[0] = a[0], p2[0] = b[0];
    for(int i = 1; i < n; i++) p1[i] = a[i] + p1[i-1];
    for(int i = 1; i < m; i++) p2[i] = b[i] + p2[i-1];

    int ap = -1, bp = -1;
    while(ap+1 < n && p1[ap+1] <= k) ap++;

    int ans = 0;
    while(ap >= -1){
        while(bp+1 < m && p2[bp+1] + (ap > -1 ? p1[ap] : 0) <= k) bp++;
        // cout << ap << " " << bp << '\n';
        ans = max(ans, ap+1 + bp+1);

        ap--;
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 7928
#include<bits/stdc++.h>
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 repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vi t(n+1), x(n+1), y(n+1);
  REP(i,n+1) cin >> t[i] >> x[i] >> y[i];
  t[0] = x[0] = y[0] = 0;
  bool ans = true;
  REP(i,n+1){
    int d = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
    int time = t[i] - t[i-1];
    if(time < d || d % 2 != time % 2) ans = false;
  }
  YesorNo(ans);

}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int N;
	cin >> N;

	map<string, int> mps;
	rep(i, N){
		string s;
		cin >> s;

		auto it = mps.find(s);
		if(it == mps.end()) mps[s] = 0;
		mps[s]++;
	}

	int M;
	cin >> M;

	map<string, int> mpt;
	rep(i, M){
		string t;
		cin >> t;

		auto it = mpt.find(t);
		if(it == mpt.end()) mpt[t] = 0;
		mpt[t]++;
	}

	int ans = 0;
	for(auto it = mps.begin(); it != mps.end(); it++){
		string key = it->first;
		int vals = it->second;

		auto itt = mpt.find(key);
		if(itt == mpt.end()){
			ans = max(ans, vals);
		}else{
			int valt = itt->second;
			ans = max(ans, vals - valt);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

    int n, q;
    cin >> n >> q;
    queue<pair<string, int>> que;
    rep(i, n) {
        string s; int t;
        cin >> s >> t;
        que.emplace(s, t);
    }
    int time = 0;
    while (!que.empty()) {
        auto p = que.front();
        que.pop();
        time += min(p.se, q);
        p.se -= q;
        if (p.se <= 0) {
            cout << p.fi << " " << time << endl;
        } else {
            que.push(p);
        }
    }
}



Measured memory_bytes: 6276
//ITP1_3_B

using System;
using System.Collections.Generic;
/*using System.Linq;
using System.Text;
using System.Threading.Tasks;*/


class Program
{
    static void Main(string[] args)
     {
        int i, j = 1;
        while( ( i = int.Parse(Console.ReadLine()) ) != 0 )
        {
            Console.WriteLine("Case " + j++ + ": " + i);
        }
     }
    
}

Measured memory_bytes: 9268
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back

int main(void){
    int n, l;
    string s, ans = "";
    vector<string> vec;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> l;
    REP(i, n) {
        cin >> s;
        vec.PB(s);
    }

    sort(ALL(vec));
    REP(i, n) {
        ans += vec[i];
    }

    cout << ans << "\n";
    return 0;
}

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

using ll = long long;

const string YES = "Yes", NO = "No";

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

ll A, B, C, D;

string solve() {
    if (A < B || B > D) return NO;
    if (B <= C) return YES;
    ll v = gcd(D, B);
    return B - v + (A % v) <= C ? YES : NO;
}

int main(void) {
    int T; cin >> T;
    for (int i = 0; i < T; ++i) {
        cin >> A >> B >> C >> D;
        cout << solve() << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long LL;
using namespace std;
int main() {
	int N;
	cin >> N;
	map<int, int> cnt;
	REP(i, N) {
		int a;
		cin >> a;
		cnt[a]++;
	}
	vector<int> v;
	for (auto e : cnt) {
		if (e.second >= 4) {
			v.push_back(e.first);
			v.push_back(e.first);
		}
		else if (e.second >= 2) {
			v.push_back(e.first);
		}
	}
	if (v.size() >= 2) {
		cout << (LL)v[v.size() - 1]*v[v.size() - 2] << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 4992
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10**9 + 7
nums = [[0, 0] for _ in range(n)]

for i in range(n):
    for j in range(i):
        if a[i] > a[j]:
            nums[i][0] += 1
    for j in range(i, n):
        if a[i] > a[j]:
            nums[i][1] += 1

kbig = ((k+1) * k) // 2
ksmall = (k * (k-1)) // 2

result = 0
for i in range(n):
    result = (result + nums[i][0] * ksmall + nums[i][1] * kbig) % mod

print(result)

Measured memory_bytes: 42476
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
//#define endl "\n"
using namespace std;
using namespace __gnu_pbds;

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


int main() 
{ 
    fastio
    int n, m;
    cin>>n>>m;

    vector<ld> vec(n);
    for(auto& it : vec) cin>>it;

    ld sum = accumulate(all(vec), 0);

    ld need = sum/(4*m);
    int cur = 0;
    for(int i = 0; i<n; ++i)
    {
        if(vec[i]>=need)
        {
            cur++;
        }
    }

    if(cur>=m)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] a) {
		Scanner s=new Scanner(System.in);
		int x,y,z,i;
		while(s.hasNext()){
			x=s.nextInt();
			y=s.nextInt();
		z=x+y;
		for(i=1;10<=z;i++){
			z=z/10;
		}
		System.out.println(i);
		}
	}
}

Measured memory_bytes: 11000
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

int main(){
  int n,z,w; cin >> n >> z >> w;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  if(n>=2) cout << max( abs(a[n-1]-w),abs(a[n-2]-a[n-1]) ) << endl;
  else cout << abs(a[n-1]-w) << endl;
}

Measured memory_bytes: 3608
n,m=(int(x) for x in input().split())

k = {}
l = {}
ok = 0
ng = 0
for i in range(m):
    p,s = input().split()
    if p in k and k[p] == 0 :
        continue
    elif p in k and s == 'AC':
        ok += 1
        k[p] = 0
    elif  s == 'WA':
        ng += 1 
        if p in k:
            k[p] += 1
        else:
            k[p] = 1
    elif  s == 'AC':
        ok+=1
        k[p] = 0

nng = 0
for v,vv in k.items():
    nng += vv

print(ok,ng- nng)



Measured memory_bytes: 17116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int n;
vector<int> a;

vector<int> run() {
    multiset<int> s;
    vector<int> ret;
    int sum = 0;
    rep (i,n) s.insert(a[i]), sum += a[i];
    ret.push_back(sum);
    for (int i = n; i < 2*n; i++) {
        s.insert(a[i]);
        sum += a[i] - *s.begin();
        s.erase(s.begin());
        ret.push_back(sum);
    }
    return ret;
}

int32_t main() {
    cin >> n;
    a.resize(3*n); cin >> a;

    vector<int> b = run();
    reverse(all(a));
    for (auto &x : a) x = -x;
    vector<int> c = run();
    reverse(all(c));
    
    int m = -1e15;
    rep (i,n+1) chmax(m, b[i]+c[i]);
    cout << m << endl;
}


Measured memory_bytes: 9592
// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn sieve_of_Eratosthenes(n: usize) -> Vec<bool> {
    let mut res = vec![true; n];
    if n > 0 {
        res[0] = false;
        if n > 1 {
            res[1] = false;
        }
    }
    let mut i = 2;
    while i*i < n {
        if res[i] {
            let mut j = i*2;
            while j < n {
                res[j] = false;
                j += i;
            }
        }
        i += 1;
    }
    res
}

fn main() {
    let q = readl!(usize);
    let pv = sieve_of_Eratosthenes(100000+1);
    let mut imos = [0;100000+1];
    for i in 2..imos.len()-1 {
        if pv[i] && pv[(i+1)/2] {
            imos[i+1] = 1;
        }
        imos[i+1] += imos[i];
    }
    // debug!(&imos[0..50]);
    for _ in 0..q {
        let (l, r) = readl!(usize, usize);
        println!("{}", imos[r+1]-imos[l]);
    }
}



Measured memory_bytes: 5116
#include <bits/stdc++.h>
using namespace std;
long long n,y;
void solve()
{
    long long x1,x2,x3,tag=0;
    for (x1=min(n,y/10000);x1>=0;x1--)
    {
        for (x2=min(n-x1,(y-x1*10000)/5000);x2>=0;x2--)
        {
            for (x3=min(n-x1-x2,(y-x1*10000-x2*5000)/1000);x3>=0;x3--)
                if (x1+x2+x3==n)
                {
                    if (x1*10000+x2*5000+x3*1000==y)
                    {
                        tag=1;
                        break;
                    }
                }
            if (tag) break;
        }
        if (tag) break;
    }
    if (tag) cout<<x1<<" "<<x2<<" "<<x3;
    else cout<<"-1 -1 -1";
    cout<<endl;
}
int main()
{
    while(cin>>n>>y)
        solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct bian{
	int x,to,next;
}edge[400001];
int head[100005],tot=0;
void add(int x,int y,int z){
	edge[++tot].next=head[x];edge[tot].to=y;edge[tot].x=z;head[x]=tot;
}
int n,m,vis[100005],dis[100005];
void dfs(int x,int fa){
	vis[x]=1;
	for(int i=head[x];i;i=edge[i].next)if(fa!=edge[i].to){
		if(dis[edge[i].to]!=0x7f7f7f7f){
			if(edge[i].x!=dis[edge[i].to]-dis[x]){
				puts("No");exit(0);
			}
		}else{
			dis[edge[i].to]=dis[x]+edge[i].x;
			dfs(edge[i].to,x);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,x,y,z;i<=m;++i){
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z);
		add(y,x,-z);
	}
	memset(dis,0x7f,sizeof dis);
	for(int i=1;i<=n;++i)if(!vis[i])dfs(i,i);
	puts("Yes");
	return 0;
}

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

using llong = long long;
using namespace std;

int main(){
    llong n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
}

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

typedef long long ll;
ll INF = 1000000000000000;
using Graph = vector<vector<pair<ll,ll>>>;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
vector.erase(vector.begin() + index);
}


struct UnionFind{
    vector<int> par;
    vector<int> rank;

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

    int root(int x){
       while(x != par[x]){
        x =  par[x] = par[par[x]];
       }
       return x;
    }

    void unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry)return;
        if(rank[x] > rank[y]){
          par[y] = rx;
        }
        if(rank[x] < rank[y]){
          par[rx] = ry;
        }else{
          par[ry] = rx;
          if(rank[x] == rank[y]){
            rank[rx]++;
          }
        }
    }

    bool same(int x,int y){
      return root(x) == root(y);
    }
};

int main(){
 int sx,sy,gx,gy;
 cin >> sx >> sy >> gx >> gy;
 int dx = gx - sx,dy = gy - sy;
 for(int i = 0;i < dx;i++){
   cout << 'R';
 }
 for(int i = 0;i < dy;i++){
   cout << 'U';
 }
 for(int i = 0;i < dx;i++){
   cout << 'L';
 }
 for(int i = 0;i < dy;i++){
   cout << 'D';
 }
 cout << 'D';
 for(int i = 0;i < dx+1;i++){
   cout << 'R';
 }
 for(int i = 0;i < dy + 1;i++){
   cout << 'U';
 }
 cout << 'L';
 cout << 'U';
 for(int i = 0;i < dx+1;i++){
   cout << 'L';
 }
 for(int i = 0;i < dy+1;i++){
   cout << 'D';
 }
 cout << 'R' << endl;
}


Measured memory_bytes: 256