akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int k;
    cin >> k;
    int dp[n+1][k+1][2];
    memset(dp , 0 , sizeof(dp));
    dp[0][0][0] = 1;
    dp[0][1][0] = s[0] - '0' - 1;
    dp[0][1][1] = 1;

    for(int i = 1 ; i < n ; i++)
    {
        for(int j = 0 ; j <= k ; j++)
        {
                if(j > 0)
                dp[i][j][0] += dp[i-1][j-1][0] * 9;
                dp[i][j][0] += dp[i-1][j][0];
                if(s[i] > '0'){
                    if(j > 0)
                    dp[i][j][0] += dp[i-1][j-1][1] * (s[i] - '0' - 1);
                    dp[i][j][0] += dp[i-1][j][1];
                }

                if(s[i] == '0')dp[i][j][1] = dp[i-1][j][1];
                else if(j > 0)dp[i][j][1] = dp[i-1][j-1][1];
                // debug(i);
                // debug(j);
                // debug(dp[i][j][0]);
                // debug(dp[i][j][1]);
        }
    }

    cout << dp[n-1][k][0] + dp[n-1][k][1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void solve(){
    int n;
    cin>>n;
    vector<ll> x(n),y(n),p(n);
    auto X=vector(1<<n,vector(n,LLONG_MAX));
    auto Y=vector(1<<n,vector(n,LLONG_MAX));
    fr(i,n) cin>>x[i]>>y[i]>>p[i];
    fr(b,1<<n){
        vector<int> id;
        fr(i,n){
            X[b][i]=abs(x[i]);
            Y[b][i]=abs(y[i]);
            if((b>>i)&1) id.push_back(i);
        }
        fr(i,n) for(auto j:id){
                chmin(X[b][i],abs(x[i]-x[j]));
                chmin(Y[b][i],abs(y[i]-y[j]));
        }
    }
    int n3{1};
    fr(i,n) n3*=3;
    auto ans=vector(n+1,LLONG_MAX);
    fr(b,n3){
        ll tmp{};
        int cnt{n};
        int B{b},bx{},by{};
        fr(i,n){
            if(B%3==1) bx^=1<<i;
            else if(B%3==2) by^=1<<i;
            else --cnt;
            B/=3;
        }
        fr(i,n) tmp+=min(X[bx][i],Y[by][i])*p[i];
        chmin(ans[cnt],tmp);
    }
    for(auto&i:ans) cout<<i<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t{1};
    //cin>>t;
    fr(i,t) solve();
}

Measured memory_bytes: 12944
s=input()
n=len(s)
ans=0
def dfs(i,f):
    global ans
    if i==n-1:
        a=sum(list(map(int,f.split("+"))))
        ans+=a
        return a
    dfs(i+1,f+s[i+1])
    dfs(i+1, f + "+" + s[i+1])
   
dfs(0,s[0])
print(ans)

Measured memory_bytes: 3060
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define rep(i,n) for(LL i=0;i<n;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) ((int)s.size())
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 10000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<int>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;

#pragma endregion


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

void y_n(bool p) {
	if (p)_y();
	else _n();
}

void Y_N(bool p) {
	if (p) _Y();
	else _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}


/************************************************************************/
signed main(void) {
	cin.tie(0); ios::sync_with_stdio(false);

	while (1) {
		int d, e;
		cin >> d >> e;
		if (d == 0 && e == 0)break;
		double ans = INT_INF;
		for (int x = 0; x <= d; x++) {
			int y = d - x;
			ans = min(ans, abs(sqrt(x*x + y * y) - e));
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3260
# coding: utf-8
# Your code here!
ls = []
count = [0]*9
for i in range(3):
    ls.extend(input().split(' '))
for i in range(int(input())):
    s = input()
    if s in ls:
        i = ls.index(s)
        count[i]="1"
flag = 0
for i in range(3):
    if count[i] == count[i+3] == count[i+6]=="1":
        flag = 1
        break
for i in range(0,8,3):
    if count[i] == count[i+1] == count[i+2] == "1":
        flag = 1
        break
if count[0]==count[4]==count[8]=="1":
    flag = 1
if count[2] == count[4] == count[6] == "1":
    flag = 1
if flag == 1:
    print("Yes")
elif flag == 0:
    print("No")

Measured memory_bytes: 3316
import java.util.Scanner;

/**
 *  http://abc047.contest.atcoder.jp/tasks/abc047_b
 * @author おとうさん
 */
public class Main {
    public static void main(String[] args) {
        int W, H, N ;
        Scanner sc = new Scanner(System.in);
        W = sc.nextInt();
        H = sc.nextInt();
        N = sc.nextInt();
        int x[]=new int[N] ;
        int y[]=new int[N] ;
        int a[]=new int[N] ;
        for (int i=0 ; i<N; i++){
            x[i]=sc.nextInt() ;
            y[i]=sc.nextInt() ;
            a[i]=sc.nextInt() ;            
        }
        int x_low, x_high, y_low, y_high ;
        x_high = W ;
        y_high = H ;
        x_low = 0 ;
        y_low = 0 ;
        for (int i=0 ; i<N ;i++) {
            switch (a[i]) {
                case 1 :
                    if (x[i]>x_low) x_low = x[i] ;
                    break ;
                case 2 :
                    if (x_high>x[i]) x_high = x[i] ;
                    break ;
                case 3 :
                    if (y[i]>y_low) y_low = y[i] ;
                    break ;
                case 4 :
                    if (y_high>y[i]) y_high = y[i] ;
                    break ;
            }
        }
        int ans ;
        if (x_high < x_low ) x_high = x_low ;
        if (y_high < y_low ) y_high = y_low ;
        ans = (x_high - x_low) * (y_high - y_low) ;
        if (ans<0) ans = 0 ;
        System.out.println(ans) ;      

    }
    
}


Measured memory_bytes: 10320
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;cin>>n;
  vector<int> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
    sum+=s[i];
  }
  sort(s.begin(),s.end());
  if(sum%10==0){
    for(int i=0;i<n;i++){
      sum-=s[i];
      if(sum%10!=0) break;
      sum+=s[i];
    }
  }
  if(sum%10==0) sum=0;
  cout<<sum<<endl;
}

Measured memory_bytes: 256
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,M = map(int,input().split())
X = list(map(int,input().split()))

if N >= M:
    print(0)
else:
    X.sort()
    D = []
    for i in range(M-1):
        D.append(X[i+1]-X[i])
    D.sort()
    print(sum(D[0:M-N]))

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

typedef long long ll;

int main()
{
  ll k,a,b;
  cin>>k>>a>>b;
  ll mi=min(a,b);
  if(a%k==0 || b%k==0)
  	cout<<"OK";
  else
  {
  	mi=mi-mi%k+k;
    if(mi>=a && mi<=b)
    	cout<<"OK";
    else
    	cout<<"NG";
  }
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main(void){
    long long n=1,k,a,b;
    cin>>k>>a>>b;
    if(a+1<b){
        if(k<=a-1){
            cout<<k+1<<endl;
            return 0;
        }
        n+=a-1;
        k-=a-1;
        n=a;
        n+=(k/2)*(b-a);
        k-=(k/2)*2;
        n+=k;
        cout<<n<<endl;
    }else{
        cout<<k+1<<endl;
    }
    return 0;
}


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

int digsum(int x){
  int sum=0;
  while(x) sum+=x%10,x/=10;
  return sum;
}

int main(){
  int n,a,b; cin >> n >> a >> b;
  long long ans=0;
  for(int i=1;i<=n;++i){
    int tmp=digsum(i);
    if(a<=tmp && tmp<=b) ans+=i;
  }
  cout << ans << endl;
      
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int t[2000],u[2000];
int a[2000000],b[2000000];
int N,M;


int main(){
  int i,j,sum,ans;
  
  while(1){
    scanf("%d %d",&N,&M);
    if(N==0&&M==0)break;
    
    for(i=0;i<2000000;i++){
      a[i]=0;
      b[i]=0;
    }
    
    for(i=0;i<N;i++){
      scanf("%d",&t[i]);
      sum=0;
      for(j=i;j>=0;j--){
        sum+=t[j];
        a[sum]++;
      }
    }
    
    for(i=0;i<M;i++){
      scanf("%d",&u[i]);
      sum=0;
      for(j=i;j>=0;j--){
        sum+=u[j];
        b[sum]++;
      }
    }

    ans=0;
    for(i=0;i<2000000;i++){
      ans+=(a[i]*b[i]);
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 16240
N = int(input())
a = list(map(int, input().split()))

ans = 0
while max(a) >= N:
    for i in range(N):
        if a[i] >= N:
            tmp = a[i] // N
            for j in range(N):
                if j == i:
                    a[j] -= tmp*N
                else:
                    a[j] += tmp
            ans += tmp

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	long long int n,i,j,k=0,z=0;
	cin>>n;
	if(n%2==0)
        {
            z=0;
            while(n%2==0)
            {
                n/=2;
                z++;
            }
            k+=floor((sqrt(1.0+8*z)-1)/2);
        }
	for(i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        {
            z=0;
            while(n%i==0)
            {
                n/=i;
                z++;
            }
            k+=floor((sqrt(1.0+8*z)-1)/2);
        }
    }
    if(n>1)k++;
    cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 3732
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import heapq

n = ni()
a = na()
ls = []

for i in a:
    heapq.heappush(ls,-i)

s = {}
ans = 0

for _ in range(n):
    m = -heapq.heappop(ls)
    if m in s and s[m] > 0:
        s[m] -= 1
        ans += 1
        continue
    dif = 2**m.bit_length()-m
    if dif in s:
        s[dif] += 1
    else:
        s[dif] = 1

print(ans)

Measured memory_bytes: 40368
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int c = int.Parse(input[1]);
    int[][] vertexes = new int[n][];//ここに受け取る
    int[] times = new int[100000];
    int answer = 0;
    for(int i = 0; i < n; i++)
    {
      int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      vertexes[i] = new int[3];
      vertexes[i][0] = nums[0]-1;
      vertexes[i][1] = nums[1]-1;
      vertexes[i][2] = nums[2];
    }
    var sorted = vertexes.OrderBy(a => a[2]).ThenBy(a => a[0]).ToList();

    int tvMemo = sorted[0][2];
    for(int i = sorted[0][0]; i <= sorted[0][1]; i++)
    {
      times[i]++;
    }
    
    for(int i = 1; i < n; i++)
    {
      if(tvMemo == sorted[i][2] && sorted[i-1][1] == sorted[i][0])
      {
        for(int j = sorted[i][0]+1; j <= sorted[i][1]; j++)
        {
          times[j]++;
        }
      }else
      {
        for(int j = sorted[i][0]; j <= sorted[i][1]; j++)
        {
          times[j]++;
        }
      }
      tvMemo = sorted[i][2];
    }

    for(int i = 0; i < 100000; i++)
    {
      answer = Math.Max(answer, times[i]);
    }

		Console.WriteLine(answer);
	}
}


Measured memory_bytes: 29112
d = {}
N = int(input())
p = [int(input()) for i in range(N)]

for i in range(N):
    if((p[i]-1) in d):
        d[p[i]] = d[p[i]-1] + 1
    else:
        d[p[i]] = 1

print(N-max(d.values()))

Measured memory_bytes: 37732
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

int main() {
	int l;
	cin >> l;
	// x + y + z = l
	// (l - (y+z)) * y * z が max
	long double x;
	x = l * 1.0 / 3.0;
	cout << setprecision(30) << x * x * x << endl;

  return 0;
}


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

using namespace std;

int dp[101][501][501];

int roundup(int v){
	return (v + 999) / 1000 * 1000;
}

bool solve(){
  int INF = 5000 * 1000;
  int n;
  cin >> n;
  if (n == 0)
 	return true;
  vector<int> P(n);
  for (auto &p: P) cin >> p;
  for (auto &i: dp){
  	for (auto &j: i){
      for (auto &k: j){
      	k = -INF;
      }
    }
  }
  
  int max_500 = 0;
  dp[0][0][0] = 0;
  
  for (int i = 0; i < n; i++){
    for (int j = 0; j < 501; j++){
      for (int k = 0; k < 501; k++){
        if (dp[i][j][k] < 0) continue;
        dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
        int change = min(dp[i][j][k], 999 - (roundup(P[i]) - P[i]));
        int pay = roundup(P[i]) + change;
        int next = dp[i][j][k] + roundup(P[i]) - P[i];
        if (pay - P[i] >= 500){
          dp[i + 1][j + roundup(P[i]) / 1000][k + 1] = max(dp[i + 1][j + roundup(P[i]) / 1000][k + 1], next - 500);
          max_500 = max(max_500, k + 1);
        }
        else
          dp[i + 1][j + roundup(P[i]) / 1000][k] = max(dp[i + 1][j + roundup(P[i]) / 1000][k] , next);
      }
    }
  }
  
  int ans = INF;
  for (int i = 0; i < 501; i++)
    ans = min(ans, i * 1000 - dp[n][i][max_500] - 500 * max_500);
  
  cout << max_500 << " " << ans << endl;;
  
  return false;
  
  
}

int main(){
	while (true){
    	if (solve())
          break;
    }
}


Measured memory_bytes: 102120
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>();
        NavigableMap<Integer, Integer> map = new TreeMap<>();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            list.add(a);
            min = Math.min(min, a);
            int temp = a - min;
            map.merge(temp, 1, Integer::sum);
        }
        System.out.println(map.lastEntry().getValue());
    }
}

Measured memory_bytes: 52424
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

void print(const char *s) {
    std::cout << s << std::endl;
}

int main(void)
{
    int64_t r, D, x;
    std::cin >> r >> D >> x;

    for (int64_t i = 0; i < 10; ++i) {
        x = r * x - D;
        std::cout << x << std::endl;
    }

    return 0;
}

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

void komekome(int N,string &S,int K){
    char a = S[K-1];
    for(int i=0;i<N;i++){
        if(S[i]!=a){
          S[i]='*';
        }
    }
}
int main(){
    int N,K;
    string S;
    cin >> N >> S >> K;
    komekome(N,S,K);
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N; cin>>N;
  vi ans(N),A(N);
  int memo=0;
  rep(i,0,N) cin>>A[i];
  REP(i,2,N){
    int K=N-i;
    memo=A[K]-memo;
    }
  memo=A[N-1]-memo;
  ans[N-1]=memo/2;
  REP(i,2,N){
    int K=N-i;
    ans[K]=A[K]-ans[K+1];
    }
  rep(i,0,N) cout<<ans[i]*2<<" ";
  cout<<endl;
  }


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	string s;
	ll a=0,b=0;

	cin>>s;

	rep(i,s.size()){
		if(s[i]=='A'){
			a=i;
			break;
		}
	}
	rrep(j,s.size()){
		if(s[j]=='Z'){
			b=j;
			break;
		}
	}
	cout<<b-a+1<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

vector<vector<int> > v;
int x[4] = {1,0,-1,0}, y[4] = {0,1,0,-1};
int h,w;
void bfs(int a, int b){
	if (v[a][b] == 1){
		rep(i,4){
			if (0<=a+y[i] && a+y[i] <= h-1 && 0 <= b+x[i] && b+x[i] <= w-1){
				if (v[a+y[i]][b+x[i]] >= 0) v[a][b] = 0;
				if (v[a+y[i]][b+x[i]] == 1) bfs(a+y[i], b+x[i]);
			}
		}
	}
}
int main(){
	cin >> h >> w;
	rep(i,h){
		string s; cin >> s;
		vector<int> a(w);
		rep(j,w){
			if (s[j]=='#'){
				a[j] = 1;
			}else{
				a[j] = -1;
			}
		}
		v.push_back(a);
	}
	
	rep(i,h)rep(j,w){
		bfs(i,j);
	}
	rep(i,h)rep(j,w){
		if (v[i][j]==1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
 }


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

#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;

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

	sort(a, a + n, greater<int>());

	ll ans = a[0];
	int l = n / 2;
	if (n & 1)
		l++;
	int i = 1;
	for (i ; i < l; i++)
		ans += 2 * (ll)a[i];
	if (n & 1)
		ans -= a[i - 1];

	cout << ans;
}


int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

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

	int t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}




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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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



int main(){
    int N; cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    ll ans=0, mn=LINF;
    int cnt=0;
    bool flag=false;
    for(int i=0; i<N; i++){
        if(A[i] < 0) cnt++;
        if(A[i] == 0) flag=true;
        mn=min(mn, llabs(A[i]));
        ans+=llabs(A[i]);
    }
    if(cnt%2 != 0 && !flag){
        ans-=2*mn;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T> T myCeil(const T a, const T b) { return (a + b - 1) / b; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll xc = b/c - myCeil(a,c) + 1;
    ll xd = b/d - myCeil(a,d) + 1;
    ll cd = lcm(c,d);
    ll xcd = b/cd - myCeil(a,cd) + 1;
    ll ans = (b-a+1) - (xc + xd - xcd);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3588
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let n : usize = get_one();
    let mut coins = Vec::new();
    coins.push(1);
    let mut i = 1;
    while 6_usize.pow(i) < 100000 {
        coins.push(6_usize.pow(i));
        i+=1;
    }
    i = 1;
    while 9_usize.pow(i) < 100000 {
        coins.push(9_usize.pow(i));
        i+=1;
    }
    coins.sort();
    let mut dp = vec!(vec!(0;n+1 as usize);coins.len() as usize);

    for j in 0..(n+1) {
        dp[0][j] = j;
    }
    for k in 1..coins.len() {
        for j in 1..(n+1) {
            //println!("{} {}", k, j);
            if j >= coins[k] {
                dp[k][j] = std::cmp::min(dp[k-1][j], dp[k][j-coins[k]] + 1);
            }
            else {
                dp[k as usize][j] = dp[(k-1)][j];
            }
        }
    }
    //for row in &dp {
    //    println!("{:?}", row);
    //}
    println!("{}", dp[(coins.len()-1) as usize][n as usize]);
}


Measured memory_bytes: 16636
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define nmax 200001
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].insert(b-1); adj[b-1].insert(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].insert(b-1);}

vector<ll> B(nmax,0);

int main() {
    
    ll n,m;
    cin>>n>>m;

    vector<ll> s(n);
    fill_nums(s,n);

    vector<ll> t(m);
    fill_nums(t,m);

    vector<vector<ll>> dp1(m+1, vector<ll>(n+1,0));
    for(int i=0;i<=n;i++)
        dp1[0][i]=1;


    // vector<vector<ll>> dp2 = dp1;

    ll sum = 1;
    for(int i=1;i<=m;i++) {

        for(int j=1;j<=n;j++) {
            if(t[i-1]==s[j-1])
                dp1[i][j] = dp1[i-1][j-1];
            dp1[i][j] = (dp1[i][j]+dp1[i][j-1])%N;
        }

        sum = (sum + dp1[i][n])%N;
        for(int j=1;j<=n;j++) {
            dp1[i][j] = (dp1[i][j]+dp1[i-1][j])%N;
        }
        dp1[i][0]=1;
    }

    cout<<sum<<endl;

    return 0;
}




Measured memory_bytes: 33152
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long int mod= 998244353;
long long int power(long long int x,long long int y)
{
    long long int res=1;
    x%=mod;
    while(y>0)
    {
        if(y&1)
        res=(res*x)%mod;
        y/=2;
        x=(x*x)%mod;
    }
    return res;
}
int main() {
	long int n;
	cin>>n;
	long int a[n];
	long long int b[n+2]={0};
	long int cc=INT_MIN;
	for(long int i=0;i<n;i++)
	{
	cin>>a[i];
	b[a[i]]++;
	cc=max(cc,a[i]);
	}
	if(a[0]!=0 || b[0]>1)
	cout<<"0"<<endl;
	else
	{
	long long int ans=1;
	for(long int i=1;i<=cc;i++)
	{
	   ans=(1ll*ans*power(b[i-1],b[i]))%mod;
	}
	cout<<ans;
	}
	return 0;
}

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

int main() {
	int N;
	string S;
	cin >> N >> S;
	long long ANS = 0;
	long long RS = 0, GS = 0, BS = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') RS++;
		if (S[i] == 'G') GS++;
		if (S[i] == 'B') BS++;
	}
	ANS = RS * GS * BS;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j + i + i < N; j++) {
			if (S[j] != S[i + j] && S[i + j] != S[i + i + j] && S[i + i + j] != S[j]) ANS--;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 3632
{-# LANGUAGE BangPatterns, OverloadedStrings #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  s <- getLine
  [q] <- readInts
  queries <- replicateM q (words <$> getLine) 
  putStrLn $ solve s q queries

solve s q queries = translateQueriesSub False queries "" ""
  where
    translateQueriesSub rev (q:qs) hs ts = if head q == "1"
      then translateQueriesSub (not rev) qs hs ts
      else let f = head $ q !! 1 in let c = head $ q !! 2 in
        if (not rev && f == '1') || (rev && f == '2')
          then translateQueriesSub rev qs (c:hs) ts
          else translateQueriesSub rev qs hs (c:ts)
    translateQueriesSub rev [] hs ts =
      if rev
        then ts ++ (reverse s) ++ (reverse hs)
        else hs ++ s ++ (reverse ts)

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 175740
N, M = map(int,input().split())
s = [list(map(int, input().split())) for _ in range(M)]

road = []
for i in range(M):
    for j in range(2):
        road.append(s[i][j])


for k in range(N):
    ans = 0
    ans = road.count(k+1)
    print(ans)

Measured memory_bytes: 3060
s = input()
t = input()

S = []
T = []
for i in s:
    S.append(i)
for j in t:
    T.append(j)
S = sorted(S)
T = list(reversed(sorted(T)))

a = "".join(S)
b = "".join(T)
if a < b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
N = int(input())
L_X = list(map(int,input().split()))

def answer(n,l):
    ans = 10000000
    tmp = 0
    for i in range(min(l),max(l)+1):
        tmp = 0
        tmp_L = map(lambda x:(x-i)**2,l)
        tmp = sum(tmp_L)
        if ans >= tmp:
            ans = tmp
    return(ans)        
print(answer(N,L_X)) 

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int d[2][100010];
vector <int> v[100010];

void dfs(int a, int x, int depth) {
    if (d[a][x] != -1) return;
    d[a][x] = depth;
    for(auto i : v[x]) {
        dfs(a, i, depth+1);
    }
} 


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a, b;

    rep(i, N-1) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    rep(i, 2) rep(j, N+1) d[i][j] = -1;
    int cnt = 0;
    dfs(0, 1, 0); dfs(1, N, 0);
    rep(i, N) {
        if (d[0][i+1] <= d[1][i+1]) cnt++;
    } 
    if(cnt*2 > N) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

    return 0;
}


Measured memory_bytes: 11264
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String v = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51";
        String[] split = v.split(",");
        System.out.println(split[scan.nextInt()-1]);
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <climits>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, M, j = 0;
	cin >> N >> M;
	vector<long> A(N), a(N);
	for (long& i : A) cin >> i;
	sort(A.begin(), A.end());
	vector<pair<int, long>> BC(M + 1, make_pair(INT_MAX, 0));
	for (int i = 0; i < M; ++i) cin >> BC[i].first >> BC[i].second;
	sort(BC.begin(), BC.end(), [](pair<int, long>& a, pair<int, long>& b)->bool { return a.second > b.second; });
	for (int i = 0; i < N; ++i) {
		if (BC[j].first == 0) ++j;
		--BC[j].first;
		a[i] = BC[j].second;
	}
	long ans = 0;
	for (int i = 0; i < N; ++i) ans += max(A[i], a[i]);
	cout << ans;
}

Measured memory_bytes: 3328
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(cnt: i64, d: i64, x: i64, y: i64) -> String {
    if cnt == 0 {
        assert!(x == 0);
        assert!(y == 0);
        return "".to_string();
    }
    let w = 1i64 << std::cmp::max(d, 0);
    let mut ret;
    let mut nx = x;
    let mut ny = y;
    if x.abs() > y.abs() {
        if x > 0 {
            ret = "R".to_string();
            nx -= w;
        } else {
            ret = "L".to_string();
            nx += w;
        }
    } else {
        if y > 0 {
            ret = "U".to_string();
            ny -= w;
        } else {
            ret = "D".to_string();
            ny += w;
        }
    }
    ret += &calc(cnt - 1, d - 1, nx, ny);
    return ret;
}

fn main() {
    let n = read::<usize>();;
    let mut ps = vec![(0, 0); n];
    let mut flags = 0;
    for i in 0..n {
        ps[i].0 = read::<i64>();
        ps[i].1 = read::<i64>();
        flags |= 1 << (ps[i].0 + ps[i].1).abs() % 2;
    }
    if flags == 3 {
        println!("-1");
        return;
    }
    let cnt: i64 = if flags == 1 { 35 } else { 34 };
    println!("{}", cnt);
    for i in 0..cnt {
        let w = 1i64 << std::cmp::max(0, 31 - i);
        if i != 0 {
            print!(" ");
        }
        print!("{}", w);
    }
    println!("");
    for i in 0..n {
        let ans = calc(cnt, 31, ps[i].0, ps[i].1);
        println!("{}", ans);
    }
}


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


int main (){
    int N, M;
    cin>>N>>M;
    vector<int> Check(M);
    for(int i=0; i<N; i++){
        int K;
        cin>>K;
        vector<int> Ai(K);
        for(int j=0; j<K; j++){
          	cin>>Ai.at(j);
            Check.at(Ai.at(j)-1) ++;
        }
    }
    int Count =0;
    for(int i=0; i<M; i++){
        if(Check.at(i)==N){
            Count ++;
        }
    }
    cout<<Count<<endl;
}

Measured memory_bytes: 256
# coding: utf-8


def bpow(x, y, z):
    a = 1
    for b in format(y, 'b'):
        a = (a*a) % z
        if b == '1':
            a = (a*x) % z
    return a


def solve(*args: str) -> str:
    n, m, k = map(int, args[0].split())
    mod = 998244353

    if m == 1 and n-1 == k:
        return str(1)

    ncr = 1
    p = m*bpow(m-1, n-1, mod) % mod
    ret = p
    inv = bpow(m-1, mod-2, mod)
    for i in range(1, k+1):
        ncr = (ncr * (n-i)*bpow(i, mod-2, mod)) % mod
        p = (p*inv) % mod
        ret += p*ncr % mod

    return str(ret % mod)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main()
{
	int K, X;

	cin >> K >> X;

	if (K == 1)
	{
		cout << X << endl;
	}
	else
	{
		int start = max(-1000000, X - (K - 1));
		int goal = min(X + (K - 1), 1000000);

		for (int i = start; i <= goal; i++)
		{
			cout << i << " ";
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll n;
cin >> n;
ll t[n + 1], x[n + 1], y[n + 1];
t[0] = 0;
x[0] = 0;
y[0] = 0;
for (ll i = 0; i < n; i++) cin >> t[i+1] >> x[i+1] >> y[i+1];
bool flag = true;
for (ll i = 0; i < n; i++) {
    if (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]) > t[i + 1] - t[i]) flag = false;
    if ((t[i + 1] - t[i]) % 2 != (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])) % 2) flag = false;
}
cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 5928
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
ll arr[100000] = {};
ll res[100000] = {};
ll n, m;
ll solve(ll n){
	res[0] = 0;
	res[1] = res[0] + abs(arr[0] - arr[1]);
	for (int i = 2; i < n; i++){
		ll min = 1000000000;
		for (int k = 1; k <= m && k <= i; k++){
			if (res[i - k] + abs(arr[i] - arr[i - k]) < min){
				min = res[i - k] + abs(arr[i] - arr[i - k]);
			}
		}
		res[i] = min;
	}
	return res[n-1];
}
int main(){
	cin >> n>>m;
	for (ll i = 0; i < n; i++){
		cin >> arr[i];
	}
	cout<<solve(n);
	getchar();
	getchar();
	return 0;
}

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

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

using namespace std;

struct Point 
{
    double x, y;
    Point(double x=0, double y=0) : x(x), y(y) {}
    
	double distance (const Point &o) const 
	{
        return sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y));
    }

    Point operator+(const Point &o) const 
	{
        return Point(x+o.x, y+o.y);
    }
 
    Point operator-(const Point &o) const 
	{
        return Point(x-o.x, y-o.y);
    }
 	
    Point operator*(const double m) const 
	{
   	   return Point(x*m, y*m);
    }

    Point operator/(const double d) const 
	{
       return Point(x/d, y/d);
    }

    double cross(const Point &o) const 
	{
       return x * o.y - y * o.x;
    }
 
    double dot(const Point &o) const 
	{
        return x * o.x + y * o.y;
    }
 
    double atan() const 
	{
        return atan2(y, x);
    }

    double norm() const 
	{
        return dot(*this);
    }

	double area_abs(const Point &a,const Point &b) const
	{
		double t = (a.x - x) * (b.y - y);
		double t2 = (a.y - y) * (b.x - x);
		double areas = abs(t-t2);
		return areas/2;
	}

	//符号付き面積
	double area(const Point &a,const Point &b)
	{
		return ((a.x - x) * (b.y - y)) + ((b.x - x) * (y - a.y));
	}
	//線分abが自身の含まれているのかどうか判断する
	int between(const Point &a,const Point &b)
	{
		if(area(a,b) != 0) return 0;

		if(a.x != b.x)
		{
			return ((a.x <= x) && (x <= b.x) || (a.x >= x) && (x >= b.x));
		}
		else
		{
			return ((a.y <= y) && (y <= b.y) || (a.y >= y) && (y >= b.y));
		}
	}
};

//交差しているとき１を返す
int intersect(Point a,Point b,Point c,Point d)
{
	if(c.between(a,b) || d.between(a,b) || a.between(c,d) || b.between(c,d))
	{
		return 1;
	}
	else
	{
		return (c.area(a,b) * d.area(a,b) < 0 && a.area(c,d) * b.area(c,d) < 0);
	}
}


int main()
{
	int n;
	cin >> n;
	vector<Point> p;
	Point k,s;

	rep(i,n)
	{	
		p.clear();
		rep(j,3)
		{
			int x,y;
			cin >> x >> y;
			Point temp(x,y);
			p.push_back(temp);
		}

		int kx,ky,sx,sy;
		cin >> kx >> ky >> sx >> sy;

		k = Point(kx,ky);
		s = Point(sx,sy);
		
		int cnt = 0;
		
		if(intersect(k,s,p[0],p[1]))
		{
			cnt++;
		}

		if(intersect(k,s,p[1],p[2]))
		{
			cnt++;
		}

		if(intersect(k,s,p[0],p[2]))
		{
			cnt++;
		}
		
		if(cnt == 1) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;
int h,w,k;
vector<vector<char>>grid(6,vector<char>(6));
bool check(){
	int cnt=0;
	rep(i,h)rep(j,w){
		if(grid[i][j]=='#'){
			cnt++;
		}
	}
	if(cnt==k){
		return true;
	}
	return false;
}
void solve()
{
	
	cin>>h>>w>>k;
	
	rep(i,h){
		rep(j,w){
			cin>>grid[i][j];
		}		
	}
	vector<vector<char>>init=grid;
	int ans=0;
	rep(i,pow(2,h)){
		rep(j,pow(2,w)){
			grid=init;
			rep(k,h){
				if(i&(1<<k)){
					rep(l,w){
						grid[k][l]='.';
					}
				}
			}
			rep(k,w){
				if(j&(1<<k)){
					rep(l,h){
						grid[l][k]='.';
					}
				}
			}
			if(check()){
				ans++;
			}

		}
	}
	cout<<ans<<endl;


}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 4088
N = int(input())
activity = [[int(i) for i in input().split()] for _ in range(N)]

dp = [[0, 0, 0] for _ in range(100010)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j==k: continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j]+activity[i][k])

print(max(dp[N]))

Measured memory_bytes: 76120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x1,y1,x2,y2;
  int x3,y3,x4,y4;
  int dis;
  cin>>x1>>y1>>x2>>y2;
  x3=x2+(y1-y2);
  x4=x1+(y1-y2);
  y3=y2-(x1-x2);
  y4=y1-(x1-x2);
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::*;
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        k: usize,
    }
    if k % 2 == 0 || k % 5 == 0 {
        println!("-1");
        return;
    }
    let mut s = 7;
    let mut ans = 1;
    while s % k != 0 {
        ans += 1;
        s *= 10;
        s += 7;
        s %= k;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2200
#include<iostream>
#include<array>
#include<algorithm>

int main(){
    
    std::array<size_t, 5> time;
    std::array<size_t, 120> ans = {};

    for(auto&& e : time){
        std::cin >> e;
    }

    std::sort(time.begin(), time.end());

    for(size_t i = 0; i < 120; i++){
        for(size_t j = 0; j < 5; j++){
            ans[i] += time[j];
            while(j != 4 && ans[i] % 10 != 0){
                ans[i]++;
            }
        }
        std::next_permutation(time.begin(), time.end());
    }

    std::cout << *std::min_element(ans.begin(), ans.end()) << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main() {
	ll a; double b;
    cin>>a>>b;
    ll k=b*100+1e-4 ;
  //cout<<k<<endl;
    ll m=(a*k)/100;
    cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 3704
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A);
  rep(i, A) cin >> p[i];
  vector<ll> q(B);
  rep(i, B) cin >> q[i];
  vector<ll> r(C);
  rep(i, C) cin >> r[i];

  std::sort(p.rbegin(), p.rend());
  std::sort(q.rbegin(), q.rend());
  std::sort(r.rbegin(), r.rend());

  ++A; ++B; ++C;

  vector<ll> p_sum(A);
  p_sum[0] = 0;
  srep(i, 1, A) {
    p_sum[i] = p_sum[i-1] + p[i-1];
  }
  vector<ll> q_sum(B);
  q_sum[0] = 0;
  srep(i, 1, B) {
    q_sum[i] = q_sum[i-1] + q[i-1];
  }
  vector<ll> r_sum(C);
  r_sum[0] = 0;
  srep(i, 1, C) {
    r_sum[i] = r_sum[i-1] + r[i-1];
  }

  vector<ll> max_pq(C, 0);
  int x_index {X};
  int y_index {Y};
  max_pq[0] = p_sum[X] + q_sum[Y];
  srep(i, 1, C) {
    if (x_index == 0 && y_index == 0) break;
    if (x_index == 0) {
      --y_index;
      max_pq[i] = p_sum[x_index] + q_sum[y_index];
    } else if (y_index == 0) {
      --x_index;
      max_pq[i] = p_sum[x_index] + q_sum[y_index];
    } else if (p[x_index-1] < q[y_index-1]) {
      --x_index;
      max_pq[i] = p_sum[x_index] + q_sum[y_index];
    } else {
      --y_index;
      max_pq[i] = p_sum[x_index] + q_sum[y_index];
    }
  }
  ll max_answer {};
  rep(i, C) {
    if (X+Y < i) break;
    ll tmp = max_pq[i] + r_sum[i];
    maxs(max_answer, tmp);
  }
  cout << max_answer << '\n';
}


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

bool prime[10000001];

int main(){
    fill_n(prime,10000000,true);
    prime[0]=prime[1]=false;
    for(int i=2;i*i<=10000000;i++){
        if(!prime[i])continue;
        for(int j=2;i*j<10000000;j++)prime[i*j]=false;
    }
    int n;
    while(cin>>n,n){
        for(int i=n;i>0;i--){
            if(prime[i]&&prime[i-2]&&prime[i-6]&&prime[i-8]){
                cout<<i<<endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 10924
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B&lang=jp
// hos?????????????????????????????????
// lowlink????¨??????????????????§??????
// lowlink????¨??????????????????§????????????????????¢?????¨?????????????????????????????§
// http://kagamiz.hatenablog.com/entry/2013/10/05/005213??????????????????
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
vector<int> G[100000];
vector<P> bridge;
vector<int> articulation;
int ord[100000], low[100000];
bool vis[100000];
int v, e, s, t, k;
void dfs(int v, int p, int &k) {
    vis[v] = true;
    ord[v] = k++; low[v] = ord[v];
    bool isArticulation = false;
    int ct = 0;
    for (int i=0; i<G[v].size(); i++) {
        if (!vis[G[v][i]]) {
            ct++;
            dfs(G[v][i], v, k);
            low[v] = min(low[v], low[G[v][i]]);
            if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
            if (ord[v] < low[G[v][i]]) bridge.push_back(P(min(v, G[v][i]), max(v, G[v][i])));
        } else if (G[v][i] != p) {
            low[v] = min(low[v], ord[G[v][i]]);
        }
    }
    if (p == -1 && ct > 1) isArticulation = true;
    if (isArticulation) articulation.push_back(v);
}
int main() {
    scanf("%d%d",&v,&e);
    for (int i=0; i<e; i++) {
        scanf("%d%d",&s,&t);
        G[s].push_back(t); G[t].push_back(s);
    }
    if (v == 1) {
    } else {
        k = 0;
        for (int i=0; i<v; i++) {
            if (!vis[i]) dfs(i, -1, k);
        }
        sort(bridge.begin(), bridge.end());
        for (int i=0; i<bridge.size(); i++) printf("%d %d\n",bridge[i].first, bridge[i].second);
    }
}

Measured memory_bytes: 5192
#include<stdio.h>

int max(int a,int b){
  int r,tmp;
  if(a<b){
   tmp = a;
   a = b;
   b = tmp;
 }
 /* ユークリッドの互除法 */
 r = a % b;
 while(r!=0){
   a = b;
   b = r;
   r = a % b;
 }
 /* 最大公約数を出力 */
 return b;
}

int main(void){
  int a,b,k,i,j;
  scanf("%d%d%d",&a,&b,&k);
  int d=max(a,b);
  for(i=1;i<=k;i++){
    for(j=d;1<=j;j--){
      if(a%j==0 && b%j==0)break;
    }
    d=j-1;
  }
  printf("%d\n",d+1);
  return 0;
}


Measured memory_bytes: 128
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}
int main() {
	int n,p[200005],memo=0,result=0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &p[i]);
		if (p[i] == i) {
			if (memo == 0) {
				memo++;
			}
			else { memo = 0; result++; }
		}
		else {
			if (memo == 0) {
				
			}
			else { result++; memo = 0; }
		}

	}
	if (memo == 1) {
		result++;
	}
	printf("%d", result);
}

Measured memory_bytes: 512