akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a = -1, z = -1;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'Z') {
      z = i;
      break;
    }
  }
  cout << z - a + 1 << endl;
  return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<endl;}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
}

int main(){
  int d;cin>>d;
  string s,t;
  s="Christmas";
  t=" Eve";
  for(; d<25;d++)s+=t;
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ff first
#define dd second
#define mp make_pair
#define pb push_back
#define pp pair<int,int>
#define N 100007 // check
#define M 10000
#define K 76
#define ll long long
using namespace std;

int n,d,m,s,t;

vector<int> graph[N];
vector<int> w1[N];
vector<int> w2[N];
int dist1[N];
int dist2[N];
int ans[N];

void dijkstra(int v, int * dist, vector<int> * w, vector<int> * graph) {
    dist[v] = 0;

    priority_queue<pp> q;
    q.push({0,v});

    while(not q.empty()) {
        pp temp = q.top(); q.pop();
        temp.ff *= -1;
        if(temp.ff == dist[temp.dd]) {
            dist[temp.dd] = temp.ff;
            for(int i = 0; i < graph[temp.dd].size(); ++i) {
                int who = graph[temp.dd][i];
                int wag = w[temp.dd][i];
                int nv = wag+dist[temp.dd];
                if(nv < dist[who]) {
                    dist[who] = nv;
                    q.push({-nv, who});
                }
            }
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m >> s >> t;

    for(int i = 0; i < m; ++i) {
        int a,b,c,d; cin >> a >> b >> c >> d;
        graph[a].pb(b);
        graph[b].pb(a);
        w1[a].pb(c);
        w1[b].pb(c);
        w2[a].pb(d);
        w2[b].pb(d);
    }

    for(int i = 0; i <= n; ++i) {
        dist1[i] = 1e17;
        dist2[i] = 1e17;
        ans[i] = 1e17;
    }

    dijkstra(s, dist1, w1, graph);
    dijkstra(t, dist2, w2, graph);

    int mini = 1e17;

    for(int i = 0; i < n; ++i) {
        ans[i] = dist1[i+1]+dist2[i+1];
    }

    for(int i = n-2; i >= 0; --i) ans[i] = min(ans[i], ans[i+1]);

    for(int i = 0; i < n; ++i) {
        cout << ((int)(1e15-ans[i])) << "\n";
    }

}

Measured memory_bytes: 22392
def main():
    N = int(input())
    ab_cnt = 0
    b_cnt = 0
    a_cnt = 0
    ans = 0
    for _ in range(N):
        S = input()
        ans += S.count("AB")
        if S[0] == "B" and S[-1] == "A":
            ab_cnt += 1
        elif S[0] == "B":
            b_cnt += 1
        elif S[-1] == "A":
            a_cnt += 1
    if ab_cnt > 1:
        ans += max(ab_cnt - 1, 0)
        ab_cnt = 1
    if a_cnt <= b_cnt:
        ans += a_cnt
        a_cnt = 0
        b_cnt -= a_cnt
    elif b_cnt < a_cnt:
        ans += b_cnt
        b_cnt = 0
        a_cnt -= b_cnt
    if ab_cnt > 0 and (a_cnt > 0 or b_cnt > 0):
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45160
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<tuple>
#include<stack>
#include<iomanip>
#include<map>
using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const ll MOD = 998244353;
const int N = 200000 + 5;
ll dp[N], sum[N];

int main() {
    int n, k;
    cin >> n >> k;
    vector<pii> rng(k);
    for (int i = 0; i < k; ++i) {
        cin >> rng[i].first >> rng[i].second;
    }
    dp[1] = 1;
    for (int i = 2; i <= n; ++i) {
        dp[i - 1] = (dp[i - 1] + dp[i - 2]) % MOD;
        for (int j = 0; j < k; ++j) {
            int l, r;
            tie(l, r) = rng[j];
            dp[i] = (dp[i] + dp[max(0, i - l)] - dp[max(0, i - r - 1)] + MOD) % MOD;
        }
    }
    cout << dp[n] << endl;
    return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

ll rui(ll u){
    if(u==0) return 1;
    else if(u==1) return 2;
    else if(u%2==0) return rui(u/2)*rui(u/2)%mod;
    else return rui(u-1)*2%mod;
}

int main(){
  
    string L;cin>>L;
    int N=L.size();
    ll ans=1,cnt=0;
    for(int i=0;i<N;i++){
        if(L[i]=='1'){
            ans=ans*3%mod;
            cnt++;
        }else{
            ll a=rui(cnt+1);
            ans=ans*3%mod;
            if(ans>=a) ans=ans-a;
            else ans=ans+mod-a;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
use proconio::{fastout, input};
// use proconio::marker::*;
use std::collections::BTreeMap;

#[fastout]
fn main() {
   input! {
      mut n: usize,
      ab: [(i64, i64); n]
   }
   let mut zero = 0;
   let mut hm = BTreeMap::<(i64, i64), (usize, usize)>::new();
   for (_a, _b) in ab {
      if _a == 0 && _b == 0 {
         zero += 1;
         continue;
      }

      let m = num::integer::gcd(_a.abs(), _b.abs());
      let a = _a / m;
      let b = _b / m;

      if a == 0 {
         hm.entry((0, 1))
            .and_modify(|(l, _)| *l += 1)
            .or_insert((1, 0));
      } else if b == 0 {
         hm.entry((0, 1))
            .and_modify(|(_, r)| *r += 1)
            .or_insert((0, 1));
      } else if a.is_negative() ^ b.is_negative() {
         hm.entry((a.abs(), b.abs()))
            .and_modify(|(l, _)| *l += 1)
            .or_insert((1, 0));
      } else {
         hm.entry((b.abs(), a.abs()))
            .and_modify(|(_, r)| *r += 1)
            .or_insert((0, 1));
      }
   }

   let mut ans = Mint::new(1);
   for &(l, r) in hm.values() {
      ans *= Mint::new(2).pow(l) + Mint::new(2).pow(r) - Mint::new(1);
   }
   ans -= Mint::new(1);
   ans += Mint::new(zero);
   println!("{}", ans);
}

use std::ops::*;
const MOD: i64 = 1000000007;
#[derive(Copy, Clone, Debug)]
pub struct Mint {
   x: i64,
}
impl Mint {
   fn new(x: i64) -> Self { Mint { x: x } }
   fn pow(self, n: usize) -> Self {
      let mut x = Mint::new(1);
      let mut r = self;
      let mut n = n;
      while n > 0 {
         if n & 1 == 1 {
            x *= r;
         }
         r *= r;
         n >>= 1;
      }
      x
   }
   fn inv(self) -> Self { self.pow((MOD - 2) as usize) }
}
impl AddAssign for Mint {
   fn add_assign(&mut self, rhs: Self) {
      self.x += rhs.x;
      self.x %= MOD;
   }
}
impl Add for Mint {
   type Output = Self;
   fn add(self, other: Self) -> Self {
      let mut res = self;
      res += other;
      res
   }
}
impl SubAssign for Mint {
   fn sub_assign(&mut self, rhs: Self) {
      self.x -= rhs.x;
      if self.x < 0 {
         self.x += MOD;
      }
   }
}
impl Sub for Mint {
   type Output = Self;
   fn sub(self, other: Self) -> Self {
      let mut res = self;
      res -= other;
      res
   }
}
impl MulAssign for Mint {
   fn mul_assign(&mut self, rhs: Self) {
      self.x *= rhs.x;
      self.x %= MOD;
   }
}
impl Mul for Mint {
   type Output = Self;
   fn mul(self, other: Self) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl DivAssign for Mint {
   fn div_assign(&mut self, rhs: Self) { *self *= rhs.inv(); }
}
impl Div for Mint {
   type Output = Self;
   fn div(self, other: Self) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl From<i64> for Mint {
   fn from(num: i64) -> Self { Mint { x: num } }
}
impl From<i32> for Mint {
   fn from(num: i32) -> Self { Mint { x: num as i64 } }
}
impl From<usize> for Mint {
   fn from(num: usize) -> Self { Mint { x: num as i64 } }
}
use std::fmt;
impl fmt::Display for Mint {
   fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.x) }
}


Measured memory_bytes: 23112
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm> 
#include<cstring>
#define ios ios::sync_with_stdio(false)
#define mem(arr) memset(arr,0,sizeof(arr))
using namespace std;
typedef long long ll;
const ll maxn = 1e7 + 10;
const ll mod = 1e9 + 7;
int x[maxn],y[maxn];
int main()
{
	int n;
	ll ans;
    cin>>n;
    for(int i = 1;i <= n; i++)
	{
        int a,b;
		cin>>a>>b;
        x[i] = a - b;
        y[i] = a + b;
    }
    sort(x + 1,x + n + 1);
    sort(y + 1,y + n + 1);
    ans = max(x[n] - x[1],y[n] - y[1]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5100
import java.util.*
import java.lang.Math.*


val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1_000_000_007L
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)


fun solve(A: IntArray): Int {
    val N = A.size
    if (N == 1) return 1

    when (A.count{it == 1}) {
        in 2..N -> { return 0 }
        1 -> { return 1 }
        else -> {
            var B = A.sorted()
            if (B[0] == B.last()) return 0

            val AMAX = 1_000_000
            val hist = IntArray(AMAX+1){0}
            for (i in 0 until N) {
                hist[B[i]] += 1
            }

            val fc = IntArray(AMAX+1){0}
            for (i in B.indices) {
                if (fc[B[i]] != 0) continue

                val unique = hist[B[i]] == 1

                fc[B[i]] = if (unique) B[i] else -1

                for (j in B[i]*2 .. AMAX step B[i]) {
                    if (fc[j] == 0) fc[j] = if (unique) B[i] else -1
                }
            }

            return fc.distinct().filter { it>0 }.count()
        }
    }
}


fun main(args: Array<String>) {
    val N = readInt()
    val A = readIntArray()

    val ans = solve(A)

    println(ans)
}


Measured memory_bytes: 92668
#include <bits/stdc++.h>
#define rei register int
#define pb push_back
using namespace std;
const int maxn = 1000010;
int h,w,ch,dh,cw,dw;
int s,t;
int dep[maxn];
char sc[1100][1100];
vector<int>ver[maxn],val[maxn];
void add(int x,int y,int W){
	ver[x].pb(y),ver[y].pb(x);
	val[x].pb(W),val[y].pb(W);
}
int main(){
//	puts("1");
	cin >> h >> w;
	cin >> ch >> cw; s = (ch - 1) * w + cw;
	cin >> dh >> dw; t = (dh - 1) * w + dw;
	for(rei i = 1;i <= h;++i)
	 for(rei j = 1;j <= w;++j){
		char ch = getchar(); int id = (i - 1) * w + j;
		while(ch != '#' && ch !='.') ch = getchar(); sc[i][j] = ch;
		if(ch == '.') {
			if(i > 1 && sc[i - 1][j] == '.') add(id,id - w,0);
			if(j > 1 && sc[i][j - 1] == '.') add(id,id - 1,0);
			for(rei k = max(i - 2,1);k <= i;++k)
			 for(rei t = max(j - 2,1);t <= j;++t) {
//			if(i == 1 && j == 4) cerr << k << " " << t <<" "  << sc[k][t] << " " << (k - 1) * w + t <<   endl;
				if((k != i || t != j) && sc[k][t] == '.') {
//			if(i == 1 && j == 4) cerr << id << " " << (k - 1) * w + t << endl;
				add(id,(k - 1) * w + t,1);
				}
				
			}
			for(rei k = max(i - 2,1);k < i;++k)
				for(rei t = j;t <= min(j + 2,w);++t){
//				if(i == 2 && j == 2) cerr << k << " " << t << endl;
				if(sc[k][t] == '.') add(id,(k - 1) * w + t,1);
			}
		}
	} 
//	for(rei i = 0;i < ver[2].size();++i)
//	 cerr << ver[2][i] << " " ; cerr << endl;
//	for(rei i = 0;i < val[2].size();++i)
//	 cerr << val[2][i] << " " ; cerr << endl;
	int dq[maxn << 1],head(maxn),tail(maxn - 1);
	dq[++tail] = s; dep[s] = 1;
	while(head <= tail){
		int x = dq[head++];
		for(rei i = 0;i < ver[x].size();++i) if(dep[ver[x][i]] == 0){
			if(val[x][i] == 0) dep[ver[x][i]] = dep[x],dq[--head] = ver[x][i];
			else dep[ver[x][i]] = dep[x] + 1,dq[++tail] = ver[x][i];
		} else if(dep[ver[x][i]] > dep[x] + val[x][i]) dep[ver[x][i]] = dep[x] + val[x][i],dq[--head] = ver[x][i];
	} dep[t] ? printf("%d",dep[t] - 1) : puts("-1");
}

Measured memory_bytes: 162500
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  vector<ll> v(3);
  rep(i,0,3) cin>>v[i];
  sort(all(v));
  ll ab = v[0]*v[1];
  ll k = v[2]/2;
  ll ans = abs((v[2]-k*2)*ab);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3592
A,B,K=map(int,input().split())
for k in range(K):
    if k%2==0:
        if A%2==1:
            A-=1
        A//=2
        B+=A
    if k%2==1:
        if B%2==1:
            B-=1
        B//=2
        A+=B
print(A,B)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
	int n,m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		int ban[1000] = {0};
		int saikoro[1000] = {0};
		int iti = 0;
		for (int i = 0; i < n; i++) {
			cin >> ban[i];
		}
		for (int i = 0; i < m; i++) {
			cin >> saikoro[i];
		}
		int j;
		for (j = 0; j < m; j++) {
			iti += saikoro[j];
			if (iti >= n-1) {
				break;
			}
			iti += ban[iti];
			if (iti >= n-1) {
				break;
			}
		}
		cout << j+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  char c='a';
  string S;
  cin>>S;
  int x=S.size();
  bool ok=true;
  rep(i,26){
    ok=true;
  rep(i,x){
    if(S[i]==c){
      ok=false;
      if(c=='z') break;
      c++;
      break;
    }
  }
    if(ok){
      cout<<c<<endl;
      break;
    }
  }
  
  if(!ok)
    cout<<"None"<<endl;
}
  

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <cmath>
#include <sstream>
#include <queue>
#include <map>
#include <cstring>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
    int N;
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cin >> N;
    vector<long long> x(N + 2);
    vector<long long> y(N + 2);
    vector<long long> r(N + 2);
    vector<vector<double> >distance(N + 2, vector<double>(N + 2));
    x[0] = x1;
    x[1] = x2;
    y[0] = y1;
    y[1] = y2;
    r[0] = r[1] = 0;
    for (int i = 2; i < N + 2; ++i) {
        cin >> x[i] >> y[i] >> r[i];
    }
    for (int i = 0; i < N + 2; ++i) {
        for (int j = i; j < N + 2; ++j) {
            if (i == j) {
                distance[i][j] = 0;
            } else {
                double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) - r[i] - r[j];
                distance[j][i] = distance[i][j] = max(0.0, d);
            }
        }
    }
    for (int j = 0; j < N + 2; ++j) {
        for (int i = 0; i < N + 2; ++i) {
            for (int k = i + 1; k < N + 2; ++k) {
                if (distance[i][k] > distance[i][j] + distance[j][k]) {
                    distance[i][k] = distance[k][i] = distance[i][j] + distance[j][k];
                }
            }
        }
    }
    printf("%.10lf\n", distance[0][1]);
    return 0;
}


Measured memory_bytes: 8192
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
  
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    string s;
    cin >> s;
    int n = sz(s);
    bool ok = n % 2 == 0;
    rep(i, 0, n) {
        if (i % 2 == 0) {
            if (s[i] != 'h') {
                ok = false;
            }
        } else {
            if (s[i] != 'i') {
                ok = false;
            }
        }
    }
    cout << (ok ? "Yes\n" : "No\n");
    return 0;
}

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

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

using namespace std;




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

    vector<int> prime;
    rep(i, n+1){
        if(i == 0 || i == 1)  continue;
        bool b = true;
        for(auto e : prime){
            if(i % e == 0)  b = false;
        }
        if(b){
            prime.push_back(i);
        }
    }

    map<int, int> m;

    ll res = 1;
    ll mod = pow(10, 9) + 7;

    rep(i, n+1){
        if(i == 0 || i == 1)  continue;
        int num = i;
        rep(j, (ll)prime.size()){
            if(num % prime[j] == 0){
                m[prime[j]]++;
                num /= prime[j];
                j = -1;
            }
        }
    }

    for(auto iter = m.begin(); iter != m.end(); iter++){
        res *= iter->second + 1;
        res %= mod;
    }

    cout << res << endl;





    return 0;
}


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

#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vec;
typedef vector<pll> vecp;
typedef map<ll, ll> mpll;


const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
#define LOCAL 3
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


void solve()
{
	ll n, m;
	cin>>n>>m;
	if(n < m)
	{
		rep(i, 0, m) cout<<n;
		cout<<endl;
	}
	else
	{
		rep(i, 0, n) cout<<m;
		cout<<endl;
	}
}


int main()
{
	ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int k = in.nextInt();

        int count = 0;
        while (b <= a) {
            b *= 2;
            count++;
        }

        while (c <= b) {
            c *= 2;
            count++;
        }

        if (count <= k) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35728
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;

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


	cout<<endl<<endl;
	d[0][0]=a[0];
	d[0][1]=b[0];
	d[0][2]=c[0];
	//printf("%i %i %i\n", d[0][0], d[0][1], d[0][2]);

	for(int i=1; i<n; i++) {
		d[i][0]=max(d[i-1][1],d[i-1][2])+a[i];
		d[i][1]=max(d[i-1][0],d[i-1][2])+b[i];
		d[i][2]=max(d[i-1][1],d[i-1][0])+c[i];

		//printf("%i %i %i\n", d[i][0], d[i][1], d[i][2]);
	}
	printf("%i\n", max(d[n-1][0], max(d[n-1][1], d[n-1][2])));
}

Measured memory_bytes: 2560
N = int(input())

if(N == 100000):
    ans = 90909
elif(10000 <= N < 100000):
    ans = 909 + N - 9999
elif(1000  <= N < 10000):
    ans = 909
elif(100   <= N < 1000):
    ans = 9 + N -99
elif(10    <= N < 100):
    ans = 9
elif(1     <= N < 10):
    ans = N

print(ans)




Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<unistd.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int N;cin>>N;
    int ans=0;
    REP(i,N){
        int a;cin>>a;
        if(a&1) ans++;
    }
    if(ans&1) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}


Measured memory_bytes: 256
from collections import deque
import copy
H, W = map(int, input().split())
 
start = set()
for y in range(H):
  for x, w in enumerate(input()):
    if w == '.':
      start.add((x,y))

score = 0
ssize = [(-1,0),(0,-1),(1,0),(0,1)]
for xy in start:
  d = deque()
  d.append((xy+(0,)))
  step = 0
  can = copy.deepcopy(start)
  can.remove(xy)
  while len(d) > 0:
    now = d.popleft()
    step = now[2]
    for xs, ys in ssize:
      nxt = (now[0]+xs, now[1]+ys)
      if nxt in can:
        d.append(nxt+(step+1,))
        can.remove(nxt)
  score = max(step, score)
  
print(score)

Measured memory_bytes: 3572
// In The Name Of Allah //
#include <bits/stdc++.h>
#define pb emplace_back
#define inf (int)1e9
#define ff first
#define ss second
#define ll long long
#define sp(n) cout << setprecision(n) << fixed
#define hellcat ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define give(x) cout << #x << " " << x << endl
#define debug cout << "dddd" << '\n'
#define debarr(a, n) for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

template <class S, class T>
inline S smax(S &l, T r) {
  return l = max(l, (S)r);
}
template <class S, class T>
inline bool smin(S &l, T r) {
  return l = min(l, (S)r);
}

const int MAXN = 1e5 + 10;
int h[MAXN];
ll dp[MAXN];

int32_t main () {
	hellcat;

	int n, k;
	cin >> n >> k;

	for (int i = 0; i < n; ++i) cin >> h[i];

	for (int i = 1; i < n; ++i) {
		ll ans = abs(h[i] - h[i - 1]) + dp[i - 1];
		for (int j = 2; j <= k; ++j) {
			if ((i - j) < 0)
				break;
			smin(ans, (dp[i - j] + abs(h[i - j] - h[i])));
		}
		dp[i] = ans;
	}

	cout << dp[n - 1] << '\n';

	return 0;
}


Measured memory_bytes: 1408
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.numeric;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  writeln(a.reduce!gcd);
}


Measured memory_bytes: 4604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a%3==0 || b%3==0||(a+b)%3==0) System.out.println("Possible");
		else System.out.println("Impossible");
	}

}


Measured memory_bytes: 27068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める
double dist(vector<int> y, vector<int> z, int d){
    int total = 0;
    rep(i,d){
        total += (y[i]-z[i])*(y[i]-z[i]);
    }
    double ans = sqrt(total);
    return ans;
}

bool is_int(double x){
    return floor(x) == x;
}
int main()
{
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    rep(i,n)rep(j,d) cin >> x[i][j];
    int ans = 0;
    rep(i,n){
        for (int j = i; j < n; j++)
        {
            if(i == j) continue;
            double di = dist(x[i],x[j],d);
            if(is_int(di)) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			String s = sc.next();
			char[] cs = s.toCharArray();
			
			int res = 0;
			
			for(int i=0;i<n-2;i++) {
				if(cs[i]=='A'&&cs[i+1]=='B'&&cs[i+2]=='C') {
					res++;
				}
			}
			
			System.out.println(res);
			
		}

	}
	

	

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<double,double> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<17;




int main(){
    int N;
    cin >> N;
    int dp[N+1];
    for(int i=0;i<N+1;i++){
        dp[i]=INF;
    }
    dp[0]=0;
    for(int i=0;i<N;i++){
        int s=1;
        for(int j=1;j<30;j++){
            if(i+s>N) break;
            dp[i+s]=min(dp[i+s],dp[i]+1); 
            s*=6;
        }
        s=1;
        for(int j=1;j<30;j++){
            if(i+s>N) break;
            dp[i+s]=min(dp[i+s],dp[i]+1); 
            s*=9;
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

using namespace std;

int main(void) {
	int in[5], n[5]={0,1,2,3,4}, tmp, i, j;

	cin >> in[0] >> in[1] >> in[2] >> in[3] >> in[4];
	for(i=0;i<5;i++) {
		for(j=i;j<5;j++) {
			if(in[n[j]] > in[n[i]]) {
				tmp = n[j];
				n[j] = n[i];
				n[i] = tmp;
			}
		}
	}
	printf("%d %d %d %d %d\n", in[n[0]] ,in[n[1]] ,in[n[2]] ,in[n[3]] ,in[n[4]]);
	return 0;
}

Measured memory_bytes: 0
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,a,b) for (int i = a; i < (b); i++)
#define sz(t) int(t.size())
using namespace std;
typedef long long ll;

// int dp[100005][100005];

// vector<pair<int, int> > ab;
vector<vector<int> > profit(100005);
// int a[100005];
// int b[100005];

int main(void) {
    int n, m;
    cin >> n >> m;


    REP(i, 1 , n + 1) {
        int ta, tb;
        cin >> ta >> tb;
        profit[ta].push_back(tb);
    }

    priority_queue<int> q;

    ll ans = 0;
    REP(i, 1, m + 1) {
        for (auto u : profit[i]) {
            q.push(u);
        }

        if (q.empty())
            continue;

        ans += q.top();
        q.pop();
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 5632
#include <cstdio>

bool pf[233333];

int main()
{
	for(int i=1; i<=100; i++) pf[i*i]=true;
	int n,k,a; scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		int sum=0;
		for(int x=1; x*x<i; x++) for(int y=1; y*y<i; y++)
		{
			int p=i-x*x-y*y-x*y,k=(x+y)*(x+y)+4*p;
			if(p<=0) continue;
			for(int j=x+y; j*j<=k; j+=2) if(j*j==k)
			{
				sum++; break;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 1716
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

int height[NUM]; //同じグループに属しているかどうかだけを調べるために使用
int calc_parent[NUM];
int relative_weight[NUM]; //自分のボスとの相対的な重さの差を持つ配列

struct Info{
	void set(int arg_parent_id,int arg_weight_sum){
		parent_id = arg_parent_id;
		weight_sum = arg_weight_sum;
	}
	int parent_id,weight_sum;
};

Info find_parent_and_calc_weight(int id){
	if(calc_parent[id] == id){
		Info ret;
		ret.set(id,0); //大ボスの相対的重さは必ず0
		return ret;
	}
	else{
		Info ret = find_parent_and_calc_weight(calc_parent[id]); //大ボスのidと、自分より上の相対的重さの総和を取得
		calc_parent[id] = ret.parent_id;
		relative_weight[id] += ret.weight_sum; //自分より上の相対的重さを足す
		ret.weight_sum = relative_weight[id];

		return ret;
	}
}


//グループの統合、および相対的重さ木の統合を行う
void unite(int a,int b,int w){

	//まずは
	Info a_info = find_parent_and_calc_weight(a);
	Info b_info = find_parent_and_calc_weight(b);

	if(a_info.parent_id == b_info.parent_id)return; //大ボスが同じならreturn

	//統合処理
	if(height[a_info.parent_id] == height[b_info.parent_id]){ //木の高さが同じ場合はaに併合する

		relative_weight[b_info.parent_id] = w-(relative_weight[b]-relative_weight[a]);
		calc_parent[b_info.parent_id] = a_info.parent_id;

	}else if(height[a_info.parent_id] == height[b_info.parent_id]){ //木の高さが高い方に併合する
		relative_weight[b_info.parent_id] = w-(relative_weight[b]-relative_weight[a]);
		calc_parent[b_info.parent_id] = a_info.parent_id;
		height[a_info.parent_id]++;
	}else{

		relative_weight[a_info.parent_id] = (relative_weight[b]-relative_weight[a])-w;
		calc_parent[a_info.parent_id] = b_info.parent_id;
	}
}

bool isSame(int a,int b){
	Info left = find_parent_and_calc_weight(a);
	Info right = find_parent_and_calc_weight(b);

	return left.parent_id == right.parent_id;
}

int main(){

	int N,Q;
	scanf("%d %d",&N,&Q);

	for(int i = 0; i <= N; i++){
		height[i] = 0;
		calc_parent[i] = i;
		relative_weight[i] = 0; //初期値は0にしておく
	}

	int command,A,B,value;
	for(int loop = 0; loop < Q; loop++){
		scanf("%d",&command);

		if(command == 0){
			scanf("%d %d %d",&A,&B,&value);
			unite(A,B,value);
		}else{
			scanf("%d %d",&A,&B);
			if(!isSame(A,B)){ //★ここでそれぞれの経路圧縮&weight計算が行われる★
				printf("?\n");
			}else{
				printf("%d\n",relative_weight[B]-relative_weight[A]);
			}
		}
	}

	return 0;
}



Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
int main() {
	FASTIO;
	string a;
	while(cin >> a) {
		list<char> s;
		int sz = a.size(), reverses = 0, p = 1;
		for(int  i = 0; i < sz; i++) {
			s.emplace_back(a[i]);
		}
		int q, t, f;
		char c;
		cin >> q;
		while(q--) {
			cin >> t;
			if(t == 1) {
				reverses++;
				p = !p;
			} else {
				cin >> f >> c;
				if(f == 1) {
					if(p)
						s.emplace_front(c);
					else
						s.emplace_back(c);
				} else {
					if(p)
						s.emplace_back(c);
					else
						s.emplace_front(c);
				}
			}
		}
		if(reverses & 1) s.reverse();
		for(auto x : s) {
			cout << x;
		}
		cout << endl;
	}
}

Measured memory_bytes: 10064
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];

void rec(int p) {
	
	vector<int> children;
	for (size_t i = 0; i < te[p].size(); i++)
	{
		int f = te[p][i].t;
		if (fe[f].size() != 1) {
			for (size_t j = 0; j < fe[f].size(); j++)
			{
				if (fe[f][j].t == p) {
					fe[f].erase(fe[f].begin() + j);
					break;
				}
			}
		}
		else {
			children.push_back(f);
		}
	}
	for (size_t i = 0; i < children.size(); i++)
	{
		rec(children[i]);
	}
}
void Solve() {

	int n, m;
	cin >> n >> m;

	for (size_t i = 0; i < n + m - 1; i++)
	{
		int f, t;
		cin >> f >> t;
		te[f].push_back(t);
		fe[t].push_back(f);
	}
	int p = 0;
	for (size_t i = 1; i <= n; i++)
	{
		if (fe[i].size() == 0) p = i;
	} 

	rec(p);
	for (size_t i = 1; i <= n; i++)
	{
		if (fe[i].size() == 0) cout << 0 << endl;
		else cout << fe[i][0].t << endl;
	}
}


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



Measured memory_bytes: 25728
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	int ans = s.size();
	for (int i = 0; i < s.size()-1; ++i) {
		if (s[i]!=s[i+1]) {
			ans = min(ans, max(i+1, (int)s.size()-i-1));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
//code by 27.
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<cassert>
#include<climits>
#include<cmath>
#include<memory.h>
using namespace std;
vector<int>a[1000001];
int f[1000001];
queue<int>que;
int main()
{
	int g=0,g1=0,g2=0;
	int n,m;
	cin>>n;
	int x,y;
	for(int i=1;i<=n-1;i++)
	{
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	que.push(1);
	que.push(n);
	f[1]=1;
	f[n]=-1;
	while(g<n)
	{
		for(int i=0;i<a[que.front()].size();i++)
		{
			//cout<<"*"<<a[que.front()][i]<<" "<<f[a[que.front()][i]]<<endl;
			if(f[a[que.front()][i]]==0&&f[que.front()]==-1)
			{
				f[a[que.front()][i]]=-1;
				que.push(a[que.front()][i]);
			}
			else if(f[a[que.front()][i]]==0&&f[que.front()]==1)
			{
				f[a[que.front()][i]]=1;
				que.push(a[que.front()][i]);
			}
		}
		if(f[que.front()]==1)g1++;
		else if(f[que.front()]==-1)g2++;
		que.pop();
		g++;
	}
	if(g2>=g1)cout<<"Snuke";
	else cout<<"Fennec";
	return 0;
}

Measured memory_bytes: 29184
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

//自作関数 a^n mod MODを求める
int m_pow(int a, int n){
  if(n == 0) return 1;
  if(n % 2 == 0){
    int t = m_pow(a, n / 2);
    return t * t % MOD;
  }
  return a * m_pow(a, n - 1) % MOD;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int n,a,b;

  cin >> n >> a >> b;

  int ans = (n / (a + b)) * a;

  ans += min(a, n % (a + b));

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    int ans=0;
    FOR(i,1,n){
        ans+=min(b,a*(vec[i]-vec[i-1]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n;
    int m;
    
    cin>>n>>m;
    
    unordered_multimap<int, int> e1;
    unordered_multimap<int, int> en;
    for(int i = 0 ; i < m ; i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==1)  e1.insert(make_pair(a,b));
        if(b==1)  e1.insert(make_pair(b,a));
        if(a==n)  en.insert(make_pair(b,a));
        if(b==n)  en.insert(make_pair(a,b));
    }
    bool isfind = false;
    auto range_e1 = e1.equal_range(1);
    for(auto it = range_e1.first ; it != range_e1.second ; it++)
    {
        int x = it->second;
        if(en.find(x) != en.end())
        {
            isfind = true;
            break;
        }
    }
    
    if(isfind)
    {
        cout<<"POSSIBLE";
    }
    else
    {
        cout<<"IMPOSSIBLE";
    }
    return 0;
}

Measured memory_bytes: 8520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int MAX = 5e6;
const ll mod = 1e9+7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * (ll)i % mod;
        inv[i] = mod - inv[mod%i] * (mod/(ll)i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

ll f(ll x, ll y) {
  ll res = 0;
  rep(i,x+1) {
    (res += COM(y+i+1,i+1)) %= mod;
  }
  return res;
}

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  COMinit();
  ll ans = f(c,d) - f(c,b-1) - f(a-1,d) + f(a-1,b-1);
  cout << ((ans % mod) + mod) % mod << endl;
  return 0;
}

Measured memory_bytes: 117504
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n, m = MAP()
a = LIST()
s = sum(a)
if n < s:
    print(-1)
else:
    print(n - s)

Measured memory_bytes: 68836
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll n,k;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	n%=k;
	cout<<min(n,k-n);
	re 0;
}

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

int main() {
    vector<int> a(3);
    for (int i = 0; i < 3; i++) cin >> a.at(i);
    sort(a.begin(), a.end());

    int x , y;
    x = a.at(2) - a.at(1);
    y = a.at(2) - a.at(0);
    int ans = 0;
    bool can = true;
    if ((x + y) % 2 != 0) can = false;
    while (true){
        if (x >= 1) {
            x--;
            y--;
            ans++;
        }
        
        else if (x == 0 && y > 0) {
            y-=2;
            ans++;
        }

        if (x <= 0 && y <= 0) break;
    }

    if (!can) {
        ans++;
        //cout << "O" << endl;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
map : count()返回被查找元素的个数 有返回1 无返回0  注意map中不存在相同元素 (下标，即first)
		find()返回位置 若没有则返回map.end()
拆点
*/
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
#define LL long long
#define MAXN 100005
#define INF 1000000000
int N,M,cnt;
map<int,int> id[2*MAXN];//id[u][c]:u属性为c的虚点编号
vector< pair<int,int> > G[5*MAXN];
int dist[5*MAXN];
bool vis[5*MAXN];
void mg()
{
	for(int i=0;i<M;i++)
	{
		int u,v,c;
		scanf("%d %d %d",&u,&v,&c);
		if(!id[u].count(c)) 
		{
			id[u][c]=++cnt;
			G[u].push_back(make_pair(cnt,1));
			G[cnt].push_back(make_pair(u,1));
		}
		if(!id[v].count(c)) 
		{
			id[v][c]=++cnt;
			G[v].push_back(make_pair(cnt,1));
			G[cnt].push_back(make_pair(v,1));
		}
		G[id[u][c]].push_back(make_pair(id[v][c],0));
		G[id[v][c]].push_back(make_pair(id[u][c],0));
	}
}
void sp()
{
	fill(dist,dist+5*MAXN,INF);
	dist[1]=0;
	vis[1]=1;
	queue<int> que;
	que.push(1);
	while(!que.empty())
	{
		int u=que.front();
		que.pop();
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i].first,l=G[u][i].second;
			if(dist[v]>dist[u]+l)
			{
				dist[v]=dist[u]+l;
				if(!vis[v])
				{
					vis[v]=1;
					que.push(v);
				}
			}
		}
		vis[u]=0;
	}
}
int main()
{
	scanf("%d %d",&N,&M);
	cnt=N;
	mg();
	sp();
	if(dist[N]==INF) printf("-1\n");
	else printf("%d\n",dist[N]/2);
	return 0;
}

Measured memory_bytes: 61056