akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];


int main()
{
	long long N, cnt = 0, tmp, ans = 0;
	
	string S;
	long long K;
	cin >> S;
	cin >> K;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '1') {
			cnt++;
		}
		else {
			tmp = i;
			break;
		}
	}
	if (cnt >= K) cout << 1;
	else cout << S[tmp];

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

// multi-dimensional vector (require c++14)
template <typename T, typename U>
static inline vector<U> make_nd_vector(T &&n, U &&val) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
static inline decltype(auto) make_nd_vector(T &&n, Args &&... args) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<decltype(make_nd_vector(forward<Args>(args)...))>(
      forward<T>(n), make_nd_vector(forward<Args>(args)...));
}
//
// Print from Iterator
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
//
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> g[n];
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool good = true;
    for (auto j : g[i]) {
      if (h[i] <= h[j]) {
        good = false;
      }
    }
    if (good)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 8364
#include <cstdio>

using namespace std;

int main(){

  while(1){

  int n,a=0,b=0;

  scanf("%d",&n);

  if(n == 0) break;

  for(int i = 0;i < n;i++){
    int t1,t2;

    scanf("%d%d",&t1,&t2);

    if(t1 > t2){
      a += (t1+t2);
    }else if(t1 < t2){
      b += (t1+t2);
    }else{
      a += t1;
      b += t2;
    }
  }

  printf("%d %d\n",a,b);

  }

  return 0;

}


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

#define pb push_back
#define mp make_pair
#define f first
#define s second

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	map<pair<string,int>,int> mep;
	vector<pair<string,int> >v;
	
	for(int i = 0 ; i < n ; i ++){
		string s;
		int p;
		cin>>s;
		cin>>p;
		v.pb(mp(s,-p));
		mep[mp(s,-p)] = i + 1;
	}
	
	sort(v.begin(), v.end());
	
	for(int i = 0 ; i < n ; i ++)
		cout<<mep[v[i]]<<"\n";
	
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    string ans = "Yes";
    for(int i=0;i<s.size();i++) {
        if(s[i] == s[s.size()-1-i]) continue;
        else {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(ll i=0;i<(ll)n;++i)
#define Rev(i,n) for(ll i=(ll)n-1;i>=0;--i)
#define Rep(i,n) for(ll i=1;i<=(ll)n;++i)
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const ll N = 55;
map< ll , vi > G[N];
int U[N];
int V[N];
vi tree[N];
void dfs(ll s , ll p , vi path , ll source){
	// trace(source, s, path);
	G[source][s] = path;
	for(auto it : tree[s]){
		int v = (U[it]^V[it]^s);
		if(v == p) continue;
		vi z = path;

		z.pb(it);
		dfs(v , s , z , source);
	}
}
pii cc[N];
// inline ll mul(ll a , ll b){
// 	return a*1ll*b%md;
// }
signed main(){
	fio; cout<<fixed<<setprecision(25);	
	ll n ; 
	cin >> n;
	ll u , v;
	for(ll i = 1;i <= n-1 ; ++i){
		cin >> u >> v;
		U[i] = u;
		V[i] = v;
		tree[u].pb(i);
		tree[v].pb(i);
	}
	for(ll i = 1;i <= n ; ++i){
		vi v;
		v.clear();
		dfs(i , -1 , v, i);
	}
	ll m ;
	cin >> m;
	for(ll i = 0;i < m ; ++i){
		cin >> cc[i].F >> cc[i].S;
	}
	ll ans = (1ll<<(n-1));

	for(int i = 1;i < (1ll<<m) ; ++i){
		int no = __builtin_popcount(i);
		int edges[n-1];
		for(int i = 0;i < n-1 ; ++i)
			edges[i] = 0;
		for(int j = 0;j < m; ++j){
			if(i&(1<<j)){
				vi v = G[cc[j].F][cc[j].S];
				// trace(cc[j].F , cc[j].S , v);
				for(auto it : v)
					edges[it-1] = 1;
			}
		}
		ll cnt = 1;
		for(int i = 0;i < n-1 ; ++i){
			if(!edges[i]){
				cnt *= 2ll;
			}
		}
		if((no%2) == 0){
			ans += cnt;
		}
		else{
			ans -= cnt;
		}
	}	
	cout << ans << endl;






	return 0;
}


Measured memory_bytes: 896
package main

import "fmt"

var memo map[int]map[int]int

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a % b)
}
func main() {
	var n int
	fmt.Scan(&n)

	sum := 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= n; j++ {
			for k := 1; k <= n; k++ {
				sum += gcd(gcd(i, j), k)
			}
		}
	}

	fmt.Println(sum)
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;
int N;
int color[200000];
int black=0;
int white=0;
int mini;

signed main(void) {
    cin >> N;
    rep(i,N){
        char a;
        cin >> a;
        if(a=='.'){
            color[i]=0;
        }else{
            color[i]=1;
        }
    }

    rep(i,N){
        if(color[i] == 0){
            white++;
        }
    }

    mini = white;

    REP(p, 1, N){
        if(color[p-1]==1){
            black++;
        }else{
            white--;
        }
        if(black+white < mini){
            mini = black+white;
        }
    }

    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int n;
    cin >> n;
    int sum = 0;
    int max = 0;
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        if(p > max){
            max = p;
        }
        sum += p;
    }

    cout << sum - (max/2) << endl;

    return 0;
}


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

#define ll long long
const ll mx = 2e5+10;
int tc, n;

void solve(int kk)
{
    cin >> n;
    ll a, b;
    vector < pair<ll, ll> > Add, Sub;
    pair <ll, ll> p[n+1];
    for(int i=0; i<n; i++)
        cin >> a >> b,
        Add.push_back({a+b, i}), Sub.push_back({a-b, i}),
        p[i] = {a, b};
    
    sort(Add.begin(), Add.end());
    sort(Sub.begin(), Sub.end());

    ll mm = -1e18;
    ll a1 = p[Add[0].second].first;
    ll b1 = p[Add[0].second].second;
    ll a2 = p[Add[n-1].second].first;
    ll b2 = p[Add[n-1].second].second;
    
    mm = max(mm, abs(a1-a2)+abs(b1-b2));

    a1 = p[Sub[0].second].first;
    b1 = p[Sub[0].second].second;
    a2 = p[Sub[n-1].second].first;
    b2 = p[Sub[n-1].second].second;

    mm = max(mm, abs(a1-a2)+abs(b1-b2));

    cout << mm << "\n";
}

int main(){
 #ifndef ONLINE_JUDGE
freopen("D:\\Codings\\CPP\\input.in", "r", stdin);
freopen("D:\\Codings\\CPP\\output.in", "w", stdout);
#endif
	ios::sync_with_stdio(0), cin.tie(0);
	int t=1;
    //cin >> t;
    while(++tc<=t)
        solve(tc);
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===



int dp[100100];



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

	int N; cin >> N;
	Vi h(N);
	for (int i = N - 1; i >= 0; --i) {
		cin >> h[i];
	}

	for (int i = 0; i <= N ; ++i) {
		dp[i] = I_INF;
	}
	dp[1] = 0;
	dp[2] = abs(h[1] - h[0]);

	for (int i = 3; i <= N; ++i) {
		int cost1 = abs(h[i - 1] - h[i - 2]);
		int cost2 = abs(h[i - 1] - h[i - 3]);
		dp[i] = min(dp[i - 1] + cost1, dp[i - 2] + cost2);
	}

	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 1024
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


    

n,m,x=mi()

a=[[0 for i in range(m)]for j in range(n)]
p=[0]*n
for i in range(n):
    a1=li()
    p[i]=a1[0]
    a[i]=a1[1:]

ans=1000000007
for i in range(1,pow(2,n)):
    s=bin(i)[2:]
    s='0'*(n-len(s))+s
    s1=0
    x1=[0]*m
    for j in range(n):
        if s[j]=='1':
            for k in range(m):
                x1[k]+=a[j][k]
            s1+=p[j] 
    f1=1
    for j in range(m):
        if(x1[j]<x):
            f1=0
        
    if(f1):
        ans=min(ans,s1)
if(ans==1000000007):
    ans=-1
print(ans)

Measured memory_bytes: 68900
#include <stdio.h>
#define swap(type, x, y)  do{ type t = x; x = y; y = t; }while(0)

void quick(int array[], int left, int right){
  int pl = left, pr = right, x = array[(left+right)/2];
  do{
    while(array[pl] < x)  pl++;
    while(array[pr] > x)  pr--;
    if(pl <= pr){
      swap(int, array[pl], array[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(array, pl, right);
  if(pr > left)   quick(array, left, pr);
}

int main(){
  int n;  scanf("%d", &n);
  int a[200005] = {0};
  for(int i=1; i<=n; i++)  scanf("%d", a+i);
  quick(a, 1, n);
  if(a[1]==1){
    if(a[2]!=1){
      printf("1\n"); return 0;
    }else{
      printf("0\n"); return 0;
    }
  }
    
  int table[1000006] = {0};
  long ans = 0;
  for(int i=1; i<=n; i++){
    if(a[i-1]==a[i] || a[i]==a[i+1]){ table[a[i]] = 1;  continue; }
    int soin[1000] = {0};
    int ai = a[i];
    for(int j=2; j*j<=a[i]; j++){
      while(ai%j==0){
	soin[++soin[0]] = j;
	ai /= j;
      }
    }
    if(ai!=1) soin[++soin[0]] = ai;
    int thisans = 1;
    for(int bit=1; bit<(1<<soin[0]); bit++){
      int yaku = 1;
      for(int b=0; b<soin[0]; b++){
	if(bit & (1<<b))
	  yaku *= soin[b+1];
      }
      if(table[yaku]){ thisans = 0; break; }
    }
    if(thisans){ ans++; }// printf("ok : %d\n", a[i]); }
    table[a[i]] = 1;
  }
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 6424
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun sumList(a: Iterable<Long>): List<Long> {
        val result = mutableListOf(0L)
        var i = 0L
        a.forEach {
            i += it
            result.add(i)
        }
        return result
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val X = sc.next().toInt()
        val L = LongArray(N) { sc.next().toLong() }
        val S = sumList(L.toList())
        pw.println(S.takeWhile { it <= X }.count())
    }
}


Measured memory_bytes: 33484
#include <iostream>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a;

ll nibeki(ll q){
	ll r = 1;
	while(true){
		r *= 2;
		if(r > q){break;}
	}
	return r;
}

int main(){
	cin >> n;
	multiset<ll> mst;
	for(ll i = 0; i < n; i++){
		cin >> a;
		mst.insert(a);
	}
	
	ll ans = 0;
	while(!mst.empty()){
		auto itrend = mst.end();
		itrend--;
		a = *itrend;
		mst.erase(itrend);
		ll ia = nibeki(a)-a;
		if(mst.find(ia) != mst.end()){
			ans++;
			mst.erase(mst.find(ia));
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11008
s = input()
s_header = int(s[0:2])
s_footer = int(s[2:4])




if s_header >=1 and s_header <=12 and s_footer >= 1 and s_footer <= 12 :
  print("AMBIGUOUS")
elif s_header >= 0 and s_footer >=1 and s_footer <=12:
  print("YYMM")
elif s_header >=1 and s_header <=12 and s_footer >= 0:
  print("MMYY")
else:
  print("NA")



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    string z;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] == 'B')
        {
            if(!z.empty())
                z.pop_back();
        }
        else
            z += s[i];
    }
    cout << z;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int W, a, b;

signed main()
{
    cin >> W >> a >> b;
    if (b + W < a) {
        cout << a - (b + W) << endl;
    } else if (a + W < b) {
        cout << b - (a + W) << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll x;
    cin >> x;
    ll n = 1000;
    vector<ll> num(n,0);
    ll a = 0, b = 0;
    rep2(i,1,n) num[i] = pow(i,5);
    rep2(i,0,n){
        rep2(j,0,i){
            if (num[i]-num[j]==x){
                a = i;
                b = j;
                break;
            }
            if (num[i]+num[j]==x){
                a = i;
                b = -j;
                break;
            }
        }
        if (a!=0) break;
    }
    cout << a << " " << b << endl;
}

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

int cnt[10];
char s[10];

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    if (a + k - 1 >= b - k + 1)
    {
        for (int i = a; i <= b; ++i) cout << i << endl;
    }
    else
    {
        for (int i = a; i < a + k; ++i) cout << i << endl;
        for (int i = b - k + 1; i <= b; ++i) cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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)*}
    };
}

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:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, b: [i64; n - 1],
    }
    let mut tot = 0;
    for i in 0..n - 2 {
        tot += min(b[i], b[i + 1]);
    }
    tot += b[0] + b[n - 2];
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
n = list(map(int, input()[::-1])) + [0]
s = 0
res = 0
for i, ni in enumerate(n[:-1]):
    k = ni + s
    if k < 5 or (k == 5 and int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)


Measured memory_bytes: 18768
S = input()
n = len(S)
s = int(S, 2)
b = ''.join(map(str, [i % 2 for i in range(1, n + 1)]))
p = int(b, 2)
q = p >> 1
print(min(bin(s ^ n).count('1') for n in [p, q]))

Measured memory_bytes: 55808
# 奇数と奇数の時だけ 積 // 2 に + 1 する

a, b = map(int, input().split())

if a == 1 or b == 1:
    print(1)

elif a % 2 == 1 and b % 2 == 1:
    print(a * b // 2 + 1)
    # print("a")

else:
    print(a * b // 2)
    # print("b")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)	
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7  ;
#define ld long double
#define MAX (int)(pow(10,5)+ 10)




void deal(){
	ll n;
	cin>>n;
	vector<ld> dp(n+1, 0);
	dp[0] = 1;
	for(ll i =1; i<=n; i++){
		vector<ld> dpc(n+1,0);
		ld pi;
		cin>>pi;
		dpc[0] = dp[0]*(1-pi);
		for(ll j = 1; j<=n; j++)
			dpc[j] = dp[j-1]*pi + dp[j] * (1-pi);
		dp = dpc;
	}
	ld sum = 0;
	for(ll j = (n+2)/2; j<=n; j++)
		sum+=dp[j];
	cout<<setp(15)<<sum;
}
 
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}
 
/*
 
5 1
1 2 3 4 5


*/

Measured memory_bytes: 384
/* --- Sugoroku and Pieces ---
とにかく、足す.
足したときに、
i) (A_i) + 1 ≠ (A_i+1)であること.
ii) A_i ≠ 2019であること.
この２つの条件が満たされているかを確かめる.　←　この処理をmoveとする.

まとめると:
	N個の駒がある.　→　それぞれの駒の座標を格納できる「配列」Aを用意. 長さはNである.
	そのあと、M個のクエリが寄せられる.(たぶんクエリじゃない)　→　そのクエリ(?)を格納する「配列」Bを用意. 長さはMである.
	A.at(B.at(i) - 1)について、上記の処理moveを行う.
*/
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int>X(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> X.at(i);
	}
	int M; cin >> M;
	vector<int>A(M);
	for (int i = 0; i < M; i++) {
		cin >> A.at(i);
		if (X.at(A.at(i) - 1) + 1 != X.at(A.at(i)) && X.at(A.at(i) - 1) != 2019) X.at(A.at(i) - 1)++;
	}

	for (int i = 0; i < N; i++) {
		cout << X.at(i) << endl;
	}
}


Measured memory_bytes: 3096
#include<stdio.h>
#define N 100000
#define Q 50000

int binarySearch(int);
void sort(void);
int S[N];
int n;
main(){
  int q,T[N],i,j,s,count=0;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    s= binarySearch(T[i]);
    if( s!=n ){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

void sort(void){
  int flag,i,j,s,minj;

  for(i=0;i<=n-1;i++){
    minj=i;
    flag=0;
    for(j=i;j<=n-1;j++){
      if(S[j]<S[minj]){
    minj=j;
    flag=1;
      }
    }
    if(flag==1){
      s=S[i];
      S[i]=S[minj];
      S[minj]=s;
    }
  }
}

int binarySearch(int key){
  int left=0,right=n,mid;

  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key)
      return mid;
    else if(key<S[mid])
      right=mid;
    else{
      left=mid+1;
    }
  }
  return n;
}

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

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

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using DoP = pair<double, double>;
using edge = struct { int to; double cost;}; // edge x = {to, cost}

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1<<29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    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;
  }
};
// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int n;
vector<int> w;
vector<vector<int>> dp;

int rec(int l = 0, int r = n) {
  if(r-l <= 1) return 0;
  if(r-l == 2) {
    if(abs(w[l]-w[l+1]) <= 1) {
      return 2;
    }
    else {
      return 0;
    }
  }
  if(dp[l][r] != -1) return dp[l][r];

  if(abs(w[l]-w[r-1]) <= 1 && rec(l+1, r-1) == r-l-2) chmax(dp[l][r], r-l);
  for(int i = l+1; i <= r-1; ++i) chmax(dp[l][r], rec(l, i)+rec(i, r));
  return dp[l][r];
}

int main(){
  vector<int> ans;
  while(true) {
    cin >> n;
    if(n == 0) break;
    w.resize(n);
    rep(i, n) cin >> w[i];
    dp.assign(n+2, vector<int>(n+2, -1));
    ans.push_back(rec());
  }
  for(auto x : ans) cout << x << endl;
}


Measured memory_bytes: 3192
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, long long> pdl;

const long double pi = 3.141592653589793;

#define debug(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main() {

    //freopen("fighting_the_zombies.txt","r",stdin);
    //freopen("output_file_name.txt","w",stdout);

    ll n, a, b; cin>>n>>a>>b;
    vector<ll> A(n);
    rep(i, n) cin>>A[i];
    ll answer = 0;
    for(int i = 1;i < n;i++) {
        answer += min((A[i]-A[i-1])*a, b);
    }

    cout<<answer<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {

    int n;
    cin>>n;

    vector<int>b(n);
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            if(i==j)
                continue;
            ans+=b[i]*b[j];
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

int main() {
   string S;
   cin >> S;
   int a, b, c;
   a = 0;
   b = 0;
   c = 0;
   for(int i = 0; i < S.size(); i++) {
       if(S[i] == 'a') a++;
       if(S[i] == 'b') b++;
       if(S[i] == 'c') c++;
   }

   if(a == 1 && b == 1 && c == 1) cout << "Yes";
   else cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int dp[41][500][500] = {};
int main(){

  int n, ma, mb;
  scanf("%d %d %d", &n, &ma, &mb);

  vector<int> a(n), b(n), c(n);
  REP(i,n){
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
  }

  REP(i,n+1){
    REP(j,500){
      REP(k,500){
        dp[i][j][k] = INF;
      }
    }
  }

  dp[0][0][0] = 0;
  REP(i,n){
    REP(j,n*10+1){
      REP(k,n*10+1){
        if(j - a[i] >= 0 && k - b[i] >= 0){
          dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a[i]][k-b[i]] + c[i]);
        }else{
          dp[i+1][j][k] = dp[i][j][k];
        }
      }
    }
  }

  int ans = INF;
  int mx = max(ma, mb);
  for(int i = 1; i * mx <= n*10 + 1; ++i){
    ans = min(ans, dp[n][ma*i][mb*i]);
  }

  if(ans == INF) ans = -1;

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



Measured memory_bytes: 40320
n,y=map(int,input().split())
y=y/1000
ans=(-1,-1,-1)
for i in range(1+n):
    for j in range(n-i+1):
        if i*10+j*5+(n-i-j)==y and n-i-j>=0:
            ans=(i,j,n-i-j)
print(*ans)


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl;
#define CNO cout<<"No"<<endl;

typedef long long LL;
typedef long double LD;

struct sta{
  LL a;
  LL s;
  LL pr;
};

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> rx(n);
  rx[0] = a[0];
  repp(i,1,n) rx[i]=rx[i-1]^a[i];

  int t=0;
  vector<int> r(n,0);
  if(rx[n-1]==0){
    r[n-1]=1;
    t++;
  }
  per(i,n-1){
    if(rx[i]==0){
      t++;
      r[i]=r[i+1]+1;
    }else{
      r[i]=r[i+1];
    }
  }
  map<int,sta> mp;
  LL ans=0;
  if(rx[n-1]==0){
    ans=1;
    rep(i,t-1) ans=(ans*2)%MOD;
    per(i,n){
      if(rx[i]==0) continue;
      auto itr = mp.find(rx[i]);
      if(itr==mp.end()){
        ans=(ans+1)%MOD;
        mp[rx[i]]={1,1,r[i]};
      }else{
        LL na = (itr->second.a+itr->second.s*(r[i]-itr->second.pr)%MOD)%MOD;
        ans=(ans+na)%MOD;
        itr->second = {na, (itr->second.s+na)%MOD, r[i]};
      }
    }
  }else{
    ans=1;
    per(i,n){
      if(rx[i]!=rx[n-1]) continue;
      auto itr = mp.find(rx[i]);
      if(itr==mp.end()){
        mp[rx[i]]={0,1,r[i]};
      }else{
        LL na = (itr->second.a+itr->second.s*(r[i]-itr->second.pr)%MOD)%MOD;
        ans=(ans+na)%MOD;
        itr->second = {na, (itr->second.s+na)%MOD, r[i]};
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector <vector <char>> C(N, vector<char>(M));
  for (int i =0;i<N;i++){
    for (int j =0;j<M;j++){
      cin >>C.at(i).at(j);
    }
  }
  // (ここで空白のマスのみの行を削除)
  for (int k=0;k<N;k++){
  int sumM=0;
  for (int i=0;i<M;i++){
   if (C.at(k).at(i) == '.'){
     sumM ++;
   }
  }
   if (sumM == M){
   for (int j =0;j<M;j++){
     if (k<N-1){
       for (int i=k;i<N-1;i++){
       C.at(i).at(j) = C.at(i+1).at(j);
       }
       }
    }
     N--;
     k--;
   }
   } 
  // (ここで空白のマスのみの列を削除)
  for (int k=0;k<M;k++){
  int sumN=0;
  for (int i=0;i<N;i++){
   if (C.at(i).at(k) == '.'){
     sumN ++;
   }
  }
   if (sumN == N){
   for (int j =0;j<N;j++){
     if (k<M-1){
       for (int i=k;i<M-1;i++){
       C.at(j).at(i) = C.at(j).at(i+1);
       }
       }
    }
     M--;
     k--;
   }
   } 
  
  // (ここで2次元配列を出力)
  for (int i =0;i<N;i++){
   for (int j =0;j<M;j++){
    cout << C.at(i).at(j);
     if (j == M-1){
     cout << endl;      
     }
   }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 29
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}

ll N;

int main() {
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    ll r = 0;
    ll ans = 0;
    ll s = 0, x = 0;
    REP(i, N) {
        while(r < N) {
            s += A[r];
            x ^= A[r];
            if(x != s) {
                s -= A[r];
                x ^= A[r];
                break;
            }
            r++;
        }
        cerr << i << " " << r << endl;
        ans += r - i;
        s -= A[i];
        x ^= A[i];
    }
    cout << ans << endl;
	return 0;
}


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

int main(){
     bool issosu[101198];
     for(int i= 0; i<= 101197; i++) issosu[i] = true;
     issosu[0] = issosu[1] = false;
     for(int i= 2; i<= 101197; i++){
	  if(issosu[i]){
	       for(int j = i* 2; j <= 101197; j += i){
		    issosu[j] = false;
	       }

	  }
     }
     int N,P;
     while(cin>>N>>P,N!=-1&&P!=-1){
	  vector<int> primes;
	  int p=1;
	  while(primes.size()!=P){
	       if(issosu[N+p])primes.push_back(N+p);
	       ++p;
	  }
	  vector<int> sums;
	  for(int i=0;i<P;i++){
	       for(int j=i;j<P;j++){
		    sums.push_back(primes[i]+primes[j]);
	       }
	  }
	  sort(sums.begin(),sums.end());
	  //unique(sums.begin(),sums.end());
	  cout<<sums[P-1]<<endl;
	  //for(int i=0;i<P;i++)cout<<sums[i]<<endl;
     }
}

Measured memory_bytes: 1060
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define MOD 1000000007;

int main(){
  ll n,m,ans=0;cin>>n>>m;
  vll x(n),y(n),z(n);
  rep(i,0,n){
    cin>>x[i]>>y[i]>>z[i];
  }
  rep(i,0,1<<3){
    vll all(n,0);ll tmp=0;
    rep(j,0,n){
      if(i>>2&1){all[j]+=x[j];}
      else{all[j]-=x[j];}
      if(i>>1&1){all[j]+=y[j];}
      else{all[j]-=y[j];}
      if(i>>0&1){all[j]+=z[j];}
      else{all[j]-=z[j];}
    }
    sort(all.begin(),all.end());
    reverse(all.begin(),all.end());
    rep(j,0,m){
      tmp+=all[j];
    }
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <math.h> 


int main(void)
{
	int N,*a,i,prefixSum=0;
	scanf("%d",&N);
	a=(int*)malloc(sizeof(int)* (N+3));
	a[0]=0;
	a[N+1]=0;
	for(i=1;i<=N;i++){
		scanf("%d", &a[i]);
		prefixSum+=abs(a[i]-a[i-1]);
	}
	prefixSum+=abs(a[N]-a[N+1]);

	for(i=1;i<=N;i++)
	{
		printf("%d\n",prefixSum-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1]));
	}
	free(a);
	return 0;
}

Measured memory_bytes: 1536
N, M = gets.split.map(&:to_i)
counter = Array.new(N, 1)
red_exists = Array.new(N, false)
red_exists[0] = true
visited = Array.new(N, false)
visited[0] = true

M.times do
  x, y = gets.split.map { |x| x.to_i - 1 }

  counter[x] -= 1
  counter[y] += 1

  if visited[x]
    visited[y] = true
    red_exists[y] = true
  end

  if counter[x].zero?
    visited[x] = false
    red_exists[x] = false
  end
end

ans = 0

N.times do |i|
  next unless red_exists[i]

  ans += 1
end

puts ans


Measured memory_bytes: 4092
def main():
  M=10**9+7
  a,b,c,d=map(int,input().split())
  n=c+d+2
  fac=[0]*(n+1)
  fac[0]=lt=1
  for i in range(1,n+1):fac[i]=lt=lt*i%M
  inv=[0]*(n+1)
  inv[n]=lt=pow(fac[n],M-2,M)
  for i in range(n,0,-1):inv[i-1]=lt=lt*i%M
  comb=lambda n,k:fac[n]*inv[n-k]*inv[k]
  f=lambda r,c:fac[r+c+2]*inv[c+1]*inv[r+1]-c-r-2
  print((f(c,d)-f(c,b-1)-f(a-1,d)+f(a-1,b-1))%M)
main()

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

int main(){
  int i,j,n,C[10001];
  unsigned short *A, *B,k=10000;

  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=1;i<=n;i++){
    scanf("%hd",&A[i]);
  }
  
  for(i=0;i<=k;i++) C[i]=0;
  for(j=1;j<=n;j++) C[A[j]]++;
  for(i=1;i<=k;i++) C[i]+=C[i-1];

  for(j=n;j>=1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i!=n) printf(" ");
  }
  printf("\n");
  return 0;
}


  

  

  



Measured memory_bytes: 9588
#include<stdio.h>
int e(int a,int b){
  if(a%b==0){
    return b;
  }else{
    return e(b,a%b);
  }
}

int main(){
  int a,b,tmp;
  while(1){
    if(scanf("%d%d",&a,&b)!=2){
      break;
    }
    if(a<b){
      tmp=b;
      b=a;
      a=tmp;
    }
    if(a<0||b<0){
      break;
    }
    if(e(a,b)>0){
      printf("%d\n",e(a,b));
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

std::set<int> a;
std::multiset<int> aa;

int main(int argc, char *argv[]) {  
	int n, k;
	std::cin >> n >> k;
	for(int i = 0; i < n; i++) {
		int t;
		std::cin >> t;
		a.insert(t);
		aa.insert(t);
	}
	std::vector<int> m;
	for(auto it: a) {
		m.push_back(aa.count(it));
	}
	std::sort(m.begin(), m.end());
	int ans = 0;
	for(int i = 0; i < std::max((int)a.size()-k, 0); i++) {
		ans += m[i];
	}
	std::cout << ans << std::endl;
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  vll p(n), q(n);
  REP(i, n)
    cin >> p[i];
  REP(i, n)
    cin >> q[i];

  vll a(n);
  REP(i, n)
    a[i] = 1+i;

  ll cur = 0;
  ll aa,bb;
  aa = bb = 0;
  do{
    bool aflag,bflag;
    aflag = bflag = true;
    REP(i, n){
      if(a[i] != p[i])
        aflag = false;
      if(a[i] != q[i])
        bflag = false;
    }

    if(aflag)
      aa = cur;
    if(bflag)
      bb = cur;
    cur++;
  }
  while(next_permutation(a.begin(), a.end()));

  cout << abs(aa-bb) << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		
		if(B%A == 0){
			System.out.println(A+B);
		}else{
			System.out.println(B-A);
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n,m;
    cin >> n >> m;
    int k;
    cin >> k;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(k == i * (m - j) + j * (n - i)){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	int n, m, prob, ac = 0, wa = 0;
	cin>>n>>m;
	string verd;
	vector<pair<bool, int> > problem(n+1, make_pair(false, 0));
	for(int i=0;i<m;i++)
	{
		cin>>prob>>verd;
		if(problem[prob].first == true)					//if problem already aced don't do anything
		{
			continue;
		}
		else											//if not
		{
			if(verd.compare("AC") == 0)					//if aced
			{
				problem[prob].first = true;				//then make done true
				ac++;									//inc ac
			}
			else									
			{
				problem[prob].second++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(problem[i].first == true)
			wa += problem[i].second;
	}
	cout<<ac<<" "<<wa;
	return 0;
}

Measured memory_bytes: 1024
from itertools import permutations
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall

def WarshallFloyd(M):
    M = csgraph_from_dense(M)
    return floyd_warshall(M)

N, M, K = map(int, input().split())
R = [int(i) - 1 for i in input().split()]
E = [[0] * N for _ in range(N)]
for a, b, c in (map(int, input().split()) for _ in range(M)):
    a -= 1; b -= 1
    E[a][b] = E[b][a] = c

E = WarshallFloyd(E)
ans = min(sum(E[p[i]][p[i + 1]] for i in range(K - 1)) for p in permutations(R))
print(int(ans))


Measured memory_bytes: 19244
def lo2(n):
    count=0
    while n%2==0:
        count+=1
        n=n//2
    return count

N = int(input())

ans = 1
ma = 0
for i in range(1,N+1):
    if lo2(i)>ma:
        ans = i
        ma=lo2(i)

print(ans)


Measured memory_bytes: 61984
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000000
using Graph=vector<vector<int>>;

int main(){
  int Q;
  cin>>Q;
  vector<pair<ll,ll>> ans;
  ll B=0;
  multiset<ll> lower,upper;
  ll medium=INF;
  ll dif1=0,dif2=0;
  for(int i=0;i<Q;i++){
    int q;
    cin>>q;
    if(q==1){
      ll a,b;
      cin>>a>>b;
      B+=b;
      int n=upper.size()+lower.size()+1;
      if(medium==INF){
        medium=a;
      }else if(n==1){
        if(a<medium){
          dif2=medium-a;
          upper.insert(medium);
          medium=a;
        }else{
          dif2=a-medium;
          upper.insert(a);
        }
      }else{
        if(n%2==0){
          if(a<medium){
            dif1+=medium-a;
            lower.insert(a);
          }else{
            upper.insert(a);
            dif2+=a-medium;
            dif2-=(*upper.begin()-medium)*(ll)upper.size();
            lower.insert(medium);
            dif1+=(*upper.begin()-medium)*(ll)lower.size();
            medium=*upper.begin();
            upper.erase(upper.find(medium));
          }
        }else{
          if(a>medium){
            upper.insert(a);
            dif2+=a-medium;
          }else{
            lower.insert(a);
            dif1+=medium-a;
            dif1-=(medium-*lower.rbegin())*(ll)lower.size();
            upper.insert(medium);
            dif2+=(medium-*lower.rbegin())*(ll)upper.size();
            medium=*lower.rbegin();
            lower.erase(lower.find(medium));
          }
        }
      }
    }else{
      ans.push_back(make_pair(medium,B+dif2+dif1));
    }
  }

  for(int i=0;i<ans.size();i++){
    cout<<ans.at(i).first<<" "<<ans.at(i).second<<endl;
  }
}


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

using namespace std;

void solve() {
    int n;
    cin >> n;

    vector<double> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];

    vector<vector<double>> dp(n+1, vector<double>(n+1, -1.0));

    function<double(int, int)> calc_dp = [&] (int i, int s) {
        if (i > s || i < 0 || s <= 0)
            return 0.0;

        if (i == 0 && s == 1) {
            return (1-p[0]);
        }

        if (i == 1 && s == 1) {
            return p[0];
        }

        if (dp[i][s] != -1)
            return dp[i][s];

        dp[i][s] = p[s-1] * calc_dp(i-1, s-1) + (1-p[s-1]) * calc_dp(i, s-1);
        return dp[i][s];
    };

    double ans = 0.0;
    for (int i = n/2 + 1; i <= n; ++i) {
        ans += calc_dp(i, n);
    }
    printf("%.10lf\n", ans);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 74016
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <tuple>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<vector<PII> > VVPII;
typedef priority_queue<PII, vector<PII>, greater<PII> > PQPII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int DX[] = {0, 1, 0, -1};
const int DY[] = {-1, 0, 1, 0};

//other
//--------------------------------------------
#define RANGE(a, c, b) ((a <= b) && (b < c))

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int convertInt(string word, int start, int end){
	string num_str = word.substr(start, end);
	return  toInt(num_str);
}

int main(int argc, char const *argv[])
{
	int sum = 0;
	while(!cin.eof()){
		string word;
		cin >> word;
		bool flag = false;
		int start = (int)10e9, end;
		REP(i, word.length()){
			if(isdigit(word[i])){
				start = min(start, i);
				end = max(end, i);
				flag = true;
			}else if(flag){
				flag = false;
				sum += convertInt(word, start, end);
				start = (int) 10e9;
				end = 0;
			}
		}
		if(flag){
			end = word.length() - start;
			sum += convertInt(word, start, end);

		}
	
	}
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1224