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

using namespace std;

int main() {
    //freopen("inp.inp", "r", stdin);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& i : a) {
        cin >> i;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans++;
        while (a[i] == a[i+1]) {
            i++;
        }
        if (i + 1 == n) break;
        if (a[i] < a[i+1]) {
            while (a[i] <= a[i+1] and i + 1< n) {
                ++i;
            }
        } else {
            while (a[i] >= a[i+1] and i + 1< n)
                ++i;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640
Scanf.scanf "%d %d" (fun a b ->
    print_endline @@
    if compare 0 a <> compare 0 b || a + b = 0 then "Zero" else
        if 1 <= a then "Positive" else
            if (b - a) mod 2 = 0 then "Negative" else "Positive"
)

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int unit=n%10;
  if(unit==2||unit==4||unit==5||unit==7||unit==9)cout<<"hon";
  else if(unit==0||unit==1||unit==6||unit==8)cout<<"pon";
  else cout<<"bon";
  return 0;}


Measured memory_bytes: 3532
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import string

def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

x = get_int()
if x<600: print("8")
elif x>=1800: print("1")
else:
    print(8-(x-400)//200)

Measured memory_bytes: 10048
use std::io::stdin;

fn std_args() -> Vec<i32> {
    let mut args = String::new();
    stdin().read_line(&mut args).ok();
    let args: Vec<i32> =
        args.split_whitespace()
            .map(|n| n.parse::<i32>().unwrap())
            .collect::<Vec<i32>>();
    args
}

fn main() {
    let v = std_args();
    let (a, b) = (v[0], v[1]);
    if a <= 8 && b <= 8 {
        println!("Yay!");
    } else {
        println!(":(");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI l(2*n);
    REP(i,2*n) cin >> l[i];
    sort(l.begin(),l.end());
    int ans = 0;
    REP(i,n) ans += l[2*i];

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int A,B;

signed main(){

    in(A,B);
    out(B%A==0?B+A:B-A);

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f,max_n=200005,mod=1e9+7;
inline ll lowbit(ll x){return x&(-x);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
double r,pi=acos(-1);
int n,k;
long long sum1[max_n];
long long ans;
int main()
{
	//std::ios::sync_with_stdio(false);
	//std::cin.tie(nullptr);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		sum1[i]=sum1[i-1]+i;
	}
	for(int i=k;i<=n+1;i++)
	{
		long long a=sum1[i-1];
		long long b;
		if(n-i>=0)
		{
			b=sum1[n]-sum1[n-i];
		}
		else
		{
			b=sum1[n];
		}
		ans=ans+(b-a+1)%mod;
		ans%=mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5092
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int m, k;

void solve() {
    if ((m <= 1 && k > 0) || (k >= (1<<m))) {
        cout << -1 << endl;
        return;
    }

    if (k == 0) {
        for (int i = 0; i < (1<<m); i++) {
            cout << i << " " << i;
            if (i == (1<<m)-1) cout << endl;
            else cout << " ";
        }
    } else {
        for (int i = 0; i < (1<<m); i++) {
            if (i == k) continue;
            cout << i << " ";
        }
        cout << k << " ";
        for (int i = (1<<m)-1; i >= 0; i--) {
            if (i == k) continue;
            cout << i << " ";        
        }
        cout << k << endl;
    }
}

void input() {
    cin >> m >> k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


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

/* 
 * g++ -std=c++17 main.cpp -o main
 */
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) {
    int a;
    cin>>a;
    A[i] = a;
  }
  int mx = *max_element(A.begin(), A.end());
  int mn = INT_MAX;
  for (int i = -100; i <= 100; i++) {
    int sum = 0;
    for(int k = 0; k < N; k++) {
      sum += (int) pow(A[k]-i, 2.0);
    }
    mn = min(mn, sum);
  }
  cout << mn;
  cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

ll n,k,p;
string s,t;
ll dp[110][2],a[110];

int main() {
  cin >> n >> p;
  rep(i,n) cin >> a[i];
  dp[0][0]=1;
  rep(i,n)rep(j,2){
    dp[i+1][j]+=dp[i][j];
    dp[i+1][(j+a[i])%2] +=dp[i][j];
  }
  cout << dp[n][p] << endl;
}

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

int main(){
  while(1){


    
  int n;
  cin>>n;
  if(n==0){break;}
  vector<int> day[100];
  set<int> a[100];
  for(int i=0;i<100;i++){
    a[i].insert(i);
  }
  for(int i=0;i<n;i++){
    int m;
    cin>>m;
    for(int t=0;t<m;t++){
      int d;
      cin>>d;
      day[d].push_back(i);
    }
  }
  int ans=-1;
  for(int i=1;i<=30;i++){
    set<int> p;
    if(day[i].size()>=2){
      for(int t=0;t<day[i].size();t++){
        p.insert(a[day[i][t]].begin(),a[day[i][t]].end());
      }
      if(p.size()==n){ans=i; break;}
      for(int t=0;t<day[i].size();t++){
	a[day[i][t]].insert(p.begin(),p.end());
      }
    }
  }
  cout<<ans<<endl;
	



  }
  
  return 0;
}
  
  



Measured memory_bytes: 3208
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>

using namespace std;

typedef long long lint;

using namespace std;

void test_case() {
    char c;
    cin >> c;
    if(isupper(c)) cout << "A\n";
    else cout << "a\n";
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int tests=1;
    //cin >> tests;
    for(int test = 0; test < tests; ++test) {
        test_case();
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N, K=0, i=2; cin >> N;
  if(N==0){ cout << "0\n"; return 0; }
  else if(N>0){ while(i<=N){ if(N&i){ N+=i; K+=i; } i<<=2; } }
  else{ i=1; N=-N; while(i<=N){ if(N&i){ N+=i; K+=i; } i<<=2; } }
  i=1; N+=K; string S;
  while(i<=N){ S+=(N&i)?"1":"0"; i<<=1; }
  for(i=S.size()-1; i>=0; i--){ cout << S[i]; }
  cout << "\n";
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(void){
    while(1){
        int n,m,i,j,a,b,count=0,cou[500]={0},pro[500][500]={0};
        scanf("%d",&n);
        scanf("%d",&m);
        if(n==0&&m==0)break;
        for(i=0;i<m;i++){
            scanf("%d %d",&a,&b);
            pro[a-1][b-1]=1;
            pro[b-1][a-1]=1;
        }
        for(i=0;i<n;i++){
            if(pro[0][i]==1){
                cou[i]=1;
                for(j=0;j<n;j++){
                    if(pro[i][j]==1){
                        cou[j]=1;
                    }
                }
            }
        }
        for(i=1;i<n;i++){
            if(cou[i]==1){
                count++;
            }
        }
        printf("%d\n",count);
    }
return 0;
}

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

using namespace std;
typedef long long int ll;
#define debug(val) "[ " << #val " : " << (val) << " ]\n"
#define space " "
#define space " "
#define vi vector<int>
#define PI atan(1)*4
#define pb push_back
#define ff first
#define ss second
#define PI atan(1)*4


void solve() {
	int n ; 
	cin >> n ;
	vi a(n),dp(n) ; 
	for(int i=0;i<n;i++){
		cin >> a[i] ; 
	}
	dp[0] = 0 ;
	dp[1] = abs(a[1]-a[0]) ;  
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-2]+abs(a[i] - a[i-2]) , dp[i-1] + abs(a[i] - a[i-1])) ; 
	}
	cout << dp[n-1] << endl; 
		
   
}
int main() {
#ifdef _DEBUG // place in cmake-build-debug folder
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        // cout << "Case #" << i << ": ";
        solve();
    }
}


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

int main(){
    int a ;
    int b;
    int c;
    cin >> a >> b>> c;

    if(a >= b){
        if(a >= c){
            if(b >= c){
                cout << c<<" "<<b<<" "<<a << endl;
            }else{
                cout << b<<" "<< c <<" "<<a << endl;
            }
        }else{
            cout << b<<" "<<a<<" "<<c << endl;
        }
    }else{
        if(c >= b){
            cout << a<<" "<<b<<" "<<c << endl;
        }else{
            if(a >= c){
                cout << c<<" "<<a<<" "<<b << endl;
            }else{
                cout << a<<" "<<c<<" "<<b << endl;
            }
            
        }
    }
    return 0;
}


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

int main() {
  int H, W, x, a, b, i, j;
  cin >> H >> W;
  
  for (i=0; i<H+2; i++){
    
    if (i==0 || i==H+1){
      for (j=0; j<W+2; j++){
        cout << "#";
      }
    }
    else{
      string vec;
      cin >> vec;    
      for (j=0; j<W+2; j++){

        if (j==0 || j==W+1){
            cout << "#";
        }

        else{
          cout << vec.at(j-1);
        }
      }
    }

    cout << endl;

  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))

template<typename TYPE>
TYPE gcd(TYPE x, TYPE y){
	TYPE r = x % y;
	if (r == 0.0) return y;
	else return gcd(y, r);
}

template<typename TYPE>
TYPE lcm(TYPE x, TYPE y){
	return x * y / gcd(max(x, y), min(x, y));
}

int main()
{
	long long int x, y;
	while (cin >> x >> y){
		cout << gcd(max(x, y), min(x, y)) << ' ' << lcm(x, y) << "\n";
	}
	cout.flush();
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main() {
	char f;
	int a = 0;
	for (int i = 0; i < 3; i++) {
		cin >> f;
		if (f == '7') {
			a = 1;
		}
	}
	if (a == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

const ull mod = 1e9 + 7;

int main(){
    ull n; cin >> n;
    string s1, s2; cin >> s1 >> s2;
    ull ans;
    bool mode;
    if(s1[0] == s2[0]){
        ans = 3;
        mode = 0;
    }else{
        ans = 6;
        mode = 1;
    }
    for(int i = (mode ? 2 : 1); i < n;){
        if(!mode && s1[i] == s2[i]){
            ans *= 2;
            ans %= mod;
            ++i;
        }else if(!mode && s1[i] != s2[i]){
            ans *= 2;
            ans %= mod;
            i += 2;
            mode = 1;
        }else if(mode && s1[i] == s2[i]){
            ++i;
            mode = 0;
        }else{
            ans *= 3;
            ans %= mod;
            i += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
import bisect

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1), reverse=True)
bi = [bisect.bisect_left(a, bc[i][1]) for i in range(m)]
ans = 0
did = 0
for i in range(m):
    if bi[i] - did <= 0:
        continue
    if bi[i] - did > bc[i][0]:
        ans += bc[i][0] * bc[i][1]
        did += bc[i][0]
    else:
        ans += (bi[i] - did) * bc[i][1]
        did += (bi[i] - did)
print(sum(a[did:]) + ans)

Measured memory_bytes: 36836
# https://www.calc-site.com/areas/triangle_two_side_angle
from math import sin,cos,sqrt,radians

a,b,C = list(map(int, input().split()))
# 度をラジアンに変換しておく
C = radians(C)
# S
S = 1/2*(a*b*sin(C))
# L
a2,b2 = a**2,b**2
sqrt_p = a2+b2-2*a*b*cos(C)
sqrt_p = sqrt(sqrt_p)
L = a+b+sqrt_p
# h
h = b*sin(C)
print('{:.7f}'.format(S))
print('{:.7f}'.format(L))
print('{:.7f}'.format(h))


Measured memory_bytes: 5716
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll a, b; cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int A, B;

int main() {
  cin >> A >> B;
  int ans = 0;
  repe(i, A, B) {
    int num[5];
    int n = i;
    rep(j, 0, 5) {
      num[j] = n % 10;
      n /= 10;
    }
    bool can = true;
    rep(j, 0, 2) {
      if (num[j] != num[4 - j]) can = false;
    }
    if (can) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
p = 1000000007
s = input()
n = len(s)
e,a,b,c = 1,0,0,0
for i in range(n):
  if s[i] == "A":
    e,a,b,c = e,(e+a)%p,b,c
  elif s[i] == "B":
    e,a,b,c = e,a,(a+b)%p,c
  elif s[i] == "C":
    e,a,b,c = e,a,b,(b+c)%p
  else:
    e,a,b,c = (3*e)%p,(e+3*a)%p,(a+3*b)%p,(b+3*c)%p
print(c) 

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,a[10010];
	while(~scanf("%d%d",&n,&m))
	{
		for(int i=0;i<m;i++)
		a[i]=1;
		int sum=n-m;
		a[m-1]+=sum;
		printf("%d\n",a[m-1]-a[0]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    ll n, m;
    cin >> n >> m;
    ll count = 0;
    if (m/2 < n) cout << m/2 << std::endl;
    else {
        ll x = m - n*2;
        cout << n + x/4 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;
int main() {
	int k;
	cin >> k;
	int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	cout << a[k - 1];
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(stdin.readLine());
        }

        int[] c = new int[n + 1];
        for (int i = 0; i < n; i++) {
            c[p[i]] += c[p[i] - 1] + 1;
        }

        int max = Arrays.stream(c).max().getAsInt();
        stdout.println(n - max);
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 39380
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
int h,w,step;
char mp[25][25];
const int ox[]={1,-1,0,0};
const int oy[]={0,0,1,-1};

bool dfs(int X,int Y){
	for(int i=0;i<4;i++){
		int x=X+ox[i];
		int y=Y+oy[i];
		if(0<=x&&x<h&&0<=y&&y<w&&mp[x][y]=='.'){
			mp[x][y]='@';
			step++;
			dfs(x,y);
		}
	}
}

int main()
{
	while(scanf("%d%d",&w,&h)!=EOF&&(w+h)){
		for(int i=0;i<h;i++)
			scanf("%s",&mp[i]);
		step=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(mp[i][j]=='@'){
					step=1;
					dfs(i,j);
					i=w=25;
				}
			}
		}
		printf("%d\n",step);
	}
	return 0;
}

Measured memory_bytes: 2588
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: usize = read();
    let mut sum = 0;
    let mut ans = 0;

    for i in 0..x + 1 {
        sum += i;
        if sum >= x {
            ans = i;
            break;
        }
    }

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


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

int cnt[100000];

int main() {
    int N; cin >> N;
    
    for (int i = 0; i < N; i++) {
        int d; cin >> d;
        cnt[d-1]++;
    }

    int d[100000]; d[0] = cnt[0];
    for (int i = 1; i <= 100000; i++) {
        d[i] = d[i-1]+cnt[i];
    }

    int ans = 0;
    for (int i = 0; i < 100000; i++) {
        if (d[i] == (N-d[i])) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import math as ma

n = int(input())
m = [list(map(int, input().split())) for i in range(n)]
t = [[0 for j in range(n) ] for i in range(n)]
f = [0 for _ in range(n)]
ans = 0

for i in range(n):
    for j in range(n):
        if i == j or t[i][j] > 0:
            pass
        else:
            x = m[i][0] - m[j][0]
            y = m[i][1] - m[j][1]
            l = x**2 + y**2
            t[i][j] = ma.sqrt(l)
            t[j][i] = ma.sqrt(l)
        #     print('l',l)
        # print('aa',m,t,f)

for i in range(n):
    ans += sum(t[i])

print(ans/n)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

int s[10], c[10];
int ans[10];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    int i, j;
    rep(i, m) {
        cin >> s[i] >> c[i];
    }
    rep(i, m) {
        if (s[i] > n) {
            cout << -1 << endl;
            return 0;
        }
        rep(j, m) {
            if (s[i] == s[j] && c[i] != c[j]) {
                cout << -1 << endl;
                return 0;
            }
        }
        if (s[i] == 1 && c[i] == 0 && n != 1) {
            cout << -1 << endl;
            return 0;
        }
        ans[s[i]] = c[i];
    }
    if (ans[1] == 0 && n != 1) ans[1] = 1;
    xrep(i, 1, n + 1) {
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {

	string s;

	cin >> s;

	int sum = 0;
	for (int i = 0; i < s.length(); i++) {
		sum += (int)(s[i]-'0');
	}

	
	int a = (int)std::stoi(s.c_str());

	if (a%sum == 0)cout << "Yes" << endl;
	else	cout << "No" << endl;
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
// m Restaurant
int N,x=0,z=0;
scanf("%d",&N);
if(1<=N&&N<=100){
x=N*800;
z=N/15;
x-=(z*200);
}
    printf("%d",x);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
#include<utility>
using namespace std;

int main(){
  long long n, m;
  cin >> n >> m;
  if (n > m) swap(n, m);

  long long ans;
  if(n==1 && m==1) ans = 1;
  else if(n==1) ans = m-2;
  else ans = (n-2)*(m-2);

  cout << ans << endl;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)

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

    int n;
    cin >> n;

    vector<int> arr;
    int i;
    int c = 0;
    while (c < n && cin >> i)
    {
        arr.push_back(i);
        ++c;
    }

    reverse(arr.begin(), arr.end());

    REP(i2, n)
    {
        if (i2 > 0)
        {
            cout << " ";
        }

        cout << arr[i2];
    }

    cout << endl;

    return 0;
}



Measured memory_bytes: 3092
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS

int main(int argc, char const *argv[])
{
	int x,a;
	int c;
	scanf("%d%d",&x,&a);
	c = (x < a) ? 0 : 10;
	printf("%d\n", c);
	return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[700][2005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  
  dp[0][0]=1;
  ll ans=0;
  rep(i,n/3){
    rep(j,n+1){
      for(ll k=3; k+j<=n; k++){
        (dp[i+1][k+j]+=dp[i][j])%=MOD;
      }
    }
    (ans+=dp[i+1][n])%=MOD;
  }
  cout<<ans<<endl;
}

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

int n;
string str;
vector<int> G[200005];
map< int , int > mp, mp2;


int solve(){
  int key=0;
  
  mp[key]=0;
  for(int i=0;i<n;i++){
    int ch = str[i]-'a';
    key ^= (1<<ch);
    if(mp.count(key)>0){
      G[ mp[key] ].push_back( i+1 );
      G[ mp2[key] ].push_back( i+1 );
      mp[key]=i+1;
    }else{
      mp[key]=i+1;
      mp2[key]=i+1;
    }
    

    for(int j=0;j<26;j++){
      int tmp=key;
      tmp^=(1<<j);
      if(mp.count(tmp)>0 ){
        G[ mp[tmp] ].push_back( i+1 );
      }
      if( mp2.count(tmp)>0) {
        G[ mp2[tmp] ].push_back( i+1 );
      }
    }
    
  }
  /*
  for(int i=0;i<=n;i++){
    cout<<i<<endl;
    for(int to:G[i]){
      cout<<to<<' ';
    }
    cout<<endl<<endl;
  }
  */
  const int INF = 1e9;
  vector<int> dp(n+1,INF);
  
  dp[0]=0;

  for(int i=0;i<n;i++){
    for(int j=0;j<(int)G[i].size();j++){
      int to=G[i][j];
      dp[to]=min(dp[to],dp[i]+1);
    }
    dp[i+1]=min(dp[i+1],dp[i]+1);
  }
  return dp[n];
}

int main(){
  while(  cin>>str ){

    n=str.size();
    for(int i=0;i<=n;i++)G[i].clear();
    mp.clear();
    
    cout<<solve()<<endl;
  }
  return 0;
}


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

int main() {
  while(true) {
  int d[101];
  fill(d, d + 101, 0);
  int N, Q; cin >> N >> Q;
  if(N == 0 && Q == 0) break;
  for(int i = 0; i < N; ++i) {
    int M; cin >> M;
    for(int j = 0; j < M; ++j) {
      int k; cin >> k;
      d[k]++;
    }
  }
  int ans = 0;
  int large = 0;
  for(int i = 1; i <= 100; ++i) {
    if(d[i] > large && d[i] >= Q) {
      ans = i;
      large = d[i];
    }
  }
  cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio> 
using namespace std;
/*---------------------------------------------------*/

int main(){
  int n,u,k,v;
  int g[101][101]={};
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(int i=0;i<k;i++){
      scanf("%d",&v);
      g[u][v]=1;
    }
  }
  for(int i=1;i<n+1;i++){
    printf("%d",g[i][1]);
    for(int j=2;j<n+1;j++){
      printf(" %d",g[i][j]);
    }
    printf("\n");
  }
  return 0;
}

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

int main()
{
	int N;
	cin >> N;
	if (N <= 999) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ABD" << endl;
	}
}

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

struct Rational {
    long long num;
    long long den;
    bool operator<=(const Rational& r) const { return compare(r) <= 0; }
    inline long long compare(const Rational& r) const {
        long long ln = num, ld = den, rn = r.num, rd = r.den;
        if ( ld < 0 ) ln = -ln, ld = -ld;
        if ( rd < 0 ) rn = -rn, rd = -rd;
        return ln * rd - ld * rn;
    }
};

ll solve() {
    ll K;
    cin >> K;

    auto S = [](ll n) -> ll {
        ll r = 0;
        while ( n > 0 ) {
            r += n % 10;
            n /= 10;
        }
        return r;
    };
    vector<ll> pow(18);
    pow[0] = 1;
    for ( int i = 1; i < 18; i++ ) pow[i] = pow[i-1] * 10;
    vector<ll> ans;
    ll n = 1e15;
    Rational m{0, 1};
    while ( n > 0 ) {
        for ( ll d = 0; pow[d] <= n ; d++ ) {
            ll x = n - pow[d];
            Rational xr{S(x), x};
            if ( m <= xr ) {
                m = xr;
                n = x;
                if ( n <= 0 ) break;
                ans.push_back(n);
                break;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    for ( int i = 0; i < K; i++ ) {
        cout << ans[i] << "\n";
    }
    return 0;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
#define INF 0x3fffffff
#define MAXSIZE 100005
//const double eps=1e-8;
//#define Equ(a,b) ((fabs((a)-(b)))<(eps))
//const double pi=acos(-1.0);

int main(){
    int n;
    int a0=0,a1=0,a2=0;
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        int b;
        scanf("%d",&b);
        if (b%4==0) {
            a2++;
        }
        else if (b%2==0){
            a1++;
        }
        else{
            a0++;
        }
    }
    if (a1==0&&a2>=a0-1) {
        printf("Yes\n");
    }
    else if (a2>=a0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll mod = 1000000007;
int main() {
	ll x;
	cin >> x;
	if (x < 7) {
		cout << "1" << endl;
	}
	else {
		ll y;
		y = x;
		ll ans = (y / 11)*2;
		ll k = y % 11;
		if (k > 6) {
			cout << ans + 2 << endl;
		}
		else if(k!=0){
			cout << ans + 1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
#define ll long long
int main(void){
    ll n;
    ll inf = 1000000007;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    ll ans = 3;
    if(n==1) ans = 3;
    else if(n==2) ans = 6;
    else if(n>=3){
        ll check;
        if(s1[0]==s2[0])
            check = 0;
        else if(s1[0]!=s2[0]){
            check = 1;
            ans = 6;
        }
        for(ll i = check; i < n-1; i++){
            if(s1[i+1]==s2[i+1]){
                if(s1[i]==s2[i])
                    ans = (ans*2)%inf;
            }
            else if(s1[i+1]!=s2[i+1]){
                if(s1[i]!=s2[i])
                    ans = (ans*3)%inf;
                else if(s1[i]==s2[i])
                    ans = (ans*2)%inf;
                i++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

map<long long , int> pa;

int main()
{
  int n,i;
  long long a;
  cin>>n;
  
  //順番に数字を読み込む→mapに取り込む
  for(i=0;i<n;i++)
  {
    cin>>a;
    pa[a]++;
    //cout<<pa[a];
    if(pa[a]==2)
    {
      cout<<"NO";
      goto end;
    }
  }
  cout<<"YES";
  end:; 
}

Measured memory_bytes: 12800
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

signed main() {
	double N;
	cin >> N;
	int a = N / (double)108 * (double)100;
	int b = a + 1;
	int A = (double)a / (double)100 * (double)108;
	int B = b / (double)100 * (double)108;
	if (A == N)cout << a;
	else if (B == N)cout << b;
	else cout << ":(";
}

Measured memory_bytes: 256
// Aizu Vol-5 0594: Super Metropolis
// 2017.8.31 bal4u@uu

#include <stdio.h>

#define abs(x) ((x)>=0?(x):-(x))
#define max(x,y) ((x)>=(y)?(x):(y))

int shortpath(int xf, int yf, int xt, int yt)
{
	if ((xt >= xf && yt <= yf) || (xt <= xf && yt >= yf)) return abs(xt-xf)+abs(yt-yf);
	return max(abs(xt-xf), abs(yt-yf)); 
}

int main()
{
	int w, h, n, x1, y1, x2, y2, ans;

	scanf("%d%d%d%d%d", &w, &h, &n, &x1, &y1);
	for (ans = 0, n--; n-- > 0; x1 = x2, y1 = y2) {
		scanf("%d%d", &x2, &y2);
		ans += shortpath(x1, y1, x2, y2);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <ctime>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 1LL << 62
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

const double pi = acos(-1);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int L;
    cin >> L;
    vector<ll> A(L);
    rep(i, L) cin >> A[i];

    vector<vector<ll>> dp(L + 1, vector<ll>(5, inf));
    rep(i, 5) dp[0][i] = 0;
    rep(i, L) {
        ll mi = dp[i][0];
        dp[i + 1][0] = mi + A[i];
        mi = min(mi, dp[i][1]);
        dp[i + 1][1] = mi + (A[i] == 0 ? 2 : A[i] % 2);
        mi = min(mi, dp[i][2]);
        dp[i + 1][2] = mi + ((A[i] + 1) % 2);
        mi = min(mi, dp[i][3]);
        dp[i + 1][3] = mi + (A[i] == 0 ? 2 : A[i] % 2);
        mi = min(mi, dp[i][4]);
        dp[i + 1][4] = mi + A[i];
    }
    ll ans = min({dp[L][0], dp[L][1], dp[L][2], dp[L][3], dp[L][4]});
    output(ans);
    
    return 0;
}



Measured memory_bytes: 16000
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[][][] check = new boolean[500][500][500];
		while (true) {
			int n = sc.nextInt();
			int h = sc.nextInt();
			if(n == 0 && h == 0) break;
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					Arrays.fill(check[i][j], false);
				}
			}
			int count = 0;
			for (int i = 0; i < h; i++) {
				String c = sc.next();
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;

				if (c.equals("xy")) {
					for (int j = 0; j < n; j++) {
						if (check[a][b][j])
							continue;
						check[a][b][j] = true;
						count++;
					}
				} else if (c.equals("xz")) {
					for (int j = 0; j < n; j++) {
						if (check[a][j][b])
							continue;
						check[a][j][b] = true;
						count++;
					}
				} else {
					for (int j = 0; j < n; j++) {
						if (check[j][a][b])
							continue;
						check[j][a][b] = true;
						count++;
					}
				}

			}
			System.out.println(n * n * n - count);
		}
		
		
		
		
	}
}

Measured memory_bytes: 233940
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1e9+7;
int N, M;
vector<vector<tuple<Int, int, int>>> graph;
void dijkstra(int start, vector<Int>& dist)
{
    using P = pair<Int, int>;
    priority_queue<P, vector<P>, greater<P>> Q;
    vector<bool> visited(N);
    Q.emplace(0, start);
    while (!Q.empty()) {
        Int d, n; tie(d, n) = Q.top();
        Q.pop();
        if (visited[n]) continue;
        visited[n] = true;
        dist[n] = d;
        for (auto& tup : graph[n]) {
            int dd, nn, edge; tie(dd, nn, edge) = tup;
            Q.emplace(d + dd, nn);
        }
    }
}
void counting(int start, vector<Int>& distOpp, vector<Int>& countV, vector<Int>& countE)
{
    using P = pair<Int, int>;
    priority_queue<P, vector<P>, greater<P>> Q;
    vector<bool> visited(N);
    Q.emplace(0, start);
    countV[start] = 1;
    while (!Q.empty()) {
        Int d, n; tie(d, n) = Q.top();
        Q.pop();
        if (visited[n]) continue;
        visited[n] = true;
        for (auto& tup : graph[n]) {
            int dd, nn, id; tie(dd, nn, id) = tup;
            if (distOpp[n] - distOpp[nn] == dd) {
                (countV[nn] += countV[n]) %= MOD;
                (countE[id] += countV[n]) %= MOD;
                Q.emplace(d + dd, nn);
            }
        }
    }
}
int main()
{
    cin >> N >> M;
    int S, T; cin >> S >> T; S--, T--;
    graph.resize(N);
    vector<Int> distS(N), distT(N), countVS(N), countES(M), countVT(N), countET(M);
    vector<tuple<int, int, int>> edges;
    for (int i = 0; i < M; i++) {
        int u, v, d; cin >> u >> v >> d; u--, v--;
        edges.emplace_back(u, v, d);
        graph[u].emplace_back(d, v, i);
        graph[v].emplace_back(d, u, i);
    }
    dijkstra(S, distS);
    dijkstra(T, distT);
    counting(S, distT, countVS, countES);
    counting(T, distS, countVT, countET);
    Int all = 0, collision = 0;
    for (int i = 0; i < N; i++) {
        if (distS[i] * 2 == distS[T]) {
            Int pat = countVS[i] * countVT[i] % MOD;
            (all += pat) %= MOD;
            (collision += pat * pat) %= MOD;
        }
    }
    for (int i = 0; i < M; i++) {
        int u, v, d; tie(u, v, d) = edges[i];
        if ( (distS[u] * 2 < distS[T] && distT[v] * 2 < distS[T])
          || (distS[v] * 2 < distS[T] && distT[u] * 2 < distS[T]) ) {
            Int pat = countES[i] * countET[i] % MOD;
            (all += pat) %= MOD;
            (collision += pat * pat) %= MOD;   
        }
    }
    cout << (all * all % MOD - collision + MOD) % MOD << endl;
    return 0;
}


Measured memory_bytes: 29088
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long int N;
    long int K;
    
    cin >> N >> K;
    
    vector<long long int> H(N);
    
    for(int i=0; i<N; i++) {
        cin >> H.at(i);
    }
    
    sort(H.begin(), H.end());
    
    // K回必殺技で N-1-K番目までを攻撃
    
    long long int count = 0;
    if (N-K-1 >= 0) {
        for (int i=0; i<=N-1-K; i++) {
            count += H.at(i);
        }
    }
    
    cout << count << endl;
    
}


Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    X, K, D = LI()
    X = abs(X)

    a = math.ceil(X/D)

    if K < a:
        print(abs(X-D*K))
        return
    else:
        K -= a
        X -= D*a
        if K % 2 == 0:
            print(abs(X))
            return
        else:
            print(abs(X+D))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9988
import math
A, B = map(int, input().split())
V = 10000
for i in range(1, 10001):
    a = math.floor(i*0.08)
    b = math.floor(i*0.1)
    if a == A and b == B:
        # print(a)
        # print(b)
        if V > i:
            V = i
        else:
            continue
    else:
        continue
if V == 10000:
    print(-1)
else:
    print(V)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 507;
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;
    int a = 0, w = 0, t = 0, l = 0;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == "AC") {a++;}
        if (s == "WA") {w++;}
        if (s == "TLE") {t++;}
        if (s == "RE") {l++;}
    }
    cout << "AC x " << a << endl << "WA x " << w << endl << "TLE x " << t << endl << "RE x " << l;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
    int n, q;
    std::cin >> n;
    std::vector<int> a(n);
    for (auto& e: a) {
        std::cin >> e;
    }
    std::cin >> q;
    std::vector<int> b(q);
    int m = 0;
    for (auto& e: b) {
        std::cin >> e;
        m = std::max(m, e);
    }
    bool dp[21][2001];
    dp[0][0] = true;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= m; ++j) {
            dp[i + 1][j] = dp[i][j];
            if (j >= a[i]) {
                dp[i + 1][j] |= dp[i][j - a[i]];
            }
        }
    }
    for (auto&& e: b) {
        std::cout << (dp[n][e] ? "yes" : "no") << std::endl;
    }
}



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

int main(){
    int n; cin>>n;
    int acc = 0;
    for (int i=1;i<=n;i++){
        if(to_string(i).size() % 2 == 1){
            acc++;
        }
    }
    cout << acc << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		solve(sc, out);
		
		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out){
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		
		int[] a = new int[m];
		
		for(int i = 0; i < m; i++) a[i] = sc.nextInt();
		
		int cnt = 0;

		for(int i = 0; i < m; i++) {
			if(x > a[i]) cnt++;
		}
		
		out.println(Math.min(cnt, m-cnt));
		
	}

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

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21204