akhauriyash/Code-Regression huggingface dataset:
struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R:std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read{
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_line(&mut self) {
        self.i = 0; self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {break;}
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn read_t<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
    
    #[allow(dead_code)]
    pub fn read_i32(&mut self) -> i32 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_usize(&mut self) -> usize {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_u64(&mut self) -> u64 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_string(&mut self) -> String {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.to_owned()
    }
}

fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let read = Read::new(stdin);
    solve(read);
}

fn solve<R: std::io::BufRead>(mut r: Read<R>) {
    let a:i64 = r.read_t();
    let b:i64 = r.read_t();
    let n:i64 = r.read_t();
    
    let x = if b - 1 > n {
        n
    } else {
        b-1
    };
    let X = ((a*x) as f64 / b as f64) as i64;
    let Y = (x as f64 / b as f64) as i64;

    println!("{}",X-Y);
}


Measured memory_bytes: 2136
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    while(cin >> n, n){
        vector<vector<int>> v(n);
        for (int i = 0; i < n; ++i) {
            int x;
            scanf("%d", &x);
            for (int j = 0; j < x; ++j) {
                int y;
                scanf("%d", &y);
                v[i].emplace_back(y);
            }
            sort(v[i].begin(),v[i].end());
        }
        vector<int> ans;
        vector<int> s;
        int x;
        scanf("%d", &x);
        for (int j = 0; j < x; ++j) {
            int y;
            scanf("%d", &y);
            s.emplace_back(y);
        }
        sort(s.begin(), s.end());
        for (int i = 0; i < n; ++i) {
            vector<int> u;
            set_intersection(v[i].begin(), v[i].end(), s.begin(), s.end(), back_inserter(u));
            if(s.size() == u.size()) ans.emplace_back(i);
        }
        if(ans.size() != 1){
            puts("-1");
        }else{
            printf("%d\n", ans.front()+1);
        }
    }
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
struct T{
	int mn[2];
	int mx[2];
};
vector<T> solve(vector<int> A) {
	int k = 0;
	int sum = A[0];
	int ksum = A[0];
	vector<T> res((int)A.size() - 3);
	for (int i = 1; i < (int)A.size() - 2; i++) {
		sum += A[i];
		//cerr <<i << " " <<  ksum << " " << A[k + 1] << " " <<  sum << endl;
		while ((ksum + A[k + 1]) * 2 < sum) {
			ksum += A[k + 1];
			k++;
		}
		res[i - 1].mn[0] = min(ksum, sum - ksum);
		res[i - 1].mx[0] = max(ksum, sum - ksum);
		ksum += A[k + 1];
		res[i - 1].mn[1] = min(ksum, sum - ksum);
		res[i - 1].mx[1] = max(ksum, sum - ksum);
		ksum -= A[k + 1];
	}
	return  res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<T> X = solve(A);
	/*for (int i = 0; i < X.size(); i++) {
		cerr << X[i].mn[0] << " " << X[i].mx[0] << endl;
	}*/
	reverse(A.begin(), A.end());
	vector<T> Y = solve(A);
	reverse(Y.begin(), Y.end());
	res = (int)1 << 60;
	for (int i = 0; i < X.size(); i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int a = X[i].mx[j] - X[i].mn[j];
				a = max(a, X[i].mx[j] - Y[i].mn[k]);
				a = max(a, Y[i].mx[k] - X[i].mn[j]);
				a = max(a, Y[i].mx[k] - Y[i].mn[k]);

				res = min(res, a);
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 15844
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
int main(){
	int d=read(), t=read(), s=read();
	if ((d-1)/s+1<=t) puts("Yes");
	else puts("No");
    return 0;
}

Measured memory_bytes: 3636
// https://atcoder.jp/contests/abc078/tasks/arc085_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, Z, W;
  cin >> N >> Z >> W;

  VL as(N);
  rep(i, N) cin >> as[i];

  VVL dp(N + 1, VL(2));  // dp[i][j] i 枚カードがひかれていて j = 0: 先手, j =
                         // 1: 後手が操作する時の答え

  repr(i, N) {
    // 先手
    {
      ll op = i == 0 ? W : as[i - 1];

      // 全部を取る場合
      chmax(dp[i][0], abs(op - as[N - 1]));

      repf(j, i + 1, N) chmax(dp[i][0], dp[j][1]);
    }

    // 後手
    {
      dp[i][1] = INF;
      ll op = i == 0 ? Z : as[i - 1];

      // 全部を取る場合
      chmin(dp[i][1], abs(op - as[N - 1]));
      repf(j, i + 1, N) chmin(dp[i][1], dp[j][0]);
    }
  }

  ll res = dp[0][0];
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 384
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, k, x, ans = 0;
	cin >> n >> k;
	while (n--) {
		cin >> x;
		if (x < k - x)
			ans += 2 * x;
		else
			ans += 2 * (k - x);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
 
class Program {
    private static int Main() {
        while( true ) {
            var cards = Console.ReadLine();
            if( cards == "-" ) { break; }
 
            var input = Console.ReadLine();
            int count = int.Parse( input );
 
            int index = 0;
            for( int i = 0; i < count; ++i ) {
                input = Console.ReadLine();
                index += int.Parse( input );
            }
 
            index %= cards.Length;
 
            var output = cards.Substring( index ) + cards.Substring( 0, index );
            Console.WriteLine( output );
        }
 
        return 0;
    }
}

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

using namespace std;
typedef long long ll;

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll min = a * x + b * y;
    int ans;
    for (int i = 0; i < 100001; i++)
    {
        ans = i * 2 * c + max(0, x - i) * a + max(y - i, 0) * b;
        if (ans < min)
        {
            min = ans;
        }
    }
    cout << min << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
P pos[200];
int main() {
    int N;
    while(scanf("%d",&N),N) {
        pos[0]=P(0,0);
        int min_x=0,max_x=0,min_y=0,max_y=0;
        for(int i=1;i<=N-1;i++) {
            int n,d;
            scanf("%d %d",&n,&d);
            int dx=0,dy=0;
            if(d==0) dx=-1;
            if(d==1) dy=-1;
            if(d==2) dx=1;
            if(d==3) dy=1;
            pos[i]=P(pos[n].first+dx,pos[n].second+dy);
            min_x=min(min_x,pos[i].first);
            max_x=max(max_x,pos[i].first);
            min_y=min(min_y,pos[i].second);
            max_y=max(max_y,pos[i].second);
        }
        printf("%d %d\n",(max_x-min_x+1),(max_y-min_y+1));
    }
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#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[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -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);
    string S;
    cin >> S;
    int N = S.size();
    vector<int> cnt(26,0);
    for(int i=0; i<N; i++){
        cnt[S[i]-'a']++;
    }
    int odd = 0;
    for(int i=0; i<26; i++){
        if(cnt[i]%2) odd++;
    }
    cout << odd/2 << enld;
    return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 

const int INF = 1 << 29;

int main(){

    int n;
    cin >> n;
    vector<int> h(n);
    for(int& i : h){
        cin >> i;
    }

    vector<int> cache(n,INF);

    cache[0] = 0;
    cache[1] = abs(h[1] - h[0]);

    for(int i = 2; i < n; ++i){
        cache[i] = min(cache[i],cache[i - 1] + abs(h[i] - h[i - 1]));
        cache[i] = min(cache[i],cache[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << cache[n - 1];

    return 0;
}

Measured memory_bytes: 1024
import math
n = int(input())
ans = 1001001001
for a in range(1, n):
    b = n - a
    if a > b: break
    map(int, str(a))
    cnddt = sum(map(int, str(a))) + sum(map(int, str(b)))
    ans = min(ans, cnddt)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	vector<string> v(8);
	rep(i,8){
		cin>>v[i];
	}
	cout<<90<<endl;
	rep(i,8){
		rep(j,8){
			cout<<v[7-j][i];
		}
		cout<<endl;
	}
	cout<<180<<endl;
	rep(i,8){
		rep(j,8){
			cout<<v[7-i][7-j];
		}
		cout<<endl;
	}
	cout<<270<<endl;
	rep(i,8){
		rep(j,8){
			cout<<v[j][7-i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1196
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    neg_dists = []
    pos_dists = []
    exists_zero = False
    for xi in x:
        if xi < 0:
            neg_dists.append(abs(xi))
        elif xi > 0:
            pos_dists.append(abs(xi))
        else:
            exists_zero = True
    neg_dists.sort()
    pos_dists.sort()
    ans = 10 ** 9
    count = K - int(exists_zero)
    for i in range(count):
        d = 0
        if i >= len(neg_dists):continue
        d += neg_dists[i]
        if len(pos_dists) == 0 or count-2-i >= len(pos_dists):continue
        d += pos_dists[count-2-i] + neg_dists[i]
        ans = min(ans, d)
    for i in range(count):
        d = 0
        if i >= len(pos_dists):continue
        d += pos_dists[i]
        if len(neg_dists) == 0 or count-2-i >= len(neg_dists):continue
        d += neg_dists[count-2-i] + pos_dists[i]
        ans = min(ans, d)
    if len(neg_dists) > 0 and count <= len(neg_dists):ans = min(ans, neg_dists[count-1])
    if len(pos_dists) > 0 and count <= len(pos_dists):ans = min(ans, pos_dists[count-1])
    if exists_zero and len(neg_dists) == 0 and len(pos_dists) == 0:ans = 0
    print(ans)
            
if __name__ == "__main__":
    main()

Measured memory_bytes: 59288
n,m=map(int,input().split())
h =list(map(int,input().split()))
l=[True]*n
for _ in range(m):
    i, j=map(int ,input().split())
    i-=1
    j-=1
    if h[i]-h[j]>0:
      l[j]=False
    elif h[j]-h[i] >0:
      l[i]=False
    else:
      l[i]=False
      l[j]=False
      
print(l.count(True))       

Measured memory_bytes: 20116
#include <climits>
#include <iostream>

int main() {
  int min = INT_MAX;
  int cnt = 0;
  int N; std::cin >> N;
  for (int i = 0; i < N; ++i) {
    int a; std::cin >> a;
    if (min >= a) {
      min = a;
      ++cnt;
    }
  }

  std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 115：C - Christmas Eve


def main():
    N, K = [int(i) for i in raw_input().strip().split(' ')]
    H = []
    for _ in range(N):
        h = int(raw_input().strip())
        H.append(h)
    H.sort()

    min_h = 10**10
    for i in xrange(N-K+1):
        h = H[i+K-1] - H[i]
        if h < min_h:
            min_h = h
    print min_h


if __name__ == '__main__':
    main()


Measured memory_bytes: 8964
#include<bits/stdc++.h>
using namespace std;
int n;
map<string,int> mp;
string appear[200005];
map<string,bool> vis;
string ans[200005];
bool cmp(string a,string b){
    return a<b;
}
int main(){
    cin>>n;
    string s;
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>s;
        appear[++cnt]=s;
        mp[s]++;
    }
    int maxn=0;
    for(int i=1;i<=cnt;i++){
        maxn=max(maxn,mp[appear[i]]);
    }
    int cc=0;
    for(int i=1;i<=cnt;i++){
        if(mp[appear[i]]==maxn&&!vis[appear[i]]){
//            cout<<appear[i]<<endl;
            vis[appear[i]]=1;
            ans[++cc]=appear[i];
        }
    }
    sort(ans+1,ans+1+cc,cmp);
    for(int i=1;i<=cc;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 40832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n,x,t; cin >> n >> x >> t;
    cout << t*((n+x-1)/x) << endl;
return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.size();  
    for (int i = 0; i < n; ++ i) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2;
            return 0;
        }
        if (i + 2 < n && s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3;
            return 0;
        }
    }
    cout << -1 << " " << -1;
}

Measured memory_bytes: 512
L, R = map(int, input().split())
ans = 2019
if R - L >= 2019:
    print(0)
else:
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans = min(ans, (i * j) % 2019)
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1000000007;

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)>abs(x-b)) cout<<"B"<<endl;
    else cout<<"A"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};
ll mod_pow(ll x, ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % MOD, n / 2);
	if (n & 1) res = res * x % MOD;
	return res;
}
 
ll comb(ll a, ll b) {
	ll mul = 1;
	ll div = 1;
	rep(i, 0, b) {
		mul *= (a - (ll)i);
		mul %= MOD;
		div *= ((ll)i + 1);
		div %= MOD;
	}
 
	mul *= mod_pow(div, MOD - 2);
	return mul%MOD;
}

ll fact[100005];
ll n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    if (abs(n - m) > 1) {
      cout << 0 << endl;
      return 0;
    }
    if (n > m) swap(n, m);
    fact[0] = 1;
    rep(i, 0, m) {
      fact[i+1] = fact[i] * (i+1) % MOD;
    }    
    if (n == m) cout << fact[n] * fact[m] % MOD * 2 % MOD << endl;
    else cout << fact[n] * fact[m] % MOD << endl;
    return 0;
}



Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
c = 0
flag = True
while True:
    for i in range(len(A)):
        if A[i] % 2 == 0:
            A[i] = A[i] // 2
        else:
            flag = False
    if flag:
        c += 1
    else:
        break
print(c)

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

int main(){
    int N;
    cin >> N;
    int V[N], C[N];
    for(int i=0;i<N;i++){ cin >> V[i]; }
    for(int i=0;i<N;i++){ cin >> C[i]; }
    int sum=0;
    
    for(int i=0;i<N;i++){
        int value = V[i]-C[i];
        if(value > 0){ sum += value; }
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0
 H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:
    F[v]=t
    heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c]+=[(e,d)];E[d]+=[(e,c)]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6308
import java.util.*;

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

class ABC125 {
    static void solutionC() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextLong();
        }
        long[] L = new long[N+1];
        long[] R = new long[N+1];
        L[0] = 0;
        R[N] = 0;
        for (int i=1; i<N+1; i++) {
            L[i] = gcd(L[i-1],A[i-1]);
            R[N-i] = gcd(A[N-i],R[N-i+1]);
        }
        long[] M = new long[N];
        long maxValue = Long.MIN_VALUE;
        for (int i=0; i<N; i++) {
            M[i] = gcd(L[i],R[i+1]);
            if (maxValue < M[i]) maxValue = M[i];
        }
        System.out.println(maxValue);
    }

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

Measured memory_bytes: 50084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <set>
#include <vector>
#include <functional>
#include <map>
#include <queue>
using namespace std;
int n;
bool b[300000];
int a[300001];
int minn;
int main()
{
  cin>>n;
  for (int i=0;i<n;i++)
  {
    char c;
    cin>>c;
    if (c=='E') b[i]=true;
    a[i+1]=a[i]+b[i];
  }
  int minn=n;
  for (int i=1;i<=n;i++)
    minn=min(minn,i-1-a[i-1]+a[n]-a[i]);
  cout<<minn<<endl;
  //system("pause");
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <sstream>
struct Scanner {
  std::string pp(const char ch) {
    switch (ch) {
    case ' ':
      return "Space";
    case '\n':
      return "Newline";
    case EOF:
      return "EOF";
    default:
      return std::string(1, ch);
    }
  }
  void readSpace() {
    auto ch = getchar();
    if (ch != ' ') {
      throw std::runtime_error(std::string("want: Space, got: ") + pp(ch));
    }
  }
  void readNewline() {
    auto ch = getchar();
    if (ch != '\n') {
      throw std::runtime_error(std::string("want: Newline, got: ") + pp(ch));
    }
  }
  void readEof() {
    auto ch = getchar();
    if (ch != EOF) {
      throw std::runtime_error(std::string("want: EOF, got: ") + pp(ch));
    }
  }
  std::string readString(size_t minLength, size_t maxLength) {
    std::string ret;
    char ch;
    while (ch = getchar(), ch != ' ' and ch != '\n' and ch != EOF) {
      ret += ch;
    }
    ungetc(ch, stdin);
    if (not(minLength <= ret.size() and ret.size() <= maxLength)) {
      std::ostringstream os;
      os << "length of " << ret << " is not in [" << minLength << ", "
         << maxLength << "]";
      throw std::runtime_error(os.str());
    }
    return ret;
  }
  template <typename T>
  T readInt(const T lb, const T ub) {
    auto ch = getchar();
    if ((not isdigit(ch)) and (ch != '-')) {
      ungetc(ch, stdin);
      throw std::runtime_error(std::string("want: [0-9\\-]+, got: ") + pp(ch));
    }
    T ret = ch == '-' ? 0 : ch - '0';
    int sgn = ch == '-' ? -1 : +1;
    while (isdigit(ch = getchar())) {
      ret = ret * 10 + (ch - '0');
    }
    ungetc(ch, stdin);
    ret *= sgn;
    if (not(lb <= ret and ret <= ub)) {
      std::ostringstream os;
      os << ret << " is not in [" << lb << ", " << ub << "]";
      throw std::runtime_error(os.str());
    }
    return ret;
  }
};

using namespace std;
int main() {
  Scanner sc;
  auto s = sc.readString(4, 4);
  sc.readNewline();
  sc.readEof();
  if (s[0] == s[1] or s[1] == s[2] or s[2] == s[3]) {
    puts("Bad");
  } else {
    puts("Good");
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <vector>
typedef long long lld;
typedef std::vector<int> vin;
const int MAXN = 1e5+5;
enum Dir { PREV=0, NEXT=1 };
int P[MAXN];
int one[MAXN][2]; // 1st Greater [Prev, Next]
int two[MAXN][2]; // 2nd Greater [Prev, Next]
std::map<int,int> SS;
vin S;
int N;

void init() {
  int val[] = { 0, N+1 };
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < 2; ++j) {
      one[i][j] = two[i][j] = val[j];
    }
  }
}

void one_greater(Dir d, int i) {
    while (!S.empty()) {
      int k = S.back();
      if (P[k] > P[i]) break;
      one[k][d] = i;
      SS[P[k]] = k;
      S.pop_back();
    }
}

void two_greater(Dir d, int i) {
    while (!SS.empty()) {
      int k = SS.begin()->first;
      if (k > P[i]) break;
      two[SS.at(k)][d] = i;
      SS.erase(k);
    }
}

void next_greater() {
  S.clear();
  SS.clear();
  for (int i = 1; i <= N; ++i) {
    two_greater(NEXT, i);
    one_greater(NEXT, i);
    S.push_back(i);
  }
}

void prev_greater() {
  S.clear();
  SS.clear();
  for (int i = N; i >= 1; --i) {
    two_greater(PREV, i);
    one_greater(PREV, i);
    S.push_back(i);
  }
}

lld solve() {
  lld res = 0LL;
  for (int i = 1; i <= N; ++i) {
    // Include next / prev element greater than P[i]
    res += 1LL * P[i] * (two[i][NEXT] - one[i][NEXT]) * (i - one[i][PREV]);
    res += 1LL * P[i] * (one[i][NEXT] - i) * (one[i][PREV] - two[i][PREV]);
  }
  return res;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &P[i]);
  }
  init();
  next_greater();
  prev_greater();
  printf("%lld\n", solve());
  return 0;
}

Measured memory_bytes: 2812
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> nums(100010);
    rep(i, N) {
        cin >> A[i];
        nums[A[i]]++;
    }
    int Q;
    cin >> Q;
    ll sum = 0;
    rep(i, N) sum += A[i];
    rep(i, Q) {
        ll b, c;
        cin >> b >> c;
        sum += nums[b] * (c - b);
        nums[c] += nums[b];
        nums[b] = 0;

        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 4824
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>A(n), B(n);
	rep(i, n) {
		cin >> A[i] >> B[i];
	}
	vector<pair<int, int>>AB(n);
	rep(i, n) { AB[i] = make_pair(A[i], B[i]);
	}
	sort(AB.begin(), AB.end());
	long long ans = 0;
	rep(i, n) {
		int buy = min(m, AB[i].second);
		ans += (long long)AB[i].first * buy;
		m -= buy;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;

int main ()
{
	ll a,b,i,j,t1=1,t2;
	cin>>a>>b;
	for(i=0;i<b;i++)
		t1*=2;
	t2=b*1900+(a-b)*100;
	cout<<t1*t2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll arr[n+5]={0};
    ll pos[n+5]={0};
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        pos[arr[i]]=i;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<pos[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 5160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	int a, b; cin >> a >> b;
	
	if (a % 2 == 0 && b % 2 == 0)cout << (a + b) / 2 << endl;
	else if (a % 2 == 1 && b % 2 == 0)cout << (a + b) / 2  + 1<< endl;
	else if (a % 2 == 0 && b % 2 == 1)cout << (a + b) / 2  + 1<< endl;
	else if (a % 2 == 1 && b % 2 == 1)cout << (a + b) / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

// > 2018-07-24T23:00:53+0800

int solve(int a, int b, int c, int *arr){
        if(a>2){a-=3;}
        if(b>2){b-=3;}
        if(c>2){c-=3;}
        // solving task a, b, and c in order.
        return abs(arr[b]-arr[a]) + abs(arr[c]-arr[b]);
}

int main(){
        int a[3];
        int n = 0, temp = 0;
        int i;
        cin >> a[0] >> a[1] >> a[2];
        n = solve(0, 1, 2, a);
        for(i=0; i<3; i++){
                temp = solve(i, i+1, i+2, a);
                if(temp<n){n = temp;}
                temp = solve(i, i+2, i+1, a);
                if(temp<n){n = temp;}
        }
        cout << n;
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION

vector<pair<int,int> > vp [100005];
vector<bool> vi (100005);
vector<int> res (100005);

bool DFS(int a, int d =0)
{
  if(vi[a]) return res[a] == d;
  res [a] = d;
  vi[a] = true;
  for (auto &c : vp[a])
  {
    if(!DFS(c.first,d + c.second))return false;
  }
  return true;
}
void solve(void)
{
  int N,M; cin>>N; cin>>M;
  for (int i = 0; i < M; i++)
  {
    int L,R,D;
    cin>>L>>R>>D;
    L--;R--;
    vp[L].emplace_back(R,D);
    vp[R].emplace_back(L,-1*D);
    
  }
  bool elf = true;
  for (int i = 0; i < N; i++)
  {
    if(vi[i])continue;
    if(!DFS(i))
    {
      cout<<"No"<<endl;
      return;
    }
  }
  cout<<"Yes"<<endl;
  
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 15616
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, d, x, y, num = 0;
        n = sc.nextInt();
        d = sc.nextInt();
        for (int i = 0; i < n; i++) {
            x = sc.nextInt();
            y = sc.nextInt();
            double dist = Math.sqrt(Math.pow(x, 2)+Math.pow(y, 2));
            if(dist <= d) ++num;
        }
        System.out.println(num);
        sc.close();
    }
}


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

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

    if (N.back() == '2' or N.back() == '4' or N.back() == '5' or N.back() == '7' or N.back() == '9') cout << "hon" << endl;
    if (N.back() == '3') cout << "bon" << endl;
    if (N.back() == '0' or N.back() == '1' or N.back() == '6' or N.back() == '8') cout << "pon" << endl;
    return 0;
}

Measured memory_bytes: 3612
import sys
input = sys.stdin.readline
N, m, l = map(int, input().split())
graph = [[] for i in range(N+1)]

INF = 2 ** 31 - 1
d = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(N+1):
    d[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    d[a][b] = c
    d[b][a] = c


for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

d2 = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(N+1):
    d[i][i] = 0

for i in range(N+1):
    for j in range(N+1):
        if d[i][j] <= l:
            d2[i][j] = 1

for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j])


q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    if d2[s][t] == INF:
        print(-1)
    else:
        print(d2[s][t] - 1)


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

#if __has_include("print.hpp")
#include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int main(){
  string s;
  cin >> s;
  vector<int> v;
  int size = int(s.size());
  ll res = 0;

  // // while(true) {
  // //   bool flag = true;
  // for (int i = 0; i < size - 1; i++)
  // {
  //   if(s[i] == 'B' && s[i+1] == 'W')
  //   {
  //     // flag = false;
  //     res++;
  //     s[i] = 'W';
  //     s[i+1] = 'B';
  //   }
  // }
  // cout << s << endl;
  // // if(flag) break;
  // // }
  //
  // // while(true) {
  // //   bool flag = true;
  // for (int i = size-1; i > 0; i--)
  // {
  //   if(s[i] == 'W' && s[i-1] == 'B')
  //   {
  //     // flag = false;
  //     res++;
  //     s[i] = 'B';
  //     s[i-1] = 'W';
  //   }
  // }
  // cout << s << endl;
  // // cout << s << endl;
  // // if(flag) break;
  // // }

  int count = 0;
  for (int i = 0; i < size; i++)
  {
    if(s[i] == 'W') v.push_back(i);
  }

  for (int i = 0; i < int(v.size()); i++)
  {
    res += v[i] - count;
    count++;
  }

  cout << res << endl;
}


Measured memory_bytes: 1532
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n,k;
    cin>>n>>k;
    int res=1,i=k;
    while(i<n){
        i+=(k-1);
        res++;
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3648
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a;
		int b;
		while(true) {
			a = sc.nextInt();
			b = sc.nextInt();
			if(a==0 && b==0)break;
			System.out.println(Math.min(a, b) + " " + Math.max(a, b));
		}
		sc.close();
	}
	
}


Measured memory_bytes: 36220
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if(a<b){
    	if(b<c){
    		System.out.println(a+" "+b+" "+c);
    	}else if(c<a){
    		System.out.println(c+" "+a+" "+b);
    	}else{
    		System.out.println(a+" "+c+" "+b);
    	}
    }else{
    	if(a<c){
    		System.out.println(b+" "+a+" "+c);
    	}else if(c<b){
    		System.out.println(c+" "+b+" "+a);
    	}else{
    		System.out.println(b+" "+c+" "+a);
    	}
    	
 
    }
    
  
  }

}

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

int main()
{
    int n;
    int distf[100000] = {}, dists[100000] = {};
    vector<int> adjList[100000];
    bool visitedf[100000], visiteds[100000];
    queue<int> fennec, snuke;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        visitedf[i] = false;
        visiteds[i] = false;
    }
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        adjList[a - 1].push_back(b - 1);
        adjList[b - 1].push_back(a - 1);
    }

    fennec.push(0);
    snuke.push(n - 1);
    distf[0] = 0;
    dists[n - 1] = 0;

    int turn = 1; //1 for fennec, -1 for snuke

    while (!fennec.empty()) {
        int fcur;
        fcur = fennec.front();
        fennec.pop();
        visitedf[fcur] = true;

        for (int i = 0; i < adjList[fcur].size(); ++i) {
            if (visitedf[ adjList[fcur][i] ]) continue;
            fennec.push(adjList[fcur][i]);
            distf[ adjList[fcur][i] ] = distf[fcur] + 1;
        }
    }

    while (!snuke.empty()) {
        int scur;
        scur = snuke.front();
        snuke.pop();
        visiteds[scur] = true;
        for (int i = 0; i < adjList[scur].size(); ++i) {
            if (visiteds[ adjList[scur][i] ]) continue;
            snuke.push(adjList[scur][i]);
            dists[ adjList[scur][i] ] = dists[scur] + 1;
        }
    }

    int fpoint = 0, spoint = 0;
    for (int i = 0; i < n; ++i) {
        if (distf[i] <= dists[i]) {
            fpoint++;
        } else {
            spoint++;
        }
    }
    if (fpoint > spoint) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

    return 0;
}

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

using namespace std;
using ll=long long;
#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,n) for (int i=a;i<(n);++i)
int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  string a,b;cin>>a>>b;
  if(a.size()>b.size()){
    cout<<"GREATER"<<endl;
    return 0;
  }else if(a.size()<b.size()){
    cout<<"LESS"<<endl;
    return 0;
  }else{
    rep(i,a.size()){
      if(a[i]-'0'>b[i]-'0'){
       cout<<"GREATER"<<endl;
       return 0;
      }else if(a[i]-'0'<b[i]-'0'){
       cout<<"LESS"<<endl;
       return 0;
      }
    }
    cout<<"EQUAL"<<endl;
  }
}


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

int main() {

    int a,b,c;

    cin >> a >> b >> c;

    if(a == b){
        cout << c << endl;
    }
    else if(b == c){
        cout << a << endl;
    }
    else{
        cout << b << endl;
    }

    return 0;
}

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

int main() {

	int N,K,R,S,P,score=0;
  string T;
  cin>>N>>K>>R>>S>>P>>T;
  map<char,int> es;
  es['r']=P;
  es['s']=R;
  es['p']=S;
  for(int i=0; i<N;i++)
  {
    if(i>=K)
    {
      char a,b,c;   
      a=T.at(i-K); b=T.at(i);
      if(i+K<N){c=T.at(i+K);}
      if(a==b){T.at(i)='l';}
      else{score += es.at(b);}     
    }
    else{score+=es.at(T.at(i));}
   }
cout<<score<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

struct Dinic{
  const int INF=1<<28;
  
  struct edge {
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };

  int n;
  vector<vector<edge> > G;
  vector<map<int,int> > M;
  vector<int> level,iter;

  Dinic(){}
  Dinic(int sz):n(sz),G(n),M(n),level(n),iter(n){}
  
  void add_edge(int from,int to,int cap){
    M[from][to]=G[from].size();
    M[to][from]=G[to].size();
    G[from].push_back(edge(to,cap,G[to].size()));
    // undirected
    //G[to].push_back(edge(from,cap,G[from].size()-1));
    // directed
    G[to].push_back(edge(from,0,G[from].size()-1));
  }
  
  void bfs(int s){
    fill(level.begin(),level.end(),-1);
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
      int v=que.front();que.pop();
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap>0&&level[e.to]<0){
          level[e.to]=level[v]+1;
          que.push(e.to);
        }
      }
    }
  }
  
  int dfs(int v,int t,int f){
    if(v==t) return f;
    for(int &i=iter[v];i<(int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to]){
        int d = dfs(e.to,t,min(f,e.cap));
	     if(d>0){
	       e.cap-=d;
	       G[e.to][e.rev].cap+=d;
	       return d;
	     }
      }
    }
    return 0;
  }
  
  int flow(int s,int t,int lim){
    int fl=0;
    for(;;){
      bfs(s);
      if(level[t]<0||lim==0) return fl;
      fill(iter.begin(),iter.end(),0);
      int f;
      while((f=dfs(s,t,lim))>0){
	     fl+=f;
	     lim-=f;
      }
    }
  }

  int flow(int s,int t){
    return flow(s,t,INF);
  }

  //cap==1 only
  bool back_edge(int s,int t,int from, int to){
    for(int i=0;i<(int)G[from].size();i++) {
      edge& e=G[from][i];
      if(e.to==to) {
        if(e.cap==0&&flow(from,to,1)==0) {
          flow(from,s,1);
          flow(t,to,1);
          return 1;
        }
      }
    }
    return 0;
  }
};

int A,B,C,D,NB,NC,ND,x,y,z;

int main(){
	while(cin>>A>>B>>C>>D>>NB>>NC>>ND,A!=-1){
		Dinic DIN(500);
		map<int,int>Ai,Bi,Ci,Di,Bp,Cp;  // number -> id;
		int id=0;
		r(i,A)Ai[i]=id++;
		r(i,B)Bp[i]=id++;
		r(i,B)Bi[i]=id++;
		r(i,C)Cp[i]=id++;
		r(i,C)Ci[i]=id++;
		r(i,D)Di[i]=id++;
		r(i,B){
			cin>>x;
			while(x--){
				cin>>y;
				y--;
				DIN.add_edge(Ai[y],Bp[i],1);
			}
		}
		r(i,C){
			cin>>x;
			while(x--){
				cin>>y;
				y--;
				DIN.add_edge(Bi[y],Cp[i],1);
			}
		}
		r(i,D){
			cin>>x;
			while(x--){
				cin>>y;
				y--;
				DIN.add_edge(Ci[y],Di[i],1);
			}
		}
		r(i,B){
			DIN.add_edge(Bp[i],Bi[i],1);
		}
		r(i,C){
			DIN.add_edge(Cp[i],Ci[i],1);
		}

		r(i,A)r(j,C){
			DIN.add_edge(Ai[i],id,1);
			if(!i)DIN.add_edge(id+1,Cp[j],1);
		}
		DIN.add_edge(id,id+1,NB); id+=2;
		r(i,B)r(j,D){
			DIN.add_edge(Bi[i],id,1);
			if(!i)DIN.add_edge(id+1,Di[j],1);
		}
		DIN.add_edge(id,id+1,NC); id+=2;
		int source=id,sink=id+1; id+=2;
		r(j,C){
			DIN.add_edge(Ci[j],id,1);
		}
		DIN.add_edge(id,sink,ND);
		r(i,A)DIN.add_edge(source,i,1);
		r(i,D)DIN.add_edge(Di[i],sink,1);
		cout<<DIN.flow(source,sink)<<endl;
	}
}


Measured memory_bytes: 4080