akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#define df 0
typedef long int li;
void rem(li x,li& you,li& others,int n);
int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >> n;
  li a[n],s=0;
  for(auto& x:a){
    cin >> x;
    s+=x;
  }
  
  li y[n],oth[n];
  for(int i=0;i<n;i++){
    y[i]=oth[i]=0;
  }
  bool flag;
  do{
    li sum=0;
      for(int i=0;i<n;i++){
	rem(a[i],y[i],oth[i],n);
	sum+=oth[i];
      }
    flag=false;
    li amin=sum+y[0];
    for(int i=0;i<n;i++){
      a[i]=sum+y[i]-oth[i];
      if(a[i]>=n)flag=true;
      if(a[i]<amin)amin=a[i];
      y[i]=oth[i]=0;
      if(df)printf("%ld ",a[i]);
    }
    if(df)printf("\n");
    if(amin>=n){
      amin-=n-1;
      for(auto& x:a){
	x-=amin;
	if(df)printf("%ld ",x);
      }
      if(df)printf("\n");
    }
    sum=0;
  }while(flag);
  li sum=0;
  for(auto& x:a) sum+=x;
  printf("%ld",s-sum);
}


void rem(li x,li& you,li& others,int n){
  you+=x%n;
  x/=n;
  others+=x%n;
  x/=n;
  if(x){
    rem(x,you,others,n);
  }
}

/// confirm df==0 ///


Measured memory_bytes: 256
N, A, B, C = [int(item) for item in input().split()]

take = [int(input()) for i in range(N)]

def dfs(n, a, b, c):
  if n == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 10**9
  ret0 = dfs(n+1, a+take[n], b, c) + 10
  ret1 = dfs(n+1, a, b+take[n], c) + 10
  ret2 = dfs(n+1, a, b, c+take[n]) + 10
  ret3 = dfs(n+1, a, b, c)
  return min(ret0, ret1, ret2, ret3)

ans = dfs(0, 0, 0, 0)
print(ans)

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

int main(){
    int S, h, m, s;
    cin >> S;

    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;

    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3096
k, n = map(int, input().split())
a = list(map(int, input().split()))

j = 0
i = 0
while i<n:
    if i == n-1:
        x = k + a[0] - a[i]
    else:
        x = a[i+1] - a[i]
    if x>j:
        j=x
    i+=1

print(k-j)


Measured memory_bytes: 26444
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

long long lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    int a, b; cin >> a >> b;
    cout << lcm(a, b) << endl;
    return 0;
}


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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, ans=0, tmp=0;
vector<ll> A;
string S;

signed main(){
    cin >> S;
    tmp = S.size()-2;
    if(S[0]==S.back()) tmp--;
    if(tmp%2) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}

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

#define N 10

int main() {
	static char s[N + 1];
	int n, i, min;

	scanf("%s", s);
	n = strlen(s);
	min = 123456;
	for (i = 0; i < n - 2; i++) {
		int a = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		 
		if (min > abs(a - 753))
			min = abs(a - 753);
	}
	printf("%d\n", min);
	return 0;
}


Measured memory_bytes: 128
n=int(input())
a=[]
for i in range(n):
    ai=int(input())
    a.append(ai)
    
right=[0]
left=[0]
maxr=0
maxl=0
for i in range(n-1):
    maxl=max(maxl,a[i])
    maxr=max(maxr,a[-i-1])
    left.append(maxl)
    right.append(maxr)
for i in range(n):
    print(max(left[i],right[-i-1]))

Measured memory_bytes: 15644
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,c=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]!=i+1)
      c++;
  }
  if(c>2)
    return cout<<"NO",0;
  
  return cout<<"YES",0;
}

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

using namespace std; 
#define fr for(int i = 0;i < n;i++)
#define pb push_back
void printVector(set<int>x){
    for(auto i:x){
        cout << i << " ";
    }
    cout << endl;
}


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

    char c;
    cin >> c;
    if(c >= 65 && c <= 90) cout << 'A';
    else cout << 'a' << endl;

}

Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;


void solve(std::vector<long long> T, std::vector<long long> A, std::vector<long long> B){
    ll T1 = T[0], T2 = T[1], A1 = A[0], A2 = A[1], B1 = B[0], B2 = B[1];
    ll TA1 = T1 * A1, TA = TA1 + T2 * A2, TB1 = T1 * B1, TB = TB1 + T2 * B2;
    if(TA == TB){
        cout<< "infinity"<<endl;
        return;
    }
    ll WT = T1 + T2;
    if(TA > TB) {
        swap(TA, TB); swap(TA1, TB1);
    }
    //* NOW TA < TB
    if(TB1 > TA1) {
        cout<<0<<endl; return;
    }

    ll delta = TB - TA;
    ll ans = (TA1 - TB1 +1 + delta - 1) / delta;
    if(ans == 1) cout<< 1<<endl;
    else if((ans -1) * delta == TA1 - TB1){
        cout<< 2*ans - 2<<endl;
    }
    else{
        cout<<2*ans-1<<endl;
    }
    
    
}

int main(){
    std::vector<long long> T(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&T[i]);
    }
    std::vector<long long> A(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&B[i]);
    }
    solve(std::move(T), std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
#include<numeric>

int gcd(int x, int y) {
	return y ? gcd(y, x % y) : x;
}
int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vector<int>L(n+1),R(n+1);
	L[0] = 0;
	R[0] = 0;
	rep(i, n) {
		L[i + 1] = gcd(L[i], a[i]);
	}
	rep(i, n) {
		R[i + 1] = gcd(R[i], a[n -1- i]);
	}
	vector<int>m(n);
	int ans = 0;
	rep(i, n) {
		
		m[i] = gcd(L[i], R[n - i-1]);
		
		ans = max(ans, m[i]);
	}
	cout << ans;
	return 0;
}

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

int dep[101000], fa[101000], root, rfa[101000], ans[101000], cnt[101000];
int pnt, in[101000], x, y, n;
vector<int> g[101000];

void Dfs(int x) {
  //cerr << x << endl;
  if(dep[root] < dep[x])
    root = x;
  for(int i = 0; i < g[x].size(); i++) {
    int v = g[x][i];
    if(v == fa[x]) continue;
    dep[v] = dep[x] + 1;
    fa[v] = x;
    Dfs(v);
  }
}

void Out(int x, int *a) {
  int now = 1, pnt = 0;
  for(; x; x = a[x]) {
    for(int i = now + 1; i <= now + cnt[x]; i++)
      ans[i - 1] = i;
    ans[now + cnt[x]] = now; 
    now += cnt[x] + 1;
  }
}

bool Solve(void) {
  if(dep[root] == 1) {
    ans[1] = 1, ans[2] = 2;
    return 1;
  }
  int head = root, tail = root;
  while(root) {
    in[root] = 1;
    tail = root;
    if(fa[root]) rfa[fa[root]] = root;
    root = fa[root];
  }
  cerr << head << " " << tail << endl;
  for(int i = 1; i <= n; i++)
    if(!in[i] && !in[fa[i]]) return 0;
    else if(!in[i]) ++cnt[fa[i]];
  bool flg = 0;
  for(int h = head, t = tail; h != tail; h = fa[h], t = rfa[t])
    if(cnt[h] != cnt[t]) {
      if(cnt[h] < cnt[t])
	Out(head, fa);
      else Out(tail, rfa);
      flg = 1;
      break;
    }
  if(!flg) Out(head, fa);
  return 1;
}

int main(void) {
  scanf("%d", &n);
  for(int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  Dfs(1);
  //cerr << root << endl;
  fa[root] = 0;
  dep[root] = 0;
  Dfs(root);
  //cerr << root << endl;
  if(Solve())
    for(int i = 1; i <= n; i++)
      printf("%d ", ans[i]);
  else puts("-1");
  return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
#define ll long long
#define SZ(vvv) ((int)vvv.size())
#define fastIO cout << fixed << setprecision(3), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 4e5 + 5, M = 205, OO = 1e9, MOD2 = 1e9 + 7;
const ll INF = 1e18;

void runtestcase() {
    string str;
    cin >> str;
    str = string(str.size(), '0') + str;
    int n = SZ(str) - 1;
    int ans = 0;
    for (int i = n; i >= 0; --i) {
        if(str[i] > '9') {
            str[i - 1]++;
            str[i] -= 10;
        }
        if(str[i] > '5') {
            ans += 10 - (str[i] - '0');
            str[i - 1]++;
        } else{
            if(str[i] <= '4' || (str[i] == '5' && str[i - 1] < '5')) {
                ans += str[i] - '0';
            } else {
                ans += 10 - (str[i] - '0');
                str[i - 1]++;
            }
        }
    }
    cout << ans;
}

int main() {
    fastIO;
#ifdef LOCAL
    freopen("input.in", "rt", stdin);
//    freopen("output.in", "wt", stdout);
#endif
    int t = 1, tt = 1;
//    cin >> t;
    while(t) {
//		cout << "Case #" << tt << ':' << ' ';
        runtestcase();
//        cout << '\n';
        --t, ++tt;
    }
}


Measured memory_bytes: 7120
S = input()
for i in range(len(S)):
  if S[i] == "U":
    continue
  if S[i] == "D":
    continue
  if i % 2 == 1:
    if S[i] == "L":
      continue
  else:
    if S[i] == "R":
      continue
  print("No")
  exit()
print("Yes")

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

int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  int res = 0;
  for (int x = 0; x < n; x++) {
    for (int y = x+1; y < n; y++) {
      res += v.at(x) * v.at(y);
    }
  }
  cout << res << '\n';
  return 0;
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    string t;
    cin>>s>>t;
    s = s+s;
    
    bool c = false;
    for(int i=0; i<s.length()-t.length(); i++){
        if(s.substr(i,t.length())==t){
            c = true;
            break;
        }
    }
    if(c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 3228
N = int(input())
S = input()
 
left = 0
right = S[1:].count("E")
ans = left + right

for i in range(1, N):
    if S[i - 1] == "W":
        left += 1
    if S[i] == "E":
        right -= 1 
    ans = min(ans, left + right)
print(ans)

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int search_good_observatory(vector<long> &myh,vector<vector<int>> &mydata,int x)
{
  if(mydata.at(x).size() == 0)return 1;
  for(int i = 0 ; i < (int)mydata.at(x).size() ; i++)
  {
    if(myh.at(x) <= myh.at(mydata.at(x).at(i)-1)) return 0;
  }
  return 1;
}

vector<long> h;
int main(void)
{
  int N,M;
  cin >> N >> M;
  h = vector<long>(N);
  vector<int> A(M),B(M);
  for(int i = 0 ; i < N ; i++)cin >> h.at(i);
  for(int i = 0 ; i < M ; i++)cin >> A.at(i) >> B.at(i);
  vector<vector<int>> data(N);
  for(int i = 0 ; i < M ; i++)
  {
    data.at(A.at(i)-1).push_back(B.at(i));
    data.at(B.at(i)-1).push_back(A.at(i));
  }
  int ans = 0;
  for(int i = 0 ; i < N ; i++)
  {
    ans += search_good_observatory(h,data,i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9800
r, c = map(int, input().split())
a = []
ans = []
for i in range(r):
    t = list(map(int, input().split()))
    a.append(t)

for k in a:
    t = sum(k)
    k.append(t)

for x in range(c+1):
    z = 0
    for y in a:
        z += y[x]
    else:
        ans.append(z)
else:
    a.append(ans)

for i in a:
    print(*i)



Measured memory_bytes: 6192
#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;i<=b;i++)
#define Rep(i,a,b)	for(int i=a;i>=b;i--)
	
#define fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

#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*= 10)+= ch - '0';
		return	f ? -x : x;
}

#define n	200005

int		N, K, M, A[n], B[n];

bool	Cmp(int a, int b)	{
		return	A[a] < A[b];
}

int		main()	{
		N= IN();
		K= IN();
		
		For(i, 1, N)	{
			int x= IN();
			A[x]++;
			
			if	(A[x] == 1)	B[++ M]= x;
		}
		
		sort(B+1, B+M+1, Cmp);
	
		if	(M <= K)	puts("0");
		else	{
			int ans= 0;
			For(i, 1, M - K)	ans+= A[B[i]];
			cout << ans << endl;
		}
}













Measured memory_bytes: 1792
N, M = map(int, input().split())
if N % 2 != 0:
    for i in range(M):
        print(1+i, N-i)
elif N // 4 > M:
    for i in range(M):
        print(1+i, N-i)
else:
    for i in range(N//4):
        print(1+i, N-i)
    for i in range(N//4, M):
        print(1+i, N-i-1)

Measured memory_bytes: 9280
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    char trump;
    string str = "0123456789TJQKA";
    while(1){
        cin >> trump;
        if(trump == '#') break;
        string d[4][13];
        rep(i, 0, 4){
            rep(j, 0, 13) cin >> d[i][j];
        }
        int ans = 0; 
        int prev = 0;
        rep(i, 0, 13){
            int MAX = -1, MAXid = -1;
            bool istrump = false;
            char suit = d[prev][i][1];
            rep(j, 0, 4){
                string now = d[j][i];
                int num = str.find(now[0]);
                // cout << now << ' ' << num << endl;
                if(istrump){
                    if(now[1] == trump && num > MAX){
                        MAX = num; MAXid = j;
                    }
                }else{
                    if(now[1] == trump){
                        MAX = num; MAXid = j; istrump = true;
                    }else if(now[1] == suit && num > MAX){
                        MAX = num; MAXid = j;
                    }
                }
            }
            // cout << MAXid << ' ' << MAX << endl;
            prev = MAXid;
            if(MAXid % 2 == 0) ans++;
        }
        if(ans > 6){
            cout << "NS " << ans - 6 << endl; 
        }else{
            cout << "EW " << 7 - ans << endl; 
        }
    }
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

ll f(ll a) {
  ll ret = 0;
  while(a%2==0 && a>0) {
    a /= 2;
    ret++;
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a.at(i);
  ll ans = 0;
  rep(i,n) ans += f(a.at(i));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void)
{
    unsigned int S, h, m, s;
    
    cin >> S;
    h = S / 3600;
    m = (S / 60) % 60;
    s = S - (S / 60) * 60;
    cout << h << ':' << m << ':' << s << endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;

int main()
{
	double W,H,x,y;
	cin>>W>>H>>x>>y;
	double area = (W*H)/2;
	printf("%.10lf",area);
	if( x == (W/2) && y == (H/2)){
		cout<<" "<<1<<endl;
	}else{
		cout<<" "<<0<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int min(int a, int b){
  if(a <= b) return a;
  if(b <= a) return b;
}

int main(){

  int i, j, l, k, n, q;
  int p[101], m[101][101];
  
  scanf("%d", &n);
  for(i=1; i<=n; i++){
    scanf("%d%d", &p[i-1], &p[i]);
  }

  for(i=1; i<=n; i++){
    m[i][i] = 0;
  }

  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i+l-1;
      m[i][j] = 100000000;
      for(k=i; k<=j-1; k++){
	q = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];

	m[i][j] = min(m[i][j], q);
      }
    }
  }

  printf("%d\n", m[1][n]);

  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <cstdlib>
#include <cstdio>

int a[5] ;

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

Measured memory_bytes: 3820
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>

using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int N, M;
vi G[100010];
int S[1000010];
int dp[100010];

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> N >> M;
    REP(i,1,N+1) S[i] = 0;
    rep(i,M){
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        S[y]++;
    }
    int ans = 0;
    rep(i,N+1) dp[i] = 0;

    queue<int> Q;
    REP(i,1,N+1) if(!S[i]) Q.push(i);
    while(!Q.empty()){
        int v = Q.front(); Q.pop();
        for(auto u : G[v]){
            S[u]--;
            if(S[u]==0) dp[u] = dp[v]+1, Q.push(u);
            ans = max(ans, dp[u]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6784
#include <iostream>

using namespace std;

int A, B;
string S;

bool check(int start, int n)
{
	for (int i = 0; i < n; i++) {
		char c = S[start + i];
		if ('0' <= c && c <= '9') {
			;
		} else {
			return false;
		}
	}
	return true;
}

int main(void) 
{
	cin >> A >> B;
	cin >> S;

	string result = "No";

	if (S[A] == '-') {
		if (check(0, A) && check(A + 1, B)) {
			result = "Yes";
		}
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <complex>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;

// INF
#define IINF (INT_MAX/2)
#define INF (1<<29)

// math
#define SQ(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)

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

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// conversion
template<class T> inline string toStr(T a) { ostringstream oss; oss << a; return oss.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

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

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

// isPalindrome
inline bool isPalindrome(string s) {
  return equal(s.begin(), s.end(), s.rbegin());
}

int check(char grid[2][2]) {
  if(grid[0][0] == '#'
     && grid[0][1] == '.'
     && grid[1][0] == '.'
     && grid[1][1] == '.') {
    return +1;
  }
  
  if(grid[0][0] == '.'
     && grid[0][1] == '#'
     && grid[1][0] == '#'
     && grid[1][1] == '#'
  ) {
    return +1;
  }
  
  if(grid[0][0] == '#'
     && grid[0][1] == '#'
     && grid[1][0] == '#'
     && grid[1][1] == '.'
  ) {
    return -1;
  }

  if(grid[0][0] == '.'
     && grid[0][1] == '.'
     && grid[1][0] == '.'
     && grid[1][1] == '#'
  ) {
    return -1;
  }
  
  return 0;
}

int main() {
  
  int H, W;
  while(cin >> H >> W) {
    H+=2, W+=2;
    vector<vector<char>> G(H, vector<char>(W, '.'));
    REP(i, 1, H-1) {
      REP(j, 1, W-1) {
        cin >> G[i][j];
      }
    }
    
    vector<pair<double, int>> event;
    
    // rep(i, H) {rep(j, W) {cout << G[i][j];}cout << endl;}
    
    rep(i, H-1) {
      rep(j, W-1) {
        
        char grid[2][2];
        grid[0][0] = G[i][j];
        grid[0][1] = G[i][j+1];
        grid[1][0] = G[i+1][j];
        grid[1][1] = G[i+1][j+1];
        
        int num = check(grid);
        if(num!=0) {
          double ang = atan2((H-2)-i, j);
          event.PB(MP(atan2((H-2)-i, j), num));
        }
        
      }
    }
    
    sort(ALL(event));
    
    int mx = 1;
    int cnt = 0;
    for(auto e : event) {
      cnt += e.second;
      mx = max(mx, cnt);
    }
    cout << mx+1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  lli H;
  cin >> H;
  if(H==1){
  cout << 1 << endl;
    return 0;
  }
  lli ans=1;
  lli count=0;
  while(H>0){
  count++;
    H/=2;
  }
  rep(i, count)
    ans = ans*2;
  
    cout << ans-1 << endl;
}


Measured memory_bytes: 256
PROGRAM c167b

IMPLICIT NONE
INTEGER A, B, C, K

READ *, A, B, C, K

IF (K <= A) THEN
 PRINT *, K
 ELSE IF (K <= A + B) THEN
 PRINT *, A
 ELSE
 PRINT *, A - (K-(A+B))
 END IF
 
END PROGRAM c167b

Measured memory_bytes: 2792
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int main(){

    int ans;
    string S;
    cin>>S;

    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{
        ans=1;
    }

    cout <<ans<<endl;
    
    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll N,Q,L,R;
ll a[200010];
ll q[200010],x[200010],s[200010],t[200010];
ll solve(ll i){
    ll res=a[i];
    for(int i=0;i<Q;i++){
	if(q[i]==1){
	    if(res>=x[i]){
		res=(res+s[i])*t[i];
	    }
	}
	if(q[i]==2){
	    if(res<=x[i]){
		res=(res-s[i])/t[i];
	    }
	}
    }
    return res;
}
int main(){
  cin>>N>>Q>>L>>R;
  for(int i=0;i<N;i++)cin>>a[i];
  sort(a,a+N);
  for(int i=0;i<Q;i++){
      cin>>q[i]>>x[i]>>s[i]>>t[i];
  }
  ll l,r,m;
  l=-1,r=N;
  while(l<r-1){
      m=(l+r)>>1;
      if(solve(m)>=L)r=m;
      else l=m;
  }
  ll vl=r;
  l=-1,r=N;
  while(l<r-1){
      m=(l+r)>>1;
      if(solve(m)<=R)l=m;
      else r=m;
  }
  ll vr=l;
  cout<<max(0LL,vr-vl+1)<<endl;
  return 0;
}



Measured memory_bytes: 10788
import java.util.*;

class Card {
	Card(String mark, int number, int order) {
		this.mark = mark;
		this.number = number;
		this.order = order;
	}
	@Override
	public String toString() {
		return mark + " " + number;
	}
	public String mark;
	public int number;
	public int order;
}

public class Main {
	public static void main(String[] args)  {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Card[] cards = new Card[n];
		for (int i = 0; i < n; i++) {
			cards[i] = new Card(scanner.next(), scanner.nextInt(), i);
		}
		quickSort(cards, 0, n - 1);
		System.out.println(isStable(cards, n) ? "Stable" : "Not stable");
		for (int i = 0; i < n; i++) {
			System.out.println(cards[i]);
		}
	}
	public static boolean isStable(Card[] c, int n) {
		for (int i = 1; i < n; i++) {
			if (c[i - 1].number == c[i].number && c[i - 1].order > c[i].order) {
				return false;
			}
		}
		return true;
	} 
	public static void quickSort(Card[] c, int p, int r) {
		if (p < r) {
			int q = partation(c, p, r);
			quickSort(c, p, q - 1);
			quickSort(c, q + 1, r);
		}
	}
	public static int partation(Card[] c, int p, int r) {
		int x = c[r].number;
		int i = p - 1;
		Card t;
		for (int j = p; j < r; j++) {
			if (c[j].number <= x) {
				i++;
				t = c[i];
				c[i] = c[j];
				c[j] = t;
			}
		}
		t = c[r];
		c[r] = c[i + 1];
		c[i + 1] = t;
		return i + 1;
	}	
}

Measured memory_bytes: 98180
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

h = ii()
dp = [0] * 50
dp[0] = 1
for i in range(1,50):
    dp[i] = 2 * dp[i-1] + 1
ima = 0
while True:
    if 2 ** ima <= h:
        ima +=1
    else:
        break
if (2 ** ima) == h:
    print(dp[ima])
else:
    print(dp[ima-1])


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

ll k;

int main()
{
    _FastIO;
    cin >> k;
    k--;
    queue<ll> q;
    for(ll i = 1; i < 10; i++){
        q.push(i);
    }
    while(k--){
        ll x = q.front();
        ll n = x;
        q.pop();
        if(n % 10)  q.push(x * 10 + n % 10 - 1);
        q.push(x * 10 + n % 10);
        if(n % 10 < 9)  q.push(x * 10 + n % 10 + 1);
    }
    cout << q.front() << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 整数の入力
            int h = Integer.parseInt(in.next());
            int w = Integer.parseInt(in.next());
            int n = Integer.parseInt(in.next());
            int ans = 0;
            int n2 = 0;

            if (h > w) {
                while (true) {
                    n2 += h;
                    ans++;
                    if (n2 >= n) {
                        break;
                    }
                }
            } else {
                while (true) {
                    n2 += w;
                    ans++;
                    if (n2 >= n) break;
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21332
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	h,w := scanInt(), scanInt()

	a := make([]string, h)

	for i := 0; i < h; i++ {
		a[i] = scanText()
	}

	cnt := make([][]int, h)

	for i := 0; i < h; i++ {
		cnt[i] = make([]int, w)
		for j := 0; j < w; j++ {
			cnt[i][j] = h*w
		}
	}

	for i := 0; i < h; i++ {
		now := h*w
		for j := 0; j < w; j++ {
			if a[i][j] == '#' {
				now = 0
			} else {
				now++
			}

			cnt[i][j] = min(cnt[i][j],now)
		}

		now = h*w
		for j := 0; j < w; j++ {
			if a[i][w-1-j] == '#' {
				now = 0
			} else {
				now++
			}

			cnt[i][w-1-j] = min(cnt[i][w-1-j],now)
		}
	}

	for i := 0; i < w; i++ {
		now := h*w
		for j := 0; j < h; j++ {
			if a[j][i] == '#' {
				now = 0
			} else {
				now++
			}

			cnt[j][i] = min(cnt[j][i],now)
			now = cnt[j][i]
		}

		now = h*w
		for j := 0; j < h; j++ {
			if a[h-1-j][i] == '#' {
				now = 0
			} else {
				now++
			}

			cnt[h-1-j][i] = min(cnt[h-1-j][i],now)
			now = cnt[h-1-j][i]
		}
	}

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			ans = max(ans,cnt[i][j])
		}
	}

	fmt.Println(ans)

}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<pint> a(n);
    rep(i,n) {
        int ai; cin >> ai;
        a.emplace_back(ai, i);
    }
    gsort(a);
    rep(i,n) {
        int ans = a[0].first;
        if (i == a[0].second) ans = a[1].first;
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 6416
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define V vector<int>
#define VLL vector<ll>
#define VV vector<vector<ll>>
#define vec vector
#define scan(a) scanf("%d",&a)
#define print(a) printf("%d",a)
#define be(x) begin(x),end(x)
#define For(a) for(int i=0;i<a;i++)
#define Forin(j,a,b) for(int j=a;j<b;j++)
#define len(a) a.size()
#define pb push_back 
#define mp make_pair
#define Um unordered_map
#define Us unordered_set
#define F first
#define S second
#define mod 1000000007

void solve();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
    
    /*int t;
    cin>>t;
    while(t--)
    {
        //solve();
        solve();cout<<"\n";
        //cout<<"Case #"<<tc<<": "<<solve()<<"\n";
        //cout<<solve()<<"\n";
    }*/
    solve();
    cout<<"\n";
return 0;
}
void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll m1=a*c;
    ll m2=a*d;
    ll m3=b*c;
    ll m4=b*d;
    cout<<max({m1,m2,m3,m4});     
}

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

Measured memory_bytes: 596
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    A, B, K = map(int, input().split())
    C = gcd(A, B)
    divs = [1, C]
    i = 2
    while i**2 <= C:
        if C % i == 0:
            divs.append(i)
            if C // i != i:
                divs.append(C//i)
        i += 1
    divs.sort(reverse=True)
    print(divs[K-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().run();
        return 0;
    }

    void run()
    {
        Scanner cin = new Scanner();
        int n = cin.nextInt();
        int[,] dist = new int[n, n];
        int MAX = 1000000009;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                dist[i, j] = MAX;
            }
        }
        for (int i = 0; i < n; i++)
        {
            int a = cin.nextInt() - 1;
            int num = cin.nextInt();
            for (int j = 0; j < num; j++)
            {
                dist[a, cin.nextInt() - 1] = 1;
            }
        }
        for (int k = 0; k < n; k++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    dist[i, j] = Math.Min(dist[i, j], dist[i, k] + dist[k, j]);
                }
            }
        }

        int T = cin.nextInt();
        for (int i = 0; i < T; i++)
        {
            int s = cin.nextInt() - 1;
            int d = cin.nextInt() - 1;
            int t = cin.nextInt();
            if (dist[s, d] + 1 <= t) Console.WriteLine(dist[s,d] + 1);
            else Console.WriteLine("NA");
        }

    }

}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

}

Measured memory_bytes: 5816
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int X,Y;
    cin >> X >> Y;
    for(int i=0; i<=X; i++){
        if(i*2+(X-i)*4 == Y){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF (2e9)
#define EPS (1e-6)
#define int ll
#define NATHANLEE_IS_EVIL true
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<endl;}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif
void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(!NATHANLEE_IS_EVIL);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int32_t main() {
	INIT();
	//code...
	int n; cin>>n;
	string s; cin>>s;
	int l=0,r=0;
	for(auto &i:s)
		r+=(i=='R');
	if(l==r){
		cout<<l<<"\n";
		return 0;
	}
	for(auto &i:s){
		l+=(i=='W');
		r-=(i=='R');
		if(l==r){
			cout<<l<<"\n";
			return 0;
		}
	}
	cout<<";lkjaspmdj o34umpos dliv jp0;o34tmp9umpvo;kld p9ou\n";
	return 404;
}

Measured memory_bytes: 3776
n,m,x = map(int,input().split())
lis = list(map(int,input().split()))
cou = 0
co = 0
for i in range(x,n+1):
	if i in lis:
		cou += 1
for k in range(x):
	if k in lis:
		co += 1
print(min(cou,co))

Measured memory_bytes: 3060
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] P = new int[N];
		for (int i = 0; i < N; ++i) {
			P[i] = sc.nextInt();
			--P[i];
		}
		boolean ans = false;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i != j) {
					P[i] ^= P[j];
					P[j] ^= P[i];
					P[i] ^= P[j];
				}
				boolean ok = true;
				for (int k = 0; k < N; ++k) {
					ok &= P[k] == k;
				}
				ans |= ok;
				if (i != j) {
					P[i] ^= P[j];
					P[j] ^= P[i];
					P[i] ^= P[j];
				}
			}
		}
		System.out.println(ans ? "YES" : "NO");
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

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

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int N=20;

char ch[N];

signed main()
{
	scanf("%s",ch+1);
	int n=strlen(ch+1);
	if(n&1) return printf("No\n"),0;
	for ( int i=1;i<=n;i+=2 ) 
		if(ch[i]=='h'&&ch[i+1]=='i') continue;
		else return printf("No\n"),0;
	printf("Yes\n");
}

Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val n = sc.nextInt()
    val p = Array.fill(n)(sc.nextInt())
    val count = p.sliding(3, 1).count { case Array(a, b, c) =>
      if ((b >= a && b < c) || (b >= c && b < a)) true
      else false
    }
    println(count)
  }

}


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

namespace AOJ
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sets = int.Parse(Console.ReadLine());
			for(var i = 0; i < sets ; i++)
			{
				int a = 0;
				int b = 0;
				var arr = Console.ReadLine().Split(' ').Select(j => int.Parse(j));
				bool success = true;
				foreach(var ball in arr)
				{
					if(ball > a || ball > b)
					{
						int aa = ball - a;
						int bb = ball - b;
						if(aa < 0)
							aa = int.MaxValue;
						if(bb < 0)
							bb = int.MaxValue;
						if(aa <= bb)
						{
							a = ball;
						}
						else
						{
							b = ball;
						}
					}
					else
					{
						success = false;
						break;
					}
				}
				Console.WriteLine(success ? "YES" : "NO");
			}
		}
	}
}

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

using namespace std;

string A, B, C;

void system(string& s){
  if(s[0]=='a'){
    s.erase(0,1);
    if(A.empty()==1){
      cout<<"A"<<endl;
    } else {
      system(A);
    }
  } else if(s[0]=='b'){
    s.erase(0,1);
    if(B.empty()==1){
      cout<<"B"<<endl;
    } else {
      system(B);
    }
  } else if(s[0]=='c'){
    s.erase(0,1);
    if(C.empty()==1){
      cout<<"C"<<endl;
    } else{
      system(C); 
    }
  }
}


int main(){
  cin>>A>>B>>C;
  
  system(A);
       
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main() {
  int A_score;
  int S = 0;
  for (int i = 0; i < 4; i++) {
    cin >> A_score;
    S += A_score;
  }
  int B_score;
  int T = 0;
  for (int i = 0; i < 4; i++) {
    cin >> B_score;
    T += B_score;
  }
  S >= T ? cout << S << endl : cout << T << endl;
  return 0;
}


Measured memory_bytes: 3084
n = int(input())
a = list(map(int, input().split()))

s = [a[0]]
for i in range(1, n):
    s.append(a[i] + s[i-1])

l = 0
r = 2
ans = float("inf")

for m in range(1, n-1):
    while l < m - 1 and abs(s[m] - 2 * s[l]) > abs(s[m] - 2 * s[l+1]):
        l += 1
    while r <= m or r < n - 1 and abs(s[n-1] - 2 * s[r] + s[m]) > abs(s[n-1] - 2 * s[r+1] + s[m]):
        r += 1
    mx = max(s[l], s[m] - s[l], s[r] - s[m], s[n-1] - s[r])
    mn = min(s[l], s[m] - s[l], s[r] - s[m], s[n-1] - s[r])
    ans = min(ans, mx - mn)

print(ans)


Measured memory_bytes: 24684
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const LL INF = (LL)1e11;

int main() {
    int A, B, Q;
    scanf("%d %d %d", &A, &B, &Q);
    vector<LL> tem, shr;
    tem.push_back(-INF);
    shr.push_back(-INF);
    for (int i = 0; i < A; i++) {
        LL tmp;
        scanf("%lld", &tmp);
        shr.push_back(tmp);
    }
    for (int i = 0; i < B; i++) {
        LL tmp;
        scanf("%lld", &tmp);
        tem.push_back(tmp);
    }
    tem.push_back(INF);
    shr.push_back(INF);
    for (int i = 0; i < Q; i++) {
        LL x;
        scanf("%lld", &x);
        int btem = upper_bound(tem.begin(), tem.end(), x) - tem.begin();
        int bshr = upper_bound(shr.begin(), shr.end(), x) - shr.begin();
        int stem = btem - 1, sshr = bshr - 1;
        //printf("btem = %lld bshr = %lld\n", tem[btem], shr[bshr]);
        LL ans = INF;
        ans = min(ans, max(tem[btem], shr[bshr]) - x);
        ans = min(ans, x - min(tem[stem], shr[sshr]));
        ans = min(ans, 2 * (tem[btem] - shr[sshr]) - max(tem[btem] - x, x - shr[sshr]));
        ans = min(ans, 2 * (shr[bshr] - tem[stem]) - max(x - tem[stem], shr[bshr] - x));
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3060