akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

int n, mod = 1e9 + 7;; 
vector<vector<int>> graph;
ll dp[100003][2];
// B -- W
// W -- B/W

// state only depends on which vertex we are at and whether its parent is colored black

ll solve(int u, int p, bool p_black){
	if(dp[u][p_black] != -1) return dp[u][p_black];
	ll ways_white = 1, ways_black = !p_black;
	for(int v : graph[u]){
		if(v == p) continue;
		ways_white *= solve(v,u,0);
		ways_white %= mod;
		if(!p_black){
			ways_black *= solve(v,u,1);
			ways_black %= mod;
		}
	}
	return dp[u][p_black] = (ways_black + ways_white) % mod;
}


void solution(){
	cin >> n;
	graph = vector<vector<int>>(n);
	for(int i = 0; i < n-1; i++){
		int u, v; cin >> u >> v;
		u--; v--;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	memset(dp,-1,sizeof(dp));
	cout << solve(0,-1,0) << endl;

}	


int main(){ 

	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}


Measured memory_bytes: 18408
#include <stdio.h>
#define MAX 50

int A[MAX],n;

int solve(int i, int m){
	if(m==0)return 1;
	if(i>=n)return 0;
	
	int res=solve(i+1,m)||solve(i+1,m-A[i]);
	return res;
}

int main(void){
	int i,q,m;
	
	scanf("%d",&n);
	
	
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
		
	}
	scanf("%d",&q);
	
	for(i=0;i<q;i++){
		scanf("%d",&m);
		
		if(solve(0,m)){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}
	
	return 0;
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::process;
fn main() {
    input!{
        s:chars,
        t:chars,
    }
    for i in (0..s.len()).rev() {
        let mut flag = true;
        for j in i..(i+t.len()) {
            if i+t.len() > s.len() {
                flag = false;
                continue;
            }
            if !(s[j] == t[j - i] || s[j] == '?') {
                flag = false;
            }
        }
        if flag {
            let mut ans = "".to_string();
            for j in 0..s.len() {
                if j>=i && j<=(i+t.len()-1) {
                    ans.push(t[j - i]);
                }else {
                    ans.push(if s[j] == '?' {'a'} else {s[j]});
                }
            }
            println!("{}", ans);
            process::exit(0);
        }
    }
    println!("UNRESTORABLE");

}

Measured memory_bytes: 4352
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println(a * t < b ? a * t : b);
	}
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

vec<int> getCoef(int n, int sign) {
   vec<int> res(n);
   rep (i, n) {
      int c = (i == 0 || i == n-1) ? 1 : 2;
      c *= (i & 1) ? sign : -sign;
      res[i] = c;
   }
   return res;
}

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

   sort(all(a));

   int ans = 0;
   for (int sign = -1; sign <= 1; sign += 2) {
      auto c (getCoef(n, sign));
      sort(all(c));

      int sum = 0;
      rep (i, n) sum += a[i] * c[i];
      chmax(ans, sum);
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 998244353;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

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;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[3005][3005];

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = mint(1);
    for (int i=a; i<=c; i++) {
        for (int j=b; j<=d; j++) {
            if (i==a && j==b) continue;
            dp[i][j] = dp[i-1][j]*j + dp[i][j-1]*i - dp[i-1][j-1]*(i-1)*(j-1);
        }
    }

    mint ans = dp[c][d];
    
    cout << ans << endl;
    return 0;
}


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

int main(void){
    int a,b,c,k;
    cin >> a >> b >> c >> k;

    ll ans = 0;
    if(k>a){
        ans += a;
        k -= a;
    }else{
        cout << k << endl; return 0;
    }
    if(k>b){
        k -= b;
    }else{
        cout << ans << endl; return 0;
    }
    ans -= k;
    cout << ans << endl;
    return 0;
}

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

/* -128 ~ 127 */
using i8  = int8_t;
/* 0 ~ 255 */
using u8  = uint8_t;
/* -32,768 ~ 32,767 */
using i16 = int16_t;
/* 0 ~ 65,535 */
using u16 = uint16_t;
/* -2,147,483,648 ~ 2,147,483,647 */
using i32 = int32_t;
/* 0 ~ 4,294,967,295 */
using u32 = uint32_t;
/* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using i64 = int64_t;
/* 0 ~ 18,446,744,073,709,551,615 */
using u64 = uint64_t;
/* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f32 = float;
/* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f64 = double;
using f80 = __float80;

template <class T>
using Vec = vector<T>;

template <typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

/* 定数 */
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;

#define fn auto
#define ALL(v) v.begin(), v.end()

#define GCD(a, b) __gcd(a, b) // 最大公約数
#define LCM(a, b) a / __gcd(a, b) * b // 最小公倍数

fn Main() {
    u32 K;
    cin >> K;
    queue<u64> X;
    for (int i = 1; i < 10; i++) {
        X.push(i);
    }
    for (int i = 1; i < K; i++) {
        u64 a = X.front();
        X.pop();
        if (a % 10 != 0)
            X.push(a * 10 + a % 10 - 1);
        X.push(a * 10 + a % 10);
        if (a % 10 != 9)
            X.push(a * 10 + a % 10 + 1);
    }
    cout << X.front() << endl;

}

fn main() -> int {
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}




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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll a, b, c, d;
  rep(i, 4) {
    cin >> a >> b;
    if(a == 1) a = 6000;
    else if (a == 2) a = 4000;
    else if (a == 3) a = 3000;
    else if (a == 4) a = 2000;
    cout << a * b << endl;
  }
	return 0;
}


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

#define ll long long
#define ar array
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define endl "\n"

int ans;
int x, n;
int arr[100];


int find_poss(bool subtract){
    int *end = arr + n;
    int cur=x;
    while (1){
        int *result = find(arr, end, cur);
        if (result == end){
            return cur;
        }
        else{
            if (subtract){
                cur--;
            }
            else{
                cur++;
            }
        }
    }
} 

void solve()
{

    pair <int, int> poss_ans;
    poss_ans = make_pair (find_poss(true),find_poss(false));
    int diff1 = abs(poss_ans.first - x);
    int diff2 = abs(poss_ans.second - x);
    if (diff1<diff2){
        cout<<poss_ans.first;
    }
    else if (diff1==diff2){
        cout<<poss_ans.first;
    }
    else{
        cout<<poss_ans.second;
    }
}

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

    cin >> x >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> arr[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstring>


int main() {
    int n; std::cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int a; std::cin >> a;
        cnt += a & 1;
    }
    std::cout << (~cnt & 1 ? "YES" : "NO") << std::endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int l[n];
  int myx = 0;
  for(int i=0; i<n; i++) {
    cin >> l[i];
  }
  int cnt = 1;
  for(int i=0; i<n; i++) {
    myx += l[i];
    if(myx <= x) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define maxn 1005

using namespace std;

struct nod{
	int nex,id;
	nod(int a,int b){nex=a;id=b;}
	nod(){}
};
int n,m,tim;
int vis[maxn];
int bel[maxn][maxn][2];
int u[maxn*maxn],v[maxn*maxn];
vector<nod>edge[maxn];

inline void dfs(int now,int fa,int b,int f)
{
	vis[now]=tim; bel[fa][now][f]=b;
	int len=edge[now].size();
	for(int i=0;i<len;i++)
		if(vis[edge[now][i].nex]!=tim)
			dfs(edge[now][i].nex,fa,b,f);
}

inline void solve(int now)
{
	tim++;vis[now]=tim;
	int len=edge[now].size();
	for(int i=0;i<len;i++)if(vis[edge[now][i].nex]!=tim)
		dfs(edge[now][i].nex,now,edge[now][i].id,0);
	reverse(edge[now].begin(),edge[now].end());
	tim++;vis[now]=tim;
	for(int i=0;i<len;i++)if(vis[edge[now][i].nex]!=tim)dfs(edge[now][i].nex,now,edge[now][i].id,1);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		edge[u[i]].push_back(nod(v[i],i));
	}
	for(int i=1;i<=n;i++)solve(i);
	for(int i=1;i<=m;i++)
	{
		if((bel[v[i]][u[i]][0]!=0)^(bel[u[i]][v[i]][0]!=i || bel[u[i]][v[i]][1]!=i))printf("diff\n");
		else printf("same\n");
	}
}

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

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

long lcm(long a, long b){
  return a/gcd(a,b)*b;
}

int main(){
  int N;
  cin >> N;
  vector<long> T(N);
  for(int i=0; i<N; i++){
    cin >> T[i];
  }
  long ans =T[0];
  for(int i=1; i<N; i++){
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <limits>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <array>
#include <tuple>
#include <utility>
#include <cctype>
#include <typeinfo>
using namespace std;

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define ii(n)    ff(i, n)
#define kk(n)    ff(k, n)
#define mm(n)    ff(m, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define iii(a, b) fff(i, a, b)
#define kkk(a, b) fff(k, a, b)
#define mmm(a, b) fff(m, a, b)
#define xx first
#define yy second
#define bb begin()
#define ee end()
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }

using LL = long long;
using pii = pair<int, int>;


const LL INF = 9223372036854775807LL;
//const int INF = 2147483647;
   




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << '\n';
    

    int N, K;
    cin >> N >> K;
    vector<int> aa(N);
    ii (N)
        cin >> aa[i];

    vector<LL> sums_not_including(N+1, 0);
    vector<LL> sums_only_positives(N+1, 0);
    iii (1, N+1) {
        sums_not_including[i]  = sums_not_including[i-1] + aa[i-1];
        sums_only_positives[i] = sums_only_positives[i-1] + max(0, aa[i-1]);
    }
    LL rr = 0;
    ff (offset, N-K+1) {
        LL here = LL(sums_only_positives[offset])
                + LL(sums_only_positives[N]) - sums_only_positives[offset+K];
        rr = max(rr, here);
        here += sums_not_including[offset+K] - LL(sums_not_including[offset]);
        rr = max(rr, here);
    }

    cout << rr << '\n';
    


    return 0;
}



Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define ll long long int
#define lp(i,n) for(ll i=0;i<n;i++)
using namespace std;
ll max(ll a,ll b){
    return a>b?a:b;
}
int main(){
    ll n,a,b,c;
    cin>>n;
    ll d[n][3];
    lp(i,n)
    cin>>d[i][0]>>d[i][1]>>d[i][2];

    ll dp[n][3];
    dp[0][1]=d[0][1];
    dp[0][0]=d[0][0];
    dp[0][2]=d[0][2];
    ll flag1=0;
    ll flag2=1;
    ll flag3=2;
    for(ll i=1;i<n;i++){
        dp[i][0]=d[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=d[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=d[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#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())
#define PB push_back
#define MP make_pair
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() {
  ll n;
  cin >> n;
  ll a[n];
  ll x,y,z;
  const ll MOD = 1000000007;
  FOR(i,0,n-1) cin >> a[i];

  x = 0; y = 0; z = 0;

  ll ans = 1;

  FOR(i,0,n-1){
    if(x==a[i]) {
      ++x;
      ll num = 1;
      if(y==a[i]) ++num;
      if(z==a[i]) ++num;
      ans *= num;
      ans %= MOD;
    }
    else if(y==a[i]) {
      ++y;
      ll num = 1;
      if(z==a[i]) ++num;
      ans *= num;
      ans %= MOD;
    }
    else if(z==a[i]){
      ++z;
    }
    else{
      cout << 0 << endl;
      return 0;
    }
  }

  cout << ans << endl;







  


}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin >> k >> n;
    vector<int> a(n);
    vector<int> dist(n);
    rep(i,n) cin >> a[i];
    int dist_max = 0;
    rep(i,n-1) chmax(dist_max,a[i+1] - a[i]);
    chmax(dist_max,k-a[n-1]+a[0]);
    cout << k-dist_max << endl;

}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<long long int> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  
  if(N%2 == 1){
    for(int e = 0; e < N; e += 2){
      cout << a[N-e-1] << " ";
    }
    for(int p = 0; p + 2 < N; p += 2){
      cout << a[1+p] << " "; 
    }
  }else{
    for(int e = 0; e < N; e+= 2){
      cout << a[N-e-1] << " ";
    }
    for(int p = 0; p < N; p +=2){
      cout << a[p] << " ";
    }
  }
}


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

int main () {
  int k, s, ans = 0;
  cin >> k >> s;
  
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int a = s-i-j;
      if (0 <= a && a <= k) {
        ans ++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;string s;ll k;
  cin>>n>>s>>k;
  k--;
  char c=s[k];
  rep(i,n){
    if(s[i]==c)cout<<c;
    else cout<<"*";
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int main(void) {
	char S[100001];
	vector<char> ans;
	int cnt = 0;
	int s = 0;
	int n = 0;
	int n_ans = 0;

	scanf("%s", S);
	n = strlen(S);

	for (size_t i = 0; i < n; i++)
	{
		n_ans = ans.size();
		if (n_ans == 0) {
			ans.push_back(S[i]);
		}
		else if (ans[n_ans-1] != S[i])
		{
			cnt += 2;
			ans.pop_back();
		}
		else
		{
			ans.push_back(S[i]);
		}
	}
	printf("%d\n", cnt);
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int main()
{
    int n,k,s=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&k);
        if(k%2==0) s++;
    }
    if(s==n) printf("second\n");
    else printf("first\n");
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def minimize(k, n, bs):
    deltas = [bs[i + 1] - bs[i] for i in range(n - 1)]
    deltas.append(bs[0] - bs[-1] + k)
    return k - max(deltas)


def main():
    k, n = (int(z) for z in input().split())
    bs = [int(b) for b in input().split()]
    res = minimize(k, n, bs)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24948
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main(){
  int n;
  cin>>n;
  
  vector<ll> p(n);
  map<int,int> q;
  rep(i,n){
    cin>>p[i];
    if(q.count(p[i])) q.at(p[i])++;
    else q[p[i]]=1;
  }

  ll ans=0;
  for(int i=n-1;i>=0;i--){
    if(q[p[i]]>1) continue;
    if(p[i]==1 && q[1]==1) ans++;
    bool ok=true;
    for(int j=1;j*j<=p[i];j++){
      if(p[i]%j==0) {
        if(q.count(j)) ok=false;
        if(j!=1 && q.count(p[i]/j)) ok=false;
      }
    }
    if(ok) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int32_t main() {

    simplify
    int n;
    cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr.rbegin(),arr.rend());

    int ans=arr[0];
    vector<int>toTake;

    for(int i=1;i<n;i++){
        toTake.push_back(arr[i]);
        toTake.push_back(arr[i]);
    }
    sort(toTake.rbegin(),toTake.rend());

    for(int i=0;i<n-2;i++){
        ans+=toTake[i];
    }
    cout<<ans;
    

    return 0;
}



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

int main()
{
    long long int n,i,j;
    cin>>n;

    vector<double> v;

    for(i=0;i<n;i++)
    {
        double p;
        cin>>p;
        v.push_back(p);
    }


    double dp[3005][3005];

    for(i=0;i<3003;i++)
        for(j=0;j<3003;j++)
            dp[i][j]=0.0;

    dp[0][1]=v[0];
    dp[0][0]=1-v[0];

    for(i=1;i<n;i++)
    {
        for(j=0;j<=n;j++)
        {
            dp[i][j+1]+=dp[i-1][j]*v[i];
            dp[i][j]+=dp[i-1][j]*(1-v[i]);
        }
    }

    double sum=0;

    for(i=(n+1)/2;i<=n;i++)
        sum+=dp[n-1][i];

    std::cout << std::fixed;
    std::cout << std::setprecision(10);
    cout<<sum;


}


Measured memory_bytes: 70784
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>

using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
int main()
{
    int a,b;
    scanf("%d %d\n",&a,&b);
    if(a%2==1 &&b%2==1)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
n=int(input())
d=[0 for _ in range(n+1)]
f=[0 for _ in range(n+1)]
G=[]
G.append([])
for i in range(n):
    u,k,*v=map(int,input().split())
    G.append(v)

checked=[False for _ in range(n+1)]
timestamp=1

def dfs(id):
    global timestamp
    d[id]=timestamp
    checked[id]=True
    timestamp+=1
    for v in G[id]:
        if not checked[v]:
            dfs(v)
    f[id]=timestamp
    timestamp+=1

for id in range(1,n+1):
    if not checked[id]:
        dfs(id)

for i in range(1,n+1):
    print("{0} {1} {2}".format(i,d[i],f[i]))



Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define F first
#define S second
#define PB push_back 
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int SIZE=100+5*1e+3;
const LL p=7+1e+9;
LL DP[3][SIZE];
LL fx[SIZE],jump[SIZE];
LL N,L;
int main(){
	cin >> N >> L;
	FOR(i,1,N+1){
		cin >> fx[i];
		fx[i]++;
	}
	FOR(i,1,N+1)
		cin >> jump[i];
	LL ans=0;
	REP(i,2)
		DP[i][0]=1;
	FOR(k,1,L+1){
		LL i=k&1;
		FOR(j,1,N+1){
			ans=0;
			if(jump[j]!=0 && (k-fx[j])>=0 && (k-fx[j])%jump[j]==0)
				ans+=DP[i^1][j-1];
			if(jump[j]==0 && k==fx[j])
				ans+=DP[i^1][j-1];
			ans+=DP[i^1][j];
			DP[i][j]=ans%p;
		}
	}
	cout << DP[L&1][N] << endl;	
//	cout << search(0,fx[0]) << endl;
}	

Measured memory_bytes: 1316
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=100005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m;
map<int,int> sum;

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		sum[x]++;
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		int x;scanf("%d",&x);
		if(sum[x]>0) sum[x]--; else{puts("NO");return 0;}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
   
int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> dp(n+1, 0);
    dp[0] = 1; dp[1] = 1;
    for (int i = 0; i < m; ++i) {
        int xx; 
        cin >> xx;
        dp[xx] = -1;
    }
    int MOD = 1000000007;
    for (int i = 1; i <= n; ++i) {
        if (dp[i] < 0) {
            dp[i] = 0;
            continue;
        }
        dp[i] = dp[i-1]+dp[i-2];
        dp[i] %= MOD;
    }
    cout << dp[n] << endl;
    return 0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
   string in;
   cin >> in;
   int v[4];
   for (int i = 0; i < 4; i++) {
      v[i] = in[i] - '0';
   }

   for (int mask = 0; mask <= (1<<3); mask++) {
      int sum = v[0];
      string s = to_string(v[0]);
      for (int i = 0; i < 3; i++) {
         if ( (mask >> i) & 1 ) {
            sum += v[i+1];
            s += '+';
         } else {
            sum -= v[i+1];
            s += '-';
         }
         s += to_string(v[i+1]);
      }
      if (sum == 7) {
         cout << s << "=7" << endl;
         return 0;
      }
   }

   return 0;
}

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

int main(){
    long N, K;
    cin >> N >> K;
    long ans = (N / K) * (N / K) * (N / K);
    if(!(K & 1)) ans += ((N + K / 2) / K) * ((N + K / 2) / K) * ((N + K / 2) / K);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
string a;
unordered_map<int, int>v;
	
int main(){
	IOS
	cin >> a;
	int b=a.length();
	for(int i=0;i<b;i++){
		if(a[i]=='1'){
			v[1]++;
		}
		else v[0]++;
	}
	cout << 2*min(v[0], v[1]) << '\n';
}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

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

int main(){
	int dmg[26];
	string mp[100];
	int HP, HPmax;
	int reg[12];
	int dp[2][1<<12];
	while(cin >> HP >> HPmax, HP){
		int R, C; cin >> R >> C;
		for(int i=0;i<R;i++) cin >> mp[i];
		int T; cin >> T;
		for(int i=0;i<T;i++){
			char c; int d; cin >> c >> d;
			dmg[c-'A'] = d;
		}
		int S; cin >> S;
		vector<int> act;
		for(int i=0;i<S;i++){
			char c; int d; cin >> c >> d;
			for(int j=0;j<d;j++){
				if(c=='U') act.push_back(0);
				if(c=='D') act.push_back(1);
				if(c=='R') act.push_back(2);
				if(c=='L') act.push_back(3);
			}
		}
		int P; cin >> P;
		for(int i=0;i<P;i++) cin >> reg[i];
		memset(dp, 0, sizeof(dp));
		dp[0][(1<<P)-1] = HP;
		int x = 0, y = 0;
		int cur = 0, next = 1;
		for(int i=0;i<act.size();i++){
			memset(dp[next], 0, sizeof(dp[next]));
			x += dx[act[i]];
			y += dy[act[i]];
			int damage = dmg[mp[x][y]-'A'];
			for(int j=(1<<P)-1;j>=0;j--){
				if(dp[cur][j] == 0) continue;
				if(dp[cur][j] > damage) dp[next][j] = max(dp[next][j], dp[cur][j]-damage);
				for(int k=0;k<P;k++){
					if(!(j&(1<<k))) continue;
					dp[cur][j^(1<<k)] = max(min(HPmax, dp[cur][j]+reg[k]), dp[cur][j^(1<<k)]);
				}
			}
			swap(cur, next);
		}
		cout << (dp[cur][0] > 0 ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 972
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	string sa;
	cin>>sa;
	sa[1]=(char)((int)'B'+(int)'R'-(int)sa[1]);
	cout<<sa<<endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string x;
    cin >> x;
    vector<char> st;
    int ret = x.size();
    for (int i = 0; i < x.size(); ++i) {
        if (!st.empty() && st.back() == 'S' && x[i] == 'T') {
            st.pop_back();
            ret -= 2;
        } else {
            st.push_back(x[i]);
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 772
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <memory.h>
#include <algorithm>
#include <cassert>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(c) (c).begin(), (c).end()
#define sz(c) int((c).size())
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fst first
#define snd second

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using pii = pair<int, int>;

#define FNAME "a"

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#endif

int n;
vector<string> s;

bool read() {
    if  (!(cin >> n)) {
        return 0;
    }
    string tmp;
    getline(cin, tmp);
    s.clear();
    s.resize(n);
    forn(i, n) {
        getline(cin, s[i]);
    }

    forn(i, n) {
        eprintf("%s\n", s[i].data());
    }
    return 1;
}

void solve() {
    vi bad(2 * n, 0);
    forn(i, n * 2) {
        forn(j, n * 2) {
            int i1 = i;
            int j1 = j;
            while (1) {
                i1 = i1 - 1;
                j1 = j1 + 1;

                if  (i1 < 0 || j1 >= 2 * n) {
                    break;
                }

                if  (s[i % n][j % n] == s[i1 % n][j1 % n]) {
                    continue;
                }

                int d0 = i - j;
                int d1 = i1 - j1;

                if  (d0 > d1) {
                    swap(d0, d1);
                }

                assert((d0 + d1) % 2 == 0);
                int d = (d0 + d1) / 2;
                if  (-n < d && d < n) {
                    bad[n + d] = 1;
                }
            }
        }
    }

    int ans = 0;
    forn(a, n) {
        forn(b, n) {
            if  (bad[n + (a - b)]) {
                continue;
            }
            ++ans;
            eprintf("ok a=%d, b=%d\n", a, b);
        }
    }
    
    cout << ans << endl;
}

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

#ifdef LOCAL
    freopen(FNAME ".in", "r", stdin);
    freopen(FNAME ".out", "w", stdout);
#endif

    while (read()) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 384
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
ans = 0
N = int(input())
f = factorization(N)
for pair in f:
  p = pair[0]
  e = pair[1]
  i = 1
  while(e-i>=0):
    e = e - i
    i = i  + 1
    ans = ans + 1
if N == 1:
  ans = 0
print(ans)

Measured memory_bytes: 9496
n, k = gets.chomp.split(" ").map(&:to_i)
r, s, p = gets.chomp.split(" ").map(&:to_i)
t = gets.chomp

ans = 0
win = Array.new(n, true)
(0..n-1).each do |i|
	point = 0
	if t[i] == 'r'
		point = p
	elsif t[i] == 's'
		point = r
	elsif t[i] == 'p'
		point = s
	end

	if (i >= k) && (t[i-k] == t[i]) && win[i-k]
		point = 0
		win[i] = false
	end
	ans += point
end

puts ans


Measured memory_bytes: 4732
n = int(input())
f = []
a = ["0","1"]
for i in range(n):
	ff = list(map(int, input().split()))
	f.append(ff)

p = []
for i in range(n):
	pp = list(map(int, input().split()))
	p.append(pp)

def calc(t):
	y = list(t)
	tmp = 0
	flg = False
	for k in range(n):
		c = 0
		for b in range(10):
			if y[b] == "1" and f[k][b]:
				c += 1
				flg = True
		tmp += p[k][c]
	if flg == True:
		return tmp
	else:
		return -10**10

x = []
def dfs(i, s):
	for j in a:
		if i == 10:
			x.append(calc(s))
			return
		else:
			dfs(i+1, s+j)
dfs(0, "")
print (max(x))

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	list := make([]int, a)
	for i := 0; i < a; i++ {
		fmt.Scan(&list[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(list)))

	snake := 0
	for i := 0; i < b; i++ {
		snake += list[i]
	}
	fmt.Println(snake)
}


Measured memory_bytes: 512
import java.io.*;
 
public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true) {
            String[] line = br.readLine().split(" ");
            int a = Integer.parseInt(line[0]);
            int b = Integer.parseInt(line[2]);
             
            if(line[1].equals("+")) System.out.println(a + b);
            else if(line[1].equals("-")) System.out.println(a - b);
            else if(line[1].equals("*")) System.out.println(a * b);
            else if(line[1].equals("/")) System.out.println(a / b);
            else break;
        }
         
    }
}

Measured memory_bytes: 24404
#include<bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int maxn = 105;
int era[105];
vector<int>primes;
int dp[105][105];
int counter[105];
void proccess(int n){
	while(n!=1){
		counter[era[n]]++;
		n/=era[n];
	}
}
int f(int curr,int make){
	if(curr>=primes.size()) return 0;
	int&ret = dp[curr][make];
	if(~ret) return ret;
	ret = 0;
	for(int i=0; i<=primes[curr]; i++){
		if(make%(i+1)==0){
			if(make==i+1) ret++;
			else ret+=f(curr+1,make/(i+1));
		}
	}
	return ret;
}
int main(){
	memset(dp,-1,sizeof(dp));
	for(int i=2; i<=maxn; i++) era[i] = i;
	for(int i=2; i*i<=maxn; i++){
		if(era[i]==i){
			for(int j=i*i; j<=maxn; j+=i) era[j] = i;
		}
	}
	int n;
	cin>>n;
	for(int i=2; i<=n; i++){
		proccess(i);
	}
	for(int i=2; i<=n; i++){
		if(counter[i]) primes.push_back(counter[i]);
	}
	cout<<f(0,75);
}

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

int main(void){
  int N,K,count,integer;
  double Nf,Kf,decimal;
  scanf("%d %d",&N,&K);
  Nf = log((double)N);
  Kf = log((double)K);
  integer =(int)Nf/Kf;
  decimal = Nf/Kf - integer;//小数部分があれば繰り上げが必要
  if(decimal==0){
    count = (Nf/Kf+1);
  }else{
    count = (Nf/Kf+1);
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Algae | diff Algae.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Algae.cpp && ./a.out

/*
 
 5/25/2019
 
 5:02-
 
 */

LL R,D,X;

void solve() {
  REP(i,10) {
    LL x=R*X-D;
    cout<<x<<endl;
    X=x;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>R>>D>>X;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <bitset>
#include <queue>
#include <set>
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

#define LL long long 
#define ULL unsigned long long
#define eps 1e-9
#define N 100010
#define M 600050
#define pii pair<int,int>
#define MP make_pair
#define inf 100000000
#define md (ll+rr>>1)
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define ls rt<<1
#define rs rt<<1|1
#define Pi acos(-1.0)
#define mod 1000000007
#define ui unsigned int
#define pb push_back
LL powmod(LL a,LL b,LL p){
	if(b < 0) return 0;
	LL res = 1; a %= p;
	for(;b;b>>=1){
		if(b & 1) res = res * a % p;
		a = a * a % p;
	}
	return res;
}

int n;
int a[N];

int main(){
	cin>>n;
	for(int i = 0; i < 2*n; i++) cin>>a[i];
	sort(a,a+2*n);
	int ans = 0;
	for(int i = 0; i < 2*n; i += 2){
		ans += min(a[i],a[i+1]);
	} 	
	cout<<ans<<endl;
}

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

int main() {
    int A, B, K;

    cin >> A >> B;

    if (A>B) swap(A, B);

    if (A%2!=B%2) cout << "IMPOSSIBLE";
    else {
        K = (B-A)/2+A;
        cout << K;
    }
}

Measured memory_bytes: 256
N = list(map(int,input().split()))
M = 10**9 + 7
red = N[0] - N[1]
x = red+1
print(x)
for i in range(2,N[1]+1):
    x = x*(red+2-i)*(N[1]-i+1)//(i*(i-1))
    print(int(x%M))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int r[80][7],c[80][7],v[7],vis[7],s[7],vis2[7];
int n,m,x[7],y[7],k;
char map1[10][10];
static int num1,num2;
void dfs1(int t,int cnt,int q);
void dfs2(int t,int cnt,int q);
int main()
{
	scanf("%d %d %d",&n,&m,&k);
	//cout<<n<<" "<<m<<" "<<k;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			cin>>map1[i][j];
		}
	}
	for (int i=0;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		dfs1(1,0,i);
	}
	for (int i=0;i<=m;i++)
	{
		memset(vis2,0,sizeof(vis2));
		dfs2(1,0,i);
	}
//	for (int i=0;i<num2;i++)
//	{
//		for (int j=0;j<7&&c[i][j]!=0;j++)
//		{
//			cout<<c[i][j]<<" ";
//		}
//		cout<<endl;
//	}
//	for (int i=0;i<num1;i++)
//	{
//		for (int j=0;j<7&&r[i][j]!=0;j++)
//		{
//			cout<<r[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	int ans=0;
	for (int i=0;i<num1;i++)
	{
		for (int j=0;j<num2;j++)
		{	
			memset(x,0,sizeof(x));
			for (int p=0;p<7&&r[i][p]!=0;p++)
			{
				x[r[i][p]]=1;
			}
			memset(y,0,sizeof(y));
			for (int q=0;q<7&&c[j][q]!=0;q++)
			{
				y[c[j][q]]=1;
			}
			int cnt=0;
			for (int mx=1;mx<=n;mx++)
			{
				for (int my=1;my<=m;my++)
				{
					if (!x[mx]&&!y[my])  
					{
						if (map1[mx][my]=='#')   cnt++;
					} 
				}
			}
			if (cnt==k)   ans++;
		}
	}
	cout<<ans;
	return 0;
}

void dfs1(int t,int cnt,int q)
{
	if (cnt==q)
	{
		memcpy(r[num1++],v,sizeof(v));
		return ;
	}
	for (int i=t;i<=n;i++)
	{
		if(!vis[i])
		{
			v[cnt]=i;
			vis[i]=1;
			dfs1(i+1,cnt+1,q);
			vis[i]=0;
		}
	}
}


void dfs2(int t,int cnt,int q)
{
	if (cnt==q)
	{
		memcpy(c[num2++],s,sizeof(s));
		return ;
	}
	for (int i=t;i<=m;i++)
	{
		if (!vis2[i])
		{
			s[cnt]=i;
			vis2[i]=1;
			dfs2(i+1,cnt+1,q);
			vis2[i]=0;
		}
	}
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int count = 0;
    double lim = 0;
    for(int i = 0; i < n; i++) lim += a[i];
    lim = lim / (4 * m);
    for(int i = 0; i < n; i++){
        if((double)a[i] >= lim) count++;
    }

    if(count >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc109/tasks/abc109_b

n=int(input())

w=[input() for _ in range(n)]
if len(set(w))<n:
    print('No')
    exit()

for i in range(n-1):
    if w[i][-1]==w[i+1][0]: continue
    print('No')
    exit()
print('Yes')

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

using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  int sum=0;

  if(A>B){
    sum+=A;
    A-=1;
  }
  else
  {
    sum+=B;
    B-=1;
  }
  if(A>B){
    sum+=A;
    A-=1;
  }
  else
  {
    sum+=B;
    B-=1;
  }
  
  cout << sum<<endl;

  
  return 0;
}


Measured memory_bytes: 256