akhauriyash/Code-Regression huggingface dataset:
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	int out=-inf;
	rep(i,n)loop(j,i,n+1){//[i,j)
		vi t;
		rep(k,i)t.pb(in[k]);
		loop(k,j,n)t.pb(in[k]);
		int c=m-i-(n-j);
		if(c<0)continue;
		sort(all(t));
		int s=0;
		rep(k,t.size())s+=t[k];
		rep(k,t.size())if(c&&t[k]<0){
			c--;
			s-=t[k];
		}
		cmax(out,s);
	}
	
	cout<<out<<endl;
}











Measured memory_bytes: 256
def abc178d():
    s = int(input())
    dp = [[0] * (s+1) for _ in range(700)]
    for j in range(3, s+1):
        dp[0][j] = 1
    for i in range(1, 700):
        for j in range((i+1)*3, s+1):
            if j == (i+1)*3:
                dp[i][j] = sum(dp[i-1][i*3:j-2])
            else:
                dp[i][j] = dp[i][j-1] + dp[i - 1][j-3]
    cnt = 0
    for i in range(0, 700):
        cnt += dp[i][s]
    print(cnt%(pow(10, 9)+7))
abc178d()

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

const int N = 100010;
typedef long long ll;

char s[N], t[N];

int main(){
    int n, m;
    scanf("%d%d%s%s", &n, &m, s, t);
    ll lcm = 1ll * n * m / std::__gcd(n, m);
    for (int i = 0, j = 0; i < n && j < m;){
        ll x1 = i * (lcm / n);
        ll x2 = j * (lcm / m);
        if (x1 < x2){
            ++ i;
        }
        else if (x1 > x2){
            ++ j;
        }
        else{
            if (s[i] != t[j]){
                puts("-1");
                return 0;
            }
            ++ i, ++ j;
        }
    }
    printf("%lld\n", lcm);
    return 0;
}

Measured memory_bytes: 384
<?php
  
  fscanf(STDIN,"%d%d",$h,$w);
$a_li=array();
for($i=0;$i<$h;$i++){
  $a_li[]=explode(" ",trim(fgets(STDIN)));
}

//print_r($a_li);
for($i=0;$i<$h+2;$i++){
  $flag=false;

  for($j=0;$j<$w+2;$j++){
    if($i==0 || $i==($h+2)-1){
      echo "#";
    }elseif($j==0 || $j==($w+2)-1){
      echo "#";
    }else{
      if($flag){
        continue;
      }
      echo $a_li[$i-1][0];
      $flag=true;
    }
  }
  echo "\n";
}



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

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> c(N,0);
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		c[a-1]++;
		c[b-1]++;
	}
	for(int i=0;i<N;i++){
		if(c[i]%2==1){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int year, month, day;
char mark;

int main(void) {
    // insert code here...
    cin >> year >> mark >> month >> mark >> day;
//    cout << year << " " << month << " " << day << endl;
    if(month > 4){
        cout << "TBD" << endl;
    }else{
        cout << "Heisei" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 384
t = input()
l = t.split(" ")
N = int(l[0])
K = int(l[1])
count = 0
numbers = list(range(1, N+1))
while True:
    if len(numbers) >= K:
        numbers.pop(0)
        count = count + 1
    else:
        print(count)
        break


Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
import collections
import itertools

def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    dp = collections.defaultdict(int)

    for i,x in enumerate([a,b,c]):
        dp[0,i] = x[0]

    for i,abc in itertools.islice(enumerate(zip(a,b,c)),1,None):
        for p,q in ((p,q) for p in range(3) for q in range(3) if p != q):
            dp[i,p] = max(dp[i,p], dp[i-1,q] + abc[p])

    print(max([dp[N-1,c] for c in range(3)]))


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    c = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, a, b, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 59392
#include<iostream>
#include<vector>
#include<map>
#include<set>
using namespace std;

int main(){
	int n;
	cin>>n;
	
	vector<int> a(n);
	
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	if(n%2==0){
		for(int i=0;i<n;i+=2){
			cout<<a[n-i-1]<<" ";
		}
		
		for(int i=0;i<n;i+=2){
			cout<<a[i]<<" ";
		}
	}else{
		for(int i=0;i<n;i+=2){
			cout<<a[n-i-1]<<" ";
		}
		
		for(int i=1;i<n;i+=2){
			cout<<a[i]<<" ";
		}
	}
	
	cout<<endl;
	
	
	
	return 0;
}

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


int main()
{
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	if(A+B>C+D)
	{
		cout<<"Left"<<endl;
	}
	else if(A+B<C+D)
	{
		cout<<"Right"<<endl;
	}
	else
	{
		cout<<"Balanced"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3636
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


int main()
{
	int N, M;
	cin >> N >> M;

	vector<P> v(M);
	rep(i, M)
	{
		cin >> v[i].first >> v[i].second;
	}

	rep(i, 1000)
	{
		string s = to_string(i);

		if (s.length() != N) continue;

		bool flg = true;

		for (auto p : v)
		{
			if (s[p.first - 1] - '0' != p.second)
			{
				flg = false;
				break;
			}
		}

		if (flg)
		{
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}

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

struct Edge {
  int to, id;
};

vector<vector<Edge>> G;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
  int k = 1;
  for (int i = 0; i < G[v].size(); i++) {
    int to = G[v][i].to, ei = G[v][i].id;
    if (to == p) continue;
    if (k == c) ++k;
    ans[ei] = k++;
    dfs(to, ans[ei], v);
  }
}

void Main() {
  int n;
  cin >> n;
  G.resize(n);
  ans.resize(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back((Edge){b, i});
    G[b].push_back((Edge){a, i});
  }
  dfs(0);
  int mx = 0;
  for (int i = 0; i < G.size(); i++) {
    mx = max(mx, int(G[i].size()));
  }
  cout << mx << endl;
  for (int i = 0; i < n - 1; i++) {
    cout << ans[i] << endl;
  }
}

int main() {
std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 8320
#include<stdio.h>

int d[50];

int fi(int n)
{
  if(n==0 || n==1) return d[n] = 1;
  if(d[n] != -1) return d[n];
  return d[n] = fi(n-1) + fi(n-2);
}

int main()
{int n,i;
  for(i=0;i<50;i++) d[i] = -1;
  scanf("%d",&n);
  printf("%d\n",fi(n));

  return 0;
}



Measured memory_bytes: 2728
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007


int main()
{
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for(int i = 0; i < n; i++){
		int h;
		cin >> h;
		if(h >= k) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define min(a,b) (a<b)?(a):(b)

int ans(int n);

int main()
{
    int n;
    scanf("%d",&n);
    printf("%d",ans(n));
}

int ans(int n)
{
    int flag=0;
    if(n<6)return n;
    if(n<80)flag=1;
    int six=6*6*6*6*6*6;
    int nine=9*9*9*9*9;
    while(n-six<0)six/=6;
    while(n-nine<0)nine/=9;
    if(flag)
    return min((ans(n-six)+1),(ans(n-nine)+1));
    else return min((ans(n%six)+(n/six)),(ans(n%nine)+(n/nine)));
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int flag, swap, count=0, i, j, n, A[100];

  scanf("%d",&n);
  for( i=0 ; i<n ; i++ )
    scanf("%d",&A[i]);

  flag=1;
  while(flag){
    flag = 0;
    for( j=n-1 ; j>0 ; j-- ){
      if(A[j]<A[j-1]){
	swap = A[j];
	A[j] = A[j-1];
	A[j-1] = swap;
	count++;
	flag = 1;
      }
    }
  }
  for( i=0 ; i<n-1 ; i++ )
    printf("%d ",A[i]);
  printf("%d\n",A[i]);
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#define max 100000
#define sentinel 2000000000

typedef struct{
  char suit;
  int value;
} card;

card l[max/2+2],r[max/2+2];

void merge(card*,int,int,int,int);
void mergeSort(card*,int,int,int);
void quickSort(card*,int,int,int);
int partition(card*, int, int,int);

int main(){

  int n,i,v;
  card a[max],b[max];
  char s[10];
  int flag = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",s,&v);
    a[i].suit = b[i].suit = s[0];
    a[i].value = b[i].value = v;
  }

  mergeSort(a,n,0,n);
  quickSort(b,n,0,n-1);

  for(i=0;i<n;i++){
    if( a[i].suit != b[i].suit ) flag = 0;
  }

  if(flag == 1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",b[i].suit, b[i].value);
  }
  
  return 0;
}

void merge(card a[], int n, int left, int mid, int right){

  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0; i<n1 ;i++) l[i] = a[left + i];
  for(i=0; i<n2; i++) r[i] = a[mid + i];
  l[n1].value = r[n2].value = sentinel;
  i = j = 0;
  for(k=left; k<right; k++){
    if(l[i].value <= r[j].value){
      a[k] = l[i++];
    }
    else {
      a[k] = r[j++];
    }
  }
}

void mergeSort(card a[], int n, int left, int right){

  int mid;
  if(left + 1 <right){
    mid = (left + right) / 2;
    mergeSort(a, n, left, mid);
    mergeSort(a, n, mid, right);
    merge(a, n,left, mid, right);
  }
}

int partition(card a[], int n, int p, int r){

  int i, j;
  card t, x;
  x = a[r];
  i = p - 1;
  for(j=p; j<r; j++){
    if(a[j].value <= x.value){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }
  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;
  return i+1;
}

void quickSort(card a[], int n, int p, int r){

  int q;
  if( p<r ){
    q = partition(a,n,p,r);
    quickSort(a,n,p,q-1);
    quickSort(a,n,q+1,r);
  }
}



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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B) cout << C << endl;
    else if(A != B && B == C) cout << A << endl;
    else cout << B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmax(a,b) a=max(a,b);
#define chmin(a,b) a=min(a,b);
class Segtree{
	
	private:
	int V;
	typedef struct st{
		ll a;
	}st;
	st st0=(st){(ll)1e18};
	typedef struct op{
		ll a;
	}op;
	op op0=(op){0};
	st f(st p,st q){
		return (st){min(p.a,q.a)};
	}
	void g(st &p,op q){
		p.a+=q.a;
	}
	void h(op &p,op q){
		p.a+=q.a;
	}
	
	st *dat;
	op *laz;
	
	st propagate(ll k){
		if(k<V){
			h(laz[k*2],laz[k]);
			h(laz[k*2+1],laz[k]);
		}
		g(dat[k],laz[k]);
		laz[k]=op0;
		return dat[k];
	}
	void upd(ll l,ll r,op p){
		l+=V,r+=V+1;
		for(ll d=20;d>=0;d--){
			propagate(l>>d);
			propagate(r>>d);
		}
		for(ll a=l,b=r;a<b;a>>=1,b>>=1){
			if(a&1){h(laz[a],p);a++;}
			if(b&1){b--;h(laz[b],p);}
		}
		for(ll a=l,b=r;a+b;a>>=1,b>>=1){
			dat[a/2]=f(propagate(a/2*2),propagate(a/2*2+1));
			dat[b/2]=f(propagate(b/2*2),propagate(b/2*2+1));
		}
	}
	st qry(ll l,ll r){
		l+=V,r+=V+1;
		for(ll d=20;d>=0;d--){
			propagate(l>>d);
			propagate(r>>d);
		}
		st L=st0,R=st0;
		for(ll a=l,b=r;a<b;a>>=1,b>>=1){
			if(a&1){L=f(L,propagate(a));a++;}
			if(b&1){b--;R=f(propagate(b),R);}
		}
		st res=f(L,R);
		return res;
	}
	
	public:
	void init(int ns){
		V=1;
		while(V<=ns)V*=2;
		dat=new st[2*V];
		laz=new op[2*V];
		for(int i=0;i<2*V;i++){
			//dat[i]=st0;
			dat[i]=(st){0};
			laz[i]=op0;
		}
	}
	void update(ll l,ll r,ll a){
		upd(l,r,(op){a});
	}
	ll query(ll l,ll r){
		st res=qry(l,r);
		return res.a;
	}
};
Segtree seg;

int main(){
	int n,q;
	cin>>n>>q;
	seg.init(n);
	rep(i,n)seg.update(i,i,0);
	while(q--){
		ll p,s,t,x;
		cin>>p;
		if(p==0){
			cin>>s>>t>>x;
			seg.update(s,t,x);
		}
		if(p==1){
			cin>>s>>t;
			cout<<seg.query(s,t)<<"\n";
		}
	}
}



Measured memory_bytes: 7212
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int N,M;
int P[20];
bool StoD[20][20];

int ans = 0;
int main() {
  cin >> N >> M;
  rep(i,M) {
    int k;
    cin >>k;
    rep(j,k){
      int s;
      cin >> s;
      StoD[s-1][i] = true;
    }
  }
  rep(i,N) {
    rep(j,M) {
      cerr << StoD[i][j] << " ";
    }
    cerr << endl;
  }
  rep(i,M) {
    cin >> P[i];
  }
  rep(i,(1<<N)){
    int tmp[20] = {0};
    rep(j,N){
      if (i & (1 << j)){
        rep(k,N){
          if(StoD[j][k]) tmp[k]++;
        }
      }
    }
    // check
    bool isOK = true;
    rep(j,M){
      if (tmp[j]%2 != P[j]) isOK = false;
    }
    if (isOK) {
      cerr << i << endl;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    ll n, w;
    cin >> n >> w;
    vector<ll> cap(n + 1), val(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> cap[i] >> val[i];
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= w; j++){
            if(j >= cap[i]){
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - cap[i]] + val[i]);
            }
            else{
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[n][w] << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long A, long long B){
  cout << A * B << endl;
}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  cout << (N - 1) / 2 + 1 << endl;
  return 0;
}

Measured memory_bytes: 3628
In=input()
A=int(In[0])
B=int(In[1])
C=int(In[2])
D=int(In[3])

tot=A
S=''
for bits in range(1<<3):
    if bits & 1:
        tot += B
        S += '+'
    else:
        tot -= B
        S += '-'
    if bits & 1<<1:
        tot += C
        S += '+'
    else:
        tot -= C
        S += '-'
    if bits & 1<<2:
        tot += D
        S += '+'
    else:
        tot -= D
        S += '-'
    if tot==7:
        print(str(A)+S[0]+str(B)+S[1]+str(C)+S[2]+str(D)+'=7')
        quit()
    else:
        S=''
        tot=A
        pass

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

using namespace std;

#define ll long long

void solve(){
  ll d, t, s;
  cin >> d >> t >> s;
  if(d<=t*s){
    cout << "Yes\n";
    return;
  }
  cout << "No\n";
}

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


Measured memory_bytes: 3616
n, m = [int(i) for i in input().split(" ")]
x = [0] * n
y = [0] * n
z = [0] * n

for i in range(0, n):
    xi, yi, zi = [int(i) for i in input().split(" ")]
    x[i] = xi
    y[i] = yi
    z[i] = zi

e = []

def sort_append(b):
    global e
    s = sorted([x[i] * b[0] + y[i] * b[1] + z[i] * b[2] for i in range(0, n)], reverse=True)
    e.append(sum(s[0:m]))
    
def ser(b):
    if len(b) == 3:
        sort_append(b)
    else:
        ser(b + [1])
        ser(b + [-1])

ser([])
print(max(e))

Measured memory_bytes: 3188
#include <stdio.h>

int main(void) {
  int a,b,t;
  int count=0;
  scanf("%d%d%d",&a,&b,&t);
  for(int i=a;i<=t+0.5;i+=a) {
    count+=b;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    if(A < B)swap(A,B);
    int sum = A;
    A--;
    sum += max(A,B);
    cout << sum << endl;
}

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

class C
{
	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var h = read();
		long m = h[1], v = 0L;
		foreach (var x in new int[h[0]].Select(_ => read()).OrderBy(x => x[0]))
		{
			if (x[1] >= m) { v += x[0] * m; break; }
			v += x[0] * x[1];
			m -= x[1];
		}
		Console.WriteLine(v);
	}
}


Measured memory_bytes: 25656
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	ll res=0;
	for(int i=1;i<=n;i++) if(i%3!=0&&i%5!=0) res+=i;
	cout<<res<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION
void solve(void)
{

  string str;
  cin>>str;
  bool check = 0;
  for (int i = 0; i < str.size(); i++)
  {
    /* code */
    if(str[i] == '7')check = 1;
  }
  if(check)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 3656
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(input())

two_dices = (N-1) // 11
remain = N % 11
ans = 2 * two_dices
if 1 <= remain <= 6:
    ans += 1
else:
    ans += 2


print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n;
int mod = 1000000007;
vector<vector<int>> adj, dp;
vector<int> fact;
int solve(int man, int mask_women)
{
    if(man >= n)
        return 1;
    if(dp[man][mask_women] != -1)
        return dp[man][mask_women];
    int count = 0;
    for(int i = 0; i < adj[man].size(); i++)
    {
        int women = adj[man][i];
        bool b = mask_women & (1 << women);
        if(b == 0)
        {
            int new_mask_women = mask_women;
            new_mask_women |= (1 << women);
            count = (count + solve(man + 1, new_mask_women)) % mod;
        }
    }
    dp[man][mask_women] = count;
    return count;
}

int main()
{
    cin >> n;
    adj = vector<vector<int>> (n);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            int x;
            cin >> x;
            if(x == 1)
                adj[i].push_back(j);
        }
    }
    int mask = 0;
    dp = vector<vector<int>> (n + 1, vector<int>(1 << ( n + 1), -1));
    cout << solve(0, 0);
    return 0;
}

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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  std::vector<std::vector<int>> a(n,std::vector<int>(m));
  std::vector<int> c(n);
  rep(i,n) {
    cin >> c.at(i);
    rep(j,m) cin >> a.at(i).at(j);
  }

  int ans = INF;
  // 000,001,,,111などn桁分bitで表す
  rep(s,1<<n) {
    int cost = 0;
    std::vector<int> d(m);
    // 001などで一桁ずつ調べる
    // 1となっているのが本を購入する場合
    rep(i,n) {
      if ((s>>i)&1) {
        cost += c.at(i);
        // 購入した結果得られるアルゴリズム理解度
        rep(j,m) d.at(j) += a.at(i).at(j);
      }
    }
    bool ok = true;
    // 理解度が足りていないものが一つでもあればfalse
    rep(j,m) if (d.at(j) < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,k,x,y,sum=0;
  cin >> n >> k >> x >> y;
  for(int i=0;i<n;i++){
    if(k!=0){
      sum+=x;
      k--;
    } else{
      sum+=y;
    }
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
	char z[103];
	int n, m, i, j;
	while(scanf("%d%d",&n,&m)!=EOF) {
		for(i=-2;i<m;i++) {
			printf("#");
		}
		printf("\n");
		for(j=0;j<n;j++) {
			scanf("%s",z);
			printf("#%s#\n",z);
		}
		for(i=-2;i<m;i++) {
			printf("#");
		}
		printf("\n");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,M; cin >> N >> M;
    vc<pair<int,vi>> v;
    rep(i,M){
        int a,b;
        cin >> a >> b;
        vi A(b);
        rep(j,b){
            cin >> A[j];
            A[j]--;
        }
        v.eb(pair<int,vi>(a,A));
    }

    vi dp(5000,INF);
    dp[0]=0;
    rep(i,M){
        int now=0;
        for(auto a:v[i].se){
            now|=(1<<a);
        }
        rep(j,1<<N){
            chmin(dp[j|now],dp[j]+v[i].fi);
        }
    }
    if(dp[(1<<N)-1]==INF) cout << -1 << endl;
    else cout << dp[(1<<N)-1] << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
  int a, b, c;

  cin >> a >> b >> c;

  if(a == b && b == c){
    cout << 1 << endl;
  }else if(a == b && b != c){
    cout << 2 << endl;
  }else if(a == c && a !=b){
    cout << 2 << endl;
  }else if(a != b && b == c){
    cout << 2 << endl;
  }else{
    cout << 3 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

count = [0] * (n+1)
for x in a:
    count[x] += 1

def comb(x):
    return x * (x-1) // 2

s = 0
for x in count:
    s += comb(x)

for x in a:
    print(s - comb(count[x]) + comb(count[x] - 1))

Measured memory_bytes: 25644
#include <bits/stdc++.h>
using namespace std;
inline void boost(){ 
	ios_base::sync_with_stdio(0); 
	cin.tie(0); 
}

int f[90001];
int main(){
	boost();
	int h,w,d;
	cin>>h>>w>>d;
	map <int, pair <int, int> >adr;
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			int x;
			cin>>x;
			adr[x].first = i;
			adr[x].second = j;
		}
	}
	for(int i=1; i<=h*w; i++){
			if( i <= d)
				f[i] = 0;
			else{
				f[i] = f[i-d] + abs(adr[i].first - adr[i-d].first) + abs(adr[i].second - adr[i-d].second);
			}
	}
	int q;
	cin>>q;
	int z,y;
	vector <int> ans;
	for(int i=0; i<q; i++){
		cin>>z>>y;
		ans.push_back(f[y] - f[z]);
	}
	for(int i = 0 ; i<ans.size(); i++){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 7672
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        s: String
    }
    let acgt = ['A', 'C', 'G', 'T'];
    let mut max_len = 0;
    for i in 0..s.len() {
        let first = i;
        for k in 0..s.len() - i {
            let last = s.len() - k;

            let mut is_acgt = true;
            for idx in first..last {
                let elem = s.chars().nth(idx).unwrap();
                let mut has_acgt = false;
                for c in &acgt {
                    if elem == *c {
                        has_acgt =true;
                        break;
                    }
                }
                if !has_acgt {
                    is_acgt = false;
                    break;
                }
            }

            if is_acgt {
                let len = last - first;
                max_len = max_len.max(len);
            }
        }
    }
    println!("{}", max_len);
}


Measured memory_bytes: 2140
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()




int main() {
	ll N, X;
	cin >> N >> X;

	ll n = N, x = X - 1, len_n = (1ull << (n + 2)) - 3, ans = 0;
	while(true) {
		if (n == 0) { ++ans; break; }
		else if (x == 0) break;
		else if (x == (len_n - 1) / 2) { ans += 1ull << n;	break; }
		else if (x == len_n - 1) { ans += (1ull << (n + 1)) - 1; break; }

		else if (x < (len_n - 1) / 2) --x;
		else {
			ans += 1ull << n;
			x -= (1ull << (n + 1)) - 1;
		}
		len_n = (len_n - 3) / 2;
		--n;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)

for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]

print(ans)

Measured memory_bytes: 3060
import numpy as np
N = int(input())
W_list = [int(i) for i in input().split(" ")]
ans = np.abs(W_list[0] - np.sum(W_list[1:N]))
sum_list = np.sum(W_list)
for j in range(2, N):
    difference = np.abs(sum_list - 2 * np.sum(W_list[:j]))
    if difference < ans:
        ans = difference
    else:
        break
 
print(ans)

Measured memory_bytes: 13688
from itertools import product

MAX = 10**4
N, Ma, Mb = map(int, input().split())
chems = [tuple(map(int, input().split())) for _ in range(N)]
chems = sorted(chems, key=lambda x: x[2])
rng = range(401)
dp = [[[None for _ in rng] for _ in rng] for _ in range(N+1)]
dp[0][0][0] = MAX
for i, (a, b, c) in enumerate(chems):
    for j, k in product(rng, repeat=2):
        if j < a or k < b:
            dp[i+1][j][k] = dp[i][j][k]
        else:
            if dp[i][j-a][k-b] == MAX:
                dp[i+1][j][k] = min(c, dp[i][j][k]) if dp[i][j][k] is not None else c
            elif dp[i][j-a][k-b] is not None:
                dp[i+1][j][k] = min(dp[i][j-a][k-b] + c, dp[i][j][k]) if dp[i][j][k] is not None else dp[i][j-a][k-b] + c
            else:
                dp[i+1][j][k] = dp[i][j][k]
ans = MAX
for j, k in product(rng, repeat=2):
    if j == 0 or k == 0: continue
    if j * Mb == k * Ma and dp[N][j][k] is not None:
        ans = min(ans, dp[N][j][k])
print(-1 if ans == MAX else ans)

Measured memory_bytes: 106204
#include <stdio.h>

int main(){
  int a,b;

  scanf("%d %d",&a,&b);
  
  if (a == b){
    printf("a == b\n"); 
}else if (a<b){
    printf("a < b\n");
  }else if (a <= b){
    printf("a <= b\n");
  }else if (a > b){
    printf("a > b\n");
  }else if (a >= b){
    printf("a >= b\n");
  
  }
  return 0;
    
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int h, n;
  cin >> h >> n;
  int A = 0;
  rep(i, n) {
    int a;
    cin >> a;
    A += a;
  }
  if (h <= A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;

    return 0;
}


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

int main() {
    int x, n;
    cin >> x >> n;
    unordered_map<int,int> m;
    for (int i = -1; i <= 101; i++)  {
        m[i] = false;
    }
    for (int i = 0, temp; i < n; i++) {
        cin >> temp;
        m[temp] = true;
    }
    int j = 0;
    while (true) {
        if (!m[x-j]) {
            cout << x-j;
            return 0;
        } else if (!m[x+j]) {
            cout << x+j;
            return 0;
        }
        j++;
    }
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABCO080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b,x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);

                x = a * n;
            if (x > b)
                x = b; 

            Console.WriteLine(x);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] p = new int[n];
        int count = 0;
        for(int i=0; i<n; i++){
            p[i] = sc.nextInt();
        }

        for(int i=1; i<n-1; i++){
            if((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])){
                count += 1;
            }
        }
        System.out.println(count);

    }
}

Measured memory_bytes: 21972
void main() {
    string[] tmp = readln.split;
    string a = tmp[0], b = tmp[1];
    writeln(a == b ? "H" : "D");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1,s2,u;
	int n,m;
	cin>>s1>>s2>>n>>m>>u;
	if(s1==u)
		cout<<n-1<<' '<<m;
	else
		cout<<n<<' '<<m-1;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn smallest_factor(n: usize) -> usize {
  if n % 2 == 0 { return 2; }
  if n % 3 == 0 { return 3; }
  if n % 5 == 0 { return 5; }

  let mut k = 7;
  for dk in [4,2,4,2,4,6,2,6].iter().cycle() {
    if n % k == 0 { 
      return k; 
    }
    k += dk;
    if k * k >= n {
      return n;
    }
  }
  return n;
}
fn is_prime(n: usize) -> bool {
  smallest_factor(n) == n
}

fn main() {
  input! { 
    x: usize,
  }
  for p in x..2*x {
    if is_prime(p) {
      println!("{}", p);
      break;
    }
  }
}


Measured memory_bytes: 2120
#include <stdio.h>
int main(int argc, char const *argv[]) {

  int i,j;
  int count = 0;
  int num_S;
  int num_T;
  int start,end,middle;


  scanf("%d",&num_S);
  int S[num_S];
  for( i = 0 ; i < num_S ; i++ ){
    scanf("%d",&S[i]);
  }

  scanf("%d",&num_T);
  int T[num_T];
  for( i = 0 ; i < num_T ; i++ ){
    scanf("%d",&T[i]);
  }

  for( i = 0 ; i < num_T ; i++ ){

    start = 0;
    end = num_S;

    while( start < end ){

      middle = ( start + end ) / 2;

      if( S[middle] >T[i] ){
        end = middle;
      }else if( S[middle] < T[i] ){
        start = middle + 1;
      }else if( S[middle] == T[i] ){
        count++;
        break;
      }

    }

  }

  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1184
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

check = 0

for i in range(X+1, Y+1):
    tmp = 0
    for j in range(N):
        if x[j] < i:
            tmp += 1
    for j in range(M):
        if y[j] >= i:
            tmp +=1
    if tmp == N+M:
        check = 1
        break

if check == 1:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
#else
#define DE(...) 0
void debug(...) {}
#endif
const int maxn = 300010;
int n, m, g[maxn], sz[maxn];
int find(int i) { return i == g[i] ? i : g[i] = find(g[i]); }
void merge(int a, int b) {
	if ((a = find(a)) == (b = find(b))) return;
	if (sz[a] < sz[b]) swap(a, b);
	sz[a] += sz[b];
	g[b] = a;
}
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for (int i = 1;i <= n;++i)
		g[i] = i, sz[i] = 1;
	int res = 0;
	while (m--) {
		int a, b;
		cin >> a >> b;
		merge(a, b);
	}
	for (int i = 1;i <= n;++i)
		res = max(res, sz[i]);
	cout << res << '\n';
}



Measured memory_bytes: 5180
import sys

n, m = map(int, input().split())
a_array = [input() for i in range(n)]
b_array = [input() for i in range(m)]

for ai in range(n-m+1):
    for aj in range(n-m+1):
        can = True
        for bi in range(m):
            if a_array[ai+bi][aj:aj+m] != b_array[bi]:
                can = False
                break
        if can:
            print('Yes')
            sys.exit()

print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int,int> PII;
#define MP make_pair

class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }
 
  int find(int x){
	if(par[x] == x)
	  return x;
	return (par[x] = find(par[x]));
  }
 
  void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
 
	if(rank[x] < rank[y])
	  par[x] = y;
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }
 
  bool same(int x, int y){
	return find(x) == find(y);
  }

};


int main(){
  int N, W, H; cin >> N >> W >> H;
  vector<PII> xs(N), ys(N);
  for(int i=0;i<N;++i){
	int x, y; cin >> x >> y;
	xs[i] = MP(x,i), ys[i] = MP(y,i);
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());

  UnionFind uf(N);
  for(int i=0;i+1<N;++i){
	if(xs[i].first == xs[i+1].first)
	  uf.unite(xs[i].second, xs[i+1].second);
	if(ys[i].first == ys[i+1].first)
	  uf.unite(ys[i].second, ys[i+1].second);
  }

  vector<int> cnt(N, 0);
  for(int i=0;i<N;++i)
	cnt[uf.find(i)]++;

  int ans = 0, tot = 0;
  for(int i=0;i<N;++i)
	if(cnt[i] != 0)
	  ++tot, ans += cnt[i] - 1;

  //cout << "(" << tot << ", " << ans << ")" << endl;
  if(tot > 1){
	if(xs[0].first == 1 || xs.back().first == W || ys[0].first == 1 || ys.back().first == H)
	  ans += 2*tot - 2;
	else
	  ans += 2 * tot - 1;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,k;cin >> n  >>k;
    vl v(n);
    rep(i,n){
        ll a;cin >> a;
        a%=k;
        v[i]=a;
    }
    vl cum(n+1,0);
    rep(i,n)cum[i+1]=(cum[i]+v[i])%k;
    unordered_map<ll,ll> ma;
    rep(i,n+1)ma.ins(mp(cum[i],0));
    ll ans=0;
    rep(i,n+1){
        ll p=cum[i];
        ans+=ma[p];
        ma[p]++;
    }
    cout <<ans <<endl;
}

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

int main()
{
	int A, B;
	cin >> A >> B;
	if (B * 2 <= A) {
		cout << A - B * 2 << endl;
	}
	else if(B*2>A){
		cout << 0 << endl;
	}
	
	return 0;
}


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

using namespace std;

const long long int INF=1e10;

int main() {
    int N;
    cin >> N;
    vector<vector<int> > F(N, vector<int>(10));
    for(int n=0; n<N; n++) {
        for(int j=0; j<10; j++) {
            cin >> F[n][j];
        }
    }
    vector<vector<long long int> > P(N, vector<long long int>(11));
    for(int n=0; n<N; n++) {
        for(int j=0; j<11; j++){
            cin >> P[n][j];
        }
    }
    
    long long int ans;
    long long int max_ans=-INF;
    for(int bit=1; bit<(1<<10); bit++) {
        vector<int> count(N, 0);
        ans=0;
        for(int j=0; j<10; j++) {
            if(bit & (1<<j)) {
                for(int n=0; n<N; n++) {
                    if(F[n][j]==1) {
                        count[n]++;
                    }
                }
            }
        }
        for(int n=0; n<N; n++) {
            ans += P[n][count[n]];
        }
        if(ans>max_ans) {
            max_ans = ans;
        }
    }
    
    cout << max_ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>

using namespace std;

void solve()
  {
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	int dp[n];
	memset(dp,INT_MAX,sizeof dp);
	dp[0]=0;
	repA(i,1,n-1)
	{
		if(i-1>=0&&dp[i-1]!=INT_MAX)dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		if(i-2>=0&&dp[i-2]!=INT_MAX)dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
		
	}
	cout<<dp[n-1]<<endl;


  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}
	

Measured memory_bytes: 5128
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

string ans;

void ps(int n,char a){
    for(int i=0;i<n;i++) ans+=a;
    return;
}

int main(){
    int n,x;cin>>n>>x;
    vector<int> A(n);
    rep(i,0,n) cin>>A[i];
    ll count=0;
    rep(i,1,n){
        int a=A[i]+A[i-1]-x;
        if(a<=0) continue;
        if(A[i]>=a){
            A[i]-=a;
            count+=a;
        }else{
            count+=A[i];
            if(A[i-1]>=a-A[i]){
                A[i-1]-=(a-A[i]);
                count+=(a-A[i]);
            }else{
                count+=A[i-1];
                A[i-1]=0;
            }
            A[i]=0;
        }
    }
    cout<<count<<endl;
}    

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

int main()
{
    string str;
    cin >> str;
    int Q;
    cin >> Q;
    bool flag = true;
    for (int q = 0; q < Q; q++)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            flag = (!flag);
        }
        else
        {
            int a;
            char c;
            cin >> a >> c;
            if (flag)
            {
                if (a == 1)
                {
                    str.insert(str.begin(), c);
                }
                else
                {
                    str += c;
                }
            }
            else
            {
                if (a == 1)
                {
                    str += c;
                }
                else
                {
                    str.insert(str.begin(), c);
                }
            }
        }
    }
    if (!flag)
    {
        reverse(str.begin(), str.end());
    }
    cout << str << endl;

    return 0;
}

Measured memory_bytes: 900
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final double a = scanner.nextDouble();
        final double b = scanner.nextDouble();
        final double h = scanner.nextDouble();
        final double m = scanner.nextDouble();

        final double hPi = 2 * Math.PI * ((h + m / 60) / 12d);
        final double mPi = Math.PI * m / 30d;

        System.out.println(Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(hPi - mPi)));
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

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

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

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

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


Measured memory_bytes: 33316