akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int H = 30;
string s[H];
int h, w, k;

const int DEBUG = 0;

ll calc(int DEBUG) {
  string t[H];
  REP(i, 0, h) {
    t[i] = s[i];
  }
  ll sum = 0;
  int turn = 0;
  while (1) {
    // fall
    bool fell = 0;
    REP(i, 0, w) {
      int pos = h - 1;
      for (int j = h - 1; j >= 0; --j) {
	if (t[j][i] != '.') {
	  if (pos != j) {
	    swap(t[pos][i], t[j][i]);
	    fell = 1;
	  }
	  pos--;
	}
      }
    }
    if (DEBUG) {
      cout << "turn " << turn << endl;
      REP(i, 0, h) {
	cout << t[i] << endl;
      }
    }
    if (not fell) {
      break;
    }
    // perish
    REP(i, 0, h) {
      int cnt = 0;
      REP(j, 0, w + 1) {
	if ((j > 0 && j < w && t[i][j] == t[i][j - 1])) {
	  cnt++;
	} else {
	  if (cnt >= k) {
	    //perish
	    ll sc = t[i][j - 1] - '0';
	    if (t[i][j - 1] == '.') {
	      sc = 0;
	    }
	    sc = sc << turn;
	    sum += sc * cnt;
	    REP(l, 0, cnt) {
	      t[i][j - cnt + l] = '.';
	    }
	  }
	  cnt = 0;
	  if (j < w) {
	    cnt++;
	  }
	}
      }
    }
    turn++;
  }
  return sum;
}

int main(void){
  cin >> h >> w >> k;
  REP(i, 0, h) {
    cin >> s[i];
  }

  ll ma = 0;
  REP(i, 0, h) {
    REP(j, 0, w) {
      char tmp = s[i][j];
      s[i][j] = '.';
      ma = max(ma, calc(i == 3 && j == 2 && DEBUG));
      s[i][j] = tmp;
    }
  }
  cout << ma << endl;
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;
struct UnionFind {
  vector<ll> par, sizes;
  ll cnt;
  UnionFind(ll N) : par(N), sizes(N, 1), cnt(N) {
    for (ll i = 0; i < N; i++) par[i] = i;
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

  bool same(ll x, ll y) { return find(x) == find(y); }

  ll size(ll x) { return sizes[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
    cnt--;
  }

  ll count() const { return cnt; }
};
int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, t;
  cin >> n >> t;

  vll as(n), bs(n);
  rep(i, n) cin >> as[i] >> bs[i];

  vvll dp1(n + 1, vll(t, 0));
  vvll dp2(n + 2, vll(t, 0));

  rep(i, n) {
    rep(j, t - 1) {
      dp1.at(i + 1).at(j + 1) = dp1.at(i + 1).at(j);
      chmax(dp1.at(i + 1).at(j + 1), dp1.at(i).at(j + 1));
      if (j + 1 - as[i] >= 0)
        chmax(dp1.at(i + 1).at(j + 1), bs[i] + dp1.at(i).at(j + 1 - as[i]));
    }
  }

  rep(i, n) {
    rep(j, t - 1) {
      dp2.at(i + 1).at(j + 1) = dp2.at(i + 1).at(j);
      chmax(dp2.at(i + 1).at(j + 1), dp2.at(i).at(j + 1));
      if (j + 1 - as[n - 1 - i] >= 0)
        chmax(dp2.at(i + 1).at(j + 1),
              bs[n - 1 - i] + dp2.at(i).at(j + 1 - as[n - 1 - i]));
    }
  }

  ll juee = 0;
  rep(i, n) {
    rep(j, t){
      ll tmp = dp1[i][j] + bs[i] + dp2[n - 1 - i][t - 1 - j];
      chmax(juee, tmp);
    }
  }

  cout << juee << endl;

  return 0;
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;
vll ans;

bool isP(lli x){
  for(lli i = 2;i*i <= x;i++){
    if(x%i == 0) return false;
  }
  return true;
}

bool check(){
  for(lli i = 0;i < ans.size();i++){
    for(lli j = i+1;j < ans.size();j++){
      for(lli k = j+1;k < ans.size();k++){
        for(lli l = k+1;l < ans.size();l++){
          for(lli m = l+1;m < ans.size();m++){
            if(isP(ans[i]+ans[j]+ans[k]+ans[l]+ans[m])) return false;
          }
        }
      }
    }
  }
  return true;
}

int main(){
  cin >> n;
  for(lli i = 2;i <= 55555;i+=5){
    if(isP(i)){
      ans.push_back(i);
    }
    // if(check() == false) ans.pop_back();
    if(ans.size() == n) break;
  }
  // cout << check() << endl;
  for(lli i = 0;i < n-1;i++){
    cout << ans[i] << " ";
  }
  cout << ans[n-1] << endl;

}


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

using namespace std;

int main(void){

    int n, a, b;
    cin >> n >> a >> b;
    
    if((b-a)%2!=0) {
        cout << "Borys" << endl;
    }
    else {
        cout << "Alice" << endl;
    }

    return 0;
    
}


Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 2e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll& a , ll b){a =  (a + b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll h , w  ;cin>>h>>w;  
vector<vector<ll>>v(h,vector<ll>(w));
for(ll i = 0 ; i<h ; i++){
	for(ll j = 0 ; j<w ; j++){
		char ch; cin>>ch ;
		if(ch=='#')v[i][j] = 1;
	}
}

vector<vector<ll>>dp(h,vector<ll>(w));

for(ll i = 0 ;i<w ; i++){
	if(v[0][i]==1)break;
	dp[0][i] = 1 ; 
}	
for(ll i = 0 ; i<h ; i++){
	if(v[i][0]==1)break;
	dp[i][0] = 1; 
}

for(ll i = 1 ; i< h ; i++){
	for(ll j =1 ; j<w ; j++){
		if(v[i][j]==1){
			continue;
		}
		add_self(dp[i][j],dp[i][j-1]);
		add_self(dp[i][j],dp[i-1][j]);

	}
}

cout<<dp[h-1][w-1];


	
}


Measured memory_bytes: 16000
S = input()

dp = [[0]*(len(S)+1) for i in range(4)]
dp[0][0] = 1

for i in range(4):
    for j in range(1, len(S)+1):
        if S[j-1] == '?':
            dp[i][j] = 3 * dp[i][j-1]
        else:
            dp[i][j] = dp[i][j-1]
        if i > 0:
            if S[j-1] == '?' or 'ABC'.find(S[j-1]) == i-1:
                dp[i][j] += dp[i-1][j-1]
        dp[i][j] %= 10**9+7

print(dp[3][len(S)])

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

int main(){
int n;
cin >> n;
set<int> d;
int x;

for (int i = 0; i < n; i++)
{
  cin >> x;
  d.insert(x);
}



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

Measured memory_bytes: 256
#include <cstdio>

int n,P,Q,R,C;
int t[1000],p[1000],q[1000],r[1000];

int main(){
	int n;
	while(scanf("%d", &n),n){
		for(int i = 0; i < n; i++) scanf("%d%d%d%d",&t[i],&p[i],&q[i],&r[i]);
		scanf("%d%d%d%d", &P, &Q, &R, &C);
		bool ok = true;
		for(int i = 0; i < n; i++){
			if(p[i]<=P&&q[i]<=Q&&r[i]<=R&&(p[i]+r[i])*4+q[i]*9<=C){
				printf("%d\n", t[i]);
				ok = false;
			}
		}
		if(ok) printf("NA\n");
	}
}

Measured memory_bytes: 1056
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	string s;cin>>s;
	int ans=0;
	while(-1){
		string t;cin>>t;if(t=="END_OF_TEXT"){break;}
		for(auto &c:t){if('A'<=c&&c<='Z'){c-=(int)'A'-(int)'a';}}
		
		if(s==t){ans++;}
	}
	cout<<ans<<endl;
	RE;
}


Measured memory_bytes: 3228
import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
ab = []
for i in range(N):
	ab.append(list(map(int, input().split())))
cd = []
for i in range(N):
	cd.append(list(map(int, input().split())))

ab.sort()
cd.sort()
num = 0
for i in range(N):
	blue = cd[i]
	red_y_max = -1
	index = -1
	for j in range(N):
		if ab[j][0] > blue[0]:
			break
		if ab[j][1] > red_y_max and ab[j][1] < blue[1]:
			red_y_max = ab[j][1]
			index = j
	if index != -1:
		ab[index][1] = 100000000000
		num += 1
print(num)

Measured memory_bytes: 38768
import math

def main():
    A, B, H, M = map(int, input().split())

    sita = M*6
    fai = 0.5*(60*H + M)

    arufa = abs(sita - fai)
    if arufa > 180:
        arufa = 360 - arufa

    #print(sita,fai,arufa)
    arufa = math.radians(arufa)
    #print(arufa)
    #print(math.cos(arufa))
    #print(float(A**2 + B**2))

    ans = float(A**2 + B**2) - 2*A*B*(math.cos(arufa))
    #print(ans)
    ans = math.sqrt(ans)

    return ans

print(main())


Measured memory_bytes: 9508
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    ll n, k;
    cin >> n >> k;
    vint a(n);
    rep(i, n)
    {
        cin >> a[i];
        a[i]--;
    }
    vll vis(n, 0);
    ll i = 0;
    while (true)
    {
        if (vis[i] >= 2)
        {
            break;
        }
        vis[i]++;
        i = a[i];
    }

    ll loop = 0, pre = 0;
    rep(i, n)
    {
        pre += vis[i] == 1;
        loop += vis[i] == 2;
    }
    if (k >= pre)
    {
        k -= pre;
        k %= loop;
    }
    else
    {
        int now = 0;
        rep(i, k)
        {
            now = a[now];
        }
        cout << now + 1 << endl;
        return 0;
    }

    vis = vll(n, -pre - 5);
    i = 0;
    ll c = 0;
    while (true)
    {
        if (vis[i] >= 0)
            break;
        vis[i] = c - pre;
        i = a[i];
        c++;
    }
    rep(i, n)
    {
        if (vis[i] == k)
        {
            cout << i + 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 7220
import java.util.*;

public class Main {
	private int[] afin = new int[26];
	private String[] alpha = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", 
			"r", "s", "t", "u", "v", "w", "x", "y", "z"};

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.nextLine());
		while (n-- > 0) {
			String str = scan.nextLine();
			for (int a = 0; a < 26; a++) {
				boolean find = false;
				for (int b = 0; b < 26; b++) {
					boolean[] confirm = new boolean[26];
					Arrays.fill(confirm, false);
					boolean flag = true;
					for (int i = 0; i < 26; i++) {
						if (!confirm[(a * i + b) % 26]) confirm[(a * i + b) % 26] = true;
						else {flag = false; break;}
					}
					if (flag) {
						for (int i = 0; i < 26; i++) {
							afin[i] = (a * i + b) % 26;
						}
						//System.out.println("a:"+ a + " b:" + b + Arrays.toString(afin));
						StringBuffer str2 = new StringBuffer();
						for (int i = 0; i < str.length(); i++) {
							if (str.substring(i, i + 1).equals(" ")) {
								str2.append(str.substring(i, i + 1));
							}else {
								int j = 0;
								while (!str.substring(i, i + 1).equals(alpha[j++]));
								str2.append(alpha[afin[j - 1]]);
							}
						}
						//System.out.println(str2);
						
						if (str2.indexOf("this") >= 0 || str2.indexOf("that") >= 0) {
							System.out.println(str2);
							find = true;
							break;
						}
					}
				}
				if (find) break;
			}
		}
	}
	
	private void debug() {
		System.out.println();
	}

}

Measured memory_bytes: 57792
#include<bits/stdc++.h>
using namespace std;
int n,k;
vector<int>g[2222];
int main()
{
	cin>>n>>k;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	vector<vector<int> >mt(n,vector<int>(n,1e9));
	for(int i=0;i<n;i++)
	{
		vector<int>&r=mt[i];
		queue<int>q;
		r[i]=0;
		q.push(i);
		while(!q.empty())
		{
			int u=q.front();
			q.pop();
			for(int j=0;j<g[u].size();j++)
			{
				int v=g[u][j];
				if(r[v]<1e9)
				{
					continue;
				}
				r[v]=r[u]+1;
				q.push(v);
			}
		}
	}
	int ans=1e9;
	if(k%2)
	{
		for(int u=0;u<n;u++)
		{
			for(int j=0;j<g[u].size();j++)
			{
				int v=g[u][j],cnt=0;
				for(int i=0;i<n;i++)
				{
					if(mt[u][i]+mt[v][i]<=k)
					{
						cnt++;
					}
				}
				ans=min(ans,n-cnt);
			}
		}
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			int cnt=0;
			for(int j=0;j<n;j++)
			{
				if(mt[i][j]<=k/2)
				{
					cnt++;
				}
			}
			ans=min(ans,n-cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int s;
  cin >> s;
  vector<int> a = {s};
  int n = s;
      int i;
  while(1){
    if(n %2 == 0){
      n = n/2;
    }else{
      n = 3 * n + 1;
    }

    for(i = 0;i < a.size();i++){
      if(a[i] == n){
        cout << a.size() + 1 << endl;
        return 0;
      }
    }
    a.push_back(n);
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>

using namespace std;

//const int inf=numeric_limits<int>::infinity();

int n,a[150],ss;
float hk,rs=1000.0;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        hk+=float(a[i]);
    }
    hk/=n;
    for(int i=0;i<n;i++){
        if( abs(float(a[i])-hk) <rs){
            rs=abs(float(a[i])-hk);
            ss=i;
        }
    }
    printf("%d\n",ss);
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

int main()
{
    int t;
    for (scanf("%d", &t); t--;)
    {
        int n;
        scanf("%d", &n);
        struct camel { int k, l, r; camel(const int& k, const int& l, const int& r) :k(k), l(l), r(r) {} };
        std::vector<camel> a, b;
        for (int i = 0; i < n; i++)
        {
            int k, l, r;
            scanf("%d %d %d", &k, &l, &r);
            auto& v = l >= r ? a : b;
            v.emplace_back(k, l, r);
        }
        std::sort(a.begin(), a.end(), [](const camel& l, const camel& r) { return l.k > r.k; });
        std::sort(b.begin(), b.end(), [](const camel& l, const camel& r) { return l.k < r.k; });
        long long h = 0;
        for (auto& i : a) h += i.r;
        for (auto& i : b) h += i.l;
        {
            std::priority_queue<int> q;
            for (int i = (int)a.size(), j = 0; i >= 1; i--)
            {
                while (j < (int)a.size() && a[j].k >= i)
                {
                    q.emplace(a[j].l - a[j].r);
                    j++;
                }
                if (!q.empty())
                {
                    h += q.top();
                    q.pop();
                }
            }
        }
        {
            std::priority_queue<int> q;
            for (int i = (int)a.size() + 1, j = 0; i <= n; i++)
            {
                while (j < (int)b.size() && b[j].k < i)
                {
                    q.emplace(b[j].r - b[j].l);
                    j++;
                }
                if (!q.empty())
                {
                    h += q.top();
                    q.pop();
                }
            }
        }
        printf("%lld\n", h);
    }
    return 0;
}

Measured memory_bytes: 6624
import sys
import copy
sys.setrecursionlimit(10**9)
N,M,Q = list(map(int,input().split()))
A = []
for n in range(Q):
    a,b,c,d = map(int,input().split())
    A.append((a-1,b-1,c,d))

def dfs(arr, cur):
    if cur == N-1:
        score = 0
        for aa in A:
            a,b,c,d = aa 
            if arr[b]-arr[a] == c:
                score+=d
        return score
    else:
        mx = 0
        for s in range(arr[cur], M+1):
            arr = copy.copy(arr)
            # それ以降を1ふやす．
            for i in range(cur+1, N):
                arr[i] = s
            mx = max(mx, dfs(arr, cur+1))
        return mx


t = dfs([1 for i in range(N)], 0)
print(t)


Measured memory_bytes: 69504
import sys
input=sys.stdin.readline
from collections import Counter
n,m=map(int,input().split())
A,B=[],[]
for _ in range(n):
    A.append(tuple(map(lambda x:int(x)-1,input().split())))
    B.append(A[-1][0])
delete=[False]*m
ans=n
idx=[0]*n
for _ in range(m-1):
    c=Counter(B)
    sport,num=c.most_common()[0]
    ans=min(ans,num)
    delete[sport]=True
    for i in range(n):
        while delete[A[i][idx[i]]]:
            idx[i]+=1
        B[i]=A[i][idx[i]]
print(ans)

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

public class Main {

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

        String arg = br.readLine();
        String[] inputArray = arg.split(" ");
        int[] inputIntArray = new int[inputArray.length];

        for (int count = 0; count < inputIntArray.length; count++) {
            inputIntArray[count] = Integer.parseInt(inputArray[count]);
        }
        int x = inputIntArray[0];
        int y = inputIntArray[1];
        String retStr;

        if (x < y) {
            retStr = "a < b";
        } else if (x == y) {
            retStr = "a == b";

        } else {
            retStr = "a > b";
        }

        System.out.println(retStr);
    }
}

Measured memory_bytes: 16896
#include<bits/stdc++.h>
using namespace std;
int a[4]={1,0,-1,0};
int b[4]={0,1,0,-1};
struct p
{
    int x,y,time;
};
char c[55][55];
int v[55][55],d[55][55];
int main()
{
    int h,w;
    queue<p>q;
    scanf("%d%d",&h,&w);
    int sum=h*w;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin>>c[i][j];
            if(c[i][j]=='#')sum--;
        }
    }
    q.push({1,1,1});
    while(!q.empty())
    {
        p k=q.front();
        q.pop();
        if(v[k.x][k.y])continue;
        v[k.x][k.y]=1;
        d[k.x][k.y]=k.time;
        for(int i=0;i<4;i++)
        {
            if(c[k.x+a[i]][k.y+b[i]]=='.')
            {
                q.push({k.x+a[i],k.y+b[i],k.time+1});
            }
        }
    }
    if(d[h][w])printf("%d\n",sum-d[h][w]);
    else printf("-1\n");
}


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

typedef    long long          ll;
typedef    vector<long long>    vi; 
typedef    vector<vi>         vvi; 
typedef    pair<long,long>      ii; 
#define    sz(a)              long((a).size()) 
#define    pb                 push_back 
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end() 
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define    present(c,x)       ((c).find(x) != (c).end()) 
#define    cpresent(c,x)      (find(all(c),x) != (c).end())  
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "


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

  ll n,i,j;
  cin>>n;
  ll a[n+1][4];
  for(i=0;i<n;i++)
  {
    for(j=0;j<3;j++)
        cin>>a[i][j];
  }

  for(j=1;j<n;j++)
  {
    a[j][0]+=max(a[j-1][1],a[j-1][2]);
        a[j][1]+=max(a[j-1][0],a[j-1][2]);

    a[j][2]+=max(a[j-1][1],a[j-1][0]);


  }

  cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]));


  return 0;
 }

Measured memory_bytes: 3328
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = str(input())
ans = "yes"
count = 0
for i in range(len(N)):
    count += int(N[i])

if(count%9==0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 70404
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void) {
    int D, S, T;
    cin >> D >> S >> T;
    if(T*S >= D) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int count = 0;
    int running_max = 0;
    for (int i = 0; i < n; ++i) {
        int h;
        cin >> h;
        if (running_max <= h) {
            ++count;
        }
        running_max = max(running_max, h);
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()





int main() {
	ll N;
	cin >> N;
	vector<string> W(N);
	rep(i, N) cin >> W[i];

	rep(i, N) {
		if (1 < count(all(W), W[i])) {
			cout << "No" << endl;
			return 0;
		}
	}
	fori(i, 1, N) {
		if (W[i - 1].back() != W[i][0]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

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


int main(){
    int a,b;
    cin >> a >> b;
    if(a>=13) cout << b << endl;
    else if(a<=5) cout << 0 << endl;
    else cout << b/2 << endl;
    return 0;
}


Measured memory_bytes: 3560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> l(m), r(m);
	rep(i, m) cin >> l[i] >> r[i];
	sort(l.begin(), l.end());
	sort(r.begin(), r.end());
	if (l[m - 1] <= r[0]) cout << r[0]-l[m-1] + 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main () {

	int N;
	
	scanf("%d", &N);
	
	int A[N];
	for(int Ai = 0; Ai < N; Ai++) {
		scanf("%d", &A[Ai]);
	}
	
	long long  total_hight = 0;
	int max = A[0];
	for(int Ai = 1; Ai < N; Ai++) {
            
		if(max > A[Ai]) {
           //printf("max %d - A[i] %d total_hight= %d\n", max, A[Ai], max - A[Ai]);
			total_hight += max - A[Ai];
		} else {
	      	max = A[Ai];
        }  
	}
	
	printf("%lld", total_hight);
	return 0;
}


Measured memory_bytes: 2456
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

class UnionFind {
  public:
    vi Parent;
    UnionFind(int N) {
      Parent = vi(N,-1);
    }
  
    int root(int A) {
      if(Parent[A] < 0) return A;
      return Parent[A] = root(Parent[A]);
    }
  
    int size(int A) {
      return -Parent[root(A)];
    }
  
    bool connect(int A,int B) {
      A = root(A);
      B = root(B);
      if(A == B) return false;
      if(size(A) < size(B)) swap(A,B);
      Parent[A] += Parent[B];
      Parent[B] = A;
      return true;
    }
};
  
int main() {
  int N,M;
  cin >> N >> M;
  vi p(N);
  rep(i,N) {
    cin >> p[i];
    p[i]--;
  }
  UnionFind tree = UnionFind(N);
  rep(i,M){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    tree.connect(x,y);
  }
  int ans = 0;
  rep(i,N) {
    if(tree.root(i) == tree.root(p[i])) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

size_t N;
vector<int> A;
unsigned CNT = 0;

void read() {
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
}

void merge(vector<int> &A, size_t left, size_t mid, size_t right) {
  size_t n1 = mid - left;
  size_t n2 = right - mid;
  vector<int> L(n1 + 1);
  vector<int> R(n2 + 1);
  L.at(n1) = 1'000'000'000 + 1;
  R.at(n2) = 1'000'000'000 + 1;
  for (size_t i = 0; i < n1; i++) L.at(i) = A.at(left + i);
  for (size_t i = 0; i < n2; i++) R.at(i) = A.at(mid + i);
  size_t i = 0;
  size_t j = 0;
  for (size_t k = left; k < right; k++) {
    CNT++;
    if (L.at(i) <= R.at(j))
      A.at(k) = L.at(i++);
    else
      A.at(k) = R.at(j++);
  }
}

void merge_sort(vector<int> &A, size_t left, size_t right) {
  if (left + 1 < right) {
    size_t mid = (left + right) / 2;
    merge_sort(A, left, mid);
    merge_sort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  read();
  merge_sort(A, 0, N);
  cout << A.at(0);
  for (size_t i = 1; i < N; i++) cout << " "s << A.at(i);
  cout << endl;
  cout << CNT << endl;
}



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

using ll = long long;

int main(){
 int n;
 float m;
 vector<int> arr;
 cin>>n>>m;
 int total = 0;
 for(int i=0;i<n;i++){
   int temp;
   cin>>temp;
   total+=temp;
   arr.push_back(temp);
 }
 sort(arr.begin(),arr.end());
 float com = (1/(4*m))*total;
 int output = 0;
 for(int i=0;i<n;i++){
   if((float)arr[i]>=com){
     output++;
     if(output==m){
       break;
     }
   }
 }
 if(output==m){
    cout<<"Yes"<<endl;
 }
 else{
   cout<<"No"<<endl;
 }
 

}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextInt();
  vector<int> A(N);
  REP(i, N) A[i] = nextInt();
  map<int,int> count;
  REP(i, N) count[i - A[i]]++;
  ll ans = 0;
  REP(i, N) {
    count[i - A[i]]--;
    ans += count[A[i] + i];
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

#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++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long B){
    if(B % A == 0){
        cout << (B+A) <<endl;
    }else{
        cout << (B-A) << endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
S = list(input())
S.pop()

l = 0
r = 0
ans = [0 for _ in range(len(S))]
for i, s in enumerate(S):
    #print(i, ans)
    if s == 'R':
        if i % 2 == 0:
            l += 1
        else:
            r += 1
    else:
        if S[i-1] == 'R':
            k = i
            if i % 2 == 0:
                ans[i-1] += r
                ans[i] += l+1
            else:
                ans[i-1] += l
                ans[i] += r+1
            l = 0
            r = 0
        else:
            if (i-k)%2 == 0:
                ans[k] += 1
            else:
                ans[k-1] += 1
print(' '.join([str(a) for a in ans]))

Measured memory_bytes: 11176
import numpy as np
from copy import deepcopy
temp=list(map(int, input().split()))
R=temp[0]
C=temp[1]

color=np.zeros((R,C)).astype(int)

for i in range(R):
  temp=input()
  a=np.zeros(C).astype(int)
  for j in range(C):
      if temp[j]=='#':
        a[j]=1
      else:
        a[j]=0
  color[i]=a
  
def Adj(u):
  adj=[]
  for v in [(u[0]-1,u[1]),(u[0]+1,u[1]),(u[0],u[1]-1),(u[0],u[1]+1)]:
      if v[0]>=0 and v[0]<R and v[1]>=0 and v[1]<C:
        adj.append(v)
  return adj  

def BFS(s,c,d):
  Q=[s]
  while Q !=[]:
    u=Q[0]
    del Q[0]
    for v in Adj(u):  
      if c[v[0],v[1]]==0:
        c[v[0],v[1]]=1
        d[v[0],v[1]]=d[u[0],u[1]]+1
        Q.append(v)
        
def main():
  ma=0
  for sx in range(R):
    for sy in range(C):
      if color[sx,sy]==0:
        d=np.zeros((R,C)).astype(int)
        c=deepcopy(color)
        c[sx,sy]=1
        BFS((sx,sy),c,d)
        ma=max(np.max(d),ma)
  print(ma)

main()


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

int main() {
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;

    string strnum = "0123456789";
    string stralph = "abcdefghijklmnopqrstuvwxyz";
    string strAlph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for (int i=0; i<A+B+1; i++){
        if (i == A){
            if (S[i] == '-'){
                continue;
            } else {
                cout << "No" << endl;
                return 0;
            }
        } else if (i != A) {
            if ( (int)strnum[0] <= (int)S[i] && (int)S[i] <= (int)strnum[9]) {
                continue;
            } else {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import permutations
from math import factorial
from math import sqrt

n = int(input())

nf = factorial(n)

xy = []
X = 0
Y = 1

l = [i for i in range(n)]
s = 0

for i in range(n):
    x, y = map(int, input().split())
    xy.append([x, y])


for p in permutations(l, n):
    p = list(p)
    for i in range(len(p) - 1):
        s += ((xy[p[i]][X] - xy[p[i+1]][X])**2 + (xy[p[i]][Y] - xy[p[i+1]][Y])**2)**0.5

print(s/nf)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int h, w, k;
    cin >> h >> w >> k;
    char g[h][w];
    rep(i, h) rep(j, w) cin >> g[i][j];
    int ans[h][w];
    rep(i, h) rep(j, w) ans[i][j] = -1;
    int cake = -1;

    rep(i, h)
    {
        bool first = true;
        rep(j, w)
        {
            if (g[i][j] == '#')
            {
                cake++;
                if (first)
                {
                    first = false;
                    for (int k = j; k >= 0; k--)
                    {
                        ans[i][k] = cake;
                    }
                }
                ans[i][j] = cake;
            }
            else
            {
                if (first == false)
                    ans[i][j] = cake;
            }
        }
    }
    rep(i, h)
    {
        rep(j, w)
        {
            if (ans[i][j] != -1)
            {
                continue;
            }
            int k = i;
            while (k >= 0)
            {
                if (ans[k][j] != -1)
                {
                    ans[i][j] = ans[k][j];
                    break;
                }
                k--;
            }
            k = i;
            if (ans[i][j] == -1)
            {
                while (k < h)
                {
                    if (ans[k][j] != -1)
                    {
                        ans[i][j] = ans[k][j];
                        break;
                    }
                    k++;
                }
            }
            assert(ans[i][j] != -1);
        }
    }
    rep(i, h)
    {
        rep(j, w)
        {
            cout << ans[i][j] + 1 << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1152
import java.io.*;
public class Main {
 public static void main(String[] args){
  try{
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   char botton[][]={{' '},
                            {'\'' , ',' , '.' , '!' , '?'},
                            {'a' , 'b' , 'c' , 'A' , 'B' , 'C'},
                            {'d' , 'e' , 'f' , 'D' , 'E' , 'F'},
                            {'g' , 'h' , 'i' , 'G' , 'H' , 'I'},
                            {'j' , 'k' , 'l' , 'J' , 'K' , 'L'},
                            {'m' , 'n' , 'o' , 'M' , 'N' , 'O'},
                            {'p' , 'q' , 'r', 's' , 'P' , 'Q' , 'R' , 'S'},
                            {'t' , 'u' , 'v' , 'T' , 'U' , 'V'},
                            {'w' , 'x' , 'y' , 'z' , 'W' , 'X' , 'Y' , 'Z'}};
    int n[]={0,5,6,6,6,6,6,8,6,8};
    while(true){
     String s=br.readLine();
     s+="x";
     int sl=s.length();
     int cnt=1;
     
     for(int i=1;i<sl;i++){
      char x,ch;
      int num,l;
      if(s.charAt(i-1)!=s.charAt(i)){
       x=s.charAt(i-1);
       if(x!='0'){
        num=x-'0';
        ch=botton[num][(cnt-1)%n[num]];
        System.out.print(ch);
       }
       else if(x=='0')for(int j=0;j<cnt-1;j++)System.out.print(" ");
       cnt=0;
       cnt++;
      }
      else cnt++;
     }
     System.out.print("\n");
   }
  }
  catch(Exception e){return ;}
 }
}



Measured memory_bytes: 24512
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n;
    cin >> n;
    int ans = 0;
    int a[n];
    rep(i, n) {
        cin >> a[i];
        if((i + 1) % 2 == 1 && a[i] % 2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> sum(n+1);
    vector<ll> posi(n+1);
    posi[0] = 0;
    sum[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        sum[i] = sum[i-1] + a[i-1];
        posi[i] = posi[i-1];
        if(a[i-1] > 0) posi[i] += a[i-1];
    }

    ll ans = 0;
    for(int i = 1; i <= n-k+1; i++)
    {
        ll tmp = posi[i-1] + posi[n] - posi[i+k-1];
        if(sum[i+k-1] - sum[i-1] > 0) tmp += sum[i+k-1] - sum[i-1];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
package main

import (
	"fmt"
	"math"
)

const v = 1000000007

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	if abs(n - m) > 1 {
		fmt.Println(0)
	} else {
		a := factorial(n)
		b := factorial(m)
		ab := a * b % v
		if m == n {
			ab = ab * 2 % v
		}
		fmt.Println(ab)
	}
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func factorial(x int) int {
	res := 1
	for i := x; i >= 1; i-- {
		res *= i
		res %= v
	}
	return res
}

Measured memory_bytes: 512
# n: スイッチの数
# m: ランプの数
n, m = gets.split.map(&:to_i)

# key: ランプ 
# value: スイッチのリスト
d = []
m.times do |i| 
  k, *s = gets.split.map{|s| s.to_i - 1 }
  d[i] = s
end

mods = gets.split.map(&:to_i)

ans = 0
(0..n).each do |k|
  [*0...n].combination(k) do |turn_on|
    ans += 1 if (0...m).all?{|i| (d[i] & turn_on).size % 2 == mods[i]}
  end
end

puts ans


Measured memory_bytes: 2044
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
#print(S)
Syoko=[[0 for _ in range(W)] for _ in range(H)]
State=[[0 for _ in range(W)] for _ in range(H)]
#まず横から連続する壁のない領域をcountし、Syokoにいれる
for i in range(H):
    cnt=0
    id=0
    buf=[]
    for j in range(W):
        if S[i][j]=="#":
            buf.append(j)
    buf.append(W+1)
    for j in range(W):
        if buf[id]!=j:
            if id==0:
                Syoko[i][j]=min(buf[0],W)
            elif id==len(buf)-1:
                Syoko[i][j]=(W-1)-buf[id-1]
            else:
                Syoko[i][j]=buf[id]-(buf[id-1]+1)
        else:
            id=id+1
#print(Syoko)
for j in range(W):
    cnt=0
    id=0
    buf=[]
    for i in range(H):
        if S[i][j]=="#":
            buf.append(i)
    buf.append(H+1)
    for i in range(H):
        if buf[id]!=i:
            if id==0:
                State[i][j]=min(buf[0],H)
            elif id==len(buf)-1:
                State[i][j]=(H-1)-buf[id-1]
            else:
                State[i][j]=buf[id]-(buf[id-1]+1)
        else:
            id=id+1
#print(State)
ma=0
for i in range(H):
    for j in range(W):
        ma=max(ma,State[i][j]+Syoko[i][j]-1)
print(ma)


Measured memory_bytes: 251400
def xgcd(a, b)
  b > 0 ? q=v=w=x = 1 : a=x = 0
  y = 0
  while b > 0
    v -= q*x; w -= q*y
    q,b = a.divmod a=b
    v,w,x,y = x,y,v,w
  end
  [a,x,y]
end
N,A,B = gets.split.map &:to_i
n,s,P = 1,2,10**9+7
30.times {|i| n*=s and n%=P if N[i]>0; s*=s; s%=P}
a,b = [A,B].map{|r| N < r+r ? N-r : r}.sort
s=t=u = 1
F =->(x,y){ x.upto(y){|i| t*=N+1-i; u*=i; t%=P; u%=P}; s += t*xgcd(u,P)[1]%P }
F[1,a]; F[a+1,b]
p (n<s ? P+n-s : n-s) % P

Measured memory_bytes: 1788
x1, y1, x2, y2 = map(int, input().split())

vec = (x2-x1, y2-y1)

vec = (-vec[1], vec[0])

x3 = x2 + vec[0]
y3 = y2 + vec[1]

vec = (-vec[1], vec[0])

x4 = x3 + vec[0]
y4 = y3 + vec[1]

print(x3, y3, x4, y4)

Measured memory_bytes: 38384
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, M, A[1 << 18], B[1 << 18];
int cnt = 0;
bool used[1 << 18];
vector<int> X[1 << 18];

void dfs(int pos) {
	if (used[pos] == true) return;
	used[pos] = true;
	cnt++;
	for (int i : X[pos]) {
		if (used[i] == true) continue;
		dfs(i);
	}
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}

	int Answer = 0;
	for (int i = 1; i <= N; i++) {
		if (used[i] == true) continue;
		cnt = 0;
		dfs(i);
		Answer = max(Answer, cnt);
	}
	cout << Answer << endl;
	return 0;
}

Measured memory_bytes: 23952
import java.util.Scanner;

public class Main{
    public static void main(String[] ar){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        sc.close();
        if(a<b)
           System.out.println("a < b");
        else if(a>b)
           System.out.println("a > b");
        else
           System.out.println("a == b");
    }
}


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

using namespace std;

#define ll long long
#define pii pair<int, int>

#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char dir[] = {'R', 'L', 'D', 'U'};
const int MOD = 1e9 + 7;

void solve()
{   
    int n; cin >> n;
    vector<int> a, b, c;
    for(int i = 0; i < n; i++)
    {
        int x, y, z; cin >> x >> y >> z;
        a.pb(x);
        b.pb(y);
        c.pb(z);
    }

    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
}

int main()
{
    fastio

    //ifstream fin(".in");
    //ofstream fout(".out");


    int t = 1;
    //cin >> t;

    while(t-- > 0) solve();
}


Measured memory_bytes: 5580
#include<iostream>
#include<sstream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<string>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define mem(a,b) memset(a,b,sizeof(a))
#define random(a,b) (rand()%(b-a+1)+a)
#define ll long long
#define ull unsigned long long
#define e 2.71828182
#define Pi acos(-1.0)
#define ls(rt) (rt<<1)
#define rs(rt) (rt<<1|1)
#define lowbit(x) (x&(-x))
using namespace std;
int read()
{
	int s=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') s=-1;ch=getchar();}
	while(isdigit(ch)) {x=10*x+ch-'0';ch=getchar();}
	return x*s;
}
string str[3]={"Sunny","Cloudy","Rainy"};
int main()
{
	string S;
	cin>>S;
	if(S==str[0]) cout<<str[1];
	else if(S==str[1]) cout<<str[2];
	else cout<<str[0];
}


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

int main()
{
    int n;
    cin >> n;
    int a[100002];
    int les = n;
    int lar = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        les = min(les, a[i]);
        lar = max(lar, a[i]);
    }
    if(lar - les > 1){
        cout << "No" << endl;
        return 0;
    }
    if(lar == les && lar == n - 1){
        cout << "Yes" << endl;
        return 0;
    }
    int col = lar;
    int rest = n;
    if(lar - les == 1){
        for(int i = 0; i < n; i++) 
            if(a[i] == les){
                col--;
                rest--;
            }
    }
    if(col > 0 && rest / col >= 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int a,b;
    int n,temp;
    cin >> n;
    a = n/1.08;
    //printf("%d",a);
    b = (a+1)*1.08;
    //printf("%d",b);
    if(a*1.08==n)
    {
        printf("%d",a);
    }
    else if( b==n)
    {
         printf("%d",a+1);
    }
    else
    {
        printf(":(");
    }
}


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

int main()
{
    int n, x;

    while (1) {
        cin >> n >> x;
        if (!n && !x) break;

        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) cnt++;
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 3044
n = int(input())
ls = list(map(int, input().split()))
ls = sorted(ls)

cnt = 0

for i in range(n):
    li = ls[i]
    for j in range(i+1, n):
        lj = ls[j]
        if li == lj:
            continue
        for k in range(j+1, n):
            lk = ls[k]
            if lj == lk:
                continue
            if li + lj <= lk:
                break
            cnt += 1

print(cnt)

Measured memory_bytes: 9212