akhauriyash/Code-Regression huggingface dataset:
using System;

class MainClass : MyUtil
{
	public static void Main (string[] args)
	{
		while (true) {
			int n = int.Parse (Console.ReadLine ());
			if (n == 0)
				break;

			bool[] flag = new bool[n];
			for (int i = 0; i < n; i++)
				flag [i] = true;
			bool[,] data = new bool[n, n];

			int[] ins;
			for (int i = 0; i < n; i++) {
				ins = ReadIntMap ();
				for (int j = 1; j <= ins [0]; j++) {
					int k = ins [j] - 1;
					data [i, k] = true;
				}
			}

			ins = ReadIntMap ();
			for (int i = 1; i <= ins [0]; i++) {
				int l = ins [i] - 1;
				for (int m = 0; m < n; m++) {
					flag [m] = flag [m] && data [m, l];
				}
			}

			int cnt = 0, me = 0;
			for (int i = 0; i < n; i++) {
				if (flag [i]) {
					me = i + 1;
					cnt++;
				}
			}
			Console.WriteLine (cnt == 1 ? me : -1);
		}
	}
}

class MyUtil : MyIO
{
}

class MyIO
{
	public static String ReadLine ()
	{
		return Console.ReadLine ();
	}

	public static int[] ReadIntMap ()
	{
		string[] strs = Console.ReadLine ().Split (' ');
		int[] ret = new int[strs.Length];
		for (int i = 0; i < strs.Length; i++) {

			ret [i] = int.Parse (strs [i]);
		}
		return ret;
	}
}

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

void output_edge(int W) {
  rep(i, W + 2) cout << '#';
  cout << endl;
}

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> lines(H);
  rep(i, H) {
    string line;
    cin >> line;
    lines.at(i) = line;
  }

  output_edge(W);
  rep(i, H) cout << '#' << lines.at(i) << '#' << endl;
  output_edge(W);
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
  int K, S;
  cin >> K >> S;

  int ans = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (z <= K && z >= 0) ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

/* O(log n) */
struct UnionFind {
  vector<int> parent;  // parent[root] is the negative of the size.
  UnionFind(int n) : parent(n, -1){};
  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v)
      return false;
    if (parent[u] > parent[v])
      swap(u, v);
    parent[u] += parent[v];
    parent[v] = u;
    return true;
  }
  bool issame(int u, int v) {
    return root(u) == root(v);
  }
  int root(int u) {
    return parent[u] < 0 ? u : parent[u] = root(parent[u]);
  }
  int size(int u) {
    return -parent[root(u)];
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
    p[i]--;
  }

  UnionFind u(N);
  int x, y;
  rep(i, M) {
    cin >> x >> y;
    x--;
    y--;
    u.unite(x, y);
  }

  ll ans = 0;
  rep(i, N) {
    if (u.issame(p[i], p[p[i]]))
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
def get_max_length(grid, n)
  max_length = 0

  for y in 0...n
    length = 0
    for x in 0...n
      if grid[y][x] == 1
        length += 1
        max_length = length if length > max_length
      else
        length = 0
      end
    end
  end

  for x in 0...n
    length = 0
    for y in 0...n
      if grid[y][x] == 1
        length += 1
        max_length = length if length > max_length
      else
        length = 0
      end
    end
  end

  for i in 0..(n * 2 - 2)
    length = 0
    x = 0
    y = i - x
    while x < n && y >= 0
      if y < n && grid[y][x] == 1
        length += 1
        max_length = length if length > max_length
      else
        length = 0
      end
      x += 1
      y -= 1
    end
  end

#  for i in 0..(n * 2 - 2)
#    length = 0
#    x = 0
#    y = n - 1 - i - x
#    while x < n && y >= 0
#      if y < n && grid[y][x] == 1
#        length += 1
#        max_length = length if length > max_length
#      else
#        length = 0
#      end
#      y += 1
#      x += 1
#    end
#  end
  for i in -(n - 1)..(n - 1)
    length = 0
    x = 0
    y = i + x
    while x < n && y < n
      if y >= 0 && grid[y][x] == 1
        length += 1
        max_length = length if length > max_length
      else
        length = 0
      end
      x += 1
      y += 1
    end
  end

  max_length
end

while line = gets
  n = line.chomp.to_i
  break if n == 0

  grid = []
  n.times do
    grid << gets.chomp.split('').map(&:to_i)
  end

  puts get_max_length(grid, n)
end

Measured memory_bytes: 10508
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define print(x) printf("%d\n",x)

using namespace std;

pair<int,pair<int,int> > cat[1000];
int catx[1000];
int caty[1000];
int catc[1000];
int esa[1000];
int n,m;
int acc;

bool can(int lim){
  vector<int> e(esa, esa+m);
  while(true){
    if(e.size() <= 1){
      if(lim >= acc)
        break;
      else
        return false;
    }

    int mm = e.size();
    vector<int> counts(mm);
    int ep = 0;
    int next = e[1];
    int maxc = -1;
    int maxp;

    REP(i,n){
      if(ep == mm - 1){
        counts[ep] += catc[i];
      }else{
        if(catx[i] <= e[ep+1]){
#define ABS(x) ((x) < 0 ? -(x) : (x))
          int da = ABS(e[ep  ] - catx[i]);
          int db = ABS(e[ep+1] - catx[i]);
          if(da <= db){
            counts[ep] += catc[i];
          }else{
            counts[ep+1] += catc[i];
          }
        }else{
          while(ep != mm-1 && catx[i] > e[ep+1]) ep++;
          i--;
        }
      }
      if(maxc < counts[ep]){
        maxc = counts[ep];
        maxp = ep;
      }
      if(ep != mm-1 && maxc < counts[ep+1]){
        maxc = counts[ep+1];
        maxp = ep+1;
      }
    }

    //printf("counts: ");
    //REP(i,mm) printf("(%d):%d ",e[i],counts[i]); puts("");
    if(maxc <= lim) break;
    if(maxp == 0 || maxp == mm - 1) return false;
    //if(counts[maxp - 1] > lim && counts[maxp + 1] > lim) return false;
    e.erase(e.begin() + maxp);
  }
  return true;
}

int main(){
  while(scanf("%d%d",&n,&m), n+m){
    int tmp;
    REP(i,n) scanf("%d%d%d",&cat[i].f,&cat[i].s.f,&cat[i].s.s);
    REP(i,m) scanf("%d",esa+i);
    if(n == 0){
      puts("0");
      continue;
    }

    sort(cat, cat+n);
    sort(esa, esa+m);
    REP(i,n) catx[i] = cat[i].f;
    REP(i,n) caty[i] = cat[i].s.f * cat[i].s.f;
    REP(i,n) catc[i] = cat[i].s.s;

    int high = acc = accumulate(catc, catc+n, 0);
    int low  = *max_element(catc, catc+n);

    while(high >= low){
      int mid = (high + low) / 2;
      //printf("%d %d %d\n",low,mid,high);
      if(can(mid)){
        high = mid - 1;
      }else{
        low = mid + 1;
      }
    }
    low = max(*max_element(catc, catc+n), low - 2);
    while(!can(low)) low++;
    print(low);
  }
  return 0;
}

Measured memory_bytes: 956
#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 ll INF = 1000000000000000000;

int main()
{
	ll N, M;
	cin >> N >> M;
	if (N > M) swap(N, M);
	if (N == 1 && M == 1) cout << 1 << endl;
	else if (N == 1 && M != 1) cout << M - 2 << endl;
	else cout << (N - 2) * (M - 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,int> P;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> a(n),d, F;
    vector<P> I(m);
    // vector<int> b(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    rep(i,m){
        ll c;int b;
        cin >> b >> c;
        I[i] = (P){c,b};
    }
    sort(I.begin(),I.end(),greater<P>());
    int k = 0;
    rep(i,n){
        if(k>=m)break;
        int x, c;
        x = I[k].first; c = I[k].second;
        if(c>0){
            // printf("x:%d, c:%d\n",x,c);
            F.push_back(x);
            --I[k].second;
            if(I[k].second<=0)++k;
        }
    }
    sort(F.begin(),F.end(),greater<ll>());
    // rep(i,F.size()){
    //     cout << F[i]<<" ";
    // }
    // cout << endl;

    rep(i,min((int)F.size(),n)){
        if(a[i]<F[i])swap(a[i],F[i]);
    }
    ll ans = 0;
    rep(i,n){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3704
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;
typedef long long ll;
const int MODULO = 1000000000;
const int INF = 2000000000; //1e9 * 2
const double EPS = 1e-7;
const double PI = acos(-1.0);

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

//start

short table[5000][5000];

int main(){

	int n,m; cin>>n>>m;
	FOR(i,m){
		short a,b,x; cin>>a>>b>>x;
		a--;b--;
		table[a][b] = x+1;
	}
	
	for(int i = 1; i < n; i++) FOR(j,i+1){
		if(j==0) table[i][j] = max<short>(table[i][j],table[i-1][j]-1);
		else if(j == i) table[i][j] = max<short>(table[i][j],table[i-1][j-1]-1);
		else table[i][j] = max<short>(table[i][j],max(table[i-1][j],table[i-1][j-1])-1);
	}
	int ans = 0;
	FOR(i,n) FOR(j,i+1) ans += table[i][j] > 0;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 48828
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}


int main(){
    ll n,k;
    cin >> n >> k;
    ll w[n],v[n];
    for (ll i=0;i<n;i++)cin >> w[i] >> v[i];
    ll dp[n+1][k+1];
    for (ll i=0;i<=n;i++){
        fill(dp[i],dp[i]+k+1,0);
    }
    for (ll i=1;i<=n;i++){
        for (ll sum_w=0;sum_w<=k;sum_w++){
            if (w[i-1]<=sum_w){
                chmax(dp[i][sum_w],dp[i-1][sum_w-w[i-1]]+v[i-1]);
            }
            chmax(dp[i][sum_w],dp[i-1][sum_w]);
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int x,a,b;
   cin >> x >> a >> b;
   int d=b-a;
   if(d<=0)cout << "delicious" << endl;
   else if(d<=x)cout <<  "safe" << endl;
   else if(d>x)cout << "dangerous" <<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Lagrange's Four-Square Theorem
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		//2^15 = 32768
		//sqrt(32768) = 181.01...
		int[] vs = new int[182];
		int[][] dp = new int[32769][4];

		for (int i = 1; i < 182; i++) {
			vs[i] = i * i;
			dp[vs[i]][0] = 1;
		}

		for (int i = 181; i >= 1; i--) {
			for (int j = 1; j < 4; j++) {
				for (int k = vs[i]; k < 32769; k++) {
					if (dp[k][j - 1] > 0 && k + vs[i] < 32769) {
						dp[k + vs[i]][j] += dp[k][j - 1];
					}
				}
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			int sum = 0;
			for (int i = 0; i < 4; i++) {
				sum += dp[n][i];
			}
			System.out.println(sum);

		} //end while
	}//end main
}

Measured memory_bytes: 26832
#include<bits/stdc++.h>
using namespace std;
int dp[100050];
int N,W,w[105],v[105];
int main(){
    cin>>N>>W;

    for(int i=1;i<=N;i++)
        cin>>w[i]>>v[i];

    dp[0]=0;
    for(int i=1;i<=100000;i++)
            dp[i]=1000000005;
    for(int i=1;i<=N;i++)
    for(int j=100000;j>=v[i];j--)
    {
        if(j-v[i]>=0   )
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
    }
    for(int j=100000;j>=0;j--){
        if(dp[j]<=W){
            cout<<j;
            return 0;
        }
    }
}


Measured memory_bytes: 640
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int Mod=1e9+7;
const int N=2e5+5;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,m;
int L[N],R[N],s[N],f[N],sum[N];
struct Node{int x,y;}a[N],P[N];
int mod(int x){return x>=Mod?x-Mod:x;}
bool cmp1(Node A,Node B){return A.y!=B.y?A.y<B.y:A.x<B.x;}
bool cmp2(Node A,Node B){return A.x!=B.x?A.x<B.x:A.y<B.y;}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){a[i].x=read();a[i].y=read();}
	sort(a+1,a+n+1,cmp1);
	s[0]=0;
	for(int i=1;i<=n;i++){
		int l=1,r=i;s[i]=max(s[i-1],a[i].x);
		while(l<=r){int mid=(l+r)>>1;if(s[mid]>=a[i].x){P[i].x=mid;r=mid-1;}else l=mid+1;}
	}
	s[n+1]=inf;
	for(int i=n;i>=1;i--){
		int l=i,r=n;s[i]=min(s[i+1],a[i].x);
		while(l<=r){int mid=(l+r)>>1;if(s[mid]<=a[i].x){P[i].y=mid;l=mid+1;}else r=mid-1;}
	}
	sort(P+1,P+n+1,cmp2);
	int j=0;f[0]=sum[0]=1;
	for(int i=1;i<=n;i++){
		while(P[j].y<P[i].x-1)j++;
		f[i]=mod(sum[i-1]-sum[j-1]+Mod);
		sum[i]=mod(sum[i-1]+f[i]);
	}
	while(P[j].y<n)j++;
	printf("%d\n",mod(sum[n]-sum[j-1]+Mod));
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> a(200005);
    vector<int> b(200005);
    vector<int> c(200005);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=i-a[i];
        c[i]=i+a[i];
    }

    map<int,int> mp;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(mp.count(b[i])){
            ans+=mp[b[i]];
        }
        mp[c[i]]++;               
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 14808
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  ll N, M;
  cin >> N >> M;
  if (M < 2 * N) {
    cout << M / 2 << endl;
  } else {
    cout << N + (M - 2 * N) / 4 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
//二項係数 nCr
const int MAX = 700000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  ll h,w,a,b;
  cin>>h>>w>>a>>b;
  COMinit();
  vll t(w-b);
  rep(i,w-b){
    t[i]=COM(i+b+h-a-1,i+b);
  }
  ll ans=0;
  rep(i,w-b){
    ans+=t[i]*COM(a-1+w-b-1-i,a-1);
    ans%=MOD;
  }
  COUT(ans);
}

Measured memory_bytes: 20356
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<cassert>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()


using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(int argc, char const* argv[])
{
    int N;
    int ans = 0;

    cin >> N;

    for (int i = 0; i < N; i++) {
        int l, r;
        cin >> l >> r;
        ans += r-l+1;
    }

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



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        int sum = 0;
        for(int i = 0; i < n; i++)
        {
            int x, y, h, w; cin >> x >> y >> h >> w;
            int large = x + y + h;
            if(large <= 60 and w <= 2) sum += 600;
            else if(large <= 80 and w <= 5) sum += 800;
            else if(large <= 100 and w <= 10) sum += 1000;
            else if(large <= 120 and w <= 15) sum += 1200;
            else if(large <= 140 and w <= 20) sum += 1400;
            else if(large <= 160 and w <= 25) sum += 1600;
        }
        cout << sum << endl;
    }
    return 0;
}




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

#define M 1000000007
vector<int> dist;
vector<vector<int>> edge;

int main() {
    int n;
    cin >> n;
    dist.resize(n, M);
    edge.resize(n);
    for (int i = 0; i < n; ++i) {
        int id, k;
        cin >> id >> k;
        if (id != i + 1) exit(1);
        if (!k) continue;

        edge[i].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> edge[i][j];
            --edge[i][j];
        }
    }
    queue<int> q;
    q.push(0);
    dist[0] = 0;
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int t : edge[p]) {
            if (dist[t] > dist[p] + 1) {
                dist[t] = dist[p] + 1;
                q.push(t);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << (i + 1) << " " << (dist[i] < M ? dist[i] : -1) << "\n";
    }
    return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
int n;
string s;
int r[324000];
int main(){
	cin >> n;
	cin >> s;
	for(int i = 0;i < n;i++){
		if(s[i] == 'E')r[i] = 1;
		if(i)r[i] += r[i-1];
	}
	int ans = 1 << 28;
	for(int i = 0;i < n;i++){
		int tmp = 0;
		if(i)tmp = i - r[i-1];
		tmp += r[n-1] - r[i];
		ans  = min(ans, tmp);
	}

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

Measured memory_bytes: 1796
#include <stdio.h>
#include <math.h>

int asc(const void *a, const void *b) {//sort
  return *(int *)a - *(int *)b;
}

int main(void){
	int N;
	scanf("%d",&N);
	int a[N][3];
	for (int i = 0; i < N; ++i){
		for (int j = 0; j < 3; ++j){
			scanf("%d",&a[i][j]);
		}
		qsort(a[i], sizeof(a[i]) / sizeof(int), sizeof(int), asc);
		if (pow(a[i][0],2.0) + pow(a[i][1],2.0) == pow(a[i][2],2.0)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2036
from collections import Counter
import math

def combi(n, r):
  if n >= 2:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  else:
    return 0

n = int(input())
a = list(map(int, input().split()))
s = [0]
for i in range(n):
  s.append(s[i] + a[i])
cs = Counter(s)

ans = 0
for i in cs.values():
  ans += combi(i, 2)
print(ans)

Measured memory_bytes: 113096
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
/* テンプレートここまで */

int main() {
  string a,b;
  cin >> a >> b;
  if(a==b) cout << "H" << endl;
  else cout << "D" << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			while (n-- > 0) {
				int pm = scanner.nextInt();
				int pe = scanner.nextInt();
				int pj = scanner.nextInt();
				int ave = (pm + pe + pj) / 3;
				if (pm == 100 || pe == 100 || pj == 100 || (pm + pe) / 2 >= 90
						|| ave >= 80)
					System.out.println("A");
				else if (ave >= 70 || (ave >= 50) && (pm >= 80 || pe >= 80))
					System.out.println("B");
				else
					System.out.println("C");
			}
		}
	}
}

Measured memory_bytes: 28212
N = int(input())
ab, a, b, ans = 0, 0, 0, 0
for i in range(N):
  s = str(input())
  ans += s.count('AB')
  if (s[0]=='B') and (s[-1]=='A'):
    ab += 1
  elif s[0] == 'B':
    b += 1
  elif s[-1] == 'A':
    a += 1
    
if ab > 0:
  ans += ab - 1
  if a > 0:
    ans += 1
    a -= 1
  if b > 0:
    ans += 1
    b -= 1
ans += min(a, b)
print(ans)

Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    // cin.tie(0);
   	// ios::sync_with_stdio(false);
    // ll ll=0;
    // cout << ll;
    string s,t;
    cin >> s;
    cin >> t;
    int cnt=0;
    const char *x= s.c_str();
    const char *y= t.c_str();
    for(int i=0; i<3; i++){
        if(x[i]==y[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

void Main() {
  string s;
  cin >> s;

  int q;
  cin >> q;

  int t[q], f[q];
  char c[q];
  for (int i = 0; i < q; i++) {
    cin >> t[i];
    if (t[i] == 2) {
      cin >> f[i] >> c[i];
    }
  }

  char pre[q], suf[q];
  int prei = 0, sufi = 0;

  bool reversed = false;
  for (int i = 0; i < q; i++) {
    if (t[i] == 1) {
      if (reversed) reversed = false;
      else reversed = true;
    } else {
      if (reversed) {
        if (f[i] == 1) {
          suf[sufi] = c[i];
          sufi++;
        } else {
          pre[prei] = c[i];
          prei++;
        }
      } else {
        if (f[i] == 1) {
          pre[prei] = c[i];
          prei++;
        } else {
          suf[sufi] = c[i];
          sufi++;
        }
      }
    }
  }

  if (reversed) {
    reverse(s.begin(), s.end());
    for (int i = sufi - 1; i >= 0; i--) {
      cout << suf[i];
    }
    cout << s;
    for (int i = 0; i < prei; i++) {
      cout << pre[i];
    }
  } else {
    for (int i = prei - 1; i >= 0; i--) {
      cout << pre[i];
    }
    cout << s;
    for (int i = 0; i < sufi; i++) {
      cout << suf[i];
    }
  }
  cout << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

a = input().split()

a = [int(x) for x in a]

flag = True
i = 0
count = 0

while flag:
    flag = False

    for j in range(n-1, i, -1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            count += 1
            flag = True

    i += 1

for i,x in enumerate(a):
    if i != len(a)-1:
        print(x, end=" ")
    else:
        print(x, end="")
print()
print(count)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//



//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    int n, m;
    cin >> n >> m;
    vector<bool> v(n);
    fill(ALL(v), false);
    vector<int> wv(n);
    int waans = 0;
    int acans = 0;
    rep(i, m){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC"){
            if(!v[p]){
                v[p] = true;
                acans++;
            }
        }
        else{
            if(!v[p]){
                wv[p]++;
            }
        }
    }

    rep(i, n){
        if(v[i]){
            waans += wv[i];
        }
    }

    cout << acans << " " << waans << endl;
    
    
    return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    N,K = map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))

    A.sort()
    F.sort(reverse=True)

    def c(s): # sに対して単調減少
        sum_x = 0
        for i in range(N):
            a,f=A[i],F[i]
            tp = s//f
            if not a <= tp:
                sum_x += a-tp

        return sum_x <= K

    l=-1
    r=10**20
    while r-l>1:
        mid = (l+r)//2
        if c(mid):
            r = mid
        else:
            l = mid

    print(r)

if __name__ == "__main__":
  main()


Measured memory_bytes: 119884
<?php
$input = fgets(STDIN); 
$input_array = explode(" ", $input);

$int_array = array_map( function($value) { return (int)$value; }, $input_array);

$ans= $int_array[2]*60+$int_array[3]-$int_array[0]*60-$int_array[1]-$int_array[4];
echo $ans;

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

using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using vec_i64 = vector<i64>;
using vvec_i64 = vector<vec_i64>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    i64 const MOD = 1e9 + 7;

    i64 N, K;
    cin >> N >> K;

    vec_i64 a_list;
    for (int32_t i = 0; i < N; i++) {
        i64 tmp;
        cin >> tmp;
        a_list.emplace_back(tmp);
    }

    // dp[j] = #combinations when j candies are left
    vec_i64 dp(K + 1, 0);
    dp.at(K) = 1;
    for (i64 i = 0; i < N; i++) {
        // for (i32 i = 0; i < dp.size(); i++) {
        //     cout << dp.at(i) << " ";
        // }
        // cout << "\n";
        // i64 const threshold = suffix_sum.at(i);
        vec_i64 prefix_sum_dp(K + 1, 0);
        vec_i64 next_dp(K + 1, 0);
        i64 current_sum = 0;
        for (i64 j = 0; j <= K; j++) {
            current_sum += dp.at(j);
            prefix_sum_dp.at(j) = current_sum;
        }
        for (i64 j = 0; j <= K; j++) {
            // calc dp[j] = sum_{} dp[k] using a prefix sum
            i32 upper_num_taken_candies = min(K - j, a_list.at(i));
            next_dp.at(j) = j > 0 ? prefix_sum_dp.at(j + upper_num_taken_candies) - prefix_sum_dp.at(j - 1) : prefix_sum_dp.at(j + upper_num_taken_candies);
            next_dp.at(j) %= MOD;
        }
        dp = next_dp;
    }
    cout << dp.at(0) << "\n";
}


Measured memory_bytes: 2664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int n;
vi g[N];
int a[N], ans[N], rem[N];
set<int> s;

void dfs(int v, int p) {
	auto it = s.lower_bound(a[v]);
	if(it != s.end()) {
		rem[p] = *it;
		s.erase(it);
	}
	s.insert(a[v]);
	ans[v] = s.size();
	for(auto i : g[v]) {
		if(i != p) {
			dfs(i, v);
		}
	}
	s.erase(a[v]);
	if(rem[p] != 0) {
		s.insert(rem[p]);
	}
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1, 0);
	for(int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}

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

using namespace std;

//#define MD 10

int main(){
    long int n,x;
    cin>>n>>x;
    vector<long int> a(n);
    for(long int i=0;i<n;i++){
        cin>>a[i];
    }
    
    long int ans=0;
    for(long int i=1;i<n;i++){
        if(a[i-1]+a[i]<=x){
            continue;
        }else if(a[i-1]>x){
            ans+=(a[i]+a[i-1]-x);
            a[i]=0;
            a[i-1]-=a[i-1]-x;
        }else{
            ans+=(a[i]+a[i-1]-x);
            a[i]-=(a[i]+a[i-1]-x);
        }
    }
    
    cout<<ans<<endl;
            
    return 0;
}

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

ll gcd(ll A,ll B){
  while(A%B!=0){
    ll tmp=A%B;
    A=B;
    B=tmp;
  }
  return B;
}

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());

  ll x=A.at(0);
  for(int i=0;i<N;i++){
    x=gcd(x,A.at(i));
  }

  if(K%x==0&&K<=A.at(N-1)){
    cout<<"POSSIBLE"<<endl;
  }else{
    cout<<"IMPOSSIBLE"<<endl;
  }
}


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

int main()
{
	int N;
	cin >> N;
	cout << (N+1)/2 << endl;
	return 0;
}

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

int main(void) {
  string station;
  cin >> station;

  int res = 0;
  if (station[0] != station[1]) {
    res += 1;
  }
  if (station[1] != station[2]) {
    res += 1;
  }

  cout << ((res > 0) ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
N= int(input())
M = int(N**(1/2))
ans = 1
for i in range(1,M+1):
    if N%i == 0:
        ans = i
print(ans+N//ans-2)

Measured memory_bytes: 6820
N,D=map(int,input().split())
d_list=list()
for i in range(N):
    List=list(map(int,input().split()))
    d_list.append(List)
count=0
for i in range(N):
    dis=d_list[i][0]**2+d_list[i][1]**2
    if dis<=D**2:
        count +=1
print(count)

Measured memory_bytes: 45456
import numpy as np
from scipy.spatial import ConvexHull
from scipy.spatial.qhull import QhullError


def solve(n, pts):
    ans = [0] * n

    try:
        hull = ConvexHull(pts)
    except QhullError:
        lm = np.argmin(pts, axis=0)
        rm = np.argmax(pts, axis=0)
        if lm[0] != rm[0]:
            l, r = lm[0], rm[0]
        elif lm[1] != rm[0]:
            l, r = lm[1], rm[0]
        else:
            l, r = lm[0], rm[1]
        ans[l] = ans[r] = 0.5
        return ans

    ps = np.array(list(map(pts.__getitem__, hull.vertices)))
    vs = ps - np.roll(ps, 1, axis=0)

    vt = vs.T
    vt[0] *= -1
    arcs = np.arctan2(*vt)
    arcs = np.append(arcs, arcs[0])
    da = np.diff(arcs) / (2 * np.pi) % 1

    for i, a in zip(hull.vertices, da):
        ans[i] = a

    return ans


n = int(input())
pts = [list(map(int, input().split())) for _ in range(n)]
print('\n'.join(map(str, solve(n, pts))), end='')


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

int main()
{
    int N, K;
    vector<int> p;

    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        int _p;
        cin >> _p;
        p.push_back(_p);
    }
    sort(p.begin(), p.end());

    int answer = 0;
    for(int i = 0; i < K; i++) {
        answer += p[i];
    }

    cout << answer << endl;

    return 0;
}

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

bool so[1000001];

int main(void)
{
	so[0] = so[1] = true;
	// 素数表 true = 素数じゃない
	for(int i = 2; i <= 1000000; i++){
		for(int j = i*2; j <= 1000000; j+=i){
			so[j] = true;
	
		}
	}

	int N,M;

	while(cin >> N >> M, N | M){
		bool d[1000001] = {};
		d[0] = true;

		int mo;
		for(int i = 0; i < N; i++){
			cin >> mo;

			for(int j = 0; j + mo <= M; j++)
				d[j+mo] |= d[j];

		}

		int max = 0;
		for(int i = 0; i <= M; i++)
			if(d[i] && !so[i] && max < i)
				max = i;
		if(max)
			cout << max << endl;
		else
			cout << "NA" << endl;
	}
	

	return 0;
}
	

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

int main(){
    int x, y;

    while(true){
        cin >> x >> y;
        if(x == 0 && y == 0){
            break;
        }
        if(x > y){
            cout << y << " " << x << endl;
        }
        else{
            cout << x << " " << y << endl;
            
        }
    }

}





Measured memory_bytes: 3004
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll factorial(int n){
    if(n==1) return 1;
    return (n * factorial(n-1)) % 1000000007; 
}

int main() {
    int n,m;
    cin >> n >> m;
    if(n-m<-1 || 1<n-m){
        cout << 0 << endl;
        return 0;
    }
    ll ans = factorial(n)*factorial(m)%1000000007;
    if(n==m) cout << ans*2 % 1000000007 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;

int main() {
	ll N,A,B,C,D;
	cin>>N>>A>>B>>C>>D;
	A--;B--;C--;D--;
	string S;cin>>S;
	vector<int> a(N,0),b(N,0);
	a[A] = 1;
	b[B] = 1;
	rep(i,N){
		if(i+1<N)
		if(a[i]&&S[i+1] == '.'){
			a[i+1]++;
		}
		if(i+2<N)
		if(a[i]&&S[i+2] == '.'){
			a[i+2]++;
		}
		if(i+1<N)
		if(b[i]&&S[i+1] == '.'){
			b[i+1]++;
		}
		if(i+2<N)
		if(b[i]&&S[i+2] == '.'){
			b[i+2]++;
		}
	}
	bool can = false;
	for (int i = B-1; i+1 <= D; ++i){
		if(a[i]&&b[i+1]&&a[i+2]){
			can = true;
		}
	}
	string ans = "No";
	if(C<D){
		if(a[C]&&b[D])ans ="Yes";
	}
	else{
		if(a[C]&&b[D]&&can){
			ans = "Yes";
		}
	}
	cout<<ans<<endl;
}

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


int main(void){
	int n;
	scanf("%d", &n);
	if(n%2 == 1)
		printf("%d", n/2 + 1);
	else	
		printf("%d", n/2);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

int main() {
  int N, K;
  std::cin >> N >> K;
  bool dislike[10] = {0};
  for (int i = 0; i < K; ++i) {
    int D;
    std::cin >> D;
    dislike[D] = true;
  }
  std::queue<int> Q;
  Q.push(0);
  for (; not Q.empty();) {
    int X = Q.front();
    Q.pop();
    if (X >= N) {
      printf("%d\n", X);
      break;
    }
    for (int i = 0; i < 10; ++i) {
      if (dislike[i]) {
        continue;
      }
      Q.push(X * 10 + i);
    }
  }
  return 0;
}


Measured memory_bytes: 512
#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(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() {
	int  n, m, q;
	cin >> n >> m >> q;
	hei(int) a(q), b(q), c(q), d(q);
	int i;
	rep(i, 0, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	int ans = 0;
	int s[10];
	m++;
	rep(s[0], 1, m) {
		rep(s[1], s[0], m) {
			rep(s[2], s[1], m) {
				rep(s[3], s[2], m) {
					rep(s[4], s[3], m) {
						rep(s[5], s[4], m) {
							rep(s[6], s[5], m) {
								rep(s[7], s[6], m) {
									rep(s[8], s[7], m) {
										rep(s[9], s[8], m) {
											int z = 0;
											int sum = 0;
											rep(z, 0, q) {
												if (s[b[z] - 1] - s[a[z]-1] == c[z])sum += d[z];
											}
											ans = max(sum, ans);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
def no
  puts "No"
  exit
end

  n = gets.strip.to_i
  s = []
  n.times { s.append gets.strip }
  
  tp, tm = [], []
  lr = 0
  n.times do |i|
    l, r = 0, 0
    s[i].each_char do |c|
      case c
      when '('
        l += 1
      when ')'
        if l > 0
          l -= 1 
        else
          r += 1
        end
      end
    end
    if l >= r
      tp.append r * 10**6 + l
    else
      tm.append l * 10**6 + r
    end
    lr += l - r
  end
  
  no if lr != 0
  
  lr = 0
  tp.sort.each do |a|
    r = a / 10**6
    l = a % 10**6
    if lr >= r
      lr += l - r
    else
      no
    end
  end
  
  lr = 0
  tm.sort.each do |a|
    l = a / 10**6
    r = a % 10**6
    if lr >= l
      lr += r - l
    else
      no
    end
  end
  puts "Yes"


Measured memory_bytes: 106056
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define M 110
#define NIL -1
 
int n;
int G[M][M];
int d[M];
int Q[M];
int c[M];
int t = 0;

void enQ(int);
int deQ(void);
void bfs(int);

int main(){    
    int i = 10;
    int j = 3;
    int k;
    int u;
    int v;
     
    scanf("%d",&n);   
    for(j=1;j<=n;j++){
        for(i=1;i<=n;i++){
            G[j][i] = 0;
        }
    }
    for(j=1;j<=n;j++){
        scanf("%d %d",&u,&k);
        for(i=1;i<=k;i++){
            scanf("%d",&v);
            G[u][v]=1;
        }
    }
    bfs(1);
     
    for(i=1;i<=n;i++){
        if(d[i] == 1000) d[i] = NIL;
        printf("%d %d\n",i,d[i]);
    }
     
    return 0;
     
}

 
void enQ(int a){
  static int x;
  if(x == 110) x = 0;
    Q[x] = a;
    x++;
}
 
int deQ(void){
  static int h;
    if(h == 110) h = 0;
    return Q[h++];
}
 
void bfs(int x){
  int i;
  int j;
  int e = 0;
  
    for(j=1;j<=n;j++){
        c[j] = 0;
        d[j] = 1000;
    }   
    c[x] = NIL;
    d[x] = 0;
    enQ(x);
    e++;
     
    while(e != 0){
        j = deQ();
        e--;
        for(i=1;i<=n;i++){
            if(c[i] == 0 && G[j][i] == 1){
                c[i] = NIL;
                d[i] = d[j] + 1;
                enQ(i);
                e++;
            }
        }
        c[j] = 1;
    }
}




Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N = 1e5 + 5;
int a[N];
int n;
int mem[N];
int oo = 0x3f3f3f3f;
int solve(int i = 0){
    if(i+1 == n)
        return 0;
    int &res = mem[i];
    if(~res)
        return res;
    return res = min((i+1<n?solve(i+1)+abs(a[i]-a[i+1]):oo),
            (i+2<n?solve(i+2)+abs(a[i]-a[i+2]):oo) );
}

int main() {
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false), cin.tie(0);
#endif
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    memset(mem, -1, sizeof(mem));
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    cout<<solve()<<'\n';
}

Measured memory_bytes: 6664
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int k = sc.nextInt();
    String[] str = s.split("");
    String a = str[k-1];    
    
    for(int i = 0 ; i <s.length() ; ++i){
      if(str[i].equals(a)){
        str[i] = a;
      }else{
        str[i] = "*";
      }
      
    }
    String ans = String.join("",str);
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 35700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int mod = A % B;
		boolean ans = false;

		for (int i = 2; i <= B; i++) {
			int tmp = A * i % B;
			if (tmp == C) {
				ans = true;
				break;
			}
			if (mod == tmp) {
				break;
			}
		}
		if (ans) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 23124
N = input()
A = map(int, raw_input().split())
S = sum(A)
if S%(N*(N+1)/2)==0:
    c = S/(N*(N+1)/2)
    for i in range(N):
        A[i] -= c*(i+1)
    ans = "YES"
    for i in range(N-1):
        t = A[i]-A[(i+1)%N]
        if t<0 or t%N!=0:
            ans = "NO"
    print ans
else:
    print "NO"

Measured memory_bytes: 11436
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    k = int(input())
    a, b = map(int, input().split())

    for i in range(a, b+1):
        if i % k == 0:
            print("OK")
            exit()

    print("NG")


if __name__ == "__main__":
    resolve()



Measured memory_bytes: 61676