akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <array>
#include <vector>
#include <string>
using namespace std;

int main(){
	int h,w;
	cin >> h >> w;
	vector<string> s(h);
	vector<vector<int>> flag = vector<vector<int>>(h,vector<int>(w,0));

	for(auto& str : s){
		cin >> str;
	}

	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w;++j){
			if(s[i][j] == '#'){
				for(int x = i - 1; x <= i + 1; ++x){
					for(int y = j - 1; y <= j + 1; ++y){
						if(x >= 0 && x < h&&y >= 0 && y < w){
							++flag[x][y];
						}
					}
				}
			}
		}
	}

	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			if(s[i][j] == '#'){
				cout << '#';
			} else{
				cout << flag[i][j];
			}
		}
		cout << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
  // ios_base::sync_with_stdio(0); cin.tie(0);
  int a, b, x, y;
  scanf("%d%d%d%d", &a, &b, &x, &y);
  printf("%lf %d\n", double(a)*double(b) / 2, x + x == a&&y + y == b);
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long n;
long a[200005];

int main(){
    scanf("%ld", &n);
    std::map<long, long> mp;
    long ans = 0;
    for(int i = 1; i <= n; i++){
        scanf("%ld", a+i);
        ans += mp[-a[i] + i];
        mp[a[i] + i]++;
    }
    printf("%ld\n", ans);
}


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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    sort(v.begin(), v.end(), [](const int &a, const int &b){return a < b;});
    
    long ans = 0;
    for(int i = 0; i < n - k; i++) {
        ans += v[i];
    }
    
    cout << ans << endl;
    return 0;
}


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

int main () {
  int n, r;
  cin >> n >> r;
  if (n >= 10) cout << r << endl;
  else cout << r + 100 * (10 - n) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[2001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, K, Q, A[2001];
	scanf("%d %d %d", &N, &K, &Q);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	data d[2001];
	for (i = 0; i < N; i++) {
		d[i].key = A[i+1];
		d[i].id = i + 1;
	}
	merge_sort(d, N);
	d[N].key = 0;
	
	int j, k, l, r, X, Y, min = 1 << 30, count[2][2001], sum;
	for (i = 0; i < N; i++) {
		if (d[i+1].key == d[i].key) continue;
		Y = d[i].key;
		l = i;
		r = N;
		while (l < r) {
			X = d[(l+r)/2].key;
			for (j = 1, k = 0, count[0][0] = 0, count[1][0] = 0; j <= N; j++) {
				if (A[j] < Y) {
					count[0][++k] = 0;
					count[1][k] = 0;
				} else if (A[j] <= X) count[0][k]++;
				else count[1][k]++;
			}
			for (j = 0, sum = 0; j <= k; j++) {
				if (count[1][j] >= K - 1) sum += count[0][j];
				else if (count[0][j] + count[1][j] >= K) sum += count[0][j] + count[1][j] - K + 1;
			}
			if (sum >= Q) r = (l + r) / 2;
			else l = (l + r) / 2 + 1;
		}
		if (l == N) break;
		else if (d[l].key - Y < min) min = d[l].key - Y;
	}
	
	printf("%d\n", min);
	fflush(stdout);
	return 0;
}

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

template<class Cost = int>
struct Edge {
    int from, to;
    Cost cost;
    Edge(const int &from = -1, const int &to = -1, const Cost &cost = 1)
        : from(from), to(to), cost(cost) {}

    bool operator<(const Edge<Cost> &rhs) const { return this->cost < rhs.cost; }
    bool operator>(const Edge<Cost> &rhs) const { return this->cost > rhs.cost; }
};

template<class Cost = int>
struct Graph : vector<vector<Edge<Cost>>> {
    int n;
    Graph(int _n = 0) : n(_n) { this->resize(n); }

    void add_edge(const int &src, const int &dst, const Cost &cost = 1) {
        assert(0 <= src && src < n && 0 <= dst && dst < n);
        (*this)[src].emplace_back(src, dst, cost);
    }
    void add_biedge(const int &src, const int &dst, const Cost &cost = 1) {
        add_edge(src, dst, cost), add_edge(dst, src, cost);
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long N, M; cin >> N >> M;
    Graph<> G(N);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        G.add_biedge(--a, --b);
    }
    auto coloring = [&]() {
        vector<int> C(N, -1); C[0] = 0;
        bool ok = true;
        auto dfs = [&](auto &&self, int curr, int prev) -> void {
            for (auto &e: G[curr]) {
                if (e.to == prev) continue;
                if (C[e.to] == -1) {
                    C[e.to] = 1 - C[curr];
                    self(self, e.to, curr);
                } else {
                    if (C[e.to] != 1 - C[curr]) ok = false;
                }
            }
        };
        dfs(dfs, 0, -1);
        if (ok) {
            long long E[2] = {0, 0};
            for (int i = 0; i < N; i++) E[C[i]]++;
            cout << E[0] * E[1] - M << "\n";
        } else {
            cout << N * (N-1) / 2 - M << "\n";
        }
    };
    coloring();
    return 0;
}

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

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


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

// ---------------------------template starts here-------------------------- 

#define int long long int
#define pb push_back
#define MAX INT_MAX
#define F first
#define precise std::cout << std::fixed;std::cout << std::setprecision(6); 
#define S second  
#define mp make_pair
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

set <int> s;
bool ar[100001];
void seive() {
    ar[0] = ar[1] = true;

    for(int p=2; p*p<=100001; p++) {
        if(ar[p] == false) {
            for(int i=p*p;i<=100001;i+=p)
                ar[i] = true ;
        }
    }

    for(int p=2;p<=100001;p++) {
        if(ar[p] == false)
            s.insert(p);
    }
}

bool is_palindrome(string str) {
    int len = str.length();
    for(int i=0;i<=len/2;i++) {
        if(str[i] != str[len-1-i])
            return false;
    }
    return true;
}

int binexpo(int x, int y, int p) {    
    int res = 1;     // Initialize result  
    x = x % p; // Update x if it is more than or  
                // equal to p  

    while (y > 0)  {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;
}
// --------------------------template ends here------------------------------

void solve() {
    string str;
    cin >> str;

    int len = str.length();

    if(str[2] == str[3] && str[4] == str[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;    

    return;
}
int32_t main() {
    FO;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  char s[5];
  scanf("%s", s);

	int flag = 0;
  for (int i = 1; i < 4; i++) {
  	if (s[i] == s[i-1]) {
  		flag = 1;
			break;
  	}
  }

	if (flag == 1) {
		printf("Bad\n");
	} else {
		printf("Good\n");
	}

  return 0;
}

Measured memory_bytes: 128
import math
N = input()
N = int(N)
x = N // 3
x = int(x)
p = 10 ** 9 + 7
sum = 0
if x == 0:
  print(0)
else:
  for k in range(x):
    y =  N - 3*k - 3
    l = k 
    M = y + l
    a = math.factorial(l)
    b = math.factorial(M) 
    c = math.factorial(y)
    d = a * c
    z = b // d
    z = z % p
    sum += z
    sum = sum %p

  sum = int(sum)
  print(sum)

  

  

Measured memory_bytes: 9076
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int X, A;
    cin >> X >> A;
    cout << (X < A ? 0 : 10) << endl;
}


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

int N;
int M;
int cnt[114514];

int main() {
  scanf("%d%d", &N, &M);
  for (int i=0; i<M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    cnt[a]++;
    cnt[b]++;
  }

  for (int i=2; i<=N; i++) {
    if (cnt[i]%2) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin>>A>>B>>C;
  int count=0;
  int X;
  cin>>X;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(500*i+100*j+50*k==X){
          count++;
        }
      }
    }
  }
  cout<<count;
}

Measured memory_bytes: 3624
N = int(input())
txy = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)]
flag = True
for i in range(N):
    nt = txy[i+1][0]
    nx = txy[i+1][1]
    ny = txy[i+1][2]
    t = txy[i][0]
    x = txy[i][1]
    y = txy[i][2]
    move = nt - t
    tmp = abs(nx-x)+abs(ny-y)
    if move >= tmp:
        if abs(move-tmp) % 2 != 0:
            flag = False
            break
    else:
        flag = False
        break
print('Yes' if flag else 'No')


Measured memory_bytes: 28148
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var d = new int[m, 2];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            d[i, 0] = int.Parse(line[0]) - 1;
            d[i, 1] = int.Parse(line[1]);
        }
        getAns(n, m, d);
    }
    static void getAns(int n, int m, int[,] d)
    {
        int istart, iend;
        if (n == 1) { istart = 0; iend = 9; }
        else if (n == 2) { istart = 10; iend = 99; }
        else { istart = 100; iend = 999; }
        for (int i = istart; i <= iend ; i++)
        {
            var t = i.ToString();
            var ok = true;
            for (int j = 0; j < m; j++)
            {
                if (t[d[j, 0]] - '0' != d[j, 1]) ok = false;
            }
            if (ok) { Console.WriteLine(i); return; }
        }
        Console.WriteLine(-1);
    }
}


Measured memory_bytes: 13140
S = list(input())
def dfs(S, i, bind, ans): 
  if i == len(S):
    return ans + int(bind)
  return dfs(S, i + 1, S[i], int(bind) + ans) + dfs(S, i + 1, bind + S[i], ans)
print(dfs(S, 1, S[0], 0))

Measured memory_bytes: 3444
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
ll f[200001];

//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination


int main(){
    int n,m,k;
    f[0]=1;
    rep2(i,200000){
        f[i]=f[i-1]*i%mod;
    }
    cin >> n >> m >> k;
    ll c= comb(n*m-2,k-2)%mod;//２マスの組み合わせを固定した場合の残りの組み合わせ
    ll ans=0;
    rep(d,n){
        ll num=(n-d)*m*m%mod;//xの絶対値の差がdになるような２マスの選び方
        ans=(ans+d*num%mod)%mod;
    }
    rep(d,m){
        ll num=(m-d)*n*n%mod;
        ans=(ans+d*num%mod)%mod;//y同上
    }
    ans*=c;
    ans%=mod;
    cout<< ans<< endl;
    return 0;
}

Measured memory_bytes: 1792
//#include<iostream>
#include<cstring>
#include<cstdio>
//#include<time.h>
//#include<complex>
#include<algorithm>
#include<stdlib.h>
using namespace std;

int n,m;
#define maxn 5011
#define maxm 211
int a[maxm][maxn],p[maxm][maxn];
/* ji ru bian */ struct Edge{int to,next;}edge[maxn*maxm]; int first[maxm][maxn],le=2;
void in(int x,int y,int v) {Edge &e=edge[le]; e.to=v; e.next=first[x][y]; first[x][y]=le++;}
#define LL long long
LL f[maxn]; int dis[maxn];
int sta[maxn],top;

int qread()
{
	char c; int s=0; while ((c=getchar())<'0' || c>'9');
	do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s;
}

int main()
{
//	freopen("ditf.in","r",stdin);
//	freopen("ditf.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<n;i++) scanf("%d",&dis[i]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			a[j][i]=qread();
	
	for (int j=1;j<=m;j++)
	{
		top=0;
		for (int i=n;i;i--)
		{
			while (top && a[j][sta[top]]<=a[j][i]) top--;
			if (top) in(j,sta[top],i);
			p[j][i]=sta[top];
			sta[++top]=i;
		}
	}
	
//	for (int j=1;j<=m;j++,cout<<endl)
//		for (int i=1;i<=n;i++)
//			cout<<p[j][i]<<' ';cout<<endl;

//	for (int j=1;j<=m;j++)
//		for (int i=1;i<=n;i++)
//		{
//			cout<<j<<' '<<i<<"!!!"<<endl;
//			for (int k=first[j][i];k;k=edge[k].next)
//			{
//				Edge &e=edge[k]; cout<<e.to<<' ';
//			}cout<<endl;
//		}cout<<endl;
	
	for (int j=1;j<=m;j++) f[1]+=a[j][1];
	for (int j=1;j<=m;j++)
	{
		int now=a[j][1];
		for (int i=2;i<=n;i++) if (a[j][i]>now) f[i]+=a[j][i]-now,now=a[j][i];
	}
	
	LL Ans=0;
	for (int L=1;L<=n;L++)
	{
//		for (int i=L;i<=n;i++) cout<<f[i]<<' ';cout<<endl<<endl;
		LL ans=f[L]; Ans=max(Ans,ans);
		for (int R=L+1;R<=n;R++) ans-=dis[R-1],ans+=f[R],Ans=max(Ans,ans);
		
		for (int j=1;j<=m;j++)
		{
			int hh=p[j][L];
			for (int x=L+1,last=0;x!=hh;x=p[j][x])
				f[x]+=a[j][x]-last,last=a[j][x];
			if (hh)
			{
				f[hh]-=a[j][hh]-a[j][L];
				f[hh]+=a[j][hh]-a[j][edge[first[j][hh]=edge[first[j][hh]].next].to];
			}
		}
	}
	
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 20736
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vector<string> s(N);
        rep(i, 0, N) cin >> s[i];
        ll M;
        cin >> M;
        vector<string> t(M);
        rep(i, 0, M) cin >> t[i];

        set<string> st;
        map<string, ll> blue;
        map<string, ll> red;
        string r(300, 'x');

        rep(i, 0, N) {
                blue[s[i]]++;
                st.insert(s[i]);
        }
        rep(i, 0, M) {
                red[t[i]]++;
                st.insert(t[i]);
        }

        ll mx = -inf;

        for (auto x : st) {
                chmax(mx, blue[x] - red[x]);
        }
        chmax(mx, blue[r] - red[r]);

        cout << mx << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

int main(void){
	int N,M,a,days=0,i,ans;
	cin >> N >> M;
	myfor(i,M){
		cin >> a;
		days += a;
	}
	if(days > N)ans=-1;
	else ans = N - days; 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
char str[1000][20];
int c[1000];
int d[1000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%s%d%d",str[i],c+i,d+i);
		for(int i=0;i<b;i++){
			int e;
			scanf("%d",&e);
			bool ok=false;
			for(int j=0;j<a;j++){
				if(1+d[j]-c[j]<=e&&e<=d[j]){
					printf("%s %d\n",str[j],e-d[j]+c[j]);
					ok=true;
					break;
				}
			}
			if(!ok)printf("Unknown\n");
		}
	}
}

Measured memory_bytes: 1068
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
using ll=long long int;
using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;
using vvl=vector<ll>;
using vs=vector<string>;
constexpr int INF=1<<30;
constexpr ll INFL=1l<<60;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define RANGE(i,a,b) for(int i=(a);i<=(b);i++)
#define RANGER(i,a,b) for(int i=(b);i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

#define EVALe 1

#ifdef EVAL
#define LOG(i) 0
#else
#define LOG(i) cerr<<#i<<": "<<i<<endl
#endif

void solve(){
	int N,mn=INF,ans=0,P;
	cin>>N;
	REP(i,N){
		scanf("%d",&P);
		if(mn>=P)ans++;
		mn=min(mn,P);
	}
	cout<<ans<<endl;
}

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

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

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

    sort(a.begin(), a.end());
    
    int amari = a[0];
    while(1){
        bool isconst = true;
        for(int i = 0; i < n; i++){
            if(a[i] % amari != 0){
                amari = a[i] % amari;
                a[i] = amari;
                isconst = false;
            }
        }
        if(isconst) break;
    }
    cout << amari << endl;
}

Measured memory_bytes: 3764
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector< vector<int> > G(n, vector<int>());
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist(n, -1);
    dist[0] = 0;
    deque<int> q;
    q.push_back(0);
    vector<int> ans(n);
    ans[0] = 0;
    
    while(!q.empty()) {
        int curr = q.front();
        q.pop_front();
        for (int nxt : G[curr]) {
            if (dist[nxt] != -1) continue;
            q.push_back(nxt);
            dist[nxt] = dist[curr] + 1;
            ans[nxt] = curr;
        }
    }

    for (int i = 0; i < n; i++) {
        if (dist[i] != -1) continue;
        cout << "No" << endl;
        return 0;
    }

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


Measured memory_bytes: 10168
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let _ = lines.next();
    let a_line = lines.next().unwrap().unwrap();
    let splited = a_line.trim().split_whitespace();
    let mut ls: Vec<i32> = splited.map(|s| s.parse().unwrap()).collect();
    ls.sort();

    let mut ans = 0;
    for i in 0..ls.len() {
        for j in i + 1..ls.len() {
            let k = bin_search(&ls[j + 1..], ls[i] + ls[j]);
            ans += k;
        }
    }

    writeln!(&mut writer, "{}", ans).unwrap();
}

fn bin_search(ls: &[i32], n: i32) -> i32 {
    let mut low = -1;
    let mut top = ls.len() as i32;

    while top - low > 1 {
        let mid = (low + top) / 2;
        if ls[mid as usize] < n {
            low = mid;
        } else {
            top = mid;
        }
    }

    low + 1 as i32
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"4
3 4 2 1",
            br"1
",
        ),
        (
            br"3
1 1000 1",
            br"0
",
        ),
        (
            br"7
218 786 704 233 645 728 389",
            br"23
",
        ),
    ];

    #[test]
    fn test_d() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }

    #[test]
    fn test_bin_search() {
        assert_eq!(bin_search(&[10, 20, 20, 20, 30], 5), 0);
        assert_eq!(bin_search(&[10, 20, 20, 20, 30], 10), 0);
        assert_eq!(bin_search(&[10, 20, 20, 20, 30], 15), 1);
        assert_eq!(bin_search(&[10, 20, 20, 20, 30], 20), 1);
        assert_eq!(bin_search(&[10, 20, 20, 20, 30], 25), 4);
        assert_eq!(bin_search(&[10, 20, 20, 20, 30], 30), 4);
        assert_eq!(bin_search(&[10, 20, 20, 20, 30], 35), 5);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

#define SEGTREE_MAX 131072

typedef struct {
	int max_num;
	int push_num;
} segtree_t;

segtree_t segtree[SEGTREE_MAX*2-1];

void segtree_push(int youso) {
	if(youso*2+1<SEGTREE_MAX*2-1) {
		segtree[youso*2+1].push_num+=segtree[youso].push_num;
		segtree[youso*2+2].push_num+=segtree[youso].push_num;
	}
	segtree[youso].max_num+=segtree[youso].push_num;
	segtree[youso].push_num=0;
}

void segtree_add_internal(
		int youso,int add,int start,int end,int kstart,int kend) {
	segtree_push(youso);
	if(end<=kstart || kend<=start)return;
	if(start<=kstart && kend<=end) {
		segtree[youso].push_num+=add;
		segtree_push(youso);
	} else {
		segtree_add_internal(youso*2+1,add,start,end,
			kstart,kstart+(kend-kstart)/2);
		segtree_add_internal(youso*2+2,add,start,end,
			kstart+(kend-kstart)/2,kend);
		segtree[youso].max_num=segtree[youso*2+1].max_num;
		if(segtree[youso].max_num<segtree[youso*2+2].max_num) {
			segtree[youso].max_num=segtree[youso*2+2].max_num;
		}
	}
}

int segtree_getmax_internal(
		int youso,int start,int end,int kstart,int kend) {
	int r1,r2;
	segtree_push(youso);
	if(end<=kstart || kend<=start)return 0;
	if(start<=kstart && kend<=end) {
		return segtree[youso].max_num;
	} else {
		r1=segtree_getmax_internal(youso*2+1,start,end,
			kstart,kstart+(kend-kstart)/2);
		r2=segtree_getmax_internal(youso*2+2,start,end,
			kstart+(kend-kstart)/2,kend);
		if(r1>r2)return r1; else return r2;
	}
}

void segtree_init(void) {
	memset(segtree,0,sizeof(segtree));
}

void segtree_add(int start,int end,int add) {
	segtree_add_internal(0,add,start,end,0,SEGTREE_MAX);
}

int segtree_getmax(int start,int end) {
	return segtree_getmax_internal(0,start,end,0,SEGTREE_MAX);
}

int main(void) {
	int n,i;
	int h,m,s;
	int start,end;
	while(1) {
		scanf("%d",&n);
		if(n==0)break;
		segtree_init();
		for(i=0;i<n;i++) {
			scanf("%d:%d:%d",&h,&m,&s);
			start=h*60*60+m*60+s;
			scanf("%d:%d:%d",&h,&m,&s);
			end=h*60*60+m*60+s;
			segtree_add(start,end,1);
		}
		printf("%d\n",segtree_getmax(0,24*60*60));
	}
	return 0;
}

Measured memory_bytes: 2468
n = int(input())
lst = list(map(int, input().split()))
dp = [[0]*3 for i in range(n)]
dp[0] = lst
for i in range(1, n):
    lst = list(map(int, input().split()))
    dp[i] = [max(dp[i-1][1], dp[i-1][2])+lst[0], max(dp[i-1][0], dp[i-1][2])+lst[1], max(dp[i-1][0], dp[i-1][1])+lst[2]]
print(max(dp[-1]))

Measured memory_bytes: 22772
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int64_t a[n];
    for(int i=0;i<n;i++) cin >> a[i];

    int64_t sum=0;
    int64_t small=a[0];
    for(int i=1;i<n;i++){
        if(small>a[i]){
            sum += small -a[i]; 
        }else{
            small=a[i];
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 5128
#include <iostream>

using namespace std;
void Merge(int L[],int R[],int A[],int N);
void merge_sort(int A[],int N);

int main()
{
    int X,Y,A,B,C;
    int i,j=0;
    long MAX=0;
    cin >> X >> Y >> A >> B >> C;
    int red[A];
    int green[B];
    int coless[C];

    int largest[X+Y+C];
    for(i=0;i<A;i++) cin >> red[i];
    for(i=0;i<B;i++) cin >> green[i];
    for(i=0;i<C;i++) cin >> coless[i];

    merge_sort(red,A);
    merge_sort(green,B);
    merge_sort(coless,C);

    for(i=0;i<X;i++)
    {
        largest[j]=red[A-1];
        A--;
        j++;
    }

    for(i=0;i<Y;i++)
    {
        largest[j]=green[B-1];
        B--;
        j++;
    }

    for(i=0;i<C;i++)
    {
        largest[j]=coless[i];
        j++;
    }
    merge_sort(largest, j);

    for(i=0;i<X+Y;i++)
    {
        MAX+=largest[j-1];
        j--;
    }

    cout << MAX<<endl;

    return 0;
}

void merge_sort(int A[],int N)
{
    if(N==1) return;
    int I=N/2;
    int J=(N+1)/2;
    int L[I];
    int R[J];
    int i,j,k=0;

    for(i=0;i<I;i++)
    {
        L[i]=A[k];

        k++;
    }


    for(j=0;j<J;j++)
    {
        R[j]=A[k];

        k++;
    }

    merge_sort(L,sizeof(L)/4);
    merge_sort(R,sizeof(R)/4);
    Merge(L,R,A,N);
}

void Merge(int L[],int R[],int A[],int N)
{
    int Size=N;
    int i=0,j=0,k;
    for(k=0;k<Size;k++)
    {
        if(j==((Size+1)/2))
        {
            A[k]=L[i];
            i++;
            continue;
        }
        if(i==Size/2)
        {
            A[k]=R[j];
            j++;
            continue;
        }
        if(L[i]<=R[j])
        {
            A[k]=L[i];
            i++;
        }
        else
        {
            A[k]=R[j];
            j++;
        }

    }
}


Measured memory_bytes: 8052
x,y = map(lambda x:int(x),input().split(" "))
if y==0:
    print(x)
else:
    input_list = list(map(lambda x:int(x),input().split(" ")))
    for i in range(y+2):
        if x-i not in input_list:
            print(x-i)
            break
        elif x+i not in input_list:
            print(x+i)
            break
            

Measured memory_bytes: 9196
object Main extends App {
	val a = new Array[Int](5)
	val b = new Array[(Int, Int)](5)

	for(i<-0 until 5){
		a(i) = scala.io.StdIn.readInt

		if(a(i)%10 == 0) b(i) = (0, i)
		else b(i) = (10 - a(i)%10, i)
	}


	val c = b.sortBy(_._1)
	var ans = 0
	for(x<- c){
		ans += a(x._2) + x._1
	}

	println(ans - c(4)._1)

	

}

Measured memory_bytes: 27316
#include <iostream>


using namespace std;


int main()
{
   int a , b;
   cin >> a >> b;
   
   if (a == b)
       cout << "a == b" << endl; 
   else if (a > b)
       cout << "a > b" << endl;
   else 
       cout << "a < b" << endl;
   
   return 0;
}



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

struct unionfindtree {
    vector<int> parent;
    int group;
    unionfindtree(int size): parent(size+1), group(size) {
        iota(begin(parent), end(parent), 0);
    }
    int find(int n) {
        return parent[n] == n ? n : parent[n] = find(parent[n]);
    }
    void unite(int n, int m) {
        n = find(n);
        m = find(m);
        if (n != m) {
            group--;
            parent[n] = m;
        }
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ab(m);
    for (auto& e : ab) cin >> e.first >> e.second;
    
    int ans = 0;
    for (int i = 0; i < m; i++) {
        unionfindtree uft(n);
        for (int j = 0; j < m; j++) {
            if (j == i) continue;
            uft.unite(ab[j].first, ab[j].second);
        }
        if (uft.group != 1) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define print(i) std::cout << (i) << '\n'
int main(){
int k; cin>>k;
int a=7;
rep(i,k){
  if(a%k)a=(10*a+7)%k;
  else {print(i+1);return 0;}
}
print(-1);
}


Measured memory_bytes: 3608
n=int(input())
a=0
w=0
t=0
r=0
for i in range(n):
    s=input()
    if s=="AC":
        a+=1
    elif s=="WA":
        w+=1
    elif s=="TLE":
        t+=1
    else:
        r+=1
print("AC x "+str(a))
print("WA x "+str(w))
print("TLE x "+str(t))
print("RE x "+str(r))
    
    

Measured memory_bytes: 9196
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
 
 
 
 
 
int main(){
    TEZ;
    long double a,b;
    cin>>a>>b;
    cout<<(ll)trunc(a*b);
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
	
typedef long long int ll;
ll n,m,l,r,k;

ll chk(ll x)
{
	ll ans=0;
	for (int i = 1; i <= n; ++i)
	{
		ans+=min(m,x/i);
	}
	return ans;
}
int main()
{
	ll n;
	cin>>n;
	vector<ll>ans;
	ll a,cnt[100],bit,maxi=0;
	memset(cnt,0,sizeof(cnt));
	for (int i = 0; i < n; ++i)
	{
		cin>>a;
		while(a!=0)
		{
			ans.push_back(a%2);
			a/=2;
		}
		bit=0;
		for (int i = 0; i < ans.size(); ++i)
		{
			cnt[bit++]+=ans[i];
		}
		maxi=max(maxi,bit);
		ans.clear();
	}	
	ll fin=0,pow=1;
	for(int i=0;i<=70;++i)
	{
		fin=(fin+(((pow*cnt[i])%mod)*(n-cnt[i]))%mod)%mod;
		pow=(pow*2)%mod;
	}
	cout<<fin<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int a[n];
  M m;
  REP(i,n-1) {
    cin >> a[i+1];
    a[i+1]--;
    if (m[a[i+1]]) m[a[i+1]]++;
    else m[a[i+1]]=1;
  }

  REP(i,n) {
    cout << m[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 13752
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d,n,ax,ay,bx,by,cx,cy,dx,dy,ABX,ABY,CDX,CDY,mn;
  cin>>n>>a>>b>>c>>d;
  mn=99999;
  for(int i=1;i<=n;i++){
    ax=a%i;
    if(ax==0)ax=i;
    ay=a/i+1;
    if(a%i==0)ay--;
 
    bx=b%i;
    if(bx==0)bx=i;
    by=b/i+1;
    if(b%i==0)by--;
 
    cx=c%i;
    if(cx==0)cx=i;
    cy=c/i+1;
    if(c%i==0)cy--;
 
    dx=d%i;
    if(dx==0)dx=i;
    dy=d/i+1;
    if(d%i==0)dy--;
 
    ABX=ax-bx,ABY=ay-by,CDX=cx-dx,CDY=cy-dy;
    if(ABX<0)ABX*=-1;
    if(ABY<0)ABY*=-1;
    if(CDX<0)CDX*=-1;
    if(CDY<0)CDY*=-1;
    if(mn>ABX+ABY+CDX+CDY)mn=ABX+ABY+CDX+CDY;
     
     
  }
  cout<<mn<<endl;
  return 0;
}

Measured memory_bytes: 1160
N = 2019
cnt = [0] * N
S = input()
ans = 0
for s in S:
    s = int(s)
    new = [0] * N
    for n in range(N):
        idx = (10 * n + s) % N
        new[idx] += cnt[n]
    cnt = new
    cnt[s] += 1
    ans += cnt[0]

print(ans)


Measured memory_bytes: 76420
n, m = list(map(int, input().split()))
A = []
for i in range(n):
    a = list(map(int, input().split()))
    A.append(a)
b = []
for i in range(m):
    b.append(int(input()))
c = []
for i in range(n):
    kari = 0
    for j in range(m):
        kari += A[i][j] * b[j]
    c.append(kari)
for i in c:
    print(i)


Measured memory_bytes: 6020
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int X, A, B;
  ci(X, A, B);
  if(B <= A){
    co("delicious");
  }
  else if(B - A <= X){
    co("safe");
  }
  else{
    co("dangerous");
  }
}

Measured memory_bytes: 256
import fractions
import sys
sys.setrecursionlimit(10**9)

MOD = 1000000007  # type: int
INF=10**20

class Counter:
    def __init__(self):
        self.dict = {}

    def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

    def decrement(self,x):
        self.dict[x] -= 1
        if self.dict[x] <= 0:
            del self.dict[x]

    def get_dict(self):
        return self.dict



class Counting():
    def __init__(self,maxim,mod):
        maxim += 1

        self.mod = mod
        self.fact = [0]*maxim
        self.fact[0] = 1
        for i in range(1,maxim):
            self.fact[i] = self.fact[i-1] * i % mod

        self.invfact = [0]*maxim
        self.invfact[maxim-1] = pow(self.fact[maxim-1],mod-2,mod)
        for i in reversed(range(maxim-1)):
            self.invfact[i] = self.invfact[i+1] * (i+1) % mod


    def nCk(self,n,r):
        if n < 0 or n < r: return 0
        return self.fact[n] * self.invfact[r] * self.invfact[n-r] % self.mod

    def nPk(self,n,r):
        if n < 0 or n < r: return 0
        return self.fact[n] * self.invfact[n-r] % self.mod

        


def solve(N: int, A: "List[int]", B: "List[int]"):

    both_zero = 0
    a_zero = 0
    b_zero = 0
    
    counter = Counter()
    for i in range(N):
        a,b=A[i],B[i]   

        if a * b == 0:
            if a == 0 and b == 0:
                both_zero += 1
                continue
            elif a == 0:
                a,b = 0,1
            else:
                a,b = -1,0

        
        gcd = fractions.gcd(a,b)
        a //= gcd
        b //= gcd

        # (a,b): -はaの方に寄せる
        if a < 0 and b < 0:
            a *= -1
            b *= -1
        if a < 0 and b > 0:
            pass

        if a > 0 and b < 0:
            a *= -1
            b *= -1
        
        counter.add((a,b))

    
    seen = set()
    cannot = 0
    counter = counter.get_dict()

    ans = 1
    for e,count in counter.items():
        a,b = e
        if e in seen: continue
        # print(e)
    
        if a > 0:
            b *= -1
        else:
            a *= -1

        if (b,a) in seen: continue

        if (b,a) in counter:
            count2 = counter[(b,a)]

            ans *= pow(2,count,MOD) + pow(2,count2,MOD) - 1
        else:
            ans *= pow(2,count,MOD)
        
        ans %= MOD
        seen.add((b,a))
        # print(ans)
        
    # ans *= pow(2,a_zero,MOD) + pow(2,b_zero,MOD) - 1
    ans %= MOD

    ans += both_zero - 1
    ans %= MOD

    print(ans)


    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)



if __name__ == "__main__":
    main()


Measured memory_bytes: 160000
#include <iostream>

using namespace std;

int main(){

	int N,M;
	int r;

	while(cin>>N>>M){
		if(N==0&&M==0)break;

		cin>>r;

		int *t = new int[r];
		int *n = new int[r];
		int *m = new int[r];
		int *s = new int[r];

		for(int i=0;i<r;i++){
			cin>>t[i]>>n[i]>>m[i]>>s[i];
		}

		int q;
		cin>>q;

		for(int i=0;i<q;i++){
			int start,end,studentNum;
			cin>>start>>end>>studentNum;

			int pcNum=0;
			int pcStart=0;
			int sum=0;

			for(int j=0;j<r;j++){

				if(studentNum == m[j]){
					if(s[j]==1){
						if(pcNum==0){
							if(t[j]<=start){
								pcStart=start;
							}
							else if(t[j]>=end){
								pcStart=end;
							}
							else{
								pcStart=t[j];
							}
						}
						pcNum++;
					}
					else{
						if(pcNum==1){
							if(t[j]<=start){
								sum += 0;
							}
							else if(t[j]>=end){
								sum += end -pcStart;
							}
							else{
								sum += t[j]-pcStart;
							}
						}
						pcNum--;
					}
				}
			}
			cout<<sum<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1320
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

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


int main() {
	double W, H, x, y;
	cin >> W >> H >> x >> y;

	double N = W * H / 2;


	if (x == W / 2 && y == H / 2) {
		cout << N << ' ' << '1' << endl;
	}
	else {
		cout << N << ' ' << '0' << endl;
	}
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
        k: usize,
    }
    let a = s.iter().position(|&c| c != '1');
    println!("{}", match a {
        Some(a_) => if a_ > k - 1 { 1 } else { s[a_].to_digit(10).unwrap() },
        None => 1,
    });
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll m;
  m = max(a * c, max(b * d, max(a * d, b * c)));
  cout << m << endl;
  return 0;
}

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

using namespace std;

// https://atcoder.jp/contests/abc173/tasks/abc173_c

int main() {

    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> input(H, vector<char>(W));
    for (auto &x: input) {
        for (auto &y: x) {
            cin >> y;
        }
    }
    int ans{0};
    for (int maskR = 0; maskR < (1 << H); ++maskR) {

        for (int maskC = 0; maskC < (1 << W); ++maskC) {

            int black = 0;
            for (int i = 0; i < H; ++i) {

                for (int j = 0; j < W; ++j) {

                    if (
                            ((maskR >> i) & 1) == 0 and
                            ((maskC) >> j & 1) == 0 and
                            input[i][j] == '#'
                            ) {
                        ++black;
                    }
                }
            }
            if (black == K) ++ans;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>
#include <chrono>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

auto start = std::chrono::system_clock::now();
inline double get_time() {
  auto end = std::chrono::system_clock::now();
  auto dur = end - start;
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
  return msec;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

int D;
LL C[26];
VVL S;

void input(){
    cin >> D;
    REP(i,26) cin >> C[i];
    S.assign(D,VL(26));
    REP(i,D) REP(j,26) cin >> S[i][j];
}

void solve(){
    // last days
    LL L[26] = {};

    LL score = 0;
    REP(day,D){

        LL best = -LINF;
        LL choice = -1;

        REP(cand, 26){
            LL tmp = L[cand];
            L[cand] = day+1;

            LL gain = S[day][cand];
            REP(i,26){
                LL interval = day+1 - L[i];
                gain -= C[i] * (interval + interval+12) * 13 / 2;
                //gain -= C[i] * (day+1 - L[i]);
            }

            if(best < gain){
                best = gain;
                choice = cand;
            }


            L[cand] = tmp;
        }

        L[choice] = day+1;
        cout << choice+1 << "\n";

    }

}


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    input();
    solve();
    while(1){
        if(get_time() > 1980) break;;
    }

}

Measured memory_bytes: 3744
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

template<typename value_type>
class floyd_warshall
{
public:
	const value_type INF = 1e9;

public:
	vector<vector<value_type>> dist;

public:
	floyd_warshall(int vertex_count)
		: dist()
	{
		dist.assign(vertex_count, vector<value_type>(vertex_count, INF));
	}

public:
	void create_edge(int from, int to, value_type cost)
	{
		dist[from][to] = cost;
	}

	void process()
	{
		for (int k = 0; k < (int)dist.size(); k++)
		{
			for (int i = 0; i < (int)dist.size(); i++)
			{
				for (int j = 0; j < (int)dist.size(); j++)
				{
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
	}
};

//floyd_warshall<int> fw(N);
//fw.create_edge(u, v, c);
//fw.process();
//int ret = fw.dist[a][b];

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

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

	vector<string> map_S;

	for (int i = 0; i < H; i++)
	{
		string S;
		cin >> S;

		map_S.push_back(S);
	}

	floyd_warshall<int> fw(H * W);

	for (int i = 0; i < H * W; i++)
	{
		fw.create_edge(i, i, 0);
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (j + 1 < W && map_S[i][j] == '.' && map_S[i][j + 1] == '.')
			{
				fw.create_edge(i * W + j, i * W + (j + 1), 1);
				fw.create_edge(i * W + (j + 1), i * W + j, 1);
			}
			
			if (i + 1 < H && map_S[i][j] == '.' && map_S[i + 1][j] == '.')
			{
				fw.create_edge(i * W + j, (i + 1) * W + j, 1);
				fw.create_edge((i + 1) * W + j, i * W + j, 1);
			}
		}
	}

	fw.process();

	int max_dist = 0;
	for (int i = 0; i < H * W; i++)
	{
		for (int j = 0; j < H * W; j++)
		{
			if (fw.dist[i][j] != fw.INF)
			{
				max_dist = max(max_dist, fw.dist[i][j]);
			}
		}
	}

	cout << max_dist;

	return 0;
}


Measured memory_bytes: 896