akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define _ % P
const int N = 262144, P = 998244353;
int ri() {
	char c = getchar(); int x = 0, f = 1; for(;c < '0' || c > '9'; c = getchar()) if(c == '-') f  = -1;
	for(;c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) - '0' + c; return x * f;
}
int a[N], p[N], sum, m, n;
int Pow(int x, int k) {
	int r = 1;
	for(;k; x = 1LL * x * x _ , k >>= 1)
		if(k & 1)
			r = 1LL * r * x _;
	return r;
}
int Inv(int x) {return Pow(x, P - 2);}
void FWT(int *F) {
	for(int d = 1;d < m; d <<= 1)
		for(int i = 0;i < m; i += d << 1)
			for(int j = 0;j < d; ++j) {
				int tp = F[i + j + d];
				F[i + j + d] = (F[i + j] - tp) _;
				F[i + j] = (F[i + j] + tp) _;
			}
}
int main() {
	n = ri(); m = 1<< n;
	for(int i = 0;i < m; ++i)
		p[i] = ri(), sum = (sum + p[i]) _;
	sum = Inv(sum);
	for(int i = 0;i < m; ++i)
		p[i] = 1LL * p[i] * sum % P;
	--p[0];
	for(int i = 1;i < m; ++i)
		a[i] = -1;
	a[0] = m - 1;
	FWT(p); FWT(a);
	for(int i = 0;i < m; ++i)
		a[i] = 1LL * a[i] * Inv(p[i]) _;
	FWT(a); int ivm = Inv(m);
	for(int i = 0;i < m; ++i) {
		a[i] = 1LL * a[i] * ivm _;
		printf("%d\n", ((a[i] - a[0]) _ + P) _);
	}
	return 0;
}



Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;

int main(){
	string s;
	cin >> s;
	int len;
	len=s.size()-2;
	
	cout << s[0] << len << s[s.size()-1] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#define TST 0
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)
#define printM(a, n, m) F(i, 0, n){ FE(j, 0, m) cout << a[i][j] << (i==m?'\n':' ');}

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

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

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

#define printMatrix(mat,n,m){ \
    F(i, 0, n){               \
        F(j, 0, m){           \
            cout << mat[i][j] << space;\
        }\
        cout << endl;\
    }\
}

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;
    string str;
    cin >> str;
    int ans = 0;
    FE(i, 0, str.size()-3){
        if(str[i] == 'A'){
            if(str[i+1] == 'B'){    
                if(str[i+2] == 'C'){
                    ans ++; 
                }
            }
        }
    }

#if TST==1
#endif
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vint num(n);
        for (int i = 0; i < n; ++i) cin >> num[i];
        sort(ALL(num));
        
        int sum = 0;
        for (int i = 1; i < n-1; ++i) sum += num[i];
        sum /= (n-2);
        
        cout << sum << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 1216
#include <stdio.h>
#define N 100

int main()
{
  int n,i,j,v,r;
  int a[N];

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

   for(r=0 ; r<n-1 ; r++)
	{
	  printf("%d ",a[r]);
	}
   printf("%d\n",a[n-1]);

  for(i=1 ; i<n ; i++)
    {
      v = a[i];
      j = i-1;
      while(j>=0 && a[j] > v)
	{
	  a[j+1] =a[j];
	  j--;
	}
      a[j+1] = v;

      for(r=0 ; r<n-1 ; r++)
	{
	  printf("%d ",a[r]);
	}
      printf("%d\n",a[n-1]);
      
    }

  return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;
ll n,q,m,k,l,ans;
vll a,b;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    cin >> n >> q;
    string s;cin >> s;
    vi cumsum(n+1);// i文字目までに含まれるACの個数
    cumsum[0] = 0;cumsum[1] = 0;
    rng(i,1,n) {
        int tmp = cumsum[i];
        if(s[i-1]=='A' && s[i]=='C') tmp++;
        cumsum[i+1] = tmp;
    }
    // cout << "hoge" << endl;
    // rep(i,n+1) cout << cumsum[i] << endl;
    rep(i,q) {
        int l,r;
        cin >> l >> r;
        cout << (cumsum[r]-cumsum[l]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1488
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int x[51];

ll dp[55][55][2510];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);

    int N, A;
    cin >> N >> A;
    int sum = 0;
    REP(i, N)
    {
        cin >> x[i];
        sum += x[i];
    }

    //i番目, 何個取ったか, その時の値 = 個数

    dp[0][0][0] = 1;
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            for (int k = 0; k <= sum; ++k)
            {
                if (k - x[i] >= 0)
                {
                    dp[i + 1][j + 1][k] = dp[i][j + 1][k] + dp[i][j][k - x[i]];
                }
                else
                {
                    dp[i + 1][j][k] = dp[i][j][k];
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= N; ++i)
    {
        ans += dp[N][i][i * A];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N, sum;
  cin >> N;
  sum = 0;

  for (int i = 0; i < N; i++)
  {
    int l, r;
    cin >> l >> r;
    sum += (r - l + 1);
  }
  cout << sum << endl; 
}

Measured memory_bytes: 3536
import numpy as np
h, w = map(int, input().split())

field = [list(input()) for x in range(h)]
for i, row in list(enumerate(field))[::-1]:
    if "#" not in row:
        del field[i]

field = list(np.transpose(field))
for i, row in list(enumerate(field))[::-1]:
    if "#" not in row:
        del field[i]

for i in np.transpose(field):
    print("".join(i))

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

int main() {
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int a = 1000-n, count = 0;
		if(a>=500){
			a -= 500;
			count++;
		}
		while(a>=100){
			a -= 100;
			count++;
		}
		if(a>=50){
			a -= 50;
			count++;
		}
		while(a>=10){
			a -= 10;
			count++;
		}
		if(a>=5){
			a -= 5;
			count++;
		}
		while(a>0){
			a--;
			count++;
		}
		cout << count << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,t,tb=0,x,xb=0,y,yb=0,tt,i;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> t >> x >> y;
    tt=t-tb-abs(x-xb)-abs(y-yb);
    if(tt<0||tt%2==1){
      cout << "No" << endl;
      return 0;
    }
    tb=t; xb=x; yb=y;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

long long r, d, x;

int main()
{
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    std::cin >> r >> d >> x;
    for (int i = 1; i <= 10; ++i)
        std::cout << (x = x * r - d) << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var AB = new List<List<long>>();
            for(var i=0;i<N;++i)
                AB.Add(Slist());
            var absorted = AB.OrderBy(ab => ab[0]).ToArray();
            var ans = 0L;
            var num = 0L;
            for(var i=0;i<N;++i)
            {
                ans += absorted[i][0] * Min(M - num, absorted[i][1]);
                num += absorted[i][1];
                if (M <= num)
                    break;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 37124
<?php
fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $k);
if (abs($a-$b) > 10**18){
    print("Unfair\n");
    exit(0);
}
if ($k%2){
    $ans = $b-$a;
} else {
    $ans = $a-$b;
}
print("$ans\n");
?>

Measured memory_bytes: 4856
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>

using namespace std;


int main(){
    int n,tmp;
    cin >> n;
    //vector<int> p(n);
    int p[52];
    int c=0;
    for(int i=1;i<=n;i++) cin >> p[i];
    for(int i=1;i<=n;i++){
        if(p[i] != i){
            tmp=p[i];
            p[i]=p[tmp];
            p[tmp]=tmp;

            c++;
        }
    }
    if(c > 1) cout << "NO" <<endl;
    else cout << "YES" <<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vec vector
#define vi vec<int>
#define vvi vec<vec<int>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [=](auto i)
#define compare(i, j) [=](auto i, auto j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;

int ceil_div(int X, int Y) {
  return (X - 1) / Y + 1;
}

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int n;

  cin >> n;
  vvi dp(n, vi(3)); //select i-th and skipped j-times.
  cin >> dp[0][0];
  cin >> dp[1][1];
  FOR(i, 2, n) {
    int a;
    cin >> a;
    if (i % 2 == 0) {
      dp[i][0] = dp[i - 2][0] + a;
      if(n % 2 == 1) {
        dp[i][2] = dp[i - 2][2] + a;
        if(i > 3) {
          dp[i][2] = max(dp[i][2], dp[i - 3][1] + a);
          dp[i][2] = max(dp[i][2], dp[i - 4][0] + a);
        }
      }
    } else {
      dp[i][1] = dp[i - 2][1] + a;
      if(i > 2) dp[i][1] = max(dp[i][1], dp[i - 3][0] + a);
    }
  }
  if (n % 2 == 0) cout << max(dp[n - 1][1], dp[n - 2][0]) << endl;
  else cout << max(dp[n - 1][2], max(dp[n - 2][1], dp[n - 3][0])) << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 14272
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
int main(){ 
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	ll ans=0;
	for(int i=0;i<k;i++)
		ans+=a[i];
	cout<<ans<<endl;
}



Measured memory_bytes: 3552
#include<stdio.h>
int main()
 {

    long long int s,d,t,n=0;
    long long int i[15];
  for(s=0;s<=9;s++)
   {
	scanf("%lld,",&i[s]);
   }

	 for(d=0;d<=9;d++)
	 {
	  for(s=0;s<=9;s++)
	   {
		if(i[d]<i[s])
		 {
		  t=i[s];
		  i[s]=i[d];
		  i[d]=t;
		 }
		}
	   }
   for(s=9;s>=7;s--)
   {
	 printf("%lld\n",i[s]);

	}
 return 0;
 }

Measured memory_bytes: 600
n = int(input())
a=[int(i) for i in input().split()]
h = [0]*(n+1)
for i in a:
    h[i]+=1


from operator import mul
from functools import reduce
import copy
hh = copy.deepcopy(h)
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for index,i in enumerate(hh):

    if i==0 or i==1:
        h[index]=0
        continue
    h[index] = cmb(i,2)

ss = sum(h)

for i,j in zip(a,hh):

    if hh[i]<=2:

        print(ss-h[i])
    else:

        print(ss-h[i]+cmb(hh[i]-1,2))

Measured memory_bytes: 26140
#include<stdio.h>

int main(void){
	int hi,ho;
	char top,at,ans;
	
	scanf("%c %c",&at,&top);
	
	if(at=='H') hi = 0;
	else if(at=='D')hi = 1;
	if(top=='H') ho = 0;
	else if(top=='D')ho = 1;
	
	if(hi==ho) ans='H';
	else ans='D';
	
	printf("%c",ans);
	
	return 0;
}

Measured memory_bytes: 128
import heapq
from itertools import permutations
n, m, r = [int(item) for item in input().split()]
rs = [int(item) for item in input().split()]
abc = [[int(item) for item in input().split()] for _ in range(m)]
INF = 10**9

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.num = len(adj)
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def reset(self):
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def calc(self, start, goal=None):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest in range(self.num):
                cost = self.adj[src][dest]
                if cost != INF and self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
                    self.prev[dest] = src
        if goal is not None:
            return self.get_path(goal)
        else:
            return self.dist

    def get_path(self, goal):
        path = [goal]
        dest = goal

        while self.prev[dest] != INF:
            path.append(self.prev[dest])
            dest = self.prev[dest]
        return list(reversed(path))

path = [[INF] * n for _ in range(n)]
short_path = [[INF] * n for _ in range(n)]
for i in range(n):
    path[i][i] = 0
for a, b, c in abc:
    path[a-1][b-1] = path[b-1][a-1] = c

dij = Dijkstra(path)
for item in rs:
    for i in range(n):
        short_path[item-1][i] = dij.calc(item-1)[i]
    dij.reset()

ans = INF
for pattern in permutations(rs):
    distance = 0
    for i in range(1,r):
        distance += short_path[pattern[i-1]-1][pattern[i]-1]
    ans = min(ans, distance)
print(ans)

Measured memory_bytes: 6868
#include <iostream>

using namespace std;

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

        m = 1;
        for(int i=0; i<n; i++){
                if(m * 2 < m + k) m = m * 2;
                else m = m + k;
         }
        cout << m;
 }

Measured memory_bytes: 256
s = input()
t = list(input())

index = -1
rep = 0
length = len(s)
ans = 0
for tar in t:
    if index+1 == length:
        rep += 1
        index = -1
        
    kari_index = s[index+1:].find(tar)

    if kari_index == -1:
        tmp = s.find(tar)
        if  tmp == -1:
            ans = -1
        else:
            rep += 1
            index = tmp
    else:
        index += kari_index + 1

if ans != -1:
    ans = rep * len(s) + index + 1
print(ans)

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

int main()
{
    ll n;
    cin >> n;
    //cout << ( (2 + n - 1) * (n - 2) ) / 2 + 1 << endl;
    cout << n * (n - 1) / 2 << endl;
    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  int ans=((N-1)+(K-2))/(K-1);
  cout << ans << endl;
}

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

int main()
{
  int H,W;
  cin>>H>>W;
  int A[H][W];
  
  for(int i=0;i<H;i++)
  {
    for(int j=0;j<W;j++)
    {
      char s;
      cin>>s;
      if(s=='.'){A[i][j]=-1;}
      else{A[i][j]=-2;}
    }
  }
  
  int Ans[H][W];
  Ans[H-1][W-1]=1;
  
  for(int i=H-1;i>=0;i--)
  {
    for(int j=W-1;j>=0;j--)
    {
      if(i==H-1 && j==W-1){continue;}
      if(A[i][j]==-2){Ans[i][j]=0;continue;}
      Ans[i][j]=0;
      if(i+1<H && Ans[i+1][j]!=-2){Ans[i][j]=(Ans[i][j]+Ans[i+1][j])%1000000007;}
      if(j+1<W && Ans[i][j+1]!=-2){Ans[i][j]=(Ans[i][j]+Ans[i][j+1])%1000000007;}
      
    }
  }

    // for(int i=0;i<H;i++)
    // {
    //     for(int j=0;j<W;j++)
    //     {
    //       cout<<Ans[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<Ans[0][0]<<endl;

    
}

Measured memory_bytes: 11376
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define eF(i,u) for(int i=h[u];i;i=nxt[i])
#define Mod 1000000007
			
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;

int n,m,S,T;
ll Ans;
int U[200001],V[200001],D[200001];
int h[100001],nxt[400001],to[400001],w[400001],tot;
void ins(int x,int y,int z){nxt[++tot]=h[x];to[tot]=y;w[tot]=z;h[x]=tot;}

ll d1[100001],d2[100001],g1[100001],g2[100001];bool v1[100001],v2[100001];
priority_queue<pli,vector<pli>,greater<pli> > pq;

void Dij(ll*d,ll*g,bool*v,int s){
    d[s]=0ll;
    pq.push(pli(0ll,s));
    g[s]=1;
    while(!pq.empty()){
        pli P=pq.top(); pq.pop();
        int u=P.second; ll du=P.first;
        if(v[u]||d[u]<du) continue;
        v[u]=1;
        eF(i,u){
            if(d[to[i]]==du+w[i])
                g[to[i]]=(g[to[i]]+g[u])%Mod;
            if(d[to[i]]>du+w[i])
                g[to[i]]=g[u],
                d[to[i]]=du+w[i], pq.push(pli(d[to[i]],to[i]));
        }
    }
}

int main(){
//	freopen("0.in","r",stdin);
    int x,y,z;
    scanf("%d%d",&n,&m);
    scanf("%d%d",&S,&T);
    F(i,1,m) scanf("%d%d%d",&x,&y,&z), ins(x,y,z), ins(y,x,z), U[i]=x, V[i]=y, D[i]=z;
    memset(d1,0x3f,sizeof d1);
    Dij(d1,g1,v1,S);
    memset(d2,0x3f,sizeof d2);
    Dij(d2,g2,v2,T);
    ll Dist=d1[T];
    Ans=g1[T]*g1[T]%Mod;
    F(i,1,n){
        if(d1[i]+d2[i]==Dist&&d1[i]==d2[i])
            Ans=(Ans-g1[i]*g1[i]%Mod*g2[i]%Mod*g2[i]%Mod)%Mod;
    }
    int u,v,d;
    F(i,1,m){
        u=U[i], v=V[i], d=D[i];
        if(d1[u]+d+d2[v]==Dist && d1[u]+d>d2[v] && d2[v]+d>d1[u]){
            Ans=(Ans-g1[u]*g2[v]%Mod*g1[u]%Mod*g2[v]%Mod)%Mod;
        }
        u=V[i], v=U[i], d=D[i];
       
	    if(d1[u]+d+d2[v]==Dist && d1[u]+d>d2[v] && d2[v]+d>d1[u]){
            Ans=(Ans-g1[u]*g2[v]%Mod*g1[u]%Mod*g2[v]%Mod)%Mod;
        }
    }
    /*for(int i=1;i<=n;i++)
		if(d1[i]+d2[i]==d1[T])    
    		printf("%d %d\n",g1[i],g2[i]);*/
    printf("%lld",(Ans%Mod+Mod)%Mod);
    return 0;
}


Measured memory_bytes: 12656
local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end

local function getlcm(x, y)
  local gcd = getgcd(x, y)
  return (x // gcd) * y
end

local n = io.read("*n")
local lcm = io.read("*n")
for i = 2, n do
  lcm = getlcm(lcm, io.read("*n"))
end
print(lcm)


Measured memory_bytes: 1008
n = int(input())
st = [list(input().split()) for i in range(n)]
s = [i[0] for i in st]
t = [int(i[1]) for i in st]
x = input()
SUM = 0
for i in range(s.index(x) + 1, n):
    SUM += t[i]
print(SUM)

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

constexpr int MAX = 100010;

struct Edge{
    int v;
    Edge* next;
};

int N, M;
Edge* G[MAX];
int component[MAX];

void push( int u, int v ){
    Edge* e = new Edge;
    e->v = v;
    e->next = nullptr;

    Edge* i;
    for( i = G[u]; i->next != nullptr; i = i->next ){}
    i->next = e;
}

void dfs( int s, int k ){
    component[s] = k;
    for( Edge* e = G[s]->next; e != nullptr; e = e->next ){
        if( !component[e->v] ){
            dfs( e->v, k );
        }
    }
}

int main(){
    for( int i = 0; i < MAX; i++ ){
        Edge* e = new Edge;
        e->v = -1;
        e->next = nullptr;       
        G[i] = e;
    }
    
    cin >> N >> M;
    for( int i = 0; i < M; i++ ){
        int u, v; cin >> u >> v;
        push( u, v );
        push( v, u );
    }

    int k = 1;
    for( int i = 0; i < N; i++ ){
        if( !component[i] ){
            dfs( i, k );
            k++;
        }
    }

    int q; cin >> q;
    for( int i = 0; i < q; i++ ){
        int u, v; cin >> u >> v;
        if( component[u] == component[v] ){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 16760
#include<bits/stdc++.h>
using namespace std;
int n;
string s[100001];
int main() {
	cin>>n>>s[0];
	for(int i=1; i<=n; i++)
		cin>>s[i];
	sort(s+1,s+1+n);
	for(int i=1; i<=n; i++)
		cout<<s[i];
	return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
// #define INF 10010010010

typedef long long ll;
typedef pair<int, int> p;

ll n, x;
vector<ll> v;
vector<ll> cost;

void init(){
  vector<ll> tmp(n, 0);
  for (ll i = 0; i < n; i++){
    cin >> tmp[i];
  }
  v = tmp;
  vector<ll> tmp2(n, LLONG_MAX);
  cost = tmp2;
}

ll calc(ll k){
  ll res = 0;
  for (ll i = 0; i < n; i++) {
    if(i - k >= 0) cost[i] = min(cost[i], v[i-k]);
    else cost[i] = min(cost[i], v[n-(k-i)]);

    // for (ll j = 0; j <= k; j++) {
    //   if(i - j >= 0){
    //     count = min(count, v[i-j]);
    //   }else{
    //     count = min(count, v[n-(j-i)]);
    //   }
    // }
    // cost[k] =
    res += cost[i];
  }
  // prll(cost);
  return res + k * x;
}


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

  ll res = LLONG_MAX;
  for (ll i = 0; i < n; i++) {
    // cout << calc(i) << endl;
    res = min(res, calc(i));
  }
  cout << res << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  vi P(N);
  rep(i, N) cin >> P[i];
  
  int curmin = P[0];
  int ct = 0;
  rep(i, N) {
    if(P[i] <= curmin) {
      ct++;
    }
    chmin(curmin, P[i]);
  }
  
  fin(ct);
}

Measured memory_bytes: 1024
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<map>
#include<iostream>
using namespace std;
const int maxn=3000000;
const long long INF= 1111111111111111;
struct Edge{
	int from,to,dist;
	Edge(int u,int v,int d):from(u),to(v),dist(d){}
	;
};
long long n,m;
vector<Edge>edges;
vector<int>G[maxn];
bool done[maxn];
long long d[maxn];
long long p[maxn];
void Addedge(long long from,long long to,long long dist){
	edges.push_back(Edge(from,to,dist));
	m=edges.size();
	G[from].push_back(m-1);
}
struct HeadNode{
	long long d;
	long long u;
	bool operator<(const HeadNode& rhs) const{
	return d>rhs.d;
	}
};
void dijkstra(int s){
	priority_queue<HeadNode>Q;
	for(int i=1;i<=n;i++)d[i]=INF;
	d[s]=0;
	memset(done,0,sizeof(done));
	Q.push((HeadNode){0,s});
	while(!Q.empty()){
		HeadNode x =Q.top();Q.pop();
		int u=x.u;
		if(done[u])continue;
		done[u]=true;
		for(int i=0;i<G[u].size();i++){
			Edge& e= edges[G[u][i]];
			if(d[e.to]>d[u]+e.dist){
				d[e.to]=d[u]+e.dist;
				p[e.to]=G[u][i];
				Q.push((HeadNode){d[e.to],e.to});
			}
		}
	}
}
int main(){
//int n,a[100001]={0};
cin>>n;
long long x,y,z;
for(int i=1;i<n;i++){
scanf("%d%d%d",&x,&y,&z);
Addedge(x,y,z);
Addedge(y,x,z);
}
int n1,m1;
cin>>n1>>m1;
dijkstra(m1);
for(int i=1;i<=n1;i++){	
scanf("%d%d",&x,&y);
	cout<<d[x]+d[y]<<endl;
}
//cout<< <<endl;
return 0;
}


Measured memory_bytes: 87600
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll a, b, x;
  cin >> a >> b >> x;
  if (x <=a + b&&x>=a){
    print("YES");
  }
  else{
    print("NO");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 2e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
vector<int> tree[MAXN];
ll subtree[MAXN];
ll fact[MAXN];
ll ans[MAXN];
ll pprod[MAXN];

ll dfs(int u, int p) {
	subtree[u] = 1LL;
	for (int i = 0; i < tree[u].size(); ++i) {
		int v = tree[u][i];
		if (v == p) continue;
		subtree[u] += dfs(v, u);
	}
	return subtree[u];
}

ll binexp(ll b, ll e) {
	ll ret = 1;
	while (e) {
		if (e & 1) ret = ret * b%MOD;
		b = b * b%MOD;
		e >>= 1;
	}
	return ret;
}

ll cal(int u, int p) {
	ll &ret = pprod[u];
	ret = 1LL;
	ll prod = 1LL;
	for (int i = 0; i < tree[u].size(); ++i) {
		int v = tree[u][i];
		if (v == p) continue;
		ret = ret * cal(v, u) % MOD;
		prod = prod * fact[subtree[v]] % MOD;
	}
	ret = ret * fact[subtree[u] - 1] % MOD* binexp(prod, MOD - 2) % MOD;
	return ret;
}

void change_root(int u, int p) {
	for (int i = 0; i < tree[u].size(); ++i) {
		int v = tree[u][i];
		if (v == p) continue;
	}
	if (u != 1) {
		ans[u] = ans[p] * binexp(fact[subtree[u] - 1], MOD - 2) % MOD*fact[N - 1] % MOD*binexp(fact[N - subtree[u]], MOD - 2) % MOD*fact[subtree[u]]%MOD*binexp(fact[N - 1], MOD - 2)%MOD*fact[N - subtree[u] - 1]%MOD;
	}
	for (int i = 0; i < tree[u].size(); ++i) {
		int v = tree[u][i];
		if (v == p) continue;
		change_root(v, u);
	}
}

int main()
{
	int i, j, u, v;
	scanf("%d", &N);
	for (i = 1; i < N; ++i) {
		scanf("%d%d", &u, &v);
		tree[u].push_back(v);
		tree[v].push_back(u);
	}
	fact[0] = 1;
	for (i = 1; i <= N; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}
	dfs(1, 0);
	cal(1, 0);
	ans[1] = pprod[1];
	change_root(1, 0);
	for (i = 1; i <= N; ++i) {
		printf("%lld\n", ans[i]);
	}
}

Measured memory_bytes: 20212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String[] s = { "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
				"u", "v", "w", "x", "y", "z" };
		Scanner kb = new Scanner(System.in);
		String p = kb.next();
		for (int i = 0; i < s.length; i++) {
			if (s[i].equals(p)) {
				System.out.println(s[i + 1]);
			}
		}
		kb.close();
	}

}


Measured memory_bytes: 21844
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] a = new char[H][];
		for(int i=0; i<H; i++) {
			a[i] = sc.next().toCharArray();
		}
		
		boolean ok = true;
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				if(a[i][j]=='#') {
					int cnt1 = 0;
					if(i>0 && a[i-1][j]=='#')
						cnt1++;
					if(j>0 && a[i][j-1]=='#')
						cnt1++;
					if(!(i==0 && j==0) && cnt1!=1)
						ok = false;
					
					int cnt2 = 0;
					if(i<H-1 && a[i+1][j]=='#')
						cnt2++;
					if(j<W-1 && a[i][j+1]=='#')
						cnt2++;
					if(!(i==H-1 && j==W-1) && cnt2!=1)
						ok = false;
					
				}
			}
		}
		
		System.out.println(ok ? "Possible" : "Impossible");
		sc.close();
	}
}


Measured memory_bytes: 9812
fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_end().to_owned()
    };
    let t = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_end().to_owned()
    };

    let all:Vec<char>=s.chars().collect();
    let partial:Vec<char>=t.chars().collect();
    let mut check:Vec<u32>=Vec::new();

    for i in 0..(all.len()-partial.len()+1)
    {
        let mut count:u32=partial.len() as u32;
        for j in 0..partial.len()
        {
            if all[i+j as usize]==partial[j as usize]{
                count-=1;
            }
        }
        check.push(count);
    }

    let  ans:&u32=check.iter().min().unwrap();

    println!("{}",ans);
}


Measured memory_bytes: 2128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
#include <utility>
using namespace std;
typedef long long longlong;
typedef long long LL;

int main(void) {
	LL n, k, i, j, l, an = 0, aa, bb;
	cin >> n >> k;
	vector<LL> a(n);
	vector<LL> b(n);
	vector<LL> ans(1000000,0);
	for (i = 0; i < n; ++i) {
		cin >> aa >> bb;
		ans[aa-1] += bb;
	}
	for (i = 0; i < 1000000 + 1; ++i) {
		an += ans[i];
		if (an >= k) {
			cout << i+1 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
  int N;
  std::cin >> N;
  
  std::vector<int> vec(N);
  for (int i=0;i<N;i++) std::cin >> vec[i];
  
  std::sort(vec.begin(),vec.end(),std::greater<int>());
  
  int Alice=0,Bob=0;
  
  for (int i=0;i<N;i++) {
    if (i%2==0) {
      Alice+=vec[i];
    } else {
      Bob+=vec[i];
    }
  }
  
  std::cout << Alice-Bob;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  ll X,Y;
  cin >> X >> Y;
  ll ans=1;
  ll prev=X;
  while(1){
    if(Y/2<prev) break;
    ll now=2*prev;
    ++ans;
    prev=now;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long n,a,b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    long cnta ,cntb;
    cnta = cntb = 0;
    vector<string> ans;
    rep(i,n){
        if(s[i]=='a'){
            if((cnta+cntb)<(a+b)) ans.push_back("Yes");
            else ans.push_back("No");
            cnta++;
        }
        else if(s[i]=='b'){
            if((cnta+cntb)<(a+b) && cntb<b) ans.push_back("Yes");
            else ans.push_back("No");
            if(cntb<b) cntb++;
        }
        else ans.push_back("No");
    }
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 6260
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[400000];
lld brr[200][200];
lld dp[200][200];
lld rec(lld a,lld b){
    if (dp[a][b]!=-1)return dp[a][b];
    if (a==0&&b==0){
        if (brr[a][b])return 1;
        else return 0;
    }
    lld lef=INT_MAX;lld up=INT_MAX;
    if (a!=0){
        lef=rec(a-1,b);
        if (brr[a-1][b]==0&&brr[a][b])lef++;
    }
    if (b!=0){
        up=rec(a,b-1);
        if (brr[a][b-1]==0&&brr[a][b])up++;
    }
    dp[a][b]=min(lef,up);
    return dp[a][b];
}
int main()
{
     ios;
     lld TESTS,q,a,s,b,r,k,c,p,h,w,d,x,y,z,xs,ys,t;
     TESTS=1;
     //cin>>TESTS;
   //  memset(dpt,0,sizeof(dpt));memset(dput,0,sizeof(dput));
   memset(dp,-1,sizeof(dp));
     while(TESTS--)
     {
         cin>>h>>w;
         char ch;
         rep(i,0,h-1) rep(j,0,w-1){cin>>ch;if (ch=='#')brr[i][j]=1;else brr[i][j]=0;}
         cout<<rec(h-1,w-1);
     }
    return 0;
}


Measured memory_bytes: 768
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    N = readline() |> parseInt
    A,B = readline() |> split |> parseMap
    P = readline() |> split |> parseMap
    
    ctr_A = 0
    ctr_B = 0
    ctr_C = 0
    for i in 1:N
        if P[i] <= A 
            ctr_A += 1
        elseif P[i] <= B 
            ctr_B += 1
        else 
            ctr_C += 1
        end
    end
    ans = min(ctr_A,ctr_B,ctr_C)
    println(ans)
end

main()



Measured memory_bytes: 110464
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

H, W = rdi()
print "#" * (W+2)
for i in range(H):
        s = rd()
        print "#" + s + "#"
print "#" * (W+2)


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

using namespace std;

int main(){
    int k,n,t = 0;

    cin>>k>>n;

    int vec[n];

    for (int i = 0; i < n; i++)
    {
        cin>>vec[i];
    }
    for (int i = 0; i < n-1; i++)
    {
        t = max(t, vec[i+1]-vec[i]);
    }

    t = max(t,k-vec[n-1]+vec[0]);

    cout<<k-t<<"\n";
    
}   

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


bool p[247000] = { false };

int main(){
	p[0] = p[1] = true;
	for (int i = 2; i < 247000; i++) {
		if (!p[i]) {
			for (int j = 2; j*i < 247000; j++) {
				p[i*j] = true;
			}
		}
	}
	int n, c;
	while (cin >> n && n != 0) {
		c = 0;
		for (int i = n + 1; i <= 2 * n; i++) {
			if (!p[i]) {
				c++;
			}
		}
		cout << c << endl;
	}

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
    llong A, B, C, K;
    cin >> A >> B >> C >> K;
    llong ans = -1;
    if (K <= A )  {
        ans = K;
    }
    else if (K <= (A+B)) {
        ans = A;
    }
    else if (K <= (A+B+C) ) {
        ans = A - (K - (A+B));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>

using namespace std;

const int inf = 1 << 29;
int N,A,B,C;
vector<int> l;

int dfs(int depth, int LA,int LB, int LC){
  if( depth == N ){ 
    if( LA > 0 && LB > 0 && LC > 0){ 
      return abs( A - LA ) + abs( B - LB ) + abs( C - LC) - 30;}
    else{ return inf;}}
  else{
   int c1 = dfs( depth + 1, LA + l[depth], LB, LC) + 10;
   int c2 = dfs( depth + 1, LA, LB + l[depth], LC) + 10;
   int c3 = dfs( depth + 1, LA, LB, LC + l[depth]) + 10;
   int c4 = dfs( depth + 1, LA, LB, LC) ;
    
    return min(min(c1,c2),min(c3,c4));}}

int main(){
  cin >> N >> A >> B >> C;
 l.resize(N);
  for(int i = 0;i < N; i++){ cin >> l[i];}
  cout << dfs(0,0,0,0) << endl; 
  return 0;}
  
  


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

int main() {
  int a;
  int b;
  
  cin >> a;
  cin >> b;
  
  if (a > 9 || b > 9) {
    cout << "-1";
    return 0;
  }
  
  cout << a * b;
    
  return 0;   
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll oddxor(ll a){
   return ((a+1)/2)%2 ;
}
ll funcxor(ll b){
   if(b%2) return oddxor(b);
   else return oddxor(b+1)^(b+1);
}
int main() {
  ll a,b;
  cin >> a >> b;
  cout << (funcxor(a-1) ^ funcxor(b) ) << endl;
  
}


Measured memory_bytes: 256
s = input()
l = len(s)
strk = 0
if l%2 == 1:
    c = s[(l-1)//2]
    for i in range(1,(l+1)//2):
        a = s[(l-1)//2+i]
        b = s[(l-1)//2-i]
        if a != c or b != c:
            break
        else:
            strk = i
if l%2 == 0:
    c = s[l//2]
    for i in range(1,l//2+1):
        a = s[l//2+i-1]
        b = s[l//2-i]
        if a != c or b != c:
            break
        else:
            strk = i
print((l+1)//2+strk)

Measured memory_bytes: 3188
fun main(arr:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val items = readLine()!!.split(" ").map { it.toLong() }
    val cntList = mutableListOf(items[0] % m)
    for(i in (1 until n)) {
        cntList.add((cntList.last() + items[i])%m)
    }
    val cnt = mutableMapOf<Long, Int>()
    for(i in cntList) {
        if(cnt.containsKey(i)) {
            cnt[i] = cnt[i]!! + 1
        } else {
            cnt[i] = 1
        }
    }
    val ans = cnt.values.map { it.toLong()*(it-1)/2 }.sum() + (cnt[0L]?:0)
    println(ans)
}


Measured memory_bytes: 58572
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int N, M;
int a, b;
map<int, int> cnt;

signed main()
{
    cin >> N >> M;
    REP(i,M) {
        cin >> a >> b;
        cnt[a]++; cnt[b]++;
    }
    
    for (auto it=cnt.begin(); it!=cnt.end(); it++) {
        if (it->second % 2 == 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
}


Measured memory_bytes: 5632
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int N = scan.nextInt();
      	int upper  = N / 100;
      	int down = N % 100;
      	if(down == 0 || down > 13){//tsuki ga ato janai
          	if(upper == 0 || upper > 12){
        		System.out.print("NA");
            }
          	else {
            	System.out.print("MMYY");
            }
        }
      	if(0 < down && down < 13){
        	if(0 < upper && upper < 13){
            	System.out.print("AMBIGUOUS");
            }
          	else {
            	System.out.print("YYMM");
            }
        }
      	
    }
 
}

Measured memory_bytes: 21844
#include<stdio.h>

int main (void){
	
	int m,f,r,score;
	
	for(;;){
		scanf("%d %d %d",&m,&f,&r);
		if(m == -1 && f == -1 && r == -1) break;
		
		score = m+f;
		
		if(score>=80) {
			printf("A\n");
		}else if(m == -1 || f == -1){
			printf("F\n");
		}else if(65<=score && score<80){
			printf("B\n");
		}else if(50<=score && score<65){
			printf("C\n");
		}else if(30<=score && score<50){
			if(r>=50){
				printf("C\n");
			}else{
			printf("D\n");
			}
		}else if(score<30){
			printf("F\n");
		}
	}
return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define rad M_PI/3
#define N 200001
#define Max 10000
int main()
{
    unsigned short *A,*B;
    int C[Max+1];
    int n,i,j;
    scanf("%d",&n);
 
    A=malloc(sizeof(short)*n+1);
    B=malloc(sizeof(short)*n+1);

    for (i = 0; i <= Max; i++) {
        C[i]=0;
    }
    for(i=0;i<n;i++){
        scanf("%hu", &A[i+1]);
        C[A[i+1]]++;
    }
    for(i=1;i<=Max;i++){
        C[i]=C[i]+C[i-1];
    }
    for(j=1;j<=n;j++){
        B[C[A[j]]]=A[j];
        C[A[j]]--;
    }
    for(i=1;i<=n;i++){
        if(i>1)printf(" ");
        printf("%d",B[i]);
    }
    printf("\n");
     
  return 0;
}


Measured memory_bytes: 9620
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
var a=arr[0]

var i = 0
var o = 0
while a != 0 {
	var s = String(a) 
  	a -= 1
  	if( ( s.characters.count % 2 ) == 1 ) {
      o += 1
    }
}

print( o )

Measured memory_bytes: 4208
import sys
from collections import defaultdict

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    W = INPUT()

    l = defaultdict(bool)
    l[W] = True
    for i in range(N-1):
        next_W = INPUT()
        if l[next_W] or next_W[0] != W[-1]:
            print("No")
            sys.exit()
        l[next_W] = True
        W = next_W

    print("Yes")


if __name__ == '__main__':
    main()

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

int div_m2(int n) {
  if(n < 0) return (-n + 1) / 2;
  return -(n / 2);
}

int main() {
  int N; cin >> N;
  vector<int> num;
  if(N == 0) num.push_back(0);
  while(N != 0) {
    num.push_back(abs(N) % 2);
    N = div_m2(N);
  }
  reverse(num.begin(), num.end());
  for(auto n: num) cout << n;
  cout << endl;
  return 0;
}


Measured memory_bytes: 256