akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>

using namespace std;

#define fi first
#define se second
#define rep(i,n) for(ll i=0; i < (n); ++i)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int dist[100010];
const int INF = 100;

int main() {
	ll K;
	cin >> K;
	rep(i,100010) dist[i] = INF;

	bool src = true;
	priority_queue<pii> q;
	q.push(pii(0,0));
	while(q.size()) {
		pii a = q.top(); q.pop();
		a.fi = -a.fi;
		if(a.fi > dist[a.se])
			continue;

		for(int i = src ? 1 : 0; i < 10; i++) {
			int nex_stat = (a.se + i*K)/10;
			int weight   = (a.se + i*K)%10;
			if(dist[nex_stat] > a.fi + weight) {
				dist[nex_stat] = a.fi + weight;
				q.push(pii(-dist[nex_stat], nex_stat));
			}
		}
		src = false;
	}

	cout << dist[0] << endl;
	return 0;
}


Measured memory_bytes: 9836
#include<bits/stdc++.h>
const int N=25005,mo=1e9+7;
inline int poww(int x,int y){int ans=1;for(;y;y>>=1,x=1ll*x*x%mo)if(y&1)ans=1ll*ans*x%mo;return ans;}
int n,K,m,a[N],i,j,f[N],fac[N],fs[N],mi[N],imi[N],ans,fi,la,lst[405],mx;
bool b[405];
inline int calc(int i,int lm){
	int ans=1ll*mi[i-lm]*fs[i-lm]%mo,j;
	for(j=0;i-j-K>=0 && j<lm;++j)ans=(ans+1ll*f[i-j]*fac[K-(lm-j)])%mo;return ans;
}
int main(){
	scanf("%d%d%d",&n,&K,&m);for(i=1;i<=m;++i)scanf("%d",a+i);
	for(i=2,*mi=*imi=*fac=fac[1]=1,imi[1]=poww(mi[1]=K,mo-2);i<N;++i)
		mi[i]=1ll*mi[i-1]*mi[1]%mo,imi[i]=1ll*imi[i-1]*imi[1]%mo,fac[i]=1ll*fac[i-1]*i%mo;
	for(i=K;i<=n;++i)f[i]=(mi[i-K]+mo-calc(i,K))%mo,fs[i]=(fs[i-1]+1ll*f[i]*imi[i]%mo*fac[K])%mo;
	for(i=1;i<=m && !b[a[i]];b[a[i++]]=1);fi=i-1;memset(b,0,sizeof b);
	for(i=m;i && !b[a[i]];b[a[i--]]=1);la=i+1;
	for(i=1;i<=m;++i){
		mx=std::max(mx,lst[a[i]]),lst[a[i]]=i;
		if(i-mx>=K){printf("%lld\n",1ll*(n-m+1)*mi[n-m]%mo);return 0;}
	}
	if(la==1 && K>m+1)for(i=1;i<=n;++i)for(j=i+K-1;j<=n && j<=i+2*K-m-3;++j)
		ans=(ans+1ll*f[n-(j-K+1)+1]*f[i+K-1]%mo*fac[K-m]%mo*fac[j-i+1-K]%mo*((K-m)-(j-i+1-K)-1))%mo;
	for(i=1;i+m-1<=n;++i){
		int w1=calc(i+fi-1,fi),w2=calc(n-(i+la-1)+1,m-la+1);
		ans=(ans+1ll*w1*mi[n-(i+m-1)]+1ll*w2*mi[i-1]+1ll*(mo-w1)*w2)%mo;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
a = ord('a')

s = [ord(x)-a for x in list(input())]
t = [ord(x)-a for x in list(input())]

n = len(s)
m = len(t)

positions = [[0]*26 for i in range(n+1)]

for i in range(n):
    for j in range(26):
        if j == s[-1-i]:
            positions[-2-i][j] = n-i
        else:
            positions[-2-i][j] = positions[-1-i][j]

roop = 0
p = 0
flag = 1
for i in range(m):
    a = t[i]
    if positions[p][a]==0:
        roop += 1
        p = 0
    p = positions[p][a]
    if p == 0:
        flag = 0
        break

print(roop*n+p if flag else -1)

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

int main() {
  int k;
  string s;

  cin >> k >> s;

  int l = s.size();

  if (k >= l) {
    cout << s << endl;
  } else {
    cout << s.substr(0, k) << "..." << endl;
  }
  

}

Measured memory_bytes: 3628
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i == 0 or i == H - 1:
            print('#' * W)
        else:
            print('#' + '.' * (W - 2) + '#')
    print('')



Measured memory_bytes: 5616
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define SP <<" "<<
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;



int main(){
    int n,W; cin >> n >> W;
    int w[n],v[n];

    rep(i,n){
        cin >> w[i] >> v[i];
    }

    ll dp[n+10][n * 1000 + 10];
    rep(i,n+1) rep(j,n*1000 + 1) dp[i][j] = INF;
    dp[0][0] = 0;

    rep1(i,n){
        rep(j,n*1000 + 1){
            if(j - v[i-1] >= 0){
                dp[i][j] = min(dp[i-1][j] , dp[i-1][j-v[i-1]] + w[i-1]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    int ans = 0;
    
    rep(i,n * 1000 + 1){
        if(dp[n][i] <= W) ans = i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 80896
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
#define inf 1000000000000000
using namespace std;

vector<int> v[100003];
bool vis[100003];
int dp[100003];

void dfs(int s){
  vis[s] = 1;
  if(v[s].size() == 0){
    dp[s] = 0;
  }
  for(auto it: v[s]){
    if(!vis[it]){
      dfs(it);
    }
    dp[s] = max(dp[s], dp[it] + 1);
  }

}

int main()
{
FASTIO
//input_from_file

int n, m;
cin >> n >> m;

for(int i = 0; i < m; i++){
  int x, y;
  cin >> x >> y;
  x--; y--;
  v[x].pb(y);
}

int ans = 0;

for(int i = 0; i < n; ++i){
  if(!vis[i]){
    dfs(i);
  }
  ans = max(ans, dp[i]);
}

cout << ans;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,t;
  cin >> n >>t;
  vector<int> c(n);
  vector<int> ta(n);
  int i;
  for(i = 0;i<n;i++){
    cin >> c[i] >> ta[i];
  }
  int ans = 1001;
  for(i = 0;i<n;i++){
    if(ta[i] <= t){
      if(c[i] < ans){
        ans = c[i];
      }
    }
  }
  if (ans == 1001){
    cout << "TLE" << endl;
  }else{
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n != 0){
			int[][] grid = new int[21][21];
			for(int i = 0; i < n; i++){
				grid[sc.nextInt()][sc.nextInt()]++;
			}
			int cou = 0;
			int m = sc.nextInt();
			int x = 10;
			int y = 10;
			for(int i = 0; i < m; i++){
				String d = sc.next();
				int l = sc.nextInt();
				if(d.equals("N")){
					for(int j = 0; j <= l; j++){
						if(grid[x][y+j]==1){
							cou++;
							grid[x][y+j]=0;
						}
					}
					y+=l;
				}else if(d.equals("S")){
					for(int j = 0; j <= l; j++){
						if(grid[x][y-j]==1){
							cou++;
							grid[x][y-j]=0;
						}
					}
					y-=l;
				}else if(d.equals("E")){
					for(int j = 0; j <= l; j++){
						if(grid[x+j][y]==1){
							cou++;
							grid[x+j][y]=0;
						}
					}
					x+=l;
				}else if(d.equals("W")){
					for(int j = 0; j <= l; j++){
						if(grid[x-j][y]==1){
							cou++;
							grid[x-j][y]=0;
						}
					}
					x-=l;
				}
			}
			System.out.println(cou==n?"Yes":"No");
			n = sc.nextInt();
		}
	}
}



Measured memory_bytes: 42260
void main(){
	int[] box;
	box = _scanln();
	writefln("%d %d %d", box[2], box[0], box[1]);
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2860
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int N;
//素因数分解
map<int,int> primes;
//素因数分解
void PrimeF(int N){
    int M=N;
    for(int i=2;i<sqrt(N)+1;i++){
        int cnt=0;
        while(M%i==0){
            M/=i;
            cnt++;
        }
        if(cnt>0){
            if(primes.find(i)!=primes.end())primes[i]+=cnt;
            else primes[i]=1;
        }
    }
    if(M!=1){
        if(primes.find(M)!=primes.end())primes[M]+=1;
        else primes[M]=1;
    }
    return;
}
signed main(){
    scanf("%lld",&N);
    primes.clear();
    for(int i=1;i<=N;i++){
        PrimeF(i);
    }
    vector<int> nums;
    int up3=0;
    int up5=0;
    int up25=0;
    int up15=0;
    int up75=0;
    for(auto itr=primes.begin();itr!=primes.end();itr++){
        nums.pb(itr->second+1);
        //printf("%lld:%lld\n",itr->first,itr->second);
        if(itr->second+1>=3)up3++;
        if(itr->second+1>=5)up5++;
        if(itr->second+1>=15)up15++;
        if(itr->second+1>=25)up25++;
        if(itr->second+1>=75)up75++;
    }
    int ans=0;
    if(up5>=2&&up3>=3)ans+=up5*(up5-1)/2*(up3-2);//5,5,3
    if(up15>=1&&up5>=2)ans+=up15*(up5-1);//15,5
    if(up25>=1&&up3>=2)ans+=up25*(up3-1);//25,3
    if(up75>=1)ans+=up75;//75
    printf("%lld\n",ans);
}

Measured memory_bytes: 3320
n,k = map(int, input().split( ))
if n==k:
    print(0)
    exit()
h = list(map(int, input().split( )))
#h = [0]+h#h[0]=0追加
inf = 10**15

dp = [[inf]*n for _ in range(n+1)] #dp[i][j]右端がi、j+1本残す
mn = h[0]
for i in range(n):
    #mn = min(mn,h[i])
    dp[i][0] = h[i]#min(mn,h[i])

for i in range(1,n):##右端
    for j in range(i+1):#本数
        for t in range(j-1,i):#右から2番目,
            dp[i][j] = min(dp[i][j], dp[t][j-1] + max(h[i]-h[t], 0))

ans = inf 

for i in range(n):
    ans = min(ans, min(dp[i][n-k-1:]))###
print(ans)


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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

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

  int h,w,hh,ww;
  cin >> h >> w >> hh >> ww;
  cout << h*w - (hh*w + ww * h - hh * ww) << endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i = 0,count = 0;
  char s[100001];
  
  scanf("%s",s);
  
  while(s[i] != '\0'){
    if(s[0] == '0'){
   if((i % 2) == 0){
    if(s[i] != '0'){
     count++;
    }
   }else{
    if((i % 2) == 1){
     if(s[i] != '1'){
      count++;
     }
    }
   }
    }else{
    if((i % 2) == 0){
    if(s[i] != '1'){
     count++;
    }
   }else{
    if((i % 2) == 1){
     if(s[i] != '0'){
      count++;
     }
    }
   }
    }
    i++;
  }
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        a: [i64;n],
    }

    let mut route = a[0].abs() + a[n-1].abs();
    for i in 1..n {
        route += (a[i] - a[i-1]).abs();
    }
    debug!(route);

    println!("{}", route-a[0].abs()-(a[1]-a[0]).abs()+a[1].abs());
    for i in 1..n-1 {
        let route_tmp = route - (a[i]-a[i-1]).abs() -(a[i+1]-a[i]).abs()+ (a[i+1]-a[i-1]).abs();
        println!("{}", route_tmp);
        debug!(route_tmp);
    }
    println!("{}", route-a[n-1].abs()-(a[n-1]-a[n-2]).abs()+a[n-2].abs());
}


Measured memory_bytes: 5160
# -*- coding: utf-8 -*-

def judge_tri(a, b, c):
    if a+b>c and b+c>a and c+a>b:
        return True
    else:
        return False

N = int(input())
L = map(int, input().split())

cnt = 0
L_sort = sorted(L)
for i in range(N):
    for j in range(i+1, N, 1):
        if L_sort[i] != L_sort[j]:
            for k in range(j+1, N, 1):
                if L_sort[i] != L_sort[k] and L_sort[j] != L_sort[k]:
                    if judge_tri(L_sort[i], L_sort[j], L_sort[k]):
                        cnt += 1

print(cnt)

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n,x;cin >> n >>x;
    vl size(n),pat(n);
    size[0]=5;
    pat[0]=3;
    rep(i,n-1){
        size[i+1]=size[i]*2+3;
        pat[i+1]=pat[i]*2+1;
    }
    ll count=n-1,ans=0;
    while(true){
        if(count==0){
            if(x==5||x==4)ans+=3;
            if(x==3)ans+=2;
            if(x==2)ans+=1;
            break;
        }
        if(x==size[count]){
            ans+=pat[count];
            break;
        }
        if(x<size[count]&&x>size[count-1]+2){
            ans+=pat[count-1]+1;
            x-=(size[count-1]+2);
            count--;
            continue;
        }
        if(x==size[count-1]+2){
            ans+=pat[count-1]+1;
            break;
        }
        if(x<size[count-1]+2&&x>1){
            x--;
            count--;
        }
        if(x==1)break;
    }
    cout <<ans <<endl;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int time = -1;
    bool Aarr[110] = {};
    bool Barr[110] = {};
    for (int i = 0; i <= 100; i++) {
        if (A <= i && i <= B) {
            Aarr[i]++;
        }
    }
    for (int i = 0; i <= 100; i++) {
        if (C <= i && i <= D) {
            Barr[i]++;
        }
    }
    for (int i = 0; i <= 100; i++) {
        if (Aarr[i] == 1 && Barr[i] == 1) {
            time++;
        }
    }
    if (time == -1) {
        cout << 0 << endl;
    }
    else {
        cout << time << endl;
    }
}

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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    rep (i, n) {
        int a;
        cin >> a;
        sum += a;
    }
    cout << sum - n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prd(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 2e18+10;
const int Mod = 1e9+7;
const int MAXN = 1000010;
const int N=2e5+10;
const int M=210;
const int M1=1e9+7;
const int M2=1e9+9;
const int base=131;
ll a[N];
int main()
{
  ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  ll sum=0;
  for(int i=2;i<=n;i++)
  {
    if(a[i]>=a[i-1]) continue;
    sum+=(a[i-1]-a[i]);
    a[i]=a[i-1];
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 5164
#include<stdio.h>
int main()
{
    int a;
    int flag;
    while(scanf("%d",&a)!=EOF)
    {
        flag=0;
        while(a!=0)
        {
            if(a%10==9)
            {
                flag=1;
                break;
            }
            a=a/10;
        }
        if(flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  string a, b, c;
  cin >> a >> b >> c;
  int ai = 1;
  int bi = 0;
  int ci = 0;
  char ans;
  
  char ch = a[0];
  
  while(1){
    if(ch == 'a'){
      if(ai == a.length()){
        ans = 'A';
        break;
      }
      ch = a[ai++];
    }else if(ch == 'b'){
      if(bi == b.length()){
        ans = 'B';
        break;
      }
      ch = b[bi++];
    }else{
      if(ci == c.length()){
        ans = 'C';
        break;
      }
      ch = c[ci++];
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
(* O(2^|s| |s|) *)
let s = read_line () in
let slen = String.length s in
let f bits =
  let m = slen - 1 in
  let b = Buffer.create @@ 2 * slen in
  Buffer.add_char b s.[0];
  for i = 1 to m do
    if bits lsr (m - i) land 1 = 1 then Buffer.add_char b '+';
    Buffer.add_char b s.[i];
  done;
  Buffer.to_bytes b |> Bytes.to_string |> Str.split (Str.regexp "+")
  |> List.map int_of_string |> List.fold_left (+) 0 in
Array.init (1 lsl (slen - 1)) f |> Array.fold_left (+) 0 |> Printf.printf "%d\n"

Measured memory_bytes: 3968
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int k = sc.nextInt();
        TreeSet<String> set = new TreeSet<>();
        for (int c = 'a'; c <= 'z'; c++) {
            char ch = (char) c;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == ch) {
                    for (int j = i, x = 0; j < s.length() && x < 5; j++, x++) {
                        set.add(s.substring(i, j + 1));
                    }
                }
            }
            if (set.size() >= k) {
                break;
            }
        }
        set.stream().skip(k-1).findFirst().ifPresent(System.out::println);
    }
}

Measured memory_bytes: 29908
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 300010;
int H,W,M;
int xx[SIZEN],yy[SIZEN];
struct Node{
    int id,num;
    Node(int id,int num){
        this->id = id;
        this->num = num;
    }
    Node(){}
}t1[SIZEN],t2[SIZEN];
int bn[SIZEN];
int bm[SIZEN];
bool ismaxn[SIZEN];
bool ismaxm[SIZEN];
int main(){
    scanf("%d%d%d",&H,&W,&M);
    int mxn = 0,mxm = 0;
    for(int i = 1;i <= M;i++){
        int x,y;scanf("%d%d",&x,&y);
        bn[x]++;
        bm[y]++;
        xx[i] = x;
        yy[i] = y;
        mxn = max(mxn,bn[x]);
        mxm = max(mxm,bm[y]);
    }
    int cntn = 0;
    int cntm = 0;
    for(int i = 1;i <= 300000;i++){
        if(bn[i] == mxn)cntn++;
        if(bm[i] == mxm)cntm++;
    }
    LL total = 1LL*cntn * cntm;
    for(int i = 1;i <= M;i++){
        if(bn[xx[i]] == mxn && bm[yy[i]] == mxm)total--;
    }
    if(total == 0)printf("%d\n",mxn + mxm - 1);
    else printf("%d\n",mxn + mxm);
    return 0;

}

Measured memory_bytes: 6392
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,d,a;
	cin>>n>>d>>a;
	vii v;
	for(ll i=0;i<n;i++){
		ll x,h;
		cin>>x>>h;
		h = ceil((h*1.0)/a);
		v.pb({x,h});
	}
	sort(v.begin(),v.end());
	ll c[n]={},ans=0;
	ll j=0;
	for(ll i=0;i<n;i++){
		while(j<n && v[j].first<=v[i].first+2*d) j++;
		
		ll req;
		req = max(0LL , v[i].second-c[i]);
		ans+=req;
		c[i]+=req;
		c[j]-=req;
		c[i+1]+=c[i];
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6256
#include <iostream>

using namespace std;

int main()
{
	int result = 0;

	int numberOfPerson, turnOffDelay;
	cin >> numberOfPerson >> turnOffDelay;
	
	int lastSwitch = 0;
	for (int i = 0; i < numberOfPerson; i++) {
		int time;
		cin >> time;
		int delta = time - lastSwitch;
		result += delta < turnOffDelay ? delta : turnOffDelay;
		lastSwitch = time;
	}
	result += turnOffDelay;

	cout << result << endl;
	return 0;
}

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

#define  fastIO  ios_base::sync_with_stdio(0); cin.tie(0);
#define  int long long int 
#define  endl '\n'

void solveTestCase()
{
	
	int n,k;
	cin >> n >> k;

	vector<int>v(n);

	for(int &i : v)
		cin >> i;

	sort(v.begin(), v.end());

	int ans = 0;

	for(int i=0; i<k; i++)
		ans += v[i];

	cout << ans << endl;

}

int32_t main()
{

	fastIO

	solveTestCase();

	return 0;

}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, q, cnt, A[N], C[N], M[N];
int main()
{
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++)
        scanf("%d", &A[i]), C[A[i]] ++;
    for (int i = 1; i <= n; i++)
        for (int j = i; j > max(i - C[i], 0); j--)
            M[j] ++;
    for (int i = 1; i <= n; i++)
        if (!M[i])
            cnt ++;
    for (; q; q --)
    {
        int id, a;
        scanf("%d%d", &id, &a);
        C[A[id]] --;
        if (A[id] - C[A[id]] >= 1)
            M[A[id] - C[A[id]]] --, cnt += !M[A[id] - C[A[id]]];
        A[id] = a;
        if (a - C[a] >= 1)
            cnt -= !M[a - C[a]], M[a - C[a]] ++;
        C[a] ++;
        printf("%d\n", cnt);
    }
    return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

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

struct P {
	int y, x;
};
struct B {
	vector<P> p;
	set<int> c;
	int parent;
	char uni;
	int all;
	int xl, xr;
	double m;
	B() {
		all = 0;
		parent = -1;
		m = 0;
		xl = +1e9;
		xr = -1e9;
	}
};

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

int main() {

	int w, h;
	while (cin >> w >> h && w) {
		char p[60][10];
		vector<B> b;
		rep(y, h)rep(x, w) {
			cin >> p[y][x];
		}
		bool use[60][10]; memset(use, 0, sizeof(use));
		function<vector<P>(int, int)> get = [&](int y,int x) {
			if (use[y][x])return vector<P>();
			use[y][x] = true;
			vector<P> ret; ret.push_back(P{ y, x });
			rep(i, 4) {
				int ty = y + dy[i], tx = x + dx[i];
				if (ty >= 0 && tx >= 0 && ty < h && tx < w && p[y][x] == p[ty][tx]) {
					auto tmp = get(ty, tx);
					each(j, tmp) {
						ret.push_back(j);
					}
				}
			}
			return ret;
		};
		rep(y, h)rep(x, w) {
			if (use[y][x] == false && p[y][x] != '.') {
				b.push_back(B());
				b.back().uni = p[y][x];
				b.back().p = get(y, x);
			}
		}
		int n = b.size();
		rep(i, n) rep(j, n)if (i != j) {
			for (auto ip : b[i].p) {
				for (auto jp : b[j].p) {
					if (ip.y == jp.y + 1 && ip.x == jp.x) {
						b[i].c.insert(j);
						b[j].parent = i;
					}
				}
			}
		}
		int root;
		rep(i, n) {
			if (b[i].parent == -1) {
				root = i;
			}
		}

		function<bool(int)> solve = [&](int m) {
			b[m].all = b[m].p.size();

			each(i, b[m].c) {
				if (solve(i) == false)return false;
				b[m].m += b[i].m;
				b[m].all += b[i].all;
			}
			each(i, b[m].p) {
				if (i.y + 1 == h || (p[i.y + 1][i.x] != b[m].uni && p[i.y + 1][i.x] != '.')) {
					b[m].xr = max(b[m].xr, (i.x + 1));
					b[m].xl = min(b[m].xl, (i.x));
				}
				b[m].m += double(i.x + 0.5);
			}
			return b[m].xl * b[m].all < b[m].m && b[m].m < b[m].xr * b[m].all;			
		};

		if (solve(root) == false) {
			cout << "UNSTABLE" << endl;
		}
		else {
			cout << "STABLE" << endl;
		}
	}


	return 0;
}

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

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


Measured memory_bytes: 3140
from copy import deepcopy

S = list(input())
T = list(input())

NS = len(S)
NT = len(T)

lst = []

for i in range(NS - NT + 1): #スタート位置
    # print (i)
    tmp = deepcopy(S)
    flag = True
    for j in range(i):
        if tmp[j] == '?':
            tmp[j] = 'a'
    for j in range(NT):
        if tmp[i + j] == '?':
            tmp[i + j] = T[j]
        elif tmp[i + j] == T[j]:
            continue
        else:
            flag = False
            break
    for j in range(i + NT, NS):
        if tmp[j] == '?':
            tmp[j] = 'a'
    if flag:
        lst.append(''.join(tmp))

lst.sort()

if lst:
    print (lst[0])
else:
    print ('UNRESTORABLE')

Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n; cin >> n;

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

    vector<int> v;
    int cnttemp = 0;
    for(int i=1; i<n; i++){
        cnttemp++;
        if(a[i] != a[i-1]){
            v.push_back(cnttemp);
            cnttemp = 0;
        }
        else if(i == n-1){
            v.push_back(cnttemp+1);
        }
    }

    int cnt = 0;
    for(int i=0; i<v.size(); i++){
        // cout << v[i] << endl;
        cnt += v[i]/2;
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec(n);
    rep(i,n){
        cin>>vec[i];
    }
    sort(vec.begin(),vec.end());
    int minv;
    for(i=0;i+k-1<vec.size();i++){
        if(i==0)minv=vec[i+k-1]-vec[i];
        else{
            minv=min(minv,vec[i+k-1]-vec[i]);
        }
    }
    cout<<minv<<endl;
}

Measured memory_bytes: 640
N=int(input())
s=input()
animals = ["" for _ in range(N)]

def convert(animal):
    if animal == "S":
        return "W"
    else:
        return "S"

def animalOnRight(left,center,sig):
    if center == "S":
        if sig == "o":
            return left
        else:
            return convert(left)
    else:
        if sig == "o":
            return convert(left)
        else:
            return left
for (a0,a1) in [("W","S"),("W","W"),("S","S"),("S","W")]:
    animals[0],animals[1] = (a0,a1)
    for i in range(N-2):
        animals[i+2] = animalOnRight(animals[i],animals[i+1],s[i+1])
        #print(animals)
    satisfied = (animalOnRight(animals[N-2],animals[N-1],s[N-1]) == animals[0]) and (animalOnRight(animals[N-1],animals[0],s[0]) == animals[1])
    if satisfied:
        for char in animals:
            print(char, end='')
        print()
        exit()
print(-1)


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

using namespace std;

int h, w;
vector<string> vs;

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

void dfs(int y, int x, char c) {
    for (int i = 0; i < 4; i++) {
        if (x+dx[i] >= 0 && x+dx[i] < w && y+dy[i] >= 0 && y+dy[i] < h && vs[y+dy[i]][x+dx[i]] == c) {
            vs[y+dy[i]][x+dx[i]] = '-';
            dfs(y+dy[i], x+dx[i], c);
        }
    }
}

int main() {
    while (cin >> h >> w, h|w) {
        vs.clear();
        string input;
        int count = 0;
        for (int i = 0; i < h; i++) {
            cin >> input;
            vs.push_back(input);
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (vs[i][j] != '-') {
                    dfs(i, j, vs[i][j]);
                    count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}

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

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vector <ll> a(m),b(m),c(k),d(k);
    vector <vector <ll>> tomo(n+1),bro(n+1); 
    rep(i,m) {
        cin >> a[i] >> b[i];
        tomo[a[i]].push_back(b[i]);
        tomo[b[i]].push_back(a[i]);
    }
    rep(i,k){
        cin >> c[i] >> d[i];
        bro[c[i]].push_back(d[i]);
        bro[d[i]].push_back(c[i]);
    }

    vector <ll> wa;
    wa.push_back(0);
    ll kau;
    vector <int> syo(n+1,0);
    queue <int> q;
    ll syozo;
    syozo=0;
    ll l;
    ll qq;

    rep(i,n){
        
        if (syo[i+1]!=0){
            continue;
        }
        else{
            ++syozo;
        syo[i+1]=syozo;
        kau=1;
        q.push(i+1);
        while(q.size()!=0){
            qq=q.front();
            q.pop();
            l=tomo[qq].size();
            rep(j,l){
            if(syo[tomo[qq][j]]==0){
                syo[tomo[qq][j]]=syozo;
                q.push(tomo[qq][j]);
                ++kau;
            }
            }
        }
        wa.push_back(kau);
    }
    }
    
    int ans;
    rep(i,n){
        ans=wa[syo[i+1]]-tomo[i+1].size()-1;
        rep(j,bro[i+1].size()){
            if(syo[i+1]==syo[bro[i+1][j]]){
                --ans;
            }
        }
        printf("%d%c",ans,i==n-1?'\n':' ');
    }
    

    return 0;
}

Measured memory_bytes: 16884
S = input()
T = input()
ls = len(S)
lt = len(T)

ans = float("inf")
for i in range(0,ls-lt+1):
  cnt = 0
  for j in range(lt):
    if T[j] != S[i+j]:
      cnt += 1
  ans = min(ans, cnt)
  
print(ans)

Measured memory_bytes: 9112
// <------------- Template -----------------------> //

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

#pragma optimization_level 3   									//Comment optimisations for an interatcive problem - use endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

// <------------- Declare Variables Here ------------> //

ll n,m;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

int main() {
	fastio;
	cin>>n>>m;
	if(n==m) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
from itertools import permutations as perm


def inpl():
    return list(map(int, input().split()))


N = int(input())
P = tuple(inpl())
Q = tuple(inpl())

A = list(perm([i for i in range(1, N + 1)]))
A.sort()

for i, a in enumerate(A):
    # print(a)
    if a == P:
        p = i
    if a == Q:
        q = i

print(abs(p - q))


Measured memory_bytes: 8052
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   long sum = 0;
	   int a = sc.nextInt();
	   int[] c = new int[10000];
	   for(int i = 0; i < a; i++) {
	       c[i] = sc.nextInt();
	   }
	   
	   int max = c[0];
	   int min = c[0];
	  
	   for (int i = 0; i < a; i++) {
	        sum += c[i];
	        if (min > c[i]) {
	        	min = c[i];
	        } else if (max < c[i]) {
	        	max = c[i];
	        }
	     }
       System.out.printf("%d %d %d\n", min, max, sum);
   }
}


Measured memory_bytes: 41436
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

main = do
  n <- readLn :: IO Int
  a <- getIntListBC
  let b = sort $ zip a [1..n]
      c = sort $ zipWith (\(x, y) z -> abs $ y-z) b [1..n]
  print $ flip div 2 . sum . map (flip mod 2) $ c

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.lines <$> BC.getContents

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int H, W; scanf("%d %d", &H, &W);

	vector<string> C(H);
	REP(i,H){
		cin >> C[i];
	}

	REP(i,H){
		REP(j,2){
			cout << C[i] << endl;
		}
	}
	


	return 0;

}


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

int main(){
	long n, a, b;
	scanf("%ld%ld%ld", &n, &a, &b);
	long q = n / (a + b);
	long r = n % (a + b);
	printf("%ld\n", a * q + (r <= a ? r : a));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
ll mod=1e9+7;
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}
ll toll(string s){
	ll a=0;
	rep(i,s.size()) a=(a*10+s[i]-'0')%mod;
	return a;
}
ll calc(string s,string t){
	ll ret=0;
	int S=s.size(),T=t.size();
	ll p10=1;
	rep(i,S-T+1){
		string sub=s.substr(S-T-i,T);
		ll low=toll(s.substr(S-i)),up=toll(s.substr(0,S-T-i));
		if(t=="0") up--;
		if(sub<t){
			add(ret,up*p10);
		}else if(sub==t){
			add(ret,up*p10+low+1);
		}else{
			add(ret,(up+1)*p10);
		}
		p10=p10*10%mod;
	}
	if(t=="0") ret++;
	return ret;
}
int main(){
	string A,B,C;
	cin>>A>>B>>C;
	ll ret=calc(B,C);
	if(A!="0"){
		int I=A.size()-1;
		while(A[I]=='0'){
			A[I]='9';
			I--;
		}
		A[I]--;
		ret-=calc(A,C);
	}
	cout<<(ret+mod)%mod<<endl;
}

Measured memory_bytes: 1252
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();
        if (e - a <= k) {
            System.out.println("Yay!");
        } else {
            System.out.println(":(");
        }
    }

}


Measured memory_bytes: 21716
import sys

"""テンプレ"""

# 高速
input = sys.stdin.readline

# 1行を空白でリストにする(int)
def intline():
    return list(map(int, input().split()))


# 上のstrヴァージョン
def strline():
    return list(map(str, input().split()))


# 1列に並んだ数
def intlines(n):
    return [int(input() for _ in range(n))]


# 上の文字列ヴァージョン
def lines(n):
    return [input() for _ in range(n)]
    

"""ここからメインコード"""

a, b, _ = intline()
print(a * b // 2)

Measured memory_bytes: 3316
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null)
    for{
      in <- inputs
      val Array(a, b) = in.split(" ").map(_.toInt)
    }(a, b) match {
      case (0,  0) =>
      case (a,  b) if a <= b => println(s"$a $b")
      case (a,  b) if a > b => println(s"$b $a")
    }
  }
}

Measured memory_bytes: 49424
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map_as(H, replace={'#': 1, '.': 0}, pad=None):
    '''
    文字列のmapを置換して読み込み。デフォでは#→1,.→0
    '''
    if pad is None:
        ret = []
        for _ in range(H):
            ret.append([replace[s] for s in read()[:-1]])
            # 内包表記はpypyでは若干遅いことに注意
            # #numpy使うだろうからこれを残しておくけど
    else:  # paddingする
        ret = [[pad] * (W + 2)]  # Wはどっかで定義しておくことに注意
        for _ in range(H):
            ret.append([pad] + [replace[s] for s in read()[:-1]] + [pad])
        ret.append([pad] * (W + 2))

    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


H, W, K = ints()

import numpy as np
C = np.array(read_map_as(H))
ans = 0
for rows in product(range(2), repeat=H):
    C_r = C.copy()
    for i, tf in enu(rows):
        if tf:
            C_r[i, :] = 0
    for cols in product(range(2), repeat=W):
        C_rc = C_r.copy()
        for j, tf in enu(cols):
            if tf:
                C_rc[:, j] = 0
        ans += (C_rc.sum() == K)
print(ans)


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111
#define MOD 1000000007

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

ll fact[N] ;

int main() {
  fact[1] = 1 ;
  for(ll i = 2 ;i<=100005 ; i++)
    fact[i] = (fact[i-1]*i)%MOD ;

  ll n, m , ans ;
  scanf("%lld %lld", &n, &m) ;

  if(m>n) swap(n,m) ;
  if(n-1>m){
    printf("0") ;
    return 0 ;
  }
  ans = fact[n] ;

  for(int i = m ;i>(m-n+1) ; i--)
    ans = (ans*i)%MOD ;
 
  if(n==m) ans = (ans*2)%MOD ;
  printf("%lld", ans) ;
	
  return 0 ;
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init, ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T>& v) {
	T ans = -INF;
	rep(i, 0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C & c, std::ostream & os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll n, m, x, y, t, q, s,k;

int main() {
	cin >> n;
	vl a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vl puras, minas;
	rep(i, 0, n) {
		if (a[i] < 0) {
			minas.push_back(a[i]);
		}
		else {
			puras.push_back(a[i]);
		}
	}
	if (puras.size() == 0) {
		ll tmp = minas.back();
		minas.pop_back();
		puras.push_back(tmp);
	}
	else if (minas.size() == 0) {
		swap(puras.back(), puras.front());
		ll tmp = puras.back();
		puras.pop_back();
		minas.push_back(tmp);
	}
	ll M = 0;
	rep(i, 0, puras.size()) {
		M += puras[i];
	}
	rep(i, 0, minas.size()) {
		M -= minas[i];
	}
	printf("%lld\n", M);
	ll ref = minas.back();
	minas.pop_back();
	ll tmp = puras.size() - 1;
	rep(i, 0, tmp) {
		printf("%lld %lld\n", ref, puras.back());
		ref -= puras.back();
		puras.pop_back();
	}
	printf("%lld %lld\n", puras.back(), ref);
	ref = puras.back() - ref;
	tmp = minas.size();
	rep(i, 0, tmp) {
		printf("%lld %lld\n", ref, minas.back());
		ref -= minas.back();
		minas.pop_back();
	}
}

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

int main(){
	int w,h,x,y,r;
	
	cin >>w>>h>>x>>y>>r;
	
	if(x+r>w || x-r<0 || y+r>h || y-r<0){
		cout << "No" <<endl;
	}else{
		cout << "Yes" <<endl;
	}
	
}

Measured memory_bytes: 1156
#include <iostream>
#include <queue>

int main() {
    auto k = 0;
    std::cin >> k;

    if (k < 10) {
        std::cout << k << std::endl;
        return 0;
    }

    auto q = std::queue<std::uint64_t>();
    for (auto i = 1; i <= 9; ++i) q.emplace(i);

    auto counter = 9;
    while (!q.empty()) {
        auto n = q.front();
        q.pop();

        auto n_last = n % 10;

        if (n_last > 0) {
            q.emplace(n * 10 + n_last - 1);
            counter++;
            if (counter == k) {
                std::cout << q.back() << std::endl;
                break;
            }
        }

        q.emplace(n * 10 + n_last);
        counter++;
        if (counter == k) {
            std::cout << q.back() << std::endl;
            break;
        }

        if (n_last < 9) {
            q.emplace(n * 10 + n_last + 1);
            counter++;
            if (counter == k) {
                std::cout << q.back() << std::endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3672
#inport
import sys
import numpy as np
from collections import deque


#input
N,M,X = [int(x) for x in sys.stdin.readline().split()]

g = np.zeros([N,M+1])
for _ in range(N):
    g[_] = [int(x) for x in sys.stdin.readline().split()]

g_split = np.split(g, [1], 1)

money = -1

#bit全数検査
for i in range(2**N):
    #ケースループ毎の初期化
    money_tmp = 0 #お金
    skill_tmp = np.zeros(M) #スキル
    for j in range(N):
        if(( i >> j ) & 1):
            #bitが立っているときの処理
            money_tmp = money_tmp + g_split[0][j]
            skill_tmp = skill_tmp + g_split[1][j]
    #ケース積算終了後の処理
    #スキルが条件を満たしているかの判定
    if np.all(skill_tmp >= X):
        if money == -1:
            money = int(money_tmp[0])
        elif money > money_tmp:
            money = int(money_tmp[0])

print(money)


Measured memory_bytes: 27236
#include<iostream>
using namespace std;
int n,p[2<<17];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a;cin>>a;
		p[a-1]=i;
	}
	int ans=1,now=1;
	for(int i=1;i<n;i++)
	{
		if(p[i]>p[i-1])now++;
		else ans=ans<now?now:ans,now=1;
	}
	ans=ans<now?now:ans;
	cout<<n-ans<<endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#define Fr(i,a,b) for(int i=(a);i<=(int)(b);++i)
#define Dr(i,a,b) for(int i=(a);i>=(int)(b);--i)
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
#define bug(x) cout<<#x<<'='<<x<<" "
#define debug(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
const int M=100005,Mo=1e9+7;
int n;
char s[M];
int cnt[27];
int main() {
	cin>>n>>s+1;
	Fr(i,1,n)cnt[s[i]-'a']++;
	ll ans=1;
	Fr(i,0,25)ans=ans*(cnt[i]+1),ans%=Mo;
	printf("%lld\n",((ans-1)%Mo+Mo)%Mo);
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s; cin >> s;

    int n = s.size();

    int a = -1;
    int b = -1;

    rep(i, n-2){
        if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2]){
            a = i+1;
            b = i+3;
            break;
        }
    }

    if(n >= 3){
        cout << a << " " << b << endl;
    }
    else{
        if(s[0] == s[1]){
            cout << 1 << " " << 2 << endl;
        }
        else{
            cout << -1 << " " << -1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int BIG = 2e9 + 55;

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

    ll a, b, c, k; cin >> a >> b >> c >> k;
    ll delta = 0;

    if(k % 2){
        delta = -1;
    } else {
        delta = 1;
    }

    ll diff = a * delta - b * delta;

    if(diff > INF){
        cout << "Unfair\n";
        return 0;
    }

    cout << diff << '\n';

    return 0;
}


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

#define MAX 100010

int N;
long long A[MAX];
 
int main(){
  long long answer = 0, lower = 1LL;
  cin >> N;
  for(int i=0;i<N;++i) cin >> A[i];

  for(int i=0;i<N;++i) {
    if( lower == 1LL ) {
      answer += (A[i]-1LL);
      lower = 2LL;
      continue;
    }
    
    if( lower == A[i] ) {
      ++lower;
      continue;
    }
 
    if( lower > A[i] ) continue;    
 
    long long coef = A[i] / lower;
    if( ( A[i] - coef * lower ) == 0LL ) {
      --coef;
    }
    answer += coef;
  }
  cout << answer << endl; 
  return 0;
}


Measured memory_bytes: 1152