akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main()
{
    int n;
    cin >> n;

    vector<vector<int>> A(n, vector<int>(n));

    int u, d, v;
    rep(i, n)
    {
        cin >> u >> d;
        rep(j, d)
        {
            cin >> v;
            A.at(u - 1).at(v - 1) = 1;
        }
    }

    rep(i, n)
    {
        rep(j, n)
        {
            if (j == 0)
            {
                cout << A.at(i).at(j);
            }
            else
                cout << " " << A.at(i).at(j);
        }
        cout << endl;
    }
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,sum=0;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a.at(i);
    sort(a.begin(),a.end());
    for(int i=0;i<k;i++) sum+=a.at(i);
    cout<<sum<<"\n";
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    string s;
    int sum = 0;
    cin >> s;
    if(s.at(0)=='1'){
        sum++;
    }
    if(s.at(1)=='1'){
        sum++;
    }
    if(s.at(2)=='1'){
        sum++;
    }
    cout << sum << endl;
}

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


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

    int h, w, rem;
    cin>>h>>w>>rem;
    int a[h][w];
    vector<pair<int, int>> pos;
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            char c;
            cin>>c;
            if (c=='.') a[i][j] = 0;
            else {
                a[i][j] = -1;
            }
        }
    }
    int cnt = 0;
    for (int i=0; i<(1LL<<h); i++){
        for (int j=0; j<(1LL<<w); j++){
            for (int k=0; k<h; k++){
                if ((1ll<<k)&i){
                    for (int l=0; l<w; l++){
                        if (a[k][l]==-1) a[k][l] = 1;
                    }
                }
            }
            for (int l=0; l<w; l++){
                if ((1ll<<l)&j){
                    for (int k=0; k<h; k++){
                        if (a[k][l]==-1) a[k][l] = 1;
                    }
                }
            }
//            for (int k=0; k<h; k++){
//                for (int l=0; l<w; l++){
//                    cout<<a[k][l]<<" ";
//                }
//                cout<<endl;
//            }
//            cout<<endl;
            int check = 0;
            for (int k=0; k<h; k++){
                for (int l=0; l<w; l++){
                    if (a[k][l]==-1) check++;
                }
            }
            if (rem==check) {
                cnt++;
//                for (int k=0; k<h; k++){
//                    for (int l=0; l<w; l++){
//                        cout<<a[k][l]<<" ";
//                    }
//                    cout<<endl;
//                }
            }
            for (int k=0; k<h; k++){
                for (int l=0; l<w; l++){
                    if (a[k][l]!=0) a[k][l] = -1;
                }
            }
        }
    }

    cout<<cnt<<endl;


    return 0 ;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int n,a,b;
char s[1000005];
int main() {
    scanf("%d %d %d",&n,&a,&b);
    int x=0,y=0;
    scanf("%s",s);
    for (int i=0;i<n;i++) {
        if (s[i]=='a') {
            x++;
            if (x<=a+b) printf("Yes\n");
            else printf("No\n");
        } else if (s[i]=='b') {
            y++, x++;
            if (x<=a+b&&y<=b) printf("Yes\n");
            else {
                x--;
                printf("No\n");
            }
        } else {
            printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 768
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: ∵∴∵
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  string o, e;
  cin >> o >> e;
  int on = o.size(), en = e.size();
  string ans(on + en, ' ');

  for (int i = 0; i < on; i++) ans[2 * i] = o[i];
  for (int i = 0; i < en; i++) ans[2 * i + 1] = e[i];
  cout << ans << endl;
  return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

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

    int n;
    cin >> n;

    long long ret = 0;
    for (int a=1; a<=n; a++)
        ret += (n - 1) / a;
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3668
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    ay = [0]*h
    ax = [0]*w
    for x in s:
        ay[x[0]] += 1
        ax[x[1]] += 1

    my = max(ay)
    mx = max(ax)
    
    by = bx = 0
    for y in ay:
        if y == my:
            by += 1
    for x in ax:
        if x == mx:
            bx += 1
            
    ans = my + mx
    tmp = 0
    for x in s:
        if ay[x[0]]+ax[x[1]]==ans:
            tmp += 1
    if tmp == by*bx:
        ans -= 1
    print(ans)
    
if __name__ == '__main__':
    solve()

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

using namespace std;
int c[1005];
int main()
{
	long long a,b,p=1,j,i;
	cin >> a;
	for(i=2; i<=a; i++)
	{
		b=i;
		for(j=2; j<=b; j++)
		{
			if(b%j==0)
			{
				b=b/j;
				c[j]++;
				j--;
				
			}
		}
	}
	for(i=2; i<=a; i++)
	{
		if(c[i]!=0)
		p=p*(c[i]+1)%1000000007;
	}
	cout <<p;
}


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

using std::pair;
using std::make_pair;
typedef pair<int, int> Pair;

#define update_max(a, b) if ((a) < (b)) (a) = (b)
#define update_min(a, b) if ((a) > (b)) (a) = (b)

void run(int case_id = 0) {
  int n;
  std::cin >> n;
  double answer = 0;
  for (int i = 1; i <= n; ++ i) {
    double x;
    std::cin >> x;
    answer += 1.0 / x;
  }
  std::cout << std::setprecision(9) << std::fixed;
  std::cout << 1.0 / answer << std::endl;
}

void multi_cases_main() {
  int num_tests;
  std::cin >> num_tests;
  for (int t = 1; t <= num_tests; ++ t) {
    run(t);
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  run();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;
long long n,N,x,y,h,xAns,yAns,Cx,Cy,H,X,Y;
long long i,j,k,l;
long long INF = -1;
long long hAns = INF;
long long ans2=0;
bool flag = false;
int main(){
  cin >> N;
  vector <long long> x(N);
  vector <long long> y(N);
  vector <long long> h(N);
  for(i=0;i<N;i++){
    cin >> x.at(i) >> y.at(i) >> h.at(i);
  }
  for(Cy=0;Cy<101;Cy++){
    for(Cx=0;Cx<101;Cx++){
      hAns = -1;
      for(k=0;k<N;k++){
        if(h.at(k) > 0){
          H = h.at(k) + abs(x.at(k)-Cx) + abs(y.at(k)-Cy);
          //cout << abs(x-Cx) << " " << abs(y-Cy) << " " << H << endl;
          if(hAns == -1){
            hAns = H;
          }else {
            if(hAns != H){
              hAns = -2;
              break;
            }
          }
        }
      }
      if(hAns == -2){
        continue;
      }
      for(k=0;k<N;k++){
        if(h.at(k) == 0){
          H = h.at(k) + abs(x.at(k)-Cx) + abs(y.at(k)-Cy);
          if(hAns > H){
            hAns = -2;
            break;
          }
        }
      }
      if(hAns == -2){
        continue;
      }
      cout << Cx << " " << Cy << " " << hAns << endl;
      return 0;
    }
  }
  cout << Cx << " " << Cy << " " << hAns << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#ifdef WIN32
#define ld "%I64d"
#else
#define ld "%lld"
#endif
using namespace std;
int main(){
	int n,k,i,j,l;
	scanf("%d%d",&n,&k);
	if(!k){
		printf(ld,1ll * n * n);
		return 0;
	}
	long long ans = 0;
	for(i = 1;i <= n;++i){
		if(i < k) continue;
		j = n / i  * i;
		l = n - j;
		if(l >= k) ans += l - k + 1;
		ans += j - n / i * k;
	}
	printf(ld,ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
  while (1) {
    int n, y, x, i, j;
    double ans = 0;

    scanf("%d", &n);

    if (n == 0) break;

    scanf("%d", &y);
    
    for (i = 0; i < n; i++) {
      int b, r, t;
      double z;

      scanf("%d %d %d", &b, &r, &t);

      if (t == 1) {
        z = 1 + y * r / 100.0;
      } else {
        z = 1;

        for (j = 0; j < y; j++) z *= (1 + r / 100.0);
      }

      if (z > ans) {
        x = b;
        ans = z;
      }
    }

    printf("%d\n", x);
  }

  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std; 
int pgcd(int a, int b) {
  while (a != b) {
   	if (a > b) 
      a = a-b; 
    else
      b = b-a; 
  }
  return a; 
}
int ppcm(int a, int b) {
  return (a*b)/pgcd(a, b); 
}
int main() {
  int d; 
  cin >> d; 
  cout << ppcm(d, 360)/d; 
}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
int n, f[maxn + 10];
vector<int> g[maxn + 10];
void dfs(int x, int fa) {
    bool isb = 0;
    for (int i = 0; i < (int)g[x].size(); ++i) {
        int e = g[x][i];
        if (e != fa) {
            dfs(e, x); f[x] += f[e];
            if (!f[e]) {
                if (!isb) isb = 1;
                else ++f[x];
            }
        }
    }
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; ++i) {
        int l, r; scanf("%d%d", &l, &r); ++l; ++r;
        g[l].push_back(r); g[r].push_back(l);
    }
    for (int i = 1; i <= n; ++i)
        if ((int)g[i].size() > 2) {
            dfs(i, 0);
            printf("%d", f[i]); return 0;
        }
    printf("1");
}


Measured memory_bytes: 30208
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	int n, m;
	cin >> n >> m;
	if(n==m)
		cout << "Yes\n";
	else 
		cout << "No\n";
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	int n;cin>>n;
	string s;cin>>s;
	int ans=0;
	rep(i,n-2) if(s.substr(i,3)=="ABC") ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
from itertools import takewhile

"""
演算子は要素とセットでモノイドを形成するようなものでなければならない。
すなわち、結合律が成り立ち単位元が存在する必要がある。

equalityはsetを高速化するために使う。めんどい場合はNoneにしてもOK
"""
class SegmentTree:

  @classmethod
  def all_identity(cls, operator, equality, identity, size):
    return cls(operator, equality, identity, [identity]*(2 << (size-1).bit_length()))

  @classmethod
  def from_initial_data(cls, operator, equality, identity, data):
    size = 1 << (len(data)-1).bit_length()
    temp = [identity]*(2*size)
    temp[size:size+len(data)] = data
    data = temp

    for i in reversed(range(size)):
      data[i] = operator(data[2*i],data[2*i+1])
    return cls(operator, equality, identity, data)

  # これ使わずファクトリーメソッド使いましょうね
  def __init__(self, operator, equality, identity, data):
    if equality is None:
      equality = lambda a,b: False
    self.op = operator
    self.eq = equality
    self.id = identity
    self.data = data
    self.size = len(data)//2

  def _interval(self, a, b):
    a += self.size
    b += self.size
    ra = self.id
    rb = self.id

    data = self.data
    op = self.op
    while a < b:
      if a & 1:
        ra = op(ra,data[a])
        a += 1
      if b & 1:
        b -= 1
        rb = op(data[b],rb)
      a >>= 1
      b >>= 1
    return op(ra,rb)

  def __getitem__(self, i):
    if isinstance(i, slice):
      return self._interval(
                  0 if i.start is None else i.start,
                  self.size if i.stop is None else i.stop)
    elif isinstance(i, int):
      return self.data[i+self.size]

  def __setitem__(self, i, v):
    i += self.size
    data = self.data
    op = self.op
    eq = self.eq
    while i and not eq(data[i],v):
      data[i] = v
      v = op(data[i^1],v) if i & 1 else op(v,data[i^1])
      i >>= 1

  def __iter__(self):
    return self.data[self.size:]

# 素数生成器
def generate_primes():
  from collections import defaultdict
  from itertools import count
  D = defaultdict(list)

  q = 2
  for q in count(2):
    if q in D:
      for p in D[q]:
        D[p+q].append(p)
      del D[q]
    else:
      yield q
      D[q*q].append(q)

from operator import add,eq

Q = int(input())
Q = [tuple(map(int,input().split())) for _ in range(Q)]

m = max(r for l,r in Q)


primes = set(takewhile(lambda x: x <= m, generate_primes()))
primes.remove(2)

A = [0]*(m+1)

for p in primes:
  if (p+1)//2 in primes:
    A[p] = 1

A[3] = 1

T = SegmentTree.from_initial_data(add, eq, 0, A)

for l,r in Q:
  print(T[l:r+1])

Measured memory_bytes: 24200
#include <iostream>

int main() {
  int x = 0;
  int y = 0;
  
  std::cin >> x >> y;
  
  if (x == y) {
    std::cout << x << std::endl;

    return 0;
  }
  
  if (y > x) {
    int tmp = x;
    x = y;
    y = tmp;
  }

  int m = x % y;

  int d = m;

  while (d > 0) {
    if (((y % d) == 0) && ((m % d) == 0)) {
      break;
    }

    d--;
  }

  std::cout << d << std::endl;
    

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int h,w;
    cin >> h >> w;
    int c[10][10];
    for(int i = 0; i < 10; i++) for(int j = 0; j < 10; j++) cin >> c[i][j];
    for(int k = 0; k < 10; k++){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    int flag[10] = {};
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int a; cin >> a;
            if(a != -1) flag[a]++;
        }
    }
    int res = 0;
    for(int i = 0; i < 10; i++){
        res += flag[i]*c[i][1];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back  
#define INF 1000000000000
typedef long long C;
typedef complex<C> P; 
#define X real() 
#define Y imag()


									// nestedcode


 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll h,a;
   cin>>h>>a;
   ll ans = (h+a-1)/a;
   cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(k>=s.size()){
        cout << s << endl;
    }else{
        rep(i,k){
            cout << s[i];
        }
        cout << "..." << endl;
    }

return 0;
}


Measured memory_bytes: 3628
N = int(input())
A = sorted(-int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

from bisect import *

ans = 0
for b in B:
    a = bisect_right(A, -b)
    c = bisect_right(C, b)
    ans += (len(A) - a) * (len(C) - c)
print(ans)

Measured memory_bytes: 23248
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc109_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();

            for (int i = 1; i <= 3; i++)
            {
                if((input[0]*input[1]*i)%2 != 0){
                    WriteLine("Yes");
                    return;
                }
            }
            WriteLine("No");
        }
    }
}

Measured memory_bytes: 13396
import math
from sys import *
inp=stdin.readline

zip=zip 
def linp(x):
    return list(map(int,x.split()))
def minp(x):
    return map(int,x.split())

n,m=minp(inp())
a=linp(inp())
an=n-sum(a)
if an>=0:
    print(an)
else:
    print("-1")
    




    

Measured memory_bytes: 10068
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------
vector<string> mark = {"S","H","C","D"};

int main(){
  vector<vector<int>> G(4,vector<int> (13,0));
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    string S;
    int num;
    cin >> S >> num;
    num--;
    for(int j=0; j<4; j++){
      if(S == mark[j]){
        G[j][num]++;
      }
    }
  }
  for(int j=0; j<4; j++){
    for(int i=0; i<13; i++){
      if(G[j][i] == 0){
        cout << mark[j] << " " << i+1 << endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3136
a, b, c, x , y = map(int, input().split())


mini = 1000000000000

for i in range(max(x,y)+1):
    sum = (2*c*i) + (a *max(0, x-i) + (b * max(0, y-i)))
    if sum <= mini:
        mini = sum

print(mini)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

MODN = int(1e9 +7)

def modpow(a, n, modn):
  res = 1
  while n>0:
    if n % 2 == 1:
      res = res * a % modn
    a = a * a % modn
    n = n // 2
  return res

fact = [1] * (N+1)
for i in range(1,N+1):
  fact[i] = fact[i-1] * i % MODN
  
# sum(1/i) for i in 1 to N with MODN condition
divsum = [0] * (N+1) #1-indexed
for i in range(1,N+1):
  divsum[i] = (divsum[i-1] + modpow(i, MODN-2, MODN)) % MODN
  
#print(fact)
#print(divsum)

ans = 0
for i in range(N):
  work = 1 + (divsum[i+1] - 1 if i > 0 else 0) + (divsum[N-i] - 1 if i < N-1 else 0)
  #print(work, A[i], i)
  ans += work * A[i] % MODN
  
print(ans * fact[N] % MODN)


Measured memory_bytes: 62576
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

ll nxt()
{
    ll x;
    cin >> x;
    return x;
}

const ll L = 21;
const ll mod = 1e9 + 7;

ll a[L][L];

void solve()
{
    ll n = nxt();   

    vector <ll> dp((1LL << n), 0);

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

    dp[0] = 1;

    for(ll mask = 0; mask < (1LL << n); mask++)
    {
        ll man = __builtin_popcountll(mask);

        for(ll i = 0; i < n; i++)
        {
            if(mask & (1LL << i) && a[man-1][i])
            {
                dp[mask] += dp[mask & ~(1LL << i)];
                dp[mask] %= mod;
            }
        }
    }

    cout << dp[(1LL << n) - 1] << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 16640
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int merge(int *A, int left, int mid, int right){
	int i, j, k, c = 0, n1 = mid-left, n2 = right-mid;
	int L[n1+1], R[n2+1];

	for(i = 0; i < n1; i++)
		L[i] = A[left+i];
	L[n1] = INT_MAX;
	for(i = 0; i < n2; i++)
		R[i] = A[mid+i];
	R[n2] = INT_MAX;

	i = 0;
	j = 0;
	for(k = left; k < right; k++){
		c++;
		if(L[i] <= R[j]){
			A[k] = L[i];
			i++;
		}
		else{
			A[k] = R[j];
			j++;
		}
	}
	return c;
}

int mergeSort(int *A, int left, int right){
	static int c = 0;
	int mid;

	if(left+1 < right){
		mid = (left + right)/2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		c += merge(A, left, mid, right);
		return c;
	}
}

int main(){
	int n, i, c;
	int *A;

	scanf("%d", &n);
	A = (int *)malloc(sizeof(int) * n);
	for(i = 0; i < n; i++)
		scanf("%d", &A[i]);

	c = mergeSort(A, 0, n);

	for(i = 0; i < n; i++){
		printf("%d", A[i]);
		if(i < n-1)
			printf(" ");
		else
			printf("\n");
	}
	printf("%d\n", c);

	free(A);
	return 0;
}


Measured memory_bytes: 5568
#include <iostream>
using namespace std;
int main(void){
    int k1, k2;
    int h1, h2;
    int a, b, c, d;
    
    int kentyan = 0;
    int hirotyan = 0;
    
    cin >> h1 >> h2;
    cin >> k1 >> k2;
    cin >> a >> b >> c >> d;
    
    //けんちゃんの点数
    if(10 <= k1 && 20 <= k2) kentyan = (a * k1) + (b * k2) + (k1 / 10) * c + (k2 / 20) * d;
    else if(10 <= k1) kentyan = (a * k1) + (b * k2) + (k1 / 10) * c;
    else if(20 <= k2) kentyan = (a * k1) + (b * k2) + (k2 / 20) * d;
    else kentyan = (a * k1) + (b * k2);
    
    //ひろちゃんの点数
    if(10 <= h1 && 20 <= h2) hirotyan = (a * h1) + (b * h2) + (h1 / 10) * c + (h2 / 20) * d;
    else if(10 <= h1) hirotyan = (a * h1) + (b * h2) + (h1 / 10) * c;
    else if(20 <= h2) hirotyan = (a * h1) + (b * h2) + (h2 / 20) * d;
    else hirotyan = (a * h1) + (b * h2);    
    
    //勝敗の結果
    if(kentyan == hirotyan) cout << "even" << endl;  
    else if(kentyan < hirotyan) cout << "hiroshi" << endl;
    else cout << "kenjiro" << endl;
    
    return 0;
    
}



Measured memory_bytes: 3092
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int INF = INT_MAX / 2;

vector<int> problems;
vector<int> bonus;

// based on editorial.pdf
int main(void) {
    int D;
    ll G;
    cin >> D >> G;

    problems.resize(D);
    bonus.resize(D);
    for (int i = 0; i < D; i++) {
        int p, c;
        cin >> p >> c;
        problems[i] = p;
        bonus[i] = c;
    }

    int ans = INF;

    // bits means all problems having (i+1) * 100 points will be solved
    // e.g. 001 means only problems having 100.
    for (int bits = 0; bits < (1 << D); bits++) {
        set<int> for_bonus;
        for (int i = 0; i < D; i++) {
            if ((bits >> i) & 1) {
                for_bonus.insert(i);
            }
        }

        int point = 0;
        int num = 0;

        // printf("bonus: ");
        for (auto pb : for_bonus) {
            // printf("%d ", pb);
            num += problems[pb];
            point += problems[pb] * (pb + 1) * 100 + bonus[pb];
        }
        // printf("\n");
        // printf("after bonus. num: %d, point: %d\n", num, point);

        if (point >= G) goto end;

        for (int i = D - 1; i >= 0; i--) {
            if (for_bonus.find(i) != for_bonus.end()) continue;
            for (int j = 0; j < problems[i] - 1; j++) {
                num++;
                point += 100 * (i + 1);
                // printf("[%d] num: %d, point: %d\n", i, num, point);
                if (point >= G) goto end;
            }
        }

end:
        if (point >= G) {
            chmin(ans, num);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll table[200001],table2[200001];
ll h,w,a,b;
ll mod=1e9+7;
ll f(ll x,ll y){
    if(y==1)return x;
    if(y%2==0)return (f(x,y/2)%mod*f(x,y/2)%mod)%mod;
    else return (f(x,y-1)%mod*x)%mod;
}
ll comb(ll x,ll y){
    x-=2,y--;
    if(x==0)return 1;
    if(y==0)return 1;
    ll ans=1;
    ans*=table[x-1];
    ans%=mod;
    ans*=table2[y-1];
    ans%=mod;
    ans*=table2[max(0LL,x-y-1)];
    ans%=mod;
    return ans;
}
int main(void){
    ll cnt=1;
    for(ll i=1;i<=200001;i++){
        cnt*=i;
        cnt%=mod;
        table[i-1]=cnt%mod;
        if(i<=200001){
            table2[i-1]=f(cnt,mod-2)%mod;
        }
    }
    //cout<<table[199998]<<endl;
    cin>>h>>w>>a>>b;
    ll ans=0;
    for(ll i=0;i<h-a;i++){
        ans+=comb(b+i+1,i+1)*comb(h-i+w-b,w-b);
        ans%=mod;
        //cout<<comb(b+i+1,i+1)<<comb(100009,3)<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
import math
N, D = [int(s) for s in input().split(' ')]

Xs = []
for n in range(N):
    X = [int(s) for s in input().split(' ')]
    Xs.append(X)
j = 0
b = [i * i for i in range(1, int(math.sqrt(40 ** 2 * 10)) + 1)] # 40 ** 2 * 10 = 16000 < 130 * 130
count = 0
for Xi in Xs:
    j += 1
    for Xj in Xs[j:]:
        a = 0
        for d in range(D):
            a += (Xi[d] - Xj[d]) ** 2
        if a in b:
            count += 1

print(count)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(m), y(m);
    vector<vector<pair<int, int>>> v(n);

    rep(i, m) {
        cin >> p[i] >> y[i];
        v[p[i]-1].push_back(make_pair(y[i], i));
    }

    rep(i, n) {
        sort(v[i].begin(), v[i].end());
        for(unsigned j = 0; j < v[i].size(); j++) {
            y[v[i][j].second] = j+1;
        }
    }

    rep(i, m) {
        printf("%06d%06d\n", p[i], y[i]);
    }
    
    return 0;
}

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

int main()
{
    int X, N, atai, M = 0, M2 = 0;
    cin >> X >> N;
    vector<int> p(N);

    bool dekita = false;

    for (int i = 0; i < N; i++)
    {
        cin >> p.at(i);
    }
    if (N == 0)
    {
        dekita = true;
        atai = X;
    }

    for (int i = 0; i <= 100; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (X - i == p.at(j))
            {
                M = j;
            }
            if (X + i == p.at(j))
            {
                M2 = j;
            }
        }
        if (dekita == true)
        {
            cout << atai << endl;
            break;
        }
        else if (X - i != p.at(M) && X - i != p.at(M2))
        {
            atai = X - i;
            cout << atai << endl;
            break;
        }
        else if (X + i != p.at(M) && X + i != p.at(M2))
        {
            atai = X + i;
            cout << atai << endl;
            break;
        }
    }
}


Measured memory_bytes: 3564
N = int(input())


#整数N以下の素数を#素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = prime_factorize(N)
b = set(a)

dic = {}
for i in b:
    n = 0
    while True:
        n += 1
        if a == []:
            break
        a.pop(0)
        if a == []:
            break
        if a[0] != i:
            break
    dic[i] = n


an = 0
for k, v in dic.items():
    num = int((-1+(1+8*v)**(1/2))/2)
    an += num

print(an)


Measured memory_bytes: 9492
#include <stdio.h>
int main(){
 int a,b,i,d;
 while(1){
 scanf("%d %d",&a,&b);
 if(a==0 && b==0)break;
 for(i=0;i<a;i++){
  for(d=0;d<b;d++)
   {printf("#"); }
  printf("\n"); }
 printf("\n"); } 
 return 0;
} 


Measured memory_bytes: 2124
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int r = sc.nextInt();
            if (n == 0 && r == 0) break;
            int[] N = new int[n];
            for (int i = 0; i < n; i++) {
                N[i] = n - i;
            }
            for (int i = 0; i < r; i++) {
                int p = sc.nextInt();
                int c = sc.nextInt();
                int[] tmp = new int[n];
                for (int j = p - 1; j < p - 1 + c; j++) {
                    tmp[j-p+1] = N[j];
                }
                for (int j = 0; j < p - 1; j++) {
                    tmp[c + j] = N[j];
                }
                for (int j = p + c - 1; j < n; j++) {
                    tmp[j] = N[j];
                }
                N = tmp;
            }
            System.out.println(N[0]);
        }
        sc.close();
    }
}


Measured memory_bytes: 37380
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        int line = sc.nextInt();
if(line<1000)
        System.out.println("ABC");
else System.out.println("ABD");
    }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

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: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<functional>

#include<algorithm>
typedef long long ll;
using namespace std;

int main(){
  char miria[256];

  cin >>miria;
  //cout <<miria[5] <<miria[6] << endl;
  if(strcmp(miria,"2019/04/30")>0){
    cout << "TBD" << endl;
  }else{
    cout << "Heisei" << endl;
  }
  return 0;
}

Measured memory_bytes: 888
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
n, m = map(int, input().split())
graph_list = []
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph_list.append([a, b])

ans = n * (n - 1) // 2
ans_list = []
union = UnionFind(n)
for i, j in reversed(graph_list):
    ans_list.append(ans)
    if not union.same(i, j):
        ans -= union.size(i) * union.size(j)
    union.union(i, j)
for i in reversed(ans_list):
    print(i)

Measured memory_bytes: 25628
#include <stdio.h> 

  int main(void) { 

    int a; 

    int b;

    int z;   

  int min;  

   int max; 

    long int sum;

    min = 1000000;   

  max = -1000000; 

      sum = 0;  

    scanf("%d",&a); 

      for(b=0; b<a; b++)     { 

        scanf("%d",&z); 

                 if(min > z)         { 

            min = z;    

     }     

    if(max < z)         {     

        max =z;    

     }     

    sum = sum + z; 

    }     

    printf("%d %d %ld\n",min,max,sum);

      return 0;

} 

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		if(500 * N >= K) {
			System.out.print("Yes");
		}else {
			System.out.print("No");			
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
 
int main() {
	int w,h,x,y,r;
  	cin>>w>>h>>x>>y>>r;
  	//上、下、左、右
  	if(h>=y+r && y-r>=0 && x-r>=0 && w>=x+r){
    	cout<<"Yes"<<endl;
    }else{
    	cout<<"No"<<endl;
    }
}



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

typedef long long int ll;
typedef pair<ll, ll> P;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double PI = 3.1415926535;

int main(void){
    ll a, b; cin >> a >> b;
    ll n = a + b;
    if(n%2 == 1)printf("IMPOSSIBLE\n");
    else printf("%lld\n", n/2);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	static int Data[][];
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int N=in.nextInt(),W=in.nextInt();
		Data=new int[N][2];
		
		for(int i=0;i<N;i++) {
			Data[i][0]=in.nextInt();
			Data[i][1]=in.nextInt();
		}		
		System.out.println(DP2Controll(W));
	}
	
	static int DP1(int limit) {
		int dp[][]=new int[Data.length+1][limit+1];
		
		for(int i=1;i<=Data.length;i++) {
			for(int j=0;j<=limit;j++) {
				if(j-Data[i-1][1]<0)dp[i][j]=dp[i-1][j];
				else dp[i][j]=Math.max(dp[i-1][j], dp[i-1][j-Data[i-1][1]]+Data[i-1][0]);
			}
		}
		
		int max=0;
		for(int i=0;i<=limit;i++)max=Math.max(max, dp[Data.length][i]);

		return max;
	}
	 
	static int dp2[][];
	static boolean done[][];
	
	static int DP2Controll(int limit) {
		dp2=new int[Data.length+1][limit+1];
		done=new boolean[Data.length+1][limit+1];
		
		int res=DP2(0,limit);
		return res;
	}
	
	static int DP2(int i,int j) {
		if(done[i][j])return dp2[i][j];

		int res;
		
		if(i==Data.length)res=0;
		else if(j<Data[i][1]) res=DP2(i+1,j);
		else {
			res=Math.max(DP2(i+1,j), DP2(i+1,j-Data[i][1])+Data[i][0]);
		}

		done[i][j]=true;
		dp2[i][j]=res;
		
		return dp2[i][j];
	}

}



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

UL D;
LL C[26];
LL S[400][26];

UL T[400];
LL Last[400][26];
LL Score[26] = {};
LL Sum = 0;

LL MaxScore = -1000000000;
UL ans[400];

mt19937 mt;

void CalcScore(UL i){
 Sum -= Score[i];
 Score[i]=0;
 rep(d,D){
  Last[d+1][i]=Last[d][i];
  if(T[d]==i) {
   Score[i] += S[d][i];
   Last[d+1][i]=d;
  }
  Score[i] -= C[i] * ((LL)d-Last[d+1][i]);
 }
 Sum += Score[i];
}

void Change(){
 UL d = mt() % D;
 UL t = mt() % 26;
 UL TBuf = T[d]; T[d] = t;
 LL SumBuf = Sum;
 CalcScore(TBuf);
 CalcScore(t);
 if (Sum <= MaxScore - 1000) {
  T[d] = TBuf;
  CalcScore(t);
  CalcScore(TBuf);
 }
 else if(MaxScore < Sum) {
  rep(d,D) ans[d] = T[d];
  MaxScore = Sum;
 }
}

void Swap(){
 UL d = mt() % (D-1);
 if(T[d]==T[d+1]) return;
}

void Step(){
 Change();
}

int main() {
 ULL StartP = clock();
 mt.seed(999999999);

 scanf("%u", &D);
 rep(i,26) scanf("%lld",&C[i]);
 rep(i,D)rep(j,26) scanf("%lld",&S[i][j]);
 
 rep(d,D) T[d] = mt() % 26;
 rep(i,26) CalcScore(i);
 MaxScore = Sum;
 rep(i,26) Last[0][i] = -1;
 while(true){
  ULL CheckP = clock();
  if(CheckP-StartP > CLOCKS_PER_SEC * 3 / 2) break;
  Step();
 }
 
 rep(i,D) printf("%u\n", ans[i]+1);
 
 return 0;
}



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

int main()
{
    int l,r,d ;
    cin>>l>>r>>d;
    int cnt=0;
    for(int i=l  ; i<=r ; ++i)
    {
        if(i%d==0)
        ++cnt;
    }
    cout<<cnt;

    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, M;
  cin >> N >> M;

  vector<int> h(N);
  REP(i, N) cin >> h[i];

  vector<vector<int>> graph(N);
  REP(i, M){
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }
  
  int ans = 0;
  REP(i, N){
    bool flag = true;
    for(auto u : graph[i]){
      if(h[i] <= h[u]){
        flag = false;
        break;
      }
    }
    if(flag){
      ans++;
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 9800
def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = [int(i) for i in input().split(" ")]
    else:
        P = []

    if x not in P:
        print(x)
        return

    xm = x
    xp = x

    while True:
        xm = xm - 1
        if xm not in P:
            print(xm)
            return
        xp = xp + 1
        if xp not in P:
            print(xp)
            return


q3()


Measured memory_bytes: 9144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//
		int input_low = 0;
		int house_number = 0;
		int floar_number = 0;
		int room_number = 0;
		int person = 0;

		// テキスト入力
		Scanner sc = new Scanner(System.in);

		// A大学の公舎を作る
		int school_house[][][];
		school_house = new int[4][3][10];

		// 入力の数だけ回す
		while (sc.hasNext()) {

			// 入力行数
			input_low = sc.nextInt();
			break;
		}

		// 入力行数分回す
		for (int i = 0; i < input_low; i++) {

			while(sc.hasNext()){
			// 部屋の指定
			house_number = sc.nextInt();
			floar_number = sc.nextInt();
			room_number = sc.nextInt();
			person = sc.nextInt();
			break;
			}

			// 部屋に人を放り込む
		int now_person = school_house[house_number-1][floar_number-1][room_number-1];
		school_house[house_number-1][floar_number-1][room_number-1] = now_person + person;
			

		}

		// 出力
		for (int hi = 0; hi < 4; hi++) {
			for (int fi = 0; fi < 3; fi++) {
				for (int ri = 0; ri < 10; ri++) {
					System.out.print(" "+school_house[hi][fi][ri]);
				}
				System.out.print("\n");
			}
			//最後の行を表示
			while (hi < 3) {
				System.out.println("####################");
				break;
			}
		}

	}

}

Measured memory_bytes: 20676
#include<bits/stdc++.h>                                                        
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0; i<n; i++){
    cin >> p.at(i);
  }
  int count=0;
  for(int i=0; i<n-2; i++){
    if((p.at(i)<p.at(i+1) && p.at(i+1)<p.at(i+2)) ||
        (p.at(i)>p.at(i+1) && p.at(i+1)>p.at(i+2))){
      count++;
    }
  }
  cout << count << endl;
}

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

using namespace std;

int main() {
    int n;
    cin>>n;
    std::vector<int>v(n);
    for(auto &x:v)cin>>x;
    long long ans=0;
    for(int i=1;i<v.size();i++)
    {
        if(v[i]>=v[i-1])continue;
        else {
            ans+=v[i-1]-v[i];
            v[i]=v[i-1];
        }
    }
    cout<<ans<<endl;
	return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    vector<Int> b = a;
    for (Int i = 0; i < n - 1; i++) {
        b[i + 1] += b[i];
    }
    Int res = 1;
    for (Int i = n - 2; i >= 0; i--) {
        if (b[i] * 2 >= a[i + 1]) {
            res++;
        }
        else {
            break;
        }
    }
    dump(res);
    return 0;
}


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

int main()
{
  int n ;
  cin >> n ;
  queue<int> data ;
  for(int i = 0 ; i < n ; i++)
  {
    int x ;
    cin >> x ;
    data.push(x) ;
  }
  int judge = 1 ;
  int answer = 0 ;
  bool ansjudge = false ;
  while(!data.empty())
  {
    if(data.front() == judge)
    {
      judge++ ;
      ansjudge = true ;
      data.pop() ;
    }
    else
    {
      answer++ ;
      data.pop() ;
    }
  }

  if(ansjudge)
  {
    cout << answer << endl ;
  }
  else
  {
    cout << -1 << endl ;
  }
  
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int main(void){
    // Your code here!
    int n,k;
    char c;
    
    cin >> n >>k ;
    
    for(int i=0;i<n;i++){
        cin >> c;
        if(i==k-1)cout <<(char)((int)c+32);
        else cout<<c;
        
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


#define huge 1000000007
typedef long long ll;

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll K = 0;
	ll Y = 0;
	ll X = 0;
	ll m[100000] = {};
	//ll c[10000] = {};
	//ll d[10000] = {};
	//ll *x, *c, *d;
	string S;
	ll count = 0;
	ll sum = 0;
	ll min = 1000;
	ll i = 0;
	char p;
	cin >> A >> p >> B;
	
	if (p == '+') {
		cout << A + B << endl;
	}
	else {
		cout << A - B << endl;
	}

	return 0;

}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			long sumX = mod(IntStream.range(0, n).mapToLong(i -> mod((2 * i + 1 - n) * scanner.nextLong())).sum());
			long sumY = mod(IntStream.range(0, m).mapToLong(i -> mod((2 * i + 1 - m) * scanner.nextLong())).sum());
			System.out.println(mod(sumX * sumY));
		}
	}

	/**
	 * @param l
	 * @return l mod MOD
	 */
	private static long mod(long l) {
		long result = l % MOD;
		return (result >= 0) ? result : result + MOD;
	}
}


Measured memory_bytes: 59208
a,b=map(int,input().split()) 
c=10000 
d=5000 
e=1000 
ans=False 
for i in range(a+1): 
	for j in range(a+1-i): 
		if i*c+j*d+(a-i-j)*e==b and a-i-j>=0: 
			ans=True 
			break 
	if(ans):break 
if(ans):print(i,j,a-i-j) 
else:print(-1,-1,-1) 

Measured memory_bytes: 3064
#include<cstdio>
int main(){
  int q,h,s,d,n;
  scanf("%d%d%d%d%d",&q,&h,&s,&d,&n);
  if(q*4<s)s=q*4;
  if(h*2<s)s=h*2;
  if(s*2<d)printf("%lld\n",n*1ll*s);
  else printf("%lld\n",n/2*1ll*d+(n%2)*s);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


int main(){
  long long x, y;
  cin >> x >> y;
  
  long long cntx = (2*x-y)/3, cnty = x - 2*cntx;
  if((2*x-y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  
  COMinit();
  cout << COM(cntx+cnty, cnty) << endl;
}

Measured memory_bytes: 119808