akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 2;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

ll two[1223456];

void init()
{
    two[0] = 0;
    for (int i = 1; i < 1123456; i++)
    {
        two[i] = 0;
        ll t = 2;
        int j = i;
        while (j > 0)
        {
            two[i] += j / 2;
            j /= 2;
        }
    }
}

bool isEven(int n, int m)
{
    ll c = two[n] - two[n - m];
    ll p = two[m];

    return c - p > 0;
}

int calc(int *b, int size)
{
    int c[10];

    auto cur = b;
    auto nex = c;

    for (int j = 0; j < size - 1; j++)
    {
        for (int k = 0; k < size - j - 1; k++)
            nex[k] = abs(cur[k] - cur[k + 1]);

        swap(cur, nex);
    }

    return cur[0];
}

int solve(int n, string a_)
{
    int a[1123456];

    int s = 0;

    int h[4] = {0, 0, 0, 0};

    for (int i = 0; i < n; i++)
    {
        a[i] = a_[i] - '0';
        h[a[i]]++;
        if (!isEven(n - 1, i))
            s ^= a[i];
    }

    if (s % 2 == 1)
    {
        return 1;
    }

    if (!h[2] && h[1] && h[3])
    {
        n--;
        for (int i = 0; i < n; i++)
            a[i] = abs(a[i] - a[i + 1]);

        int s = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] == 2 && !isEven(n - 1, i))
                s ^= 1;
        }

        if (s == 1)
            return 2;

        return 0;
    }

    return 0;
}

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

    init();

    int n;
    string a_;

    cin >> n;

    cin >> a_;

    cout << solve(n, a_) << endl;

    return 0;

    /*
    for (int i = 0; i < fastPow(3, 10); i++)
    {
        int b[10];
        string s = "";
        int j = i;
        for (int k = 0; k < 10; k++)
        {
            b[k] = j % 3 + 1;
            s += '1' + j % 3;
            j /= 3;
        }

        cout << s << endl;

        cout << solve(10, s) << " " << calc(b, 10) << endl;

        assert(solve(10, s) == calc(b, 10));
    }
    */

    return 0;
}


Measured memory_bytes: 15388
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
    init();
    solve();
}

ll N;
ll K;
vector<ll> A;

void init()
{
    cin >> N;
    CINV(A, N);
}

bool check() {
    ll sum = 0; rep(i, N) sum += A[i];
    if (sum % (N * (N + 1) / 2)) return false;
    K = sum / (N * (N + 1) / 2);
    rep(i, N) {
        A[i] -= K;
        if (A[i] < 0) return false;
    }
    return true;
}


void solve()
{
    if (!check()) {
        cout << "NO" << endl;
        return;
    }
    ll cnt = 0;
    rep(i, N-1) {
        if ((A[i] - A[i+1] + K) % N) {
            cout << "NO" << endl;
            return;
        }
        cnt += (A[i] - A[i+1] + K) / N;
    }
    if ((A[N-1] - A[0] + K) % N) {
        cout << "NO" << endl;
        return;
    }
    cnt += (A[N-1] - A[0] + K) / N;
    if (cnt != K) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}



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

int main() {
  int64_t N,K;
  cin >> N >> K;
  
  vector<int> vec(N);
  rep(i,N){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end()); // {1, 2, 2, 5}
  
  rep(i,K){
     vec.pop_back();
  }
  
  int64_t ans = 0;
  
  rep(i,N-K){
    ans+=vec.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[N];
    ll K = 0;
    REP(i, 0, N) {
        cin >> A[i];
        if (i >= 2) {
            K ^= A[i];
        }
    }
    bool ok = true;
    ll a = A[0], b = A[1];
    ll sum = a + b;
    if ((sum - K) & 1) {
        ok = false;
    }
    ll p = (sum - K) / 2;
    if (p < 0) {
        ok = false;
    }
    ll ans = 0;
    PER(i, 60, -1) {
        ll tmp = (1LL << i);
        if (p & tmp) {
            if (K & tmp) {
                ok = false;
            }
            ans += tmp;
        }
    }
    PER(i, 60, -1) {
        ll tmp = (1LL << i);
        if (K & tmp) {
            if (ans + tmp <= a) {
                ans += tmp;
            }
        }
    }
    if (ans > a || ans == 0) {
        ok = false;
    }
    if (ok) {
        cout << a - ans << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>

using namespace std;


int main(){

  while(1){
    string n,m;
    cin >> n >> m;
    if(n == "0" && m == "0") break;
    int hit=0,br=0;
    for(int i=0;i<4;i++){
      if(n[i] == m[i]) hit++;
    }
    int hoge[10]={};
    for(int i=0;i<4;i++){
      hoge[stoi(n.substr(i,1))]=1;
    }
    for(int i=0;i<4;i++){
      if(hoge[stoi(m.substr(i,1))] == 1) br++;
    }
    br -= hit;
    cout << hit << " " << br <<endl;



  }

}

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

void show_stack(stack<char> st) {
  cout << "stack: ";
  while (!st.empty()) {
    cout << st.top();
    st.pop();
  }
  cout << endl;
}

bool bfs(int integers[], stack<char>& st, int ans, int h) {
  if (h == 4) {
    if (ans == 7) {
      return true;
    } else {
      return false;
    }
  }

  bool is_ok = false;
  // プラス
  st.push('+');
  is_ok = bfs(integers, st, ans + integers[h], h + 1);
  if (is_ok) {
    return true;
  }
  st.pop();

  // マイナス
  st.push('-');
  is_ok = bfs(integers, st, ans - integers[h], h + 1);
  if (is_ok) {
    return true;
  }
  st.pop();

  return false;

}

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string in;
  cin >> in;

  int integers[4];
  for (int i = 0; i < in.size(); i++) {
    integers[i] = in.at(i) - '0';
  }

  stack<char> st;
  bfs(integers, st, integers[0], 1);
  char ops[3];
  for (int i = 0; i < 3; i++) {
    ops[2 - i] = st.top();
    st.pop();
  }
  for (int i = 0; i < 3; i++) {
    cout << integers[i] << ops[i];
  }
  cout << integers[3] << "=7" << endl;

}


int main() {
  answer1();
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int tr[12];
	int num, i, n;
	
	num = 0;
	
	while (scanf("%d", &n) != EOF){
		
		if (n == 0){
			num--;
			printf("%d\n", tr[num]);
			
		}
		else {
			tr[num] = n;
			num++;
		}
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

signed main() {
	int x, y, z, k, a[1500], b[1500], c[1500], fin = 0;
	vector<int>d;
	vector<int>ans;
	cin >> x >> y >> z >> k;
	rep(i, x) cin >> a[i];
	rep(i, y) cin >> b[i];
	rep(i, z) cin >> c[i];
	rep(i, x) {
		rep(j, y) {
			d.push_back(a[i] + b[j]);
			fin++;
		}
	}
	sort(d.begin(), d.end());
	reverse(d.begin(), d.end());
	int mi = min(fin, k);
	for(int i=0;i<mi;i++){
		rep(j, z) {
			ans.push_back(d[i] + c[j]);
		}
	}
	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());
	rep(i, k) {
		cout << ans[i] << endl;
	}

	END;
}

Measured memory_bytes: 42980
#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>;

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;}

int count_divive2(int x) {
    int ans = 0;
    while (x % 2 == 0) {
        ans++;
        x /= 2;
    }

    return ans;
}

void solve() {
    ll N, M;
    cin >> N >> M;

    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int cntpow2 = count_divive2(a[0]);
    for (int i = 0; i < N; i++) {
        if (cntpow2 != count_divive2(a[i])) {
            cout << 0 << endl;
            return;
        }
    }

    ll T = a[0] / 2;
    for (int i = 0; i < N; i++) {
        T = lcm(T, a[i] / 2);
    }

    // cout << M << endl;
    // cout << T << endl;
    cout << M / T / 2 + (M / T % 2) << endl;

}

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


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n;
  cin >> n;
  int a[n+1], b[n];
  for(int i=0; i<n+1; ++i) cin >> a[i];
  for(int i=0; i<n; ++i) cin >> b[i];
  ll ans = 0;
  for(int i=0; i<n; ++i){
    ll res = min(a[i], b[i]);

    ans += res;
    a[i] -= res;
    b[i] -= res;

    ll res1 = min(a[i+1], b[i]);

    ans += res1;
    a[i+1] -= res1;
    b[i] -= res1;

  }
  cout << ans << endl;
}

Measured memory_bytes: 4356
#include<iostream>
using namespace std;
int main()
{
	int A,B,ans;
	cin>>A>>B;
	if(A>=B){
		if((A-1)>=B){
			ans=A+(A-1);
		}
		else if((A-1)<=B){
			ans=A+B;
		}
	}
	else if(A<=B){
		if((B-1)>=A){
			ans=B+(B-1);
		}
		else if((B-1)<=A){
			ans=B+A;
		}
	}
	cout<<ans<<endl;
 } 

Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace AtCoder {
    public class Program {
        static int[] getKeys() {
            var Keys = Console.ReadLine().Split(' ');
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(delimiter);
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        public static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        public static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }


        static void Main() {
            var Key = getKeys();
            int N = Key[0];
            int M = Key[1];
            if (N >= M) {
                Console.WriteLine(0);
                return;
            }
            Key = getKeys();
            Array.Sort(Key);
            List<int> distances = new List<int>();
            for (int i = 1; i < M; i++) {
                distances.Add(Key[i] - Key[i - 1]);
            }
            distances.Sort((x, y) => y - x);
            for (int i = 0; i < N - 1; i++) {
                distances.Remove(distances.First());
            }
            Console.WriteLine(distances.Sum());
        }
    }
}


Measured memory_bytes: 25052
#include <iostream>
#include <string>

struct MyList {
  uint32_t value = 0;
  MyList* prev = nullptr;
  MyList* next = nullptr;
};

int main() {
  uint32_t N = 0;
  std::cin >> N;

  // nullptrは面倒なので、dummyで必ず存在するfirst
  MyList* first = new MyList;
  first->value = -1;
  first->prev = first;
  first->next = first;

  std::string command;
  uint32_t x = 0;
  for (size_t i = 0; i < N; i++) {
    std::cin >> command;
    if (command.front() == 'i') {
      std::cin >> x;

      MyList* elem = new MyList;
      elem->value = x;
      elem->prev = first;
      elem->next = first->next;

      first->next->prev = elem;
      first->next = elem;

    } else {
      MyList* target = nullptr;
      switch (command.size()) {
        case 6:  // delete
          target = first->next;
          std::cin >> x;
          while (!((target == first) || (target->value == x)))
            target = target->next;
          if (target == first) target = nullptr;
          break;

        case 11:  // deleteFirst
          if (first->next != first) target = first->next;
          break;

        case 10:  // deleteLast
          if (first->prev != first) target = first->prev;
          break;

        default:
          break;
      }

      if (target == nullptr) continue;
      target->prev->next = target->next;
      target->next->prev = target->prev;
      delete target;
    }
  }

  MyList* current = first->next;
  while (current != first) {
    if (current != first->next) std::cout << " ";
    std::cout << current->value;
    current = current->next;
    delete current->prev;
  }
  std::cout << std::endl;

  delete first;

  return 0;
}


Measured memory_bytes: 34356
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
   
    int n, m;
    cin>>n>>m;
    
    vector<vector<int>> v(m);
    vector<int> p(m), k(m);
    
    for(int i=0; i<m; i++){
        cin>>k[i];
        for(int j=0; j<k[i]; j++){
            int tmp;
            cin>>tmp;
            v[i].push_back(tmp);
        }
    }
    
    for(int i=0; i<m; i++){
        cin>>p[i];
    }
    
    bool bi=false;
    int cc=0;
    
    for(int i=0; i<(2<<(n-1)); i++){
        bi=true;
        
        for(int j=0; j<m; j++){
            int cnt=0;
            for(int ii=0; ii<k[j]; ii++){
                if(i&(1<<(v[j][ii]-1))){
                    cnt++;
                }
            }
            if((cnt%2)!=p[j]){
                bi=false;
                break;
            }
        }
        
        if(bi){
            cc++;
        }
    }
    cout<<cc<<endl;
}


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

using namespace std;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;

ll mod = 1e9+7;

string solve() {
    int n, a; cin >> n;
    rep(i, n) {
        cin >> a;
        if (a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)) {
            return "DENIED";
        }
    }

    return "APPROVED";
}

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

	cout << solve() << endl;
}


Measured memory_bytes: 3668
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<string.h>

#include<iomanip>
#define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148
using namespace std;
#define A 0.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333


int main()
{
	int n;
	while(cin>>n)
	{
		for(int i=1;i<=n;i++)
			{
				if(i%3==0)
				{
					cout<<" "<<i;
			
					continue;
				}
				
					if(i%10==3)
						{
							cout<<" "<<i;
							
					continue;
					}
					for(int k=i;k>0;k=k/10)
					{
						if(k%10==3)
						{
							cout<<" "<<i;//????????????
						
						break;
						}
						continue;
					}
		}
		cout<<endl;
		
	}
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, n;
  while (cin >> a >> n, a or n) {
    map<int, int> mp;
    for (int i = 0; ; ++i) {
      if (mp.count(a)) {
        cout << mp[a] << ' ' << a << ' ' << i - mp[a] << '\n';
        break;
      }
      mp[a] = i;
      string s = to_string(a);
      while ((int)s.size() < n) {
        s += '0';
      }
      sort(rbegin(s), rend(s));
      a = stoi(s);
      reverse(begin(s), end(s));
      a -= stoi(s);
    }
  }
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 200010
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}


int32_t main()
{
    //freopen("C:/Users/Joe/Desktop/tests/in11.txt", "r", stdin);
    //freopen("C:/Users/Joe/Desktop/tests/out11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    int t=1;
    //cin >> t;
    while(t--)
    {
        double w,h,x,y;
        cin >> w >> h >> x >> y;
        
        if(x*2==w && y*2==h)
            cout << fixed << setprecision(9) << 0.5*w*h << " " << 1 << endl;
        else
            cout << fixed << setprecision(9) << 0.5*w*h << " " << 0 << endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
ll sumA[maxn], sumB[maxn];
int ans, n, m, k, x;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) cin >> x, sumA[i] = sumA[i - 1] + x;
    for (int i = 1; i <= m; i++) cin >> x, sumB[i] = sumB[i - 1] + x;
    for (int i = 0; i <= n && sumA[i] <= k; i++) {
        ll rem = k - sumA[i];
        int Index = upper_bound(sumB, sumB + m + 1, rem) - sumB;
        ans = max(ans, i + Index - 1);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6776
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

n = int(input())
numbers = [int(x) for x in input().split()]
print(reduce(gcd, numbers))

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

typedef pair<int, int> pii;

const int MN = 100010;

int N;
int A[3][100010], B[100010], C[100010], D[100010], E[100010];

void yes() {
    printf("Yes");
}
void no() {
    printf("No");
}

struct Fenwick1 {
    vector<int> tree;
    void init() {
        tree = vector<int>(MN + 1, 0);
    }
    void upd(int idx, int val) {
        for(int i = idx + 1; i <= MN; i += (i & -i)) tree[i] += val;
    }
    int quer(int a) {
        int ret = 0;
        for(int i = a + 1; i >= 1; i -= (i & -i)) ret += tree[i];
        return ret;
    }
    int quer(int a, int b) {
        return quer(b) - quer(a - 1);
    }
} sum;

struct Fenwick2 {
    vector<int> tree;
    void init() {
        tree = vector<int>(MN + 1, 0);
    }
    void upd(int idx, int val) {
        for(int i = idx + 1; i <= MN; i += (i & -i)) tree[i] ^= val;
    }
    int quer(int a) {
        int ret = 0;
        for(int i = a + 1; i >= 1; i -= (i & -i)) ret ^= tree[i];
        return ret;
    }
} bit;

int main() {
    scanf("%d", &N);

    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < N; j++) {
            scanf("%d", &A[i][j]);
            A[i][j]--;
        }
    }

    for(int i = 0; i < N; i++) {
        if(A[0][i] / 3 != A[1][i] / 3 || A[0][i] / 3 != A[2][i] / 3) {
            no();
            return 0;
        }
        if(A[1][i] % 3 != 1) {
            no();
            return 0;
        }

        B[i] = A[0][i] / 3;
        C[i] = A[0][i] < A[1][i];
        D[ B[i] ] = i;

        if((i & 1) ^ (B[i] & 1)) {
            no();
            return 0;
        }
    }

    sum.init();
    bit.init();

    for(int i = 1; i < N; i += 2) {
        bit.upd(i, C[i]);
        bit.upd(i + 1, C[i]);
    }

    for(int i = 0; i < N; i += 2) {
        int t = 2*(D[i] / 2 + sum.quer(D[i], N - 1));
        sum.upd(D[i], 1);
        bit.upd(i, 1);
        bit.upd(t, 1);
    }

    for(int i = 1; i < N; i += 2) {
        E[i] = bit.quer(i);
    }
    for(int i = 0; i < N; i += 2) {
        E[i] = C[ D[i] ] ^ (abs((i - D[i]) / 2) & 1);
    }

    for(int i = 0; i < N; i++) C[i] = E[i];

    sum.init();
    bit.init();

    for(int i = 0; i < N; i += 2) {
        bit.upd(i, C[i]);
        bit.upd(i + 1, C[i]);
    }

    for(int i = 1; i < N; i += 2) {
        int t = 2*(D[i] / 2 + sum.quer(D[i], N - 1)) + 1;
        sum.upd(D[i], 1);
        bit.upd(i, 1);
        bit.upd(t, 1);
    }

    for(int i = 0; i < N; i += 2) {
        E[i] = bit.quer(i);
    }
    for(int i = 1; i < N; i += 2) {
        E[i] = C[ D[i] ] ^ (abs((i - D[i]) / 2) & 1);
    }

    for(int i = 0; i < N - 2; i++) {
        if(E[i] == 0) {
            E[i] ^= 1;
            E[i + 2] ^= 1;
        }
    }

    if(E[N - 2] && E[N - 1]) yes();
    else no();
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    string s;
    cin >> s;
    string sample = "AKIHABARA";

    int id = 0;
    string s2 = "";
    string s3 = "";
    rep(i, s.length()) {
        if (id > 8) {
            break;
        }
        if (s[i] != sample[id]) {
            s2 += 'A';
            i--;
        }
        else {
            s2 += s[i];
            s3 += s[i];
        }
        id++;
    }
    if (s2.length() == 8) s2 += 'A';
    yn(s2 == sample && s == s3);
    return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))

X = np.sort(X)
minX = X[0]
maxX = X[-1]
ans = 999999999

for i in range(minX, maxX+1, 1):
    x = (X - i) ** 2
    total = np.sum(x)
    ans = min(ans, total)

print(ans)

Measured memory_bytes: 27076
if __name__ == "__main__":
    s = input()
    yen = s.split()
    for i in range(len(yen)):
        yen[i] = int(yen[i])
    times_A = yen[1] / yen[0]
    if(times_A < yen[2]):
        print(int(times_A))
    else:
        print(yen[2])

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int n; cin >> n;
    vector<ll> a(n);
    ll minus = 0;
    rep(i, n){
        cin >> a[i];
        if(a[i] < 0) minus++;
    }

    ll ans = 0;
    if( minus%2 == 0 ){
        rep(i, n) ans += abs(a[i]);
    }else{
        ll m = 1e9;
        rep(i, n){
            ans += abs(a[i]);
            m = min(m, abs(a[i]));
        }
        ans -= m*2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
p = 1000000007

n, m = map(int, input().split())

u = [0]*(n+1)
F = [0]*(n+1)
for i in range(m):
	x = int(input())
	u[x] = 1

F[0] = 1
for i in range(1, n+1):
	F[i] = (F[i-1]+F[i-2])%p if i > 1 else F[i-1]
	if u[i] == 1: F[i] = 0

print(F[n])


Measured memory_bytes: 7668
#!/usr/bin/env python3
import heapq
# import bisect

n, m = list(map(int, input().split()))
a = list(map(lambda x: int(x)*(-1), input().split()))

heapq.heapify(a)
for i in range(m):
    value = heapq.heappop(a)
    value = (value+1)//2
    heapq.heappush(a, value)

# print(a)
print(-sum(a))


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//解説見た


//2でなんかいわれるか
ll f(ll x){
	ll res = 0;
	while (x%2 == 0){
		x /= 2;
		res++;
	}
	return res;
}


ll gcd(ll a,ll b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}

int main(){
	ll n,m;
	cin>>n>>m;
	ll a[n]={};
	for(ll i=0; i<n; i++){
		cin>>a[i];
		a[i]= a[i]/2;
	}
	//cout<<"a"<<endl;
	ll t=f(a[0]);
	//cout<<t<<endl;
	//リストaがすべてa/2**nで割れるかどうか
	for(ll i=0; i<n; i++){
		if( f(a[i]) != t){
			cout<< 0 << endl;
			return 0;
		}
		a[i] >>= t;
	}
	//cout<<"a"<<endl;
	ll l=1;
	for(ll i=0; i<n; i++){
		//cout<<a[i]<<" ";
		ll c=max(l,a[i]);
		ll b=min(l,a[i]);
		l= l * a[i]/gcd(c,b) ;
		//cout<<l<<" "<<endl;
	}
	//cout<<endl;
	//cout<<l<<endl;
	m = m>>t;
	m = m/l;
	m = (m+1)/2;
	cout<<m<<endl;
}
	

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  vector<vector<int>> G(N);
  for (int i = 0, a, b; cin >> a >> b; i++) G.at(--a).push_back(--b), G.at(b).push_back(a);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (auto g : G.at(i)) if (H.at(g) >= H.at(i)) goto NG;
    ans++;
    NG:;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 8792
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 50005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  cin >> n >> k;
  ll arr[n + 5];
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i + 1; j <= n + 1; j++) {

      ll tot = i + (n - j + 1);
      if (tot > k)
        continue;
      ll rem = k - tot;

      ll res = 0;
      vector<ll> curr;
      for (ll a = 1; a <= i; a++) {
        curr.push_back(arr[a]);
        res += arr[a];
      }
      for (ll b = j; b <= n; b++) {
        curr.push_back(arr[b]);
        res += arr[b];
      }

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

      for (ll x : curr) {
        if (x >= 0)
          break;
        if (rem == 0)
          break;

        res -= x;
        rem--;
      }
      ans = max(ans, res);
    }
  }

  cout << ans << en;

  return 0;
}

/*
1
11 5 8 3 4
NEESSWWNESE
 */

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define CYES cout << "Yes" \
                  << "\n"
#define CNO cout << "No" \
                 << "\n"
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";

int main()
{
    int a, b;
    cin >> a >> b;
    if (a == b)
    {
        for (int i = 0; i < a; i++)
        {
            cout << a;
        }
    }
    else if (a > b)
    {
        for (int i = 0; i < a; i++)
        {
            cout << b;
        }
    }
    else
    {
        for (int i = 0; i < b; i++)
        {
            cout << a;
        }
    }
    cout << "\n";
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N,K = map(int,input().split())
    count = 0
    for i in range(K+1,N+1):
        p = N//i
        r = N%i
        count += p*max(0,i-K)+max(0,r-K+1)

    print(count) if K != 0 else print(count-N)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
from collections import Counter
n, m = map(int, input().split())
a = list(map(int, input().split()))
cum = [0] * (n + 1)
for i in range(n):
    cum[i + 1] = (cum[i] + a[i]) % m
c = Counter(cum)
ans = 0
for v in c.values():
    ans += v * (v - 1) // 2
print(ans)

Measured memory_bytes: 16524
#include<iostream>
int nu[105];
int main(){
    int n;
    std::cin>>n;
    for(int i=0;i<n;i++)
        std::cin>>nu[i];
    int ans=0;
    for(int i=1;i<n;i++)
        if(nu[i]==nu[i-1]) {
            i++;
            ans++;
        }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int main(){
    vector<int> vec(3);
    rep(i,3) cin >> vec[i];
    sort(vec.begin(), vec.end());
    cout << abs(vec[2]-vec[1]) + abs(vec[1]-vec[0]);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"Yes"<<endl
#define prN         cout<<"No"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


pll A[MAXN+5];
ll dp[1005][20005];
ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc2(m,n);
	f1(i,2e4)dp[0][i]=oo;
	f1(i,n){
		sc2(x,y);
		fu(j,1,2e4){
			dp[i][j]=dp[i-1][j];
			if(j>=x)mnz(dp[i][j],min(dp[i-1][j-x],dp[i][j-x])+y);
		}
	}
	ans=oo;
	fu(i,m,2e4)mnz(ans,dp[n][i]);
	pr(ans);
	
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

Measured memory_bytes: 157952
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 100;
char str[N];
int a, b;
int main()
{
    bool t1 = true;
    scanf("%d%d", &a, &b);
    scanf("%s", str);
    int t = strlen(str);
    if(t!=a+b+1)
    {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < t;i++)
    {
        if(i==a)
        {
            if(str[a]!='-')
            {
                t1 = false;
            }
        }
        else
        {
            if(!(str[i]>='0'&&str[i]<='9'))
            {
                t1 = false;
            }
        }
    }
    if(t1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,k = na()

if n==k-1:
    print(1)
    exit(0)

prev_min = sum([i for i in range(k)])
prev_max = sum([i for i in range(n, n-k, -1)])
prev_num_min = k-1
prev_num_max = n-k+1
cnt = 0
for i in range(n-k+2):
    # print("{} {}".format(prev_min, prev_max))
    cnt += prev_max-prev_min+1
    cnt %= mod
    
    prev_num_min += 1
    prev_num_max -= 1
    prev_min += prev_num_min
    prev_max += prev_num_max

print(cnt)




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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

vector<pair<int, int> > g[N];
int sz[N];
int mx_sz[N];

void dfs(int u, int p)
{
    sz[u] = 1;
    mx_sz[u] = 0;
    for (auto v : g[u])
        if (v.fi != p)
        {
            dfs(v.fi, u);
            sz[u] += sz[v.fi];
            mx_sz[u] = max(mx_sz[u], sz[v.fi]);
        }
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    rep(i, 0, n - 1)
    {
        int u, v, t;
        cin >> u >> v >> t;
        u--; v--;
        g[u].push_back({v, t});
        g[v].push_back({u, t});
    }
    dfs(0, -1);
    ll ans = 0;
    rep(i, 0, n)
        for (auto j : g[i])
            if (sz[i] < sz[j.fi])
                ans += 2LL * j.se * min(sz[i], n - sz[i]);
    rep(i, 0, n)
        for (auto j : g[i])
            if (sz[i] < sz[j.fi])
            {
                if (sz[i] == n - sz[i])
                {
                    cout << ans - j.se << "\n";
                    return 0;
                }
            }
    rep(i, 0, n)
        if (mx_sz[i] * 2 <= n && sz[i] * 2 >= n)
        {
            int best = inf;
            for (auto j : g[i])
                best = min(best, j.se);
            cout << ans - best << "\n";
            return 0;
        }
    return 0;
}


Measured memory_bytes: 11904
#include <cstdio>
#include <cstring>
#include <queue>
#define CLR(x) memset((x), -1, sizeof(x))
const int  MAXH = 22;
const int  MAXK = 4;
const char ROAD = '.';
int  D[MAXH][MAXH];
char S[MAXH][MAXH];
int H, W;

struct Pair {
  int r, c;

  bool in_range() const {
    return (0 <= r) && (r < H) && (0 <= c) && (c < W);
  }
};
const Pair dir[MAXK] = {{-1,0}, {0,+1}, {+1,0}, {0,-1}};

int bfs(const Pair& src) {
  int far = 0;
  CLR(D);
  std::queue<Pair> Q;
  D[src.r][src.c] = 0;
  Q.push(src);
  while (!Q.empty()) {
    Pair u = Q.front();
    Q.pop();
    for (int k = 0; k < MAXK; ++k) {
      Pair v = u;
      v.r += dir[k].r;
      v.c += dir[k].c;
      if (!v.in_range()) continue;
      if (D[v.r][v.c] != -1) continue;
      if (S[v.r][v.c] != ROAD) continue;
      D[v.r][v.c] = D[u.r][u.c] + 1;
      Q.push(v);
      far = std::max(D[v.r][v.c], far);
    }
  }
  return far;
}

int main() {
  scanf(" %d%d", &H, &W);
  for (int i = 0; i < H; ++i) {
    scanf(" %s", S[i]);
  }
  int ret = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j] == ROAD) {
        ret = std::max(bfs({i, j}), ret);
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    LL n,m;
    vector<LL> x,y;
    Problem(LL n, LL m):n(n),m(m),x(n),y(m){};

    void solve(){
        LL xx=0,yy=0;
        for(int i=0; i<n; ++i){
            cin >> x[i];
        }
        for(int i=0; i<m; ++i){
            cin >> y[i];
        }
        for(int i=0; i<n-1; ++i){
            xx=(xx+((x[i+1]-x[i])*(i+1)%MOD)*(n-1-i))%MOD;
        }
        for(int i=0; i<m-1; ++i){
            yy=(yy+((y[i+1]-y[i])*(i+1)%MOD)*(m-1-i))%MOD;
        }
        DBG(xx,yy)
        cout << (xx*yy)%MOD <<"\n";

    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0,m;
    cin >> n >> m;
    Problem p(n,m);
    p.solve();
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  string S;
  cin >> S;
  string T;
  cin >> T;

  int ans = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] != T[i]) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3860
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

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

int main(){
    string A;
    string B;
    string C;
    cin>>A>>B>>C;
    cout<<A[0]<<B[1]<<C[2]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll NIL = (-1)*(pow(2, 63) - 1);
struct Node {
    ll key = NIL;
    int p = -1, l = -1, r = -1; // p, l, r is all id
};
Node u[500000];
int id, root;
void insert(int node){
    int y = u[node].p, x = root;
    while(x != -1 && u[x].key != NIL){
        y = x;
        if(u[node].key < u[x].key)x = u[x].l;
        else x = u[x].r;
    }
    u[node].p = y;

    if(y == -1)root = node;
    else if(u[node].key < u[y].key)u[y].l = node;
    else u[y].r  = node; 
}
void inorder(int node){
    if(u[node].l != -1)inorder(u[node].l);
    if(u[node].r != -1) {
        cout << " " << u[node].key;
        inorder(u[node].r);
        return;
    }
    cout << " " << u[node].key;
    return;
}
void preorder(int node){
    cout << " " << u[node].key;
    if(u[node].l == -1 && u[node].r == -1)return;
    if(u[node].l != -1)preorder(u[node].l);
    if(u[node].r != -1)preorder(u[node].r);
}
int main(){
    root = -1;
    ll n; cin >> n;
    rep(i,n){
        string com;
        ll v;
        cin >> com;
        if(com == "insert"){
            cin >> v;
            u[id].key = v;
            insert(id++);
        }
        else {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    string num;
    for (int i = 0; i < N; i++) {
        num += 'a';
    }
    for (int i = 0; i < M; i++) {
        int s;
        char c;
        cin >> s >> c;
        if (s == 1 && c == '0' && N != 1) {
            num = "-1";
            break;
        }
        if (num[s - 1] == 'a') {
            num[s - 1] = c;
        }
        if (num[s - 1] != c) {
            num = "-1";
            break;
        }
    }
    if (num != "-1") {
        for (int i = 0; i < N; i++) {
            if (num[i] == 'a') {
                num[i] = '0';
                if (i == 0 && N != 1) {
                    num[i] = '1';
                }
            }
        }
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string S;
ll K, box1 = 0, box2 = 0, box3 = 0;;

int main() {
	cin >> S;
	cin >> K;
	if (sz(S) == 1) {
		cout << K / 2 << endl;
		return 0;
	}
	S += S + S;
	for (int i = 1; i < sz(S); i++) {
		if (S[i - 1] == S[i]) {
			if (i < sz(S) / 3) {
				box1++;
				i++;
			}
			else if (i < sz(S) * 2 / 3) {
				box2++;
				i++;
			}
			else {
				box3++;
				i++;
			}
		}
	}
	if (K % 2 == 0) {
		cout << box1 + box2 * K / 2 + box3 * (K / 2 - 1) << endl;
	}
	else {
		cout << box1 + (box2 + box3) * (K / 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200100],b[200500];
int main()
{
	int n,i;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i]-i;
	}
	sort(b+1,b+1+n);
	int tmp=(n+1)/2,minnum=b[tmp];
	long long ans=0;
	for (i=1;i<=n;i++)
	    ans+=abs(minnum-b[i]);
	//cout << minnum << endl;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var s = Console.ReadLine();
            var result = 0L;

            for (int bit = 0; bit < (1 << s.Length - 1); bit++)
            {
                var st = s;

                for (int i = 0; i < s.Length - 1; i++)
                {
                    if ((bit & (1 << i)) == 0) continue;

                    var c = i + st.Count(x => x == '+') + 1;

                    st = st.Substring(0, c) + "+" + st.Substring(c, st.Length - c);
                }

                result += st.Split('+').Sum(x => long.Parse(x));
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 11348