akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
from copy import copy
def resolve():
    n,a=map(int,input().split())
    X=list(map(lambda x:int(x)-a,input().split()))
    dp=defaultdict(int)
    dp[0]=1
    for x in X:
        ndp=copy(dp)
        for key,val in dp.items():
            ndp[key+x]+=val
        dp=ndp

    print(dp[0]-1)
resolve()

Measured memory_bytes: 40304
#include <cmath>
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(void) {
  int a, b, x;
  cin >> a >> b >> x;
  double ans;
  if(2 * x - a * a * b > 0)
    ans = 180.0
          * atan((long double)(2 * (a * a * b - x))
                 / (long double)(a * a * a))
          / acos(-1);
  else
    ans = 180.0
          * atan((double)(a * b * b) / (double)(2 * x))
          / acos(-1);
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>

using namespace std;
int main(void) {
	int N;
	bool isYes = true;
	string W[100];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		cin >> W[i];
		if (i != 0) {
			if (W[i].front() != W[i - 1].back()) {
				isYes = false;
				break;
			}
		}
		for (int j = 0; j < i; j++) {
			if (W[i] == W[j]) {
				isYes = false;
			}
		}

		if (isYes == false) {
			break;
		}
	}

	if (isYes == true) {
		printf("Yes");
	} else {
		printf("No");
	}

	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	S := readString()
	if S == "hi" ||
		S == "hihi" ||
		S == "hihihi" ||
		S == "hihihihi" ||
		S == "hihihihihi" {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")

}


Measured memory_bytes: 640
n = int(input())
arr = list(map(int, input().split()))

arr.sort(reverse=True)

if n % 2 == 0:
    print(arr[0] + sum(arr[1:1 + (n - 2) // 2]) * 2)
else:
    print(arr[0] + sum(arr[1:1 + (n - 2) // 2]) * 2 + arr[1 + (n - 2) // 2])

Measured memory_bytes: 31608
N, A, B = gets.split.map(&:to_i)
vs = gets.split.map(&:to_i)
                                      
MAX = 51
C = Array.new(MAX) { Array.new(MAX, 0) }
         
def comb_table                          
  (0..N).each do |i|
    (0..i).each do |j|
      if j == 0 || j == i
        C[i][j] = 1
      else
        C[i][j] = (C[i-1][j-1]+C[i-1][j])
      end
    end
  end
end

comb_table
rvs = vs.sort.reverse

max_average = 0.0
A.times do |i|
  max_average += rvs[i]
end
max_average /= A

puts(max_average)

a_th_val_num = 0
a_th_val_pos = 0

N.times do |i|
  if rvs[i] == rvs[A-1]
    a_th_val_num += 1
    a_th_val_pos += 1 if i < A
  end
end

cnt = 0
if a_th_val_pos == A
  while a_th_val_pos <= B
    cnt += C[a_th_val_num][a_th_val_pos]
    a_th_val_pos += 1
  end
else
  cnt += C[a_th_val_num][a_th_val_pos]
end

puts(cnt)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);
 
int main(){
  string s, t;
  cin >> s >> t;
  int n = sz(s);
  vector<set<int>> st(26);
  for (int i = 0; i < n; i++) {
    st[s[i] - 'a'].insert(i);
    st[s[i] - 'a'].insert(i + n);
  }
  ll res = 0;
  ll cnt = 0;
  int m = sz(t);
  int id = -1;
  for (int i = 0; i < m; i++) {
    if (st[t[i] - 'a'].empty()) {
      cout << -1 << endl;
      return 0;
    }
    auto itr = *st[t[i] - 'a'].upper_bound(id);
    if (itr >= n) itr %= n, cnt++;
    id = itr;
  }
 
  cout << cnt * n + id + 1 << endl;
  return 0;
} 

Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int n;
  cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  bool ja=true;
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0) ja=false;
    }
  }
  if(ja) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

char s[N];

int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	scanf("%s",s+1);

	int len=strlen(s+1);
	ll sum=0;
	for(int i=1;i<=len;++i){
		sum+=s[i]-'0';
	}

	if(sum%9==0) puts("Yes");
	else puts("No");

    return 0;
}

Measured memory_bytes: 3776
#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>

/* http://d.hatena.ne.jp/komiyam/20120118/1326812613 */
std::vector<int> z_array(const std::string &str) {
  int len = str.length();
  std::vector<int> z(len);
  z[0] = len;
  for (int i = 1, left = 0, right = 0; i < len; ++i){
    if (i > right) {
      left = right = i;
      for(; right < len && str[right - left] == str[right]; ++right) {}
      z[i] = right - left;
      right--;
    }
    else{
      int k = i - left;
      if(z[k] < right - i + 1){
	z[i] = z[k];
      }
      else{
	left = i;
	for(;right < len && str[right - left] == str[right]; right++);
	z[i] = right - left;
	right--;
      }
    }
  }
  return z;
}

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef vector<int> VI;

bool all_equal(const string &w) {
  int n = w.length();
  assert (n >= 1);
  REP(i, 1, n) {
    if (w[i] != w[0]) {
      return false;
    }
  }
  return true;
}

vector<bool> make_good(const vector<int> &za) {
  int n = za.size();
  vector<bool> ret(n + 1, true);
  REP(i, 1, n) {
    if (za[i] >= i) {
      for (int j = 2 * i; j <= za[i] + i && j <= n; j += i) {
	ret[j] = false;
      }
    }
  }
  return ret;
}

int main(void){
  string w;
  cin >> w;
  // Check if all the chars in w are equal
  if (all_equal(w)) {
    cout << w.length() << endl << 1 << endl;
    return 0;
  }
  // Check if w is a repetition
  int n = w.length();
  VI za = z_array(w);
  bool is_rep = false;
  int replen = -1;
  REP(i, 2, n) {
    if (n % i != 0) { continue; }
    // Is w a repetition of w[0 .. i]?
    if (za[i] >= n - i) {
      is_rep = true;
      replen = i;
      break;
    }
  }
  if (not is_rep) {
    cout << 1 << endl << 1 << endl;
    return 0;
  }
  // Check each position
  string rev_w = w;
  reverse(rev_w.begin(), rev_w.end());
  VI zr = z_array(rev_w);
  int cnt = 0;
  vector<bool> ga = make_good(za);
  vector<bool> gr = make_good(zr);
  
  REP(i, 1, n) {
    // w[0..i], w[i..n] are both good?
    if (ga[i] && gr[n - i]) {
      cnt += 1;
    }
  }
  cout << 2 << endl;
  cout << cnt << endl;
}


Measured memory_bytes: 5252
#include <atcoder/fenwicktree>
#include <iostream>

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n, q;
    std::cin >> n >> q;
    atcoder::fenwick_tree<long long> fw(n);
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        fw.add(i, a);
    }
    for (int i = 0; i < q; ++i) {
        int t, x, y;
        std::cin >> t >> x >> y;
        if (t == 0) fw.add(x, y);
        else std::cout << fw.sum(x, y) << "\n";
    }
    return 0;
}


Measured memory_bytes: 8252
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

class at {
private:
    int sign(long long a) {
        return (a >= 0 ? 1 : -1);
    }
public:
    void solve(istream& in, ostream& out) {
        int n;
        in >> n;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
        }
        
        long long ans = 1000LL*1000*1000*1000*1000*1000;
        for (int flag = 0; flag <= 1; ++flag) {
            long long sum = 0, res = 0;
            for (int i = 0; i < n; ++i) {
                sum += a[i];
                if (i % 2 == flag) {
                    if (sum <= 0) {
                        res += 1 - sum;
                        sum = 1;
                    }
                } else {
                    if (sum >= 0) {
                        res += 1 + sum;
                        sum = -1;
                    }
                }
            }
            ans = min(ans, res);
        }
        out << ans << "\n";
    }
};


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

	at solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#define max(a,b) (((a)>(b))?(a):(b))
typedef long long ll;
int main(){
	ll a=0,b=0,x;
	int n;
	scanf("%d",&n);
	while (n--){
		scanf("%lld",&x);
		b=max(b,x);
		a+=x;
	}
	if (b>=a-b) puts("No");else puts("Yes");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	long long int n, lmt, ans=0;
	cin>> n;

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

	lmt=(long long int)sqrt(n)+1;

	for(long long int i=1;i<lmt;i++){
		if(n%i==0 && 0<n/i && n/i-1>i){
			ans+=n/i-1;
			//cout<< i << " " << n/i-1 << endl;
		}
	}

	cout<< ans << endl;


}

Measured memory_bytes: 764
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	while(cin>>N) {
		string s = to_string(N);
		ll sum=0;
		REP(i, s.size()) {
			sum+=s[i]-'0';
		}
		
		cout<<(N%sum==0?"Yes":"No")<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
//#define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 705;

int n, m;
bool lnk[N][N];
int cnt[2];
int col[N];
bool f;

void dfs(int u, int c) {
    col[u] = c;
    ++cnt[c];
    for(int v = 1; v <= n; v++) {
        if(lnk[u][v]) {
            if(col[v] == -1) dfs(v, 1 - c);
            else if(col[v] == c) {
                f = false;
                return;
            }
        }
    }
}

pii num[N];
bool dp[N][N];

void run() {
    memset(col, -1, sizeof(col));
    memset(dp, 0, sizeof(dp));
    f = true;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++) {
            if(i != j) lnk[i][j] = 1;
        }
    for(int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        lnk[u][v] = lnk[v][u] = 0;
    }
    int tot = 0;
    for(int i = 1; i <= n; i++) {
        if(col[i] == -1) {
            cnt[0] = cnt[1] = 0;
            dfs(i, 0);
            num[++tot] = MP(cnt[0], cnt[1]);
        }
    }
    if(f == false) {
        cout << -1 << '\n';
        return;
    }
    dp[0][0] = 1;
    for(int i = 1; i <= tot; i++) {
        for(int j = 0; j <= n; j++) {
            if (j >= num[i].fi) dp[i][j] |= dp[i - 1][j - num[i].fi];
            if (j >= num[i].se) dp[i][j] |= dp[i - 1][j - num[i].se];
        }
    }
    int ans = 1e9;
    for(int i = 0; i <= n; i++) {
        if(dp[tot][i]) {
            ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
#ifdef Local
    freopen("../input.in", "r", stdin);
    freopen("../output.out", "w", stdout);
#endif
    while(cin >> n >> m) run();
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(lint i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int A[N],B[N];
  REP(i,N){
    cin>>A[i];
  }
  REP(i,N){
    cin>>B[i];
  }
  lint ans=1e9;;
  REP(c,1<<N){
    vector<pair<int,int> > v0,v1;
    REP(i,N){
      if((c>>i)&0b1){
        v0.push_back(make_pair((i%2?B[i]:A[i]),i));
      }else{
        v1.push_back(make_pair((i%2?A[i]:B[i]),i));
      }
    }
    if(v1.size()!=N/2)continue;
    // for(auto e:v0)cerr<<e.first<<" ";
    // cerr<<endl;
    // for(auto e:v1)cerr<<e.first<<" ";
    // cerr<<endl;
    sort(ALL(v0));
    sort(ALL(v1));
    vector<pair<int,int> > v;
    REP(i,N){
      if(i%2==0)v.push_back(v0[i/2]);
      else v.push_back(v1[i/2]);
    }
    bool f=true;
    FOR(i,1,N)if(v[i].first<v[i-1].first)f=false;
    if(!f)continue;
    // for(auto e:v)cerr<<e.first<<" ";
    // cerr<<endl;
    lint temp=0;
    REP(i,N)FOR(j,i+1,N){
      if(v[i].second>v[j].second)temp++;
    }
    // cerr<<temp<<endl<<endl;
    ans=min(temp,ans);
  }

  if(ans==1e9){
    cout<<-1<<endl;
  }else{
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll a,b,k;cin>>a>>b>>k;
    if(a-k>0){cout<<a-k<<" ";k-=a;}
    else {cout<<0<<" ";k-=a;}
  if(k<0)k=0;
    if(b-k>0)cout<<b-k<<" ";
    else cout<<0;
    return 0;  
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1000000000;
const int MOD = 1000000007;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<int>> g(n, vector<int>());
  rep(i, m){
    int t1, t2;
    cin >> t1 >> t2;
    --t1;
    --t2;
    g[t1].push_back(t2);
    g[t2].push_back(t1);
  }

  ll ans = 0;
  for(int i = 0; i < n; ++i){
    bool high = true;
    for(auto itr : g[i]){
      if(h[i] <= h[itr]){
        high = false;
        break;
      }
    }
    if(high) ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9068
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,k;
    string s;
    cin>>n>>k>>s;
    vector<int> a(0);
    int f=s[0]-'0';
    int cnt=0;
    if(!f) a.emplace_back(0);
    rep(i,n){
        if(f==(s[i]-'0')){
            cnt ++;
        }
        else{
            if(!f) cnt=-cnt;
            a.emplace_back(cnt);
            cnt=1;
            f =s[i]-'0';
        }
    }
    if(!f) cnt=-cnt;
    a.emplace_back(cnt);
    if(!f) a.emplace_back(0);
    int ans=0;
    cnt=0;
    n=a.size();
    int ss=0,t=0;
    rep(i,n){
        if(a[i]<0) cnt ++;
        if(cnt>k) break;
        ans +=abs(a[i]);
        t=i;
    }
    int now=ans;
    while(t+2<n){
        now =now-abs(a[ss])+a[ss+1]-a[t+1]+a[t+2];
        ss +=2;
        t +=2;
        ans=max(ans,now);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#define MAX_N 1000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){// this size is really ok??
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

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

  ll X,Y;
  cin>>X>>Y;
  if(X>Y) swap(X,Y);

  if((X+Y)%3!=0){
    cout<<0<<endl;
    return 0;
  }
  int num=(X+Y)/3;
  if(X<num){
    cout<<0<<endl;
    return 0;
  }

  int k=X-num;
  setComb();
  cout<<comb(num,k)<<endl;

  return 0;
}


Measured memory_bytes: 23680
import java.util.*;
import java.io.*;
 
class Main{
public static void main(String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	int n = Integer.parseInt(br.readLine());
  	int[] h = new int[n];
  	String[] s = br.readLine().split(" ");
  	for(int i=0;i<n;i++)
      h[i] = Integer.parseInt(s[i]);
  	int[] dp = new int[n];
  	dp[1] = Math.abs(h[1]-h[0]);
  	for(int i=2;i<n;i++)
      dp[i] = Math.min(Math.abs(h[i]-h[i-1])+dp[i-1],Math.abs(h[i]-h[i-2])+dp[i-2]);
      
      System.out.println(dp[n-1]);
    }
}

Measured memory_bytes: 44608
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MOD 1000000007
#define MAXN 200000

/*
Brute force on number of empty rooms.
All number of empty rooms x will be reachable as long as x <= k and x < n.
*/

LL fastExponentiation(LL base, int p) {
    if (p == 0)
        return 1;

    LL half = fastExponentiation(base, p/2);
    LL halfhalf = (half * half)%MOD;

    if (p%2 == 0)
        return halfhalf;
    else
        return (halfhalf * base)%MOD;
}

LL fact[MAXN + 3];

LL C(int n, int k) {
    if (k > n)
        return 0;

    LL numerator = fact[n];
    LL denomintator = fastExponentiation((fact[k] * fact[n - k])%MOD, MOD - 2);
    return (numerator * denomintator)%MOD;
}

int main() {
    fact[0] = 1;
    for (int i = 1; i <= MAXN; i++)
        fact[i] = (fact[i - 1] * i)%MOD;

    int n, k;
    cin >> n >> k;

    LL answer = 0;

    //There is at most min(n - 1, k) empty room
    for (int numEmpty = 0; numEmpty <= min(n - 1, k); numEmpty++) {
        LL waysToChooseEmptyRoom = C(n, numEmpty); //number of ways to choose empty rooms

        int numNonEmpty = n - numEmpty;
        int numToSpread = numEmpty;
        LL waysToSpread = C(numToSpread + numNonEmpty - 1, numNonEmpty - 1); //number of ways to spread the people to non-empty rooms

        answer += (waysToChooseEmptyRoom * waysToSpread)%MOD;
        answer %= MOD;
    }

    cout << answer << endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
    ll a, b, c, d, e , m, n, k, x, y, l,r, h, w;
    string s, t;
    ll ans = 0;
    double dans = 0;
    string sans = "Yes";
    vector<ll> ar;
    vector<string> sr;
    vector<vector<char>> arr;

    cin >> a >> b;

    ans = -1;
    ll i = 1;

    while(1){
        ll _a = i*0.08;
        ll _b = i*0.10;

        if(_a==a && _b==b){
            ans = i;
            break;
        }
        else if(_a > a && _b > b){
            break;
        }

        i++;
    }

    std::cout << ans << endl;

    // std::cout << sans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
import collections
import itertools as it
import math
import numpy as np

# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()
n = int(input())
a = list(map(int, input().split()))

for a_ in a:
  if a_ % 2 == 0:
    if a_ % 3 != 0 and a_ % 5 != 0:
      print('DENIED')
      break
else:
  print('APPROVED')

Measured memory_bytes: 12500
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void) {
    ll w, s;
    cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
/** author: __nishad__ **/

#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    ll n, m, i;
    string s;
    cin>>n>>m>>s;
    bool ans = true;

    for(i=0; i<n; i++){
        if(s[i] < 48 || s[i] > 57)
            ans = false;
    }
    if(s[n] != '-')
        ans = false;

    for(i=n+1; i<(n+m+1); i++){
        if(s[i] < 48 || s[i] > 57)
            ans = false;
    }

    cout<<(ans? "Yes" : "No");





}


Measured memory_bytes: 256
import numpy as np

N, M, C = [int(s) for s in input().split(" ")]
B = np.array([int(s) for s in input().split(" ")])
counter = 0
for _ in range(N):
    A = np.array([int(s) for s in input().split(" ")])
    if np.dot(A, B) + C > 0:
        counter += 1
print(counter)

Measured memory_bytes: 21544
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
#define N 100

int a[2][N] = {0};
int p[N] = {0};
int w[100];
int sum;
int u;
void dfs(int k, int n)
{
    int i;

    if(k == n)
    {
        int flag=0;
        for(i = 0; i < n ; i++)
            if(p[i]==w[i])flag++;

        if(flag==n) u=sum;
        sum++;
    }
    else
    {
        for(i = 0; i < n; i++)
        {
            if(a[0][i] == 0)
            {
                p[k] = a[1][i];
                a[0][i] = 1;

                dfs(k+1, n);

                p[k] = a[0][i] = 0;
            }
        }
    }
return ;
}

int main()
{
        int n, i;
        memset(a, 0, sizeof(a));
        memset(p, 0, sizeof(p));
        scanf("%d",&n);
        for(i = 0; i < n; i ++)
            a[1][i]=i+1;
           sum=1;
        for(int i=0;i<n;i++)
            scanf("%d",&w[i]);

        dfs(0, n);int a=u;
        for(int i=0;i<n;i++)
            scanf("%d",&w[i]);
            sum=1;
        dfs(0, n);int b=u;
        printf("%d",abs(a-b));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void)
{
  	int h, n, sum, tmp;
	cin >> h >> n;
    tmp = 0, sum = 0;
    for(int i=0;i<n;i++)
    {
        cin >> tmp;
        sum += tmp;
    }
    if(h <= sum)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
 	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

//I imitated Ant Book version 1: P.84.

int n,q,com,x,y;
int rank[10000],parent[10000];

int find(int x){
	if(x == parent[x])return x;
	else{
		return parent[x] = find(parent[x]);
	}
}

bool isSame(int x,int y){
	return find(x) == find(y);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);

	if(x == y)return;

	if(rank[x] < rank[y]){
		parent[x] = y;
	}else{
		parent[y] = x;
		if(rank[x] == rank[y])rank[x]++;
	}
}

int main(){

	scanf("%d %d",&n,&q);

	for(int i = 0; i < n; i++){
		rank[i] = 0;
		parent[i] = i;
	}

	for(int i = 0; i < q; i++){
		scanf("%d %d %d",&com,&x,&y);

		if(com == 1){
			if(isSame(x,y))printf("1\n");
			else{
				printf("0\n");
			}
		}else{
			if(isSame(x,y))continue;

			unite(x,y);
		}
	}

	return 0;
}


Measured memory_bytes: 2704
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
    int n;
    cin >> n;
    vector<ll> a(n),s(n+1);
    s[0] = 0;
    REP(i,n){
        cin >> a[i];
        s[i+1] = s[i]+a[i];
    }
    ll res = LLONG_MAX;
    REP(i,n){
        ll t1 = s[i];
        ll t2 = s[n]-t1;
        int itr1 = lower_bound(all(s),t1/2)-s.begin();
        int itr2 = lower_bound(all(s),t1+t2/2)-s.begin();
        for(int j=-1;j<=1;++j){
            for(int k=-1;k<=1;++k){
                int nt1 = itr1+j;
                int nt2 = itr2+k;
                if(0<nt1&&nt1<i&&i<nt2&&nt2<n){
                    vector<ll> ary = {s[nt1]-s[0],s[i]-s[nt1],s[nt2]-s[i],s[n]-s[nt2]};
                    chmin(res,*max_element(all(ary))-*min_element(all(ary)));
                }
            }
        }
    }
    put(res);
    return 0;
}


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

void gcd(int x, int y);

int main()
{
    int x, y;
    cin >> x >> y;

    gcd(x, y);
}

void gcd(int x, int y)
{
    int d;

    if (x < y)
    {
        swap(x, y);
    }

    // x = qy + r
    int r = x % y;

    if (r == 0)
    {
        cout << y << endl;
    }
    else
    {
        gcd(y, r);
    }
}


Measured memory_bytes: 3108
#include <stdio.h>
int main(){
  int i,n,T,c,t,r=1e9;
  scanf("%d%d",&n,&T);
  for(i=0;i<n;i++){
    scanf("%d%d",&c,&t);
    if(t>T)continue;
    if(r>c)r=c;
  }
  if(r==1e9)puts("TLE");
  else printf("%d",r);
  return 0;
}

Measured memory_bytes: 128
# 11　AtCoder Beginner Contest 128 C - Switches
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    d = [0]*n
    flag = True
    for j in range(n):
        if ((i>>j)&1):
            d[j] = 1
    for k in range(m):
        count = 0
        for l in range(1,s[k][0]+1):
            if d[s[k][l]-1]:
                count += 1
        if count%2!=p[k]:
            flag = False
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACB115A
{
    class Program
    {
        static void Main(string[] args)
        {
            int D;
            D = int.Parse(Console.ReadLine());
            if (D == 25)
            {
                Console.WriteLine("Christmas");
            }
            else if (D==24)
            {
                Console.WriteLine("Christmas Eve");
            }
            else if(D==23)
            {
                Console.WriteLine("Christmas Eve Eve");
            }
            else if(D==22)
            {
                Console.WriteLine("Christmas Eve Eve Eve");
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11220
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

bool judge(int m,vp &l0,vp &l){
    complex<double> c0(l0[1].fi-l0[0].fi,l0[1].se-l0[0].se);
    complex<double> t(1,0);
    complex<double> r(0,1);
    complex<double> c(l[1].fi-l[0].fi,l[1].se-l[0].se);
    bool found=false;
    rep(i,4){
        if(c0*t==c){
            found=true;
            break;
        }
        t*=r;
    }
    Rep(i,1,m-1){
        c0=complex<double>(l0[i+1].fi-l0[i].fi,l0[i+1].se-l0[i].se);
        c=complex<double>(l[i+1].fi-l[i].fi,l[i+1].se-l[i].se);
        found&=c0*t==c;
    }
    return found;
}

void run(){
    int n;
    cin>>n;
    if(!n)return;
    int m0;
    cin>>m0;
    vp l0(m0);
    rep(i,m0){
        int x,y;
        cin>>x>>y;
        l0[i]={x,y};
    }
    vi ans;
    rep(i,n){
        int m;
        cin>>m;
        vp l(m);
        rep(j,m){
            int x,y;
            cin>>x>>y;
            l[j]={x,y};
        }
        if(m!=m0)continue;
        bool found=judge(m,l0,l);
        reverse(all(l));
        found|=judge(m,l0,l);
        if(found)ans.pb(i+1);
    }
    rep(i,ans.size())cout<<ans[i]<<endl;
    cout<<"+++++"<<endl;
    run();
}


Measured memory_bytes: 3044
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

	int N;
	int p[100000];
	bool b[100000];

	int num = 0;

	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&p[i]);
	}

	for(int i=0;i<N;i++){
		if(p[i] == (i+1)){
			b[i] = true;
		}else{
			b[i] = false;
		}
	}

	for(int i=0;i<N;i++){
		if(b[i]){
			num++;
			if(i<N-1){
				if(b[i+1]){
					i++;
				}
			}
		}
	}

	printf("%d\n",num);


	return 0;
}


Measured memory_bytes: 640
abcde = []
for i in range(5):
    abcde.append(int(input()))

ans = 0
for i, a in enumerate(abcde):
    if a % 10 == 0:
        ans += a

b = abcde[0]
for a in abcde:
    if a % 10 != 0:
        if a % 10 < b:
            b = a % 10
        ans -= a % 10
        ans += a + 10
b = 10 - b

ans -= b
print(ans)


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string s;
	string code = "CODEFESTIVAL2016";
	int ans = 0;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i] != code[i]){
			ans++;
		}
	}

	cout << ans << endl;

	

	return 0;
}


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

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int INF = 10000;

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

	int n;
	cin >> n;

	int chmin[26];
	rep(i,26) chmin[i] = INF;

	rep(i,n){
		string s;
		cin >> s;

		int ch[26] = {};
		rep(j,s.size()) ch[s[j]-'a']++;
		rep(j,26) chmin[j] = min(chmin[j],ch[j]);
	}

	rep(i,26) cout << string(chmin[i], char('a' + i));
	cout << endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

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

    if(N == K) {
        cout << 0 << endl;
    } else if(N < K) {
        if(abs(N - K) < N) {
            cout << abs(N - K) << endl;
        } else {
            cout << N << endl;
        }
    } else if(N > K) {
        if(N % K == 0) {
            cout << 0 << endl;
        } else {
            ll amp = N % K;
            if(abs(amp - K) > amp) {
                cout << amp << endl;
            } else {
                cout << abs(amp - K) << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vs=vector<string>;
using vvi =vector<vector<int>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
int main(){
    int n;
    cin>>n;
    vvi c(n,vi(26));
    rep(i,n){
        string s;
        cin>>s;
        rep(j,s.size()){
            c[i][s[j]-'a']++;
        }
    }
    vc ans;
    rep(i,26){
        bool ok=true;
        int cnt=INF;
        rep(j,n){
            if(c[j][i]==0){
                ok=false;
                break;
            }
            else cnt=min(cnt,c[j][i]);
        }
        if(ok){
            rep(j,cnt)ans.push_back((char)(i+'a'));
        }
    }
    rep(i,ans.size())cout<<ans[i];
    cout<<endl;
    return 0;
}

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

//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,size_t b){return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
    laz.assign(2*n-1,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
  void update(int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<int,int> ch(n,
			  [](int a,int b){return a+b;},
			  [](int a,int b){return a+b;},
			  [](int a,int b){return a+b;},
			  0,0,
			  [](int a,int b){return a*b;});
  ch.build(n,vector<int>(n,0));
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<ch.query(s-1,t)<<endl;
    }else{
      cin>>t>>x;
      ch.update(t-1,t,x);
    }
  }
}


Measured memory_bytes: 5144
"use strict"
function main(arg) {
    let [X,K,D] = arg.trim().split("\n")[0].split(" ").map(Number)
    let history = [null,null,null]

    let x = Math.abs(X)
    let i = 0
    if (Math.abs(x - K * D) < Math.abs(x - K * (D-1))) {
        console.log(x - K * D)
        // console.log("aa")
        return
    } else {
        let t = Math.floor(x / D)
        i = t
        x = x - (t * D)
        // console.log(t)
    }

    for (; i < K; i++) {
        let a = Math.abs(x - D)
        let b = Math.abs(x + D)
        if (a < b) {
            x = x - D
        } else {
            x = x + D
        }
        history[0] = history[1]
        history[1] = history[2]
        history[2] = x
        // console.log(history)
        if (history[0] === history[2]) {
            // console.log((K-i) % 2)
            if ((K-i) % 2 === 1) {
                x = history[0]
            } else {
                x = history[1]
            }
            break
        }
    }
    console.log(Math.abs(x))
    // console.log(x)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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


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

    int N = S.size();
    int ans = INT_MAX;
    /* K をある値に決めたとき、K < i < N-K を満たす S[i] は自由に変えられる。
       なぜなら、例えば i = K+1 のとき、S[0:K+1] をフリップし、S[0:K] をフリップすれば
       S[0:K] は不変のまま S[K+1] を変えられるからである。
       従って、K >= N/2 であり、K を大きくしていって条件を満たさなくなる点を探す。
     */
    int il, ir;
    char c;
 
    if( N % 2 == 0 ){
        ans = N / 2;
        il = N / 2 - 1;
        ir = N / 2;
        c = S[il];
    }else{
        ans = (N - 1) / 2;
        il = ir = (N - 1) / 2;
        c = S[il];
    }
    while( il >= 0 && ir < N && S[il] == c && S[ir] == c ){
        ans++;
        il--;
        ir++;
    }
    

    // 解説PDFの実装
    /*for( int i = 0; i < N-1; ++i ){
        if( S[i] != S[i+1] ){
            int tmp = max( i+1, N-i-1 );
            ans = min( ans, tmp );
        }
    }
    if( ans == INT_MAX ) ans =  N;  // 文字列が全て同じとき
    */

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int R;
  cin >> R;
  double pi = 3.141592653589793238;
  printf("%.12lf\n", 2* pi *R);

  return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long INF = MOD*MOD;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k,ans;
string s,t;

int main(){
	cin >> s >> t;
	int azS[26] = {};
	int azT[26] = {};
	rep(i,s.size()){
		azS[s[i]-'a']++;
		azT[t[i]-'a']++;
	}
	sort(azS,azS+26);
	sort(azT,azT+26);
	
	bool frag = true;
	rep(i,26){
		if(azS[i] != azT[i]) frag = false;
	}
	if(frag) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 776