akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,store,i;
    cin>>a>>b;
    int c=0;
    if(a<b)
    {
            for(i=a;i<=b;i++)
    {
        int s=a-i;
        int t=b-i;
        if(s<0) s=s*-1;
        if(t<0) t=t*-1;
        if(s==t)
        {
            c=1;
            store=i;
            break;
        }

    }
    }
    else {
        for(i=b;i<=a;i++)
    {
        int s=a-i;
        int t=b-i;
        if(s<0) s=s*-1;
        if(t<0) t=t*-1;
        if(s==t)
        {
            c=1;
            store=i;
            break;
        }

    }
    }
    if(c==1) cout<<store<<endl;
    else cout<<"IMPOSSIBLE\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MAX_N 100100
struct BIT{
	ll bit[MAX_N+1];
	void add(int i,ll x){
		i++;
		while(i<=MAX_N){
			bit[i]+=x;
			i+=i&-i;
		}
		return;
	}
	ll sum(int i){
		i++;
		ll res=0;
		while(i>0){
			res+=bit[i];
			i-=i&-i;
		}
		return res;
	}
	ll sum(int l,int r){// [l,r]
		if(l==0)return sum(r);
		else return sum(r)-sum(l-1);
	}
}bit;
string s;
string A[2],B[2];
string S,T;
int cnt[30];
set<int> se[30];
int c[30];
int N;
ll ans = 0ll;
ll solve(){
	ll res = 0ll;
	for(int i=0;i<S.size();i++){
		bit.add(i,1);
		se[S[i]-'a'].insert(i);
	}
	for(int i=0;i<T.size();i++){
		set<int>::iterator it = se[T[i]-'a'].begin();
		bit.add(*it,-1);
		res += bit.sum(*it);
		se[T[i]-'a'].erase(it);
	}
	return res;
}
inline int asc(int x){
	return s[x]-'a';
}
int main(){
	cin >> s;
	N = s.size();
	for(int i=0;i<s.size();i++){
		cnt[s[i]-'a']++;
	}
	int odd = 0;
	int center = -1;
	for(int i=0;i<26;i++){
		if(cnt[i]%2==1){
			odd++;
			center = i;
		}
	}
	if(odd>1){
		cout << -1 << endl;
		return 0;
	}
	if(odd==1){
		for(int i=0;i<N;i++){
			c[asc(i)]++;
			if(asc(i)==center&&c[center]==(cnt[center]+1)/2){
				center = i;
				break;
			}
		}
		if(center>N/2){
			center = N-1-center;
			reverse(all(s));
		}
	}
	int p = 0,q = 0;
	memset(c,0,sizeof(c));
	for(int i=0;i<2;i++){
		A[i].resize(N);
		B[i].resize(N);
	}
	int flag = 0;
	for(int i=0;i<(N+1)/2;i++){
		c[asc(i)]++;
		if(i==center){
			ans += q;
			flag = 1;
			continue;
		}
		if(c[asc(i)]<=cnt[asc(i)]/2){
			ans+=q+flag;
			A[0][p++]=s[i];
		}else{
			A[1][q++]=s[i];
		}
	}
	A[0].resize(p);
	A[1].resize(q);
	p=0;q=0;
	memset(c,0,sizeof(c));
	for(int i=0;i<N/2;i++){
		c[asc(N-1-i)]++;
		if(c[asc(N-1-i)]<=cnt[asc(N-1-i)]/2){
			ans+=q;
			B[0][p++]=s[N-1-i];
		}else{
			B[1][q++]=s[N-1-i];
		}
	}
	B[0].resize(p);
	B[1].resize(q);
	reverse(all(B[1]));
	reverse(all(A[1]));
	ans += ((ll)A[1].size()+(ll)flag)*(ll)B[1].size();
	S = A[0]+B[1];
	T = B[0]+A[1];
	//cout << A[0] << ' ' << A[1] << endl;
	//cout << B[0] << ' ' << B[1] << endl;
	//cout << S << endl;
	//cout << T << endl;
	ans += solve();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6916
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
#define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

const int mod = 1e9 + 7;
const int N = 4e5 + 5;

int a[N];
 
inline void solve() {
   int n;
   cin >> n;
   n -= 1;
   if (n) {
    n = n * (n+1) / 2;
   }
   cout << n;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t; while(t--)
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
	int a, b, c, tempa, tempb, temp, tempc, ans = 0;
	cin >> a >> b >> c;
	if (a >= b && a >= c) {
		temp = b + c;
		if (a == temp) {
			ans = 0;
		}
		else {
			ans = 1;
		}
	}
	else if ((a >= b && a <= c)|| (a <= b && b <= c)) {
		temp = a + b;
		if (c == temp) {
			ans = 0;
		}
		else {
			ans = 1;
		}
	}
	else if (a<=b && b>=c) {
		temp = a + c;
		if (b == temp) {
			ans = 0;
		}
		else {
			ans = 1;
		}
	}
		if (ans == 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	return 0;
}
	
	

Measured memory_bytes: 384
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main()
{
    int n,k;cin>>n>>k;
    int r,s,p;cin>>r>>s>>p;
    string t;cin>>t;

    LL result = 0;

    REP(i,n){
        if(i-k>=0 && t[i-k] == t[i]){
            t[i] = 'x';
        }
        if(t[i] == 'r'){
            result += p;
        }
        if(t[i] == 's'){
            result += r;
        }
        if(t[i] == 'p'){
            result += s;
        }
    }
    cout<<result<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 892
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const A = list[1].trim().split(' ');
const q = Number(list[2]);
const mi = list[3].trim().split(' ');

const dp = {};
const memo = (i, sum) => {
  dp[sum] = true;
  if (i === n) {
    return true;
  }
  memo(i + 1, sum);
  memo(i + 1, sum + Number(A[i]));
}
memo(0, 0);

for (let i = 0; i < q; i++) {
  console.log(dp[mi[i]] ? 'yes' : 'no');
}



Measured memory_bytes: 17100
#include<bits/stdc++.h>
#define int int64_t
using namespace std;

const int M = 1e9+7;
vector<int> adj[100005] , vis(100005);
int dp[100005][2];

void dfs(int root) {
	vis[root] = 1;
	int b = 1 , w = 1;
	for(auto u:adj[root]) {
		if(!vis[u]) {
			dfs(u);
			b = (b * dp[u][0])%M;
			w = (w * (dp[u][0] + dp[u][1])%M)%M;
		}
	}
	dp[root][0] = w;
	dp[root][1] = b;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

	int n , u , v;
	cin >> n;
	for(int i = 1; i < n; i++) {
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1);
	cout << (dp[1][1] + dp[1][0])%M << "\n";
	
    return 0;
}


Measured memory_bytes: 14976
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
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 run() {
    input! {
        n: usize,
        m: usize,
        p: i64,
        e: [(usize1, usize1, i64); m],
    }
    let mut g = vec![vec![]; n];
    for (a, b, c) in e {
        let c = p - c;
        g[a].push((b, c));
    }
    let inf = 100000000000000000;
    let mut dp = vec![inf; n];
    dp[0] = 0;
    for _ in 0..n {
        for v in 0..n {
            if dp[v] == inf {
                continue;
            }
            for &(u, c) in g[v].iter() {
                let d = dp[v] + c;
                if d < dp[u] {
                    dp[u] = d;
                }
            }
        }
    }
    let mut q = std::collections::VecDeque::new();
    let mut neg = vec![false; n];
    for v in 0..n {
        if dp[v] == inf {
            continue;
        }
        for &(u, c) in g[v].iter() {
            let d = dp[v] + c;
            if d < dp[u] {
                neg[v] = true;
                q.push_back(v);
                break;
            }
        }
    }
    while let Some(v) = q.pop_front() {
        for &(u, _) in g[v].iter() {
            if neg[u] {
                continue;
            }
            neg[u] = true;
            q.push_back(u);
        }
    }
    if neg[n - 1] {
        println!("-1");
    } else {
        println!("{}", std::cmp::max(0, -dp[n - 1]));
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
n=int(input())
s=list(map(int,input().split()))
s=sorted(s,reverse=True)

#Alice,Bob
a=[]
b=[]

for i in range(n):
    if i%2==0:
        a.append(s[i])
    else:
        b.append(s[i])
        
print(sum(a)-sum(b))
        

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>      // std::setprecision
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
using namespace std;
using namespace boost::math;

int main() {
	int N;

	cin >> N;
    vector<double> p(N);
  
    for (auto &i : p)
      cin >> i;
  
    boost::multi_array<double, 2> dp(boost::extents[N][N+1]);
  
    dp[0][0] = 1.0 - p[0];
    dp[0][1] = p[0];
    REP (i, N-1) {
      dp[i+1][0] = 0.0;
      REP(j,i+2) {
        dp[i+1][j] += dp[i][j] * (1.0 - p[i+1]);
        dp[i+1][j+1] = dp[i][j] * p[i+1];
      }
    }

    double r = 0.0;
    for (auto i : boost::irange(N / 2 + 1, N + 1))
      r += dp[N-1][i];
  
	cout << setprecision(10) << r << endl;

	return 0;
}


Measured memory_bytes: 70528
#include <iostream>
#include <string>

using namespace std;

int main() {
	long long N;
	long long sum = 0;
	long long blue = 0;
	long long red = 0;
	long long answer = 0;
	cin >> N >> blue >> red;
	sum = blue + red;
	answer = N / sum * blue;
	if (N % sum > blue) answer += blue;
	else answer += N % sum;
	cout << answer;
	return 0;
}

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

int main()
{

	char s[11],t[11],u[11];
	int a,b,i;
  
(void) scanf("%s %s",s,t);
(void) scanf("%d %d",&a,&b);
(void) scanf("%s",u);
  
 // printf("%s %s %s",s,t,u);
  
if (strcmp(s,u)==0)
{
	printf("%d %d",a-1,b);
	return 0;
}
	printf("%d %d",a,b-1);

return 0;

}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using ll = long long int;
using ld = long double;
using str = string;

int main(){
  //kyopro;
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  vector<int> a{};
  if(S.at(0) == '0') a.push_back(0);
  char kensaku = S.at(0);
  int renzoku{};
  for(auto&& i : S){
    if(kensaku == i){
      renzoku++;
    }
    else{
      kensaku = i;
      a.push_back(renzoku);
      renzoku = 1;
    }
  }
  a.push_back(renzoku);
  if(S.at(N-1) == '0') a.push_back(0);
  int sumax{};
  
  if(a.size()/2 < K) K = a.size()/2;
  vector<int> goukei{};
  goukei.push_back(0);
  int sum{};
  for(auto&& i :a){
    sum += i;
    goukei.push_back(sum);
  }
  int maximum{};
  for(int i{}; i * 2 + K * 2 + 1 < goukei.size() + 1; i++){
    int l = i * 2;
    int r = i * 2 + K * 2 + 1;
    maximum = max(maximum, goukei.at(r) - goukei.at(l));
  }
  cout << maximum << rt;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  P("ABC"+to_string(n));
  return 0;
}


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

int main(int argc, char const *argv[])
{
    int w, h, x, y;
    cin >> w >> h >> x >> y;

    double area = double(w) * double(h) / 2.0;
    bool flag = x + x == w && y + y == h;
    cout << area << " " << flag << endl;
    return 0;
}


Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n = inp[0]
t = []
n.times do|i|
  d = inp
  next if(d[0] == 0 and d[1] == 0)
  ka = d[0]/d[1].to_f
  tails = Math.atan(ka)*180/Math::PI
  tails +=180 if(d[1]<0)
  t.push([tails.to_f,d[0],d[1]])
end
x = y = 0
ans = 0

t.sort_by!{|u|u[0]}

t.size.times do |i|
  x=y=0
  tail =i
  tails = t[i][0]
  t.size.times do |j|
    ind = (i+j)%t.size
    a = t[ind]
    nt = a[0]
    x += a[1]
    y += a[2]
    while(180 < (nt-tails)%360 and tail < t.size)
      ans = [ans,(x**2+y**2)**0.5].max
      x -= t[tail][1]
      y -= t[tail][2]
      tail += 1
      tails = t[tail][0] if(t[tail])
      tails +=360 if(t[tail] and i+j >= t.size)
    end
    ans = [ans,(x**2+y**2)**0.5].max
  end
end
tails = 180

p ans

=begin
def search(t,d, ind)
  ans = 0
  return
end
n = inp[0]
@memo = na2(n,n,false)
n.times do |i|
  @memo[i][0] = 0
end
@mem = na2(n+1,n+1)
a = []
n.times do |i|
  a[i] = inp
end
n.times do |i|
  (n-1).times do|j|
    p 7
    @mem[i+1][a[i][j]] = j
  end
end
@mem.each do|a|
  p a
end
=end

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

typedef long long ll;

string s;
int n;

bool is_valid() {
    if (s[n-1]=='1') {
        return false;
    }
    if (s[0]=='0')
        return false;
    for (int i=0; i<n/2; ++i) {
        if (s[i]!=s[n-2-i]) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> s;
    n=s.size();
    if (!is_valid()) {
        cout << -1;
        return 0;
    }
    int cur_root=1;
    int cur_size=n-1;
    int cur_v=2;
    for (int i=(n-1)/2; i>=0; --i) {
        if (s[i]=='1') {
            int sub_size=i+1;
            for (int k=0; k<cur_size-sub_size; ++k) {
                cout << cur_v << ' ' << cur_root << endl;
                ++cur_v;
            }
            cout << cur_v << ' ' << cur_root << endl;
            cur_size=i;
            cur_root=cur_v;
            ++cur_v;
        }
    }
    return 0;
}

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

int main(void){
  int n, k, a[10000];
  cin >> n >> k;
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  sort(a, a+n, greater<int>());
  int sum=0;
  for(int i=0;i<k;++i){
    sum += a[i];
  }
  cout << sum << endl;
}

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

int main() {
	int S, h, m, s;
	cin >> S;
	s = S % 60;
	m = (S / 60) % 60;
	h = S / 3600;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
typedef pair<int, int> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

void Z_algorithm(const string &s, vector<int> &a) {
    int sz = s.size();
    a.resize(sz);
    a[0] = sz;
    int i = 1, j = 0;
    while (i < sz) {
        while (i + j < sz && s[j] == s[i + j])++j;
        a[i] = j;
        if (j == 0) {
            ++i;
            continue;
        }
        int k = 1;
        while (i + k < sz && k + a[k] < j)a[i + k] = a[k], ++k;
        i += k;
        j -= k;
    }
}

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

    int l1 = s.size();
    int l2 = t.size();

    t += s;
    vector<int> r;
    Z_algorithm(t, r);
    rep(i, l1) {
        if (r[l2 + i] >= l2) {
            cout << i << endl;
        }
    }

}


Measured memory_bytes: 8924
<?php
 
fscanf(STDIN, "%d %d", $a, $b);
$line = fgets(STDIN);
$arr = array_map('intval', explode(' ', $line));
$sum = 0; 
$num = count($arr);
 
for ($i = 0; $i < $b; $i++) {
  $min = min($arr);
  $min_key = array_search($min, $arr);
  $sum += $min;
  unset($arr[$min_key]);
  $arr = array_values($arr);
  
}
 
echo $sum;

Measured memory_bytes: 16260
#include<bits/stdc++.h>
#define MST(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i = a ; i < b ; ++i)
#define per(i,a,b) for(int i = a ; i > b ; --i)
#define ALL(v) v.begin(),v.end()
#define ft first
#define sd second
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
template<class T> void show(T *x,int len,int s = 0) {for(int i = s ; i < s+len-1 ; ++i) cerr << x[i] << ' ';cerr << x[s+len-1] << endl;}
void debug() {cerr << endl;}
template <typename T, typename... Args> void debug(T x,Args... args) {cerr << x << ' ';debug(args...);}

namespace fast_IO{
	const int maxbuff = 1<<17;
	char ibuff[maxbuff],obuff[maxbuff];
	inline char Getchar(){
	    static char *p1=ibuff,*p2=ibuff;
		if(p1 == p2) {
	    	p1 = ibuff;
	    	p2 = ibuff+fread(ibuff,1,maxbuff,stdin);
	    	if(p1 == p2) return -1;
	    }
	    return *p1++;
	}

	int optr = 0;
	inline void Putchar(char c) {
		if(optr == maxbuff) {fwrite(obuff,1,optr,stdout);optr = 0;}
		obuff[optr++] = c;
	}

	inline void Flush() {
		fwrite(obuff,1,optr,stdout);
	}

	template<class T>
		inline int read(T &x) {
			x = 0;
			char c = Getchar();
			if(c == EOF) return -1;
			for( ; (c < '0' || c > '9') && c != EOF ; c = Getchar());
			if(c == EOF) return -1;
			for( ; c >= '0' && c <= '9' ; c = Getchar()) x = x*10+c-'0';
			return 0;
		}

	template<class T>
		inline void write(const T &x,int tag = 0) {
			if(!x) {
				if(!tag) Putchar(x+'0');
				return ;
			}
			write(x/10,1);
			Putchar(x%10+'0');
		}

	template<class T>
		inline void writeln(const T &x) {
			write(x);Putchar('\n');
		}

	template<class T>
		inline void writesp(const T &x) {
			write(x);Putchar(' ');
		}
}
template<class T>
inline void cmin(T &A,const T &B) {A = (A<B?A:B);}
template<class T>
inline void cmax(T &A,const T &B) {A = (A>B?A:B);}
int sqr(int x) {return x*x;}
int main() {
	#ifdef LOCAL
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	int c1[4],c2[4];
	for(int i = 1 ; i <= 3 ; ++i) cin >> c1[i];
	for(int i = 1 ; i <= 3 ; ++i) cin >> c2[i];
	int dist = (c1[1]-c2[1])*(c1[1]-c2[1])+(c1[2]-c2[2])*(c1[2]-c2[2]);
	if(dist > sqr(c1[3]+c2[3])) puts("4");
	else if(dist == sqr(c1[3]+c2[3])) puts("3");
	else if(dist == sqr(c1[3]-c2[3])) puts("1");
	else if(dist < sqr(c1[3]+c2[3]) && dist > sqr(c1[3]-c2[3])) puts("2");
	else puts("0");
	return 0;
}



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

int pay(int x, int y)
{
  return x + y/2;
}

int main()
{
  int x;
  int y;
  std::cin >>x;
  std::cin >>y;

  std::cout <<pay(x,y) <<std::endl;
  return 0;
}




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

int main(void){
    int L, R, d;
    int count=0;
    cin >> L >> R >> d;
    for(int i=L; i<=R; i++){
        if(i%d==0){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }




int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n, l;
    cin >> n >> l;
    vs s(n);
    for (ll i = 0; i < n; ++i) {
        cin >> s[i];
    }
    sort(all(s));
    string ans;
    for (ll i = 0; i < n; ++i) {
        ans += s[i];
    }

    cout << ans << endl;

    print_time();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define lli long long
#define REP(i,a,b) for (int i = a; i < b; i++)
#define test int t; cin>>t; while(t--)
using namespace std;

int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   // test
    {
        int n,k,t;
        cin>>n>>k>>t;
        if(n%k)
        cout<<((n/k)+1)*t;
        else
        cout<<((n/k))*t;
    }
    return 0;
}

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

using namespace std;
#define REP(i,n) for(int i = 0; i <(int)(n); i++)

typedef long long ll;

const int NMAX = 51;
const int VMAX = 51*51+1;
//const int VMAX = 100;
ll dp[NMAX][NMAX][VMAX];

int main() {
  dp[0][0][0] = 1;
  int N, A; cin>>N>>A;
  vector<int> data(N);
  REP(i,N) cin>>data[i];
  REP(i,N) {
    int x = data[i];
    int from = i, to = i+1;

    for(int a = 0; a < NMAX; a++)
      for(int b = 0; b < VMAX; b++)
	dp[to][a][b] = 0LL;


    for(int m = 0; m < N; m++) {
      for(int v = 0; v < VMAX; v++) {
	dp[to][m][v] += dp[from][m][v];
	if(m+1 < NMAX && v+x < VMAX) {
	  dp[to][m+1][v+x] += dp[from][m][v];
#ifdef DEBUG
	  cout << i<<to<<","<<m+1 << "," << v+x << "," << dp[to][m+1][v+x] << endl;
#endif
	}
      }
    }
  }
  ll ans = 0;
  for(int i = 1; i <= N; i++) {
#ifdef DEBUG
    cout << i << " " << dp[N][i][A*i] << endl;
#endif
    ans += dp[N][i][A*i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 52096
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

void solve(long long W, long long H, std::vector<long long> p, std::vector<long long> q){
    vector<pair<int,int>> v;

    for(int i = 0; i < W; ++i) {
        v.push_back(make_pair(p[i], 0LL));
    }
    for(int j = 0; j < H; ++j) {
        v.push_back(make_pair(q[j], 1LL));
    }
    sort(ALL(v));
    int res = 0;
    int a = W + 1, b = H + 1;
    for(int i = 0; i < v.size(); ++i) {
        if (v[i].second == 0) {
            res += v[i].first * b;
            a--;
        } else {
            res += v[i].first * a;
            b--;
        }
    }
    cout << res << endl;
}

signed main(){
    long long W;
    scanf("%lld",&W);
    long long H;
    scanf("%lld",&H);
    std::vector<long long> p(W-1-0+1);
    for(int i = 0 ; i < W-1-0+1 ; i++){
        scanf("%lld",&p[i]);
    }
    std::vector<long long> q(H-1-0+1);
    for(int i = 0 ; i < H-1-0+1 ; i++){
        scanf("%lld",&q[i]);
    }
    solve(W, H, std::move(p), std::move(q));
    return 0;
}

Measured memory_bytes: 8048
#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() {
    ll n, m;
    cin >> n >> m;
    cout << (n-1)*n/2 + (m-1)*m/2 << endl;
}      

Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define testcases() int t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
  	ll r;
	cin>>r;
  	cout<<3*r*r;
	return 0;
}

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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n,q=1,p=1;
        cin>>n;
        ll a[n];
        loop(i,0,n-1)
        {
            cin>>a[i];
            if(a[i]==0)
            {
                q=0;
                cout<<0;
                break;
            }
        }
        if(q==0) continue;
        loop(i,0,n-1)
        {
            if(a[i]>1000000000000000000/p)
            {
                q=0;
                break;
            }
            else p*=a[i];
        }
        if(q or p==0) cout<<p;
        else cout<<-1;

    }
    return 0;
}


Measured memory_bytes: 4392
use std::cmp::{min,max};
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let (a,b,c,x,y) = {
        let t = read_vec::<i64>();
        (t[0],t[1],t[2],t[3],t[4])
    };
    let c = c * 2;
    let mut ans =  1e9 as i64 ;
    for i in 0..100001{
        ans  = min((max(0,x-i)*a + max(0,y-i)*b + i*c),ans);
    }
    println!("{}",ans );
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for(int i = 1;i <= n;i++) {
    for(int j = 1;j <= n;j++) {
      for(int k = 1;k <= n;k++) {
        sum += gcd(i, gcd(j,k) );
      }
    }
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3624
while true
  n = gets.chomp.to_i
  break if n == 0
  trans = {}
  n.times do |i|
    x, y = gets.chomp.split(" ")
    trans[x] = y
  end
  m = gets.chomp.to_i
  result = ""
  m.times do |i|
    x = gets.chomp
    result << (trans[x] || x)
  end
  puts result
end

Measured memory_bytes: 6212
/**
*	created: 13.09.2020 21:06:03
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> inline bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

signed main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << max({a*c, b*c, b*d, a*d}) << endl;
    return 0;
}

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

int main() {
  int a,b,c; cin >> a >> b >> c;
  if((a == 5 && b == 5 && c == 7)||(a == 5 && b == 7 && c == 5)||(a == 7 && b == 5 && c == 5)){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}



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

const int M = 200005;

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    
    vector<long int> cnt(M);
    rep(i,n) {
        cnt[a[i]]++;
    }
    
    vector<long int> con(M);
    long int sum = 0;
    rep(i,M) {
        con[i] = cnt[i] * (cnt[i] - 1) / 2;
        sum += con[i];
    }
    
    rep(i,n) {
        cout<< sum - (cnt[a[i]] - 1) << endl;
    }
    
    return 0;
}




Measured memory_bytes: 7204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int i = 0; i < n; i++ ){ cout << x[i] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second
     
using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;

vi v, s;

map<int,int> ma;

int ans[2];

int main(){

  n = in();
  REP( i , n ){
    v.pb( in() );
  }
  
  s = v;
  SORT( s );
  
  REP( i , n ){
    ma[ s[i] ] = i;
  }

  REP( i , n ){
    if( ma[ v[i] ] % 2 != i % 2 ){
      ans[i%2]++;
    }
  }

  cout << max( ans[0] , ans[1] ) << endl;
  
  return 0;
}


Measured memory_bytes: 5752
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){

	int a, b, x;
	cin >> a >> b >> x;
	if(a+b<x){
		cout << "NO" << endl;
		return 0;
	} else if(a>x){
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		if (R < 1200) {
			System.out.println("ABC");
		} else if (R < 2800) {
			System.out.println("ARC");
		} else {
			System.out.println("AGC");
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
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; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    int fi  = 0;
    REP(i,N){
        cin >> A[i];
        if(i%2 == 0){
            fi += A[i];
        }
        else fi -= A[i];
    }

    vector<int> ans(N);
    ans[0] = fi;
    cout << ans[0] << ' ';
    REPP(i,1,N){
        ans[i] = 2*A[i-1]-ans[i-1];
        cout << ans[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
using namespace std;
int gcd(int a, int b) {
    if (a % b == 0) {
        return (b);
    }
    else {
        return (gcd(b, a % b));
    }
}
int main() {
    long long a, b, c, d;
    long long ans = 0;
    cin >> a >> b >> c >> d;
    long long lcm = c * d / gcd(c, d);
    ans += b / c - (a - 1) / c;
    ans += b / d - (a - 1) / d;
    ans -= b / lcm - (a - 1) / lcm;
    cout << b - a - ans + 1 << endl;
}

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

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = min(k, a);
    k -= min(k, a);
    if(k > 0ll){
        k -= b;
    }
    if(k > 0ll){
        ans -= min(k, c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}

namespace {
  const int mo = 1e9 + 7;
  inline int mul(int x, int y) {
    return 1LL * x * y % mo;
  }
  inline void U(int &x, int y) {
    if ((x += y) >= mo) x -= mo;
  }
}

const int N = 610;

int n, a[N], empty[N], ban[N], dp[N][N][N];

int main(void) {
  read(n);
  rep (i, 2 * n) {
    read(a[i]);
    if (a[i] != -1)
      empty[a[i]] = true;
  }
  int cnt = 0;
  for (int i = 1; i <= 2 * n; i += 2) {
    if (a[i] != -1 && a[i + 1] != -1)
      ban[a[i]] = ban[a[i + 1]] = true;
    if (a[i] == -1 && a[i + 1] == -1)
      ++cnt;
  }
  // cout << "cnt = " << cnt << "\n";
  dp[2 * n + 1][0][0] = 1;
  for (int i = 2 * n; i >= 1; i--) {
    if (ban[i]) {
      memcpy(dp[i], dp[i + 1], sizeof dp[i]);
      continue;
    }
    // cout << i << "\n";
    for (int x = 0; x <= 2 * n; x++)
      for (int y = 0; y <= 2 * n; y++) {
        if (!empty[i]) {
          U(dp[i][x][y], dp[i + 1][x + 1][y]);
          if (x)
            U(dp[i][x][y], dp[i + 1][x - 1][y]);
          U(dp[i][x][y], mul(y + 1, dp[i + 1][x][y + 1]));
        } else {
          U(dp[i][x][y], dp[i + 1][x + 1][y]);
          if (y) U(dp[i][x][y], dp[i + 1][x][y - 1]);
        }
      }
  }
  int ans = dp[1][0][0];
  // cout << ans << "\n";
  rep (i, cnt) ans = mul(ans, i);
  cout << ans << "\n";
}


Measured memory_bytes: 873344
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  ll N, M; cin >> N >> M;

  vector <ll> A(N), B(M);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < M; i++) cin >> B[i];
  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());

  ll ans = 1;
  for (int i = 0; i < N - 1; i++){
    if (A[i] == A[i + 1]) ans = 0;
  }
  for (int i = 0; i < M - 1; i++){
    if (B[i] == B[i + 1]) ans = 0;
  }
  
  ll I = 0, J = 0;
  for (ll now = N * M; now >= 1; now--){
    bool flagi = false, flagj = false;

    for (int i = I; i < N; i++){
      if(A[i] > now){
        I++;
      }else if (A[i] == now){
        I++; flagi = true;
      }else{
        break;
      }
    }
    
    for (int j = J; j < M; j++){
      if (B[j] > now){
        J++;
      }else if(B[j] == now){
        J++; flagj = true;
      }else break;
    }

    if (flagi == true && flagj == true){
      ans *= 1;
    }else if(flagi == true){
      ans *= J;
    }else if(flagj == true){
      ans *= I;
    }else{
      ans *= I * J - ((N * M) - now);
    }
    ans %= nmax;
  }
  
  cout << ans << endl;
  return 0;
}


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

//string型文字列をint型整数にして返す
int str_to_num(string s) {return atoi(s.c_str());}
//約数の総数を返す
int count_divisor(int n){int c[n/2] = {1}; int n_half = n/2; for(int i=2;i<n_half;i++){if(n%i==0){n /= i;c[i]+=1;i--;if(n>1) continue;else break;}  }int r = 1;for(int i=2;i<n_half;i++){r *= c[i];}return r;}
//各桁の数の和を返す
int dig_num(int n){return (n<10) ? n: dig_num(n/10) + n%10;}

int main(){
  int N; cin >> N;
  string r = "YES";
  
  int c = 0;
  REP(i,N){
    int p; cin >> p;
    c += !(p==i+1);
  }
  if(c>2){r = "NO";}
  
  cout << r << '\n';
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int t;
    int h;
    t=0;
    h=0;
    string T,H;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>T>>H;
        if(T>H){
            t+=3;
        }
        else if(T<H){
            h+=3;
        }
        else{
            t+=1;
            h+=1;
        }
    }
    cout<<t<<" "<<h<<endl;
}



Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	int n, l; cin >> n >> l;
	int best = 999999;
	int bestVal;
	int sum = 0;
	for(int i=l; i<l+n; i++){
		sum += i;
		if(abs(i) < best){
			best = abs(i);
			bestVal = i;
		}
	}
	cout << sum - bestVal << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.141592653589793238462643383279
using namespace std;
int main(){
  int N;
  int A[300000];
  cin>>N;
  FOR(i,0,3*N){
    cin>>A[i];
  }
  sort(A,A+3*N,greater<int>());
  long long sum=0;
  int k=1;
  FOR(i,0,N){
    sum+=A[k];
    k+=2;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 1408
r, g, b, n = list(map(int, input().split()))

a1, a2, a3 = sorted([r, g, b])
ans = 0
a3n = n // a3
a2n = n // a2
for i in range(a3n + 1):
    for j in range(a2n + 1):
        r = n - (a3 * i + a2 * j)
        if r < 0:
            break
        if r % a1 == 0:
            ans += 1

print(ans)


Measured memory_bytes: 3060
//problem_b.go

package main

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

const (
	constMod = int(1e9) + 7
)

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

// -----------------------------------------

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntSlice(n int) []int {
	ns := []int{}
	for i := 0; i < n; i++ {
		ns = append(ns, getInt())
	}
	return ns
}

func getIntDoubleSlice(m int, n int) [][]int {
	var nds [][]int
	for i := 0; i < m; i++ {
		ns := getIntSlice(n)
		nds = append(nds, ns)
	}
	return nds
}

func getFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getFloatSlice(n int) []float64 {
	fs := []float64{}
	for i := 0; i < n; i++ {
		fs = append(fs, getFloat())
	}
	return fs
}

func getFloatDoubleSlice(m int, n int) [][]float64 {
	var fds [][]float64
	for i := 0; i < m; i++ {
		fs := getFloatSlice(n)
		fds = append(fds, fs)
	}
	return fds
}

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

func getStringSlice(n int) []string {
	ss := []string{}
	for i := 0; i < n; i++ {
		ss = append(ss, getString())
	}
	return ss
}

func getStringDoubleSlice(m int, n int) [][]string {
	sds := [][]string{}
	for i := 0; i < m; i++ {
		ss := getStringSlice(n)
		sds = append(sds, ss)
	}
	return sds
}

// -----------------------------------------

// Num Fanction

func numAbs(x int) int {
	if x < 0 {
		return -x
	}

	return x
}

func numModPow(a int, n int, m int) int {
	result := 1

	for n > 0 {
		if n%2 == 1 {
			result = (result * a) % m
		}
		a = (a * a) % m
		n >>= 1
	}

	return result
}

func numGcd(a int, b int) int {
	if b == 0 {
		return a
	}

	return numGcd(b, a%b)
}

func numLcm(a int, b int) int {
	return a * b / numGcd(a, b)
}

func numModInv(a int, p int) int {
	if a == 1 {
		return 1
	}

	return p - numModInv(p%a, p)*(p/a)%p
}

func numModFrac(n int) []int {
	frac := []int{1}

	for i := 1; i <= n; i++ {
		frac = append(frac, i*frac[i-1]%constMod)
	}

	return frac
}

func numModConb(n int, r int) int {
	frac := numModFrac(n)

	return (frac[n] / ((frac[n-r] * frac[r]) % constMod)) % constMod
}

// -----------------------------------------

// sort
// sort.SliceStable(SLICENAME, func(i, j int) bool { return SLICENAME[i] < SLICENAME[j] })

// reverse sort
// sort.SliceStable(SLICENAME, func(i, j int) bool { return SLICENAME[i] > SLICENAME[j] })

// -----------------------------------------

func solve() {

	n := getInt()
	sum := 0

	for i := 1; i <= n; i++ {
		if i%3 != 0 && i%5 != 0 {
			sum += i
		}
	}

	fmt.Fprintln(wr, sum)

}

// -----------------------------------------

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}


Measured memory_bytes: 1764
n,k=map(int, input().split())
a=[0]+list(map(int, input().split()))

dp=[10**10]*(n+1)

dp[1]=0
for i in range(2,n+1):
    for j in range(1,k+1):
        if i-j>0:
            dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]))

print(dp[n])


Measured memory_bytes: 85592
K = int(input())

a = [0] * K
a[0] = 7 % K

for i in range(1, K):
    a[i] = (a[i-1] * 10 + 7) % K

ans = -1
for i in range(K):
    if a[i] == 0:
        ans = i + 1
        break

print(ans)


Measured memory_bytes: 48548