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

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    cin >> a[0];
    int c = 0;
    while(a[0] % 2 == 0){
        a[0] /= 2;
        c++;
    }
    bool flag = true;
    for(int i=1; i<n; i++){
        cin >> a[i];
        if(a[i] % (1LL<<c) != 0 || (a[i] / (1LL<<c)) % 2 == 0){
            flag = false;
        }
        a[i] /= (1LL<<c);
    }

    if(!flag){
        cout << 0 << endl;
        return 0;
    }

    int lcm = a[0];
    for(int i=1; i<n; i++){
        lcm = lcm / gcd(lcm, a[i]) * a[i];
        if(lcm * (1LL<<(c-1)) > m){
            cout << 0 << endl;
            return 0;
        }
    }
    lcm *= (1LL<<(c-1));

    cout << (m+lcm)/lcm/2 << endl;

    return 0;
}

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

int main(){
  int N;
  double T, A;
  cin >> N;
  cin >> T >> A;
  double H;
  double temp = 1000;
  int pos;
  for(int i = 1; i <= N; i++){
    cin >> H;
    if(abs(T-0.006*H-A) < temp){
      pos = i;
      temp = abs(T-0.006*H-A);
    }
  }
  cout << pos << endl;
  return 0;
}


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

int main(){
  long long int N,ans=0,i;
  cin>>N;
  for(i=1; i*(i+1)<N; ++i){
    if(N%i==0) ans+=N/i-1;
  }
  cout<<ans;
  return 0;
}

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

vector<int> adj[200005];
int vis[200005];
int cnt = 0;

void dfs(int v)
{
    cnt++;
    vis[v] = 1;
    for (auto u : adj[v])
    {
        if (!vis[u])
            dfs(u);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int p, q;
        cin >> p >> q;
        adj[p].push_back(q), adj[q].push_back(p);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (vis[i])
            continue;
        dfs(i);
        ans = max(cnt, ans);
        cnt = 0;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 21560
N = int(input())
L = list(map(int, input().split()))
L.sort()
c = 0
for a in range(N):
	
	if a == 0:
		c = c + int(L[0]) / pow(2, N - 1)# (2**(N-1))
	else:
		c = c + int(L[a]) / pow(2, N - a)#(2**(N-a))
print(c)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
long ceil(long N,long x) {
  if(N%x!=0) x=N/x+1;
  else x=N/x;
  return x;
}
 
int main() {
  long N,A,B,C,D,E;
  cin >>N>> A>>B>>C>>D>>E;
  
  
  cout <<ceil(N,min({A,B,C,D,E}))+4 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    vector<tuple<string, size_t, size_t>> rs;
    rs.reserve(n);
    for (size_t i = 0; i < n; ++i) {
        string s;
        size_t v;
        cin >> s >> v;
        rs.emplace_back(std::move(s), v, i);
    }
    sort(rs.begin(), rs.end(), [](const auto& l, const auto& r) {
        return get<0>(l) < get<0>(r) || get<0>(l) == get<0>(r) && get<1>(r) < get<1>(l);
    });
    for (const auto& elem : rs)
        cout << get<2>(elem) + 1 << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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 (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int MOD = 1000000007;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
    int N;
    cin >> N;
    vvi a(N+1, vi(3, 0));
    reps(i, N) {
        rep(j, 3) {
            cin >> a[i][j];
        }
    }
    vvi dp(N+1, vi(3, 0));
    reps(i, N) {
        rep(j, 3) {
            // jは今日やること
            rep(k, 3) {
                // kは前日にやったこと
                if (j != k) {
                    chmax(dp[i][j], dp[i-1][k] + a[i][j]);
                }
            }
        }
    }
    int ans = 0;
    rep(i, 3) {
        chmax(ans, dp[N][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int v[] = new int[N];
        double temp;

        for (int i = 0;i < N; i++){
            v[i] = scanner.nextInt();
        }

        Arrays.sort(v);
        temp = v[0];
        
        for (int i = 1;i < N;i++){
            temp = (temp + v[i])/2;
        }

        System.out.println(temp);
    }
}

Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(1000000)
n=int(input())
graph=[[] for i in range(n)]
color=[-1]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    graph[a-1].append([b-1,c%2])
    graph[b-1].append([a-1,c%2])
def coloring(pre,c):
  color[pre]=c
  for i,j in graph[pre]:
    if color[i]<0:
      coloring(i,color[pre]^j)
coloring(0,1)
for i in color:
  print(i)


Measured memory_bytes: 155296
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;


int main (int argc, char const *argv[])
{
    int X;
    cin>>X;

    
    if (X==7||X==5||X==3) {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
  int N,M,K;
  cin >> N >> M >> K;
  
  bool can = false;
  
  for(int i=0;i<=N;i++){
    for(int j=0;j<=M;j++){
      if(i * M + (N - i * 2) * j == K) can = true;
    }
  }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define mod 1000000007
using namespace std;
int H, W;
char mat[1002][1002];
int dp[1002][1002];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W;
    for(int i = 1; i <= H; ++i)
        cin >> (mat[i] + 1); // 1 index string reading
    dp[1][1] = 1;
    for(int i = 1; i <= H; ++i)
        for(int j = 1; j <= W; ++j)
        {
            if(mat[i][j] == '#') // we can't go to walls
                continue;
            if(i == 1 && j == 1) // the base case
                continue;
            dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
        }
    cout << dp[H][W] << '\n';
    return 0;
}


Measured memory_bytes: 5120
import random
import time
start=time.time()
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
hh.sort(reverse=1)
t=hh[0][0]
hhh=[]
for x,i in hh:
  if x==t:hhh.append((x,i))
ans=[]
random.shuffle(w)
for j in w:
  for x,i in hhh:
    if (i,j) in hw:
      ans.append(s+x-1)
    else:
      exit(print(s+x))
  if time.time()-start>=1.7:
    m=ans[0]
    if h-1000<=len(hhh)<=h-random.randint(10,1000):m+=1
    exit(print(m))
print(ans[0])

Measured memory_bytes: 187864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    ll N;
    cin >> N;
    vll H(N), M(N);
    for(auto &a:H) cin >> a;
    ll ans = 0;
    partial_sum(
        H.begin(),
        H.end(),
        M.begin(),
        [](ll a, ll b) {
            return max(a, b);
        }
    );
    for(int i = 0; i < N; i++) {
        if(H[i]-M[i] >= 0) ans++;
    }
    cout << ans << endl;
}

int main() {
    FIO;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

//struct position{int x;};

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

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


Measured memory_bytes: 384
#include <stdio.h>

int neighbors[105][105];
int nSucc[105];

int main() {
  int n, curQ = 0, d, i, j, dump, index;
  memset(neighbors, 0, sizeof(neighbors));
  memset(nSucc, 0, sizeof(nSucc));

  scanf("%d", &n);

  for (i = 1; i < n+1; i++) {
    scanf("%d %d", &dump, &nSucc[i]);
    for (j = 0; j < nSucc[i]; j++) {
      scanf("%d", &neighbors[i][j]);
    }
  }

  int qlen[2];
  int q[2][105];

  memset(qlen, 0, sizeof(qlen));

  q[0][0] = 1;
  qlen[0]++;

  int mind[105];
  for (i = 0; i < 105; i++) {
    mind[i] = 10000;
  }
  mind[1] = 0;

  for (d = 1; qlen[curQ] > 0; d++) {
    for (i = 0; i < qlen[curQ]; i++) {
      index = q[curQ][i];
      for (j = 0; j < nSucc[index]; j++) {
        if (d < mind[neighbors[index][j]]) {
          mind[neighbors[index][j]] = d;
          q[1-curQ][qlen[1-curQ]++] = neighbors[index][j];
        }
      }
    }
    qlen[curQ] = 0;
    curQ = 1 - curQ;
  }
 for (i = 1; i < n+1; i++) {
    if (mind[i] == 10000)
      printf("%d %d\n", i, -1);
    else
      printf("%d %d\n", i, mind[i]);
  }
}



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

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = sum(B)

for i in range(N-1):
	if A[i] + 1 == A[i + 1]:
		ans += C[A[i]-1]

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main() {
	int k, x;
	scanf("%d%d", &k, &x);
	for (int i = k - 1; i >= 0; i--) {
		printf("%d ", x - i);
	}
	for (int i = 1; i < k; i++) {
		printf("%d ", x + i);
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,m,k,x,y,a[100001],ans=0;
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
      cin>>n;
      for(long long int i=1;i<=n;i++)
      {
         cin>>a[i];
         if(a[i]%2!=0 && i%2!=0)
            ans++;
      }
      cout<<ans<<endl;
   return 0;
}


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

using namespace std;

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

#define EACH(i, a) for(auto&& i:a)
#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for(ll i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(v) (v).begin(),(v).end()

const ll linf = 1e18;
const ll inf = 1e9;

template<class T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}

ll lastid = 0;
struct Employee {
    string name;
    ll val;
    ll id;
};
bool operator<(const Employee& e1, const Employee& e2) {
    return P(e1.val, e1.id) < P(e2.val, e2.id);
}
struct Log {
    string name;
    string text;
};

set<Employee> s1, s2;
map<string, Employee> m;

set<string> nw, pw;
void output_log(string name) {
    vector<Log> log;
    EACH(name, nw) {
        log.pb({name, name+" is not working now."});
    }
    EACH(name, pw) {
        log.pb({name, name+" is working hard now."});
    }
    EACH(l, log) {
        if (l.name == name) {
            cout << l.text << endl;
        }
    }
    EACH(l, log) {
        if (l.name != name) {
            cout << l.text << endl;
        }
    }
    pw.clear();
    nw.clear();
}
void check() {
    int n = s1.size() + s2.size();
    int hardcnt = n/5;
    while (s1.size() > hardcnt) {
        nw.insert(s1.begin()->name);
        s2.insert(*s1.begin());
        s1.erase(s1.begin());
    }
    while (s1.size() < hardcnt) {
        auto it = s2.end();
        assert(it != s2.begin());
        --it;
        pw.insert(it->name);
        s1.insert(*it);
        s2.erase(it);
    }
    if (s1.size() > 0 && s2.size() > 0) {
        assert(*prev(s2.end(), 1) < *s1.begin());
    }
}
void add_employee(Employee& e) {
    e.id = lastid++;
    if ( s1.size() > 0 && *s1.begin() < e ) {
        s1.insert(e);
    }
    else {
        s2.insert(e);
    }
    m[e.name] = e;
    check();
}
void remove_employee(string name) {
    if ( s1.count(m[name]) > 0 ) {
        s1.erase(m[name]);
    }
    else {
        s2.erase(m[name]);
    }
    check();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    set<int> s;
    REP(i, n) {
        Employee e;
        cin >> e.name >> e.val;
        add_employee(e);
    }
    check();
    pw.clear(); nw.clear();
    int m; cin >> m;
    REP(t, m) {
        string q; cin >> q;
        string name;
        if (q == "+") {
            Employee e; cin >> e.name >> e.val;
            add_employee(e);
            if ( s1.count(e) > 0 ) {
                pw.insert(e.name);
            }
            else {
                nw.insert(e.name);
            }
            name = e.name;
        }
        else {
            cin >> name;
            remove_employee(name);
        }
        output_log(name);
    }
}

Measured memory_bytes: 13560
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    int aIndex = 1;
    int bIndex = 0;
    int cIndex = 0;
    char tmp = a.charAt(0);
    while(true){
      switch(tmp){
        case 'a':
          if(a.length() == aIndex){
            System.out.println("A");
            System.exit(0);
          }
          tmp = a.charAt(aIndex++);
          break;
          
        case 'b':
          if(b.length() == bIndex){
            System.out.println("B");
            System.exit(0);
          }
          tmp = b.charAt(bIndex++);
          break;
          
        case 'c':
          if(c.length() == cIndex){
            System.out.println("C");
            System.exit(0);
          }
          tmp = c.charAt(cIndex++);
          break;
      }
    }
  }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int n, m;
	bool can = true;
	string s, t;
	cin >> n >> m >> s >> t;
	int turn = __gcd(s.size(), t.size());
	for (int i = 0; i < turn; i++) {
		can &= (s[s.size() / turn * i] == t[t.size() / turn * i]);
	}
	if (can == false) {
		cout << -1 << endl;
		return 0;
	}
	cout << s.size() * t.size() / turn << endl;
}
/*
a c b e w r (2)
a b e w

a c b e w r (2)
a  b  e  w

*/

Measured memory_bytes: 3744
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
ab = []
edges = [[]for _ in range(n)]
for _ in range(n-1):
    a, b = list(map(lambda x: int(x)-1, input().split()))
    edges[a].append(b)
    edges[b].append(a)
    ab.append((a, b))

colors = defaultdict(int)


def dfs(v, parent):
    palette = [i for i in range(len(edges[v])+1, 0, -1)
               if i != colors[(parent, v)]]
    for v2 in edges[v]:
        if v2 == parent:
            continue
        color = palette.pop()
        colors[(v2, v)] = color
        colors[(v, v2)] = color
        dfs(v2, v)

dfs(0, -1)

print(max(colors.values()))
for a, b in ab:
    print(colors[(a, b)])


Measured memory_bytes: 106792
#include<iostream>
#include<cstdio>
using namespace std;
int T,a,b,k,n;
int main()
{
	cin>>k>>a>>b;
	while(true) {
		if(n>=a&&n<=b) T=1;
		n+=k;
		if(n>b) break;
	}
	if(T) puts("OK");
	else puts("NG");
}

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

int main(){
  int  H,W,M;
  cin>>H>>W>>M;
  int AH[300100]={};
  int AW[300100]={};
  int ans=0;
  int h,w;
  set<pair<int,int>>s;
  for(int i=0;i<M;i++){
    cin>>h>>w;
    AH[h]++;
    AW[w]++;
    s.insert({h,w});  
  }
  vector<int>hp,wp;
  int maxh=0;
  int maxw=0;
  for(int i=1;i<=H;i++){
    if(AH[i]>=maxh){
      maxh=AH[i];
    }
  }
  for(int i=1;i<=H;i++){
    if(AH[i]==maxh){
      //cout<<"h"<<i<<endl;
      hp.push_back(i);
    }
  }
  for(int i=1;i<=W;i++){
    if(AW[i]>=maxw){
      maxw=AW[i];
    }
  }   
  for(int i=1;i<=W;i++){
      //cout<<"$"<<i<<" "<<AW[i]<<endl;
    if(AW[i]==maxw){
      //cout<<"w"<<i<<endl;
      wp.push_back(i);
    }
  }
  //cout<<"maxh"<<maxh<<"maxw"<<maxw<<endl;
  //cout<<hp.size()<<" "<<wp.size()<<endl;
  ans=maxh+maxw;
  

  int flag=1;
  for(auto it = hp.begin();it != hp.end();it++){
    for(auto it2 = wp.begin();it2 != wp.end();it2++){
      //cout<<*it<<" "<<*it2<<endl;
      if(s.find({*it,*it2}) != s.end()){
        continue;
      }
      else{
        flag=0;
        break;
      }
    }
    if(flag==0) break;
  }

  if(flag){
    cout<<ans-1<<endl;
  }
  else{
    cout<<ans<<endl;
  }
  return 0;    
}


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

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int> B(N - 1);
	for(auto &x: B) cin >> x;

	//先頭
	int sum = B[0];
	for(int i = 1; i < N - 1; i++) {
		sum += min(B[i - 1], B[i]);
	}
	//末尾
	sum += B[N - 2];
	cout << sum << endl;
}


Measured memory_bytes: 256
def main():
    from collections import defaultdict
    from heapq import heappush, heappop
    _, m, *ab = map(int, open(0).read().split())
    works = defaultdict(list)
    for a, b in zip(*[iter(ab)]*2):
        works[a].append(-b)

    candidates, pay = [], 0
    for day in range(1, m+1):
        if day in works:
            for x in works[day]:
                heappush(candidates, x)
        if candidates:
            pay += heappop(candidates)
    print(-pay)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32688
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

	VAR(int, k);

	int p = k / 50, q = k % 50;
	vector< int > ans(50, 50 + p - q - 1);
	REP(i, q) {
		ans[i] += 51;
	}
	OUT(50)BR;
	REP(i, 50) {
		OUT(ans[i]);
		if (i < 49) SP
			else BR
	}
	
  
  return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const ll INF = 1e18;

const int N = 20;

ll a[N];
int n;

ll ans = INF;

ll vv[N];


void run(int sz, int x) {
	if (x == n - 1) {
		ll cur = a[n - 1];
		ll ad = 0;
		while (sz > 1) {
			ll tmp = vv[sz - 1] + ad;
			cur += tmp;
			sz -= 1;
			ad = tmp;
		}
		ans = min(ans, vv[0] + ad + cur);
		return;
	}
	ll cur = a[x];
	ll ad = 0;
	while (sz) {
		ll sav1 = vv[sz];
		vv[sz] = cur;
		vv[sz - 1] += ad;
		run(sz + 1, x + 1);
		vv[sz - 1] -= ad;
		vv[sz] = sav1;
		--sz;
		cur += vv[sz] + ad;
		ad += vv[sz];
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n;
	for (int i = 0; i < n; ++i)
	cin >> a[i];
	vv[0] = a[0];
	run(1, 1);
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {unsigned long long int Q,H,S,D,N;
  cin >> Q >> H >> S >> D >>N;
 unsigned long long int ans;
  if(8*Q<=4*H && 8*Q<=2*S && 8*Q <=D)
  {ans=4*Q*N;}
  else if (4*H<=2*S && 4*H<=D)
  {ans=2*H*N;}
  else if (2*S<=D)
  {ans=S*N;}
  
  else{
    if(N%2==0)
    {ans=N*D/2;}
    else {
      if(8*Q<=4*H && 8*Q<=2*S)
      {ans = (N-1)/2*D + 4*Q;}
      else if(4*H<=2*S)
      {ans = (N-1)/2*D + 2*H;}
      else
      {ans = (N-1)/2*D + S;}
    }
  }
    cout << ans << endl;
}

Measured memory_bytes: 256
h1, m1, h2, m2, k = map(int, input().split())
h = (h2 - h1) % 24
if m2 >= m1:
    res = h*60 + (m2 - m1)
else:
    res = (h-1)*60 + (m2 - m1 + 60)

print(res - k)


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




int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    vector < pair < int, int > > ans;
    if(n % 2 == 0){
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                if(i + j != n + 1){
                    ans.push_back(make_pair(i, j));
                }
            }
        }
    }
    else{
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                if(i + j != n){
                    ans.push_back(make_pair(i, j));
                }
            }
        }
    }
    cout << (int)ans.size() << "\n";
    for(auto it : ans){
        cout << it.first << " " << it.second << "\n";
    }
}


Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).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;;) => {
        {
            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;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn nessesary(vs: &[usize], k: usize, skip: usize) -> bool {
    let n = vs.len();

    let mut dp = vec![vec![false; k]; n];
    dp[0][0] = true;
    for (i, &v) in vs
        .iter()
        .enumerate()
        .filter(|&(i, _)| i != skip)
        .map(|(_, v)| v)
        .enumerate()
    {
        for j in 0..dp[i].len() {
            if j >= v {
                dp[i + 1][j] |= dp[i][j - v];
            }
            dp[i + 1][j] |= dp[i][j]
        }
    }

    dp[n - 1]
        .iter()
        .enumerate()
        .any(|(i, &v)| vs[skip] >= k || (k - vs[skip] <= i && i < k && v))
}

fn main() {
    let (_, k) = scan!(usize, usize);
    let mut vs = scan!(usize;;);
    vs.sort();

    let (mut left, mut right) = (0, vs.len() + 1);
    while left + 1 < right {
        let mid = (left + right) / 2;
        if nessesary(&vs, k, mid - 1) {
            right = mid;
        } else {
            left = mid;
        }
    }

    println!("{}", left);
}


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

#define ll long long

#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    int a,b; cin>>a>>b;
    int ans = a+b;
  	if(ans<(a-b)) ans =a-b;
  	if(ans<(a*b)) ans =a*b;
    
    printf("%d\n",ans);
    return 0;  
}

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

int main(void){
  int64_t N,M;
  cin >> N >> M;
  
  int64_t sum1 = 0;
  if(N<2){
    sum1 = 0;
  } else if(N==2){
    sum1 = 1;
  } else {
    sum1 = N * (N-1) / 2;
  }
  
  int64_t sum2 = 0;
  if(M<2){
    sum2 = 0;
  } else if(M==2){
    sum2 = 1;
  } else {
    sum2 = M * (M-1)/ 2;
  }

  cout << sum1+sum2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 998244353;
const int N = 333;

int sz, ones[N], dp[N][N][N], cum[N];

void add(int &x, int y) {
    x += y;
    if (x >= MOD) x -= MOD;
}

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

    string s; int k; 
    cin >> s >> k;
    int n = si(s);
    k = min(k, n+2);
    s += '0';
    {
        int cnt = 0;
        for (auto c : s) {
            if (c == '0') {
                ones[sz++] = cnt;
                cnt = 0;
            }
            else cnt++;
        }
    }

    for (int from = 0; from < sz; from++) {
        for (int used = 0; used <= k; used++) {
            if (from ) forn(i,n+1) {
                cum[i] = dp[from-1][i][used];
                if (i) add(cum[i], cum[i-1]);
            }
            for (int extra = 0; extra <= n; extra++) {
                if (from == 0) {
                    dp[from][extra][used] = used <= k;
                }
                else {
                    int have = ones[from] + extra;
                    add(dp[from][extra][used], cum[extra]);
                    for (int more = 1; more <= ones[from]; more++) {
                        add(dp[from][extra][used], dp[from-1][extra+more][used+more]);
                    }
                }
            }
        }
    }
    cout << dp[sz-1][0][0] << endl;

    return 0;
}


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

 



int main() {
	int N, X;
	cin >> N >> X;
	if (500 * N >= X) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ull = unsigned long long int;
using ll = long long;

int main() {
    bool x;
    cin >> x;
    cout << int(!x) << endl;
    return 0;
}

Measured memory_bytes: 3620
input_line = [int(i) for i in input().split()]
n = input_line[0]
a = input_line[1]
b = input_line[2]

x, y = divmod(n, a + b)
i, j = divmod(y, a + 1)

if i > 0:
	print(a * x + a)
else:
    print(a * x + j)


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

int main()
{
   int a,b;
   cin>>a>>b;
   for(int i=1;i<=2e5;i++)
   {
       if(floor(i*0.08)==a&&floor(i*0.1)==b)
       {
           cout<<i<<"\n";
           return 0;
       }
   }
   cout<<-1<<endl;
}


Measured memory_bytes: 256
import math,itertools,bisect,sys,copy,queue
sys.setrecursionlimit(10**7)
INF = 10**20

def LI(): return [int(x) for x in sys.stdin.readline().split()]

N,E = LI()
dp = [[INF for _ in range(N)] for _ in range(N)]
for i in range(N): dp[i][i] = 0
for _ in range(E):
    s,t,d = LI()
    dp[s][t] = d

for k in range(N):
    for i in range(N):
        for j in range(N):
            if dp[i][k] < INF and dp[k][j] < INF:
                dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])

for i in range(N):
    if dp[i][i] < 0:
        print ('NEGATIVE CYCLE')
        exit(0)
for i in range(N):
    for j in range(N):
        print (dp[i][j] if dp[i][j] < INF else 'INF',end='')
        if j < N-1: print (' ',end='')
    print ('')



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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
    string S;
    ll Q;
	cin>>S;
    cin>>Q;
    ll t;
    ll f;
    char c;
    ll flag = 1;
    ll tmp_flag = 1;

    vector<char> front_ls,back_ls;

    rep(i,Q){
        cin>>t;
        if(t==1){
            flag*=-1;
        }else{
            cin>>f;
            cin>>c;
            if(f==1){
                tmp_flag = 1*flag;
            }else{
                tmp_flag = -1*flag;
            }
            if(tmp_flag == 1){
                front_ls.push_back(c);
            }else{
                back_ls.push_back(c);
            }
        }
    }

    if(flag == 1){
        rep(i,front_ls.size()){
            cout<<front_ls[front_ls.size()-1-i];
        }
        cout<<S;
        rep(i,back_ls.size()){
            cout<<back_ls[i];
        }
        cout<<"\n";
    }else{
        rep(i,back_ls.size()){
            cout<<back_ls[back_ls.size()-1-i];
        }
        rep(i,S.size()){
            cout<<S[S.size()-1-i];
        }
        rep(i,front_ls.size()){
            cout<<front_ls[i];
        }
        
        cout<<"\n";
    }
	
	return 0;
}

Measured memory_bytes: 976
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;

int main()
{	
	int a,b,k,tmp;
	scanf("%d %d %d",&a,&b,&k);
	for(int i = 1;i <= k;i++){
		if(i % 2 == 1){
			if(a % 2 == 1) a--;
			b = b + a/2;
			a = a/2;
			}
		if(i % 2 == 0){
			if(b % 2 == 1) b--;
			a = a + b/2;
			b = b/2;
			}
	}
	printf("%d %d",a,b);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=550,M=250250;
int i,j,k,n,m;
int a[N],ans[M],l[M],r[M];
struct cc {
	int x,p;
	bool operator < (const cc &n) const {
		return p<n.p;
	}
} A[N];
int main() {
	scanf("%d",&n);
	m=n*n;
	for (i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		A[i].x=i;
		A[i].p=a[i];
	}
	sort(A+1,A+n+1);
	for (i=1;i<=m;i++) r[i]=i+1,l[i]=i-1;
	r[0]=1;l[m+1]=m;
	for (i=1;i<=n;i++) {
		for (j=r[0],k=1;k<A[i].x;k++,j=r[j]) {
			ans[j]=A[i].x;
			r[l[j]]=r[j];
			l[r[j]]=l[j];
			if (j>=A[i].p) return puts("No"),0;
		}
		ans[A[i].p]=A[i].x;
		r[l[A[i].p]]=r[A[i].p];
		l[r[A[i].p]]=l[A[i].p];
	}
	for (i=n;i;i--) {
		for (j=l[m+1],k=n;k>A[i].x;k--,j=l[j]) {
			ans[j]=A[i].x;
			r[l[j]]=r[j];
			l[r[j]]=l[j];
			if (j<=A[i].p) return puts("No"),0;
		}
	}
	puts("Yes");
	for (i=1;i<=m;i++) printf("%d ",ans[i]);
	puts("");
}

Measured memory_bytes: 3968
#include <iostream>
using namespace std;
bool f(int x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}
int main() {
    int n, a=2;
    cin>>n;
    for(int i=0;i<n;i++){
        while(!f(a)){
            a+=5;
        }
        cout<<a;
        if(i<n-1)cout<<" ";
        a+=5;
    }
    cout<<endl;
	return 0;
}

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

int main() {

  int N, last = 101,ans;
  cin >> N;
  
  vector<int> d(N);
  
  for (int i = 0 ; i < N ; i++)
    cin >> d.at(i);
  
  sort(d.begin(),d.end());  
    
  for (int i = N - 1 ; i >= 0 ; i--){
    if (d.at(i) < last){
      ans ++;
      last = d.at(i);
    }
  }
  
  cout << ans << endl;
    
    
}

Measured memory_bytes: 256
import numpy as np
import itertools

N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

Num = range(1,N+1)

Number = str(''.join(map(str,Num)))


per_num=list(itertools.permutations(Number))
pernum_arr = np.ones(len(per_num))
for i in range(len(per_num)): 
    pernum_arr[i] = int(''.join(map(str,per_num[i])))
P = int(''.join(map(str,P)))
Q = int(''.join(map(str,Q)))

ans = abs(np.where(pernum_arr==P)[0]-np.where(pernum_arr==Q)[0])
print(ans[0])


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

int main() {
    ll l, r;
    cin >> l >> r;

    ll ans = 2017 * 2018 + 1;
    if (r-l < 2019) {
        for (ll i = l; i < r; i++) {
            for (ll j = i+1; j <= r; j++) {
                ans = min(ans, i*j % 2019);
            }
        }
    } else ans = 0;

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


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

#define db(x) cerr << #x << " = " << x << endl;

typedef long long   ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll,  ll  > pll;

const ll   MOD       = 1000000007;
const ll   INF       = 1000000007ll*1000000007ll;
const ll   N         = 1000002;
const ll   logN      = 20;
const ld   PI        = acos(-1);
const ll   HashPrime = 31;

inline void No() {
    cout << "NO\n";
}
inline void Yes() {
    cout << "YES\n";
}

#define fi first
#define se second

void solve() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
        if (i*500+j*100+k*50 == x) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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


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

int main() {

  int N;
  cin >> N;

  string S;
  vector<string> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> S;
    sort(S.begin(),S.end());
    vec.at(i) = S;
  }

  sort(vec.begin(), vec.end());

  long long ans = 0;
  int ctr = 0;

  for (int i = 1; i < N; i++) {
    if (vec.at(i - 1) == vec.at(i)) {
      ctr ++;
      ans += ctr;
    }
    else {
      ctr = 0;
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 5760
let modulo = 1000000007
let (+) a b = (a + b) mod modulo
let ( * ) a b = (a * b) mod modulo
let rec ( ** ) a n =
  if n = 0 then 1
  else if n mod 2 = 1 then a * a ** (n-1)
  else let h = a ** (n/2) in h * h
let inv x = x ** (modulo-2)
let (/) a b = a * inv b

let comb =
  let fact = Array.make 200001 1 in
  let facti = Array.make 200001 1 in
  for i = 1 to 200000 do
    fact.(i) <- i * fact.(i-1);
    facti.(i) <- inv fact.(i)
  done;
  fun n k -> fact.(n) * facti.(k) * facti.(n-k)

let () =
  Scanf.scanf "%d %d %d %d" @@ fun n a b c ->
  let a, b, c = a / (a+b), b / (a+b), c / (100-c) in
  Array.init n (fun i ->
    ((a**n * b**i + a**i * b**n) * comb (n+i-1) (n-1)) * (c+1) * (n+i))
  |> Array.fold_left (+) 0
  |> Printf.printf "%d\n"



Measured memory_bytes: 4736
#include<stdio.h>

int main(void){
	int n;
	int a[100];
	int i, j,count,x;
	scanf("%d", &n);
	for(i = 0;i<n;i++){
		scanf("%d", &a[i]);
	}
	count =0;
	for(i = 0;i<n;i++){
		for(j = n-1;j>i;j--){
			if(a[j]<a[j-1]){
				x = a[j-1];
				a[j-1] = a[j];
				a[j] = x;
				count++;
			}
		}
	}
	for(i = 0;i<n-1;i++){
		
		printf("%d ", a[i]);
	}
	printf("%d\n", a[n-1]);
	printf("%d\n", count);
	
	return 0;


}





Measured memory_bytes: 2040
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		if ((a <= b && b<= a+w) || (a<=b+w && b+w <= a+w)) {
			System.out.println(0);
			return;
		}
		if (a+w < b) {
			System.out.println(b-(a+w));
			return;
		}
		if (b+w < a) {
			System.out.println(a-(b+w));
			return;
		}
		System.out.println(0);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <algorithm>

using namespace std;

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

	if (n % 2 == 1)
	{
		cout << n / 2 + 1 << endl;
	}
	else
	{
		cout << n / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

h,w = mii()
mat = llstr(h)
dp = [[0]*w for i in range(h)]
dp[0][0]=1

for i in range(h):
    for j in range(w):
        if i==0 and j==0:
            continue
        if i==0 and mat[i][j]==".":
            dp[i][j] = dp[i][j-1]
        elif i>0 and mat[i][j]==".":
            if mat[i-1][j]=="#":
                dp[i][j] = dp[i][j-1]
            else:
                dp[i][j] =dp[i][j-1]+dp[i-1][j]
    
print(dp[-1][-1]%(mod))


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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long N,count = 0;
  cin >> N;
  long long sN = N;
  int sw = 0;
  while(sN > 9){
    if(sN % 10 != 9){
		sw = 1;
    }
    count++;
    sN /= 10;
  }
    if(sw == 0){
      cout << sN + count*9 << endl;
    }else{
      cout << sN - 1 + count * 9 << endl;
    }
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    ll n;
    cin >> n;
    if(n==2){
        cout<<1<<endl;
        return 0;
    }
    int ans=2;
    for (ll i = 2; i * i <= n; i++) {
        if(n%i==0){
            ll n2=n;
            while(n2%i==0){
                n2/=i;
            }
            if(n2%i==1)
            ans++;
        }
    }
    for(ll i=2;i*i<=n-1;i++){
        if((n-1)%i==0){
            if(i*i==n-1)
            ans++;
            else
            ans+=2;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(){

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

    int a[m],b[m];

    vector<vector<int>> G(n);

    for(int i=0;i<m;i++){
        cin >> a[i];
        cin >> b[i];
        G[a[i]-1].push_back(b[i]-1);
        G[b[i]-1].push_back(a[i]-1);
    }

    vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    vector<vector<int>> C(n);

    C[0].push_back(0);

    for(int i=1;i<n;i++){
        C[dist[i]].push_back(i);
    }

    int c[n]={};
    int q=0;

    for(int i=1;i<n;i++){
        for(int j=0;j<C[i].size();j++){
            if(i==1)c[C[i][j]]=1;
            else{
                for(int k=0;k<G[C[i][j]].size();k++){
                    for(int l=0;l<C[i-1].size();l++){
                        if(C[i-1][l]==G[C[i][j]][k]){
                            c[C[i][j]]=C[i-1][l]+1;
                            break;    
                        }
                    }
                }
            }
        }
    }

    cout << "Yes" << endl;

    for(int i=1;i<n;i++){
        cout << c[i] << endl;
    }


}

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

ll N, Q, a, q, p, x, l, r;

int main() {
    scanf("%lld%lld", &N, &Q);
    fenwick_tree<ll> fw(N);
    rep(i, N) {
        scanf("%lld", &a);
        fw.add(i, a);
    }
    rep(i, Q) {
        scanf("%lld", &q);
        if (q == 0) {
            scanf("%lld%lld", &p, &x);
            fw.add(p, x);
        } else {
            scanf("%lld%lld", &l, &r);
            printf("%lld\n", fw.sum(l, r));
        }
    }
}

Measured memory_bytes: 8236
<?php
  
while (True) {
  fscanf(STDIN, "%d %d %d", $m, $f, $r);
  $mf = $m + $f;
  if ($m === -1 && $f === -1 && $r === -1) {
    break;
  }
  if ($m === -1 || $f === -1) {
    echo "F";
  } elseif ($mf >= 80) {
    echo "A";
  } elseif ($mf >= 65) {
    echo "B";
  } elseif ($mf >= 50) {
    echo "C";
  } elseif ($mf >= 30) { 
    if ($r >= 50) {
      echo "C";
    } else { 
      echo "D";
    }
  } else {
    echo "F"; 
  }
  echo "\n";
}


Measured memory_bytes: 9200
x, k, d = map(int, input().split())

def sgn(x):
    if x > 0:
        return 1
    if x < 0:
        return -1
    return 0

if x > 0:
    x_greedy = x - k*d
else:
    x_greedy = x + k*d

if sgn(x) == sgn(x_greedy):
    print(abs(x_greedy))
    exit()

x_r = x % d
x_l = x_r -d

r_parity = (abs(x - x_r) // d) %2

if k%2 == r_parity:
    print(abs(x_r))
else:
    print(abs(x_l))

    


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
    return 0;
}


Measured memory_bytes: 256