akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    string input;
    cin >> input;
    int res = 0;
    rep0(i,3){
        if(input[i]=='o'){
            res++;
        }
    }
    cout << 700+res*100 << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;
ll n,ans;
vll a,b;



int main() {
    cin >> n;
    a.resize(n+1);
    rep(i,n) cin >> a[i+1]; 
    int b = a[1];
    ans = 1;
    while(ans<=n){
        if(b==2) break;
        ans++;
        b = a[b];
    }
    cout << (ans<=n?ans:-1) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin>>s;
    ll ans;
    if(s=="SUN") ans=7;
    else if(s=="MON") ans=6;
    else if(s=="TUE") ans=5;
    else if(s=="WED") ans=4;
    else if(s=="THU") ans=3;
    else if(s=="FRI") ans=2;
    else if(s=="SAT") ans=1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn scan<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn scan_split<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_split_with<T: std::str::FromStr>(ch: char) -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split(ch)
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_lines<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| scan::<T>()).collect()
}

#[allow(unused_macros)]
macro_rules! scan_as_tuple {
    ( $t:ty ) => {
        (scan::<$t>(),)
    };
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok();
            let v = s.trim().split_whitespace();
            let mut it = v;
            let ret = ( $(it.next().unwrap().parse::<$t>().ok().unwrap()),* );
            assert!(it.next() == None, "not all tokens consumed");
            ret
        }
    };
}

fn main() {
    let n = scan::<i32>();
    let k = scan::<i32>();
    let x = scan::<i32>();
    let y = scan::<i32>();
    
    if n <= k {
        println!("{}", x*n);
    } else {
        println!("{}", x*k+y*(n-k));
    }
}

Measured memory_bytes: 4352
N = int(input())
A =  [0] + list(map(int, input().split())) + [0]

a = []
for i in range(N+1):
    a.append(abs(A[i+1] - A[i]))
    
s = sum(a)

for i in range(1,N+1):
    ans = s - (a[i-1] + a[i]) + abs(A[i+1] - A[i-1])
    print(ans)

Measured memory_bytes: 14048
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
    int main() {
      string A;
      cin >> A;
      if (A[3] != '8') {A[3] = '8';}
      cout << A << endl;
      
      
	}

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

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


int main() {
  int s;
  cin >> s;
  int l = s/100;
  int r = s%100;
  int lb = (0<l && l<13)?1:0;
  int rb = (0<r && r<13)?1:0;
  if (lb && rb) cout << "AMBIGUOUS" << endl;
  else if (lb) cout << "MMYY" << endl;
  else if (rb) cout << "YYMM" << endl;
  else cout << "NA" << endl;
  return 0;
}

Measured memory_bytes: 3612
# include <iostream>
# include <string>
# include <cctype>
# include <vector>
# include <cstdlib>
# include <cstring>
# include <algorithm>
# include <iomanip>
# include <cmath>
# define ll long long
using namespace std ;
//const double INF=0x3f3f3f3f+1.0;
//const double eps=1e-6;
//const double PI=2.0*acos(0.0);
//const double pi=acos(-1.0) ;//也可以用cmath中的M_PI
int main()
{
    ios::sync_with_stdio(false) ;
    int a,b ;
    while(cin>>a>>b)
    {
    	int c=a*b ;
    	cout << c-(a+b-1) << endl ;
	}
	return 0 ;
}


Measured memory_bytes: 256
def BubbleSort(C_B, N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if int(C_B[j][1]) < int(C_B[j-1][1]) :
                C_B[j], C_B[j-1] = C_B[j-1], C_B[j]
    return C_B

def SelectionSort(C_S, N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if int(C_S[j][1]) < int(C_S[minj][1]):
                minj = j
        C_S[i], C_S[minj] = C_S[minj], C_S[i]
    return C_S

def J(C, C_):
    for i in range(1,len(C_)):
        if int(C_[i-1][1]) == int(C_[i][1]):
            p = C.index(C_[i-1])
            q = C.index(C_[i])
            if q<p:
                return 'Not stable'
    return 'Stable'

N = int(input())
C = list(input().split())
C_B = C.copy()
C_S = C.copy()
CB = BubbleSort(C_B, N)
CS = SelectionSort(C_S, N)

for i in range(len(CB)):
    if i==len(CB)-1:
        print(CB[i])
    else:
        print(CB[i],end=' ')
print(J(C, CB))
for i in range(len(CS)):
    if i==len(CS)-1:
        print(CS[i])
    else:
        print(CS[i],end=' ')
print(J(C, CS))


Measured memory_bytes: 5608
from collections import Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
c = Counter(A)

for i in range(1, N + 1):
    if Q - c[i] >= K:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 11876
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          ABC093-B
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz size
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,x,n) for(int i=x;i<(n);i++)
typedef pair<int,int> ii;
#define vii vector<ii>
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 2*1e5+1;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b;
    int pwur = qpow(b,e>>1);
    return pwur * pwur;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// Criba de Eratostenes ------------------------------------
const int pr=10000;
map<int,int>isp;
void criba(){
    for(int i=0;i<=pr;i++)isp[i]=i;
    isp[0]=isp[1]=-1;
    for(int i=2;i*i<=pr;i++){
        if(isp[i]==i){
        for(int j=2*i;j<=pr;j+=i)
            isp[j]=i;
        }
    }
}
/// My Code ------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    ///freopen("a.in","r",stdin);
    ///freopen("a.out","w",stdout);
    ///criba();
    int a,b,k;
    cin>>a>>b>>k;
    if(b-a+1<k){
        while(a<=b){
            cout<<a++<<enl;
        }
        return 0;
    }
    int kk=k;
    set<int>st;
    if(a>b)swap(a,b);
    while(k--){
        st.insert(a++);
    }
    while(kk--){
        st.insert(b--);
    }
    for(auto val:st)cout<<val<<enl;

    return 0;
}


Measured memory_bytes: 3672
import java.util.*;
import java.io.*;
class Main {
    static long MOD = (long)(1e9+7);
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] grid = new int[n][m];
        for(int i = 0; i<n; i++) {
            String s = sc.next();
            for(int j = 0; j<m; j++) {
                if(s.charAt(j)=='#')
                    grid[i][j] = -1;
                else grid[i][j] = 1;
            }
        }
        long[][] dp = new long[n][m];
        dp[0][0] = grid[0][0];
        for(int i = 1; i<m; i++)
            if(grid[0][i]!=-1)
                dp[0][i]+=dp[0][i-1];
        for(int i = 1; i<n; i++) 
            if(grid[i][0]!=-1)
                dp[i][0]+=dp[i-1][0];
        for(int i = 1; i<n; i++) {
            for(int j = 1; j<m; j++) {
                if(grid[i][j]!=-1)
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
            }
        }
        System.out.println(dp[n-1][m-1]);
    }
}

Measured memory_bytes: 53788
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

X, Y = map(int, input().split())

cnt = 1
while X <= Y:
    X *= 2
    cnt += 1

print(cnt - 1)

Measured memory_bytes: 3568
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int INF = 1e9;
// LIS(longest increasing subsequence)
// http://even-eko.hatenablog.com/entry/2013/09/05/215236
int dp[100005];
int lis(vector<int> &a) {
    int n = a.size();
    fill(dp, dp + n, INF);
    for (int i = 0; i < n; ++i) {
        *lower_bound(dp, dp + n, a[i]) = a[i];
    }
    return lower_bound(dp, dp + n, INF) - dp;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    cout << lis(a) << endl;
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define mkp make_pair

int32_t main()
{
 int t=1;
 //cin>>t;
while(t--)
{
	int n;
    cin>>n;
   int a[n+1],dp[n+1];
   for(int i=1;i<=n;i++)cin>>a[i];
     int cost=0;
     dp[1]=0;
     dp[2]=abs(a[1]-a[2]);  
    // f(i,n+1)cout<<a[i]<<" ";
     //cout<<endl;
     for(int i=3;i<=n;i++)
     {
		 dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));  //cout<< dp[i-1]+abs(a[i]-a[i-1])<<" "<<dp[i-2]+abs(a[i]-a[i-2])<<endl;
		 
		// cout<<cost<<endl;
	 }
         	cout<<dp[n]<<endl;
    
}
   
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(){
	char str[10];
	for(int i = 0;i < 10;i++)str[i] = 'x';
	scanf("%s",str);
	int i = 0;
	int cnt = 0;
	int max = 0;
	while(str[i]!='x' && i<10){
		if(str[i] == 'A' ||str[i] == 'T'||str[i] == 'G'||str[i] == 'C'){
			cnt ++;
		}else{
			if(max < cnt) max = cnt;
			cnt = 0;
		}
		i++;
	}
	printf("%d\n",max);

	return 0;
}









Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int K = keyboard.nextInt();
		String S = keyboard.next();
		String d = "...";
		
		if(S.length() > K) {
			S = S.substring(0,K);
			S += d;
		}
		
		System.out.print(S);
		keyboard.close();
	}
}


Measured memory_bytes: 39508
<?php
    $W = [];
    $K = [];
    for($i = 1; $i <= 20; $i++){
        if($i <= 10){
            $W[] = trim(fgets(STDIN));
        }else{
            $K[] = trim(fgets(STDIN));
        }
    }
    rsort($W);
    rsort($K);
    echo ($W[0] + $W[1] + $W[2]). " " . ($K[0] + $K[1] + $K[2]) . "\n";


Measured memory_bytes: 9240
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>

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

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	string s, t;
	cin >> s;
	cin >> t;
	int count = 0;
	for (int i = 0; i < 3; i++)
	{
		if (s[i] == t[i])
		{
			count++;
		}
	}
	cout << count;
}


Measured memory_bytes: 31488
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=505;
int n,m;
char pp[N][N],rd[N][N],bl[N][N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
int main()
{
	//freopen("AND Grid.in","r",stdin);
	read(n,m);
	for(RG int i=1;i<=n;i++)
	{
		scanf("%s",pp[i]+1);
		for(RG int j=1;j<=m;j++) if(pp[i][j]=='#') rd[i][j]=bl[i][j]='#';
	}
	for(RG int i=1;i<=n;i++) rd[i][1]=bl[i][m]='#';
	for(RG int i=2;i<n;i++)
	 for(RG int j=2;j<m;j++)
	  if(i&1) rd[i][j]='#'; else bl[i][j]='#';
	for(RG int i=1;i<=n;i++)
	{
		for(RG int j=1;j<=m;j++) printf("%c",rd[i][j]=='#' ? '#' : '.');
		printf("\n");
	}
	printf("\n");
	for(RG int i=1;i<=n;i++)
	{
		for(RG int j=1;j<=m;j++) printf("%c",bl[i][j]=='#' ? '#' : '.');
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a,b,s=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		s+=b-a;
	}
	cout<<s+n<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int n;
    bool highlow = true;

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

    for(int i=n-1;i>0;i--){
       if(high[i] < high[i-1]){
          if(high[i] >= high[i-1]-1){
            high[i-1]--;
          }else{
            highlow = false;
          }
       }
    }
cout << (highlow? "Yes": "No") << endl;
}



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

int main(){
  string s; cin >> s;
  reverse(s.begin(), s.end());
  string a = "dream", b = "dreamer", c = "erase", d ="eraser";
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  reverse(c.begin(), c.end());
  reverse(d.begin(), d.end());
  bool ok = true;
  string tmp = "";
  for(int i = 0; i < s.size(); i++){
    tmp += s[i];
    if(tmp.size() == a.size()){
      if(tmp == a || tmp == c) tmp = "";
    }
    if(tmp.size() == d.size()){
      if(tmp == d) tmp = "";
    }
    if(tmp.size() == b.size()){
      if(tmp == b) tmp = "";
      else{
        ok = false;
        break;
      }
    }
  }
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.size();
    
    REP(i,0,n){
        if(i%2==0){
            if(s[i]=='L'){cout<<"No"<<endl; return 0;}
        }else{
            if(s[i]=='R'){cout<<"No"<<endl; return 0;}
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int size=1e5+5,mod=1e9+7;
typedef long long int ll;
vector <int> g[size];
ll dp[size][2];
void dfs(int src,int par=-1)
{
    dp[src][0]=dp[src][1]=1;
    for(auto v:g[src])
    {
        if(v==par)
            continue;
        dfs(v,src);
        ll tmp = (dp[v][0]+dp[v][1])%mod;
        dp[src][0] = (1LL*dp[src][0]*tmp)%mod;
        dp[src][1] = (1LL*dp[src][1]*dp[v][0])%mod;
    }
}
int main()
{
    int n;
    cin>>n;
    if(n==1)
    {
        cout<<"2\n";
        return 0;
    }
    for(int i=0,u,v;i<n-1;i++)
    {
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    ll ans = 0;
    dfs(1);
    ans = (ans+dp[1][0]+dp[1][1])%mod;
    for(int i=2;i<=n;i++)
    {

    }
//    for(int i=1;i<=3;i++)
//        cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    cout<<(1LL*dp[1][0]+dp[1][1])%mod<<endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}

int main(){
	int n; cin>>n;
    int ans=0;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
  for(int i=1;i<=n-2;i++){
     if((p[i-1]<p[i] && p[i]<p[i+1])||(p[i-1]>p[i] && p[i]>p[i+1])) ans++;
  }
  printf("%d",ans);
}

Measured memory_bytes: 256
#import bisect
import heapq
from collections import deque
n,m = map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))

lis = [[]for i in range(m)]

for i in range(n):
    if ab[i][0]<=m:
        lis[ab[i][0]-1].append(ab[i][1])

pys = []
heapq.heapify(pys)
sum = 0
for i in range(m):
    tmp = lis[i]
    if tmp:
        for j in tmp:
            heapq.heappush(pys,-j)
    if pys:
        sum-=heapq.heappop(pys)

print(sum)


Measured memory_bytes: 39788
ans=0
n,m=map(int,input().split())
a=[(1,int(i)) for i in input().split()]
for i in range(m):
    b,c=map(int,input().split())
    a.append((b,c))
a=sorted(a,key=lambda x:x[1])

t=0
while t<n:
    k,x=a.pop()
    ans+=x*min(k,n-t)
    t+=k
print(ans)

Measured memory_bytes: 85016
# 2019/09/01
# AtCoder Beginner Contest 139 - C

# Input
n = int(input())
h = list(map(int,input().split()))

# Count
maxc = -1
cnt = 1
for i in range(1, n):
    if h[i-1] >= h[i]:
        cnt = cnt + 1
    else:
        if maxc < cnt:
            maxc = cnt
        cnt = 1

if maxc < cnt:
    maxc = cnt

ans = maxc - 1

# Output
print(ans)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define lP pair<ll,ll>
#define iP pair<int,int>

typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;

int main(){
	int H, W, X, Y;
	cin >> H >> W >> X >> Y;
	if (H*W % 2 == 1 && (X + Y) % 2 == 1) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char s[200];
int i,c,f,l;
int main()
{
    cin>>s;
    l=strlen(s);
    for(i=0;i<l;i++)
    {
        if(s[i]=='C')c=1;
        if(s[i]=='F'&&c==1)f=1;
    }
    if(f)cout<<"Yes";
    else cout<<"No";
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,h=1,j=0;
    cin>>a;
    string s[a];
    for(int i=0;i<=a-1;i++)
    {
    	cin>>s[i]; 
	}
	for(int i=1;i<=a-1;i++)
	{
		for(int k=i-1;k>=0;k--)
		{
			if(s[i]==s[k])
			{
				h=0;
			} 
		}
		int len=s[i-1].length();
		if(s[i][0]==s[i-1][len-1])
		{
			j++; 
		} 
	}
	if(h==1&&j==a-1)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N, A, B;
	cin >> N >> A >> B;
	if (abs(A-B)%2==0){
		cout << "Alice\n";
	}
	else{
		cout << "Borys\n";
	}
}

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

int main() {
  string N;
  cin >> N;
  
  if (N.at(0) == N.at(1) && (N.at(1) == N.at(2) && N.at(2) == N.at(3)) ){
    cout << "Yes" <<endl;
  }
  else if (N.at(0) == N.at(1) && N.at(1) == N.at(2) ){
    cout << "Yes" <<endl;
  }
  else if (N.at(1) == N.at(2) && N.at(2) == N.at(3)){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

signed main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll acnt = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		ll ccnt = c.end() - upper_bound(c.begin(), c.end(), b[i]);
		ans += acnt * ccnt;
	}

	cout << ans NL;

	return 0;

}



Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
const long long inf=1e9+7;
const long long mod=1e9+7;
const int64_t CYCLES_PER_SEC=2800000000;
//
inline uint32_t Xor128(){
	static uint32_t x=123456789;
	static uint32_t y=362436069;
	static uint32_t z=521288629;
	static uint32_t w=88675123;
	uint32_t t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct Timer{
	int64_t start;
	Timer(){reset();}
	void reset(){start=getcycle();}
	void plus(double a){start-=(a*CYCLES_PER_SEC);}
	inline double get(){return (double)(getcycle()-start)/CYCLES_PER_SEC;}
	inline int64_t getcycle(){
		uint32_t low,high;
		__asm__ volatile ("rdtsc":"=a"(low),"=d"(high));
		return ((int64_t)low)|((int64_t)high<<32);
	}
};
int main(){
	long long x;
	cin>>x;
	long long ans=0;
	ans+=(x/500)*1000;
	x=x%500;
	ans+=(x/5)*5;
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll n,m;
  cin>>n>>m;
  priority_queue<pll> que;
  rep(i,n){
    ll ai;
    cin>>ai;
    que.emplace(ai,1);
  }
  rep(i,m){
    ll b,c;
    cin>>b>>c;
    que.emplace(c,b);
  }
  ll sum = 0;
  ll cnt = 0;
  while(!que.empty()&&cnt<n){
    auto [v,c] = que.top();
    que.pop();
    if(cnt+c<=n){
      sum += v*c;
      cnt += c;
    }else{
      sum += (n-cnt)*v;
      cnt = n;
    }
  }
  cout<<(sum)<<endl;

}

Measured memory_bytes: 7452
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
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; }

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
using pint = pair<int,int>;
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<set<int>> f_or_b(N);

  UnionFind uf(N);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    f_or_b[a].insert(b);
    f_or_b[b].insert(a);
    uf.merge(a, b);
  }

  REP(i, K) {
    int c, d;
    cin >> c >> d;
    c--; d--;
    if (!uf.issame(c, d)) continue;
    f_or_b[c].insert(d);
    f_or_b[d].insert(c);
  }

  REP(i, N) {
    int ans = 0;
    ans = uf.size(i) - 1 - f_or_b[i].size();
    cout << ans << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 24704
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
LL a[4], k;

int main() {
    for(int i=1;i<=3;i++) cin>>a[i];
    sort(a+1,a+4);
    cin>>k;
    LL ans=a[1]+a[2];
    for(int i=1;i<=k;i++) a[3]*=2LL;
    ans+=a[3];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

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

    int L=s.length();
    dp[0][0]=1;

    for(int i=0;i<L;i++)
    {
        if(s[i]=='?'){
            for(int k=0;k<10;k++)
            {
                for(int j=0;j<N;j++)
                {
                    dp[i+1][(10*j+k)%N] += dp[i][j];
                    dp[i+1][(10*j+k)%N] %= mod;
                }
            }

        }else{
            int k = s[i]-'0';
            for(int j=0;j<N;j++)
            {
                dp[i+1][(10*j+k)%N] += dp[i][j];
                dp[i+1][(10*j+k)%N] %= mod;
            }
        }
    }
    ull ans = dp[L][5]%mod;
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,temp;
	cin>>n;
	map<int,int> x;
	for(int i=0;i!=n;++i){
		cin>>temp;
		++x[temp];
	}
	bool test=true;
	if(n%2){
		if(x.find(0)==x.end() || x.find(0)->second!=1)
			test=false;
		for(int i=2;i<n;i+=2){
			if(x.find(i)==x.end() || x.find(i)->second!=2)
				test=false;
		}
	}
	else{
		for(int i=1;i<n;i+=2){
			if(x.find(i)==x.end() || x.find(i)->second!=2)
				test=false;
		}
	}
	if(test){
		long long ans=1,e=n/2,mod=1E9+7;
		while(e--){
			ans*=2;
			if(ans>mod)
				ans%=mod;
		}
		cout<<ans;
	}
	else
		cout<<0;
}

Measured memory_bytes: 3200
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define MN 100005
using namespace std;
int n,f[MN];
deque<int> q;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)f[i]=1e9;f[1]=1;q.push_front(1);
	while(!q.empty()){
		int tmp=q.front();q.pop_front();
		if(f[tmp*10%n]>f[tmp])f[tmp*10%n]=f[tmp],q.push_front(tmp*10%n);
		if(f[(tmp+1)%n]>f[tmp]+1)f[(tmp+1)%n]=f[tmp]+1,q.push_back((tmp+1)%n);
	}printf("%d\n",f[0]);
}

Measured memory_bytes: 816
#include<stdio.h>

int main(){
    int array[500][500];
    int n,i,j,v,u,jisu;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            array[i][j] = 0;
        }
    }

    for(i=0;i<n;i++){
        scanf("%d%d",&u,&jisu);
        u = u - 1;
        for(j=0;j<jisu;j++){
            scanf("%d",&v);
            v = v - 1;
            array[u][v] = 1;
        }
    }

    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(j>0){
                printf(" ");
            }
            printf("%d",array[i][j]);
        }
        printf("\n");
    }

    return 0;
}


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

typedef long long ll;

ll gcd(ll a, ll b){
    if(a<b) return gcd(b,a);
    ll r;
    while(r=a%b){
        a = b; b = r;
    }
    return b;
}

int main(){
    int N,K;
    cin >> N >> K ;
    map<int,int> m;
    for(int i = 0; i < N; i++){
        int n;
        cin >> n;
        for(int j = 0; j < n; j++){
            int tmp;
            cin >> tmp;
            if(m.count(tmp) == 0){
                m[tmp] = 1;
            } else { 
                m[tmp] += 1;
            }
        }
    }
    int ans = 0;
    for(auto x: m){
        if(x.second == N){
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long double ld;
typedef complex<ld> Point;
typedef pair<double, int> P;

const ld eps = 1e-9, pi = acos(-1.0);

namespace std
{
bool operator<(const Point &lhs, const Point &rhs)
{
	if (lhs.real() < rhs.real() - eps)
		return true;
	if (lhs.real() > rhs.real() + eps)
		return false;
	return lhs.imag() < rhs.imag();
}
} // namespace std

Point input_point()
{
	ld x, y;
	cin >> x >> y;
	return Point(x, y);
}

bool eq(ld a, ld b)
{
	return (abs(a - b) < eps);
}

ld dot(Point a, Point b)
{
	return real(conj(a) * b);
}

ld cross(Point a, Point b)
{
	return imag(conj(a) * b);
}

class Line
{
  public:
	Point a, b;
	int own; //a�ЂȂ�1 b�ЂȂ�0
	int pos; //���˂Ȃ�1 �n���Ȃ�0
	Line() : a(Point(0, 0)), b(Point(0, 0)), own(-1), pos(-1) {}
	Line(Point a, Point b, int own, int pos) : a(a), b(b), own(own), pos(pos) {}
};

int ccw(Point a, Point b, Point c)
{
	b -= a;
	c -= a;
	if (cross(b, c) > eps)
		return 1; //a,b,c�������v���
	if (cross(b, c) < -eps)
		return -1; //a,b,c�����v���
	if (dot(b, c) < 0)
		return 2; //c,a,b�̏��Œ�����
	if (norm(b) < norm(c))
		return -2; //a,b,c�̏��Œ�����
	return 0;	  //a,c,b�Œ�����
}

bool isis_ss(Line s, Line t)
{ //�����Ɛ����̌����
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
		   ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

bool isis_sp(Line s, Point p)
{ //�_�̐����㔻��
	return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}

Point is_ll(Line s, Line t)
{ //�����ƒ����̌�_
	Point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

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

	int num;
	cin >> num;
	while (num--)
	{
		ld xa, ya, xb, yb;
		cin >> xa >> ya >> xb >> yb;
		Point a(xa, ya), b(xb, yb);
		int n;
		cin >> n;
		vector<Line> rosen; //�H���S��
		for (int i = 0; i < n; i++)
		{
			ld xs, ys, xt, yt;
			int o, l;
			cin >> xs >> ys >> xt >> yt >> o >> l;
			Point s(xs, ys), t(xt, yt);
			Line li(s, t, o, l);
			rosen.push_back(li);
		}
		Line route(a, b, 1, -1); //�n�_�I�_
		vector<P> lines;		 //P(�����Aindex) �����H�����X�g
		for (int i = 0; i < n; i++)
		{
			if (cross(route.b - route.a, rosen[i].b - rosen[i].a) == 0)
				continue;
			if (isis_ss(route, rosen[i]))
			{
				Point kouten = is_ll(route, rosen[i]);
				double dis = norm(route.a - kouten);
				lines.push_back(P(dis, i));
			}
		}
		sort(lines.begin(), lines.end());
		int res = 0, pos;
		if (lines.size() == 0)
		{
			cout << 0 << endl;
			continue;
		}
		int idx = lines[0].second;
		if (rosen[idx].own == 1)
		{
			pos = rosen[idx].pos;
		}
		else
		{
			pos = 1 - rosen[idx].pos;
		}
		for (int i = 0; i < (int)lines.size(); i++)
		{
			int idx = lines[i].second;
			//cout << idx<<" "<<pos << " " << rosen[idx].own << " " << rosen[idx].pos << endl;
			if (rosen[idx].own == 1)
			{
				if (rosen[idx].pos == pos)
					continue;
				else
				{
					pos = 1 - pos;
					res++;
				}
			}
			else
			{
				if (rosen[idx].pos != pos)
					continue;
				else
				{
					pos = 1 - pos;
					res++;
				}
			}
			//cout << i<<" "<<pos << endl;
		}
		cout << res << endl;
	}
}



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

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;

vvii g;
int n;

bool hascycle;
vi color;

void cycle(int v)
{
    color[v] = 1;
    for(ii u : g[v])
        if(!color[u.second])
            cycle(u.second);
        else if(color[u.second] == 1)
            hascycle = true;
    color[v] = 2;
}

vi sorted;

void toposort(int v)
{
    color[v] = 1;
    for(ii u : g[v])
        if(!color[u.second])
            toposort(u.second);
    sorted.push_back(v);
}

bool posible;
vi dis;

void check(int v, int d)
{ 
    color[v] = 1;
    dis[v] = d;
    for(ii u : g[v])
        if(!color[u.second])
            check(u.second, d + u.first);
        else if(dis[u.second] != d + u.first)
            posible = false; 
    color[v] = 2;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int m,x,y,w;
    while(cin >> n >> m)
    {
        g = vvii(n);
        for(int i = 0; i < m; i++)
        {
            cin >> x >> y >> w; x--; y--;
            g[x].push_back({w, y});
        }
        // Cycle check
        color = vi(n, 0); hascycle = false;
        for(int i = 0; i < n; i++)
            if(!color[i])
                cycle(i);
        if(hascycle)
            cout << "No" << '\n';
        else
        {
            // Toposort
            color = vi(n, 0); sorted.clear(); 
            for(int i = 0; i < n; i++)
                if(!color[i])
                    toposort(i);
            reverse(sorted.begin(), sorted.end());
            // Distance check
            color = vi(n, 0); dis = vi(n, 0); posible = true;
            for(int v : sorted)
                if(!color[v])
                    check(v, 0);
            cout << (posible? "Yes" : "No") << '\n';
        }
    }
    return 0;
} 

Measured memory_bytes: 11632
while(1):
 w,h = map(int,input().split())
 if((w == 0)and(h == 0)): break

 Map = []
 Map.append(['@']*(w+2))
 land = []
 for i in range(h):
  c = list('@'+input().replace(' ', '')+'@')
  Map.append(c)
  for j in range(w+2):
   if(c[j] == '1'): land.append([i+1,j])
 Map.append(['@']*(w+2))
 #print(land)

 #深さ優先探索
 def dfs(start_x,start_y):
  stack = []
  stack.append([start_x,start_y])
  
  while(1):      
   #stackが空になると終了
   if(stack == []): return
  
   #座標の取り出し
   cord = stack.pop()
   x,y = cord[0],cord[1]
  
   #行き止まりor海なら何もしない
   if((Map[x][y] == '0')or(Map[x][y] == '@')): continue
   #訪問済みなら何もしない
   elif(vis[x][y] == 1): continue
   else:
    vis[x][y] = 1 #訪問済みに

   #次行くところ
   vec_x = [0,0,1,-1,1,-1,1,-1]
   vec_y = [1,-1,0,0,1,-1,-1,1]
   for i in range(8):
     if(Map[x+vec_x[i]][y+vec_y[i]] == '1'):
       stack.append([x+vec_x[i],y+vec_y[i]])    
  
 ans = 0
 vis = [[0]*(w+2) for _ in range(h+2)]
 for i in range(len(land)):
  start_x,start_y = land[i][0],land[i][1]
  if(vis[start_x][start_y] == 0):
      dfs(start_x,start_y)
      ans += 1
      #print('aaa')
 print(ans)
   


Measured memory_bytes: 6568
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	1000005

int		N, pre[n], Q[n];

char	A[n], B[n];

int		main(int argc, char* argv[]){
// 		freopen("game.in", "r", stdin);
// 		freopen("game.out", "w", stdout);
	
		N= IN();
		scanf("%s%s", A+1, B+1);
		
		int flag= 0;
		For(i, 1, N)	if	(A[i] != B[i])	flag= 1;
		if	(! flag)	return	puts("0"), 0;
		
		for (int i= N, j= N; i; i--)	{
			j= min(j, i);
			for (; j && A[j] != B[i]; j--);
			if	(! j)	return	puts("-1"), 0;
			pre[i]= j;
		}
		
		int	Ans= 1, l= 1, r= 0;
		Rep(i, N, 1)	if	(pre[i] > pre[i-1])	{
			for (; l <= r && Q[l] - (r-l) > i; l++);
			if	(pre[i] < i)	Q[++ r]= pre[i], Ans= max(Ans, r-l+2);
		}
		printf("%d\n", Ans);
		
		return	0;
}

Measured memory_bytes: 9984
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  string s; cin >> s;
  deque<char> ans;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      if (ans.size() > 0) {
        ans.pop_back();
      }
    } else {
      ans.push_back(s[i]);
    }
  }
  outl(string(ans.begin(), ans.end()));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 504
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    s = s.replace("RRR","");
    if(s.length()==0){
      System.out.println(3);
      return;
    }
    s = s.replace("RR","");
    if(s.length()==1){
      System.out.println(2);
      return;
    }
    s = s.replace("R","");
    if(s.length()<3){
      System.out.println(1);
      return;
    }
    System.out.println(0);
  }
}


Measured memory_bytes: 36036
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std ;

#define to(k) E[k].to
#define next(k) E[k].next

const int N = 3050 ;

struct edge{
    int to ;
    int next ;
}E[N * N] ;

int res ;
int ctn ;
int n, m ;
int nienie ;
int vis[N] ;
int clr[N] ;
int cnt[2] ;
int head[N] ;
bool A[N][N] ;
bitset <N * N> ans ;

void add(int x, int y){
    to(++ ctn) = y ;
    next(ctn) = head[x] ;
    head[x] = ctn ;
}
void dfs(int x, int c){
    vis[x] = 1 ; clr[x] = c ; cnt[c] ++ ;
    for (int k = head[x] ; k ; k = next(k))
        if (!vis[to(k)]) dfs(to(k), c ^ 1) ;
        else if (clr[to(k)] == c) return nienie = 1, void() ;
}
int calc(int x){
    return x * (x - 1) + (n - x) * (n - x - 1) ;
}
int main(){
    cin >> n >> m ; ans[0] = 1 ;
    int u, v ; res = 1000000000 ;
    for (int i = 1 ; i <= m ; ++ i){
        scanf("%d%d", &u, &v) ;
        A[u][v] = A[v][u] = 1 ;
    }
    for (int i = 1 ; i <= n ; ++ i)
        for (int j = 1 ; j <= n ; ++ j)
            if (!A[i][j] && (i ^ j)) add(i, j) ;
    for (int i = 1 ; i <= n ; ++ i){
        if (!vis[i]){
            cnt[0] = cnt[1] = 0 ; dfs(i, 0) ;
            ans = (ans << cnt[0]) | (ans << cnt[1]) ;
        }
    }
    if (nienie) return puts("-1"), 0 ;
    for (int i = 1 ; i <= n ; ++ i)
        if (ans[i]) res = min(res, calc(i)) ;
    return cout << res / 2 << endl, 0 ;
}


Measured memory_bytes: 12928
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#define fup(i,a,b) for(int i=a;i<=b;i++)
#define fdw(i,a,b) for(int i=a;i>=b;i--)
#define sync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define cl(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
const int N=2e6+10;
int main()
{
    int n,m;
    cin>>n>>m;
    if(n!=m)puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-9
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	int n;
	cin >> n;
	vector<int> cnt(n + 1, false);
	for (int i = 2; i <= n; ++i)
		if (i * 2 <= n)
			for (int j = i * 2; j <= n; j += i)
				cnt[j]++;
	ll ans = 1;
	for (int i = 2; i <= n; ++i)
		ans += (cnt[i] + 2) * 1ll * i;
	cout << ans;
}

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

int main()
{
  int n;
  cin>>n;
  vector<int> v(n);
  for(int &i:v) cin>>i;
  cout<<*max_element(v.begin(),v.end()) - *min_element(v.begin(),v.end())<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

int N,M,K,X,Y;
int a,b,c,d;
string S,T;
int A,B;
void input()
{
    cin>>K>>A>>B;
}
void solve()
{
    X = 1;
    if (A>=B-1) {
        X += (K);
        cout<<X<<endl;return;
    }

    int cost = 0;

    for( ; X<A and K>=0; ++X){
        K--;
    }
    for ( ; K>1; K -= 2) {
        X += (B-A);
    }
    if (K) X++;
    cout<<X<<endl;

}
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top=0,S[1000];

void push(int x)
{
	S[++top]=x;
}

int pop()
{
	top--;
	return S[top+1];
}

int main()
{
	char a[10],ch;
	int x,y;
	while(1)
	{
		scanf("%s",a);
		if(a[0]=='+')
		{
			x=pop();
			y=pop();
			push(x+y);
		}
		else if(a[0]=='*')
		{
			x=pop();
			y=pop();
			push(x*y);
		}
		else if(a[0]=='-')
		{
			x=pop();
			y=pop();
			push(y-x);
		}
		else 
		{
			push(atoi(a));
		}
		if((ch=getchar())=='\n') break;
	}
	printf("%d\n",pop());
	return 0;
}


Measured memory_bytes: 2108
import java.util.*;

public class Main {
  public static void main(String[] args) {

    int[] num = {1,3,1,2,1,2,1,1,2,1,2,1};

    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt(); sc.close();

    if(num[x-1] == num[y-1]) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21716