akhauriyash/Code-Regression huggingface dataset:
N=int(input())
import sys
sys.setrecursionlimit(10**6)
T=[[] for _ in range(N)]
for i in range(N-1):
    a,b,c=map(int, input().split())
    T[a-1].append((b-1,c))
    T[b-1].append((a-1,c))

Q,K=map(int, input().split())
D=[-1]*N
D[K-1]=0
def dfs(start, nowd):
    to=T[start]
    for t in to:
        next_node,c=t
        if D[next_node]!=-1:
            continue
        nextd=nowd+c
        D[next_node]=nextd
        dfs(next_node, nextd)
dfs(K-1,0)
for i in range(Q):
    x,y=map(int, input().split())
    print(D[x-1]+D[y-1])


Measured memory_bytes: 136160
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int[] scores = new int[n];

			int sum = 0;
			for(int i = 0;i < n;i++){
				scores[i] = sc.nextInt();
				//System.out.print(i + " : ");
				//System.out.println(scores[i]);
				sum += scores[i];
			}

			double ave = (double) sum / n;
			//System.out.println("ave : " + ave);

			double a2 = 0;
			for(int i = 0;i < n;i++){
				a2 += (scores[i] - ave) * (scores[i] - ave);
			}
			a2 /= n;
			double a = Math.sqrt(a2);

			System.out.printf("%.8f\n", a);
		}
		//System.out.println();
	}
}


Measured memory_bytes: 31688
import copy

def count(w,h):
    Dtemp = copy.deepcopy(Data)

    for i in range(W):
        if ((1 << i) & w) != 0:
            for hh in range(H):
                Dtemp[hh][i] = 'R'
    for i in range(H):
        if ((1 << i) & h) != 0:
            for ww in range(W):
                Dtemp[i][ww] = 'R'
    c = 0
    for hh in range(H):
        for ww in range(W):
            if Dtemp[hh][ww] == '#':
                c += 1
    return c

H,W,K = map(int,input().split())
Data = []
for _ in range(H):
    s = input()
    l = []
    for c in s:
        l.append(c)
    Data.append(l)

ans = 0
for w in range(0,2**W):
    for h in range(0,2**H):
        if count(w,h) == K:
            ans += 1
print(ans)

Measured memory_bytes: 9276
def main():
    A, B = map(int, input().split())
    A = (A-2) % 13
    B = (B-2) % 13
    if A > B:
        print("Alice")
    elif A < B:
        print("Bob")
    else:
        print("Draw")


if __name__ == "__main__":
    main()


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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<int> numa(n+1, 0), numb(n+1, 0);
    for(int i=0; i<n; i++){
        cin >> a[i];
        numa[a[i]]++;
    }
    for(int i=0; i<n; i++){
        cin >> b[i];
        numb[b[i]]++;
    }
    reverse(b.begin(), b.end());

    for(int i=0; i<n; i++){
        if(a[i] == b[i]){
            int j;
            if(numa[a[i]] + numb[b[i]] > n){
                cout << "No" << endl;
                return 0;
            }
            if(i % 2 == 0){
                for(j=0; j<n; j++){
                    if(i == j) continue;
                    if(a[i] != a[j] && a[i] != b[j]){
                        swap(b[i], b[j]);
                        break;
                    }
                }
            }
            else{
                for(j=n-1; j>=0; j--){
                    if(i == j) continue;
                    if(a[i] != a[j] && a[i] != b[j]){
                        swap(b[i], b[j]);
                        break;
                    }
                }
            }
        }
    }
    cout << "Yes" << endl;
    for(int i=0; i<n-1; i++){
        cout << b[i] << " ";
    }
    cout << b[n-1] << endl;

    return 0;
}

Measured memory_bytes: 9588
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
int change(char a){
    if(a=='J')return 77;
    if(a=='O')return 43;
    return 23;
}
int changenan(int a){
    if(a==7)return 0;
    if(a==6)return 77;
    if(a==5)return 43;
    if(a==4)return 23;
    if(a==3)return (77|43);
    if(a==2)return (77|23);
    if(a==1)return (43|23);
    return ((77|43)|23);
}
int main(){
    int n;
    string sc;
    scanf("%d",&n);
    cin >> sc;
    int dp[8][1001]={0};
    int hk=77,imp,in;
    imp=change(sc[0]);
    in=hk&imp;
    for(int i=7;0<=i;i--){
        if((in&(1<<i))!=0)
            dp[i][0]=1;
    }
    for(int i=1;i<sc.size();i++){
        for(int j=7;0<=j;j--){
            if(dp[j][i-1]!=0){
                hk=changenan(j);
                imp=change(sc[i]);
                in=(hk&imp);
                for(int k=7;0<=k;k--){
                    if((in&(1<<k))!=0){
                    dp[k][i]+=dp[j][i-1];
                    dp[k][i]%=10007;
                    }
                }
            }
        }
    }
    int ans=0;
    for(int i=0;i<8;i++)
        ans+=dp[i][sc.size()-1];
    printf("%d\n",ans%10007);
    return 0;
}

Measured memory_bytes: 1268
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i64 = input();
    let b: i64 = input();
    let c: i64 = input();
    let k: u32 = input();

    let max = std::cmp::max(std::cmp::max(a, b), c);
    println!("{}", a + b + c + max * (2i64.pow(k) - 1));
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"

using namespace std;

int main() {
    /*int a,b,h,s;
    cin >> a >> b >> h;
    
    s=(a+b)*h/2;
    
    cout << s << endl;*/
    
    /*int N,A,B;
    cin >> N >> A;
    B=N*N-A;
    
    cout << B << endl;*/
    
   /* int A,B,C,D,s1,s2;
    cin >> A >> B >> C >> D;
    
    s1=A*B;
    s2=C*D;
    
    if(s1>s2){
        cout << s1 << endl;
    }
    else if(s1<s2){
        cout << s2 << endl;
    }
    else{
        cout << s1 << endl;
    }*/
    
   /* int a,b,c,s;
    cin >> a >> b >> c;
    
    s=0;
    if(a!=b){
        s=s+1;
    }
    if(a!=c){
        s=s+1;
    }
    if(b!=c){
        s=s+1;
    }
    if(a==b&&a==c&&b==c){
        s++;
    }
    cout << s << endl;*/
    
    /*int N,K,X,Y,s;
    cin >> N >> K >> X >> Y;
    
    if(N>K){
        s=K*X+Y*(N-K);
    }
    
    
    
    else if(N<=K){
        s=N*X;
    }
    
    cout << s << endl;*/
    
   /* long long N,A[200000],B[200000],s;
    cin >> N;
    
    int i = 0;
    while(i<N){
        cin >> A[i] >> B[i];
        i++;
    }
    
    i=0;
    while(i
    <N){
        s=A[i]*B[i];
        i++;
        cout << s << endl;
    }*/
    
    /* N,A,B,ans;
    cin >> N;
    
    for(int i=0;i<N;i++){
        
    }*/

    int N,L,maxL,sumL;
    cin >> N;
    
    maxL=0;
    sumL=0;
    for(int i=0;i<N; i++){
        cin >> L;
        maxL=max(L,maxL);
        sumL+=L;
    }
    if(maxL<sumL-maxL){
        cout << "Yes" << endl;
    }
    else if(maxL>=sumL-maxL){
        cout << "No" << endl;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  
  val result = (0 until n).foldLeft((0, 0)){ (acc, i) =>
    val Array(t, h) = StdIn.readLine().split(' ')
    
    if(t.compare(h) > 0) (acc._1 + 3, acc._2)
    else if(t.compare(h) < 0) (acc._1, acc._2 + 3)
    else (acc._1 + 1, acc._2 + 1)
  }
  
  println(result._1 + " " + result._2)
}


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

int main(){
  int n;
  cin>>n;
  int a[n];
  int one=0,two=0,three=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]==1)
      one++;
    if(a[i]==2)
       two++;
    if(a[i]==3)
       three++;
  }
  double dp[310][310][310];
  dp[0][0][0]=0;
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=n;j++)
    {
      for(int k=0;k<=n;k++)
      {
        double curr=n;
        if(k>0)
          curr+=k*dp[k-1][j][i];
        if(j>0)
          curr+=j*dp[k+1][j-1][i];
        if(i>0)
          curr+=i*dp[k][j+1][i-1];
        if((i+j+k)!=0)
       	  dp[k][j][i]=(double)curr/(i+j+k);
      }
    }
  }
  cout<<fixed<<setprecision(10)<<dp[one][two][three];
}

Measured memory_bytes: 228096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int NMAX=100;
static const int MMAX=100;
bool black[NMAX][MMAX];
int W,H,N;
void paint(int x,int y,int a){
    if(a==1){
        for(int i=0;i<x;i++){
            for(int j=0;j<H;j++)
                black[i][j]=true;
        }
    }else if(a==2){
        for(int i=x;i<W;i++){
            for(int j=0;j<H;j++)
                black[i][j]=true;
        }
    }else if(a==3){
        for(int i=0;i<W;i++){
            for(int j=0;j<y;j++)
                black[i][j]=true;
        }
    }else {
        for(int i=0;i<W;i++){
            for(int j=y;j<H;j++)
                black[i][j]=true;
        }
    }
}

int main(){
    cin>>W>>H>>N;
    int x,y,a;
    for(int i=0;i<N;i++){
        cin>>x>>y>>a;
        paint(x,y,a);
    }

    int cunt=0;
    for(int i=0;i<W;i++){
        for(int j=0;j<H;j++){
            if(!black[i][j])cunt++;
        }
    }
    cout<<cunt<<"\n";
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,m,a[200000],b[200000],c[200000]={0};
    string s="IMPOSSIBLE";
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        if(a[i]==1){
            c[b[i]]=1;
        }
    }
    for(int i= 0;i<m;i++){
        if(b[i]==n){
            if(c[a[i]]==1){
                s="POSSIBLE";
                i=m;
            }
        }
    }
    cout<<s<<endl;
}


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

int main() {
  int n; cin>>n;
  vector<int> p(n),q(n);
  rep(i, n) cin>>p[i];
  rep(i, n) cin>>q[i];

  vector<int> a(n);
  rep(i, n) a[i]=i+1;

  int R=-1,L=-1;
  int cnt=0;
  do {
    cnt++;
    bool fragP=true;
    bool fragQ=true;
    rep(i, n) {
      if (a[i]!=p[i]) fragP=false;
      if (a[i]!=q[i]) fragQ=false;
    }
    if (fragP) R=cnt;
    if (fragQ) L=cnt;
  } while (next_permutation(a.begin(), a.end()));
  cout<<abs(R-L)<<endl;
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "string.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

ll n;

long double dp[310][310][310];

long double rec(int i,int j,int k){
  if(dp[i][j][k]>0)return dp[i][j][k];
  if(i==0&&j==0&&k==0)return 0.0l;

  long double ret=0.0l;

  if(i>0)ret+=rec(i-1,j,k)*i;
  if(j>0)ret+=rec(i+1,j-1,k)*j;
  if(k>0)ret+=rec(i,j+1 ,k-1)*k;

  ret+=n;

  ret/=(long double)(i+j+k);

  dp[i][j][k]=ret;
  return ret;
}

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

  std::cin>>n;

  memset(dp,-1,sizeof(dp));

  ll a=0,b=0,c=0;
  rep(i,0,n){
    ll temp;
    std::cin>>temp;
    if(temp==1)a++;
    if(temp==2)b++;
    if(temp==3)c++;
  }

  std::cout<<std::setprecision(10)<<std::fixed;

  std::cout<<rec(a,b,c)<<"\n";

  return 0;
}

Measured memory_bytes: 465792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

string c[20];
int visited[20][20] , vid;
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
int n , m , ans;

void bfs (int i , int j){

    if (c[i][j] == '#') 
        return;

    ++vid;
    queue <pair<int,int>> q;
    q.push({i,j});
    visited[i][j] = vid;
    int cnt = 0;
    while (!q.empty()){
        int sz = q.size();
        while (sz--){
            int x = q.front().first , y = q.front().second;
            q.pop();
            for (int d = 0 ; d < 4 ; ++d){
                int ni = x + dx[d];
                int nj = y + dy[d];
                if (ni < 0 || nj < 0 || ni >= n || nj >= m || visited[ni][nj] == vid || c[ni][nj] == '#')
                    continue;
                q.push({ni,nj});
                visited[ni][nj] = vid;
            }
        }
        ++cnt;
    }

    ans = max (ans , cnt-1);
}

void Suhaib_Sawalha (){

    cin >> n >> m;
    for (int i = 0 ; i < n ; ++i)
        cin >> c[i];

    for (int i = 0 ; i < n ; ++i)
        for (int j = 0 ; j < m ; ++j)
            bfs(i,j);

    cout << ans;
}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

struct UnionFind {
    vector<int> d;
    // n要素で初期化
    UnionFind(int n): d(n,-1) {}
    // 木の根を決める
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    // xとy属する集合を併合
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    // xとyが同じ集合に属するか否か
    bool same(int x, int y) { return root(x) == root(y); }
    // xの属する集合のサイズ
    int size(int x) { return -d[root(x)];}
};

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

    UnionFind uf(n);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }

    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        if(!uf.same(i, i + 1)){
            uf.unite(i, i + 1);
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

template<long long mod = 1000000007>
struct modint{
	long long a;

	modint() : a(0){}
	modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	operator long long() const{ return a; }

	bool operator==(const modint &x) const{ return a == x.a; }
	bool operator!=(const modint &x) const{ return a != x.a; }

	modint operator-() const{ return modint(a ? (mod - a) : 0); }
	modint operator~() const{ return pow(mod - 2); }

	modint operator+(const modint &x) const{ return modint(*this) += x; }
	modint operator-(const modint &x) const{ return modint(*this) -= x; }
	modint operator*(const modint &x) const{ return modint(*this) *= x; }
	modint operator/(const modint &x) const{ return modint(*this) /= x; }

	modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

signed main(){
	int n,k;
	modint<> dp[100010],ans = 0;
	cin >> n >> k;
	for(int i = k;i >= 1;i--){
		dp[i] = modint<>(k / i).pow(n);
		for(int j = i * 2;j <= k;j += i) dp[i] -= dp[j];
		ans += dp[i] * modint<>(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4404
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,(n)-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int sx, sy, tx, ty;
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>sx>>sy>>tx>>ty;

    int dx = tx - sx;
    int dy = ty - sy;
    string dl(dx, 'L');
    string dr(dx, 'R');
    string dd(dy, 'D');
    string du(dy, 'U');
    cout<<dr<<du<<dl<<dd;
    cout<<'D'<<dr<<'R'<<du<<'U'<<'L';
    cout<<'U'<<dl<<'L'<<dd<<'D'<<'R';
    cout << endl;
}


Measured memory_bytes: 256
import heapq

N = int(input())
A = [int(i) for i in input().split()]
num = [i for i in range(1, N+1)]
dic = {key: val for key, val in zip(A, num)}

C = []
heapq.heapify(A)
for i in range(N):
    a = heapq.heappop(A)
    c = dic[a]
    C.append(c)
print(*C)

Measured memory_bytes: 21984
n,k = (int(i) for i in input().split())
h = list(int(i) for i in input().split())
dp = [0]
for i in range(1,n):
    s = float("inf")
    for j in range(1,min(k,i)+1):
        s = min(s,dp[i-j]+abs(h[i]-h[i-j]))
    dp.append(s)
print(dp[-1])

Measured memory_bytes: 58720
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=x && x<w && 0<=y && y<h)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;

/** Problem2015 : Square Route **/
int main()
{

	int N, M;
	while (cin>>N>>M, N||M) {
		map<int, int> nx, ny;
		vector<int> ix, iy;
		
		rep(i, N) {
			int in;
			cin>>in; ix.push_back(in);
		}
		rep(i, M) {
			int in;
			cin>>in; iy.push_back(in);
		}
		
		rep(i, N) {
			int tmp = ix[i];
			nx[tmp]++;
			REP(j, 1, N-i) {
				tmp+=ix[i+j];
				nx[tmp]++;
			}
		}
		
		rep(i, M) {
			int tmp = iy[i];
			ny[tmp]++;
			REP(j, 1, M-i) {
				tmp+=iy[i+j];
				ny[tmp]++;
			}
		}
		
		map<int, int>::iterator it = nx.begin();
		int ans=0;
		for (; it!=nx.end(); it++) {
			ans += it->second * ny[it->first];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 32224
from collections import deque

H, W = map(int, input().split())
maze = [input() for i in range(H)]
reached = [[0] * W for i in range(H)]
score = -1
count = 0

for i in range(H):
    count += maze[i].count('#')

que = deque([])
que.append([0, 0])

flag = False
while que:
    py, px = que.popleft()
    dy = (0, 1, 0, -1)
    dx = (1, 0, -1, 0)
    for j, i in zip(dy, dx):
        ny = py + j
        nx = px + i
        if ny < 0 or ny >= H or nx < 0 or nx >= W:
            continue
        if maze[ny][nx] == '#':
            continue
        if reached[ny][nx]:
            continue

        que.append([ny, nx])
        reached[ny][nx] += reached[py][px] + 1
        if ny == H-1 and nx == W-1:
            score = reached[ny][nx]
            flag = True
            break
    if flag:
        break

if flag:
    score = H * W - score - count - 1
    print(score)
else:
    print(score)


Measured memory_bytes: 3316
#include<stdio.h>
typedef long long ll;
const ll mod = 1e9+7;
int main(){
  ll n, k, s, t, len, i, sum;
  scanf("%lld%lld",&n,&k);
  s = 0;
  t = 0;
  sum = 0;
  for(i=0;i<=n;i++){
    s += i;
    t += n - i;
    len = t - s + 1;
    //printf("%lld\n",len);
    if(i+1>=k){
      sum = (sum + len)%mod;
    }
  }
  printf("%lld",sum);
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"

using namespace std;
typedef long long ll;
typedef pair <ll,ll> pii;

const ll NMAX = 100001;
const ll MOD = 998244353;
const ll BLOCK = 447;

int c[10],k;
int banned[10];

bool OK(int x){
    do{
        if(banned[x % 10]){
            return 0;
        }
        x /= 10;
    }while(x);
    return 1;
}

int main() {
    int n,i;
    cin >> n >> k;
    for(i = 1;i <= k;i++){
        cin >> c[i];
        banned[c[i]]++;
    }
    for(i = n;;i++){
        if(OK(i))
            break;
    }
    cout << i;
    return 0;
}


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

int main()
{
    int N,X,D=0,r=1;
    cin>>N>>X;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin>>L.at(i);
    }
    for(int i=0;i<N;i++){
        D+=L.at(i);
        if(D==X){
            r++;
            cout<<r<<endl;
            exit(0);
        }else if(D>X){
            cout<<r<<endl;
            exit(0);
        }
        r++;
    }
    cout<<r<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ) {
    if ( A[j] <= x ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

int main() {
  int i, q;

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

  q = partition(0, n - 1);

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

  return 0;
}



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

int main(){
    using namespace std;
    char c;
    cin >> c;
    if(c == 'S'){
        puts("Cloudy");
    }else if(c == 'C'){
        puts("Rainy");
    }else{
        puts("Sunny");
    }
    return 0;
}

Measured memory_bytes: 768
((stdin) => {
	let [l1, l2] = stdin.split('\n');
	let [x, n] = l1.split(' ');
	[x, n] = [+x, +n];
	let p = l2.split(' ');
	for (let i = 0; i < n; i++) {
		p[i] = +p[i];
	}

	let d = 0;
	for (d = 0; d <= 100; d++) {
		if (!p.includes(x - d)) {
			console.log(x - d);
			return 0;
		}
		if (!p.includes(x + d)) {
			console.log(x + d);
			return 0;
		}
	}

})(require("fs").readFileSync("/dev/stdin", "UTF-8"));

Measured memory_bytes: 29652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		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 time;

		if(a < 0) System.out.println(- a * c + d + b * e);
		else System.out.println((b - a) * e);
	}

}



Measured memory_bytes: 26164
h, w, k = [int(i) for i in input().split()]
masu = [input() for _ in range(h)]
ans = 0
for mark_h in range(2**h):
    for mark_w in range(2**w):
        black = 0
        for i in range(h):
            for j in range(w):
                if (mark_h>>i)&1==1 and (mark_w>>j)&1==1:
                    if masu[i][j]=="#":
                        black+=1
        if black==k:
            ans+=1
print(ans)

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

int main(){
    int x1,y1,x2,y2;
    int x3,y3,x4,y4;

    cin>>x1>>y1>>x2>>y2;

    x4=x1-(y2-y1);
    y4=y1+(x2-x1);

    x3=x2+x4-x1;
    y3=y2+y4-y1;

    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;

    return 0;


}

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

using namespace std;

int main() {

	long long n;
	cin >> n;

	long long res = 0;
	if (n % 2 == 0) {
		long long tenth = 5;
		long long counter = 0;
		while (tenth <= n) {

			res += n / (long long)pow(5,counter)/10;
			tenth *= 5;
			counter++;
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 4196
#include<stdio.h>
int main (void){
int a[10000],b[100],S[100],n,m,i,j,k,l,o,p;
scanf("%d %d",&n,&m);
for(i=1;i<=(n*m);i++){
	scanf("%d",&a[i]);
}
for(j=1;j<=m;j++){
	scanf("%d",&b[j]);
}
for(l=1;l<=n;l++){//l??????
	S[l]=0;
	for(o=1;o<=m;o++){
		S[l]=S[l]+a[(((l-1)*m)+o)]*b[o];
	}

}
for(p=1;p<=n;p++){
	printf("%d\n", S[p]);

}
return 0;	
}

Measured memory_bytes: 1756
#include <iostream>

int main()
{
	int N;
	std::cin >> N;

	int* array01 = (int*)malloc(sizeof(int) * N);
	for (int i = 0; i < N; i++)
	{
		array01[i] = 0;
	}

	for (int i = 1; i < N; i++)
	{
		int temp;
		std::cin >> temp;
		array01[temp-1]++;
	}

	for (int i = 0; i < N; i++)
	{
		std::cout << array01[i] << std::endl;
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

int N;
string s;
vector <int> ans;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> s;
    N = s.length();
    bool bad = false;
    if (s[0] == '0') bad = true;
    if (s[N-1] == '1') bad = true;
    for (int i = 0; i < N; i++)
    {
        if (i < N - 1 && s[i] != s[N-2-i])
            bad = true;
        if (s[i] == '1')
            ans.push_back (i + 1);
    }

    if (bad)
    {
        cout << "-1\n";
        return 0;
    }

    int ctot = 1;
    for (int x : ans)
    {
        cout << ctot << " " << ctot + 1 << "\n";
        ctot++;
    }

    for (int i = 0; i + 1 < ans.size(); i++)
    {
        int nd = ans[i+1] - ans[i] - 1;
        for (int j = 0; j < nd; j++)
        {
            cout << ctot + 1 << " " << i + 2 << "\n";
            ctot++;
        }
    }
}

Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll n;
  cin >>n;
  ll a[n];
  for(ll i=0;i<n;i++) cin >>a[i];
  ll ans=0;
  for(ll i=0;i<n;i++){
    ans+=(a[i]-1);
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#define MAX 20
using namespace std;

int new_a(int a, int digit){ /*次の数字を計算*/
    int max,min;
    string a_s;
    ostringstream sout;

    sout << setfill('0') << setw(digit) << a;//
    a_s = sout.str();                        //int -> string　と　0埋め
    sort(a_s.begin(), a_s.end());//昇順ソート
     min = stoi(a_s);//string -> int
    
     
    reverse(a_s.begin(), a_s.end());//要素を反転（降順ソート）
    max = stoi(a_s);
  
    
    return max - min;

}
int main(void){

    int a; 
    int digit;
    int a_n[MAX];
    while(1){
        cin >> a >> digit;//入力    scanf("%d",&a); scanf("%d",&digit);
        if(a == 0 && digit == 0){//終了判定
            break;
        }
        
        
        int i=0;
        int not_equal = 1;
        while(not_equal){
            a_n[i] = a;
            a = new_a(a,digit);
            i++;
            for(int j=0; j<i; j++){
                if(a == a_n[j]){//今までの数字と比較
                    cout << j << ' ' << a << ' ' << i-j << endl;//出力  printf("%d %d %d\n",j,a,i-j);
                    not_equal =0;
                    break;

                }
            }
        }
    }

}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int cache;
    cin >> cache;
    if (a.size() == 0 || cache <= a.at(a.size() - 1)) {
      a.push_back(cache);
    } else {
      int lower_bound = 0, upper_bound = a.size();
      while (lower_bound < upper_bound - 1) {
        int half = (lower_bound + upper_bound) / 2;
        if (cache <= a.at(half - 1)) {
          lower_bound = half;
        } else {
          upper_bound = half;
        }
      }
      a.at(lower_bound) = cache;
    }
  }
  cout << a.size() << endl;
}


Measured memory_bytes: 892
N, K = map(int, input().split())
posX = []
negX = []
for x in map(int, input().split()):
    if 0 <= x:
        posX.append(x)
    else:
        negX.append(-x)

negX.sort()

len_posX = len(posX)
len_negX = len(negX)

ans = float('inf')
for pos_k in range(len_posX + 1):
    neg_k = K - pos_k
    if len_negX <= neg_k - 1:
        continue

    if neg_k == 0 and len_posX != 0:
        ans = min(ans, posX[pos_k - 1])
    elif pos_k == 0 and len_negX != 0:
        ans = min(ans, negX[neg_k - 1])
    elif len_posX != 0 and len_negX != 0:
        ans = min(ans, posX[pos_k - 1] + 2 * negX[neg_k - 1], 2 * posX[pos_k - 1] + negX[neg_k - 1])

print(ans)


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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	int A[3];
	vector<int> a(3);

	rep (i, 3)
		cin >> a[i];

	sort(all(a));

	int ans = 0;
	ans += a[2] - a[1];
	ans += a[1] - a[0];

	cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};
typedef struct node * NodePointer;
NodePointer nil;
NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(1){
    if( cur == nil ) return NULL;
    if( cur->key == key ) return cur;
    cur = cur->next;
  }
}
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
} 
void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}
 
void deleteLast(){
  NodePointer t = nil->prev;
  if( t == nil ) return;
  deleteNode(t);
}
void delete(int key){
  NodePointer t;
  t=listSearch(key);
  if(t==NULL) return;
  deleteNode(t);
}
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->prev = nil;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
}
int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
    if ( com[6] == 'F' ) deleteFirst();
    else if ( com[6] == 'L' ) deleteLast();
      } else {
    delete(key); nd++; 
      }
      size--;
    }
  }
  printList();
  return 0;
}


Measured memory_bytes: 32932
// luogu-judger-enable-o2
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, t, p, l;
int a[N];
int main()
{
    n = read(), l = read(), t = read();
    for(int i = 0, d; i < n; ++i) 
    {
        a[i] = read(), d = read();
        if(d == 1) p += (a[i]+t)/l, a[i] = (a[i]+t)%l;
        else p += (a[i]-t)/l, a[i] = (a[i]-t)%l, p -= a[i] < 0, a[i] = (a[i]+l)%l;
    }
    p = (p%n+n)%n, sort(a, a+n);
    for(int i = p; i < n; ++i) printf("%d\n", a[i]);
    for(int i = 0; i < p; ++i) printf("%d\n", a[i]);
    return 0;
}

Measured memory_bytes: 1536
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var time = new int[101];
            for (int i = 0; i <= 100; i++)
            {
                if (inp[0] < i && i <= inp[1] && inp[2] < i && i <= inp[3]) time[i]++;
            }
            Console.WriteLine(time.Sum());
        }
    }
}

Measured memory_bytes: 13268
n = int(input())
li = list(map(int, input().split()))
li_a = []
for x in li:
  if x%2 == 0:
    li_a.append(x)
a = 0
for y in li_a:
  if y%3 == 0 or y%5 == 0:
    continue
  else:
    a += 1
if a == 0:
  print("APPROVED")
else:
  print("DENIED")

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

bool isEnoughSmall(double x) {
    return(abs(x*x*x - q) < 0.00001*q);
}

double formula(double beforeX) {
    return(beforeX - ((beforeX*beforeX*beforeX-q) / (double)(3.0*beforeX*beforeX)));
}

void solve() {
    double nowx = q / 2.0;
    while(true) {
        nowx = formula(nowx);
        if(isEnoughSmall(nowx)) break;
        //printf("exec:%.6f\n", nowx);
    }
    printf("%.6f\n", nowx);
}

int main(void) {
    while(cin >> q, q != -1) {
        solve();
    }
    return(0);
}

Measured memory_bytes: 1176
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n;
    cin >> n;
    string s[n],t;
    string::iterator it,it2;
    for(int i = 0;i < n;i++){
        cin >> s[i];
    }
    for(int i = 0;i < n-1;i++){
        for(int j = i+1;j < n;j++){
            if(s[i] == s[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    for(int i = 0;i < n-1;i++){
        it = s[i].end()-1;
        it2 = s[i+1].begin();
        if(*it != *it2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a,b,c;
  int n,m;
  cin >> a >> b >> n >> m >> c;
  if (c == a){
    cout << n-1 << " " << m << endl;
  }
  else{
    cout << n << " " << m-1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=200000+10;
int n,a[N],b[N],p[N],dep[N];
vector<int> g[N];
void dfs(int u,int p){
	dep[u]=dep[p]+1;
	for(auto v:g[u]){
		if(v==p)continue;
		dfs(v,u);
	}
}
/*
3 3 2

min(odd, even): <= 2
min(odd, even) >= 3
*/
int main() {
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	dfs(1,1);
	int d1=n/3,d2=n/3,d3=n/3;
	if(n%3==1) d1++;
	if(n%3==2) d1++,d2++;
	int c1=0,c2=0;
	for(int i=1;i<=n;i++)if(dep[i]%2==0)c1++;else c2++;

	int x=1,y=2,z=3;
	if(min(c1,c2)<=d3) {
		int bu = c1<c2 ? 0 : 1;
		for(int i=1;i<=n;i++){
			if(dep[i]%2==bu){
				p[i]=z; z+=3;
			} else {
				if(x<=n) p[i]=x,x+=3;
				else if(y<=n) p[i]=y,y+=3;
				else p[i]=z,z+=3;
			}
		}
	} else {
		for(int i=1;i<=n;i++){
			if(dep[i]%2==0){
				if(x<=n){
					p[i]=x; x+=3;
				}else{
					p[i]=z; z+=3;
				}
			} else {
				if(y<=n){
					p[i]=y; y+=3;
				}else{
					p[i]=z; z+=3;
				}
			}
		}
	}
	for(int i=1;i<=n;i++)printf("%d ", p[i]);
	
}

Measured memory_bytes: 20480
#include <stdio.h>

int main(void){
  int a,b;
  char op;
  while(1){
    scanf("%d %c%d",&a,&op,&b);
    if(op == '?'){
      break;
    }
    else{
      if(op == '+'){
        printf("%d\n",a + b);
      }
      else if(op == '-'){
        printf("%d\n",a - b);
      }
      else if(op == '*'){
        printf("%d\n",a * b);
      }
      else if(op == '/'){
        printf("%d\n",a / b);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e3+20;

int n,m;
vector<int>ed[maxn];
int top[maxn][maxn];
int graph[maxn][maxn];
int parent[maxn][maxn];

#define pii pair<int,int>

void Add(int from,int to)
{
	if(top[from][to]==to || top[to][from]==from)return;
	else if(top[from][to])Add(top[from][to],to);
	else if(top[to][from])Add(top[to][from],from);
	else {
		vector<pii >edges;
		REP(th,0,1)
		{
			graph[from][to]=1;
			top[from][to]=to;
			/*function<void(int)> dfs=[&](int u) {
				for(int v:ed[u])
					if(v!=parent[from][u])
					{
						if(top[from][v]==0)
						{
							top[from][v]=to;
							dfs(v);
						}else if(graph[from][v])
						{
							graph[from][v]=graph[v][from]=0;
							edges.push_back(mkr(to,v));
						}
					}
					};*/
			queue<int>q;
			q.push(to);
			while(!q.empty())
			{
				int u=q.front();q.pop();
				for(int v:ed[u])
					if(v!=parent[from][u])
					{
						if(top[from][v]==0)
						{
							top[from][v]=to;
							q.push(v);
						}else if(graph[from][v])
						{
							graph[from][v]=graph[v][from]=0;
							edges.push_back(mkr(to,v));
						}
					}
			}
			
			swap(from,to);
		}
		for(pii t:edges)Add(t.fi,t.se);
	}
}

inline void init()
{
	n=read();m=read();
	REP(i,1,n-1)
	{
		int u=read(),v=read();
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
	REP(now,1,n)
	{
		function<void(int,int)> dfs=[&](int u,int fa)
		{
			for(int v:ed[u])
				if(v!=fa)
				{
					parent[now][v]=u;
					dfs(v,u);
				}
		};
		dfs(now,0);
	}
	
	REP(i,1,m)
	{
		int u=read(),v=read();
		Add(u,v);
	}
}

ll ans;

inline void doing()
{
	REP(rt,1,n)
	{
		function<void(int u,int t)> dfs=[&](int u,int t)
		{
			for(int v:ed[u])
				if(v!=parent[rt][u])
				{
					int nt=t;
					if(top[t][v]==v)ans++,nt=v;
					dfs(v,nt);
				}
		};
		dfs(rt,rt);
	}
	printf("%lld\n",ans/2);
}

int main()
{
	init();
	doing();
	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

void solve () {
    int r,c,k;
    cin >> r >> c >> k;
    string grid[r];
    for (int i = 0;i < r;++i) {
        cin >> grid[i];
    }
    int ans = 0;
    for (int i = 0;i < pow(2,r);++i) {
        for (int j = 0;j < pow(2,c);++j) {
            int cnt = 0;
            for (int u = 0;u < r;++u) {
                for (int v = 0;v < c;++v) {
                    if (((1<<u)&i) > 0 || ((1<<v)&j) > 0) continue;
                    else {
                        if (grid[u][v] == '#') ++cnt;
                    } 
                }
            }
            if (cnt == k) {
                ++ans;
            }
        }
    }
    cout << ans << '\n';
}

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



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

int main(){
    int r, g, b ,n, cnt = 0;

    cin >> r >> g >> b >> n;
    for(int i=0; i<=n/r;i++){
        for(int j=0; j<= (n - i*r)/g; j++){
            if((n-i*r-j*g)%b==0)cnt+=1;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>
#include <stack>
#include <deque>
#include <queue>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

const int MOD = 1e9 + 7;
const ll MAX = 200009;
ll inv[MAX], fac[MAX], finv[MAX];

void settable() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int n, k;
const int mxN = 1e5 + 6;
vector<int> G[mxN];
mint ans = 1;

ll f(ll n, ll k) {
    if (n < k) return 0;
    return fac[n] * finv[n-k];
}

void dfs(int u, int p = -1) {
    for (auto e : G[u]) {
        if (e == p) continue;
        else dfs(e, u);
    }

    ll nk = p == -1 ?  k : k - 2;
    ll nc = p == -1 ?  G[u].size() + 1:G[u].size() - 1;
    ans *= f(nk, nc);

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    settable();
    cin >> n >> k;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0);
    cout << ans.x << endl;
}

Measured memory_bytes: 15104
#include <stdio.h>
int main(void)
{
    char a[5];
    int i=0;
        scanf("%s", a);
        for(i=1;i<4;i++){
            if(a[i]==a[i-1]){
                printf("Bad\n");
                return 0;
            }
        }
    printf("Good\n");
    

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define pi pair<int,int>
#define ff first
#define ss second
#define int long long

const int N = 4004;
const int M = 1e9 + 7;

int mod(int m){
   m %= M;
   return (m + M) % M;
}

int power(int x,int y) {
   int res = 1;
   x = mod(x);
   while (y > 0) {
      if (y & 1)
         res =mod(res*x);
      y = y>>1;
      x = mod(x*x);
   }
   return mod(res);
}

int f[N],invf[N];
void fact(){
   f[0]=f[1]=1;
   for(int i=2;i<N;i++)
      f[i]=mod(f[i-1]*i);

   invf[N-1]=power(f[N-1],M-2);
   for(int i=N-1;i>0;i--)
      invf[i-1]=mod(invf[i]*i);

}

int nCr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   ans = mod(ans*invf[r]);
   return ans;
}

int nPr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   return ans;
}

int32_t main(){
	boost;
	fact();
	int n,k;
	cin>>n>>k;
	int blue = k;
	int red = n - k;
	for(int i=1;i<=k;i++){
		int x = nCr(blue - 1,i - 1);
		int y = nCr(red + 1,i);
		cout<<mod(x*y)<<endl;
	}
}



Measured memory_bytes: 3636
import java.util.*;

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 X = sc.nextInt();
    
    int ans = 0;
    for (int i = 0; i <= A; i++) {
      for (int j = 0; j <= B; j++) {
        for (int k = 0; k <= C; k++) {
          if (500*i + 100*j + 50*k == X) {
            ans++;
          }
        }
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int h1=sc.nextInt(),m1=sc.nextInt(),h2=sc.nextInt(),m2=sc.nextInt(),k=sc.nextInt();
		sc.close();
		int start =h1*60+m1,goal=h2*60+m2;
		System.out.println(goal-k-start);
	}
}

Measured memory_bytes: 35852
#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() {
  vector<char> S(4);
  rep(i, 4) cin >> S[i];
  std::sort(S.begin(), S.end());
  if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


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

using namespace std;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int a, b, c;
  cin >> a >> b >> c;
  int cnt = 0;
  while((a&1) + (b&1) + (c&1) == 0) {
    tie(a, b, c) = tuple<int,int,int>{(c+b)>>1, (a+c)>>1, (a+b)>>1};
    if(cnt > 10000000) {
      cnt = -1;
      break;
    }
    cnt++;
  }

  cout << cnt << endl;
}

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

using namespace std;

#define rep(i, start, end) for (int(i) = (start); (i) < (end); (i)++)
#define rep_r(i, end, start) for (int(i) = (end); (i) >= (start); i--)
#define len(ar) (sizeof(ar) / sizeof(ar[0]))

int main() {
  int N, M;
  cin >> N;
  map<string, int> m;

  rep(i, 0, N) {
    string key;
    cin >> key;
    if (m.find(key) != m.end()) {
      m[key]++;
      continue;
    }
    m[key] = 1;
  }

  cin >> M;
  rep(i, 0, M) {
    string key;
    cin >> key;
    if (m.find(key) != m.end()) {
      m[key]--;
      continue;
    }
    m[key] = -1;
  }

  int max = 0;
  for (auto i = m.begin(); i != m.end(); i++) {
    if (i->second > max) max = i->second;
  }

  cout << max;

  return 0;
}

Measured memory_bytes: 256