akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=510, inf=2e9;

int h, w;
char B[MX][MX];
bool X[MX][MX], Y[MX][MX];

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>h>>w;
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
            cin>>B[i][j];
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
            if(B[i][j]=='#') X[i][j]=Y[i][j]=true;
    for(int i=1; i<=h; i++)
        for(int j=2; j<=w-1; j++)
            if(i%2==0) X[i][j]=true;
            else Y[i][j]=true;
    for(int i=1; i<=h; i++)
        X[i][1]=true, Y[i][w]=true;
    for(int i=1; i<=h; i++,cout<<'\n')
        for(int j=1; j<=w; j++)
            cout<<(X[i][j] ? '#' : '.');
    cout<<'\n';
    for(int i=1; i<=h; i++,cout<<'\n')
        for(int j=1; j<=w; j++)
            cout<<(Y[i][j] ? '#' : '.');
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<double> p(n);
    rep(i, n) {
        cin >> p[i];
        p[i] = (1.0 + p[i]) / 2;
    }
    double now = 0.0;
    rep(i, k) now += p[i];
    double ans = now;
    for (int i = k; i < n; i++) {
        now += p[i];
        now -= p[i - k];
        chmax(ans, now);
    }
    cout << fixed << setprecision(20) << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool> vecbool;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> vecstr;
typedef vector<vecint> vec2int;
typedef vector<vecbool> vec2bool;
int dx[4]{-1, +1, 0, 0};
int dy[4]{0, 0, -1, +1};
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main() {
  init();
  int n;
  cin >> n;
  n++;
  ll sum = 0;
  REP(i, n) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3692
N, K = [int(x) for x in input().split(' ')]
A = [int(x) for x in input().split(' ')]
N = len(A)

S = A
D = [0] * N
for _ in range(K):
  for x in range(N):
    D[x] = 0
  for x in range(N):
    D[max(0, x - S[x])] += 1
    if(x + S[x] + 1 < N):
      D[x + S[x] + 1] -= 1
  S[0] = D[0]
  for x in range(1, N):
    S[x] = S[x-1] + D[x]
  if all([x == N for x in S]):
    break
      
print(' '.join([str(x) for x in S]))


Measured memory_bytes: 172440
#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define LL long long
using namespace std;

int n,tar,ans,len;
string s;
int main(){
	cin>>s;
	int dif=0;
	int sam=0;
	len=s.length();
	for (int i=1;i<len;i++){
		if (s[i]!=s[i-1]) dif++;
		else sam++;
	}
	if (sam+1==len) cout<<"0\n";
	else cout<<dif<<"\n";
}

Measured memory_bytes: 3704
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  n <- getl toInt
  when (n /= 0) $ do
    xs <- rgetl n toInt
    print $ solve xs
    main
    
solve :: [Int] -> Int
solve xs = sum . zipWith (*) [0 .. length xs - 1] . sortBy (\a b -> b `compare` a) $ xs

toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

rgetl :: Int -> (String -> a) -> IO [a]
rgetl n f = map f <$> replicateM n getLine

tests :: [Test]
tests = [
  "solve1" ~: 0 ~=? solve [33],
  "solve2" ~: 2 ~=? solve [55,2],
  "solve3" ~: 31 ~=? solve [2,6,4,3,9]
  ]

Measured memory_bytes: 7508
from itertools import permutations
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
if p==q:
    print(0)
else:
    p, q = tuple(p), tuple(q)
    l = [i for i in range(1, n+1)]
    flag = False
    ss = 0
    for i, each in enumerate(permutations(l)):
        if each == p or each == q:
            if flag:
                print(abs(ss - i))
            else:
                flag = True
                ss = i

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n, x;
    cin >> n >> x;

    int m = 2 * n - 1;

    if (x == 1 || x == m) {
        cout << "No" << endl;
        quick_exit(0);
    }

    cout << "Yes" << endl;

    vector<int> a(m);
    if (n == 2) {
        for (int i = 0; i < m; i++) {
            a[i] = i + 1;
        }
    } else {
        if (x == 2) {
            a[n] = m - 1;
            a[n - 1] = x;
            a[n - 2] = 1;
            a[n - 3] = m;
        } else {
            a[n] = 2;
            a[n - 1] = x;
            a[n - 2] = m;
            a[n - 3] = 1;
        }
        int j = 3;
        for (int i = 0; i < m; i++) {
            if (a[i] == 0) j += j == x, a[i] = j++;
        }
    }

    for (int i = 0; i < m; i++) {
        cout << a[i] << '\n';
    }

    return 0;
}

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

int main(){
  double s,l;
  int sc,lc,g;

  while(cin >> s >> l){
    if(s<35.5)sc = 0;
    else if(s<37.5)sc = 1;
    else if(s<40.0)sc = 2;
    else if(s<43.0)sc = 3;
    else if(s<50.0)sc = 4;
    else if(s<55.0)sc = 5;
    else if(s<70.0)sc = 6;
    else sc = 7;

    if(l<71.0)lc = 0;
    else if(l<77.0)lc = 1;
    else if(l<83.0)lc = 2;
    else if(l<89.0)lc = 3;
    else if(l<105.0)lc = 4;
    else if(l<116.0)lc = 5;
    else if(l<148.0)lc = 6;
    else lc = 7;

    if(lc<sc)g=sc;
    else g=lc;

    if(g == 0)cout << "AAA" << endl;
    else if(g == 1)cout << "AA" << endl;
    else if(g == 2)cout << "A" << endl;
    else if(g == 3)cout << "B" << endl;
    else if(g == 4)cout << "C" << endl;
    else if(g == 5)cout << "D" << endl;
    else if(g == 6)cout << "E" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 
ll MOD = 1000000007;
ll INF =1<<29;
ll dp[100100];
 
int main() {
     int a,b;
     cin >> a>>b;
     int c = b-a;
     int A=0;
     for(int i = 1;i<c;++i){
         A+=i;
     }
     cout << A-a <<endl;
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())

N,L = LI()
S = [0 for i in range(N)]
for i in range(N):
    S[i] = str(input())

S.sort()
print("".join(S))


Measured memory_bytes: 6604
#include <bits/stdc++.h>
using namespace std;
const int N=2100;
bitset <N*N> dp;
int n,a[N],sum;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for (int i=1;i<=n;i++) sum+=a[i];
	dp[0]=1;
	for (int i=1;i<=n;i++) dp|=(dp<<a[i]);
	for (int i=(sum+1)/2;i<=sum;i++)
	{
		if (dp[i]==1)
		{
			printf("%d\n",i);
			return 0;
		}
	}
}

Measured memory_bytes: 5452
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

    int n;
    cin >> n;
    vector<int>arr(n);
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr.begin(), arr.end());
    int num = INF, ans;
    for(int i = 0; i < n-1; i++) {
        if(max(arr[i], arr.back()-arr[i]) < num)
            num = max(arr[i], arr.back()-arr[i]), ans = arr[i];
    }
    cout << arr.back() <<' ' << ans;



	return 0;
}


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

int list_num(int* l_tensuu,int size)
{
	int ans=0;
	for(int i=0;i <= size - 1;i++)
		ans += l_tensuu[i];
	return ans;
}

int main()
{
	int size_x;
	int size_y=5;
	while(1){
		cin >> size_x;
		if(size_x==0)
			break;
		else{
		//メモリ宣言
			int **array = new int*[size_x];
			for (int i = 0; i < size_x; i++) {
				array[i] = new int[size_y];
			}
			for(int i=0; i < size_x;i++){
				for(int j=0; j < size_y;j++){
					cin >> array[i][j];
				}
			}

			//合計を求める
			int *p = new int[size_x];
			for (int i=0;i<size_x;i++){
				p[i] = list_num(array[i],5);}

			//ソートする
			sort(p,p+size_x);

			//表示する
			cout << p[size_x-1] << " " << p[0] << endl;


			//メモリ解放
			for (int i = 0; i < size_x; i++) {
				delete[] array[i];
			}
			delete[] array;
		}
	}
	return 0;
}

Measured memory_bytes: 1224
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();
		int c = 1;
		for (int i = 0; i + 1 < S.length(); ++i) {
			if (S.charAt(i) != S.charAt(i + 1)) {
				++c;
			}
		}
		for (int i = 0; c > 1 && i < K; ++i) {
			if (c >= 3) {
				c -= 2;
			} else {
				c -= 1;
			}
		}
		System.out.println(N - c);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 24552
N = int(input())
D = [0] + list(map(int, input().split()))
Diffs = [[[0, 0] for i in range(N+1)] for j in range(N+1)]

candidates = []
for i in range(N+1):
  for j in range(i+1, N+1):
    di, dj = D[i], D[j]
    diff1, diff2 = abs(di-dj), min(24-di-dj, di+dj)
    candidates.extend([[i, j, diff1, 0], [i, j, diff2, 1]])
    Diffs[i][j] = [diff1, diff2]

ans = 0
for idx1, idx2, diff, c in candidates:
  conditions = [-1] * (N+1)
  if c == 0:
    conditions[idx1] = conditions[idx2] = 0
  else:
    conditions[idx1] = 0; conditions[idx2] = 1
  res = True
  for i in range(N+1):
    for j in range(i+1, N+1):
      if idx1 == i and idx2 == j:
        continue
      diff1, diff2 = Diffs[i][j]
      if diff1 < diff and diff2 < diff:
        res = False
        break
      elif diff1 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = 0; conditions[j] = 1
        elif c1 < 0:
          conditions[i] = 1 - c2
        elif c2 < 0:
          conditions[j] = 1 - c1
        else:
          if c1 == c2:
            res = False
            break
      elif diff2 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = conditions[j] = 0
        elif c1 < 0:
          conditions[i] = c2
        elif c2 < 0:
          conditions[j] = c1
        else:
          if c1 != c2:
            res = False
            break
    else:
      continue
    break
  if res:
    ans = max(ans, diff)

print(ans)

Measured memory_bytes: 44508
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int n;
	int ans=0;
	int ymin;
	pair<int,int> index;
	pair<int,int> r[100];
	pair<int,int> b[100];
	int pl[200][200];
	for(int i=0;i<200;i++)
	{
		for(int j=0;j<200;j++)
		{
			pl[i][j]=0;
		}
	}
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>r[i].first>>r[i].second;
		pl[r[i].first][r[i].second]++;
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i].first>>b[i].second;
	}
	sort(r,r+n);
	sort(b,b+n);
	for(int i=0;i<n;i++)
	{
		index = make_pair(0,0);
		ymin=-1;
		for(int j=b[i].first-1;j>=0;j--)
		{
			for(int k=b[i].second-1;k>ymin;k--)
			{
				if(pl[j][k]>0)
				{
					if(k>ymin)
					{
						index = make_pair(j,k);
						ymin=k;
					}
				}
			}
		}
		if(ymin!=-1)
		{
			pl[index.first][index.second]--;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
use std::io::*;
fn dijkstra(start: usize, graph: &Vec<Vec<(usize, i64)>>) -> Vec<i64> {
    let mut dist = vec![std::i64::MAX; graph.len()];
    dist[start] = 0;
    let mut bh = std::collections::BinaryHeap::new();
    bh.push((0i64, start));
    while let Some((cost, v)) = bh.pop() {
        if dist[v] < -cost {
            continue;
        }
        for e in graph[v].iter() {
            let nv = e.0;
            let nc = e.1;
            if dist[nv] > -cost + nc {
                dist[nv] = -cost + nc;
                bh.push((-dist[nv], nv));
            }
        }
    }
    dist
}
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let mut g: Vec<Vec<(usize, i64)>> = vec![Vec::new(); n];
    for _ in 0..m {
        let l: usize = itr.next().unwrap().parse().unwrap();
        let r: usize = itr.next().unwrap().parse().unwrap();
        let c: i64 = itr.next().unwrap().parse().unwrap();
        g[l - 1].push((r - 1, c));
    }
    for i in (1..n).rev() {
        g[i].push((i - 1, 0));
    }
    let d = dijkstra(0, &g);
    if d[n - 1] == std::i64::MAX {
        println!("-1");
    } else {
        println!("{}", d[n - 1]);
    }
}


Measured memory_bytes: 18684
def calc_max_grade(scores):
    sum_s = sum(s)
    if sum_s % 10 == 0:
        for x in sorted(s):
            if not x % 10 == 0:
                return sum_s - x
        return 0
    else:
        return sum_s

n = int(input())
s = []
for i in range(n):
    s.append(int(input()))

print(calc_max_grade(s))

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

public class Class1
{
    public static void Main(string[] args)
    {
        var str = Console.ReadLine().Split(' ');
        var list = new List<int>();
        foreach (var item in str)
        {
            list.Add(int.Parse(item));
        }
        var x = list[0];
        var a = list[1];
        var b = list[2];
        var xa = Absolute(x - a);
        var xb = Absolute(x - b);
        if (xa < xb)
            Console.WriteLine("A");
        else if (xb < xa)
            Console.WriteLine("B");
    }

    public static int Absolute(int param)
    {
        if (param < 0)
            return -param;
        else
            return param;
    }
}

Measured memory_bytes: 11092
n = int(input())
a = list(map(int,input().split()))
ans = [0,0]

s = max(a[0],1)
ans[0] = abs(s-a[0])
for i in range(n-1):
    if s * (s + a[i+1]) >= 0:
        if s > 0:
            ans[0] += s + a[i+1] + 1
            s = -1
        else:
            ans[0] += 1 - (s + a[i+1])
            s = 1
    else:
            s += a[i+1]
s = min(-1,a[0])
ans[1] = abs(s-a[0])
for i in range(n-1):
    if s * (s + a[i+1]) >= 0:
        if s > 0:
            ans[1] += s + a[i+1] + 1
            s = -1
        else:
            ans[1] += 1 - (s + a[i+1])
            s = 1
    else:
            s += a[i+1]
print(min(ans))

Measured memory_bytes: 14372
#include<bits/stdc++.h>
#define int long long
#define mx 100005
#define inf 1e18
using namespace std;
int arr[mx];
int n,k;
int dp[mx];
int dfs(int n){
	if(dp[n] != -1){
		return dp[n];
	}
	if(n <= 1){
		return 0;
	}
	int ret = inf;
	for(int i=1;i<=k;i++){
		if(n - i > 0){
			ret = min(ret,dfs(n-i) + abs(arr[n] - arr[n-i]));
		}
	}
	dp[n] = ret;
	return ret;	
}
signed main(){
	//freopen("input.txt","r",stdin);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<dfs(n);
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    ll sum = 0;
    map<ll, ll> mp;
    mp[0] = 1;
    rep(i, N){
        sum += A[i];
        if(mp.count(sum)) mp[sum]++;
        else mp[sum] = 1;
    }
    ll ans = 0;
    for(auto &e: mp){
        ll i = e.second;
        ans += i*(i-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 14336
fun main(args:Array<String>):Unit {
    var (n, q) = readLine()!!.split(' ').map(String::toInt)
    while (n != 0 || q != 0){
        val dateSuspect = Array(100){0}
        repeat(n){
            readLine()!!.split(' ').map(String::toInt).drop(1).forEach { dateSuspect[it]++ }
        }
        val date = dateSuspect.withIndex().filter{it.value >= q}.maxBy{it.value}
        println(date?.index ?: 0)
        val (nn, nq) = readLine()!!.split(' ').map(String::toInt)
        n = nn
        q = nq
    }
}




Measured memory_bytes: 48980
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
void file() {
    freopen("read.in", "r", stdin);
    freopen("write.out", "w", stdout);
}
const int N = 100;
inline int read() {
    int sym = 0, res = 0;char ch = getchar();
    while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
    return sym ? -res : res;
}
int n, m, ans, f[N][N];
int main() {
    n = read();
    for (int i = 1; i <= n; i++) {
        int r = i, l = r % 10; 
        while (r >= 10) r /= 10;
        f[l][r]++;
    }
    for (int i = 1; i <= n; i++) {
        int r = i, l = r % 10; 
        while (r >= 10) r /= 10;
        ans += f[r][l];
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
h,w=map(int, input().split())
s=[[0 for _ in range(w)] for _ in range(h)]
for j in range(h):
    s[j]=list(input())
l=[[0 for _ in range(w)] for _ in range(h)]
r=[[0 for _ in range(w)] for _ in range(h)]
u=[[0 for _ in range(w)] for _ in range(h)]
d=[[0 for _ in range(w)] for _ in range(h)]
max=0

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            l[i][j]=0
            u[i][j]=0
        else:
            if j==0:
                l[i][j]=1
            else:
                l[i][j]=l[i][j-1]+1
            if i==0:
                u[i][j]=1
            else:
                u[i][j]=u[i-1][j]+1
                      
for i in range(h-1,-1,-1):
    for j in range(w-1,-1,-1):
        if s[i][j]=='#':
            r[i][j]=0
            d[i][j]=0
        else:
            if j==w-1:
                r[i][j]=1
            else:
                r[i][j]=r[i][j+1]+1
            if i==h-1:
                d[i][j]=1
            else:
                d[i][j]=d[i+1][j]+1
                   
for i in range(h):
    for j in range(w):        
        total=l[i][j]+r[i][j]+d[i][j]+u[i][j]

        if max<total:
            max=total

print(max-3)

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

int A, B, C;
void solve()
{
	bool found = false;
	for(int i = 1; i <= B; i++){
		if(A*i % B == C)
			found = true;
	}
	if(found) cout << "YES" << endl;
	else cout << "NO" << endl;
}
int main()
{
	cin >> A >> B >> C;
	solve();
	return 0;
}


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

bool CNT(int x)
{
    for (int i = 2; i*i<=x; i++)
    {
        if (x%i==0) return false;
    }
    return true;
}

int main()
{
    int n, a, c = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        c+=CNT(a);
    }
    printf("%d\n", c);
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define For(i,n) for(ll int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(a,b,c) for(ll a=b;a<c;a++)
#define M 1000000007
/*
TOO MUCH TO LEARN
 	ostringstream str1;
    str1 << c;
    string x = str1.str();
 
    accumulate(a,b,sum)
*/
//............
//set
/*
set <ll> :: iterator itr;
if (b.find(a[i]) != b.end())
*/
//............
//queue
/*
void Print(queue<ll>& Queue)
{
    while (!Queue.empty()) {
        cout << Queue.front() << " ";
        Queue.pop();
    }
}
 
// Function to reverse the queue
void reverseQueue(queue<ll>& Queue)
{
    stack<ll> Stack;
    while (!Queue.empty()) {
        Stack.push(Queue.front());
        Queue.pop();
    }
    while (!Stack.empty()) {
        Queue.push(Stack.top());
        Stack.pop();
    }
}
*/
/*
ll power(ll x, ll y, ll m)
{
    ll res = 1;      // Initialize result
 
    x = x % m;  // Update x if it is more than or
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % m;
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % m;
    }
    return res;
}
*/
 
// ll knapSack(ll W, ll wt[], ll val[], ll n) 
// { 
//    ll i, w; 
   
  
//    // Build table K[][] in bottom up manner 
//    for (i = 0; i <= n; i++) 
//    { 
//        for (w = 0; w <= W; w++) 
//        { 
//            if (i==0 || w==0) 
//                K[i][w] = 0; 
//            else if (wt[i-1] <= w) 
//                  K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
//            else
//                  K[i][w] = K[i-1][w]; 
//        } 
//    } 
  
//    return K[n][W]; 
// } 
int main()
{
	fast;
    ll n;
    cin>>n;
    ll a[n][3],b[n][3];
    For(i,n)
    {
        For(j,3)cin>>a[i][j];
    }
    For(i,3)b[0][i]=a[0][i];
    f(i,1,n)
    {
        b[i][0]=a[i][0]+max(b[i-1][1],b[i-1][2]);
        b[i][1]=a[i][1]+max(b[i-1][0],b[i-1][2]);
        b[i][2]=a[i][2]+max(b[i-1][1],b[i-1][0]);
    }
    ll m=0;
    For(i,3)
    {
        m =max(b[n-1][i],m);
    }
    cout<<m<<endl;
}

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

#define all(A) begin(A), end(A)
#define sz(A) int(A.size())

using namespace std;

typedef long long ll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b and b == c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return (0);
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int a = sc.nextInt(); // 高橋 体力
        int b = sc.nextInt(); // 高橋 攻撃力
        int c = sc.nextInt(); // 青木 体力
        int d = sc.nextInt(); // 青木 攻撃力

        for (int i = 1; a > 0 && c > 0; i++) {
            if (i % 2 == 0) {
                a = a - d;
            } else {
                c = c - b;
            }
        }

        if (a > 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35772
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string str;
    int q;
    cin>>str>>q;
    int n=str.size();
    deque<char>dq(n);
    for(int i=0;i<n;i++)
        dq[i]=str[i];
    int turn =0;
    while(q--){
        int v;
        cin>>v;
        if(v==1){
            turn=!turn;
        }
        else{
            int f;
            char c;
            cin>>f>>c;
            if(turn==0){
                if(f==1)
                    dq.push_front(c);
                else
                    dq.push_back(c);
            }
            else{
                if(f==2)
                    dq.push_front(c);
                else
                    dq.push_back(c);
            }
        }
    }
    if(turn)
        reverse(dq.begin(),dq.end());
    for(auto z : dq)
        cout<<z;
    return 0;
}


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

#define pb push_back
#define se second
#define fi first

using namespace std;

typedef long long ll;

int n, a[(int)3e5], d[(int)3e5], ans;

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = n - 1; i > 0; i--){
        if(a[i] >= a[i + 1])
            d[i] = d[i + 1] + 1;
        ans = max(ans, d[i]);
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG

int main() {
    int n, k;
    cin >> n >> k;
    cout << (n % k == 0 ? 0 : 1) << endl;
}


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

using namespace std;
const int OO = 0x3f3f3f3f;
//const long long OO = (long long) 5e18+7;
//const unsigned long long UOO = (long long) 10e18+7;
#define lp(i,a,n) for(long long i = a ; i < n ; ++i)
#define lpr(i,a,n) for(long long i = a ; i >= n ; --i)
#define rep(i,vec) for(ll i = 0 ; i < vec.size() ; ++i)
#define reprv(i,vec) for(ll i = vec.size()-1; i >=0 ; --i)
#define eps (1e-5)
#define pb(i) push_back(i)
#define EPS 1e-9
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef vector<int> vi ;
typedef   long long ll;
typedef   unsigned long long ull;
typedef vector<ll> vll ;
typedef pair<int,int> pii ;
typedef vector< pair<int,int> >  vpii;
typedef vector<pair<long long,long long>> vpll;
typedef vector<vector<int> > vvi ;
typedef complex<double> point;
typedef pair<ll,ll> pll;

using namespace std;
ll  inv(ll a, ll b) {return 1 < a ? b - inv(b % a, a) * b / a : 1;}
ll  Pow(ll  B,ll  P){ll  R=1; while(P>0)  {if(P&1) R=(R*B);P/=2;B=(B*B);}return R;} //compute b^p
ll  GCD(ll  a,ll  b){ while(b){b ^= a ^=b ^= a %=b;}  return a;}
ll  LCM(ll  a,ll  b) { return (a / GCD(a,b)*b); }
ll  BigMod(ll  B,ll  P,ll  M){ ll  R=1; while(P>0)  {if(P&1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (ll )R;} //compute b^p%m
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int i=uniform_int_distribution<int>(1,n)(rng);


int N,w;
pll v[105];
ll mem[105][100005];

ll dp(int pos, int lft){
    if(pos ==N) return 0;
    if(mem[pos][lft] != -1) return mem[pos][lft];
    ll ans = dp(pos+1,lft);
    if(v[pos].ff <= lft) ans = max(ans,dp(pos+1,lft-v[pos].ff)+v[pos].ss);
    return mem[pos][lft] = ans;
}




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
//    cout.tie(0);
//#ifndef ONLINE_JUDGE
//   freopen( "output.txt" , "w" , stdout ) ;
//   freopen( "input.txt" , "r" , stdin ) ;
//#endif

    memset(mem,-1,sizeof mem);

    cin >> N >> w;
    lp(i,0,N) cin >> v[i].ff >> v[i].ss;

    cout << dp(0,w);

    return 0;
}


Measured memory_bytes: 85592
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, a, b);
    if (a < 10 && b < 10) {
        print(a * b);
    } else {
        print(-1);
    }
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

int main(){
    cin.tie(0), ios::sync_with_stdio(false);
    int a,b,c=1,d=1;
    cin >> a >> b;

    bool grid[100][100];
    REP(i,100) REP(j,100) grid[i][j] = i<50;
    while(--a>0){
        grid[c][d] = false;
        if(d<98) d+=2;
        else c+=2,d=0;
    }
    c=51,d=1;
    while(--b>0){
        grid[c][d] = true;
        if(d<98) d+=2;
        else c+=2,d=0;
    }

    cout << "100 100\n";
    REP(i,100){
        REP(j,100) cout << (grid[i][j] ? "#" : ".");
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
i = input().split()

w = int(i[0])
h = int(i[1])
x = int(i[2])
y = int(i[3])
r = int(i[4])

left_pos = x - r
right_pos = x + r
top_pos = y + r
bottom_pos = y - r

if left_pos < 0 or w < right_pos or bottom_pos < 0 or h < top_pos:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 7660
#include <iostream>

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

using namespace std;

int main(void)
{
	int a, b, c, d=0;

	cin >> a  >> b >>  c;

	d = a;
	a = c;
	c = b;
	b = d;

	cout << a << " " << b << " " << c << endl;

}




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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define RREP(i,a) for(int i = a;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

string s;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cin >> s;
	int a, z;
	rep (i, s.size()) {
		if (s[i] == 'A') {
			a = i;
			break;
		}
	}
	rep (i, s.size()) {
		if (s[i] == 'Z') {
			z = i;
		}
	}
	cout << z - a + 1 << endl;
	return 0;
}




Measured memory_bytes: 720
// B.

#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		string s;
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}
	return 0;
}


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, "\e[31;1m"); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\e[0m")
#else
    #define eprintf(...) 42
#endif

std::string solve(char C)
{
    if ('a' == C || 'i' == C || 'u' == C || 'e' == C || 'o' == C)
    {
        return "vowel";
    }
    return "consonant";
}

int main(void)
{
    char C;
    std::cin >> C;
    std::cout << solve(C) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> w(n);
    int sum = 0;
    rep(i, n)
    {
        cin >> w[i];
        sum += w[i];
    }
    int min_v = INF;
    int a_sum = 0;
    rep(i, n)
    {
        a_sum += w[i];
        min_v = min(min_v, abs(sum - 2*a_sum));
    }
    cout << min_v << endl;
    return 0;
}

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

const int P = 998244353;

unordered_map<string, int> memF, memG;

int F(const string &s);
int G(const string &s) {
	if (s.size() == 1)
		return s[0] - '0' + 1;
	if (memG.count(s)) return memG[s];
	int ans = 0;
	for (int i = 1; i < (int)s.size(); ++i)
		if (s.size() % i == 0) {
			string tmp(i, '1');
			for (int j = 0; j < (int)s.size(); j += i)
				for (int k = 0; k < i; ++k)
					if (s[j + k] == '0') tmp[k] = '0';
			ans = (ans + F(tmp)) % P;
		}
	return memG[s] = ans;
}
int F(const string &s) {
	if (s.empty())
		return 1;
	if (memF.count(s)) return memF[s];
	int ans = 0;
	for (int i = 1; i <= (int)s.size(); ++i)
		ans = (ans + 1LL * G(s.substr(0, i)) * F(s.substr(i, (int)s.size() - i))) % P;
	return memF[s] = ans;
}

int main() {
	string s;
	cin >> s;
	cout << F(s) << '\n';
	return 0;
}


Measured memory_bytes: 12184
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF 100100100

int main(void)
{
    int n, w[101];
    int ans = INF;
    scanf("%d", &n);
    rep(i, n)
        scanf("%d", &w[i]);

    rep(i, n)
    {
        int t = i, s[2] = {0};
        rep(j, n)
        {
            if (j <= t)
                s[0] += w[j];
            else
                s[1] += w[j];
        }
        ans = min(ans, abs(s[0] - s[1]));
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
robots = [tuple(map(int,input().split())) for _ in range(N)]

robots = [(x+l,x-l) for x,l in robots]

robots.sort()

cnt = 0
last = -float('inf')
for r,l in robots:
    if last <= l:
        cnt += 1
        last = r

print(cnt)

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

int main(){
  int h,w;
  cin >>h >>w;
  string board[50];
  rep(i,h) cin >>board[i];
  const int dx[8]={-1,-1,-1,0,0,1,1,1};
  const int dy[8]={-1,0,1,-1,1,-1,0,1};
  rep(i,h){
    rep(j,w){
      if(board[i][j]=='#') continue;
      int cnt = 0;
      rep(d,8){
        const int ni = i+dy[d];
        const int nj = j+dx[d];
        if(ni<0 or h<=ni) continue;
        if(nj<0 or w<=nj) continue;
        if(board[ni][nj]=='#') cnt++;
      }
      board[i][j] = char(cnt+'0');
    }
  }
  rep(i,h) cout << board[i] << endl;
  return 0;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
Y = [list(map(int, input().split())) for _ in range(Q)]

grid = [[0] * (N + 1) for _ in range(N + 1)]
for l, r in X:
    grid[l][r] += 1

for i in range(N):
    for j in range(N):
        grid[i + 1][j + 1] += grid[i][j + 1]

for i in range(N):
    for j in range(N):
        grid[i + 1][j + 1] += grid[i + 1][j]

for p, q in Y:
    print(grid[q][q] + grid[p - 1][p - 1] - grid[p - 1][q] - grid[q][p - 1])


Measured memory_bytes: 109528
#include<bits/stdc++.h>
using namespace std;
bool same(int x){
  	vector<int> v;
  	while(x){
      v.push_back(x%10);
      x/=10;
    }
  	int a=v[0];
  	for(int i=1;i<v.size();i++) if(v[i]!=a) return 0;
  	return 1;
}
signed main(){
  	int n;
  	cin>>n;
  	while(!same(n)) n++;
  	cout<<n;
    return 0;
}

Measured memory_bytes: 3580
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        string[] inputs = Console.ReadLine().Split(' ');
        int H = int.Parse(inputs[0]);
        int W = int.Parse(inputs[1]);
        string[] a = new string[H];
        for (int i = 0; i < H; i++)
        {
            a[i] = Console.ReadLine();
        }
        for (int i = -1; i < H + 1; i++)
        {
            Console.Write('#');
            if (i == -1 || i == H)
            {
                for (int j = 0; j < W; j++)
                {
                    Console.Write('#');
                }
            }
            else Console.Write(a[i]);
            Console.WriteLine('#');
        }
    }
}


Measured memory_bytes: 13140
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;



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

	int h, w;
	cin >> h >> w;
	char p[h+1][w+1];

	forsn(i,1,h+1) forsn(j,1,w+1) cin >> p[i][j];

	ll dp[h+1][w+1];

	forn(i,h+1) dp[i][0]=0;
	forn(i,w+1) dp[0][i]=0;

	forsn(i,1,h+1)forsn(j,1,w+1){
		if(p[i][j]=='#') dp[i][j]=0;
		else dp[i][j] = (dp[i][j-1] + dp[i-1][j])%MOD;
		if(i==1 && j==1) dp[i][j]=1;
	//	dbg(dp[i][j]); dbg2(i,j);
	}

	cout << dp[h][w];

}


Measured memory_bytes: 9088
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

int main() {
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll series = N * (N+1) / 2;
  VL as(N);
  ll sum = 0;
  FOR(a,as) {
    cin >> a;
    sum += a;
  }
  if(sum % series != 0) {
    cout << "NO" << endl;
    return 0;
  }
  ll times = sum / series;
  ll left_times = times;
  REP(i,0,N) {
    ll diff = as[i] - as[(i+1)%N] + times;
    if(diff < 0 || diff % N != 0) {
      cout << "NO" << endl;
      return 0;
    }
    left_times -= diff / N;
  }
  assert(left_times == 0);
  cout << "YES" << endl;
  return 0;
}


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

using namespace std;

int main() {
	
	int n, m, zb=0, maxi=0;
	string a[101], b[101];
	cin>>n;
	for (int i=0; i<n; i++) {
		cin>>a[i];
	}
	cin>>m;
	for (int i=0; i<m; i++) {
		cin>>b[i];
	}
	for (int i=0; i<n; i++) {
		zb=0;
		for (int j=i; j<n; j++) {
			if (a[i]==a[j]) {
				zb++;
			}
		}
		for (int j=0; j<m; j++) {
			if (a[i]==b[j]) {
				zb--;
			}
		}
		if (zb>maxi) maxi=zb;
	}
	cout<<maxi;
	
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, x;
  cin >> N >> x;
  vector<int> a;
  for (int i = 0; i < N; ++i) {
    int ai;
    cin >> ai;
    a.push_back(ai);
  }
  sort(a.begin(), a.end());

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (x >= a[i]) {
      ++ans;
      x -= a[i];
    }
  }

  if (ans == N && x != 0) {
    --ans;
  }

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

Measured memory_bytes: 256
fun main() {
    fun gcd(a: Int, b: Int): Int {
        if (b == 0) return a
        return gcd(b, a % b)
    }

    val value = readLine()!!.toInt()
    var ans = 0L
    for(i in 1..value) {
        for(j in 1..value) {
            for(k in 1..value) {
                ans += gcd(i, gcd(j, k))
            }
        }
    }

    println(ans)
}

Measured memory_bytes: 34488
import numpy as np
n = int(input())

w = list(map(int,input().split()))

w = np.array(w)
a = w[0]
b = np.sum(w[1:])

ans = np.sum(w[:])

for i in range(1,n):
    a += w[i]
    b -= w[i]
    ans = min(ans,abs(a-b))

print(ans)


Measured memory_bytes: 14444
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  /*bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };*/
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[3331][3333];
int l[3331];
int j[3331];

long long x,y,z,mod=1000000007;
//string r;
char r[3331];

P u[3331];
queue<int> q;
//stack<int> s;
set<int> s;
map<int,int> p;

vector<int> v[2];

bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  return a.x<b.x;
}

long long f(int n,int m)
{
  if(n>a) return 1;
  //if(m>u[l[n]].y-n+1) return 0;
  if(o[n][m]>=0) return o[n][m];
  if(l[n]==0)
  {
   if(l[n+1]==0) return f(n+1,m);
  else
  {
    //printf("##%d %d\n",n,m);
   return f(n+1,m+j[u[l[n+1]].y]-j[n]);
  }
  }
  long long k=0;
  /*if(l[n+1]==0)
  {
    k=f(n+1,m);
  }
  else*/ if(l[n+1]!=l[n]&&l[n+1])
  {
    if(m<=u[l[n]].y-n) k=f(n+1,m+j[u[l[n+1]].y]-j[u[l[n]].y]);
    if(m&&m-1<=u[l[n]].y-n) k=(k+f(n+1,m-1+j[u[l[n+1]].y]-j[u[l[n]].y]))%mod;
  }
  else
  {
    if(m<=u[l[n]].y-n) k=f(n+1,m);
    if(m&&m-1<=u[l[n]].y-n) k=(k+f(n+1,m-1))%mod;
  }
  return o[n][m]=k;
}

int main()
{
  memset(o,-1,sizeof(o));
  scanf("%d %d",&a,&b);
  scanf("%s",r+1);
  for(int t=1;t<=a;j[t]+=j[t-1],t++)
  if(r[t]=='1') j[t]=1;
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d",&n,&m);
    if(u[c].x==n) u[c].y=max(u[c].y,m);
    else if(u[c].y<m)
    {
      c++;
      u[c]={n,m};
    }
  }
  for(int t=1;t<=c;t++)
  {
    for(int i=u[t].x;i<=u[t].y;i++)
      l[i]=t;
  }
  printf("%lld",f(u[1].x,j[u[1].y]-j[u[1].x-1]));
}
//3
//21




Measured memory_bytes: 87296
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fib(int n) {
    if (n == 0 || n == 1) return dp[n] = 1;
    if (dp[n] != -1) return dp[n];
    return dp[n] = fib(n - 1) + fib(n - 2);
}

int main() {
    int n, i;
    for (i = 0; i<50; i++) {
        dp[i] = -1;
    }
    
    scanf("%d", &n);
    printf("%d\n", fib(n));
    
    return 0;
}


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

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

int main() {
    int n;
    cin >> n;
    vector<long long int> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    if(n==1){
        cout << x[0] << " " << y[0] << " " << h[0] << endl;
        return 0;
    }

    long long int xt, yt, ht;
    for (int i = 0; i < n; i++) {
        if(h[i]>0){
            xt = x[i];
            yt = y[i];
            ht = h[i];

            break;
        }
    }

    long long int ans = 0;
    long long int ax, ay;

    for (long long int cy = 0; cy <= 100; cy++){
        for (long long int cx = 0; cx <= 100; cx++){
            long long int height = ht + abs(xt - cx) + abs(yt - cy);
            bool b = true;

            for (int i = 0; i < n; i++) {
                long long int temp = max(height - abs(x[i] - cx) - abs(y[i] - cy), 0LL);
                
                if(temp!=h[i]){
                    b = false;
                    break;
                }
            }

            if(b){
                ax = cx;
                ay = cy;
                ans = height;
            }
        }
    }

    cout << ax<<" "<<ay<<" "<<ans << endl;
}

Measured memory_bytes: 256