akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int main(void){
    int n;
    cin >> n;
    bool ans = false;
    if(n % 10 == 7){
        cout << "Yes" << endl;
        return 0;
    }
    n /= 10;
    if(n % 10 == 7){
        cout << "Yes" << endl;
        return 0;
    }
    n /= 10;
    if( n == 7){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    cin>>N;
    cout<<N*N*N<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int d[35]={0};
	d[0]=1;
	for(int i=0;i<30;i++)for(int j=1;j<=3;j++)d[i+j]+=d[i];
	while(cin>>d[33],d[33])cout<<(d[d[33]]+3649)/3650<<endl;
	return 0;
}


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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = 1e9 + 5;
const LL infll = 1e18+5;
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

const int MAXN = 5e3+5;
int n, k;
char inp[MAXN];
set<vector<char>> all;

int main() {
	scanf("%s", inp);
	n = strlen(inp);
	vector<char> ret;
	gi(k);
	for (int i=0; i<n; i++) {
		ret.clear();
		for (int j=i; j<i+5 && j<n; j++) {
			ret.psb(inp[j]);
			// printf ("ret = ");
			// for (auto xx : ret) printf ("%c", xx);;
			// endln;
			all.insert(ret);
		}
	}
	int hit = 0;
	for (auto xx : all) {
		hit++;
		if (hit==k) {
			ret = xx;
			break;
		}
		// printf ("hit = %d\n", hit);
		// for (auto pr : xx)
			// printf ("%c", pr);
		// endln;
	}
	assert(sz(all)>=k);
	for (int i=1; i<k; i++) 
		all.erase(all.begin());
	ret = *all.begin();
	for (auto xx : ret) printf ("%c", xx);
	endln;
	return 0;
}

Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
from sys import stdin
input = stdin.readline
MOD = 10**9+7

def main():
    n = int(input().strip())
    buf = 9**n
    ans = 10**n - buf - buf + 8**n
    print(ans%MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 11032
#include <stdio.h>
#define m 1000000007
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    unsigned long long a[200003]={},i,j,s=0;
    for(i=1;i<=n+1;i++) {
        a[i]=1+i*(n+1-i);
        a[i]=a[i]%m;
    }
    for(j=k;j<=n+1;j++) {
        s+=a[j];
    }
    printf("%llu\n",s%m);
    

    return 0;
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// http://drken1215.hatenablog.com/entry/2019/02/16/075900
using Edge = pair<int, long long>;
int N, M;
vector<vector<Edge>> G;

int main() {
    int N, M;
    cin >> N >> M;
    G.resize(N);
    REP(i, M) {
        int a, b;
        long long w;
        cin >> a >> b >> w;
        a--;
        b--;
        G[a].push_back(Edge(b, -w));
    }
    vector<long long> dist(N, INF);
    bool negative = false;
    dist[0] = 0;
    for(int iter = 0; iter <= N * 2; iter++) {
        for(int v = 0; v < N; v++) {
            // vertex
            if(dist[v] == INF) {
                continue;
            } //なんで
            for(auto e : G[v]) {
                if(chmin(dist[e.first], dist[v] + e.second)) {
                    if(e.first == N - 1 and iter == N * 2) {
                        negative = true; //壊れてる
                    }
                }
            }
        }
    }
    if(!negative) {
        cout << -dist[N - 1] << endl;
    } else {
        cout << "inf" << endl;
    }
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double p = 3.141592653589;
		double r = scan.nextDouble(); //????????§???????????\???
		double x = 2*r*p;
		double y = r*r*p;
		System.out.println(String.format("%.6f", y) + " " + String.format("%.6f", x));
	}
}

Measured memory_bytes: 28328
H, W = list(map(int, input().split()))
S = [list(input()) for _ in range(H)]
import queue
import copy
class gridMan:
  def __init__(s, L):
    s.L = L
  def makeWall(s, x):
    w = len(s.L[0]) + 2
    s.L = [[x] * w] + [[x] + i + [x] for i in s.L] + [[x] * w]
  def dist(s, S):
    T = copy.deepcopy(s.L)
    T[S[0] + 1][S[1] + 1] = 1
    q = queue.Queue()
    q.put([S[0] + 1, S[1] + 1])
    ans = 0
    while not q.empty():
      h, w = q.get()
      k = T[h][w]
      ans = max(ans, k)
      for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        hh = h + i
        ww = w + j
        if T[hh][ww] == -1:
          continue
        t = T[hh][ww]
        if t == 0:
          q.put([hh, ww])
          T[hh][ww] = k + 1
    return ans - 1

for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      S[i][j] = -1
    else:
      S[i][j] = 0

g = gridMan(S)
g.makeWall(-1)
ans = 0
for sx in range(H):
  for sy in range(W):
    if S[sx][sy] == -1:
      continue
    ans = max(ans, g.dist([sx, sy]))

print(ans)


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

long long x, y;
__int128_t X, Y;


int main() {
    cin >> x >> y;
    X = x; Y = y;
    int ans = 0;
    while(X <= Y) {
        X *= 2;
        ans++;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int[] input = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
		
		sc.close();
		
		Arrays.sort(input);
		
		StringJoiner sj = new StringJoiner(" ");
		for(int i : input) {
			sj.add(String.valueOf(i));
		}
		
		System.out.println(sj.toString());
		
	}

}

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

using namespace std;

#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const int inf = 1e9; 

const double PI =  3.14159265;

int main(){
	IO;
	int k, n, a, cnt = 0, maxi = 0, prev, a0;
	cin>>k>>n;
	cin>>a0;
	prev = a0;
	n--;
	while(n--){
		cin>>a;
		maxi = max(a-prev, maxi);
		cnt += a - prev;
		prev = a;
	}
	cnt += (k-a)+(a0);
	maxi = max((k-a)+(a0),maxi);
	cnt -= maxi;
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int mx = (n - 1) * (n - 2) / 2;
    if (mx < k)
    {
        cout << -1 << endl;
        return 0;
    }
    vector<pair<int, int>> ans;
    for (int i = 0; i < n - 1; i++)
    { //スターグラフを作る
        ans.push_back(make_pair(i + 1, n));
    }
    int add = mx - k;
    vector<pair<int, int>> edge;
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < i; j++)
        {
            edge.push_back(make_pair(i + 1, j + 1));
        }
    }
    for (int i = 0; i < add; i++)
    {
        ans.push_back(edge[i]);
    }
    cout << (int)ans.size() << endl;
    for (int i = 0; i < (int)ans.size(); i++)
    {
        cout << ans[i].first << ' ' << ans[i].second << endl;
    }
}

Measured memory_bytes: 384
/*
author : seryu
title : contest
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string s,t;
	cin >> s >> t;
	rep(i, sz(t))
	{
		if(s == t)
		{
			cout << "Yes" << endl;
			return;
		}
		t = t.substr(sz(t)-1,1) + t.substr(0,sz(t)-1);
	}
	cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &X[i]);
    Y[i] = X[i];
  }

  sort(Y.begin(), Y.end());
  for (int i = 0; i < N; ++i) {
    int mid = (X[i] <= Y[N / 2 - 1]) ? Y[N / 2] : Y[N / 2 - 1];
    printf("%d\n", mid);
  }
  return 0;
}


Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return x * modpow(x * x % mod, n / 2) % mod;
	return  modpow(x * x % mod, n / 2) % mod;
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
double w, h, x, y;
signed main() {
	cin >> w >> h >> x >> y;
	printf("%.12Lf", w * h / 2.0);
	if (w / 2.0 == x && h / 2.0 == y) {
		cout << " 1" << endl;
	}
	else {
		cout << " 0" << endl;
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;
class Union_Find{
  public:
  Union_Find(){};
  static const ll MAX_N = 100000*2+1;
  int par[MAX_N];
  int ranks[MAX_N];
  void init(int n){
    rep(i,MAX_N){
      par[i] = i;
      ranks[i] = 0;
    }
  }
  int find(int x){
    if(par[x] == x){
      return x;
    }
    else{
      return par[x] = find(par[x]);
    }
  }

  void Unite(int a, int b){
    a = find(a);
    b = find(b);
    if(a == b) return ;
    if(ranks[a] < ranks[b]){
      par[a] = b;
    }
    else{
      par[b] = a;
      if(ranks[a] == ranks[b]) ranks[a]++;
    }
  }
  bool same(int a,int b){
    return find(a) == find(b);
  }
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Union_Find u,u1;
  u.init(0);
  u1.init(0);
  ll n,k,l,a,b;
  cin >> n >> k >> l;
  rep(i,k){
    cin >> a >> b;
    u.Unite(a,b);
  }
  rep(i,l){
    cin >> a >> b;
    u1.Unite(a,b);
  }
  map<pll,ll> m;
  rep(i,n){
    m[make_pair(u.find(i+1),u1.find(i+1))]++;
  }
  rep(i,n){
    cout << m[make_pair(u.find(i+1),u1.find(i+1))] << endl;
  }
  return 0;
}



Measured memory_bytes: 15232
{-# LANGUAGE Strict #-}
import           Control.Monad (replicateM)
import           Data.Fixed
import           Data.List     (permutations)

main :: IO ()
main = do
  n <- readLn
  xys <- replicateM n readInt2
  print (realToFrac $ solve n xys :: Pico)

readInt2 :: IO (Int, Int)
readInt2 = (\[x, y] -> (x, y)) .  map read . words <$> getLine

solve :: Int -> [(Int, Int)] -> Double
solve n xys = s / fromIntegral m
  where s = sum [route xys' | xys' <- permutations xys]
        m = product [1 .. n]

route :: [(Int, Int)] -> Double
route xys = sum [distance xy1 xy2 | (xy1, xy2) <- zip xys $ tail xys]

distance :: (Int, Int) -> (Int, Int) -> Double
distance (x1, y1) (x2, y2) =
  sqrt . fromIntegral $ (x1 - x2) ^ (2 :: Int) + (y1 - y2) ^ (2 :: Int)


Measured memory_bytes: 6024
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

#define int ll
#define endl '\n'

map<int,int> mp1,cnt,cnt1;
// set<pii> mp2,mp3;
vector<int> a(200002),b(200002);

vector<int> vv;
int vvs;

int rand1() {
	int ans = rand();
	ans *= rand();
	// ans = abs(ans);
	ans %= vvs;
	return vv[ans];
}

int cnta[30][2];
int cntb[30][2];
int res[30][2];

signed main() {
	fast;

	int n;
	cin>>n;

	
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];

	if(n==1) {
		cout<<0<<" "<<(a[0]^b[0]);
		return 0;
	}

	for(int i=0;i<n;i++) {
		int temp = a[i];
		for(int j=29;j>=0;j--) {
			if((temp&(1LL<<j))>0) cnta[j][1]++;
			else cnta[j][0]++;
		}
		temp = b[i];
		for(int j=29;j>=0;j--) {
			if((temp&(1LL<<j))>0) cntb[j][1]++;
			else cntb[j][0]++;
		}
	}

	for(int i=29;i>=0;i--) {
		if(cnta[i][0]!=cntb[i][1]) res[i][1] = 1;
		if(cnta[i][0]!=cntb[i][0]) res[i][0] = 1;
	}

	for(int i=0;i<n;i++) {
		cnt[a[i]]++;
		mp1[a[i]]=i;
	}

	// for(auto x: cnt) {
	// 	mp2.insert({x.s,x.f});
	// }

	// for(auto x: cnt1) {
	// 	mp3.insert({x.s,x.f});
	// }

	for(auto x: mp1) {
		// int temp = cnt[a[x.s]];
		// int num = 1;
		// if(temp>1000) num = 1;
		// else if(temp>100) num = 3;
		// else if(temp>10) num = 6;
		// else if(temp>1) num = 20;

		// for(int i=0;i<num;i++) 
		vv.pb(x.s);
	}

	vvs = vv.size();

	

	//if same

	vector<int> k(n);
	for(int i=0;i<n;i++) {
		k[i] = a[i]^b[0];
		int f = 1;
		for(int j=29;j>=0;j--) {
			if((k[i]&(1ll<<j))>0) {
				if(res[j][1]) f = 0;
			}
			else {
				if(res[j][0]) f = 0;
			}
		}
		if(!f) k[i] = -1;
	}

	// for(auto x: k) cout<<x<<" ";cout<<endl;

	for(int i=0;i<n;i++) {
		if(k[i]==-1) continue;

		int f = 1;
		for(int iter = 0; iter<150;iter++) {
			int index = 0;
			while(index==0) index = rand1();
			if((b[index]^a[(index+i)%n])!=k[i]) {f=0;break;}
		}
		
		if(f) cout<<i<<" "<<k[i]<<endl;
	}

}

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

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

  double ans = 0;
  for(int i = 0; i < n; i++){
    double money;
    string current;
    cin >> money >> current;
    if(current == "JPY"){
      ans += money;
    }else{
      ans += money*380000.0;
    }
  }
 cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LLONG_MAX;
int dr[] = {1,0,-1,0};
int dc[] = {0,1,0,-1};
struct st{
    int r,c,len;
};
int bfs(int sr,int sc, const vector <vector <char>> &ar) {
    int h = ar.size(), w = ar[0].size();
    int ans = 0;
    vector <vector <int>> used(h,vector <int> (w));
    if(ar[sr][sc] == '#')
        return 0;
    used[sr][sc] = 1;
    queue<st> q;
    q.push({sr,sc,0});
    while(!q.empty()){
        st cur = q.front();
        q.pop();
        ans = max(ans,cur.len);
        for(int i = 0; i < 4; ++i){
            int nr = cur.r + dr[i];
            int nc = cur.c + dc[i];
            if(nr >= 0 && nr < h && nc >= 0 && nc < w && !used[nr][nc] && ar[nr][nc] == '.'){
                used[nr][nc] = 1;
                q.push({nr,nc,cur.len + 1});
            }
        }
    }
    return ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG
			assert(freopen("inp", "r", stdin));
			assert(freopen("out", "w",stdout));
	#else
			#define cerr if(false)cerr
	#endif
    int h,w;
    cin >> h >> w;
    vector <vector <char>> ar(h,vector <char> (w));
    for(auto &i : ar){
        for(auto &j : i)
            cin >> j;
    }
    int ans = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            ans = max(ans,bfs(i,j,ar)); 
        }
    }
    cout << ans << '\n';
    //for(auto &i : ar){
        //for(auto &j : i)
            //cout << j;
        //cout << '\n';
    //}
   cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC 
    << " sec" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  printf("%s\n",(a==5||a==7)&&(b==5||b==7)&&(c==5||c==7)&&a+b+c==17?"YES":"NO");
  return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, l;
	ll ans = 0;

	cin >> n >> l;

	REP(i, n) {
		ans += l + i;
	}

	if (l < 0) {
		if (l + n - 1 < 0) {
			ans -= l + n - 1;
		}
	}
	else {
		ans -= l;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// =======================
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long int
#define ull unsigned long long int 
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ss second
#define setbits(x) _builtin_popcount(x)
#define parity(x) _builtin_parity(x)
#define leadzero(x) __builtin_clz(x)
#define trailzero(x) __builtin_ctz(x)
#define endl "\n"
#define elif else if
// =======================
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
typedef map<int, int> mii;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
  uniform_int_distribution<int> uid(0,lim-1);
  return uid(rang);
}
int mpow(int base, int exp); 
void yes(){ cout << "YES\n"; }
void no(){  cout << "NO\n";  }

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
// =======================
vi a,dp;
int n,k;
void solve() {
  cin >> n >> k;
  a = vi(n+1);
  Fo(i,1,n+1) cin >> a[i];
  dp = vi(n+1,-1);
}

int cost(int i){
  if(i==1)  return 0;
  if(dp[i]!=-1)  return dp[i];
  dp[i] = INT_MAX;
  Fo(j,1,k+1){
    if(i-j>=1)  dp[i] = min( dp[i], cost(i-j)+abs(a[i]-a[i-j]));
  }
  return dp[i];
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
      cout << cost(n);
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}


Measured memory_bytes: 8776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W));
    vector<vector<int>> B(H, vector<int>(W));
    for (int i = 0; i < H; ++i)
        for (int j = 0; j < W; ++j)
            cin >> A[i][j];
    for (int i = 0; i < H; ++i)
        for (int j = 0; j < W; ++j)
            cin >> B[i][j];

    vector<bitset<25610>> bs(W + 1);
    bs[1][12800] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 1; j <= W; ++j) {
            int tmp = abs(A[i][j - 1] - B[i][j - 1]);
            bs[j] = (bs[j] << tmp) | (bs[j] >> tmp);
            bs[j] |= (bs[j - 1] << tmp) | (bs[j - 1] >> tmp);
        }
    }

    int ans = 1e9;
    for (int i = 0; i < 25610; ++i)
        if (bs[W][i])
            ans = min(ans, abs(i - 12800));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3732
N = int(input())
list_a = list(map(int, input().split()))

Alice_score = 0
Bob_score = 0

while len(list_a) > 0:
    Alice_score += list_a.pop(list_a.index(max(list_a)))
    if len(list_a) > 0:
        Bob_score += list_a.pop(list_a.index(max(list_a)))

print(Alice_score - Bob_score)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<pii> vpii;
typedef vector<vint> det1;
typedef vector<vpii> det2;

const int MAXN = 401;
char S[MAXN][MAXN];
int  G[MAXN][MAXN];

int W, H;

void dfs(int x, int y, ll* rx, ll* ry)
{
    if (G[y][x]) { return; }
    G[y][x] = 1;

    if (S[y][x] == '.') { (*rx) += 1; } else { (*ry) += 1; }

    if (x + 1 < W  && S[y][x] != S[y][x + 1]) { dfs(x + 1, y, rx, ry); }
    if (y + 1 < H  && S[y][x] != S[y + 1][x]) { dfs(x, y + 1, rx, ry); }
    if (x - 1 >= 0 && S[y][x] != S[y][x - 1]) { dfs(x - 1, y, rx, ry); }
    if (y - 1 >= 0 && S[y][x] != S[y - 1][x]) { dfs(x, y - 1, rx, ry); }
}

int main()
{
    cin >> H >> W;
    rep(i, H) { cin >> S[i]; }

    ll ans = 0;

    rep(y, H)
    rep(x, W)
    {
        ll rx = 0, ry = 0;

        dfs(x, y, &rx, &ry);
        ans += rx * ry;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e5+1e4;
int l[Maxn][31],ita[31];
int n,c,last;
int main()
{
	scanf("%d%d",&n,&c);
	for(register int i=1;i<=n;++i)
		{
			int sn,tn,cn;
			scanf("%d%d%d",&sn,&tn,&cn);
			last=max(tn,last);
			l[sn][cn]++;
			l[tn+1][cn]--;
		}
	int ans=0;
	for(register int i=1;i<=last;++i)
	{
		int now=0;;
		for(register int j=1;j<=c;++j)
		{
			ita[j]+=l[i][j];
			if(ita[j]) now++;
		}
		ans=max(now,ans);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 12544
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int n;
	cin >> n;
	n = sqrt(n);
	cout << n*n;
	return 0;
}

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

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

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

    vector<pii> bridge(M);
    rep(i, 0, M){
        int a, b;
        cin >> a >> b;
        bridge[i] = make_pair(a, -b);
    }

    sort(all(bridge));

    int l = 0, r = 10001;
    int ans = 1;
    rep(i, 0, M){
        int a = bridge[i].first;
        int b = -(bridge[i].second);
        if (r <= a){
            ans++;
            l = a;
            r = b;
        }
        else{
            l = max(l, a);
            r = min(r, b);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4056
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353

dp = [0 for _ in range(s+1)]
dp[0] = 1
for v in a:
    for i in reversed(range(s-v+1)):
        dp[i+v] += dp[i] * (MOD+1) // 2
        dp[i+v] %= MOD

print(dp[s] * pow(2, n, MOD) % MOD)

Measured memory_bytes: 68640
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
  	vector<int> data;
  	cin >> n;
  for(int i = 0; i < n; i++){
    int t;
    cin >> t;
    data.push_back(t);
  }
  int ans = 0;
  for(int i = 1; i < n - 1; i++){
    if((data[i-1] < data[i] && data[i] < data[i+1])
       || (data[i-1] > data[i] && data[i] > data[i+1])) ans++;
        
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  	int n,p,sum=0,mi=1e9;
  	scanf("%d" ,&n);
  	while(n--)
    {
      	scanf("%d" ,&p);
      	if(p<mi)
        {
          	mi=p;
          	sum++;
        }
    }
  	printf("%d" ,sum);
}

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

long long int a,b,k,c,d,l[1000010];
int main(){
    for (int i=1; i<=1000000; i++){
        for (int j=i; j<=1000000; j+=i){
            l[j]++;
        }
    }
    cin>>a;
    for (int i=a; i<=1000000; i++){
        if (l[i]==2){
            cout<<i<<endl;
            return 0;
        }
    }
}


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

using namespace std;

typedef long long ll;



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

    int N;
    cin >> N;

    int ans = 0;

    for (int i = 1; i <= 1000000; ++i) {
        for (int j = 1; i * j < 1000000; ++j) {
            if (i * j < N) {
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  if(s.at(0) == 'A'){
    int count = 0;
    int countC = 0;
    for(int i = 0; i < s.size(); i++){
      if('a' <= s.at(i)  && s.at(i) <= 'z') {count++;}
      if( 1  < i && i <( s.size() -1 ) && s.at(i) == 'C'){countC++;}
    }
//cout << countC <<" " << count ;
   if(countC == 1 && count == s.size() -2){cout << "AC" << endl; return 0;}
  }
  cout << "WA" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n;
  cin >> n;
  V a(n);
  VIN(n,a);
  double t;
  t = 0.0;
  REP(i,n){
    t += 1.0000 / a.at(i);
  }
  cout << 1.0000000 / t << endl;
  return 0;
}



Measured memory_bytes: 256
import sys
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque 

input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def _dbg(o):
    print(o, file=sys.stderr)

# ---------------------------------------

N = inp()
h = inpl()

INF = 1001001001

dp = [0] * (N)
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])


Measured memory_bytes: 20704
#include <iostream>
#include <vector>
#include <set>
#include <map>
// #include <cmath>
// #include <algorithm>
// #include <numeric>
// #include <string>
// #include <queue>
// #include <iomanip>
// #include <list>
// #include <cassert>

// #define MOD 1000000007
// #define INF 1000000001

using namespace std;
// typedef unsigned long long ull;
// typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}

int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    int k = 1;
    while (k * 2 <= N) {
        k *= 2;
    }
    cout << k << endl;
    return 0;
}


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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

ll dp[85], a[85];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  dp[1] = 1000;

  int n; read(n);
  rep(i, 1, n + 1) read(a[i]);
  rep(i, 2, n + 1) {
    dp[i] = dp[i - 1];
    rep(j, 1, i) {
      chmax(dp[i],
          dp[j] % a[j] + (dp[j] / a[j] * a[i]));
    }
  }
  die(dp[n]);
}


Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

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

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

bool check (int n) {
	int ans = 0;
	while(n) {
		++ans;
		n /= 10;
	}
	return ans & 1;
}

int main () {
    to_pray();

    int n;
    cin >> n;
    
    int cnt = 0;
    
    for (int i = 1; i <= n; ++ i)
    	cnt += check(i);
    	
    cout << cnt;
    cout << '\n';
    return 0;
}

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}

#define pii pair<int,int>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i);
#define int long long int
#define all(n) n.begin(),n.end()
#define mem(n,i) memset(n,i,sizeof n);
//vector<vector<int>>arr(n + 5, vector<int>(m + 5,0));

signed main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int x, n; cin >> x >> n;
	vector<int>vv(n);
	for (int &it : vv)
		cin >> it;
	sort(all(vv));
	int d = x;
	int dd = x;
	int i = 0;
	if (!binary_search(all(vv), x))
	{
		cout << x;
		return 0;
	}
	while (1)
	{
		if (i & 1 ^ 1)
		{
			d--;
			if (!binary_search(all(vv), d))
			{
				cout << d;
				return 0;
			}

		}
		else
		{
			dd++;
			if (!binary_search(all(vv), dd))
			{
				cout << dd;
				return 0;
			}
		}
		i++;
	}
}

Measured memory_bytes: 3620
module Main where

import Control.Applicative
import Text.Printf

main :: IO ()
main = loop

loop :: IO ()
loop = do
  { [x,y] <- getInts
  ; if x == 0 && y == 0 then return ()
    else do
      { putInts (if x > y then [y, x] else [x, y])
      ; loop
      }
  }

--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show



Measured memory_bytes: 4100
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    S = [list(input().strip()) for _ in range(H)]

    ans = 0
    f = False
    if S[0][0] == '#':
        ans += 1
        f = True

    q = collections.deque()
    q.append([[0, 0], 0, f])

    d = [[10 ** 9] * W for j in range(H)]

    while q:
        c = q.pop()
        dist = c[1]
        fl = c[2]

        j = c[0][0]
        i = c[0][1]

        if d[j][i] <= dist:
            continue
        else:
            d[j][i] = dist

        if i != W - 1:
            if S[j][i + 1] == '#':
                if fl:
                    q.append([[j, i + 1], dist, True])
                else:
                    q.append([[j, i + 1], dist + 1, True])
            else:
                q.append([[j, i + 1], dist, False])

        if j != H - 1:
            if S[j + 1][i] == '#':
                if fl:
                    q.append([[j + 1, i], dist, True])
                else:
                    q.append([[j + 1, i], dist + 1, True])
            else:
                q.append([[j + 1, i], dist, False])

    ans += d[H - 1][W - 1]

    print(ans)

if __name__ == '__main__':
        main()


Measured memory_bytes: 3528
import java.util.Scanner;

public class Main {

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

		while (true) {
			String str = scan.nextLine();
			
			if(str.equals("0")) {
				break;
			}
			
			int sum = 0;
			for(char c : str.toCharArray()) {
				sum += c - 48;
			}
			
			System.out.println(sum);
		}
		
		scan.close();
	}
}



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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int ans = 0;

bool check(int x) {
  bool c3, c5, c7;
  c3 = c5 = c7 = false;
  while (x) {
    int tmp = x % 10;
    if (tmp == 3) c3 = true;
    else if (tmp == 5) c5 = true;
    else if (tmp == 7) c7 = true;
    else return false;
    x /= 10;
  }

  return c3 && c5 && c7;
}

int main() {
  cin >> N;

  int x = 357;
  while (x <= N) {
    ans += check(x);
    
    if (x % 10 == 3 || x % 10 == 5) x += 2;
    else if (x % 10 == 7) x += 16;
    else if (100 / 10 == 7) x += 156;
    else if (x % 1000 / 100 == 7) x += 1556;
    else if (x % 10000 / 1000 == 7) x += 15556;
    else if (x % 100000 / 10000 == 7) x += 155556;
    else if (x % 1000000 / 100000 == 7) x += 1555556;
    else if (x % 10000000 / 1000000 == 7) x += 15555556;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector <int>;
using vll = vector <ll>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

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

    int n; cin >> n;
    vi a;
    REP(i, n) {
        int tmp; cin >> tmp;
        a.push_back(tmp);
    }

    vi b;
    REP(i, n) {
        int tmp; cin >> tmp;
        b.push_back(tmp);
    }
    sort(b.begin(), b.end());

    vi c;
    REP(i, n) {
        int tmp; cin >> tmp;
        c.push_back(tmp);
    }
    sort(c.begin(), c.end());

    vll bc;
    REP(i, n) {
        auto iter = upper_bound(c.begin(), c.end(), b[i]);
        int idx = distance(iter, c.end());
        bc.push_back(idx);
    }

    for (int i = n-2; i >= 0; i--) {
        bc[i] += bc[i+1];
    }

    ll cnt = 0;
    REP(i, n) {
        auto iter = upper_bound(b.begin(), b.end(), a[i]);
        int idx = distance(b.begin(), iter);
        cnt += bc[idx];
    }

    cout << cnt << "\n";
}


Measured memory_bytes: 5428
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

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


int main()
{

    int n; cin>>n;
    ll sum = 0 ;
    for(int i = 1 ; i<=n ; i++){

        if(i%3 !=0 && i%5!=0)sum+=i;
    }

    cout << sum << endl;

    return 0;
}


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

int main() {
  vector<int> n(4);
  cin >> n[0] >> n[1] >> n[2] >> n[3];
  sort(n.begin(), n.end());
  if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        var v = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );
        int n = v[0], l = v[1];
        string[] str = new string[n];
        for(int i = 0 ; i < n ; i++)
            str[i] = Console.ReadLine();

        //--------------------------------solve--------------------------------//

        Array.Sort( str );
        foreach(string s in str)
            Console.Write( s );

    }




}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if((a==b && a!=c)||(a==c && a!=b)||(c==b && c!=a)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main(){
  int a,b;
  cin>>a>>b;

  cout<<a/b<<endl;

  cout<<a%b<<endl;

  double l= (double)a/b;//int main(){
    cout << fixed << setprecision(5);
  

  cout<<l<<endl;

 
}


Measured memory_bytes: 3248
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

void caesar_decipher(string &s, int d) {
    d %= 26;
    for (char &c: s)
        if (c >= 'a' && c <= 'z') {
            c += d;
            if (c < 'a') {
                c += 26;
            } else if (c > 'z') {
                c -= 26;
            }
        }
}

bool testcase_ends() {
    char buf[128];
    if (fgets(buf, 128, stdin) == NULL)
        return 1;

    string s(buf);

    string keywords[]={"the", "this", "that"};
    auto is_valid=[&](string &s)->bool {
        for (string &kw: keywords)
            if (s.find(kw) != string::npos)
                return true;

        return false;
    };

    for (int i=0; i<26; ++i) {
        if (is_valid(s)) break;

        caesar_decipher(s, 1);
    }

    printf("%s", s.c_str());
    return 0;
}

int main() {
    int solved=0;
    while (!testcase_ends())
        ++solved;

    return !solved;
}

Measured memory_bytes: 2716
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	ll n, s; cin >> n >> s;
	for(ll b = 2; b * b <= n; b++){
		ll sum = 0, m = n;
		for(; m; m /= b) sum += m % b;
		if(sum == s){
			cout << b << endl;
			return 0;
		}
	}
	
	ll ans = (s == n ? s + 1 : 1e18);
	
	for(ll c = 1; c <= s && c * c <= n; c++) if((n - s) % c == 0){
		ll b = (n - s) / c + 1;
		ll a = n - b * c;
		if(0 <= a && a < b && c < b) ans = min(ans, b);
	}
	cout << (ans >= 1e18 ? -1 : ans) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
string b;
  cin >> b;
  if("A"== b){
    cout <<"T" << endl;
  }else if("C"==b){
    cout << "G"<<endl;
  }else if("G"==b){
    cout << "C"<<endl;
  }else if("T"==b){
    cout << "A"<<endl;
  }else{
    //do nothing
  }
  
return 0;
}


Measured memory_bytes: 256