akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<vector<int>>a(N, vector<int>(N));
	rep(i, 0, N)rep(j, 0, N) { cin >> a[i][j]; }
	vector<int>cost(1 << N);
	rep(bits, 0, 1 << N) {
		rep(i, 0, N) {
			rep(j, i + 1, N) {
				if (bits&(1 << i) and bits&(1 << j))cost[bits] += a[i][j];
			}
		}
	}
	vector<int>dp(1 << N);
	rep(bits, 1, 1 << N) {
		for (int i = bits; i > 0; i = (i - 1)&bits) {
			chmax(dp[bits], dp[bits^i] + cost[i]);
		}
	}
	cout << dp[(1 << N) - 1] << endl;


	return 0;
}


Measured memory_bytes: 1280
from heapq import heappop, heappush

X,Y,Z,K = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

hq = []
heappush(hq, (-(a[0]+b[0]+c[0]), 0, 0, 0))
for _ in range(K):
    ans, i, j, k = heappop(hq)
    print(-ans)

    if i+1 < X:
        t = (-(a[i+1]+b[j]+c[k]), i+1, j, k)
        if t not in hq:
            heappush(hq, t)

    if j+1 < Y:
        t = (-(a[i]+b[j+1]+c[k]), i, j+1, k)
        if t not in hq:
            heappush(hq, t)
    
    if k+1 < Z:
        t = (-(a[i]+b[j]+c[k+1]), i, j, k+1)
        if t not in hq:
            heappush(hq, t)


Measured memory_bytes: 3828
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)

judge = sum(A)*1/(4*M)
cnt = 0
for i in range(M):
  if(A[i]>=judge):
    cnt += 1

if(cnt == M):
  print('Yes')
else:
  print('No')
  

Measured memory_bytes: 9116
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
void solve() {
  int n;
  cin >> n;
  map<string, int> m;
  int max = 0;
  for (int i = 0; i < n; ++i) {
    string si;
    cin >> si;
    auto it = m.begin();
    tie(it, ignore) = m.insert({si, 0});
    it->second++;
    max = std::max(it->second, max);
  }
  for (const auto& elem : m) {
    if (elem.second == max) {
      cout << elem.first << "\n";
    }
  }
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 25216
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),sum=0;
		int[] w = new int[n];

		for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		}

		int hrf = sum/2;
		int j = 0,tmp=0;
		int s1 = 0, s2 = sum;
		while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		}

		int min = s1 - s2;
		s1 -= tmp;
		s2 += tmp;
		min = (min > s2 - s1) ? s2 - s1: min;
		min = (min < 0) ? min * -1: min;
		System.out.println(min);
	}

}


Measured memory_bytes: 22868
def count_2(k, ret)
  return ret if k % 2 == 1

  count_2(k / 2, ret + 1)
end

def solve(a)
  a.map! { |i| count_2(i, 0) }
    .reduce{ |a, e| a + e }
end

def main
  stdin = STDIN.gets
  na = stdin.split(/\s/).map!(&:to_i)
  n = na[0]
  a = STDIN.gets.split(/\s/).map!(&:to_i)

  puts solve(a)
end

main

Measured memory_bytes: 2300
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
LL A[100001];
LL gcd(LL a,LL b){
   if(b==0)return a;
   return gcd(b,a%b);
}
int main(){
    cin>>N;
    REP(i,N){
        cin>>A[i];
    }
    int ans=0;
    while(1){
        int even=0;
        REP(i,N){
            if(A[i]%2==0)even++;
        }
        if(even%2==1)break;
        if(even!=N-1){
           ans=1-ans;
           break;
        }
        bool check=false;
        REP(i,N){
            if(A[i]==1){
               check=true;
            }
            A[i]=A[i]/2;
        }
        ans=1-ans;
        if(check){
           break;
        }
        
        LL ggg=A[0];
        REP(i,N-1){
            ggg=gcd(A[i],ggg);
        }
        REP(i,N){
            A[i]=A[i]/ggg;
        }
    }
    
    if(ans==0){
       cout<<"First"<<endl;
    }else{
       cout<<"Second"<<endl;
    }
}

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

int main(){
  int K;

  while(true){
  
    cin >> K;

    if(K == 0) break;
    
    int *c = new int[K*(K-1)/2];
    int ans = 0;
  
    for(int i=0; i<K*(K-1)/2 ; ++i){
      cin >> c[i];

      ans += c[i];
    }

    cout << ans / (K-1) << endl;

    delete[] c;

  }
  return 0;
}



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

using namespace std;

const long long INF = 1e18;

int n, m;
long long a[3][1005], cost[1005], res, sign[1005];

bool cmp(int u, int v){
	return cost[u] < cost[v];
}

long long go(){
	vector <int> p;
	
	for(int i = 0; i < n; i++){
		p.push_back(i);
		cost[i] = sign[0] * a[0][i] + sign[1] * a[1][i] + sign[2] * a[2][i];
	}
	
	sort(p.begin(), p.end(), cmp);
	
	long long v1 = 0;
	long long v2 = 0;
	long long v3 = 0;
	
	for(int i = 0; i < m; i++){
		v1 += a[0][p[i]];
		v2 += a[1][p[i]];
		v3 += a[2][p[i]];
	}
	
	return abs(v1) + abs(v2) + abs(v3);
}

void solve(int lv){
	if(lv == 3){
		res = max(res, go());
		return;
	}
	sign[lv] = 1;
	solve(lv + 1);
	sign[lv] = -1;
	solve(lv + 1);
}

int main(){
	scanf("%d%d", &n, &m);
	
	for(int i = 0; i < n; i++)
	scanf("%lld%lld%lld", &a[0][i], &a[1][i], &a[2][i]);
	
	res = -INF;
	
	solve(0);
	
	printf("%lld\n", res);
}


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

int main() {
    int N; cin >> N;
    vector<int> H(N);
    rep(i, N){
        cin >> H[i];
    }
    int ans = 0;
    int cnt = 0;
    int now = H[0];
    for (int i = 1; i < N; i++){
        int nex = H[i];
        if(now >= nex){
            now = nex;
            cnt++;
            ans = max(ans, cnt);
        } else {
            ans = max(ans, cnt);
            cnt = 0;
            now = nex;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    while(true){
    cin >> a >> b;
        if(a == 0 && b == 0)
	    break;
        for ( int i = 0; i < a; i++ ){
            for ( int j = 0; j < b; j++ ){
                if(i == 0 || i == a - 1 || j == 0 || j == b - 1) {
                cout << "#";
                }else{
                cout << ".";
                }
            }
        cout << endl;
        }
    cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int k = -1;
	for(int i = 1; i < 1000; i++) {
		if( (i * (i-1)) / 2 == n) {
			k = i;
			break;
		}
	}
	if(k == -1) {
		cout << "No";
		exit(0);
	}
	cout << "Yes\n";
	vector<vector<int>> sets(k);
	int num = 1;
	for(int i = 0; i < k; i++) {
		for(int j = i + 1; j < k; j++) {
			sets[i].push_back(num);
			sets[j].push_back(num);
			num++;
		}
	}
	cout << k << "\n";
	for(int i = 0; i < k; i++) {
		cout << sets[i].size() << " ";
		for(int x : sets[i]) cout << x << " ";
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(void){
    int N;
    int counter = 0;
    int flag = false;
    scanf("%i", &N);
    int A[N];
    for (int i = 0; i < N; i++){
        scanf("%i", &A[i]);
    }
    while (!flag){
        for (int i = 0; i < N; i++){
            if (A[i] % 2){
                flag = true;
                break;
            } else {
                A[i] /= 2;
            }
        }
        if (!flag){
            counter += 1;
        }
    }
    printf("%i\n", counter);
}

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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
//int a[N+2];
map<int,int>mm;
bool chk(int n){
  while(n>0){
    int dig=n%10;
    if(mm[dig])return false;
    n/=10;
  }
  return true;
}
int32_t  main(){
	IOS;
  int n,k;cin>>n>>k;
  fori(i,k){
    int va;cin>>va;
    mm[va]=1;
  }
  for(int i=n;i<1e5;++i){
    //check if i is a valid number 
    if(chk(i)){cout<<i<<endl;return 0;}
  }


  return 0;
}



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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

long long solve(long long n){
    if (n % 2 == 1) return 0;
    
    long long res = 0;
    
    n /= 2;
    while(n){
        res += n / 5;
        n /= 5;
    }
    return res;
}

int main(){
    long long n;
    cin >> n;
    
    cout <<solve(n) << endl;
}

Measured memory_bytes: 256
q=int(input())
def check(t,a,b):
    k=(2*a+t)//2
    return k*(2*a+t-k)<a*b

for i in range(q):
    a,b=sorted(map(int,input().split()))
    if a==b or a==b-1:
        print(2*a-2)
        continue
    l,r=1,b-a
    while l+1<r:
        t=(l+r)//2
        if check(t,a,b):
            l=t
        else:
            r=t
    if check(r,a,b):
        print(2*a-2+r)
    else:
        print(2*a-2+l)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>

using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

vector<pair<int, int> > vpi;
int x, y, n, m;
int col[1<<20];
vector<pair<int,int>> g[1<<20];
bool vis[1<<20];
vector<int> ans;

int dfs(int x) {
  vis[x] = 1;
  int y = col[x];
  for(auto node:g[x]) {
    if(vis[node.first]) continue;
    int val = dfs(node.first);
    if(val) ans.push_back(node.second);
    y ^= val;
  }
  return y;
}

int main() {

//  freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  cin >> n >> m;
  for(int i = 0;i < n;i++) {
    cin >> x >> y;
    vpi.push_back({x, y});
  }
  sort(vpi.begin(), vpi.end());
  col[0] = vpi[0].second;
  for(int i = 1;i < n;i++) {
    col[i] = vpi[i].second ^ vpi[i-1].second;
  }
  col[n] = vpi[n-1].second;
  // for(auto x:vpi) cout<<x.first<<":"<<x.second<<", ";cout<<endl;
  // for(int i=0;i<=n;i++) cout<<col[i]<<", ";cout<<endl;

  for(int i = 0;i < m;i++) {
    cin >> x >> y;
    int si = lower_bound(vpi.begin(), vpi.end(), make_pair(x, 0)) - vpi.begin();
    int ei = upper_bound(vpi.begin(), vpi.end(), make_pair(y, 1)) - vpi.begin();

    g[si].push_back({ei, i+1});
    g[ei].push_back({si, i+1});
  }

  // print graph

  // for(int i = 0;i <= n;i++) {
  //   cout << i << ": ";
  //   for(auto node:g[i]) cout << node.first << " ";cout<<endl;
  // }

  for(int i = 0;i <= n;i++) {
    if(vis[i]) continue;
    int val = dfs(i);
    if(val == 1) {
      cout << -1 << endl;
      return 0;
    }
  }

  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for(auto x:ans) cout << x << " ";

  return 0;
}


Measured memory_bytes: 38260
#include<bits/stdc++.h>
using namespace std;
struct sta{
  int st[95][95];
  int x,y;
  int n;
};
int main(){
  int m,n;
  while(cin >> m >> n,m||n){
    sta s,b;
    memset(b.st,0,sizeof(b.st));
    int i,j,k,l;
    for(i=1;i<=n;i++){
      for(j=1;j<=m;j++){
	cin >> b.st[j][i];
      }
    }
    
    int ans=0;
    int ax[]={1,-1,0,0};
    int ay[]={0,0,1,-1};
    for(i=1;i<=n;i++){
      for(j=1;j<=m;j++){
	if(b.st[j][i]==0) continue;
	for(k=1;k<=n;k++){      
	  for(l=1;l<=m;l++){
	    s.st[l][k]=b.st[l][k];
	  }
	}
	s.x=j;s.y=i;s.n=1;s.st[s.x][s.y]=0;
	queue<sta> q;
	q.push(s);
	while(!q.empty()){
	  s=q.front();q.pop();
	  ans=max(ans,s.n);
	  for(k=0;k<4;k++){
	    s.x+=ax[k];s.y+=ay[k];
	    if(s.st[s.x][s.y]){
	      s.st[s.x][s.y]=0;
	      s.n++;
	      q.push(s);
	      s.n--;
	      s.st[s.x][s.y]=1;
	    }
	    s.x-=ax[k];s.y-=ay[k];
	  }
	}
      }
    }
    cout << ans << endl;
  }    
  return 0;
}

Measured memory_bytes: 29336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;
    if ((int)s.size() <= k) cout << s << endl;
    else cout << s.substr(0, k) << "..." << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll S,W;
int main(){
    cin>>S>>W;
    if(S<=W){
        cout<<"unsafe";
        return 0;
    }else{
        cout<<"safe";
    }

    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict, deque
n=int(input())
v=n*(n-1)//2
es=[[] for _ in range(v)]

for i in range(n):
    *A,=map(int,input().split())
    for j in range(n-2):
        a=A[j]
        x,y=min(a-1,i),max(a-1,i)
        ith=((n-x)+(n-1))*x//2-1+(y-x)
        b=A[j+1]
        x,y=min(b-1,i),max(b-1,i)
        jth=((n-x)+(n-1))*x//2-1+(y-x)
        es[ith].append(jth)

outs = defaultdict(list)
ins = defaultdict(int)

for v1 in range(v):
    for v2 in es[v1]:
        outs[v1].append(v2)
        ins[v2] += 1

q = deque((v1,0) for v1 in range(v) if ins[v1] == 0)
res = []
while q:
    v1,cnt = q.popleft()
    res.append((v1,cnt))
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append((v2,cnt+1))
x=len(res)
if x!=v:
    print(-1)
else:
    print(res[-1][1]+1)

Measured memory_bytes: 281132
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int count = 0;
            if (S == T) {
                Console.WriteLine(0);
                return;
            }

            for (int i = 0; i < S.Length; i++) {
                if (S[i] != T[i]) {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27516
import java.util.*

fun main(args:Array<String>){
    val (n,a,b) = readLine()!!.split(" ").map{it.toInt()}
    val x = readLine()!!.split(" ").map{it.toLong()}
    var ans = 0L
    for(i in 0 until n - 1){
        ans += Math.min(a * (x[i + 1] - x[i]), b.toLong())
    }
    println(ans)
}


Measured memory_bytes: 53524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;

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

struct Data
{
	int tx,ty,kx,ky,cost;

	Data(int tx,int ty,int kx,int ky,int cost) : tx(tx),ty(ty),kx(kx),ky(ky),cost(cost) {}
};

int main()
{
	int x,y;
	while(cin >> x >> y)
	{
		if(x == 0 && y == 0) break;

		int tx,ty,kx,ky;
		cin >> tx >> ty >> kx >> ky;

		tx--;
		ty--;
		kx--;
		ky--;

		int field[55][55];
		memset(field,0,sizeof(field));

		rep(i,y) rep(j,x) cin >> field[i][j];

	   	bool used[52][52][52][52];
		rep(i,52) rep(j,52) rep(k,52) rep(l,52) used[i][j][k][l] = false;
		used[tx][ty][kx][ky] = true;

		queue<Data> que;
		que.push(Data(tx,ty,kx,ky,0));
		
		bool flag = false;
		int ans;

		while(que.size())
		{
			Data data = que.front();
			que.pop();

			if(data.cost >= 100) break;

			if(data.tx == data.kx && data.ty == data.ky)
			{
				flag = true;
				ans = data.cost;
				break;
			}

			rep(i,4)
			{
				int ntx = data.tx + dx[i];
				int nty = data.ty + dy[i];
				int nkx = data.kx + dx[(i+2)%4];
				int nky = data.ky + dy[(i+2)%4];

				Data nd(data.tx,data.ty,data.kx,data.ky,data.cost+1);

				if(0 <= ntx && ntx < x && 0 <= nty && nty < y && field[nty][ntx] == 0)
				{
					nd.tx = ntx;
					nd.ty = nty;
				}

				if(0 <= nkx && nkx < x && 0 <= nky && nky < y && field[nky][nkx] == 0)
				{
					nd.kx = nkx;
					nd.ky = nky;
				}

				if(!used[nd.tx][nd.ty][nd.kx][nd.ky])
				{
					used[nd.tx][nd.ty][nd.kx][nd.ky] = true;
					que.push(nd);
				}
			}

		}

		if(flag) cout << ans << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 8528
s = input()

if len(s) != 1:
    ans = [0] *(round(len(s)/2))
else:
    ans = [0]

ind = 0
for i in range(len(s)):

    if (i+1) % 2 == 1:
        ans[ind] =str( s[i])
        ind += 1

ans = ''.join(ans)
print(str(ans))


Measured memory_bytes: 3572
#include <iostream>
#include <set>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    set<int> As;
    for (int i = 1; i <= N; ++i) {
        As.insert(i);
    }
    
    int D, A;
    for (int i = 0; i < K; ++i) {
        cin >> D;
        for (int j = 0; j < D; ++j) {
            cin >> A;
            As.erase(A);
        }
    }

    cout << As.size() << endl;
}


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

int main()
{
	int a,b,c,sum=0;
	char s[100];
	
	cin>>a>>b>>c;
    sum=max({a,b,c})-min({a,b,c});
    cout<<sum<<endl;
	return 0;
}
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w,i,j;
	cin>>h>>w;
	char a[h][w];
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		cin>>a[i][j];
	}
	for(i=0;i<h+2;i++)
	{
		for(j=0;j<w+2;j++)
		{
			if(i==0||j==0||i==h+1||j==w+1)
			cout<<"#";
			else
			cout<<a[i-1][j-1];
		}
		cout<<endl;
	}
	
	}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

ll N, K, A[1<<20];

ll find_answer(vector<int> &B) {
  // B[i] > B[j]-K
  ll ans = 0;

  for(int j = 1; j < (int) B.size();j++) {
    auto it = upper_bound(B.begin(), B.begin()+j, B[j]-K);
    ans += (B.begin()+j-it);
  }

  return ans;
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  unordered_map<ll, vector<int> > uma;
  uma[0].push_back(0);

  cin >> N >> K;
  for(int i = 1;i <= (int) N;i++) {
    cin >> A[i];
    A[i]--;
    A[i] = (A[i] + A[i-1]) % K;
    uma[A[i]].push_back(i);
  }

  ll ans = 0;
  for(auto it = uma.begin();it != uma.end();it++) {
    ans += find_answer(it->second);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 19400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int A[1];
int size=1;
int m=2;
#define N 101
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)
/*
bool prime(ll n){if(n==1)return false;for(ll i=2;i*i<=n;i++)if(n%i==0){return false;}return true;}
void prime_fact(int n){for(int i=2;i*i<=n;i++){int count=0;if(n%i==0){while(n%i==0)n/=i,count++;cout<<i<<"^"<<count<<" ";}}if(n>1)cout<<n<<"^1";}
ll power(ll base ,ll pow){ll res=1;while(pow>0){if(pow&1)res*=base,pow-=1;else base*=base,pow/=2;}return res;}
void prime_fact_seieve(int n){for(int i=2;i<=size;i++){if(A[i]==0)for(ll j=i;j<=size;j+=i)if(A[i]==0)A[j]=i;}while(n>2){cout<<A[n]<<"*";n/=A[n];}}
template <class X> X gcd(X a , X b) { return b==0?a: gcd( b, a%b); }
template <class X> X lcm(X a , X b) { return a/gcd(a,b) * b ; }
ll Ab[N][N],I[N][N];  // identity matrix and a matrix to store result
void multiply(ll I[][N],ll A[][N],int dim)
{   int res[dim+1][dim+1];
    for(int i=0;i<dim;i++)
    {  for(int j=0;j<dim;j++)
        {
           res[i][j]=0;
           for(int k=0;k<dim;k++)
           {  res[i][j]+=((I[i][k]%mod)*(A[k][j])%mod)%mod;}}}

        for(int i=0;i<dim;i++)
            for(int j=0;j<dim;j++)
                I[i][j]=res[i][j];}
void powerMat(ll A[][N],int dim,int n)
{   for(int i=0;i<dim;i++)
    for(int j=0;j<dim;j++)
    {if(i==j) I[i][j]=1;
     else     I[i][j]=0;}
     while(n>0)
     {
         if(n%2)
         multiply(I,A,dim),n--;
         else
         multiply(A,A,dim),n/=2;
     }
     for(int i=0;i<dim;i++)
         for(int j=0;j<dim;j++)
             A[i][j]=I[i][j];
}
void printMat(ll A[][N],int dim)
{
    for(int i=0;i<dim;i++)
    {for(int j=0;j<dim;j++)
        {
            cout<<A[i][j]<<" ";
        }cout<<"\n";}
}
// REMEMBER PREFIX SUM SUFFIX SUM OR GCD VERY INTERESTING QUESTIONS
ll power(ll base ,ll pow,ll mo){ll res=1;while(pow>0){if(pow&1)res=(res%mo*base%mo)%mo,pow-=1;else base=(base%mo*base%mo)%mo,pow/=2;}return res;}*/
bool Binary(vector<int> arr,int n,int ele,int b)
{  int l=0,r=n-1,m;
   while(l<=r)
   {
       m=l+(r-l)/2;
       if(arr[m]==ele)
       {arr[m]=b;return true;}
       else if(arr[m]>ele)
           r=m-1;
       else
           l=r+1;
   }
    return false;

}

int main()
{
    fast;
    int n,m;
    cin>>n>>m;
    if(m%n==0)
        cout<<n+m;
    else
        cout<<m-n;
    
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j

static const int MAX = 100005;
static const int INFTY = (1<<21);
static const int WHITE = 0; // 未到達
static const int GRAY = 1; // 到達
static const int BLACK = 2; // 探索済み
static const ll mod = 1e9+7;

int color[MAX];
int k[MAX];
int p[MAX];

int N, K;

pair<vector<int>, int> adj[MAX];

void solve() {
  queue<int> que;
  rep(i, 0, MAX) {
    color[i] = 0;
    k[i] = -1;
    p[i] = -1;
  }
  k[0] = K;
  adj[0].second = 0;
  p[1] = 0;
  color[1] = GRAY;

  que.push(1);

  while(!que.empty()) {
    int u = que.front();
    que.pop();
    color[u] = BLACK;

    rep(j, 0, adj[u].first.size()) {
      int v = adj[u].first[j];
      adj[v].second += 1;
    }

    k[u] = K - adj[p[u]].second;

    rep(j, 0, adj[u].first.size()) {
      int v = adj[u].first[j];
      if (color[v] == BLACK) continue;
      p[v] = u;
      que.push(v);
    }
  }
};

int main() {
  cin >> N >> K;
  int a, b;
  rep(i, 1, N) {
    scanf("%d %d", &a, &b);
    adj[a].first.pb(b);
    adj[a].second = 0;
    adj[b].first.pb(a);
    adj[b].second = 0;
  }

  solve();
  ll ans = 1;
  rep(i, 1, N + 1) {
    ans *= k[i];
    ans = ans % mod;
  }
  cout << ans << endl;
};


Measured memory_bytes: 8440
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = 2e5 + 100;
const int ALP = 26;
map <int, int> dp;//[1 << ALP];
char str[N];


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    scanf("%s", str);
    int len = strlen(str);
    int cur = 0;
    dp[0] = 0;

    for (int i = 0; i < len; i++)
    {
        cur ^= (1 << (str[i] - 'a'));
        int cdp = N;
        if (dp.count(cur) )
            cdp = dp[cur] + 1;

        for (int j = 0; j < ALP; j++)
        {
            if (dp.count(cur ^ (1 << j)))
                cdp = min(cdp, dp[cur ^ (1 << j)] + 1);
        }
        if (!dp.count(cur))
            dp[cur] = cdp;
        else
            dp[cur] = min(dp[cur], cdp);
        if (i == len - 1)
            printf("%d\n", cdp);
    }


	return 0;
}



Measured memory_bytes: 9856
import java.util.*;
import java.io.*;

class Main{
	public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
    String week[]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
    for(;;){
    int day=0;
    int m =sc.nextInt();
    int d =sc.nextInt();
    if(m==0) break;
    day+=d;
    for(int i=2; i<=m; i++){
    if(i==5||i==7||i==10||i==12)day+=30;
    else if(i==3)day+=29;
    else day+=31;
    }
   System.out.println(week[day%7]);
    }
	}
}

Measured memory_bytes: 17244
import string
N,M=map(int,input().split())
A=list(range(N))
B=list(range(N))
for i in range(N):
 A[i]=0
for i in range(N):
 B[i]=0
CL=0
PN=0
for i in range(M):
 P,s=input().split()
 p=int(P)
 if A[p-1]==0:
  if s=="WA":
   B[p-1]+=1
  else:
   CL+=1
   PN+=B[p-1]
   A[p-1]=1
print("{0} {1}".format(CL,PN))

Measured memory_bytes: 11632
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main(){
  int n;
  cin>>n;
  int cnt=0;
  vector<int>a(n),b(n);
  rep(i,n)cin>>a[i]>>b[i];
  rep(i,n-2){
    if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<algorithm>
#define NN 2011
using namespace std;

int main(){
  int xmax=0,sum,n,takara[NN],hasi[NN],flag=0,vmax=0,h,hh,ans=0;
  
  while(1){
    ans=0;
    flag=0;
    sum=0; 
    xmax=0;
    cin >> n ;
    if(n == 0)break;
    
    for(int i=0;i<n;i++){
      cin >>takara[i];
      cin >>hasi[i];
      if(takara[i] > hasi[i])flag=1;
      sum+=takara[i];
      xmax=max(xmax,hasi[i]);
    }
    if(flag==1){
      cout << "No" << endl; 
      continue;
    } 

    if(sum > xmax){
     
      cout << "No" << endl;
      continue;
    }

    vmax=0;
    for(int i=0;i<n;i++){
      vmax=i;
      for(int j=i;j<n;j++){
	if(hasi[vmax]>=hasi[j])vmax=j;
      }
      h=hasi[vmax];
      hasi[vmax]=hasi[i];
      hasi[i]=h;

      hh=takara[vmax];
      takara[vmax]=takara[i];
      takara[i]=hh;

    }

    /*
    for(int i=0;i<n;i++){
    cout << "takara[" << i << "] =" << takara[i];
    cout << "hasi[" << i << "] =" << hasi[i] << endl;

    }  
    */

    int flag2=0;
    for(int i=0;i<n;i++){
      if(ans>hasi[i]){
	flag2=1;
      }
      ans+=takara[i]; 
      if(ans>hasi[i]){
	flag2=1;
      }
    }
    if(flag2==0){
    cout << "Yes" << endl; 
    }
    else{
      cout << "No" << endl; 
    }
    flag2=0;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] times = new int[5];
    times[0] = sc.nextInt();
    times[1] = sc.nextInt();
    times[2] = sc.nextInt();
    times[3] = sc.nextInt();
    times[4] = sc.nextInt();

    int[] rems = new int[5];
    for (int i = 0; i < 5; i++) {
      rems[i] = (times[i]-1) % 10;
    }

    int minRem = rems[0];
    int minMen = 0;
    for (int i = 1; i < 5; i++) {
      if (rems[i] < minRem) {
        minRem = rems[i];
        minMen = i;
      }
    }

    int t = 0;
    for (int i = 0; i < 5; i++) {
      if (i != minMen) {
        if (times[i] % 10 == 0) {
          t += times[i];
        } else {
          t += ((times[i] / 10) + 1) * 10;
        }
      }
    }
    t += times[minMen];

    System.out.println(t);
  }
}


Measured memory_bytes: 22612
#include<iostream>
#include<vector>
using namespace std;
const long long mod=1000000007;
vector<long long>dp0;
vector<long long>dp1;
vector<vector<int> >G;
long long dfs(int root,int par,int color)
{
    if(color==0)
    {
        if(dp1[root]==-1)
        {
            dp1[root]=1;
            for(int i=0;i<G[root].size();i++)
            {
                int chd=G[root][i];
                if(chd!=par)
                {
                    dp1[root]=(dp1[root]*dfs(chd,root,1))%mod;
                }
            }
        }
        return dp1[root];
    }
    else
    {
        if(dp0[root]==-1)
        {
            dp0[root]=1;
            for(int i=0;i<G[root].size();i++)
            {
                int chd=G[root][i];
                if(chd!=par)
                {
                    dp0[root]=(dp0[root]*dfs(chd,root,0))%mod;
                }
            }
        }
        if(dp1[root]==-1)
        {
            dp1[root]=1;
            for(int i=0;i<G[root].size();i++)
            {
                int chd=G[root][i];
                if(chd!=par)
                {
                    dp1[root]=(dp1[root]*dfs(chd,root,1))%mod;
                }
            }
        }
        return (dp0[root]+dp1[root])%mod;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,i,j,k;
    cin>>n;
    dp0.resize(n+1,-1);
    dp1.resize(n+1,-1);
    G.resize(n+1);
    for(i=1;i<=n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    cout<<dfs(1,0,1);
}


Measured memory_bytes: 14208
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 1e5 + 7;
int N;
int64_t a[MAX_N];

std::map<int64_t, int> mp;

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> a[i];
        mp[a[i]]++;
    }

    if (3 < mp.size()) {
        std::cout << "No" << std::endl;
        return 0;
    }

    if (mp.size() == 1) {
        if (a[1] == 0) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
        return 0;
    }

    std::vector<int64_t> x, y;
    for (auto p : mp) {
        x.push_back(p.first);
        y.push_back(p.second);
    }

    if (mp.size() == 2) {
        if (N % 3 == 0 && x[0] == 0 && y[0]*2 == y[1]) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
        return 0;
    }

    //std::cout << x[0] << " " << x[1] << " " << x[2] << std::endl;

    if ((x[0] ^ x[1]) == x[2] && y[0] == y[1] && y[1] == y[2]) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

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


void solve(long long N, long long K){

    /*
    long long x;

    x = N;


    for(int n = 0; n < 30; n++){
        cout << n << ": " << x << endl;
        x = abs(x-K);
    }
    */

    long long rem;
    long long diff;
    rem = N % K;
    diff = abs(rem-K);

    //cout << rem << ", " << diff << ", " << min(rem, diff) << endl;
    cout << min(rem, diff) << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{min,max};

struct DisjointSet {
    ps: Vec<Option<usize>>,
    ns: Vec<i64>,
}

fn init(n: usize) -> DisjointSet {
    return DisjointSet { ps: vec![None; n], ns: vec![1; n] };
}

fn unite(ds: &mut DisjointSet, x: usize, y: usize) {
    let nx = find(ds, x);
    let ny = find(ds, y);
    if nx == ny {
        return;
    }
    let (a,b) = if ds.ns[nx] < ds.ns[ny] { (nx,ny) } else { (ny,nx) };
    ds.ps[a] = Some(b);
    ds.ns[b] += ds.ns[a];
}

fn find(ds: &mut DisjointSet, x: usize) -> usize {
    match ds.ps[x] {
        Some(y) => {
            let res = find(ds, y);
            ds.ps[x] = Some(res);
            return res;
        },
        None => {
            return x;
        },
    }
}

fn same(ds: &mut DisjointSet, x: usize, y: usize) -> bool {
    return find(ds,x) == find(ds,y);
}

fn main() {
    let xs = read_vec_i64();
    let (n,q) = (xs[0] as usize, xs[1] as usize);
    let mut ds = init(n);
    for _ in 0..q {
        let ys = read_vec_i64();
        let (com,x,y) = (ys[0], ys[1] as usize, ys[2] as usize);
        if com == 0 {
            unite(&mut ds, x, y);
        }
        else {
            println!("{}", if same(&mut ds,x,y) { 1 } else { 0 });
        }
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}



Measured memory_bytes: 5048
#include <iostream>
#include <vector>

int main(int argc, char const* argv[]) {
    int h, w;
    std::cin >> h >> w;

    std::vector<std::string> grid(h);
    for (auto& g : grid) {
        std::cin >> g;
    }

    for (int x = 0; x < w; ++x) {
        for (int y = 0; y < h; ++y) {
            bool e = false;
            if (grid[y][x] == '.') {
                continue;
            }
            if (x != 0) {
                e |= grid[y][x - 1] == '#';
            }
            if (y != 0) {
                e |= grid[y - 1][x] == '#';
            }
            if (x != w - 1) {
                e |= grid[y][x + 1] == '#';
            }
            if (y != h - 1) {
                e |= grid[y + 1][x] == '#';
            }
            if (!e) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    string s,t;
    cin >> s >> t;
    int n_s = s.size();
    int n_t = t.size();
    int cnt = -1;
    for(int i = 0; i < n_s-n_t+1; i++) {
        int k = i;
        int num=0;
        for (int j=0; j<n_t; j++){
            if (s[k] == t[j]){
                num++;
            
            }
            k++;

        }
        cnt = max(cnt,num);
    }
    cout << n_t - cnt << endl;

    return 0;
}

Measured memory_bytes: 3600
fun main(args: Array<String>) {
    val N = nextLong()
    var a = Math.sqrt(N.toDouble()).toLong()
    while (N % a != 0L && a > 1) a -= 1
    val b = N / a
    println(a + b - 2)
}fun next() = readLine()!!
fun nextLong() = next().toLong()


Measured memory_bytes: 31744
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll fc[225816]={1ll},nv[225816]={1ll},w[225816];
int c[225816],ufp[225816],ufr[225816];
P fi=P(INFLL,INF),se=P(INFLL,INF),gfi[225816];
vector<int> v[225816];

ll rwpw(ll a, ll p=MOD-2){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufr[i] = 1;
		ufp[i] = i;
	}
}

int ufind(int x){
	if(x==ufp[x]){
		return x;
	}
	return ufp[x] = ufind(ufp[x]);
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		return;
	}
	if(ufr[x]<ufr[y]){
		swap(x,y);
	}
	ufr[x] += ufr[y];
	ufp[y] = x;
}

ll comb(int n, int k){
	ll ret = fc[n];
	mul_mod(ret,nv[k]);
	mul_mod(ret,nv[n-k]);
	return ret;
}

int main(void){
	int n,i,m,j,p,q;
	ll x,y,ans=1ll;
	P tmp;
	cin >> n >> x >> y;
	ufinit(n);
	fill(gfi,gfi+n,P(INFLL,INF));
	for(i=1; i<=n; ++i){
		fc[i] = fc[i-1]*i%MOD;
		nv[i] = rwpw(fc[i]);
	}
	for(i=0; i<n; ++i){
		cin >> c[i] >> w[i]; --c[i];
		tmp = P(w[i],i);
		gfi[c[i]] = min(gfi[c[i]],tmp);
		fi = min(fi,tmp);
	}
	for(i=0; i<n; ++i){
		if(c[i]==c[fi.second]){
			continue;
		}
		se = min(se,P(w[i],i));
	}
	for(i=0; i<n; ++i){
		if(gfi[c[i]].first + w[i] <= x){
			unionf(gfi[c[i]].second,i);
		}
		if(c[i]==c[fi.second]){
			if(se.first + w[i] <= y){
				unionf(se.second,i);
			}
		}else{
			if(fi.first + w[i] <= y){
				unionf(fi.second,i);
			}
		}
	}
	for(i=0; i<n; ++i){
		v[ufind(i)].push_back(c[i]);
	}
	for(i=0; i<n; ++i){
		if(!v[i].l_ength()){
			continue;
		}
		m = v[i].l_ength();
		sort(v[i].begin(),v[i].end());
		p = 1; q = m;
		for(j=1; j<m; ++j){
			if(v[i][j-1]!=v[i][j]){
				mul_mod(ans,comb(q,p));
				q -= p; p = 0;
			}
			++p;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 22272
#include <stdio.h>

int main(void){
	int a, b;

	scanf("%d", &a);

	if(a % 2 == 0){
		b = (a/2) * (a/2);
	}
	else{
		b = (a/2) * (a/2 + 1);
	}

	printf("%d\n", b);


	return 0;
}


Measured memory_bytes: 128
N,K = map(int,input().split())
A = list(map(int,input().split()*2))
base1 = 0
base2 = 0
for i in range(N):
  count1=0
  count2=0
  for j in range(i+1,i+N+1):
    if A[i] > A[j]:
      if j < N:
        count1+=1
      else:
        count2+=1
  base1+=count1
  base2+=count2

ans = (base1*K*(K+1) + base2*K*(K-1))//2
div = 10**9 + 7
print(ans%div)

Measured memory_bytes: 3316
/*
* @author:  codancer
* @createTime:  2020-04-12, 20:10:44
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
const int N = 5000;
ll R[N],G[N],B[N];
char s[N];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	rep(i,1,n){
		R[i]=R[i-1];
		G[i]=G[i-1];
		B[i]=B[i-1];
		if(s[i]=='R') R[i]++;
		if(s[i]=='G') G[i]++;
		if(s[i]=='B') B[i]++;
	}
	ll ans=0;
	rep(i,2,n-1){
		if(s[i]=='R'){
			ans+=G[i-1]*(B[n]-B[i]);
			ans+=B[i-1]*(G[n]-G[i]);
			for(int steps=1;i-steps>=1&&i+steps<=n;steps++){
				if(s[i-steps]=='G'&&s[i+steps]=='B') --ans;
				if(s[i-steps]=='B'&&s[i+steps]=='G') --ans;
			}
		}
		if(s[i]=='G'){
			ans+=R[i-1]*(B[n]-B[i]);
			ans+=B[i-1]*(R[n]-R[i]);
			for(int steps=1;i-steps>=1&&i+steps<=n;steps++){
				if(s[i-steps]=='R'&&s[i+steps]=='B') --ans;
				if(s[i-steps]=='B'&&s[i+steps]=='R') --ans;
			}
		}
		if(s[i]=='B'){
			ans+=G[i-1]*(R[n]-R[i]);
			ans+=R[i-1]*(G[n]-G[i]);
			for(int steps=1;i-steps>=1&&i+steps<=n;steps++){
				if(s[i-steps]=='G'&&s[i+steps]=='R') --ans;
				if(s[i-steps]=='R'&&s[i+steps]=='G') --ans;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3788
/* 
    author said_v15
  *
   created with web_programmer
  
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string stri;
#define forn for(i=0;i<n;i++)
#define car cin>>arr[i]
#define fl int flag=0; 
#define forn2 for(i=0;i<2*n;i++)
#define pb push_back   
#define pob pop_back  
#define sn "\n"
#define vi vector<int> 
int main()
{  
   ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  int a;
  cin>>a;
  int cel=a/100;
  int drob=a%100;
  if(1<=cel && cel<=12)
  {
      if(1<=drob && drob<=12) cout<<"AMBIGUOUS";
      else cout<<"MMYY";
  }
  else 
  {
      if(drob>=1 && drob<=12) cout<<"YYMM";
      else cout<<"NA";
  }
  return 0;
    
}

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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

P get_start(vector<vector<char>> &board, int h, int w) {
    rep(y, h) rep(x, w) {
            if (board[y][x] == 'S') return P(y, x);
        }
    __throw_runtime_error("");
}

ll check(ll y, ll x, ll h, ll w, ll k) {
    ll l = (x + k - 1) / k;
    ll u = (y + k - 1) / k;
    ll r = (w - x - 1 + k - 1) / k;
    ll d = (h - y - 1 + k - 1) / k;

    return min({l, u, r, d});

}

int main() {
    ll h, w, k;
    cin >> h >> w >> k;


    vector<vector<char>> board(h, vector<char>(w, ' '));
    rep(y, h) rep(x, w) cin >> board[y][x];
    vector<vector<int>> distances(h, vector<int>(w, INT_MAX / 10));

    P s = get_start(board, h, w);

    distances[s.first][s.second] = 0;

    struct Point {
        ll y, x, cost;
    };

    queue<Point> q;
    q.push({s.first, s.second, 0});

    auto to_id = [&](int y, int x) {
        return y * w + x;
    };

    struct Direction {
        int x, y;
    };

    vector<Direction> directions = {
            {0,  1},
            {1,  0},
            {0,  -1},
            {-1, 0},
    };


    auto reachable = [&](int y, int x, int distance) {
        if (x == -1 || x == w || y == -1 || y == h) return false;
        if (board[y][x] == '#') {
            return false;
        }
        if (distances[y][x] <= distance) {
            return false;
        }
        return true;
    };


    while (!q.empty()) {
        Point p = q.front();
        q.pop();
        for (Direction d : directions) {
            int nx = p.x + d.x;
            int ny = p.y + d.y;
            int nd = p.cost + 1;
            if (reachable(ny, nx, nd)) {
                distances[ny][nx] = nd;
                q.push({ny, nx, nd});
            }
        }
    }

    ll ans = INF;
    rep(y, h) rep(x, w) {
            if (distances[y][x] > k) continue;
            ll now = check(y, x, h, w, k) + 1;
            cmin(ans, now);
        }
    cout << ans << endl;

}


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

int main() {
	
	int n, lim = 0,a;
	long long  ans = 0;
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++) {
		scanf("%d", &a);
		if(a < lim) {
			ans += lim - a;
		}
		else 
			lim = a;
	}
	
	printf("%lld", ans);
	
	return 0;
}

Measured memory_bytes: 3776
#include<cstdio>
const int N=1e5+10;
int n,a[N],sum,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=2;i<=n;i++)
		if(a[i]<=a[i-1])sum++;
		else
		{
			if(ans<sum)ans=sum;
			sum=0;
		}
	if(ans<sum)ans=sum;
	printf("%d",ans);
	return 0;
}

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

Measured memory_bytes: 1128