akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int a,b,c;cin>>a>>b>>c;
    if(a%2 || b%2 || c%2){
        cout << 0 << endl;
        return 0;
    }
    if(a==b && b==c && c==a){
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    while(1){
        ans++;
        int na = b/2 + c/2;
        int nb = a/2 + c/2;
        int nc = a/2 + b/2;
        if(na%2 || nb%2 || nc%2){
            cout << ans << endl;
            return 0;
        }
        a = na;b = nb; c = nc;
    }
}



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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
    
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    int ans=0;
    if(k<=a){
        ans+=k;
        cout<<ans<<endl;
        return;
    }
    else{
        k-=a;
        ans+=a;
    }
    if(k<=b){
        ans+=b*0;
        cout<<ans<<endl;
        return;
    }
    else{
        ans+=b*0;
        k-=b;
    }

    ans-=k;
    cout<<ans<<endl;
    
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 7816
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();

        int i=0;
        int num=0;
        int A[]=new int[N+1];
        int B[]=new int[N+1];

        for(i=1;i<=N;i++){
            A[i]=sc.nextInt();
            B[A[i]]=i;
        }

        for(i=1;i<=N;i++){
            if(i==1){
                System.out.print(B[i]);
            }else{
                System.out.print(" "+B[i]);
            }
        }

        //END
    }
}



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

int main(void){
  int n, m, a, suki[50];
  cin >> n >> m;
  for(int i=0;i<=m;++i)suki[i] = 0;
  for(int i=0;i<n;++i){
    int k;
    cin >> k;
    for(int j=0;j<k;++j){
      cin >> a;
      ++suki[a];
    }
  }
  int cnt=0;
  for(int i=1;i<=m;++i){
    if(suki[i]==n) ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
     
    int main() {
    int n;
    cin >> n;
    vector<long long> p;
    vector<long long> q;
      long long s=0;
      for(int i = 0;i < n;i++){
        long long a;
        cin >> a;
       if(i%2==0)p.push_back(a);
        else {q.push_back(a);s+=a;}
      }
      if(n%2==0){
        long long t=0;
        long long h=0;
        for(int i = 0;i < n/2;i++){
          h += p.at(i)-q.at(i);
          t = max(h,t);
        }
        /*h = 0;
        for(int i = n/2-1;i > -1;i--){
          h += p.at(i)-q.at(i);
          t = max(h,t);
        }*/
        cout << s+t << endl;}
          else{
         vector <long long> t(n/2+1);
         vector <long long> r(n/2+1);
        long long h=0;
        for(int i = 0;i < n/2;i++){
          h += p.at(i)-q.at(i);
          t.at(i+1) = max(h,t.at(i));
        }
        h = 0;
        for(int i = n/2-1;i > -1;i--){
          h += p.at(i+1)-q.at(i);
          r.at(i) = max(h,r.at(i+1));
        } 
        long long ans = 0;
        for(int i = 0;i < n/2+1;i++){
          ans = max(t.at(i)+r.at(i),ans);
        }
            cout << ans+s << endl;
          }
    }

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

typedef long long ll;

ll a[200001];

int main () {
    ios_base :: sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    multiset <ll> m;
    for(ll i=1; i<=n; ++i) {
        cin>>a[i];
        m.insert(a[i]);
    }
    for(ll i=1; i<=n; ++i) {
        auto t = m.find(a[i]);
        if(t!=m.end())m.erase(t);
        cout<<*m.rbegin()<<"\n";
        m.insert(a[i]);
    }
    return 0;
}

Measured memory_bytes: 12544
#include <iostream>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#define max(x, y)	(((x) > (y))? (x) : (y))
#define abs(x)		(((x) < 0)? (-1*(x)) : (x))
#define REP(x,y)	for (i=(x);i<(y);i++)
using namespace std;

//int dp[10000][10000];
int i,A,B;
string S;

int main() {
	cin >> A >> B ;
  	cin >> S;
  	bool ng = false;
  
  	REP(0,A+B+1){
	    if (i!=A && S[i]=='-') ng=true;
    } 
  
  	if ( !ng && S[A] == '-'  && S.size() == (A+B+1))
		cout << "Yes" << endl;
  	else 
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
a,b,x= map(int,input().split())

import math
if (2*x)/(a*b) > a:
  tan = (a*b-(x/a))*2/(a*a)
  print(math.degrees(math.atan(tan)))
else:
  print(math.degrees(math.atan(a*b*b/(2*x))))

Measured memory_bytes: 3060
program main
  implicit none
  character(len=10) :: s
  integer :: i, j, l = 0

  read *, s

  do i = 1, 10
    do j = 10, i, -1
      if (verify(s(i:j), 'ATGC') .eq. 0) then 
        l = max(l, j-i+1)
        cycle
      end if
    end do
  end do

  print '(i0)', l

end program

Measured memory_bytes: 256
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, M;
Vec< Vec< int > > adj;
Vec< bool > vis;

void dfs(int v) {
	if (vis[v]) return;
	vis[v] = true;
	for (int u : adj[v]) dfs(u);
}

int main() {
	cin >> N >> M;
	adj.assign(N + M, Vec< int >());
	for_(i,0,N) {
		int K;
		cin >> K;
		for_(j,0,K) {
			int L;
			cin >> L;
			--L;
			adj[i].push_back(N+L);
			adj[N+L].push_back(i);
		}
	}
	
	vis.assign(N+M, false);
	dfs(0);
	
	for_(i,0,N) {
		if (!vis[i]) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 8440
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int gcd(int a, int b) {
    if (b == 0)
        return a;

    return gcd(b, a%b);
}

int main(void)
{
    int N;
    cin >> N;

    long long ans = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            for (int k = 1; k <= N; k++)
                ans += gcd(gcd(i, j), k);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
   int r;cin>>r;
   cout<<r*r<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(void) {
	int D, N;

	scanf("%d %d", &D, &N);

	if (N == 100){
		switch (D) {
		case 0:
			printf("101\n");
			break;
		case 1:
			printf("10100\n");
			break;
		default:
			printf("1010000\n");
			break;
		}
		fflush(stdout);
		return 0;
	}
	switch (D) {
	case 0:
		printf("%d\n", N);
		break;
	case 1:
		printf("%d00\n", N);
		break;
	default:
		printf("%d0000\n", N);
		break;
	}
	fflush(stdout);

	return 0;
}


Measured memory_bytes: 128
N,M = list(map(int, input().split()))
P = []
Y = []
for _ in range(M):
    p,y = list(map(int, input().split()))
    P.append(p)
    Y.append(y)
count = [0]*(N+1)
ans = [0]*(M+1)
data = [[p,y,i] for p,y,i in zip(P,Y,range(1,M+1))]

data.sort(key=lambda x: x[1])

for i in range(M):
    count[data[i][0]] += 1
    ans[data[i][2]] = count[data[i][0]]


for j in range(1,M+1):
    a = P[j-1]
    b = ans[j]
    print(str(a*(10**6)+b).zfill(12))






Measured memory_bytes: 30524
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;
using vd = vector<ld>;

template<class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<class TIn, class TOut = null_type>
using order_tree = tree<TIn, TOut, less<TIn>, rb_tree_tag,
	tree_order_statistics_node_update>;
// .find_by_order(int r) and .order_of_key(TIn v)

constexpr int INF = 2000000010;
constexpr ll LLINF = 9000000000000000010LL;
constexpr ld PI = acos(-1);

struct block { ll l, d; };
bool test(int m, const vi &A) {
	if (!m) return false;
//	cerr << "Testing " << m << endl;
	vector<block> b{block{A[0], 1}};
	for (size_t i = 1; i < A.size(); ++i) {
		if (A[i-1] < A[i]) {
			b.push_back(block{A[i] - A[i-1], 1});
		} else {
			// Pop some blocks
			ll tp = A[i-1] - A[i];
			while (tp > 0) {
				if (b.back().l <= tp)
					tp -= b.back().l, b.pop_back();
				else
					b.back().l -= tp, tp = 0;
			}
			// Increment.
			bool ok = false;
			ll readd = 0LL;
			for (int j = (int)b.size()-1; j >= 0; --j) {
				if (b[j].d < m) {
					if (b[j].l == 1)
						b[j].d++;
					else
						b[j].l--, b.push_back({1, b[j].d+1});
					ok = true;
					break;
				} else {
					readd += b[j].l;
					b.pop_back();
				}
			}
			if (!ok) return false;
			if (readd) b.push_back(block{readd, 1});
		}
//		cerr << "Blocks after stage " << i << endl;
//		for (block bl : b) cerr << " (" << bl.l << ", " << bl.d << ") ";
//		cerr << endl;
	}
	return true;
}

void solve() {
	int N;
	cin >> N;

	vi A(N);
	for (ll &a : A) cin >> a;

	int l = 0, r = N+10;
	while (l < r) {
		int m = (l + r) / 2;
		if (test(m, A))
			r = m;
		else
			l = m + 1;
	}
	cout << l << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(12);
	
	solve();
	
	return 0;
}


Measured memory_bytes: 9104
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323


#define TST 0

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;
    vl a(n);
    long sum = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        sum = sum ^ a[i];
    }
    for(int i = 0;i < n;i++){
        long sunuke = sum ^ a[i];
        cout << sunuke;
        if(i == n-1){
            cout << endl;
        }else{
            cout << " ";
        }
    }

#if TST==1

#endif
}



Measured memory_bytes: 4780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  vector<ll> data;
  
  // REP(i, 1, N) a[i] += a[i - 1];
  REP(i, 0, N){
    ll sum = 0;
    REP(j, i, N){
      sum += a[j];
      data.push_back(sum);
    }
  }
  // cout << "size_sheck: " << N*(N+1)/2 << " " << data.size() << endl;
  // for(auto x : data) cout << x << " "; cout << endl;
  
  ll bit = 1;
  while(10000000000000LL >= (2LL<<bit)){
    bit++;
  };

  while(bit != -1){
    // cout << "turn: " << (2LL<<bit) << endl; 
    vector<ll> hit;
    for(auto &x : data){
      if(x&(2LL<<bit)) hit.push_back(x);
    }
    if(K<=hit.size()){
      data.resize(hit.size());
      copy(all(hit), data.begin());
    }
    // for(auto x : data) cout << x << " ";cout << endl;
    bit--;
  }

  ll ans = LLONG_MAX;
  for(auto &x : data)if(x)ans = ans & x;
  cout << ans << endl;
  return 0;
}


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

int main() {
  	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  	int n;
  	cin >> n;
  	cout << (n % 2 == 0? n - 1: n) / 2 << "\n";
  	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
n = [a for a in A if a < 0]
S = sum([abs(a) for a in A])
if len(n) % 2 == 0:
    print(S)
else:
    print(S - 2 * min([abs(i) for i in A]))

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

long long a,b,x;

int main() {

    while(cin>>a>>b>>x) {

        if(a==0) {
            printf("%lld\n",b/x+1);
        } else {

            printf("%lld\n",b/x-(a-1)/x);

        }

    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int zs;
string st;
int main()
{
	cin>>st;
	for (int i=0;i<st.size()-1;i++)
	  if (st[i]!=st[i+1]) zs++;
	cout<<zs<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000'000'007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a >= 10 || b >= 10){
    cout << -1 << endl;
  }
  else{
	cout << a*b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
a,b,x=map(int,input().split())

import math

if (a*a*b)/2 < x :
  d=(-1/(a**2)*x+b)*2/a
  print(math.degrees(math.atan(d))) 

else:
  e=(2*x)/(a*b*b)
  print(90-math.degrees(math.atan(e))) 

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e6 + 3)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
int exp(int a, int b){
    LL res = 1;
    LL sum = a;
    for(int i=0;i<30;++i){
        if(BIT(i)&b){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
    }
    return res;
}

int main(){
    map<char, int> c2i;
    c2i['N']=0;
    c2i['S']=1;
    c2i['E']=2;
    c2i['W']=3;
    bool check[4]={0};
    string str;
    cin >> str;
    REP(i, str.size()){
        check[c2i[str[i]]] = 1;
    }
    cout << ((check[0]!=check[1])||(check[2]!=check[3])?"No":"Yes") << endl;
    return 0;
}


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

long long const MOD = 1000000007LL;

long long gcd(long long a, long long b) {
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    int n;
    cin >> n;

    long long t;
    cin >> t;
    long long res = t;
    long long nowGcd = t;
    long long fuctorial = t;
    
    for (int i = 0; i < n - 1; i++) {
        cin >> t;
        nowGcd = gcd(res, t);

        res = res / nowGcd * t;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,m = map(int,input().split())
# 配列入力の受け取り
# arrA = list(map(int,input().split()))
arrA = np.array(input().split(),dtype=np.int64)

arrA.sort()
arrA = arrA[::-1]
total = arrA.sum()

if arrA[m-1] >= total/(4*m):
    ans = "Yes"
else:
    ans = "No"

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Measured memory_bytes: 14420
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int N, M;
    cin >> N >> M;
    vector<vector<int> > G(N);
    rep(i, 0, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int Q;
    cin >> Q;
    vector<int> v(Q), d(Q), c(Q);
    rep(i, 0, Q) {
        cin >> v[Q - i - 1] >> d[Q - i - 1] >> c[Q - i - 1];
        v[Q - i - 1]--;
    }

    vector<vector<bool> > used(N, vector<bool>(11, false));
    vector<int> ans(N);

    function<void(int, int, int)> func = [&](int vv, int dd, int cc) {
        if (used[vv][dd]) return;
        used[vv][dd] = true;
        if (dd == 0) {
            ans[vv] = cc;
            return;
        }
        func(vv, dd - 1, cc);
        for (auto child : G[vv]) {
            func(child, dd - 1, cc);
        }
    };

    rep(i, 0, Q) {
        func(v[i], d[i], c[i]);
    }

    for (int i = 0; i < N; ++i) {
        cout << ans[i] << endl;
    }


    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

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

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve() {
  int N; cin >> N; LL H, H_prev; H_prev = -1;
  int range=0; int ans=0;
  REP0(i, N){
    cin >> H;
    if (H_prev >= H) range++;
    else range=0;
    ans = max(ans, range);
    H_prev = H;
  }
  cout << ans << endl;
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=300005;
const int P=998244353;

int n;
char str[N];
int a[N],cur,ans;

void init(){
	scanf("%d",&n);
	scanf("%s",str);
	for(int i=0;i<n;i++) if(str[i]=='E') a[i]=0; else a[i]=1;
	for(int i=1;i<n;i++) if(a[i]==0) cur++;
	ans=cur;
	for(int i=1;i<n;i++){
		if(a[i]==0) cur--;
		if(a[i-1]==1) cur++;
		ans=min(ans,cur);
	}
	printf("%d\n",ans);
}

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

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
int gcd(const vector<int> &v) {
	int ret = v[0];
	for (int i = 1; i < v.size(); i++)
		ret = gcd(ret, v[i]);
	return ret;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> A(N); rep(i, 0, N) {
		cin >> A[i];
	}
	sort(all(A));
	vector<int> v;
	rep(i, 0, N - 1) {
		if (A[i + 1] == A[i])continue;
		v.emplace_back(A[i + 1] - A[i]);
	}
	rep(i, 0, N) {
		if (A[i] == K) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	if (v.size() == 0) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	int g = gcd(v);
	dump(g);

	if (K < min(A[0], g) || A.back() < K) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	rep(i, 0, N) {
		if (A[i] < K) {
			if ((K - A[i]) % g == 0) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,i,c=0;
    cin>>n;
    string s;
    cin>>s;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R')
        c++;
    }
    int ans=c;
    for(i=0;i<c;i++)
    {
        if(s[i]=='R')
        ans--;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

int dp[55][55][2510];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE t(n), a(n); rep(i, n)cin >> t[i] >> a[i];
	int x = 1, y = 1;
	rep(i, n) {
		int tmp = max((x + t[i] - 1) / t[i], (y + a[i] - 1) / a[i]);
		x = tmp * t[i]; y = tmp * a[i];
	}
	cout << x + y << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    map<Int, Int> mp;
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    Int res = 0;
    for (Int i = n - 1; i > 0; i--) {
        for (Int j = i - 1; j >= 0; j--) {
            if (a[j] > a[i]) res++;
            res %= mod;
        }
    }
    res = (res * k) % mod;
    if (k == 1) {
        dump(res);
        return 0;
    }
    vector<Int> x(3000, 0);
    for (Int i = 0; i < n; i++) x[a[i]]++;
    for (Int i = 2500; i > 0; i--) {
        x[i - 1] += x[i];
    }   
    for (auto i : mp) {
        Int add = (x[i.fi + 1] * i.se) % mod;
        Int mul = k * (k - 1) / 2 % mod;
        res += add * mul % mod;
        res %= mod;
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;

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

    char maze[h][w];

    for(long long i = 0; i < h; i++){
        for(long long j = 0; j < w; j++){
            cin >> maze[i][j];
        }
    }

    long long maxv = 0;
    for(long long sy = 0; sy < h; sy++){
        for(long long sx = 0; sx < w; sx++){
            for(long long gy = 0; gy < h; gy++){
                for(long long gx = 0; gx < w; gx++){
                    if(sy == gy and sx == gx) continue;
                    if(maze[sy][sx] == '#' || maze[gy][gx] == '#') continue;

                    queue<pair<long long, long long> > q;
                    vector<vector<long long> > dist(h, vector<long long>(w, -1));
                    q.push(make_pair(sy, sx));
                    dist[sy][sx] = 0;

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

                    while(!q.empty()){
                        pair<long long, long long> top;
                        top = q.front();
                        q.pop();

                        for(long long i = 0; i < 4; i++){
                            if(0 <= top.first + dy[i] and top.first + dy[i] < h and 0 <= top.second + dx[i] and top.second + dx[i] < w and maze[top.first+dy[i]][top.second+dx[i]] != '#' and dist[top.first+dy[i]][top.second+dx[i]] == -1){
                                dist[top.first+dy[i]][top.second+dx[i]] = dist[top.first][top.second] + 1;
                                q.push(make_pair(top.first+dy[i], top.second+dx[i]));
                            }
                        }
                    } 

                    maxv = max(maxv, dist[gy][gx]);
                }
            }
        }
    }
    cout << maxv << endl;
    return 0;
}

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

int main(){
    long long a;
    long long b;
    long long c;
    long long d;
    cin >> a >> b >> c >> d;
    long long ans;
    ans = max(max(a*c,a*d),max(b*c,b*d));
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int n;
void dfs(string s,char mx){
  if(s.size()==n){
    cout << s << endl;
  }
  else{
    for(char c='a';c<=mx;c++){
      if(c==mx) dfs(s+c,mx+1);
      else dfs(s+c,mx);
    }
  }
}

int main(){
  cin >> n;
  dfs("a",'b');
  
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    vector<vector<int>> a;
    for (int i = 0; i < 2; i++) {
        a.push_back(vector<int>(n));
        for (int j = 0; j < n; j++) cin >> a[i][j];
    }
    for (int i = 1; i < n; i++) {
        a[0][i] += a[0][i-1];
    }
    for (int i = n - 1; i > 0; i--) {
        a[1][i-1] += a[1][i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, a[0][i] +a[1][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  ll n,k; cin >> n >> k;
  cout << min(n%k,abs(n%k-k)) << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    string s;
    int q;
    cin >> s >> q;
    int n = s.length();
    deque<char> deq;
    for(int i = 0; i < n; ++i)  deq.push_back(s[i]);
    bool flag = true;
    for(int i = 0; i < q; ++i){
        int type;
        cin >> type;
        if(type == 1)   flag ^= true;
        else{
            int f;
            char ch;
            cin >> f >> ch;
            if(f == 1){
                if(flag)    deq.push_front(ch);
                else    deq.push_back(ch);
            }
            else{
                if(flag)    deq.push_back(ch);
                else    deq.push_front(ch);
            }
        }
    }
    if(flag){
        while(!deq.empty()){
            cout << deq.front();
            deq.pop_front();
        }
    }
    else{
        while(!deq.empty()){
            cout << deq.back();
            deq.pop_back();
        }
    }
    cout << '\n';
}

Measured memory_bytes: 976
#include<stdio.h>
int main()
{
    int a,b,c,m;
    scanf("%d %d %d",&a,&b,&c);
    m=a*b;
    if(c>m)
    {
        printf("%d",m);
    }
    else
    {
        printf("%d\n",c);
    }
    return 0;

}


Measured memory_bytes: 256
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let NQ = lines.shift().trim().split(/\s/).map((v) => v - 0);
    let N = NQ[0], Q = NQ[1];
    let S = lines.shift().trim();
    let left = 0;
    let right = N - 1;
    for (let n = Q-1; n >= 0; n--) {
        let td = lines[n].trim().split(/\s/);
        let t = td[0], d = td[1];
        if      (S.charAt(left-1 ) === t && d === "R") left--;
        else if (S.charAt(left   ) === t && d === "L") left++;
        if      (S.charAt(right  ) === t && d === "R") right--;
        else if (S.charAt(right+1) === t && d === "L") right++;
        if (left > right) break;
    }
    console.log(right - left + 1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

map<char, char> mp;

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

	int A[26], B[26];
	REP(i, 26) A[i] = -1;
	REP(i, 26) B[i] = -1;

	bool flag = true;
	REP(i, S.size()){
		if(A[S[i]-'a']==-1){
			A[S[i]-'a'] = T[i]-'a';
		}else{
			if(A[S[i]-'a'] != T[i]-'a') flag = false;
		}

		if(B[T[i]-'a']==-1){
			B[T[i]-'a'] = S[i]-'a';
		}else{
			if(B[T[i]-'a'] != S[i]-'a') flag = false;
		}
	}
	cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 50;
char G[maxn][maxn];
int  d[maxn][maxn];
int ans = 0;
int W,H;

int valid(int x,int y){
    return (x >=0 && y >= 0 && x<=W-1 && y <= H-1 && G[x][y] == '.');
}

void bfs(int x,int y){
    d[x][y] = 0;
    queue<pii> que;
    que.push(MP(x,y));
    while(!que.empty()){
        pii k = que.front();que.pop();
        for(int i = 0;i < 4;i++){
            int nx = k.first + dx[i];
            int ny = k.second + dy[i];
            if(valid(nx,ny) && d[nx][ny] == -1){
                d[nx][ny] = d[k.first][k.second] + 1;
                ans = max(ans,d[nx][ny]);
                que.push(MP(nx,ny));
            }

        }
    }


}

int main()
{
    cin >> W >> H;
    getchar();
    _for(i,0,W){
        fgets(G[i],maxn,stdin);
    }
    _for(i,0,W){
        _for(j,0,H){
            MEM(d,-1);
            if(valid(i,j))
                bfs(i,j);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main() {
	int H, W;

	cin >> H >> W;

	char mineField[H][W];
	int counter[H][W];
	

	for (int i = 0 ; i < H ; i++) {
		string s;
		cin >> s;
		for (int j = 0 ; j < W ; j++) {
			mineField[i][j] = s.at(j);
		}
	}

	for (int i = 0 ; i < H ; i++) {
		for (int j = 0 ; j < W ; j++) {
			counter[i][j] = 0;
		}
	}

	for (int s = 0 ; s < H ; s++) {
		for (int t = 0 ; t < W ; t++) {
			if (mineField[s][t] == '#') {

				if ( (s + 1 < H) && (t + 1 < W) ){
					if( mineField[s + 1][t + 1] == '.' ){
						counter[s + 1][t + 1]++;
					}
				}

				if ( s + 1 < H){
					if( mineField[s + 1][t] == '.' ){
						counter[s + 1][t]++;
					}
				}

				if ((s + 1 < H) && (t > 0) ){
					if( mineField[s + 1][t - 1] == '.' ){
						counter[s + 1][t - 1]++;
					}
				}

				if (t + 1 < W ) {
					if( mineField[s][t + 1] == '.' ){
						counter[s][t + 1]++;
					}
				}

				if (t > 0){
					if( mineField[s][t - 1] == '.' ){
						counter[s][t - 1]++;
					}
				}

				if ( (s > 0) && (t + 1 < W ) ){
					if( mineField[s - 1][t + 1] == '.' ){
						counter[s - 1][t + 1]++;
					}
				}

				if (s > 0) {
					if( mineField[s - 1][t] == '.' ){
						counter[s - 1][t]++;
					}
				}

				if (( s > 0 ) && (t > 0) ) {
					if( mineField[s - 1][t - 1] == '.' ){
						counter[s - 1][t - 1]++;
					}
				}
			}
		}
	}

	for (int s = 0 ; s < H ; s++) {
		for (int t = 0 ; t < W ; t++) {
			if (mineField[s][t] == '#') {
				cout << "#";
			} else {
				cout << counter[s][t];
			}
		}
		cout << endl;
	}
}

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

int main() {
  int n,m,c;
  cin>>n>>m>>c;
  int ans =0;
  vector<int> b(m);
  for(int i=0;i<m;i++)
    cin >> b[i];
  
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a[i][j];
    }
  }
  
  for(int i=0;i<n;i++){
    int sum =c;
    int j=0;
    while(j<m){
      sum += (a[i][j])*b[j];
      j++;
    }
    if(sum>0)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

int main(){
    ll n,m,ans;
    cin>>n>>m;
    vector<ll>x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
        x[i]=abs(m-x[i]);
    }
    if(n==1){
        cout<<x[0];
        return 0;
    }
    for(int i=0;i<n-1;i++){
        if(i==0) ans=__gcd(x[i],x[i+1]);
        else ans=__gcd(x[i],ans);
    }
    cout<<ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    vector<vector<int>> v(3, vector<int>(3));
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> v[i][j];
        }
    }
    bool flag = true;
    for (int i = 0; i < 2; ++i) {
        int x = v[i][0] - v[i + 1][0];
        for (int j = 1; j <= 2; ++j) {
            if (v[i][j] - v[i + 1][j] != x) {
                flag = false;
            }
        }
    }
    for (int i = 0; i < 2; ++i) {
        int x = v[0][i] - v[0][i+1];
        for (int j = 1; j <= 2; ++j) {
            if(v[j][i] - v[j][i+1] != x){
                flag = false;
            }
        }
    }
    cout << (flag ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 256
words = lambda t : list(map(t, input().split()))
n,m,v,p = words(int)
a = words(int)

a.sort()
ans = p-1
end = n-p+1
loopend = n-v+1
sm = sum(a[0:end])
needed = (v - (p-1)) * m
#print(a)
for i in range(end):
    sm -= a[i]
    needed -= m
    if a[i] + m < a[end-1]:
        continue
    max_score = (a[i] + m) * (end-i-1) - sm
    #print(a[i]+m, end-i-1, sm)
    #print(max_score, needed)
    if needed <= max_score:
        ans = n-i
        break
print(ans)


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

bool flg = false,flg2 = false;
int n,k,d[10];


void cal(int h){
    int x = h;
    flg = false;
    while(x > 0){
        for(int i = 0;i < k;i++){
            if(x % 10 == d[i]){
                flg = true;
            }
        }
        x /= 10;
    }
    if(!flg) flg2 = true;
}

int main(void){
    cin >> n >> k;
    for(int i = 0;i < k;i++) cin >> d[i];
    for(int i = n;i < 10*n;i++){
        cal(i);
        if(flg2){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
N,A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for _ in range(50*(N+2))] for _ in range(N+2)] for _ in range(N+2)]

dp[0][0][0] = 1
#kまでみた
for k in range(N):
    #used個使った
    for used in range(N):
        for i in range(50*N):
            #使う時
            if dp[used][k][i] == 0: 
                continue
            dp[used+1][k+1][i+X[k]] += dp[used][k][i]
            dp[used][k+1][i] += dp[used][k][i]
ans = 0
for used in range(1,N+1):
    ans += dp[used][N][used*A]
print(ans)




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

using namespace std;

int H[500010], N[500010], G[500010], V[500010], Cnt = 0;

void addedge(int x, int y) {G[++Cnt] = y, N[Cnt] = H[x], H[x] = Cnt;}

void DFS(int x, int f = -1)
{
	for(int T = H[x]; T; T = N[T]) if(G[T] != f) DFS(G[T], x), V[x] ^= V[G[T]];
	V[x]++;
}

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		addedge(a, b), addedge(b, a);
	}
	DFS(1);
	puts(V[1] == 1 ? "Bob" : "Alice");
	return 0;
}

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

ll n;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    string res="";
    while(n){
        res=(char)(97+(n-1)%26)+res;
        n=(n-1)/26;
    }
    
    
    cout<<res;
    
    return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys
import math
## 組み合わせの総数だけ知りたい
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, M: int):
    answer = 0
    if N >= 2:
        answer += comb(N,2)
    
    if M >= 2:
        answer += comb(M,2)

    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060