akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define print(val) print_helper(#val, val);
#define bg begin
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int32_t,int32_t>
#define loop(i,n) for(int64_t i=0; i<n; i++)
#define loop1(i,a,b) for(int64_t i=a; i<=b; i++)
#define rloop(i,n) for(int64_t i=n-1; i>=0; i--) 
#define rloop1(i,a,b) for(int64_t i=a; i>=b; i--) 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void err() {cout << "-1\n";}
template <typename T>
void print_c(T & a) {
for_each(begin(a),end(a),[](auto & i){cout << i << " ";}); cout << "\n"; }
template <typename T, typename V>
void fill(T & collection, V val) {fill(begin(collection),end(collection),val);}
template <typename T>
void print_helper(string name, T val) {cout << name << ": " << val << "\n";}

int main() {
  fast_io
  int n; cin >> n;
  vector<ll> vec(n+1);
  fill(vec,0);
  loop(i,n-1) {
    int a;
    cin >> a;
    vec[a]++;
  }
  loop1(i,1,n) {
    cout << vec[i] << "\n";
  }
}


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

int main(){
	map<int,int> mp;
	
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	
	int ans=0;
	
	/*
	for(int i=0;i<n;i++){
		if(a[i]<mp[a[i]]){
			ans+=mp[a[i]]-a[i];
		}else if(a[i]>mp[a[i]]){
			ans+=mp[a[i]];
		}
	}
	*/
	
	for(auto &el:mp){
		if(el.first<el.second){
			ans+=el.second-el.first;
		}else if(el.first>el.second){
			ans+=el.second;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main()
{
	vector<int> v, c;
	int n, x, ans = 0;
  cin>>n;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		v.push_back(x);
	}
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		c.push_back(x);
	}
	for (int i = 0; i < n; i++)
	{
		if (v[i] > c[i])
			ans += v[i] - c[i];
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int uf[100100], r[100100];

void init(int n){
  rep(i,n)uf[i] = i, r[i] = 0;
}

int find(int a){
  if(uf[a] == a)return a;
  return uf[a] = find(uf[a]);
}

void unite(int a,int b){
  a = find(a); b = find(b);
  if(a==b)return;
  if(r[a] < r[b])uf[a] = b;
  else{
    uf[b] = a;
    if(r[a] == r[b])r[b]++;
  }
}

ll pow(ll a, ll n){
  ll res = 1;
  while(n){
    if(n&1)(res *= a) %= mod;
    (a *= a) %= mod; n>>=1;
  }
  return res;
}

int n,m,a,b;

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

  while(cin >> n >> m, n){
    init(n);

    rep(i,m){
      cin >> a >> b; a--; b--;
      unite(a,b);
    }

    map<int,int> g;
    rep(i,n)g[find(i)]++;
    
    ll ans = pow(2,g.size());
    for(map<int,int>::iterator it=g.begin();it!=g.end();it++){
      if(it->second != 1){
	ans++; ans %= mod;
	break;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 6664
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin >>a >>b ;
    if (a >b ){
        cout <<"a > b"<< endl;
    }else{
        if (a<b){
            cout << "a < b" <<endl;
        }else{
            cout << "a == b" <<endl;
        }
    }
}



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

int main(void){
    int a, b;
    char op;
    
    while(1){
        cin >> a >> op >> b;
        if(op == '?') break;
        
        if(op == '+') cout << a + b << endl;
        else if(op == '-') cout << a - b << endl;
        else if(op == '*') cout << a * b << endl;
        else if(op == '/') cout << a / b << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	int sum=0,a=0;
	rep(i,0,n){
		int b; cin>>b;
		chmax(a,b);
		sum+=b;
	}
	int k=sum-a;
	if(k>a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<fstream>
using namespace std;
#define ll long long
#define abs(n) (n < 0 ? -1 * (n) : (n))
int n, a;
vector<int> x(50);
vector<vector<ll>> m(51, vector<ll>(5002, -1));

ll ave(int i, int s)
{
    if(i == n) return 0;
    s += x[i];
    int sp0 = (s >= 0 ? s : abs(s) + 2500),
        smx = (s-x[i] >= 0 ? s-x[i] : abs(s-x[i]) + 2500);
    if(m[i+1][sp0] < 0) m[i+1][sp0] = ave(i+1, s);
    if(m[i+1][smx] < 0) m[i+1][smx] = ave(i+1, s-x[i]);
    ll k = m[i+1][sp0] + m[i+1][smx];
    //ll k = ave(i+1, s) + ave(i+1, s-x[i]);
    if(s == 0) k += 1;
    return k;
}

int main()
{
    cin >> n >> a;
    for(int i = 0; i < n; i++){
        cin >> x[i];
        x[i] -= a;
    }
    cout << ave(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,n,res=0,j;
    cin>>n;
    ll a[n+10];
    for(i=1; i<=n; i++)
        cin>>a[i];
    for(i=1;i<=n;)
    {
         for(j=i+1;j<=n;j++)
         {
             if(a[j]>a[j-1])break;
         }
         res = max(res,(j-i)-1);
         i=j;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include<iomanip>
using namespace std;

int N, K;

int main() {
    cin >> N >> K;
    int M = (N - 1) * (N - 2) / 2 - K;
    if (M < 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << (N - 1) + M << endl;
    for (int i = 1; i < N; i++) {
        cout << 1 << ' ' << i + 1 << endl;
    }
    for (int i = 2; i < N && M; i++) {
        for (int j = i + 1; j <= N && M; j++) {
            cout << i << ' ' << j << endl;
            --M;
        }
    }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
input = lambda: sys.stdin.readline()[:-1]
n,q=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n-1)]
px=[tuple(map(int,input().split())) for i in range(q)]
# ab.sort(key=lambda tup:(tup[0],tup[1]))

cnt=[0]*(n+1)
data=[[] for i in range(n+1)]

for i in ab:
	data[i[0]].append(i[1])
	data[i[1]].append(i[0])
for j in px:
	cnt[j[0]]+=j[1]


stack=[(1,0)]

while stack:
	v,parent=stack.pop()
	for to in data[v]:
		if to == parent:
			continue
		cnt[to]+=cnt[v]
		stack.append((to,v))

	
print(*cnt[1:])

Measured memory_bytes: 99616
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

int main(void) {

    ios::sync_with_stdio(false); cin.tie(0);

    string s;
    cin >> s;

    int n = s.size();

    string KEY = "keyence";
    bool ok = false;

    for (int i = 0; i <= 7; i++) {
        string mae = "", ushi = "";
        rep (j, i) {
            mae += s[j];
        }
        rep (j, 7 - i) {
            ushi = s[n - j - 1] + ushi;
        }
        string tmp = mae + ushi;
        if (tmp == KEY) ok = true;
    }

    if (ok) YES()
    else NO()
    return 0;
}

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

a_rui = []

tmp = 0

for i in range(n):
    tmp += a[i]
    a_rui.append(tmp)
    
ans = 10**20
#print(a_rui)
for i in range(n-1):
    #print(a_rui[i],a_rui[n-1] - a_rui[i])
    ans = min(ans,abs(a_rui[i]-(a_rui[n-1] - a_rui[i]) ) )
    
print(ans)

Measured memory_bytes: 24812
#include <stdio.h>
#include "string.h"
int main(int argc, char const *argv[]) {
  int a,c=0,p=0,i,n,m,b[100010]={};
  char s[3];
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %s",&a,s);
    if(b[a]==-1){
      continue;
    }
    if(s[0]=='W'){
      b[a]++;
    }else{
      p+=b[a];
      b[a]=-1;
      c++;
    }
  }
  printf("%d %d\n",c,p);
  return 0;
}


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

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

int main()
{
    int N;
    cin >> N;
    set<int> s;
    vector<int> num(1e+6+1, 0);
    REP(i, N){
        int A;
        cin >> A;
        s.insert(A);
        ++num[A];
    }

    int ans = 0;
    vector<bool> divide(1e+6+1, false);
    for(auto v: s){
        if(!divide[v] and num[v] == 1) ++ans;
        int tmp = v;
        for(int j = 1; tmp <= 1e+6; ++j){
            tmp = v*j;
            // if(divide[tmp]) break;
            divide[tmp] = true;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> X(N);
    for (int i=0; i<N; ++i) {
        cin >> X.at(i);
    }
    vector<int> sortedX(N);
    copy(X.begin(), X.end(), sortedX.begin());
    sort(sortedX.begin(), sortedX.end());
    for (const int Xi: X) {
        if (Xi < sortedX[N/2])
            cout << sortedX[N/2] << '\n';
        else
            cout << sortedX[N/2-1] << '\n';
    }
}


Measured memory_bytes: 3712
/**
 * Problem: test.cpp
 * Author: babhishek21
 * Lang: C++11
 */

#include <bits/stdc++.h> // using GCC/G++
// #include "custom/prettyprint.hpp" // G++11 only
using namespace std;

static const int MOD = 1000000007;
static const int INF = 0x3f3f3f3f;
static const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
#define pb push_back
#define eb emplace_back
#define mp make_pair

#define debug(x) cerr << #x << " : " << x << endl;
#define whole(func, x, ...) ([&](decltype((x)) var) { return (func)(begin(var), end(var), ##__VA_ARGS__); })(x)

int h[100010];
long long arr[100010];

int main() {
  // ios_base::sync_with_stdio(false); // for fast I/O

  int n, k;

  cin >> n >> k;

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

  arr[0] = 0;

  for(int i=1; i<n; i++)
    for(int j=1; j<=k && i-j >= 0; j++)
      arr[i] = min(arr[i], arr[i-j] + abs(h[i] - h[i-j]));

  cout << arr[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll ans = max({a*c,a*d,b*c,b*d});
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    long double x = (long double) n / 3;
    cout << fixed << setprecision(9) << (long double) x * x * x;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	int x;
	vi a(n + 1);
	a[0] = 0;
	rep2(i, 1, n) {
		cin >> x;
		a[i] += a[i - 1] + x;
	}
	vi b(n + 1);
	b[0] = 0;
	rep2(i, 1, n) {
		cin >> x;
		b[i] += b[i - 1] + x;
	}
	int ans = 0;
	rep2(i, 1, n) {
		x = a[i] + (b[n] - b[i - 1]);
		ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("Yes");
#define PN printf("No");
#define Py printf("yes");
#define Pn printf("no");
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int N;

int main() {
	S(N);
	int n = N % 10;
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) printf("hon");
	else if (n == 0 || n == 1 || n == 6 || n == 8) printf("pon");
	else printf("bon");
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s ;
  cin >> s;
  
  s[n]=s[0];
  string t[4]={"SS","SW","WS","WW"};
  
  for(int i=0;i<4;i++){
    for(int j=1;j<n+1;j++){
      if(t[i].substr(j-1,2)=="SS"){
        if(s[j]=='o'){
          t[i]+='S';
        }
        else{
          t[i]+='W';
        }
      }
      if(t[i].substr(j-1,2)=="SW"){
        if(s[j]=='o'){
          t[i]+='W';
        }
        else{
          t[i]+='S';
        }
      }
      if(t[i].substr(j-1,2)=="WS"){
        if(s[j]=='o'){
          t[i]+='W';
        }
        else{
          t[i]+='S';
        }
      }
      if(t[i].substr(j-1,2)=="WW"){
        if(s[j]=='o'){
          t[i]+='S';
        }
        else{
          t[i]+='W';
        }
      }
    }
    if(t[i].substr(0,2)==t[i].substr(n,2)){
      cout << t[i].substr(0,n) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

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

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

const ll MOD = 1000000007;
const ll INF = 10000000;

int n;

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


    if (abs(a - b) <= 8 - min(a, b)) cout << "Yay!" << endl;
    else cout << ":(" << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    int i;
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (i = 0; i < n; i++)
    {
        printf("%d", a[i]);
        if (i < n - 1)
            printf(" ");
        }
    printf("\n");
    for (i = 1; i <= n - 1; i++)
    {
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v)
        {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        int s;
        for (s = 0; s < n; s++)
        {
            printf("%d", a[s]);
            if (s < n - 1)
            {
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, k;
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3640
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: i
    character(3):: s(3),ans


    do i=1,3
        read*, s(i)
    end do

    do i=1,3
        ans(i:i) = s(i)(i:i)
    end do

    print'(a)', ans
end program main

Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))
result = sum(a)

for i in range(1, n):
    if a[i-1]+a[i] > x:
        dif = a[i-1]+a[i]-x
        if dif <= a[i]:
            a[i] -= dif
        else:
            a[i-1] -= dif-a[i]
            a[i] = 0
print(result-sum(a))

Measured memory_bytes: 14132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)


int main(){
  char n;
  string s;
  cin >> n;
  cout << char(n+1) << endl;
  
   
   return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

#define MAX_L (20010)

char s[MAX_L];
int main()
{
    int max_h = 0;
    int cur = 0;
    int index = 0;
    queue<int> part;
    queue<int> lake_left;
    stack<int> lake_right;
    int num_lake = 0;
    int total_area = 0;
    int index_max = 0;
    int index_last = 0;
    scanf("%s", s);

    while ( s[index_last] != 0 ) {
	if ( s[index_last] == '\\' ) {
	    cur--;
	}
	else if ( s[index_last] == '/' ) {
	    cur++;
	    if ( cur > max_h ) {
		index_max = index_last;
		max_h = cur;
	    }
	}
	index_last++;
    }
    index_last--;

    cur = 0;
    max_h = 0;

    while ( index <= index_max ) {
	if ( part.empty() ) {	// ????????´???
	    if ( s[index] == '\\' && cur == max_h ) {
		cur--;
		part.push(cur);
	    }
	    else if ( s[index] == '/' ) {
		cur++;
		max_h = max( max_h, cur );
	    }
	}
	else {
	    if ( s[index] == '\\' ) {
		cur--;
	    }
	    else if ( s[index] == '/' ) {
		cur++;
		max_h = max( max_h, cur );
	    }
	    part.push(cur);

	    if ( cur == max_h ) {
		int part_area = 0;
		while ( !part.empty() ) {
		    int pre = part.front(); part.pop();
		    part_area += ( cur - pre );
		}
		total_area += part_area;
		if ( part_area ) {
		    lake_left.push( part_area );
		    num_lake++;
		}
	    }
	}
	index++;
    }

    max_h = 0;
    cur = 0;
    while ( !part.empty() ) {
	part.pop();
    }
    index = index_last;

    while ( index >= index_max ) {
	if ( part.empty() ) {	// ????????´???
	    if ( s[index] == '/' && cur == max_h ) {
		cur--;
		part.push(cur);
	    }
	    else if ( s[index] == '\\' ) {
		cur++;
		max_h = max( max_h, cur );
	    }
	}
	else {
	    if ( s[index] == '/' ) {
		cur--;
	    }
	    else if ( s[index] == '\\' ) {
		cur++;
		max_h = max( max_h, cur );
	    }
	    part.push(cur);

	    if ( cur == max_h ) {
		int part_area = 0;
		while ( !part.empty() ) {
		    int pre = part.front(); part.pop();
		    part_area += ( cur - pre );
		}
		total_area += part_area;
		if ( part_area ) {
		    lake_right.push( part_area );
		    num_lake++;
		}
	    }

	}
	index--;
    }


    printf("%d\n", total_area);
    printf("%d", num_lake);

    while ( !lake_left.empty() ) {
	printf(" ");
	printf("%d", lake_left.front());
	lake_left.pop();
    }

    while ( !lake_right.empty() ) {
	printf(" ");
	printf("%d", lake_right.top());
	lake_right.pop();
    }

    printf("\n");

    return 0;
}

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

const int N = 2e5+5, MOD = 998244353;
int n, m, k, p[N];

int mul(int x, int y) {
    ll tmp = 1LL * x * y;
    return tmp % MOD;
}
int add(int x, int y) {
    ll tmp = 1LL*x + 1LL*y;
    return tmp % MOD;
}
int pow(int x, int e) {
    int res = 1;
    for(; e; e>>=1) {
        if(e&1) res = mul(res, x);
        x = mul(x, x);
    }
    return res;
}
int inv(int x) {
    return pow(x, MOD-2);
}
int C(int x, int y) {
    int det = mul(p[x], p[y-x]);
    return mul(p[y], inv(det));
} 
void preprocess() {
    p[0] = 1;
    for(int i=1; i<N; i++)
        p[i] = mul(p[i-1], i);
}
int main() {
    preprocess();
    cin >> n >> m >> k;
    int ans = 0;
    for(int t=n-k; t<=n; t++) {
        int tmp = mul(m, pow(m-1, t-1));
        tmp = mul(tmp, C(n-t, n-1));
        ans = add(ans, tmp);
    }
    cout << ans;
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 200001
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int r[MAX/2+2],l[MAX/2+2];

ll merge(int a[],int left,int mid,int right){
    int n1=mid -left;
    int n2=right-mid;
    long long int cnt=0;
    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]=r[n2]=sentinel;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(l[i]<=r[j]){
            a[k]=l[i];
            i++;
        }else{
            a[k]=r[j];
            j++;
            cnt+=n1-i;
        }
    }
    return cnt;
}

ll mergesort(int a[],int left,int right){
    int mid=(left+right)/2;
    ll v1,v2,v3;
    if(right-left>1){
        v1=mergesort(a,left,mid);
        v2=mergesort(a,mid,right);
        v3=merge(a,left,mid,right);
        return v1+v2+v3;
    }else return 0;
}

int main() {
    int a[MAX],n;
    ll cnt;
    cin>>n;
    rep(i,n) cin>>a[i];
    cnt=mergesort(a,0,n);
    cout<<cnt<<endl;
}



Measured memory_bytes: 4608
#include <stdio.h>
int main(void){
    // Your code here!
    long int N;
    long int A[100002],B[100002]={0};
    long int power;
    long int sum;
    scanf("%ld\n",&N);

    int i;
    
    for(i=1;N+1>=i;i++){
        scanf("%ld",&A[i]);
    }
    for(i=1;N>=i;i++){
        scanf("%ld",&B[i]);
    }
    
    sum = 0;
    
    if(A[1]>B[1]){
        sum += B[1];
        power = 0;
    }
    else{
        sum += A[1];
        power = B[1] - A[1];
    }
    
    for(i=2;N+1>=i;i++){
        if(A[i]>power){
           A[i]-= power;
           sum += power;
        }  
        else{
            sum += A[i];
            A[i] = 0;
            
        }
        
        if(A[i]>B[i]){
            sum += B[i];
            power = 0;
        }
        else{
            power = B[i] - A[i];
            sum += A[i];
        }
    }
    
    printf("%ld\n",sum);
    return 0;

}


Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long int
using namespace std;
const int INF = 1000000;
const int MAX_N = 300;

int main() {
  // 入力
  int N;
  cin >> N;
  
  ll a[N][N];
  rep(i,N){
    rep(j,N){
      cin >> a[i][j];
    }
  }
  
  bool f = false;
  ll ans = 0;
  // 
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      ll mi = 2000000000LL;
      for (int k = 0; k < N; k++) {
        if(k==i||k==j)continue;
        if(mi>a[i][k]+a[k][j])mi = a[i][k]+a[k][j];
        if(a[i][j] > a[i][k]+a[k][j]) f = true;
      }
      if(a[i][j] < mi) ans += a[i][j];
    }
  }
  
  
  if(!f){
    printf("%lld\n", ans);
  }else{
    printf("%d\n", -1);
  }
  return 0;
}

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

int main(){
  int N, M;
  cin >>N >>M;
  vector<int> L(M);
  vector<int> R(M);
  for(int t =0;t<M;t++){
    cin >>L.at(t) >>R.at(t);
  }
  //以上入力
  int Lmax, Rmin;
  Lmax=L.at(0);
  Rmin=R.at(0);
  for(int t = 0;t<M;t++){
    if(L.at(t)>Lmax){
      Lmax = L.at(t);
    }
  }
  for(int t = 0;t<M;t++){
    if(R.at(t)<Rmin){
      Rmin = R.at(t);
    }
  }
  int ans;
  if(Rmin>=Lmax){
    ans = Rmin-Lmax+1;
  }else{
    ans=0;
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 1024
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

const int MAXN = 3e3 + 7;

int n;
ll C[MAXN][MAXN], S[MAXN][MAXN], HA, _2[MAXN];

ll fp(ll a, ll b, ll p) {
	ll r = 1;
	while (b) {
		if (b & 1) r = r * a % p;
		b >>= 1, a = a * a % p;
	}
	return r;
}

int main() {
	scanf("%d %lld", &n, &HA);
	S[0][0] = C[0][0] = 1;
	rep(i, 1, n + 2) {
		C[i][0] = 1;
		rep(j, 1, i) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % HA, S[i][j] = (S[i - 1][j - 1] + j * S[i - 1][j] % HA) % HA;
	}

	ll ans = 0;
	rep(i, 0, n) {
		ll gx = 0, f22 = fp(2, fp(2, n - i, HA - 1), HA), fn = 1, base = fp(2, n - i, HA);
		rep(j, 0, i) gx = (gx + S[i + 1][j + 1] * f22 % HA * fn % HA) % HA, fn = fn * base % HA;
		gx = gx * C[n][i] % HA;
		if (i & 1) ans = (ans + HA - gx) % HA;
		else ans = (ans + gx) % HA;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 139904
@1=map$-=$_-2,@0=1..<>+2;--$0[-1];map$\+=$'*($$_[$N=$$_[$`]]-($$_[$P=${1-$_}[$`]]=$N))*($`-$P),/\t/,0for`tr ' ' '
'|nl|sort -nk2`;print

Measured memory_bytes: 42236
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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 stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



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

  ll x, y;
  cin >> x >> y;

  rep(i, 0, x+1) rep(j, 0, x+1){
    if(i + j == x && i*2 + j*4 == y){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3668
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		for(;;){
			if(!sc.hasNextInt()){
				break;
			}
			int a = sc.nextInt();
			int b = sc.nextInt();
			int ta = a;
			int tb = b; 
			for(;;){
				if(a==b)break;
				if(a>b){
					a-=b;
				}else{
					b-=a;
				}
				
			}
			int gcd =  a;
			int lcm = ta/a * tb;
			System.out.println(gcd + " "+lcm);
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
		
	}
}

Measured memory_bytes: 12000
import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner sc=new Scanner(System.in);
    	while(true) {
    		int H=sc.nextInt();
    		int W=sc.nextInt();
    		if(W==0&&H==0)break;
    		for(int i=0;i<H;i++) {
    			for(int j=0;j<W;j++) {
    				if((i+j)%2==0) System.out.printf("#");
    				else System.out.printf(".");
    			}
    			System.out.printf("\n");
    		}
    		System.out.printf("\n");
    	}
        sc.close();
    }
}



Measured memory_bytes: 62336
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	string s;
	cin >> s;

	int f = 0;
	each(c, s) {
		if (c == 'C') {
			f = 1;
		}
		if (c == 'F' && f) {
			f = 2;
		}
	}
	if (f == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e3 + 11;
int n, K;
int f[22][N], C[N][N], a[N];
inline int A(int x, int y){
    return x + y - (x + y >= mod ? mod : 0);
}
inline int M(int x, int y){
    return 1LL * x * y % mod;
}
int main(){
    C[0][0] = 1;
    for(int i = 1;i <= 1000; i++){
        C[i][0] = 1;
        for(int j = 1;j <= 1000; j++)
            C[i][j] = A(C[i-1][j], C[i-1][j-1]);
    }
    cin>>n>>K;
    for(int i = 1;i <= K; i++){
        cin>>a[i];
    }
    f[0][0] = 1;
    for(int i = 0;i < K; i++){
        for(int j = 0;j <= n; j++){
            for(int k = 0;j + k <= n; k++){
                if(k <= a[i+1])
                    f[i+1][j+k] = A(f[i+1][j+k], M(f[i][j], M(C[n-j][k], C[n-k][a[i+1]-k])));
            }
        }
    }
    cout<<f[K][n]<<endl;
    return 0;
}


Measured memory_bytes: 4352
#include <stdio.h>

int main()
{
        int a;
        int b;
        int c;
        int n;
        int i = 0;
        int j = 0;
        int ans[1000] = {}; 
        scanf("%d\n", &n);
        while (scanf("%d %d %d\n", &a, &b, &c) != EOF)
        {   
                if (a*a+b*b==c*c || b*b+c*c==a*a || a*a+c*c==b*b)
                        ans[i] = 1;
                i++;    
        }   
        for(j = 0; j < i; j++)
        {   
                if(ans[j]==1)
                        printf("YES\n");
                else
                        printf("NO\n");
        }   
        return (0);
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int a,b;cin>>a>>b&&a|b;){
		char x='.',y='#';
		if(a<b){
			swap(a,b);
			swap(x,y);
		}

		int h=100,w=100;
		vs grid(h,string(w,y));
		grid[0]=string(w,x);
		rep(i,w/2) grid[1][2*i+1]=x;

		a--,b--;
		repi(i,2,h) rep(j,w/2){
			if(b==0) goto end;
			grid[i][2*j+i%2]=x;
			a--,b--;
		}
		end:;

		rep(i,h/2) rep(j,w/2){
			if(a==0)
				goto end2;
			grid[h/2+i*2][2*j]=x;
			a--;
		}
		end2:;

		cout<<h<<' '<<w<<endl;
		rep(i,h) cout<<grid[i]<<endl;
	}
}


Measured memory_bytes: 256
function solve()
  n=parse(Int,readline())
  as=map(x->parse(Int,x),split(readline()))
  s=readline()
  t=Int[]
  ok=false
  for i=n:-1:1
    a=as[i]
    for b=t
      a=min(a,xor(a,b))
    end
    if a!=0
      if s[i]=='1'
        ok=true
      else
        push!(t,a)
      end
    end
  end
  println(ok ? 1 : 0)
end
t=parse(Int,readline())
for _=1:t
  solve()
end

Measured memory_bytes: 167192
def main():
    S = input()
    T = input()
    anss = []
    #Sを全文字調べる
    for i in range(len(S)):
        #s文字目からTが始められるかどうか調べる
        #始められるならTを進めていき当てはまるか調べる
        flag = True
        for j in range(len(T)):
            if i + j >= len(S):
                flag = False
                break
            if S[i + j] == "?":
                continue
            if S[i + j] != T[j]:
                flag = False
                break
        if flag == True:
            a = list(S)
            a[i:i + len(T)] = list(T)
            for k in range(len(S)):
                if a[k] == "?":
                    a[k] = "a"
            anss.append("".join(a))
    if anss == []:
        print("UNRESTORABLE")
    else:
        anss = sorted(anss)
        print(anss[0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());

        // 主処理
        long result = (long) Math.pow(k - 1, n - 1) * k;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23504
#include <bits/stdc++.h>
//#define DEBUG
#define REP( i , nn ) for(int i = 0 ; i < (int) nn; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve(){
    int n;
    cin >> n;
    vi b(n);
    REP(i,n) cin >> b[i];
    //clean b
  
    int sum = b[0];
    for(int i = 1 ; i < n - 1 ; i++){
        sum += min(b[i-1], b[i]);
    }
    sum += b[n-2];
    cout << sum << "\n";
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

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

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
  int n; cin >> n;
  vector <long long> lucas(max(n + 1, 2));
  lucas[0] = 2;
  lucas[1] = 1;
  for (int i = 2; i <= n; ++i)
  lucas[i] = lucas[i - 1] + lucas[i - 2];

  cout << lucas[n] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,x[110];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	for(i=1,k=0;i<=n;i++)
	  {
	   scanf("%d",&j);
	   x[j]++;
	   k=max(k,j);
	  }
	for(i=k,j=k+1;j>0;i--,j-=2)
	  if(x[i]<min(j,2) || j<=2 && x[i]>min(j,2))
	    {
	     printf("Impossible\n");
	     return 0;
		}
	for(;i>0;i--)
	  if(x[i])
	    {
	     printf("Impossible\n");
	     return 0;
		}
	printf("Possible\n");
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

h_lines = {}
v_lines = {}

for _ in range(N):
	a, b, c = map(int, input().split())
	if c in v_lines:
		v_lines[c].append((a, b))
	else:
		v_lines[c] = [(a, b)]

for _ in range(M):
	d, e, f = map(int, input().split())
	if d in h_lines:
		h_lines[d].append((e, f))
	else:
		h_lines[d] = [(e, f)]

h_lines = list(h_lines.items())
v_lines = list(v_lines.items())

h_lines.sort()
v_lines.sort()

rows = len(v_lines) - 1
cols = len(h_lines) - 1

h_walls = [[False] * rows for _ in range(cols + 1)]
v_walls = [[False] * (rows + 1) for _ in range(cols)]

for i, (y, l) in enumerate(h_lines):
	for x1, x2 in l:
		j = 0
		while j < rows:
			if x1 <= v_lines[j][0]:
				break
			j += 1
		while j < rows:
			if x2 < v_lines[j + 1][0]:
				break
			h_walls[i][j] = True
			j += 1

for j, (x, l) in enumerate(v_lines):
	for y1, y2 in l:
		i = 0
		while i < cols:
			if y1 <= h_lines[i][0]:
				break
			i += 1
		while i < cols:
			if y2 < h_lines[i + 1][0]:
				break
			v_walls[i][j] = True
			i += 1

#for i in range(cols + 1):
#	print("+" + "+".join("--" if f else "  " for f in h_walls[i]) + "+")
#	if i < cols:
#		print("  ".join("|" if f else " " for f in v_walls[i]))

def find_initial_pos():
	for i in range(cols):
		if h_lines[i][0] <= 0 and 0 <= h_lines[i + 1][0]:
			for j in range(rows):
				if v_lines[j][0] <= 0 and 0 <= v_lines[j + 1][0]:
					return (i, j)
	return None

def calc_area():
	cur = find_initial_pos()
	if cur == None:
		return "INF"
	stack = [cur]
	area = 0
	visited = [[False] * rows for _ in range(cols)]
	visited[cur[0]][cur[1]] = True
	
	search = (
		( 1,  0, lambda y, x: not h_walls[y + 1][x]),
		(-1,  0, lambda y, x: not h_walls[y][x]),
		( 0,  1, lambda y, x: not v_walls[y][x + 1]),
		( 0, -1, lambda y, x: not v_walls[y][x]),
	)
	
	while stack:
		y, x = stack.pop()
		area += (h_lines[y + 1][0] - h_lines[y][0]) * (v_lines[x + 1][0] - v_lines[x][0])
#		print(area, y, x)
		for dy, dx, check in search:
			if check(y, x):
				ny = y + dy
				nx = x + dx
#				print(">", ny, nx)
				if nx < 0 or nx >= rows or ny < 0 or ny >= cols:
					return "INF"
				if not visited[ny][nx]:
					stack.append((ny, nx))
					visited[ny][nx] = True
	
	return str(area)

print(calc_area())


Measured memory_bytes: 100652
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

ll par[100000]; // par[i]... iの親
ll mem[100000]; // iの(自分も含めた) 子の構成島数

ll root(ll x) {
    // 自身が親と同一の時まで再帰的にrootをたどる
    if(par[x]==x) return x;
    else {
      return root(par[x]);
    }
}

void unite(ll x, ll y) {
  ll rx = root(x);
  ll ry = root(y);
  if(rx==ry) return;
  else {
    if(rx>ry) {
      ll tmp = rx;
      rx = ry;
      ry = tmp;
    }
    mem[ry] += mem[rx];
    par[rx] = ry;
    return;
  }
}

int main() {
  ull N, M;
  cin >> N >> M;
  ull A[M], B[M];
  rep(i, M) {
    ull a, b;
    cin >> a >> b;
    A[i] = a-1;
    B[i] = b-1;
  }

  /* Uion-find というデータ構造を使えば処理時間を短縮できるらしい */
  // cf. https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396
  // cf. https://atc001.contest.atcoder.jp/tasks/unionfind_a

  rep(i, N) par[i] = i; // 最初は全て自分が親
  rep(i, N) mem[i] = 1;

  ////////////////////

  ull ans[M]; // ans
  ans[M-1] = N*(N-1)/2; // 全ての橋が崩壊した時の不便さ
  for(ll i=M-1; i>0; i--) {
    ll ra = root(A[i]);
    ll rb = root(B[i]);
    if(ra==rb) ans[i-1] = ans[i];
    else {
      ans[i-1] = ans[i] - mem[ra]*mem[rb];
      // cout << "log:" << ans[i-1] << endl;
      // cout << "A, B " << A[i] << ' ' << B[i] << endl;
      // cout << "rA, rB " << root(A[i]) << ' ' << root(B[i]) << endl;
      // cout << "mrA, mrB " << mem[root(A[i])] << ' ' << mem[root(B[i])] << endl;
      unite(rb, ra);
    }
  }

  rep(i, M) {
    cout << ans[i] << endl;
  }

  return 0;
}


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

using namespace std;

int main()
{
	int n;cin>>n;
	vector<int> v(n);

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

	long long money=1000;
	long long stocks = 0;

	/*stocks = (money/v[0]);
	money = money - (stocks*v[0]);*/
	int buy=1,sell=0;

	for(int i=0;i<n-1;++i)
	{
		if(sell){
			if(v[i]>v[i+1]) {money+=(stocks*v[i]);
			stocks=0; sell=0;buy=1;}
		}
		else if(buy){
			if(v[i]<v[i+1])
			{
				stocks = (money/v[i]);
				money = money - (stocks*v[i]);
				sell=1;buy=0;
			}
		}
	}
	if(stocks > 0) money+=stocks*v[n-1];
	cout<<money;
}

Measured memory_bytes: 3600
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, D;
    cin >> N >> D;
    cout << (N + 2 * D) / (2 * D + 1);

    return 0;
}

Measured memory_bytes: 3648
def main():
    A, B = (int(i) for i in input().split())

    def trial_division(n):
        divs = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divs.append(i)
                if i != n//i:
                    divs.append(n//i)
        return set(divs)
    dA = trial_division(A)
    dB = trial_division(B)
    C = sorted(dA & dB)
    N = len(C)
    seen = [True]*(N)
    for i in range(1, N):
        for j in range(i+1, N):
            if seen[j] and C[j] % C[i] == 0:
                seen[j] = False
    print(seen.count(True))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40556
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}

ll N, D;
vector<vi> v;
bool f(int a, int b) {
	ll s = 0;
	rep(i, D) {
		s += pow(v[a][i] - v[b][i], 2);
	}
	if (pow((ll)(sqrt(s)), 2) == s) {
		return 1;
	}
	return 0;
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	cin >> N >> D;
	rep(i, N) {
		vi X(D);
		rep(j, D) {
			cin >> X[j];
		}
		v.push_back(X);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (f(i, j)) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
	string s;
  	cin >> s;
  	vector<int> vec(26);
  	for (char c : s) {
      vec[c-'A']++;
    }
  for (int x : vec) {
    if (x && x != 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;	
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

const ll mod = 1000000007;

vector<ll> knapsack_limitation(const vector<ll> & w, const vector<ll> & m, const vector<ll> & v, const ll weight) {
	const int inv = -1;
	const int n = w.size();
	vector<ll> dp(weight + 1, inv);
	dp[0] = 0;
	rep(i, n) {
		for (int a = 0; a < w[i]; a++) {
			deque<ll> ids, vals;
			for (int j = 0; w[i] * j + a <= weight; j++) {
				ll cw = w[i] * j + a;
				if (cw != inv) {
					ll val = dp[cw] - j * v[i];
					while (!vals.empty() && val > vals.back()) {
						ids.pop_back();
						vals.pop_back();
					}
					ids.push_back(j);
					vals.push_back(val);
				}
				if (ids.size()) {
					dp[cw] = vals.front() + j * v[i];
					if (ids.front() == j - m[i]) {
						ids.pop_front();
						vals.pop_front();
					}
				}
			}
		}
	}
	return dp;
}


int main(void)
{
	int N, W;
	cin >> N >> W;
	vector<ll> v(N), w(N), m(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i] >> w[i] >> m[i];
	}
	auto ret = knapsack_limitation(w, m, v, W);
	cout << *max_element(begin(ret), end(ret)) << endl;
}



Measured memory_bytes: 3288