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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#ABC088-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
h,w=IL()
G=[S() for i in range(h)]
used=[[False for i in range(w)] for j in range(h)]
q=[[0,0,1]]
pos=False
while len(q)>0:
    gy,gx,dis=q.pop(0)
    if gy==h-1 and gx==w-1:
        pos=True
        break
    if not used[gy][gx]:
        if gy!=0:
            if G[gy-1][gx]=="." and not used[gy-1][gx]:
                q.append([gy-1,gx,dis+1])
        if gx!=0:
            if G[gy][gx-1]=="." and not used[gy][gx-1]:
                q.append([gy,gx-1,dis+1])
        if gy!=h-1:
            if G[gy+1][gx]=="." and not used[gy+1][gx]:
                q.append([gy+1,gx,dis+1])
        if gx!=w-1:
            if G[gy][gx+1]=="." and not used[gy][gx+1]:
                q.append([gy,gx+1,dis+1])
    used[gy][gx]=True
if pos:
    ans=0
    for i in range(h):
        ans+=G[i].count(".")
    print(ans-dis)
else:
    print(-1)

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

const int INFTY =1000000001;
int C;

void merge(int A[],int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int* L=new int[n1+1];
  int* R=new int[n2+1];
  for(int i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=INFTY;
  R[n2]=INFTY;
  for(int i=0,j=0,k=left;k<right;k++){
    if(C++,L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      j++;
    }
  }
  delete[] L;
  delete[] R;
}

void mergeSort(int A[],int left,int right){
  if(left+1>=right){
    return;
  }
  int mid=(left+right)/2;
  mergeSort(A,left,mid);
  mergeSort(A,mid,right);
  merge(A,left,mid,right);
}

int main(){
  int n;
  cin>>n;
  int S[n];
  for(int i=0;i<n;i++){
    cin>>S[i];
  }
  mergeSort(S,0,n);
  for(int i=0;i<n;i++){
    if(i==n-1){
      cout<<S[i]<<endl;
    }else{
      cout<<S[i]<<' ';
    }
  }
  cout<<C<<endl;
}


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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif


#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define vvi vv(int)
#define vvl vv(ll)
#define vvii vv(pii)
#define vvll vv(pll)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1)

using namespace std;

#define prime 1000000007

int main(){
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for(int i = 0, a; i < n; ++i) cin >> a;
	cout << (n-1+k-2)/(k-1) << endl;
	return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int asums[26][MAX_N + 1];

/* subroutines */

/* main */

int main() {
  string s;
  cin >> s;
  int n = s.size();

  int i, j;
  for (j = 1; j < n; j++) {
    if (s[j] == s[j - 1]) {
      i = j - 1;
      break;
    }
    if (j > 1 && s[j] == s[j - 2]) {
      i = j - 2;
      break;
    }
  }

  if (j >= n) puts("-1 -1");
  else printf("%d %d\n", i + 1, j + 1);
  return 0;
}


Measured memory_bytes: 512
n = int(input())
a = [int(i) for i in input().split()] 

operation = 0

while(True):
    odd_flag = False
    for i in range(0,n):
        if a[i] % 2 != 0:
            odd_flag = True
        else:
            a[i] = a[i] / 2
    if odd_flag == True:
        break
    operation += 1
print(operation)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
  
int main(){
    ll n, m; cin >> n >> m;
    if(n > 1 and m > 1){
    cout << (m - 2) * (n - 2) << endl;
    }else if(n == 1 and m == 1){
        cout << 1 << endl;
    }else if(n == 1){
        cout << max(m - 2, 0LL) << endl;
    }else if(m == 1){
        cout << max(n - 2, 0LL) << endl;
    }
}


Measured memory_bytes: 256
class Tree():
    def __init__(self):
        self.parent = -1
        self.depth = 0
        self.child = []

n = int(input())
tree = [Tree() for i in range(n)]
for i in range(n):
    cmd = list(map(int, input().split()))
    node = tree[cmd[0]]
    node.child.extend(cmd[2:])
    for j in cmd[2:]:
        c = tree[j]
        c.parent = cmd[0]
for t in tree:
    d, p = 0, t.parent
    while p != -1:
        d += 1
        p = tree[p].parent
    t.depth = d
for i in range(n):
    t = tree[i]
    if t.parent == -1:
        state = 'root'
    elif t.child:
        state = 'internal node'
    else:
        state = 'leaf'
    print('node {}: parent = {}'.format(i, t.parent),
          'depth = {}'.format(t.depth),
          state,
          '[{}]'.format(', '.join(map(str, t.child))),
          sep=', ')

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define B 1000000007

int N;
vector<int> g[100010];
map<ull,ll> cnt;
ll res=0;

ull dfs(int v,int pre){
  ull crth=0;
  for(int nv : g[v]){
    if(nv==pre)continue;
    crth+=dfs(nv,v);
  }
  crth*=B;
  crth+=1;
  res+=cnt[crth];
  cnt[crth]++;
  return crth;
}

int main(){
  cin>>N;
  rep(i,N-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0,-1);
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 22648
n = gets.chomp.to_i
arr = []
n.times do
  x, l = gets.chomp.split(' ').map(&:to_i)
  arr << [x - l, x + l]
end
arr.sort_by! { |a| a[1] }
count = 1
current = arr[0]
(1...n).each do |i|
  next if arr[i][0] < current[1]
  count += 1
  current = arr[i]
end
puts count

Measured memory_bytes: 12664
import math

N = int(input())

min_l = len(str(N))

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        j = int(N / i)
        min_l = min(min_l, max(len(str(i)), len(str(j))))
print(min_l)


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)


const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>
void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>
void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}


// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n, k;
	cin >> n >> k;
	vector<int>vec(n), vec2(n, INF);
	vecin(vec);
	vec2[0] = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < min(n, i + k+1); j++) {
			vec2[j] = min(vec2[j], vec2[i] + abs(vec[i] - vec[j]));
		}
	}
	cout << vec2.back() << endl;
}


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

using ll = long long;
const ll MOD = 998244353;

int main() {
    string s;
    cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4, 8) << "\n";
}

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

int main(){
	int D;
	cin >> D;
	
	vector<int> c(26);
	rep(i, 26) cin >> c[i];
	
	vector<vector<int>> s(D, vector<int> (26));
	rep(d, D) {
		rep(i, 26) {
			cin >> s[d][i];
		}
	}
	
	vector<int> t(D);
	rep(d, D) cin >> t[d];
		
	int M;
	cin >> M;
	
	vector<int> d(M), q(M);
	rep(i, M) cin >> d[i] >> q[i];
	
	rep(m, M) {
		vector<int> last(26, 0);
		int v = 0;
		t[d[m]-1] = q[m];
		rep(d, D) {
			v += s[d][t[d]-1];
			rep(i, 26) {
				if (i == t[d]-1) {
					last[i] = d + 1;
				}
				v -= c[i] * (d+1 - last[i]);
			}
//			cout << v << endl;
		}
		cout << v << endl;
	}
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vvi s(m+1);
  vi k(m+1);
  int ans = 0;
  for(int i=1; i<=m; i++){
    cin >> k[i];
    rep(j,k[i]){
      int si;
      cin >> si;
      s[i].push_back(si);
    }
  }
  vi p(m+1);
  rep(i,m) cin >> p[i+1];
  
  for(int i = 0; i<(1<<n); i++){
    vi cnt(m+1, 0);
    rep(is,n){
      if((i >> is) & 1){
        for(int j=1; j<=m; j++){
          for(auto x : s[j]){
            if(x == is+1) cnt[j]++;
          }
        }
      }
    }
    
    bool ok = true;
    for(int is=1; is<=m; is++){
      if(p[is] != cnt[is]%2) ok = false;
    }
    //rep(ia,m) cout << cnt[ia+1] << " ";
    if(ok) ans++;
    //cout << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
/*
 * AtCode Beginner Contest 131 : C.Anti Division
 * Credit : Editorial
 * 27 August 2019
 *
 */

#include <bits/stdc++.h>
#include <numeric>
using namespace std;

typedef long long ll;
ll A,B,C,D;

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

int main()
{
	cin >> A >> B >> C >> D;

	ll totalnum = B - A + 1;

	ll totalMC = B/C - A/C +  ((A % C) ? 0 : 1);// kelipatan C di range
	ll totalMD = B/D - A/D + ((A % D) ? 0 : 1); // kelipatan D di range

	ll kpk = lcm(C,D);
	ll totalKPK = B/kpk - A/kpk + ((A % kpk) ? 0 : 1 );//KPK di range


	cout << totalnum - totalMC - totalMD + totalKPK << '\n';

	return 0;
}

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

int main()
{
	int n, i;
	cin >> n;
	int a[n+1], b[n+1], maxv=0, s=0;
	for (i=1; i<=n; i++)
	{
		cin >> a[i];
		b[i]=a[i];
	}
	sort(b+1, b+n+1);
	for (i=1; i<=n; i++)
	{
		if (a[i]>maxv)
		{
			maxv=a[i];
		}
	}
	for (i=1; i<=n; i++)
	{
		if (a[i]==maxv)
		{
			s++;
		}
	}
	if (s==1)
	{
		for (i=1; i<=n; i++)
		{
			if (a[i]==maxv)
			{
				cout << b[n-1] << endl;
			}
			else
				cout << maxv << endl;
		}
	}
	else
	{
		for (i=1; i<=n; i++)
			cout << maxv << endl;
	}
	return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int a, b, c, d; 
	cin >> a >> b >> c >> d;
	cout << ((a*b >= c*d) ? a*b : c*d) << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0;i < (n-1);i++) {
    if (s.at(i) == '?') {
      if (i > 0 && s.at(i-1) == 'P' ) {
        s.at(i) = 'D';
      } else if (s.at(i+1) == '?' || s.at(i+1) == 'D') {
        s.at(i) = 'P';
      } else {
        s.at(i) = 'D';
      }
    }
  }
  if (s.at(n-1) == '?') s.at(n-1) = 'D';
  cout << s << endl;
}


Measured memory_bytes: 3756
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll m = n;
    ll c = 0;
    rep(i,2,sqrt(m)+1){
        if (n%i) continue;
        ll a = 0;
        while(n%i == 0){
            a++;
            n /= i;
        }
        ll b = sqrt(a);
        while(a >= b*(b+1)/2){
            b++;
        }
        //PRINT(a << " " << b);
        c += b-1;
    }
    if (n > 1) c++;
    PRINT(c);
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	string ans = s;

	if(s[0] == '?') ans[0] = 'D';

	char pre = s[0];
	char next;
	if(3 < s.size()) next = s[2];

	REP(i, 1, s.size()){
		char c = s[i];
		if(i == s.size() - 1){
			if(c == '?') ans[i] = 'D';
		}
		else{
			pre = s[i - 1];
			next = s[i + 1];

			if(c == '?' && pre == 'D' && next == 'D' || c == '?' && pre == 'D' && next == '?') ans[i] = 'P';
			else if(c == '?') ans[i] = 'D';
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3924
count = gets.to_i
input = gets.chomp
input_arr = input.split(' ').map(&:to_i)

def sums(arr)
	sum = 0
	arr.each {|i|
		sum += i
	}
	return sum
end
puts sprintf('%d %d %d', input_arr.min, input_arr.max, sums(input_arr))

Measured memory_bytes: 9164
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<Int> get_div(Int x) {
    vector<Int> ans;
    for(Int i = 1;i*i <= x;i++) {
        if(x % i == 0) {
            ans.push_back(i);
            if(i*i != x)
                ans.push_back(x/i);
        }
    }

    sort(ans.begin(),ans.end());

    return ans;
}

bool isprime(Int x) {
    if(x <= 2)
        return true;

    if(x % 2 == 0)
        return false;

    for(Int i = 3;i*i <= x;i+=2) {
        if(x % i == 0)
            return false;
    }

    return true;
}

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

    vector<Int> div_a = get_div(a);
    vector<Int> div_b = get_div(b);

    
    if(div_a.size() > div_b.size()) {
        vector<Int> temp = div_b;
        div_b = div_a;
        div_a = temp;
    }
   
    Int bx = 0;
    vector<Int> common;
    for(int i = 0;i < div_a.size();i++) {
        while(div_b[bx] < div_a[i] && bx < div_b.size())
            bx++;

        if(div_a[i] == div_b[bx]) {
            common.push_back(div_a[i]);
            bx++;
        }
        

        if(bx == div_b.size())
            break;
    }

    vector<Int> ans;
    for(auto u: common) {
        if(isprime(u))
            ans.push_back(u);
    }

    cout<<ans.size()<<endl;

    return 0;
}





Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x=nxtl();
    ll test=x/11;
    test*=2;
    x%=11;
    if(x>0)
    {
        x-=6;
        test++;
    }
    if(x>0)
        test++;
    cout<<test<<endl;
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    h, w, k = map(int, input().split())
    s = [input() for i in range(h)]
    ans = [[0] * w for i in range(h)]
    a_list = []
    for x in range(w):
        for y in range(h):
            if s[y][x] == '#':
                a_list.append((y, x))
    for i, a in enumerate(a_list):
        i += 1
        y = a[0]
        ans[y][a[1]] = i
        while y > 0:
            y -= 1
            if ans[y][a[1]] != 0:
                break
            ans[y][a[1]] = i
        y = a[0]
        while y < h - 1:
            y += 1
            if s[y][a[1]] == '#':
                break
            ans[y][a[1]] = i

    for x in range(w):
        if ans[0][x] != 0:
            continue
        nx = x
        while nx < w - 1:
            nx += 1
            if ans[0][nx] != 0:
                for i in range(h):
                    ans[i][x] = ans[i][nx]
                break

    for x in range(w-1, -1, -1):
        if ans[0][x] != 0:
            continue
        nx = x
        while nx > 0:
            nx -= 1
            if ans[0][nx] != 0:
                for i in range(h):
                    ans[i][x] = ans[i][nx]
                break

    for i in range(h):
        print(' '.join(str(j) for j in ans[i]))
main()


Measured memory_bytes: 14532
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int N,M,D;
    cin >> N >> M;
    int A[M];
    D = N;

    rep(i, M){
        cin >> A[i];
        D -= A[i];
    }

    if(D < 0){
        cout << -1 << endl;
    }else{
        cout << D << endl;
    }
}

Measured memory_bytes: 3644
A = [input().split() for l in range(3)]
N=int(input())
b = [input() for l in range(N)]

for i in range(3):
    for j in range(3):
        for k in b:
            if A[i][j]==k:
                A[i][j]='*'

if (A[0][0]==A[0][1]==A[0][2]) or (A[1][0]==A[1][1]==A[1][2]) or (A[2][0]==A[2][1]==A[2][2]) or (A[0][0]==A[1][0]==A[2][0]) or (A[0][1]==A[1][1]==A[2][1]) or (A[0][2]==A[1][2]==A[2][2]) or (A[1][1]==A[2][2]==A[0][0]) or (A[0][2]==A[1][1]==A[2][0]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3444
n,m = map(int,input().split())
# aisle_lists = [list(map(int,input().split())) for _ in range(m)]

room_set = set()
aisle_dict = dict()

for _ in range(m):
    a,b = map(int,input().split())

    if a in room_set:
        aisle_dict[a].append(b)
    else:
        room_set.add(a)
        aisle_dict[a] = [b]

    if b in room_set:
        aisle_dict[b].append(a)
    else:
        room_set.add(b)
        aisle_dict[b] = [a]


visit_room = {1}
signpost = dict()
now_rooms= [1]

while len(visit_room) < n:
    tmp_now_rooms = []

    for now_room in now_rooms:
        for connect_room in aisle_dict[now_room]:
            if connect_room not in visit_room:
                signpost[connect_room] = now_room
                tmp_now_rooms.append(connect_room)
                visit_room.add(connect_room)

    now_rooms = tmp_now_rooms

print('Yes')
for i in range(2,n+1):
    print(signpost[i])

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
  int n;
  int val;
  cin >> n;
  map<int,int> mapa;
  rep(i,n)
  {
    cin >> val;
    mapa.insert(make_pair(val, i + 1));
  }
  rep(i,n)
  {
     cout << mapa[i + 1];
     if(i < n - 1){cout << " ";}
  }
  return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
        string s,t;
        cin>>s>>t;
        //cout<<5<<endl;
        //int n = min(s.length(), t.length());
        vector<vector<int> > dp(s.length(), vector<int>(t.length()));
        //vector<vector<string> > ans(s.length(), vector<string>(t.length()));
        //ans[0][0] = "";
        dp[0][0] = 0;
        for(int i=0; i<t.length(); i++)
        {
                if(s[0]==t[i])
                {
                    dp[0][i] = 1;
                }
                else if(i>0)
                {
                        dp[0][i] = dp[0][i-1];
                }
        }
        for(int i=0; i<s.length(); i++)
        {
                if(t[0]==s[i]) 
                {
                        dp[i][0] = 1;
                }
                else if(i>0)
                {
                        dp[i][0] = dp[i-1][0];
                }
        }
        for(int i=1; i<s.length(); i++)
        {
                for(int j=1; j<t.length(); j++)
                {
                        if(s[i]==t[j])
                        {
                                dp[i][j] = 1 + dp[i-1][j-1];
                                //ans[i][j] = ans[i-1][j-1] + s[i]; 
                                
                        }
                        else
                        {
                                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                                if(dp[i-1][j]>=dp[i][j-1])
                                {
                                        //ans[i][j] = ans[i-1][j];
                                }
                                else
                                {
                                        //ans[i][j] = ans[i][j-1];
                                }
                        }
                }
        }
        //cout<<ans[s.length()-1][t.length()-1];
        int i = s.length()-1, j=t.length()-1;
        //cout<<dp[i][j]<<endl;
        int k = dp[i][j]-1;
        char ans[dp[i][j]+1];
        ans[dp[i][j]] = '\0';
        while(i>=0 && j>=0)
        {
            if(s[i] == t[j])
            {
                //cout<<i<<" "<<j<<endl;
                ans[k] = s[i];
                k--;
                i--;
                j--;
            }
            else if(i==0)
            {
                j--;
            }
            else if(j==0)
            {
                i--;
            }
            else if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
                j--;
        }
        //cout<<k<<endl;
        //cout<<"LMAO"<<endl;
        cout<<ans;
        return 0;
}

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

using namespace std;

int main(void)
{
	int k,n;
	cin>>k>>n;
	int a[n];
	int b[n];
	for(int i = 0; i < n; i++) 
	{
		cin>>a[i];
		b[i] = a[i]+k;
	}
	int max = 0;
	for(int i = 0; i < n-1;i++){
		if(a[i+1] - a[i] > max){
			max = a[i+1] - a[i];
		}
	}
	if(b[0] - a[n-1] > max){
		max = b[0] - a[n-1];
	}
	
	cout<<k-max<<endl;
	return 0;
}



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

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

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

int main()
{
    ll H, W, K;
    cin >> H >> W >> K;

    vector<string> C(H);
    rep (i, H) { cin >> C[i]; }

    ll ans = 0;

    for (ll w=0;w<(1<<W);++w)
    for (ll h=0;h<(1<<H);++h)
    {
        ll n = 0;

        rep (x, W)
        rep (y, H)
        {
            if (C[y][x] != '#') { continue; }

            if ((w>>x)&1) { continue; }
            if ((h>>y)&1) { continue; }

            ++n;
        }

        if (n == K) { ++ans; }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	998244353
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

const int N = 3010;

int dp[N][N];

int32_t main(){
	int n, s;
	cin >> n >> s;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	int b[s+2] = {0};
	
	for(int i = 1; i <= n; i++){
		dp[i][a[i-1]] = i;
		for(int j = a[i-1]+1; j <= s; j++){
			dp[i][j] = b[j-a[i-1]];
		}
		for(int j = 0; j <= s; j++)
			b[j] = (b[j] + dp[i][j]) % MOD;
	}

	int ans = 0;
	
	for(int i = 1; i <= n; i++){
		ans = (ans + (dp[i][s] * (n-i+1)) % MOD) % MOD;
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 70784
#include<iostream>
#include<vector>

using namespace std;

int main(void){

    int n, x, d = 0, ans;
    
    cin >> n >> x;

    vector<int> l(n);

    for(int i = 0;i < n;i++){
        cin >> l[i];
    }

    for(int i = 1;i <= n;i++){
        d += l[i-1];
        if(d > x){
            ans = i;
            break;
        }
       
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int zero = 0, one = 0;
    rep(i, n)
    {
        if (s[i] == '0')
            zero++;
        else
            one++;
    }
    int ans = n - abs(zero - one);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3752
import java.util.Scanner;
import java.util.Stack;

public class Main {

	
	public static void main(String argv[]) {

        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String num1,num2;
        int n1,n2;
        String[] tokens = str.split(" ");
        
        Stack<String> stack = new Stack<>();
        for(int i=0; i<tokens.length; i++)
        {
        	if(tokens[i].equals("+") || tokens[i].equals("-") || tokens[i].equals("*"))
        	{
        		num2 = stack.pop();
        		num1 = stack.pop();
        		n1 = Integer.parseInt(num1);
        		n2 = Integer.parseInt(num2);
        		if(tokens[i].equals("+")) 
        		{
        			n1 = n1 + n2;
        			stack.push(Integer.toString(n1));
        		}
        		else if(tokens[i].equals("-"))
        		{
        			n1 = n1 - n2;
        			stack.push(Integer.toString(n1));
        		}
        		else if(tokens[i].equals("*"))
        		{
        			n1 = n1 * n2;
        			stack.push(Integer.toString(n1));
        		}
        	}
        	else
        	{
        		stack.push(tokens[i]);
        	}        		
        }
        
        System.out.println(stack.pop());
        in.close();
    }
}



Measured memory_bytes: 26284
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        double jpy = 0;
        double btc = 0;

        for (int i = 0; i < n; i++) {
            String[] arr = sc.nextLine().split(" ");

            if (arr[1].equals("JPY"))
                jpy += Double.parseDouble(arr[0]);
            else
                btc += Double.parseDouble(arr[0]);
        }

        jpy = btc * 380000 + jpy;
        System.out.println(jpy);
    }
}

Measured memory_bytes: 23124
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = A[0]
if n%2 ==0:
    ans +=sum(A[1:n//2]) *2
else:
    ans += sum(A[1:n//2]) *2 + A[n//2]
print(ans)


Measured memory_bytes: 31440
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int a,b,i,sum=0;
	
	while(scanf("%d",&a) != EOF){
		cin>>b;	
		a=a+b;
		while(a!=0){
			a = a / 10;
			sum++;
		}

		cout<<sum<<endl;
		sum=0;
	}
    return 0;
}

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

namespace contest_Csharp
{
    class Program
    {


        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var vals = Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToList();
            var N = vals[0];
            var A= Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToList();

            var ans = A.Where((x,i)=> (x%2==1 && i%2==0)).Count();


            Console.WriteLine(ans);
            Console.Out.Flush();
        }





    }
}




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

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;
static long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, K; cin >> N >> K;
	vector<LL> V;
	for(int i=0; i<N; i++){
		LL v; cin >> v;
		V.push_back(v);
	}

	LL ans = INF*(-1);
	for(int i=0; i<=K; i++){
		for(int j=0; j<=K; j++){
			if(i+j > K || i+j > N) break;
			deque<LL> W;
			for(int s=0; s<i; s++){
				W.push_back(V[s]);
			}
			for(int s=0; s<j; s++){
				W.push_back(V[V.size()-1-s]);
			}
			if(W.size() > 0){
				sort(W.begin(), W.end());
			}
			for(int s=0; s<K-(i+j); s++){
				if(W.size() < 1) break;
				LL b = W.front();
				if(b < 0){
					W.pop_front();
				}
			}
			LL sum = 0;
			for(int s=0; s<W.size(); s++){
				if(W.size() < 1) break;
				sum += W[s];
			}
			if(ans < sum){
				ans = sum;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3756
#include<cstdio>
#include<algorithm>

using namespace std;


int main(void)
{
	int a, b, c, d, e, f;
	int sum;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
	sum = a + b + c + d + e + f - (min(a, min(b, min(c, d))) + min(e, f));
	printf("%d\n", sum);


	return 0;
}

Measured memory_bytes: 2672
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]


n = int(input())

if (n == 1):
    print(1)
else:
    l1 = 2
    l2 = 1
    ans = 0
    for i in range(n-1):
        ans = l2 + l1
        l1 = l2
        l2 = ans
    print(ans)




Measured memory_bytes: 9168
#include "bits/stdc++.h"
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define nl '\n'
#define precision(n) setprecision(n)
typedef long double ld;
typedef long long ll;

int main() { _
    int n, d, x; cin >> n >> d >> x;
    int eaten = 0;
    forn(i, 0, n) {
        int ai; cin >> ai;
        for (int x = 1; x <= d; x += ai) {
            eaten++;
        }
    }
    cout << eaten + x << nl;
    return 0;
}


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

#define loopi(x,y) for(int i = x;i<(y);i++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)
#define loopj(x,y) for(int j = x;j<(y);j++)


#define nl cout<<"\n";
#define ll long long int
using namespace std;
#define mod  1000000007


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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin >> n;
	ll dt = 26;
	int k = 1;

	while (dt < n)
	{
		n -= dt;
		dt *= 26;
		k++;
	}

	string ans;

	if (n == dt)
	{
		while (k)
		{
			ans += 'z';
			k--;
		}
	}
	else
	{
		dt /= 26;

		int c;

		while (dt >= 1)
		{
			// cout << n << "#";
			if (n == 0)
				c = 25;
			else
				c = (n - 1) / dt;
			ans += char(int(c) + 97);
			n = n % dt;
			dt /= 26;
		}
	}

	cout << ans;

	return 0;
}

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

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

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

int main(int argc, char const *argv[]){
  ll R, W, c, r;
  while(cin>>R>>W>>c>>r, R) {
    ll tmp = (c*W - R) / r;
    if (c*W - R < 0) {
      tmp = 0;
    } else if ((c*W - R)%r!=0) {
      tmp++;
    }
    cout << tmp << endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
int H, W;
vector<string> S;
vv<int> dist;
queue<pair<int, int>> q;

int f(int x, int y) {
    rep(i, H) dist[i].assign(W, INF);
    dist[x][y] = 0;
    q.emplace(x, y);
    while (!q.empty()) {
        auto v = q.front();
        q.pop();
        rep(d, 4) {
            int nx = v.first + dx[d], ny = v.second + dy[d];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W || S[nx][ny] == '#' || dist[nx][ny] != INF) continue;
            dist[nx][ny] = dist[v.first][v.second] + 1;
            q.emplace(nx, ny);
        }
    }

    int res = 0;
    rep(i, H) rep(j, W) {
        if (S[i][j] == '.') {
            res = max(res, dist[i][j]);
        }
    }
    return res;
}

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

    dist.resize(H);

    int ans = 0;
    rep(i, H) rep(j, W) {
        if (S[i][j] == '.') {
            ans = max(ans, f(i, j));
        }
    }
    write(ans);
}

Measured memory_bytes: 256
/**
 *    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 n; cin >> n;
    vector<int> a(n);
    rep(i, n) {
        char x;
        cin >> x;
        a[i] = x - '1';
    }
    int tmp = 0;
    bool check = 0;
    rep(i, n) {
        if(a[i] == 1) {
            check = 1;
            tmp += (((n - 1) & i) == i);
        }
    }
    if(tmp % 2 == 1) {
        cout << 1 << endl;
        return;
    }
    if(check) {
        cout << 0 << endl;
        return;
    }
    rep(i, n) {
        a[i] /= 2;
    }
    tmp = 0;
    rep(i, n) {
        if(a[i] == 1) {
            tmp += (((n - 1) & i) == i);
        }
    }
    if(tmp % 2 == 1) {
        cout << 2 << endl;
    } else {
        cout << 0 << endl;
    }
}

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: 4224
#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<string> days(7);
  days = { "SAT","FRI","THU","WED","TUE","MON","SUN" };
  string s;
  cin >> s;

  for(int i=0;i<7;i++){
    if(s == days.at(i)){
      cout << i+1 << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
bool vis[maxn];
int main(){
	int n,k;cin>>n>>k;
	for(int i=1;i<=k;i++){
		int x;cin>>x;
		for(int j=1;j<=x;j++){
			int q;cin>>q;
			vis[q]=true;
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(!vis[i]) ++cnt;
	}
	cout<<cnt<<endl;
}


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


int main() {
  ll n, d, ans = 0;
  cin >> n >> d;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    ll D = x*x+y*y;
    if(D<=d*d) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef complex<double>qua;
qua calc(qua a,qua b, qua c,qua d)
{
    a-=d;
    b-=d;
    c-=d;
    return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
int main()
{
    int t;
    double x1,y1,x2,y2,x3,y3,x4,y4;
    for(scanf("%d",&t);t;--t)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        qua ans=calc(qua(x1,y1),qua(x2,y2),qua(x3,y3),qua(x4,y4));
        printf("%0.8f %0.8f\n",ans.real(),ans.imag());
    }
    return 0;
}



Measured memory_bytes: 3248
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if ("Sunny".equals(s)) {
			System.out.println("Cloudy");
		} else if ("Cloudy".equals(s)) {
			System.out.println("Rainy");
		} else {
			System.out.println("Sunny");
		}
	}
	
}

Measured memory_bytes: 21716
#include<iostream>

using namespace std;

int main(){
    int N;
    int flag=0;
    cin >> N;
    while(N > 0){
        if(N%10==7){
            flag = 1;
            break;
        }
        N /= 10;
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

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

int main() {
    int n,k,res=0;cin>>n>>k;
    rep(i,n) {
        int x;cin>>x;
        if((x-0)>(k-x)) res+=(k-x)*2;
        else res+=(x-0)*2;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
import sys

a, b, c, k = map(int, input().split())
ans = 0
if k <= a :
    print(k)
    sys.exit()
else :
    ans += a
    k -= a

if k <= b :
    print(ans)
    sys.exit()
else :
    k -= b
    ans -= k

print(ans)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
const int INF = 1000000001;
int main(){
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i,N)cin >> h[i];
    sort(h.begin(),h.end());
    int l = 0;
    int ans = INF;
    for(int r = K-1; r < N; r++){
        ans = min(h[r]-h[l],ans);
        l++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int fact[100005 + 5];
int add(int a, int b) {
	a += b;
	if (a < 0) {
		a += MOD;
	}
	if (a >= MOD) {
		a -= MOD;
	}
	return a;
}
int prod(int a, int b) {
	return (1ll * a * b) % MOD;
}
int sub(int a, int b) {
	a -= b;
	if (a < 0) {
		a += MOD;
	}
	if (a >= MOD) {
		a -= MOD;
	}
	return a;
}
int pow(int a, int b) {
	int ans = 1;
	while(b) {
		if (b & 1) {
			ans = prod(ans , a);
		}
		a = prod(a, a);
		b /= 2;
	}
	return ans;
}
int C(int n, int m) {
	int a = fact[n];
	int b = prod(fact[m], fact[n - m]);
	b = pow(b, MOD - 2);
	return prod(a, b);
}
int main() {
	int n, k, ans = 0;
	cin >> n >> k;
	fact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = prod(fact[i - 1], i);
	}
	vector < int > v(n + 5);
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
	}
	sort(v.begin() + 1, v.begin() + 1 + n);
	reverse(v.begin() + 1, v.begin() + 1 + n);
	for (int i = 1; i <= n - k + 2; i++) {
			ans = add(ans, prod(C(n - i, k - 1), v[i]));
	}
	reverse(v.begin() + 1, v.begin() + 1 + n);
	for (int i = 1; i <= n - k + 2; i++) {
			ans = sub(ans, prod(C(n - i, k - 1), v[i]));
	}
	cout << ans << "\n";
	// 10 10 10 -10 -10 -10
}

Measured memory_bytes: 1024