akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  cout << N / 2 * min(min(min(Q * 8, H * 4), S * 2), D) +
              N % 2 * min(min(Q * 4, H * 2), S)
       << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	string to = "keyence";
	string S;
	cin >> S;
	for (int i = 0; i < to.size(); i++) {
		if (S.substr(0, i) == to.substr(0, i) && S.substr(S.size() - 7 + i, S.size()-1) == to.substr(to.size() - 7 + i, to.size() - 1)) {
			cout << "YES" << endl;
			return 0;
		}
	}
	if (S.substr(0, 7) == to) {
		cout << "YES" << endl;
		return 0;
	}
	cout << "NO" << endl;
	return 0;
}

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

int f(int x) {
  return x*x;
}

int main(void) {
  int d;
  while(cin >> d) {
    int s = 0;
    for(int i = d; i <= 600-d; i += d) {
      s += f(i) * d;
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
a = list(map(int, input().split()))
a_set = set(a)
ans = 0

from collections import Counter
x_count = Counter(a)

for i in a_set:
    if i != x_count[i]:
        if i < x_count[i]:
            ans += abs(x_count[i] - i)
        elif i > x_count[i]:
            ans += x_count[i]
        
print(ans)

Measured memory_bytes: 23796
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int a1, a2, a3;

    cin >> a1 >> a2 >> a3;

    if (a1 + a2 + a3 >= 22) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  static int min_value(int a,int b,int c){
    if(b>c) return min_value(a,c,b);
    else if(a>c) return min_value(c,b,a);
    else return a+b;

  }

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

    System.out.println(min_value(a,b,c));
  }
}

Measured memory_bytes: 22868
//:::: Alien :::://
// Muhammad Eid //
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define prINT pair<int, int>

const int N = 1e3 +5;
int ar[N];

void Mo35(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

int main(){
Mo35();

    int n, k; cin>> n>> k;
    for(int i=0; i<n;) cin>> ar[i++];
    sort(ar, ar+n);
    int sum = 0;
    for(int i=0; i<k; ++i) sum += ar[i];
    cout<< sum;

return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
    ll N, D;
    cin >> N >> D;
    vector<double> x(N), y(N);
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> x.at(i) >> y.at(i);
        if (x.at(i) * x.at(i) + y.at(i) * y.at(i) <= double(D * D)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6428
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
  char str[1000 + 3];
  int q, i, j;
  char cmd[8];
  int a, b;
  char p[1000 + 3];
  char tmp;

  scanf("%s", str);
  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    scanf("%s", cmd);
    
    if (!strcmp(cmd, "replace")) {
      scanf("%d %d %s", &a, &b, p);
      strncpy(&str[a], p, b - a + 1);
    } else if (!strcmp(cmd, "reverse")) {
      scanf("%d %d", &a, &b);
      for (j = 0; j < (b - a + 1) / 2; j++) {
        tmp = str[b-j];
        str[b-j] = str[a+j];
        str[a+j] = tmp;
      }
    } else if (!strcmp(cmd, "print")) {
      scanf("%d %d", &a, &b);
      for (j = a; j <= b; j++) printf("%c", str[j]);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 584
/* Contest */
#include<bits/stdc++.h>
#define all(s) (s).begin(),(s).end()
#define rall(s) (s).rbegin(),(s).rend()
#define sep ios::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
int main()
{	
	sep;
	ll n,m,sum=0,cnt=0;
	cin>>n>>m;
	vector<ll>a(n);
	for(auto &x:a) cin>>x,sum+=x;
	for(auto x:a)
	{
		if(x>=double(sum)/(4*m)) cnt++;
		if(cnt==m) return cout<<"Yes",0;
	}

	cout<<"No";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  ll h, n,a,sum=0;
  cin >> h >> n;
  rep(i,n)
  {
    cin >> a;
    sum += a;
  }
  if(h<=sum)
    cout << "Yes";
  else
    cout << "No";
}

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

#define mod 1000000007
#define pb push_back
#define bs binary_search
#define bp __builtin_popcountll

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s,t;
    cin>>s>>t;
    int i,c,n;
    c=0;
    n=s.length();
    for(i=0;i<n;i++)
    {
        if(s[i]==t[i])
        c++;
    }
    
    if(c==n)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;

return 0;
}

Measured memory_bytes: 3576
// In The Name Of God
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int (a) = (b); (a) < (c); (a)++)
#define setp cout << fixed << setprecision(15)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define all(x) (x).begin() , (x).end()

const int maxn = 1e5+100;
int x[maxn];

int32_t main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for2(i,1,1+n) cin >> x[i];
    x[n+1] = 0;
    int cur = 0;
    int total = 0;
    for2(i,1,2+n){
        total += abs(cur-x[i]);
        cur = x[i];
    }
    for2(i,1,n+1){
        cout << total - abs(x[i]-x[i-1]) - abs(x[i+1]-x[i]) + abs(x[i+1]-x[i-1]) << endl;
    }
    return 0;
}



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

using namespace std;

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


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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<string>> snake(h, vector<string>(w));
    string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> snake[i][j];
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (snake[i][j] == "snuke")
            {
                cout << alphabet[j] << i + 1;
                break;
            }
        }
    }
}

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

int main() {
  int N,M;
  cin >> N >> M;
  int L = 1;
  int R = N;

  rep(i,M) {
    int l,r;
    cin >> l >> r;
    L = max(L,l);
    R = min(R,r);
  }

  cout << max(0, R-L+1) << endl;
  return 0;
}

// https://github.com/atcoder/live_library

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  int n;
  cin>>n;
  ll a[n];
  rep(i,0,n) cin>>a[i];
  vector<ll> suf(n,0);
  suf[n-1]=a[n-1];
  rrep(i,n-2,0) suf[i]=(suf[i+1]+a[i])%mod;

  ll ans=0;
  rep(i,0,n-1){
    ans=(ans+a[i]*suf[i+1])%mod;
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 6364
#include <iostream>
#include <vector>

int main() {
  unsigned int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<unsigned int>> a_mat(n, std::vector<unsigned>(m, 0));
  for (size_t i = 0; i < n; ++i) {
    unsigned int k;
    std::cin >> k;
    for (size_t k_i = 0; k_i < k; k_i++) {
      unsigned int idx = 0;
      std::cin >> idx;
      a_mat.at(i).at(idx - 1) = 1;
    }
  }

  unsigned int counter = 0;
  for (size_t j = 0; j < m; ++j) {
    bool is_ok = true;
    for (size_t i = 0; i < n; ++i) {
      if (a_mat.at(i).at(j) == 0) {
        is_ok = false;
        break;
      }
    }
    if (is_ok) {
      ++counter;
    }
  }
  std::cout << counter << std::endl;

  return 0;
}


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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve(){
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	
	int n, sum = 0, ans = 0;
	cin >> n;
	VI v(n);
	rep(i, n){
		cin >> v[i];
		sum += v[i];
	}
	int avg = int(round((double)sum / n));

	rep(i, n) ans += int(pow(abs(v[i] - avg), 2));


	cout << ans << endl;
}


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


	solve();
	system("PAUSE");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main(){

  string s;
  cin >> s;
  for(ll i=0;i<3;i++){
    ll a=ctoi(s[i]);
    cout << 10-a;
  }
  cout << endl;

}

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

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

    int H, W;
    cin >> H >> W;

    map<int, int> candidates;
    multiset<int> moves;

    rep(i, W) {
        candidates[i] = i;
        moves.insert(0);
    }

    rep(i, H) {
        int A, B;
        cin >> A >> B;
        A--;

        int r = -1;
        while (true) {
            auto it = candidates.lower_bound(A);
            if (it == candidates.end() || it->first > B) break;
            r = max(r, it->second);
            moves.erase(moves.find(it->first - it->second));
            candidates.erase(it);
        }
        if (r != -1 && B != W) {
            moves.insert(B - r);
            candidates[B] = r;
        }

        if (moves.size() == 0) {
            cout << -1 << endl;
        } else {
            cout << *moves.begin() + (i + 1) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    constexpr int N = 1e5;
    int n; cin >> n;
    string s; cin >> s;
    int l = s.size();

    REP(i,4) {
        bitset<N+10> ans(i);

        FOR(j,1,l-1){
            if (ans[j]) {   // W
                if (s[j] == 'o') {
                    ans[j+1] = ~ans[j-1];
                } else {    // x
                    ans[j+1] = ans[j-1];
                }
            } else {    // S
                if (s[j] == 'o') {
                    ans[j+1] = ans[j-1];
                } else {    // x
                    ans[j+1] = ~ans[j-1];
                }
            }
        }

        if (ans[l-1]) { // W
            if (s[l-1] == 'o') {
                if (ans[0] == ans[l-2]) continue;
            } else {
                if (ans[0] != ans[l-2]) continue;
            }
        } else {
            if (s[l-1] == 'o') {
                if (ans[0] != ans[l-2]) continue;
            } else {
                if (ans[0] == ans[l-2]) continue;
            }
        }
        if (ans[0]) { // W
            if (s[0] == 'o') {
                if (ans[1] == ans[l-1]) continue;
            } else {
                if (ans[1] != ans[l-1]) continue;
            }
        } else {
            if (s[0] == 'o') {
                if (ans[1] != ans[l-1]) continue;
            } else {
                if (ans[1] == ans[l-1]) continue;
            }
        }

        string astr = "";
        REP(j,l){
            astr += ans[j] ? "W" : "S";
        }
        cout << astr << endl;
        return 0;
    }
    cout << "-1" << endl;


    return 0;
}

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

int	main()
{
	const static int64_t	inf = static_cast<int64_t>(1e+12 + 1);
	int	N, M, P;
	cin >> N >> M >> P;
	vector<int64_t>	v_score(N, -inf);
	map<int, map<int, int64_t>>	e_score;
	int	A, B, C;
	for (int i = 0; i < M; ++i) {
		cin >> A >> B >> C;
		--A; --B;
		if (!e_score.count(A))
			e_score[A] = map<int, int64_t>();
		if (!e_score.at(A).count(B))	
			e_score.at(A)[B] = C - P;
		else if (C - P > e_score.at(A).at(B))
			e_score.at(A)[B] = C - P;
	}
	v_score.at(0) = 0;
	int64_t	score;
	bool	updated;
	for (int i = 0; i < N; ++i) {
		updated = false;
		for (A = 0; A < N; ++A) {
			if (v_score.at(A) == -inf)
				continue;
			if (!e_score.count(A))
				continue;
			for (auto pr : e_score.at(A)) {
				B = pr.first;
				score = v_score.at(A) + pr.second;
				if (score > v_score.at(B)) {
					v_score.at(B) = score;
					updated = true;
				}
			}
		}
		if (!updated)
			break;
	}
	if (!updated) {
		if (v_score.at(N - 1) > 0)
			cout << v_score.at(N - 1) << endl;
		else
			cout << 0 << endl;
		return 0;
	}
	vector<bool>	has_upper(N, true);
	for (int i = 0; i < N; ++i) {
		for (A = 0; A < N; ++A) {
			if (v_score.at(A) == -inf)
				continue;
			if (!e_score.count(A))
				continue;
			for (auto pr : e_score.at(A)) {
				B = pr.first;
				score = v_score.at(A) + pr.second;
				if (score > v_score.at(B)) {
					v_score.at(B) = score;
					has_upper.at(B) = false;
				}
				if (!has_upper.at(A))
					has_upper.at(B) = false;
			}
		}
	}
	if (has_upper.at(N - 1)) {
		if (v_score.at(N - 1) > 0)
			cout << v_score.at(N - 1) << endl;
		else
			cout << 0 << endl;
	} else
		cout << -1 << endl;
	return 0;
}


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

int main(){
	int N;string S;
	cin >> S ; N = S.size();
  	int ans = N;
	for(int i = 0;i < N-1;i++){
  	  if(S[i]!=S[i+1]) ans = min(ans,max(i+1,N-i-1));
  	}
  	//if(ans==INF) ans = N;
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  
  
  int N, count = 0; cin >> N;
  vector<int> diameter(N);
  for(int &ele : diameter) cin >> ele;

  sort(ALL(diameter));
  for(int idx = 1; idx < N; ++idx){
    count += (diameter[idx] != diameter[idx - 1]);
  }
  cout << count + 1 << "\n";
  return 0;
}

Measured memory_bytes: 256
using System.Linq;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var raw = ReadLine().Split().Select(int.Parse).ToArray();
            var N = raw[0];
            var K = raw[1];
            var max = 0;
            var pi = 0;
            var pArray = ReadLine().Split().Select(int.Parse).ToArray();
            var k = pArray.Take(K).Sum();
            for (int i = 0; i < N - K + 1; i++)
            {
                if (i != 0) k = k - pArray[i - 1] + pArray[i + K - 1];
                if (max < k)
                {
                    max = k;
                    pi = i;
                }
            }

            var ans = pArray.Skip(pi).Take(K).Select(s => (double)(1 + s) / 2).Sum();
            WriteLine(ans.ToString("F10"));
        }
    }
}

Measured memory_bytes: 29532
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, Y) = get!(usize, usize);

    for x in 0..(N + 1) {
        for y in 0..(N - x + 1) {
            if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y {
                println!("{} {} {}", x, y, N - x - y);
                return;
            }
        }
    }
    println!("-1 -1 -1");
}


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


int main(){
  int N;
  cin >> N;
  int ans = 0;
  for(int ii=0; ii<N; ii++){
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#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<int,P>
#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()
int main(){
    int n;
    cin>>n;
    map<int,int> ma;
    REP(i,n){
        int t;
        cin>>t;
        ma[t]++;
    }
    int ans=0;
    for(auto itr:ma){
        if(itr.se<itr.fi){
            ans+=itr.se;
        }else{
            ans+=itr.se-itr.fi;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

struct Edge{
    int id;
    int to;
};
const int INF=1000000005;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<Edge>> to(n+1);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        to[a].push_back(Edge{i,b});
        to[b].push_back(Edge{i,a});
    }
    int ans=0;
    
    for(int i=0;i<m;i++){
        vector<int> dist(n,INF);
        dist[0]=0;
        queue<int> q;
        q.push(0);
        while(!q.empty()){
            int temp=q.front();
            q.pop();
            for(const auto& item:to[temp]){
                if(dist[item.to]!=INF||item.id==i) continue;
                dist[item.to]=dist[temp]+1;
                q.push(item.to);
            }
        }
        if(find(dist.begin(),dist.end(),INF)!=dist.end()){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
int n,a[15],x[15][15],y[15][15],ans=0;
void check(int bits)
{
	int num=0;
	REP(i,n)
		if(bits>>i&1)
		{
			num++;
			REP(j,a[i])
				if((bits>>x[i][j]&1)!=y[i][j])return;
		}
	ans=max(ans,num);
}
int main()
{
	cin>>n;
	REP(i,n)
	{
		cin>>a[i];
		REP(j,a[i])cin>>x[i][j]>>y[i][j],x[i][j]--;
	}
	rep(bits,1,1<<n)check(bits);
	cout<<ans<<endl;
	return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin >> a >> b >> c;
      if(a >= c)Cout(0);
      else{
        ans = c - a;
        if(ans <= b)Cout(ans);
        else Cout("NA");
      }
     

       
return 0;
}



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


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

struct edge {int to; ll cost; };

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

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

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}

int main(){
  int n;
  ll k;
  cin >> n >> k;
  ll a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  ll lo=0, hi=1000000005;
  while(hi-lo>1){
    ll mid = (lo+hi)/2;
    ll tmp = 0;
    for(int i=0; i<n; i++){
      tmp += a[i]/mid-1;
      if(a[i]%mid) tmp++;
    }
    if(tmp>k) lo = mid;
    else hi = mid;
  }
  cout << hi << endl;
  return 0;
}


Measured memory_bytes: 5160
a = input()
b = 0
c = 'R'
d = []
for i in a:
  if i == 'R' and c == 'R':
    b = b + 1
    c = 'R'
  elif i == 'R':
    c = 'R'
    b = 1
  else:
    c = 'S'
    b = 0
  d.append(b)
e = sorted(d, reverse=True)
print(e[0])

Measured memory_bytes: 9068
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e6+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
ll dp[N][2][2];
signed main()
{
	Very_fast;
	ll n;
	cin>>n;
	dp[0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		dp[i][0][0]=dp[i-1][0][0]*8%mod;
		dp[i][0][1]=(dp[i-1][0][0]+dp[i-1][0][1]*9%mod)%mod;
		dp[i][1][0]=(dp[i-1][0][0]+dp[i-1][1][0]*9%mod)%mod;
		dp[i][1][1]=(dp[i-1][0][1]+dp[i-1][1][0]+dp[i-1][1][1]*10%mod)%mod;
	}
	ll ans=0;
	ans%=mod;
	cout<<dp[n][1][1];
	return 0;
}

Measured memory_bytes: 34776
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define rep_eq(i,l,r) for(int i=l; i<=(int)(r); i++)
#define all(vec) vec.begin(),vec.end()
#define allr(vec) vec.rbegin(),vec.rend()
using namespace std;

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

using ll=int64_t;

using vb=vector<bool>;
using vc=vector<char>;
using vs=vector<string>;
using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

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

  int N; cin >>N;
  vi a(N);
  map<int,int> mp;
  rep(i,0,N) {
    cin >>a[i];
    if (mp.count(a[i])) {
      mp[a[i]]++;
    } else {
      mp[a[i]]=1;
    }
  }

  int ans=0;
  for (auto x : mp) {
    if (x.second<x.first) {
      ans+=x.second;
    } else if (x.first<x.second) {
      ans+=x.second-x.first;
    }
  }

  cout <<ans <<'\n';
  return 0;
}


Measured memory_bytes: 8112
#include<bits/stdc++.h>
#define maxn 2000005
using namespace std;
const int mod = 1e9+7;
int X[7],Y[7],fac[maxn],inv[maxn],ans;
struct node{int x,y,f;}p[9];
inline int C(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline int F(int a,int b,int c,int d){return C(c+d-a-b,c-a);}
int solve(node s,node t){
	int ret=0;
	for(int x=X[3];x<=X[4];x++){
		ret=(ret-1ll*F(s.x,s.y,x,Y[3]-1)*F(x,Y[3],t.x,t.y)%mod*(x+Y[3]))%mod;
		ret=(ret+1ll*F(s.x,s.y,x,Y[4])*F(x,Y[4]+1,t.x,t.y)%mod*(x+Y[4]+1))%mod;
	}
	for(int y=Y[3];y<=Y[4];y++){
		ret=(ret-1ll*F(s.x,s.y,X[3]-1,y)*F(X[3],y,t.x,t.y)%mod*(X[3]+y))%mod;
		ret=(ret+1ll*F(s.x,s.y,X[4],y)*F(X[4]+1,y,t.x,t.y)%mod*(X[4]+y+1))%mod;
	}
	return ret*s.f*t.f;
}
int main()
{
	for(int i=1;i<=6;i++) scanf("%d",&X[i]);
	for(int i=1;i<=6;i++) scanf("%d",&Y[i]);
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod,inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<maxn;i++) inv[i]=1ll*inv[i]*inv[i-1]%mod;
	p[1]=(node){X[1]-1,Y[1]-1,1},p[2]=(node){X[1]-1,Y[2],-1},p[3]=(node){X[2],Y[1]-1,-1},p[4]=(node){X[2],Y[2],1};
	p[5]=(node){X[6]+1,Y[6]+1,1},p[6]=(node){X[6]+1,Y[5],-1},p[7]=(node){X[5],Y[6]+1,-1},p[8]=(node){X[5],Y[5],1};
	for(int i=1;i<=4;i++) for(int j=5;j<=8;j++) ans=(ans+solve(p[i],p[j]))%mod;
	printf("%d\n",(ans+mod)%mod);
}

Measured memory_bytes: 16000
import numpy as np
H, W, D = map(int, input().split())
grid = np.array([[0, 0]] * (H * W))
for i in range(H):
    Ai = list(map(int, input().split()))
    for j in range(W):
        grid[Ai[j] - 1] = [i, j]
Q = int(input())
tasks = [list(map(int, input().split())) for _ in range(Q)]

accum = [0] * (H*W)
for i in range(H * W):
    if i >= D:
        accum[i] = accum[i - D] + abs(grid[i][0] - grid[i - D][0]) + abs(grid[i][1] - grid[i - D][1])

for q in range(Q):
    Li, Ri = tasks[q]
    print(accum[Ri - 1] - accum[Li - 1])


Measured memory_bytes: 39920
l = input()
M = 10**9+7
n = len(l)
ans = 1
dp = [1]
for i in range(n):
    ans*=3
    ans%=M
    dp.append(dp[i]*3%M)
cnt = 1
t = 0
for i in range(n):
    if l[i]=='1':
        cnt*=2
        cnt%=M
    if l[i]=='0':
        t=cnt*2*dp[n-i-1]
        t%=M
        ans+=(M-t)
        ans%=M
print(ans)

Measured memory_bytes: 46448
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2330&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(){
    ll res = 0;
    ll N; cin >> N;
    res = ceil(log(N)/log(3));
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    FOR(b, N + 1, 1) {
        if (b <= K)
            continue;
        for (ll i = b; i <= N + b; i += b) {
            ll l = std::max(1LL, K + i - b);
            if (l > N)
                break;
            ll r = std::min(N, b - 1 + i - b);
            ans += r - l + 1;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using llong = long long;
#define REP(I, N) for (std::decay_t<decltype(N)> I = 0, I##_LEN = (N); I < I##_LEN; ++I)


const int MOD = 1000000007;

constexpr int N_MAX = 100;
int a[N_MAX];
llong dp[N_MAX][210];

void solve() {
    int N;  // 1 <= N <= 100
    cin >> N;
    REP (i, N) {
        cin >> a[i];    // -100 <= a[i] <= 100
    }

    // 整数xを整数yに書き換えるとき、コストが(x - y)^2かかる
    // 必要なコストの総和の最小値

    // i番目までの数字を使う
    // jに書き換えたときの必要なコストの総和. ただし、添字jはa[i]+100とする
    // dp[0][j] = 0;    // 一つも数字を使わないとき
    // iをjに書き換えるときのコスト = pow (a[i] - (j-100), 2)   

    // 全探索をしてもたかだか100*200程度

    REP (i, N) {
        REP (j, 201) {
            dp[i+1][j] = pow(a[i] - (j-100), 2) + dp[i][j];
        }
    }

    llong ans = 1000000007;
    REP (j, 201) {
        ans = min(dp[N][j], ans);
    }

    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    solve();
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int r[SIZE],dd[242][242];
int main(){
    DRIII(N,M,R);
    REP(i,N)REP(j,N){
        if(i!=j)dd[i][j]=MOD;
    }
    REP(i,R){
        RI(r[i]);
        r[i]-=1;
    }
    REP(i,M){
        DRIII(x,y,v);
        x--;y--;
        dd[x][y]=dd[y][x]=v;
    }
    REP(k,N)REP(i,N)REP(j,N)dd[i][j]=min(dd[i][j],dd[i][k]+dd[k][j]);
    int an=MOD;
    sort(r,r+R);
    do{
        int now=0;
        REPP(i,1,R){
            now+=dd[r[i-1]][r[i]];
        }
        an=min(an,now);
    }while(next_permutation(r,r+R));
    printf("%d\n",an);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

int main(){
    ll k,a,b;
    cin>>k>>a>>b;
    if(a+1>=b||1+k<a){
        cout<<1+k<<endl;
        return 0;
    }
    ll ans=1;
    ans+=a-1;
    k-=a-1;
    if(k&1)ans++;
    ans+=(k/2)*(b-a);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int n = scan.nextInt();
        int a[] = new int[n];
        
        int cnt = 0;
        int check_same = 0;
        int max_num = -101;
        boolean isAllsame = true;
        
        int about_ave = 0;
        int min_cost = Integer.MAX_VALUE;
        
        for(int i = 0 ; i < n ; i++){
          a[i] = scan.nextInt();
          
          if(i == 0)check_same = a[i];
          else{
            if(check_same != a[i])isAllsame = false;
          }
          
          about_ave += a[i];
          
          if( max_num < a[i] )max_num =a[i];
        }
        
        about_ave /= n;
        
        for( int j = about_ave ; j < max_num ; j++ ){
          int tmp_cost = 0;
          
          for( int i = 0 ; i < n ; i++ ){
            tmp_cost += (a[i] - j) * (a[i] - j);
          }
          //System.out.println("!"+ tmp_cost);
          
          if(tmp_cost < min_cost)min_cost = tmp_cost;
        }
        
        if( isAllsame )
          cnt = 0;
        else
          cnt = min_cost;
        
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

int main(){
    int n; cin >> n;
    map<string, int> mp;
    rep(i,n){
        string s; cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int main()
{
	// freopen("input.in", "r", stdin);

	int n; scanf("%d", &n);
	int curr = 1;
	for(int i = 1; i <= n; i++)
	{
		int x; scanf("%d", &x);
		if(curr == x) curr++;
	}
	printf("%d\n", (curr == 1)? -1 : n-curr+1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int S = 1 << 21;
char p0[S],*p1,*p2;
#ifndef ZXY
#define getchar() (p2 == p1 && (p2 = (p1 = p0) + fread(p0,1,S,stdin)) == p1 ? EOF : *p1++)
#endif
inline int read() {
	static int x,c;x = 0;
	do{c = getchar();}while(!isdigit(c));
	do{x = (x << 3) + (x << 1) + (c & 15);c = getchar();}while(isdigit(c));
	return x;
}
int a,b,c,k,ans;
int main() {
	cin >> a >> b >> c >> k;
	while(a >= b) b <<= 1,++ans;
	while(b >= c) c <<= 1,++ans;
	if(ans <= k) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

int main(){
  ll n,k; cin >> n >> k; vl cost(n); vl dp(n,INT_MAX);
  dp[0] = 0;
  
  rep(i,n) cin >> cost[i];
  
  for(ll i=0; i < n; i++){
    for(ll j=1; j <= k; j++){
      if(i+j < n){
        dp[i+j] = min(dp[i+j],dp[i]+abs(cost[i]-cost[i+j]));
      }
    }
  }
  
  
  cout << dp[n-1] << endl;
  
  
}
    


Measured memory_bytes: 4776
#line 1 "F.cpp"
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

#line 1 "~/git/library/utility/literals.cpp"



/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#include <cstddef>
#line 11 "~/git/library/utility/literals.cpp"

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }


#line 1 "~/git/library/utility/make/vector.cpp"
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */

#ifndef H_make_vector
#define H_make_vector

#line 10 "~/git/library/utility/make/vector.cpp"
#include <type_traits>
#line 12 "~/git/library/utility/make/vector.cpp"

namespace detail {
  template <typename Tp, size_t Nb>
  auto make_vector(std::vector<size_t>& sizes, Tp const& x) {
    if constexpr (Nb == 1) {
      return std::vector(sizes[0], x);
    } else {
      size_t size = sizes[Nb-1];
      sizes.pop_back();
      return std::vector(size, make_vector<Tp, Nb-1>(sizes, x));
    }
  }
}  // detail::

template <typename Tp, size_t Nb>
auto make_vector(size_t const(&sizes)[Nb], Tp const& x = Tp()) {
  std::vector<size_t> s(Nb);
  for (size_t i = 0; i < Nb; ++i) s[i] = sizes[Nb-i-1];
  return detail::make_vector<Tp, Nb>(s, x);
}

#endif  /* !defined(H_make_vector) */
#line 8 "F.cpp"

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<intmax_t> a(n);
  for (auto& ai: a) scanf("%jd", &ai);

  intmax_t const inf = -1e17;
  auto dp = make_vector({n+1, 3_zu}, inf);
  // dp[0][0] = 0;
  dp[1][0] = a[0];
  dp[2][1] = a[1];
  if (n >= 3) dp[3][2] = a[2];

  for (size_t i = 1; i < n; ++i) {
    for (size_t j = 0; j <= 2; ++j) {
      dp[i+1][j] = std::max(dp[i+1][j], dp[i-1][j] + a[i]);
      if (i-2 < n && j < 2) {
        dp[i+1][j+1] = std::max(dp[i+1][j+1], dp[i-2][j] + a[i]);
      }
      if (i-3 < n && j < 1) {
        dp[i+1][j+2] = std::max(dp[i+1][j+2], dp[i-3][j] + a[i]);
      }
    }
  }

  if (n % 2 == 0) {
    printf("%jd\n", std::max({dp[n][1], dp[n-1][0]}));
  } else {
    printf("%jd\n", std::max({dp[n][2], dp[n-1][1], dp[n-2][0]}));
  }
}


Measured memory_bytes: 15180
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int a, b;
   cin >> a >> b;
   cout << (a + b + 1) / 2 << endl;
   return 0;
}

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

#define ll long long
using namespace std;

const ll INF = 1e11;
ll n, m, l, q;
ll graph[311][311];
ll graph2[311][311];
ll st[300*300+1][2];
ll abc[300*300+1][3];


void input(){
  cin>>n>>m>>l;
  for(int i=0;i<m;i++){cin>>abc[i][0]>>abc[i][1]>>abc[i][2];}
  cin>>q;
  for(int i=0;i<q;i++){cin>>st[i][0]>>st[i][1];}
}

int main(){
  input();

  for(int i=0; i<=n; i++){
    for(int j=0; j<=n; j++){
      graph[i][j]=INF;
      graph2[i][j]=INF;
    }
    graph[i][i]=0;
    graph2[i][i]=0;
  }

  for(int i=0; i<m; i++){
    graph[abc[i][0]][abc[i][1]] = abc[i][2];
    graph[abc[i][1]][abc[i][0]] = abc[i][2];
  }

  for(int k=0; k<=n; k++){
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
        if (graph[i][j] > graph[i][k] + graph[k][j]){graph[i][j] = graph[i][k] + graph[k][j];}
      }
    }
  }

  for(int i=0; i<=n; i++){
    for(int j=0; j<=n; j++){
      if(graph[i][j] <= l){graph2[i][j] = 1;}
    }
  }

  for(int k=0; k<=n; k++){
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
        if (graph2[i][j] > graph2[i][k] + graph2[k][j]){graph2[i][j] = graph2[i][k] + graph2[k][j];}
      }
    }
  }

  for(int i=0; i<q; i++){
    ll result = graph2[st[i][0]][st[i][1]]==(INF) ? -1 : graph2[st[i][0]][st[i][1]]-1;
    cout <<result << endl;
  }

 return 0;
}

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

typedef long long lint;

int main(){
    lint N,M;
    cin >> N >> M;
    vector<lint> edge[100001];
    for(int i=1;i<=M;i++){
        lint a,b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    bool checked[100001];
    for(int i=1;i<=N;i++) checked[i]=false;

    vector<lint> path;
    path.push_back(1);
    path.push_back(edge[1].back());
    checked[1]=checked[edge[1].back()]=true;
    
    bool b=true,e=true;
    while(b){
        b=false;
        for(lint x:edge[path.front()]){
            if(checked[x]) continue;
            path.insert(path.begin(),x);
            checked[x]=true;
            b=true;
            break;
        }
    }
    while(e){
        e=false;
        for(lint x:edge[path.back()]){
            if(checked[x]) continue;
            path.push_back(x);
            checked[x]=true;
            e=true;
            break;
        }
    }

    cout << path.size() << endl;
    for(int i=0;i<path.size();i++){
        cout << path[i];
        if(i==path.size()-1) cout << endl;
        else cout << ' ';
    }

    return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    int n = 5;
    vi t = { a, b, c, d, e }, nt(n);
    rep(i, n) {
        nt[i] = (t[i] + 9) / 10 * 10;
    }
    int ans = INF;
    rep(i, n) {
        int cnt = 0;
        rep(j, n) {
            if (j == i) cnt += t[j];
            else cnt += nt[j];
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	static int[] D=new int[101];
	static int n;
    static int[][] v=new int [101][101];
	static void bfs(int src) {
    	Queue<Integer>	Q=new ArrayDeque<Integer>();
    	Q.add(src);
    	D[src]=0;
    	while(! Q.isEmpty()) {
    		int cur = Q.remove();//先頭要素を取り出す
    		for(int i=2; i<=n;i++) {//各行先に対して
    			if(D[i]==0 && v[cur][i]>0) {//未訪問で、curから辺があるなら
    				D[i] = D[cur]+1;
    				Q.add(i);//行き先を訪問先に加える
    			}
    		}
    	}
    }
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        v=new int [101][101];
        for(int i=1; i<=n; i++) {
        	int u=sc.nextInt();
        	int k=sc.nextInt();
        	for(int j=1; j<=k; j++) {
        		int a=sc.nextInt();
        		v[u][a]++;
        	}
        }
        bfs(1);
        for(int i= 1; i<=n; i++) {
        	if(i != 1 && D[i]==0)	System.out.println(i + " "+-1);
        	else	System.out.println(i + " " + D[i]);
        }
        
        
        
        
	}
}


Measured memory_bytes: 27980
#include<stdio.h>

#define INFTY 2097152
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,A[100][100];

void dik(){
  int mincost,u,i,v,iro[100],d[100],p[100];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    iro[i]=WHITE;
  }
  d[0]=0;
  iro[0]=GRAY;
  while(1){
    mincost=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(iro[i]!=BLACK&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(u==-1)break;
    iro[u]=BLACK;
    for(v=0;v<n;v++){
      if(iro[v]!=BLACK&&A[u][v]!=INFTY){
	if(d[u]+A[u][v]<d[v]){
	  d[v]=d[u]+A[u][v];
	  iro[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,(d[i]==INFTY ? -1: d[i]));
  }
}
int main(){
  int i,j,a,b,c,d;
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)A[i][j]=INFTY;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    for(j=0;j<b;j++){
      scanf("%d %d",&c,&d);
      A[a][c]=d;
    }
  }

  dik();
  
  return 0;
}



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


int main(){
   ll a,b,c;
   scanf("%lld%lld%lld",&a,&b,&c);
   a=abs(a);
   ll l=(ll)floor(a*1.0/c);
   if(a*1.0/c>b){
    printf("%lld",a-b*c);
   }else{
       ll res=1e18;
        if(l%2==b%2){
            res=min(res,abs(a-l*c));
            if(l+2<=b)
            res=min(res,abs(a-(l+2)*c));
            if(l-2<=b&&l-2>=0)
            res=min(res,abs(a-(l-2)*c));
        }else{
            if(l+1<=b)
            res=min(res,abs(a-(l+1)*c));
            if(l-1<=b&&l-1>=0)
            res=min(res,abs(a-(l-1)*c));
        }
        printf("%lld",res);
   }
    return 0;
}



Measured memory_bytes: 3808