akhauriyash/Code-Regression huggingface dataset:
n, a, b = map(int, input().split())
vlist = list(reversed(sorted(map(int, input().split()))))

cc = [[0 for _ in range(51)] for _ in range(51)]
for i in range(51):
  for j in range(i+1):
    if j == 0 or j == i:
      cc[i][j] = 1
    else:
      cc[i][j] = cc[i-1][j-1] + cc[i-1][j]

avg = sum(vlist[:a]) / a
avaln, avalp = 0, 0
for i in range(n):
  if vlist[i] == vlist[a-1]:
    avaln += 1
    if i < a:
      avalp += 1

cnt = 0
if avalp == a:
  for ap in range(a, b+1):
    cnt += cc[avaln][ap]
else:
  cnt += cc[avaln][avalp]

print('%.8f' % avg)
print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
int b[80][80][13000];

int main() {
    int h,w,m=13000;
    cin >> h >> w;
    vector<vector<int>> a(w,vector<int>(h)),c(w,vector<int>(h,0));
    c[0][0]=1;
    rep(i,h){
        rep(j,w) cin >> a[j][i];
    }
    rep(i,h){
        rep(j,w){
            int f;
            cin >> f;
            a[j][i]=abs(a[j][i]-f);
        }
    }
    rep(i,w){
        rep(j,h){
            rep(k,m) b[i][j][m]=0;
        }
    }
    b[0][0][a[0][0]]=1;
    queue<pp> q;
    q.push(mk(0,0));
    while(!q.empty()){
        int f=q.front().first,g=q.front().second;
        q.pop();
        if (f+1!=w){
                rep(i,m){
                    if (b[f][g][i]==1){
                        b[f+1][g][i+a[f+1][g]]=1;
                        b[f+1][g][abs(i-a[f+1][g])]=1;
                    }
                }
            if (c[f+1][g]==0){
                c[f+1][g]=1;
                q.push(mk(f+1,g));
            }
        }
        if (g+1!=h){
                rep(i,m){
                    if (b[f][g][i]==1){
                        b[f][g+1][i+a[f][g+1]]=1;
                        b[f][g+1][abs(i-a[f][g+1])]=1;
                    }
                }
            if (c[f][g+1]==0){
                c[f][g+1]=1;
                q.push(mk(f,g+1));
            }
        }
    }
    int ans;
    rep(i,m){
        if (b[w-1][h-1][i]==1){
            ans=i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 323584
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:128777216")

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>

#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>

#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>

#include <memory.h>
#include <cassert>
#include <time.h>
#include <functional>

using namespace std;

#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, b, a) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define _(a, val) memset (a, val, sizeof (a))
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long lint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;

const lint LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;

#ifdef MY_DEBUG
#define dbgx( x ) { cerr << #x << " = " << x << endl; }
#define dbg( ... ) { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#else
#define dbgx( x ) {  } 
#define dbg( ... ) {  } 
#endif

void prepare(string s) {
#ifdef MY_DEBUG
  freopen("input.txt", "r", stdin);
  //freopen ("output.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
  //freopen ("output.txt", "w", stdout);
#endif
}

string s;

void read() {
  cin >> s;
}

int get_sum(string s) {
  int r = 0;
  for (int i = 0; i < sz(s); ++i) {
    r += s[i] - '0';
  }
  return r;
}

void solve() {
  int ans = get_sum(s);
  int sum = 0;
  for (int i = 0; i < sz(s); ++i) {
    string t = s.substr(i);
    if (t[0] == '0') continue;
    t[0]--;
    for (int j = 1; j < sz(t); ++j)
      t[j] = '9';
    ans = max(ans, get_sum(t) + sum);
    sum += s[i] - '0';
  }
  printf("%d\n", ans);
}

int main() {
  prepare("");

  read();
  solve();
  dbg("Clock = %.3f\n", clock() / (double)CLOCKS_PER_SEC);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int main() 
{int a,b,x;
 cin>>a>>b>>x;
 if (a+b>=x and a<=x)
 cout<<"YES";
 else
 cout<<"NO"; 
 system("pause");
 return 0;
}        


Measured memory_bytes: 504
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int32{0, 1, 0, -1}
var dx = []int32{1, 0, -1, 0}
var MAX = math.MaxInt64

func maxInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func minInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

var inf uint32 = math.MaxUint32

type Point struct {
	x, y int32
}

var H, W, K int32
var i, j int32

func main() {
	// s := time.Now()
	H = int32(nextInt())
	W = int32(nextInt())
	K = int32(nextInt())
	var start, goal Point
	start.y = int32(nextInt() - 1)
	start.x = int32(nextInt() - 1)
	goal.y = int32(nextInt() - 1)
	goal.x = int32(nextInt() - 1)
	grid := make([]string, H)
	for i = 0; i < H; i++ {
		grid[i] = nextString()
	}
	step := make([][]uint32, H)
	for i = 0; i < H; i++ {
		step[i] = make([]uint32, W)
	}
	for i = 0; i < H; i++ {
		for j = 0; j < W; j++ {
			step[i][j] = inf
		}
	}
	step[start.y][start.x] = 0
	q := make([]*Point, 0)
	q = append(q, &start)
	idx := 0
	var next Point
	for idx < len(q) {
		now := q[idx]
		idx++
		for d := 0; d < 4; d++ {
			var k int32
			for k = 1; k <= K; k++ {
				next.x = now.x + dx[d]*k
				next.y = now.y + dy[d]*k
				if next.x < 0 || next.x >= W || next.y < 0 || next.y >= H {
					break
				}
				if grid[next.y][next.x] == '@' {
					break
				}
				if step[next.y][next.x] <= step[now.y][now.x] {
					break
				}
				if step[next.y][next.x] <= step[now.y][now.x]+1 {
					continue
				}
				step[next.y][next.x] = step[now.y][now.x] + 1
				q = append(q, &Point{x: next.x, y: next.y})
			}
		}
		// elapsed := time.Since(s)
		// if elapsed > 2900*time.Millisecond {
		// 	break
		// }
	}
	if step[goal.y][goal.x] == inf {
		fmt.Println("-1")
	} else {
		fmt.Println(step[goal.y][goal.x])
	}
}


Measured memory_bytes: 36580
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <typeinfo>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;



int main(){
    while(true){
        vector<int> a;
        rep(i,3){
            int tmp;
            cin>>tmp;
            a.push_back(tmp);
        }
        sort(a.begin(),a.end());
        if(a[0]==0 && a[1]==0 && a[2]==0)break;
    
        int n;
        cin>>n;
        
        rep(i,n){
            int x;
            cin>>x;
            if( pow( (a[0]/2) , 2 ) + pow( (a[1]/2) , 2 ) < pow(x,2))cout<<"OK"<<endl;
            else cout<<"NA"<<endl;
        }
    }

    return 0;
 }

Measured memory_bytes: 1208
K,*as=$<.read.split.map(&:to_i)

ret = 0

(1..K).each do |i|
  (1..K).each do |j|
    (1..K).each do |k|
      ret += i.gcd(j).gcd(k)
    end
  end
end

# (1..K).each do |i|
#   (i..K).each do |j|
#     (j..K).each do |k|
#       n = i.gcd(j).gcd(k)
#       if i == j && i == k
#         ret += n
#       elsif i != j && j != k
#         ret += n*6
#       else
#         ret += n*3
#       end
#     end
#   end
# end

puts ret


Measured memory_bytes: 14388
n=gets.to_i
a=gets.chomp.split(" ").map(&:to_i)
max=0
count=0
(n-1).times do |i|
  if a[i]>=a[i+1]
    count+=1
  else
    if count>max
      max=count
    end
    count=0
  end
end
if count>max
      max=count
end
puts max

Measured memory_bytes: 9604
def myAnswer(N:int,A:list) -> int:
   dic = {}
   for a in A:
      if(a in dic.keys()):
         dic[a]+=1
      else:
         dic[a] = 1
   ans = []
   for key,value in dic.items():
      if(value >= 4):
         ans.append(key)
         ans.append(key)
      elif(value >= 2):
         ans.append(key)
   if(len(ans) <= 1):
      return 0
   ans.sort(reverse = True)
   return ans[0]*ans[1]

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

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

int main(void){
	int n,m;cin>>n>>m;
	int A[1005];
	for(int i=0;i<n;++i){
		cin>>A[i];
	}
	int vote[1005]={};
	int maxa = 0;
	int ans;
	for(int B,i=0;i<m;++i){
		cin>>B;
		for(int j=0;j<n;++j){
			if(B >= A[j]){
				++vote[j];
				maxa = max(maxa, vote[j]);
				if(maxa == vote[j]) ans=j+1;
				break;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1168
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
int gcd(int a, int b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
int ans = 0;
int s[10][10];
int k[10];
int p[10];
void bit(int m, int n, int d) {
	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			bool w = true;
			rep(i, 0, d) {
				int x = 0;
				rep(j, 0, k[i])if (now[s[i][j] - 1] == '1')x++;
				if (x % 2 != p[i])w = false;
			}
			if (w)ans += 1;
		}
		else {
			for (int i = m - 1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}
;
int main() {
	int n;
	cin >> n;
	string t = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
	string s, ans = "";
	cin >> s;
	rep(i, 0, s.size()) {
		ans += t[s[i] - 65+ n]-32;
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MSET(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535 
 
ll gcd(ll a, ll b) {
    if (b == 0) 
        return a; 
    return gcd(b, a % b);
}
 
int32_t main() {
    fastio;
    ll x;
    cin>>x;
    cout<<(360) / gcd(x, 360LL) <<endl;
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
  int n, i, j;
  char *s;
  char *ans;
  scanf("%d", &n);
  s = (char*)malloc(n * sizeof(char));
  scanf("%s", s);
  ans = (char*)malloc(n * sizeof(char));
  char tmp;
  tmp = *s;
  ans[0] = s[0];
  j=0;
  for(i=1; i<n; i++) {
    if(s[i] != ans[j]) {
      ans[++j] = s[i];
    }
  }
  ans[++j] = '\0';
  printf("%d\n", strlen(ans));
  return 0;
}


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

using namespace std;
const int mod = 1e9+7;
int ad(int x,int y) { x+=y; return x>=mod?x-mod:x; }
int sb(int x,int y) { x-=y; return x<0?x+mod:x; }
int mu(int x,int y) { return 1ll*x*y%mod; }
void up(int &x,int y) { x+=y; if(x>=mod)x-=mod; }
int ksm(int a,int b) {
	int ans = 1;
	for(;b;b>>=1,a=mu(a,a))
		if(b&1) ans=mu(ans,a);
	return ans;
}
int n;
const int maxn = 2e5+5;
int a[maxn],rd[maxn],from[maxn],f[maxn];
bool vis[maxn];
int ans = 1;
int CR[maxn],cnt;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		rd[a[i]]++;
	}
	for(int i=1;i<=n;i++) {
		if(rd[i]>2) { puts("0"); return 0; }
		else if(rd[i]<2||vis[i]) continue;
		int p = i;
		do{
			if(vis[p]) { puts("0"); return 0; }
			vis[p] = 1; from[a[p]] = p;
			p = a[p];
		}while(p!=i);
	}
	for(int i=1;i<=n;i++) {
		if(!rd[i]) {
			int p = i; int l1 = 0; int l2 = 0;
			while(!vis[p]) vis[p] = 1 , l1++ , p = a[p];
			do{
				l2++; p = from[p];
			}while(rd[p]!=2);
			if(l1==l2) continue;
			else if(l1<l2) ans = mu(ans,2);
			else { puts("0"); return 0; }
		}
	}
	for(int i=1;i<=n;i++) {
		if(!vis[i]) {
			int p = i; int cd = 0;
			do{
				p = a[p];
				cd++;
				vis[p] = 1;
			}while(p!=i);
			CR[++cnt] = cd;
		}
	}
	sort(CR+1,CR+1+cnt);
	for(int i=1,j;i<=n;i=j+1) {
		j = i;
		while(j<n&&CR[j+1]==CR[i]) j++;
		f[i-1] = 1;
		for(int k=i;k<=j;k++) {
			f[k] = f[k-1];
			if(CR[i]>1&&(CR[i]&1)) up(f[k],f[k-1]);
			if(k!=i) up(f[k],mu(f[k-2],mu(k-i,CR[i]) ) );
		}
		ans = mu(ans,f[j]);
	}
	printf("%d",ans);
	
}

Measured memory_bytes: 3200
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
double a,l,x;
int main(){
  while(cin>>a>>l>>x){
    double b=sqrt(l*l-0.25*a*a);
    double h=sqrt((2.0*l*x+x*x)*0.25);
    printf("%.8f\n",a*b*0.5+l*h);
  }
  return 0;
}

Measured memory_bytes: 1240
n = int(input())

ans = [0 for _ in range(10005)]

for i in range(1, 105):
    for j in range(1, 105):
        for k in range(1, 105):
            m = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if m < 10005:
                ans[m] += 1

for i in range(n):
    i += 1
    print(ans[i])

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	ll cnt = 1, x = 2;
	while (cnt < N) {
		cnt += x;
		++x;
	}
	int f = cnt - N;
	rep(i, 1, x) {
		if (i == f)continue;
		cout << i << "\n";
	}

	return 0;
}

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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int 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;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

int cutA(int A, int B, int C) {
    int a1 = A / 2;
    int a2 = A - a1;
    return abs(a1-a2) * B * C;
}

signed main() {
    make3(int, A, B, C);

    // 3断面確かめる

    int ans = INF;
    // A
    ans = min(ans, cutA(A, B, C));

    // B
    ans = min(ans, cutA(B, A, C));

    // C
    ans = min(ans, cutA(C, A, B));

    cout << ans << endl;
}



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

const long long MAX = 510000;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    long long S;
    cin >> S;
    long long ans=0;
    long long i;
    for(i=1; S-3*i>=0; i++){
        ans+=COM(S -3*i +(i-1),i-1);
        ans%=MOD;
    }
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 15664
N, M, X = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
toll_gate = [0] * (N + 1)
for i in A:
    toll_gate[i] = 1
print(min(sum(toll_gate[0 : X + 1]), sum(toll_gate[X : N + 1])))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  unordered_set<ll> st[200005];
int countt=0;
void DFSUtil(long long v, bool visited[]) 
{ 
    // Mark the current node as visited and print it 
    visited[v] = true; 
  //  cout << v << " "; 
    countt++;
    // Recur for all the vertices 
    // adjacent to this vertex 
  
    for(auto i:st[v] ) 
        if(!visited[i]) 
            DFSUtil(i, visited); 
} 
int main()
{
    fast_cin;
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

    ll N,M;
    cin>>N>>M;
  

    ll u,v;
    for(ll i=0;i<M;i++){
        cin>>u>>v;
        --u,--v;
        st[u].insert(v);
        st[v].insert(u);
    }
    
    bool vis[N];
    for(ll i=0;i<N;i++)
        vis[i]=false;
    ll ans=0;
    countt=0;
     for (ll v=0; v<N; v++) 
    { 
        if (vis[v] == false) 
        { 
            // print all reachable vertices 
            // from v 
            DFSUtil(v, vis); 
            if(countt>ans)
                ans=countt;
            countt=0;
          
        } 
    } 
    cout<<ans<<"\n";

}

Measured memory_bytes: 39736
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=(1<<22);
int dp[1000000];
int d[20];
int main()
{
	int n, m; cin >> n >> m;
	fill(dp, dp + n + 1 , INF);
	for (int i = 0; i < m; ++i) {
		cin >> d[i];
	}
	dp[0] = 0;
	for (int i = 0; i < m; ++i) {
		for (int j = d[i]; j <= n; ++j) {
			dp[j] = min(dp[j], dp[j - d[i]] + 1);
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1==0){cout<<"1";}
  else if(x2==0){cout<<"2";}
  else if(x3==0){cout<<"3";}
  else if(x4==0){cout<<"4";}
  else {cout<<"5";}
  return 0;
}

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

int main(){
  int A, B;
  string S;
  cin >> A >> B >> S;
  for(int i = 0; i < A; i++){
    if(!(S.at(i) >= '0' && S.at(i) <= '9')){
      cout << "No" << endl;
      return 0;
    }
  }
  if(S.at(A) != '-'){
    cout << "No" << endl;
    return 0;
  }
  for(int i = A + 1; i < A + B + 1; i++){
    if(!(S.at(i) >= '0' && S.at(i) <= '9')){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int r; cin >> r;
  cout << 3*r*r << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N;
int K;
int A[100005], B[100005];
void Read()
{
    cin >> N >> K;
    for(int i = 1; i <= N; i++)
        cin >> A[i] >> B[i];
}

void Solve()
{
    int nb = 0;
    long long ans = 0;
    for(int i = 30; i >= 0; i--)
    {
        if((K & (1 << i)) == 0)
            continue;
        int conf = nb + ((1 << i) - 1);
        long long sum = 0;
        for(int j = 1; j <= N; j++)
            if((A[j] | conf) == conf)
                sum += B[j];
        ans = max(ans, sum);
        nb += (1 << i);
    }
    int conf = nb;
     long long sum = 0;
        for(int j = 1; j <= N; j++)
            if((A[j] | conf) == conf)
                sum += B[j];
        ans = max(ans, sum);
    cout << ans << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int judge = sc.nextInt();
			if (judge == 0)
				break;

			int[] score = new int[judge];
			int max = 0, min = 1000, sum = 0;

			for (int i = 0; i < judge; i++) {
				score[i] = sc.nextInt();
				sum += score[i];
				if (score[i] > max)
					max = score[i];
				if (score[i] < min)
					min = score[i];
			}

			System.out.println((sum - max - min) / (judge - 2));
		}
	}
}

Measured memory_bytes: 29568
#include<bits/stdc++.h>
typedef int LL;
const LL maxn=1001,Maxn=1e7+9,inf=0x3f3f3f3f;
const LL dx[]={0,-1,0,1,0},dy[]={0,0,1,0,-1};
inline LL Read(){
    LL x(0),f(1); char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') f=-1; c=getchar();
    }
    while(c>='0' && c<='9'){
        x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
    }return x*f;
}
struct node{
	LL val,id; std::string s;
}a[maxn];
LL n;
inline bool cmp(node x,node y){
	return x.s<y.s || (x.s==y.s && x.val>y.val);
}
int main(){
	n=Read();
	for(LL i=1;i<=n;++i){
//		printf("(%d)",i);
		std::cin>>a[i].s; scanf("%d",&a[i].val); a[i].id=i;
	}
//	puts("233");
	std::sort(a+1,a+1+n,cmp);
	for(LL i=1;i<=n;++i) printf("%d\n",a[i].id);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

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

  ll n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  for (ll i = 0; i < n; i++)
    cout << s[i] << t[i];
  cout << en;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[200010], b[200010];
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	for (int i = 0; i < n; i++) {
		if (a[i] >= b[n / 2])cout << b[n / 2 - 1] << endl;
		else cout << b[n / 2] << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
sp_l = list(input())
t_l = list(input())

candidates = []
for i in range(len(sp_l)): 
    s_l = sp_l[:] # make new but identical list
    if sp_l[i] == t_l[0] or sp_l[i] == '?':
        s_l[i] = t_l[0]
        for j in range(1,len(t_l)):
            if i+j >= len(sp_l):
                break
            if sp_l[i+j] == t_l[j] or sp_l[i+j] == '?':
                s_l[i+j] = t_l[j]
            else:
                break
        else:
            candidates.append(''.join(s_l))

if len(candidates) == 0:
    print('UNRESTORABLE')
else:
    for i in range(len(candidates)):
        candidates[i] = candidates[i].replace('?','a')
    candidates.sort()
    print(candidates[0])

Measured memory_bytes: 3064
N,K,S = map(int,input().split())
arr = [0]*N
# if K == 0:
#     print(S-1)
#     exit()
for i in range(K):
    arr[i] = S
if S != 10**9:
    for j in range(K,N):
        arr[j] = 10**9
else:
    for j in range(K,N):
        arr[j] = 1

print(*arr)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, m;
	ll a[114514];
	pll bc[114514];
	cin>>n>>m;
	REP(i, n){
		cin>>a[i];
	}
	sort(a, a+n);
	REP(i, m){
		cin>>bc[i].second>>bc[i].first;
	}
	sort(bc, bc+m);
	ll ans=0;
	int now=m-1;
	bool ok=false;
	REP(i, n){
		if(ok){
			ans+=a[i];
		}
		else{
			if(a[i]>=bc[now].first){
				ok=true;
				ans+=a[i];
				continue;
			}
			ans+=bc[now].first;
			--bc[now].second;
			if(bc[now].second==0){
				--now;
			}
			if(now<0){
				ok=true;
			}
		}
		// DEBUG(ans);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 2944
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <bitset>

using namespace std;
#define lowbit(i) (i & (-i))
#define eps 1e-7
#define GETMID int mid = (l + r) >> 1
#define lson u << 1
#define rson u << 1 | 1
#define Lson u << 1, l, mid
#define Rson u << 1 | 1, mid + 1, r
#define Maxn (100000 + 10)
#define MP(a, b) make_pair(a, b)
#define PB(a) push_back(a);
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

void solve(int n) {
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			if(i + j == n + 1) continue;
			else printf("%d %d\n", i, j);
}

int main() {
	int n;
	scanf("%d", &n);
	if(n & 1) {
		printf("%d\n", (n - 1) * (n - 1) / 2);
		solve(n - 1);
		for(int i = 1; i < n; ++i)
			printf("%d %d\n", i, n);
	} else printf("%d\n", (n - 2) * n / 2), solve(n);
	
	return 0;
}


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

int main(void)
{
    string s;
    cin >> s;
    bool flag = false;
    for (int i = 0; i < s.length();i++){
        if(i!=0){
            if(s[i]=='C'&&s[i-1]=='A')
                flag = true;
        }
    }
    if(flag)
        cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    int s=0;
    rep(i,n) {
        cin >> a[i];
        s+=a[i];
    }
    int cnt=0;
    rep(i,n) {
        if (a[i]*4*m>=s) ++cnt;
    }
    if (cnt>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
     
    return 0;   
}

Measured memory_bytes: 3648
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let x = get_line().parse::<i64>().unwrap();

    let mut money = 100;
    let mut count = 0;

    while x > money {
        money = (1.01 * (money as f64)) as i64;
        count += 1;
    }

    println!("{}", count);
}


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

int main()
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int N = F/100 + 1;
    bool p[N]; // p[i] --- i*100[g]の水を作ることができるか
    fill(p, p + N, false);
    for(int i = 0; i*A < N; ++i) {
        for(int j = 0; i*A + j*B < N; ++j) {
            if(i == 0 && j == 0) continue;
            p[i*A+j*B] = true;
        }
    }

    int suger[N]; // suger[i] --- i*100[g]の水に入れることのできる最大の砂糖[g]
    fill(suger, suger + N, 0);
    for(int i = 0; i < N; ++i) {
        if(p[i]) {
            for(int j = 0; 100*i + j*C <= F; ++j) {
                for(int k = 0; 100*i + j*C + k*D <= F; ++k) {
                    int tmp = j*C + k*D;
                    if(tmp <= E*i) suger[i] = max(suger[i], tmp);
                }
            }
        }
    }

    /*
    for(int i = 0; i < N; ++i)
        if(p[i]) cout << i*100 + suger[i] << " " << suger[i] << endl;
    */

    bool flg = false;
    int a, b;
    for(int i = 0; i < N; ++i) {
        if(p[i]) {
            if(flg) {
                int c = i*100 + suger[i],
                    d = suger[i];
                if(b*c < a*d) { a = c; b = d; }
            }
            else {
                a = i*100 + suger[i];
                b = suger[i];
                flg = true;
            }
        }
    }

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char c;
    int i;
    int n = 0;
    char S[5];
    scanf("%s",S);
    for(i=0;i<4;i++){
        if(S[i]=='+'){
            n=n+1;
        }else if(S[i]=='-'){
            n=n-1;
        }
    }
    // printf("%c\n",S[2]);
    printf("%d",n);    
}

Measured memory_bytes: 128
n, k = map(int, input().split())
p = list(map(int, input().split()))
e = [(1 + p[i]) / 2.0 for i in range(n)]
res = 0
cur = 0
for i in range(k):
    cur += e[i]
res = cur
for i in range(k, n):
    cur += e[i] - e[i-k]
    res = max([res, cur])
print(res)

Measured memory_bytes: 75912
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int N, M, P;
int V[10];
int main(void){
    cin >> N >> M;
    REP(i,M){
        int k;
        cin >> k;
        REP(j,k){
            int s;
            cin >> s;
            V[s-1] |= (1 << i);
        }
    }
    int p;
    REP(i,M) {
        cin >> p;
        if(p==1) P |= 1 << i;
    }

    int count = 0;
    REP(i, 1<<N){
        int res = 0;
        REP(j,N){
            if(((i>>j)&1) == 1) res ^= V[j];
        }
        if (res == P) count++;
    }
    cout << count << endl;


    return 0;
}



Measured memory_bytes: 256
'use strict';
process.stdin.on('data', function(chunk) {
  var lines = chunk.toString().split('\n');
  var params = lines[0].split(' ').map(Number);
  var result = (function(data) {
   return data.sort(function(a,b) {
    return a - b;
   }).join(' ');
  }(params
  ));

  console.log(result);
});

process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 7648
/*
神题
1.b[i]=a[i]~a[n*2-i]
2.b中i之前所有数都不能在b[i]~b[i+1]之间（不包括端点）
f[i][j][k]=填完了b的后i个数，b的倒数第i个数有j种选择，它在这j种选择中排第k小，方案数
转移时计算选择种类数，枚举当前选择哪种
O(n^4)
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 110
#define mod 1000000007
using namespace std;
int n, w[N], f[N][N][N], sum, ans, now, x, y, x1, x2;
int main(){
	scanf("%d", &n); for(int i=1; i<=n*2-1; i++)scanf("%d", &w[i]);
	sort(w+1, w+n*2);
	sum=1; for(int i=2; i<=n*2-1; i++)if(w[i-1]<w[i])sum++;
	memset(f, 0, sizeof(f)); f[1][1][1]=1; now=1;
	for(int i=1; i<=n-1; i++){
		x1=w[n-i+1]==w[n-i]?0:1;
		x2=w[n+i-1]==w[n+i]?0:1;
		for(int j=1; j<=now; j++)
			for(int k=1; k<=j; k++){
				x=j+x1+x2; y=k+x1;
				for(int ii=1; ii<=y-1; ii++)f[i+1][x-y+ii+1][ii]=(f[i+1][x-y+ii+1][ii]+f[i][j][k])%mod;
				f[i+1][x][y]=(f[i+1][x][y]+f[i][j][k])%mod;
				for(int ii=y+1; ii<=x; ii++)f[i+1][x-ii+y+1][y+1]=(f[i+1][x-ii+y+1][y+1]+f[i][j][k])%mod;
			}
		now+=x1+x2;
	}
	ans=0;
	for(int i=1; i<=sum; i++)
		for(int j=1; j<=i; j++)ans=(ans+f[n][i][j])%mod;
	printf("%d", ans);
}

Measured memory_bytes: 5376
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <tuple>
#include <string>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

int main() {
  intmax_t n, a, b;
  scanf("%jd %jd %jd", &n, &a, &b);
  n %= 12;

  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      a = a-b;
    } else {
      b = a+b;
    }
  }
  printf("%jd %jd\n", a, b);
}



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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;


ll odd(ll a){
  return (a+1)/2%2;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b; cin>>a>>b; a--;
  ll xa,xb;
  if(a%2){
    xa=odd(a);
  }else{
    xa=(a+1)^odd(a+1);
  }
  if(b%2){
    xb=odd(b);
  }else{
    xb=(b+1)^odd(b+1);
  }
  cout<<(xa^xb)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

const int N = 1e5+7;
const int K = 1007;

int n, k, ans;

int x[N];
int y[N];
char c[N];

int res[4*K][4*K];

void add(int a, int b, int c, int d)
{
	a %= 2*k;
	b %= 2*k;
	c %= 2*k;
	d %= 2*k;

	if(a>b)
		b += 2*k;

	if(c>d)
		d += 2*k;

	++res[a][c];
	++res[b+1][d+1];
	--res[a][d+1];
	--res[b+1][c];
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
	{
		cin >> x[i] >> y[i] >> c[i];

		x[i] %= 2*k;
		y[i] %= 2*k;

		x[i] += 2*k;
		y[i] += 2*k;

		x[i] %= 2*k;
		y[i] %= 2*k;

		int lx = -x[i];
		int rx = k-1-x[i];

		int ly = -y[i];
		int ry = k-1-y[i];

		lx += 2*k;
		rx += 2*k;
		ly += 2*k;
		ry += 2*k;

		lx %= 2*k;
		rx %= 2*k;
		ly %= 2*k;
		ry %= 2*k;

		if(c[i]=='B')
		{
			add(lx, rx, ly, ry);
			add(lx+k, rx+k, ly+k, ry+k);
		}
		else
		{
			add(lx+k, rx+k, ly, ry);
			add(lx, rx, ly+k, ry+k);
		}
	}

	for(int i = 0; i < 4*k; ++i)
	{
		for(int j = 0; j < 4*k; ++j)
		{
			if(i>0)
				res[i][j] += res[i-1][j];
		}
	}

	for(int i = 0; i < 4*k; ++i)
	{
		for(int j = 0; j < 4*k; ++j)
		{
			if(j>0)
				res[i][j] += res[i][j-1];
		}
	}

	for(int i = 0; i < 2*k; ++i)
	{
		for(int j = 0; j < 2*k; ++j)
		{
			ans = max(ans, res[i][j]+res[i+2*k][j+2*k]+res[i+2*k][j]+res[i][j+2*k]);
		}
	}

	cout << ans;
}

Measured memory_bytes: 64512
n,*a=map(int,open(0).read().split())
from numpy import*
a=array(a)
asum=a.cumsum()
#print(asum)
b=(asum[-1]-2*asum)
#print(asum[-1]-asum,"\n",(b[0:n-1]))
print(min(abs(b[0:n-1])))

Measured memory_bytes: 24064
#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 rrng(a) a.rbegin(), a.rend()
#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 eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << 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 tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll n, k;
const ll mod = 1000000007LL;
vi G[101010], checked(101010, 0);

ll dfs(ll pa, int u) {
  checked[u] = 1;
  ll color;
  ll res = 1;
  if (pa == -1)
    color = k-1;
  else
    color = k - 2;
  if (k < sz(G[u])) return 0;
  for (auto v : G[u]) {
    if (checked[v]) continue;
    res *= color;
    color--;
    res %= mod;
  }
  for (auto v : G[u]) {
    if (checked[v]) continue;
    res *= dfs(u, v);
    res %= mod;
  }
  return res;
}
int main() {
  cin >> n >> k;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans = k * dfs(-1, 0);
  ans %= mod;
  print(ans);
  return 0;
}

Measured memory_bytes: 9600
# https://atcoder.jp/contests/abc104/tasks/abc104_c

import itertools as it

INF = 100000007

if __name__ == "__main__":
    D, G = map(int, input().split())
    pairs = [[int(s) for s in input().split()] for _ in range(D)]
    p, c = zip(*pairs)
    res = INF

    iterables = it.product([False, True], repeat=D)
    for choice in iterables:
        cnt = 0
        total = 0
        for i in range(D):
            if choice[i]:
                cnt += p[i]
                total += 100 * (i + 1) * p[i] + c[i]

        for j in reversed(range(D)):
            if total >= G:
                break
            if not choice[j]:
                item_value = 100 * (j + 1)
                item_count = min(p[j], (G - total + item_value - 1) // item_value)
                cnt += item_count
                total += item_value * item_count

        if cnt < res:
            res = cnt

    print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

int main() {
    ll N,K;
    cin >> N >> K;
    ll ans=0;
    if(K==0){
        cout << N*N << endl;
        return 0;
    }
    for(int b=K+1;b<=N;b++){
        ans+=N/b*(b-K);
        ans+=max(N%b-K+1,(ll)0);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

void solve(istream &ccin = cin, ostream &ccout = cout) {
  ll n;
  ccin >> n;
  ll1d d(n);
  rep(i, n) ccin >> d[i];
  set<ll> s;
  rep(i, n){
    s.insert(d[i]);
  }

  ccout << s.size() << endl;


}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc118/tasks/abc118_c

// http://ctylim.hatenablog.com/entry/2015/08/30/191553
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cstdio>

#define ALL(a) (a).begin(), (a).end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define MAXINDEX(c) distance((c).begin(), max_element((c).begin(), (c).end()))
#define MININDEX(c) distance((c).begin(), min_element((c).begin(), (c).end()))
#define DEBUG(x) std::cerr << #x << " = " << (x) << " (" << __FILE__ << "::" << __LINE__ << ")" << std::endl;
#define ERROR(s) std::cerr << "Error::" << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << "::" << (s) << std::endl;
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)

#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

template <typename T>
T inputValue()
{
  T a;
  // std::cin >> a;
  scanf("%llu", &a);
  return a;
}

void inputArray(int *p, int a)
{
  rep(i, a)
  {
    std::cin >> p[i];
    // scanf("%d",p+i);
  }
}

template <typename T>
void inputVector(std::vector<T> *p, int a)
{
  rep(i, a)
  {
    T input;
    // std::cin >> input;
    scanf("%llu", &input);
    p->push_back(input);
  }
}

template <typename T>
void output(T a, int precision)
{
  if (precision > 0)
  {
    std::cout << std::setprecision(precision) << a << "\n";
  }
  else
  {
    std::cout << a << "\n";
  }
}

using namespace std;

int gcd(int a, int b)
{
  while (1)
  {
    if (a < b)
      swap(a, b);
    if (!b)
      break;
    a %= b;
  }
  return a;
}

typedef unsigned long long int ulli;
int main(int argc, char **argv)
{

  int N = 0;
  int bit1 = 0;

  char c;
  while (( c = getc(stdin)) != EOF && (c == '0' || c == '1') ) {
    N ++ ;
    bit1 = bit1 + (c=='1');
  }
  cout << N-abs(bit1-(N-bit1)) << endl;
}

// https://stackoverflow.com/questions/18097922/return-value-of-operator-in-c
// C11(ISO/IEC 9899:201x) §6.5.8 Relational operators
// Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false.107) The result has type int.


Measured memory_bytes: 256
while true
n = gets.chomp.split
m = n[0].to_i
d = n[1].to_i
if m == 0
    break
end
if m == 1
    a = d % 7 
    elsif m == 2
    a = (d + 3) % 7
    elsif m == 3
    a = (d + 4) % 7
    elsif m == 4
    a = (d + 7) % 7
    elsif m == 5
    a = (d + 2) % 7
    elsif m == 6
    a = (d + 5) % 7
    elsif m == 7
    a = (d + 7) % 7
    elsif m == 8
    a = (d + 3) % 7
    elsif m == 9
    a = (d + 6) % 7
    elsif m == 10
    a = (d + 1) % 7
    elsif m == 11
    a = (d + 4) % 7
    elsif m == 12
    a = (d + 6) % 7
end


if a == 1
    puts "Thursday"
    elsif a == 2
    puts "Friday"
    elsif a == 3
    puts "Saturday"
    elsif a == 4
    puts "Sunday"
    elsif a == 5
    puts "Monday"
    elsif a == 6
    puts "Tuesday"
    elsif a == 0
    puts "Wednesday"
end
end



Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, a[MAXN], ans[MAXN];
int main() {
	read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	for (int i = n; i >= 1; i--) {
		int pos = 0;
		for (int j = 1; j <= i; j++)
			if (a[j] == j) pos = j;
		if (pos == 0) {
			puts("-1");
			return 0;
		}
		ans[i] = pos;
		for (int j = pos; j < i; j++)
			a[j] = a[j + 1];
	}
	for (int i = 1; i <= n; i++)
		writeln(ans[i]);
	return 0;
}

Measured memory_bytes: 256