akhauriyash/Code-Regression huggingface dataset:
def main():
    N = int(input())
    cnttable = [[0] * 9 for _ in range(9)]
    for i in range(1,N+1):
        if i%10 == 0:
            continue
        if i < 10:
            cnttable[i-1][i-1] += 1
        else:
            tmp = list(str(i))
            cnttable[int(tmp[0])-1][int(tmp[-1])-1] += 1

    ans = 0
    for i in range(9):
        for j in range(i, 9):
            if i == j:
                ans += cnttable[i][j] * cnttable[j][i]
            else:
                ans += cnttable[i][j] * cnttable[j][i] * 2

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
def resolve():
    a, b, k = map(int, input().split())
    if a+k-1 >= b-k+1:
        for i in range(a, b+1):
            print(i)
    else:
        for i in range(a, a+k):
            print(i)
        for i in range(b-k+1, b+1):
            print(i)
resolve()

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

int main(){
	// sengen
	int n,m;
	// nyuryoku
	cin >> n >> m;
	// keisan
	int sum = 0;
	if(n > 1){
		sum += n*(n-1)/2;
	}
	if(m > 1){
		sum += m*(m-1)/2;
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    int N;
    cin >> N;
    N++;
    vector<int> a(N);
    a.pb(0);
    rep(i,N) cin >> a[i+1];
    
    vector<int> next(N);
    vector<int> eo(N);
    rep(i,N){ 
        //i番目->i+1番目
        if(i==N-1) next[i] = abs(a[0]-a[i]);
        else next[i] = abs(a[i]-a[i+1]);
        
        //i番目->i+2番目
        if(i >= N-2) eo[i] = abs(a[i+2-N]-a[i]);
        else eo[i] = abs(a[i]-a[i+2]);
    }
    
    int ans = accumulate(ALL(next),0);
    rep(i,N-1) cout << ans - next[i] - next[i+1] + eo[i] << '\n';
}

Measured memory_bytes: 2424
n = int(input())
a = []
for i in range(n):
  a_ = int(input())
  a.append(a_)
res = []
i = 1
for _ in range(n):
  res.append(a[i-1])
  i = a[i-1]
  if i == 2:
    break

if 2 in res:
  print(len(res))
else:
  print(-1)

Measured memory_bytes: 13836
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int main(){
    string a,b;
    cin >> a >> b;
    string answer = "H";
    if(a != b){
        answer = "D";
    }
    cout << answer << endl;
}


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

int main(){
    int n, m, l;
    int a[100][100]={{}}, b[100][100]={{}};
    long c[100][100]={{}};
    cin >> n >> m >> l;

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

    for(int i=0; i<m; i++){
        for(int j=0; j<l; j++){
            cin >> b[i][j];
        }
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            for(int k=0; k<m; k++){
                c[i][j]+=a[i][k]*b[k][j];
            }

        }
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            cout << c[i][j];
            if(j!=l-1)cout << " ";
        }
        cout << endl;
    }

    return 0;
}


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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

int main()
{   
    int N;
    while(cin >> N, N)
    {
        vector<int> h(N + 1);
        rep(i, N + 1) cin >> h[i];
        int ans = 0;

        rep(i, N + 1)
        {
            vector<int> tmp = h;

            tmp.erase(tmp.begin() + i);

            bool isAri = true;

            int diff = tmp[1] - tmp[0];

            REP(j, 1, tmp.size() - 1)
            {
                if(tmp[j + 1] - tmp[j] != diff)
                {
                    isAri = false;
                }
            }

            if(isAri) 
            {
                ans = h[i];
                break;
            }
        }

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


Measured memory_bytes: 3108
#include <stdio.h>
int vegi[1000];
int main() {
	int N, M;
	int i, j, swp, sum;
	for(;;) {
		scanf("%d %d", &N, &M);
		if(N == 0 && M == 0) break;
		for(i = 0; i < N; ++ i) scanf("%d", &vegi[i]);
		for(i = 0; i < N; ++ i) {
			for(j = i; j < N; ++ j) {
				if(vegi[i] < vegi[j]) {
					swp = vegi[i];
					vegi[i] = vegi[j];
					vegi[j] = swp;
				}
			}
		}
		sum = 0;
		for(i = 0; i < N; ++ i) {
			if(i % M == M - 1) continue;
			sum += vegi[i];
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    if (N > M) swap(N, M);

    ll count;
    if (N == M  && N == 1) count = 1;
    else if (N == 1) count = M-2;
    else count = (N-2) * (M-2);

    cout << count << endl;
}

Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

L = []
for i in range(1, k+1):
    for j in range(1, k+1):
        for p in range(1, k+1):
            L.append(gcd(i, j, p))

print(sum(L))


Measured memory_bytes: 188928
N = int(input())
A = list(map(int, input().split())) # N + 1
B = list(map(int, input().split())) # N

# 重みがないのですべて小さい方から倒せると仮定する
cnt = 0
for i in range(N):
    cnt += min(B[i], A[i])
    diff = B[i] - A[i]
    if diff > 0:
        if A[i+1] < diff:
            cnt += A[i+1]
            A[i+1] = 0
        else:
            cnt += diff
            A[i+1] -= diff
        A[i] = 0
    else:
        A[i] -= B[i]
#print("A",A)
#print("B",B)
print(cnt)

Measured memory_bytes: 18476
#include <cstdio>
#include <algorithm>

int testcase_ends() {
  int e;
  scanf("%d", &e);
  if (e == 0) return 1;

  int res = e;
  for (int z = 0; z*z*z <= e; ++z)
    for (int y = 0; y*y+z <= e; ++y) {
      int x = e-(y*y+z*z*z);
      if (x < 0) continue;
      res = std::min(res, x+y+z);
    }
  printf("%d\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



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

using namespace std;

int main() {
  string board[50];
  int H, W;
  cin >> H >> W;

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


  for(int i=0; i < H; ++i) {
    for(int j=0; j < W; ++j) {
      if(board[i][j] == '#') continue;

      int num = 0;
      for(int k = 0; k < 9; ++k) {
        int ni = i +k/3 -1;
        int nj = j +k%3 -1;
        if (ni < 0 or H <= ni) continue;
        if (nj < 0 or W <= nj) continue;
        if (board[ni][nj] == '#') ++num;
      }
      board[i][j] = char(num + '0');
    }
  }

  for(int i = 0; i < H; ++i) cout << board[i] << endl;


  return 0;

}


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

int main() {
int a,b,c,k;
cin>>a>>b>>c>>k;
int ans;

if(k<=a){
    cout<<k<<endl;
}
else if(k<=a+b){
 cout<<a<<endl;
}
else {
   ans=a-(k-a-b);
   cout<<ans<<endl;
}

}



Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
 
 
 
class Solve
{
    public Solve() { }
    public static int Main()
    {
        new Solve().calc();
        return 0;
    }
 
 
    Scanner cin;
 
    void calc()
    {
        cin = new Scanner();
        int len = cin.nextInt();
        int[] num = new int[len];
        for(int i=0; i<len; i++)
        {
            num[i] = cin.nextInt();
        }
        Array.Sort(num);

        int index = len / 2;
        int result = num[index] - num[index - 1];

        Console.WriteLine(result.ToString());
    }
}
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 18912
#include<stdio.h>
int gcd(int x,int y){
  return y?gcd(y,x%y):x;
}
int main(){
  int i,j;
  scanf("%d %d",&i,&j);
  gcd(i,j);
  printf("%d\n",gcd(i,j));
  return 0;
}



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

ll solve() {
    ll H, W, M;
    cin >> H >> W >> M;
    vector<ll> h(M), w(M);
    vector<ll> ch(H), cw(W);
    set<pii> ps;
    for ( int i = 0; i < M; i++ ) {
        cin >> h[i] >> w[i];
        h[i]--, w[i]--;
        ch[h[i]]++;
        cw[w[i]]++;
        ps.insert(pii(h[i],w[i]));
    }
    ll mx_h = *max_element(ch.begin(), ch.end());
    ll mx_w = *max_element(cw.begin(), cw.end());
    vector<int> ixh, ixw;
    for ( int i = 0; i < H; i++ ) {
        if ( ch[i] == mx_h ) ixh.push_back(i);
    }
    for ( int i = 0; i < W; i++ ) {
        if ( cw[i] == mx_w ) ixw.push_back(i);
    }
    ll ans = mx_h + mx_w;
    ll diff = -1;
    for ( int i : ixh ) {
        for ( int j : ixw ) {
            if ( ps.count(pii(i,j)) == 0 ) {
                diff = 0;
                break;
            }
        }
        if ( diff == 0 ) break;
    }
    ans += diff;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 30800
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;


int main()
{
    int x[3][3],y[3][3]={0};
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>x[i][j];
            y[i][j]=0;
        }
    }
    int a,b,k=0;
    cin>>a;
    while(a--)
    {
        cin>>b;
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                if(x[i][j]==b){y[i][j]=1;k++;break;}
            }
        }
    }
    if(k==9)
    {
        cout<<"Yes"<<endl;
    }
    else if(k<3)
    {
        cout<<"No"<<endl;
    }
    else
    {


    int flag=0;
    for(int i=0;i<3;i++)
    {
        int add=0;
        for(int j=0;j<3;j++)
        {
            add+=y[i][j];
        }
        if(add==3){flag=1;break;}
    }
    for(int j=0;j<3;j++)
    {
        int add=0;
        for(int i=0;i<3;i++)
        {
            add+=y[i][j];
        }
        if(add==3){flag=1;break;}
    }
    int add3=0;
    for(int i=0;i<3;i++)
    {
        add3+=y[i][i];
    }
    if(add3==3)flag=1;
    int add4=0;
    for(int i=0;i<3;i++)
    {
        add4+=y[i][2-i];
    }
    if(add4==3)flag=1;
    if(flag==0)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define HMAX 50
#define WMAX 50
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
char L[HMAX][WMAX];
int w,h;

void dfsW(int y, int x){
  if (L[y][x]=='.')
    L[y][x]='P';
  for (int i=0;i<4;i++){
    int mx=x+dx[i];
    int my=y+dy[i];
    if ((0<=mx && mx<w) && (0<=my && my<h) && (L[my][mx]=='.'))
      dfsW(my,mx);
  }  
}

void dfsB(int y, int x){
  if (L[y][x]=='.')
    L[y][x]='Q';
  else if (L[y][x]=='P')
    L[y][x]='N';
  for (int i=0;i<4;i++){
    int mx=x+dx[i];
    int my=y+dy[i];
    if ((0<=mx && mx<w) && (0<=my && my<h) && (L[my][mx]=='.' || L[my][mx]=='P'))
      dfsB(my,mx);
  }  
}

int main(){
  while (true){
    scanf("%d %d",&w,&h);
    if (w==0 && h==0) return 0;
    for (int i=0;i<h;i++)
      scanf("%s",L[i]);
    for (int i=0;i<h;i++){
      for (int j=0;j<w;j++)
	if (L[i][j]=='W')
	  dfsW(i,j);
    }
    for (int i=0;i<h;i++){
      for (int j=0;j<w;j++)
	if (L[i][j]=='B')
	  dfsB(i,j);
    }
    int cntB=0,cntW=0;
    for (int i=0;i<h;i++){
      for (int j=0;j<w;j++)
	if (L[i][j]=='P')
	  cntW++;
	else if (L[i][j]=='Q')
	  cntB++;
    }
    printf("%d %d\n",cntB,cntW);
  }
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,q;
	cin>>n>>m>>q;
	vector<int>a(q);
	vector<int>b(q);
	vector<int>c(q);
	vector<int>d(q);
	for(int i=0;i<q;++i)
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	vector<int>A(n);
	int ans=0;
	function<void(int,int)>dfs=[&](int p,int low){
		if(p==n){
			int tot=0;
			for(int i=0;i<q;++i)
				tot+=(A[b[i]-1]-A[a[i]-1]==c[i])*d[i];
			ans=max(ans,tot);
			return;
		}
		for(int i=low;i<=m;++i){
			A[p]=i;
			dfs(p+1,i);
			A[p]=0;
		}
	};
	dfs(0,1);
	cout<<ans;
	return 0;
}

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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct mint {
  ll x;
  mint(ll x=0) : x(x%mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  rep(i, 4001) rep(j, i+1) {
    c[i+1][j] += c[i][j];
    c[i+1][j+1] += c[i][j];
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, k; std::cin >> n >> k;
  init();
  auto comb = [&](int n, int k) -> mint {
    return c[n][k];
  };
  auto ff = [&](int n, int k) -> mint {
    return comb(n+k-1, k-1);
  };
  auto f = [&](int n, int k) -> mint {
    if (n == 0 && k == 0) return 1;
    if (n < k) return 0;
    if (k < 1) return 0;
    return ff(n-k, k);
  };
  rrep(i, k) {
    mint blue = f(k, i);
    mint red = ff(n-k-(i-1), i+1);
    mint ans = blue * red;
    std::cout << ans.x << "\n";
  }
}


Measured memory_bytes: 125568
n, W = map(int, input().split())
value = []
weight = []

n1 = n // 2
n2 = n - n1

vw1 = [[0, 0]]
vw2 = [[0, 0]]

for _ in range(n1):
  v, w = map(int, input().split())
  sz = len(vw1)
  for i in range(sz):
    p = vw1[i][:]
    p[0] += w
    p[1] += v
    vw1.append(p)

for _ in range(n2):
  v, w = map(int, input().split())
  sz = len(vw2)
  for i in range(sz):
    p = vw2[i][:]
    p[0] += w
    p[1] += v
    vw2.append(p)

vw1.sort()
vw2.sort()

maxv = 0
for i in range(2 ** (n - n // 2)):
  w, v = vw2[i]
  if maxv < v:
    maxv = v
  else:
    vw2[i][1] = maxv


ind1 = 0
ind2 = 2 ** (n - n // 2) - 1
ans = 0
while ind1 < 2 ** (n // 2) and ind2 >= 0:
  w1, v1 = vw1[ind1]
  w2, v2 = vw2[ind2]
  while ind2 > 0 and w1 + w2 > W:
    ind2 -= 1
    w2, v2 = vw2[ind2]
  if w1 + w2 <= W:
    ans = max(ans, v1 + v2)
  ind1 += 1

print(ans)


Measured memory_bytes: 358560
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define P pair<LL,LL>
const LL inf = 0x3f3f3f3f;
const LL mod = 924844033;
const LL N = 1e5+10;
template <typename tp> inline void read(tp &x)
{
	x=0;char c=getchar();int f=0;
	for(;c>'9'||c<'0';f|=(c=='-'),c=getchar());
	for(;c<='9'&&c>='0';x=(x<<3)+(x<<1)+c-'0',c=getchar());
	if(f) x=-x;
}
LL n,e,t;
LL x[N],dp[N];
signed main()
{
	read(n),read(e),read(t);
	for(int i=1;i<=n;i++) read(x[i]);
	memset(dp,inf,sizeof(dp));
	LL flag=inf;dp[0]=0;
	for(int i=1,now=0;i<=n;i++)
	{
		while(t<=2*(x[i]-x[now+1]))
			flag=min(flag,dp[now]-2*x[now+1]),now++;
		dp[i]=min(dp[now]+t,flag+2*x[i]);
	}
	printf("%lld\n",dp[n]+e);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int _;scanf("%d",&_);
	while(_--){
		int a,b,l,r;scanf("%d %d %d %d",&a,&b,&l,&r);
		int H=1,T=max(a,b),s=T+1,mid,m1,m2,m3;
		while(H<=T){
			mid=H+T>>1;
			if(1ll*a*mid+mid>=b&&1ll*b*mid+mid>=a)T=mid-1,s=mid;else H=mid+1;
		}
		H=1;T=a/s;m1=0;
		while(H<=T){
			mid=H+T>>1;
			int A=a-mid*s,B=b-mid+1;
			if(1ll*A*s+s>=B&&1ll*B*s+s>=A)H=mid+1,m1=mid;else T=mid-1;
		}
		H=1;T=s-1;m2=0;
		while(H<=T){
			mid=H+T>>1;
			int A=a-m1*s-mid,B=b-m1;
			if(1ll*A*s+s>=B&&1ll*B*s+s>=A&&A>=0&&B>=0)H=mid+1,m2=mid;else T=mid-1;
		}m3=b-m1-(a-m1*s-m2)*s;
		for(int i=l;i<=r;++i){
			if(i<=m1*(s+1))putchar(65+(i%(s+1)==0));else
			if(i-m1*(s+1)<=m2+m3)putchar(65+(i-m1*(s+1)>m2));else
			putchar(65+((i-m1*(s+1)-m2-m3)%(s+1)!=1));
		}putchar('\n');
	}
}

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


int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

    string s;

    cin >> s;

    int len = s.length();

    for(int i=0; i<len; i++)
    {
        cout << 'x';
    }

    return 0;
}









Measured memory_bytes: 3584
import java.util.*;

public class Main {
    public static void main(String...args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        PriorityQueue<Long> pq = new PriorityQueue(n, Comparator.reverseOrder());
        for(int i = 0; i < n; i++){
            Long q = Long.parseLong(String.valueOf(in.nextInt()));
            pq.add(q);
        }
        for (int i = 1; i <= m; i++) {
            Long l = pq.poll() / 2L;
            pq.add(l);
        }
        Long result = 0L;
        int l = pq.size();
        for(int i = 0; i < l; i++) {
            result += pq.poll();

        }
        System.out.println(result);
    }
}


Measured memory_bytes: 63300
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
    int H, W;
    cin >> H >> W;
    vector<string> M(H);
    for (int i = 0; i < H; i++) {
        cin >> M[i];
    }
    bool ans = true;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            bool ok = false;
            if (M[i][j] == '.') continue;
            for (int k = 0; k < 4; k++) {
                int tx = j + dx[k];
                int ty = i + dy[k];
                if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue;
                if (M[ty][tx] == '#') {
                    ok = true;
                }
            }
            if (!ok) {
                ans = false;
            }
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
void solve()
{
    string a,b;
    cin>>a>>b;
    int ans=INT_MAX;
    for(int i=0;i<=a.size()-b.size();i++)
    {int cnt=0;
        for(int j=0;j<b.size();j++)
        {
            if(a[i+j]!=b[j])
                cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  deque<int> dq;
  rep(i,n){
    int a; cin>>a;
    if(i%2==0)
    dq.pb(a);
    else
    dq.push_front(a);
  }
  if(n%2!=0){
    for(auto itr=dq.end()-1;dq.begin()<=itr;itr--){
      cout<<*itr<<" ";
    }
  }else{
    for(auto itr=dq.begin();dq.end()!=itr;itr++){
      cout<<*itr<<" ";
    }
  }

  return 0;
}


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

using namespace std;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, c;
    cin >> n >> k >> c;
    string schedule;
    cin >> schedule;
    vector<int> from_left(k), from_right(k);
    
    // Populate from_left
    int pos = 0;
    for (int i = 0; i < k; ++i) {
        while (schedule[pos] == 'x') {
            ++pos;
        }
        from_left[i] = pos;
        pos += c + 1;
    }
    
    // Populate from_right
    pos = n-1;
    for (int i = k-1; i >= 0; --i) {
        while (schedule[pos] == 'x') {
            --pos;
        }
        from_right[i] = pos;
        pos -= c + 1;
    }
    
    vector<int> fixed_days;
    for (int i = 0; i < k; ++i) {
        if (from_left[i] == from_right[i]) {
            fixed_days.push_back(from_left[i]);
        }
    }
    for (auto day : fixed_days) {
        cout << day + 1 << "\n";
    }
    return 0;
}


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

template <typename T>
class avl_tree {
	struct node {
		T val;
		int dep, size;
		node *ch[2];
		node() : node(0) {}
		node(T v, node* l = nullptr, node* r = nullptr)
			: val(v), dep(1), size(1), ch{ l, r } {}
		void *operator new(size_t) {
			static const int pmax = 2e5;
			static int p = 0;
			static node pool[pmax];
			return pool + p++;
		}
	};
	int depth(node *t) { return !t ? 0 : t->dep; }
	int count(node *t) { return !t ? 0 : t->size; }
	node *update(node *t) {
		t->dep = max(depth(t->ch[0]), depth(t->ch[1])) + 1;
		t->size = count(t->ch[0]) + count(t->ch[1]) + 1;
		return t;
	}
	node *rotate(node *t, int b) {
		node *s = t->ch[!b];
		t->ch[!b] = s->ch[b];
		s->ch[b] = t;
		update(t);
		return update(s);
	}
	node *fix(node *t) {
		if (!t) return t;
		int dd = depth(t->ch[0]) - depth(t->ch[1]);
		if (abs(dd) < 2) return t;
		int b = dd < 0;
		if (depth(t->ch[b]->ch[!b]) > depth(t->ch[b]->ch[b])) {
			t->ch[b] = rotate(t->ch[b], b);
		}
		return rotate(t, !b);
	}
	node *insert(node *t, T val) {
		if (!t) return new node(val);
		if (val == t->val) return t;
		int b = val > t->val;
		t->ch[b] = insert(t->ch[b], val);
		return fix(update(t));
	}
	T minimum(node *t) {
		while (t->ch[0]) t = t->ch[0];
		return t->val;
	}
	node *erase(node *t) {
		if (!t) return t;
		if (!t->ch[0] && !t->ch[1]) return nullptr;
		if (!t->ch[0]) return t->ch[1];
		if (!t->ch[1]) return t->ch[0];
		T mini = minimum(t->ch[1]);
		return fix(update(new node(mini, t->ch[0], erase(t->ch[1], mini))));
	}
	node *erase(node *t, T val) {
		if (!t) return t;
		if (val == t->val) return fix(erase(t));
		int b = val > t->val;
		t->ch[b] = erase(t->ch[b], val);
		return fix(update(t));
	}
	node *root;
public:
	avl_tree() : root(nullptr) {}
	int size() {
		return count(root);
	}
	void insert(T val) {
		root = insert(root, val);
	}
	void erase(T val) {
		root = erase(root, val);
	}
	bool count(T val) {
		node *t = root;
		while (t) {
			if (t->val == val) return true;
			t = t->ch[val > t->val];
		}
		return false;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int q;
	cin >> q;
	avl_tree<int> avl;
	while (q--) {
		int com, x;
		cin >> com >> x;
		if (com == 0) {
			avl.insert(x);
			printf("%d\n", avl.size());
		}
		else if (com == 1) {
			puts(avl.count(x) ? "1" : "0");
		}
		else {
			avl.erase(x);
		}
	}
	return 0;
}



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

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

string yn(bool x){
    return x ? "Yes" : "No";
}

int abs(int x){
    return x >= 0 ? x : -x;
}



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

    set<int> m;

    int cnt = 1;
    while(true){
        auto it = m.find(s);
        if(it != m.end()) break;
        m.insert(s);

        if(s %2 == 0) s /= 2;
        else s = 3 * s + 1;

        cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, P = map(int, raw_input().split())

if N == 1:
    print P
    exit()

if N > 60:
    print 1
    exit()

num = 1
ans = 0
while True:
    if P % (num ** N) == 0:
        ans = num
    if P < (num ** N):
        break
    num += 1

print ans

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

int nagasa(string s) {
   return (int)(s.length());
}

int main() {
   string s, t;
   cin >> s >> t;
   int ns = nagasa(s);
   for (int i=0; i<ns; i++) {
      if (s[i]!=t[i]) {
         cout << "No" << endl;
         return 0;
      }
   }
   if (ns+1 == nagasa(t)) {
      cout << "Yes" << endl;
   }
   else cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=1e5+5;
const int mod=1e9+7;
int add(int a,int b)
{
    a+=b;
    if(a>=mod)
        a-=mod;
    return a;
}
int mul(int a,int b)
{
    return ((ll)a*b)%mod;
}
vector<vector<int> > graf(N);
map<int,int> mapa[N][2];
int calc(int tr,int par,int color)
{
    if(mapa[tr][color][par]!=0)
        return mapa[tr][color][par];
    int sol=1;
    for(auto p:graf[tr])
    {
        if(p==par)
            continue;
        if(color==0)
        {
            sol=mul(sol,add(calc(p,tr,0),calc(p,tr,1)));
        }
        else
        {
            sol=mul(sol,calc(p,tr,0));
        }
    }
    mapa[tr][color][par]=sol;
    return sol;
}
int main()
{
    int n;
    scanf("%i",&n);
    for(int i=1;i<n;i++)
    {
        int a,b;
        scanf("%i %i",&a,&b);
        a--;
        b--;
        graf[a].pb(b);
        graf[b].pb(a);
    }
    printf("%i\n",add(calc(0,-1,0),calc(0,-1,1)));
    return 0;
}


Measured memory_bytes: 35584
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}
char readc() {
	char c=getchar();
	while (c!='-'&&c!='+') c=getchar();
	return c;
}

const int N=100000+10;

int n;
ll dp[N][3];

int main() {
	n=read();
	dp[1][0]=read(),dp[1][1]=dp[1][2]=-1e18;
	for (int i=2;i<=n;++i) {
		char op=readc(); int w=read();
		if (op=='+') {
			dp[i][0]=max({dp[i-1][0],dp[i-1][1],dp[i-1][2]})+w;
			dp[i][1]=max(dp[i-1][1],dp[i-1][2])-w;
			dp[i][2]=dp[i-1][2]+w;
		} else {
			dp[i][0]=max({dp[i-1][0],dp[i-1][1],dp[i-1][2]})-w;
			dp[i][1]=max(max(dp[i-1][1],dp[i-1][2])+w,dp[i-1][0]-w);
			dp[i][2]=max(dp[i-1][1],dp[i-1][2])+w;
		}
	}
	printf("%lld\n",max({dp[n][0],dp[n][1],dp[n][2]}));
	return 0;
}


Measured memory_bytes: 6120
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define mp make_pair
#define pb push_back
void solve(){
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	for(ll i=k;i<=n+1;i++){
		ll mn=((i*(i-1))/2)%mod;
		ll mx=((n+1)*n)/2-((n+1-i)*(n-i))/2;
		ans=((ans+mx-mn+1)%mod+mod)%mod;
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}



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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a == b && b == c) {
    cout << 1 << endl;
  } else if (a == b || b == c || a == c) {
    cout << 2 << endl;
  } else {
    cout << 3 << endl;
  }
  
  
  return 0;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}
 
 
struct Comp {
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    if (a.first != b.first) {
      return a.first < b.first;
    }
    return a.second > b.second;
  }
 
}comp_functor;
 
 
int main() 
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ;
    
    long long int i,a[3000006],b[3000006],x,y,z,c=0,temp,t,n,h;
    
    cin>>n>>h;
    
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    
    sort(a,a+n);
    sort(b,b+n);
    
    for(i=n-1;i>=0;i--)
    {
        if(b[i]>a[n-1])
        {
            h-=b[i];
        }
        else
        {
            break;
        }
        
        c++;
        
        if(h<=0)
        {
            break;
        }
    }
    
    if(h<=0)
    {
        cout<<c;
        return 0;
    }
    
    //cout<<c<<endl;

    c+=h/a[n-1];
    
    if(h%a[n-1]!=0)
    {
        c++;
    }
    
    cout<<c;
    
    return 0;
}

Measured memory_bytes: 5248
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

void solv() {

	ll n;
	cin >> n;
	priority_queue<pll,vector<pll>,greater<pll>> q;

	for (size_t i = 0; i < n; i++)
	{
		ll a, b;
		cin >> a >> b;
		q.push(make_pair(b, a));
	}

	ll nt = 0;
	while (!q.empty())
	{
		pll p = q.top();
		q.pop();
		nt += p.second;
		if (p.first < nt) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;

}

int main() {
	//	COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int a=0;
    int b;
    for (int i=0;i<s.length();i++){
        if(s[i]=='0') a++;
    }
    b=s.length()-a;
    if(b<a) a=b;
    cout<<a*2<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
// using cplx = complex<double>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); ++i)
const ll mod = 1e9 + 7;

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

bool pairCompare(const P &firstElof, const P &secondElof) {
    return firstElof.second < secondElof.second;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    i64 N, A, B;
    cin >> N >>  A >> B;
    cout << N/(A+B)*A + min(N%(A+B), A) << endl;
}


Measured memory_bytes: 256
S = input()
Q = int(input())

reverseNum = 0
initialTopAppend = ""
initialLastAppend = ""
for i in range(Q):
    l = input().split()
    if l[0] == "1":
        reverseNum += 1
        continue
    if reverseNum % 2 == 0:
        if l[1] == "1":
            initialTopAppend = l[2] + initialTopAppend
        else:
            initialLastAppend += l[2]
    else:
        if l[1] == "1":
            initialLastAppend += l[2]
        else:
            initialTopAppend = l[2] + initialTopAppend

ans = initialTopAppend + S + initialLastAppend

if reverseNum % 2 != 0:
    ans = ans[::-1]

print(ans)

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

int main() {
  int n,q,l,r;
  int x[114514]={0};
  std::string a;
  cin >> n >> q >> a;
  for(int i=1;i<n;i++){
    x[i]=x[i-1];
    if(a[i-1]=='A'&&a[i]=='C')x[i]++;
  }
  for(int i=0;i<q;i++){
    cin >> l >> r;
    cout << x[r-1]-x[l-1] << endl;
  }
}


Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int main()
{
	int n,l,r,c=0,t;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		t=r-l+1;
		c+=t;
	}
	cout<<c<<endl;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, k;
int a[100010];
bool win[100010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    rep(i, 0, n) cin >> a[i];
    int MIN = *min_element(a, a + n);
    rep(i, 0, MIN) win[i] = false;
    rep(i, MIN, k + 1){
        win[i] = false;
        rep(j, 0, n){
            win[i] |= a[j] <= i && !win[i - a[j]];
        }
    }
    if(win[k]) cout << "First" << endl;
    else cout << "Second" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;cin >> n;
  int total = 0; 
 
  for (int i = 0; i<n; i++) {
    int r;cin >> r;
    int l;cin >> l;
    total += (l - r + 1);
  }
 cout << total;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

table = [0] * 100001

c = 0
s = sum(A)
 
for i in A:
    table[i] += 1
 
for i in range(Q):
    B, C = map(int,input().split())
    c = table[B]
    s += (C - B) * c
    table[C] += table[B]
    table[B] = 0
    print(s)


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

int main() {
	const ll MOD = 1e9 + 7;
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; ++i) { cin >> s[i]; }

	vector<vector<ll>> dp(H, vector<ll>(W, 0));
	dp[0][0] = 1;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (s[i][j] == '#') { continue; }

			int d = i + 1;
			int r = j + 1;
			if ((d < H) && (s[d][j] == '.')) {
				dp[d][j] = (dp[d][j] + dp[i][j]) % MOD;
			}
			if ((r < W) && (s[i][r] == '.')) {
				dp[i][r] = (dp[i][r] + dp[i][j]) % MOD;
			}
		}
	}

	cout << dp[H - 1][W - 1] << endl;

	return 0;
}


Measured memory_bytes: 9216
N = int(input())

B = list(map(int, input().split()))
A = [0] * N

A[0] = B[0]
A[1] = B[0]

for i in range(1, N-1):
    if A[i] <= B[i]:
        A[i+1] = B[i]
    else:
        A[i] = B[i]
        A[i+1] = B[i]

print(sum(A))


Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = input[0];
        var K = input[1];

        double ans = 0;
        for (var i = 1; i <= N; i++) {
           var cnt = 0;
           double a = 1 / (double)N;
           double b = i;
           while (b < K) {
               b *= 2;
               cnt++;
           }
           ans += a * (1 / Math.Pow(2, cnt));
        }
        
        Console.WriteLine(ans);

    }
}


Measured memory_bytes: 11348
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}


signed main(){
	ll a,b,c;
	cin >> a >> b >> c;
	
	if( (a <= c && c <= b)|| ( b <= c && c <= a)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;

}

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

struct Node {
    int value;
    Node *prev, *next;
};

Node *nil;

void init() {
    nil = new Node;
    nil->next = nil;
    nil->prev = nil;
}

void insert(int value) {
    Node *node = new Node;
    node->value = value;
    node->next = nil->next;
    nil->next->prev = node;
    nil->next = node;
    node->prev = nil;
}

Node* listSearch(int value) {
    Node *cur = nil->next;
    while (cur != nil && cur->value != value) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    delete t;
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteValue(int value) {
    deleteNode(listSearch(value));
}

void print() {
    Node *cur = nil->next;
    int first = 0;
    while (1) {
        if (cur == nil) break;
        if (first > 0) printf(" ");
        ++first;
        printf("%d", cur->value);
        cur = cur->next;
    }
    printf("\n");
}

int main() {

    int n;
    cin >> n;
    init();
    for (int i = 0; i < n; ++i) {
        char command[32];
        cin >> command;
        if (command[0] == 'i') {
            int value;
            cin >> value;
            insert(value);
        } else if (command[0] == 'd') {
            if (strlen(command) > 6) {
                if (command[6] == 'F') deleteFirst();
                else if (command[6] == 'L') deleteLast();
            } else {
                int value;
                cin >> value;
                deleteValue(value);
            }
        }
    }

    print();
    return 0;
}

Measured memory_bytes: 32428
S = input()
T = input()
ls = len(S)
lt = len(T)
mx = 0
for i in range(ls - lt + 1):
  S2 = S[i:i + lt]
  cnt = 0
  for j in range(lt):
    if S2[j] == T[j]:
      cnt += 1
  mx = max(mx, cnt)

print(lt - mx)

Measured memory_bytes: 8988
# AGC 043 A
H,W = map(int, input().split())
table = [input() for _ in range(H)]

inf = 10**9
dp = [[inf] * (W+1) for _ in range(H+1)]
dp[0][0] = 0 if table[0][0] == "." else 1

for h in range(H):
    for w in range(W):
        flg = table[h][w] == "." and (table[h][w+1] == "#" if w < W-1 else True) 
        dp[h][w+1] = min(dp[h][w+1], dp[h][w] + 1 if flg else dp[h][w])

        flg = table[h][w] == "." and (table[h+1][w] == "#" if h < H-1 else True)
        dp[h+1][w] = dp[h][w] + 1 if flg else dp[h][w]

print(dp[H-1][W-1])


Measured memory_bytes: 9124
n,x = map(int,input().split())
a = list(map(int,input().split()))

a.sort()
c = 0
i = 0
while(True):
    if(i >= n - 1):
        break
    if(x < a[i]):break
    c += 1
    x -= a[i]
    i += 1
if(x == a[i]):c += 1
print(c)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int INF = 5*1e8;

class UnionFind{
  vi p,r;
public:
  UnionFind(int n):p(n,-1),r(n,0){ }
  inline int find(int x){ return (p[x]<0)?x:(p[x] = find(p[x])); }
  inline bool same(int x,int y){return find(x)==find(y);}
  inline void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;

    if(r[x] < r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }
};

inline int MSB(int x){ return x>0?31-__builtin_clz(x):-1; }

struct LCA{
  vector<vi> par,w;
  vi depth;
  int ln;
  
  LCA(void){}
  LCA(const vector<vi> &t, const vi &weight, int root){
    int n = t.size(); ln = MSB(n)+1;
    depth.resize(n); par.resize(ln,vi(n));
    w.resize(ln,vi(n)); w[0] = weight;

    stack< pair<int,int> > s;
    s.push(make_pair(root,-1));
    while(s.size()){
      int v = s.top().first, p = s.top().second; s.pop();
      par[0][v] = p;
      depth[v] = ((p<0)?0:(depth[p]+1));

      for(int u : t[v]){
	if(u != p)s.push(make_pair(u,v));
      }
    }

    rep(k,ln-1)rep(v,n){
      if(par[k][v]<0){
	par[k+1][v] = -1;
	w[k+1][v] = INF;
      }else{
	par[k+1][v] = par[k][par[k][v]];
	w[k+1][v] = min(w[k][v], w[k][par[k][v]]);
      }
    }
  }

  inline int min_lca(int u, int v)const{
    int res = INF;
    if(depth[u] > depth[v])swap(u,v);
    rep(k,ln){
      if((depth[v]-depth[u])>>k & 1){
	res = min(res, w[k][v]);
	v = par[k][v];
      }
    }

    if(u==v)return min(res, w[0][u]);
    for(int k = ln-1;k>=0;k--){
      if(par[k][u] != par[k][v]){
	res = min(res, min(w[k][u], w[k][v]));
	u = par[k][u]; v = par[k][v];
      }
    }
    return min(res, min(w[1][u], w[1][v]));
  }
};

int main(){
  int n,m,k,Q;
  scanf("%d%d%d%d",&n,&m,&k,&Q);
  vector< vector<pii> > g(n);
  rep(i,m){
    int a,b,l;
    scanf("%d%d%d",&a,&b,&l); a--; b--;
    g[a].push_back(pii(b,l));
    g[b].push_back(pii(a,l));
  }

  vi dis(n,INF);
  priority_queue<pii> q;
  rep(i,k){
    int f;
    scanf("%d",&f); f--;
    dis[f] = 0;
    q.push(pii(0,f));
  }

  while(q.size()){
    pii p = q.top(); q.pop();
    int d = -p.first, v = p.second;
    if(dis[v] < d)continue;
   
    for(pii nxt : g[v]){
      int u = nxt.first, cost = d+nxt.second;
      if(dis[u] > cost){
	dis[u] = cost;
	q.push(pii(-cost,u));
      }
    }
  }

  vector<pii> order(n);
  rep(i,n)order[i] = pii(dis[i],i);

  sort(all(order)); reverse(all(order));
  UnionFind uf(n);

  vector<vi> tree(n);
  rep(i,n){
    int v = order[i].second;
    priority_queue<pii> nxt;
    for(pii p : g[v]){
      int u = p.first;
      nxt.push(pii(dis[u],u));
    }

    while(nxt.size() && nxt.top().first>=dis[v]){
      int u = nxt.top().second; nxt.pop();
      if(!uf.same(v,u)){
	tree[u].push_back(v);
	tree[v].push_back(u);
	uf.unite(v,u);
      }
    }
  }
 
  LCA query(tree, dis, 0);
  rep(i,Q){
    int u,v;
    scanf("%d%d",&u,&v); u--; v--;
    printf("%d\n",query.min_lca(u,v));
  }
}

Measured memory_bytes: 31012
S = input()

AGCT = {"A", "G", "C", "T"}

j = 0
l = 0
l_log = []

while j < len(S):
    if S[j] in AGCT:
        l += 1
        if j == len(S) - 1:
            l_log.append(l)
    else:
        l_log.append(l)
        l = 0
    j += 1

print(max(l_log))


Measured memory_bytes: 3060
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nmvp = readln.split.to!(long[]);
    auto N = nmvp[0];
    auto M = nmvp[1];
    auto V = nmvp[2];
    auto P = nmvp[3];
    auto as = readln.split.to!(long[]);
    sort!"a > b"(as);

    bool check(long i) {
        auto a = as[i] + M;
        if (as[P-1] > a) return false;

        auto x = (V - P + 1 - N + i) * M;
        if (x <= 0) return a >= as[P-1];

        foreach (j; P-1..i) {
            x -= min(M, a - as[j]);
            if (x <= 0) break;
        }

        return x <= 0;
    }

    if (check(N-1)) {
        writeln(N);
        return;
    }

    long l = P-1, r = N-1;
    while (l+1 < r) {
        auto m = (l+r)/2;
        if (check(m)) {
            l = m;
        } else {
            r = m;
        }
    }
    writeln(r);
}

Measured memory_bytes: 4532