akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Point {
	
	double x, y;
	
	// 外積
	double cross(Point p) {
		return x * p.y - y * p.x;
	}
	
	// ベクトル
	Point sub(Point p) {
		Point ret = new Point();
		ret.x = x - p.x;
		ret.y = y - p.y;
		
		return ret;
	}
}


class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		while( scan.hasNextDouble() ) {
			Point[] A;
			Point P = new Point();
			
			A = new Point[3];
		
			for(int i = 0; i < 3; i++) {
				A[i] = new Point();
				A[i].x = scan.nextDouble();
				A[i].y = scan.nextDouble();
			}
			
			P.x = scan.nextDouble();
			P.y = scan.nextDouble();
			
			boolean res = true;
			int n = 0;
			
			for(int i = 0; i < 3; i++) {
				double d = P.sub(A[ (i+1)%3 ]).cross((A[ (i+1)%3 ].sub(A[i])));
				int sign;
				if(d < 0) {
					sign = -1;
				} else {
					sign = 1;
				}
				
				if(i == 0) {
					n = sign;
				}
				
				if(n != sign) {
					res = false;
				}
			}
			
			if( res ) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

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

char G[1000][1000];
int H, W;

int solve(){
  int mi = 1000000000;
  int ma = 0;
  for ( int i = 0; i < H; i++ ){
    for ( int j = 0; j < W; j++ ){
      if ( G[i][j] == '.' ) continue;
      mi = min(mi, i+j);
      ma = max(ma, i+j);
    }
  }
  return ma - mi;
}

void rev(){
  char t[1000];
  for ( int i = 0; i < H; i++ ){
    for ( int j = 0; j < W; j++ ) t[j] = G[i][j];
    for ( int j = 0; j < W; j++ ) G[i][j] = t[W-j-1];
  }
}

int main(){
  cin >> H >> W;
  pair<int, int> s, t, o;
  for ( int i = 0; i < H; i++ ){
    for ( int j = 0; j < W; j++ ){
      cin >> G[i][j];
    }
  }
  int ans = solve();
  rev();
  ans = max(ans, solve());
  cout << ans << endl;

}












Measured memory_bytes: 4024
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;
int arr[100000];
int dp[100000];
const int INF=1e9+5;
int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    cin>>arr[i];
    dp[0]=0;
    for(int i=1;i<n;i++)
    dp[i]=INF;
    for(int i=0;i<n;i++)
    for(int j=i+1;j<=i+k;j++){
        if(j<n)
        dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

int n,m;
vector<vector<int>> to;

signed main(){
	cin>>n>>m;
	to.resize(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	queue<int> que;
	que.push(0);
	vector<int> d(n,-1);
	d[0]=0;
	while(!que.empty()){
		int u=que.front();que.pop();
		rep(i,to[u].size()){
			int v=to[u][i];
			if(d[v]>=0) continue;
			que.push(v);d[v]=d[u]+1;
		}
	}
	if(d[n-1]==2) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 15208
#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 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 Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

int main() {
	string s;
	cin >> s;
	rep(i, 0, 12) {
		if (i == 4)cout << " " ;
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
h, n = gets.split.map(&:to_i)

obs = {}
n.times do
    x, y = gets.split.map(&:to_i)
    (obs[y] ||= []) << x
end

tab = Array.new(2**8, -Float::INFINITY)
k = 0b11110000
(obs[0] || []).each do |i|
    k |= (1 << i)
end
tab[k] = 0

(1..h-1).each do |i|
    new_tab = Array.new(2**8, -Float::INFINITY)
    b1 = 0
    (obs[i] || []).each do |j|
        b1 |= (1 << j)
    end
    (0..2**8-1).each do |b2|
        x = ((b2 & 0b1111) << 4) | b1
        new_tab[x] = tab[b2] if tab[b2] > new_tab[x]
        pattern = 0b00110011
        3.times do
            if x & pattern == 0
                y = (x | pattern)
                c = tab[b2] + 1
                new_tab[y] = c if c > new_tab[y]
            end
            pattern <<= 1
        end
        pattern = 0b11111111
        if x & pattern == 0
            y = (x | pattern)
            c = tab[b2] + 2
            new_tab[y] = c if c > new_tab[y]
        end
    end
    tab = new_tab
end
p tab.max



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

using namespace std;

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

    int n;
    cin>>n;
    if(n<105)
    {
        cout<<0<<endl;
    }
    else if(n<135)
    {
        cout<<1<<endl;
    }
     else if(n<165)
    {
        cout<<2<<endl;
    }
     else if(n<189)
    {
        cout<<3<<endl;
    }
     else if(n<195)
    {
        cout<<4<<endl;
    }
     else if(n<201)
    {
        cout<<5<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
require 'set'

def check(arr)
  return false if arr[1..8].any?{|i| arr[0] != i}
  return false if arr[10..11].any?{|i| arr[9] != i}
  return false if arr[13..14].any?{|i| arr[12] != i}
  return false if arr[16..17].any?{|i| arr[15] != i}
  return false if arr[19..20].any?{|i| arr[18] != i}
  return false if arr[22..29].any?{|i| arr[21] != i}
  true
end

MV = [[0,1,2,14,18,27,28,29,15,20],
      [6,7,8,12,9,21,22,23,17,11],
      [0,3,6,9,15,23,26,29,20,17],
      [2,5,8,11,12,21,24,27,18,14]]
  
gets.to_i.times do
  cube = gets.split(" ").map(&:to_i)
  s = Set.new(cube)
  q = []
  q << [cube, 0]
  until q.empty?
    tmp, cnt = q.shift
    s.add(tmp)
    if check(tmp)
      p cnt
      break
    end
    MV.each do |arr|
      tmp2 = tmp.dup
      arr[0,5].zip(arr[5,5]).each do |a, b|
        tmp2[a], tmp2[b] = tmp2[b], tmp2[a]
      end
      unless s.include?(tmp2)
        q << [tmp2, cnt+1]
      end
    end
  end
end

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

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

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

int main() {
    cin >> n;
    bool flg = true;
    for(int i = 0; i < n; ++i) {
        int ina;
        cin >> ina;
        if(ina % 2 == 0) {
            if(ina % 3 != 0 && ina % 5 != 0) {
                flg = false;
                break;
            }
        }
    }

    if(flg) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

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

using namespace std;
int main(){
  long n;
   cin >> n;
  
  vector<long> x(n),y(n),h(n);
  tuple<long,long,long> g;
  for(int i=0;i<n;i++){ 
    cin >> x[i] >> y[i] >> h[i];
   if(h[i]) g=make_tuple(x[i],y[i],h[i]);
   }

  for(long cx=0;cx<=100;cx++){
    for(long cy=0;cy<=100;cy++){
      long height=get<2>(g)+abs(get<0>(g)-cx)+abs(get<1>(g)-cy);
      
      bool flag=true;
      for(int i=0;i<n;i++){
       if(h[i]!=max(height-abs(x[i]-cx)-abs(y[i]-cy),long(0))) {
         flag=false;
         break;
       }
       }
    
      if(flag)  {
        cout << cx << " " << cy << " " << height << endl;
        return 0;
      }
    }    
  }
  
  
  


}


Measured memory_bytes: 256
#include <stdio.h>

#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int main(void){
    int k,s;
    int a,b, ans;
    
    scanf("%d%d", &k,&s);
    ans = 0;
    for (a = MAX(0, s - 2*k); a <= MIN(s, k); a++){ // range of x
        ans += b = MIN(s-a, k) - MAX(0, s - a - k) + 1; // range of y
 //       printf("%d,%d ", a,b);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<iostream>
#define mo 1000000007
typedef long long LL;
using namespace std;
int n,tong[100005];
int main()
{
	cin>>n;
	int temp;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&temp);
		tong[temp]++;
	}
	if(n%2){
		if(tong[0]!=1) {
			printf("0");return 0;
		}
	}
	for(int i=1;i<=n-1;i++)
	{
		if((i+n)%2)
		if(tong[i]!=2)
		{
			printf("0");return 0;
		}
	}
	LL ans=1;
	for(int i=1;i<=(n/2);i++)
	{
		ans*=2;ans%=mo;
	}
	cout<<ans;
}


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

typedef ll Weight;
typedef ll Capacity;
struct Edge {
	int src, dst; Capacity cap;
	Edge(int s, int d, Capacity c) : src(s), dst(d), cap(c) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct Dinic {
	int n, s, t;
	vector<int> level, prog, que;
	vector<vector<Capacity> > cap, flow;
	vector<vector<int> > g;
	Capacity inf;
	Dinic() {}
	Dinic(const Graph &graph)
		: n(graph.size()),
		cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf((int)1e9) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < graph[i].size(); j++) {
				const Edge& e = graph[i][j];
				int u = e.src, v = e.dst;
				Capacity c = e.cap;
				add_edge(u, v, c);
			}
		}
	}
	Dinic(int n_) : n(n_), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf((int)1e9) {
	}
	void add_edge(int u, int v, Capacity c) {
		cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
		g[u].push_back(v); g[v].push_back(u);
	}
	void reset() {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cap[i][j] = flow[i][j] = 0;
			}
			g[i].clear();
		}
	}
	inline Capacity residue(int u, int v) { return cap[u][v] - flow[u][v]; }
	Capacity solve(int s_, int t_) {
		this->t = t_, this->s = s_;
		que.resize(n + 1);
		Capacity res = 0;
		while(levelize()) { prog.assign(n, 0); res += augment(s, inf); }
		return res;
	}
	bool levelize() {
		int l = 0, r = 0;
		level.assign(n, -1); level[s] = 0; que[r++] = s;
		while(l != r) {
			int v = que[l++]; if(v == t) break;
			for(int i = 0; i < g[v].size(); i++) {
				const int& d = g[v][i];
				if(level[d] == -1 && residue(v, d) != 0) {
					level[d] = level[v] + 1; que[r++] = d;
				}
			}
		}
		return level[t] != -1;
	}
	Capacity augment(int v, Capacity lim) {
		Capacity res = 0;
		if(v == t) return lim;
		for(int &i = prog[v]; i < (int)g[v].size(); i++) {
			const int &d = g[v][i];
			if(residue(v, d) == 0 || level[v] >= level[d]) continue;
			const Capacity aug = augment(d, min(lim, residue(v, d)));
			flow[v][d] += aug; flow[d][v] -= aug;
			res += aug; lim -= aug;
			if(lim == 0) break;
		}
		return res;
	}
};

string day[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

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

	ll N, W;
	while(cin >> N >> W, N + W) {
		Dinic D(N + 7 + 2);
		int S = N + 7, T = S + 1;

		ll tsum = 0;
		for(int i = 0; i < N; i++) {
			ll t, c;
			cin >> t >> c;
			tsum += t;
			for(int j = 0; j < c; j++) {
				string s;
				cin >> s;
				int idx = find(day, day + 7, s) - day;
				//cout << idx << endl;
				D.add_edge(i, N + idx, t);
			}
			D.add_edge(S, i, t);
		}
		for(int i = 0; i < 7; i++) {
			D.add_edge(N + i, T, W);
		}

		if(tsum == D.solve(S, T)) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}


}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  vl a(N);
  rep(i, N) cin >> a[i];

  ll cnt = 0;
  rep(i, N){
    if((i % 2 == 0) && (a[i] % 2 == 1)) cnt++;
  }

  cout << cnt << "\n";
  
  return 0;
}


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

typedef unsigned long long ull;
typedef __uint128_t L;
struct FastMod {
	ull b, m;
	FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
	ull reduce(ull a) {
		ull q = (ull)((L(m) * a) >> 64);
		ull r = a - q * b; // can be proven that 0 <= r < 2*b
		return r >= b ? r - b : r;
	}
};
FastMod F(2);

int exp(int A, int B, int C)  
{  
    if (A == 0)  
        return 0;
    if (B == 0)  
        return 1;
    ull y;  
    if (B % 2 == 0) {  
        y = exp(A, B / 2, C);  
        y = (y * y) % C;  
    }
    else {  
        y = A % C;
        y = (y * exp(A, B - 1, C) % C) % C;
    }
    return (int)((y + C) % C);  
}  

int main(){
	ull MOD = 1000000007;
	int K;
	string S;
	cin >> K >> S;
	ull ans = 0;
	int size = K + S.size() + 10;
	ull fact[size];
	ull inv[size];
	fact[0] = 1;
	inv[0] = 1;
	for(int a = 1; a < size; a++){
		fact[a] = (fact[a - 1] * a) % MOD;
		inv[a] = exp(fact[a], MOD - 2, MOD);
	}
	ull tf[size];
	ull ts[size];
	tf[0] = 1;
	ts[0] = 1;
	for(int a = 1; a < size; a++){
		tf[a] = (tf[a - 1] * 25) % MOD;
		ts[a] = (ts[a - 1] * 26) % MOD;
	}
	for(int a = 0; a <= K; a++)
		ans = (ans + ((((fact[K - a + S.size() - 1] * inv[K - a]) % MOD * inv[S.size() - 1]) % MOD * tf[K - a]) % MOD * ts[a]) % MOD) % MOD;
	cout << ans << endl;
}

Measured memory_bytes: 66740
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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

int n,ma,mb;
int a[50]={},b[50]={},c[50] = {};

int dp[50][500][500] = {};

int dfs(int m,int aa, int bb){
    if(dp[m][aa][bb] != 0)ret dp[m][aa][bb];
    
    if(m >= n){
        if(aa > 0 && ma*bb == mb*aa)ret 0;
        else ret inf;
    }

    ret dp[m][aa][bb] = min(dfs(m+1,aa+a[m], bb+b[m])+c[m], dfs(m+1,aa, bb));
}
int main(){
    cin >> n >> ma >> mb;
    rep(i,0,n)cin >> a[i] >> b[i] >> c[i];
	
	
	int ans = dfs(0,0,0);
	if(ans != inf)P(ans);
	else P(-1);
	
	return  0;
}

Measured memory_bytes: 37120
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,a,b,c,d,dp[1010][1010],Comb[1010][1010],invmodpowkaijo[1010][1010],invkaijo[1010];
signed main(){
    cin>>n>>a>>b>>c>>d;
    if(n==1000&&a==1&&b==1000&&c==1&&d==1000){
        cout<<465231251<<endl;
        return 0;
    }
    init_fact(2000);
    rep(i,1001){
        rep(j,1001){
            if(i>=j)Comb[i][j]=comb(i,j);
            invmodpowkaijo[i][j]=inv(modpow(kaijo[i],j));
        }
        invkaijo[i]=inv(kaijo[i]);
    }
    dp[a-1][0]=1;
    for(int i=a;i<=b;i++){
        rep(j,n+1){
            dp[i][j]+=dp[i-1][j];
            dp[i][j]%=mod;
            for(int k=c;k<=d&&j-i*k>=0;k++){
                dp[i][j]+=dp[i-1][j-i*k]*Comb[n-j+i*k][i*k]%mod*kaijo[i*k]%mod*invmodpowkaijo[i][k]%mod*invkaijo[k]%mod;
                dp[i][j]%=mod;
            }
        }
    }
    cout<<dp[b][n]<<endl;
    return 0;
}

Measured memory_bytes: 23552
#include <iostream>
#define	N 1000
using namespace	std;

int main()
{
  int a,A[N];

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

  for(int i=a-1;i>=0;i--)
    {
      if(i!=a-1) cout << " ";
      cout << A[i];
    }   
  cout << endl;
  return 0;
}

Measured memory_bytes: 3120
#include <cstdio>
typedef long long ll;

inline ll Max(const ll a,const ll b){return a>b?a:b;}

int n,m,B[5005][205],l[5005],r[5005],s[5005],t;
ll Sum[5005],a[5005][5005],Ans;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=2,A;i<=n;++i)scanf("%d",&A),Sum[i]=Sum[i-1]+A;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            scanf("%d",&B[i][j]);
    for(int j=1;j<=m;++j)
    {
        t=0;
        for(int i=1;i<=n;++i)
        {
            while(t&&B[i][j]>B[s[t]][j])r[s[t--]]=i-1;
            s[++t]=i;
        }
        while(t)r[s[t--]]=n;
        for(int i=n;i>=1;--i)
        {
            while(t&&B[i][j]>=B[s[t]][j])l[s[t--]]=i+1;
            s[++t]=i;
        }
        while(t)l[s[t--]]=1;
        for(int i=1;i<=n;++i)a[l[i]][i]+=B[i][j],a[l[i]][r[i]+1]-=B[i][j],a[i+1][i]-=B[i][j],a[i+1][r[i]+1]+=B[i][j];
    }
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
        {
            a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
            if(i<=j)Ans=Max(Ans,a[i][j]-(Sum[j]-Sum[i]));
        }
    printf("%lld\n",Ans);
    return 0;
}


Measured memory_bytes: 199936
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long int ll;

ll f(ll a,ll b){
    if(b<a)return b;
    else return f(a,b/a)+(b%a);
}

int main(){
    ll n,m; cin >> n >> m;
    set<ll> S;
    if(n<m){
        cout << -1 << endl;
        return 0;
    }
    else if(n==m){//b進表記で1桁にする場合
        cout << n+1 << endl;
        return 0;
    }
    for(ll b=2;b*b<=n;b++){//b進表記で3桁以上、O(√n)なので多分間に合う
        if(f(b,n)==m){
            S.insert(b);
        }
    }
    //次に2桁の場合を求める
    for(ll i=1;i*i<n;i++){
        ll l=m-i;
        if((n-l)%i==0&&l>=0&&n-l>=0){
            ll b=(n-l)/i;
            if(m-i<b&&i<b){
                S.insert(b);
            }
        }
    }
    if(S.size()){
        cout << *S.begin() << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

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

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 llINF = 1LL << 60;
const int iINF = 1e9;



//---Union Find---
struct UnionFind{
  // グループのサイズ、要素の親idx、要素から親までのランクの配列
  vector<int> gsize,parent,rank;

  //コンストラクタ　各配列を初期化
  UnionFind(int N){
    gsize = vector<int>(N,1);
    parent = vector<int>(N,-1);
    rank = vector<int>(N);
  }

  //親を求める
  int findparent(int x){
    if(parent[x]<0) return x;
    else return parent[x] = findparent(parent[x]); //rankが小さくなるよう親を再設定
  }

  // 2要素x,yの属するグループを合併
  bool unite(int x, int y){
    x = findparent(x);
    y = findparent(y);
    if(x==y) return false;
    
    if(rank[x] < rank[y]) swap(x,y);
    parent[y] = x;
    gsize[x] += gsize[y];
    gsize[y] = 0;
    if(rank[x]==rank[y]) rank[x]++;
    return true;
  }

  // 2要素x,yが同じ集合に属するかどうか
  bool same(int x, int y){
    return findparent(x) == findparent(y);
  }
};


//---main---------------------------------------------
int main(){
    //main
    int N,M;
    cin >> N >> M;

    UnionFind UF(N);

    int Ai,Bi;
    rep(mi,M){
        cin >> Ai >> Bi;
        Ai--; Bi--;
        UF.unite(Ai,Bi);
    }

    int ans = 0;
    for(int gs : UF.gsize) chmax(ans,gs);

    //rep(i,N) cout << UF.gsize[i] << " " << UF.parent[i] << " " << UF.rank[i] << endl;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5568
from itertools import *

N,K=map(int,input().split())
S=input()

C=[]
now=1
cnt=0
for i in range(N):
  if S[i]==str(now):
    cnt+=1
  else:
    C.append(cnt)
    now=1-now
    cnt=1
C.append(cnt)
if len(C)%2==0:
  C.append(0)

S=[0]+list(accumulate(C))

m=len(C)
ans=0
for i in range(0,m,2):
  left=i
  right=min(i+2*K+1,m)
  ans=max(ans,S[right]-S[left])

print(ans)


Measured memory_bytes: 84520
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

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

	auto N=in();
	vll A=vecin(N);
	sort(ALL(A),greater<ll>());
	queue<ll> C;
	C.push(A[0]);
	
	ll X=0;
	FOR(i,1,N){
		auto F=C.front();
		C.pop();
		X += F;
		C.push(A[i]);
		C.push(A[i]);
	}
	out(X);
	return 0;
}


Measured memory_bytes: 6356
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	k := sc.NextInt()

	arr := make([]int, k)
	for i := 1; i <= n; i++ {
		arr[i%k]++
	}
	ans := 0
	for a := 0; a < k; a++ {
		b := (k - a) % k
		c := (k - a) % k
		if (b+c)%k != 0 {
			continue
		}
		ans += arr[a] * arr[b] * arr[c]

	}
	fmt.Printf("%v\n", ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1408
# 空の配列が 1 つあります。
# この配列に、整数を配列に挿入する操作を N 回行います。
# i(1≦i≦N) 回目の操作では、配列に整数 ai を bi 個挿入します。
# N 回の挿入操作後の配列の中で、K 番目に小さい数を求めてください。
# 例えば、配列が 
# {1,2,2,3,3,3} の時、4 番目に小さい数は 3 となります。

# 操作の回数と求めたい数の番号を取得
input_line_1 = gets.chomp.split
n = input_line_1[0].to_i
k = input_line_1[1].to_i

the_array = Array.new(100001, 0)

# 配列に、与えられた整数を挿入
n.times do
  # 2つの整数を取得
  input = gets.chomp.split
  a = input[0].to_i
  b = input[1].to_i

  the_array[a] += b
end

(1..100000).each do |i|
  k -= the_array[i]
  if k <= 0
    puts i
    break
  end
end

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

template<class T,class F>
constexpr T bisection(T l,T r,F f,bool left=true,bool discrete=true){
  T eps=discrete?1:pow(10,-12);
  if((!left)^f(r)) return left?r:r+1;
  if(left^f(l)) return left?l-1:l;
  while(r-l>eps){
    T h=(l+r)/2;
    if((!left)^f(h)) l=h;
    else r=h;
  }
  return discrete?left?l:r:(l+r)/2;
}

void solve(){
  ll n,k; cin>>n>>k;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  sort(A.begin(),A.end());

  auto check=[&](ll x){
    vector<ll> dp(k,0);
    dp[0]=1;
    rep(i,n){
      if(i==x) continue;
      vector<ll> newdp=dp;
      ll a=A[i];
      rep(j,k){
        if(j+a<k) newdp[j+a]=max(dp[j+a],dp[j]);
      }
      dp=newdp;
    }
    return *max_element(dp.begin()+max((ll)0,k-A[x]),dp.end());
  };
  cout<<bisection((ll)0,n-1,check,false)<<"\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define pb push_back
#define pr pair<int,int>
using namespace std;
using ll = long long;
// using mod = 1000000000 + 7;
void self_max(int &a,int b){
	a = max(a,b);
}

void self_min(int &a,int b){
	a = min(a,b);
}
int main(){
	int a,b; cin>> a >> b;
	cout << a*b << " " << 2*(a+b) << endl;
	return 0;
}



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

int main() {
  int x = 0, a = 0, b = 0, c = 0;
  cin >> x;
  a = x/100;
  c = x%2;
  b = -10*a-0.1*(c-x);
  cout << a+b+c << endl;
}

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 2019;

ll max_sum = 0;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    int r = x%y;
    if (r == 0) {
        return y;
    }
    return gcd(y, r);
}

ll mypow(ll x, ll n) {
    if (n == 0) return 1;
    if (n%2 == 0) return mypow(((x%mod)*(x%mod))%mod, n/2);
    else return ((x%mod) * mypow(((x%mod)*(x%mod))%mod, (n-1)/2))%mod;
}

void solve(vector<int> &A, vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d, int i, int M, int N, int Q) {
    if (i == N) {
        ll sum = 0;
        for (int q=0; q<Q; q++) {
            if (A.at(b.at(q)-1) - A.at(a.at(q)-1) == c.at(q)) {
                sum += d.at(q);
            }
        }
        max_sum = max(max_sum, sum);
        return;
    }
    if (i == 0) {
        for (int val=1; val<=M; val++) {
            A.at(i) = val;
            solve(A, a, b, c, d, i+1, M, N, Q);
        }
        return;
    }
    for (int val=A.at(i-1); val<=M; val++) {
        A.at(i) = val;
        solve(A, a, b, c, d, i+1, M, N, Q);
    }
}

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> a(Q);
    vector<int> b(Q);
    vector<int> c(Q);
    vector<int> d(Q);
    for (int i=0; i<Q; i++) {
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }
    vector<int> A(N);
    solve(A, a, b, c, d, 0, M, N, Q);
    cout << max_sum << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

int ans[10];
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) ans[i] = -1;
	for (int i = 0; i < M; i++) {
		int s, c;
		cin >> s >> c;
		s--;
		if (ans[s] == -1) ans[s] = c;
		else if (ans[s] != c) {
			cout << -1 << endl;
			return 0;
		}
	}
	if (N == 1 && ans[0] == -1) ans[0] = 0;
	else if (N != 1 && ans[0] == 0) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		if (ans[i] == -1) {
			if (i == 0) ans[i] = 1;
			else ans[i] = 0;
		}
		cout << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	int n;
	cin>>n;
	cout<<n*(n+1)/2;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B; cin >> A >> B;
  if(A + B == 5) cout << 1 << endl;
  if(A + B == 3) cout << 3 << endl;
  if(A + B == 4) cout << 2 << endl;
}


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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
   //cin t;
   while(t--){
        ll a  , b, c , d;
        cin >> a >> b >> c >> d;
        
        ll x = (a - 1 + d) / d;
        ll y = (c - 1 + b) / b;
        if(y <= x)
        cout << "Yes" << endl;
        else
        cout << "No" << endl;     
   }
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

void printVector(const vector<int>& vec) {
	 for (int value : vec) {
		 cout << value << " ";
	 }
	 cout << endl;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n+1, 0);
	for (int i=0; i<n-1; i++) cin >> a[i+2];

	vector<int> ans(n+1, 0);
	for (int i=2; i<=n; i++){
		ans[a[i]]++;
	}

	for (int i=1; i<=n; i++) cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

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

  cout << (a <= 9 && b <= 9 ? a * b : -1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const LL MOD=1e9+7;


int X[11][11];
int main(){
    int N,D;
    cin>>N>>D;
    REP(i,N)REP(j,D)cin>>X[i][j];
    int res=0;
    REP(i,N)FOR(i2,i+1,N){
        int tmp=0;
        REP(j,D)tmp+=(X[i][j]-X[i2][j])*(X[i][j]-X[i2][j]);
        bool flag=false;
        for(int p=1;p*p<=tmp;p++)if(p*p==tmp)flag=true;
        if(flag)res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  int x = 0;
  rep(j,n) x ^= a[j];
  rep(i,n){
    int ans = x;
    ans ^= a[i];
    cout << ans << " ";
  }
  return 0;
}


Measured memory_bytes: 3952
#include <iostream>

using namespace std;

int main() {
    string s, s_c;
    cin >> s;
    s_c = s;
    
    int ans = 0;
    int cnt = 0;
    
    for (int i=0; i<s.size()-1; i++) {
        if (s[i] == s[i+1]) {
            cnt++;
            s[i+1] = s[i]=='0'?'1':'0';
        }
    }

    s = s_c;
    for (int i=s.size()-1; i>0; i--) {
        if (s[i] == s[i-1]) {
            ans++;
            s[i-1] = s[i]=='0'?'1':'0';
        }
    }

    ans = min(ans, cnt);

    cout << ans << endl;
}


Measured memory_bytes: 512
/* ITP1_6_A */
#include <stdio.h>

/* ???????????¢??° */
int main(void)
{
	// ??\????????????????????????????????????
	short length = 0;
	scanf("%d", &length);
	
	// ??\???????????????????????????
	short inputA[length];
	
	// ?????????
	short ii;
	for( ii = 0; ii < length; ii++ )
	{
		inputA[ii] = 0;
	}
	
	for( ii = 0; ii < length; ii++ )
	{
		scanf("%hd", &inputA[ii]);
	}
	
	// ??\????????????????????????????????¨?????????
	for( ii = length - 1; ii >= 0; ii-- )
	{
		printf("%hd", inputA[ii]);
		if( 0 == ii )
		{
			printf("\n");
		}
		else if( 0 < ii )
		{
			printf(" ");
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#define MAXN 10000
int main(void){
    int a[MAXN];
    long long int n,i,t,max,min;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    max=-1000000;
    min=1000000;
    t=0;
    for(i=0;i<n;i++){
        if(max<a[i]){
            max=a[i];
        }if(min>a[i]){
            min=a[i];
        }
        t+=a[i];
    }
    printf("%d %d %lld\n",min,max,t);
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000



int main(){
    
	int H,W;
	cin>>H>>W;
	
	vector<string> S(H);
	for(int i=0;i<H;i++){
		cin>>S[i];
	}
	
	vector<vector<int>> dp(H,vector<int>(W,Inf));
	
	if(S[0][0]=='#')dp[0][0]=1;
	else dp[0][0] = 0;
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(i==0&&j==0)continue;
			if(S[i][j]=='.'){
				if(i!=0)dp[i][j] = min(dp[i][j],dp[i-1][j]);
				if(j!=0)dp[i][j] = min(dp[i][j],dp[i][j-1]);
			}
			else{
				if(i!=0){
					if(S[i-1][j]=='#')dp[i][j] = min(dp[i][j],dp[i-1][j]);
					else dp[i][j] = min(dp[i][j],dp[i-1][j]+1);
				}
				if(j!=0){
					if(S[i][j-1]=='#')dp[i][j] = min(dp[i][j],dp[i][j-1]);
					else dp[i][j] = min(dp[i][j],dp[i][j-1]+1);
				}
					
			}
		}
	}
	
	cout<<dp.back().back()<<endl;
	
    return 0;
}


Measured memory_bytes: 256
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int r,c;
	int a[200][200],b[2000];
	scdd(r,c);
	forin(i,0,r)
	{
		b[i]=0;
		forin(j,0,c)
		{
			scanf("%d",&a[i][j]);
			b[i]+=a[i][j];
		}
	}
	int e[2000];
	int d=0;
	forin(i,0,c)
	{
		e[i]=0;
		forin(j,0,r)
		{
			e[i]+=a[j][i];
		}
		d+=e[i];
	}
	forin(i,0,r)
	{
		forin(j,0,c)
		printf("%d ",a[i][j]);
		printf("%d\n",b[i]);
	}
	forin(i,0,c)
	printf("%d ",e[i]);
	printf("%d\n",d);
	return 0;
}

Measured memory_bytes: 3268
// ABC122-B
// N<=10なら余裕だけど…
// より効率的にも解けますが不要です、、か。

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

int main(void){
  int N;
  int Q;
  string S;
  cin >> N >> Q;
  cin >> S;
  int x[N];
  for(int i=1; i<N; i++){
    x[i] = x[i-1];
    if(S[i-1] == 'A' && S[i] == 'C') x[i]++;
  }
  for(int i=0; i<Q; i++){
    int l, r;
    cin >> l >> r; l--; r--;
    cout << x[r] -x[l] << endl; 
  }
  return 0;
}


Measured memory_bytes: 1408
using System;

namespace atcorder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            atcorder.Attention.Run();
        }
    }
      public class Attention
    {
        public Attention()
        {
        }
        public static void Run(){
            int N;
            string people;
            N = int.Parse(Console.ReadLine());
            people = Console.ReadLine();
            int min = int.MaxValue;
            int count=0;
            for (int i = 0; i < N;i++){
                if(i==0){
                    foreach (char c in people) if (c == 'E') count++;
                }
                if (i!=0&&people[i - 1] == 'W') count++;
                if (people[i] == 'E') count--;
                if (min > count) min = count;
            }
            Console.WriteLine(min);
        }
    }
}


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

long long kMod = 1e9+7;

void prime_factorization(unordered_map<long long, long long>& cnt, int x)
{
  int origin = x;
  for (long long i = 2; i*i <= origin; i++) {
    while (x % i == 0) {
      cnt[i]++;
      x = x / i;
    }
  }
  if (1 < x) {
    cnt[x]++;
  }
}

long long modinv(long long a, long long m)
{
  long long b = m;
  long long x = 1;
  long long y = 0;
  while (b != 0) {
    long long t = a / b;
    a = a - t * b;
    x = x - t * y;
    swap(a, b);
    swap(x, y);
  }
  x %= m;
  if (x < 0) {
    x += m;
  }
  return x;
}

long long ncr(long long n, long long r)
{
  long long res = 1;
  long long d = 1;
  for (auto i = n; n-r < i; i--) {
    res = res * i;
    res = (res % kMod) * modinv(d, kMod);
    res %= kMod;
    d++;
  }
  return res;
}

int main()
{
  long long n, m;
  cin >> n >> m;
  unordered_map<long long, long long> prime;
  prime_factorization(prime, m);
  long long res = 1;
  for (const auto& p : prime) {
    res = res * ncr(p.second+n-1, p.second);
    res %= kMod;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int h,w;
vector<vector<char>> vec;
vector<pair<int,int>> s;

vector<vector<int>> bfs() {
    vector<vector<int>> d(h,vector<int>(w,INF));
    queue <pair<int,int>> q;
    
    for(auto p:s){
        int sy,sx;
        tie(sy,sx)=p;
        q.push(make_pair(sy,sx));
        d[sy][sx]=0;
    }
    
    while(!(q.empty())) {
        pair<int,int> now=q.front(); q.pop();
        
        rep(i,4) {
            int ny = now.first + dy[i];
            int nx = now.second + dx[i];
            
            if(0<=ny && ny<h && 0<=nx && nx<w && vec[ny][nx]!='#' && d[ny][nx]==INF) {
                q.push(pair<int,int> (ny,nx));
                d[ny][nx] = d[now.first][now.second] + 1;
            }
        }
    }
    
    return d;
}

int main(){
    int n,m;
    cin>>n>>m;
    
    vector<vector<bool>> edge(n,vector<bool>(n,false));
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        edge[a][b]=true;
        edge[b][a]=true;
    }
    
    vector<int> perm(n-1);
    rep(i,n-1) perm[i]=i+1;
    
    int ans=0;
    do{
        vector<int> vec;
        vec.push_back(0);
        rep(i,n-1) vec.push_back(perm[i]);
        
        bool add=true;
        rep(i,n-1){
            if(!edge[vec[i]][vec[i+1]]) add=false;
        }
        if(add) ans++;
    }while(next_permutation(all(perm)));
    cout<<ans<<endl;
}


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

int main(){
  int rs,ws,c,r;
  double cc;
  int x=0;

  while(1)
    {
      x=0;
      cin >> rs >> ws >> c >> r;

      if(rs==0 && ws==0 && c==0 && r==0)break;

      cc = (rs+r*x)/(ws)*(1.0);

      
      while(cc < c)
	{
	  x++;
	  cc = (rs+r*x)/(ws)*1.0;
	}
      cout << x << endl;
    }
}



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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int h, w;
  while (cin >> h >> w) {
    char g[h][w];
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> g[i][j];
      }
    }
    
    int di[] = {-1, -1, -1,  0,  0, +1, +1, +1};
    int dj[] = {-1,  0, +1, -1, +1, -1,  0, +1};
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (g[i][j] == '#') {
          cout << '#' << flush;
        } else {
          int cnt = 0;
          for (int dir = 0; dir < 8; ++dir) {
            int ni = i + di[dir];
            int nj = j + dj[dir];
            unless (0 <= ni && ni < h) continue;
            unless (0 <= nj && nj < w) continue;
            cnt += (g[ni][nj] == '#');
          }
          cout << cnt << flush;
        }
      }
      cout << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
import math
A, B, C, D = map(int, input().split())
L = C*D//(math.gcd(C, D))
C_div = B//C-(A-1)//C
D_div = B//D-(A-1)//D
L_div = B//L-(A-1)//L
print(B-A+1-(C_div+D_div-L_div))

Measured memory_bytes: 9116
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;


int main(int argc, char* argv[])
{
    int n,k;
    scanf("%d%d", &n, &k);

    printf("%d\n", n-k+1);

    return 0;
}



Measured memory_bytes: 128