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

using namespace std;

typedef long long int ll;

const int N = 16;
const ll oo = (ll) 1e18;

int n;
ll mat[N][N];
ll val[1 << N];
ll memo[1 << N];

ll dp(int mask) {
    if(mask == 0) return 0;
    ll &ans = memo[mask];
    if(ans != -1) return ans;
    ans = -oo;
    for(int smask = mask; smask > 0; smask = (smask - 1) & mask) {
        ll cur = val[smask] + dp(mask - smask);
        ans = max(ans, cur);
    }
    return ans;
}

void solve() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> mat[i][j];
        }
    }
    for(int mask = 0; mask < 1 << n; ++mask) {
        ll cur = 0;
        for(int i = 0; i < n; ++i) {
            if((mask & (1 << i)) == 0) continue;
            for(int j = i + 1; j < n; ++j) {
                if((mask & (1 << j)) == 0) continue;
                cur += mat[i][j];
            }
        }
        val[mask] = cur;
    }
    memset(memo, -1, sizeof(memo));
    cout << dp((1 << n) - 1) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    solve();
    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

#define N 101

int main(){
  int i, j, k, l, m, n, A[N][N];

  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      A[i][j] = 0;
    }
  }
  for(i = 1; i <= n; i++){
    scanf("%d%d", &l, &m);
    for(j = 1; j <= m; j++){
      scanf("%d", &k);
      A[l][k] = 1; 
    }
  }

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

  return 0;

}

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

int main(){
  
  int n,m;
  cin >> n >>m;
  int k[30]={0},l[30][30]={0};
  
  for(int i=0;i<n; i++){
    cin >> k[i];
  	for(int j=0; j<k[i]; j++) cin >> l[i][j];
  }
  
  int a=0,ans=0;
  for(int i=1; i<=m; i++){
    
    for(int j=0; j<30; j++){
      for(int k=0; k<30; k++){
      	if(l[j][k]==i) a++;
      }
    }
    if(a==n) ans++;
    a=0;
  }
  
cout << ans << endl;  

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}
 
int main() { 
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(s.size() > n) {
        rep(i, n) cout << s[i];
        cout << "..." << endl;
        return 0;
    }
    rep(i, s.size()) cout << s[i];
}

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

int main() {
  int h, w;
  cin >> h >> w;
  
  vector<string> v(h);
  for(int i=0; i<h; i++) cin >> v[i];
  
  vector<bool> tate(h, false);
  vector<bool> yoko(w, false);
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(v[i][j] == '#') {
        tate[i] = true;
        yoko[j] = true;
      }
    }
  }
  
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(tate[i] == true && yoko[j] == true) {
        cout << v[i][j];
      }
    }
    if(tate[i] == true) cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main() {
  const int64_t mod = 1000000007;
  int H,W;
  cin >> H >> W;
  
  vector<string> grid(H);
  for(int i=0;i<H;i++){
    string line;
    cin >> line;
    grid[i] = line;
  }
  
  int64_t dp[1001][1001];
  for(int i=0;i<=H;i++){
    for(int j=0;j<=W;j++){
      dp[i][j] = -1;
    }
  }
  
  dp[1][1] = 1;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(i==1&&j==1){continue;}
      if(grid[i-1][j-1] == '#'){continue;}
      if(dp[i-1][j]>=0 && dp[i][j-1]>=0){
        dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
      } else {
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
      
      //cout << i << "," << j << ":" << dp[i][j] << endl;
    }
  }
  
  dp[H][W] = max(dp[H][W],(int64_t)0);

	cout << dp[H][W] << endl;
	return 0;
}

Measured memory_bytes: 9088
from itertools import product
import numpy as np


def submit():
    n, m, x = map(int, input().split())
    books = {}
    for i in range(n):
        e = list(map(int, input().split()))
        c = e[0]
        books[i] = (c, np.array(e[1:]))

    min_cost = float("inf")
    for pt in product([0, 1], repeat=n):
        curr_cost = 0
        curr_skills = np.zeros(m)
        for i, isbuy in enumerate(pt):
            if isbuy: # book iを買ったことにする
                cost, skills = books[i]
                curr_cost += cost
                curr_skills += skills

            if np.all(curr_skills >= x) and curr_cost < min_cost:
                min_cost = curr_cost

    if min_cost == float("inf"):
        print(-1)
    else:
        print(min_cost)


submit()

    

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

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

using namespace std;
using lint=long long;

int main(){
	lint n,a,b; cin>>n>>a>>b;
	cout<<n/(a+b)*a+min(n%(a+b),a)<<'\n';
	return 0;
}


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

using namespace std;


int main(void) {
  set<int> s;
  int q, command, x;
  cin >> q;

  for(int i = 0; i < q; i++) {
    cin >> command >> x;
    switch(command) {
      case 0:
        s.insert(x);
        cout << s.size() << endl;
        break;
      case 1:
        cout << s.count(x) << endl;
        break;
    }  
  }
  

}


Measured memory_bytes: 12436
# 予めsx, syを全て計算しておく
# このとき漸化式を使えば毎回全ての話を求める必要がない

mod = int(1e9+7)
n, m = [int(num) for num in input().split()]

x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]


sx = [0] * n
sx[0] = x[0]
for i in range(n-1):
    sx[i+1] = sx[i] + x[i+1]
sxd = 0  
for i in range(n-1):
    sxd += ((sx[n-1] - sx[i]) - x[i] * ((n-1) - (i+1) + 1)) #% mod

sy = [0] * m
sy[0] = y[0]
for k in range(m-1):
    sy[k+1] = sy[k] + y[k+1]
syd = 0
for k in range(m-1):
    syd += ((sy[m-1] - sy[k]) - y[k] * ((m-1) - (k+1) + 1)) #% mod

ans = ((sxd % mod) * (syd % mod)) % mod

print(ans)

Measured memory_bytes: 20672
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

struct edge {
    int to, cost;
};

const int N=1e5+5;
int n;
vector<edge> G[N];
int parent[N];
LL depth[N];

void go( int v, int p, LL d ) {
    parent[v]=p;
    depth[v]=d;
    for ( auto e:G[v] ) {
        int u=e.to,w=e.cost;
        if ( u==p ) continue;
        go(u,v,d+w);
    }
}

int main() {
    cin >> n;
    for ( int i=0; i<n-1; i++ ) {
        int a,b,c;
        cin >> a >> b >> c;
        --a; --b;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    int q,k;
    cin >> q >> k;
    --k;
    go(k,-1,0);
    while ( q-- ) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        cout << abs(depth[a]+depth[b]) << '\n';
    }
    return 0;
}


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

int main(){
	string s1 , s2;
	int m , h;
	while(1){
		cin>>s1;
		if(s1=="-") break;
		cin >> m;
		for(int i=0;i<m ; i++){
			cin>>h;
			s2=s1.substr(0,h);
			s1.erase(0,h);
			s1.append(s2);
		}
		cout << s1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, W, K = map(int, readline().split())
C = np.array([list(readline().decode().rstrip()) for _ in range(H)])

ans = 0
for bit_h in range(1, 1 << H):
    b_h = [i for i in range(H) if bit_h & (1 << i)]

    for bit_w in range(1, 1 << W):
        b_w = [i for i in range(W) if bit_w & (1 << i)]
        acc = (C[b_h][:, b_w] == "#").sum()
        if acc == K:
            ans += 1
print(ans)

Measured memory_bytes: 27300
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  bool found = false;
  for(int i=1;i<=9;i++){
  	for(int j=1;j<=9;j++){
  		if(i*j==n){
  			found=true;
  		}
  	}
  }
  if(found){
  	cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
### https://note.nkmk.me/python-union-find/
# 例題
#https://atcoder.jp/contests/practice2/tasks/practice2_a
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n 
    # 各要素の親要素の番号を格納するリスト 
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する

  def find(self, x): # 要素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が属するグループと要素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): # 要素xが属するグループのサイズ（要素数）を返す
    return -self.parents[self.find(x)]

  def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す
    return self.find(x) == self.find(y)

  def members(self, x): # 要素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())

  def all_group_members(self): #{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    #print()での表示用
    #ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す

N, Q = map(int, input().split())
UF = UnionFind(N)
while Q:
  Q -= 1
  t, u, v = input().split()
  u = int(u)
  v = int(v)
  if t == '0':
    UF.union(u, v)
  else:
    if UF.same(u, v):
      print(1)
    else:
      print(0)

Measured memory_bytes: 83356
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll mod = 998244353;
#define int ll
int n, k;
int a[100005], dp[100005];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>k;
    for(int i=1; i<=n; i++) cin>>a[i-1];
   //for(int i=0; i<n; i++) cout<<a[i]<<" "; cout<<endl;
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    //cout<<dp[0]<<" "<<dp[1]<<" ";
    for(int i=2; i<n; i++){
        dp[i]=1e18;
        for(int d=1; d<=min(i, k); d++) dp[i]=min(dp[i], dp[i-d]+abs(a[i]-a[i-d]));
    }
    cout<<dp[n-1];
   // for(int i=0; i<=k; i++) cout<<dp[i]<<" ";
    //cout<<dp[min(n-1, k)];
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int a, b, c, d, e, f, g;
	cin >> a >> b >> c >> d >> e;
	f = a * 60 + b;
	g = c * 60 + d;
	f = g - f;
	f = f - e;
	cout << f;
}

Measured memory_bytes: 3632
a,b,c,x,y = gets.chomp.split(" ").map(&:to_i)
ans = 0

diff = (x-y).abs
min = x > y ? y : x
max_price = x > y ? a : b

if a+b > c*2 then
  ans += min * c*2
else
  ans += min*a + min*b
end

if max_price > c*2 then
  ans += diff * c*2
else
  ans += max_price * diff
end

print ans


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

const int INF =110000;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        int N;
        cin >> N;

        vector<int> a(N),b(N),c(N);
        rep(i,N){cin>>a[i]>>b[i]>>c[i];}

        int dp[100010][3];
        rep(i,N){
                rep(j,3){
                        dp[i][j]=0;
                }
        }

        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];

        rep2(i,1,N){
                dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
                dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
                dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);

        }



        cout << max({dp[N-1][0],dp[N-1][1],dp[N-1][2]}) << endl;

        return 0;
}

Measured memory_bytes: 2560
sx,sy,tx,ty = map(int,input().split())
ans = ''
u = 'U'*(ty-sy)
r = 'R'*(tx-sx)
d = 'D'*(ty-sy)
l = 'L'*(tx-sx+1)
u2 = 'U'*(ty-sy+1)
r2 = 'R'*(tx-sx+1)
d2 = 'D'
r3 = 'R'
d3 = 'D'*(ty-sy+1)
l2 = 'L'*(tx-sx+1)
print(u+r+d+l+u2+r2+d2+r3+d3+l2+'U')

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int N;
vector<vector<int> > edge(200005);
vector<ll> LIS(200005);
vector<ll> A(200005);
int ans[200005];
ll use[200005];
bool fin[200005];

void solve(int u, int v) { // vからuにきた
  int index;
  index = lower_bound(LIS.begin(), LIS.end(), A[u]) - LIS.begin();
  use[u] = LIS[index];
  LIS[index] = A[u];
  index = lower_bound(LIS.begin(), LIS.end(), big) - LIS.begin();
  ans[u] = index;
  fin[u] = true;
  for(int i=0;i<edge[u].size();++i) {
    if(fin[edge[u][i]]==true || edge[u][i]==v) continue;
    solve(edge[u][i], u);
  }
  index = lower_bound(LIS.begin(), LIS.end(), A[u]) - LIS.begin();
  LIS[index] = use[u];
}

int main() {
  for(int i=0;i<200005;++i) LIS[i] = big;
  cin>>N;
  for(int i=0;i<N;++i) cin>>A[i];
  int u, v;
  for(int i=0;i<N-1;++i) {
    cin>>u>>v;
    u--;
    v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  solve(0, -1);
  for(int i=0;i<N;++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 34108
#include<bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i=a;i<(int)b;i++)
int main() 
{
    int w,a,b,l1,l2,r1,r2;
    cin>>w>>a>>b;
    l1=a;
    r1=a+w;
    l2=b;
    r2=b+w;
    if(l2>=l1 && l2<=r1)
     cout<<0;
    else
    {
      if(l2>r1)
       cout<<l2-r1;
      else
      {
        if(r2>=l1 && r2<=r1)
         cout<<0;
        else
        {
          if(l1>r2)
           cout<<l1-r2;
        }
      }
    }
	return 0;
}


Measured memory_bytes: 256
INF = float('inf')

n = int(input())
a = list(map(int, input().split()))

memo = [-1] * n
memo[0] = 0

for i in range(1, n):
    memo[i] = min(abs(a[i] - a[i-1]) + memo[i-1],
                  abs(a[i] - a[i-2]) + memo[i-2] if i - 2 >= 0 else INF)

print(memo[n-1])


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

using namespace std;

int main(){
    long long int x;
    cin>>x;
    long long int cnt=0;
    long long int a=100;
    while(a<x)
    {
        a=a+a/100;
        cnt++;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int K,N;
int A[200010];

signed main(){
	cin>>K>>N;
	REP(i,N){
		cin>>A[i];
	}
	int ans=INF;
	if(N==2){
		cout<<min(A[1]-A[0],K-A[1]+A[0])<<endl;
		return 0;
	}
	for(int i=0;i<N;i++){
		if(i==0){
			ans=min(ans,A[0]+K-A[1]);
			ans=min(ans,A[N-1]-A[0]);
		}
		else if(i==N-1){
			ans=min(ans,K-A[N-1]+A[N-2]);
			ans=min(ans,A[N-1]-A[0]);
		}
		else{
			ans=min(ans,K-A[i]+A[i-1]);
			ans=min(ans,A[i]+K-A[i+1]);
		}
		DEB(ans)END
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    ll n,d;cin>>n>>d;
    ll x[MAX2],y[MAX2];
    d=d*d;
    rep(i,n)cin>>x[i]>>y[i];
    int ans=0;
    rep(i,n){
        if(x[i]*x[i]+y[i]*y[i]<=d)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6708
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    char ans[100][100];
    rep(i,50){
        rep(j,100) ans[i][j]='#';
    }
    rep(i,50){
        rep(j,100) ans[i+50][j]='.';
    }
    
    int a,b;cin>>a>>b;
    a--,b--;
    bool f=true,bf=false;
    for(int i=0;i<100;i+=2){
        for(int j=0;j<100;j+=2){
            if(a==0){
                bf=true;break;
            }
            ans[i][j]='.';a--;
        }
        if(bf) break;
    }
    f=true,bf=false;
    for(int i=99;i>=0;i-=2){
        for(int j=0;j<100;j+=2){
            if(b==0){
                bf=true;break;
            }
            ans[i][j]='#';b--;
        }
        if(bf) break;
    }
    cout<<"100 100"<<endl;
    rep(i,100){
        rep(j,100){
            cout<<ans[i][j];
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll t1,t2;
ll a1,a2;
ll b1,b2;

int main(){
	cin>>t1>>t2;
	cin>>a1>>a2;
	cin>>b1>>b2;
	if(!((a1>b1)^(a2>b2))){
		cout<<0<<endl;
		return 0;
	}
	ll a=a1*t1+a2*t2;
	ll b=b1*t1+b2*t2;
	if(a==b){
		cout<<"infinity"<<endl;
		return 0;
	}
	if(a<b){
		swap(a1,b1);
		swap(a2,b2);
		swap(a,b);
	}
	if(a1>b1&&a2<b2){
		cout<<0<<endl;
		return 0;
	}
	ll s1=b1*t1-a1*t1;
	ll s2=a-b;
	//cout<<s1<<" "<<s2<<endl;
	cout<<(s1/s2)*2-(s1%s2==0)+1<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  int S=0;
  for(int i=0;i<N;i++){
    cin >> V[i];
  }
  for(int i=0;i<N;i++){
    cin >> C[i];
    S+=max(V[i]-C[i],0);
  }
  cout << S <<endl;
}

Measured memory_bytes: 256
#D
import heapq

n,m = map(int,input().split())
L = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(L) #リストをキューに
for _ in range(m):
    a = heapq.heappop(L)
    heapq.heappush(L, (-1)*(-a//2))

print(-sum(L))


Measured memory_bytes: 14180
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
t=input()
ls=len(s)
lt=len(t)
ans=100000
for i in range(ls-lt+1):
    c=0
    for k in range(lt):
        if s[i+k]!=t[k]:
            c+=1
    ans=min(ans,c)
print(ans)


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

#define NIL -2
#define INF 1000000001

using namespace std;
const static int down = -1;
const static int up   = 1;
const static int flat = 0;


int main(){
    stack<int> height_stack;
    stack<pair<int,int> > S2; 
    string str;
    int counter = 0;
    deque<int> ans;
    int sum_area = 0;
    int local_area = 0;
    cin >> str;
    for(int i = 0;i < str.size();i++){
        if(str[i] == '\\') {
            height_stack.push(i);
            S2.push(make_pair(i,0));
        }
        else if(str[i] == '/' && !height_stack.empty()){
            int twin = height_stack.top();height_stack.pop();
            sum_area += i - twin;
            while(true){
                pair<int,int> left = S2.top();S2.pop();
                if(left.second == 0){
                    S2.push(make_pair(left.first,local_area + i-twin));
                    local_area = 0;
                    break;
                }
                local_area += left.second;
            }
        }
    }
    while(!S2.empty()){
        pair<int,int> t = S2.top(); S2.pop();
        if(t.second != 0){
            ans.push_front(t.second);
            counter ++;
        }
    }
    cout << sum_area <<"\n";
    cout << counter ;
    while(!ans.empty()) {
        cout << " " <<ans.front();
        ans.pop_front();
    }
    cout << "\n";
    return 0;   
}



Measured memory_bytes: 3364
while True:
  H, W =map(int,input().split())
  if H == 0 and W == 0:
    break
  print("#" * W)
  for i in range(H - 2):
    print("#","." * (W - 2), "#", end="",sep='')
    print()
  print("#" * W)
  print()


Measured memory_bytes: 5632
p [61, 230, 865, 3247, 12185, 45719, 171531, 643550, 2414454, 9058467, 33985227, 127504505, 478366600, 794717734, 733354121, 261943303, 776803305, 580025381, 51688048, 44657419, 737209731, 604119499, 159693437, 858533109, 639056669, 549054109, 996291083, 531294469, 23314687, 783022045, 855462856, 649970414, 68697295, 409213624, 604356692, 88638656, 978442997, 534833116, 763737161, 785892908, 123883652, 639213333, 181836645, 998121103, 124885216, 501575626, 39816123, 113468411, 799008836, 775465589, 256852905, 664630886, 971550783, 751629411, 51018086, 702530485, 725438992, 696683714, 792638194, 221791721, 149602322, 414054379, 986519078, 981760191, 305799096, 515140586, 406959393, 975058685, 245601370, 324759692, 673385295, 191483611, 570246669, 427196161, 781042769, 569725155, 842176273, 25328739, 847501730, 206282374, 353770801, 323137024, 371653459, 940737264, 123820509, 915711339, 847205021, 252858375, 718889563, 866398347, 738390145, 133009077, 333099663, 170591295, 329869205, 616680192, 597534442, 388130742][gets.to_i-3]

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

char get() {
    string str;
    cin >> str;
    if (str[0] == 'V') exit(0);
    return str[0];
}

char odd_sex;
set<int> already;

void dfs(int l, int r) {
    int mid = (l + r) / 2;
    cout << mid << endl;
    char c = get();
    cerr << l << " " << r << endl;
    if (c == odd_sex ^ mid % 2) dfs(mid + 1, r);
    else dfs(l, mid);
}

int main(void) {
    int N;
    cin >> N;
    cout << 0 << endl;
    odd_sex = get();
    dfs(1, N);
}


Measured memory_bytes: 852
#include<stdio.h>
int main(){
    int a, b, d, r;
    long double f;
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
	f = (long double)a / (long double)b;
    printf("%d %d %Lf\n", d, r, f);
    return 0;
}


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

using namespace std;

int main (){
  int N,t;
  cin >> N;
  vector<int> a(100001);
  int b[] = { 1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049 };
  a[0] = 0;
    for (int i = 1; i <= N; i++) {
        int min = 100000;
        for (int j = 0; j <= 11; j++) {
            if (i >= b[j] && a[i - b[j]] < min) {
                min = a[i - b[j]];
            }
        }
        a[i] = min + 1;
    }
  cout << a[N] << endl;
  return 0;
}

Measured memory_bytes: 640
S = input()

ans = "Yes"
L = []
cnt = 0
for i in range(4):
    if S[i] not in L:
        cnt += 1
    L.append(S[i])
        
if cnt != 2:
    ans ="No"
else:
    for i in range(4):
        if L.count(L[i]) != 2:
            ans = "No"
            break
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
全部転写して調べると300^4

123
456
789

456
789
123

123123
456456
789789
123123
456456
789789

abab
caca
abab
caca

2K*2Kの盤面作ってスライドさしてチェック？
いけるかも
あれ、N^4じゃん
breakあるけど最悪パターンでＴＬＥか
ＷＡはなんだ
どうしよう
ああ、1箇所ＮＧだったら+1+1スライドした場合もＮＧか
1箇所ＯＫだったら、+1+1スライドしたら、スライド箇所だけ調査とか
外側ＮＧだった場合考慮外になる
スライドしても一緒なのか
たしかに比較してる数字いっしょや

*/
int main(){
  ll N; cin>>N;
  ll N2=N*2;
  vector<vector<char>> A(N2,vector<char>(N2,'.'));
  for(ll i=0; i<N; i++){
    for(ll j=0; j<N; j++){
      char c; cin>>c;     
      A[i][j]=c;
      A[i][j+N]=c;
      A[i+N][j]=c;
      A[i+N][j+N]=c;      
    }
  }
  //a始点移動
  ll ans=0;
  for(ll a=0; a<N; a++){
    bool end=false;
    for(ll i=0; i<N; i++){
      for(ll j=i+1; j<N; j++){
        if(A[i][j+a]!=A[j][i+a]){
//cout<<"i:"<<i<<" j:"<<j<<" a:"<<a<<" b:"<<b<<endl;
          end=true;
          break;
        }
      }
      if(end) break;
      if(i==N-1) ans+=N-a;
    }
  }
  //b始点移動
  for(ll b=1; b<N; b++){
    bool end=false;
    for(ll i=0; i<N; i++){
      for(ll j=i+1; j<N; j++){
        if(A[i+b][j]!=A[j+b][i]){
//cout<<"i:"<<i<<" j:"<<j<<" a:"<<a<<" b:"<<b<<endl;
          end=true;
          break;
        }
      }
      if(end) break;
      if(i==N-1) ans+=N-b;        
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4000
#include<iostream>
#include<string>
using namespace std;
bool judge(string s, int num){
    int i, f=0;
    string tmp;
    tmp=to_string(num);
    for(i=0;i<s.size();i++){
        if(num<10){
            if(s[i]=='0' && f==0) f++;
            else if(s[i]=='0' && f==1) f++;
            else if(s[i]==tmp[0] && f==2) f++;
            if(f==3) return true;
        }
        else if(num<100){
            if(s[i]=='0' && f==0) f++;
            else if(s[i]==tmp[0] && f==1) f++;
            else if(s[i]==tmp[1] && f==2) f++;
            if(f==3) return true;  
        }
        else{
            if(s[i]==tmp[0] && f==0) f++;
            else if(s[i]==tmp[1] && f==1) f++;
            else if(s[i] == tmp[2] && f==2) f++;
            if(f==3) return true;
        }
    }
    return false;
}
int main(){
   long long n, i, ans=0;
   string s;
   cin >> n >> s;

   for(i=0;i<=999;i++){
       if(judge(s, i)) ans++;
   }

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

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }



void func(long long K, long long A, long long B){

    REP(i,A,B+1){
        if(i%K==0){
            cout<<"OK"<<endl;
            return;
        }
    }
    cout<<"NG"<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    func(K, A, B);
    return 0;
}


Measured memory_bytes: 3764
#include <stdio.h>
#include <stdlib.h>

int pa, pb, pc;
long long df;

void read(void)
{
    if (scanf("%d %d %d", &pa, &pb, &pc) != 3)
        exit(EXIT_FAILURE);
}

void exec(void)
{
    int sa, sb, sc;
    
    if (pa % 2 == 0 || pb % 2 == 0 || pc % 2 == 0) {
        df = 0;
        return;
    }
    if (pa < pb) {
        if (pb < pc)
            sa = pa, sb = pb, sc = pc;
        else if (pc < pa)
            sa = pc, sb = pa, sc = pb;
        else
            sa = pa, sb = pc, sc = pb;
    } else {
        if (pa < pc)
            sa = pb, sb = pa, sc = pc;
        else if (pc < pb)
            sa = pc, sb = pb, sc = pa;
        else
            sa = pb, sb = pc, sc = pa;
    }
    df = 1LL * sa * sb;
}

void print(void)
{
    printf("%lld\n", df);
}

void repl(void)
{
    read();
    exec();
    print();
}

int main(void)
{
    repl();
    return 0;
}


Measured memory_bytes: 128
from math import ceil, floor
#ceil()  # 切り上げ。常にup
#floor()  # 切り捨て。常にdown
#int()  # 常に0に近く（正負で挙動違う）
#round(f),  round(f, 1)  # 四捨五入（第二引数で小数点桁数を指定）
n = int(input())
l = [int(input()) for _ in range(5)]
print(ceil(n / min(l)) + 4)

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int N=scan.nextInt();
        long[] L=new long[3];
        int i;
        L[0]=2;
        L[1]=1;
        for(i=2;i<=N;i++){
            L[i%3]=L[(i+1)%3]+L[(i+2)%3];
            //System.out.println(L[i%3]);
        }
        System.out.println(L[(i-1)%3]);
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

// common
#define X real()
#define Y imag()

using Vector2 = complex<double>;
using Line = pair<Vector2, Vector2>;
using Segment = pair<Vector2, Vector2>;
const double EPS = 1e-10;
const double PI = 3.14159265359;

bool equals(double a, double b){
    if(abs(a - b) < EPS){
        return true;
    }
    else{
        return false;
    }
}

// struct

struct Circle{
    Vector2 c;
    double r;
    Circle(Vector2 c, double r){
        this->c = c;
        this->r = r;
    }
};

// Vector2
double dot(Vector2 a, Vector2 b){
    return (a.X * b.X + a.Y * b.Y);
}

double cross(Vector2 a, Vector2 b){
    return (a.X * b.Y - a.Y * b.X);
}

double distLP(Line l, Vector2 p){
    return abs(cross(l.second - l.first, p - l.first) / abs(l.second - l.first));
}

// ccw
int ccw(Vector2 p1, Vector2 p2, Vector2 p3){
    Vector2 a = p2 - p1;
    Vector2 b = p3 - p1;
    double dotValue = dot(a, b);
    double crossValue = cross(a, b);
    if(crossValue > EPS) return 1;  // anticlockwise
    if(crossValue < -EPS) return -1;    // clockwise
    if(dotValue < -EPS) return 2;   // p2-p1-p3
    if(norm(a) < norm(b)) return -2;    // p1-p2-p3
    return 0;   // p1-p3-p2
}

// line segment

bool intersect(Segment s1, Segment s2){
    if(ccw(s1.first, s2.first, s2.second) * ccw(s1.second, s2.first, s2.second) > 0){
        return false;
    }
    if(ccw(s2.first, s1.first, s1.second) * ccw(s2.second, s1.first, s1.second) > 0){
        return false;
    }
    return true;
}

double distSP(Segment s, Vector2 p){
    if(dot(s.second - s.first, p - s.first) < 0.0) return abs(p - s.first);
    if(dot(s.first - s.second, p - s.second) < 0.0) return abs(p - s.second);
    return distLP(s, p);
}

double dist(Segment s1, Segment s2){
    if(intersect(s1, s2)){
        return 0.0;
    }
    double a = min(distSP(s1, s2.first), distSP(s1, s2.second));
    double b = min(distSP(s2, s1.first), distSP(s2, s1.second));
    return min(a, b);
}

int main(){

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        Segment s1(Vector2(x0, y0), Vector2(x1, y1));
        Segment s2(Vector2(x2, y2), Vector2(x3, y3));
        double ans = dist(s1, s2);
        cout << fixed << setprecision(9) << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3324
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define P pair<int,int>
using namespace std;

int a;
int c[10000];
P d[10000];
int chain() {
	int sum = 0,k=-1;
	for (int b = 0; b < a; b++) {
		int e = b;
		for (; e < a; e++) {
			if (c[b] != c[e+1])break;
		}
		d[sum] = P(c[b], e-b + 1);
		if (e - b+1 > 3)k = sum;
		b = e;
		sum++;
	}
	if (k == -1)return 0;
	int s = d[k].second;
	for (int p = 1;; p++) {
		if (k - p < 0 || k + p >= sum)break;
		if (d[k - p].first == d[k + p].first&&d[k - p].second + d[k + p].second > 3)s += d[k - p].second + d[k + p].second;
		else break;
	}
	return s;
}
int main() {
	while (cin >> a, a) {
		for (int b = 0; b < a; b++)scanf("%d", &c[b]);
		int MAX = 0;
		for (int e = 0; e < a; e++) {
			for (int f = 1; f <= 3; f++) {
				if (c[e] == f)continue;
				int copy = c[e]; c[e] = f;
				MAX = max(MAX, chain());
				c[e] = copy;
			}
		}
		cout << a - MAX << endl;
	}
}

Measured memory_bytes: 3240
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

#[allow(unused_imports)]
use input::*;

fn main() {
    let (x, t): (usize, usize);
    input!(x, t);
    if t > x {
        p(0);
    } else {
        p(x - t);
    }
}

Measured memory_bytes: 4352
#include<cstdio>
#define min(_a, _b) (_a < (_b) ? _a : (_b))

int N, A, B, P[102], C[3];

void insert(int i)
{
	if(i > A)
	{
		if(i > B)
			C[2]++;
		else 
			C[1]++;
	}
	else
		C[0]++;
	
}
int main()
{
	scanf("%d%d%d", &N, &A, &B);
	for(int i = 1; i <= N; ++i)
	{
		scanf("%d", P + i);
		insert(P[i]);
	}
	int Ans = min(C[0], min(C[1], C[2]));
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, K = MI()
    snuke = [0] * N
    for i in range(K):
        d = II()
        for s in LI1():
            snuke[s] += 1

    ans = 0
    for s in snuke:
        if s == 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 68552
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
process.stdin.on('data', function (chunk) {
    var lines = chunk.toString().split(' ');
    var A = parseInt(lines[0]);
    var B = parseInt(lines[1]);
    
    if(A+B >=10){
        console.log("error");
    }else{
        console.log(A+B);
    }
});

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    string s;
    cin >> s;
    int wcount = 0;
    ll ans =0;

    for(int i=0;i<s.size();i++){
        if(s[i]=='W'){
            ans+=i-wcount;
            wcount++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,K;
    cin >> N >> K;
    if(K > (N-1)*(N-2)/2) {
        cout << -1 << endl;
        return 0;
    }
    int res = 0;
    cout << N-1+((N-1)*(N-2)/2-K) << endl;
    for(int i = 1; i <= N; i++) {
        for(int j = i+1; j <= N; j++) {
            if(res == N-1+((N-1)*(N-2)/2-K)) {
                return 0;
            }
            cout << i << " " << j << endl;
            res++;
        }
    }
}


Measured memory_bytes: 3532
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ld INF = 10e+20;
const ll LIM = 100 * 1000;
const char UNREACHABLE[] = "unreachable";

int solve(void);

struct lll {
	ll from;
	ll from_from;
	ll spd;
};

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

int solve(void)
{
	ll n, m, s, g;
	const ll spd_max = 31;

	cin >> n >> m;
	if(!(n|m)) { return 0; }
	
	cin >> s >> g;

	vector<ll> x(m), y(m), d(m), c(m);
	for(int i = 0; i < m; i++)
	{
		cin >> x[i] >> y[i] >> d[i] >> c[i];
	}
	for (int i = 0; i < m; i++)
	{
		x.push_back(y[i]);
		y.push_back(x[i]);
		d.push_back(d[i]);
		c.push_back(c[i]);
	}
	
	// dp[都市ID][更にひとつ前の都市ID][到着時の速度] = 最小所要時間
	vector<vector<vector<ld>>> dp(n+1, vector<vector<ld>>(n+1, vector<ld>(spd_max, INF)));
	dp[s][s][0] = 0.0f;

	queue<lll> q;
	q.push(lll{s, s, 0});

	while (!q.empty())
	{
		const auto t = q.front();
		q.pop();
		for (int i = 0; i < x.size(); i++)
		{
			if ( x[i] != t.from ) { continue; }
			if ( y[i] == t.from_from ) { continue; }
			for (int j = -1; j <= 1; j++)
			{
				const ll v = j + t.spd;
				if( v <= 0 || v >= spd_max ) { continue; }
				if( v > c[i] ) { continue; }
				const ld arrival_time
					= (ld)(d[i])/(ld)(v) + dp[t.from][t.from_from][t.spd];
				if (arrival_time < dp[y[i]][t.from][v])
				{
					dp[y[i]][t.from][v] = arrival_time;
					q.push(lll{y[i], t.from, v});
				}
			}
		}
	}

	ld ans = INF;
	for(int i = 1; i <= n; i++)
		ans = min(dp[g][i][1], ans);

	if (ans == INF)
	{
		cout << UNREACHABLE << endl;
	}
	else
	{
		cout << fixed << setprecision(12) << ans << endl;
	}

	return 1;
}


Measured memory_bytes: 4012
def mi():return map(int,input().split())
import numpy as np
A,B,M=mi()
a=np.array(list(mi()))
b=np.array(list(mi()))
minab=min(a)+min(b)

ans=float("inf")

for i in range(M):
    x,y,c=mi()
    tmp=a[x-1]+b[y-1]-c
    ans=min(ans,tmp)
print(min(ans,minab))


Measured memory_bytes: 24304
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"2018 218"# => "Yes",
// r#"2763 0"# => "No",
r#"5 3 2"# => "NO",

}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i64,
        b: i64,
    }

    std::cmp::max(std::cmp::max(a + b, a - b), a * b).to_string()
}

Measured memory_bytes: 4352
import numpy as np
import itertools

N, M = map(int, input().split())
L = []
S = [np.array([0 for _ in range(M)]) for _ in range(N)]

for _ in range(M):
  l = list(map(int, input().split()))
  L.append(l)

P = list(map(int, input().split()))
cnt = 0

l = 0
for s in L:
  l += 1
  for i in range(s[0]):
    S[s[1+i]-1][l-1] += 1

for T in itertools.product([1,0], repeat = N):
  Flag = True
  ans = np.zeros(M)
  for i in range(N):
    if T[i] == 1:
      ans += S[i]
  for j in range(M):
    if ans[j] % 2 != P[j]:
      Flag = False
  if Flag:
    cnt += 1

print(cnt)

Measured memory_bytes: 14440