akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
    #include <iostream>
    #include <map>
    #include <vector>
     
    int main() {
    	int N = 0;
    	std::string S1, S2;
     
    	std::cin >> N >> S1 >> S2;
     
    	/*
    	 *    xoo  x.o  xxo
    	 *    x..  x.o  ..o
    	 */
     
    	std::uint64_t count = 1;
    	std::uint64_t mod   = std::pow(10, 9) + 7;
     
    	for (int i = 0; i < N; ++i) {
    		if (S1[i] == S2[i]) {
    			if (i == 0) {
    				count *= 3;
    				count %= mod;
    			} else if (S1[i - 1] == S2[i - 1]) {
    				count *= 2;
    				count %= mod;
    			}
    		} else {
    			if (i == 0) {
    				count *= 6;
    				count %= mod;
    			} else if (S1[i - 1] == S2[i - 1]) {
    				count *= 2;
    				count %= mod;
    			} else {
    				count *= 3;
    				count %= mod;
    			}
    			++i;
    		}
    	}
     
    	std::cout << count << std::endl;
     
    	return 0;
    }

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

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long N, std::vector<std::string> s){
    rep(i,N){
        sort(all(s[i]));
    }
    sort(all(s));
    ll ans=0;
    string tmp;
    ll cnt=0;
    tmp=s[0];
    //rep(i,N)op(s[i])
    repf(i,1,N){
        if(tmp==s[i])cnt++;
        else{
            tmp=s[i];
            ans+=cnt*(cnt+1)/2;
            cnt=0;
        }
    }
    ans+=cnt*(cnt+1)/2;
    op(ans)
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> s(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
    }
    solve(N, std::move(s));
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,Y;
  int ii, jj, kk;
  cin >> N >> Y;
  bool F;
  F = false;
  for(int i = 0;i <= N;i++){
    for(int j = 0;j <= N - i;j++){
      if(Y == 10000 * i + 5000 * j + 1000 * (N - i - j)){
        F = true;
        ii = i;
        jj = j;
        kk = N - i - j;
        break;
      }
    }
    if(F) break;
  }
  if(F){
    cout << ii << ' ' <<jj << ' ' << kk << endl; 
  }
  else{
    cout << "-1 -1 -1" << endl; 
  }
}

Measured memory_bytes: 256
class Node
  attr_accessor :parent, :rank
  
  def initialize(n)
    @parent = n
    @rank = 0
  end
end

class UnionFindTree
  attr :ans

  def initialize(n)
    @nodes = (0..n).to_a.map { |i| Node.new(i) }
    @count = [1] * (n+1)
    @ans = n * (n-1) / 2
  end
  
  def find(x)
    return x if @nodes[x].parent == x
    
    return @nodes[x].parent = find(@nodes[x].parent)
  end
  
  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b
    
    if @nodes[a].rank < @nodes[b].rank
      @nodes[a].parent = b
    else
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
    @ans -= @count[a] * @count[b]
    tmp = @count[a] + @count[b]
    @count[a]=tmp
    @count[b]=tmp
  end

  def same?(a, b)
    find(a) == find(b)
  end
  
  def parents
    @nodes.map(&:parent)
  end
end

N,M=gets.chomp.split.map(&:to_i)
ab = []
M.times do
  ab.unshift(gets.chomp.split.map(&:to_i))
end
tree = UnionFindTree.new(N)
ans = []
ab.each do |a, b|
  ans.unshift(tree.ans)
  tree.unite(a,b)
end
ans.each do |v|
  puts v
end

Measured memory_bytes: 19400
/**

author:	©LoneWolfDON
Git: MahinHossainMunna

**/
/*

*/

#include <stdio.h>

int main()
{
    int S, W;

    scanf("%d%d", &S, &W);

    if(W >= S)
        printf("unsafe\n");
    else
        printf("safe\n");

    return 0;
}


Measured memory_bytes: 1660
#include "bits/stdc++.h"
//#include<iostream>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define fr(i , a , b) for(int  i = a ; i <= b ; i++)
#define all(v) v.begin() , v.end()
#define mod  1000000007
#define N 100005
#define mod1 1000000007
#define mod2 1000000009
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n" 
#define mid  (s+e)/2
#define MAX 10000007
//const int inf = (int)1e18 + 10;;
int dpa[N] , dpb[N] , dpc[N];
int a[N] , b[N] , c[N];
signed main(){
  fast;
  
  //freopen("input.txt" , "r" , stdin);
  //freopen("output.txt" , "w" , stdout);
  

    int n ;
    cin >> n ;
    for(int i = 0 ; i < n ; i++)
          cin >> a[i] >> b[i] >> c[i];



    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];
    for(int i = 1 ; i <n ; i++){
           dpa[i] = max(dpb[i-1]  , dpc[i-1]) + a[i];
           dpb[i] = max(dpc[i-1]  , dpa[i-1]) + b[i];
           dpc[i] = max(dpa[i-1]  , dpb[i-1]) + c[i];
           
    }

    cout << max(dpa[n-1] , max(dpb[n-1] , dpc[n-1])) << endl;

   

 }

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<string> wet = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;

    if (s == wet[0]) cout << wet[1] << endl;
    if (s == wet[1]) cout << wet[2] << endl;
    if (s == wet[2]) cout << wet[0] << endl;
}

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

int main() {
  long long N;
  cin >> N;
  string S;
  cin >> S;
  long long sum = 0;
  long long r_num = 0;
  long long g_num = 0;
  long long b_num = 0;
  for (long long i = 0; i < N; i++) {
    if (S[i] == 'R') {
      r_num++;
    } else if (S[i] == 'G') {
      g_num++;
    } else {
      b_num++;
    }
  }
  sum = r_num * g_num * b_num;

  for (long long i = 0; i < N - 2; i++) {
    for (long long j = i + 1; j < N - 1; j++) {
      if (2 * j - i < N) {
        if (S.at(i) != S.at(j) && S.at(i) != S.at(2 * j - i) &&
            S.at(j) != S.at(2 * j - i)) {
          sum--;
        }
      }
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define _USE_MATH_DEFINES
#include <cmath>

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

using namespace std;
typedef long long ll;

const int MAXN = 50;
const int NIL  = -1;

struct Node {
   int p, l, r;
};

Node T[MAXN];
int  P[MAXN], I[MAXN], root;
int  cnt = 0;

void postorder(int u) {
   if (T[u].l != NIL) postorder(T[u].l);
   if (T[u].r != NIL) postorder(T[u].r);
   if (cnt != 0) cout << " ";
   cout << u;
   cnt++;
}

void makeT(int u, int n, int head, int tail) {
   int p_place, i_place;

   rep(i, n) {
      if (P[i] == u)
         p_place = i;
      if (I[i] == u)
         i_place = i;
   }
   if (head != i_place) {
      T[u].l = P[p_place + 1];
      T[P[p_place + 1]].p = u;
      makeT(P[p_place + 1], n, head, i_place);
   }
   if (i_place + 1 != tail) {
      T[u].r = P[p_place + 1 + i_place - head];
      T[P[p_place + 1 + i_place - head]].p = u;
      makeT(P[p_place + 1 + i_place - head], n, i_place + 1, tail);
   }
}

int main() {
   int n;

   cin >> n;
   rep1(i, n) T[i].p = T[i].r = T[i].l = NIL;
   rep(i, n) cin >> P[i];
   rep(i, n) cin >> I[i];
   makeT(P[0], n, 0, n);

   rep1(i, n) {
      if (T[i].p == NIL) root = i;
   }
   postorder(root);
   cout << endl;
   return(0);
}



Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define max_n 100
string S, T;
int main()
{
    cin >> S >> T;
    int ans = 0;
    rep(i,3)
    {
        if(S.at(i)==T.at(i))
            ans++;
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						if (i + j + k + l == n)ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		char[] a;
		int p;
		int s;
		int t;
		char[] m;
		
		while(n-- != 0){
			a = new char[3000];
			p = 1500;
			s = 1500;
			t = 1500;
			
			m = scan.next().toCharArray();
			a[p] = m[0];
			
			for(int i = 1; i < m.length;i ++){
				if(m[i] == '-')p++;
				else p--;
				i += 2;
				s = Math.min(s, p);
				t = Math.max(t, p);
				a[p] = m[i];
			}
			
			for(int i = s; i <= t; i++){
				System.out.print(a[i]);
			}
			System.out.println();
		}
	}
}

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

using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);

    long long n;
    cin>>n;

    int ans = 0 ;

    for(long long int i = 2; i*i<=n; i++){
        int powercount = 0;

        if(n%i == 0){
            while(n%i == 0){
                powercount++;
                n /= i;
            }
        }
        ans += floor((-1 + sqrt(1+8*powercount))/2);
    }

    if(n>1) ans++;

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  string s;
  int n, count[55][50] = {};
  cin >> n;
  rep(i,n){
    cin >> s;
    rep(j,s.size()){
      count[i][s[j] - 'a'] ++;
    }
  }
  rep(i,26){
    int minv = count[0][i];
    reps(j,n - 1){
      minv = min(count[j][i], minv);
    }
    rep(j,minv){
      cout << (char)('a' + i);
    }
    //   cout << '\n';
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
import bisect
from collections import defaultdict


def in_sort(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


def main():
    s = input()
    t = input()

    c_idx = defaultdict(list)

    for i, c in enumerate(s):
        c_idx[c].append(i)

    idx = -1
    ans = 0
    for c in t:
        if len(c_idx[c]) == 0:
            return -1

        idx_in_c = bisect.bisect_right(c_idx[c], idx)
        # next s
        if idx_in_c == len(c_idx[c]):
            idx -= len(s)
            ans += len(s)
            idx_in_c = bisect.bisect_right(c_idx[c], idx)
        
        idx = c_idx[c][idx_in_c]

    return ans + idx + 1


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 8052
#include"bits/stdc++.h"
using namespace std;
int dy[4]={0,1,0,-1},dx[4]={1,0,-1,0};
int H,W,ans=0;
char t;
bool maze[1002][1002];
int dist[1002][1002];
queue<pair<int,int>> que;
int main()
{
  cin >> H >> W;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> t;
      maze[i][j] = (t=='.');
      dist[i][j] = -1*(t=='.');
      if(t=='#') que.push(make_pair(i,j));
    }
  }
  while(!que.empty()){
    int cy=que.front().first,cx=que.front().second;
    que.pop();
    ans=dist[cy][cx];
    for(int i=0;i<4;i++){
      int ny=cy+dy[i],nx=cx+dx[i];
      if(ny<0||H<=ny||nx<0||W<=nx||maze[ny][nx]=='#')
        continue;
      if(dist[ny][nx]==-1){
        dist[ny][nx]=dist[cy][cx]+1;
        que.push(make_pair(ny,nx));
      }
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 13328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[100001],b[31];
int main(){
    int n;
    cin>>n;
    int x=0;
    rep(i,n){
        cin>>a[i];
        x^=a[i];
        int y=a[i]^(a[i]-1);
        int pc=__builtin_popcount(y);
        b[pc]=y;
    }
    int cnt=0;
    for(int i=29;i>=0;--i){
        if((x>>i)&1){
            if(b[i+1]==0){
                cout<<-1<<endl;
                return 0;
            }
            else x^=b[i+1],++cnt;
        }
    }
    if(x==0)cout<<cnt<<endl;
    else cout<<-1<<endl;
    return 0;
}

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

long long calc(int x){
    if(x < 0) return 0;
    if(x == 0) return 1;
    return calc(x - 1) + calc(x - 2) + calc(x - 3);
}

int main(){
    long long n;
    while(cin >> n, n){
        cout << (calc(n) + 3649) / 3650  << endl;
    }
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  ll N,M;
  cin>>N>>M;
  vector<ll>A(M);
  ll sum=0;
  
  rep(i,M){
    cin>>A[i];
    sum+=A[i];
  }
  
  if(sum<=N){
    cout<<N-sum<<endl;
  }
else{
cout<<"-1"<<endl;
}
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i=s;i<=n;i++)
 
int main()
{
  int a,b;
  cin >> a >> b;
  bool ans=false;
  rep(i,0,a)
  {
     if(i*2+(a-i)*4==b)
         ans=true;
  }
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
  

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

int main(){
  string S;
  int N;
  cin >> S;
  N = S.size();

  int res[2] = {0,0};
  // index 0 = black or white.

  //black、最初が0になってほしい
  for(int j=0; j<N; j++){
    if(j%2==0){
     
      if(S[j] == '1') res[0]++;
    }else{//j%2==1

      if(S[j] == '0') res[0]++;
    }
  }
  //white、最初が1になってほしい
  for(int j=0; j<N; j++){
    if(j%2==1){
      
      if(S[j] == '1'){

	res[1]++;
      }
    }else{//j%2==0
      
      if(S[j] == '0') {

	res[1]++;
      }
    }	    
  }

  if(res[0]>res[1]) cout<<res[1]<<endl;
  else cout<<res[0]<<endl;
  
  return 0;
}


Measured memory_bytes: 512
il = list(map(int, input().split()))

a = il[0]
b = il[1]
c = il[2]
d = il[3]

connectable = False
#print(abs(a-b))
#print(abs(b-c))
#print(abs(a-c))

if abs(a-b) <= d and abs(b-c) <= d:
    connectable = True
elif abs(a-c) <= d:
    connectable = True
else:
    pass


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

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

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

int H, W;
char F[411][411];

bool use[411][411];

bool in(int y, int x) {
    return 0 <= y && y < H && 0 <= x && x < W;
}

int cnt[2];
void dfs(int y, int x) {
    use[y][x] = true;
    if (F[y][x] == '#') cnt[0]++;
    else cnt[1]++;

    REP (d, 4) {
	int yy = y + dy[d];
	int xx = x + dx[d];
	if (in(yy, xx) && !use[yy][xx] && F[y][x] != F[yy][xx]) {
	    dfs(yy, xx);
	}
    }
}

void MAIN() {
    scanf("%d%d", &H, &W);
    REP (i, H) scanf("%s", F[i]);

    LL ans = 0;
    REP (i, H) REP (j, W) if (F[i][j] == '#' && !use[i][j]) {
	cnt[0] = cnt[1] = 0;
	dfs(i, j);
	ans += (LL)cnt[0] * cnt[1];
    }

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

int main(){
    int N;
    cin >> N;
    map<int, int> cnt;
    int64_t ans=0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        ans += a;
        cnt[a] += 1;
    }
    int Q;
    cin >> Q;
    for(int i=0; i<Q; i++){
        int B,C;
        cin >> B >> C;
        ans += (C-B) * cnt[B];
        cnt[C] += cnt[B];
        cnt[B] = 0;
        cout << ans << endl;
    }  
}


Measured memory_bytes: 8052
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};

in sq4(in x){
    in y=1;
    while(y*y*y*y<x){
        y ++;
    }
    return y;
}

in p5(in x){
    in y=x*x;
    return y*y*x;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in x;
    cin>>x;
    in limb=sq4(x);

    in s=0;
    while(p5(s)<=x){
        if(p5(s)==x){
            cout<<s<<" "<<0<<endl;
            return 0;
        }
        s ++;
    }

    in one=1ll;

    for(in b=-limb;b<limb;b++){//1e4
        if(b==0) continue;
        in b2=b*b;
        for(in a=max(one,b+1);a*a*b2<=x;a++){
            if(p5(a)-p5(b)==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
}/*
./problem.exe
*/

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

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

    int N, M, R;
    cin >> N >> M >> R;
    
    int c[N][N];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j) c[i][j] = 0;
            else c[i][j] = 1e9;
        }
    }

    vector<int> r(R);
    for(int i = 0; i < R; i++){
        cin >> r[i];
        r[i]--;
    }

    for(int i = 0; i < M; i++){
        int A, B, C;
        cin >> A >> B >> C;
        A--; B--;
        c[A][B] = C;
        c[B][A] = C;
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
            }
        }
    }

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

    int ans = 1e9;
    do{
        int tmp, cost = 0;
        for(int i = 0; i < R; i++){
            if(i > 0){
                cost += c[tmp][r[i]];
            }
            tmp = r[i];
        }
        ans = min(ans, cost);
    }while(next_permutation(r.begin(), r.end()));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

const int N=100001;
vector<int> G[N],rG[N],g;
bool u[N];
int n,cmp[N];
  
void add_edge(int x,int y){G[x].push_back(y);rG[y].push_back(x);}
void dfs(int x){u[x]=1;rep(i,G[x].size())if(!u[G[x][i]])dfs(G[x][i]);g.push_back(x);} 
void rdfs(int x,int k){u[x]=1;cmp[x]=k;rep(i,rG[x].size())if(!u[rG[x][i]])rdfs(rG[x][i],k);}
int scc() {
  mem(u);g.clear();rep(i,n)if(!u[i])dfs(i);mem(u);
  int k=0;rrep(i,g.size())if(!u[g[i]])rdfs(g[i],k++);return k;
}

void Main() {
  ll m;
  cin >> n >> m;
  rep(i,n+m-1) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    add_edge(x,y);
  }
  scc();
  P p[n];
  rep(i,n) p[i]=P(cmp[i],i);
  sort(p,p+n);
  ll d[n];
  mem(d);
  rep(i,n) {
    int x=p[i].S;
    rep(j,G[x].size()) d[G[x][j]]=x+1;
  }
  rep(i,n) pr(d[i]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 15228
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int N;
char S[200000+2];
int main(){
  int i;
  int res = 0;
  N = rd(S);
  for(i=(0);i<(N);i++){
    res += S[i] - '0';
  }
  if(res%9){
    wt_L("No");
    wt_L('\n');
  }
  else{
    wt_L("Yes");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200813-1 [beta]

// --- original code ---
// int N;
// char S[2d5+2];
// {
//   int res = 0;
//   rd(S@N);
//   rep(i,N) res += S[i] - '0';
//   wt(if[res%9, "No", "Yes"]);
// }


Measured memory_bytes: 4024
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;
const int INF = (1u << 31) - 1;
int lis(vector<int> &v) {
    int m = v.size();
    vector<int> dp(m + 1, INF);
    int lk = -1;
    REP(i, m) {
        int k = distance(dp.begin(), upper_bound(dp.begin(), dp.end(), v[i]));
        dp[k] = v[i];
        lk = max(k, lk);
    }
    return lk + 1;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    reverse(v.begin(), v.end());
    cout << lis(v) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
using ull = unsigned long long;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
const ll md = 1000000007;
vector<ll> fact(1e6 + 7), invfact(1e6 + 7);

ll fn(ll a, ll r, ll n, ll mod = md) {
    ll res = 1, x = r%mod;
    ll ans = 0;
    while(n) {
        if(n&1) ans = (x*ans + res)%mod;
        res = ((res*x)%mod + res%mod)%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    ans = (ans*a)%mod;
    return ans;
}

ll nCr(ll n, ll r) {
    if(r == 0) return 1;
    ll num = fact[n];
    ll den = (invfact[r] % md *invfact[n-r] % md)%md;
    return (num*den)%md;
}

ll mul(ll a, ll b, ll mod = md) {
    ll res = (a%mod * b%mod)%mod;
    return res;
}

ll mulm(ll a, ll b, ll mod = md) {
    ll r = 0;
    a %= mod;
    while (b) {
        if (b & 1) r = (r+a)%mod;
        a = (a+a)%mod;
        b = b/2;
    }
    r %= mod;
    return r;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = n/2;
        x = (x*x)%mod;
    }
    return res;
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n)  
    {  
        if (n & 1)  res = (res*x);  
        n = n/2; 
        x = (x*x);  
    }  
    return res;
}

bool is_prime(ll x) {
    if(x == 1 || x == 0) return false;
    for(int i=2; i*i <= x; i++) {
        if(x%i == 0) return false;
    }
    return true;
}

ll compgcd(ll n, vector<ll> const &primes) { 
    ll res = n; 
    for (ll i=0; primes[i]*primes[i] <= n; i++) {
        if (n % primes[i]== 0) { 
            res -= (res / primes[i]); 
            while (n%primes[i]== 0) {
               n/=primes[i]; 
            }
        } 
    } 
    if (n > 1) {
       res -= (res / n); 
    }
    return res; 
} 

void sieve(vector<bool> &prime, vector<ll> &primes, ll lim) {
    for(int i = 2; i*i <= lim; i++) {
        if(prime[i]) {
            for(int j = 2; j*i <= lim; j++) {
                prime[j*i] = false;
            }
        }
    }
    for(int i = 2; i <= lim; i++) {
        if(prime[i]) {
            primes.push_back(i);
        }
    }
}

void sieveGCD(ll lim, vector<ll> &tab, vector<ll> const &primes) {
    for(int  i = 1; i <= lim; i++) {
        tab[i] = i;
    }
    for(int i = 0; i<primes.size() && primes[i] <= lim; i++) {
        tab[primes[i]] = primes[i]-1;
        for(int j = 2; primes[i]*j <= lim; j++) {
            tab[primes[i]*j] = (tab[primes[i]*j]/primes[i])*(primes[i]-1);
        }
    }
}

ll calc(ll a, ll b, ll r) {
    ll total = r+1;
    ll tmp = a*b;
    ll count = (r/tmp)*max(a,b) + max(a,b);
    if((r/tmp)*tmp + max(a,b) > r) {
        count -= ((r/tmp)*tmp + max(a,b) - r - 1);
    }
    total -= count;
    return total;
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    cout << ceil((double)n/2) << endl;
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=2e5+5;
const ll inf=1e17;

ll ar[2001]={0};
ll br[2001]={0};

int main()
{
    idfc;

    ar[0]=1;

    int n;
    cin>>n;
    int i,j,k;
    ll ans=0;
    int lim=n/3;
    for(i=1;i<=lim;i++)
    {
        for(j=n;j>=0;j--)
        {
            for(k=3;k<=2000;k++)
            {
                if((j+k)<=n)
                {
                    br[j+k]=(br[j+k]+ar[j])%modo;
                }
                else break;
            }
        }
        for(j=0;j<=n;j++)
        {
            ar[j]=br[j];
            br[j]=0;
        }
        ans=(ans+ar[n])%modo;
    }
    cout<<ans;


    return 0;
}

Measured memory_bytes: 3592
#!/usr/bin/env python3
H, W, h, w = map(int, input().split())
if W % w == 0 and H % h == 0:
    print('No')
else:
    swapped = False
    if W % w == 0:
        H, W, h, w, swapped = W, H, w, h, True
    a = [ [ 0 for _ in range(W) ] for _ in range(H) ]
    for y in range(H):
        for x in range(0, W, w):
            a[y][x] = W
        for x in range(w - 1, W, w):
            a[y][x] = - W - 1
    if swapped:
        H, W, h, w = W, H, w, h
        b = a
        a = [ [ 0 for _ in range(W) ] for _ in range(H) ]
        for y in range(H):
            for x in range(W):
                a[y][x] = b[x][y]
    print('Yes')
    for y in range(H):
        print(*a[y])


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

int main(){
    string S;
    cin >> S;
    if(S == "SUN"){
        cout << 7 << endl;
    }else if(S == "MON"){
        cout << 6 << endl;
    }else if(S == "TUE"){
        cout << 5 << endl;
    }else if(S == "WED"){
        cout << 4 << endl;
    }else if(S == "THU"){
        cout << 3 << endl;
    }else if(S == "FRI"){
        cout << 2 << endl;
    }else if(S == "SAT"){
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long qpow(long long a,long long b) {
	long long ans=1;
	while(b>0) {
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long N,K,ans=0;
	cin>>N>>K;
	vector<long long>sum(K+1);
	for(int i=K;i>0;i--) {
		sum[i]=qpow(K/i,N);
		for(int j=2*i;j<=K;j+=i) sum[i]=(sum[i]-sum[j]+mod)%mod;
		ans=(ans+sum[i]*i%mod)%mod;
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3952
n = int(input())

a = []
xy = []
for i in range(n):
	a.append(int(input()))
	tmp = []
	for _ in range(a[i]):
		tmp.append(list(map(int,input().split())))
	xy.append(tmp)

l = []
ans = 0
for i in range(2**n):
	l = []
	torf = [0 for _ in range(n)]
	# 正直者を1にする
	for j in range(n):
			if i & (1<<j):
				torf[j] = 1
				l.append(j)
	flag = False
	for j in range(n):
		# 正直者の証言が正しいかチェック
		if torf[j] == 1:
			for k in range(a[j]):
				if torf[xy[j][k][0]-1] != xy[j][k][1]:
					flag = True
					break
		# 嘘つきの証言が嘘かチェック
		"""
		else:
			for k in range(a[j]):
				if torf[xy[j][k][0]-1] == xy[j][k][1]:
					flag = True
					break
		"""
		if flag:
			break
	if not flag:
		ans = max(ans,len(l))

print(ans)


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

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

using namespace std;

typedef long long ll;

ll l[87];

int main(){
    l[0] = 2;
    l[1] = 1;
    for(int i = 2; i < 87; ++i){
        l[i] = l[i - 1] + l[i - 2];
    }
    int n;
    cin >> n;
    cout << l[n] << endl;
    return 0;
}

Measured memory_bytes: 256
void main() {
	auto S = rs;
	ulong res = ulong.max;
	foreach(i; 0..S.length - 2) {
		auto a = S[i..i + 3];
		res = min(res, abs(753 - a.to!int));
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int a,b; cin >> a >> b;
    cout << (a - (b*2) > 0 ? a-(b*2) : 0) << endl;
    return 0;
    
}

Measured memory_bytes: 764
n = int(input())
a = list(map(int, input().split()))
cnt_m = len(list(filter(lambda x: x < 0, a)))

if cnt_m == 0:
    i_m = a.index(min(a))
    i_p = (i_m + 1) % n
elif cnt_m == n:
    i_p = a.index(max(a))
    i_m = (i_p + 1) % n
else:
    i_m = i_p = -1
    for i in range(n):
        if i_m == -1 and a[i] < 0:
            i_m = i
        if i_p == -1 and a[i] >= 0:
            i_p = i

is_used = [False] * n
ans = []

is_used[i_m] = True
is_used[i_p] = True
s_m = a[i_m]
s_p = a[i_p]
for i in range(n):
    if not is_used[i]:
        if a[i] >= 0:
            ans.append((s_m, a[i]))
            s_m -= a[i]
        else:
            ans.append((s_p, a[i]))
            s_p -= a[i]

        is_used[i] = True

ans.append((s_p, s_m))
ans_s = s_p - s_m

print(ans_s)
for ans_i in ans:
    print(*ans_i)


Measured memory_bytes: 24096
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int D;	cin>>D;
	vi c(26);
	rep(i,0,26){
		cin>>c[i];
	}
	int s[D][26];
	rep(i,0,D){
		rep(j,0,26){
			cin>>s[i][j];
		}
	}
	rep(i,0,D){
		cout<<(i%26)+1<<endl;
	}
	return 0;
}


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


N, Q = map(int, input().split())
to = [[] for _ in range(N)]
ans = [0] * N

for _ in range(N - 1):
    a, b = map(lambda x:int(x) - 1, input().split())
    to[a].append(b)
    to[b].append(a)


def dfs(v, p=-1):
    global ans
    for nv in to[v]:
        if nv == p:
            continue
        ans[nv] += ans[v]
        dfs(nv, v)


def main():
    global ans
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        ans[p] += x
    dfs(0)
    print(*ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 282824
import sys
input = sys.stdin.readline
def MI():
    return map(int, input().split())

n = int(input())
z=[]
w=[]
for i in range(n):
    x,y=MI()
    z.append(x+y)
    w.append(x-y)

print(max(max(z)-min(z), max(w)-min(w)))

Measured memory_bytes: 90508
N = gets.chomp.to_i
P = gets.chomp.split(" ").map(&:to_i)

cnt = 0
1.upto(N-2) do |i|
  cnt += 1 if (P[i-1] < P[i] && P[i] < P[i+1]) || (P[i-1] > P[i] && P[i] > P[i+1])
end
puts cnt


Measured memory_bytes: 1788
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
    int n;string s;cin>>n>>s;
    int x = 0;
    int d[n];
    rep(i,n){
        if(s[i]=='I')x++;
        if(s[i]=='D')x--;
        d[i] = x;
    }
    int res = 0;
    rep(i,n){
        res = max(res,d[i]);
    }
    cout<<res;
}



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll dp[2][102];

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

	string s;
  cin>>s;
  ll pos = s.find("C");
  ll pos2 = s.find("F",pos+1);
  
  if(pos==-1 || pos2==-1)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
  
}




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

using namespace std;
using ll = long long;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> vecn(n+1, 0);
  for (ll i = 1; i < n+1; ++i)
    cin >> vecn[i];
  vector<ll> vecm(m+1, 0);
  for (ll i = 1; i < m+1; ++i)
    cin >> vecm[i];

  for (auto itr = vecn.begin() + 1; itr != vecn.end(); ++itr)
    *itr = *itr + *(itr - 1);
  for (auto itr = vecm.begin() + 1; itr != vecm.end(); ++itr)
    *itr = *itr + *(itr - 1);

  ll best_score = 0;
  for (auto itr = vecn.begin(); itr != vecn.end() && *itr <= k; ++itr) {
    auto a = upper_bound(vecm.begin(), vecm.end(), k - *itr);
    ll score = (itr - vecn.begin()) + (a - vecm.begin() - 1);
    best_score = max(best_score, score);
  }
  cout << best_score << endl;
}

Measured memory_bytes: 6416
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

const int maxcnt = 25;

int main()
{
    int N;
    cin >> N;
    vector<vector<vector<vector<ll>>>>
        cumcnts(maxcnt+1, vector<vector<vector<ll>>>(
                maxcnt+1, vector<vector<ll>>(
                maxcnt+1, vector<ll>(
                maxcnt+1, 0))));
    vector<pair<int, int>> reqs(N);
    vector<pair<int, int>> havs(N);
    rep(i, 0, N)
    {
        string s;
        cin >> s;
        int pos = s.find('.');
        int req = 0;
        if (pos>0) req = (int) s.size() - pos - 1;
        s.erase(remove(s.begin(), s.end(), '.'), s.end()); 
        ll llA = stoll(s);
        // printf("---------\n");
        // printf("llA: %lld, req: %d, pos: %d\n", llA, req, pos);

        int h2 = 0;
        int h5 = 0;
        while (llA%2 == 0)
        {
            ++h2;
            llA /= 2;
        }
        while (llA%5 == 0)
        {
            ++h5;
            llA /= 5;
        }
        // printf("h2: %d, h5: %d\n", h2, h5);

        // calibration
        int r2 = max(0, req - h2);
        int r5 = max(0, req - h5);
        h2 = max(0, h2 - req);
        h5 = max(0, h5 - req);

        // printf("r2: %d, r5: %d, h2: %d, h5: %d\n", r2, r5, h2, h5);

        ++cumcnts[r2][r5][h2][h5];

        reqs[i] = make_pair(r2, r5);
        havs[i] = make_pair(h2, h5);
    }

    // take cumulative sum
    rep(r2, 0, maxcnt+1)
        rep(r5, 0, maxcnt+1)
        {
            rep(h2, 0, maxcnt+1)
                rep(h5, 0, maxcnt+1)
                {
                    ll& now = cumcnts[r2][r5][h2][h5]; 
                    if (h2>0 and h5>0)
                        now -= cumcnts[r2][r5][h2-1][h5-1];
                    if (h2>0)
                        now += cumcnts[r2][r5][h2-1][h5];
                    if (h5>0)
                        now += cumcnts[r2][r5][h2][h5-1];
                }
        }

    ll cnt = 0;
    rep(now, 0, N)
    {
        int req2, req5, hav2, hav5;
        tie(req2, req5) = reqs[now];
        tie(hav2, hav5) = havs[now];

        // printf("req2: %d, req5: %d, hav2: %d, hav5: %d\n",
                // req2, req5, hav2, hav5);
        rep(r2, 0, hav2+1) 
            rep(r5, 0, hav5+1)
            {
                cnt += cumcnts[r2][r5][maxcnt][maxcnt];
                if (req2>0 and req5>0)
                    cnt += cumcnts[r2][r5][req2-1][req5-1];
                if (req2>0)
                    cnt -= cumcnts[r2][r5][req2-1][maxcnt];
                if (req5>0)
                    cnt -= cumcnts[r2][r5][maxcnt][req5-1];
                // printf("r2: %d, r5: %d, cnt: %lld\n", r2, r5, cnt);
            }
        //printf("now: %d, cnt: %lld\n", now, cnt);
        

        // remove it self
        if (req2<=hav2 and req5<=hav5) --cnt;
    }

    assert (cnt % 2 == 0);

    cnt /= 2;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 10756
a,k=map(int,input().split())
L=list(map(int,input().split()))
ans=0
 
for i in range(min(k,a)+1):
  for j in range(min(k,a)-i+1):
    S=[0]+L[:i]+L[a-j:]
    S.sort()
    x=0
    while x < k-(j+i):
      if S[x]>=0:
        break
      x+=1
    ans=max(ans,sum(S)-sum(S[:x]))
    
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    int h, w;
    cin >> h >> w;

    char c[100][100];
    char out[200][100];
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> c[i][j];
            out[2*i][j] = out[2*i + 1][j] = c[i][j];
        }
    }
    for(int i = 0; i < 2*h; ++i){
        for(int j = 0; j < w; ++j){
            cout << out[i][j];
        }
        cout << endl;
    }
    
}


Measured memory_bytes: 256
N = input()

count = 1
max_val = 0
for i in range(1,len(N)):
    if N[i] == N[i-1]:
        count += 1
    else:
        count = 1
    
    max_val = max(max_val,count)

print("Yes" if max_val >= 3 else "No")

Measured memory_bytes: 3060
// yu!W 183


#include <bits/stdc++.h>
#include<string>
#define MAX_N 1000100

using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair<ii, int>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define cl(a) a.clear()

#define vi vector<int>
#define vii vector<ii>

#define LOWBIT(x) ( (x) & -(x) )

#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)

const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const ll MOD = 1e9 + 7;
const ll inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;

int dx[] = {0 , -1 , 0 , 1};
int dy[] = {1 , 0 , -1 , 0};
//vector<int> a[100000];
int main()
{
 //freopen("t.txt","r",stdin);
 long long n,m;
 long long *a;cin>>n>>m; a= new long long[n+1];
 for (long long i=1;i<=n;i++) a[i]=0;
 while (m--){
 	int  x,y; cin>>x>>y;
 	a[x]++;
	a[y]++;
 }
 
 for (long long i=2;i<=n;i++){
 	if (a[i]%2!=0){
 		cout<<"NO"; return 0;
	 }
 }

 cout<<"YES";
}


Measured memory_bytes: 1024
import math
def main():
    s = input()
    n = int(input())
    for i, ss in enumerate(s):
        num = int(ss)
        if i < n:
            if num == 1:
                continue
            else:
                print(num)
                return
        else:
            print(1)
            return
    print(1)
    return
def powpow(a,n):
    x = 1
    i = 0
    while n > 0:

        if bin(n>>i & 1):
            x=x*a
        a*=a
        i+=1
        n=n>>1
    return x

if __name__=='__main__':
    main()


Measured memory_bytes: 3064