akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var abn = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
            long a = abn[0];
            long b = abn[1];
            long n = abn[2];
            long x = Math.Min(n, b - 1);
            

            long max = Convert.ToInt64(Math.Floor((double)a * x / b)
                    - a * Math.Floor((double)x / b));

         

            Console.WriteLine(max);
        }
    }
}


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

#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

struct Distance {
    ll from, to, length;
};

class MinDistance {
    vector<P> points;

public:
    MinDistance(int n) {
        points.resize(n);
    }

    void set(int i, ll position) {
        points[i] = {position, i};
    }

    void order() {
        sort(points.begin(), points.end());
    }

    Distance getDistanceRight(int i) {
        ll length = points[i + 1].first - points[i].first;
        ll from = points[i].second;
        ll to = points[i + 1].second;
        return Distance{from, to, length};
    }


};


class UnionFind {
public:
    // 親の番号を格納する。親だった場合-size
    vector<int> parents;

    UnionFind(int n) {
        parents = vector<int>(n, -1);
    }

    // aがどのグループに属しているか
    int root(int a) {
        if (parents[a] < 0) {
            return a;
        }
        return parents[a] = root(parents[a]);
    }

    int size(int a) {
        return -parents[root(a)];
    }

    // aとbをくっつける
    bool connect(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb) {
            return false;
        }
        // 大きいほうにA
        if (size(ra) < size(rb)) {
            swap(ra, rb);
        }
        parents[ra] += parents[rb];
        parents[rb] = ra;
        return true;
    }

};


int main() {

    int n;
    cin >> n;
    MinDistance xMin(n);
    MinDistance yMin(n);

    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        xMin.set(i, x);
        yMin.set(i, y);
    }
    xMin.order();
    yMin.order();

    vector<Distance> roads;

    for (int i = 0; i < n - 1; i++) {
        roads.push_back(xMin.getDistanceRight(i));
        roads.push_back(yMin.getDistanceRight(i));
    }

    sort(roads.begin(), roads.end(), [](Distance &d, Distance e) {
        return d.length < e.length;
    });

    UnionFind uf(n);
    ll ans = 0;
    for (Distance &r : roads) {
        if (uf.root(r.from) == uf.root(r.to)) continue;
        uf.connect(r.from, r.to);
        ans += r.length;
    }

    cout << ans << endl;
}

Measured memory_bytes: 11632
#include <stdio.h>
int main(void){
    int n,m,sum=0,i,x;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d",&x);
        sum+=x;
    }
    if(n>=sum) printf("%d",n-sum);
    else printf("-1");
    return 0;
}

Measured memory_bytes: 1728
import itertools
import math

n = int(input())

allList = []

for i in range(n):
    a, b=(int(x) for x in input().split())
    allList.append([a, b])

long = 0
for i in itertools.permutations(allList):
    old = []
    for j in i:
        if (old == []):
            old = j
        else:
            long = long + pow(pow((old[0] - j[0]), 2) +pow((old[1] - j[1]), 2), 0.5)
            old = j

print(long / math.factorial(n))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 1005;
 
template <typename T> inline void read(T &a)
{
    T x=0, flag=1;
    char ch = getchar();
    while(!isdigit(ch)){
        if(ch == '-') flag = -1;
        ch = getchar();
    }
    while(isdigit(ch)){
        x = (x<<1) + (x<<3) + ch - '0';
        ch = getchar();
    }
    a = flag * x;
}

int n, d1, d2;
bool vis[MAXN][MAXN];

void build(int d)
{
	int t = 0;
	while(d % 4 == 0){
		d /= 4;
		++t;
	}
	if(d%4 == 1){
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				if(((i>>t) + (j>>t)) & 1) vis[i][j] = 1;
			}
		}
	}else{
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				if((i>>t) & 1) vis[i][j] = 1;
			}
		}
	}
}

void solve()
{
	read(n); read(d1); read(d2);
	int cnt = n * n, out = 0;
	n <<= 1;
	build(d1); build(d2);
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			if(!vis[i][j]){
				printf("%d %d\n", i, j);
				if(++out == cnt) return;
			}
		}
	}
}

int main()
{
	solve();
	return 0;
}


Measured memory_bytes: 1536
/**
 *    author:  Atreus
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;
int a[maxn], b[maxn], c[maxn], dp1[maxn], dp2[maxn], dp3[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i] >> c[i];
	for (int i = 1; i <= n; i++){
		dp1[i] = max(dp2[i - 1], dp3[i - 1]) + a[i];
		dp2[i] = max(dp1[i - 1], dp3[i - 1]) + b[i];
		dp3[i] = max(dp1[i - 1], dp2[i - 1]) + c[i];
	}
	cout << max(dp1[n], max(dp2[n], dp3[n])) << '\n';
}


Measured memory_bytes: 2560
'use strict'

function main(input) {
  input = input.slice('')
  let prev
  for (let i = 0; i < input.length; i++) {
    if (input[i] === prev) {
      console.log('Bad')
      return false
    } else {
      prev = input[i]
    }
  }
  console.log('Good')
  return false
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 22844
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << 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; }

void solve() {
	int r; cin >> r;
    if(r < 1200) cout << "ABC\n";
    else if(r < 2800) cout << "ARC\n";
    else cout << "AGC\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    cin >> N;
    bool isPrime[55556*5];
    for(int i=1;i<=55555*5;i++){
        isPrime[i] = true;
    }
    isPrime[1] = false;
    for(int i=2;i<=55555*5;i++){
        if(isPrime[i]){
            for(int j=2;j*i<=55555*5;j++) isPrime[i*j] = false;
        }
    }
    set<int> prime;
    for(int i=1;i<=55555*5;i++){
        if(isPrime[i]) prime.insert(i);
    }

    while(1){
        vector<int> ans;
        unordered_set<int> sum[5];
        unsigned int seed = clock();

        for(auto it=prime.begin();;it++){
            int p=*it;
            if(p!=2 && rand_r(&seed)>RAND_MAX/2) continue;
            if(p>55555) break;
            for(int x:sum[4]){
                if(isPrime[x+p]) goto next;
            }
            ans.push_back(p);
            for(int x:sum[3]) sum[4].insert(x+p);
            for(int x:sum[2]) sum[3].insert(x+p);
            for(int x:sum[1]) sum[2].insert(x+p);
            sum[1].insert(p);
            if(ans.size()>=N){
                for(int i=0;i<N;i++){
                    cout << ans[i] << " \n"[i==N-1];
                }
                return 0;
            }
    next:   ;
        }
    }
}


Measured memory_bytes: 1792
// AtCoder Beginner Contest 096 - Problem C: Grid Repainting 2 (https://atcoder.jp/contests/abc096/tasks/abc096_c) 
#include <bits/stdc++.h>

using namespace std;
using ii = pair<int, int>;

const vector<ii> dirs { ii(-1, 0), ii(1, 0), ii(0, -1), ii(0, 1) };

string solve(int H, int W, const vector<string>& M)
{
    for (int x = 0; x < H; ++x)
    {
        for (int y = 0; y < W; ++y)
        {
            if (M[x][y] == '.')
                continue;

            bool ok = false;

            for (auto d : dirs)
            {
                auto dx = d.first;
                auto dy = d.second;

                if (x + dx < 0 or x + dx >= H or y + dy < 0 or y + dy >= W)
                    continue;

                if (M[x + dx][y + dy] == '#') 
                {
                    ok = true;
                    break;
                }
            }

            if (not ok)
                return "No";
        }
    }

    return "Yes";
}

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

    int H, W;
    cin >> H >> W;

    vector<string> M(H);

    for (int i = 0; i < H; ++i)
        cin >> M[i];

    auto ans = solve(H, W, M);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int main(){
    ll n,A,B;
    scanf("%lld%lld%lld",&n,&A,&B);
    if(A>B||(n==1&&A!=B)){
        puts("0");
        return 0;
    }
    ll ans=max(0ll,B*(n-1)+A-(A*(n-1)+B)+1);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll a, b, c, d;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    printf("%lld\n", max(a*b, c*d));
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int yyyy, mm, dd;
  char aa,vv;
  cin >> yyyy >> aa>> mm >> vv>> dd;
  if(yyyy<2019||(yyyy==2019&&mm<=4))
    cout << "Heisei";
  else
    cout << "TBD";
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
	int n,k,i,max=0;
	cin >> n >> k;
	vector <int> l(n);
	for (i=0; i<n; i++){
		cin >> l[i];
	}
	sort(l.rbegin(), l.rend());
	for (i=0; i<k; i++){
		max += l[i];
	}
	cout << max << endl;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    ll X,Y; cin >> X >> Y;
    if(abs(X-Y) <= 1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1000 + 5;
const double pi =  acosl(-1);
const long long inf = 1e18 + 5;
using namespace std;
template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T> void print_container(T &container) { for (auto &t : container) { cout << t << " ";} cout << endl;}
template<class T> void printArr(T &a , int n) { for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << endl;}
typedef long long ll;
typedef pair<int, int> pii;

const int NN = 1e3 + 10;

int n, m, a, b, c, d;
int grid[NN][NN];
bool visited[NN][NN];

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

bool isValid(int x, int y ) {
	return x >= 0 && x < n && y >= 0 && y < m;
}



void solve() {

	clr(visited);

	cin >> n >> m >> a >> b >> c >> d;

	a--, b--, c--, d--;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char cc;
			cin >> cc;
			grid[i][j] = (cc == '.');
		}
	}

	// 0 - 1 bfs
	deque<pair<pii, int> > q;

	q.pb({{a, b}, 0});

	while (!q.empty()) {
		auto x = q.front();
		q.pop_front();
		pii kv = x.first;

		if (!isValid(kv.first, kv.second)) {
			continue;
		}

		if (kv.first == c && kv.second == d) {
			cout << x.second << endl;
			return;
		}

		if (visited[kv.first][kv.second]) {
			continue;
		} else {
			visited[kv.first][kv.second] = 1;

			for (int i = 0; i < 4; i++) {
				int nx = kv.first + dx[i];
				int ny = kv.second + dy[i];
				if ( isValid(nx, ny) && !visited[nx][ny] && grid[nx][ny]) {
					q.push_front({{nx, ny}, x.second});
				}
			}

			for (int i = -2; i <= 2; i++) {
				for (int j = -2; j <= 2; j++) {
					int nx = kv.first + i;
					int ny = kv.second + j;

					if ( isValid(nx, ny) && !visited[nx][ny] && grid[nx][ny]) {
						q.push_back({{nx, ny}, x.second + 1});
					}
				}
			}

		}

	}

	cout << -1 << endl;


}

int32_t main() {
	IOS;

	solve();

	return 0;
}




Measured memory_bytes: 13912
#include<bits/stdc++.h>
using namespace std;
int exp(int, int);
int main() {
  int a, b;
  cin >> a >> b;

  int ans;
  if (a > b) {
    ans = exp(a, b);
  } else {
    ans = exp(b, a);
  }
  cout << ans << endl;
}

int exp(int max_num, int min_num) {
  int ans = 0;
  for (int i = 0; i < max_num; i++) {
    int ex = min_num;
    for (int j = i + 1; j < max_num; j++) {
      ex *= 10;
    }
    ans += ex;
  }
  return ans;
}

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

void printArray(int A[], int N){
    for(int i=0; i<N; i++){
        cout << A[i];
        if ( i < N-1 ) cout << " ";
        else cout << "\n";
    }
}

int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = true;
    
    for(int i=0; flag; i++){
        flag = false;
        for(int j=N-1; j>=i+1; j--){
            if(A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                flag = true;
                sw++;
            }
        }
    }
    
    return sw;
}

int main(void){
    // Here your code !
    int N;
    int A[100];
    
    cin >> N;
    
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    int sw;
    
    sw = bubbleSort(A, N);
    printArray(A,N);
    cout << sw << endl;
        
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int func1(int s){
    return s%2==0 ? s/2: s*3+1;
}

int main() {
    int s; cin >> s;
    vector<int> v(100000);
    v[s-1]++;
    rep(i,100000){
        s = func1(s);
        v[s-1]++;
        if (v[s-1]>1){
            cout << i+2 << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 640
# O(k + log(n))

n, k = map(int,input().split())
D = list(input().split())

E = [0] * 20
for i in D:
    j = int(i)
    E[j] = 1
    E[10 + j] = 1

# print(E)

F = [0] * 10
r = 0
for l in range(10):
    # print(l, r)
    while l > r or E[r] == 1:
        r += 1
    F[l] = r-l

# print(F)

for i in range(10):
    if F[i] == 0:
        min_ok = i
        break

# print(min_ok, "min")

ke2 = 0
i = 0
sn = str(n)
while i < len(sn):
    l = len(sn)
    #print(i)
    d = l-1-i
    # print(d)
    if F[int(sn[d])] != 0:
        n += int(str(F[int(sn[d])]) + "0" * i)
        # print("+",n)
        for j in range(ke2, i):
            d2 = l-1-j
            n -= int(str(int(sn[d2]) - min_ok) + "0" * j)
            # print(d2,sn[d2], E[int(sn[d2])])
            # print("-", int(str(int(sn[d2]) - min_ok) + "0" * j))
    sn = str(n)
    i += 1
    # print(n)

print(n)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
 using namespace std;
 int main()
 {
 	int a,b;
 	cin>>a>>b;
 	
 	if(a*b%2==0)
 	 cout<<"Even"<<endl;
  else 
     cout<<"Odd"<<endl;
     
     return 0;
 }

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    var a = readLine()!!.split(" ").map{it.toInt()}.toIntArray()
    for(i in 1 until n){
        if(a[i] > a[i - 1]) a[i]--
    }
    var ok = true
    for(i in 1 until n){
        if(a[i] < a[i - 1]) ok = false
    }
    println(if(ok) "Yes" else "No")
}

Measured memory_bytes: 59284
/*************************************************************************
	> File Name: mid.cpp
	> Author: The-Out-Land
	> Mail: 2264454706@qq.com 
	> Created Time: 2019年10月22日 星期二 08时46分58秒
 ************************************************************************/

#include<bits/stdc++.h>

#define enter putchar('\n')
#define space putchar(' ')
#define M 4000100
#define N 2010

using namespace std;

int n,a[N];

bitset<M>ans;

bitset<M>reans;

inline int read(){
	int x=0;char c=getchar();bool y=1;
	for(;c<'0' || c>'9';c=getchar()) if(c=='-') y=0;
	for(;c>='0' && c<='9';c=getchar()) x=(x<<1)+(x<<3)+c-48;
	if(y) return x;
	return -x;
}

inline void Input(){
	n=read();
	for(int i=1;i<=n;i++)
	a[i]=read();
	return;
}

inline void solve(){
	int sum=0;
	ans=1;
	for(int i=1;i<=n;i++)
	{
		sum+=a[i];
		ans=(ans<<a[i])|ans;
		ans[a[i]]=1;
	}

	int judge=ans.count(),tot=0;


	for(int i=1;i<=sum;i++)
	{
		if(ans.test(i)) tot++;
		if(tot>=judge/2) {printf("%d\n",i);exit(0);}
	}
	return;
}

int main(){
	//freopen("mid.in","r",stdin);
	//freopen("mid.out","w",stdout);
	Input();
	solve();
	return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[111],b[111];

void mat(int n){
	int i,j,r=0;
	for(j=59; j>=0; --j){
		for(i=r; i<n; ++i){
			if(b[i]&(1ll<<j)){
				break;
			}
		}
		if(i==n){
			continue;
		}
		if(i>r){
			b[r] ^= b[i];
		}
		for(i=r+1; i<n; ++i){
			if(b[i]&(1ll<<j)){
				b[i] ^= b[r];
			}
		}
		++r;
	}
}

bool check(ll x, int n){
	int i;
	for(i=0; i<n; ++i){
		if((b[i]^x)<x){
			x ^= b[i];
		}
		// std::cout << b[i] << " " << x << std::endl;
	}
	return ((x)?false:true);
}

int main(void){
	int t,n,i,m;
	bool flag;
	std::string s;
	std::cin >> t;
	while(t--){
		std::cin >> n;
		m = 0;
		flag = true;
		for(i=0; i<n; ++i){
			std::cin >> a[i];
		}
		std::cin >> s;
		for(i=0; i<n; ++i){
			s[i] -= '0';
		}
		std::reverse(a,a+n);
		std::reverse(s.begin(),s.end());
		for(i=0; i<n; ++i){
			if(s[i]){
				if(!check(a[i],m)){
					std::cout << "1" << std::endl;
					flag = false;
					break;
				}
			}else{
				b[m] = a[i]; ++m;
				mat(m);
			}
		}
		if(flag){
			std::cout << "0" << std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main()
{
    int n;
    int a;
    //z:4で割り切れる    y:2で割り切れる　　　x:他
    int z=0,x=0,y=0;

    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(a%4==0)
        {
            z++;
        }
        else if(a%2==0)
        {
            y++;
        }
        else
        {
            x++;
        }
    }


    if((y==0&&x<=z+1)||(y!=0&&x<=z))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main() {

	string S;
	cin >> S;

	string result = "Good";
	for (int i = 1; i < S.length(); i++)
	{
		if (S[i - 1] == S[i])
		{
			result = "Bad";
			break;
		}
	}

	cout << result << endl;
	
	return 0;
}

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

int main(){
    int n, k, a, idx;
    int c = 0;
    int ans = 0;
    int counter = 0;
    cin >> n >> k;
    vector<int> balls(n+3, 200005);
    for(int i=0; i<n; i++){
        cin >> a;
        if(balls[a] == 200005){
            balls[a] = 1;
            c += 1;
        }
        else{
            balls[a] += 1;
        }
    }
    sort(balls.begin(), balls.end());
    while(c > k){
        ans += balls[counter];
        counter += 1;
        c -= 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")

#define NMAX 200010

int a[NMAX];
int imos[NMAX];

void reset(int n) {
    for(int i = 0; i < n; i++) imos[i] = 0;
}

int max(int a, int b) {
    if(a > b) return a;
    else return b;
}

int min(int a, int b) {
    if(a > b) return b;
    else return a;
}

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

    for(int itr = 0; itr < k; itr++) {
        int f = 0;
        reset(n+1);
        for(int i = 0; i < n; i++){
            if(a[i] != n) f = 1;
            imos[max(0, i - a[i])]++;
            imos[min(n, i + a[i] + 1)]--;
        }
        int acc = 0;
        for(int i = 0; i < n; i++){
            acc += imos[i];
            a[i] = acc;
        }
        if(!f) break;
    }

    for(int i = 0; i < n; i++) printf("%d\n", a[i]);
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
const int maxn = 100005;
string s[1005];
int dp[1005][1005];
int n, m;
void go() {
	cin >> n >> m;
	f(n) {
		cin >> s[i];
	}
	dp[0][0] = 1;
	for (int i = 1 ; i < n ; i++) {
		dp[i][0] = dp[i - 1][0] && (s[i][0] == '.');
	}
	for (int i = 1 ; i < m ; i++) {
		dp[0][i] = dp[0][i - 1] && (s[0][i] == '.');
	}
	f1(n - 1) {
		fr(j,1,m) {
			if (s[i][j] == '.')
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
		}
	}
	cout << dp[n - 1][m - 1] << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}

Measured memory_bytes: 8556
#include <algorithm>
#include <complex>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    bool b[26];
    for (int i = 0; i < 26; i++) {
        b[i] = false;
    }
    for (int i = 0; i < s.size(); i++) {
        b[s[i] - 'a'] = true;
    }
    for (int i = 0; i < 26; i++) {
        if (!b[i]) {
            cout << char(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
n = int(input())
t = 0
f = False
for i in range(n):
    a,b = map(int, input().split())
    if a == b:
        t += 1
    else:
        t = 0
    if t>= 3:
        f = True
        # break

if f:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 62252
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second


int main(int argc, char const *argv[]) {
  int n,m,max,min;
  ll ans = INF;
  int s[10], c[10];
  bool flag = false;

  std::string number;

  std::cin >> n >> m;
  REP(i, m) std::cin >> s[i] >> c[i];

  max = pow(10,n);
  if (n == 1) min = 0;
  else min = pow(10,n-1);
  FOR(i,min, max-1) {
    number = std::to_string(i);
    flag = true;
    REP(j, m) {
      if (int(number[s[j]-1]-'0') != c[j]) {
        flag=false;
      }
      //std::cout << flag << '\n';
    }
    if (flag) ans = std::min(ans,i);
  }
  if (ans == INF) std::cout << "-1" << '\n';
  else std::cout << ans << '\n';
  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

int n;
string tmp;

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}

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

  while(n--){
    int alpha, beta;
    vector<string> s;
    string ss;
    getline(cin, ss);
    s = split(ss, ' ');

    vrep(v, s) if((*v).size() == 4){
      bool ok = false;

      rep(a, 26) if(!ok) rep(b, 26){
        string word = *v;
        rep(i, 4){
          word[i] -= 'a';
          word[i] = (word[i] + 26 - b) % 26;
          word[i] = (word[i] * a) % 26;
          word[i] += 'a';
        }
        if(word == "this" || word == "that"){
          alpha = a;
          beta  = b;
          ok = true;
          break;
        }
      }
      if(ok) break;
    }

    vrep(v, s){
      tmp = *v;
      rep(i, tmp.size()){
        tmp[i] -= 'a';
        tmp[i] = (tmp[i] + 26 - beta) % 26;
        tmp[i] = (tmp[i] * alpha) % 26;
        tmp[i] += 'a';
      }
      //      cout << tmp << " ";
      cout << tmp << ((v+1)==s.end() ? "\n" : " ");
    }
    //    cout << "\b" << endl;
  }

  return 0;
}

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


using namespace std;


int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    
    int p1, p2, p3;
    
    p1 = max(X, Y) * 2 * C;
    
    p2 = X * A + Y * B;
    
    if(X >= Y){
        p3 = Y * 2 * C + (X - Y) * A;
    } else {
        p3 = X * 2 * C + (Y - X) * B;
    }
    
    cout << min(p1, min(p2, p3)) << endl;
}

Measured memory_bytes: 256
N=int(input())
S=list()
for i in range(N):
    S.append(input())
M=int(input())
T=list()
for i in range(M):
    T.append(input())
A=set(S)
ans=0
for i in A:
    s=0
    s=S.count(i)-T.count(i)
    if s>ans:
        ans=s
print(ans)

Measured memory_bytes: 38256
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ay = list(map(int,input().split()))
  ab.append(ay)
ans = []
for i in range(n):
  ans.append(0)
for i in range(m):
  for j in range(1,n+1):
    #print(i,j)
    if j in ab[i]:
      ans[j-1] += 1
for i in range(n):
  print(ans[i])

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

int main(){
	int a,b;
	cin >> a >> b;
	if(a <= 8 && b <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <climits>
#include <queue>
#include <stack>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

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

class LazySegmentTree
{
  private:
    int N = 1;
    vector<ll> node, lazy;

  public:
    LazySegmentTree(vector<ll> vec)
    {
        int size = (int)vec.size();

        while (N < size)
            N *= 2;

        node.resize(2 * N - 1);
        lazy.resize(2 * N - 1, 0);

        rep(i, size) node[i + N - 1] = vec[i];
        for (int i = N - 2; i >= 0; i--)
            node[i] = node[i * 2 + 1] + node[i * 2 + 2];
    }

    void evaluate(int i, int l, int r)
    {
        if(lazy[i] != 0)
            node[i] += lazy[i];
        
        if(r - l > 1)
        {
            lazy[2 * i + 1] += lazy[i] / 2;
            lazy[2 * i + 2] += lazy[i] / 2;
        }

        lazy[i] = 0;
    }

    void add(int a, int b, ll x, int i = 0, int l = 0, int r = -1)
    {
        if(r < 0) r = N;

        evaluate(i, l, r);

        if(b <= l || r <= a) return;

        if(a <= l && r <= b)
        {
            lazy[i] += (r - l) * x;
            evaluate(i, l, r);
        }
        else
        {
            add(a, b, x, 2 * i + 1, l, (l + r) / 2);
            add(a, b, x, 2 * i + 2, (l + r) / 2, r);
            node[i] = node[2 * i + 1] + node[2 * i + 2];
        }
    }

    ll getsum(int a, int b, int i = 0, int l = 0, int r = -1)
    {
        if(r < 0) r = N;

        evaluate(i, l, r);

        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[i];
        ll vl = getsum(a, b, 2 * i + 1, l, (l + r) / 2);
        ll vr = getsum(a, b, 2 * i + 2, (l + r) / 2, r);

        return vl + vr;
    }

};

int main()
{
    int N, Q;
    cin >> N >> Q;
    LazySegmentTree seg(vector<ll> (N, 0));
    rep(i, Q)
    {
        int query;
        cin >> query;
        
        if(query == 0)
        {
            int s, t, x;
            cin >> s >> t >> x;
            seg.add(s - 1, t, x);
        }
        else
        {
            int s, t;
            cin >> s >> t;
            cout << seg.getsum(s - 1, t) << endl;
        }
    }
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int A,B,Q;
vector<ll> S,T,X;

int main (void) {
    cin>>A>>B>>Q;
    S.pb(-INF);
    REP(i,A) {
        ll temp;
        cin>>temp;
        S.pb(temp);
    }
    S.pb(INF);
    A = S.size();
    T.pb(-INF);
    REP(i,B) {
        ll temp;
        cin>>temp;
        T.pb(temp);
    }
    T.pb(INF);
    B = T.size();
    REP(i,Q) {
        ll temp;
        cin>>temp;
        X.pb(temp);
    }

    REP(i,Q) {
        ll x = X[i];
        vector<ll> ss(2),tt(2);
        auto s_it = lower_bound(ALL(S),x);
        auto t_it = lower_bound(ALL(T),x);
        ss[0] = *s_it;
        ss[1] = *(s_it - 1);
        tt[0] = *t_it;
        tt[1] = *(t_it - 1);
        ll ans = INF;
        REP(j,2) REP(k,2) {
            ans = min(ans, abs(ss[j] - x) + abs(tt[k] - ss[j]));
        }
        REP(j,2) REP(k,2) {
            ans = min(ans, abs(tt[j] - x) + abs(ss[k] - tt[j]));
        }
        cout << ans << endl;
    }


    return 0;
}

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

using namespace std;
int n,m,k,sum = 0;
char a[10][10];
bool avail[10][10];
void reset(){
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) avail[i][j] = false;
}
int main(){
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++){
        string s;
        cin >> s;
        for (int j = 1; j <= m; j++){
            a[i][j] = s[j - 1];
            if (a[i][j] == '#') sum++;
        }
    }
    for (int i = 0; i <= n; i++) a[i][0] = '.';
    for (int j = 0; j <= m; j++) a[0][j] = '.';
    int ans = 0;
    for (int i = 0; i < (1LL << (n + 1)); i++)
        if ((i >> 0) & 1 == 1)
        for (int j = 0; j < (1LL << (m + 1)); j++)
            if ((j >> 0) & 1 == 1){
                reset();
                int cnt = 0;
                for (int mask = 0; mask <= n; mask++)
                    if ((i >> mask) & 1 == 1){
                    //cout << ((j >> mask) & 1);
                        for (int cj = 1; cj <= m; cj++)
                            if (avail[mask][cj] == false && a[mask][cj] == '#'){
                            avail[mask][cj] = true;
                            //cout << "(" << mask + 1<< ";" << cj << ")\n";
                            cnt++;
                            }
                    }
                    //cout << "\n";
                    for (int mask = 0; mask <= m; mask++)
                         if ((j >> mask) & 1 == 1){
                            //cout << ((j >> mask) & 1);
                            for (int ci = 1; ci <= n; ci++)
                                if (avail[ci][mask] == false && a[ci][mask] == '#'){
                                    avail[ci][mask] = true;
                                    //cout << "(" << ci << ";" << mask + 1<< ")\n";
                                    cnt++;
                                }
                         }
                    //cout << i << " " << j << " " << cnt << "\n";
                    if (sum - cnt == k){
                        ans++;
                        //cout << i << " " << j << "\n";
                    }
                }
    /*for (int i = 1; i <= (1 << (n + 1)); i++){
        for (int mask = 0; mask <= n; i++)
            cout << ((i >> mask) & 1);
            cout << "\n";
    }*/
    //for (int mask = (int)log2(100); mask >= 0; mask--) cout << ((100 >> mask) & 1);
    cout << ans;
}

Measured memory_bytes: 3644
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

class UnionFind
{
private:
  vector<int> par, sizes;

public:
  UnionFind(int n = 200010) : par(n), sizes(n, 1)
  {
    rep(i, n) par[i] = i;
  }

  int root(int x)
  {
    if (x == par[x])
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (sizes[x] < sizes[y])
      swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }

  bool same(int x, int y)
  {
    return root(x) == root(y);
  }

  int size(int x)
  {
    return sizes[root(x)];
  }
};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  struct query
  {
    int a, b;
  };

  ll n, m;
  cin >> n >> m;
  vector<query> q;
  UnionFind uf;
  rep(i, m)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    q.push_back({a, b});
  }
  reverse(all(q));
  vector<ll> ans;
  ll t = n * (n - 1) / 2;
  rep(i, m)
  {
    ans.push_back(t);
    int a = q[i].a, b = q[i].b;
    if (uf.same(a, b))
      continue;
    t -= (ll)uf.size(a) * (ll)uf.size(b);
    uf.unite(a, b);
  }
  reverse(all(ans));
  rep(i, m) cout << ans[i] << "\n";
  return 0;
}


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

int main(){
  string S ; 
  cin >> S ;
  int N ;
  N = S.size() ; 
  
  for(int i = 0 ; i< N/2 ; i++){
    if(S.at(i) == S.at(N-1-i) && S.at(i) == S.at(N/2-i-1)){
      continue ; 
    }
    else{
      cout << "No" << endl ; 
      return  0 ; 
    }
  }
  
  cout << "Yes" << endl ; 
}

Measured memory_bytes: 3604
package main

import (
    "bufio"
    "fmt"
    "os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var N int
	var S []string

	fmt.Scan(&N)
	for i := 0; i<N; i++ {
		if sc.Scan() {
			s := sc.Text()
			S = append(S, s)
		}
	}

	// fmt.Println(N)
	// for _, s := range(S){
	// 	fmt.Println(s)
	// }


	count := 0
	for b := 0 ; b< N; b++{
		ff := false
		for i:= 0; i<N ;i++{
			f := false
			for j := 0; j < N ; j++{
				if S[i][(j+b)%N] != S[j][(i+b)%N]{
					f = true
					break
				}
			}
			if f == true{
				ff = true
				break
			}
		}
		if !ff{
			count += N
		}
	}

	fmt.Println(count)
	// def slv(S):
    // count = 0
    // N = len(S)
    // # for a, b in itertools.product(range(len(S)), repeat=2):
    // for b in range(N):
    //     # print('-------------------', a, b)
    //     for i, j in itertools.combinations_with_replacement(range(len(S)), 2):
    //         # print(i, j)
    //         if S[i][(j + b) % N] != S[j][(i + b) % N]:
    //             break

    //     else:
    //         # print(a, b)
    //         count += N
    // # print(S)
    // return count

}


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

using namespace std;

int main(){
    int N,L; cin >> N >> L;
    int apple = 100;
    int ans = 0;
    for(int i=1; i<=N; ++i){
        if(abs(apple) > abs(L+i-1)) apple=(L+i-1);
    }
    for(int i=1; i<=N; ++i){
        ans += (L+i-1);
    }
    cout << ans - apple << endl;
}

Measured memory_bytes: 256
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    x = int(input())

    if (x == 1):
        print(0)
    else:
        print(1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9548
h,w=map(int,input().split())
dp=[[float("inf") for i in range(w+1)] for j in range(h+1)]
dp[0][1]=0
town=[["0"]*(w+1)]
for i in range(h):
    town.append(list("0"+input()))
for i in range(1,w+1):
    for j in range(1,h+1):
        dp[j][i]=min(dp[j-1][i],dp[j][i-1])+int(town[j][i])
print(dp[-1][-1])


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N;
  cin >> N;
  string S;
  map<string, int> m;
  rep(i, N) {
    cin >> S;
    m[S]++;
  }
  int temp = 0;
  for (auto ite = m.begin(); ite != m.end(); ite++) {
    temp = max(ite->_2, temp);
  }
  for (auto ite = m.begin(); ite != m.end(); ite++) {
    if (temp == ite->_2)
      cout << ite->_1 << endl;
  }
}


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

#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfl2(x, y) scanf("%I64d%I64d" , &x,&y)
#define sfl(x) scanf("%I64d" , &x)
#define sfl3(x, y, z) scanf("%I64d%I64d%I64d", &x, &y, &z)
#define sfd(x) scanf("%lf", &x)
#define sfd2(x, y) scanf("%lf", &x, &y)
#define sfs(x) scanf("%s", &x)
#define testv(x) cerr << x << ' '
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define test cerr << "here"
#define fst(x) cout << fixed << setprecision(x)
#define mod 1000000007
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;

int a[100005][30];

int main()
{
    ENGZ
    string s;
    cin >> s;
    pair<int, int> ans = {-1, -1};
    for (int i = 0; i < s.size() - 1 && ans.first == -1; i++)
    {
        if (s[i] == s[i + 1])
            ans = {i + 1, i + 2};
        else if (i < s.size() - 2 && s[i] == s[i + 2])
            ans = {i + 1, i + 3};
    }
    cout << ans.first << ' ' << ans.second;
    return 0;
}

Measured memory_bytes: 512
function Main(input) {
	const S = parseInt(input);
	const MOD = 1e9 + 7;
	var upr = 0, i = 1;
	do{
		if(S <= Math.pow(10, i - 1) * 9 * i)upr = i;
		i++;
	}while(!upr)
	
	i = Math.floor(S / upr);
	var ans = 0;
	var l = Math.pow(10, upr - 1), r = l + i - 1;
	var flr = i * f(l);
	do{
		if(S % i)ans++;
		else ans += powmod(10, S / i - 1, MOD) * 9 - i + 1;
	}while(--i)
	
	while(--l){
		flr += f(l);
		if(flr > S)flr -= f(r--);
		if(flr === S)ans++;
	}
	
	console.log((ans + MOD) % MOD);
}

function powmod(a, b, c){//a^b%c
	const N = 1e4;//オーバーフロー防止
	var rt = 1;
	while(b){
		if(b & 1) rt = (Math.floor(a / N) * rt % c * N + a % N * rt) % c;
		a = (Math.floor(a / N) * a % c * N + a % N * a) % c
		b >>>= 1;
	}
	return rt;
}

function f(n){
	if(n < 10)return 1;
	if(n < 100)return 2;
	if(n < 1000)return 3;
	if(n < 10000)return 4;
	if(n < 100000)return 5;
	if(n < 1000000)return 6;
	if(n < 10000000)return 7;
	return 8;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10060
#!/usr/bin/env python3

N, M = list(map(int, input().split()))
k = []
s = []
for i in range(M):
    l = list(map(int, input().split()))
    k.append(l[0])
    s.append(l[1:])
p = list(map(int, input().split()))

# print(f"N: {N}, M: {M}")
# print(f"k: {k}")
# print(f"s: {s}")
# print(f"p: {p}")

res = 0
for bit in range(2 ** N):
    # print(f"bit: {bin(bit)}")
    num_on = 0
    for i_light in range(M):
        # print(f"# check light {i_light} is on")
        count = 0
        for k_switch in range(k[i_light]):
            # s[i, k_i]番目のswitchがonかどうか
            if bit & (1 << s[i_light][k_switch]-1):
                # print(f"### switch {s[i_light][k_switch]} is on")
                count += 1
            # else:
                # print(f"### switch {s[i_light][k_switch]} is NOT on")
        # i番目のlightが点灯しているとき
        # print(f"# count % 2 == p[i]: {count%2} == {p[i_light]}")
        if count % 2 == p[i_light]:
            # print(f"## light {i_light} is on")
            num_on += 1
        # else:
            # print(f"## light {i_light} is NOT on")
    # M個のlight全てが点灯しているとき
    if num_on == M:
        # print(f"all light is on")
        res += 1

print(res)


Measured memory_bytes: 41328
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector <int> ans(n, -1);
    forn (i, 0, m) {
        int s, c;
        cin >> s >> c, --s;
        if (ans[s] != -1 && ans[s] != c)
            return cout << -1, 0;
        ans[s] = c;
    }
    if (n > 1 && ans[0] == 0)
        return cout << -1, 0;
    if (n > 1 && ans[0] == -1)
        ans[0] = 1;
    forn (i, 0, n) {
        if (ans[i] == -1)
            cout << "0";
        else
            cout << ans[i];
    }
    return 0;
}

Measured memory_bytes: 256
import itertools
import math

n = int(input())
l = list(map(int, input().split()))

maxi_idx = l.index(max(l))
sum = 0
for i in range(n):
    if i != maxi_idx:
        sum += l[i]

if sum > max(l):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String str;
		int[] alpha=new int[26];
		while(sc.hasNext()){
			str=sc.nextLine();
			for(int i=0;i<str.length();i++){
				int ind=Character.getNumericValue(str.charAt(i))-10;
				if(0<=ind&&ind<26){
					alpha[Character.getNumericValue(str.charAt(i))-10]++;
				}
			}
		}
		for(int i=0;i<26;i++){
			System.out.println((char)(i+97)+" : "+alpha[i]);
		}
	}
}


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

//#define endl printf("\n")

#define lp(i,m,n) for(int i=m;i<n;i++)

#define co(n) cout<<n<<endl;

using namespace std;

int main()
{

    int a,l,s=0,c=0,r=10000000;

    cin>>a>>l;

    lp(i,0,a)//{

     s=i+l+s;
    //}



    lp(i,0,a)
    {
           c=l+i;
           if(abs(r)>abs(c)) r=c;//finding min flav
    }

    co(s-r);//-ve the eatten apple's flv//no need to worry about 1 they will nulliyfy

    return 0;
}


Measured memory_bytes: 256