akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1010;
char a[maxn], b[maxn];
int n;

int main()
{
    cin>>n;
    cin>>a>>b;
    for(int i = 0; i <= n - 1; i ++) {
        cout<<a[i]<<b[i];
    }
    return 0;
}

Measured memory_bytes: 256
use std::collections::HashMap;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn usize() -> usize {
    read()
}

fn vec_usize(n: usize) -> Vec<usize> {
    let mut vec = Vec::new();
    for _ in 0..n {
        vec.push(usize())
    }
    vec
}

fn main() {
    let n = usize();
    let d_vec = vec_usize(n);
    let m = usize();
    let t_vec = vec_usize(m);
    let mut ds = HashMap::new();
    let mut ts = HashMap::new();
    for i in 0..n {
        let level = d_vec[i] + 1;
        let count = ds.get(&level).unwrap_or(&0) + 1;
        ds.insert(level, count);
    }
    for i in 0..m {
        let level = t_vec[i] + 1;
        let count = ts.get(&level).unwrap_or(&0) + 1;
        ts.insert(level, count);
    }
    let mut result = "YES";
    for level in ts.keys() {
        if ts.get(level).unwrap() > ds.get(level).unwrap_or(&0) {
            result = "NO";
            break;
        }
    }
    println!("{}", result);
}


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

int main()
{
    int N,M,T=0,temp;
    cin>>N>>M;
    for(int i=0; i<M; i++)
    {
        cin>>temp;
        T += temp;
    }
    int rest = N-T;
    if(rest>=0)
        cout<<rest;
    else
        cout<<-1;
  
  	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],lhj=0,ma=-1;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		ma=max(a[i],ma);
		if(a[i]<=ma-2&&i!=1){
			cout<<"No";
			return 0;
		}
		else if(a[i-1]==a[i]+1&&i!=1){
			if(lhj==0) lhj=1;
			else{
				cout<<"No";
				return 0;
			}
		}
		else if(a[i-1]<=a[i]) lhj=0;
	}
	cout<<"Yes";
	return 0;
}


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

template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) {
      N = n;
      bit.resize(n+1, 0);
    }
    void clear() {
      bit.assign(N, 0);
    }
    void add(int a, T w) {
      for (int x = a; x <= N; x += x & -x) bit[x] += w;
    }
    T sum(int a) {
      T ret = 0;
      for (int x = a; x > 0; x -= x & -x) ret += bit[x];
      return ret;
    }
};


int main(){
  int n; cin >> n;
  vector<int> v(n), u(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i]; u[i] = v[i];
  }
  sort(u.begin(), u.end());
  int left = 0; int right = n;
  Fenwick<int> f(n*2+1);
  while (u[left] != u[right-1] && right - left > 1) {
    int mid = (left + right) / 2;
    if (u[mid] == u[left]) {
      left = mid;
      continue;
    }
    int tmp = 0; long long cnt = 0;
    f.add(tmp+n, 1);
    for (int i = 0; i < n; i++) {
      if (u[mid] <= v[i]) tmp++;
      else if (u[mid] > v[i]) tmp--;
      cnt += (long long) (f.sum(tmp+n) * 2 - (i + 1));
      f.add(tmp+n, 1);
    }
    f.clear();
    if (cnt >= 0) left = mid;
    else right = mid;
  }
  cout << u[left] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9+7;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};


int main() {
    using mint = ModInt<MOD>;
    int n, m;
    cin >> n >> m;
    vector<int> lx(n), ly(m);
    for (auto& e : lx) cin >> e;
    for (auto& e : ly) cin >> e;
    
    vector<int> x, y;
    for (int i = 0; i < n-1; i++) x.push_back(abs(lx[i] - lx[i+1]));
    for (int i = 0; i < m-1; i++) y.push_back(abs(ly[i] - ly[i+1]));
    
    mint sx = 0, sy = 0;
    for (long long i = 0; i < n-1; i++) {
        mint res = ((i+1) * (n - (i+1)));
        sx += (res * x[i]);
    }
    for (long long i = 0; i < m-1; i++) {
        mint res = ((i+1) * (m - (i+1)));
        sy += (res * y[i]);
    }
    
    mint ans = sx * sy;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;    }
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;    }


//Variables Declaration


int main() {
    int n;
    cin>>n;
    int tab[n]={0};
    int a;
    for (int i = 0; i < n-1; ++i)
    {
        cin>>a;
        tab[a-1]++;
    }
    for(int i=0 ; i<n ; ++i){
        cout<<tab[i]<<endl;
    }
}


Measured memory_bytes: 4364
import sys
bbn=1000000007
	
#+++++
		
def main():
	a, b , c = map(int, input().split())
	ret = 'Yes' if (a <= c and c <= b) else 'No'
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3060
import numpy as np
C=np.zeros((3,3),dtype=str)
for i in range(3):
  a=list(map(str,input()))
  C[i][0]=a[0]
  C[i][1]=a[1]
  C[i][2]=a[2]
print(C[0][0]+C[1][1]+C[2][2])

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

int main(){
    int l,r,d;
    cin >>l >>r >>d;
int num=0;
int i=0;
int cnt=0;
    while(true){
       i++;
    num=i*d;
    if(num>r)break;
    if(num>=l)cnt++;
    }
  cout <<cnt <<" " <<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>	
using namespace std;
int k;
double l,r,e,p,t;
double ans;
double eps=1e-11;
void dfs(double l,double r,double s, double d)
{
	if (d==k)
	{
		double m=(l+r)/2;
		if (fabs(m-t)<=e) ans+=s;
	    return ;
	}
	else
	{//if (s<eps) return ;
	  if (fabs(l-t)<e && fabs(r-t)<e)
	  {
		ans+=s;
		return;
	  }
      else
	  	if (t-r>e || l-t>e) return ; 
        else
		{
		  double m=(l+r)/2;
	      if (m<t)
	      {
		     dfs(l,m,s*p,d+1);
		     dfs(m,r,s*(1-p),d+1);
	      } 
	      else 
	      {
	  	     dfs(m,r,s*p,d+1);
		     dfs(l,m,s*(1-p),d+1);
          }
		}
	}
}
int main()
{
	cin>>k>>l>>r>>p>>e>>t;
	ans=0;
	dfs(l,r,1,0);
	printf("%.10lf\n",ans);
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
#define oo 1000000007
using namespace std;
long long k;
long long dp[10005][105][2];
string s;
vector<long long>num;
long long solve(long long idx, long long sum, long long tight)
{
    if (idx == num.size())
        return (sum%k==0);
    if (dp[idx][sum][tight] != -1)
        return dp[idx][sum][tight];
    long long res = 0;
    int biggest;
    if (tight)
     biggest= (num[idx]) ;
     else
        biggest=9;
    for (int i = 0; i <= biggest; i++)
    {
        int newtight = ((num[idx])== i) ? tight : 0;
        res =(res+solve(idx + 1, (sum + i) % k, newtight))%oo;
    }
    return dp[idx][sum][tight] = res;
}
long long khoitao(string s)
{

    for(long long i=0;i<s.size();i++)
        num.push_back(s[i]-'0');
    return solve(0,0,1);
}
main()
{
    num.clear();
    memset(dp,-1,sizeof(dp));
    cin>>s>>k;
    cout<<(khoitao(s)-1+oo)%oo;
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Can't Wait for Holiday
            var S = Console.ReadLine();
            int ans = 7;

            switch (S)
            {
                case "MON":
                    ans = 6;
                    break;
                case "TUE":
                    ans = 5;
                    break;
                case "WED":
                    ans = 4;
                    break;
                case "THU":
                    ans = 3;
                    break;
                case "FRI":
                    ans = 2;
                    break;
                case "SAT":
                    ans = 1;
                    break;
            }

            Console.WriteLine(ans);
        }
    }
}

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

using namespace std;

const int MAX=1000001;

void sieve(int MAX,bool prime[]){
	for(int i=0; i<=MAX; i++)	prime[i]=true;
	prime[0]=false;
	prime[1]=false;
	for(int i=2; i*i<=MAX; i++){
		if(prime[i])for(int j=i+i; j<=MAX; j+=i)prime[j]=false;
	}
}

int main(){
	bool prime[MAX+1];
	sieve(MAX,prime);
	int N,X;
	while(cin >> N >> X && N && X){
		int a[N];
		for(int i=0; i<N; i++)	cin>>a[i];
		vector<int> dp=vector<int>(X+1, 0);
		int ans=-1;
		for(int i=0; i<N; i++){
			for(int j=1; j<=X; j++){
				if(j>=a[i]){
					dp[j]=max(dp[j],dp[j-a[i]]+a[i]);
					if(prime[dp[j-a[i]]+a[i]])	ans=max(ans,dp[j-a[i]]+a[i]);
				}
			}
		}
		if(ans>0)	cout << ans << endl;
		else		cout << "NA" << endl;
	}
}

Measured memory_bytes: 9124
#include<stdio.h>
int main(void){
int a,b,c,tmp;
scanf("%d %d %d",&a,&b,&c);
if(a>b){
tmp=a;
a=b;
b=tmp;
}
if(b>c){
tmp=b;
b=c;
c=tmp;
}
if(a>b){
tmp=a;
a=b;
b=tmp;
}
printf("%d %d %d\n",a,b,c);
return 0;
}

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

int main()
{
	int a;
	cin>>a;
	if(a<1200)
	{
		cout<<"ABC";
	}
	else if(a>=1200&&a<2800)
	{
		cout<<"ARC";
	}
	else if(a>=2800&&a<=4208)
	{
		cout<<"AGC";
	}
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	if s[0] != 'A' {
		fmt.Println("WA")
		return
	}

	cCount := 0
	for i := 2; i <= len(s)-2; i++ {
		if s[i] == 'C' {
			cCount++
		}
	}
	if cCount != 1 {
		fmt.Println("WA")
		return
	}

	for i := 1; i < len(s); i++ {
		if s[i] != 'C' && (s[i] < 'a' || s[i] > 'z') {
			fmt.Println("WA")
			return
		}
	}

	fmt.Println("AC")

}


Measured memory_bytes: 512
n=int(input())
tmp=input()
t=tmp[-1]
s=set()
s.add(tmp)
for i in range(n-1):
    tmp=input()
    if tmp[0]!=t:
        print("No")
        exit()
    if tmp in s:
        print("No")
        exit()
    s.add(tmp)
    t=tmp[-1]
print("Yes")


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int w, a, b; cin >> w >> a >> b;
    int ans = 0;
    if (b - a > w) {
        ans += b - (a + w);
    } else if (a - b > w) {
        ans += a - (b + w);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#define N 1000020
using namespace std;

char a[N];
vector<pair<int, int> > x, y;

bool CompareA(pair<int, int> a, pair<int, int> b)
{
    return a.second < b.second;
}

bool CompareB(pair<int, int> a, pair<int, int> b)
{
    return a.first + a.second > b.first + b.second;
}

int main(void)
{
    int n;
    int i, j, s;
    pair<int, int> v;

    scanf("%d", &n);
    for(i = s = 0; i < n; i ++)
    {
        scanf("%s", a);
        v = make_pair(0, 0);
        for(j = 0; a[j]; j ++)
        {
            v.first += a[j] == '(' ? 1 : -1;
            v.second = max(v.second, -v.first);
        }
        if(v.first >= 0)
            x.push_back(v);
        else
            y.push_back(v);
    }

    sort(x.begin(), x.end(), CompareA);
    sort(y.begin(), y.end(), CompareB);
    for(i = s = 0; i < (signed)x.size(); i ++)
    {
        if(s < x[i].second)
        {
            printf("No\n");

            return 0;
        }
        s += x[i].first;
    }
    for(i = 0; i < (signed)y.size(); i ++)
    {
        if(s < y[i].second)
        {
            printf("No\n");

            return 0;
        }
        s += y[i].first;
    }
    printf("%s\n", !s ? "Yes" : "No");

    return 0;
}


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

int main(void)
{
  int n, t, e;
  cin >> n >> t >> e;

  int x;
  int buf;
  bool flag = false;
  for (int i = 0; i < n; ++i)
  {
    cin >> x;
    buf = x;
    while (buf <= t+e)
    {
      if (t-e <= buf and buf <= t+e)
      {
        cout << i + 1 << endl;
        flag = true;
        break;
      }
      buf += x;
    }
    if (flag) break;
  }
  if (! flag) cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 1164
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

int main(){
	int N,K,Q;
	cin>>N>>K>>Q;
	vi ans(N+1);
	rp(i,Q){
		int a;cin>>a;
		ans[a]++;
	}

	for(int i=1; i<=N; ++i){
		if(K-Q+ans[i]>0){
			ote("Yes");
		}
		else{
			ote("No");
		}
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

ll dp[(1<<16) - 1] = {}, inp[16][16] = {};

int main() {
    nfs
    int i, j, n, mask;
    cin >> n;
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            cin >> inp[i][j];
    
    for (mask = 1; mask < (1<<n); mask++) {
        int last = __builtin_ctz(mask);
        int rmask = mask & (mask-1);
        
        dp[mask] = dp[rmask];
        for (int tmp = rmask; tmp; tmp = tmp & (tmp-1))
            dp[mask] += inp[last][__builtin_ctz(tmp)];
    }

    for (mask = 1; mask < (1<<n); mask++)
        for (int submask = mask; submask; submask = mask & (submask-1))
            dp[mask] = max(dp[mask], dp[submask] + dp[mask^submask]);

    cout << dp[(1 << n) -1];    
}

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

lint gcd(lint x, lint y){
    lint r = x % y;
    while(r != 0){
        x = y;
        y = r;
        r = x % y;
    }
    return y;
}

bool solve(){
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n);
    lint MAX = 0;
    rep(i, n){
        cin >> a[i];
        MAX = max(MAX, a[i]);
    }
    if(MAX < k){
        return false;
    }
    lint g = a[0];
    rep(i, n){
        g = gcd(g, a[i]);
    }
    return k % g == 0;
}

int main(){
    if(solve()) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
)

func main(){
	var N , G int
	fmt.Scan(&N,&G)
	a := make([] int, N)
	ans1 := 0
	Min := 1000001
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
		ans1 = ans1 + a[i]
		Min = int(math.Min(float64(Min),float64(a[i])))
	}
	//fmt.Println(ans1,Min)
	ans2 := 0
	ans2 = G - ans1
	count := 0
	for i := Min; i <= ans2; i+=Min {
		//fmt.Println(i)
		count = count + 1
	}
	fmt.Println(N + count)
	
}

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

const int mod = 1e9 + 7;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}

int N;
int fact[52], invf[52];

int cc[52][52][52];
int dp(int n, int a, int b) {
    int &ret = cc[n][a][b];
    if(ret != -1) return ret;
    if(n == 0) return ret = 1;
    if(!a && !b) return ret = 0;

    ret = 0;
    for(int i = 0; i <= a + b; i++) {
        int j = a + b - i;

        for(int k = 0; k <= 50; k++) {
            if(abs(a - i) + 2 * k > n - a - b) break;

            ret += 1LL * invf[i] * invf[j] % mod * dp(n - a - b, abs(a - i) + k, k) % mod;
            ret %= mod;
        }
    }
    return ret;
}

int main() {
    fact[0] = 1;
    for(int i = 1; i < 52; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < 52; i++) {
        invf[i] = inv(fact[i]);
    }

    scanf("%d", &N);
    if(N == 1) {
        printf("1");
        return 0;
    }

    memset(cc, -1, sizeof(cc));
    int ans = 0;
    for(int i = 1; i < N; i++) {
        ans += dp(N - 1, i / 2, i - i / 2);
        ans %= mod;
    }
    ans = 1LL * ans * fact[N] % mod;

    printf("%d", ans);
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    ll N;
    cin >> N;
    map<char, ll> mp;

    string S;
    for(ll i = 0; i < N; i++){
        cin >> S;
        if(S[0] == 'M' || S[0] == 'A' || S[0] == 'R' || S[0] == 'C' || S[0] == 'H'){
            mp[S[0]]++;
        }
    }

    if(mp.size() < 3){
        cout << 0 << endl;
    }else{
        ll map_size = mp.size();
        vector<ll> cnt_mp(map_size);
        int ii = 0;
        for(auto itr = mp.begin(); itr != mp.end(); ++itr){
            cnt_mp[ii] = itr->second;
            ii++;
        }

        ll ans = 0;
        for(ll i = 0; i < map_size-2; i++){
            for(ll j = i+1; j < map_size-1; j++){
                for(ll k = j+1; k < map_size; k++){
                    ans += cnt_mp[i] * cnt_mp[j] * cnt_mp[k];
                }
            }
        }
        cout << ans << endl;

    }
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int n,s;char str[1000005];
int main(){
for(;;){
	scanf("%d%d%s",&n,&s,&str);if(!n) return 0; int i=0,ret=0;
	while(i<s){
		if(str[i]=='O'){ i++; continue;}
		int cnt=0; i++;
		while(i+1<s && str[i]=='O' && str[i+1]=='I'){ cnt++; i+=2;}
		ret+=(cnt-n+1<0?0:cnt-n+1);
	}
	printf("%d\n",ret);
}
}

Measured memory_bytes: 2008
N = int(input())

C = []
S = []
F = []
N -= 1

for i in range(N):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N):
    Ts = 0
    #Te = 
    for j in range(i, N):
        # print(i, j, Ts, Te)
        if Ts < S[j]:
            Ts = S[j]
        else:
            if Te % F[j] > 0:
                Ts = Te + F[j] - Te % F[j]
                
        Te = Ts + C[j]
        Ts = Te
        # print(i, j, Ts, Te, C[j])
    print(Te)
    
                    
print(0)


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll H,W,D;
  cin>>H>>W>>D;
  vector<pair<ll,ll>> vp(H*W);
  for(ll i = 0; i < H; i++){
    for(ll j = 0; j < W; j++) {
      int x;
      cin>>x;
      vp[x-1]=make_pair(i,j);
    }
  }
  vector<vector<ll>> d(D);
  for(ll i = 0; i < D; i++){
    d[i].push_back(0);
    ll t = i;
    ll s = i+D;
    while(s<H*W){
      d[i].push_back(*(d[i].end()-1)+abs(vp[t].first-vp[s].first)+abs(vp[t].second-vp[s].second));
      t+=D;
      s+=D;
    }
  }
  ll Q;
  cin>>Q;
  for(ll i = 0; i < Q; i++){
    ll L,R;
    cin>>L>>R;
    L--;
    R--;
    cout<<d[R%D][R/D]-d[L%D][L/D]<<endl;
  }
}

Measured memory_bytes: 6784
n=int(input())
s=[]
t=[]
for i in range(9):
    s.append([])
for i in range(100):
    t.append([[],[]])
for i in range(1,n+1):
    a=str(i)
    b=max(int(a[0]),int(a[len(a)-1]))
    c=min(int(a[0]),int(a[len(a)-1]))
    if b!=0 and c!=0:
        if b==c:
            s[b-1].append(i)
        elif int(a[0])<int(a[len(a)-1]):
            t[b*9+c][0].append(i)
        else:
            t[b*9+c][1].append(i)
ans=0
for i in range(9):
    x=len(s[i])
    ans+=x**2
for i in range(100):
    x=len(t[i][0])
    y=len(t[i][1])
    ans+=2*x*y
print(ans)

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

int main() {
  int n;
  int mat[16][16];
  
  while( scanf("%d", &n), n ) {
    fill(mat[0], mat[15], 0);
    int x = n/2, y = n/2+1;
    for(int i=0; i<n*n; i++) {
      if(mat[y][x]) x=(x+n-1)%n, y=(y+1)%n;
      mat[y][x] = i+1;
      x=(x+1)%n, y=(y+1)%n;
    }
    
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	printf("%4d", mat[i][j]);
      }
      printf("\n");
    }
  }
  
  return 0;
}

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


using namespace std;

int main()
{
	string s;
	cin >> s;
    string org = s;
    bool judge = false;
    for(int start = 0; start < org.size()-1; start++){
    	for(int end = start; end < org.size(); end++){
            s = org;
        	string tmp = s.replace(start, end-start, "");
            //cerr << tmp << endl;
          	if(tmp == "keyence")
              judge = true;
        }
    }
    string answer = judge == true ? "YES" : "NO";
  cout << answer << endl;
}

Measured memory_bytes: 256
def main():
  mod=10**9+7
  n=int(input())
  m=len(input())
  dp=[[0]*(n+1) for _ in range(2)]
  dp[0][0]=1
  for i in range(n):
    for j in range(n+1):
      dp[(i+1)&1][j]=0
    for j in range(n):
      dp[(i+1)&1][j+1]=(dp[i&1][j]+dp[(i+1)&1][j+1])%mod
      dp[(i+1)&1][j]=(dp[(i+1)&1][j]+dp[i&1][j+1]*2)%mod
    dp[(i+1)&1][0]=(dp[(i+1)&1][0]+dp[i&1][0])%mod
  print(dp[n&1][m])
main()

Measured memory_bytes: 68244
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0)
		cout << (a + b) / 2 << "\n";
	else
		cout << (a + b) / 2 + 1 << "\n";
}

Measured memory_bytes: 3548
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if (n % 2 == 1) {
            System.out.println(0);
            return;
        }
        if (n < 10) {
            System.out.println(0);
            return;
        }
        long ans = 0;
        for (int i = 1 ; i < 30 ; i++) {
            ans += n / (long) (2 * Math.pow(5, i));
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 23764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    enum Color { white, gray, black }

    class Program
    {
        static readonly int INFTY = int.MaxValue;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[,] table = new int[n, n];

            for (int i = 0; i < n; i++)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);

                for (int j = 0; j < n; j++)
                {
                    table[i, j] = input[j] == -1 ? INFTY : input[j];
                }
            }

            Console.WriteLine(Prim(table, n));
        }

        static int Prim(int[,] table, int n)
        {
            int i, nodeId, minCost;
            int[] minCostArr = new int[n];
            int[] parents = new int[n];
            Color[] colors = new Color[n];

            for (i = 0; i < n; i++)
            {
                minCostArr[i] = INFTY;
                parents[i] = -1;
            }

            minCostArr[0] = 0;

            while (true)
            {
                minCost = INFTY;
                nodeId = -1;

                for (i = 0; i < n; i++)
                {
                    if (colors[i] != Color.black && minCostArr[i] < minCost)
                    {
                        minCost = minCostArr[i];
                        nodeId = i;
                    }
                }

                if (minCost == INFTY) break;

                colors[nodeId] = Color.black;

                for (i = 0; i < n; i++)
                {
                    if (colors[i] != Color.black && table[nodeId, i] != INFTY)
                    {
                        if (table[nodeId, i] < minCostArr[i])
                        {
                            minCostArr[i] = table[nodeId, i];
                            parents[i] = nodeId;
                            colors[i] = Color.gray;
                        }
                    }
                }
            }

            int ret = 0;
            for (i = 0; i < n; i++)
            {
                if (parents[i] != -1) ret += table[i, parents[i]];
            }
            return ret;
        }
    }
}

Measured memory_bytes: 9228
n, x = list(map(int, input().split()))
s = list(map(int,input().rstrip().split()))

s.sort()
sum = 0
cnt = 0
flg = True

for ss in s:
    cnt += 1
    sum += ss

    if(sum > x):
        print(cnt-1)
        flg = False
        break

if(flg):
    if (sum < x):
        print(cnt - 1)
    else:
        print(cnt)




Measured memory_bytes: 3316
long a[16][16],dp[1<<16],sum[1<<16];
i,j,I;
main(n)
{
	scanf("%d",&n);
	for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%ld",a[i]+j);
	for(I=0;I<1<<n;I++)
	{
		for(i=0;i<n;i++)for(j=0;j<n;j++)if(I&1<<i&&I&1<<j)sum[I]+=a[i][j];
		for(j=I;~j;dp[I]=fmax(dp[I],dp[j]+sum[I&~j--]/2))j&=I;
	}
	printf("%ld",dp[I-1]);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double PI = acos(-1.0);
int Uw, Uh, A, B, AB;
struct Point {
	double x, y;
	Point() {}
	Point(double _x, double _y) : x(_x), y(_y) {}
	double Dis() {
		return sqrt(x * x + y * y);
	}
	friend Point operator + (const Point &a, const Point &b) {
		return Point(a.x + b.x, a.y + b.y);
	}
	friend Point operator - (const Point &a, const Point &b) {
		return Point(a.x - b.x, a.y - b.y);
	}
	friend Point operator * (const Point &a, const double &b) {
		return Point(a.x * b, a.y * b);
	}
	friend Point operator / (const Point &a, const double &b) {
		return Point(a.x / b, a.y / b);
	}
}l, r, mid;
double RA, RB;
struct Circle {
	Point O;
	double R;
	Circle() {}
	Circle(Point _O, double _R) : O(_O), R(_R) {}
}CA;
double S(Circle X, Circle Y) {
	if (X.R < Y.R) {
		swap(X, Y);
	}
	double d = (X.O - Y.O).Dis();
	if (d + EPS > X.R + Y.R) {
		return 0;
	}
	if (d < X.R - Y.R + EPS) {
		return PI * Y.R * Y.R;
	}
	double alpha = acos((X.R * X.R + d * d - Y.R * Y.R) / (2 * X.R * d));
	double beta = acos((Y.R * Y.R + d * d - X.R * X.R) / (2 * Y.R * d));
	return alpha * X.R * X.R + beta * Y.R * Y.R - X.R * d * sin(alpha);
}
int main() {
	while (scanf("%d%d%d%d%d", &Uw, &Uh, &A, &B, &AB) && (Uw || Uh || A || B || AB)) {
		RA = sqrt(A / PI);
		RB = sqrt(B / PI);
		bool flag = 0;
		if (RA < RB) {
			swap(RA, RB);
			flag = 1;
		}
		if (RA * 2 > min(Uw, Uh) || RB * 2 > min(Uw, Uh)) {
			printf("impossible\n");
			continue;
		}
		CA = Circle(Point(RA, RA), RA);
		l = Point(RA, RA);
		r = Point(Uw - RB, Uh - RB);
		if (S(CA, Circle(r, RB)) > AB) {
			printf("impossible\n");
			continue;
		}
		int cnt = 0;
		while (cnt <= 100) {
			cnt++;
			mid = (l + r) / 2;
			if (S(CA, Circle(mid, RB)) < AB) {
				r = mid;
			} else {
				l = mid;
			}
		}
		if (flag) {
			printf("%.10f %.10f %.10f %.10f %.10f %.10f\n", l.x, l.y, RB, CA.O.x, CA.O.y, CA.R);
		} else {
			printf("%.10f %.10f %.10f %.10f %.10f %.10f\n", CA.O.x, CA.O.y, CA.R, l.x, l.y, RB);
		}
	}
	return 0;
}

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

int n;
vector<int> digits, rdigits;

int main(void){
    // Here your code !
    scanf("%d", &n);

    while(n){digits.push_back(n % 10); n /= 10;}
    rdigits = digits;
    reverse(rdigits.begin(), rdigits.end());
    if (rdigits == digits) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

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

  int ans = 0;
  rep(i, n) {
    ans += b[a[i]-1];
    if((a[i-1] + 1 ) == a[i]) ans+= c[a[i-1]-1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    a=[parseInt(readline()) for i in 1:5]
    modten=[i%10+10*(i%10==0) for i in a]
    smod=sort(modten,rev=true)
    ans=0
    for i in 1:5
        for j in 1:5
            if smod[i]==modten[j]
                ans+=a[j]
                if i<5
                    ans+=10-modten[j]
                end
                modten[j]=100
                break
            end
        end
    end
    println(ans)
end
main()

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

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

    if (a + b > c + d)
        cout << "Left" << endl;
    else if (a + b < c + d)
        cout << "Right" << endl;
    else
        cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
long long a[1000],n;
int main()
{
	long long ans,sum1,sum2;
	scanf("%d",&n);
	sum1=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum1+=a[i];
	}
	ans=10000000;
	sum2=0;
	for(int i=1;i<=n;i++){
		sum1-=a[i];
		sum2+=a[i];
		ans=min(abs(sum1-sum2),ans);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1005
#define ll long long
#define ld double
#define mod 998244353
using namespace std;	
int n, d;
int tu(int x)
{
	int res = x % d;
	if(res == 0) res += d;
	return res; 
}
struct th
{
	int a[maxn][maxn];
	th()
	{
		memset(a, 0, sizeof(a));
	}
	void ins(int x, int y)
	{
		a[x][y]++;
	}
	void build()
	{
		for(int i = 1; i <= d; i++)
			for(int j = 1; j <= d; j++)
				a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
	}
	int q(int l, int r, int x, int y)
	{
		int ans = a[r][y] - a[l - 1][y] - a[r][x - 1] + a[l - 1][x - 1];
		return ans;	
	} 
}q1, q2;
int s[maxn][maxn];
bool check(int t)
{
	for(int i = 1; i <= d; i++)
		for(int j = 1; j <= d; j++)
		{
			int tp[2][3], pl[2][4];
			pl[0][3] = pl[1][3] = d + 1;
			pl[0][0] = pl[1][0] = 1;
			if(i + t <= d + 1)
				tp[0][0] = 0, tp[0][1] = 1, tp[0][2] = 0, 
				pl[0][1] = i, pl[0][2] = i + t;
			else
				tp[0][0] = 1, tp[0][1] = 0, tp[0][2] = 1, 
				pl[0][1] = i + t - d, pl[0][2] = i;
			
			if(j + t <= d + 1)	
				tp[1][0] = 0, tp[1][1] = 1, tp[1][2] = 0, 
				pl[1][1] = j, pl[1][2] = j + t;	
			else
				tp[1][0] = 1, tp[1][1] = 0, tp[1][2] = 1, 
				pl[1][1] = j + t - d, pl[1][2] = j;
			bool fl = 1;
			for(int x = 0; x < 3; x++)
				for(int y = 0; y < 3; y++)
					if(tp[0][x] && tp[1][y]) continue;
					else
					{
						if(tp[0][x] + tp[1][y]) 
						{
							if(q1.q(pl[0][x], pl[0][x + 1] - 1, pl[1][y], pl[1][y + 1] - 1)) fl = 0;
						}
						else
							if(q2.q(pl[0][x], pl[0][x + 1] - 1, pl[1][y], pl[1][y + 1] - 1)) fl = 0;
					}
			if(fl) 
			{
			//	cout<<"CAN"<<i<<" "<<j<<" "<<t<<endl; 
				return 1;
			}
		}
	return 0;
}
int main()
{

	scanf("%d%d", &n, &d);
	for(int i = 0; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		s[tu(x)][tu(y)]++;
	}
	int mxs = 0;
	for(int i = 1; i <= d; i++)
		for(int j = 1; j <= d; j++)
			mxs = max(mxs, s[i][j]);
	int ns = 1;
	while(ns * ns < mxs) ns++;
	for(int i = 1; i <= d; i++)
		for(int j = 1; j <= d; j++)
		{
			if(ns * (ns - 1) < s[i][j]) q1.ins(i, j);
			if((ns - 1) * (ns - 1) < s[i][j]) q2.ins(i, j);
		}
	q1.build(), q2.build();
	int l = 1, r = d;
	while(l < r)
	{
		int mid = (l + r) >> 1;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%d\n", (ns - 1) * d + l - 1);
	return 0;
} 
/*
bbbbbb
bababa

*/

Measured memory_bytes: 12032
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def cal(x,y,f):
    return (x+y*W)*2+f

def dijkstra(lines,N,s):
    weight = [INF]*N
    weight[s] = 0
    def search(s,w_0,q,weight):
        for t,w in lines[s]:
            w += w_0
            if weight[t] > w:
                heapq.heappush(q,[w,t])
                weight[t] = w
    q = [[0,s]]
    heapq.heapify(q)
    while q:
        w,n = heapq.heappop(q)
        search(n,w,q,weight)
    return weight


dxr = [ 1, 1, 1, 1, 1, 2, 2, 2, 3]
dyr = [-2,-1, 0, 1, 2,-1, 0, 1, 0]

dxl = [-1,-1,-1,-1,-1,-2,-2,-2,-3]
dyl = [-2,-1, 0, 1, 2,-1, 0, 1, 0]

while True:
    W,H = inpl()
    if W == 0:
        break
    ss = [list(input().split()) for _ in range(H)]

    N = W*H*2+2
    S = W*H*2
    T = W*H*2+1
    lines = defaultdict(set)
    for x in range(W):
        for y in range(H):
            if ss[y][x] == 'S':
                lines[S].add((cal(x,y,0),0))
                lines[S].add((cal(x,y,1),0))
            if ss[y][x] == 'T':
                lines[cal(x,y,0)].add((T,0))
                lines[cal(x,y,1)].add((T,0))
                continue
            if ss[y][x] == 'X':
                continue
            else:
                f = 0 # 次が右足
                for i in range(9):
                    tx = x + dxr[i]
                    ty = y + dyr[i]
                    if (0 <= tx < W) and (0 <= ty < H):
                        if ss[ty][tx] == 'S' or ss[ty][tx] == 'T':
                            cost = 0
                        elif ss[ty][tx] == 'X':
                            continue
                        else:
                            cost = int(ss[ty][tx])
                        lines[cal(x,y,0)].add((cal(tx,ty,1),cost))

                f = 1 # 次が左足
                for i in range(9):
                    tx = x + dxl[i]
                    ty = y + dyl[i]
                    if (0 <= tx < W) and (0 <= ty < H):
                        if ss[ty][tx] == 'S' or ss[ty][tx] == 'T':
                            cost = 0
                        elif ss[ty][tx] == 'X':
                            continue
                        else:
                            cost = int(ss[ty][tx])
                        lines[cal(x,y,1)].add((cal(tx,ty,0),cost))

    weights = dijkstra(lines,N,S)
    if weights[T] == INF:
        print(-1)
    else:
        print(weights[T])



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

int main()
{
  while (true)
  {
    int n;
    cin >> n;
    if (!n)
    {
      break;
    }
    int h[101];
    for (int i=0; i<=n; i++)
    {
      cin >> h[i];
    }

    int def[4] = { h[1]-h[0],
		   h[2]-h[1],
		   h[3]-h[2],
		   h[4]-h[3] };

    int candi[3] = {def[0], 0, 0};
    int candc[3] = {1, 0, 0};
    int candn = 1;
    for (int i=1; i<4; i++)
    {
      bool candf = true;
      for (int j=0; j<candn; j++)
      {
	if (def[i] == candi[j])
	{
	  ++candc[j];
	  candf = false;
	  break;
	}
      }
      if (candf)
      {
	candi[candn] = def[i];
	candc[candn] = 1;
	++candn;
      }
    }
    int maxi = 0;
    for (int i=1; i<3; i++)
    {
      if (candc[maxi] < candc[i])
      {
	maxi = i;
      }
      else if (candc[maxi] == candc[i])
      {
	maxi = ((candi[maxi] > candi[i])? maxi : i);
      }
    }
    int D = candi[maxi];

    int x = 0;
    int flag = 0;
    for (int i=1; i<=n; i++)
    {
      if (h[i] != h[0]+D*(i-flag))
      {
	if (flag)
	{
	  x = 0;
	  break;
	}

	x = i;
	flag = 1;
      }
    }
    cout << h[x] << endl;
  }

  return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

/////////////////////////////////////////////////////////////
class ModuloOperator {
 public:
  ll modulo;

  ModuloOperator(ll modulo) { this->modulo = modulo; }

  ll add(ll a, ll b) {
    ll ret = a + b;
    ret %= modulo;
    return ret;
  }

  ll sub(ll a, ll b) {
    ll ret = a - b;
    if (ret < 0)
      ret += modulo;
    else
      ret %= modulo;
    return ret;
  }

  ll mul(ll a, ll b) {
    ll ret = a * b;
    ret %= modulo;
    return ret;
  }

  ll div(ll a, ll b) { return mul(a, pow(b, modulo - 2)); }

  ll pow(ll x, ll y) {
    ll res = 1LL;

    x %= modulo;

    while (y > 0) {
      if (y & 1) {
        res = mul(res, x);
      }

      y = y >> 1;
      x = mul(x, x);
    }

    return res;
  }
};
/////////////////////////////////////////////////////////////

const int MAX_N = (int)(3e5 + 5);
const int MAX_LOG = (int)(6e1 + 1);
const ll MOD = (ll)(1e9 + 7);

int n;
ll a[MAX_N];

int cnt[MAX_N];

ModuloOperator mo(MOD);

void add_to_cnt(ll t) {
  for (int i = 0; i < MAX_LOG; ++i) {
    if (t >> i & 1LL) cnt[i] += 1;
  }
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(a[i]));
  }

  ll ans = 0LL;

  add_to_cnt(a[0]);

  for (int i = 1; i < n; ++i) {
    ll tmp = a[i];

    ll base = 1LL;

    for (int j = 0; j < MAX_LOG; ++j) {
      int oz = (tmp >> j & 1LL) ? 1 : 0;
      ll times = oz == 1 ? i - cnt[j] : cnt[j];
      ll commit = mo.mul(base, times);

      ans = mo.add(ans, commit);
      base = mo.mul(base, 2LL);
    }

    add_to_cnt(a[i]);
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val n = readLine()!!
    val result = when {
        n[0] == n[1] && n[1] == n[2]  -> "Yes"
        n[1] == n[2] && n[2] == n[3]  -> "Yes"
        else -> "No"
    }
    println(result)
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<vector<map<int, ll>>> dp(N+1, vector<map<int, ll>>(2));
    vector<vector<map<int, bool>>> flg(N+1, vector<map<int, bool>>(2));
    dp[0][0][0] = 0;

    rep(i, N) {
        rep(j, 2) {
            for (auto &p : dp[i][j]) {
                int k = p.first, ni = i+1, nk = k;
                rep(nj, 2) {
                    if (j && nj) continue;
                    if (nj) nk++;
                    
                    if (nk < (ni-1)/2 || (ni+1)/2 < nk) continue;

                    if (nj) {
                        if (dp[ni][nj].count(nk)) chmax(dp[ni][nj][nk], dp[i][j][k] + A[i]);
                        else dp[ni][nj][nk] = dp[i][j][k] + A[i];
                    } else {
                        if (dp[ni][nj].count(nk)) chmax(dp[ni][nj][nk], dp[i][j][k]);
                        else dp[ni][nj][nk] = dp[i][j][k];
                    }
                }
            }
        }
    }

    ll ans = max(dp[N][0][N/2], dp[N][1][N/2]);
    cout << ans << endl;
}


Measured memory_bytes: 94548
#include <iostream>
#include <limits.h>
#include <vector>
#include <string>

using namespace std;

int main()
{
  int N;

  cin >> N;

  int first = N/100;
  int second = N%100;

  bool first_is_mm = first < 13 && first > 0;
  bool second_is_mm = second < 13 && second > 0;

  string ans;

  if (first_is_mm && second_is_mm)
    ans = "AMBIGUOUS";
  else if (first_is_mm && !second_is_mm)
    ans = "MMYY";
  else if (!first_is_mm && second_is_mm)
    ans = "YYMM";
  else
    ans = "NA";
  
  cout << ans << endl;

  return 0;
}

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

int main() {
    long a, b;
    cin >> a >> b;

    if (a % 2 == 1 && b % 2 == 1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
    int N, C; cin >> N >> C;
    vector<T> program(N);
    rep(i,N){
        int s, t, c; cin >> s >> t >> c;
        program[i] = T(s,t,c);
    }

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

    vector<T> record;
    record.push_back(program[0]);

    rep1(i,N-1){
        T now = program[i]; bool flag = true;

        rep(j, record.size()){
            if(get<2>(record[j]) == get<2>(now)){
                if(get<1>(record[j]) <= get<0>(now)){
                    record[j] = now;
                    flag = false; break;
                }
            } else {
                if(get<1>(record[j]) < get<0>(now)){
                    record[j] = now;
                    flag = false; break;
                }
            }
        }

        if(flag) record.push_back(now);

        
    }

    cout << record.size() << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector <double>  v(N);

    for(int i = 0; i < N; i++)
    {
        cin >> v[i];
    }

    sort(v.rbegin(), v.rend());
    double sum = 0;

    long divide = 2;
    for(int i = 0; i < N - 2; i++)
    {
        sum += v[i] / divide;
        divide *= 2;
    }

    sum += (v[N - 2] + v[N - 1]) / divide;

    cout << setprecision(10)<<  sum << endl;
    return 0;  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int main(){
    ll n;
    scanf("%lld",&n);
    ll a[n+1];
    ll sum=0;
    for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);	
		sum=(sum+a[i])%mod;
	} 
	ll ans=0;
	for(int i=1;i<n;i++){
		sum=(sum+mod-a[i])%mod;
		ans=(ans+a[i]*sum)%mod;
	}
	cout<<ans%mod<<endl;
}

Measured memory_bytes: 5244
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 200005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int n;
struct interval { int a, b; } p[maxn];

inline bool cmp(interval x, interval y) {
    return x.b < y.b || (x.b == y.b) && (x.a < y.a);
}

int main() {
    n = read();
    for (reg int i = 1; i <= n; i++) p[i].a = read(), p[i].b = read();
    sort(p + 1, p + n + 1, cmp);
    reg int cur = 0;
    for (reg int i = 1; i <= n; i++) {
        if (cur + p[i].a > p[i].b) { puts("No"); return 0; }
        else cur += p[i].a;
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
int main(){
  rd(N);
  if(N<1000){
    wt_L("ABC");
    wt_L('\n');
  }
  else{
    wt_L("ABD");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N;
// {
//   rd(N);
//   wt( if[N<1000, "ABC", "ABD"] );
// }


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(void){

    int a[3];
    for(int i=0;i<3;i++)cin>>a[i];
    if(a[0]==a[1]&&a[0]!=a[2])cout<<"Open"<<endl;
    else cout<<"Close"<<endl;


    return 0;
}

Measured memory_bytes: 1156
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
	let s = read_line().split("").map(|e|e.parse().unwrap())
	.collect::<Vec<String>>();
	let vec = &s[1..(s.len() - 1 as usize)];
	let r = format!("{}{}{}",vec[0],vec[1..(vec.len() - 1 as usize)].iter().count(),vec[(vec.len() -1 as usize)]);
	println!("{}",r);
}


Measured memory_bytes: 4352