akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int m = sc.nextInt();
		int[] whereH = new int[m];//爆弾の位置
		int[] whereW = new int[m];//爆弾の位置
		int[] countHeight = new int[h+1];//爆弾の個数
		int[] countWide = new int[w+1];//爆弾の個数
		for(int i = 0; i < m; i++){
			int hi = sc.nextInt();
			int wi = sc.nextInt();
			whereH[i] = hi;
			whereW[i] = wi;
			countHeight[hi]++;
			countWide[wi]++;
		}
		sc.close();
      
		//countHeightとcountWideの最大値計算
		int maxH = 0;
		int maxW = 0;
		for(int i = 0; i <= h; i++){
			if(countHeight[i] > maxH){
				maxH = countHeight[i];
			}
		}
		for(int i = 0; i <= w; i++){
			if(countWide[i] > maxW){
				maxW = countWide[i];
			}
		}
		//maxになる場所の個数
		int countMaxW = 0;
		int countMaxH = 0;
		for(int i = 0; i <= h; i++){
			if(countHeight[i] == maxH){
				countMaxH++;
			}
		}
		for(int i = 0; i <= w; i++){
			if(countWide[i] == maxW){
				countMaxW++;
			}
		}
      
		//最大値を取る場所の個数が重複地点より多い＝何もない場所における
      	long maxCount = countMaxH*countMaxW;
      	for(int i = 0; i < m; i++){
        	if(countWide[whereW[i]] == maxW && countHeight[whereH[i]] == maxH){
            	maxCount--;
            }
        }
      
		if(maxCount!=0) System.out.println(maxH+maxW);
		else  System.out.println(maxH+maxW-1);
	}
}

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

int main()
{
    int n;
    cin >> n;
    int *a = new int[n];
    rep(i, n) cin >> a[i];
    // 最後の値上がりをチェック
    int lastup = -1;
    rep(i, n - 1)
    {
        if( a[i + 1] > a[i] ) lastup = i;
    }

    // 次の日に値上がりするなら買えるだけ買う。値下がりするなら売れるだけ売る
    _LL money = 1000;
    _LL stock = 0;
    rep(i, n)
    {
        if( i < n - 1)
        {
            if( a[i] < a[i + 1] && i <= lastup )
            {
                stock += money / a[i];
                money = money % a[i];
            }
            else if( a[i] > a[i + 1] )
            {
                money += stock * a[i];
                stock = 0;
            }
        }
        else
        {
            money += stock * a[i];
            stock = 0;            
        }
//        cout << money << "," << stock << endl;
    }
    cout << money;
}

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

int main() {
	// your code goes here
	long long x;
	cin>>x;
	if (x>=400 && x<=599)
	    cout<<"8"<<"\n";
	else if (x>=600 && x<=799)
	    cout<<"7"<<"\n";
	else if (x>=800 && x<=999)
	    cout<<"6"<<"\n";
	else if (x>=1000 && x<=1199)
	    cout<<"5"<<"\n";
	else if (x>=1200 && x<=1399)
	    cout<<"4"<<"\n";
	else if (x>=1400 && x<=1599)
	    cout<<"3"<<"\n";
	else if (x>=1600 && x<=1799)
	    cout<<"2"<<"\n";
	else if (x>=1800 && x<=1999)
	    cout<<"1"<<"\n";
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    
    int m;
    cin >> m;
    rep(i, m) {
        int a;
        cin >> a;
        a--;
        if (x[a] == 2019) continue;
        rep(j, n) {
            if (x[j] == x[a] + 1) break;
            if (j == n - 1) {
                x[a]++;
            }
        }
    }
    rep(i, n) cout << x[i] << endl;
}



Measured memory_bytes: 3124
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


u = set()

def agari(i):
    if X[i]==1:
        X[i]=0
        agari(i+1)
    else:
        X[i]=1

X = [0]*20
k=0
while k<(pow(2,n)-1):
    y = 0
    for l in range(n):
        y += A[l]*X[l]
    u.add(y)
    agari(0)
    k+=1

for j in range(q):
    if m[j] in u:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll a,b; cin >> a >> b;
    if(a <= b) cout << a << endl;
    else cout << a-1 << endl;
    return 0;
}


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


void solve(std::string S){
    for(int i = 0; i <= 3; ++i){
        if(count(S.cbegin(), S.cend(), 'o') == i) cout << 700 + i * 100 << endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
(defun split (str delim)
  (let ((res (make-array 1 :element-type 'string
                           :fill-pointer 0
                           :adjustable t)))
    (loop for i from 0 below (length str)
          with start = 0
          when (eq (char str i) delim)
          do (vector-push-extend (subseq str start i) res)
             (setf start (1+ i))
          finally (let ((tail (subseq str start)))
                    (when tail
                      (vector-push-extend tail res))))
    res))

(let* ((n (parse-integer (read-line)))
       (tin (map 'vector #'parse-integer (split (read-line) #\Space)))
       (m (parse-integer (read-line)))
       (px (loop for i from 0 below m
                 collect (split (read-line) #\Space)))
       (s (reduce #'+ tin)))
  (loop for i in px
        for p = (1- (parse-integer (aref i 0)))
        do (format t "~A~%"
                   (+ (- s (aref tin p))
                      (parse-integer (aref i 1))))))

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

int main(void){
  int count = 0;
  char buf[32] = { 0 };
  char *pbuf = buf;
  
  //数字読み込み
  fgets(buf, sizeof(buf), stdin);
  for(int i = 0; i < 3; i++, pbuf++){
    if(*pbuf == '1') count++;
  }
  printf("%d\n", count);
  return 0;
}

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

long S( long a )
{
    long t , ans=0;

    while( a ){
        t = a%10;
        ans += t;
        a /=10;
    }

    return ans;
}

long f(long N)
{
    int d , i;
    long ans , x;

    d=log10(N+1);

    ans=N;
    for(i=0;i<d;i++){
        x=pow(10,i+1)*(N/pow(10,i+1)+1)-1;
        if((double)x/S(x)< (double)ans/S(ans))
            ans = x;
    }

    return ans;
}

int main( void )
{
    long i ,N,k;

    scanf( "%ld" , &k);

    N=1;
    printf("%ld\n",N);
    for(i=1;i<k;i++){
        N = f(N+1);
        printf("%ld\n",N);
    }
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> v;
    int p;
    for(int i=0; i<N; i++) {
        cin >> p;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    int sum = 0;
    for(int i=0; i<K; i++) {
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}

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

int main(){
    int N;
    double ans;
    cin>>N;
    if(N%2==0)ans=double(N/2)/N;
    else ans=double(N-(N/2))/N;
  	cout<<fixed<<setprecision(15)<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAXN 100005
#define PLI pair<long long,int>
#define fi first
#define se second
#define mp make_pair
//#define ivorysi
using namespace std;
typedef long long int64;
int N,M;
int64 C[3005][3005],S[3005][3005],ans;

int64 fpow(int64 x,int64 c,int64 MOD) {
	int64 res = 1,t = x;
	while(c) {
		if(c & 1) res = res * t % MOD;
		t = t * t % MOD;
		c >>= 1;
	}
	return res;
}
int64 ways(int x) {
	int64 res = 0;
	int64 tmp2 = fpow(2,fpow(2,N - x,M - 1),M);
	int64 t = fpow(2,N - x,M);
	int64 tmp1 = 1;
	for(int j = 0 ; j <= x ; ++j) {
		res += S[x][j] * tmp1 % M * tmp2 % M;
		tmp1 = tmp1 * t % M;
		res %= M;
	}
	return res;
}
void Solve() {
	scanf("%d%d",&N,&M);
	C[0][0] = 1;
	for(int i = 1 ; i <= N ; ++i) {
		C[i][0] = 1;
		for(int j = 1 ; j <= i ; ++j) {
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % M;
		}
	}
	S[0][0] = 1;S[1][1] = 1;
	for(int i = 1 ; i <= N ; ++i) {
		S[i][0] = 1;
		for(int j = 1 ; j <= i ; ++j) {
			S[i][j] = (S[i - 1][j - 1] + S[i - 1][j] * (j + 1)% M) % M;
		}
	}
	int t = 1;
	for(int i = 0 ; i <= N ; ++i) {
		(ans += t * C[N][i] % M * ways(i) % M) %= M;
		t = 1LL * t * (M - 1) % M;
	}
	printf("%lld\n",ans);
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
	return 0;
}

Measured memory_bytes: 139648
#include <iostream>
#include <vector>
#include <cmath>
#include <assert.h>
using namespace std;
#define ll long long


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

	ll n;
	cin >> n;
	vector<ll> H(n), B(n);
	
	ll base = n;
	
	vector<ll> dp(n + 1);
	vector<ll> tree(4 * base + 1);

	for (auto &a : H){
		cin >> a;
	}
	for (auto &a : B){
		cin >> a;
	}

	for (ll flower = 0; flower < n; ++flower){
		ll h = H[flower];
		ll b = B[flower];

		ll best = 0;

		ll l = base + 1;
		ll r = base + h;

		while (l <= r){
			if (l & 1){
				best = max(best, tree[l]);
				l++;
			}
			if ((r & 1) == 0){
				best = max(best, tree[r]);
				r--;
			}
			l /= 2;
			r /= 2;
		}

		dp[h] = best + b;
		tree[base + h] = best + b;

		for (ll index = (base + h) / 2; index >= 1; index /= 2){
			tree[index] = max(tree[2 * index], tree[2 * index + 1]);
		}
	}
	ll best = 0;
	for (ll x : dp){
		best = max(best, x);
	}
	cout << best << endl;
}

Measured memory_bytes: 11392
#include <cstdio>
int n,k;
int f[1005][1005];
int key[1005];
int main()
{
  scanf("%d%d",&n,&k);
  for(int j=1;j<=k;j++)f[1][j]=1;
  key[1]=k;
  for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
	  f[i][j]=key[i-1]-f[i-1][j];
	  key[i]+=f[i][j];
	}
  }
  printf("%d",key[n]);
  return 0;
}


Measured memory_bytes: 4096
program probc
    implicit none
    integer::a, b, c, x, y, i, tmp, ans
    read(*,*) a, b, c, x, y

    ans = a*x + b*y
    tmp = ans
    do i = 0, max(x,y)
        if(i <= min(x,y)) then
            tmp = c*2*i + a*(x-i) + b*(y-i)
        else
            if(x >= y) then
                tmp = c*2*i + a*(x-i)
            else
                tmp = c*2*i + b*(y-i)
            end if
        end if
        ans = min(ans,tmp)
    end do
    write(*,*) ans
    stop
end program

Measured memory_bytes: 2828
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int book[3];
	book[0]=a+b;
	book[1]=a-b;
	book[2]=a*b;
	sort(book,book+3);
	cout<<book[2];
	return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 611;

ll n, d1, d2, i, j, need;
vector< pair<ll, ll> > comb;
int col[maxN][maxN], gr[maxN][maxN];
queue< pair<int, int> > Q;
vector< pair<int, int> > wh[4];

void run(int val) {
    int x, y;

    y = 0;
    for (x = 0; x * x <= val; x++) {
        while (x * x + (y + 1) * (y + 1) <= val) y++;
        while (x * x + y * y > val) y--;

        if (x * x + y * y == val) comb.pb(mp(x, y));
    }
}

void bfs(int x, int y) {
    vector<ll> vx, vy;

    Q.push(mp(x, y));
    while (!Q.empty()) {
        x = Q.front().first;
        y = Q.front().second;
        Q.pop();

        for (auto e : comb) {
            vx = {e.first, -e.first};
            vy = {e.second, -e.second};

            for (auto dx : vx) {
                for (auto dy : vy) {
                    int xx = x + dx;
                    int yy = y + dy;

                    if (xx < 0 || xx >= 2 * n) continue;
                    if (yy < 0 || yy >= 2 * n) continue;
                    if (col[xx][yy] != 0) continue;
                    col[xx][yy] = -col[x][y];
                    Q.push(mp(xx, yy));
                }
            }
        }
    }
}

void solve(ll D, ll df) {
    ll i, j;

    memset(col, 0, sizeof(col));
    comb.clear();

    run(D);
    for (i = 0; i < 2 * n; i++) {
        for (j = 0; j < 2 * n; j++) {
            if (col[i][j] == 1) gr[i][j] |= df;
            if (col[i][j] != 0) continue;
            col[i][j] = 1;
            bfs(i, j);
            if (col[i][j] == 1) gr[i][j] |= df;
        }
    }
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%lld%lld%lld", &n, &d1, &d2);
    solve(d1, 1);
    solve(d2, 2);

    for (i = 0; i < 2 * n; i++) {
        for (j = 0; j < 2 * n; j++) {
            wh[gr[i][j]].pb(mp(i, j));
        }
    }

    int tp = 0;
    while (wh[tp].size() < n * n) tp++;
    wh[tp].resize(n * n);
    for (auto e : wh[tp])
        printf("%d %d\n", e.first, e.second);

    return 0;
}


Measured memory_bytes: 7528
N=int(input())
A=[int(x) for x in input().split()]
X=[]
for k in range(32):
    pp=0
    for a in A:
        pp+=(a>>k)&1
    if pp%2:
        for i in range(N):
            A[i]=A[i]^2**(k)
print(" ".join([str(x) for x in A]))

Measured memory_bytes: 104796
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  long long n;
  cin >> n;
  if (n % 2 ==0){
    cout << n << '\n';
  }
  else{
    cout << n * 2 << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
class BIT:
    """
    1-indexed
    """
    def __init__(self, size):
        self.size = size
        self.data = [0] * (size + 1)

    def add(self, index, value=1):
        while index <= self.size:
            self.data[index] += value
            index += index & (-index)

    def sum(self, index):
        """
        右端含める
        """
        ret = 0
        while index:
            ret += self.data[index]
            index -= index & (-index)
        return ret

    def search(self, val):
        """
        x_1 + ... x_i >= val を満たす最小のi
        """
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)  # 一番上の長さ

        while step:
            if i + step <= self.size and s + self.data[i + step] < val:
                i += step
                s += self.data[i]
            step //= 2
        return i + 1


def sol():
    N = int(input())
    P = [None] + list(map(int, input().split()))

    pToI = {p : i for i, p in enumerate(P[1:], 1)}
    tree = BIT(N)

    ans = 0
    for p in range(1, N + 1)[:: -1]:
        i = pToI[p]
        left = tree.sum(i)  # 左にある個数
        tree.add(i)
        right = (N - p) - left  # 右にある個数(処理済みの内，左にないものの個数)

        # L1 < L2 < p < R1 < R2
        L1 = tree.search(left - 1) if left >= 2 else 0
        L2 = tree.search(left) if left >= 1 else 0
        R1 = tree.search(left + 2) if right >= 1 else N + 1
        R2 = tree.search(left + 3) if right >= 2 else N + 1

        cnt = 0
        if L2 != 0:
            cnt += (L2 - L1) * (R1 - i)
        if R1 != 0:
            cnt += (R2 - R1) * (i - L2)

        ans += cnt * p

    print(ans)

sol()

Measured memory_bytes: 68072
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << "No" << endl;
  } else if (a != b && b != c && c != a) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long n,a[105],ans=1;
 
int main(){
  scanf("%lld",&n);
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++){
    ans = ans/__gcd(ans,a[i]) * a[i];
  }
  printf("%lld",ans);
}

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

using namespace std;

int main()
{
  long long count=0;
  long long n,d;
  cin >> n >> d;
  for(int i=0;i<n;i++)
  {
    long long x,y;
    cin >> x >> y;
    x=pow(x,2);
    y=pow(y,2);
    if(sqrt(x+y)<=d)
       {
         count++;
       }
  }
  cout << count << endl;
       return(0);
}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(b-1,n);
    cout << ((a*(x%b)) - ((a*x)%b))/b;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        ret %= MOD;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count))%MOD;
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
from sys import stdin

n = int(stdin.readline().rstrip())
k = int(stdin.readline().rstrip())
x = int(stdin.readline().rstrip())
y = int(stdin.readline().rstrip())

if n <= k:
    print(x * n)
else:
    print(y * n + (x - y) * k)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int MAX_N=16;
int n;
vvin d(MAX_N,vin(MAX_N,inf));
vvin dp((1<<MAX_N),vin(MAX_N,-1));

int rec(int S,int v){
    if(dp[S][v]>=0)return dp[S][v];
    if(S==(1<<n)-1&&v==0)return dp[S][v]=0;
    int res=inf;
    rep(u,n)if(!(S&1<<u))res=min(res,rec(S|1<<u,u)+d[v][u]);
    return dp[S][v]=res;
}

int main(){
    int m;cin>>n>>m;
    int s,t,D;
    rep(i,m){
        cin>>s>>t>>D;
        d[s][t]=D;
    }
    int ans=rec(0,0);
    if(ans!=inf)cout<<ans<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
template<typename T = int> using V = vector<T>;
template<typename T = int> using P = pair<T, T>;
using Vi = V<int>;
using Vl = V<ll>;
using Vd = V<ld>;
using Vb = V<bool>;
using VVi = V<Vi>;
using VVl = V<Vl>;
using VVb = V<Vb>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF  = 1<<30;
// const ll INFll = 1ll<<60;
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll d, t, s; cin >> d >> t >> s;

  if (d <= t * s) cout << "Yes\n";
  else cout << "No\n";
}


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

const int N = 505;

int n, m;
char a[N][N], s[N][N];

void clear() {
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			a[i][j] = s[i][j];
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);
	clear();
	for(int i = 1; i <= n; i += 2)
		for(int j = 1; j < m; ++j)
			a[i][j] = '#';
	for(int i = 1; i <= n; ++i)
		a[i][1] = '#';
	for(int i = 1; i <= n; ++i)
		puts(a[i] + 1);
	puts("");
	clear();
	for(int i = 2; i <= n; i += 2)
		for(int j = 2; j <= m; ++j)
			a[i][j] = '#';
	for(int i = 1; i <= n; ++i)
		a[i][m] = '#';
	for(int i = 1; i <= n; ++i)
		puts(a[i] + 1);
	puts("");
	return 0;
}


Measured memory_bytes: 1280
N = int(input())
xy = [list(map(int,input().split())) for _ in [0]*N]

import itertools

cnt = 0
ans = 0
for P in itertools.permutations(list(range(N))):
    cnt += 1
    tmp = 0
    for i in range(N-1):
        tmp += ((xy[P[i]][0]-xy[P[i+1]][0])**2+(xy[P[i]][1]-xy[P[i+1]][1])**2)**0.5
    ans += tmp
ans /= cnt
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define FL(i,a,b) for(int i = a;i<b;i++)
typedef vector<int> vi;

int inf = numeric_limits<int>::max();

int main(){ 
    int n;
    long int W;
    cin>>n>>W;
    vector<long int> w;
    vector<long long  int> v;
    FL(i,0,n){
        long int a;
        long long int b;
        cin>>a>>b;
        w.push_back(a);
        v.push_back(b);
    }
    long long int value[n+1][W+1] = { };
    for(int i = 1;i<=n;i++){
        for(long int j =1;j<=W;j++){
            if(w[i-1]<=j){
                value[i][j] = max(value[i][j],(v[i-1]+value[i-1][j-w[i-1]]));
            }

            value[i][j] = max(value[i-1][j],value[i][j]);
        }
    }
    cout<<value[n][W];
    
}


















Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


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

	vector<int> h(n);

	for (int i = 0; i < n ; i++) {
		int tmp;
		cin >> tmp;
		h[i] = tmp;
	}
	int count = 0;

	for (int i = 0; i < n; i++) {
		while(h[i] > 0) {
			count++;
			for (int j = i; j < n; j++) {
				if (h[j] <= 0) {
					break;
				}
				h[j] --;
			}
		}
	}
	cout << count << endl;





	return 0;
}

Measured memory_bytes: 384
if __FILE__==$0
	
	r_s=lambda{|str|str.chomp}
	s=r_s[gets]
	a=0; z=0; i=0
	while s[i]!="A" do i+=1 end
	a=i+1
	i=0
	i=s.length-1
	while s[i]!="Z" do i-=1 end
	z=i+1
	p z-a+1
end

Measured memory_bytes: 2172
# 2020/02/09
# AtCoder Beginner Contest 154 - A

# Input
s, t = input().split()
a, b = map(int,input().split())
u = input()

# Calc
if u == s:
    a = a - 1
else:
    b = b - 1

# Output
print(a, b)


Measured memory_bytes: 2940
n, m = map(int, input().split())
inf = 10000000000
mat = [[inf if j!=i else 0 for j in range(i+1)] for i in range(n)]
abcs = [list(map(int, input().split())) for _ in range(m)]
for a, b, c in abcs:
    i, j = max(a, b)-1, min(a, b)-1
    mat[i][j] = min(mat[i][j], c)

for i in range(n):
    for j in range(n):
        for k in range(j):
            mat[j][k] = min(mat[j][k], mat[max(i, j)][min(i, j)]+mat[max(i, k)][min(i, k)])

print(sum(1 for a, b, c in abcs if c > mat[max(a, b)-1][min(a, b)-1]))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
   long n;
   cin>>n;
   long g;
   for(long i = 1;i<= n-1;i++) g+= i;
   cout<<g;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
int A, B;

int calc(int num) {
  int res = 0;
  while (true) {
	res += num % 10;
	num /= 10;
	if (num == 0) break;
  }
  return res;
}

int main() {
  while (cin >> N >> A >> B) {
	long long res = 0;
	for (int i = 1; i <= N; ++i) {
	  int tmp = calc(i);
	  if (tmp >= A && tmp <= B) res += i;
	}
	cout << res << endl;
  }
}





















Measured memory_bytes: 256
from collections import defaultdict
d=defaultdict(int)
n=int(input())
def prime(n):
  if n==2:
    return True
  if n==3:
    return True
  for i in range(2,int((n)**(1/2))+1):
    if n%i==0:
      return False
  return True
plist=[]
for i in range(2,n+1):
  if prime(i):
    plist.append(i)
for i in range(1,1+n):
  num=i
  for j in plist:
    countp=0
    while num%j==0:
      num=num//j
      countp+=1
    d[j]+=countp
ans=1
for i in d:
  ans=(ans*(d[i]+1))%(10**9+7)
print(ans)

Measured memory_bytes: 3444
while (h, w = gets.split.map(&:to_i)).inject(:+) != 0 do
  donut = Array.new
  count = Hash.new(0)
  h.times do
    donut.push(gets.chomp.chars)
  end
  h.times do |y|
    w.times do |x|
      dy = [0, 1, 1, 1, 0, -1, -1, -1]
      dx = [1, 1, 0, -1, -1, -1, 0, 1]
      8.times do |i|
        used = Array.new(h){Array.new(w,false)}
        string = donut[y][x]
        used[y][x] = true
        ny = (y + dy[i]) % h
        nx = (x + dx[i]) % w
        while !used[ny][nx] do
          string += donut[ny][nx]
          count[string] += 1
          used[ny][nx] = true
          ny = (ny + dy[i]) % h
          nx = (nx + dx[i]) % w
        end
      end
    end
  end
  spell = count.select{|key, value| value >= 2}.keys.sort{|v1, v2| v1.size <=> v2.size}
  spell.select!{|v| v.size == spell.last.size}
  puts spell.size >= 1 ? spell.sort.first : 0
end

Measured memory_bytes: 51088
import sys
readline = sys.stdin.readline
from collections import deque
N = int(readline())
G = [[] for i in range(N*N)]
deg = [0]*(N*N)
day = [0]*(N*N)
F = set()
for p in range(N):
    *A, = map(int, readline().split())
    for k in range(N-1):
        A[k] -= 1
    for k in range(N-2):
        i = A[k]+p*N if A[k] < p else p+A[k]*N
        j = A[k+1]+p*N if A[k+1] < p else p+A[k+1]*N
        G[i].append(j)
        deg[j] += 1
    i = A[0]+p*N if A[0] < p else p+A[0]*N
    F.add(i)
que = deque()
for i in F:
    if deg[i] == 0:
        que.append(i)
        day[i] = 1
rest = N*(N-1)//2
while que:
    v = que.popleft()
    rest -= 1
    d = day[v]
    for w in G[v]:
        deg[w] -= 1
        if deg[w] == 0:
            day[w] = day[v] + 1
            que.append(w)
if rest > 0:
    print(-1)
else:
    print(max(day))

Measured memory_bytes: 134680
A = int(input())
B = int(input())
C = int(input())
X = int(input())

def count(A, B, C):
    ans = 0
    for i in range(0, A + 1):
        for j in range(0, B + 1):
            for k in range(0, C + 1):
                tmp = i * 500 + j * 100 + k * 50 
                if tmp == X:
                    ans += 1
    return ans

print(count(A, B, C))

Measured memory_bytes: 3064
// 2014/02/08 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		double x1, y1, x2, y2, x3, y3, xp, yp;
		cin >> x1;
		if(cin.eof())
			break;
		cin >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp;

		double c1 = (x2-x1)*(yp-y2)-(y2-y1)*(xp-x2);
		double c2 = (x3-x2)*(yp-y3)-(y3-y2)*(xp-x3);
		double c3 = (x1-x3)*(yp-y1)-(y1-y3)*(xp-x1);

		if((c1>0.0 && c2>0.0 && c3>0.0) || (c1<0.0 && c2<0.0 && c3<0.0)){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1216
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	str := sc.Text()
	strs := strings.Split(str, " ")
	stack := &Stack{}
	for _, s := range strs {
		if s == "+" {
			a := stack.pop()
			b := stack.pop()
			stack.push(b + a)
		} else if s == "-" {
			a := stack.pop()
			b := stack.pop()
			stack.push(b - a)
		} else if s == "*" {
			a := stack.pop()
			b := stack.pop()
			stack.push(b * a)
		} else {
			num, _ := strconv.Atoi(s)
			stack.push(num)
		}
	}
	fmt.Println(stack.pop())
}

type Stack struct {
	values []int
}

func (s *Stack) push(v int) {
	s.values = append(s.values, v)
}

func (s *Stack) pop() int {
	res := s.values[len(s.values)-1]
	s.values = s.values[:len(s.values)-1]
	return res
}



Measured memory_bytes: 1124
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String str = br.readLine();
    
        while(str != null){
        String[] tempStr = str.split("\\s");
        int n1 = Integer.parseInt(tempStr[0]);
        String op = tempStr[1];
        int n2 = Integer.parseInt(tempStr[2]);

        
            if(!(op.equals("?"))){
                int out = calc(n1,op,n2);
                System.out.println(out);
                str = br.readLine();
            }else{
                break;
            }
        }
       
    }

    public static int calc(int n1,String op,int n2){        

        if(op.equals("+")){
            int ans = n1 + n2;
            return ans;
        }

        if(op.equals("-")){
            int ans = n1 - n2;
            return ans;
        }        

        if(op.equals("*")){
            int ans = n1 * n2;
            return ans;
        }

        if(op.equals("/")){
            int ans = n1 / n2;
            return ans;
        }else{
            return 0;
        }
    }
}

Measured memory_bytes: 24508
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll max_val = max(a, max(b, c)), sum_val = a + b + c;
	sum_val -= max_val;
	repi(i, 0, k) max_val *= 2;
	sum_val += max_val;
	wrln(sum_val);
	return 0;
}


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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }


int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	ll n, A; cin >> n >> A;
	ll ans = n;
	REPU(k, 1, 100) {
		ll res = A * k;
		ll lb = 0, rb = tmin(n, 1000005);
		while (rb - lb > 1) {
			ll mb = (lb + rb) >> 1;
			ll tot = 1; int cnt = 0;
			while (tot < n && cnt < k + 1) tot *= mb, cnt++;
			if (tot >= n) rb = mb;
			else lb = mb;
		}
		ll tot = 1;
		res += (k + 1) * rb;
		REPU(i, 0, k + 1) tot *= rb;
		REPU(i, 0, k + 1) {
			if (tot / rb * (rb - 1) >= n) {
				tot = tot / rb * (rb - 1);
				res--;
			}
		}
		amin(ans, res);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
s=input()+'R' #以下ではRが出てきたときに値を更新しているので最後にRを付け加える
l=len(s)
ans=[0]*(l-1) #すべてのマスの答えを0で初期化
rcnt=0
lcnt=0
rpos=0
lpos=0
flag=0
for i in range(l):
 if s[i]=='R':
   if flag==1: #文字列がLRとなっているとき、直前のRLについて答えを求める
     if rcnt%2==0: #Rの個数が偶数のとき
       ans[rpos]+=rcnt//2
       ans[lpos]+=rcnt//2
     else: #Rの個数が奇数のとき
       ans[rpos]+=rcnt//2+1
       ans[lpos]+=rcnt//2
     if lcnt%2==0: #Lの個数が偶数のとき
       ans[rpos]+=lcnt//2
       ans[lpos]+=lcnt//2
     else: #Lの個数が奇数のとき
       ans[rpos]+=lcnt//2
       ans[lpos]+=lcnt//2+1
     rcnt=0
     lcnt=0
   flag=0
   rcnt+=1 #Rの個数を求める
   rpos=i #右端のRの位置を求める
 elif s[i]=='L':
   if flag==0:
     lpos=i #左端のLの位置を求める
   lcnt+=1 #Lの個数を求める
   flag=1
print(*ans)

Measured memory_bytes: 6400
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

//#include "atcoder/all"
//using namespace atcoder;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n+1, 0);
	rep(i,n) cin >> a[i];
	ll ans = 0;
	rep(i,n){
		ans += a[i]/2;
		if(a[i]%2 == 1){
			if(a[i+1] > 0){
				--a[i+1];
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3960
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
#define MAX 510000
#define MOD 1000000007

ll 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;
}
signed main(){
  init_io();
  COMinit();
  ll h,w,a,b,ans=0,tmp,nh,nw;
  cin >> h >> w >> a >> b;
  h--;
  w--;
  a--;
  b--;
  for(ll i=0;i<h-a;i++){
    tmp = COM(b+i,i);
    nh = h-i;
    nw = w-(b+1);
    tmp *= COM(nh+nw,nw);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 12160
#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)

string mp[40];
string next[40];

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

int main() {
  int w, h, dir;
  for (;;) {
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    rep (i, h) cin >> mp[i];
    rep (time, 180) {
      //rep (i, h) cout << mp[i] << endl;
      //cout << endl;
      rep (i, h) rep (j, w) {
	if (mp[i][j] == 'N') {
	  dir = 0;
	} else if (mp[i][j] == 'W') {
	  dir = 1;
	} else if (mp[i][j] == 'S') {
	  dir = 2;
	} else if (mp[i][j] == 'E') {
	  dir = 3;
	} else {
	  continue;
	}
	rep (k, 4) {
	  if (mp[i + dy[(dir + k) % 4]][j + dx[(dir + k) % 4]] == '.'
	      || mp[i + dy[(dir + k) % 4]][j + dx[(dir + k) % 4]] == 'X') {
	    mp[i][j] = "ENWS"[(dir + k) % 4];
	    break;
	  }
	}
      }
      rep (i, h) next[i] = mp[i];
      rep (i, h) rep (j, w) {
	if (mp[i][j] == '.') {
	  if (mp[i][j + 1] == 'W') {
	    next[i][j] = 'W';
	    next[i][j + 1] = '.';
	    continue;
	  }
	  if (mp[i - 1][j] == 'S') {
	    next[i][j] = 'S';
	    next[i - 1][j] = '.';
	    continue;
	  }
	  if (mp[i][j - 1] == 'E') {
	    next[i][j] = 'E';
	    next[i][j - 1] = '.';
	    continue;
	  }
	  if (mp[i + 1][j] == 'N') {
	    next[i][j] = 'N';
	    next[i + 1][j] = '.';
	    continue;
	  }
	}
	if (mp[i][j] == 'X') {
	  if (j < w - 1 && mp[i][j + 1] == 'W') {
	    next[i][j + 1] = '.';
	    continue;
	  }
	  if (0 < i && mp[i - 1][j] == 'S') {
	    next[i - 1][j] = '.';
	    continue;
	  }
	  if (0 < j && mp[i][j - 1] == 'E') {
	    next[i][j - 1] = '.';
	    continue;
	  }
	  if (i < h - 1 && mp[i + 1][j] == 'N') {
	    next[i + 1][j] = '.';
	    continue;
	  }
	}
      }
      rep (i, h) mp[i] = next[i];
      bool end = true;
      rep (i, h) rep (j, w) {
	if (mp[i][j] == 'N') end = false;
	if (mp[i][j] == 'S') end = false;
	if (mp[i][j] == 'W') end = false;
	if (mp[i][j] == 'E') end = false;
      }
      if (end) {
	cout << time + 1 << endl;
	goto aaa;
      }
    }
    cout << "NA\n";
  aaa:;
  }
}

Measured memory_bytes: 936
N = int(input())
F = [[int(i) for i in input().split()] for j in range(N)]
P = [[int(i) for i in input().split()] for j in range(N)]

Ans = -float("inf")
for i in range(1, 2**10):
    A = list(format(i, "b").zfill(10))
    Index = []
    for j in range(10):
        if A[j] == "1":
            Index.append(j)
    Benefit = 0
    for j in range(N):
        count = 0
        for a in Index:
            if F[j][a] == 1:
                count += 1
        Benefit += P[j][count]
    Ans = max(Ans, Benefit)
print(Ans)

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
    string s = in<string>();
    int N = count(ALL(s), 'N');
    int W = count(ALL(s), 'W');
    int S = count(ALL(s), 'S');
    int E = count(ALL(s), 'E');

    bool l = (W && E) || (W == E);
    bool r = (N && S) || (N == S);

    cout << (l & r ? "Yes" : "No") << endl;


    return 0;
}



Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,m,q;
vector<int>con[100111];
pair<int,pair<int,int> > cmd[100111];
int col[100111][11];
void dfs(int v,int dis,int c)
{
//	cout<<"dfs:"<<v<<" "<<dis<<" "<<c<<endl;
	if(col[v][dis])return;
	for(int i=dis;col[v][i]==0&&i>=0;i--)col[v][i]=c;
	if(dis==0)return;
	for(int i=0;i<con[v].size();i++)
	{
		dfs(con[v][i],dis-1,c);
	}
}
int main()
{
	getii(n,m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		getii(x,y);
		con[x].PB(y);
		con[y].PB(x);
	}
	geti(q);
	for(int i=1;i<=q;i++)
	{
		getiii(cmd[i].FF,cmd[i].SS.FF,cmd[i].SS.SS);
	}
	for(int i=q;i>=1;i--)
	{
		dfs(cmd[i].FF,cmd[i].SS.FF,cmd[i].SS.SS);
	}
	for(int i=1;i<=n;i++)putsi(col[i][0]);
	return 0;
}

Measured memory_bytes: 12024
n=int(input())
a=list(map(int,input().split()))
a.sort()

cnt=[0]*(a[-1]+1)
#cntは0が25個続くリスト
for x in a:
  #xは3,8,11,16,24
 for i in range(x,a[-1]+1,x):
  #x = 3ならrange(3, 25, 3) = 3, 6, 9, 12, 15, 18, 21, 24
  
  cnt[i]+=1
  #xの倍数(xを含む)だったら1が足される
ans=0
for x in a:
 if cnt[x]==1:
  ans+=1
print(ans)

Measured memory_bytes: 32188
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll n;cin>>n;
	double a[n+1];for(ll i=0;i<n;i++)cin>>a[i];
	double sum=0;
	for(ll i=0;i<n;i++)sum+=(1/a[i]);
	cout<<fixed<<setprecision(16)<<1/sum;
}


Measured memory_bytes: 256