akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
void solve()
{
    ll n;
    cin>>n;
    if(n%2)
    cout<<(n/2)+1;
    else
    cout<<n/2;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<deque>
using namespace std;
typedef long long int ll;

#define MAX_A 10000000
const ll MOD = 1000000007;


int main(){

    int n,m;
    ll ans = 0;
    cin  >> n >> m;
    if(abs(n-m) > 1){
        cout << "0" << endl;
        return 0;
    }

    vector<ll> a(MAX_A,0);
    a[0] = 1;
    for(int i = 1;i <= max(n,m);i++){

        a[i] = a[i-1]*i%MOD;
    }
    
    if(abs(n-m)==1){
        cout << a[n]*a[m]%MOD << endl;
    }else{
        cout << 2*a[n]*a[m]%MOD << endl;
    }
 

    return 0;

}

Measured memory_bytes: 78336
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int a, b, x;
	cin >> a >> b >> x;

	double menseki = 1.0 * x / a;

	double pi = acos(-1);
	double L = 0, R = pi / 2;

	rep(i, 50) {
		double M = (L + R) / 2;
		double sita;
		if (tan(M) * b < a) {
			sita = 0.5 * b * tan(M) * b;
		}
		else {
			sita = a * b - 0.5 * a / tan(M) * a;
		}
		if (sita > menseki) R = M;
		else L = M;
	}

	cout << setprecision(12) << (pi / 2 - L) / pi * 180 << endl;


	Would you please return 0;
}

Measured memory_bytes: 512
gets.to_i.times{|n|
gets
m=(1..8).map{gets}
q=[[gets.to_i-1,gets.to_i-1]]
while q!=[]
x,y=q.pop
x<8&&x>=0&&y<8&&y>=0&&m[y][x]>?0&&(
m[y][x]=?0
q.push *(-3..3).flat_map{|i|[[x,y+i],[x+i,y]]}
)
end
puts "Data #{n+1}:",m
}

Measured memory_bytes: 6112
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
int field[200][200];

int main(){
  while(1){
    cin >> n;
    if(!n)break;
    clr(field,0);
    rep(i,0,n)rep(j,0,5)cin >> field[i][j];
    ll ans = 0;
    bool f = true;
    while(f){
      f = false;
      rep(i,0,n){
        rep(j,0,5){
          l = 1;
          rep(k,j,5){
            if(field[i][k] == 0)break;
            if(field[i][k] != field[i][k+1])break;
            l++;
          }
          if(l >= 3){
            f = true;
            rep(k,j,j+l){
              ans += field[i][k];
              field[i][k] = 0;
            }
          }
        }
      }
      // rep(i,0,n){
      //   rep(j,0,5)cout << field[i][j];
      //   puts("");
      // }
      // puts("");
      pel(i,n-1,0){
        rep(j,0,5){
          if(!field[i][j]){
            // cout << i << " " << j << endl;
            l = 0;
            pel(k,i,0){
              if(!field[k][j])l++;
              else break;
            }
            rep(k,0,n-i){
              if(i - k < 0)break;
              if(i - k - l< 0)break;
              field[i-k][j] = field[i-k-l][j];
              field[i-k-l][j] = 0;
            }
          }
        }
      }
      // rep(i,0,n){
      //   rep(j,0,5)cout << field[i][j];
      //   puts("");
      // }
      // puts("===================================");
    }
    print(ans);
  }
  return 0;
}


Measured memory_bytes: 3304
#include <iostream>

using namespace std;

int main()
{
  int a,b,c;
  char op;
  cin>>a>>op>>b;
  if(op=='+'){
    c=a+b;
    cout<<c<<endl;
  }
  else{
    c=a-b;
    cout<<c<<endl;
  }



    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  val d = Angle.fromAngle(k * 360d / 2 / n).cos / Angle.fromAngle((k - 1) * 360d / 2 / n).cos
  val result = (0 until n).map{a ⇒
    val ca = Coordinate(Angle.fromAngle(a * 360d / n))
    val cb = Coordinate(Angle.fromAngle((a + 1) % n * 360d / n))
    val cm = Coordinate(Angle.fromAngle((2 * a + 1) * 180d / n)) * d
    (ca, cm, cb)
  }
  println(
    f"${result.map{case (f, m, t) ⇒ (f.x - m.x) * (f.y + m.y) + (m.x - t.x) * (m.y + t.y)}.sum / 2}%.10f"
  )
}
object Coordinate{
  def apply(angle: Angle): Coordinate = Coordinate(angle.cos, angle.sin)
}
case class Coordinate(x: Double, y: Double) {
  def *(that: Double): Coordinate = Coordinate(x * that, y * that)
}
object Angle {
  def fromAngle(angle: Double): Angle = {
    Angle(math.sin(angle / 180 * math.Pi), math.cos(angle / 180 * math.Pi))
  }
}
case class Angle(sin: Double, cos: Double)


Measured memory_bytes: 238336
#include<stdio.h>

int main(void)
{
	int m, f, r;

	while (1)
	{
		scanf("%d%d%d", &m, &f, &r);
		if ((m == -1) && (f == -1) && (r == -1)) break;
		if ((m <= 50) && (f <= 50) && (r <= 100))
		{
			if ((m == -1) || (f == -1))
			{
				printf("F\n");
			}else
			{	
				if (m + f >= 80) 
				{
					printf("A\n");
				}
				else if (m + f >= 65)
				{
					printf("B\n");
				}
				else if (m + f >= 50)
				{
					printf("C\n");
				}
				else if(m+f>=30)
				{
					if (r >= 50)
					{
						printf("C\n");
					}
					else
					{
						printf("D\n");
					}
				}
				else
				{
					printf("F\n");
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>


using namespace std;

#define debug false

int main(int argc, char *argv[]){

  int N, A, B;
  cin >> N >> A >> B;
  string Winner;
  if((A-B)%2 == 0) Winner = "Alice";
  else  Winner = "Borys";

  cout << Winner << endl;

  return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn main() {
    let mut _n_str = String::new();
    io::stdin().read_line(&mut _n_str).unwrap();

    let mut a_str = String::new();
    io::stdin().read_line(&mut a_str).unwrap();
    let a: Vec<i32> = a_str.split_whitespace()
      .map(|s| i32::from_str(s).unwrap())
      .collect();

    //println!("{:?}", a);

    let mut div = 2;
    let mut count = 0;

    loop {
      for num in a.iter() {
        if num % div != 0 {
          println!("{}", count);
          return;
        }
      }
      count += 1;
      div *= 2;
    }

}


Measured memory_bytes: 4352
#include <stdio.h>
long list[100001];
int main(){
    long n,k,x=0,a,b,i;


    scanf("%ld %ld",&n,&k);
    for(i=0;i<n;i++){
        scanf("%ld %ld",&a,&b);

        list[a]+=b;

    }
    for(i=1; i<=100000; i++){
        x+=list[i];
        if(x>=k){
            printf("%ld\n",i);
            break;
        }

    }
    return 0;

}

Measured memory_bytes: 896
import std.stdio, std.algorithm, std.conv, std.string, std.range;
import std.container;

void main(string[] args) {
    auto dlist = DList!int();

    int n = readln.chomp.to!int;
    foreach (i; 0..n) {
        string op = readln.chomp;

        if (op[0..7] == "insert ") {
            dlist.insertFront(op[7..$].to!int);
        } else if (op[0..7] == "delete ") {
            auto range = dlist[];
            for ( ; !range.empty; range.popFront()) {
                if (range.front == op[7..$].to!int) {
                    dlist.stableLinearRemove(take(range, 1));
                    break;
                }
            }
        } else if (op == "deleteFirst") {
            dlist.removeFront;
        } else if (op == "deleteLast") {
            dlist.removeBack;
        }
    }

    dlist[].map!(to!string).join(" ").writeln;
}

Measured memory_bytes: 56240
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  // ll INF = INT_MAX;
  // ll mod = 1000000007;
  // lld PI = 3.141592653;
 
// const int N = 2e5 + 5;


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
      // ifstream cin("input.txt");

      string s;
      cin>>s;
      int k;
      cin>>k;
      int f = s[0] - '0';

       int n = s.length();
       if (n<k){
        cout<<"0\n";
        return 0;
       }
      if (k==1){
     
        ll ans = 9*(n-1) + f;
        cout<<ans<<"\n";
      }else if (k==2){
        ll ans = (n-2)*(n-1)*81/2;
        // cout<<ans<<endl;
        ans+= (f-1)*9*(n-1);
        // cout<<ans<<endl;
        int ss = 1;
        while (ss<n && s[ss]== '0') ss++;
        // cout<<ss<<" "<<s[ss]<<endl;
        // if (n>=2){
        //   ans+=s[1]-'0';
        // }
        if (ss<n) ans+= s[ss]-'0';
        // cout<<ans<<endl;
        // cout<<s[ss]<<endl;
        // cout<<"-";

        // cout<<ss<<endl;
        for (int i = ss+1;i<n;i++){
         
          ans+= 9;
          // cout<<ans<<endl;
          // cout<<i<<" "<<endl;
        }
        cout<<ans<<"\n";
      }else{

        ll ans = (n-3)*(n-2)*(n-1)*9*9*9/6;
        // cout<<ans<<endl;
        ans+= (f-1)*(n-1)*(n-2)*81/2;

        // cout<<(f-1)*(n-1)*(n-2)*81/2<<endl;
        int ss = 1;
        while (ss<n && s[ss]=='0') ss++;
        if (ss<n) ans+= (n-1-ss)*(n-2-ss)*81/2;
        // cout<<ans<<endl;
        // ans+= (n-2)*(n-3)*81/2;
          // int sec = s[1] -'0';
        
         if (ss<n) ans+= (s[ss]-'0'-1)*9*(n-1-ss);
       
        
          // ans+= s[ss] -'0';
          int sss = ss+1;
          while(sss<n && s[sss]=='0') sss++;
         if (sss<n) ans+= s[sss]-'0';
         // cout<<ans<<endl;
          for (int i = sss+1;i<n;i++) ans+=9;
        
      cout<<ans<<"\n";
      // cout<<n<<endl;

      }

}

Measured memory_bytes: 3168
#include<stdio.h>
int main(void)
{
  int H,W;
  while(1)
  {
    scanf("%d %d",&H,&W);
    if(H==0&&W==0) break;

    for(int i=0;i<H;i++)
      {
        for(int k=0;k<W;k++)
          {
            if( (i==0 || i==H-1) || (k==0 || k==W-1))
              putchar('#');
            else
              putchar('.');
          }
        printf("\n");
      }
      printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1820
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

vector<int> erat(int n) {
    vector<int> primes(n);
    for (int i = 2; i < n; ++i) primes[i] = i;
    for (int i = 2; i*i < n; ++i)
        if (primes[i])
            for (int j = i*i; j < n; j+=i) primes[j] = 0;
    primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
    return primes;
}

signed main() {
    int n;
    vector<int> primes = erat(1300000);
    while(cin >> n, n) {
        int k = lower_bound(primes.begin(), primes.end(), n) - primes.begin();
        // printf("test: primes[%lld] = %lld\n", k, primes[k]);
        if(primes[k] == n) cout << 0 << endl;
        else cout << primes[k] - primes[k-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 12616
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
  using lint = long long int;
  using P = pair<lint, lint>;

  int n;
  lint t;
  cin >> n >> t;
  vector<lint> a(n);
  map<lint, int> pos;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  ///最大の利益を達成するペアを探す
  P max_pair = {a[0], 0};
  P temp = {a[0], 0};
  auto benefit = [&](P p)
  {
    lint b = p.first * (n / 2);
    lint s = p.second * (n / 2);
    return s - b;
  };
  for (int i = 1; i < n; ++i) {
    if(a[i] > temp.second)
    {
      temp.second = a[i];
    }else if(a[i] < temp.first)
    {
      lint temp_benefit = benefit(temp);
      lint max_benefit = benefit(max_pair);
      if(temp_benefit > max_benefit)
      {
        max_pair.first = temp.first;
        max_pair.second = temp.second;
      }
      temp.first = a[i];
      temp.second = 0;
    }
  }
  lint temp_benefit = benefit(temp);
  lint max_benefit = benefit(max_pair);
  if(temp_benefit > max_benefit)
  {
    max_pair.first = temp.first;
    max_pair.second = temp.second;
  }
  //cout  << "max pair = " << max_pair.first << " " << max_pair.second << endl;
  ///最大の利益を達成する互いに素なペアをカウントする
  vector<bool> counted(n, false);
  lint result = 0;
  for (int i = 0; i < n; ++i) {
    if(pos.count(a[i] + max_pair.second - max_pair.first) != 0)
    {
      if(pos[a[i] + max_pair.second - max_pair.first] > i /*&&
          !counted[pos[a[i] + max_pair.second - max_pair.first]]*/)
      {
        result++;
        //cout << a[i] << " " << a[i] + max_pair.second - max_pair.first << endl;
        //counted[i] = true;
        //counted[pos[a[i] + max_pair.second - max_pair.first]] = true;
      }
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    ll N, M, X;
    cin >> N >> M >> X;
    vector<vector<ll>> A(N, vector<ll> (M));
    vl c(N);
    for(int i=0; i<N; i++){
        cin >> c.at(i);
        for(int j=0; j<M; j++){
            cin >> A.at(i).at(j);
        }
    }
    ll ans = 12345678;
    for(int i=0; i < (1 << N); i++){
        ll sum = 0;
        vl level(M);
        for(int j=0; j<N; j++){
            if((i >> j) & 1){
                sum += c.at(j);
                for(int k=0; k<M; k++){
                    level.at(k) += A.at(j).at(k);
                }
            }
        }
        int flag = 0;
        for(int k=0; k<M; k++){
            if(level.at(k) < X){
                flag = 1;
            }
        }
        if(flag == 0){
            ans = min(ans, sum);
        }
    }
    if(ans == 12345678){
        ans = -1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3192
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>
//#include <boost/multiprecision/cpp_int.hpp>

//namespace mp = boost::multiprecision;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
//using Bint = mp::cpp_int;

int numofbits(int bits)
{
	int num;
	num = (bits >> 1) & 03333333333;
	num = bits - num - ((num >> 1) & 03333333333);  
	num = ((num + (num >> 3)) & 0707070707) % 077;
	return num;
}

int main()
{
	int N,M;
	vector<int>lp,p;
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int t=0;
		int k;
		cin>>k;
		for(int j=0;j<k;j++)
		{
			int q;
			cin>>q;
			q--;
			t|=(1<<q);
		}
		lp.push_back(t);
	}
	for(int i=0;i<M;i++)
	{
		int t;
		cin>>t;
		p.push_back(t);
	}
	int res=0;
	for(int i=0;i<(1<<N);i++)
	{
		bool ok=true;
		for(int l=0;l<M;l++)
		{
			int x=i&lp[l];
			int cnt=numofbits(x);
			ok&=(cnt%2==p[l]);
		}
		if(ok)res++;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main() {
	int a, b, c, d, e, k;

	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);
	printf(e - a <= k ? "Yay!\n" : ":(\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <queue>

typedef long long int ll;

using namespace std;

int N;

ll a[100002];

ll min(ll a, ll b) {
	return (a < b) ? a : b;
}
ll max(ll a, ll b) {
	return (a > b) ? a : b;
}

ll solve() {
	int i, j, ki;
	ll res = 0;

	ll allxor = 0;
	for (i = 0; i < N; i++) {
		allxor ^= a[i];
	}
	for (i = 0; i < N; i++) {
		a[i] &= ~allxor;
	}

	ll rank = 0;
	for (i = 59; i >= 0; i--) {
		for (j = rank; j < N; j++) {
			if (a[j] & (1LL << i)) break;
		}
		if (j == N) {
			continue;
		}

		if (j > rank) a[rank] ^= a[j];
		for (j = rank + 1; j < N; j++) {
			a[j] = min(a[j], a[j] ^ a[rank]);
		}

		rank++;
	}
	ll x = 0;
	for (i = 0; i < N; i++) {
		x = max(x, x ^ a[i]);
	}

	res = (x * 2) + allxor;

	return res;
}

int main(void) {

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

	cout << solve();

	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int x; cin >> x;
    if (x == 7 or x == 5 or x == 3) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
l = []
for i in range(5):
    inp = int(input())
    mod = inp % 10
    if mod != 0:
        mod = 10 - mod
    l.append([mod, inp])
l.sort()
ans = 0
for i in range(4):
    ans += l[i][0] + l[i][1]
ans += l[4][1]
print(ans)



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

int main() {
  int h, w, K, m = 1001001001;
  scanf("%d %d %d", &h, &w, &K);
  vector<string> s(h);
  for(int i = 0; i < h; i++) cin >> s[i];
  for(int i = 0; i < (1 << h - 1); i++) {
    bitset<9> b(i);
    int o = b.count(), prev = 0;
    vector<int> c(o + 1);
    for(int j = 0; j < w; j++) {
      int ind = 0;
      for(int k = 0; k < h; k++) {
        if(k) ind += b.test(k - 1);
        c[ind] += s[k][j] - '0';
      }
      int f = 0;
      for(auto x : c) f |= x > K;
      if(f) {
        fill(c.begin(), c.end(), 0);
        if(prev == j) {
          o = 1001001001;
          break;
        }
        prev = j--;
        if(j != w - 1) o++;
      }
    }
    m = min(m, o);
  }
  printf("%d\n", m);
}

Measured memory_bytes: 256
m=10**9+7;f=->a,b{b>0?a**b[0]*f[a*a%m,b/2]%m:1}
s=t=i=0;
b=(1..gets.to_i).map{|j|t+=f[j,m-2]};r=1;
gets.split.map{|a|s+=a.to_i*(b[i]+b[-i+=1]-1)%m;r=r*i%m}
p s*r%m

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

int findIndex(vector<long long> v, int value)
{
    auto iter = find(v.begin(), v.end(), value);
    size_t index = distance(v.begin(), iter);
    return index;
}

void printImos(vector<vector<int>> imos)
{
    rep(x, imos.size())
    {
        rep(y, imos[0].size())
        {
            cout << imos[x][y];
        }
        cout << endl;
    }
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<long long> x, y;
    vector<pair<int, int>> pos(N);

    rep(i, N)
    {
        cin >> pos[i].first >> pos[i].second;
        x.push_back(pos[i].first);
        y.push_back(pos[i].second);
    }
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    sort(y.begin(), y.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    vector<vector<int>> imos(x.size() + 1, vector<int>(y.size() + 1, 0));
    int H = x.size() + 1;
    int W = y.size() + 1;
    rep(i, N)
    {
        int ix = findIndex(x, pos[i].first);
        int iy = findIndex(y, pos[i].second);
        imos[ix + 1][iy + 1]++;
    }

    rep(i, H) rep(j, W - 1)
    {
        imos[i][j + 1] += imos[i][j];
    }
    rep(j, W) rep(i, H - 1)
    {
        imos[i + 1][j] += imos[i][j];
    }

    vector<pair<int, int>> point;
    rep(i, x.size()) rep(j, y.size())
    {
        point.push_back(make_pair(i, j));
    }
    long long ans = INT64_MAX;
    for (int ru = 0; ru < point.size(); ru++)
    {
        for (int ld = ru + 1; ld < point.size(); ld++)
        {
            int i_ru_x = point[ru].first;
            int i_ru_y = point[ru].second;
            int i_ld_x = point[ld].first;
            int i_ld_y = point[ld].second;
            if (i_ru_x == i_ld_x || i_ru_y == i_ld_y)
                continue;

            if (i_ru_x < i_ld_x)
                swap(i_ru_x, i_ld_x);
            if (i_ru_y < i_ld_y)
                swap(i_ru_y, i_ld_y);

            int point_num = imos[i_ru_x + 1][i_ru_y + 1] - imos[i_ru_x + 1][i_ld_y] - imos[i_ld_x][i_ru_y + 1] + imos[i_ld_x][i_ld_y];
            if (point_num >= K)
            {
                long long area = (x[i_ru_x] - x[i_ld_x]) * (y[i_ru_y] - y[i_ld_y]);
                ans = min(ans, area);
            }
        }
    }

    if (ans == INT64_MAX)
        ans = -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(a: i64, b: i64);
    puts!("{}\n", a * b);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main() {
  int64_t N, K;
  cin >> N >> K;
  bool all_minus = 1;
  bool all_plus = 1;
  int64_t zero_index; 
  int64_t flag = 0; // ゼロがあるかどうか 

  vector<int64_t> X(N);
  int64_t x, y;
  for (int64_t i = 0; i < N ; i++) {
    	cin >> x; 
    	X.at(i)=x;     
    	if(x > 0) all_minus =0;
    	if(x < 0) all_plus =0; 
        if(x==0) flag =1;
  }
  
  
  for (int64_t i = 0; i < N-1 ; i++) {   
    	if( X.at(i)<0 & X.at(i+1)>=0 ) zero_index =i; // 最後の負のインデックス
  }  
  
if(all_plus){
    cout << X.at( K - 1 ) << endl; 
}else if(all_minus){
    cout << - X.at( N - K   ) << endl; 
}else{

  int64_t a, b;
  int64_t answer= 400000000+1; 
  for (int64_t i = 0; i < N - K + 1 ; i++){ 
    a=X.at(i);
    b= X.at(i+K-1); 
    if (b>=0 & a<=0 ){
       answer = min( b-2*a, min( answer, 2*b-a ) );
    }
  }
  
  if( zero_index <= N - K -1 ){
    answer = min( answer, X.at( zero_index + K ) ); 
  }
  if( zero_index >= K-1 ){
    answer = min (answer, -X.at( zero_index - K + 1 ) ); 
    
  }
  
          cout << answer << endl;
  
}
//でかいelse文終わり  
}

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

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 3e3+5;
const int mo = 1e9+7;

int n,q;
int a[N];
LL f[N][N],lst[N][N];
int pos[N];
LL mi[N];
LL g[N][N];

LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}

void add(int i,int j,int x,int y){
	if (i==j||!g[i][j])return;
	LL v=g[i][j];
	f[i][j]=add(f[i][j],v);
	if (i==x||i==y)i^=x^y;
	if (j==x||j==y)j^=x^y;
	f[i][j]=add(f[i][j],v);
}

int main(){
	n=get();q=get();
	fo(i,1,n)a[i]=get();
	fo(i,1,n)
		fo(j,1,n)
		if (a[i]>a[j])f[i][j]=1;
	mi[0]=1;
	fo(i,1,q)mi[i]=mi[i-1]*2%mo;
	fo(t,1,q){
		int x=get(),y=get();
		fo(i,1,n){
			g[i][x]=f[i][x]*mi[t-1-lst[i][x]]%mo;
			g[i][y]=f[i][y]*mi[t-1-lst[i][y]]%mo;
			lst[i][x]=lst[i][y]=t;
			f[i][x]=f[i][y]=0;
		}
		fo(j,1,n)
		if (j!=x&&j!=y){
			g[x][j]=f[x][j]*mi[t-1-lst[x][j]]%mo;
			g[y][j]=f[y][j]*mi[t-1-lst[y][j]]%mo;
			lst[x][j]=lst[y][j]=t;
			f[x][j]=f[y][j]=0;
		}
		fo(i,1,n){
			add(i,x,x,y);
			add(i,y,x,y);
		}
		fo(j,1,n)
		if (j!=x&&j!=y){
			add(x,j,x,y);
			add(y,j,x,y);
		}
	}
	LL ans=0;
	fo(i,1,n)
		fo(j,i+1,n)ans=(ans+f[i][j]*mi[q-lst[i][j]])%mo;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 211968
n,m= list(map(int, input().split()))

miss=0

li=[0 for j in range(n)]
li1=[0 for j in range(n)]

for i in range(m):
    p,s= input().split()
    p=int(p)
    if s=="AC":
        if li[p-1]==0:
            li[p-1]=1
            miss+=li1[p-1]
    else:
        if li[p-1]==0:
            li1[p-1]+=1
            

    
print(sum(li),miss)



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


int main()
{
	constexpr size_t max_arity { 4000 };
	int n;
	cin >> n;
	char s[max_arity];
	int cnt_r = 0;
	int cnt_g = 0;
	int cnt_b = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
		if (s[i] == 'R')
		{
			cnt_r++;
		}
		else if (s[i] == 'G')
		{
			cnt_g++;
		}
		else if (s[i] == 'B')
		{
			cnt_b++;
		}
	}
	long long cnt = (long long)(cnt_r * cnt_g) * cnt_b;
	if (n >= 3)
	{
		for (int i = 0; i < n - 2; i++)
		{
			for (int d = 1;; d++)
			{
				int j = i + d;
				int k = i + 2 * d;
				if (!(k < n))
				{
					break;
				}
				if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k])
				{
					cnt--;
				}
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3636
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
p = LIST()

ans = 0
i = 0
while i < N:
	if p[i] == i+1:
		ans += 1
		i += 1
	i += 1
print(ans)


Measured memory_bytes: 15960
#include<bits/stdc++.h>
# define ll long long
# define mo 1000000009
using namespace std;
int main()
{
	int n;;
	cin>>n;
	double a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	double  dp[n+1][n+1];
	dp[1][0]=1-a[1];
	for(int i=2;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0]*(1.0-a[i]);
	}
	dp[1][1]=a[1];
	for(int i=2;i<=n;i++)
	{
		dp[i][i]=dp[i-1][i-1]*a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			dp[i][j]=dp[i-1][j]*(1.0-a[i])+dp[i-1][j-1]*a[i];
		}
	}
	double sum=0;
	for(int i=n/2+1;i<=n;i++)
	{
		sum+=(dp[n][i]);
	}
	cout<<fixed<<setprecision(10)<<sum;
}


Measured memory_bytes: 70528
import sys
input = sys.stdin.readline
from collections import Counter
n=int(input())
S=[input() for _ in range(n)]
Sc=Counter(S)
Scm=Sc.most_common()
a,cnt=Scm[0]
ans=[]
for a,b in Scm:
    if b==cnt:
        ans.append(a)
    else:
        continue
ans.sort()
print(*ans, sep='\n')

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

int a[200005];

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

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

    int xorsum = 0;
    for(int i = 0; i < N; i ++){
        xorsum ^= a[i];
    }

    for(int i = 0; i < N; i ++){
        printf("%d ", xorsum^a[i]);
    }

    return 0;
}


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

typedef long long ll;

ll N, P;
string S;

int main()
{
    cin >> N >> P >> S;
    ll res = 0;
    if(P == 2 || P == 5)
    {
        for(ll i = N - 1; 0 <= i; i--)
        {
            if((S[i] - '0')%P == 0) res += i + 1;
        }
        cout << res << endl;
        return 0;
    }
    map<ll, ll> V;
    for(int i = 0; i < P; i++) V.insert(make_pair(i, 0));
    ll mp10 = 1;
    ll Ti;
    for(ll i = N; i >= 0; i--)
    {
        if(i == N)
        {
            Ti = 0;
            V[Ti]++;
        }
        else
        {
            mp10 *= N - 1 - i > 0 ? 10 : 1;
            mp10 %= P;
            Ti = mp10 * (ll)(S[i] - '0') + Ti;
            Ti %= P;
            V[Ti]++;
        }
    }
    for(int i = 0; i < P; i++)
    {
        res += V[i] * (V[i] - 1) / 2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1028
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {a:usize,b:usize,c:usize,d:usize}
    println! {"{}",min(a,b)+min(c,d)}
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 33

ll POW[SIZE],table[SIZE];


int main(){

	POW[0] = 1;
	table[0] = 0;
	table[1] = 0;

	ll sum = 0;

	for(int i = 1; i < SIZE; i++){
		if(i > 1){

			table[i] = sum;
		}
		POW[i] = POW[i-1]*3;
		sum += POW[i];
	}

	ll T;
	scanf("%lld",&T);

	if(T <= 3){

		printf("%lld\n",T);
		return 0;
	}

	T -= 1;

	ll ans = 1;
	ll rank;
	//上り
	for(int i = 2; i < SIZE; i++){
		if(POW[i]+2*table[i] > T){
			T -= (POW[i-1]+table[i-1]);
			ans += i-1;
			rank = i-1;
			break;
		}
	}

	//下り
	ll mult;

	while(T > 0){

		mult = (T-table[rank])/POW[rank];
		ans += mult;
		T -= POW[rank]*mult;
		if(T == 0)break;
		rank--;
	}

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

	return 0;
}



Measured memory_bytes: 3224
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    items = set()
    for _ in range(n):
        items.add(input()[:-1])
    print(len(items))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 83224
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;
	for (int i = N; i <= 2 * N; i++) {
		int k = i - N;
		bool check = true;
		for (int j = 0; j < 2 * N - i; j++) {
			if (S.at(k) != T.at(j)) check = false;
			k++;
		}
		if (check) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

map<int64_t, int> PrimeFactorization(int64_t n) {
	assert(n > 0);
	map<int64_t, int> mp;
	if(n == 1) {
		mp[1] = 1;
		return mp;
	}
	mp[1] = 1;
	int64_t i = 2;
	while(n > 1) {
		if(n < i * i) {
			mp[n]++;
			return mp;
		}
		if(n % i == 0) {
			n /= i;
			mp[i]++;
		} else {
			i++;
		}
	}
	return mp;
}


int main() {
	int64_t a, b; cin >> a >> b;
	int64_t g = __gcd(a, b);
	auto mp = PrimeFactorization(g);
	int64_t cnt = 0;
	for(auto e : mp) {
		// cout << e.first<<endl;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		for(int i = l; i  <= r; i++) {
			if(i%d==0) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35708
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 100000
using namespace std;
typedef long long ll;
int map[255][255];
int d[255];
bool vis[255];
void bfs(int cur,int n)
{
	queue<int> q;
	int u;
	q.push(cur);
	while(!q.empty())
	{
		u=q.front();q.pop();
		for(int i=1;i<=n;i++)
		{
			if(!map[u][i]) continue;
			if(d[i]>=0) continue;//不再重复计算或者入队 
			d[i]=d[u]+1;
			q.push(i);
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout<<i<<" "<<d[i]<<endl;
	}
}
int main()
{	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			map[i][j]=0;
		}
	for(int i=0;i<n;i++)
	{
		int cur,k,u;
		cin>>cur>>k;
		while(k--)
		{
			cin>>u;
			map[cur][u]=1;
		}
	}
	for(int i=2;i<=n;i++)
	{
		d[i]=-1;
	}
	d[1]=0;
	bfs(1,n);
	return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int N = 1000+9;
const int MOD = 1000000007;

int n,a,b,c,d,f[N][N],C[N][N],POW[N],REV[N];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

inline int Pow(int w, int t) {
	int ret = 1;
	while (t) {
		if (t & 1) ret = (LL)ret * w % MOD;
		w = (LL)w * w % MOD; t >>= 1;
	}
	return ret;
}

int main() {
	n = read(); 
	a = read(); b = read();
	c = read(); d = read();
	for (int i=1;i<N;i++) C[i][1] = i, C[i][0] = 1;
	for (register int i=2;i<N;i++) {
		for (register int j=1;j<N;j++) {
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
		}
	}
	POW[0] = 1;
	for (register int i=1;i<N;i++) POW[i] = (LL)POW[i-1] * i % MOD;
	REV[N-1] = Pow(POW[N-1], MOD-2);
	for (register int i=N-2;~i;i--) REV[i] = (LL)REV[i+1] * (i+1) % MOD;
	f[a-1][n] = 1;
	for (register int i=a;i<=b;i++) {
		for (register int j=0;j<=n;j++) {
			if (f[i-1][j]) {
				(f[i][j] += f[i-1][j]) %= MOD;
				if (i*(c-1) > j) continue;
				int w = 1;
				for (register int k=1;k<c;k++) 
					w = (LL)w * C[j-(k-1)*i][i] % MOD;
				for (register int k=c;k<=d;k++) {
					if (i*k <= j) {
						w = (LL)w * C[j-(k-1)*i][i] % MOD;
						(f[i][j-i*k] += ((LL)f[i-1][j] * w % MOD) * REV[k] % MOD) %= MOD;
					} else break;
				}
			}
		}
	}
	printf("%d\n",f[b][0]);
	return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  ll cnt = 0;
  rep(i, N){
    ll a, b; cin >> a >> b;
    if(a == b) cnt++;
    else cnt = 0;
    if(cnt >= 3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3132
#include <stdio.h>
int main(void) {
	int N;
	scanf("%d", &N);
	N = N % 10;
	if (N == 3) {
		printf("bon");
	}
	else if (N == 0 || N == 1 || N == 6 || N == 8) {
		printf("pon");
	}
	else {
		printf("hon");
	}
	return 0;
}

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

int main(){
    int n; cin >> n;
    for(int i=0; i<=n; i++){
        int rest =  n-i*100;
        if(0<= rest && rest <= 5*i){
            cout << "1" << endl;
            return 0;
        }
        if(rest < 0) break;
    }
    cout << "0" << endl;
    return 0;
}

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

int main(){
	
	int i, j, num;
	int* pT;
	
	while(cin>>num){
		int count=0;
		pT = new int[num];
		
		for(i=0; i<num; i++){
			pT[i] = 0;
		}
		
		pT[0] = 1;
		
		for(i=2; i<=(num/2); i++){
			for(j=2; i*j<=num; j++){
				if(pT[i*j-1]==0){
					pT[i*j-1] = 1;
				}
			}
		}
		
		for(i=0; i<num; i++){
			if(pT[i]==0){
				++count;
			}
		}
		
		delete[] pT;
		
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5360
object Main extends App {
  import scala.io.StdIn._


  val prime = primes
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val a = readLine.trim.split(' ').map(_.toLong)
  val b = readLine.trim.split(' ').map(_.toLong)
  val g = a.reduce(gcd)
  if (b.forall(g % _ == 0)) {
    val l = primeFactors(b.map(g / _).reduce(gcd), prime)
    println(l.map(_ + 1).product)
  }else {
    println(0)
  }
  def primes: Array[Int] = {
    val upper = 10000000
    val memo = Array.tabulate(upper / 2 + 1){_ ⇒ true}
    memo(0) = false
    for (i ← 3 to math.sqrt(upper).toInt by 2){//(i * 2 + 1) * (i * 2 + 1) < upperである間は行う必要がある。少し超えてる
      if (memo(i / 2)){//i*2+1が素数
        for (j ← 3 to upper / i by 2) {
          memo((j * i) / 2) = false
        }
      }
    }
    (2 +: memo.indices.filter(memo).map(_ * 2 + 1)).toArray
  }
  def primeFactors(target: Long, prime: Array[Int]): List[Int] = {
    var i = 0
    var rest = target
    var result = Nil: List[Int]
    while (rest > 1 && prime.indices.contains(i)){
      if (rest % prime(i) == 0) result ::= 0
      while(rest % prime(i) == 0){
        result = result.head + 1 :: result.tail
        rest /= prime(i)
      }
      i += 1
    }
    if (rest != 1) 1::result
    else result
  }
  def gcd(a: Long, b: Long): Long = {
    if (b == 0) a else gcd(b, a % b)
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


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

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int l[n+1],r[n+1];
    l[0]=r[n]=0;
    for(int i=0;i<n;i++){
        l[i+1]=gcd(l[i],a[i]);
    }
    for(int i=n-1;i>=0;i--){
        r[i]=gcd(r[i+1],a[i]);
    }

    int ans=0;
    for(int i=0;i<n;i++){
        ans=max(ans,gcd(l[i],r[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#!/usr/bin/perl
#= CPAN mocules =====================================================#
use strict;				# strictモード
use warnings;			# 警告有効

#= Global values ====================================================#
#= Local routines ===================================================#
sub main(){
	my $N = <>;
	chomp $N;
	my $in = <>;
	chomp $in;
	my @border = split(/ /, $in);
	$in = <>;
	chomp $in;
	my @point = split(/ /, $in);
	my @count;

	$count[0] = [grep {$_ <= $border[0]} @point];
	$count[1] = [grep {($border[0] < $_) && ($_ <= $border[1])} @point];
	$count[2] = [grep {$border[1] < $_} @point];

	my $contest = 0xFFFFFFFF;
	foreach(@count){
		if ($contest > @{$_}){
			$contest = @{$_};
		}
	}
	print $contest, "\n";

	return 0;
}

#----- 実行 -----#
exit( main() );




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

int main() {
  int N;
  cin >> N;
  vector<long long> vec(N + 1);
  vec.at(0) = 2;
  vec.at(1) = 1;
  for (int i = 2; i < N + 1; i++) {
    vec.at(i) = vec.at(i - 1) + vec.at(i - 2);
  }
  cout << vec.at(N) << endl;
}
  

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

ll N, Q;
//値
vector<ll> value((ll)2e5,0);
//使用したかどうか
vector<bool> used((ll)2e5,false);
//連結リスト
vector<vector<ll>> G((ll)2e5);

void solve(ll n)
{
    rep(i,G.at(n).size()){
        ll nextNode =G.at(n).at(i); 
        if(used.at(nextNode))continue;
        used.at(n) = true;
        value.at(nextNode) += value.at(n);
        solve(nextNode);
        used.at(n) = false;
    }
    return;
}

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

    rep(i, N - 1)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        G.at(a).push_back(b);
        G.at(b).push_back(a);
    }

    rep(i, Q)
    {
        ll p, x;
        cin >> p >> x;
        p--;
        value.at(p) += x;
    }
    solve(0);
    rep(i,N){
        if(i>0)cout << " ";
        cout << value.at(i);
    }
    cout << endl;
}



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

using namespace std;

int main()
{
	string x;
	cin >> x;
	int a, b;
	int m=x.size();
	int n=0, s=0, w=0, e=0;
	for(int i=0; i<m; i++)
	{
		if(x[i]=='N')
		{
			n++;
		}
		if(x[i]=='S')
		{
			s++;
		}
		if(x[i]=='W')
		{
			w++;
		}
		if(x[i]=='E')
		{
			e++;
		}
	}
	if(n==0)
	{
		if(s==0)
		{
			a=0;
		}
		else
		{
			a=1;
		}
	}
	else
	{
		if(s==0)
		{
			a=1;
		}
		else
		{
			a=0;
		}
	}
	if(w==0)
	{
		if(e==0)
		{
			b=0;
		}
		else
		{
			b=1;
		}
	}
	else
	{
		if(e==0)
		{
			b=1;
		}
		else
		{
			b=0;
		}
	}
	if(a+b==0)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll XOR(ll a){
    if(a % 4 == 1)return 1;
    else if(a % 4 == 3)return 0;
    else if(a == 0)return 0;
    else return (XOR(a-1)^a);
}
signed main()
{   
    gearup;
    int n;cin>>n;
    vl a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    cout << accumulate(all(a),0) - a[n-1] + a[n-1]/2<< endl;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (wrds toInt) >>= print

solve :: [Int] -> Int
solve = product

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 3620
n, m = [int(x) for x in input().split()]
lr = [[int(x) for x in input().split()] for _ in range(m)]

lr.sort(key = lambda x : x[1])
ans = 0
rm = 0 # 最初のループで必ずif文がFalseになる値
for i in range(m):
    if lr[i][0] <= rm and lr[i][1] >= rm + 1: # 取り除いた橋でカバー可能
        continue
    rm = lr[i][1] - 1  # 取り除く橋の番号
    ans += 1

print(ans)

Measured memory_bytes: 22816