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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    string s;
    cin>>s;
    ll n = s.length();
    Vec v(4);
    rep(i,n){
        if(s[i]=='N')v[0]++;
        if(s[i]=='S')v[1]++;
        if(s[i]=='E')v[2]++;
        if(s[i]=='W')v[3]++;
    }
    bool ok = true;
    if(v[0]>0&&v[1]==0) ok = false;
    if(v[1]>0&&v[0]==0) ok = false;
    if(v[2]>0&&v[3]==0) ok = false;
    if(v[3]>0&&v[2]==0) ok = false;
    Yes(ok);
    return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int min(int a,int b){
    return a < b ? a : b;
}
int main(void){
    int A,B,M;
    cin >> A >> B >> M;
    int a[A],b[B],x[M],y[M],c[M];
    for(int i=0;i<A;i++)cin >> a[i];
    for(int i=0;i<B;i++)cin >> b[i];
    for(int i=0;i<M;i++)cin >> x[i] >> y[i] >> c[i];
    
    int ans = 1000000;
    int mina=1000000,minb=1000000;
    for(int i=0;i<A;i++){
        mina = min(mina,a[i]);
    }
    for(int i=0;i<B;i++){
        minb = min(minb,b[i]);
    }
    ans = mina + minb;
    
    for(int i=0;i<M;i++){
        ans = min(ans,a[x[i]-1]+b[y[i]-1]-c[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5096
#include <stdio.h>

int main()
{
    long n,i,nw[300001],ne[300001],ans=0,wcnt=0,ecnt=0,iti=0;
    char s[3000001];
    scanf("%ld",&n);
    scanf("%s",s);
    for(i=0;i<n;i++){
        if(s[i]=='W'){
            wcnt++;
        }else{
            ecnt++;
        }
        nw[i]=wcnt;
        ne[i]=ecnt;
    }
    long cost=ecnt-ne[0];
    for(i=1;i<n;i++){
        if(cost>nw[i-1]+ecnt-ne[i]){
            cost=nw[i-1]+ecnt-ne[i];
            iti =i;
        }
    }
    for(i=0;i<n;i++){
        if((s[i]=='W'&&i<iti)||(s[i]=='E'&&i>iti)){
            ans++;
        }
    }
    printf("%ld",ans);
    return 0;
}


Measured memory_bytes: 7040
#include <stdio.h>
#include <string.h>
 
int main()
{
 
   int n,k;
    scanf("%d%d",&n,&k);
    
    int d[k],i,j,num;
    for(i=0;i<k;++i)
        scanf("%d",&d[i]);
        
    int flag;

        for(i=n;;++i)
          {  num=i;
             flag=0;
              while(num!=0)
              {
                  for(j=0;j<k;++j)
                    {
                        if(num%10==d[j])
                           {
                               flag=1;
                               break;
                           }
                    }
                    
                    if(flag==1)
                        break;
                        
                    num/=10;
              }
              
              if(flag==0)
                  break;
          }
          
          printf("%d",i);
    
   
}

Measured memory_bytes: 128
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
INF = 1e9

def calc(x):
    a = []
    b = []
    c = []
    res = 0
    for n in range(N):
        m = (((3<<(2*n)) & x) >> (2*n))
        if m == 1:
            a.append(L[n])
        elif m == 2:
            b.append(L[n])
        elif m == 3:
            c.append(L[n])
    for l, t in zip([a, b, c], [A, B, C]):
        if len(l) == 0:
            return INF
        res += 10*max(len(l)-1, 0) + abs(sum(l) - t)
    return res

ans = INF
for x in range(pow(4, N)):
    ans = min(ans, calc(x))
print(ans)

Measured memory_bytes: 3064
n, m, c = map(int, input().split())

b = list(map(int, input().split()))

count = 0

for i in range(n) :
    sum = c
    a = list(map(int, input().split()))
    for j in range(m) :
        sum += a[j] * b[j]
    if sum > 0 :
        count += 1

print(count)

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    string n;
    cin >> n;
    for (int i = 0; i < n.length(); ++i)
    if (n[i] == '9') n[i] = '1';
    else if (n[i] == '1') n[i] = '9';
    cout << n;
}

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

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, ll> psl;
typedef pair<pii, int> tri;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<tri> viii;
 
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<string, int> msi;
typedef map<string, vi> msv;
typedef unordered_map<int, int> umap;
typedef unordered_map<ll, ll> umapl;
typedef priority_queue<int> pq;

#define fi(i,a,b) for(auto i=a;i<b;i++)
#define fd(i,a,b) for(auto i=a;i>=b;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ss second
#define ff first
#define sz(a) a.size()
#define cini(a) int a; cin >> a;
#define cinii(a, b) int a, b; cin >> a >> b;
#define ciniii(a, b, c) int a, b, c; cin >> a >> b >> c;
#define cinl(a) ll a; cin >> a;
#define cinll(a, b) ll a, b; cin >> a >> b;
#define cinlll(a, b, c) ll a, b, c; cin >> a >> b >> c;
#define cinc(c) char c; cin >> c;
#define cins(s) string s; cin >> s;
#define cinss(s1, s2) string s1, s2; cin >> s1 >> s2;
#define cinvi(v, n) vi v(n, 0); fi(i, 0, n) cin >> v[i];
#define cinvl(v, n) vl v(n, 0); fi(i, 0, n) cin >> v[i];
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define flush fflush(stdout)

#define print(v) for (auto it = v.begin(); it != v.end(); ++it) cout << *it << ' '; cout << endl;
#define print2(v) for (auto it = v.begin(); it != v.end(); ++it) cout << *it << endl;
#define printmap(m) for (auto it = m.begin(); it != m.end(); ++it) cout << it->first<<' '<<it->second << endl; cout << endl;
#define disparr(arr,n) for(ll i=0;i<(n);++i)   cout<<arr[i]<<' ';  cout<<endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

#define LC(i) 2*(i)+1
#define RC(i) 2*(i)+2
#define MID(i,j) ((i)+(j))/2
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))

#define nn "\n"
#define sp << " " <<
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int MOD = 1000000007;
const ll INF = 1e18;
const ld PI=3.141592653589793238462643383279502884197169399375105820974944;

int main()
{
	fastio; //Remove for interactive problems

	cinl(k);

	if(k%7 == 0)
		k /= 7;

	if(k%2 == 0)
		cout << -1;
	else
	{
		ll a = 1, ans = 1;
		while(a%k != 0 && ans <= k)
		{
			ans++;
			a = a*10 + 1;
			a %= k;
		}

		if(ans > k)
			ans = -1;
			
		cout << ans;
	}
	

	return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3

# from pprint import pprint

def recur(parr, curp, curi, heads):
    # if dp[curi][heads] != -1:
    # return dp[curi][heads]
    if curi >= len(parr):
        if heads >= len(parr)//2 + 1:
            return curp
        else:
            return 0

    return (recur(parr, curp*parr[curi], curi+1, heads+1)
            + recur(parr, curp*(1-parr[curi]), curi+1, heads))

n = int(input())

parr = [float(i) for i in input().split(' ')]

# print(recur(parr, 1, 0, 0))

dp = [0]*(n+1)
dp[0] = 1

for i in range(n):
    for j in range(i+1, -1, -1):
        # heads
        heads = dp[j-1] if j > 0 else 0
        # tails
        tails = dp[j]
        dp[j] = heads*parr[i-1] + tails*(1-parr[i-1])

print(sum(dp[n//2+1:]))


Measured memory_bytes: 68756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pic pair<int,char>
#define pci pair<char,int>
#define pll pair<ll,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define vic vector<pic>
#define vci vector<pci>
#define vlc vector<plc>
#define vcl vector<pcl>
#define pb push_back
const ll MOD=1e9+7;
const ll INF=1e9;
const ll MAXN=2e5+4;
const ll MAXM=1e5+3;
int dp[MAXN][3];
string s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        dp[i][0]=-INF;
        dp[i][1]=-INF;
        dp[i][2]=-INF;
    }
    dp[0][1]=1;
    if(s[0]!=s[1])dp[1][1]=1;
    dp[1][2]=1;
    int n=s.size();
    for(int i=0;i<n-1;i++)
    {
        if(s[i]!=s[i+1])
        {
            dp[i+1][1]=max(dp[i+1][1],dp[i][1]+1);
        }
        dp[i+1][1]=max(dp[i+1][1],dp[i][2]+1);
        dp[i+2][2]=max(dp[i+2][2],dp[i][1]+1);
        if(!(s[i-1]==s[i+1]&&s[i]==s[i+2]))
        {
            dp[i+2][2]=max(dp[i+2][2],dp[i][2]+1);
        }
    }
    cout<<max(dp[n-1][2],dp[n-1][1])<<endl;
return 0;
}


Measured memory_bytes: 2964
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
int visit[55]={0};
vector<int> v[55];
vector<pair<int,int> >p;
int n,m,k,ans=0;
void dfs(int pos){
	visit[pos]=1;
	for(int i=0;i<v[pos].size();i++){
		if(visit[v[pos][i]]==1)continue;
		if((p[k].fi==pos&&p[k].se==v[pos][i])||(p[k].se==pos&&p[k].fi==v[pos][i]))continue;
		dfs(v[pos][i]);
	}
}
bool check(){
	for(int i=1;i<=n;i++)if(visit[i]==0)return 1;
	return 0;
}
int main(void){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);v[b].pb(a);
		p.pb(mp(a,b));
	}
	for(k=0;k<m;k++){
		memset(visit,0,sizeof(visit));
		dfs(1);
		if(check())ans++;
	}
	cout<<ans;
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  cout  << n % k << endl;
  return 0;
}

Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end
def na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n = inp[0]
tab = na2(2,20000)
tab[0][0] = 1
n.times do |i|
  d=inp[0]
  (0..i*100).each do |j|
    if(tab[i%2][j]==1)
      tab[(i+1)%2][j+d] = 1
      tab[(i+1)%2][j] = 1
    end
  end
end

ans = 0
tab[(n)%2].each.with_index do |d,ind|
  next if(ind % 10 == 0)
  ans = [ans,ind].max if(d == 1)
end
p ans

=begin
3 2
3 3
0 0
=end

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

int main()
{
	for(int n,l;cin>>n>>l && n|l;){
		vector<char> ds(n);
		vector<int> ps(n);
		for(int i=0;i<n;i++) cin>>ds[i]>>ps[i],ps[i]*=2;
		int res=-1,last=-1;
		for(int t=0;;t++){
			if(count(begin(ds),end(ds),'#')==n){
				res=t;
				break;
			}
			last=find_if(begin(ds),end(ds),[](char c){return c!='#';})-begin(ds);
			
			for(int i=0;i<n;i++) if(ds[i]!='#'){
				if(ds[i]=='L') ps[i]--;
				if(ds[i]=='R') ps[i]++;
			}
			
			for(int i=0;i<n;i++) if(ds[i]!='#' && ps[i]==2*l) last=i,ds[i]='#';
			for(int i=0;i<n;i++) if(ds[i]!='#' && ps[i]==0) last=i,ds[i]='#';
			
			for(int i=0;i<n;i++)
				for(int j=i+1;j<n;j++)
					if(ds[i]!='#' && ds[j]!='#' && ps[i]==ps[j] && ps[i]%2==0)
						swap(ds[i],ds[j]);
		}
		cout<<res/2<<' '<<last+1<<endl;
	}
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 1000000000;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  ll n;
  cin>>n;
  n*=3;
  ll a[n];
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  ll ans = 0, count = 0;
  for(int i=n-2;i>n/3-1;i-=2) {
      ans+= a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    std::string s,t,tt;
    long long slen, tlen, lendiff;
    cin >> s >> t;
    slen = s.length();
    tlen = t.length();
    lendiff = tlen - slen;

    if (lendiff != 1) {
        printf("２文字以上異なるNo");
        return 0;
    }
    tt = t.erase(tlen-1);
    if (s == tt) { 
        printf("Yes");
    } else {
        printf("No");
    }
    return 0;
}



Measured memory_bytes: 3728
main :: IO ()                                                                                                              
main = getLine >>= \o -> getLine >>= \e -> putStrLn $ f o e                                                                
                                                                                                                           
f :: [a] -> [a] -> [a]                                                                                                     
f [] [] = []                                                                                                               
f [a] [] = [a]                                                                                                             
f (a:as) (b:bs) = a:b:(f as bs)

Measured memory_bytes: 380
//#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <stack>
#include <queue>
#include <string>
#include <map>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long
#define abs(x) (x<0 ? (-x) : x)
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d %d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld %lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d\n",a);
#define pfii(a,b) printf("%d %d\n",a,b);
#define pfl(a) printf("%lld\n",a);
#define pfll(a,b) printf("%lld %lld\n",a,b);
#define  SIZE 1000000007

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long,long long>> vpl;
typedef pair<int,int> pii;
typedef pair <ll,ll> pll;


int gcd(int a, int b) {
    while (a > 0 && b > 0)
        if (a > b) a %= b;
        else b %= a;
    return a + b;
}

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

int grid [1003][1003];


long long fast_exp(long long n,long long k){
    if(k == 0)
        return 1;
    if(k==1)
        return n;

    long long temp = fast_exp(n,k>>1);

    if((k&1)==1)
        return (n*temp*temp)%SIZE;
    return (temp*temp)%SIZE;

}
ll isprime(ll i){
    if (i==2 || i == 3){
        return 0;
    }
    bool ctr =0;
    for(ll k = 2;k*k <i;k++){
        if(i%k==0)ctr=1;
    }
    if(ctr)return 1;
    else return 0;

}
vl vec(100005,0);
int main()
{
   ll n,k,q;
   cin>>n>>k>>q;
   if(k > q){
       FOR(a,n)printf("Yes\n");
       return 0;
   }
   ll t;


   FOR(a,q){
       getL(t);
       vec[t-1]++;

   }
   FOR(a,n){
       if(k-(q -vec[a]) > 0 ){
           printf("Yes\n");
       }else{
           printf("No\n");
       }
   }


  return 0;
}

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

namespace AtCoder_ABC089_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());

            bool answer = a == 7 || a == 5 || a == 3;

            Console.WriteLine(answer? "YES" : "NO");
        }
    }
}


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

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

  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }

  int position = 0, count = 1;
  for (int i = 0; i < n; i++) {
    position += l.at(i);
    if(position <= x){
      count++;
    }
  }
    cout << count << endl;
}


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

#define repd(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  repd(i,0,n)

using namespace std;


int main(){
    int n;
    cin >> n;
    long ans = pow(n,3);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);




ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

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

ll perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}


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


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}


ll modpow(ll a,ll n,ll mod){
  ll ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

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




/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //vll segtree(524287);
  //ll N=262144;
  ll h,n;
    cin>>h>>n;
  FOR(i,0,n){
    ll a;
      cin>>a;
    h-=a;
  }
  if(h>0){
    cout<<"No\n";
  }
  else{
    cout<<"Yes\n";
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

struct edge{
	ll to,cost;
};
class Dijkstra{
public:
	vector<ll> d;
	vector<vector<edge>> G;
	vector<ll> prev;
	ll s;
	priority_queue<PL,vector<PL>,greater<PL>> q;
	Dijkstra(ll n,ll _s):d(n,1e18),G(n),s(_s),prev(n,-1){
		d[s] = 0;
	}
	void solve(){
		q.push(PL(0LL,s));
		while(q.size()){
			PL p = q.top();
			q.pop();
			ll v = p.second;
			if(d[v] < p.first)continue;
			for(ll i = 0;i < G[v].size();i++){
				edge e = G[v][i];
				if(d[e.to] > d[v] + e.cost){
					d[e.to] = d[v] + e.cost;
					prev[e.to] = v;
					q.push(PL(d[e.to],e.to));
				}
			}
		}
	}
};

int main(){
	ll n,m,s,t;
	cin >> n >> m >> s >> t;
	s--,t--;

	Dijkstra from_s(n,s);
	Dijkstra from_t(n,t);

	for(int i = 0;i < m;i++){
		ll u,v,a,b;
		cin >> u >> v >> a >> b;
		u--,v--;

		from_s.G[u].push_back(edge{v,a});
		from_s.G[v].push_back(edge{u,a});

		from_t.G[u].push_back(edge{v,b});
		from_t.G[v].push_back(edge{u,b});
	}

	from_s.solve();
	from_t.solve();

	vector<ll> accum_max(n);
	accum_max[n-1] = (ll)1e15 - from_s.d[n-1] - from_t.d[n-1];
	for(int i = n-2;i >= 0;i--){
		accum_max[i] = max(accum_max[i+1],(ll)1e15-from_s.d[i]-from_t.d[i]);
	}

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


Measured memory_bytes: 23032
import java.util.Scanner;


public class Main{

	public static void main(String args[]) {
		
		Scanner scan = new Scanner(System.in);
		
		int age = scan.nextInt();
		
		if(age == 1) {
			System.out.println("Hello World");
		}else if(age == 2) {
			int a = scan.nextInt();
			int b = scan.nextInt();
			System.out.println(a + b);
		}
		
		
	}

}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <decimal/decimal>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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(){
    double a,b,x; cin>>a>>b>>x;
    if(a*a*b<x*2){
        cout<<fixed<<setprecision(10)<<atan(2*(a*a*b-x)/(a*a*a))*180/M_PI<<endl;
    }else{
        cout<<fixed<<setprecision(10)<<atan((a*b*b)/(2*x))*180/M_PI<<endl;
    }
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,k;cin>>n>>k;
  double res=0;
  for(int i=1;i<=n;i++){
    int cnt=0;
    ll p = i;
    while(p<=k-1){
      p *= 2;
      cnt++;
    }
    res += (1.0/n * (1.0/pow(2.0, cnt)));
  }
  cout.precision(17);
  cout<<res<<endl;

  return 0;
}


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

int main(){

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    
    map<int, int> count;
    for(int i = 0; i < N; i++) count[A[i]]++;

    vector<int> num;
    for(auto x : count) num.push_back(x.second);
    sort(num.begin(), num.end());

    int ans = 0;
    for(int i = 0; i < (int)num.size() - K; i++) ans += num[i];

    cout << ans << endl; 

    return 0;
}

Measured memory_bytes: 11516
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <tuple>

using namespace std;

#define all(c) begin(c), end(c)
#define dump(c) cerr << "> " << #c << " = " << (c) << endl
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;


int main() {
  for (int N, M, A; cin >> N >> M >> A, (N | M | A) != 0; ) {
    vector<tuple<int, int, int>> lines(M);
    rep(i, M) cin >> get<0>(lines[i]) >> get<1>(lines[i]) >> get<2>(lines[i]);
    sort(all(lines), greater<tuple<int, int, int>>());

    vi num(N);
    rep(i, N) num[i] = i;
    rep(i, M)  swap(num[get<1>(lines[i]) - 1], num[get<2>(lines[i]) - 1]);

    rep(i, N) if (num[i] == A - 1) cout << i + 1 << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<cstdio>
using namespace std;

#define WHITE 0
#define EPS 1e-10
#define GRAY 1
#define BLACK 2
#define MAX_N 1000
#define INF 999999999.99

long double x[MAX_N][MAX_N];
long double MIN[MAX_N], color[MAX_N];
long double X[MAX_N], Y[MAX_N], Z[MAX_N], R[MAX_N];
long double b, sum, sum_min;
int n, c, a;

void prim() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			MIN[j] = INF;
			color[j] = WHITE;
		}
		b = INF;
		a = n;
		color[i] = GRAY;
		MIN[i] = 0;
		while (a != 0) {
			b = INF;
			for (int j = 0; j < n; j++) {
				if (color[j] == GRAY) {
					if (b > MIN[j]) {
						b = MIN[j];
						c = j;
					}
				}
			}
			color[c] = BLACK;
			a -= 1;
			for (int k = 0; k < n; k++) {
				if (color[k] != BLACK && x[c][k] >= -EPS) {
					color[k] = GRAY;
					MIN[k] = min(x[c][k], MIN[k]);
				}
			}
		}
		sum = 0;
		for (int j = 0; j < n; j++) {
			sum += MIN[j];
		}
		sum_min = min(sum_min, sum);
	}
}

int main() {
	while (true) {
		sum_min = INF;
		cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < MAX_N; i++) {
			X[i] = 0; Y[i] = 0; Z[i] = 0;
			for (int j = 0; j < MAX_N; j++) {
				x[i][j] = -INF;
			}
		}
		for (int i = 0; i < n; i++) {
			cin >> X[i] >> Y[i] >> Z[i] >> R[i];
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				long double X1 = (X[i] - X[j])*(X[i] - X[j]);
				long double Y1 = (Y[i] - Y[j])*(Y[i] - Y[j]);
				long double Z1 = (Z[i] - Z[j])*(Z[i] - Z[j]);
				long double dist = sqrtl(X1 + Y1 + Z1);
				long double dist2 = dist - R[i] - R[j];
				x[i][j] = max(0.0l, dist2);
			}
		}
		prim();
		sum_min *= 10000;
		sum_min += 5;
		sum_min /= 10;
		int RES = sum_min;
		printf("%d.%03d\n", RES / 1000, RES % 1000);
	}
	return 0;
}

Measured memory_bytes: 16920
main :: IO()
main = do
  [n, d] <- map read . words <$> getLine
  print $ slv n d
 
slv :: Integer -> Integer -> Integer
slv n d | n `mod` (2*d+1) == 0 = n `div` (2*d+1)
        | otherwise = n `div` (2*d+1) + 1

Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (int)(1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;

int main(){
  int n;
  cin>>n;
  vector<int> x(n),y(n);
  for(int i=0;i<n;i++) cin>>x[i];
  copy(x.begin(),x.end(),y.begin());
  sort(x.begin(),x.end());
  float m=(x[n/2]+x[n/2-1])/2.0;
  for(int i=0;i<n;i++) cout<<((m>=(float)y[i])?x[n/2]:x[n/2-1])<<endl;
  return 0;
}


Measured memory_bytes: 3712
ALst = list(map(int, input().split()))

tLst = []
for i in range(3):
    for j in range(i, 2):
        tLst.append(int(abs(ALst[i] - ALst[j + 1])))

tLst.sort()
ans = tLst[0] + tLst[1]
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N;
  cin >> N;

  rep(i,N){
    string s;
    cin >>s;
    if (s=="Y") {
      cout<<"Four"<<endl;
      break;
    }
    else{
      if (i==N-1) {
        cout<<"Three"<<endl;
      }
    }
  }
}

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

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String[] line = S.Split(' ');
            int N = int.Parse(line[0]);
            int M = int.Parse(line[1]);
            int res = 0;

            List<int>[] s = new List<int>[M];
            int[] k = new int[M];

            for (int i = 0; i < M; i++)
            {
                //Console.WriteLine(i);
                S = Console.ReadLine();
                line = S.Split(' ');
                s[i] = new List<int>();
                k[i] = int.Parse(line[0]);
                for (int j = 1; j <= k[i]; j++)
                {
                    s[i].Add(int.Parse(line[j]));
                }
            }

            int[] p = new int[M];
            S = Console.ReadLine();
            line = S.Split(' ');
            for (int i = 0; i < M; i++)
            {
                p[i] = int.Parse(line[i]);
            }

            bool[] sw = new bool[N];

            for (int i = 0; i < Math.Pow(2, N); i++)
            {
                int c2 = 0;
                for (int j = 0; j < N; j++)
                {
                    if (sw[j] == false)
                    {
                        sw[j] = true;
                        break;
                    }
                    else
                    {
                        sw[j] = false;
                    }

                }
                for (int j = 0; j < M; j++)
                {
                    int c1 = 0;

                    for (int l = 0; l < k[j]; l++)
                    {
                        if (sw[s[j][l] - 1] == true)
                        {
                            c1++;
                        }
                    }
                    if (c1 % 2 == p[j])
                    {
                        c2++;
                    }
                    else
                    {
                        break;
                    }

                }
                if (c2 == M)
                {
                    res++;
                }
            }
            Console.WriteLine(res);



        }
    }
}

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

int main(){
    int n;
    cin >> n;
    int p[20];
    for(int i=0;i<n;i++)
        cin >> p[i];
    
    int a[3], ans = 0;
    for(int i=1;i<n-1;i++){
        a[0] = p[i-1];
        a[1] = p[i];
        a[2] = p[i+1];
        sort(a, a + 3);
        if(a[1] == p[i])
            ans++;
    }
        
    cout << ans << endl;

}

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

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

	string s, t;
	cin >> s >> t;

	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			cnt++;
		}
	}

	cout << cnt << "\n";
    return 0;
}


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

int main(void)
{
	int W[101] = {0};
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++)
		scanf("%d", &W[i]);

	int ans = 100000;
	int T;
	for (T = 1; T < N; T++) {
		int S1 = 0, S2 = 0;
		for (i = 1; i <= T; i++)
			S1 += W[i];
		
		for (i = T + 1; i <= N; i++)
			S2 += W[i];
		
		int d = abs(S1 - S2);
		if (ans > d)
			ans = d;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int n,i;
  int x,y;
  int max=0;
  scanf("%d",&n);
  scanf("%d",&x);
  scanf("%d",&y);
  max=y-x;
  if(x>y) x=y;
  for(i=2;i<n;i++){
    scanf("%d",&y);
    if(max<(y-x)) max=y-x;
    if(x>y) x=y;
  }

  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2108
import math

n= int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

i, j = 10**12, 10**12
res  = 0
if is_prime(n):
    res = n - 1
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
            a, b = t, n//t
            if a + b < i + j:
                i, j = a, b
    res = i + j -2


print(res)


Measured memory_bytes: 3316
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<double, double> pdd;
typedef pair<double, pdd> pddd;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
    int n;
    scanf("%d", &n);
    int ret = 0;
    while(n--) {
        int t;
        scanf("%d", &t);
        while(t%2==0) {
            ret++;
            t/=2;
        }
    }
    printf("%d\n", ret);
}


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

int main() {
  string s;
  cin >> s;
  set<char> st;
  for (int i; i<s.size(); i++){
    st.insert(s[i]);
  }
  if(st.size()==s.size()){
    cout << "yes" << endl;
  }
  else{
    cout << "no" << endl;
  }
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

int main()
{
	int H = 0, A = 0, ans = 0;
	scanf("%d %d", &H, &A);
	ans = H/A;
	if (H%A != 0) {
		ans++;
	}
	printf ("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
n,m,x = map(int,input().split())
a = [0]*n
for i in range(n):
    a[i] = list(map(int,input().split()))
ans = float("Inf")
for i in range(2**n):
    c = 0
    L = [0]*m
    for j in range(n):
        if (i>>j)&1:
            c += a[j][0]
            for k in range(m):
                L[k] += a[j][k+1]
    
    sw = 1
    for k in range(m):
        if L[k] < x:
            sw = 0
            break
    if sw == 1:
        ans = min(ans, c)
        
if ans == float("Inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9236
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def main():
    l, r = list(map(int, input().split()))
    diff = r-l
    if diff >= 2018:
        return 0

    else:
        min_ = 2 ** 20
        # l の商と余り
        p = l // 2019 ; q = l % 2019
        for xi in range(l, r):
            qi = (q + (xi - l)) % 2019
            if qi == 0:
                return 0
            for xj in range(xi+1, r+1):
                qj = (q + (xj - l)) % 2019
                if qj == 0:
                    return 0
                else:
                    qij = (qi * qj) % 2019
                    if qij < min_:
                        min_ = qij

    return min_

print(main())

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define ll long long
#define int long long
#define pb push_back
#define INF 100000000
using namespace std;
typedef pair<int, int> P; // cannot use P as var
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

const int MAX_n = 100000;
int n,a[MAX_n];


signed main(){

    scanf("%lld", &n);
    REP(i,n){
        scanf("%lld", &a[i]);
    }
    //超賢い．解説見る．
    int sum=0;
    REP(i,n){
        sum+=a[i];
    }
    ll k = (ll)n * (n + 1) / 2;
    if(sum%k!=0){
        printf("NO\n");
        return 0;
    }

    k=sum/k;



    for (int i = 0; i < n; i++)
    {
        ll d = a[i] - (i == 0 ? a[n - 1] : a[i - 1]);
        d -= k;
        if (d > 0)
        {
            printf("NO\n");
            return 0;
        }
        d = -d;
        if (d % n != 0)
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;

}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

#define INF 1000000001

int N, M;
vector<P> G[100000];
vector<bool> visit(100000, false);
vector<int> x(100000, 0);
bool ok = true;

void dfs(int cur)
{
  visit[cur] = true;
  REP(i, G[cur].size())
  {
    int to = G[cur][i].first;
    int w = G[cur][i].second;
    if (visit[to]) // 訪問済みの場合
      ok = ok && (x[to] == x[cur] + w);
    else // そうでない場合
    {
      x[to] = x[cur] + w;
      dfs(to);
    }
  }
}

int main()
{
  cin >> N >> M;
  REP(i, M)
  {
    int L, R, D;
    cin >> L >> R >> D;
    L--, R--;
    G[L].push_back(P(R, D));
    G[R].push_back(P(L, -D));
  }
  REP(i, N)
  {
    if (visit[i])
      continue;
    dfs(i);
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<ll, ll>
#define p3i pair<pii, ll>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define p_q priority_queue
#define MN 1000000009

ll n, x, y, D, X, Y;
ll ans;
pii t;
priority_queue<pair<ll, pii> > pq;
set<pii> sx, sy;
ll dis(ll X, ll Y, ll X2, ll Y2){
    return min(max(X-X2, X2-X), max(Y-Y2, Y2-Y));
}
int main(){
    cin >> n;
    for (ll l=0; l<n; ++l){
        cin >> x >> y;
        sx.insert(mp(x, y));
        sy.insert(mp(y, x));
        if (l==0) pq.push(mp(0, mp(x, y)));
    }
    while(!pq.empty()){
        D=-pq.top().x; X=pq.top().y.x; Y=pq.top().y.y; pq.pop();
        //cout << X << ' ' << Y << ' ' << D << endl;
        if (sx.lb(mp(X, Y))==sx.end() ||
            *sx.lb(mp(X, Y))!=mp(X, Y)) continue;
        sx.erase(mp(X, Y));
        sy.erase(mp(Y, X));
        ans+=D;
        if (sx.lb(mp(X, Y))!=sx.end()){
            t=*sx.lb(mp(X, Y));
            pq.push(mp(-dis(X, Y, t.x, t.y), t));
        }
        if (sx.lb(mp(X, Y))!=sx.begin()){
            t=*--sx.lb(mp(X, Y));
            pq.push(mp(-dis(X, Y, t.x, t.y), t));
        }
        if (sy.lb(mp(Y, X))!=sy.end()){
            t=*sy.lb(mp(Y, X));
            x=t.x; y=t.y; t=mp(y, x);
            pq.push(mp(-dis(X, Y, t.x, t.y), t));
        }
        if (sy.lb(mp(Y, X))!=sy.begin()){
            t=*--sy.lb(mp(Y, X));
            x=t.x; y=t.y; t=mp(y, x);
            pq.push(mp(-dis(X, Y, t.x, t.y), t));
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 26220
N = int(input())
h = list(map(int,input().split()))
INF = 10**9
dp = [INF]*N
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2,N):
    dp1 = abs(h[i]-h[i-1])+dp[i-1]
    dp2 = abs(h[i]-h[i-2])+dp[i-2]
    dp[i] = min([dp1,dp2])
print(dp[N-1])

Measured memory_bytes: 13976
import java.util.*;
class Main{
  static int n;
  public static void main(String args[])throws Exception{
    Scanner sc = new Scanner(System.in);
    int count = 0;
    int number = 0;
    n = sc.nextInt();
    int array_s [] = new int[n];
    for(int i =0; i<n; i++){
      array_s[i] = sc.nextInt();
    }

    int q = sc.nextInt();
    int t;
    for(int i = 0; i<q; i++){
      t = sc.nextInt();
      //二分探索
      count += binarysearch(t, array_s);
    }
    System.out.println(count);
  }

  static int binarysearch(int k , int a[]){
    int left = 0;
    int right = n;
    int mid;
    while(left<right){
      mid = (left+right)/2;
      if(k==a[mid])return 1;
      else if(k<a[mid])right=mid;
      else left = mid+1;
    }
    return 0;
  }
}


Measured memory_bytes: 78008
N = int(input())
Alist = list(map(int,input().split()))
sum1 = sum(Alist)
dic = {}
for a in Alist:
    if not a in dic:
        dic[a] = 0
    dic[a]+=1

Q = int(input())
Qlist = []
for _ in range(Q):
    Qlist.append(list(map(int,input().split())))
for q in Qlist:
    b,c = q
    n = 0
    if b in dic:
        n = dic[b]
        dic[b] = 0
    else:
        pass

    if c in dic:
        dic[c] += n
    else:
        dic[c] = n
    sum1 += n*(c-b)

    print(sum1)

Measured memory_bytes: 35376
def main():
  n = int(raw_input())
  row = [int(x) for x in raw_input().split(' ')]
  min_val = float('inf')
  
  is_eq = True
  for x in row:
    if x != row[0]:
      is_eq = False
  if is_eq:
    print('0')
    return
  
  for x in xrange(-100, 101):
    data = [(elem - x)**2 for elem in row]
    if sum(data) < min_val:
      min_val = sum(data)
  print(min_val)

main()


Measured memory_bytes: 2568
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	memo := map[int]int{
		0: 2, 1: 1,
	}

	var fib func(x int) int
	fib = func(x int) int {
		res, exist := memo[x]
		if exist {
			return res
		}

		res = fib(x-1) + fib(x-2)
		memo[x] = res
		return res
	}

	fmt.Println(fib(N))
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<string>
#include<stack>

using namespace std;

bool check(int a){
	int b,c;
	c=a;
	b=0;
	while(c!=0){
		b*=10;
		b+=c%10;
		c/=10;
	}
	return b==a;
}

int main(){

	int n;
	int min=-1,max=-1;

	cin>>n;
	
	for(int i=n;;i--){
		if(check(i)){
			min=i;
			break;
		}
	}

	for(int i=n;;i++){
		if(check(i)){
			max=i;
			break;
		}
	}

	if(n-min>max-n) cout<<max<<endl;
	else cout<<min<<endl;

	return 0;
}

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

int asc(const void *A, const void *B) {
	if (*(int *)A > *(int *)B) return 1;
	if (*(int *)A < *(int *)B) return -1;
	return 0;
}

int main()
{
	int n[3];
	rep(i,3)
		cin >> n[i];
	int a = 0;
	int b = 0;
	int idx;
	qsort(n, sizeof(n) / sizeof(*n) , sizeof(int), asc);
	a = n[2] - n[0];
	b = n[2] - n[1];
	int ans  = 0;
	if (a % 2 == 0 && b % 2 == 0)
		ans = (a / 2) + (b / 2);
	else if (a % 2 && b % 2)
		ans = (a + b) / 2;
	else 
	{
		// if (abs(a - b) == 1)
		// 	ans = (max(a, b)) + 1;
		// else if (abs(a - b) == 3)
		// 	ans = max(a, b);
		// else
		ans = (((a+1) / 2) + ((b+1) / 2)) + 1;
	}
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    int a, b;
    
    scanf( "%d %d", &a, &b );
    
    double c, d;
    c = a;
    d = b;
    
    printf( "%d %d %f\n", a/b, a%b, c/d );
    
    return 0;
    
}


Measured memory_bytes: 2096
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    static long solve(int weight[],long price[],int wt,int n){
        
        
        long t[][]=new long[n+1][wt+1];
        
        
        
        
        for(int i=1;i<=n;i++){
            for(int j=1;j<=wt;j++){
                
                if(weight[i-1]<=j){
                    t[i][j]=Math.max(price[i-1]+t[i-1][j-weight[i-1]],t[i-1][j]);
                }
                
                else{
                    t[i][j]=t[i-1][j];
                }
                
            }
        }
        
        
       return t[n][wt];
       
        }
        
  
    
    
    
	public static void main (String[] args) throws java.lang.Exception
	{
	
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
   int wt=s.nextInt();
   
   int weight[]=new int[n];
   long price[]=new long[n];
   
   for(int i=0;i<n;i++){
       weight[i]=s.nextInt();
         price[i]=s.nextLong();
   }
  /* for(int i=0;i<n;i++){
       price[i]=s.nextLong();
   }*/
   
  System.out.println( solve(weight,price,wt,n));
   
	}
}


Measured memory_bytes: 127572
#include<stdio.h>
int main(void) {
  int n, m,i;
  int kikan[100000];
  int sum = 0;
  
  scanf("%d",&n);
  scanf("%d",&m);
  
  for(i = 0; i < m; i++) {
    scanf("%d", &kikan[i]);
    sum += kikan[i];
  }
  
  if(n >= sum) {
    printf("%d", n - sum);
  }
  else
    printf("-1");
  return 0;
}

Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		int[] ans = new int[S.length()];
		
		int rIndex = 0;
		int lIndex = S.length()-1;
		int rCount = 0;
		int lCount = 0;
		
		boolean rPhase = true;
		
		for(int i=0; i<S.length(); i++) {
			if(rPhase) {
				if(S.charAt(i)=='L') {
					rIndex = i - 1;
					lIndex = i;
					rPhase = false;
					lCount++;
				}else {
					rCount ++;
				}
			}else{
				if(S.charAt(i)=='R') {
					//record
					ans[rIndex] = (rCount - rCount/2) + lCount/2;
					ans[lIndex] = rCount/2 + (lCount - lCount/2);
					//reset
					rCount = 1;
					lCount = 0;
					rPhase = true;
				}else {
					lCount ++;
				}
			}
			
		}
		//record
		ans[rIndex] = (rCount - rCount/2) + lCount/2;
		ans[lIndex] = rCount/2 + (lCount - lCount/2);
		
		//print
		for(int i=0; i<ans.length; i++) {
			System.out.print(ans[i]);
			if(i==ans.length-1) {
				System.out.println();
			}else {
				System.out.print(" ");
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 46004