akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    string s;
    cin >> s;
    int len = (int)s.length();
    int cnt = 0;
    for (int i = 0; i < len / 2; i++) {
        if (s[i] != s[len- 1 - i])
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long n,i,a[3005],d[3005][3005],k;
int main()
{
   cin>>n;
   for(i=1;i<=n;i++)
   {
       cin>>a[i];
       d[i][i]=a[i];
   }
   for(k=2;k<=n;k++)
   {
       for(i=1;i<=n-k+1;i++)
       {
           d[i][i+k-1] = max(a[i]-d[i+1][i+k-1],a[i+k-1]-d[i][i+k-2]);
       }
   }
   cout<<d[1][n];
    return 0;
}


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

int main(void){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll m=0;
    m=a*c;
    m=max(a*d,m);
    m=max(m,b*c);
    m=max(m,b*d);
    cout<<m<<endl;
    
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  long long p[n];
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  long long min=1000000000,count=0;
  for(int i=0;i<n;i++){
    if(p[i]<min){
      min=p[i];
      count++;
    }
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int s;
  cin >> s;
  int l = s/100;
  int r = s%100;
  if(l>=1 && l<=12) {
    if(r>12 || r==0) {
      cout << "MMYY" << endl;
    }
    else {
      cout << "AMBIGUOUS" << endl;  
    }
  }
  else {
    if(r>12 || r==0) {
      cout << "NA" << endl;
    }
    else{
      cout << "YYMM" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  vector<int> n(4);
  REP(i,4) cin>>n[i];
  sort(n.begin(), n.end());
  bool ans = (n[0] == 1	&& n[1] == 4 &&	n[2] ==	7 && n[3] == 9);
  cout << (ans ? "YES" : "NO") << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

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

int main() {
	int a, b;
	cin >> a >> b;
	cout << (b - a - 1) * (b - a) / 2 - a;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr int NMAX = 100010;

ll waysTD[NMAX];
ll wtdps[NMAX+10];

int main() {
	int n, k; scanf("%d %d", &n, &k);
	waysTD[0] = 1;
	for (int i = 1; i < NMAX; ++i) wtdps[i] = 1;
	for (int i = 0; i < n; ++i) {
		int ai; scanf("%d", &ai);
		for (int x = 0; x < NMAX; ++x) {
			waysTD[x] = (wtdps[x+1] - wtdps[max(0, x-ai)] + MOD) % MOD; 
		}
		for (int x = 0; x < NMAX; ++x) {
			wtdps[x+1] = (wtdps[x] + waysTD[x]) % MOD;
		}
	}
	printf("%lld\n", waysTD[k]);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<math.h>
using namespace std;
long long n,m,a[100100],ans,b[100100];
int main()
{
	cin>>n;
	for(int i=1;i<=n+1;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
	{
		if(b[i]>=a[i])
		{
			ans+=a[i];
			b[i]-=a[i];
			a[i]=0;
			if(b[i]<=a[i+1])
			{
				ans+=b[i];
				a[i+1]-=b[i];
			}
			else
			{
				ans+=a[i+1];
				a[i+1]=0;
			}
		}
		else
		{
			ans+=b[i];
			a[i]-=b[i];
			b[i]=0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b;
  cin >> a >> b;
  cout << (a + b) % 24 << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 256
open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
	let (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
end open MyInt64
let () =
	let _ = get_i64 0 in let s = scanf " %s" (fun v -> v) in
	let ls = s |> char_list_of_string in
	List.fold_left (fun (depth,tba) v -> 
		if v='(' then (
			(depth+1L,tba)
		) else (
			if depth <= 0L then (depth-1L,max tba (0L-depth+1L))
			else (depth-1L,tba)
		)
	) (0L,0L) ls
	|> (fun (depth,tba) ->
		let pre,post = if tba + depth > 0L then (tba,tba+depth) else (tba,0L)
		in
		rep 1L pre (fun _ -> printf "(";`Ok);
		printf "%s" s;
		rep 1L post (fun _ -> printf ")";`Ok);
	)
	

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

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  K -=1;
 if (S.at(K) == 'A'){
 S.at(K) = 'a';
 }else if (S.at(K) == 'B'){
 S.at(K) = 'b';
 }else if (S.at(K) == 'C'){
 S.at(K) = 'c';
 }
  cout << S;
}

Measured memory_bytes: 256
H, W = list(map(int, input().split()))
N = int(input())
A = [int(i) for i in input().split()]

ans = []
for i in range(N):
    for j in range(A[i]):
        ans.append(i + 1)

for i in range(H):
    use = (ans[i*W:(i+1)*W])[::(-1)**i]
    for i in range(W):
        if not(i == W -1):
            print(use[i], end=" ")
        else:
            print(use[i])


Measured memory_bytes: 3884
#include <stdio.h>

int main(void) {
    int N, M, H[100005], A[100005], B[100005], x, b[100005], i;
    scanf("%d%d", &N, &M);
    for (i=1; i<=N; i++) scanf("%d", &H[i]);
    for (i=1; i<=M; i++) scanf("%d%d", &A[i], &B[i]);
    for (i=1; i<=N; i++) b[i]=1;
    for (i=1; i<=M; i++) {
        if (H[A[i]]>H[B[i]]) b[B[i]]=0;
        else if (H[A[i]]==H[B[i]]) {
            b[A[i]]=0;
            b[B[i]]=0;
        }
        else b[A[i]]=0;
    }
    x=0;
    for (i=1; i<=N; i++) x+=b[i];
    printf("%d", x);
    return 0;
}


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

int bubbleSort(int A[],int N){
  int s=0;
  bool flag=1;
  for(int i=0; flag; i++){
    flag=0;
    for(int j=N-1; j>=i+1; j--){
      if(A[j]<A[j-1]){
        swap(A[j],A[j-1]);
        flag=1;
        s++;
      }
    }
  }
  return s;
}

int main(){
  int A[100],N,s;
  cin>>N;
  for(int i=0; i<N; i++) cin>>A[i];
  s=bubbleSort(A,N);
  for(int i=0; i<N; i++){
    if(i) cout<<" ";
    cout<<A[i];
  }
  cout<<endl;
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 3092
import java.util.*;
import java.lang.Math;

public class Main{
	public static void main(String ards[]){
    	Scanner sc = new Scanner(System.in);
    	long x = sc.nextLong();
      	long a = sc.nextLong();
      	long b = sc.nextLong();
      	if(Math.abs(x-a)<Math.abs(x-b)){
        	System.out.println("A");
        }else{
        	System.out.println("B");
        }
    }
}

Measured memory_bytes: 21844
// Example program
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

int main()
{
    int a;int b;int c;
    cin>>a>>b>>c;
   vector<int>v{a,b,c};
   sort(v.begin(),v.end());
   cout << v[0] <<" "<< v[1] <<" "<< v[2] << endl;
}

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

int main() {
 int N,M;
  cin >> N >> M;
  vector<vector<int>> sc(M,vector<int>(2));
  rep(i,M) rep(j,2) cin >> sc[i][j];
  rep(i,M) sc[i][0]--;
  vector<int> ans(N);
  vector<int> c(N);
  rep(i,M){
    if(c[sc[i][0]] == 1 && ans[sc[i][0]] != sc[i][1]){
      cout << -1;
      return 0;
    }
    ans[sc[i][0]]=sc[i][1];
    c[sc[i][0]] =1;
  }
  if(N != 1 && c[0]==1 && ans[0]==0){
     cout << -1;
      return 0;
  }
  if(N != 1 && c[0]==0 && ans[0]==0) ans[0] =1;
  int answ = 0;
  for(int i=0;i<N;i++){
    answ += ans[i] * pow(10,N-1-i);
  }
  cout << answ;
}


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

int main(){
    int N, a, b, c, d;
    cin >> N;
    a = (int) sqrt(N * 2);
    b = (a + 1) * a / 2;
    
    if (b < N) {
        c = a + 1;
        d = b + a + 1 - N;
    } else {
        c = a;
        d = b - N;
    }
    
    for ( int i = 1; i <= c; i++){
        if (i != d) cout << i << "\n";
    }
    
    
  return 0;
}


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

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

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

int main() {
    string s;
    int ans = 0, val = 0;
    while(getline(cin, s)){
        for (auto &&i : s) {
            if(isdigit(i)) val = val*10+(i-'0');
            else ans += val, val = 0;
        }
        ans += val; val = 0;
    }
    cout << ans+val << "\n";
    return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    string X, Y;
    cin >> X >> Y;
    
    int x = stoi(X, nullptr, 16);
    int y = stoi(Y, nullptr, 16);
    
    if (x < y) cout << "<" << endl;
    else if (x > y) cout << ">" << endl;
    else cout << "=" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ll n,m;
   float sum=0;
   cin>>n>>m;
   vector<ll>v(n);
   for(int i=0;i<n;i++)
   {
       cin>>v[i];
       sum+=v[i];
   }
   float x=(sum)/(4*m);
   //cout<<x<<" ";
   ll c=0;
   for(int i=0;i<n;i++)

   {
       if(v[i]>=x) c++;
   }
  // cout<<c<<"\n";
   if(c>=m) cout<<"Yes\n";
   else cout<<"No\n";
}


Measured memory_bytes: 256
s = input()

bef = "R"
temp = 0
arr = []
keys = []
ans = [0 for i in range(len(s))]
for i in range(len(s)):
    if s[i] == bef:
        temp += 1
    else:
        arr.append(temp)
        temp = 1
        bef = s[i]
        if bef=="L":
            keys.append(i-1)
            keys.append(i)
arr.append(temp)
# print(arr)
# print(keys)

for i in range(len(arr)//2):
    if arr[i*2]%2 == 0:
        ans[keys[i*2]] += arr[i*2]//2
        ans[keys[i*2]+1] += arr[i*2]//2
    else:
        ans[keys[i*2]] += arr[i*2]//2+1
        ans[keys[i*2]+1] += arr[i*2]//2
    if arr[i*2+1]%2 == 0:
        ans[keys[i*2+1]] += arr[i*2+1]//2
        ans[keys[i*2+1]-1] += arr[i*2+1]//2
    else:
        ans[keys[i*2+1]] += arr[i*2+1]//2+1
        ans[keys[i*2+1]-1] += arr[i*2+1]//2

for i in range(len(ans)-1):
    print(ans[i],end=" ")
print(ans[-1])






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

int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int a = x2 - x1, b = y2 - y1;
	cout << x2 - b << " " << y2 + a << " " << x1 - b << " " << y1 + a << endl;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    fastio();
    ll N;
    cin>>N;
    ll ar[N];
    cn(ar,N);
    ll sa[N]={};
    sa[0]=ar[0];
    for(ll i=1;i<N;i++)
    {
        sa[i]=sa[i-1]+ar[i];
    }
    ll pa[N]={};
    pa[N-1]=ar[N-1];
    for(ll i=N-2;i>=0;i--)
    {
        pa[i]=pa[i+1]+ar[i];
    }
    ll ans=LONG_MAX;
    for(ll i=0;i<N-1;i++)
    {
        ll k=abs(sa[i]-pa[i+1]);
        ans=min(ans,k);
    }
    cout<<ans<<endl;
} 
/*
Powered by Buggy plugin
*/


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n,w;
    cin>> n >> w;

    ll weight[n],value[n];
    
    for(ll i=0;i<n;i++){
        cin>>weight[i]>>value[i];
    }

    ll dp[w+1]={};

    for(ll i=0;i<n;i++){
    
        for(ll j=w-weight[i];j>=0;j--){
            dp[j+weight[i]]=max(dp[j+weight[i]],dp[j]+value[i]);
        }
    }
    ll ans=0;
    for(ll i=0;i<=w;i++){
    ans=max(ans,dp[i]);
    }

    cout<<ans<<"\n";

}


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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

void solve()
{
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++)  cin >> h[i];
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
      dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1];
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 4448
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP((i),0,(n))
#define RREP(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rrep(i,n) RREP(i,n,0)
#define each(it,X) for(__typeof((X).begin())  it=(X).begin();it!=(X).end();it++)
#define all(v) ((v).begin(),(v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int,int>pr;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef set<int>si;
const int INF=1070000000ll;
const int mod=1000000007ll;

struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
    edge(){}
};
struct data{
    int pos,total,state;
    data(int a,int b,int c):pos(a),total(b),state(c){}
    data(){}
    bool operator<(const data &d)const{
        return total>d.total;
    }
};
int M,N,K,D;
int c[6];
vector<edge>G[200];
int dist[200][1<<6];
void dijkstra(){
    fill_n(*dist,200*(1<<6),INF);
    dist[N+M][0]=0;
    priority_queue<data>Q;
    Q.push(data(N+M,0,0));
    while(!Q.empty()){
        data d=Q.top();Q.pop();
        if(dist[d.pos][d.state]<d.total)continue;
        dist[d.pos][d.state]=d.total;
        rep(i,G[d.pos].size()){
            edge &e=G[d.pos][i];
            int tcost=d.total+e.cost*K,tstate=d.state;
            if(e.to<M){
                if((d.state>>e.to)&1)continue;
                tstate|=(1<<e.to);
                tcost-=c[e.to];

            }
            if(dist[e.to][tstate]<=tcost)continue;
            Q.push(data(e.to,tcost,tstate));
        }
    }
}
int get(){
    char c;cin>>c;
    if(c=='H')return M+N;
    if(c=='D')return M+N+1;
    int v;cin>>v;
    if(c=='C')return v-1;
    return M+v-1;
}
signed main(){
    cin.tie(0);ios_base::sync_with_stdio(0);

    while(cin>>M>>N>>K>>D,M||N||K||D){
        rep(i,M)cin>>c[i];
        fill_n(G,N+M+2,vector<edge>());
        rep(i,D){
            int v=get();
            int u=get();
            int d;cin>>d;
            G[v].push_back(edge(u,d));
            G[u].push_back(edge(v,d));
        }
        dijkstra();
        int mi=INF;
        rep(i,1<<M)mi=min(mi,dist[M+N+1][i]);
        cout<<mi<<endl;
    }
    return 0;
}

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

int main(){
int n,a,b;
int p[200];
int i;
int sum[3]={0,0,0};

cin>>n>>a>>b;
for(i=0;i<n;i++){
cin>>p[i];
}

for(i=0;i<n;i++){
if(p[i]<=a){
sum[0]+=1;
}
if(p[i]>a&&p[i]<=b){
sum[1]+=1;
}
if(p[i]>b){
sum[2]+=1;
}
}

for(i=1;i<3;i++){
if(sum[0]>sum[i]){
  sum[0]=sum[i];
}
}
cout<<sum[0];
}
  

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<long long> inputs;
long long dp[400][400][400]; // now_place,back_itr,k
int main(){
#define int long long
	long long n, k;
	cin >> n >> k;
	inputs.push_back(0);
	REP(i, n) {
		long long a;
		cin >> a;
		inputs.push_back(a);
	}
	n++;
	REP(i, 400) {
		REP(q, 400) {
			REP(j, 400) {
				dp[i][q][j] = LONG_INF;
			}
		}
	}
	dp[1][1][0] = 0;
	dp[1][0][1] = 0;
	for (int i = 1; i < inputs.size()-1; ++i) {
		for (int q = 0; q <= i; ++q) {
			for (int t = 0; t <= k; ++t) {
				{
					//normal
					if (inputs[q] < inputs[i+1]) {
						dp[i + 1][i+1][t] = min(dp[i + 1][i+1][t], dp[i][q][t]);
					}
					else {
						dp[i + 1][i + 1][t] = min(dp[i + 1][i + 1][t], dp[i][q][t] + inputs[q] - inputs[i + 1]);
					}
				}
				{
					//skip
					dp[i + 1][q][t+1] = min(dp[i + 1][q][t+1], dp[i][q][t]);
				}
			}
		}
	}
	long long ans = LONG_INF;
	for (int i = 0; i < inputs.size(); ++i) {
		for (int q = 0; q <= k; ++q) {
			ans = min(ans, dp[inputs.size() - 1][i][q] + inputs[i]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 500856
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.Queue

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val max = 1e5.toInt

  val N = in.next().toInt
  val X = Array.fill[List[Int]](max+1)(Nil)
  val Y = Array.fill[List[Int]](max+1)(Nil)
  for (_ <- 1 to N) {
    val x, y = in.next().toInt
    X(x) = y :: X(x)
    Y(y) = x :: Y(y)
  }

  //
  val dpX = new Array[Boolean](max+1)
  val dpY = new Array[Boolean](max+1)

  var ans = 0L
  for(i <- 1 to max) {
    if(!dpX(i)) {
      var nodex: List[Int] = Nil
      var nodey: List[Int] = Nil
      val q = new Queue[(Int, String)]

      dpX(i) = true
      q.enqueue((i, "x"))
      nodex = i :: nodex

      while(!q.isEmpty) {
        val (n, label) = q.dequeue()

        if(label == "x") {
          for(e <- X(n) if !dpY(e)) {
            dpY(e) = true
            q.enqueue((e, "y"))
            nodey = e :: nodey
          }
        }
        else {
          for(e <- Y(n) if !dpX(e)) {
            dpX(e) = true
            q.enqueue((e, "x"))
            nodex = e :: nodex
          }
        }
      }


      val cntx = nodex.length
      val cnty = nodey.length
      if (cntx >= 2 && cnty >= 2) {
        var edges = 0L

        for (e <- nodex) {
          edges += X(e).length
        }

        ans += cntx.toLong * cnty - edges
      }
    }
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 86684
MAX = 510000
MOD = 10**9+7
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
#前処理 逆元テーブルを作る
def COMinit():
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD//i)%MOD
        finv[i] = finv[i-1] * inv[i] % MOD
#実行
def COM(n, k):
    if n  < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD

COMinit()
n = int(input())
p = n//3
ans = 0
for i in range(1, p+1):
    nn = n
    nn -= 3*i
    ans += COM(nn+i-1, i-1)
print(ans%MOD)

Measured memory_bytes: 76280
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

int main(){
    int x, a;
    cin >> x >> a;
    int ans = (x < a)? 0 : 10;
    cout << ans << endl;
    return 0;
}

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

ll gcd(ll a, ll b) {
  ll smaller = min(a, b);
  ll bigger = max(a, b);
  ll surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

//最小公倍数を求めるメソッド
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main() {
  int n;
  ll m;
  cin >> n >> m;
  vector<ll> a(n);
  ll lcm_1 = 1;
  ll lcm_2 = 1;
  ll ans = 0;
  bool over = false;
  rep(i, n) cin >> a[i];
  rep(i, n){
    lcm_1 = lcm(lcm_1, a[i]);
    //cout << lcm_1 << endl;
    if(lcm_1 >=m || lcm_1 < 0){
      over = true;
      break;
    }
  }
  rep(i, n){
    lcm_2 = lcm(lcm_2, a[i]/2);
    //cout << lcm_2 << endl;
    if(lcm_2 > m || lcm_2 < 0){
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n){
    if(lcm_2 % a[i] != a[i] / 2){
      cout << 0 << endl;
      return 0;
    }
  }
  if(over){
    cout << 1 << endl;
    return 0;
  }
  m += lcm_2;
  ans = m / lcm_1;
  cout << ans << endl;
}

Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,s;
  cin >> k >> s;
  int count=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      int z=s-i-j;
      if(0<=z && z<=k)count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll n, a, b, t;
	cin >> n;
	a = 2;
	b = 1;
	REP(i, n) {
		t = b;
		b = a + b;
		a = t;
	}
	cout << a << endl;
	return 0;
}
 

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, x, m = map(int,input().split())

A = [0] * m
for i in range(m):
    A[i] = (i*i)%m

V = [-1] * m
B = [x]
xx = x

cnt = 0
while V[xx] == -1:
    V[xx] = cnt
    cnt += 1
    xx = A[xx]
    B.append(xx)

end = V[xx]
# print(end)

# print(B[:10])
# print(len(B))
# print()
S = [B[0]]
for i in range(1, len(B)):
    S.append(B[i] + S[-1])

# print(S[:10])
# print(sum(S) * (n//len(B)) + sum(S[:n%len(B)]))

if end >= n:
    print(sum(B[:n]))
else:
    n -= end+1
    # print("newn",n)
    ans = sum(B[:end+1])
    # print("ans",ans)
    ans += sum(B[end+1:]) * (n // (len(S)-end-1))
    # print("ans",ans)
    ans += sum(B[end+1:end+1+n % (len(S)-end-1)])
    print(ans)

Measured memory_bytes: 72984
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int i,n,dice[]=new int[6],swap=0;
        String com;
        for(i=0;i<6;i++) {
        	dice[i]=scan.nextInt();
        }
        com=scan.next();
        n=com.length();
        for(i=0;i<n;i++) {
        	switch(com.charAt(i)) {
        		case 'N':
        			swap=dice[0];
        			dice[0]=dice[1];
        			dice[1]=dice[5];
        			dice[5]=dice[4];
        			dice[4]=swap;
        			break;
        		case 'E':
        			swap=dice[0];
        			dice[0]=dice[3];
        			dice[3]=dice[5];
        			dice[5]=dice[2];
        			dice[2]=swap;
        			break;
        		case 'W':
        			swap=dice[0];
        			dice[0]=dice[2];
        			dice[2]=dice[5];
        			dice[5]=dice[3];
        			dice[3]=swap;
        			break;
        		case 'S':
        			swap=dice[0];
        			dice[0]=dice[4];
        			dice[4]=dice[5];
        			dice[5]=dice[1];
        			dice[1]=swap;
        			break;
        		default:
        			break;
        	}
        }
        System.out.println(dice[0]);
    }
}


Measured memory_bytes: 26396
def main():

    A, B, K = map(int, input().split())
    for i in range(K):
        if i % 2 == 0:
            if A % 2 == 1:
                A -= 1
            B += A//2
            A -= A//2
        else:
            if B % 2 == 1:
                B -= 1
            A += B//2
            B -= B//2
    return str(A) + " " + str(B) 

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,m,x;cin>>n>>m>>x;
  int cost_ahead=0,cost_back=0;
  int a[m];for(int i=0;i<m;i++){
    cin>>a[i];
    if(a[i]<x)cost_back++;
    else if(a[i]>=x)cost_ahead++;
  }
  cout<<min(cost_back,cost_ahead)<<endl;
  return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector <int> ar1(n);
	vector <int> ar2(n);
	for (int i = 0; i < n; ++i) {
		cin >> ar1[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> ar2[i];
	}
	int ans = 0;
	for (int d = 0; d < n; ++d) {
		int cur = 0;
		for (int i = 0; i <= d; ++i) {
			cur += ar1[i];
		}
		for (int i = d; i < n; ++i) {
			cur += ar2[i];
		}
		ans = max(ans, cur);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll k,x;
int main(){
    cin>>k>>x;
    for(ll i=max(-1000000LL,x-k+1);i<=min(x+k-1,1000000LL);i++){
        cout<<i<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
    Author : DemonStar
*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    ll n;
    cin >> n;
    vl v(n);
    cin >> v;
    rep(i, 1, n) v[i] += v[i - 1];
    vector<vl> dp(n, vl(n, 1e18));
    for (int i = n - 1; i >= 0; i--)
    {
        for (int j = i; j < n; j++)
        {
            if (i == j)
                dp[i][j] = 0;
            else
            {
                for (int k = i; k < j; k++)
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + v[j] - (i ? v[i - 1] : 0));
            }
        }
    }

    cout << dp[0][n - 1] << endl;

#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
using namespace std;


#include <iostream>
using namespace std;

struct 
pair<int, int> a[200002];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		if (i == a[n-1].second)
			cout << a[n-2].first << endl;
		else
			cout << a[n-1].first << endl;
	}
}

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

int isPal(string s){
    int n = s.size();
    for(int i = 0; i < n/2; i++){
        if(s[i] != s[n-1-i]) return 0;
    }
    return 1;
}

// cout << "Case #"<< k << " "<<
int a[213456], arr[213456], i1;

void pre(int arr[], int n){
      i1 = 1e5+1;
     a[i1] = arr[1];
     for(int i = 2; i <= n; i++){
         if(i%2){
            a[i1+i/2] = arr[i];
         }
         else{
            a[i1-i/2] = arr[i];
         }
     }

}

int main() {
	   int n;
	   cin >> n;
	   for(int i = 1; i <= n; i++) cin >> arr[i];
	   pre(arr, n);
	   if(n%2){
	      for(int j = i1+n/2; j >= i1-n/2; j--){
              cout << a[j] << " ";
	      }
	   }
	   else{
          for(int j = i1-n/2; j < i1+n/2; j++){
            cout << a[j] << " ";
          }
	   }
         return 0;
}


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

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

    int p1,p2,p3;
    int cnt = 0;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                p1 = -1;
                p2 = -1;
                p3 = -1;
                for(int c=0; c<n; c++){
                    if(s[c]-'0'==i){
                        p1 = c;
                        break;
                    } 
                }
                if(p1==-1) continue;
                for(int c=p1+1; c<n; c++){
                    if(s[c]-'0'==j){
                        p2 = c;
                        break;
                    } 
                }
                if(p2==-1) continue;
                for(int c=p2+1; c<n; c++){
                    if(s[c]-'0'==k){
                        p3 = c;
                        break;
                    } 
                }
                if(p3==-1) continue;
                cnt++;
            }
        }
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
const long long size=2e+5;
	long long a[size],x[size];
	long long n,s;
int main()
{	
	cin>>n>>a[0];
     x[0]=a[0];
	 s=a[0]; 
	for(int i=1;i<n;i++)
	{
		cin>>a[i];
	    x[i]=x[i-1]+a[i];
	    s+=a[i];
	}
	long long min=2e+10,result;
	for(int i=0;i<n-1;i++)
	{
	result=abs(2*x[i]-s);
	if(min>result)
	min=result;
	}
	cout<<min;
	return 0;
}
	

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n,a[100005];
cin>>n;
rep(i,0,n-1)cin>>a[i];
int c=1,f=0;
rep(i,1,n-1)
{
	if(f==0)
	{
		if(a[i]>a[i-1])f=1;
		else if(a[i]<a[i-1])f=-1;
	}
	else if(f==1)
	{
		if(a[i]<a[i-1])c++,f=0;
	}
	else
	{
		if(a[i]>a[i-1])c++,f=0;
	}
}
ol(c);
return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  string s;
  cin>>s;
  int n=s.size();

  vector<ll> dai(n,INF);
  vector<ll> sho(n,INF);

  int st=s[0]-'0';
  dai[0]=min(10-st,st+1);
  sho[0]=min(st,11-st);

  repo(i,n){
    int x=s[i]-'0';
    dai[i]=min(dai[i-1]+10-x-1, sho[i-1]+x+1);
    sho[i]=min(dai[i-1]+10-x, sho[i-1]+x);
  }

  cout << sho[n-1] << endl;
}

Measured memory_bytes: 19864
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

//親の場合parには，-(集合のサイズ)を格納
vector<ll> par(1e5+5,-1),dep(1e5+5,0);

//木の根を求める
ll find(ll x){
    if(par[x]<0){
        return x;
    }else{
        //return find(par[x])でも可能だが
        //根をつなぎなおして計算量を落としている
        return par[x]=find(par[x]);
    }
}

//xとyが同じ集合に属するか否か
bool same(ll x, ll y){
    return find(x)==find(y);
}

//xとyの属する集合を併合
void unite(ll x, ll y){
    //同じ集合なら意味なし
    x=find(x);
    y=find(y);
    if(x==y) return;
    //rankの大小でどちらにくっつけるかを判定
    if(dep[x]<dep[y]){
        par[y]+=par[x];
        par[x]=y;
    }else{
        par[x]+=par[y];
        par[y]=x;
        //同じdepのときは，yをxにくっつけ
        //xのdepをプラスする
        if(dep[x]==dep[y]) dep[x]++;
    }
}

//クラスカル法の準備
struct edge{
    int u,v,cost;
};

bool comp(const edge& e1, const edge& e2){
    return e1.cost<e2.cost;
}

int main(){
    int n;
    cin>>n;
    vector<pair<int,pair<int,int>>> pa_x(n),pa_y(n);
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        pa_x[i]={x,{y,i}};
        pa_y[i]={y,{x,i}};
    }

    sort(pa_x.begin(),pa_x.end());
    sort(pa_y.begin(),pa_y.end());
    
    vector<edge> e;
    for(int i=0;i<n-1;i++){
        edge tmp={pa_x[i].second.second,pa_x[i+1].second.second,pa_x[i+1].first-pa_x[i].first};
        e.push_back(tmp);
        tmp={pa_x[i+1].second.second,pa_x[i].second.second,pa_x[i+1].first-pa_x[i].first};
        e.push_back(tmp);
    }
    
    for(int i=0;i<n-1;i++){
        edge tmp={pa_y[i].second.second,pa_y[i+1].second.second,pa_y[i+1].first-pa_y[i].first};
        e.push_back(tmp);
        tmp={pa_y[i+1].second.second,pa_y[i].second.second,pa_y[i+1].first-pa_y[i].first};
        e.push_back(tmp);
    }
    
    //クラスカル法
    sort(e.begin(),e.end(),comp);
    ll ans=0;
    for(int i=0;i<e.size();i++){
        edge tmp=e[i];
        if(!same(tmp.u,tmp.v)){
            unite(tmp.u,tmp.v);
            ans+=tmp.cost;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12400
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    ll count=0;
    cin>>N;
    vector<ll> s;
    ll S;
    rep(i, N){
        cin>>S;
        count+=S;
        s.push_back(S);
    }
    if(count%10!=0){
        cout<<count<<endl; return 0;
    }
    sort(all(s));
    ll dec=count;
    rep(i, N){
        if(s[i]%10!=0){
            dec=s[i];
            break;
        }
    }
    cout<<count-dec<<endl;
    return 0;
}


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

using namespace std;

int main() {
    int t; cin >> t;
    for (int i = 0; i < t; i++) {
        int n, k; cin >> n >> k;
        vector<int> houses(n);
        vector<int> segments(n-1);
        for (int j = 0; j < n; j++) {
            cin >> houses[j];
        }
        for (int j = 0; j < n-1; j++) {
            segments[j] = houses[j+1] - houses[j];
        }
        sort(segments.begin(), segments.end());

        int length = 0;

        if (n <= k) length = 0;
        else {
            for (int j = 0; j < n-k; j++) {
                length += segments[j];
            }
        }

        cout << length << endl;
    }

    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, a;
  cin >> n;
  map<int, int> mp;
  for(int i = 0; i < n; ++i)
  {
    cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for(const auto& m : mp)
  {
    ans += (m.second & 1);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 8308
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

ans = 0
for i in range(n-1):
    if x-a[i] < 0:
        break
    else:
        ans += 1
        x -= a[i]
if x == a[n-1]:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
char a[200005];
int main(){
    int n,bx,by,fx,fy;
    cin>>n>>bx>>by>>fx>>fy;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        /*if(a[i]=='#' && a[i-1]=='#')
            check1=1;*/
    }
    for(int i=bx+1;i<=fx;i++){
        if(a[i]=='#' && a[i-1]=='#'){
            cout<<"No";
            return 0;
        }

    }
    for(int i=by+1;i<=fy;i++){
        if(a[i]=='#' && a[i-1]=='#'){
            cout<<"No";
            return 0;
        }

    }
    if(fx<fy)
        cout<<"Yes";
    else{
        for(int i=by+1;i<=fy+1;i++){
            if(a[i]=='.' && a[i-1]=='.' && a[i-2]=='.'){
                cout<<"Yes";
                return 0;
            }
        }
        cout<<"No";
    }

}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int a[10000],b,x,i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x);
		a[i]=x;
	}
	printf("%d",a[n-1]);
	for(i=n-2;i>=0;i--){
		printf(" %d",a[i]);
	}
	printf("\n");
	
	return 0;
}



Measured memory_bytes: 2072
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

import java.util.*;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static ArrayList<String> strList = new ArrayList<String>();
	static ArrayList<String> strList2 = new ArrayList<String>();
	static ArrayList<Integer> intList = new ArrayList<Integer>();
	static HashMap<String,Integer> Hmap = new HashMap<String,Integer>();
	public static void main(String[] args) {

		String str = sc.nextLine();

		if(str.equals("1")) {
			System.out.println("0");
		}
		else {
			System.out.println("1");
		}

	}
}


Measured memory_bytes: 26976
s = gets.chomp.split('')
count = 0
max = 0
k = 0
while k < s.size
  if /[ACGT]/ =~ s[k] #マッチしたらカウントを増やす
    count += 1
  else #マッチしなかったら
    count = 0 #カウントをリセット
  end
  if max < count #カウントが今までで最大なら
    max = count #回答を更新
  end
  k += 1
end
puts max


Measured memory_bytes: 14236
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in(), a = in(), b = in();
	ll cnt[3] = { 0,0,0 };
	REP(i, n) {
		ll p = in();
		++ *(p <= a ? cnt : p <= b ? cnt + 1 : cnt + 2);
	}
	cout << *min_element(cnt, cnt + 3) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

/** Problem0067 : The Number of Island
 ** なぜか通らない **/
char map[12][13];

void dfs(int x, int y);

void dfs(int x, int y)
{
	map[x][y] = '0';
	
	if (0 <= x-1 && map[x-1][y] == '1') dfs(x-1, y);
	if (x+1 < 13 && map[x+1][y] == '1') dfs(x+1, y);
	if (0 <= y-1 && map[x][y-1] == '1') dfs(x, y-1);
	if (y+1 < 13 && map[x][y+1] == '1') dfs(x, y+1);
}

int main()
{
	int count;
	
	while (1) {
		count = 0;
		
		for (int i=0; i<12; i++)
			for (int j=0; j<12; j++)
				cin >> map[i][j];
		
		if (cin.eof()) break;
		
		for (int i=0; i<12; i++)
			for (int j=0; j<12; j++)
				if (map[j][i] == '1') {
					dfs(j, i);
					count++;
				}
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll long long

int main() {

    while (true) {
        //入力
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;

        int ans = 0;
        rep(i, n) {
            for (int j = i + 1;j < n;++j) {
                for(int k=j+1;k<n;++k) {
                    if (i+1 + j+1 + k+1 == x)
                        ++ans;
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,W = inpl() 
a = [inpl() for _ in range(n)]
a.sort(key = lambda x:x[1], reverse = True)
a.sort(key = lambda x:x[0])
b = [[0] for _ in range(4)]
f = a[0][0]
ind = 0
for i in range(n):
    w,v = a[i]
    if w != f:
        ind += 1
        f = w
    b[ind].append(b[ind][-1] + v)
f = a[0][0]
v,x,y,z = [len(x) for x in b]
# print(b)
li = itertools.product(range(v),range(x),range(y),range(z))
res = 0
for tmp in li:
    # print(tmp)
    ww = sum(tmp[i]*(f+i) for i in range(4))
    vv = sum(b[i][tmp[i]] for i in range(4))
    # print(ww,vv)
    if ww <= W:
        res = max(res, vv)
print(res)

Measured memory_bytes: 70248