akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef int _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, k, t, ans = 0;
vi p;
vvi g;

bool check(int msk) {
	for(int f = 0; f < m; f++) {
		int t = 0;
		for(auto i : g[f])
			t += (msk>>i)&1;
		if(p[f]%2 != t%2)
			return false;
	}
	return true;
}

int main() {
	doin();
	cin >> n >> m;
	g.resize(m);
	for(int i = 0; i < m; i++) {
		cin >> k;
		while(k--)
			cin >> t, g[i].pb(t-1);
	}
	getv(p, m);
	for(int i = 0; i < 1<<n; i++) {
		ans += check(i);
	}
	cout << ans;
}


Measured memory_bytes: 256
def main():
    A, B, C = map(int, input().split())

    if A == B and A == C:
        return 0

    ans = 0
    sum = A+B+C
    while True:
        sum += 2
        if (sum % 3) == 0 and A<=(sum/3) and B<=(sum/3) and C<=(sum/3):
            break

    m = sum/3
    while True:
        if (m - A) >= 2:
            A += 2
            ans += 1
        else:
            break

    while True:
        if (m - B) >= 2:
            B += 2
            ans += 1
        else:
            break

    while True:
        if (m - C) >= 2:
            C += 2
            ans += 1
        else:
            break

    if A != m or B != m or C != m:
        ans += 1
    return ans

print(main())


Measured memory_bytes: 3064
#include <iostream>
#include <string>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

ll gcd(ll a, ll b){
  if (a % b == 0) return b;
  else return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}

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

Measured memory_bytes: 3640
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>
#include <cassert>

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

i2 P[5001];

int dp[5001][5001]; //minimize weight from
int ap[5001][5001]; //minimize weight from
int ans[5001][5001]; //maximize items

int f(int cur, int used) //minimize weight
{
    if (cur == 0 && used == 0) return 0;
    if (cur == 0) return 1e9+1;
    if (dp[cur][used] != -1) return dp[cur][used];
    
    int ret = 1e9+1;
    ret = min(ret, f(cur-1, used));
    if (P[cur].fi >= f(cur-1, used-1))
        ret = min(ret, P[cur].se+f(cur-1, used-1)); //addd weight

    return dp[cur][used] = ret;
}

int g(int cur, int used) //maximize items
{
    if (cur == 0 && used == 0) return 0;
    if (cur == 0) return -1e5;
    if (ans[cur][used] != -1) return ans[cur][used];
    int ret = -1e5;
    ret = max(ret, g(cur-1, used));
    if (P[cur].fi >= f(cur-1, used-1))
        ret = max(ret, 1+g(cur-1,used-1));
    return ans[cur][used] = ret;
}

bool cmp(const i2 &lhs, const i2 &rhs)
{
    return (lhs.fi + lhs.se) < (rhs.fi + rhs.se);
}

int n;

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);
    memset(dp, -1, sizeof dp);
    memset(ans, -1, sizeof ans);
    
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> P[i].fi >> P[i].se;
    sort(P+1, P+1+n, cmp);
    
    //for (int i = 1; i <= n; i++) cout << P[i].fi << ' ' << P[i].se << endl;
    
    int ret = 0;
    for (int i = 1; i <= n; i++) ret = max(ret, g(n,i));

    cout << ret << '\n';
    
    return 0;
    
}

/*
 Read the problem carefully.
 Don't forget to sort(), mod, ll!!!!
 MULTISET NOT SET
 Initial value = +/- infinity instead of zero!!!
 */



Measured memory_bytes: 197504
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n;
  cin >> n;
  cout << n/3 << endl;
  system("pause");
}


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

using namespace std;

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

#define ll long long

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

	int ans = INT_MAX / 2 - 1;
	rep (i, n - k + 1) {
		int l = x[i], r = x[i+k-1];
		int mind = min(abs(l) + abs(r - l), abs(r) + abs(l - r));
		ans = min(ans, mind);
	}

	cout << ans << endl;
}



Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<queue>
#include<list>

using namespace std;

int ans[100000];

int main (){
  int N, M;
  list<int> e[100000];
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  queue<int> q;
  q.push(0);
  ans[0] = 1;
  while(!q.empty()) {
    int p = q.front();
    for (auto itr = e[p].begin(); itr != e[p].end(); itr++){
      if(!ans[*itr]) {
        ans[*itr] = p + 1;
        q.push(*itr);
      }
    }
    q.pop();
  }

  cout << "Yes" << endl;
  for (int i=1; i<N; i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 18936
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = INT()
counter = list(dict(Counter(prime_factorize(n))).values())

res = 0
for ele in counter:
    res += int(math.sqrt(2*ele+0.25)-0.5)
print(res)

Measured memory_bytes: 72736
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (abs(A-B) <= D && abs(B-C) <= D){
      cout << "Yes" << endl;
  }
  else if (abs(A-C) <= D ){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
}

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

typedef long long ll;
int ara[13][13];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int i,n,x;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        x=i;
        while(x>=10)
        {
            x/=10;
        }
        ara[x][i%10]++;
    }
    int ans=0;
    for(i=1;i<=n;i++)
    {
        x=i;
        while(x>=10)
        {
            x/=10;
        }
        ans+=ara[i%10][x];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int l;
    cin >> l;
    long double a = l;
    a /= 3;
    cout << fixed << setprecision(10) << a * a * a << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_9_A {
    class Program {
        static void Main(string[] args) {
            int H = int.Parse(Console.ReadLine());
            Dictionary<int, int> keys = Console.ReadLine().Split(' ')
                .Select((key, index) => new { index, key })
                .ToDictionary(n => n.index + 1, n => int.Parse(n.key));

            StringBuilder sb = new StringBuilder();
            for(int i = 1; i <= H; i++) {
                int p = i / 2;
                int l = 2 * i;
                int r = 2 * i + 1;

                sb.Append("node " + i);
                sb.Append(": key = " + keys[i] + ", ");
                if (p > 0)
                    sb.Append("parent key = " + keys[p] + ", ");
                if (l <= H)
                    sb.Append("left key = " + keys[l] + ", ");
                if (r <= H)
                    sb.Append("right key = " + keys[r] + ", ");
                sb.AppendLine();
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10132
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n; cin >> n;
  int d[n];
  for(int i=0; i<n; i++) cin >> d[i];
  sort(d, d+n);
  int h=n/2;
  int x=d[h]-d[h-1];
  cout << x;
  return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-100
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
//	file();
	fast();
	int n; cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		if ((i % 3) && (i % 5))
		sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3640
import sys
input = sys.stdin.readline

N,M = map(int, input().split())
P = [0]*M
Y = [0]*M
for i in range(M):
	P[i],Y[i] = map(int, input().split())
 
p_dict = {} #dictionalyの初期化
for i in range(M):
	p_dict.setdefault(P[i],[]).append(Y[i])


under6 = {} #dictionalyの初期化
for p in p_dict.keys():
  sorted_year = sorted(p_dict[p])
  for i in range(len(sorted_year)):
    under6[sorted_year[i]] = i + 1

for i in range(M):
  print(str(P[i]).zfill(6) + str(under6[Y[i]]).zfill(6))




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

int main() {
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  bool ok = false, eq = true;
  int N = min(s.size(), t.size());
  rep(i,0,N-1) {
    if (s[i] < t[i]) ok = true;
    if (s[i] != t[i]) eq = false;
  }

  if (eq && s.size() < t.size()) ok = true;

  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n, k=map(int,input().split())
x=list(map(int,input().split()))

ans=10**9
for i in range(n-k+1):
    left=x[i]
    right=x[i+k-1]

    if left<=0 and right<=0:
        dist=abs(left)
    elif left>=0 and right>=0:
        dist=right
    else:
        first=min(-left, right)
        dist=first+right-left
    
    ans=min(ans, dist)

print(ans)

Measured memory_bytes: 14384
from collections import defaultdict
from bisect import bisect_left

s = input()
t = input()
d = defaultdict(list)
e = defaultdict(int)

a, b = set(s), set(t)
if a&b!=b:
    print(-1)
else:
    for i,j in enumerate(s):
        d[j].append(i)
        e[j]+=1
    
    p = -1
    orig_size = len(s)
    ans = 0

    for i in t:
        a = bisect_left(d[i], p)
        if 0<= a < e[i]:
            p = d[i][a] + 1
        else:
            p = d[i][0] + 1
            ans += orig_size
    
    print(ans+p)

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

int main(){
  int r, c;
  cin>>r>>c;
  
  int num[101][101] = {};
  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) cin>>num[i][j];

  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) num[r][c] += num[i][j];

  for(int i=0;i<r;i++){
    int sum = 0;
    for(int j=0;j<c;j++) sum += num[i][j];
    num[i][c] = sum;
  }

  for(int j=0;j<c;j++){
    int sum = 0;
    for(int i=0;i<r;i++) sum += num[i][j];
    num[r][j] = sum;
  }
  
  for(int i=0;i<=r;i++){
    for(int j=0;j<=c;j++){
      if(j) cout<<" ";
      cout<<num[i][j];
    }
    cout<<endl;
  } 
  return 0;
}



Measured memory_bytes: 3160
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long K = sc.nextLong();
		int N = sc.nextInt();
		long max = 0;
		long buf;
		int i;
		long[] A = new long[N];
		for(i = 0;i < N;i++){
			A[i] = sc.nextLong();
		}
		for(i = 0;i < N;i++){
			if(i == N-1){
				buf = (K + A[0]) - A[i];
			}else{
				buf = A[i+1] - A[i];
			}
			if(buf > max){
				max = buf;
			}
		}
		System.out.println(K - max);
	}	
}

Measured memory_bytes: 77604
//K.Chaitanya
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//std::ios::sync_with_stdio(false);
int main(){
    std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n;
	cin>>n;
	pair<int,int> a[n],d[n];
	for(ll i=0;i<n;i++){
		cin>>a[i].ff;
		a[i].ss=i;
	}
	sort(a,a+n);
	ll b=n/2;
	ll c=b-1;
	for(ll i=0;i<n;i++){
		if(i<=c){
			d[i].ss=a[b].ff;
			d[i].ff=a[i].ss;
		}
		else{
			d[i].ss=a[c].ff;
			d[i].ff=a[i].ss;
		}
	}
	sort(d,d+n);
	for(ll i=0;i<n;i++){
		cout<<d[i].ss<<endl;
	}
	return 0;
}

































Measured memory_bytes: 5376
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int main(void) {
  int N, A[100];
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  bool used[8];
  REP(i, 0, 8) used[i] = false;

  int cnt = 0;
  REP(i, 0, N) {
    if(1 <= A[i] && A[i] <= 399) used[0] = 1;
    if(400 <= A[i] && A[i] <= 799) used[1] = 1;
    if(800 <= A[i] && A[i] <= 1199) used[2] = 1;
    if(1200 <= A[i] && A[i] <= 1599) used[3] = 1;
    if(1600 <= A[i] && A[i] <= 1999) used[4] = 1;
    if(2000 <= A[i] && A[i] <= 2399) used[5] = 1;
    if(2400 <= A[i] && A[i] <= 2799) used[6] = 1;
    if(2800 <= A[i] && A[i] <= 3199) used[7] = 1;
    if(3200 <= A[i]) cnt++;
  }

  int ans = 0;
  REP(i, 0, 8) if(used[i]) ans++;

  int mi = max(1, ans);
  int mx = ans + cnt;

  cout << mi << " " << mx << endl;

  return 0;
}


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

int main(){

	deque<long int> a;
	int q;
	cin >> q;
	int querynum = 0;
	while (querynum < q) {
		int var1;
		cin >> var1;
		if (var1 == 0) {
			int var2, var3;
			cin >> var2 >> var3;
			if (var2 == 0) a.push_front(var3); else a.push_back(var3);
		}
		else if (var1 == 1) {
			int var2;
			cin >> var2;
			cout << a[var2] << endl;
		}
		else {
			int var2;
			cin >> var2;
			if (var2 == 0) a.pop_front(); else a.pop_back();
		}
		querynum++;
	}

	return 0;
}


Measured memory_bytes: 6296
#include<iostream>
using namespace std;
int main(){
  int a,c=0;
  int i,b[4];
  cin>>a;
  for(i=0;i<4;i++){
    b[i]=a%10;
    a=a/10;
    if(b[i]==2)
      c++;
  }
  
  cout<<c;
  return 0;
}
  


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

S=input().strip()

if not ("R" in S):
    print(0)
elif S[1]!="R":
    print(1)
else:
    A=1
    if S[0]=="R":
        A+=1
    if S[2]=="R":
        A+=1

    print(A)


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


int main(){
  int N,P,count,L,J;
  P = 1;
  count = 0;
  int64_t K;
  cin >> N >> K;
  vector<int> A(N+1);
  vector<int> B(N+1);
  A.at(0) = 0;
  B.at(0) = 0;
  for(int i = 1;i < (N+1);i++){
    int x;
    cin >> x;
    A.at(i) = x;
    B.at(i) = 0;
  }
  
  for(int64_t i = 0;i < K;i++){
    B.at(P) = 1;
    int T;
    T = A.at(P);
    P = T;
    count++;
    //cout <<"1 i:" << i << " P:" << P  << " count:" << count << endl;
    if(B.at(P) == 1){
      J = P;
      K -= count; 
      count = 0;
      break;
    }
  }
  
  //cout << J << P << endl;
  
  if(count == 0){
    for(int64_t i = 0;i < N;i++){
      int T;
      T = A.at(P);
      P = T;
      count++;
      //cout <<"2 i:" << i << " P:" << P  << " count:" << count << endl;
      if(P == J){
        //cout <<"2- i:" << i << " P:" << P  << " count:" << count << endl;
        break;
      }
    }
    L = K % count;
    L += count;
    for(int64_t i = 0;i < L;i++){
      int T;
      T = A.at(P);
      P = T;
      //cout <<"3 i:" << i << " P:" << P  << " count:" << count << endl;
    }
  }
  cout << P << endl;
}


Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {

  long long A,B,C;
  cin >> A >> B >> C;

  if(A+B < C) {
    cout << B*2+A+1 << endl;
  }else if(A+B == C) {
    cout << B*2+A << endl;
  }else {
    cout << B+C << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
char S[110];bool T[110];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	scanf("%s",S+1);int n=strlen(S+1),ans=n;
	for(char c='a';c<='z';++c){
		for(int i=1;i<=n;++i)T[i]=S[i]==c;
		for(int i=n;i;--i){
			bool f=0;
			for(int j=1;j<=i;++j)if(!T[j])f=1;
			if(!f){ans=std::min(ans,n-i);break;}
			for(int j=1;j<i;++j)T[j]|=T[j+1];
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor

def main():
    N, M = map(int, input().split())

    start = 1
    end = N

    used = set()
    for m in range(M):
        print("{} {}".format(start, end))
        fdiff = end - start
        bdiff = N - fdiff
        used.add(fdiff)
        used.add(bdiff)

        start += 1
        end -= 1

        fdiff = end - start
        if fdiff in used or 2 * fdiff == N:
            start += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 89884
require 'pp'

@h, @w = gets.strip.split.map(&:to_i)
maze = []

@h.times do
  maze << gets.strip.split('')
end

# 元の白マスの個数
# pp maze
num_whites = 0
@h.times do |i|
  @w.times do |j|
    # puts "maze[i][j] = #{maze[i][j]}"
    if maze[i][j] == '.'
      num_whites += 1
    end
  end
end

def bfs(maze)
  q = [[0, 0]]
  path = []
  @h.times do |i|
    path << []
    @w.times do |j|
      path[i] << nil
    end
  end

  until q.empty? do
    now_x, now_y = q.shift

    # maze.each do |row|
    #   puts row.join('')
    # end
    # 次のマスに到達した
    # ここはゴールか？
    if now_x == @w - 1 && now_y == @h - 1
      break
    end

    dirs = [
      [now_x - 1, now_y],
      [now_x + 1, now_y],
      [now_x, now_y - 1],
      [now_x, now_y + 1]
    ]
    dirs.each do |d|
      x, y = d
      if x < 0 || @w <= x || y < 0 || @h <= y
        next
      end
      cell = maze[y][x]
      if cell == '#'
        next
      end

      # 進めるマスがあった
      # puts "すすめるマスがあった(x, y) = #{x}, #{y}"

      # チェック済みにする
      maze[y][x] = '#'

      # 経路復元用のメモ
      if path[y][x] == nil
        path[y][x] = [now_x, now_y]
      end

      # キューに入れる
      q << [x, y]
    end
  end

  # 経路を返して探索終わり
  path
end

def path_length(path)
  len = 0
  x, y = @w - 1, @h - 1
  until (x == 0 && y == 0)
    # puts ("x, y = #{x}, #{y}")
    len += 1
    x, y = path[y][x]
  end
  len
end

path = bfs(maze)
# pp path
if path[@h - 1][@w - 1] == nil
  # ゴールにたどり着けない
  puts -1
else
  # puts "num_whites = #{num_whites}"
  # 元の白マスの個数 - 経路の長さ - 1 個塗って良い
  puts num_whites - path_length(path) - 1
end

Measured memory_bytes: 2428
//#include <algorithm>
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>



typedef unsigned long long ULONG;
using namespace std;

int main(void) {
	ULONG N;
	cin >> N;

	vector<ULONG> A(N);

	ULONG LIMIT = (ULONG)pow(10, 18);

	


	for (ULONG i = 0; i < N; i++) {
		cin >> A[i];
	}

	ULONG ans = A[0];
	long long ans2;

	for (ULONG i = 0; i < N; i++) {
		if (A[i] == 0) {
			cout << 0;
			return 0;
		}
	}

	for (ULONG i = 1; i < N; i++) {
        ULONG prev = ans;
		ans = ans * A[i];
      	if( ans / A[i] != prev){
			ans2 = -1;
			break;
        }
          
		if (ans > LIMIT) {
			ans2 = -1;
			break;
		}
		ans2 = ans;
	}


#ifdef _DBG_
	int a;
	cin >> a;
#endif

	cout << ans2;

	return 0;
}

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

int main() {
	ll n,m;
	cin >> n >> m;
	vector<ll> yaku;
	if (n>=2) {
		for(ll i=1;i*i<=m;i++) {
			if(m%i==0) {
				if (n*i<=m)	yaku.push_back(i);
				if (n<=i) yaku.push_back(m/i);
			}
		}
		sort(yaku.begin(),yaku.end());
		cout << yaku[yaku.size()-1] << endl;
	}
	else cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
d = [list(map(int,input().split())) for i in range(N)]
#締切昇順でsort
d.sort(key=lambda x : x[1])
ret = "Yes"
cur_task = 0
for ab in d:
    cur_task+=ab[0]
    if cur_task > ab[1]:
        ret = "No"
        break
print(ret)


Measured memory_bytes: 53728
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

int N,M,K;
string S;
signed main(){
  cin>>S;
  REP(i,0,3){
    if(S.at(i)=='7'){
      print("Yes")
      return 0;
    }
  }
  print("No")


}


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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int r;
  cin >> r;
  cout << 3*r*r << 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 t_y = sc.nextInt();
   int num = sc.nextInt();
   
   
   if(t_y<=5){
    System.out.println(0);
   }
   else if(t_y<=12)
    {
    System.out.println(num/2);     
    }
   else
   {
    System.out.println(num);

   }
   
 }
}

Measured memory_bytes: 23508
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>
 
#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >
 
using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
 
const int mod = 1000000007;
 
int dp[3030][3030];
int pre[3030][3030];
 
int main() {
    string s, t;
    cin >> s >> t;
    
    rep(i,s.size())rep(j,t.size()) {
        if (dp[i+1][j+1]<dp[i+1][j]) {
            dp[i+1][j+1] = dp[i+1][j];
            pre[i+1][j+1] = 2;
        }
        if (dp[i+1][j+1]<dp[i][j+1]) {
            dp[i+1][j+1] = dp[i][j+1];
            pre[i+1][j+1] = 3;
        }
        
        if (s[i]==t[j]) {
            if (dp[i+1][j+1]<dp[i][j]+1) {
                dp[i+1][j+1] = dp[i][j] + 1;
                pre[i+1][j+1] = 1;
            }
        }
    }
    
    string ans = "";
 
    int si = s.size();
    int ti = t.size();
 
    while (si>0 && ti>0) {
        if (pre[si][ti]==1) {
            --si; --ti;
            ans += s[si];
        }
        else if (pre[si][ti]==2) --ti;
        else --si;
    }
    //rep(i,s.size()+1) {
    //    rep(j,t.size()+1) {
    //        cout << dp[i][j] << ' ';
    //    }
    //    cout << endl;
    //}
    //cout << endl;
    //rep(i,s.size()+1) {
    //    rep(j,t.size()+1) {
    //        cout << pre[i][j] << ' ';
    //    }
    //    cout << endl;
    //}
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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; }

typedef long long ll;
// typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

template <class T>
class SegmentTree {
    public:
        int N;
        vector<T> dat;
        T def;
        std::function<T(T, T)> operation;

        SegmentTree(int _n, T _def=1001001001, function<T(T, T)> _operation=[](T a, T b){return min(a, b);});
        T query(int a, int b, int k=0, int l=0, int r=-1);
        void update(int k, T a);
};

template <class T>
SegmentTree<T>::SegmentTree(int _n, T _def, function<T(T, T)> _operation):
    def(_def), operation(_operation) {
    N = 1;
    while (N < _n) N *= 2;
    dat = vector<T>(2*N-1, def);
}

template <class T>
T SegmentTree<T>::query(int a, int b, int k, int l, int r) {
    if (r < 0) r = N;

    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return dat[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return operation(vl, vr);
}

template <class T>
void SegmentTree<T>::update(int k, T a) {
    k += N - 1;
    dat[k] = a;

    while (0 < k) {
        k = (k - 1) / 2;
        dat[k] = operation(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

int main(){
    int N, K;
    cin >> N >> K;

    vector<int> P(N);
    for (int &i : P) cin >> i;

    vector<int> dp(N);
    repr(i, N) {
        if (i == N-1) {
            dp[i] = 1;
        } else {
            if (P[i] < P[i+1]) dp[i] = dp[i+1] + 1;
            else dp[i] = 1;
        }
    }

    SegmentTree<int> stMin(N), stMax(N, -INF, [](int a, int b){ return max(a, b); });
    rep(i, N) {
        stMin.update(i, P[i]);
        stMax.update(i, P[i]);
    }

    int ans = 1;
    bool flg = false;
    if (K <= dp[0]) flg = true;

    for (int i = 1; i <= N-K; ++i) {
        if (K <= dp[i]) {
            if (!flg) {
                ans++;
                flg = true;
            }
            continue;
        }
        int minNum = stMin.query(i-1, i-1+K);
        int maxNum = stMax.query(i, i+K);
        if (P[i-1] == minNum && P[i+K-1] == maxNum) continue;
        ans++;
    }

    cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];
  vector<vector<int>> road(N, vector<int>(0));
  for (int i = 0; i < M; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    road[tmp1-1].push_back(tmp2-1);
    road[tmp2-1].push_back(tmp1-1);
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    bool can = true;
    for (int j = 0; j < road[i].size(); j++) {
      if (H[i] <= H[road[i][j]]) {
        can = false;
        break;
      }
    }
    if (can) res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 8736
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int n;
V<lint> c;

VV<lint> memo;
lint rec(int l, int r) {
  if (r - l == 1) return 0;
  if (memo[l][r] != -1) return memo[l][r];
  lint res = 9e18;
  for (int m = l + 1; m < r; ++m) {
    res = min(res, rec(l, m) + rec(m, r) + c[r] - c[l]);
  }
  return memo[l][r] = res;
 }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  cin >> n;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  c.resize(n + 1);
  for (int i = 0; i < n; ++i) {
    c[i + 1] = c[i] + a[i];
  }
  assign(memo, n, n + 1, -1);
  cout << rec(0, n) << '\n';
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
 
int main(){
    int n;
 
    cin >> n;
    int* l = new int[n];
 
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
 
    for(int i = 0; i < n; i++){
        cout << l[n-i-1] << flush;
        if(i == n-1){
            cout << endl;
            break;
        }
        cout << ' ' << flush;
    }

    delete[] l;
 
    return(0);
}

Measured memory_bytes: 1196
#include <cmath>
#include <cstdint>
#include <iostream>

using namespace std;

int main() {
  int64_t a, b, c;
  cin >> a >> b >> c;
  if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

using C = pair<ld, P>;
#define rad first
#define pnt second

C smallest_enclosing_disc(vector<P> ps){
    auto c3 = [](const P &a, const P &b, const P &c){
        ld A = norm(b - c);
        ld B = norm(c - a);
        ld C = norm(a - b);
        ld S = abs(cross(b - a, c - a));
        P p = (A*(B+C-A)*a + B*(C+A-B)*b + C*(A+B-C)*c) / (4*S*S);
        ld r = abs(p - a);
        return make_pair(r, p);
    };

    auto c2 = [](const P &a, const P &b){
        P c = (a + b) / (ld)2;
        ld r = abs(a - c);
        return make_pair(r, c);
    };

    auto in_circle = [](const P &a, const C &c){
        return norm(a - c.pnt) <= c.rad*c.rad + eps;
    };

    int n = ps.size();
    random_shuffle(ps.begin(), ps.end());
    C c = c2(ps[0], ps[1]);
    for(int i = 2; i < n; ++i){
        if(!in_circle(ps[i], c)){
            c = c2(ps[0], ps[i]);
            for(int j = 1; j < i; ++j){
                if(!in_circle(ps[j], c)){
                    c = c2(ps[j], ps[i]);
                    for(int k = 0; k < j; ++k){
                        if(!in_circle(ps[k], c)){
                            c = c3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

// http://www.spoj.com/problems/QCJ4/
// http://www.spoj.com/status/ns=18116289

// int main(){
//     srand(time(0));
//     int n;
//     cin >> n;
//     vector<P> ps(n);
//     for(int i = 0; i < n; ++i){
//         ld x,y;
//         cin >> x >> y;
//         ps[i] = P(x,y);
//     }

//     printf("%.2lf\n", (double)smallest_enclosing_disc(ps).rad*2);
// }


int n,m;
ld r[111], mb[111];
 
bool used[111];

bool chk(int s){
    vector<int> b;
    rep(i,n)if(!used[i]) b.emplace_back(r[i]);
    vector<ld> a;
    for(int i = s; i < m; ++i) a.emplace_back(mb[i]);
    sort(all(a));
    sort(all(b));
    int last = -1;
    rep(i,a.size()){
        bool found = false;
        for(int j = last+1; j < (int)b.size(); ++j){
            if(a[i] < b[j] + eps){
                found = true;
                last = j;
                break;
            }
        }
        if(!found)return false;
    }
    return true;
}

int main(){
    cin >> n;
    double ans = 0.0;
    G g(n);
    rep(i,n){
        ld x,y;
        cin >> x >> y;
        g[i] = P(x,y);
    }
    ans = smallest_enclosing_disc(g).rad;
    printf("%.12lf\n", ans);
}


Measured memory_bytes: 256
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
c = 0
d = 0
for i in range(x):
    if i in a:
        c += 1
for i in range(x+1,n+1):
    if i in a:
        d += 1
print(min(c,d))


Measured memory_bytes: 3060
// https://atcoder.jp/contests/abc164/tasks/abc164_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll S, W;
  cin >> S >> W;

  if (W >= S) {
    drop("unsafe");
  } else {
    drop("safe");
  }
}


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


int main() {
    int N ; cin >> N;
    vector<int> X(N);
    for(int i=0;i<N;i++){
        cin >> X.at(i);
    }
    int V=0, S=0;
    for(int i=0;i<N;i++){
        V+=X.at(i)*X.at(i);
        S+=X.at(i);
    }
    double m;
    double SS=S;
    m=SS/N;
    int M=round(m);

    cout << V-2*M*S + N*M*M << endl;
    
//    cout << V-S*S/N <<endl; // 例の設定うますぎ。感動した

}

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

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

    vector<int> lis;

    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        lis.push_back(a);
    }

    //sort(lis.begin(),lis.end());
    long long cnt=0;
    for(int i=0;i<n;i++)
    {
        cnt+=lis[i]/2;
        lis[i]=lis[i]%2;
        if(i+1<n&&lis[i+1]>0&&lis[i]>0)
        {
            cnt++;
            lis[i+1]--;
        }
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define fio() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define MOD 1000000007
#define nl '\n'
#define pb push_back
#define mp make_pair

using namespace std;
const int N = 3005;
int dp[N][N];
int used[N][N];
int a[N];
int solve(int l,int r)
{
	if(l>r)
		return 0;
	if(used[l][r])
		return dp[l][r];
	used[l][r]=1;
	int res=LLONG_MIN;
	res=max(res,a[l]-solve(l+1,r));
	res=max(res,a[r]-solve(l,r-1));
	dp[l][r]=res;
	return res;
}
int32_t main()
{
	fio();
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	solve(0,n-1);
	cout<<dp[0][n-1];
}



Measured memory_bytes: 140032
#include<iostream>
using namespace std;
int main(){
	int number,cardnumber,count,S[13] = {0},H[13] = {0},C[13] = {0},D[13] = {0};
	char mark;
	cin>>number;
	for(count=0;count<number;count++){
		cin>>mark>>cardnumber;
		if(mark=='S'){
			S[cardnumber-1]=1;
		}
		if(mark=='H'){
			H[cardnumber-1]=1;
		}
		if(mark=='C'){
			C[cardnumber-1]=1;
		}
		if(mark=='D'){
			D[cardnumber-1]=1;
		}
	}
	for(count=0;count<13;count++){
		if(S[count]!=1){
			cout<<"S "<<count+1<<endl;
		}
	}
	for(count=0;count<13;count++){
		if(H[count]!=1){
			cout<<"H "<<count+1<<endl;
		}
	}
	for(count=0;count<13;count++){
		if(C[count]!=1){
			cout<<"C "<<count+1<<endl;
		}
	}
	for(count=0;count<13;count++){
		if(D[count]!=1){
			cout<<"D "<<count+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
S=int(input())

K=S//3


def nCr_init(L,p):
    for i in range(L+1):
        if i<=1:
            f[i],finv[i],inv[i]=1,1,1
        else:
            f[i]=(f[i-1]*i)%p
            inv[i]=(p-inv[p%i]*(p//i))%p
            finv[i]=(finv[i-1]*inv[i])%p

def nCr(n,r,p):
    if 0<=r<=n and 0<=n:
        return (f[n]*finv[n-r]*finv[r])%p
    else:
        return 0

p=10**9+7
res=0
N=10**4+10
f,finv,inv=[0]*N,[0]*N,[0]*N

nCr_init(10**4,p)
for k in range(1,K+1):
    s=S-3*k
    res+=nCr(s+k-1,k-1,p)%p
print(res%p)

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

int main() {
  int h,w,cnt;
  cin >> h >> w;
  char vec[h][w];
  char ans[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> vec[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cnt = 0;
      if(vec[i][j] == '.'){
        for(int k=-1;k<=1;k++){
          for(int l=-1;l<=1;l++){
            if(i+k<0 || i+k>=h || j+l<0 || j+l>=w){
              continue;
            }else{
              if(vec[i+k][j+l] == '#'){
                cnt++;
              }
            }
          }
        }
        ans[i][j] = '0' + cnt;
      }else{
        ans[i][j] = '#';
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << ans[i][j];
    }
    cout << endl;
  }
}

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

int main(){
    string S,T;
    cin >> S >> T;
    int count = 0;
    for(int i = 0; i <S.length();i++){
        if(S.at(i)!=T.at(i)) count++;
    }
    cout << count;
}

Measured memory_bytes: 3912
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 510;
string s;
LL k;


int main()
{
    while (cin >> s >> k) {
        const int n = s.size();
        int cnt = 0;
        FOR(i,0,n) if (s[i] == '1')
            cnt++;
        if (k <= cnt)
            cout << s[k-1] << endl;
        else {
            FOR(i,0,n) if (s[i] > '1') {
                cout << s[i] << endl;
                break;
            }
        }
    }
    return 0;
}


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

using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); i++)
#define ford(i,n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i,l,r) for (int i = int(l); i < int(r); i++)
#define all(a) a.begin(), a.end()
#define sz(a) int(a.size())
#define mp make_pair
#define pb push_back
#define x first
#define y second

template<typename X> inline X abs(const X& a) { return a < 0 ? -a : a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;
const ld PI = acosl(ld(-1));

mt19937 mt(time(NULL));

const int N = 100 * 1000 + 13;
int n, m;
vector<int> l[N];

inline bool read()
{
	if (scanf ("%d%d", &n, &m) != 2)
		return false;
		
	forn (i, n)
	{
		int cnt;
		assert(scanf ("%d", &cnt) == 1);
		
		l[i].resize(cnt);
		
		forn (j, cnt)
		{
			assert(scanf ("%d", &l[i][j]) == 1);
			
			l[i][j]--;
		}
	}
	
	return true;
}

vector<int> g[2 * N];

int d[2 * N], q[2 * N], head, tail;
int p[2 * N];

int bfs (int s)
{
	forn(i, n + m)
		d[i] = INF;		
	head = tail = 0;
	
	q[tail++] = s;
	d[s] = 0;
	p[s] = -1;
	
	while (head != tail)
	{
		int v = q[head++];
		
		forn (i, sz(g[v]))
		{
			int to = g[v][i];
			
			if (d[to] == INF)
			{
				d[to] = d[v] + 1;
				p[to] = v;
				q[tail++] = to;
			}
		}
	}
	
	int v = 0;
	forn (i, n)
		if (d[i] > d[v])
			v = i;
			
	if (d[v] == INF)
	{
		//cerr << s << ' ' << v << ' ' << d[v] << endl;
		puts("NO");
		exit(0);
	}
			
	return v;
}

inline void solve()
{
	forn (i, n)
		forn (j, sz(l[i]))
		{
			int to = l[i][j] + n;
			
			g[i].pb(to);
			g[to].pb(i);
		}
		
	int v = 0;
	forn (i, 10)
		v = bfs(v);
		
	puts("YES");
}

int main()
{
#ifdef SU2_PROJ
	assert(freopen("input.txt", "r", stdin));
	assert(freopen("output.txt", "w", stdout));
#endif

	cout << setprecision(25) << fixed;
	cerr << setprecision(10) << fixed;

	assert(read());
	solve();

#ifdef SU2_PROJ
	cerr << "TIME: " << clock() << endl;
#endif

	return 0;
}


Measured memory_bytes: 15480
while (h, w = gets.split.map(&:to_i)) != [0,0]
  h.times do |i|
    w.times do |j|
      if (i+j) % 2 == 0
        printf("%s", '#')
      else
        printf("%s", '.')
      end
    end
    puts ""
  end
  puts ""
end


Measured memory_bytes: 6884
use strict;
use warnings;
use utf8;
binmode STDIN, ':encoding(cp932)';
binmode STDOUT, ':encoding(cp932)';
binmode STDERR, ':encoding(cp932)';

chomp(my $Day = <STDIN>);
my %Whatdays = (
    'SUN' => 7,
    'SAT' => 1,
    'FRI' => 2,
    'THU' => 3,
    'WED' => 4,
    'TUE' => 5,
    'MON' => 6
);

#print $Day;
print $Whatdays{$Day};

Measured memory_bytes: 5992
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll N; string S;
  cin >> N >> S;

  int cnt = 0, pre = 0;
  rep(i, N) {
    if (S[i] == '(') cnt++;
    else {
      cnt--;
      if (cnt < 0) pre = max(pre, -cnt);
    }
  }
  rep(i, pre) S = "(" + S;
  N += pre;

  cnt = 0;
  rep(i, N) {
    if (S[i] == '(') cnt++;
    else cnt--;
  }
  rep(i, cnt) S = S + ")";

  cout << S << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888