akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

bool is(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			return false;
		}
	}
	return true;
}

void solve(){
	int x;
	cin>>x;
	for(int i=x;;i++){
		if(is(i)){
			cout<<i;
			return;
		}
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = input()
for ni in n:
  if ni == "7":
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 9336
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
const int MAXN=100+7;
struct Edge{
	int to,nxt;
}e[MAXN*MAXN];
int head[MAXN],edge_num=1;
int n,m,dfn[MAXN],low[MAXN],dfs_clock;
bool isbri[MAXN*MAXN];
void add_edge(int u,int v){
	e[++edge_num].to=v; e[edge_num].nxt=head[u];
	head[u]=edge_num;
}
void Tarjan(int u,int inedge){
	dfn[u]=low[u]=++dfs_clock;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(!dfn[v]){
			Tarjan(v,i); low[u]=min(low[u],low[v]);
			if(dfn[u]<low[v]) isbri[i]=isbri[i^1]=1;
		}
		else if(i!=(inedge^1)) low[u]=min(low[u],dfn[v]);
	}
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v; scanf("%d %d",&u,&v);
		add_edge(u,v); add_edge(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]) Tarjan(i,0);
	}
	int ans=0;
	for(int i=1;i<=m*2+1;i++){
		if(isbri[i]) ++ans;
	}
	printf("%d\n",ans>>1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define For(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

int N;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
}

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

//Sample
int main()
{
  int N;
  long ans = 0;
  string S;

  cin >> N;
  cin >> S;

  long buf1 = 0, buf2 = 0, buf3 = 0;
  for(int i = N - 1; i >= 0; i--){
    if(S[i] == 'R')buf1++;
    if(S[i] == 'G')buf2++;
    if(S[i] == 'B')buf3++;
  }
  ans = buf1 * buf2 * buf3;

  for(int i = 0; i <= N - 3; i++){
    for(int j = i + 1; j <= N - 2; j++){
      if(S[i] != S[j]){
        int k = 2 * j - i;
        if(k < N){
          if(S[i] != S[k] && S[j] != S[k]) ans--;
        }
      }
    }
  }

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


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

int main() {
  int n;
  cin >> n;
  vector<pair<int64_t,int64_t>> vec(n);
  rep(i,n) cin >> vec[i].first >> vec[i].second;
  vector<pair<int64_t,int64_t>> vec2(n);
  rep(i,n){
    vec2[i].first=vec[i].first-vec[i].second;
    vec2[i].second=vec[i].first+vec[i].second;
  }
  sort(vec2.begin(),vec2.end());
  int64_t ans=0;
  int64_t now=-1000000000;
  rep(i,n){
    if(now<=vec2[i].first){
      ans++;
      now=vec2[i].second;
    }
    else now=min(now,vec2[i].second);
  }
  cout << ans << endl;
  

}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;

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

/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    ll sum = 0;

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

    ll ans = 1e9;
    for (int i = 1;i <= 100;i++){
        sum = 0;
        for (int j = 0;j < n;j++){
            sum += pow(x[j] - i,2);
        }
        ans = min(ans,sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

acc = []
for i in range(n+1):
    if i==0:
        acc.append(0)
    else:
        if s[i-2:i]=="AC":
            acc.append(acc[-1]+1)
        else:
            acc.append(acc[-1])
for l,r in lr:
    print(acc[r]-acc[l])


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int k, s;
    cin >> k >> s;

    // 処理
    int u   = 0;
    int ans = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            u = s - (i + j);
            if (u >= 0 && u <= k) ans++;
        }
    }

    // 出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define M 1e6+9
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
#define int long long
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}

// ll n,k,a,b,c,d,x,y,z,m,l;
// ll ans;
// vecl arr(N);
// ll dp[509][509];
// ll pre[N];



void test_case() {

    
   ll n,k;
   cin>>n>>k;

   vector<ld> arr(n), temp(n);
   rep(i,n) {
       cin>>arr[i];
   }

   for(int i=0; i<n; i++)
    {
        temp[i] = (arr[i] + 1)/2;
    }

    ld ans = 0;
    ld sum =0;
    for(int i=0; i<k; i++) {
        sum+= temp[i];
    }

    ans = sum;

    for(int i=k; i<n; i++) {
        sum+= temp[i] - temp[i-k];
        ans = max(ans, sum);
    }

    cout<<ans<<endl;
   








}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    // cin >> t;
    while(t--)
    {   
        test_case();
    }
}


Measured memory_bytes: 9500
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int d = Integer.parseInt(in.next());

            double ans = 0;
            ans = Math.ceil((double) n / (double) (2 * d + 1));

            // 出力
            out.println((int) ans);

        }

    }
}



Measured memory_bytes: 21844
#!/usr/bin/env python

S=input()

center=int(len(S)/2-1)

while(True):
    s1=S[0:center]
    s2=S[center:center+center]
    # print("debug","s1:",s1,"s2:",s2)
    if(s1==s2):
        print(len(s1)*2)
        break
    center-=1


Measured memory_bytes: 3064
//file_name:ABC47_C.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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


    ll ans = 0;

    rep(i,s.size()-1){
        if(s[i]!=s[i+1])ans++;
    }

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



Measured memory_bytes: 512
#include<stdio.h>
int main(void){

int H,W,i,t;

for(;;){
scanf("%d %d",&H,&W);

if(H==0&&W==0){
break;
}


	for(i=1;i<=H;i++){
		
		for(t=1;t<=W;t++){
			printf("#");
		}

		printf("\n");
	}
	printf("\n");
}

 return 0;
}

Measured memory_bytes: 2604
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

void solve() {
  vector<string> d = {"dreamer", "dream", "eraser", "erase"};
  REP(i,4) reverse(ALL(d[i]));
  string s;
  cin >> s;
  reverse(ALL(s));
  for (int p = 0; p < int(s.size());) {
    bool flag = false;
    for (string t: d) {
      if (p + int(t.size()) <= int(s.size()) &&
          s.substr(p, int(t.size())) == t) {
        p += t.size();
        flag = true;
        break;
      }
    }
    if (!flag) { cout << false << endl; return; }
  }
  cout << true << endl;
  return;
}


Measured memory_bytes: 512
#include<iostream>
int main(){
int W,H,x,y,r;
std::cin>>W>>H>>x>>y>>r;
if((x>=r)&&(y>=r)&&(W-r>=x)&&(H-r>=y)){
std::cout<<"Yes"<<std::endl;
}
else{
std::cout<<"No"<<std::endl;
}
return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> vec;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    vec.push_back(make_pair(x, y));
  }
  int ans = n;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      long long dx = vec[i].first - vec[j].first;
      long long dy = vec[i].second - vec[j].second;
      int num = n;
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < n; l++) {
          if (vec[k].first + dx == vec[l].first &&
              vec[k].second + dy == vec[l].second) {
            num--;
          }
        }
      }
      ans = min(ans, num);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N,L = map(int, raw_input().split())
a = map(int, raw_input().split())

for i in range(N-1):
    if a[i]+a[i+1]>=L:
        print "Possible"
        for j in range(i):
            print j+1
        for j in range(N-2,i,-1):
            print j+1
        print i+1
        break
else:
    print "Impossible"


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

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	const T init;
	const F f;
	int sz;
	vector<T> seg;
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

int main() {
	int n; cin >> n;
	pair<int, int> p[n];
	for(auto &e : p) {
		cin >> e.first >> e.second;
		e.second++;
	}
	sort(p, p + n);
	SegmentTree<int> segL(n, 0, [](int lhs, int rhs) {
		return max(lhs, rhs);
	});
	SegmentTree<int> segR(n, 1e9 + 10, [](int lhs, int rhs) {
		return min(lhs, rhs);
	});
	for(int i = 0; i < n; ++i) {
		segL.replace(i, p[i].first);
		segR.replace(i, p[i].second);
	}
	int ans = 0;
	for(int i = 0; i < n - 1; ++i) {
		{
			int l1 = p[i].first;
			int r1 = p[i].second;
			int l2 = max(segL.get(0, i), segL.get(i + 1, n));
			int r2 = min(segR.get(0, i), segR.get(i + 1, n));
			ans = max(ans, max(0, (r1 - l1)) + max(0, (r2 - l2)));
		}
		{
			int l1 = segL.get(0, i + 1);
			int r1 = segR.get(0, i + 1);
			int l2 = segL.get(i + 1, n);
			int r2 = segR.get(i + 1, n);
			ans = max(ans, max(0, (r1 - l1)) + max(0, (r2 - l2)));
		}
	}
	cout << ans << '\n';
	return 0;
}

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

void solve(long long N, long long K, std::vector<long long> p)
{
    sort(p.begin(), p.end());
    int sum = 0;
    for (int i = 0; i < K; i++)
    {
        sum += p[i];
    }
    cout << sum << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> p(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 3688
N = int(raw_input())
A = map(int, raw_input().split())
count = 0
flag = True
while flag:
    flag = False
    for i in xrange(N-1, 0, -1):
        if A[i-1] > A[i]:
            A[i-1], A[i] = A[i], A[i-1]
            count+=1
            flag = True
print ' '.join(map(str, A))
print count

Measured memory_bytes: 4224
using System;

namespace ITP1_10_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            double x1 = double.Parse(str[0]);
            double y1 = double.Parse(str[1]);
            double x2 = double.Parse(str[2]);
            double y2 = double.Parse(str[3]);

            double ans = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
            Console.WriteLine("{0}", ans);
        }
    }
}

Measured memory_bytes: 5800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f[4005][2005][2],ms=924844033,fac[40005],g[40005];
int tot;
bool vis[4005][2],ed[4005];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	fac[0]=1;
	for (int i=1;i<=n;i++){
		fac[i]=(fac[i-1]*i)%ms;
		for (int j=0;j<=1;j++){
			int len=0;
			if (!vis[i][j]){
				for (int x=i,y=j;x<=n;x+=k,y^=1){
					vis[x][y]=1; ++len;
				}
				tot+=len;
				ed[tot]=1;
			}
		}
	}
	f[1][0][0]=1;
	for (int i=1;i<=tot;i++){
		for (int j=0;j<=n;j++){
			f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%ms;
			if (ed[i]==0) f[i+1][j+1][1]=f[i][j][0];
		}
	}
	for (int i=0;i<=n;i++)
	g[i]=(f[tot][i][0]+f[tot][i][1])%ms;
	ll ans=fac[n];
	for (int i=1,j=-1;i<=n;i++,j=-j){
		ans=(ans+ms+(j*fac[n-i]*g[i])%ms)%ms;
	}
	printf("%lld\n",ans);
	return 0;
}

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

void solveeven(int n , int *arr)
{
    int ans[n];
    int left = n-1 ;
    for(int i = 0 ; i < (n/2) ; ++i){
        ans[i] = arr[left];
        left = left-2;
        if(left < 0) break;
    }
    int right = 0 ;
    for(int i = n/2 ; i<=n-1; ++i){
        ans[i] = arr[right] ;
        right = right + 2 ;
        if(right > n-2) break;
    }
    for(int i = 0 ; i <= n - 1 ; ++i){
        cout << ans[i] << " " ;
    }
    cout << endl ;
    return ;
}

void solveodd(int n , int *arr)
{
    int ans[n];
    int left = n-1 ;
    for(int i = 0 ; i < (n/2) + 1  ; ++i){
        ans[i] = arr[left];
        left = left-2;
        if(left < 0) break;
    }
    int right = 1 ;
    for(int i = (n/2) + 1 ; i<=n-1; ++i){
        ans[i] = arr[right] ;
        right = right + 2 ;
        if(right > n-2) break;
    }
    for(int i = 0 ; i <= n - 1 ; ++i){
        cout << ans[i] << " " ;
    }
    cout << endl ;
    return ;
}
void solve(int n , int *arr)
{
    if(n%2 == 0){
        solveeven(n , arr) ;
    }
    else solveodd(n , arr) ;
    return ;
}
int main()
{
    int n ;
    cin >> n ;
    int arr[n] ;
    for(int i = 0 ; i < n ; ++i){
        cin >> arr[i] ;
    }
    solve(n , arr) ;
}


Measured memory_bytes: 3712
#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)
#define all(a) a.begin(),a.end()

bool eval(vector<int> &table,string s,int &i){
    if(isdigit(s[i])) return s[i++] == '1';
    if(s[i] == '-') return !eval(table,s,++i);
    if(isalpha(s[i])) return table[s[i++]-'a'];
    i++; // (
    bool e1 = eval(table,s,i);
    char op = s[i++];
    bool e2 = eval(table,s,i);
    i++; // )
    if(op == '^') return e1^e2;
    if(op == '*') return e1*e2;
    assert(false);
}

int feature(string &E){
    int k = 0;
    int f = 0;
    rep(a,2)rep(b,2)rep(c,2)rep(d,2){
        vector<int> table = {a,b,c,d};
        int i = 0;
        if(eval(table,E,i)){
            f |= 1<<k;
        }
        k++;
    }
    return f;
}

int main(void){
    vector<string> exps[17];
    exps[1] = {"a","b","c","d"};
    for(int m = 2; m <= 16; m++){
        for(string E : exps[m-1]){
            if(E[0] == '-') continue;
            exps[m].push_back("-"+E);
        }
        rep1(x,m-2){
            int y = m-3-x;
            if(x>y) continue;
            for(string E1 : exps[x]){
                for(string E2 : exps[y]){
                    bool ng = false;
                    for(char ch : {'a','b','c','d'}){
                        if(count(all(E1),ch)+count(all(E2),ch)>1){
                            ng = false;
                        }
                    }
                    if(ng) continue;
                    exps[m].push_back("("+E1+"^"+E2+")");
                    exps[m].push_back("("+E1+"*"+E2+")");
                }
            }
        }
    }
    exps[1].push_back("0");
    exps[1].push_back("1");


    vector<int> min_len(1<<16, 20);
    rep1(m,16){
        for(string E : exps[m]){
            int f = feature(E);
            min_len[f] = min(min_len[f], m);
        }
    }

    string E;
    while(cin>>E, E != "."){
        cout<<min_len[feature(E)]<<endl;
    }
    return 0;
}



Measured memory_bytes: 13284
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
// #define int long long
#define mod (int)(1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;

int main(){
  ll n;
  cin>>n;

  cout<<n*(n-1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
        // マップの作成
        List<string> e1 = new List<string>(){ "A", "T" };
        List<string> e2 = new List<string>(){ "C", "G" };

		// 入力読み込み
        string b = Console.ReadLine();

		// 出力
		string outPut = "";

		// 対応表の確認
		if (e1.Contains(b))
		{
			foreach(string s in e1)
			{
				if (s != b)
				{
					outPut = s;
				}
			}	
		}
		else if (e2.Contains(b))
		{
			foreach(string s in e2)
			{
				if (s != b)
				{
					outPut = s;
				}
			}	
		}

		//出力
		Console.WriteLine(outPut);
	}
}

Measured memory_bytes: 13148
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

h = n_in()
import math

def do(x):
    if x == 1:
        return 1
    return 1+2*do(math.floor(x/2))

print(do(h))


Measured memory_bytes: 38436
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
typedef long long ll;
int sgn(double x){
    if(fabs(x)<eps){
        return 0;
    }
    if(x<0){
        return -1;
    }else{
        return 1;
    }
}
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    void input(){
        scanf("%lf%lf",&x,&y);
    }
    Point operator+(const Point &b)const{
        return Point(x+b.x,y+b.y);
    }
    Point operator -(const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    double operator *(const Point &b)const{
        return x*b.x+y*b.y;
    }
    Point operator *(const double &k)const{
        return Point(x*k,y*k);
    }
    double operator ^(const Point &b)const{
        return x*b.y-y*b.x;
    }
    Point operator /(const double &k)const{
        return Point(x/k,y/k);
    }
    bool operator <(const Point &b)const{
        return sgn(x-b.x)==0?sgn(y-b.y)<0:x<b.x;
    }
    double len2(){
        return x*x+y*y;
    }
};
struct Line{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e){
        s = _s;
        e = _e;
    }
    int relation(Point p){
        int c = sgn((p-s)^(e-s));
        if(c < 0){
            return 1;
        }else if(c>0){
            return 2;
        }else{
            return 3;
        }
    }
    int pointonseg(Point p){
        int c = sgn((p-s)^(p-e));
        if(c<0){
            return 4;
        }else{
            if((p.x-s.x)*(s.x-e.x)>0.0||(p.x==s.x&&(p.y-s.y)*(s.y-e.y)>0.0)){
                return 6;
            }else if((p.x-e.x)*(e.x-s.x)>0.0||(p.x==e.x&&(p.y-e.y)*(e.y-s.y)>0.0)){
                return 7;
            }else{
                return 4;
            }
        }
    }
};

int main(){
    Point p1,p2,p3;
    p1.input();
    p2.input();
    Line line(p1,p2);
    int q;
    scanf("%d",&q);
    Point ans;
    while(q--){
        p3.input();
        int ans = line.relation(p3);
        if(ans == 1){
            printf("COUNTER_CLOCKWISE\n");
        }else if(ans == 2){
            printf("CLOCKWISE\n");
        }else{
            int tmp = line.pointonseg(p3);
            if(tmp == 4){
                printf("ON_SEGMENT\n");
            }else if(tmp == 6){
                printf("ONLINE_BACK\n");
            }else if(tmp == 7){
                printf("ONLINE_FRONT\n");
            }
        }
    }
     return 0;
}


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

int main() {
    string S;
    cin >> S;
    if (S == "SUN") cout << 7 << endl;;
    if (S == "SAT") cout << 1;
    if (S == "FRI") cout << 2;
    if (S == "THU") cout << 3;
    if (S == "WED") cout << 4;
    if (S == "TUE") cout << 5;
    if (S == "MON") cout << 6;
}

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

int main(){
int N,M;
cin>>N>>M;
vector<int>l(M);
vector<int>r(M);
int maxx=0;
int minn=1000000;
for(int i=0;i<M;i++){
   cin>>l[i]>>r[i];
   maxx=max(maxx,l[i]);
   minn=min(minn,r[i]);
}
int a=0;
for(int i=1;i<=N;i++){
   if(maxx<=i&&i<=minn){
      a++;
   }
}
cout<<a<<endl;


return 0;
}


Measured memory_bytes: 3944
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush

from collections import Counter
#T = int(stdin.readline())
#for i in range(T):

    #N=int(stdin.readline())

def helper(bks,p,cc,alg,vis,m,n,x):
    
    if p==n:
        f=True
        for i in range(m):
            if alg[i]<x:
                f=False
                break
        if f:
            return cc
        return float('inf')    
    ans=float('inf')
    for b in range(p,n):
    #    if b not in vis:
    #        vis.add(b)
        for i in range(m):
            alg[i]+=bks[b][i+1]
        
        ans=min(ans,helper(bks,b+1,cc+bks[b][0],alg,vis,m,n,x) )
        #print(ans)
        for i in range(m):
            alg[i]-=bks[b][i+1]
    #       vis.remove(b)
    ans=min(ans,helper(bks,n,cc,alg,vis,m,n,x) )
    return ans


n,m,x=list(map(int,stdin.readline().split()))
bks=[[0]*(m+1) for _ in range(n)]

for i in range(n):
    bks[i]=list(map(int,stdin.readline().split()))
    

pos=True

alg=[0]*m
for i in range(n):
    for j in range(m):
        alg[j]+=bks[i][j+1]
#print(alg,x)
for i in range(m):
    if alg[i]<x:
        pos=False
        break



if not pos:
    print(-1)
else:
    alg=[0]*m
    print(helper(bks,0,0,alg,set(),m,n,x))



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

int  main(void) {
  int n; cin >> n;
  int p[n];
  rep (i, n) cin >> p[i];

  vector<int> saidai(n, 0);
  saidai[0] = p[0];
  int ans = 0;

  for (int i = 1; i < n; i++) {
    if (p[i] < saidai[i - 1]) saidai[i] = p[i];
    else saidai[i] = saidai[i - 1];
  }

  rep (i, n) {
    if (p[i] <= saidai[i]) ans++;
  }
  //rep (i, n) cout << saidai[i] << endl;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
typedef pair<int, int> pii;
#define x first
#define y second
const int N = 5e5 + 10;
int n, D, q, d[N], x[N], r[N];

int f(int x, int d) {
	return x > d ? (x - d) : (d - x < x ? d - x : x);
}

int main() {
	scanf("%d%d",&n,&D);
	rep(i,1,n) scanf("%d", d + i);
	
	x[0] = D;
	rep(i,1,n) x[i] = f(x[i - 1], d[i]);

	r[n + 1] = 0;
	dep(i,n,1) {
		r[i] = r[i + 1];
		if (r[i] >= d[i] / 2) r[i] += d[i];
	}

	scanf("%d",&q);
	rep(t,1,q) {
		int i; scanf("%d",&i);
		if (x[i - 1] <= r[i + 1]) printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}

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

int main(){
    int N,i;
    int result=1;
    string S;
    
    cin>>N;
    cin>>S;

    for(i=0;i<N-1;i++){
        if(S[i]!=S[i+1])result+=1;
    }
    cout<<result<<endl;
}

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

using namespace std;

int CountDigits(int n)
{
	int count = 0;
	while (n != 0)
	{
		count++;
		n /= 10;
	}

	return count;
}

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

	int result = 0;

	for (int i = 1; i <= n; i++)
	{
		int count = CountDigits(i);
		if (count % 2 != 0)
		{
			result++;
		}
	}
	cout << result << endl;
}

Measured memory_bytes: 256
import sys

N, K = map(int, input().split())
broken = []
for _ in range(K):
    broken.append(int(input()))

for k in range(K-1):
    if broken[k] +1 == broken[k+1]:
        print(0)
        sys.exit(0)
broken_set = set(broken)

# N段連続したら何通りあるか表を作る
P = {0: 1, 1: 1, 2: 2}
for i in range(3, N+1):
    P[i] = P[i-1] + P[i-2]

total = 1
low = 0
for i in range(1, N+1):
    if i in broken_set:
        seq = (i - 1) - low
        total *= P[seq]
        total %= 1000000007
        low = i + 1
else:
    seq = N - low
    total *= P[seq]
    total %= 1000000007

print(total)


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

using namespace std;

void show(int arr[], int n) {
	for (int i = 0; i < n - 1; i++)
		cout << arr[i] << " ";
	cout << arr[n - 1] << endl;
}

int main() {
	int arr[100];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	show(arr, n);
	int j, v;
	for (int i = 1; i < n; i++) {
		v = arr[i];
		j = i - 1;
		while (j >= 0 && arr[j] > v) {
			arr[j + 1] = arr[j];
				j--;
		}
		arr[j + 1] = v;
		show(arr, n);
	}

	return 0;
}

Measured memory_bytes: 1160
a, b, c = gets.chomp.split(" ").map{|e|e.to_i}

def doit(a,b,c)
	if a==b && b==c then return "No" end
	if a==b then return "Yes" end
	if b==c then return "Yes" end
	if c==a then return "Yes" end
	return "No"
end

print(doit(a,b,c))

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;
    string s;
    cin >> s;

    set<char> left, right;
    int max_cnt = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < i; j++) {
            left.insert(s.at(j));
        }

        for (int k = i; k < n; k++) {
            right.insert(s.at(k));
        }

        // counting
        int cnt = 0;
        for (auto l : left) {
            if (right.find(l) != right.end())
                cnt++;
        }
        max_cnt = max(max_cnt, cnt);

        // init
        cnt = 0;
        left.clear();
        right.clear();
    }

    cout << max_cnt << endl;
}


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

int cnt(int x) {
    int c = 1;
    for (int i = 2; i <= x; i++) {
        if (x % i == 0) {
            c++;
        }
    }
    return c;
}

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

    int c = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 2 != 0 && cnt(i) == 8) {
            c++;
        }
    }

    cout << c << endl;
}


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

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

    n = n%10;

    if((n==2) || (n==4) || (n==5) || (n==7) || (n==9)){
        cout << "hon" << endl;
    }else if((n==0) || (n==1) || (n==6) || (n==8)){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }

    return 0;
}

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

VVI friends;
VVI blocks;

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  UnionFind uf(N);
  friends.resize(N);
  rep(mi, M) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    friends.at(A).push_back(B);
    friends.at(B).push_back(A);
    uf.unite(A, B);
  }
  blocks.resize(N);
  rep(ki, K) {
    int C, D;
    cin >> C >> D;
    C--;
    D--;
    blocks.at(C).push_back(D);
    blocks.at(D).push_back(C);
  }
  rep(ni, N) {
    int ans = uf.size(ni) - friends.at(ni).size();
    ans--;
    for (int b : blocks.at(ni)) {
      if (uf.same(ni, b)) {
        ans--;
      }
    }
    if (ni != N - 1) {
      cout << ans << " ";
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 12152
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=998244353;
int n;
bool r[7][4010],c[4010],g[4010],tmp[4010];
void trans(char *s,bool *a)
{
	int len=strlen(s)-1;
	for(int i=0;i<=len;i++)
		a[i]=s[len-i]-'0';
}
int deg(bool *a)
{
	for(int i=4000;i>=0;i--)
		if(a[i]) return i;
}
void pls(bool *a,bool *b,int t)
{
	for(int i=t;i<=4000;i++)
		a[i]=a[i]^b[i-t];	
}
void gcd(bool *a,bool *b,bool *d)
{
	int da=deg(a),db=deg(b);
	if(da<db) swap(a,b),swap(da,db);
//	for(int i=da;i>=0;i--)
//		cout<<a[i];
//	cout<<endl;
//	for(int i=db;i>=0;i--)
//		cout<<b[i];
//	cout<<endl;	
	if(db==0&&b[0]==0) {for(int i=0;i<=4000;i++) d[i]=a[i];return ;}
	
	
	pls(a,b,da-db);
	gcd(b,a,d);
}
int main()
{
	char cs[4010];
	scanf("%d%s",&n,cs);
	trans(cs,c);
	int dc=deg(c);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",cs);
		trans(cs,r[i]);
	}
//	for(int i=1;i<=n;i++,puts(""))
//		for(int j=deg(r[i]);j>=0;j--)
//			cout<<r[i][j];
	memset(g,0,sizeof(g));
	for(int i=1;i<=n;i++)
	{
		for(int j=deg(g);j>=0;j--)
			tmp[j]=g[j];
		gcd(r[i],tmp,g);
//		for(int i=deg(g);i>=0;i--)
//			cout<<g[i];
//		cout<<"*****************************"<<endl;	
	}
	int dgcd=deg(g);
	//cout<<dgcd<<' '<<dc<<endl;
	
	memset(tmp,0,sizeof(tmp));
	for(int i=dc;i>=dgcd;i--)
		if(tmp[i]^c[i])
			pls(tmp,g,i-dgcd);
//	for(int i=dc;i>=0;i--)
//		cout<<tmp[i];
//	cout<<endl;				
	int ans=0;
	for(int i=dc;i>=dgcd;i--)
		ans=((ans<<1)+c[i])%mod;	
	for(int i=dgcd-1;i>=0;i--)
		if(tmp[i]<c[i])	break;
		else if(tmp[i]>c[i]) {ans--;break;}
	printf("%d",ans+1);			
	return 0;
}
/*4 100100
1110
1011
110101
1010110*/

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

int n, k, a[200005];

bool can(int x) {
    int need = 0;
    for (int i = 0; i < n; i++) {
        need += (a[i]-1) / x;
    }

    return need <= k;
}

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

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int lo = 1, mid, hi = 1e9;
    while (lo < hi) {
        mid = (lo+hi) / 2;
        if (can(mid)) {
            hi = mid;
        }
        else {
            lo = mid+1;
        }
    }

    cout << lo << '\n';

    return 0;
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
// #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);i++)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}
const ll inf = 1LL<<60;

int main(){
  int n,k;cin>>n>>k;
  vector<ll> h(n+1);
  vector<ll> dp(n+10,inf);

  for(ll i=0;i<n;i++){
    cin >> h[i];
  }
  dp[0]=0;
  for(ll i=0;i<n;i++){
    for(ll j=1;j<=k;j++){
      if(j<=i){
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
      }
    }
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
//#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
signed main() {
    int N, M;
    cin >> N >> M;
    int V[N][3];
    rep(i, N) {
        rep(j, 3) cin >> V[i][j];
    }
    int ans = 0;
    rep(i, 8) {
        vector<int> V0;
        rep(j, N) {
            int sum = 0;
            rep(k, 3) {
                if((i >> k) & 1)
                    sum += V[j][k];
                else
                    sum -= V[j][k];
            }
            V0.push_back(sum);
        }
        sort(all(V0), greater<int>());
        int sum = 0;
        rep(j, M) sum += V0[j];
        chmax(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 //	ios::sync_with_stdio(0);
 //   cin.tie(0);
    string s;
    cin>>s;
    lli ans=0,temp=0;
    for(lli i=0;i<s.size();i++){
    	if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')temp++;
    	else temp=0;
    	ans=max(ans,temp);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
package main

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

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

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	p := scanInts(n)
	q := scanInts(n)

	var a,b int
	cnt := 0
	permutationSearch(n, func(perm []int) {
		f1,f2 := true, true
		for i := 0; i < n; i++ {
			if perm[i]+1 != p[i] {
				f1 = false
			}
			if perm[i]+1 != q[i] {
				f2 = false
			}
		}
		if f1 {
			a = cnt
		}
		if f2 {
			b = cnt
		}
		cnt++
	})

	fmt.Fprintln(wr, abs(a-b))
	// fmt.Fprintln(wr, a,b)
}

func permutationSearch(n int, fn func(a []int)) {
	a := make([]int, n)
	for i := 0; i < n; i++ { a[i] = i }
	swap := func(i,j int) { a[i],a[j] = a[j],a[i] }

	fn(a)
	for i := n-2; i >= 0; i-- {
		if a[i] < a[i+1] {
			for j := n-1; j >= 0; j-- {
				if a[i] < a[j] {
					swap(i,j)
					for k := i+1; k < (n+i+1)/2; k++ { swap(k,n-(k-i)) }
					fn(a)
					i = n-1
					break
				}
			}
		}
	}
}


Measured memory_bytes: 640
#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;

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

  if(a+b+c<=21) cout<<"win"<<endl;
  else cout<<"bust"<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		if (n == 1) {
			System.out.println("3");
			return;
		}
		String[] s = sc.next().split("");
		long c = 0;
		int index = 0;
		boolean before;
		int mod = 1000000007;
		if (s[0].equals(s[1])) {
			c = 6;
			index = 2;
			before = true;
		}
		else {
			c = 3;
			index = 1;
			before = false;
		}
		for (; index < n;) {
			if (index < n - 1 && s[index].equals(s[index + 1])) {
				if (before) {
					c = c * 3 % mod;
				}
				else {
					c = c * 2 % mod;
				}
				index += 2;
				before = true;
			}
			else {
				if (!before) {
					c = c * 2 % mod;
				}
				index++;
				before = false;
			}
		}
		System.out.println(c);
	}
}

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

AB = []
for _ in range(N):
  AB.append(list(map(int, input().split())))

sorted_AB = sorted(AB, key=lambda x:(x[1], -x[0]))
worked = 0
for ab in sorted_AB:
  worked += ab[0]
  if worked > ab[1]:
    print('No')
    exit(0)

print('Yes')


Measured memory_bytes: 67364
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    bool ans = true;
    i64 N, M;
    cin >> N;
    M = (N * (N + 1)) / 2;
    vector<i64> A(N);
    i64 S = 0, K;
    for(i64 &x : A) {
        cin >> x;
        S += x;
    }
    if(S % M != 0) {
        ans = false;
    } else {
        K = S / M;
        for(int i = 0; i < N; i++) {
            i64 NX = K - A[(i + 1) % N] + A[i];
            if(NX < 0 || NX % N != 0) {
                ans = false;
                break;
            }
        }
    }
    R_YESNO(ans);
    return 0;
}



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

const int MOD = 1e9 + 7;

long long inv(long long a, long long b){
  return 1 < a ? b - inv(b % a, a) * b / a : 1;
}

int choose(int n, int k) {

  int max = std::max(n, k);
  std::vector<int> fat(max + 1);

  fat[0] = 1;
  for (int i = 1; i <= max; i++)
    fat[i] = 1LL * fat[i-1] * i % MOD;

  return (1LL * fat[n] * inv(fat[k], MOD) % MOD) * inv(fat[n-k], MOD) % MOD;
}

int main() {
  int x, y;
  scanf("%d%d", &x, &y);

  if ((x + y) % 3)
    return puts("0"), 0;

  int n = (x + y) / 3;

  if (x < n || y < n)
    return puts("0"), 0;

  int k = y - n;
  
  printf("%d\n", choose(n, k));
}


Measured memory_bytes: 2816